1
+ − 1
<?php
+ − 2
+ − 3
/*
+ − 4
* Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between
21
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 5
* Version 1.0 (Banshee)
1
+ − 6
* Copyright (C) 2006-2007 Dan Fuhry
+ − 7
*
+ − 8
* This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
+ − 9
* as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
+ − 10
*
+ − 11
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ − 12
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
+ − 13
*/
+ − 14
+ − 15
class template {
+ − 16
var $tpl_strings, $tpl_bool, $theme, $style, $no_headers, $additional_headers, $sidebar_extra, $sidebar_widgets, $toolbar_menu, $theme_list, $named_theme_list, $default_theme, $default_style, $plugin_blocks, $namespace_string, $style_list, $theme_loaded;
+ − 17
function __construct()
+ − 18
{
+ − 19
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 20
dc_here('template: initializing all class variables');
+ − 21
$this->tpl_bool = Array();
+ − 22
$this->tpl_strings = Array();
+ − 23
$this->sidebar_extra = '';
+ − 24
$this->toolbar_menu = '';
+ − 25
$this->additional_headers = '';
+ − 26
$this->plugin_blocks = Array();
+ − 27
$this->theme_loaded = false;
+ − 28
+ − 29
$this->theme_list = Array();
+ − 30
$this->named_theme_list = Array();
+ − 31
$e = $db->sql_query('SELECT theme_id,theme_name,enabled,default_style FROM '.table_prefix.'themes WHERE enabled=1 ORDER BY theme_order;');
+ − 32
if(!$e) $db->_die('The list of themes could not be selected.');
+ − 33
for($i=0;$i < $db->numrows(); $i++)
+ − 34
{
+ − 35
$this->theme_list[$i] = $db->fetchrow();
+ − 36
$this->named_theme_list[$this->theme_list[$i]['theme_id']] = $this->theme_list[$i];
+ − 37
}
+ − 38
$db->free_result();
+ − 39
$this->default_theme = $this->theme_list[0]['theme_id'];
+ − 40
$dir = ENANO_ROOT.'/themes/'.$this->default_theme.'/css/';
+ − 41
$list = Array();
+ − 42
// Open a known directory, and proceed to read its contents
+ − 43
if (is_dir($dir)) {
+ − 44
if ($dh = opendir($dir)) {
+ − 45
while (($file = readdir($dh)) !== false) {
+ − 46
if(preg_match('#^(.*?)\.css$#i', $file) && $file != '_printable.css') {
+ − 47
$list[] = substr($file, 0, strlen($file)-4);
+ − 48
}
+ − 49
}
+ − 50
closedir($dh);
+ − 51
}
+ − 52
}
+ − 53
+ − 54
$def = ENANO_ROOT.'/themes/'.$this->default_theme.'/css/'.$this->named_theme_list[$this->default_theme]['default_style'];
+ − 55
if(file_exists($def))
+ − 56
{
+ − 57
$this->default_style = substr($this->named_theme_list[$this->default_theme]['default_style'], 0, strlen($this->named_theme_list[$this->default_theme]['default_style'])-4);
+ − 58
} else {
+ − 59
$this->default_style = $list[0];
+ − 60
}
+ − 61
+ − 62
$this->style_list = $list;
+ − 63
+ − 64
}
+ − 65
function template()
+ − 66
{
+ − 67
$this->__construct();
+ − 68
}
+ − 69
function sidebar_widget($t, $h)
+ − 70
{
+ − 71
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 72
if(!defined('ENANO_TEMPLATE_LOADED'))
+ − 73
{
+ − 74
$this->load_theme($session->theme, $session->style);
+ − 75
}
+ − 76
if(!$this->sidebar_widgets)
+ − 77
$this->sidebar_widgets = '';
+ − 78
$tplvars = $this->extract_vars('elements.tpl');
+ − 79
$parser = $this->makeParserText($tplvars['sidebar_section_raw']);
+ − 80
$parser->assign_vars(Array('TITLE'=>$t,'CONTENT'=>$h));
+ − 81
$this->plugin_blocks[$t] = $h;
+ − 82
$this->sidebar_widgets .= $parser->run();
+ − 83
}
+ − 84
function add_header($html)
+ − 85
{
+ − 86
$this->additional_headers .= "\n" . $html;
+ − 87
}
+ − 88
function get_css($s = false)
+ − 89
{
+ − 90
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 91
if(!defined('ENANO_TEMPLATE_LOADED'))
+ − 92
$this->load_theme($session->theme, $session->style);
+ − 93
$path = ( $s ) ? 'css/'.$s : 'css/'.$this->style.'.css';
+ − 94
if ( !file_exists(ENANO_ROOT . '/themes/' . $this->theme . '/' . $path) )
+ − 95
{
+ − 96
echo "/* WARNING: Falling back to default file because file $path does not exist */\n";
+ − 97
$path = 'css/' . $this->style_list[0] . '.css';
+ − 98
}
+ − 99
return $this->process_template($path);
+ − 100
}
+ − 101
function load_theme($name = false, $css = false)
+ − 102
{
+ − 103
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 104
$this->theme = ( $name ) ? $name : $session->theme;
+ − 105
$this->style = ( $css ) ? $css : $session->style;
+ − 106
if ( !$this->theme )
+ − 107
{
+ − 108
$this->theme = $this->theme_list[0]['theme_id'];
+ − 109
$this->style = substr($this->theme_list[0]['default_style'], 0, strlen($this->theme_list[0]['default_style'])-4);
+ − 110
}
+ − 111
$this->theme_loaded = true;
+ − 112
}
+ − 113
+ − 114
function init_vars()
+ − 115
{
+ − 116
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 117
global $email;
+ − 118
+ − 119
dc_here("template: initializing all variables");
+ − 120
+ − 121
if(!$this->theme || !$this->style)
+ − 122
{
+ − 123
$this->load_theme();
+ − 124
}
+ − 125
+ − 126
if(defined('ENANO_TEMPLATE_LOADED'))
+ − 127
{
+ − 128
dc_here('template: access denied to call template::init_vars(), bailing out');
+ − 129
die_semicritical('Illegal call', '<p>$template->load_theme was called multiple times, this is not supposed to happen. Exiting with fatal error.</p>');
+ − 130
}
+ − 131
+ − 132
define('ENANO_TEMPLATE_LOADED', '');
+ − 133
+ − 134
$tplvars = $this->extract_vars('elements.tpl');
+ − 135
+ − 136
dc_here('template: setting all template vars');
+ − 137
+ − 138
if(isset($_SERVER['HTTP_USER_AGENT']) && strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE'))
+ − 139
{
+ − 140
$this->add_header('
+ − 141
<!--[if lt IE 7]>
+ − 142
<script language="JavaScript">
+ − 143
function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
+ − 144
{
+ − 145
var arVersion = navigator.appVersion.split("MSIE")
+ − 146
var version = parseFloat(arVersion[1])
+ − 147
if (version >= 5.5 && typeof(document.body.filters) == "object")
+ − 148
{
+ − 149
for(var i=0; i<document.images.length; i++)
+ − 150
{
+ − 151
var img = document.images[i];
+ − 152
continue;
+ − 153
var imgName = img.src.toUpperCase();
+ − 154
if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
+ − 155
{
+ − 156
var imgID = (img.id) ? "id=\'" + img.id + "\' " : "";
+ − 157
var imgClass = (img.className) ? "class=\'" + img.className + "\' " : "";
+ − 158
var imgTitle = (img.title) ? "title=\'" + img.title + "\' " : "title=\'" + img.alt + "\' ";
+ − 159
var imgStyle = "display:inline-block;" + img.style.cssText;
+ − 160
if (img.align == "left") imgStyle = "float:left;" + imgStyle;
+ − 161
if (img.align == "right") imgStyle = "float:right;" + imgStyle;
+ − 162
if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;
+ − 163
var strNewHTML = "<span " + imgID + imgClass + imgTitle + " style=\\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";" + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" + "(src=\\\'" + img.src + "\\\', sizingMethod=\'scale\');\\"></span>";
+ − 164
img.outerHTML = strNewHTML;
+ − 165
i = i-1;
+ − 166
}
+ − 167
}
+ − 168
}
+ − 169
}
+ − 170
window.attachEvent("onload", correctPNG);
+ − 171
</script>
+ − 172
<![endif]-->
+ − 173
');
+ − 174
}
+ − 175
+ − 176
// Get the "article" button text (depends on namespace)
+ − 177
switch($paths->namespace) {
+ − 178
case "Article":
+ − 179
default:
+ − 180
$ns = 'article';
+ − 181
break;
+ − 182
case "Admin":
+ − 183
$ns = 'administration page';
+ − 184
break;
+ − 185
case "System":
+ − 186
$ns = 'system message';
+ − 187
break;
+ − 188
case "File":
+ − 189
$ns = 'uploaded file';
+ − 190
break;
+ − 191
case "Help":
+ − 192
$ns = 'documentation page';
+ − 193
break;
+ − 194
case "User":
+ − 195
$ns = 'user page';
+ − 196
break;
+ − 197
case "Special":
+ − 198
$ns = 'special page';
+ − 199
break;
+ − 200
case "Template":
+ − 201
$ns = 'template';
+ − 202
break;
+ − 203
case "Project":
+ − 204
$ns = 'project page';
+ − 205
break;
+ − 206
case "Category":
+ − 207
$ns = 'category';
+ − 208
break;
+ − 209
}
+ − 210
$this->namespace_string = $ns;
+ − 211
$code = $plugins->setHook('page_type_string_set');
+ − 212
foreach ( $code as $cmd )
+ − 213
{
+ − 214
eval($cmd);
+ − 215
}
+ − 216
$ns =& $this->namespace_string;
+ − 217
+ − 218
// Initialize the toolbar
+ − 219
$tb = '';
+ − 220
+ − 221
// Create "xx page" button
+ − 222
+ − 223
$btn_selected = ( isset($tplvars['toolbar_button_selected'])) ? $tplvars['toolbar_button_selected'] : $tplvars['toolbar_button'];
+ − 224
$parser = $this->makeParserText($btn_selected);
+ − 225
+ − 226
$parser->assign_vars(array(
+ − 227
'FLAGS' => 'onclick="void(ajaxReset()); return false;" title="View the page contents, all of the page contents, and nothing but the page contents (alt-a)" accesskey="a"',
+ − 228
'PARENTFLAGS' => 'id="mdgToolbar_article"',
+ − 229
'HREF' => makeUrl($paths->page, null, true),
+ − 230
'TEXT' => $this->namespace_string
+ − 231
));
+ − 232
+ − 233
$tb .= $parser->run();
+ − 234
+ − 235
$button = $this->makeParserText($tplvars['toolbar_button']);
+ − 236
+ − 237
// Page toolbar
+ − 238
// Comments button
+ − 239
if ( $session->get_permissions('read') && getConfig('enable_comments')=='1' && $paths->namespace != 'Special' && $paths->namespace != 'Admin' && $paths->cpage['comments_on'] == 1 )
+ − 240
{
+ − 241
+ − 242
$e = $db->sql_query('SELECT approved FROM '.table_prefix.'comments WHERE page_id=\''.$paths->cpage['urlname_nons'].'\' AND namespace=\''.$paths->namespace.'\';');
+ − 243
if ( !$e )
+ − 244
{
+ − 245
$db->_die();
+ − 246
}
+ − 247
$nc = $db->numrows();
+ − 248
$nu = 0;
+ − 249
$na = 0;
+ − 250
+ − 251
while ( $r = $db->fetchrow() )
+ − 252
{
+ − 253
if ( !$r['approved'] )
+ − 254
{
+ − 255
$nu++;
+ − 256
}
+ − 257
else
+ − 258
{
+ − 259
$na++;
+ − 260
}
+ − 261
}
+ − 262
+ − 263
$db->free_result();
+ − 264
$n = ( $session->get_permissions('mod_comments') ) ? (string)$nc : (string)$na;
+ − 265
if ( $session->get_permissions('mod_comments') && $nu > 0 )
+ − 266
{
+ − 267
$n .= ' total/'.$nu.' unapp.';
+ − 268
}
+ − 269
+ − 270
$button->assign_vars(array(
+ − 271
'FLAGS' => 'onclick="void(ajaxComments()); return false;" title="View the comments that other users have posted about this page (alt-c)" accesskey="c"',
+ − 272
'PARENTFLAGS' => 'id="mdgToolbar_discussion"',
+ − 273
'HREF' => makeUrl($paths->page, 'do=comments', true),
+ − 274
'TEXT' => 'discussion ('.$n.')',
+ − 275
));
+ − 276
+ − 277
$tb .= $button->run();
+ − 278
}
+ − 279
// Edit button
+ − 280
if($session->get_permissions('read') && ($paths->namespace != 'Special' && $paths->namespace != 'Admin') && ( $session->get_permissions('edit_page') && ( ( $paths->page_protected && $session->get_permissions('even_when_protected') ) || !$paths->page_protected ) ) )
+ − 281
{
+ − 282
$button->assign_vars(array(
+ − 283
'FLAGS' => 'onclick="void(ajaxEditor()); return false;" title="Edit the contents of this page (alt-e)" accesskey="e"',
+ − 284
'PARENTFLAGS' => 'id="mdgToolbar_edit"',
+ − 285
'HREF' => makeUrl($paths->page, 'do=edit', true),
+ − 286
'TEXT' => 'edit this page'
+ − 287
));
+ − 288
$tb .= $button->run();
+ − 289
// View source button
+ − 290
}
+ − 291
else if($session->get_permissions('view_source') && ( !$session->get_permissions('edit_page') || !$session->get_permissions('even_when_protected') && $paths->page_protected ) && $paths->namespace != 'Special' && $paths->namespace != 'Admin')
+ − 292
{
+ − 293
$button->assign_vars(array(
+ − 294
'FLAGS' => 'onclick="void(ajaxViewSource()); return false;" title="View the source code (wiki markup) that this page uses (alt-e)" accesskey="e"',
+ − 295
'PARENTFLAGS' => 'id="mdgToolbar_edit"',
+ − 296
'HREF' => makeUrl($paths->page, 'do=viewsource', true),
+ − 297
'TEXT' => 'view source'
+ − 298
));
+ − 299
$tb .= $button->run();
+ − 300
}
+ − 301
// History button
+ − 302
if ( $session->get_permissions('read') /* && $paths->wiki_mode */ && $paths->page_exists && $paths->namespace != 'Special' && $paths->namespace != 'Admin' && $session->get_permissions('history_view') )
+ − 303
{
+ − 304
$button->assign_vars(array(
+ − 305
'FLAGS' => 'onclick="void(ajaxHistory()); return false;" title="View a log of actions taken on this page (alt-h)" accesskey="h"',
+ − 306
'PARENTFLAGS' => 'id="mdgToolbar_history"',
+ − 307
'HREF' => makeUrl($paths->page, 'do=history', true),
+ − 308
'TEXT' => 'history'
+ − 309
));
+ − 310
$tb .= $button->run();
+ − 311
}
+ − 312
+ − 313
$menubtn = $this->makeParserText($tplvars['toolbar_menu_button']);
+ − 314
+ − 315
// Additional actions menu
+ − 316
// Rename button
+ − 317
if ( $session->get_permissions('read') && $paths->page_exists && ( $session->get_permissions('rename') && ( $paths->page_protected && $session->get_permissions('even_when_protected') || !$paths->page_protected ) ) && $paths->namespace != 'Special' && $paths->namespace != 'Admin' )
+ − 318
{
+ − 319
$menubtn->assign_vars(array(
+ − 320
'FLAGS' => 'onclick="void(ajaxRename()); return false;" title="Change the display name of this page (alt-r)" accesskey="r"',
+ − 321
'HREF' => makeUrl($paths->page, 'do=rename', true),
+ − 322
'TEXT' => 'rename',
+ − 323
));
+ − 324
$this->toolbar_menu .= $menubtn->run();
+ − 325
}
+ − 326
+ − 327
// Vote-to-delete button
+ − 328
if ( $paths->wiki_mode && $session->get_permissions('vote_delete') && $paths->page_exists && $paths->namespace != 'Special' && $paths->namespace != 'Admin')
+ − 329
{
+ − 330
$menubtn->assign_vars(array(
+ − 331
'FLAGS' => 'onclick="void(ajaxDelVote()); return false;" title="Vote to have this page deleted (alt-d)" accesskey="d"',
+ − 332
'HREF' => makeUrl($paths->page, 'do=delvote', true),
+ − 333
'TEXT' => 'vote to delete this page',
+ − 334
));
+ − 335
$this->toolbar_menu .= $menubtn->run();
+ − 336
}
+ − 337
+ − 338
// Clear-votes button
+ − 339
if ( $session->get_permissions('read') && $paths->wiki_mode && $paths->page_exists && $paths->namespace != 'Special' && $paths->namespace != 'Admin' && $session->get_permissions('vote_reset') && $paths->cpage['delvotes'] > 0)
+ − 340
{
+ − 341
$menubtn->assign_vars(array(
+ − 342
'FLAGS' => 'onclick="void(ajaxResetDelVotes()); return false;" title="Vote to have this page deleted (alt-y)" accesskey="y"',
+ − 343
'HREF' => makeUrl($paths->page, 'do=resetvotes', true),
+ − 344
'TEXT' => 'reset deletion votes',
+ − 345
));
+ − 346
$this->toolbar_menu .= $menubtn->run();
+ − 347
}
+ − 348
+ − 349
// Printable page button
+ − 350
if ( $paths->page_exists && $paths->namespace != 'Special' && $paths->namespace != 'Admin' )
+ − 351
{
+ − 352
$menubtn->assign_vars(array(
+ − 353
'FLAGS' => 'title="View a version of this page that is suitable for printing"',
+ − 354
'HREF' => makeUrl($paths->page, 'printable=yes', true),
+ − 355
'TEXT' => 'view printable version',
+ − 356
));
+ − 357
$this->toolbar_menu .= $menubtn->run();
+ − 358
}
+ − 359
+ − 360
// Protect button
+ − 361
if($session->get_permissions('read') && $paths->wiki_mode && $paths->page_exists && $paths->namespace != 'Special' && $paths->namespace != 'Admin' && $session->get_permissions('protect'))
+ − 362
{
+ − 363
+ − 364
$label = $this->makeParserText($tplvars['toolbar_label']);
+ − 365
$label->assign_vars(array('TEXT' => 'protection:'));
+ − 366
$t0 = $label->run();
+ − 367
+ − 368
$ctmp = '';
+ − 369
if ( $paths->cpage['protected'] == 1 )
+ − 370
{
+ − 371
$ctmp=' style="text-decoration: underline;"';
+ − 372
}
+ − 373
$menubtn->assign_vars(array(
+ − 374
'FLAGS' => 'accesskey="i" onclick="ajaxProtect(1); return false;" id="protbtn_1" title="Prevents all non-administrators from editing this page. [alt-i]"'.$ctmp,
+ − 375
'HREF' => makeUrl($paths->page, 'do=protect&level=1', true),
+ − 376
'TEXT' => 'on'
+ − 377
));
+ − 378
$t1 = $menubtn->run();
+ − 379
+ − 380
$ctmp = '';
+ − 381
if ( $paths->cpage['protected'] == 0 )
+ − 382
{
+ − 383
$ctmp=' style="text-decoration: underline;"';
+ − 384
}
+ − 385
$menubtn->assign_vars(array(
+ − 386
'FLAGS' => 'accesskey="o" onclick="ajaxProtect(0); return false;" id="protbtn_0" title="Allows everyone to edit this page. [alt-o]"'.$ctmp,
+ − 387
'HREF' => makeUrl($paths->page, 'do=protect&level=0', true),
+ − 388
'TEXT' => 'off'
+ − 389
));
+ − 390
$t2 = $menubtn->run();
+ − 391
+ − 392
$ctmp = '';
+ − 393
if ( $paths->cpage['protected'] == 2 )
+ − 394
{
+ − 395
$ctmp = ' style="text-decoration: underline;"';
+ − 396
}
+ − 397
$menubtn->assign_vars(array(
+ − 398
'FLAGS' => 'accesskey="p" onclick="ajaxProtect(2); return false;" id="protbtn_2" title="Allows only users who have been registered for 4 days to edit this page. [alt-p]"'.$ctmp,
+ − 399
'HREF' => makeUrl($paths->page, 'do=protect&level=2', true),
+ − 400
'TEXT' => 'semi'
+ − 401
));
+ − 402
$t3 = $menubtn->run();
+ − 403
+ − 404
$this->toolbar_menu .= ' <table border="0" cellspacing="0" cellpadding="0">
+ − 405
<tr>
+ − 406
<td>'.$t0.'</td>
+ − 407
<td>'.$t1.'</td>
+ − 408
<td>'.$t2.'</td>
+ − 409
<td>'.$t3.'</td>
+ − 410
</tr>
+ − 411
</table>';
+ − 412
}
+ − 413
+ − 414
// Wiki mode button
+ − 415
if($session->get_permissions('read') && $paths->page_exists && $session->get_permissions('set_wiki_mode') && $paths->namespace != 'Special' && $paths->namespace != 'Admin')
+ − 416
{
+ − 417
// label at start
+ − 418
$label = $this->makeParserText($tplvars['toolbar_label']);
+ − 419
$label->assign_vars(array('TEXT' => 'page wiki mode:'));
+ − 420
$t0 = $label->run();
+ − 421
+ − 422
// on button
+ − 423
$ctmp = '';
+ − 424
if ( $paths->cpage['wiki_mode'] == 1 )
+ − 425
{
+ − 426
$ctmp = ' style="text-decoration: underline;"';
+ − 427
}
+ − 428
$menubtn->assign_vars(array(
+ − 429
'FLAGS' => 'onclick="ajaxSetWikiMode(1); return false;" id="wikibtn_1" title="Forces wiki functions to be allowed on this page."'.$ctmp,
+ − 430
'HREF' => makeUrl($paths->page, 'do=setwikimode&level=1', true),
+ − 431
'TEXT' => 'on'
+ − 432
));
+ − 433
$t1 = $menubtn->run();
+ − 434
+ − 435
// off button
+ − 436
$ctmp = '';
+ − 437
if ( $paths->cpage['wiki_mode'] == 0 )
+ − 438
{
+ − 439
$ctmp=' style="text-decoration: underline;"';
+ − 440
}
+ − 441
$menubtn->assign_vars(array(
+ − 442
'FLAGS' => 'onclick="ajaxSetWikiMode(0); return false;" id="wikibtn_0" title="Forces wiki functions to be disabled on this page."'.$ctmp,
+ − 443
'HREF' => makeUrl($paths->page, 'do=setwikimode&level=0', true),
+ − 444
'TEXT' => 'off'
+ − 445
));
+ − 446
$t2 = $menubtn->run();
+ − 447
+ − 448
// global button
+ − 449
$ctmp = '';
+ − 450
if ( $paths->cpage['wiki_mode'] == 2 )
+ − 451
{
+ − 452
$ctmp=' style="text-decoration: underline;"';
+ − 453
}
+ − 454
$menubtn->assign_vars(array(
+ − 455
'FLAGS' => 'onclick="ajaxSetWikiMode(2); return false;" id="wikibtn_2" title="Causes this page to use the global wiki mode setting (default)"'.$ctmp,
+ − 456
'HREF' => makeUrl($paths->page, 'do=setwikimode&level=2', true),
+ − 457
'TEXT' => 'global'
+ − 458
));
+ − 459
$t3 = $menubtn->run();
+ − 460
+ − 461
// Tack it onto the list of buttons that are already there...
+ − 462
$this->toolbar_menu .= ' <table border="0" cellspacing="0" cellpadding="0">
+ − 463
<tr>
+ − 464
<td>'.$t0.'</td>
+ − 465
<td>'.$t1.'</td>
+ − 466
<td>'.$t2.'</td>
+ − 467
<td>'.$t3.'</td>
+ − 468
</tr>
+ − 469
</table>';
+ − 470
}
+ − 471
+ − 472
// Clear logs button
15
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 473
if ( $session->get_permissions('read') && $session->get_permissions('clear_logs') && $paths->namespace != 'Special' && $paths->namespace != 'Admin' )
1
+ − 474
{
+ − 475
$menubtn->assign_vars(array(
+ − 476
'FLAGS' => 'onclick="void(ajaxClearLogs()); return false;" title="Remove all edit and action logs for this page from the database. IRREVERSIBLE! (alt-l)" accesskey="l"',
+ − 477
'HREF' => makeUrl($paths->page, 'do=flushlogs', true),
+ − 478
'TEXT' => 'clear page logs',
+ − 479
));
+ − 480
$this->toolbar_menu .= $menubtn->run();
+ − 481
}
+ − 482
+ − 483
// Delete page button
+ − 484
if ( $session->get_permissions('read') && $session->get_permissions('delete_page') && $paths->page_exists && $paths->namespace != 'Special' && $paths->namespace != 'Admin' )
+ − 485
{
+ − 486
$s = 'delete this page';
+ − 487
if ( $paths->cpage['delvotes'] == 1 )
+ − 488
{
+ − 489
$s .= ' (<b>'.$paths->cpage['delvotes'].'</b> vote)';
+ − 490
}
+ − 491
else if ( $paths->cpage['delvotes'] > 1 )
+ − 492
{
+ − 493
$s .= ' (<b>'.$paths->cpage['delvotes'].'</b> votes)';
+ − 494
}
+ − 495
+ − 496
$menubtn->assign_vars(array(
+ − 497
'FLAGS' => 'onclick="void(ajaxDeletePage()); return false;" title="Delete this page. This is always reversible unless the logs are cleared. (alt-k)" accesskey="k"',
+ − 498
'HREF' => makeUrl($paths->page, 'do=deletepage', true),
+ − 499
'TEXT' => $s,
+ − 500
));
+ − 501
$this->toolbar_menu .= $menubtn->run();
+ − 502
+ − 503
}
+ − 504
+ − 505
// Password-protect button
+ − 506
if(isset($paths->cpage['password']))
+ − 507
{
+ − 508
if ( $paths->cpage['password'] == '' )
+ − 509
{
+ − 510
$a = $session->get_permissions('password_set');
+ − 511
}
+ − 512
else
+ − 513
{
+ − 514
$a = $session->get_permissions('password_reset');
+ − 515
}
+ − 516
}
+ − 517
else
+ − 518
{
+ − 519
$a = $session->get_permissions('password_set');
+ − 520
}
+ − 521
if ( $a && $session->get_permissions('read') && $paths->page_exists && $paths->namespace != 'Special' && $paths->namespace != 'Admin' )
+ − 522
{
+ − 523
// label at start
+ − 524
$label = $this->makeParserText($tplvars['toolbar_label']);
13
fdd6b9dd42c3
Installer actually works now on dev servers; minor language change in template.php; code cleanliness fix in sessions.php
Dan
diff
changeset
+ − 525
$label->assign_vars(array('TEXT' => 'page password:'));
1
+ − 526
$t0 = $label->run();
+ − 527
+ − 528
$menubtn->assign_vars(array(
+ − 529
'FLAGS' => 'onclick="void(ajaxSetPassword()); return false;" title="Require a password in order for this page to be viewed"',
+ − 530
'HREF' => '#',
+ − 531
'TEXT' => 'set',
+ − 532
));
+ − 533
$t = $menubtn->run();
+ − 534
+ − 535
$this->toolbar_menu .= '<table border="0" cellspacing="0" cellpadding="0"><tr><td>'.$t0.'</td><td><input type="password" id="mdgPassSetField" size="10" /></td><td>'.$t.'</td></tr></table>';
+ − 536
}
+ − 537
+ − 538
// Manage ACLs button
+ − 539
if($session->get_permissions('edit_acl') || $session->user_level >= USER_LEVEL_ADMIN)
+ − 540
{
+ − 541
$menubtn->assign_vars(array(
+ − 542
'FLAGS' => 'onclick="return ajaxOpenACLManager();" title="Manage who can do what with this page (alt-m)" accesskey="m"',
+ − 543
'HREF' => makeUrl($paths->page, 'do=aclmanager', true),
+ − 544
'TEXT' => 'manage page access',
+ − 545
));
+ − 546
$this->toolbar_menu .= $menubtn->run();
+ − 547
}
+ − 548
+ − 549
// Administer page button
+ − 550
if ( $session->user_level >= USER_LEVEL_ADMIN && $paths->page_exists && $paths->namespace != 'Special' && $paths->namespace != 'Admin' )
+ − 551
{
+ − 552
$menubtn->assign_vars(array(
+ − 553
'FLAGS' => 'onclick="void(ajaxAdminPage()); return false;" title="Administrative options for this page" accesskey="g"',
+ − 554
'HREF' => makeUrlNS('Special', 'Administration', 'module='.$paths->nslist['Admin'].'PageManager', true),
+ − 555
'TEXT' => 'administrative options',
+ − 556
));
+ − 557
$this->toolbar_menu .= $menubtn->run();
+ − 558
}
+ − 559
+ − 560
if ( strlen($this->toolbar_menu) > 0 )
+ − 561
{
+ − 562
$button->assign_vars(array(
+ − 563
'FLAGS' => 'id="mdgToolbar_moreoptions" onclick="return false;" title="Additional options for working with this page"',
+ − 564
'PARENTFLAGS' => '',
+ − 565
'HREF' => makeUrl($paths->page, 'do=moreoptions', true),
+ − 566
'TEXT' => 'more options'
+ − 567
));
+ − 568
$tb .= $button->run();
+ − 569
}
+ − 570
+ − 571
$is_opera = (isset($_SERVER['HTTP_USER_AGENT']) && strstr($_SERVER['HTTP_USER_AGENT'], 'Opera')) ? true : false;
+ − 572
+ − 573
$this->tpl_bool = Array(
+ − 574
'auth_admin'=>$session->user_level >= USER_LEVEL_ADMIN ? true : false,
+ − 575
'user_logged_in'=>$session->user_logged_in,
+ − 576
'opera'=>$is_opera,
+ − 577
);
+ − 578
+ − 579
if($session->sid_super) { $ash = '&auth='.$session->sid_super; $asq = "?auth=".$session->sid_super; $asa = "&auth=".$session->sid_super; $as2 = htmlspecialchars(urlSeparator).'auth='.$session->sid_super; }
+ − 580
else { $asq=''; $asa=''; $as2 = ''; $ash = ''; }
+ − 581
+ − 582
$code = $plugins->setHook('compile_template');
+ − 583
foreach ( $code as $cmd )
+ − 584
{
+ − 585
eval($cmd);
+ − 586
}
+ − 587
+ − 588
// Some additional sidebar processing
+ − 589
if($this->sidebar_extra != '') {
+ − 590
$se = $this->sidebar_extra;
+ − 591
$parser = $this->makeParserText($tplvars['sidebar_section_raw']);
+ − 592
$parser->assign_vars(Array('TITLE'=>'Links','CONTENT'=>$se));
+ − 593
$this->sidebar_extra = $parser->run();
+ − 594
}
+ − 595
+ − 596
$this->sidebar_extra = $this->sidebar_extra.$this->sidebar_widgets;
+ − 597
+ − 598
$this->tpl_bool['fixed_menus'] = false;
+ − 599
/* if($this->sidebar_extra == '') $this->tpl_bool['right_sidebar'] = false;
+ − 600
else */ $this->tpl_bool['right_sidebar'] = true;
+ − 601
+ − 602
$this->tpl_bool['auth_rename'] = ( $paths->page_exists && ( $session->get_permissions('rename') && ( $paths->page_protected && $session->get_permissions('even_when_protected') || !$paths->page_protected ) ) && $paths->namespace != 'Special' && $paths->namespace != 'Admin');
+ − 603
+ − 604
$this->tpl_bool['enable_uploads'] = ( getConfig('enable_uploads') == '1' && $session->get_permissions('upload_files') ) ? true : false;
+ − 605
+ − 606
$this->tpl_bool['stupid_mode'] = false;
+ − 607
+ − 608
if($paths->page == $paths->nslist['Special'].'Administration') $this->tpl_bool['in_admin'] = true;
+ − 609
else $this->tpl_bool['in_admin'] = false;
+ − 610
+ − 611
$p = ( isset($_GET['printable']) ) ? '/printable' : '';
+ − 612
+ − 613
// Add the e-mail address client code to the header
+ − 614
$this->add_header($email->jscode());
+ − 615
+ − 616
// Generate the code for the Log out and Change theme sidebar buttons
+ − 617
// Once again, the new template parsing system can be used here
+ − 618
+ − 619
$parser = $this->makeParserText($tplvars['sidebar_button']);
+ − 620
+ − 621
$parser->assign_vars(Array(
+ − 622
'HREF'=>makeUrlNS('Special', 'Logout'),
+ − 623
'FLAGS'=>'onclick="mb_logout(); return false;"',
+ − 624
'TEXT'=>'Log out',
+ − 625
));
+ − 626
+ − 627
$logout_link = $parser->run();
+ − 628
+ − 629
$parser->assign_vars(Array(
+ − 630
'HREF'=>makeUrlNS('Special', 'Login/' . $paths->page),
+ − 631
'FLAGS'=>'onclick="ajaxStartLogin(); return false;"',
+ − 632
'TEXT'=>'Log in',
+ − 633
));
+ − 634
+ − 635
$login_link = $parser->run();
+ − 636
+ − 637
$parser->assign_vars(Array(
+ − 638
'HREF'=>makeUrlNS('Special', 'ChangeStyle/'.$paths->page),
+ − 639
'FLAGS'=>'onclick="ajaxChangeStyle(); return false;"',
+ − 640
'TEXT'=>'Change theme',
+ − 641
));
+ − 642
+ − 643
$theme_link = $parser->run();
+ − 644
+ − 645
$SID = ($session->sid_super) ? $session->sid_super : '';
+ − 646
15
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 647
$urlname_clean = str_replace('\'', '\\\'', str_replace('\\', '\\\\', dirtify_page_id($paths->fullpage)));
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 648
$urlname_clean = strtr( $urlname_clean, array( '<' => '<', '>' => '>' ) );
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 649
22
+ − 650
$urlname_jssafe = sanitize_page_id($paths->fullpage);
+ − 651
1
+ − 652
// Generate the dynamic javascript vars
+ − 653
$js_dynamic = ' <script type="text/javascript">// <![CDATA[
+ − 654
// This section defines some basic and very important variables that are used later in the static Javascript library.
+ − 655
// SKIN DEVELOPERS: The template variable for this code block is {JS_DYNAMIC_VARS}. This MUST be inserted BEFORE the tag that links to the main Javascript lib.
22
+ − 656
var title=\''. $urlname_jssafe .'\';
1
+ − 657
var page_exists='. ( ( $paths->page_exists) ? 'true' : 'false' ) .';
+ − 658
var scriptPath=\''. scriptPath .'\';
+ − 659
var contentPath=\''.contentPath.'\';
+ − 660
var ENANO_SID =\'' . $SID . '\';
+ − 661
var auth_level=' . $session->auth_level . ';
+ − 662
var USER_LEVEL_GUEST = ' . USER_LEVEL_GUEST . ';
+ − 663
var USER_LEVEL_MEMBER = ' . USER_LEVEL_MEMBER . ';
+ − 664
var USER_LEVEL_CHPREF = ' . USER_LEVEL_CHPREF . ';
+ − 665
var USER_LEVEL_MOD = ' . USER_LEVEL_MOD . ';
+ − 666
var USER_LEVEL_ADMIN = ' . USER_LEVEL_ADMIN . ';
+ − 667
var editNotice = \'' . ( (getConfig('wiki_edit_notice')=='1') ? str_replace("\n", "\\\n", RenderMan::render(getConfig('wiki_edit_notice_text'))) : '' ) . '\';
+ − 668
var prot = ' . ( ($paths->page_protected && !$session->get_permissions('even_when_protected')) ? 'true' : 'false' ) .'; // No, hacking this var won\'t work, it\'s re-checked on the server
+ − 669
var ENANO_SPECIAL_CREATEPAGE = \''. makeUrl($paths->nslist['Special'].'CreatePage') .'\';
15
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 670
var ENANO_CREATEPAGE_PARAMS = \'_do=&pagename='. $urlname_clean .'&namespace=' . $paths->namespace . '\';
1
+ − 671
var ENANO_SPECIAL_CHANGESTYLE = \''. makeUrlNS('Special', 'ChangeStyle') .'\';
+ − 672
var namespace_list = new Array();
+ − 673
var AES_BITS = '.AES_BITS.';
+ − 674
var AES_BLOCKSIZE = '.AES_BLOCKSIZE.';
+ − 675
var pagepass = \''. ( ( isset($_REQUEST['pagepass']) ) ? sha1($_REQUEST['pagepass']) : '' ) .'\';
+ − 676
var ENANO_THEME_LIST = \'';
+ − 677
foreach($this->theme_list as $t) {
+ − 678
if($t['enabled'])
+ − 679
{
+ − 680
$js_dynamic .= '<option value="'.$t['theme_id'].'"';
29
e5484a9e0818
Rewrote change theme dialog; a few minor stability fixes here and there; fixed IE + St Patty background image
Dan
diff
changeset
+ − 681
// if($t['theme_id'] == $session->theme) $js_dynamic .= ' selected="selected"';
1
+ − 682
$js_dynamic .= '>'.$t['theme_name'].'</option>';
+ − 683
}
+ − 684
}
+ − 685
$js_dynamic .= '\';
+ − 686
var ENANO_CURRENT_THEME = \''. $session->theme .'\';';
+ − 687
foreach($paths->nslist as $k => $c)
+ − 688
{
+ − 689
$js_dynamic .= "namespace_list['{$k}'] = '$c';";
+ − 690
}
+ − 691
$js_dynamic .= "\n //]]>\n </script>";
15
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 692
1
+ − 693
$tpl_strings = Array(
15
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 694
'PAGE_NAME'=>htmlspecialchars($paths->cpage['name']),
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 695
'PAGE_URLNAME'=> $urlname_clean,
1
+ − 696
'SITE_NAME'=>getConfig('site_name'),
+ − 697
'USERNAME'=>$session->username,
+ − 698
'SITE_DESC'=>getConfig('site_desc'),
+ − 699
'TOOLBAR'=>$tb,
+ − 700
'SCRIPTPATH'=>scriptPath,
+ − 701
'CONTENTPATH'=>contentPath,
+ − 702
'ADMIN_SID_QUES'=>$asq,
+ − 703
'ADMIN_SID_AMP'=>$asa,
+ − 704
'ADMIN_SID_AMP_HTML'=>$ash,
+ − 705
'ADMIN_SID_AUTO'=>$as2,
+ − 706
'ADDITIONAL_HEADERS'=>$this->additional_headers,
+ − 707
'COPYRIGHT'=>getConfig('copyright_notice'),
+ − 708
'TOOLBAR_EXTRAS'=>$this->toolbar_menu,
+ − 709
'REQUEST_URI'=>$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'],
+ − 710
'STYLE_LINK'=>makeUrlNS('Special', 'CSS'.$p, null, true), //contentPath.$paths->nslist['Special'].'CSS' . $p,
+ − 711
'LOGIN_LINK'=>$login_link,
+ − 712
'LOGOUT_LINK'=>$logout_link,
+ − 713
'THEME_LINK'=>$theme_link,
+ − 714
'TEMPLATE_DIR'=>scriptPath.'/themes/'.$this->theme,
+ − 715
'THEME_ID'=>$this->theme,
+ − 716
'STYLE_ID'=>$this->style,
+ − 717
'JS_DYNAMIC_VARS'=>$js_dynamic,
+ − 718
'UNREAD_PMS'=>$session->unread_pms
+ − 719
);
+ − 720
+ − 721
foreach ( $paths->nslist as $ns_id => $ns_prefix )
+ − 722
{
+ − 723
$tpl_strings[ 'NS_' . strtoupper($ns_id) ] = $ns_prefix;
+ − 724
}
+ − 725
+ − 726
$this->tpl_strings = array_merge($tpl_strings, $this->tpl_strings);
+ − 727
list($this->tpl_strings['SIDEBAR_LEFT'], $this->tpl_strings['SIDEBAR_RIGHT'], $min) = $this->fetch_sidebar();
+ − 728
$this->tpl_bool['sidebar_left'] = ( $this->tpl_strings['SIDEBAR_LEFT'] != $min) ? true : false;
+ − 729
$this->tpl_bool['sidebar_right'] = ( $this->tpl_strings['SIDEBAR_RIGHT'] != $min) ? true : false;
+ − 730
$this->tpl_bool['right_sidebar'] = $this->tpl_bool['sidebar_right']; // backward compatibility
+ − 731
}
+ − 732
+ − 733
function header($simple = false)
+ − 734
{
+ − 735
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 736
ob_start();
+ − 737
+ − 738
if(!$this->theme_loaded)
+ − 739
{
+ − 740
$this->load_theme($session->theme, $session->style);
+ − 741
}
+ − 742
+ − 743
$headers_sent = true;
+ − 744
dc_here('template: generating and sending the page header');
+ − 745
if(!defined('ENANO_HEADERS_SENT'))
+ − 746
define('ENANO_HEADERS_SENT', '');
+ − 747
if(!$this->no_headers) echo ( $simple ) ? $this->process_template('simple-header.tpl') : $this->process_template('header.tpl');
+ − 748
if ( !$simple && $session->user_logged_in && $session->unread_pms > 0 )
+ − 749
{
+ − 750
echo $this->notify_unread_pms();
+ − 751
}
+ − 752
if ( !$simple && $session->sw_timed_out )
+ − 753
{
+ − 754
$login_link = makeUrlNS('Special', 'Login/' . $paths->fullpage, 'level=' . $session->user_level, true);
+ − 755
echo '<div class="usermessage">';
+ − 756
echo '<b>Your administrative session has timed out.</b> <a href="' . $login_link . '">Log in again</a>';
+ − 757
echo '</div>';
+ − 758
}
+ − 759
}
+ − 760
function footer($simple = false)
+ − 761
{
+ − 762
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 763
dc_here('template: generating and sending the page footer');
+ − 764
if(!$this->no_headers) {
+ − 765
+ − 766
if(!defined('ENANO_HEADERS_SENT'))
+ − 767
$this->header();
+ − 768
+ − 769
global $_starttime;
+ − 770
if(isset($_GET['sqldbg']) && $session->get_permissions('mod_misc'))
+ − 771
{
+ − 772
echo '<h3>Query list as requested on URI</h3><pre style="margin-left: 1em">';
+ − 773
echo $db->sql_backtrace();
+ − 774
echo '</pre>';
+ − 775
}
+ − 776
+ − 777
$f = microtime_float();
+ − 778
$f = $f - $_starttime;
+ − 779
$f = round($f, 4);
+ − 780
$dbg = 'Time: '.$f.'s | Queries: '.$db->num_queries;
+ − 781
$t = ( $simple ) ? $this->process_template('simple-footer.tpl') : $this->process_template('footer.tpl');
+ − 782
$t = str_replace('[[Stats]]', $dbg, $t);
+ − 783
$t = str_replace('[[NumQueries]]', (string)$db->num_queries, $t);
+ − 784
$t = str_replace('[[GenTime]]', (string)$f, $t);
+ − 785
echo $t;
+ − 786
+ − 787
ob_end_flush();
+ − 788
}
+ − 789
else return '';
+ − 790
}
+ − 791
function getHeader()
+ − 792
{
+ − 793
$headers_sent = true;
+ − 794
dc_here('template: generating and sending the page header');
+ − 795
if(!defined('ENANO_HEADERS_SENT'))
+ − 796
define('ENANO_HEADERS_SENT', '');
+ − 797
if(!$this->no_headers) return $this->process_template('header.tpl');
+ − 798
}
+ − 799
function getFooter()
+ − 800
{
+ − 801
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 802
dc_here('template: generating and sending the page footer');
+ − 803
if(!$this->no_headers) {
+ − 804
global $_starttime;
+ − 805
$t = '';
+ − 806
+ − 807
if(isset($_GET['sqldbg']) && $session->get_permissions('mod_misc'))
+ − 808
{
+ − 809
$t .= '<h3>Query list as requested on URI</h3><pre style="margin-left: 1em">';
+ − 810
$t .= $db->sql_backtrace();
+ − 811
$t .= '</pre>';
+ − 812
}
+ − 813
+ − 814
$f = microtime_float();
+ − 815
$f = $f - $_starttime;
+ − 816
$f = round($f, 4);
+ − 817
$dbg = 'Time: '.$f.'s | Queries: '.$db->num_queries;
+ − 818
$t.= $this->process_template('footer.tpl');
+ − 819
$t = str_replace('[[Stats]]', $dbg, $t);
+ − 820
$t = str_replace('[[NumQueries]]', (string)$db->num_queries, $t);
+ − 821
$t = str_replace('[[GenTime]]', (string)$f, $t);
+ − 822
return $t;
+ − 823
}
+ − 824
else return '';
+ − 825
}
+ − 826
+ − 827
function process_template($file) {
+ − 828
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 829
if(!defined('ENANO_TEMPLATE_LOADED'))
+ − 830
{
+ − 831
$this->load_theme();
+ − 832
$this->init_vars();
+ − 833
}
+ − 834
eval($this->compile_template($file));
+ − 835
return $tpl_code;
+ − 836
}
+ − 837
+ − 838
function extract_vars($file) {
+ − 839
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 840
if(!$this->theme)
+ − 841
{
+ − 842
die('$template->extract_vars(): theme not yet loaded, so we can\'t open template files yet...this is a bug and should be reported.<br /><br />Backtrace, most recent call first:<pre>'.enano_debug_print_backtrace(true).'</pre>');
+ − 843
}
+ − 844
if(!is_file(ENANO_ROOT . '/themes/'.$this->theme.'/'.$file)) die('Cannot find '.$file.' file for style "'.$this->theme.'", exiting');
+ − 845
$text = file_get_contents(ENANO_ROOT . '/themes/'.$this->theme.'/'.$file);
+ − 846
preg_match_all('#<\!-- VAR ([A-z0-9_-]*) -->(.*?)<\!-- ENDVAR \\1 -->#is', $text, $matches);
+ − 847
$tplvars = Array();
+ − 848
for($i=0;$i<sizeof($matches[1]);$i++)
+ − 849
{
+ − 850
$tplvars[$matches[1][$i]] = $matches[2][$i];
+ − 851
}
+ − 852
return $tplvars;
+ − 853
}
+ − 854
function compile_template($text) {
+ − 855
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 856
if(!is_file(ENANO_ROOT . '/themes/'.$this->theme.'/'.$text)) die('Cannot find '.$text.' file for style, exiting');
+ − 857
$n = $text;
+ − 858
$tpl_filename = ENANO_ROOT . '/cache/' . $this->theme . '-' . str_replace('/', '-', $n) . '.php';
+ − 859
if(!is_file(ENANO_ROOT . '/themes/'.$this->theme.'/'.$text)) die('Cannot find '.$text.' file for style, exiting');
+ − 860
if(file_exists($tpl_filename) && getConfig('cache_thumbs')=='1')
+ − 861
{
+ − 862
include($tpl_filename);
+ − 863
$text = file_get_contents(ENANO_ROOT . '/themes/'.$this->theme.'/'.$text);
+ − 864
if(isset($md5) && $md5 == md5($text)) {
+ − 865
return str_replace('\\"', '"', $tpl_text);
+ − 866
}
+ − 867
}
+ − 868
$text = file_get_contents(ENANO_ROOT . '/themes/'.$this->theme.'/'.$n);
+ − 869
+ − 870
$md5 = md5($text);
+ − 871
+ − 872
$seed = md5 ( microtime() . mt_rand() );
+ − 873
preg_match_all("/<\?php(.*?)\?>/is", $text, $m);
+ − 874
//die('<pre>'.htmlspecialchars(print_r($m, true)).'</pre>');
+ − 875
for($i = 0; $i < sizeof($m[1]); $i++)
+ − 876
{
+ − 877
$text = str_replace("<?php{$m[1][$i]}?>", "{PHPCODE:{$i}:{$seed}}", $text);
+ − 878
}
+ − 879
//die('<pre>'.htmlspecialchars($text).'</pre>');
+ − 880
$text = 'ob_start(); echo \''.str_replace('\'', '\\\'', $text).'\'; $tpl_code = ob_get_contents(); ob_end_clean();';
+ − 881
$text = preg_replace('#<!-- BEGIN (.*?) -->#is', '\'; if(isset($this->tpl_bool[\'\\1\']) && $this->tpl_bool[\'\\1\']) { echo \'', $text);
+ − 882
$text = preg_replace('#<!-- IFSET (.*?) -->#is', '\'; if(isset($this->tpl_strings[\'\\1\'])) { echo \'', $text);
+ − 883
$text = preg_replace('#<!-- IFPLUGIN (.*?) -->#is', '\'; if(getConfig(\'plugin_\\1\')==\'1\') { echo \'', $text);
+ − 884
$text = preg_replace('#<!-- SYSMSG (.*?) -->#is', '\'; echo $template->tplWikiFormat($paths->sysMsg(\'\\1\')); echo \'', $text);
+ − 885
$text = preg_replace('#<!-- BEGINNOT (.*?) -->#is', '\'; if(!$this->tpl_bool[\'\\1\']) { echo \'', $text);
+ − 886
$text = preg_replace('#<!-- BEGINELSE (.*?) -->#is', '\'; } else { echo \'', $text);
+ − 887
$text = preg_replace('#<!-- END (.*?) -->#is', '\'; } echo \'', $text);
+ − 888
$text = preg_replace('#\{([A-z0-9]*)\}#is', '\'.$this->tpl_strings[\'\\1\'].\'', $text);
+ − 889
for($i = 0; $i < sizeof($m[1]); $i++)
+ − 890
{
+ − 891
$text = str_replace("{PHPCODE:{$i}:{$seed}}", "'; {$m[1][$i]} echo '", $text);
+ − 892
}
+ − 893
if(is_writable(ENANO_ROOT.'/cache/') && getConfig('cache_thumbs')=='1')
+ − 894
{
+ − 895
//die($tpl_filename);
+ − 896
$h = fopen($tpl_filename, 'w');
+ − 897
if(!$h) return $text;
+ − 898
$t = addslashes($text);
+ − 899
fwrite($h, '<?php $md5 = \''.$md5.'\'; $tpl_text = \''.$t.'\'; ?>');
+ − 900
fclose($h);
+ − 901
}
+ − 902
return $text; //('<pre>'.htmlspecialchars($text).'</pre>');
+ − 903
}
+ − 904
+ − 905
function compile_template_text($text) {
+ − 906
$seed = md5 ( microtime() . mt_rand() );
+ − 907
preg_match_all("/<\?php(.*?)\?>/is", $text, $m);
+ − 908
//die('<pre>'.htmlspecialchars(print_r($m, true)).'</pre>');
+ − 909
for($i = 0; $i < sizeof($m[1]); $i++)
+ − 910
{
+ − 911
$text = str_replace("<?php{$m[1][$i]}?>", "{PHPCODE:{$i}:{$seed}}", $text);
+ − 912
}
+ − 913
//die('<pre>'.htmlspecialchars($text).'</pre>');
+ − 914
$text = 'ob_start(); echo \''.str_replace('\'', '\\\'', $text).'\'; $tpl_code = ob_get_contents(); ob_end_clean(); return $tpl_code;';
+ − 915
$text = preg_replace('#<!-- BEGIN (.*?) -->#is', '\'; if(isset($this->tpl_bool[\'\\1\']) && $this->tpl_bool[\'\\1\']) { echo \'', $text);
+ − 916
$text = preg_replace('#<!-- IFSET (.*?) -->#is', '\'; if(isset($this->tpl_strings[\'\\1\'])) { echo \'', $text);
+ − 917
$text = preg_replace('#<!-- IFPLUGIN (.*?) -->#is', '\'; if(getConfig(\'plugin_\\1\')==\'1\') { echo \'', $text);
+ − 918
$text = preg_replace('#<!-- SYSMSG (.*?) -->#is', '\'; echo $template->tplWikiFormat($paths->sysMsg(\'\\1\')); echo \'', $text);
+ − 919
$text = preg_replace('#<!-- BEGINNOT (.*?) -->#is', '\'; if(!$this->tpl_bool[\'\\1\']) { echo \'', $text);
+ − 920
$text = preg_replace('#<!-- BEGINELSE (.*?) -->#is', '\'; } else { echo \'', $text);
+ − 921
$text = preg_replace('#<!-- END (.*?) -->#is', '\'; } echo \'', $text);
+ − 922
$text = preg_replace('#\{([A-z0-9]*)\}#is', '\'.$this->tpl_strings[\'\\1\'].\'', $text);
+ − 923
for($i = 0; $i < sizeof($m[1]); $i++)
+ − 924
{
+ − 925
$text = str_replace("{PHPCODE:{$i}:{$seed}}", "'; {$m[1][$i]} echo '", $text);
+ − 926
}
+ − 927
return $text; //('<pre>'.htmlspecialchars($text).'</pre>');
+ − 928
}
+ − 929
+ − 930
function parse($text)
+ − 931
{
+ − 932
$text = $this->compile_template_text($text);
+ − 933
return eval($text);
+ − 934
}
+ − 935
+ − 936
// Steps to turn this:
+ − 937
// [[Project:Community Portal]]
+ − 938
// into this:
+ − 939
// <a href="/Project:Community_Portal">Community Portal</a>
+ − 940
// Must be done WITHOUT creating eval'ed code!!!
+ − 941
+ − 942
// 1. preg_replace \[\[([a-zA-Z0-9 -_:]*?)\]\] with <a href="'.contentPath.'\\1">\\1</a>
+ − 943
// 2. preg_match_all <a href="'.preg_quote(contentPath).'([a-zA-Z0-9 -_:]*?)">
+ − 944
// 3. For each match, replace matches with identifiers
+ − 945
// 4. For each match, str_replace ' ' with '_'
+ − 946
// 5. For each match, str_replace match_id:random_val with $matches[$match_id]
+ − 947
+ − 948
// The template language is really a miniature programming language; with variables, conditionals, everything!
+ − 949
// So you can implement custom logic into your sidebar if you wish.
+ − 950
// "Real" PHP support coming soon :-D
+ − 951
+ − 952
function tplWikiFormat($message, $filter_links = false, $filename = 'elements.tpl') {
+ − 953
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 954
$filter_links = false;
+ − 955
$tplvars = $this->extract_vars($filename);
+ − 956
if($session->sid_super) $as = htmlspecialchars(urlSeparator).'auth='.$session->sid_super;
+ − 957
else $as = '';
+ − 958
error_reporting(E_ALL);
+ − 959
$random_id = sha1(microtime().''); // A temp value
+ − 960
+ − 961
/*
+ − 962
* PREPROCESSOR
+ − 963
*/
+ − 964
+ − 965
// Variables
+ − 966
+ − 967
preg_match_all('#\$([A-Z_-]+)\$#', $message, $links);
+ − 968
$links = $links[1];
+ − 969
+ − 970
for($i=0;$i<sizeof($links);$i++)
+ − 971
{
+ − 972
$message = str_replace('$'.$links[$i].'$', $this->tpl_strings[$links[$i]], $message);
+ − 973
}
+ − 974
+ − 975
// Conditionals
+ − 976
+ − 977
preg_match_all('#\{if ([A-Za-z0-9_ &\|\!-]*)\}(.*?)\{\/if\}#is', $message, $links);
+ − 978
+ − 979
for($i=0;$i<sizeof($links[1]);$i++)
+ − 980
{
+ − 981
$message = str_replace('{if '.$links[1][$i].'}'.$links[2][$i].'{/if}', '{CONDITIONAL:'.$i.':'.$random_id.'}', $message);
+ − 982
+ − 983
// Time for some manual parsing...
+ − 984
$chk = false;
+ − 985
$current_id = '';
+ − 986
$prn_level = 0;
+ − 987
// Used to keep track of where we are in the conditional
+ − 988
// Object of the game: turn {if this && ( that OR !something_else )} ... {/if} into if( ( isset($this->tpl_bool['that']) && $this->tpl_bool['that'] ) && ...
+ − 989
// Method of attack: escape all variables, ignore all else. Non-valid code is filtered out by a regex above.
+ − 990
$in_var_now = true;
+ − 991
$in_var_last = false;
+ − 992
$current_var = '';
+ − 993
$current_var_start_pos = 0;
+ − 994
$current_var_end_pos = 0;
+ − 995
$j = -1;
+ − 996
$links[1][$i] = $links[1][$i] . ' ';
+ − 997
$d = strlen($links[1][$i]);
+ − 998
while($j < $d)
+ − 999
{
+ − 1000
$j++;
+ − 1001
$in_var_last = $in_var_now;
+ − 1002
+ − 1003
$char = substr($links[1][$i], $j, 1);
+ − 1004
$in_var_now = ( preg_match('#^([A-z0-9_]*){1}$#', $char) ) ? true : false;
+ − 1005
if(!$in_var_last && $in_var_now)
+ − 1006
{
+ − 1007
$current_var_start_pos = $j;
+ − 1008
}
+ − 1009
if($in_var_last && !$in_var_now)
+ − 1010
{
+ − 1011
$current_var_end_pos = $j;
+ − 1012
}
+ − 1013
if($in_var_now)
+ − 1014
{
+ − 1015
$current_var .= $char;
+ − 1016
continue;
+ − 1017
}
+ − 1018
// OK we are not inside of a variable. That means that we JUST hit the end because the counter ($j) will be advanced to the beginning of the next variable once processing here is complete.
+ − 1019
if($char != ' ' && $char != '(' && $char != ')' && $char != 'A' && $char != 'N' && $char != 'D' && $char != 'O' && $char != 'R' && $char != '&' && $char != '|' && $char != '!' && $char != '<' && $char != '>' && $char != '0' && $char != '1' && $char != '2' && $char != '3' && $char != '4' && $char != '5' && $char != '6' && $char != '7' && $char != '8' && $char != '9')
+ − 1020
{
+ − 1021
// XSS attack! Bail out
+ − 1022
echo '<p><b>Error:</b> Syntax error (possibly XSS attack) caught in template code:</p>';
+ − 1023
echo '<pre>';
+ − 1024
echo '{if '.$links[1][$i].'}';
+ − 1025
echo "\n ";
+ − 1026
for($k=0;$k<$j;$k++) echo " ";
+ − 1027
echo '<span style="color: red;">^</span>';
+ − 1028
echo '</pre>';
+ − 1029
continue 2;
+ − 1030
}
+ − 1031
if($current_var != '')
+ − 1032
{
+ − 1033
$cd = '( isset($this->tpl_bool[\''.$current_var.'\']) && $this->tpl_bool[\''.$current_var.'\'] )';
+ − 1034
$cvt = substr($links[1][$i], 0, $current_var_start_pos) . $cd . substr($links[1][$i], $current_var_end_pos, strlen($links[1][$i]));
+ − 1035
$j = $j + strlen($cd) - strlen($current_var);
+ − 1036
$current_var = '';
+ − 1037
$links[1][$i] = $cvt;
+ − 1038
$d = strlen($links[1][$i]);
+ − 1039
}
+ − 1040
}
+ − 1041
$links[1][$i] = substr($links[1][$i], 0, strlen($links[1][$i])-1);
+ − 1042
$links[1][$i] = '$chk = ( '.$links[1][$i].' ) ? true : false;';
+ − 1043
eval($links[1][$i]);
+ − 1044
+ − 1045
if($chk) { // isset($this->tpl_bool[$links[1][$i]]) && $this->tpl_bool[$links[1][$i]]
+ − 1046
if(strstr($links[2][$i], '{else}')) $c = substr($links[2][$i], 0, strpos($links[2][$i], '{else}'));
+ − 1047
else $c = $links[2][$i];
+ − 1048
$message = str_replace('{CONDITIONAL:'.$i.':'.$random_id.'}', $c, $message);
+ − 1049
} else {
+ − 1050
if(strstr($links[2][$i], '{else}')) $c = substr($links[2][$i], strpos($links[2][$i], '{else}')+6, strlen($links[2][$i]));
+ − 1051
else $c = '';
+ − 1052
$message = str_replace('{CONDITIONAL:'.$i.':'.$random_id.'}', $c, $message);
+ − 1053
}
+ − 1054
}
+ − 1055
+ − 1056
preg_match_all('#\{!if ([A-Za-z_-]*)\}(.*?)\{\/if\}#is', $message, $links);
+ − 1057
+ − 1058
for($i=0;$i<sizeof($links[1]);$i++)
+ − 1059
{
+ − 1060
$message = str_replace('{!if '.$links[1][$i].'}'.$links[2][$i].'{/if}', '{CONDITIONAL:'.$i.':'.$random_id.'}', $message);
+ − 1061
if(isset($this->tpl_bool[$links[1][$i]]) && $this->tpl_bool[$links[1][$i]]) {
+ − 1062
if(strstr($links[2][$i], '{else}')) $c = substr($links[2][$i], strpos($links[2][$i], '{else}')+6, strlen($links[2][$i]));
+ − 1063
else $c = '';
+ − 1064
$message = str_replace('{CONDITIONAL:'.$i.':'.$random_id.'}', $c, $message);
+ − 1065
} else {
+ − 1066
if(strstr($links[2][$i], '{else}')) $c = substr($links[2][$i], 0, strpos($links[2][$i], '{else}'));
+ − 1067
else $c = $links[2][$i];
+ − 1068
$message = str_replace('{CONDITIONAL:'.$i.':'.$random_id.'}', $c, $message);
+ − 1069
}
+ − 1070
}
+ − 1071
+ − 1072
/*
+ − 1073
* HTML RENDERER
+ − 1074
*/
+ − 1075
+ − 1076
// Images
+ − 1077
$j = preg_match_all('#\[\[:'.$paths->nslist['File'].'([\w\s0-9_\(\)!@%\^\+\|\.-]+?)\]\]#is', $message, $matchlist);
+ − 1078
$matches = Array();
+ − 1079
$matches['images'] = $matchlist[1];
+ − 1080
for($i=0;$i<sizeof($matchlist[1]);$i++)
+ − 1081
{
+ − 1082
if(isPage($paths->nslist['File'].$matches['images'][$i]))
+ − 1083
{
+ − 1084
$message = str_replace('[[:'.$paths->nslist['File'].$matches['images'][$i].']]',
+ − 1085
'<img alt="'.$matches['images'][$i].'" style="border: 0" src="'.makeUrlNS('Special', 'DownloadFile/'.$matches['images'][$i]).'" />',
+ − 1086
$message);
+ − 1087
}
+ − 1088
}
+ − 1089
+ − 1090
// Internal links
+ − 1091
+ − 1092
$text_parser = $this->makeParserText($tplvars['sidebar_button']);
+ − 1093
+ − 1094
preg_match_all('#\[\[([a-zA-Z0-9 -_]*?)\]\]#is', $message, $il);
+ − 1095
for($i=0;$i<sizeof($il[1]);$i++)
+ − 1096
{
+ − 1097
$href = makeUrl(str_replace(' ', '_', $il[1][$i]), null, true);
+ − 1098
$text_parser->assign_vars(Array(
+ − 1099
'HREF' => $href,
+ − 1100
'FLAGS' => '',
+ − 1101
'TEXT' => $il[1][$i]
+ − 1102
));
+ − 1103
$message = str_replace("[[{$il[1][$i]}]]", $text_parser->run(), $message);
+ − 1104
}
+ − 1105
+ − 1106
preg_match_all('#\[\[([a-zA-Z0-9 -_]*?)\|([a-zA-Z0-9!@\#\$%\^&\*\(\)\{\} -_]*?)\]\]#is', $message, $il);
+ − 1107
for($i=0;$i<sizeof($il[1]);$i++)
+ − 1108
{
+ − 1109
$href = makeUrl(str_replace(' ', '_', $il[1][$i]), null, true);
+ − 1110
$text_parser->assign_vars(Array(
+ − 1111
'HREF' => $href,
+ − 1112
'FLAGS' => '',
+ − 1113
'TEXT' => $il[2][$i]
+ − 1114
));
+ − 1115
$message = str_replace("[[{$il[1][$i]}|{$il[2][$i]}]]", $text_parser->run(), $message);
+ − 1116
}
+ − 1117
+ − 1118
// External links
+ − 1119
$message = preg_replace('#\[(http|ftp|irc):\/\/([a-z0-9\/:_\.\?&%\#@_\\\\-]+?)\\ ([^\]]+)]#', '<a href="\\1://\\2">\\3</a><br style="display: none;" />', $message);
+ − 1120
$message = preg_replace('#\[(http|ftp|irc):\/\/([a-z0-9\/:_\.\?&%\#@_\\\\-]+?)\\]#', '<a href="\\1://\\2">\\1://\\2</a><br style="display: none;" />', $message);
+ − 1121
+ − 1122
$parser1 = $this->makeParserText($tplvars['sidebar_section']);
+ − 1123
$parser2 = $this->makeParserText($tplvars['sidebar_section_raw']);
+ − 1124
+ − 1125
preg_match_all('#\{slider(2|)=(.*?)\}(.*?)\{\/slider(2|)\}#is', $message, $sb);
+ − 1126
+ − 1127
// Modified to support the sweet new template var system
+ − 1128
for($i=0;$i<sizeof($sb[1]);$i++)
+ − 1129
{
+ − 1130
$p = ($sb[1][$i] == '2') ? $parser2 : $parser1;
+ − 1131
$p->assign_vars(Array('TITLE'=>$sb[2][$i],'CONTENT'=>$sb[3][$i]));
+ − 1132
$message = str_replace("{slider{$sb[1][$i]}={$sb[2][$i]}}{$sb[3][$i]}{/slider{$sb[4][$i]}}", $p->run(), $message);
+ − 1133
}
+ − 1134
+ − 1135
/*
+ − 1136
Extras ;-)
+ − 1137
$message = preg_replace('##is', '', $message);
+ − 1138
$message = preg_replace('##is', '', $message);
+ − 1139
$message = preg_replace('##is', '', $message);
+ − 1140
$message = preg_replace('##is', '', $message);
+ − 1141
$message = preg_replace('##is', '', $message);
+ − 1142
*/
+ − 1143
+ − 1144
//die('<pre>'.htmlspecialchars($message).'</pre>');
+ − 1145
//eval($message); exit;
+ − 1146
return $message;
+ − 1147
}
+ − 1148
+ − 1149
/**
+ − 1150
* Print a text field that auto-completes a username entered into it.
+ − 1151
* @param string $name - the name of the form field
+ − 1152
* @return string
+ − 1153
*/
+ − 1154
+ − 1155
function username_field($name, $value = false)
+ − 1156
{
+ − 1157
$randomid = md5( time() . microtime() . mt_rand() );
+ − 1158
$text = '<input name="'.$name.'" onkeyup="ajaxUserNameComplete(this)" autocomplete="off" type="text" size="30" id="userfield_'.$randomid.'"';
+ − 1159
if($value) $text .= ' value="'.$value.'"';
+ − 1160
$text .= ' />';
+ − 1161
return $text;
+ − 1162
}
+ − 1163
+ − 1164
/**
+ − 1165
* Print a text field that auto-completes a page name entered into it.
+ − 1166
* @param string $name - the name of the form field
+ − 1167
* @return string
+ − 1168
*/
+ − 1169
+ − 1170
function pagename_field($name, $value = false)
+ − 1171
{
+ − 1172
$randomid = md5( time() . microtime() . mt_rand() );
+ − 1173
$text = '<input name="'.$name.'" onkeyup="ajaxPageNameComplete(this)" type="text" size="30" id="pagefield_'.$randomid.'"';
+ − 1174
if($value) $text .= ' value="'.$value.'"';
+ − 1175
$text .= ' />';
+ − 1176
$text .= '<script type="text/javascript">
+ − 1177
var inp = document.getElementById(\'pagefield_' . $randomid . '\');
+ − 1178
var f = get_parent_form(inp);
+ − 1179
if ( f )
+ − 1180
{
+ − 1181
if ( typeof(f.onsubmit) != \'function\' )
+ − 1182
{
+ − 1183
f.onsubmit = function() {
+ − 1184
if ( !submitAuthorized )
+ − 1185
{
+ − 1186
return false;
+ − 1187
}
+ − 1188
}
+ − 1189
}
+ − 1190
}</script>';
+ − 1191
return $text;
+ − 1192
}
+ − 1193
+ − 1194
/**
+ − 1195
* Sends a textarea that can be converted to and from a TinyMCE widget on the fly.
+ − 1196
* @param string The name of the form element
+ − 1197
* @param string The initial content. Optional, defaults to blank
+ − 1198
* @param int Rows in textarea
+ − 1199
* @param int Columns in textarea
+ − 1200
* @return string HTML and Javascript code.
+ − 1201
*/
+ − 1202
+ − 1203
function tinymce_textarea($name, $content = '', $rows = 20, $cols = 60)
+ − 1204
{
+ − 1205
$randomid = md5(microtime() . mt_rand());
+ − 1206
$html = '';
+ − 1207
$html .= '<textarea name="' . $name . '" rows="'.$rows.'" cols="'.$cols.'" style="width: 100%;" id="toggleMCEroot_'.$randomid.'">' . $content . '</textarea>';
+ − 1208
$html .= '<div style="float: right; display: table;" id="mceSwitchAgent_' . $randomid . '">text editor | <a href="#" onclick="toggleMCE_'.$randomid.'(); return false;">graphical editor</a></div>';
+ − 1209
$html .= '<script type="text/javascript">
+ − 1210
// <![CDATA[
+ − 1211
function toggleMCE_'.$randomid.'()
+ − 1212
{
+ − 1213
var the_obj = document.getElementById(\'toggleMCEroot_' . $randomid . '\');
+ − 1214
var panel = document.getElementById(\'mceSwitchAgent_' . $randomid . '\');
+ − 1215
if ( the_obj.dnIsMCE == "yes" )
+ − 1216
{
+ − 1217
$dynano(the_obj).destroyMCE();
+ − 1218
panel.innerHTML = \'text editor | <a href="#" onclick="toggleMCE_'.$randomid.'(); return false;">graphical editor</a>\';
+ − 1219
}
+ − 1220
else
+ − 1221
{
+ − 1222
$dynano(the_obj).switchToMCE();
+ − 1223
panel.innerHTML = \'<a href="#" onclick="toggleMCE_'.$randomid.'(); return false;">text editor</a> | graphical editor\';
+ − 1224
}
+ − 1225
}
+ − 1226
// ]]>
+ − 1227
</script>';
+ − 1228
return $html;
+ − 1229
}
+ − 1230
+ − 1231
/**
+ − 1232
* Allows individual parsing of template files. Similar to phpBB but follows the spirit of object-oriented programming ;)
+ − 1233
* Returns on object of class templateIndividual. Usage instructions can be found in the inline docs for that class.
+ − 1234
* @param $filename the filename of the template to be parsed
+ − 1235
* @return object
+ − 1236
*/
+ − 1237
+ − 1238
function makeParser($filename)
+ − 1239
{
+ − 1240
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 1241
$filename = ENANO_ROOT.'/themes/'.$template->theme.'/'.$filename;
+ − 1242
if(!file_exists($filename)) die('templateIndividual: file '.$filename.' does not exist');
+ − 1243
$code = file_get_contents($filename);
+ − 1244
$parser = new templateIndividual($code);
+ − 1245
return $parser;
+ − 1246
}
+ − 1247
+ − 1248
/**
+ − 1249
* Same as $template->makeParser(), but takes a string instead of a filename.
+ − 1250
* @param $text the text to parse
+ − 1251
* @return object
+ − 1252
*/
+ − 1253
+ − 1254
function makeParserText($code)
+ − 1255
{
+ − 1256
$parser = new templateIndividual($code);
+ − 1257
return $parser;
+ − 1258
}
+ − 1259
+ − 1260
/**
+ − 1261
* Fetch the HTML for a plugin-added sidebar block
+ − 1262
* @param $name the plugin name
+ − 1263
* @return string
+ − 1264
*/
+ − 1265
+ − 1266
function fetch_block($id)
+ − 1267
{
+ − 1268
if(isset($this->plugin_blocks[$id])) return $this->plugin_blocks[$id];
+ − 1269
else return false;
+ − 1270
}
+ − 1271
+ − 1272
/**
+ − 1273
* Fetches the contents of both sidebars.
+ − 1274
* @return array - key 0 is left, key 1 is right
+ − 1275
* @example list($left, $right) = $template->fetch_sidebar();
+ − 1276
*/
+ − 1277
+ − 1278
function fetch_sidebar()
+ − 1279
{
+ − 1280
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 1281
+ − 1282
$left = '';
+ − 1283
$right = '';
+ − 1284
+ − 1285
if ( !$this->fetch_block('Links') )
+ − 1286
$this->initLinksWidget();
+ − 1287
+ − 1288
$q = $db->sql_query('SELECT item_id,sidebar_id,block_name,block_type,block_content FROM '.table_prefix.'sidebar WHERE item_enabled=1 ORDER BY sidebar_id ASC, item_order ASC;');
+ − 1289
if(!$q) $db->_die('The sidebar text data could not be selected.');
+ − 1290
+ − 1291
$vars = $this->extract_vars('elements.tpl');
+ − 1292
+ − 1293
if(isset($vars['sidebar_top']))
+ − 1294
{
+ − 1295
$left .= $this->parse($vars['sidebar_top']);
+ − 1296
$right .= $this->parse($vars['sidebar_top']);
+ − 1297
}
+ − 1298
while($row = $db->fetchrow())
+ − 1299
{
+ − 1300
switch($row['block_type'])
+ − 1301
{
+ − 1302
case BLOCK_WIKIFORMAT:
+ − 1303
default:
+ − 1304
$parser = $this->makeParserText($vars['sidebar_section']);
+ − 1305
$c = RenderMan::render($row['block_content']);
+ − 1306
break;
+ − 1307
case BLOCK_TEMPLATEFORMAT:
+ − 1308
$parser = $this->makeParserText($vars['sidebar_section']);
+ − 1309
$c = $this->tplWikiFormat($row['block_content']);
+ − 1310
break;
+ − 1311
case BLOCK_HTML:
+ − 1312
$parser = $this->makeParserText($vars['sidebar_section_raw']);
+ − 1313
$c = $row['block_content'];
+ − 1314
break;
+ − 1315
case BLOCK_PHP:
+ − 1316
$parser = $this->makeParserText($vars['sidebar_section_raw']);
+ − 1317
ob_start();
+ − 1318
@eval($row['block_content']);
+ − 1319
$c = ob_get_contents();
+ − 1320
ob_end_clean();
+ − 1321
break;
+ − 1322
case BLOCK_PLUGIN:
+ − 1323
$parser = $this->makeParserText($vars['sidebar_section_raw']);
+ − 1324
$c = (gettype($this->fetch_block($row['block_content'])) == 'string') ? $this->fetch_block($row['block_content']) : 'Can\'t find plugin block';
+ − 1325
break;
+ − 1326
}
+ − 1327
$parser->assign_vars(Array( 'TITLE'=>$this->tplWikiFormat($row['block_name']), 'CONTENT'=>$c ));
+ − 1328
if ($row['sidebar_id'] == SIDEBAR_LEFT ) $left .= $parser->run();
+ − 1329
elseif($row['sidebar_id'] == SIDEBAR_RIGHT) $right .= $parser->run();
+ − 1330
unset($parser);
+ − 1331
}
+ − 1332
$db->free_result();
+ − 1333
if(isset($vars['sidebar_bottom']))
+ − 1334
{
+ − 1335
$left .= $this->parse($vars['sidebar_bottom']);
+ − 1336
$right .= $this->parse($vars['sidebar_bottom']);
+ − 1337
}
+ − 1338
$min = '';
+ − 1339
if(isset($vars['sidebar_top']))
+ − 1340
{
+ − 1341
$min .= $this->parse($vars['sidebar_top']);
+ − 1342
}
+ − 1343
if(isset($vars['sidebar_bottom']))
+ − 1344
{
+ − 1345
$min .= $this->parse($vars['sidebar_bottom']);
+ − 1346
}
+ − 1347
return Array($left, $right, $min);
+ − 1348
}
+ − 1349
+ − 1350
function initLinksWidget()
+ − 1351
{
+ − 1352
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 1353
// SourceForge/W3C buttons
+ − 1354
$ob = Array();
27
dd659f6ba891
Converting all tables on new installations to UTF-8; this may break MySQL 4.0 compatibility; several minor cosmetic fixes; set Powered button under Links to "on" by default
Dan
diff
changeset
+ − 1355
$admintitle = ( $session->user_level >= USER_LEVEL_ADMIN ) ? 'title="You may disable this button in the admin panel under General Configuration."' : '';
dd659f6ba891
Converting all tables on new installations to UTF-8; this may break MySQL 4.0 compatibility; several minor cosmetic fixes; set Powered button under Links to "on" by default
Dan
diff
changeset
+ − 1356
if(getConfig('powered_btn') =='1') $ob[] = '<a style="text-align: center;" href="http://www.enanocms.org/" onclick="window.open(this.href);return false;"><img '.$admintitle.' alt="Powered by Enano" src="'.scriptPath.'/images/about-powered-enano.png" onmouseover="this.src=\''.scriptPath.'/images/about-powered-enano-hover.png\';" onmouseout="this.src=\''.scriptPath.'/images/about-powered-enano.png\';" style="border-width: 0px;" width="88" height="31" /></a>';
1
+ − 1357
if(getConfig('sflogo_enabled')=='1')
+ − 1358
{
+ − 1359
$ob[] = '<a style="text-align: center;" href="http://sourceforge.net/" onclick="window.open(this.href);return false;"><img style="border-width: 0px;" alt="SourceForge.net Logo" src="http://sflogo.sourceforge.net/sflogo.php?group_id='.getConfig('sflogo_groupid').'&type='.getConfig('sflogo_type').'" /></a>';
+ − 1360
}
+ − 1361
if(getConfig('w3c_v32') =='1') $ob[] = '<a style="text-align: center;" href="http://validator.w3.org/check?uri=referer" onclick="window.open(this.href);return false;"><img style="border: 0px solid #FFFFFF;" alt="Valid HTML 3.2" src="http://www.w3.org/Icons/valid-html32" /></a>';
+ − 1362
if(getConfig('w3c_v40') =='1') $ob[] = '<a style="text-align: center;" href="http://validator.w3.org/check?uri=referer" onclick="window.open(this.href);return false;"><img style="border: 0px solid #FFFFFF;" alt="Valid HTML 4.0" src="http://www.w3.org/Icons/valid-html40" /></a>';
+ − 1363
if(getConfig('w3c_v401') =='1') $ob[] = '<a style="text-align: center;" href="http://validator.w3.org/check?uri=referer" onclick="window.open(this.href);return false;"><img style="border: 0px solid #FFFFFF;" alt="Valid HTML 4.01" src="http://www.w3.org/Icons/valid-html401" /></a>';
+ − 1364
if(getConfig('w3c_vxhtml10')=='1') $ob[] = '<a style="text-align: center;" href="http://validator.w3.org/check?uri=referer" onclick="window.open(this.href);return false;"><img style="border: 0px solid #FFFFFF;" alt="Valid XHTML 1.0" src="http://www.w3.org/Icons/valid-xhtml10" /></a>';
+ − 1365
if(getConfig('w3c_vxhtml11')=='1') $ob[] = '<a style="text-align: center;" href="http://validator.w3.org/check?uri=referer" onclick="window.open(this.href);return false;"><img style="border: 0px solid #FFFFFF;" alt="Valid XHTML 1.1" src="http://www.w3.org/Icons/valid-xhtml11" /></a>';
+ − 1366
if(getConfig('w3c_vcss') =='1') $ob[] = '<a style="text-align: center;" href="http://validator.w3.org/check?uri=referer" onclick="window.open(this.href);return false;"><img style="border: 0px solid #FFFFFF;" alt="Valid CSS" src="http://www.w3.org/Icons/valid-css" /></a>';
+ − 1367
if(getConfig('dbd_button') =='1') $ob[] = '<a style="text-align: center;" href="http://www.defectivebydesign.org/join/button" onclick="window.open(this.href);return false;"><img style="border: 0px solid #FFFFFF;" alt="DRM technology restricts what you can do with your computer" src="http://defectivebydesign.org/sites/nodrm.civicactions.net/files/images/dbd_sm_btn.gif" /><br /><small>Protect your freedom >></small></a>';
+ − 1368
+ − 1369
$code = $plugins->setHook('links_widget');
+ − 1370
foreach ( $code as $cmd )
+ − 1371
{
+ − 1372
eval($cmd);
+ − 1373
}
+ − 1374
+ − 1375
if(count($ob) > 0) $sb_links = '<div style="text-align: center; padding: 5px 0;">'.implode('<br />', $ob).'</div>';
+ − 1376
else $sb_links = '';
+ − 1377
+ − 1378
$this->sidebar_widget('Links', $sb_links);
+ − 1379
}
+ − 1380
+ − 1381
/**
+ − 1382
* Builds a box showing unread private messages.
+ − 1383
*/
+ − 1384
+ − 1385
function notify_unread_pms()
+ − 1386
{
+ − 1387
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 1388
if ( ( $paths->cpage['urlname_nons'] == 'PrivateMessages' || $paths->cpage['urlname_nons'] == 'Preferences' ) && $paths->namespace == 'Special' )
+ − 1389
{
+ − 1390
return '';
+ − 1391
}
+ − 1392
$ob = '<div class="usermessage">'."\n";
+ − 1393
$s = ( $session->unread_pms == 1 ) ? '' : 's';
+ − 1394
$ob .= " <b>You have $session->unread_pms <a href=" . '"' . makeUrlNS('Special', 'PrivateMessages' ) . '"' . ">unread private message$s</a>.</b><br />\n Messages: ";
+ − 1395
$q = $db->sql_query('SELECT message_id,message_from,subject,date FROM '.table_prefix.'privmsgs WHERE message_to=\'' . $session->username . '\' AND message_read=0 ORDER BY date DESC;');
+ − 1396
if ( !$q )
+ − 1397
$db->_die();
+ − 1398
$messages = array();
+ − 1399
while ( $row = $db->fetchrow() )
+ − 1400
{
+ − 1401
$messages[] = '<a href="' . makeUrlNS('Special', 'PrivateMessages/View/' . $row['message_id']) . '" title="Sent ' . date('F d, Y h:i a', $row['date']) . ' by ' . $row['message_from'] . '">' . $row['subject'] . '</a>';
+ − 1402
}
+ − 1403
$ob .= implode(",\n " , $messages)."\n";
+ − 1404
$ob .= '</div>'."\n";
+ − 1405
return $ob;
+ − 1406
}
+ − 1407
+ − 1408
} // class template
+ − 1409
+ − 1410
/**
+ − 1411
* Handles parsing of an individual template file. Instances should only be created through $template->makeParser(). To use:
+ − 1412
* - Call $template->makeParser(template file name) - file name should be something.tpl, css/whatever.css, etc.
+ − 1413
* - Make an array of strings you want the template to access. $array['STRING'] would be referenced in the template like {STRING}
+ − 1414
* - Make an array of boolean values. These can be used for conditionals in the template (<!-- IF something --> whatever <!-- ENDIF something -->)
+ − 1415
* - Call assign_vars() to pass the strings to the template parser. Same thing with assign_bool().
+ − 1416
* - Call run() to parse the template and get your fully compiled HTML.
+ − 1417
* @access private
+ − 1418
*/
+ − 1419
+ − 1420
class templateIndividual extends template {
+ − 1421
var $tpl_strings, $tpl_bool, $tpl_code;
+ − 1422
var $compiled = false;
+ − 1423
/**
+ − 1424
* Constructor.
+ − 1425
*/
+ − 1426
function __construct($text)
+ − 1427
{
+ − 1428
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 1429
$this->tpl_code = $text;
+ − 1430
$this->tpl_strings = $template->tpl_strings;
+ − 1431
$this->tpl_bool = $template->tpl_bool;
+ − 1432
}
+ − 1433
/**
+ − 1434
* PHP 4 constructor.
+ − 1435
*/
+ − 1436
function templateIndividual($text)
+ − 1437
{
+ − 1438
$this->__construct($text);
+ − 1439
}
+ − 1440
/**
+ − 1441
* Assigns an array of string values to the template. Strings can be accessed from the template by inserting {KEY_NAME} in the template file.
+ − 1442
* @param $vars array
+ − 1443
*/
+ − 1444
function assign_vars($vars)
+ − 1445
{
+ − 1446
$this->tpl_strings = array_merge($this->tpl_strings, $vars);
+ − 1447
}
+ − 1448
/**
+ − 1449
* Assigns an array of boolean values to the template. These can be used for <!-- IF ... --> statements.
+ − 1450
* @param $vars array
+ − 1451
*/
+ − 1452
function assign_bool($vars)
+ − 1453
{
+ − 1454
$this->tpl_bool = array_merge($this->tpl_bool, $vars);
+ − 1455
}
+ − 1456
/**
+ − 1457
* Compiles and executes the template code.
+ − 1458
* @return string
+ − 1459
*/
+ − 1460
function run()
+ − 1461
{
+ − 1462
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 1463
if(!$this->compiled)
+ − 1464
{
+ − 1465
$this->tpl_code = $this->compile_template_text($this->tpl_code);
+ − 1466
$this->compiled = true;
+ − 1467
}
+ − 1468
return eval($this->tpl_code);
+ − 1469
}
+ − 1470
}
+ − 1471
+ − 1472
/**
+ − 1473
* A version of the template compiler that does not rely at all on the other parts of Enano. Used during installation and for showing
+ − 1474
* "critical error" messages. ** REQUIRES ** the Oxygen theme.
+ − 1475
*/
+ − 1476
+ − 1477
class template_nodb {
+ − 1478
var $tpl_strings, $tpl_bool, $theme, $style, $no_headers, $additional_headers, $sidebar_extra, $sidebar_widgets, $toolbar_menu, $theme_list;
+ − 1479
function __construct() {
+ − 1480
+ − 1481
$this->tpl_bool = Array();
+ − 1482
$this->tpl_strings = Array();
+ − 1483
$this->sidebar_extra = '';
+ − 1484
$this->sidebar_widgets = '';
+ − 1485
$this->toolbar_menu = '';
+ − 1486
$this->additional_headers = '';
+ − 1487
+ − 1488
$this->theme_list = Array(Array(
+ − 1489
'theme_id'=>'oxygen',
+ − 1490
'theme_name'=>'Oxygen',
+ − 1491
'theme_order'=>1,
+ − 1492
'enabled'=>1,
+ − 1493
));
+ − 1494
}
+ − 1495
function template() {
+ − 1496
$this->__construct();
+ − 1497
}
+ − 1498
function get_css($s = false) {
+ − 1499
if($s)
+ − 1500
return $this->process_template('css/'.$s);
+ − 1501
else
+ − 1502
return $this->process_template('css/'.$this->style.'.css');
+ − 1503
}
+ − 1504
function load_theme($name, $css, $auto_init = true) {
+ − 1505
$this->theme = $name;
+ − 1506
$this->style = $css;
+ − 1507
+ − 1508
$this->tpl_strings['SCRIPTPATH'] = scriptPath;
+ − 1509
if ( $auto_init )
+ − 1510
$this->init_vars();
+ − 1511
}
+ − 1512
function init_vars()
+ − 1513
{
+ − 1514
global $sideinfo;
+ − 1515
global $this_page;
+ − 1516
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 1517
$tplvars = $this->extract_vars('elements.tpl');
+ − 1518
$tb = '';
+ − 1519
// Get the "article" button text (depends on namespace)
+ − 1520
if(defined('IN_ENANO_INSTALL')) $ns = 'installation page';
+ − 1521
else $ns = 'system error page';
+ − 1522
$t = str_replace('{FLAGS}', 'onclick="return false;" title="Hey! A button that doesn\'t do anything. Clever..." accesskey="a"', $tplvars['toolbar_button']);
+ − 1523
$t = str_replace('{HREF}', '#', $t);
+ − 1524
$t = str_replace('{TEXT}', $ns, $t);
+ − 1525
$tb .= $t;
+ − 1526
+ − 1527
// Page toolbar
+ − 1528
+ − 1529
$this->tpl_bool = Array(
+ − 1530
'auth_admin'=>true,
+ − 1531
'user_logged_in'=>true,
+ − 1532
'right_sidebar'=>false,
+ − 1533
);
+ − 1534
$this->tpl_bool['in_sidebar_admin'] = false;
+ − 1535
+ − 1536
$this->tpl_bool['auth_rename'] = false;
+ − 1537
+ − 1538
$asq = $asa = '';
+ − 1539
+ − 1540
$this->tpl_bool['fixed_menus'] = false;
+ − 1541
$slink = defined('IN_ENANO_INSTALL') ? scriptPath.'/install.php?mode=css' : makeUrlNS('Special', 'CSS');
+ − 1542
+ − 1543
$title = ( is_object($paths) ) ? $paths->page : 'Critical error';
+ − 1544
+ − 1545
// The rewritten template engine will process all required vars during the load_template stage instead of (cough) re-processing everything each time around.
+ − 1546
$tpl_strings = Array(
+ − 1547
'PAGE_NAME'=>$this_page,
+ − 1548
'PAGE_URLNAME'=>'Null',
+ − 1549
'SITE_NAME'=>'Enano Installation',
+ − 1550
'USERNAME'=>'admin',
+ − 1551
'SITE_DESC'=>'Install Enano on your server.',
+ − 1552
'TOOLBAR'=>$tb,
+ − 1553
'SCRIPTPATH'=>scriptPath,
+ − 1554
'CONTENTPATH'=>contentPath,
+ − 1555
'ADMIN_SID_QUES'=>$asq,
+ − 1556
'ADMIN_SID_AMP'=>$asa,
+ − 1557
'ADMIN_SID_AMP_HTML'=>'',
+ − 1558
'ADDITIONAL_HEADERS'=>'<style type="text/css">div.pagenav { border-top: 1px solid #CCC; padding-top: 7px; margin-top: 10px; }</style>',
+ − 1559
'SIDEBAR_EXTRA'=>'',
+ − 1560
'COPYRIGHT'=>'Enano and all of its code, graphics, and more code is copyright © 2006 Dan Fuhry.<br />This program is Free Software; see the file "GPL" included with this package for details.',
+ − 1561
'TOOLBAR_EXTRAS'=>'',
+ − 1562
'REQUEST_URI'=>$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'],
+ − 1563
'STYLE_LINK'=>$slink,
+ − 1564
'LOGOUT_LINK'=>'',
+ − 1565
'THEME_LINK'=>'',
+ − 1566
'TEMPLATE_DIR'=>scriptPath.'/themes/'.$this->theme,
+ − 1567
'THEME_ID'=>$this->theme,
+ − 1568
'STYLE_ID'=>$this->style,
+ − 1569
'JS_DYNAMIC_VARS'=>'<script type="text/javascript">var title="'. $title .'"; var scriptPath="'.scriptPath.'"; var ENANO_SID=""; var AES_BITS='.AES_BITS.'; var AES_BLOCKSIZE=' . AES_BLOCKSIZE . '; var pagepass=\'\';</script>',
+ − 1570
'SIDEBAR_RIGHT'=>'',
+ − 1571
);
+ − 1572
$this->tpl_strings = array_merge($tpl_strings, $this->tpl_strings);
+ − 1573
+ − 1574
$sidebar = ( gettype($sideinfo) == 'string' ) ? $sideinfo : '';
+ − 1575
if($sidebar != '')
+ − 1576
{
+ − 1577
if(isset($tplvars['sidebar_top']))
+ − 1578
{
+ − 1579
$text = $this->makeParserText($tplvars['sidebar_top']);
+ − 1580
$top = $text->run();
+ − 1581
} else {
+ − 1582
$top = '';
+ − 1583
}
+ − 1584
$p = $this->makeParserText($tplvars['sidebar_section']);
+ − 1585
$p->assign_vars(Array(
+ − 1586
'TITLE'=>'Installation progress',
+ − 1587
'CONTENT'=>$sidebar,
+ − 1588
));
+ − 1589
$sidebar = $p->run();
+ − 1590
if(isset($tplvars['sidebar_bottom']))
+ − 1591
{
+ − 1592
$text = $this->makeParserText($tplvars['sidebar_bottom']);
+ − 1593
$bottom = $text->run();
+ − 1594
} else {
+ − 1595
$bottom = '';
+ − 1596
}
+ − 1597
$sidebar = $top . $sidebar . $bottom;
+ − 1598
}
+ − 1599
$this->tpl_strings['SIDEBAR_LEFT'] = $sidebar;
+ − 1600
+ − 1601
$this->tpl_bool['sidebar_left'] = ( $this->tpl_strings['SIDEBAR_LEFT'] != '') ? true : false;
+ − 1602
$this->tpl_bool['sidebar_right'] = ( $this->tpl_strings['SIDEBAR_RIGHT'] != '') ? true : false;
+ − 1603
$this->tpl_bool['right_sidebar'] = $this->tpl_bool['sidebar_right']; // backward compatibility
+ − 1604
$this->tpl_bool['stupid_mode'] = true;
+ − 1605
}
+ − 1606
function header()
+ − 1607
{
+ − 1608
if(!$this->no_headers) echo $this->process_template('header.tpl');
+ − 1609
}
+ − 1610
function footer()
+ − 1611
{
+ − 1612
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 1613
if(!$this->no_headers) {
+ − 1614
global $_starttime;
+ − 1615
$f = microtime(true);
+ − 1616
$f = $f - $_starttime;
+ − 1617
$f = round($f, 4);
+ − 1618
if(defined('IN_ENANO_INSTALL')) $nq = 'N/A';
+ − 1619
else $nq = $db->num_queries;
+ − 1620
if($nq == 0) $nq = 'N/A';
+ − 1621
$dbg = 'Time: '.$f.'s | Queries: '.$nq;
+ − 1622
$t = $this->process_template('footer.tpl');
+ − 1623
$t = str_replace('[[Stats]]', $dbg, $t);
+ − 1624
echo $t;
+ − 1625
}
+ − 1626
else return '';
+ − 1627
}
+ − 1628
function getHeader()
+ − 1629
{
+ − 1630
if(!$this->no_headers) return $this->process_template('header.tpl');
+ − 1631
else return '';
+ − 1632
}
+ − 1633
function getFooter()
+ − 1634
{
+ − 1635
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 1636
if(!$this->no_headers) {
+ − 1637
global $_starttime;
+ − 1638
$f = microtime(true);
+ − 1639
$f = $f - $_starttime;
+ − 1640
$f = round($f, 4);
+ − 1641
if(defined('IN_ENANO_INSTALL')) $nq = 'N/A';
+ − 1642
else $nq = $db->num_queries;
+ − 1643
if($nq == 0) $nq = 'N/A';
+ − 1644
$dbg = 'Time: '.$f.'s | Queries: '.$nq;
+ − 1645
if($nq == 0) $nq = 'N/A';
+ − 1646
$t = $this->process_template('footer.tpl');
+ − 1647
$t = str_replace('[[Stats]]', $dbg, $t);
+ − 1648
return $t;
+ − 1649
}
+ − 1650
else return '';
+ − 1651
}
+ − 1652
+ − 1653
function process_template($file) {
+ − 1654
+ − 1655
eval($this->compile_template($file));
+ − 1656
return $tpl_code;
+ − 1657
}
+ − 1658
+ − 1659
function extract_vars($file) {
+ − 1660
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 1661
if(!is_file(ENANO_ROOT . '/themes/'.$this->theme.'/'.$file)) die('Cannot find '.$file.' file for style "'.$this->theme.'", exiting');
+ − 1662
$text = file_get_contents(ENANO_ROOT . '/themes/'.$this->theme.'/'.$file);
+ − 1663
preg_match_all('#<\!-- VAR ([A-z0-9_-]*) -->(.*?)<\!-- ENDVAR \\1 -->#is', $text, $matches);
+ − 1664
$tplvars = Array();
+ − 1665
for($i=0;$i<sizeof($matches[1]);$i++)
+ − 1666
{
+ − 1667
$tplvars[$matches[1][$i]] = $matches[2][$i];
+ − 1668
}
+ − 1669
return $tplvars;
+ − 1670
}
+ − 1671
function compile_template($text) {
+ − 1672
global $sideinfo;
+ − 1673
$text = file_get_contents(ENANO_ROOT . '/themes/'.$this->theme.'/'.$text);
+ − 1674
$text = str_replace('<script type="text/javascript" src="{SCRIPTPATH}/ajax.php?title={PAGE_URLNAME}&_mode=jsres"></script>', '', $text); // Remove the AJAX code - we don't need it, and it requires a database connection
+ − 1675
$text = '$tpl_code = \''.str_replace('\'', '\\\'', $text).'\'; return $tpl_code;';
+ − 1676
$text = preg_replace('#<!-- BEGIN (.*?) -->#is', '\'; if($this->tpl_bool[\'\\1\']) { $tpl_code .= \'', $text);
+ − 1677
$text = preg_replace('#<!-- IFPLUGIN (.*?) -->#is', '\'; if(getConfig(\'plugin_\\1\')==\'1\') { $tpl_code .= \'', $text);
+ − 1678
if(defined('IN_ENANO_INSTALL')) $text = str_replace('<!-- SYSMSG Sidebar -->', '<div class="slider"><div class="heading"><a class="head">Installation progress</a></div><div class="slideblock">'.$sideinfo.'</div></div>', $text);
+ − 1679
else $text = str_replace('<!-- SYSMSG Sidebar -->', '<div class="slider"><div class="heading"><a class="head">System error</a></div><div class="slideblock"><a href="#" onclick="return false;">Enano critical error page</a></div></div>', $text);
+ − 1680
$text = preg_replace('#<!-- SYSMSG (.*?) -->#is', '', $text);
+ − 1681
$text = preg_replace('#<!-- BEGINNOT (.*?) -->#is', '\'; if(!$this->tpl_bool[\'\\1\']) { $tpl_code .= \'', $text);
+ − 1682
$text = preg_replace('#<!-- BEGINELSE (.*?) -->#is', '\'; } else { $tpl_code .= \'', $text);
+ − 1683
$text = preg_replace('#<!-- END (.*?) -->#is', '\'; } $tpl_code .= \'', $text);
+ − 1684
$text = preg_replace('#{([A-z0-9]*)}#is', '\'.$this->tpl_strings[\'\\1\'].\'', $text);
+ − 1685
return $text; //('<pre>'.htmlspecialchars($text).'</pre>');
+ − 1686
}
+ − 1687
+ − 1688
function compile_template_text($text) {
+ − 1689
global $sideinfo;
+ − 1690
$text = str_replace('<script type="text/javascript" src="{SCRIPTPATH}/ajax.php?title={PAGE_URLNAME}&_mode=jsres"></script>', '', $text); // Remove the AJAX code - we don't need it, and it requires a database connection
+ − 1691
$text = '$tpl_code = \''.str_replace('\'', '\\\'', $text).'\'; return $tpl_code;';
+ − 1692
$text = preg_replace('#<!-- BEGIN (.*?) -->#is', '\'; if($this->tpl_bool[\'\\1\']) { $tpl_code .= \'', $text);
+ − 1693
$text = preg_replace('#<!-- IFPLUGIN (.*?) -->#is', '\'; if(getConfig(\'plugin_\\1\')==\'1\') { $tpl_code .= \'', $text);
+ − 1694
if(defined('IN_ENANO_INSTALL')) $text = str_replace('<!-- SYSMSG Sidebar -->', '<div class="slider"><div class="heading"><a class="head">Installation progress</a></div><div class="slideblock">'.$sideinfo.'</div></div>', $text);
+ − 1695
else $text = str_replace('<!-- SYSMSG Sidebar -->', '<div class="slider"><div class="heading"><a class="head">System error</a></div><div class="slideblock"><a href="#" onclick="return false;">Enano critical error page</a></div></div>', $text);
+ − 1696
$text = preg_replace('#<!-- SYSMSG (.*?) -->#is', '', $text);
+ − 1697
$text = preg_replace('#<!-- BEGINNOT (.*?) -->#is', '\'; if(!$this->tpl_bool[\'\\1\']) { $tpl_code .= \'', $text);
+ − 1698
$text = preg_replace('#<!-- BEGINELSE (.*?) -->#is', '\'; } else { $tpl_code .= \'', $text);
+ − 1699
$text = preg_replace('#<!-- END (.*?) -->#is', '\'; } $tpl_code .= \'', $text);
+ − 1700
$text = preg_replace('#{([A-z0-9]*)}#is', '\'.$this->tpl_strings[\'\\1\'].\'', $text);
+ − 1701
return $text; //('<pre>'.htmlspecialchars($text).'</pre>');
+ − 1702
}
+ − 1703
+ − 1704
/**
+ − 1705
* Allows individual parsing of template files. Similar to phpBB but follows the spirit of object-oriented programming ;)
+ − 1706
* Returns on object of class templateIndividual. Usage instructions can be found in the inline docs for that class.
+ − 1707
* @param $filename the filename of the template to be parsed
+ − 1708
* @return object
+ − 1709
*/
+ − 1710
+ − 1711
function makeParser($filename)
+ − 1712
{
+ − 1713
$filename = ENANO_ROOT.'/themes/'.$this->theme.'/'.$filename;
+ − 1714
if(!file_exists($filename)) die('templateIndividual: file '.$filename.' does not exist');
+ − 1715
$code = file_get_contents($filename);
+ − 1716
$parser = new templateIndividualSafe($code, $this);
+ − 1717
return $parser;
+ − 1718
}
+ − 1719
+ − 1720
/**
+ − 1721
* Same as $template->makeParser(), but takes a string instead of a filename.
+ − 1722
* @param $text the text to parse
+ − 1723
* @return object
+ − 1724
*/
+ − 1725
+ − 1726
function makeParserText($code)
+ − 1727
{
+ − 1728
$parser = new templateIndividualSafe($code, $this);
+ − 1729
return $parser;
+ − 1730
}
+ − 1731
+ − 1732
} // class template_nodb
+ − 1733
+ − 1734
/**
+ − 1735
* Identical to templateIndividual, except extends template_nodb instead of template
+ − 1736
* @see class template
+ − 1737
*/
+ − 1738
+ − 1739
class templateIndividualSafe extends template_nodb {
+ − 1740
var $tpl_strings, $tpl_bool, $tpl_code;
+ − 1741
var $compiled = false;
+ − 1742
/**
+ − 1743
* Constructor.
+ − 1744
*/
+ − 1745
function __construct($text, $parent)
+ − 1746
{
+ − 1747
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 1748
$this->tpl_code = $text;
+ − 1749
$this->tpl_strings = $parent->tpl_strings;
+ − 1750
$this->tpl_bool = $parent->tpl_bool;
+ − 1751
}
+ − 1752
/**
+ − 1753
* PHP 4 constructor.
+ − 1754
*/
+ − 1755
function templateIndividual($text)
+ − 1756
{
+ − 1757
$this->__construct($text);
+ − 1758
}
+ − 1759
/**
+ − 1760
* Assigns an array of string values to the template. Strings can be accessed from the template by inserting {KEY_NAME} in the template file.
+ − 1761
* @param $vars array
+ − 1762
*/
+ − 1763
function assign_vars($vars)
+ − 1764
{
+ − 1765
if(is_array($this->tpl_strings))
+ − 1766
$this->tpl_strings = array_merge($this->tpl_strings, $vars);
+ − 1767
else
+ − 1768
$this->tpl_strings = $vars;
+ − 1769
}
+ − 1770
/**
+ − 1771
* Assigns an array of boolean values to the template. These can be used for <!-- IF ... --> statements.
+ − 1772
* @param $vars array
+ − 1773
*/
+ − 1774
function assign_bool($vars)
+ − 1775
{
+ − 1776
$this->tpl_bool = array_merge($this->tpl_bool, $vars);
+ − 1777
}
+ − 1778
/**
+ − 1779
* Compiles and executes the template code.
+ − 1780
* @return string
+ − 1781
*/
+ − 1782
function run()
+ − 1783
{
+ − 1784
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 1785
if(!$this->compiled)
+ − 1786
{
+ − 1787
$this->tpl_code = $this->compile_template_text($this->tpl_code);
+ − 1788
$this->compiled = true;
+ − 1789
}
+ − 1790
return eval($this->tpl_code);
+ − 1791
}
+ − 1792
}
+ − 1793
+ − 1794
?>