author | Dan |
Mon, 11 May 2009 19:53:25 -0400 | |
changeset 966 | 2db0975aa31a |
parent 801 | eb8b23f11744 |
child 1027 | 98c052fc3337 |
permissions | -rw-r--r-- |
1 | 1 |
<?php |
536 | 2 |
|
3 |
/* |
|
4 |
* Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between |
|
801
eb8b23f11744
Two big commits in one day I know, but redid password storage to use HMAC-SHA1. Consolidated much AES processing to three core methods in session that should handle everything automagically. Installation works; upgrades should. Rebranded as 1.1.6.
Dan
parents:
685
diff
changeset
|
5 |
* Version 1.1.6 (Caoineag beta 1) |
536 | 6 |
* Copyright (C) 2006-2008 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 |
||
1 | 15 |
/** |
16 |
* Parse structured wiki text and render into arbitrary formats such as XHTML. |
|
17 |
* |
|
18 |
* PHP versions 4 and 5 |
|
19 |
* |
|
20 |
* @category Text |
|
21 |
* @package Text_Wiki |
|
22 |
* @author Paul M. Jones <pmjones@php.net> |
|
23 |
* @license http://www.gnu.org/licenses/lgpl.html |
|
24 |
* @version CVS: $Id: Wiki.php,v 1.44 2006/03/02 04:04:59 justinpatrin Exp $ |
|
25 |
* @link http://wiki.ciaweb.net/yawiki/index.php?area=Text_Wiki |
|
26 |
* |
|
27 |
* This code was modified for use in Enano. The Text_Wiki engine is licensed |
|
28 |
* under the GNU Lesser General Public License; see |
|
29 |
* http://www.gnu.org/licenses/lgpl.html for details. |
|
30 |
* |
|
31 |
*/ |
|
32 |
||
33 |
require_once ENANO_ROOT.'/includes/wikiengine/Parse.php'; |
|
34 |
require_once ENANO_ROOT.'/includes/wikiengine/Render.php'; |
|
35 |
||
36 |
class Text_Wiki { |
|
37 |
||
38 |
var $rules = array( |
|
39 |
'Prefilter', |
|
40 |
'Delimiter', |
|
41 |
'Code', |
|
42 |
'Function', |
|
43 |
'Html', |
|
44 |
'Raw', |
|
45 |
'Include', |
|
46 |
'Embed', |
|
47 |
'Anchor', |
|
48 |
'Heading', |
|
49 |
'Toc', |
|
50 |
'Horiz', |
|
51 |
'Break', |
|
52 |
'Blockquote', |
|
53 |
'List', |
|
54 |
'Deflist', |
|
55 |
'Table', |
|
56 |
'Image', |
|
57 |
'Phplookup', |
|
58 |
'Center', |
|
59 |
'Newline', |
|
60 |
'Paragraph', |
|
61 |
'Url', |
|
62 |
'Freelink', |
|
63 |
'Interwiki', |
|
64 |
'Wikilink', |
|
65 |
'Colortext', |
|
66 |
'Strong', |
|
67 |
'Bold', |
|
68 |
'Emphasis', |
|
69 |
'Italic', |
|
70 |
'Underline', |
|
71 |
'Tt', |
|
72 |
'Superscript', |
|
73 |
'Subscript', |
|
74 |
'Revise', |
|
75 |
'Tighten' |
|
76 |
); |
|
77 |
||
78 |
var $disable = array( |
|
79 |
'Html', |
|
80 |
'Include', |
|
32
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
81 |
'Embed', |
35 | 82 |
'Tighten', |
142
ca9118d9c0f2
Rebrand as 1.0.2 (Coblynau); internal links are now parsed by RenderMan::parse_internal_links()
Dan
parents:
78
diff
changeset
|
83 |
'Image', |
ca9118d9c0f2
Rebrand as 1.0.2 (Coblynau); internal links are now parsed by RenderMan::parse_internal_links()
Dan
parents:
78
diff
changeset
|
84 |
'Wikilink' |
1 | 85 |
); |
86 |
||
87 |
var $parseConf = array(); |
|
88 |
||
89 |
var $renderConf = array( |
|
90 |
'Docbook' => array(), |
|
91 |
'Latex' => array(), |
|
92 |
'Pdf' => array(), |
|
93 |
'Plain' => array(), |
|
94 |
'Rtf' => array(), |
|
95 |
'Xhtml' => array() |
|
96 |
); |
|
97 |
||
98 |
var $formatConf = array( |
|
99 |
'Docbook' => array(), |
|
100 |
'Latex' => array(), |
|
101 |
'Pdf' => array(), |
|
102 |
'Plain' => array(), |
|
103 |
'Rtf' => array(), |
|
104 |
'Xhtml' => array() |
|
105 |
); |
|
106 |
var $delim = "\xFF"; |
|
107 |
var $tokens = array(); |
|
108 |
var $_countRulesTokens = array(); |
|
109 |
var $source = ''; |
|
110 |
var $parseObj = array(); |
|
111 |
var $renderObj = array(); |
|
112 |
var $formatObj = array(); |
|
113 |
var $path = array( |
|
114 |
'parse' => array(), |
|
115 |
'render' => array() |
|
116 |
); |
|
117 |
var $_dirSep = DIRECTORY_SEPARATOR; |
|
118 |
function Text_Wiki($rules = null) |
|
119 |
{ |
|
120 |
if (is_array($rules)) { |
|
121 |
$this->rules = $rules; |
|
122 |
} |
|
407
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
371
diff
changeset
|
123 |
|
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
371
diff
changeset
|
124 |
global $plugins; |
438 | 125 |
// This code can be run from the installer, so in some cases $plugins |
126 |
// isn't initted. (Bug in 1.1.2, fixed for 1.1.3) |
|
127 |
if ( is_object($plugins) ) |
|
407
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
371
diff
changeset
|
128 |
{ |
438 | 129 |
$code = $plugins->setHook('text_wiki_construct'); |
130 |
foreach ( $code as $cmd ) |
|
131 |
{ |
|
132 |
eval($cmd); |
|
133 |
} |
|
407
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
371
diff
changeset
|
134 |
} |
1 | 135 |
|
136 |
$this->addPath( |
|
137 |
'parse', |
|
138 |
$this->fixPath(ENANO_ROOT) . 'includes/wikiengine/Parse/Default/' |
|
139 |
); |
|
140 |
$this->addPath( |
|
141 |
'render', |
|
142 |
$this->fixPath(ENANO_ROOT) . 'includes/wikiengine/Render/' |
|
143 |
); |
|
144 |
||
145 |
} |
|
146 |
||
371
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
parents:
345
diff
changeset
|
147 |
public static function singleton($parser = 'Default', $rules = null) |
1 | 148 |
{ |
149 |
static $only = array(); |
|
150 |
if (!isset($only[$parser])) { |
|
371
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
parents:
345
diff
changeset
|
151 |
$ret = Text_Wiki::factory($parser, $rules); |
1 | 152 |
if (!$ret) { |
153 |
return $ret; |
|
154 |
} |
|
155 |
$only[$parser] =& $ret; |
|
156 |
} |
|
157 |
return $only[$parser]; |
|
158 |
} |
|
159 |
||
371
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
parents:
345
diff
changeset
|
160 |
public static function factory($parser = 'Default', $rules = null) |
1 | 161 |
{ |
162 |
$d=getcwd(); |
|
163 |
chdir(ENANO_ROOT); |
|
164 |
||
165 |
$class = 'Text_Wiki_' . $parser; |
|
460 | 166 |
$c2 = $parser; |
167 |
$file = ENANO_ROOT . '/includes/wikiengine/' . str_replace('_', '/', $c2).'.php'; |
|
1 | 168 |
if (!class_exists($class)) { |
169 |
$fp = @fopen($file, 'r', true); |
|
170 |
if ($fp === false) { |
|
171 |
die_semicritical('Wiki formatting engine error', '<p>Could not find file '.$file.' in include_path</p>'); |
|
172 |
} |
|
173 |
fclose($fp); |
|
174 |
include_once($file); |
|
175 |
if (!class_exists($class)) { |
|
176 |
die_semicritical('Wiki formatting engine error', '<p>Class '.$class.' does not exist after including '.$file.'</p>'); |
|
177 |
} |
|
178 |
} |
|
179 |
||
180 |
chdir($d); |
|
181 |
||
345
4ccdfeee9a11
WiP commit for admin panel localization. All modules up to Admin:UserManager (working down the list) are localized except Admin:ThemeManager, which is due for a rewrite
Dan
parents:
142
diff
changeset
|
182 |
$obj = new $class($rules); |
1 | 183 |
return $obj; |
184 |
} |
|
185 |
||
186 |
function setParseConf($rule, $arg1, $arg2 = null) |
|
187 |
{ |
|
188 |
$rule = ucwords(strtolower($rule)); |
|
189 |
||
190 |
if (! isset($this->parseConf[$rule])) { |
|
191 |
$this->parseConf[$rule] = array(); |
|
192 |
} |
|
193 |
||
194 |
if (is_array($arg1)) { |
|
195 |
$this->parseConf[$rule] = $arg1; |
|
196 |
} else { |
|
197 |
$this->parseConf[$rule][$arg1] = $arg2; |
|
198 |
} |
|
199 |
} |
|
200 |
||
201 |
function getParseConf($rule, $key = null) |
|
202 |
{ |
|
203 |
$rule = ucwords(strtolower($rule)); |
|
204 |
||
205 |
if (! isset($this->parseConf[$rule])) { |
|
206 |
return null; |
|
207 |
} |
|
208 |
||
209 |
if (is_null($key)) { |
|
210 |
return $this->parseConf[$rule]; |
|
211 |
} |
|
212 |
||
213 |
if (isset($this->parseConf[$rule][$key])) { |
|
214 |
return $this->parseConf[$rule][$key]; |
|
215 |
} else { |
|
216 |
return null; |
|
217 |
} |
|
218 |
} |
|
219 |
||
220 |
function setRenderConf($format, $rule, $arg1, $arg2 = null) |
|
221 |
{ |
|
222 |
$format = ucwords(strtolower($format)); |
|
223 |
$rule = ucwords(strtolower($rule)); |
|
224 |
||
225 |
if (! isset($this->renderConf[$format])) { |
|
226 |
$this->renderConf[$format] = array(); |
|
227 |
} |
|
228 |
||
229 |
if (! isset($this->renderConf[$format][$rule])) { |
|
230 |
$this->renderConf[$format][$rule] = array(); |
|
231 |
} |
|
232 |
||
233 |
if (is_array($arg1)) { |
|
234 |
$this->renderConf[$format][$rule] = $arg1; |
|
235 |
} else { |
|
236 |
$this->renderConf[$format][$rule][$arg1] = $arg2; |
|
237 |
} |
|
238 |
} |
|
239 |
||
240 |
function getRenderConf($format, $rule, $key = null) |
|
241 |
{ |
|
242 |
$format = ucwords(strtolower($format)); |
|
243 |
$rule = ucwords(strtolower($rule)); |
|
244 |
||
245 |
if (! isset($this->renderConf[$format]) || |
|
246 |
! isset($this->renderConf[$format][$rule])) { |
|
247 |
return null; |
|
248 |
} |
|
249 |
||
250 |
if (is_null($key)) { |
|
251 |
return $this->renderConf[$format][$rule]; |
|
252 |
} |
|
253 |
||
254 |
if (isset($this->renderConf[$format][$rule][$key])) { |
|
255 |
return $this->renderConf[$format][$rule][$key]; |
|
256 |
} else { |
|
257 |
return null; |
|
258 |
} |
|
259 |
||
260 |
} |
|
261 |
||
262 |
function setFormatConf($format, $arg1, $arg2 = null) |
|
263 |
{ |
|
264 |
if (! is_array($this->formatConf[$format])) { |
|
265 |
$this->formatConf[$format] = array(); |
|
266 |
} |
|
267 |
||
268 |
if (is_array($arg1)) { |
|
269 |
$this->formatConf[$format] = $arg1; |
|
270 |
} else { |
|
271 |
$this->formatConf[$format][$arg1] = $arg2; |
|
272 |
} |
|
273 |
} |
|
274 |
||
275 |
function getFormatConf($format, $key = null) |
|
276 |
{ |
|
277 |
if (! isset($this->formatConf[$format])) { |
|
278 |
return null; |
|
279 |
} |
|
280 |
||
281 |
if (is_null($key)) { |
|
282 |
return $this->formatConf[$format]; |
|
283 |
} |
|
284 |
||
285 |
if (isset($this->formatConf[$format][$key])) { |
|
286 |
return $this->formatConf[$format][$key]; |
|
287 |
} else { |
|
288 |
return null; |
|
289 |
} |
|
290 |
} |
|
291 |
||
292 |
function insertRule($name, $tgt = null) |
|
293 |
{ |
|
294 |
$name = ucwords(strtolower($name)); |
|
295 |
if (! is_null($tgt)) { |
|
296 |
$tgt = ucwords(strtolower($tgt)); |
|
297 |
} |
|
298 |
if (in_array($name, $this->rules)) { |
|
299 |
return null; |
|
300 |
} |
|
301 |
||
302 |
if (! is_null($tgt) && $tgt != '' && |
|
303 |
! in_array($tgt, $this->rules)) { |
|
304 |
return false; |
|
305 |
} |
|
306 |
||
307 |
if (is_null($tgt)) { |
|
308 |
$this->rules[] = $name; |
|
309 |
return true; |
|
310 |
} |
|
311 |
||
312 |
if ($tgt == '') { |
|
313 |
array_unshift($this->rules, $name); |
|
314 |
return true; |
|
315 |
} |
|
316 |
||
317 |
$tmp = $this->rules; |
|
318 |
$this->rules = array(); |
|
319 |
||
320 |
foreach ($tmp as $val) { |
|
321 |
$this->rules[] = $val; |
|
322 |
if ($val == $tgt) { |
|
323 |
$this->rules[] = $name; |
|
324 |
} |
|
325 |
} |
|
326 |
||
327 |
return true; |
|
328 |
} |
|
329 |
||
330 |
function deleteRule($name) |
|
331 |
{ |
|
332 |
$name = ucwords(strtolower($name)); |
|
333 |
$key = array_search($name, $this->rules); |
|
334 |
if ($key !== false) { |
|
335 |
unset($this->rules[$key]); |
|
336 |
} |
|
337 |
} |
|
338 |
||
339 |
function changeRule($old, $new) |
|
340 |
{ |
|
341 |
$old = ucwords(strtolower($old)); |
|
342 |
$new = ucwords(strtolower($new)); |
|
343 |
$key = array_search($old, $this->rules); |
|
344 |
if ($key !== false) { |
|
345 |
$this->deleteRule($new); |
|
346 |
$this->rules[$key] = $new; |
|
347 |
} |
|
348 |
} |
|
349 |
||
350 |
function enableRule($name) |
|
351 |
{ |
|
352 |
$name = ucwords(strtolower($name)); |
|
353 |
$key = array_search($name, $this->disable); |
|
354 |
if ($key !== false) { |
|
355 |
unset($this->disable[$key]); |
|
356 |
} |
|
357 |
} |
|
358 |
||
359 |
function disableRule($name) |
|
360 |
{ |
|
361 |
$name = ucwords(strtolower($name)); |
|
362 |
$key = array_search($name, $this->disable); |
|
363 |
if ($key === false) { |
|
364 |
$this->disable[] = $name; |
|
365 |
} |
|
366 |
} |
|
367 |
||
368 |
function transform($text, $format = 'Xhtml') |
|
369 |
{ |
|
370 |
$this->parse($text); |
|
371 |
return $this->render($format); |
|
372 |
} |
|
373 |
||
374 |
function parse($text) |
|
375 |
{ |
|
376 |
$this->source = $text; |
|
377 |
||
378 |
$this->tokens = array(); |
|
379 |
$this->_countRulesTokens = array(); |
|
380 |
||
381 |
foreach ($this->rules as $name) { |
|
382 |
if (! in_array($name, $this->disable)) { |
|
383 |
$this->loadParseObj($name); |
|
384 |
||
385 |
if (is_object($this->parseObj[$name])) { |
|
386 |
$this->parseObj[$name]->parse(); |
|
387 |
} |
|
32
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
388 |
// For debugging |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
389 |
// echo('<p>' . $name . ':</p><pre>'.htmlspecialchars($this->source).'</pre>'); |
1 | 390 |
} |
391 |
} |
|
392 |
} |
|
393 |
||
394 |
function render($format = 'Xhtml') |
|
395 |
{ |
|
396 |
$format = ucwords(strtolower($format)); |
|
397 |
||
398 |
$output = ''; |
|
399 |
||
400 |
$in_delim = false; |
|
401 |
||
402 |
$key = ''; |
|
403 |
||
404 |
$result = $this->loadFormatObj($format); |
|
405 |
if ($this->isError($result)) { |
|
406 |
return $result; |
|
407 |
} |
|
78
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
parents:
35
diff
changeset
|
408 |
|
1 | 409 |
if (is_object($this->formatObj[$format])) { |
410 |
$output .= $this->formatObj[$format]->pre(); |
|
411 |
} |
|
412 |
||
413 |
foreach (array_keys($this->_countRulesTokens) as $rule) { |
|
414 |
$this->loadRenderObj($format, $rule); |
|
415 |
} |
|
78
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
parents:
35
diff
changeset
|
416 |
|
1 | 417 |
$k = strlen($this->source); |
418 |
for ($i = 0; $i < $k; $i++) { |
|
419 |
||
420 |
$char = $this->source{$i}; |
|
421 |
||
422 |
if ($in_delim) { |
|
423 |
||
424 |
if ($char == $this->delim) { |
|
425 |
||
426 |
$key = (int)$key; |
|
427 |
$rule = $this->tokens[$key][0]; |
|
428 |
$opts = $this->tokens[$key][1]; |
|
429 |
$output .= $this->renderObj[$rule]->token($opts); |
|
430 |
$in_delim = false; |
|
431 |
||
432 |
} else { |
|
433 |
||
434 |
$key .= $char; |
|
435 |
||
436 |
} |
|
437 |
||
438 |
} else { |
|
439 |
||
440 |
if ($char == $this->delim) { |
|
441 |
$key = ''; |
|
442 |
$in_delim = true; |
|
443 |
} else { |
|
444 |
$output .= $char; |
|
445 |
} |
|
446 |
} |
|
447 |
} |
|
448 |
||
449 |
if (is_object($this->formatObj[$format])) { |
|
450 |
$output .= $this->formatObj[$format]->post(); |
|
451 |
} |
|
452 |
||
453 |
return $output; |
|
454 |
} |
|
455 |
||
456 |
function getSource() |
|
457 |
{ |
|
458 |
return $this->source; |
|
459 |
} |
|
460 |
||
461 |
function getTokens($rules = null) |
|
462 |
{ |
|
463 |
if (is_null($rules)) { |
|
464 |
return $this->tokens; |
|
465 |
} else { |
|
466 |
settype($rules, 'array'); |
|
467 |
$result = array(); |
|
468 |
foreach ($this->tokens as $key => $val) { |
|
469 |
if (in_array($val[0], $rules)) { |
|
470 |
$result[$key] = $val; |
|
471 |
} |
|
472 |
} |
|
473 |
return $result; |
|
474 |
} |
|
475 |
} |
|
476 |
||
477 |
function addToken($rule, $options = array(), $id_only = false) |
|
478 |
{ |
|
479 |
static $id; |
|
480 |
if (! isset($id)) { |
|
481 |
$id = 0; |
|
482 |
} else { |
|
483 |
$id ++; |
|
484 |
} |
|
485 |
||
486 |
settype($options, 'array'); |
|
487 |
||
488 |
$this->tokens[$id] = array( |
|
489 |
0 => $rule, |
|
490 |
1 => $options |
|
491 |
); |
|
492 |
if (!isset($this->_countRulesTokens[$rule])) { |
|
493 |
$this->_countRulesTokens[$rule] = 1; |
|
494 |
} else { |
|
495 |
++$this->_countRulesTokens[$rule]; |
|
496 |
} |
|
497 |
||
498 |
if ($id_only) { |
|
499 |
return $id; |
|
500 |
} else { |
|
501 |
return $this->delim . $id . $this->delim; |
|
502 |
} |
|
503 |
} |
|
504 |
||
505 |
function setToken($id, $rule, $options = array()) |
|
506 |
{ |
|
507 |
$oldRule = $this->tokens[$id][0]; |
|
508 |
$this->tokens[$id] = array( |
|
509 |
0 => $rule, |
|
510 |
1 => $options |
|
511 |
); |
|
512 |
if ($rule != $oldRule) { |
|
513 |
if (!($this->_countRulesTokens[$oldRule]--)) { |
|
514 |
unset($this->_countRulesTokens[$oldRule]); |
|
515 |
} |
|
516 |
if (!isset($this->_countRulesTokens[$rule])) { |
|
517 |
$this->_countRulesTokens[$rule] = 1; |
|
518 |
} else { |
|
519 |
++$this->_countRulesTokens[$rule]; |
|
520 |
} |
|
521 |
} |
|
522 |
} |
|
523 |
||
524 |
function loadParseObj($rule) |
|
525 |
{ |
|
526 |
$rule = ucwords(strtolower($rule)); |
|
527 |
$file = $rule . '.php'; |
|
528 |
$class = "Text_Wiki_Parse_$rule"; |
|
529 |
||
530 |
if (! class_exists($class)) { |
|
531 |
$loc = $this->findFile('parse', $file); |
|
532 |
if ($loc) { |
|
533 |
include_once $loc; |
|
534 |
} else { |
|
535 |
$this->parseObj[$rule] = null; |
|
536 |
return $this->error( |
|
537 |
"Parse rule '$rule' not found" |
|
538 |
); |
|
539 |
} |
|
540 |
} |
|
541 |
||
345
4ccdfeee9a11
WiP commit for admin panel localization. All modules up to Admin:UserManager (working down the list) are localized except Admin:ThemeManager, which is due for a rewrite
Dan
parents:
142
diff
changeset
|
542 |
$this->parseObj[$rule] = new $class($this); |
1 | 543 |
|
544 |
} |
|
545 |
||
546 |
function loadRenderObj($format, $rule) |
|
547 |
{ |
|
548 |
$format = ucwords(strtolower($format)); |
|
549 |
$rule = ucwords(strtolower($rule)); |
|
550 |
$file = "$format/$rule.php"; |
|
551 |
$class = "Text_Wiki_Render_$format" . "_$rule"; |
|
552 |
||
553 |
if (! class_exists($class)) { |
|
554 |
$loc = $this->findFile('render', $file); |
|
555 |
if ($loc) { |
|
556 |
include_once $loc; |
|
557 |
} else { |
|
558 |
return $this->error( |
|
559 |
"Render rule '$rule' in format '$format' not found" |
|
560 |
); |
|
561 |
} |
|
562 |
} |
|
563 |
||
345
4ccdfeee9a11
WiP commit for admin panel localization. All modules up to Admin:UserManager (working down the list) are localized except Admin:ThemeManager, which is due for a rewrite
Dan
parents:
142
diff
changeset
|
564 |
$this->renderObj[$rule] = new $class($this); |
1 | 565 |
} |
566 |
||
567 |
function loadFormatObj($format) |
|
568 |
{ |
|
569 |
$format = ucwords(strtolower($format)); |
|
570 |
$file = $format . '.php'; |
|
571 |
$class = "Text_Wiki_Render_$format"; |
|
572 |
||
573 |
if (! class_exists($class)) { |
|
574 |
$loc = $this->findFile('render', $file); |
|
575 |
if ($loc) { |
|
576 |
include_once $loc; |
|
577 |
} else { |
|
578 |
return $this->error( |
|
579 |
"Rendering format class '$class' not found" |
|
580 |
); |
|
581 |
} |
|
582 |
} |
|
583 |
||
345
4ccdfeee9a11
WiP commit for admin panel localization. All modules up to Admin:UserManager (working down the list) are localized except Admin:ThemeManager, which is due for a rewrite
Dan
parents:
142
diff
changeset
|
584 |
$this->formatObj[$format] = new $class($this); |
1 | 585 |
} |
586 |
||
587 |
function addPath($type, $dir) |
|
588 |
{ |
|
589 |
$dir = $this->fixPath($dir); |
|
590 |
if (! isset($this->path[$type])) { |
|
591 |
$this->path[$type] = array($dir); |
|
592 |
} else { |
|
593 |
array_unshift($this->path[$type], $dir); |
|
594 |
} |
|
595 |
} |
|
596 |
||
597 |
function getPath($type = null) |
|
598 |
{ |
|
599 |
if (is_null($type)) { |
|
600 |
return $this->path; |
|
601 |
} elseif (! isset($this->path[$type])) { |
|
602 |
return array(); |
|
603 |
} else { |
|
604 |
return $this->path[$type]; |
|
605 |
} |
|
606 |
} |
|
607 |
||
608 |
function findFile($type, $file) |
|
609 |
{ |
|
610 |
$set = $this->getPath($type); |
|
611 |
||
612 |
foreach ($set as $path) { |
|
613 |
$fullname = $path . $file; |
|
614 |
if (file_exists($fullname) && is_readable($fullname)) { |
|
615 |
return $fullname; |
|
616 |
} |
|
617 |
} |
|
618 |
||
619 |
return false; |
|
620 |
} |
|
621 |
||
622 |
function fixPath($path) |
|
623 |
{ |
|
624 |
$len = strlen($this->_dirSep); |
|
625 |
||
626 |
if (! empty($path) && |
|
627 |
substr($path, -1 * $len, $len) != $this->_dirSep) { |
|
628 |
return $path . $this->_dirSep; |
|
629 |
} else { |
|
630 |
return $path; |
|
631 |
} |
|
632 |
} |
|
633 |
||
634 |
function &error($message) |
|
635 |
{ |
|
636 |
die($message); |
|
637 |
} |
|
638 |
||
639 |
function isError(&$obj) |
|
640 |
{ |
|
371
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
parents:
345
diff
changeset
|
641 |
return ( @get_class($obj) == 'PEAR_Error' ); |
1 | 642 |
} |
643 |
} |
|
644 |
||
645 |
?> |