author | Dan |
Fri, 18 Dec 2009 22:03:55 -0500 | |
changeset 1187 | 5d33f9511995 |
parent 1171 | d42d46e13b36 |
child 1216 | 4125e19d3b27 |
permissions | -rw-r--r-- |
1 | 1 |
<?php |
73
0a74676a2f2f
Made the move to Loch Ness, and got some basic page grouping functionality working. TODO: fix some UI issues in Javascript ACL editor and change non-JS ACL editor to work with page groups too
Dan
parents:
67
diff
changeset
|
2 |
|
1 | 3 |
/* |
4 |
* Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between |
|
1081
745200a9cc2a
Fixed some upgrade bugs; added support for choosing one's own date/time formats; rebrand as 1.1.7
Dan
parents:
1073
diff
changeset
|
5 |
* Copyright (C) 2006-2009 Dan Fuhry |
1 | 6 |
* render.php - handles fetching pages and parsing them into HTML |
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 RenderMan { |
|
16 |
||
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
|
17 |
public static function strToPageID($string) |
1 | 18 |
{ |
19 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
20 |
$k = array_keys($paths->nslist); |
|
136
f2ee42f026f7
Fix: internal links parsed with RenderMan::parse_internal_links() did not get namespaces prepended; added Project: alias namespace for internal links
Dan
parents:
133
diff
changeset
|
21 |
$proj_alt = 'Project:'; |
f2ee42f026f7
Fix: internal links parsed with RenderMan::parse_internal_links() did not get namespaces prepended; added Project: alias namespace for internal links
Dan
parents:
133
diff
changeset
|
22 |
if ( substr($string, 0, (strlen($proj_alt))) == $proj_alt ) |
f2ee42f026f7
Fix: internal links parsed with RenderMan::parse_internal_links() did not get namespaces prepended; added Project: alias namespace for internal links
Dan
parents:
133
diff
changeset
|
23 |
{ |
f2ee42f026f7
Fix: internal links parsed with RenderMan::parse_internal_links() did not get namespaces prepended; added Project: alias namespace for internal links
Dan
parents:
133
diff
changeset
|
24 |
$ns = 'Project'; |
f2ee42f026f7
Fix: internal links parsed with RenderMan::parse_internal_links() did not get namespaces prepended; added Project: alias namespace for internal links
Dan
parents:
133
diff
changeset
|
25 |
$pg = substr($string, strlen($proj_alt), strlen($string)); |
f2ee42f026f7
Fix: internal links parsed with RenderMan::parse_internal_links() did not get namespaces prepended; added Project: alias namespace for internal links
Dan
parents:
133
diff
changeset
|
26 |
return Array($pg, $ns); |
f2ee42f026f7
Fix: internal links parsed with RenderMan::parse_internal_links() did not get namespaces prepended; added Project: alias namespace for internal links
Dan
parents:
133
diff
changeset
|
27 |
} |
1 | 28 |
for($i=0;$i<sizeof($paths->nslist);$i++) |
29 |
{ |
|
30 |
$ln = strlen($paths->nslist[$k[$i]]); |
|
31 |
if(substr($string, 0, $ln) == $paths->nslist[$k[$i]]) |
|
32 |
{ |
|
33 |
$ns = $k[$i]; |
|
34 |
$pg = substr($string, strlen($paths->nslist[$ns]), strlen($string)); |
|
35 |
} |
|
36 |
} |
|
37 |
return Array($pg, $ns); |
|
38 |
} |
|
39 |
||
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
|
40 |
public static function getPage($page_id, $namespace, $wiki = 1, $smilies = true, $filter_links = true, $redir = true, $render = true) |
1 | 41 |
{ |
42 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
43 |
||
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
44 |
$page = new PageProcessor($page_id, $namespace); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
45 |
$text = $page->fetch_text(); |
1 | 46 |
|
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
47 |
if ( !$render ) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
48 |
return $text; |
1 | 49 |
|
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
50 |
$text = self::render($text, $wiki, $smilies, $filter_links); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
51 |
return $text; |
1 | 52 |
} |
53 |
||
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
|
54 |
public static function getTemplate($id, $parms) |
1 | 55 |
{ |
56 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
953
323c4cd1aa37
Made some more changes to the way namespaces are handled, for optimization purposes. This is a bit of a structural reorganization: $paths->pages is obsoleted in its entirety; calculating page existence and metadata is now the job of the Namespace_* backend class. There are many things in PageProcessor that should be reorganized, and page actions in general should really be rethought. This is probably the beginning of a long process that will be taking place over the course of the betas.
Dan
parents:
832
diff
changeset
|
57 |
if ( !isPage($paths->get_pathskey($id, 'Template')) ) |
1 | 58 |
{ |
59 |
return '[['.$paths->nslist['Template'].$id.']]'; |
|
60 |
} |
|
61 |
if(isset($paths->template_cache[$id])) |
|
62 |
{ |
|
63 |
$text = $paths->template_cache[$id]; |
|
64 |
} |
|
65 |
else |
|
66 |
{ |
|
953
323c4cd1aa37
Made some more changes to the way namespaces are handled, for optimization purposes. This is a bit of a structural reorganization: $paths->pages is obsoleted in its entirety; calculating page existence and metadata is now the job of the Namespace_* backend class. There are many things in PageProcessor that should be reorganized, and page actions in general should really be rethought. This is probably the beginning of a long process that will be taking place over the course of the betas.
Dan
parents:
832
diff
changeset
|
67 |
$page = new PageProcessor($id, 'Template'); |
323c4cd1aa37
Made some more changes to the way namespaces are handled, for optimization purposes. This is a bit of a structural reorganization: $paths->pages is obsoleted in its entirety; calculating page existence and metadata is now the job of the Namespace_* backend class. There are many things in PageProcessor that should be reorganized, and page actions in general should really be rethought. This is probably the beginning of a long process that will be taking place over the course of the betas.
Dan
parents:
832
diff
changeset
|
68 |
$text = $page->fetch_text(); |
1 | 69 |
$paths->template_cache[$id] = $text; |
70 |
} |
|
71 |
||
72 |
$text = preg_replace('/<noinclude>(.*?)<\/noinclude>/is', '', $text); |
|
73 |
$text = preg_replace('/<nodisplay>(.*?)<\/nodisplay>/is', '\\1', $text); |
|
74 |
||
75 |
preg_match_all('#\(_([0-9]+)_\)#', $text, $matchlist); |
|
76 |
||
77 |
foreach($matchlist[1] as $m) |
|
78 |
{ |
|
79 |
if(isset($parms[((int)$m)+1])) |
|
80 |
{ |
|
81 |
$p = $parms[((int)$m)+1]; |
|
82 |
} |
|
83 |
else |
|
84 |
{ |
|
85 |
$p = '<b>Notice:</b> RenderMan::getTemplate(): Parameter '.$m.' is not set'; |
|
86 |
} |
|
87 |
$text = str_replace('(_'.$m.'_)', $p, $text); |
|
717
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
88 |
$text = str_replace('{{' . ( $m + 1 ) . '}}', $p, $text); |
1 | 89 |
} |
90 |
$text = RenderMan::include_templates($text); |
|
91 |
return $text; |
|
92 |
} |
|
93 |
||
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
|
94 |
public static function fetch_template_text($id) |
1 | 95 |
{ |
96 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
745
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
97 |
$fetch_ns = 'Template'; |
953
323c4cd1aa37
Made some more changes to the way namespaces are handled, for optimization purposes. This is a bit of a structural reorganization: $paths->pages is obsoleted in its entirety; calculating page existence and metadata is now the job of the Namespace_* backend class. There are many things in PageProcessor that should be reorganized, and page actions in general should really be rethought. This is probably the beginning of a long process that will be taking place over the course of the betas.
Dan
parents:
832
diff
changeset
|
98 |
if ( !isPage($paths->get_pathskey($id, 'Template')) ) |
1 | 99 |
{ |
745
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
100 |
// Transclusion of another page |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
101 |
// 1.1.5: Now You, Too, Can Be A Template, Even If You're Just A Plain Old Article! (TM) |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
102 |
$nssep = substr($paths->nslist['Special'], -1); |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
103 |
$nslist = $paths->nslist; |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
104 |
foreach ( $nslist as &$ns ) |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
105 |
{ |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
106 |
if ( $ns == '' ) |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
107 |
$ns = $nssep; |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
108 |
} |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
109 |
$prefixlist = array_flip($nslist); |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
110 |
foreach ( $nslist as &$ns ) |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
111 |
{ |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
112 |
$ns = preg_quote($ns); |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
113 |
} |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
114 |
$nslist = implode('|', $nslist); |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
115 |
if ( preg_match("/^($nslist)(.*?)$/", $id, $match) ) |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
116 |
{ |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
117 |
// in practice this should always be true but just to be safe... |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
118 |
if ( isset($prefixlist[$match[1]]) ) |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
119 |
{ |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
120 |
$new_id = $paths->nslist[ $prefixlist[$match[1]] ] . sanitize_page_id($match[2]); |
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
121 |
if ( !isPage($new_id) ) |
745
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
122 |
{ |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
123 |
return "[[$new_id]]"; |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
124 |
} |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
125 |
$fetch_ns = $prefixlist[$match[1]]; |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
126 |
$id = sanitize_page_id($match[2]); |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
127 |
} |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
128 |
} |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
129 |
else |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
130 |
{ |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
131 |
return '[['.$paths->nslist['Template'].$id.']]'; |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
132 |
} |
1 | 133 |
} |
134 |
if(isset($paths->template_cache[$id])) |
|
135 |
{ |
|
136 |
$text = $paths->template_cache[$id]; |
|
137 |
} |
|
138 |
else |
|
139 |
{ |
|
745
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
140 |
$text = RenderMan::getPage($id, $fetch_ns, 0, false, false, false, false); |
1 | 141 |
$paths->template_cache[$id] = $text; |
142 |
} |
|
143 |
||
144 |
if ( is_string($text) ) |
|
145 |
{ |
|
146 |
$text = preg_replace('/<noinclude>(.*?)<\/noinclude>/is', '', $text); |
|
147 |
$text = preg_replace('/<nodisplay>(.*?)<\/nodisplay>/is', '\\1', $text); |
|
148 |
} |
|
149 |
||
150 |
return $text; |
|
151 |
} |
|
152 |
||
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
153 |
/** |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
154 |
* Renders a glob of text. Note that this is PHP-safe, so if returned text (or rather, "?>" . $returned) has PHP it can be eval'ed. |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
155 |
* @param string Text to render |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
156 |
* @param int Render parameters - see constants.php |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
157 |
* @return string Rendered text |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
158 |
*/ |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
159 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
160 |
public static function render($text, $flags = RENDER_WIKI_DEFAULT, $smilies = true) |
1 | 161 |
{ |
162 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
163 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
164 |
if ( !$smilies ) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
165 |
$flags |= RENDER_NOSMILIES; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
166 |
|
1108
c1be67a50d81
Removed the $userpage parameter from Namespace_Default::error_404(). It screwed up a couple plugins. (Thanks Mazza for discovering the issue)
Dan
parents:
1098
diff
changeset
|
167 |
if ( !($flags & RENDER_NOSMILIES) ) |
1 | 168 |
{ |
169 |
$text = RenderMan::smilieyize($text); |
|
170 |
} |
|
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
171 |
if ( $flags & RENDER_WIKI_DEFAULT ) |
1 | 172 |
{ |
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
173 |
$text = RenderMan::next_gen_wiki_format($text, $flags); |
1 | 174 |
} |
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
175 |
else if ( $flags & RENDER_WIKI_TEMPLATE ) |
1 | 176 |
{ |
177 |
$text = $template->tplWikiFormat($text); |
|
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
178 |
} |
1 | 179 |
return $text; |
180 |
} |
|
181 |
||
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
182 |
private static function next_gen_wiki_format($text, $flags = 0) |
1 | 183 |
{ |
184 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
377
bb3e6c3bd4f4
Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
parents:
371
diff
changeset
|
185 |
global $lang; |
bb3e6c3bd4f4
Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
parents:
371
diff
changeset
|
186 |
|
1027
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
187 |
profiler_log("RenderMan: starting wikitext render"); |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
188 |
require_once( ENANO_ROOT . '/includes/wikiformat.php' ); |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
189 |
require_once( ENANO_ROOT . '/includes/wikiengine/TagSanitizer.php' ); |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
190 |
require_once( ENANO_ROOT . '/includes/wikiengine/Tables.php' ); |
592 | 191 |
|
1027
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
192 |
// this is still needed by parser plugins |
1 | 193 |
$random_id = md5( time() . mt_rand() ); |
194 |
||
1044
ad6a22377507
Wiki engine: improved behavior in block level element finding/wrapping algorithm
Dan
parents:
1027
diff
changeset
|
195 |
// Strip out <nowiki> sections |
1027
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
196 |
self::nowiki_strip($text, $nowiki_stripped); |
407
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
197 |
|
1044
ad6a22377507
Wiki engine: improved behavior in block level element finding/wrapping algorithm
Dan
parents:
1027
diff
changeset
|
198 |
// Run early parsing plugins |
407
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
199 |
$code = $plugins->setHook('render_wikiformat_veryearly'); |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
200 |
foreach ( $code as $cmd ) |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
201 |
{ |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
202 |
eval($cmd); |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
203 |
} |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
204 |
|
1044
ad6a22377507
Wiki engine: improved behavior in block level element finding/wrapping algorithm
Dan
parents:
1027
diff
changeset
|
205 |
// Strip out embedded PHP |
1027
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
206 |
self::php_strip($text, $php_stripped); |
1 | 207 |
|
1066
bead71f28f63
Fixed some formatter engine errors that were exposed through the wiki edit notice
Dan
parents:
1054
diff
changeset
|
208 |
// Convert newlines for the parser |
bead71f28f63
Fixed some formatter engine errors that were exposed through the wiki edit notice
Dan
parents:
1054
diff
changeset
|
209 |
$text = str_replace("\r\n", "\n", $text); |
bead71f28f63
Fixed some formatter engine errors that were exposed through the wiki edit notice
Dan
parents:
1054
diff
changeset
|
210 |
|
1044
ad6a22377507
Wiki engine: improved behavior in block level element finding/wrapping algorithm
Dan
parents:
1027
diff
changeset
|
211 |
// Perform render through the engine |
1027
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
212 |
$carpenter = new Carpenter(); |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
213 |
$carpenter->flags = $flags; |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
214 |
$carpenter->hook(array(__CLASS__, 'hook_pre'), PO_AFTER, 'lang'); |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
215 |
$carpenter->hook(array(__CLASS__, 'hook_posttemplates'), PO_AFTER, 'templates'); |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
216 |
if ( $flags & RENDER_WIKI_TEMPLATE ) |
1 | 217 |
{ |
1044
ad6a22377507
Wiki engine: improved behavior in block level element finding/wrapping algorithm
Dan
parents:
1027
diff
changeset
|
218 |
// FIXME: Where is noinclude/nodisplay being processed in the pipeline? (Seems to be processed, but not here) |
1027
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
219 |
} |
1108
c1be67a50d81
Removed the $userpage parameter from Namespace_Default::error_404(). It screwed up a couple plugins. (Thanks Mazza for discovering the issue)
Dan
parents:
1098
diff
changeset
|
220 |
|
c1be67a50d81
Removed the $userpage parameter from Namespace_Default::error_404(). It screwed up a couple plugins. (Thanks Mazza for discovering the issue)
Dan
parents:
1098
diff
changeset
|
221 |
// |
c1be67a50d81
Removed the $userpage parameter from Namespace_Default::error_404(). It screwed up a couple plugins. (Thanks Mazza for discovering the issue)
Dan
parents:
1098
diff
changeset
|
222 |
// Set rules for the rendering process |
c1be67a50d81
Removed the $userpage parameter from Namespace_Default::error_404(). It screwed up a couple plugins. (Thanks Mazza for discovering the issue)
Dan
parents:
1098
diff
changeset
|
223 |
// |
c1be67a50d81
Removed the $userpage parameter from Namespace_Default::error_404(). It screwed up a couple plugins. (Thanks Mazza for discovering the issue)
Dan
parents:
1098
diff
changeset
|
224 |
|
c1be67a50d81
Removed the $userpage parameter from Namespace_Default::error_404(). It screwed up a couple plugins. (Thanks Mazza for discovering the issue)
Dan
parents:
1098
diff
changeset
|
225 |
if ( $flags & RENDER_BLOCK && !($flags & RENDER_INLINE) ) |
c1be67a50d81
Removed the $userpage parameter from Namespace_Default::error_404(). It screwed up a couple plugins. (Thanks Mazza for discovering the issue)
Dan
parents:
1098
diff
changeset
|
226 |
{ |
c1be67a50d81
Removed the $userpage parameter from Namespace_Default::error_404(). It screwed up a couple plugins. (Thanks Mazza for discovering the issue)
Dan
parents:
1098
diff
changeset
|
227 |
// block only |
c1be67a50d81
Removed the $userpage parameter from Namespace_Default::error_404(). It screwed up a couple plugins. (Thanks Mazza for discovering the issue)
Dan
parents:
1098
diff
changeset
|
228 |
$carpenter->disable_all_rules(); |
c1be67a50d81
Removed the $userpage parameter from Namespace_Default::error_404(). It screwed up a couple plugins. (Thanks Mazza for discovering the issue)
Dan
parents:
1098
diff
changeset
|
229 |
foreach ( array('blockquote', 'tables', 'heading', 'hr', 'multilist', 'bold', 'italic', 'underline', 'paragraph', 'blockquotepost') as $rule ) |
c1be67a50d81
Removed the $userpage parameter from Namespace_Default::error_404(). It screwed up a couple plugins. (Thanks Mazza for discovering the issue)
Dan
parents:
1098
diff
changeset
|
230 |
{ |
c1be67a50d81
Removed the $userpage parameter from Namespace_Default::error_404(). It screwed up a couple plugins. (Thanks Mazza for discovering the issue)
Dan
parents:
1098
diff
changeset
|
231 |
$carpenter->enable_rule($rule); |
c1be67a50d81
Removed the $userpage parameter from Namespace_Default::error_404(). It screwed up a couple plugins. (Thanks Mazza for discovering the issue)
Dan
parents:
1098
diff
changeset
|
232 |
} |
c1be67a50d81
Removed the $userpage parameter from Namespace_Default::error_404(). It screwed up a couple plugins. (Thanks Mazza for discovering the issue)
Dan
parents:
1098
diff
changeset
|
233 |
|
c1be67a50d81
Removed the $userpage parameter from Namespace_Default::error_404(). It screwed up a couple plugins. (Thanks Mazza for discovering the issue)
Dan
parents:
1098
diff
changeset
|
234 |
$code = $plugins->setHook('render_block_only'); |
c1be67a50d81
Removed the $userpage parameter from Namespace_Default::error_404(). It screwed up a couple plugins. (Thanks Mazza for discovering the issue)
Dan
parents:
1098
diff
changeset
|
235 |
foreach ( $code as $cmd ) |
c1be67a50d81
Removed the $userpage parameter from Namespace_Default::error_404(). It screwed up a couple plugins. (Thanks Mazza for discovering the issue)
Dan
parents:
1098
diff
changeset
|
236 |
{ |
c1be67a50d81
Removed the $userpage parameter from Namespace_Default::error_404(). It screwed up a couple plugins. (Thanks Mazza for discovering the issue)
Dan
parents:
1098
diff
changeset
|
237 |
eval($cmd); |
c1be67a50d81
Removed the $userpage parameter from Namespace_Default::error_404(). It screwed up a couple plugins. (Thanks Mazza for discovering the issue)
Dan
parents:
1098
diff
changeset
|
238 |
} |
c1be67a50d81
Removed the $userpage parameter from Namespace_Default::error_404(). It screwed up a couple plugins. (Thanks Mazza for discovering the issue)
Dan
parents:
1098
diff
changeset
|
239 |
} |
c1be67a50d81
Removed the $userpage parameter from Namespace_Default::error_404(). It screwed up a couple plugins. (Thanks Mazza for discovering the issue)
Dan
parents:
1098
diff
changeset
|
240 |
else if ( $flags & RENDER_INLINE && !($flags & RENDER_BLOCK) ) |
c1be67a50d81
Removed the $userpage parameter from Namespace_Default::error_404(). It screwed up a couple plugins. (Thanks Mazza for discovering the issue)
Dan
parents:
1098
diff
changeset
|
241 |
{ |
c1be67a50d81
Removed the $userpage parameter from Namespace_Default::error_404(). It screwed up a couple plugins. (Thanks Mazza for discovering the issue)
Dan
parents:
1098
diff
changeset
|
242 |
// inline only |
c1be67a50d81
Removed the $userpage parameter from Namespace_Default::error_404(). It screwed up a couple plugins. (Thanks Mazza for discovering the issue)
Dan
parents:
1098
diff
changeset
|
243 |
$carpenter->disable_all_rules(); |
c1be67a50d81
Removed the $userpage parameter from Namespace_Default::error_404(). It screwed up a couple plugins. (Thanks Mazza for discovering the issue)
Dan
parents:
1098
diff
changeset
|
244 |
foreach ( array('bold', 'italic', 'underline', 'externalwithtext', 'externalnotext', 'image', 'internallink') as $rule ) |
c1be67a50d81
Removed the $userpage parameter from Namespace_Default::error_404(). It screwed up a couple plugins. (Thanks Mazza for discovering the issue)
Dan
parents:
1098
diff
changeset
|
245 |
{ |
c1be67a50d81
Removed the $userpage parameter from Namespace_Default::error_404(). It screwed up a couple plugins. (Thanks Mazza for discovering the issue)
Dan
parents:
1098
diff
changeset
|
246 |
$carpenter->enable_rule($rule); |
c1be67a50d81
Removed the $userpage parameter from Namespace_Default::error_404(). It screwed up a couple plugins. (Thanks Mazza for discovering the issue)
Dan
parents:
1098
diff
changeset
|
247 |
} |
c1be67a50d81
Removed the $userpage parameter from Namespace_Default::error_404(). It screwed up a couple plugins. (Thanks Mazza for discovering the issue)
Dan
parents:
1098
diff
changeset
|
248 |
|
c1be67a50d81
Removed the $userpage parameter from Namespace_Default::error_404(). It screwed up a couple plugins. (Thanks Mazza for discovering the issue)
Dan
parents:
1098
diff
changeset
|
249 |
$code = $plugins->setHook('render_inline_only'); |
c1be67a50d81
Removed the $userpage parameter from Namespace_Default::error_404(). It screwed up a couple plugins. (Thanks Mazza for discovering the issue)
Dan
parents:
1098
diff
changeset
|
250 |
foreach ( $code as $cmd ) |
c1be67a50d81
Removed the $userpage parameter from Namespace_Default::error_404(). It screwed up a couple plugins. (Thanks Mazza for discovering the issue)
Dan
parents:
1098
diff
changeset
|
251 |
{ |
c1be67a50d81
Removed the $userpage parameter from Namespace_Default::error_404(). It screwed up a couple plugins. (Thanks Mazza for discovering the issue)
Dan
parents:
1098
diff
changeset
|
252 |
eval($cmd); |
c1be67a50d81
Removed the $userpage parameter from Namespace_Default::error_404(). It screwed up a couple plugins. (Thanks Mazza for discovering the issue)
Dan
parents:
1098
diff
changeset
|
253 |
} |
c1be67a50d81
Removed the $userpage parameter from Namespace_Default::error_404(). It screwed up a couple plugins. (Thanks Mazza for discovering the issue)
Dan
parents:
1098
diff
changeset
|
254 |
} |
c1be67a50d81
Removed the $userpage parameter from Namespace_Default::error_404(). It screwed up a couple plugins. (Thanks Mazza for discovering the issue)
Dan
parents:
1098
diff
changeset
|
255 |
else |
c1be67a50d81
Removed the $userpage parameter from Namespace_Default::error_404(). It screwed up a couple plugins. (Thanks Mazza for discovering the issue)
Dan
parents:
1098
diff
changeset
|
256 |
{ |
c1be67a50d81
Removed the $userpage parameter from Namespace_Default::error_404(). It screwed up a couple plugins. (Thanks Mazza for discovering the issue)
Dan
parents:
1098
diff
changeset
|
257 |
// full render |
c1be67a50d81
Removed the $userpage parameter from Namespace_Default::error_404(). It screwed up a couple plugins. (Thanks Mazza for discovering the issue)
Dan
parents:
1098
diff
changeset
|
258 |
$code = $plugins->setHook('render_full'); |
c1be67a50d81
Removed the $userpage parameter from Namespace_Default::error_404(). It screwed up a couple plugins. (Thanks Mazza for discovering the issue)
Dan
parents:
1098
diff
changeset
|
259 |
foreach ( $code as $cmd ) |
c1be67a50d81
Removed the $userpage parameter from Namespace_Default::error_404(). It screwed up a couple plugins. (Thanks Mazza for discovering the issue)
Dan
parents:
1098
diff
changeset
|
260 |
{ |
c1be67a50d81
Removed the $userpage parameter from Namespace_Default::error_404(). It screwed up a couple plugins. (Thanks Mazza for discovering the issue)
Dan
parents:
1098
diff
changeset
|
261 |
eval($cmd); |
c1be67a50d81
Removed the $userpage parameter from Namespace_Default::error_404(). It screwed up a couple plugins. (Thanks Mazza for discovering the issue)
Dan
parents:
1098
diff
changeset
|
262 |
} |
c1be67a50d81
Removed the $userpage parameter from Namespace_Default::error_404(). It screwed up a couple plugins. (Thanks Mazza for discovering the issue)
Dan
parents:
1098
diff
changeset
|
263 |
} |
1027
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
264 |
$text = $carpenter->render($text); |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
265 |
|
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
266 |
// For plugin compat |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
267 |
$result =& $text; |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
268 |
|
1044
ad6a22377507
Wiki engine: improved behavior in block level element finding/wrapping algorithm
Dan
parents:
1027
diff
changeset
|
269 |
// Post processing hook |
1027
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
270 |
$code = $plugins->setHook('render_wikiformat_post'); |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
271 |
foreach ( $code as $cmd ) |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
272 |
{ |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
273 |
eval($cmd); |
1 | 274 |
} |
275 |
||
1044
ad6a22377507
Wiki engine: improved behavior in block level element finding/wrapping algorithm
Dan
parents:
1027
diff
changeset
|
276 |
// Add PHP and nowiki back in |
1027
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
277 |
self::nowiki_unstrip($text, $nowiki_stripped); |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
278 |
self::php_unstrip($text, $php_stripped); |
1 | 279 |
|
382
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
parents:
377
diff
changeset
|
280 |
profiler_log("RenderMan: finished wikitext render"); |
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
parents:
377
diff
changeset
|
281 |
|
1027
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
282 |
return $text; |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
283 |
} |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
284 |
|
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
285 |
public static function hook_pre($text) |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
286 |
{ |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
287 |
global $db, $session, $paths, $template, $plugins; // Common objects |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
288 |
|
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
289 |
$code = $plugins->setHook('render_wikiformat_pre'); |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
290 |
foreach ( $code as $cmd ) |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
291 |
{ |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
292 |
eval($cmd); |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
293 |
} |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
294 |
|
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
295 |
return $text; |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
296 |
} |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
297 |
|
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
298 |
public static function hook_posttemplates($text) |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
299 |
{ |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
300 |
global $db, $session, $paths, $template, $plugins; // Common objects |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
301 |
|
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
302 |
$code = $plugins->setHook('render_wikiformat_posttemplates'); |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
303 |
foreach ( $code as $cmd ) |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
304 |
{ |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
305 |
eval($cmd); |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
306 |
} |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
307 |
|
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
308 |
return $text; |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
309 |
} |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
310 |
|
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
311 |
/** |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
312 |
* Strip out <nowiki> tags (to bypass parsing on them) |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
313 |
* @access private |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
314 |
*/ |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
315 |
|
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
316 |
private static function nowiki_strip(&$text, &$stripdata) |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
317 |
{ |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
318 |
self::tag_strip('nowiki', $text, $stripdata); |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
319 |
} |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
320 |
|
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
321 |
/** |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
322 |
* Restore stripped <nowiki> tags. |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
323 |
* @access private |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
324 |
*/ |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
325 |
|
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
326 |
public static function nowiki_unstrip(&$text, &$stripdata) |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
327 |
{ |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
328 |
self::tag_unstrip('nowiki', $text, $stripdata); |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
329 |
} |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
330 |
|
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
331 |
/** |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
332 |
* Strip out an arbitrary HTML tag. |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
333 |
* @access private |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
334 |
*/ |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
335 |
|
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
336 |
public static function tag_strip($tag, &$text, &$stripdata) |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
337 |
{ |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
338 |
$random_id = md5( time() . mt_rand() ); |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
339 |
|
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
340 |
preg_match_all("#<$tag>(.*?)</$tag>#is", $text, $blocks); |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
341 |
|
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
342 |
foreach ( $blocks[0] as $i => $match ) |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
343 |
{ |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
344 |
$text = str_replace($match, "{{$tag}:{$random_id}:{$i}}", $text); |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
345 |
} |
1 | 346 |
|
1027
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
347 |
$stripdata = array( |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
348 |
'random_id' => $random_id, |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
349 |
'blocks' => $blocks[1] |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
350 |
); |
1 | 351 |
} |
352 |
||
1027
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
353 |
/** |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
354 |
* Restore stripped <nowiki> tags. |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
355 |
* @access private |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
356 |
*/ |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
357 |
|
1073
b19a9bcb6a45
More work on rendering engine. Fixed some bugs with paragraph skipping and added (incomplete) support for blockquotes.
Dan
parents:
1066
diff
changeset
|
358 |
public static function tag_unstrip($tag, &$text, &$stripdata, $keep = false) |
1027
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
359 |
{ |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
360 |
$random_id = $stripdata['random_id']; |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
361 |
|
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
362 |
foreach ( $stripdata['blocks'] as $i => $block ) |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
363 |
{ |
1073
b19a9bcb6a45
More work on rendering engine. Fixed some bugs with paragraph skipping and added (incomplete) support for blockquotes.
Dan
parents:
1066
diff
changeset
|
364 |
$block = $keep ? "<$tag>$block</$tag>" : $block; |
1027
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
365 |
$text = str_replace("{{$tag}:{$random_id}:{$i}}", $block, $text); |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
366 |
} |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
367 |
|
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
368 |
$stripdata = array(); |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
369 |
} |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
370 |
|
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
371 |
/** |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
372 |
* Strip out PHP code (to prevent it from being sent through the parser). Private because it does not do what you think it does. (The method you are looking for is strip_php.) |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
373 |
* @access private |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
374 |
*/ |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
375 |
|
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
376 |
private static function php_strip(&$text, &$stripdata) |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
377 |
{ |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
378 |
$random_id = md5( time() . mt_rand() ); |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
379 |
|
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
380 |
preg_match_all('#<\?(?:php)?[\s=].+?\?>#is', $text, $blocks); |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
381 |
|
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
382 |
foreach ( $blocks[0] as $i => $match ) |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
383 |
{ |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
384 |
$text = str_replace($match, "{PHP:$random_id:$i}", $text); |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
385 |
} |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
386 |
|
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
387 |
$stripdata = array( |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
388 |
'random_id' => $random_id, |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
389 |
'blocks' => $blocks[0] |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
390 |
); |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
391 |
} |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
392 |
|
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
393 |
/** |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
394 |
* Restore stripped PHP code |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
395 |
* @access private |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
396 |
*/ |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
397 |
|
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
398 |
private static function php_unstrip(&$text, &$stripdata) |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
399 |
{ |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
400 |
$random_id = $stripdata['random_id']; |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
401 |
|
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
402 |
foreach ( $stripdata['blocks'] as $i => $block ) |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
403 |
{ |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
404 |
$text = str_replace("{PHP:$random_id:$i}", $block, $text); |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
405 |
} |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
406 |
|
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
407 |
$stripdata = array(); |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
408 |
} |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
409 |
|
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
410 |
/** |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
411 |
* Deprecated. |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
412 |
*/ |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
413 |
|
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
|
414 |
public static function wikiFormat($message, $filter_links = true, $do_params = false, $plaintext = false) |
163 | 415 |
{ |
1 | 416 |
global $db, $session, $paths, $template, $plugins; // Common objects |
417 |
||
418 |
return RenderMan::next_gen_wiki_format($message, $plaintext, $filter_links, $do_params); |
|
419 |
} |
|
420 |
||
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
|
421 |
public static function destroy_javascript($message, $_php = false) |
1 | 422 |
{ |
423 |
$message = preg_replace('#<(script|object|applet|embed|iframe|frame|form|input|select)(.*?)>#is', '<\\1\\2>', $message); |
|
424 |
$message = preg_replace('#</(script|object|applet|embed|iframe|frame|form|input|select)(.*?)>#is', '</\\1\\2>', $message); |
|
425 |
$message = preg_replace('#(javascript|script|activex|chrome|about|applet):#is', '\\1:', $message); |
|
426 |
if ( $_php ) |
|
427 |
{ |
|
428 |
// Left in only for compatibility |
|
429 |
$message = preg_replace('#<(.*?)>#is', '<\\1>', $message); |
|
430 |
$message = preg_replace('#<(.*?)>#is', '<\\1>', $message); |
|
431 |
$message = preg_replace('#<(\?|\?php|%)(.*?)(\?|%)>#is', '<\\1\\2\\3>', $message); |
|
432 |
// strip <a href="foo" onclick="bar();">-type attacks |
|
433 |
$message = preg_replace('#<([a-zA-Z:\-]+) (.*?)on([A-Za-z]*)=(.*?)>#is', '<\\1\\2on\\3=\\4>', $message); |
|
434 |
} |
|
435 |
return $message; |
|
436 |
} |
|
437 |
||
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
|
438 |
public static function strip_php($message) |
1 | 439 |
{ |
440 |
return RenderMan::destroy_javascript($message, true); |
|
441 |
} |
|
442 |
||
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
|
443 |
public static function sanitize_html($text) |
1 | 444 |
{ |
445 |
$text = htmlspecialchars($text); |
|
91 | 446 |
$allowed_tags = Array('b', 'i', 'u', 'pre', 'code', 'tt', 'br', 'p', 'nowiki', '!--([\w\W]+)--'); |
1 | 447 |
foreach($allowed_tags as $t) |
448 |
{ |
|
449 |
$text = preg_replace('#<'.$t.'>(.*?)</'.$t.'>#is', '<'.$t.'>\\1</'.$t.'>', $text); |
|
450 |
$text = preg_replace('#<'.$t.' />#is', '<'.$t.' />', $text); |
|
451 |
$text = preg_replace('#<'.$t.'>#is', '<'.$t.'>', $text); |
|
452 |
} |
|
453 |
return $text; |
|
454 |
} |
|
455 |
||
91 | 456 |
/** |
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
457 |
* Reverse-renders a blob of text (converts it from XHTML back to wikitext) by using parser hints and educated guesses. |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
458 |
* @param string XHTML |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
459 |
* @return string Wikitext |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
460 |
*/ |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
461 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
462 |
public static function reverse_render($text) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
463 |
{ |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
464 |
// convert \r\n to \n |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
465 |
$text = str_replace("\r\n", "\n", $text); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
466 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
467 |
// Separate certain block level elements onto their own lines. This tidies up the tag |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
468 |
// soup that TinyMCE sometimes produces. |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
469 |
$block_elements = array('h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'div', 'table', 'ul', 'pre'); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
470 |
$block_elements = implode('|', $block_elements); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
471 |
$regex = "#(</(?:$block_elements)>)\n?<($block_elements)(>| .+?>)#i"; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
472 |
$text = preg_replace($regex, "$1\n\n<$2$3", $text); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
473 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
474 |
$text = self::reverse_process_parser_hints($text); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
475 |
$text = self::reverse_process_headings($text); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
476 |
$text = self::reverse_process_lists($text); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
477 |
$text = self::reverse_process_tables($text); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
478 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
479 |
// Lastly, strip out paragraph tags. |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
480 |
$text = preg_replace('|^ *<p>(.+?)</p> *$|m', "\\1", $text); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
481 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
482 |
return $text; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
483 |
} |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
484 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
485 |
public static function reverse_process_parser_hints($text) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
486 |
{ |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
487 |
global $db, $session, $paths, $template, $plugins; // Common objects |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
488 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
489 |
if ( !preg_match_all('|<!--#([a-z0-9_]+)(?: (.+?))?-->([\w\W]*?)<!--#/\\1-->|s', $text, $matches) ) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
490 |
return $text; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
491 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
492 |
foreach ( $matches[0] as $i => $match ) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
493 |
{ |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
494 |
$tag =& $matches[1][$i]; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
495 |
$attribs =& $matches[2][$i]; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
496 |
$inner =& $matches[3][$i]; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
497 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
498 |
$attribs = self::reverse_process_hint_attribs($attribs); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
499 |
switch($tag) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
500 |
{ |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
501 |
case 'smiley': |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
502 |
case 'internallink': |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
503 |
case 'imagelink': |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
504 |
if ( isset($attribs['code']) ) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
505 |
{ |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
506 |
$text = str_replace($match, $attribs['code'], $text); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
507 |
} |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
508 |
else if ( isset($attribs['src']) ) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
509 |
{ |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
510 |
$text = str_replace($match, $attribs['src'], $text); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
511 |
} |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
512 |
break; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
513 |
} |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
514 |
} |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
515 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
516 |
return $text; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
517 |
} |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
518 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
519 |
public static function reverse_process_hint_attribs($attribs) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
520 |
{ |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
521 |
$return = array(); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
522 |
if ( !preg_match_all('/([a-z0-9_-]+)="([^"]+?)"/', $attribs, $matches) ) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
523 |
return array(); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
524 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
525 |
foreach ( $matches[0] as $i => $match ) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
526 |
{ |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
527 |
$name =& $matches[1][$i]; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
528 |
$value =& $matches[2][$i]; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
529 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
530 |
$value = base64_decode($value); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
531 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
532 |
$return[$name] = $value; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
533 |
} |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
534 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
535 |
return $return; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
536 |
} |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
537 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
538 |
/** |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
539 |
* Escapes a string so that it's safe to use as an attribute in a parser hint. |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
540 |
* @param string |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
541 |
* @return string |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
542 |
*/ |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
543 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
544 |
public static function escape_parser_hint_attrib($text) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
545 |
{ |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
546 |
return base64_encode($text); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
547 |
} |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
548 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
549 |
public static function reverse_process_headings($text) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
550 |
{ |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
551 |
if ( !preg_match_all('|^<h([1-6])(?: id="toc[0-9]+")?>(.*?)</h\\1>$|m', $text, $matches) ) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
552 |
return $text; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
553 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
554 |
foreach ( $matches[0] as $i => $match ) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
555 |
{ |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
556 |
// generate heading tag |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
557 |
$heading_size = intval($matches[1][$i]); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
558 |
$eq = ''; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
559 |
for ( $j = 0; $j < $heading_size; $j++ ) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
560 |
$eq .= '='; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
561 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
562 |
$heading =& $matches[2][$i]; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
563 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
564 |
$tag = "$eq $heading $eq"; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
565 |
$text = str_replace($match, $tag, $text); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
566 |
} |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
567 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
568 |
return $text; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
569 |
} |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
570 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
571 |
public static function reverse_process_lists($text) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
572 |
{ |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
573 |
if ( !preg_match('!(</?(?:ul|ol|li)>)!', $text) ) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
574 |
return $text; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
575 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
576 |
$split = preg_split('!(</?(?:ul|ol|li)>)!', $text, -1, PREG_SPLIT_DELIM_CAPTURE); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
577 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
578 |
$stack_height = 0; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
579 |
$current_list = ''; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
580 |
$old_current_list = ''; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
581 |
$spaces = ''; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
582 |
$marker = '*'; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
583 |
$list_id = 0; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
584 |
$just_terminated = false; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
585 |
foreach ( $split as $tag ) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
586 |
{ |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
587 |
switch($tag) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
588 |
{ |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
589 |
case '<ul>': |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
590 |
case '<ol>': |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
591 |
$stack_height++; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
592 |
$just_terminated = false; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
593 |
if ( $stack_height > 1 ) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
594 |
$spaces .= $marker; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
595 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
596 |
$marker = ( $tag == 'ol' ) ? '#' : '*'; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
597 |
if ( $stack_height > 1 ) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
598 |
$current_list .= "\n"; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
599 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
600 |
break; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
601 |
case '</ul>': |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
602 |
case '</ol>': |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
603 |
$stack_height--; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
604 |
$spaces = substr($spaces, 1); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
605 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
606 |
if ( $stack_height == 0 ) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
607 |
{ |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
608 |
// rotate |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
609 |
$text = str_replace_once("{$old_current_list}{$tag}", trim($current_list), $text); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
610 |
$current_list = ''; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
611 |
$old_current_list = ''; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
612 |
} |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
613 |
$just_terminated = true; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
614 |
break; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
615 |
case '<li>': |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
616 |
if ( $stack_height < 1 ) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
617 |
break; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
618 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
619 |
$current_list .= "{$spaces}{$marker} "; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
620 |
break; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
621 |
case '</li>': |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
622 |
if ( $stack_height < 1 ) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
623 |
break; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
624 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
625 |
if ( !$just_terminated ) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
626 |
$current_list .= "\n"; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
627 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
628 |
$just_terminated = false; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
629 |
break; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
630 |
default: |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
631 |
if ( $stack_height > 0 ) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
632 |
{ |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
633 |
$current_list .= trim($tag); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
634 |
} |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
635 |
break; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
636 |
} |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
637 |
if ( $stack_height > 0 ) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
638 |
{ |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
639 |
$old_current_list .= $tag; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
640 |
} |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
641 |
} |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
642 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
643 |
return $text; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
644 |
} |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
645 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
646 |
public static function reverse_process_tables($text) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
647 |
{ |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
648 |
return $text; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
649 |
} |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
650 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
651 |
/** |
91 | 652 |
* Parses internal links (wikilinks) in a block of text. |
653 |
* @param string Text to process |
|
592 | 654 |
* @param string Optional. If included will be used as a template instead of using the default syntax. |
971
bc8f3ab74e5e
Render / Template: No longer does exist checks for wikilinks on sidebar
Dan
parents:
953
diff
changeset
|
655 |
* @param bool If false, does not add wikilink-nonexistent or check for exsistence of pages. Can reduce DB queries; defualts to true. |
1003
28e2f75d66fd
Class "currentpage" is now added to all internal links, including sidebar buttons, if the link points to the current page.
Dan
parents:
971
diff
changeset
|
656 |
* @param string Page ID. If specified, class="currentpage" will be added to links if they match the given page ID and namespace |
28e2f75d66fd
Class "currentpage" is now added to all internal links, including sidebar buttons, if the link points to the current page.
Dan
parents:
971
diff
changeset
|
657 |
* @param string Namespace. If specified, class="currentpage" will be added to links if they match the given page ID and namespace |
91 | 658 |
* @return string |
659 |
*/ |
|
660 |
||
1003
28e2f75d66fd
Class "currentpage" is now added to all internal links, including sidebar buttons, if the link points to the current page.
Dan
parents:
971
diff
changeset
|
661 |
public static function parse_internal_links($text, $tplcode = false, $do_exist_check = true, $match_page_id = false, $match_namespace = false) |
91 | 662 |
{ |
136
f2ee42f026f7
Fix: internal links parsed with RenderMan::parse_internal_links() did not get namespaces prepended; added Project: alias namespace for internal links
Dan
parents:
133
diff
changeset
|
663 |
global $db, $session, $paths, $template, $plugins; // Common objects |
1098
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
664 |
|
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
665 |
$parser = is_string($tplcode) ? $template->makeParserText($tplcode) : false; |
592 | 666 |
|
1123
777f32ac6b7c
More blank-urlname bugfixes, this time involving internal links
Dan
parents:
1108
diff
changeset
|
667 |
// allow blank urlname? |
777f32ac6b7c
More blank-urlname bugfixes, this time involving internal links
Dan
parents:
1108
diff
changeset
|
668 |
$repeater = have_blank_urlname_page() ? '*' : '+'; |
777f32ac6b7c
More blank-urlname bugfixes, this time involving internal links
Dan
parents:
1108
diff
changeset
|
669 |
|
91 | 670 |
// stage 1 - links with alternate text |
1123
777f32ac6b7c
More blank-urlname bugfixes, this time involving internal links
Dan
parents:
1108
diff
changeset
|
671 |
preg_match_all('/\[\[([^\[\]<>\{\}\|]' . $repeater . ')\|(.+?)\]\]/', $text, $matches); |
91 | 672 |
foreach ( $matches[0] as $i => $match ) |
673 |
{ |
|
674 |
list($page_id, $namespace) = RenderMan::strToPageID($matches[1][$i]); |
|
1098
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
675 |
$link = self::generate_internal_link($namespace, $page_id, $matches[2][$i], $match, $parser, $do_exist_check, $match_page_id, $match_namespace); |
91 | 676 |
$text = str_replace($match, $link, $text); |
677 |
} |
|
678 |
||
679 |
// stage 2 - links with no alternate text |
|
1123
777f32ac6b7c
More blank-urlname bugfixes, this time involving internal links
Dan
parents:
1108
diff
changeset
|
680 |
preg_match_all('/\[\[([^\[\]<>\{\}\|]' . $repeater . ')\]\]/', $text, $matches); |
91 | 681 |
foreach ( $matches[0] as $i => $match ) |
682 |
{ |
|
683 |
list($page_id, $namespace) = RenderMan::strToPageID($matches[1][$i]); |
|
684 |
$pid_clean = $paths->nslist[$namespace] . sanitize_page_id($page_id); |
|
159
f7e83b6db3be
Fixed: RenderMan::parse_internal_links() problems with prepending Project: instead of Site_name: to project page alias-namespace links
Dan
parents:
142
diff
changeset
|
685 |
$inner_text = ( isPage($pid_clean) ) ? htmlspecialchars(get_page_title($pid_clean)) : htmlspecialchars($matches[1][$i]); |
1003
28e2f75d66fd
Class "currentpage" is now added to all internal links, including sidebar buttons, if the link points to the current page.
Dan
parents:
971
diff
changeset
|
686 |
|
1098
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
687 |
$link = self::generate_internal_link($namespace, $page_id, $inner_text, $match, $parser, $do_exist_check, $match_page_id, $match_namespace); |
91 | 688 |
|
689 |
$text = str_replace($match, $link, $text); |
|
690 |
} |
|
691 |
||
692 |
return $text; |
|
693 |
} |
|
694 |
||
1 | 695 |
/** |
1098
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
696 |
* Internal link generation function |
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
697 |
* @access private |
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
698 |
* @return string HTML |
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
699 |
*/ |
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
700 |
|
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
701 |
private static function generate_internal_link($namespace, $page_id, $inner_text, $match, $parser = false, $do_exist_check = true, $match_page_id = false, $match_namespace = false) |
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
702 |
{ |
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
703 |
global $db, $session, $paths, $template, $plugins; // Common objects |
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
704 |
|
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
705 |
if ( ($pos = strrpos($page_id, '#')) !== false ) |
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
706 |
{ |
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
707 |
$hash = substr($page_id, $pos); |
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
708 |
$page_id = substr($page_id, 0, $pos); |
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
709 |
} |
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
710 |
else |
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
711 |
{ |
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
712 |
$hash = ''; |
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
713 |
} |
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
714 |
|
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
715 |
if ( $namespace == 'Admin' ) |
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
716 |
{ |
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
717 |
// No linking directly to Admin pages! |
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
718 |
$get = 'module=' . $paths->nslist[$namespace] . sanitize_page_id($page_id); |
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
719 |
$pid_clean = $paths->nslist['Special'] . 'Administration'; |
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
720 |
$onclick = ' onclick="ajaxLoginNavTo(\'Special\', \'Administration\', USER_LEVEL_ADMIN, \'' . addslashes($get) . '\'); return false;"'; |
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
721 |
} |
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
722 |
else |
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
723 |
{ |
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
724 |
$get = false; |
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
725 |
$onclick = ''; |
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
726 |
$pid_clean = $paths->nslist[$namespace] . sanitize_page_id($page_id); |
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
727 |
} |
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
728 |
|
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
729 |
$url = makeUrl($pid_clean, $get, true) . $hash; |
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
730 |
$quot = '"'; |
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
731 |
$exists = ( ($do_exist_check && isPage($pid_clean)) || !$do_exist_check ) ? '' : ' class="wikilink-nonexistent"'; |
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
732 |
|
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
733 |
if ( $match_page_id && $match_namespace && $pid_clean === $paths->get_pathskey($match_page_id, $match_namespace) ) |
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
734 |
$exists .= ' class="currentpage"'; |
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
735 |
|
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
736 |
if ( $parser ) |
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
737 |
{ |
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
738 |
$parser->assign_vars(array( |
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
739 |
'HREF' => $url, |
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
740 |
'FLAGS' => $exists, |
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
741 |
'TEXT' => $inner_text |
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
742 |
)); |
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
743 |
$link = $parser->run(); |
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
744 |
} |
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
745 |
else |
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
746 |
{ |
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
747 |
$omatch = self::escape_parser_hint_attrib($match); |
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
748 |
$link = "<!--#internallink src=\"$omatch\" --><a{$onclick} href={$quot}{$url}{$quot}{$exists}>{$inner_text}</a><!--#/internallink-->"; |
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
749 |
} |
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
750 |
|
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
751 |
return $link; |
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
752 |
} |
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
753 |
|
be6cfe79128c
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
Dan
parents:
1081
diff
changeset
|
754 |
/** |
1 | 755 |
* Parses a partial template tag in wikitext, and return an array with the parameters. |
63
2c57d3018a88
Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents:
37
diff
changeset
|
756 |
* @param string The portion of the template tag that contains the parameters. |
2c57d3018a88
Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents:
37
diff
changeset
|
757 |
* @example |
1 | 758 |
* <code> |
63
2c57d3018a88
Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents:
37
diff
changeset
|
759 |
foo = lorem ipsum |
2c57d3018a88
Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents:
37
diff
changeset
|
760 |
bar = dolor sit amet |
1 | 761 |
* </code> |
762 |
* @return array Example: |
|
763 |
* [foo] => lorem ipsum |
|
764 |
* [bar] => dolor sit amet |
|
765 |
*/ |
|
766 |
||
717
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
767 |
public static function parse_template_vars($input, $newlinemode = true) |
1 | 768 |
{ |
717
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
769 |
$parms = array(); |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
770 |
$input = trim($input); |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
771 |
if ( $newlinemode ) |
174
4c5c2b66a34d
SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents:
163
diff
changeset
|
772 |
{ |
1054
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
773 |
// we're going by newlines. |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
774 |
// split by parameter, then parse each one individually |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
775 |
$input = explode("\n", str_replace("\r", '', $input)); |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
776 |
$lastparam = ''; |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
777 |
$i = 0; |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
778 |
foreach ( $input as $line ) |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
779 |
{ |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
780 |
if ( preg_match('/^ *\|? *([A-z0-9_]+) *= *(.+)$/', $line, $match) ) |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
781 |
{ |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
782 |
// new parameter, named |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
783 |
$parms[ $match[1] ] = $match[2]; |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
784 |
$lastparam = $match[1]; |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
785 |
} |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
786 |
else if ( preg_match('/^ *\| *(.+)$/', $line, $match) || $lastparam === '' ) |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
787 |
{ |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
788 |
$parms[ $i ] = $match[1]; |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
789 |
$lastparam = $i; |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
790 |
$i++; |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
791 |
} |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
792 |
else |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
793 |
{ |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
794 |
$parms[ $lastparam ] .= "\n$line"; |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
795 |
} |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
796 |
} |
174
4c5c2b66a34d
SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents:
163
diff
changeset
|
797 |
} |
4c5c2b66a34d
SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents:
163
diff
changeset
|
798 |
else |
4c5c2b66a34d
SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents:
163
diff
changeset
|
799 |
{ |
717
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
800 |
$result = preg_match_all('/ |
1054
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
801 |
(?:^|[ ]*)\| # start of parameter - string start or series of spaces |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
802 |
[ ]* |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
803 |
(?: |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
804 |
([A-z0-9_]+) # variable name |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
805 |
[ ]* = [ ]* # assignment |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
806 |
)? # name section is optional - if the parameter name is not given, a numerical index is assigned |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
807 |
([^\|]+|.+?\n[ ]*\|) # value |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
808 |
/x', trim($input), $matches); |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
809 |
if ( $result ) |
1 | 810 |
{ |
1054
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
811 |
$pi = 0; |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
812 |
for ( $i = 0; $i < count($matches[0]); $i++ ) |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
813 |
{ |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
814 |
$matches[1][$i] = trim($matches[1][$i]); |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
815 |
$parmname = !empty($matches[1][$i]) ? $matches[1][$i] : strval(++$pi); |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
816 |
$parms[ $parmname ] = $matches[2][$i]; |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
817 |
} |
1 | 818 |
} |
819 |
} |
|
1054
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
820 |
// die('<pre>' . print_r($parms, true) . '</pre>'); |
1 | 821 |
return $parms; |
822 |
} |
|
823 |
||
824 |
/** |
|
825 |
* Processes all template tags within a block of wikitext. |
|
174
4c5c2b66a34d
SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents:
163
diff
changeset
|
826 |
* Updated in 1.0.2 to also parse template tags in the format of {{Foo |a = b |b = c |c = therefore, a}} |
1 | 827 |
* @param string The text to process |
828 |
* @return string Formatted text |
|
829 |
* @example |
|
830 |
* <code> |
|
831 |
$text = '{{Template |
|
717
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
832 |
| parm1 = Foo |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
833 |
| parm2 = Bar |
1 | 834 |
}}'; |
174
4c5c2b66a34d
SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents:
163
diff
changeset
|
835 |
$text = RenderMan::include_templates($text); |
1 | 836 |
* </code> |
837 |
*/ |
|
838 |
||
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
|
839 |
public static function include_templates($text) |
1 | 840 |
{ |
841 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
174
4c5c2b66a34d
SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents:
163
diff
changeset
|
842 |
// $template_regex = "/\{\{([^\]]+?)((\n([ ]*?)[A-z0-9]+([ ]*?)=([ ]*?)(.+?))*)\}\}/is"; |
717
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
843 |
// matches: |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
844 |
// 1 - template name |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
845 |
// 2 - parameter section |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
846 |
$template_regex = "/ |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
847 |
\{\{ # opening |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
848 |
([^\n\t\a\r]+) # template name |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
849 |
((?:(?:[\s]+\|?)[ ]*(?:[A-z0-9_]+)[ ]*=[ ]*?(?:.+))*) # parameters |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
850 |
\}\} # closing |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
851 |
/isxU"; |
1 | 852 |
if ( $count = preg_match_all($template_regex, $text, $matches) ) |
853 |
{ |
|
1054
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
854 |
// die('<pre>' . print_r($matches, true) . '</pre>'); |
1 | 855 |
for ( $i = 0; $i < $count; $i++ ) |
856 |
{ |
|
63
2c57d3018a88
Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents:
37
diff
changeset
|
857 |
$matches[1][$i] = sanitize_page_id($matches[1][$i]); |
717
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
858 |
$newlinemode = ( substr($matches[2][$i], 0, 1) == "\n" ); |
1 | 859 |
$parmsection = trim($matches[2][$i]); |
860 |
if ( !empty($parmsection) ) |
|
861 |
{ |
|
717
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
862 |
$parms = RenderMan::parse_template_vars($parmsection, $newlinemode); |
174
4c5c2b66a34d
SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents:
163
diff
changeset
|
863 |
if ( !is_array($parms) ) |
4c5c2b66a34d
SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents:
163
diff
changeset
|
864 |
// Syntax error |
4c5c2b66a34d
SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents:
163
diff
changeset
|
865 |
$parms = array(); |
1 | 866 |
} |
867 |
else |
|
868 |
{ |
|
869 |
$parms = Array(); |
|
870 |
} |
|
871 |
if ( $tpl_code = RenderMan::fetch_template_text($matches[1][$i]) ) |
|
872 |
{ |
|
1054
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
873 |
// Intelligent paragraphs. |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
874 |
// If: |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
875 |
// * A line is fully wrapped in a <p> tag |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
876 |
// * The line contains a variable |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
877 |
// * The variable contains newlines |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
878 |
// Then: |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
879 |
// * Drop the <p> tag, replace it fully paragraph-ized by newlines |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
880 |
|
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
881 |
if ( preg_match_all('/^( *)<p(\s.+)?>(.*?\{([A-z0-9]+)\}.*?)<\/p> *$/m', $tpl_code, $paramatch) ) |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
882 |
{ |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
883 |
$parser = new Carpenter(); |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
884 |
$parser->exclusive_rule('paragraph'); |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
885 |
|
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
886 |
foreach ( $paramatch[0] as $j => $match ) |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
887 |
{ |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
888 |
// $line is trimmed (the <p> is gone) |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
889 |
$spacing =& $paramatch[1][$i]; |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
890 |
$para_attrs =& $paramatch[2][$j]; |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
891 |
$para_attrs = str_replace(array('$', '\\'), array('\$', '\\\\'), $para_attrs); |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
892 |
$line =& $paramatch[3][$j]; |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
893 |
$varname =& $paramatch[4][$j]; |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
894 |
if ( isset($parms[$varname]) && strstr($parms[$varname], "\n") ) |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
895 |
{ |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
896 |
$newline = str_replace('{' . $varname . '}', $parms[$varname], $line); |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
897 |
$paraized = $parser->render($newline); |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
898 |
$paraized = preg_replace('/^<p>/m', "$spacing<p{$para_attrs}>", $paraized); |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
899 |
$paraized = $spacing . trim($paraized); |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
900 |
$tpl_code = str_replace_once($match, $paraized, $tpl_code); |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
901 |
} |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
902 |
} |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
903 |
} |
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
parents:
1044
diff
changeset
|
904 |
|
1 | 905 |
$parser = $template->makeParserText($tpl_code); |
906 |
$parser->assign_vars($parms); |
|
907 |
$text = str_replace($matches[0][$i], $parser->run(), $text); |
|
908 |
} |
|
909 |
} |
|
910 |
} |
|
911 |
return $text; |
|
912 |
} |
|
913 |
||
914 |
/** |
|
915 |
* Preprocesses an HTML text string prior to being sent to MySQL. |
|
916 |
* @param string $text |
|
1027
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
917 |
* @param bool $strip_all_php - if true, strips all PHP regardless of user permissions. Else, strips PHP only if user level < USER_LEVEL_ADMIN. Defaults to true. |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
918 |
* @param bool $sqlescape - if true, sends text through $db->escape(). Otherwise returns unescaped text. Defaults to true. |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
919 |
* @param bool $reduceheadings - if true, finds HTML headings and replaces them with wikitext. Else, does not touch headings. Defaults to true. |
1171
d42d46e13b36
Fixed php_in_pages out-of-scope error in Special:UploadFile; modified RenderMan::preprocess_text() to take a permissions object for any page
Dan
parents:
1157
diff
changeset
|
920 |
* @param Session_ACLPageInfo Optional permissions instance to check against, $session is used if not provided |
1 | 921 |
*/ |
1171
d42d46e13b36
Fixed php_in_pages out-of-scope error in Special:UploadFile; modified RenderMan::preprocess_text() to take a permissions object for any page
Dan
parents:
1157
diff
changeset
|
922 |
public static function preprocess_text($text, $strip_all_php = true, $sqlescape = true, $reduceheadings = true, $perms = false) |
1 | 923 |
{ |
924 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
925 |
$random_id = md5( time() . mt_rand() ); |
|
926 |
||
407
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
927 |
$code = $plugins->setHook('render_sanitize_pre'); |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
928 |
foreach ( $code as $cmd ) |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
929 |
{ |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
930 |
eval($cmd); |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
931 |
} |
1 | 932 |
|
1171
d42d46e13b36
Fixed php_in_pages out-of-scope error in Special:UploadFile; modified RenderMan::preprocess_text() to take a permissions object for any page
Dan
parents:
1157
diff
changeset
|
933 |
if ( !is_object($perms) ) |
d42d46e13b36
Fixed php_in_pages out-of-scope error in Special:UploadFile; modified RenderMan::preprocess_text() to take a permissions object for any page
Dan
parents:
1157
diff
changeset
|
934 |
{ |
d42d46e13b36
Fixed php_in_pages out-of-scope error in Special:UploadFile; modified RenderMan::preprocess_text() to take a permissions object for any page
Dan
parents:
1157
diff
changeset
|
935 |
$namespace = $paths->namespace; |
d42d46e13b36
Fixed php_in_pages out-of-scope error in Special:UploadFile; modified RenderMan::preprocess_text() to take a permissions object for any page
Dan
parents:
1157
diff
changeset
|
936 |
$perms =& $session; |
d42d46e13b36
Fixed php_in_pages out-of-scope error in Special:UploadFile; modified RenderMan::preprocess_text() to take a permissions object for any page
Dan
parents:
1157
diff
changeset
|
937 |
} |
d42d46e13b36
Fixed php_in_pages out-of-scope error in Special:UploadFile; modified RenderMan::preprocess_text() to take a permissions object for any page
Dan
parents:
1157
diff
changeset
|
938 |
else |
d42d46e13b36
Fixed php_in_pages out-of-scope error in Special:UploadFile; modified RenderMan::preprocess_text() to take a permissions object for any page
Dan
parents:
1157
diff
changeset
|
939 |
{ |
d42d46e13b36
Fixed php_in_pages out-of-scope error in Special:UploadFile; modified RenderMan::preprocess_text() to take a permissions object for any page
Dan
parents:
1157
diff
changeset
|
940 |
$namespace = $perms->namespace; |
d42d46e13b36
Fixed php_in_pages out-of-scope error in Special:UploadFile; modified RenderMan::preprocess_text() to take a permissions object for any page
Dan
parents:
1157
diff
changeset
|
941 |
} |
d42d46e13b36
Fixed php_in_pages out-of-scope error in Special:UploadFile; modified RenderMan::preprocess_text() to take a permissions object for any page
Dan
parents:
1157
diff
changeset
|
942 |
|
d42d46e13b36
Fixed php_in_pages out-of-scope error in Special:UploadFile; modified RenderMan::preprocess_text() to take a permissions object for any page
Dan
parents:
1157
diff
changeset
|
943 |
$can_do_php = ( !$strip_all_php && $perms->get_permissions('php_in_pages') ); |
d42d46e13b36
Fixed php_in_pages out-of-scope error in Special:UploadFile; modified RenderMan::preprocess_text() to take a permissions object for any page
Dan
parents:
1157
diff
changeset
|
944 |
$can_do_html = $session->check_acl_scope('html_in_pages', $namespace) && $perms->get_permissions('html_in_pages'); |
1 | 945 |
|
377
bb3e6c3bd4f4
Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
parents:
371
diff
changeset
|
946 |
if ( $can_do_html && !$can_do_php ) |
bb3e6c3bd4f4
Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
parents:
371
diff
changeset
|
947 |
{ |
bb3e6c3bd4f4
Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
parents:
371
diff
changeset
|
948 |
$text = preg_replace('#<(\?|\?php|%)(.*?)(\?|%)>#is', '<\\1\\2\\3>', $text); |
bb3e6c3bd4f4
Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
parents:
371
diff
changeset
|
949 |
} |
bb3e6c3bd4f4
Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
parents:
371
diff
changeset
|
950 |
else if ( !$can_do_html && !$can_do_php ) |
1 | 951 |
{ |
24 | 952 |
$text = sanitize_html($text, true); |
1 | 953 |
// If we can't do PHP, we can't do Javascript either. |
954 |
$text = RenderMan::destroy_javascript($text); |
|
955 |
} |
|
956 |
||
957 |
// Strip out <nowiki> sections and PHP code |
|
958 |
||
959 |
$php = preg_match_all('#(<|<)\?php(.*?)\?(>|>)#is', $text, $phpsec); |
|
960 |
||
961 |
//die('<pre>'.htmlspecialchars(print_r($phpsec, true))."\n".htmlspecialchars(print_r($text, true)).'</pre>'); |
|
962 |
||
963 |
for($i=0;$i<sizeof($phpsec[1]);$i++) |
|
964 |
{ |
|
965 |
$text = str_replace($phpsec[0][$i], '{PHP:'.$random_id.':'.$i.'}', $text); |
|
966 |
} |
|
967 |
||
968 |
$nw = preg_match_all('#<nowiki>(.*?)<\/nowiki>#is', $text, $nowiki); |
|
969 |
||
970 |
for($i=0;$i<sizeof($nowiki[1]);$i++) |
|
971 |
{ |
|
972 |
$text = str_replace('<nowiki>'.$nowiki[1][$i].'</nowiki>', '{NOWIKI:'.$random_id.':'.$i.'}', $text); |
|
973 |
} |
|
974 |
||
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:
335
diff
changeset
|
975 |
$text = str_replace('~~~~~', enano_date('G:i, j F Y (T)'), $text); |
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:
335
diff
changeset
|
976 |
$text = str_replace('~~~~', "[[User:$session->username|$session->username]] ".enano_date('G:i, j F Y (T)'), $text); |
1 | 977 |
$text = str_replace('~~~', "[[User:$session->username|$session->username]] ", $text); |
978 |
||
407
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
979 |
$code = $plugins->setHook('render_sanitize_post'); |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
980 |
foreach ( $code as $cmd ) |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
981 |
{ |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
982 |
eval($cmd); |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
983 |
} |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
984 |
|
1027
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
985 |
// gently apply some reverse-processing to allow the parser to do magic with TOCs and stuff |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
986 |
if ( $reduceheadings ) |
98c052fc3337
First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents:
1003
diff
changeset
|
987 |
$text = self::reverse_process_headings($text); |
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
988 |
|
1 | 989 |
// Reinsert <nowiki> sections |
990 |
for($i=0;$i<$nw;$i++) |
|
991 |
{ |
|
992 |
$text = str_replace('{NOWIKI:'.$random_id.':'.$i.'}', '<nowiki>'.$nowiki[1][$i].'</nowiki>', $text); |
|
993 |
} |
|
994 |
// Reinsert PHP |
|
995 |
for($i=0;$i<$php;$i++) |
|
996 |
{ |
|
997 |
$phsec = ''.$phpsec[1][$i].'?php'.$phpsec[2][$i].'?'.$phpsec[3][$i].''; |
|
998 |
if ( $strip_all_php ) |
|
999 |
$phsec = htmlspecialchars($phsec); |
|
1000 |
$text = str_replace('{PHP:'.$random_id.':'.$i.'}', $phsec, $text); |
|
1001 |
} |
|
1002 |
||
1003 |
$text = ( $sqlescape ) ? $db->escape($text) : $text; |
|
1004 |
||
1005 |
return $text; |
|
1006 |
} |
|
1007 |
||
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
|
1008 |
public static function smilieyize($text, $complete_urls = false) |
1 | 1009 |
{ |
1010 |
||
1011 |
$random_id = md5( time() . mt_rand() ); |
|
1012 |
||
1013 |
// Smileys array - eventually this will be fetched from the database by |
|
1014 |
// RenderMan::initSmileys during initialization, but it will all be hardcoded for beta 2 |
|
1015 |
||
1016 |
$smileys = Array( |
|
1017 |
'O:-)' => 'face-angel.png', |
|
1018 |
'O:)' => 'face-angel.png', |
|
1019 |
'O=)' => 'face-angel.png', |
|
1020 |
':-)' => 'face-smile.png', |
|
1021 |
':)' => 'face-smile.png', |
|
1022 |
'=)' => 'face-smile-big.png', |
|
1023 |
':-(' => 'face-sad.png', |
|
1024 |
':(' => 'face-sad.png', |
|
1025 |
';(' => 'face-sad.png', |
|
1026 |
':-O' => 'face-surprise.png', |
|
1027 |
';-)' => 'face-wink.png', |
|
1028 |
';)' => 'face-wink.png', |
|
1029 |
'8-)' => 'face-glasses.png', |
|
1030 |
'8)' => 'face-glasses.png', |
|
1031 |
':-D' => 'face-grin.png', |
|
1032 |
':D' => 'face-grin.png', |
|
1033 |
'=D' => 'face-grin.png', |
|
1034 |
':-*' => 'face-kiss.png', |
|
1035 |
':*' => 'face-kiss.png', |
|
1036 |
'=*' => 'face-kiss.png', |
|
1037 |
':\'(' => 'face-crying.png', |
|
1038 |
':-|' => 'face-plain.png', |
|
1039 |
':-\\' => 'face-plain.png', |
|
1040 |
':-/' => 'face-plain.png', |
|
1041 |
':joke:' => 'face-plain.png', |
|
1042 |
']:->' => 'face-devil-grin.png', |
|
189
fd0e9c7a7b28
Automatic set of state on Oxygen sidebar portlets should work now; reimplemented parts of the template parser (again) to workaround some PHP/PCRE issues and add support for parser plugins
Dan
parents:
174
diff
changeset
|
1043 |
']:->' => 'face-devil-grin.png', |
1 | 1044 |
':kiss:' => 'face-kiss.png', |
1045 |
':-P' => 'face-tongue-out.png', |
|
1046 |
':P' => 'face-tongue-out.png', |
|
1047 |
':-p' => 'face-tongue-out.png', |
|
1048 |
':p' => 'face-tongue-out.png', |
|
1049 |
':-X' => 'face-sick.png', |
|
1050 |
':X' => 'face-sick.png', |
|
1051 |
':sick:' => 'face-sick.png', |
|
1052 |
':-]' => 'face-oops.png', |
|
1053 |
':]' => 'face-oops.png', |
|
1054 |
':oops:' => 'face-oops.png', |
|
1055 |
':-[' => 'face-embarassed.png', |
|
1056 |
':[' => 'face-embarassed.png' |
|
1057 |
); |
|
1058 |
||
1059 |
// Strip out <nowiki> sections |
|
1060 |
//return '<pre>'.htmlspecialchars($text).'</pre>'; |
|
1061 |
$nw = preg_match_all('#<nowiki>(.*?)<\/nowiki>#is', $text, $nowiki); |
|
1062 |
||
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
1063 |
for ( $i = 0; $i < count($nowiki[1]); $i++ ) |
1 | 1064 |
{ |
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
1065 |
$text = str_replace('<nowiki>' . $nowiki[1][$i] . '</nowiki>', '{NOWIKI:'.$random_id.':'.$i.'}', $text); |
1 | 1066 |
} |
1067 |
||
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
1068 |
foreach ( $smileys as $smiley => $smiley_path ) |
1 | 1069 |
{ |
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
1070 |
$hex_smiley = hexencode($smiley, '&#x', ';'); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
1071 |
$pfx = ( $complete_urls ) ? get_server_url() : ''; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
1072 |
$text = str_replace(' ' . $smiley, |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
1073 |
' <!--#smiley code="' . self::escape_parser_hint_attrib($smiley) . '"--><nowiki> |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
1074 |
<!-- The above is a reverse-parser hint --> |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
1075 |
<img title="' . $hex_smiley . '" alt="' . $hex_smiley . '" src="' . $pfx . scriptPath . '/images/smilies/' . $smiley_path . '" |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
1076 |
style="border: 0;" /> |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
1077 |
</nowiki><!--#/smiley-->', $text); |
1 | 1078 |
} |
1079 |
//*/ |
|
1080 |
||
1081 |
// Reinsert <nowiki> sections |
|
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
1082 |
for ( $i = 0; $i < $nw; $i++ ) |
1 | 1083 |
{ |
1084 |
$text = str_replace('{NOWIKI:'.$random_id.':'.$i.'}', '<nowiki>'.$nowiki[1][$i].'</nowiki>', $text); |
|
1085 |
} |
|
1086 |
||
1087 |
return $text; |
|
1088 |
} |
|
1089 |
||
1090 |
/** |
|
1091 |
* Generates a summary of the differences between two texts, and formats it as XHTML. |
|
1092 |
* @param $str1 string the first block of text |
|
1093 |
* @param $str2 string the second block of text |
|
1094 |
* @return string |
|
1095 |
*/ |
|
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
|
1096 |
public static function diff($str1, $str2) |
1 | 1097 |
{ |
1098 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
592 | 1099 |
require_once(ENANO_ROOT.'/includes/diff.php'); |
1 | 1100 |
$str1 = explode("\n", $str1); |
1101 |
$str2 = explode("\n", $str2); |
|
1102 |
$diff = new Diff($str1, $str2); |
|
1103 |
$renderer = new TableDiffFormatter(); |
|
1104 |
return '<table class="diff">'.$renderer->format($diff).'</table>'; |
|
1105 |
} |
|
1106 |
||
35 | 1107 |
/** |
1108 |
* Changes wikitext image tags to HTML. |
|
1109 |
* @param string The wikitext to process |
|
37 | 1110 |
* @param array Will be overwritten with the list of HTML tags (the system uses tokens for TextWiki compatibility) |
35 | 1111 |
* @return string |
1112 |
*/ |
|
1113 |
||
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
|
1114 |
public static function process_image_tags($text, &$taglist) |
35 | 1115 |
{ |
1116 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
1117 |
||
37 | 1118 |
$s_delim = "\xFF"; |
1119 |
$f_delim = "\xFF"; |
|
1120 |
$taglist = array(); |
|
1121 |
||
35 | 1122 |
// Wicked huh? |
569
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1123 |
$ns_file = str_replace('/', '\\/', preg_quote($paths->nslist['File'])); |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1124 |
$regex = '/ |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1125 |
\[\[ # starting delimiter |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1126 |
:' . $ns_file . '([\w\s0-9_\(\)!@%\^\+\|\.-]+?\.(?:png|gif|jpg|jpeg)) # image filename |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1127 |
(?:(?:\|(?:.+?))*) # parameters |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1128 |
\]\] # ending delimiter |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1129 |
/ix'; |
35 | 1130 |
|
1131 |
preg_match_all($regex, $text, $matches); |
|
1132 |
||
1133 |
foreach ( $matches[0] as $i => $match ) |
|
1134 |
{ |
|
1135 |
||
1136 |
$full_tag =& $matches[0][$i]; |
|
1137 |
$filename =& $matches[1][$i]; |
|
569
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1138 |
|
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1139 |
// apply recursion (hack? @todo could this be done with (?R) in PCRE?) |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1140 |
$tag_pos = strpos($text, $full_tag); |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1141 |
$tag_end_pos = $tag_pos + strlen($full_tag); |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1142 |
while ( get_char_count($full_tag, ']') < get_char_count($full_tag, '[') && $tag_end_pos < strlen($text) ) |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1143 |
{ |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1144 |
$full_tag .= substr($text, $tag_end_pos, 1); |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1145 |
$tag_end_pos++; |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1146 |
} |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1147 |
if ( $tag_end_pos > strlen($text) ) |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1148 |
{ |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1149 |
// discard tag, not closed fully |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1150 |
continue; |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1151 |
} |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1152 |
|
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1153 |
// init the various image parameters |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1154 |
$width = null; |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1155 |
$height = null; |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1156 |
$scale_type = null; |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1157 |
$raw_display = false; |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1158 |
$clear = null; |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1159 |
$caption = null; |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1160 |
|
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1161 |
// trim tag and parse particles |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1162 |
$tag_trim = rtrim(ltrim($full_tag, '['), ']'); |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1163 |
// trim off the filename from the start of the tag |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1164 |
$filepart_len = 1 + strlen($paths->nslist['File']) + strlen($filename) + 1; |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1165 |
$tag_trim = substr($tag_trim, $filepart_len); |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1166 |
// explode and we should have parameters |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1167 |
$tag_parts = explode('|', $tag_trim); |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1168 |
|
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1169 |
// for each of the parameters, see if it matches a known option. If so, apply it; |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1170 |
// otherwise, see if a plugin reserved that parameter and if not treat it as the caption |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1171 |
foreach ( $tag_parts as $param ) |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1172 |
{ |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1173 |
switch($param) |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1174 |
{ |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1175 |
case 'left': |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1176 |
case 'right': |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1177 |
$clear = $param; |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1178 |
break; |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1179 |
case 'thumb': |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1180 |
$scale_type = 'thumb'; |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1181 |
break; |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1182 |
case 'raw': |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1183 |
$raw_display = true; |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1184 |
break; |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1185 |
default: |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1186 |
// height specification |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1187 |
if ( preg_match('/^([0-9]+)x([0-9]+)$/', $param, $dims) ) |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1188 |
{ |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1189 |
$width = intval($dims[1]); |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1190 |
$height = intval($dims[2]); |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1191 |
break; |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1192 |
} |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1193 |
// not the height, so see if a plugin took this over |
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
1194 |
// this hook requires plugins to return true if they modified anything |
569
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1195 |
$code = $plugins->setHook('img_tag_parse_params'); |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1196 |
foreach ( $code as $cmd ) |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1197 |
{ |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1198 |
if ( eval($cmd) ) |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1199 |
break 2; |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1200 |
} |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1201 |
// we would have broken out by now if a plugin properly handled this, |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1202 |
// so just set the caption now. |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1203 |
$caption = $param; |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1204 |
break; |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1205 |
} |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1206 |
} |
35 | 1207 |
|
1208 |
if ( !isPage( $paths->nslist['File'] . $filename ) ) |
|
1209 |
{ |
|
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
1210 |
$text = str_replace($full_tag, '[[' . $paths->nslist['File'] . $filename . ']]', $text); |
35 | 1211 |
continue; |
1212 |
} |
|
1213 |
||
569
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1214 |
if ( $scale_type == 'thumb' ) |
35 | 1215 |
{ |
1216 |
$r_width = 225; |
|
1217 |
$r_height = 225; |
|
1218 |
||
1219 |
$url = makeUrlNS('Special', 'DownloadFile/' . $filename, 'preview&width=' . $r_width . '&height=' . $r_height, true); |
|
1220 |
} |
|
1221 |
else if ( !empty($width) && !empty($height) ) |
|
1222 |
{ |
|
1223 |
$r_width = $width; |
|
1224 |
$r_height = $height; |
|
1225 |
||
1226 |
$url = makeUrlNS('Special', 'DownloadFile/' . $filename, 'preview&width=' . $r_width . '&height=' . $r_height, true); |
|
1227 |
} |
|
1228 |
else |
|
1229 |
{ |
|
1230 |
$url = makeUrlNS('Special', 'DownloadFile/' . $filename); |
|
1231 |
} |
|
1232 |
||
1233 |
$img_tag = '<img src="' . $url . '" '; |
|
1234 |
||
65 | 1235 |
// if ( isset($r_width) && isset($r_height) && $scale_type != '|thumb' ) |
1236 |
// { |
|
66
52017732bc20
Added "raw" option to embedded images to make complex clickables easier
Dan
parents:
65
diff
changeset
|
1237 |
// $img_tag .= 'width="' . $r_width . '" height="' . $r_height . '" '; |
65 | 1238 |
// } |
35 | 1239 |
|
66
52017732bc20
Added "raw" option to embedded images to make complex clickables easier
Dan
parents:
65
diff
changeset
|
1240 |
$img_tag .= 'style="border-width: 0px; /* background-color: white; */" '; |
35 | 1241 |
|
85
7c68a18a27be
AJAX comments are now paginated; plugin manager can now show system plugins; typo in installer corrected; links in oxygen/stpatty/admin footers changed to "About Enano" page; 1.0.1 release candidate
Dan
parents:
73
diff
changeset
|
1242 |
$code = $plugins->setHook('img_tag_parse_img'); |
7c68a18a27be
AJAX comments are now paginated; plugin manager can now show system plugins; typo in installer corrected; links in oxygen/stpatty/admin footers changed to "About Enano" page; 1.0.1 release candidate
Dan
parents:
73
diff
changeset
|
1243 |
foreach ( $code as $cmd ) |
7c68a18a27be
AJAX comments are now paginated; plugin manager can now show system plugins; typo in installer corrected; links in oxygen/stpatty/admin footers changed to "About Enano" page; 1.0.1 release candidate
Dan
parents:
73
diff
changeset
|
1244 |
{ |
7c68a18a27be
AJAX comments are now paginated; plugin manager can now show system plugins; typo in installer corrected; links in oxygen/stpatty/admin footers changed to "About Enano" page; 1.0.1 release candidate
Dan
parents:
73
diff
changeset
|
1245 |
eval($cmd); |
7c68a18a27be
AJAX comments are now paginated; plugin manager can now show system plugins; typo in installer corrected; links in oxygen/stpatty/admin footers changed to "About Enano" page; 1.0.1 release candidate
Dan
parents:
73
diff
changeset
|
1246 |
} |
7c68a18a27be
AJAX comments are now paginated; plugin manager can now show system plugins; typo in installer corrected; links in oxygen/stpatty/admin footers changed to "About Enano" page; 1.0.1 release candidate
Dan
parents:
73
diff
changeset
|
1247 |
|
35 | 1248 |
$img_tag .= '/>'; |
1249 |
||
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
1250 |
$s_full_tag = self::escape_parser_hint_attrib($full_tag); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
1251 |
$complete_tag = '<!--#imagelink src="' . $s_full_tag . '" -->'; |
35 | 1252 |
|
569
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1253 |
if ( !empty($scale_type) && !$raw_display ) |
35 | 1254 |
{ |
1255 |
$complete_tag .= '<div class="thumbnail" '; |
|
1256 |
$clear_text = ''; |
|
1257 |
if ( !empty($clear) ) |
|
1258 |
{ |
|
569
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1259 |
$side = ( $clear == 'left' ) ? 'left' : 'right'; |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1260 |
$opposite = ( $clear == 'left' ) ? 'right' : 'left'; |
320
112debff64bd
SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents:
317
diff
changeset
|
1261 |
$clear_text .= "float: $side; margin-$opposite: 20px; width: {$r_width}px;"; |
35 | 1262 |
$complete_tag .= 'style="' . $clear_text . '" '; |
1263 |
} |
|
1264 |
$complete_tag .= '>'; |
|
1265 |
||
1266 |
$complete_tag .= '<a href="' . makeUrlNS('File', $filename) . '" style="display: block;">'; |
|
1267 |
$complete_tag .= $img_tag; |
|
1268 |
$complete_tag .= '</a>'; |
|
1269 |
||
1270 |
$mag_button = '<a href="' . makeUrlNS('File', $filename) . '" style="display: block; float: right; clear: right; margin: 0 0 10px 10px;"><img alt="[ + ]" src="' . scriptPath . '/images/thumbnail.png" style="border-width: 0px;" /></a>'; |
|
1271 |
||
1272 |
if ( !empty($caption) ) |
|
1273 |
{ |
|
569
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1274 |
$complete_tag .= $mag_button . $caption; |
35 | 1275 |
} |
1276 |
||
1277 |
$complete_tag .= '</div>'; |
|
1278 |
} |
|
569
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1279 |
else if ( $raw_display ) |
66
52017732bc20
Added "raw" option to embedded images to make complex clickables easier
Dan
parents:
65
diff
changeset
|
1280 |
{ |
67 | 1281 |
$complete_tag .= "$img_tag"; |
1282 |
$taglist[$i] = $complete_tag; |
|
1283 |
||
1284 |
$repl = "{$s_delim}e_img_{$i}{$f_delim}"; |
|
1285 |
$text = str_replace($full_tag, $repl, $text); |
|
1286 |
continue; |
|
66
52017732bc20
Added "raw" option to embedded images to make complex clickables easier
Dan
parents:
65
diff
changeset
|
1287 |
} |
35 | 1288 |
else |
1289 |
{ |
|
85
7c68a18a27be
AJAX comments are now paginated; plugin manager can now show system plugins; typo in installer corrected; links in oxygen/stpatty/admin footers changed to "About Enano" page; 1.0.1 release candidate
Dan
parents:
73
diff
changeset
|
1290 |
$complete_tag .= '<a href="' . makeUrlNS('File', $filename) . '" style="display: block;"'; |
7c68a18a27be
AJAX comments are now paginated; plugin manager can now show system plugins; typo in installer corrected; links in oxygen/stpatty/admin footers changed to "About Enano" page; 1.0.1 release candidate
Dan
parents:
73
diff
changeset
|
1291 |
$code = $plugins->setHook('img_tag_parse_link'); |
7c68a18a27be
AJAX comments are now paginated; plugin manager can now show system plugins; typo in installer corrected; links in oxygen/stpatty/admin footers changed to "About Enano" page; 1.0.1 release candidate
Dan
parents:
73
diff
changeset
|
1292 |
foreach ( $code as $cmd ) |
7c68a18a27be
AJAX comments are now paginated; plugin manager can now show system plugins; typo in installer corrected; links in oxygen/stpatty/admin footers changed to "About Enano" page; 1.0.1 release candidate
Dan
parents:
73
diff
changeset
|
1293 |
{ |
7c68a18a27be
AJAX comments are now paginated; plugin manager can now show system plugins; typo in installer corrected; links in oxygen/stpatty/admin footers changed to "About Enano" page; 1.0.1 release candidate
Dan
parents:
73
diff
changeset
|
1294 |
eval($cmd); |
7c68a18a27be
AJAX comments are now paginated; plugin manager can now show system plugins; typo in installer corrected; links in oxygen/stpatty/admin footers changed to "About Enano" page; 1.0.1 release candidate
Dan
parents:
73
diff
changeset
|
1295 |
} |
7c68a18a27be
AJAX comments are now paginated; plugin manager can now show system plugins; typo in installer corrected; links in oxygen/stpatty/admin footers changed to "About Enano" page; 1.0.1 release candidate
Dan
parents:
73
diff
changeset
|
1296 |
$complete_tag .= '>'; |
35 | 1297 |
$complete_tag .= $img_tag; |
1298 |
$complete_tag .= '</a>'; |
|
1299 |
} |
|
1300 |
||
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
1301 |
$complete_tag .= "<!--#/imagelink-->"; |
37 | 1302 |
$taglist[$i] = $complete_tag; |
35 | 1303 |
|
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
1304 |
/* |
37 | 1305 |
$pos = strpos($text, $full_tag); |
35 | 1306 |
|
1307 |
while(true) |
|
1308 |
{ |
|
1309 |
$check1 = substr($text, $pos, 3); |
|
1310 |
$check2 = substr($text, $pos, 1); |
|
1311 |
if ( $check1 == '<p>' || $pos == 0 || $check2 == "\n" ) |
|
1312 |
{ |
|
1313 |
// die('found at pos '.$pos); |
|
1314 |
break; |
|
1315 |
} |
|
1316 |
$pos--; |
|
1317 |
} |
|
569
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1318 |
*/ |
35 | 1319 |
|
569
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1320 |
/* |
37 | 1321 |
$repl = "{$s_delim}e_img_{$i}{$f_delim}"; |
1322 |
$text = substr($text, 0, $pos) . $repl . substr($text, $pos); |
|
35 | 1323 |
|
1324 |
$text = str_replace($full_tag, '', $text); |
|
569
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1325 |
*/ |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1326 |
$text = str_replace_once($full_tag, $complete_tag, $text); |
35 | 1327 |
|
1328 |
unset($full_tag, $filename, $scale_type, $width, $height, $clear, $caption, $r_width, $r_height); |
|
1329 |
||
1330 |
} |
|
1331 |
||
569
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1332 |
// if ( count($matches[0]) > 0 ) |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1333 |
// die('<pre>' . htmlspecialchars($text) . '</pre>'); |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1334 |
|
35 | 1335 |
return $text; |
1336 |
} |
|
1337 |
||
37 | 1338 |
/** |
1339 |
* Finalizes processing of image tags. |
|
1340 |
* @param string The preprocessed text |
|
1341 |
* @param array The list of image tags created by RenderMan::process_image_tags() |
|
1342 |
*/ |
|
1343 |
||
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
|
1344 |
public static function process_imgtags_stage2($text, $taglist) |
37 | 1345 |
{ |
1346 |
$s_delim = "\xFF"; |
|
1347 |
$f_delim = "\xFF"; |
|
1348 |
foreach ( $taglist as $i => $tag ) |
|
1349 |
{ |
|
1350 |
$repl = "{$s_delim}e_img_{$i}{$f_delim}"; |
|
1351 |
$text = str_replace($repl, $tag, $text); |
|
1352 |
} |
|
1353 |
return $text; |
|
1354 |
} |
|
1355 |
||
1 | 1356 |
} |
1357 |
||
1358 |
?> |