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