author | Dan |
Sun, 09 Nov 2008 09:03:10 -0500 | |
changeset 731 | 8e6dbf6882c2 |
parent 717 | 236360cf79a0 |
child 745 | 0a3866f74faa |
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 |
|
685
17ebe24cdf85
Rebranded as 1.1.5 (Caoineag alpha 5) and fixed a couple bugs related to CDN support in template_nodb and installerUI. Updated readme.
Dan
parents:
592
diff
changeset
|
5 |
* Version 1.1.5 (Caoineag alpha 5) |
536 | 6 |
* Copyright (C) 2006-2008 Dan Fuhry |
1 | 7 |
* render.php - handles fetching pages and parsing them into HTML |
8 |
* |
|
9 |
* This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License |
|
10 |
* as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. |
|
11 |
* |
|
12 |
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied |
|
13 |
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. |
|
14 |
*/ |
|
15 |
||
16 |
class RenderMan { |
|
17 |
||
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
|
18 |
public static function strToPageID($string) |
1 | 19 |
{ |
20 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
21 |
$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
|
22 |
$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
|
23 |
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
|
24 |
{ |
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 |
$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
|
26 |
$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
|
27 |
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
|
28 |
} |
1 | 29 |
for($i=0;$i<sizeof($paths->nslist);$i++) |
30 |
{ |
|
31 |
$ln = strlen($paths->nslist[$k[$i]]); |
|
32 |
if(substr($string, 0, $ln) == $paths->nslist[$k[$i]]) |
|
33 |
{ |
|
34 |
$ns = $k[$i]; |
|
35 |
$pg = substr($string, strlen($paths->nslist[$ns]), strlen($string)); |
|
36 |
} |
|
37 |
} |
|
38 |
return Array($pg, $ns); |
|
39 |
} |
|
40 |
||
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
|
41 |
public static function getPage($page_id, $namespace, $wiki = 1, $smilies = true, $filter_links = true, $redir = true, $render = true) |
1 | 42 |
{ |
43 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
44 |
||
45 |
$perms =& $session; |
|
46 |
||
322
5f1cd51bf1be
Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents:
320
diff
changeset
|
47 |
if ( $page_id != $paths->page_id || $namespace != $paths->namespace ) |
1 | 48 |
{ |
49 |
unset($perms); |
|
50 |
unset($perms); // PHP <5.1.5 Zend bug |
|
51 |
$perms = $session->fetch_page_acl($page_id, $namespace); |
|
52 |
} |
|
53 |
||
54 |
if(!$perms->get_permissions('read')) |
|
55 |
return 'Access denied ('.$paths->nslist[$namespace].$page_id.')'; |
|
56 |
||
457
d823e49e2e4e
Fixed: RenderMan::getPage() failing with access denial when fetching template and view_source results in deny
Dan
parents:
322
diff
changeset
|
57 |
if($namespace != 'Template' && ($wiki == 0 || $render == false)) |
1 | 58 |
{ |
59 |
if(!$perms->get_permissions('view_source')) |
|
60 |
{ |
|
61 |
return 'Access denied ('.$paths->nslist[$namespace].$page_id.')'; |
|
62 |
} |
|
63 |
} |
|
64 |
||
65 |
$q = $db->sql_query('SELECT page_text,char_tag FROM '.table_prefix.'page_text WHERE page_id=\''.$db->escape($page_id).'\' AND namespace=\''.$db->escape($namespace).'\';'); |
|
66 |
if ( !$q ) |
|
67 |
{ |
|
68 |
$db->_die('Method called was: RenderMan::getPage(\''.$page_id.'\', \''.$namespace.'\');.'); |
|
69 |
} |
|
70 |
if ( $db->numrows() < 1 ) |
|
71 |
{ |
|
72 |
return false; |
|
73 |
} |
|
74 |
$row = $db->fetchrow(); |
|
75 |
$db->free_result(); |
|
76 |
||
77 |
$message = $row['page_text']; |
|
78 |
$chartag = $row['char_tag']; |
|
79 |
unset($row); // Free some memory |
|
80 |
||
133
af0f6ec48de3
Fully implemented password complexity enforcement; added encryption for passwords on registration form; some baby steps taken towards supporting international usernames - this is not working very well, we might need a hackish fix; TODO: implement password strength meter into installer UI and get international usernames 100% working
Dan
parents:
91
diff
changeset
|
81 |
if ( preg_match("#^\#redirect \[\[([^\]\r\n\a\t]+?)\]\]#", $message, $m) && $redir && ( !isset($_GET['redirect']) || ( isset($_GET['redirect']) && $_GET['redirect'] != 'no' ) ) ) |
1 | 82 |
{ |
83 |
$old = $paths->cpage; |
|
84 |
$a = RenderMan::strToPageID($m[1]); |
|
85 |
$a[0] = str_replace(' ', '_', $a[0]); |
|
86 |
||
87 |
$pageid = str_replace(' ', '_', $paths->nslist[$a[1]] . $a[0]); |
|
88 |
$paths->page = $pageid; |
|
89 |
$paths->cpage = $paths->pages[$pageid]; |
|
90 |
//die('<pre>'.print_r($paths->cpage,true).'</pre>'); |
|
91 |
||
92 |
unset($template); |
|
93 |
unset($GLOBALS['template']); |
|
94 |
||
95 |
$GLOBALS['template'] = new template(); |
|
96 |
global $template; |
|
97 |
||
98 |
$template->template(); // Tear down and rebuild the template parser |
|
99 |
$template->load_theme($session->theme, $session->style); |
|
100 |
||
101 |
$data = '<div><small>(Redirected from <a href="'.makeUrlNS($old['namespace'], $old['urlname_nons'], 'redirect=no', true).'">'.$old['name'].'</a>)</small></div>'.RenderMan::getPage($a[0], $a[1], $wiki, $smilies, $filter_links, false /* Enforces a maximum of one redirect */); |
|
102 |
||
103 |
return $data; |
|
104 |
} |
|
105 |
else if(preg_match('#^\#redirect \[\[(.+?)\]\]#', $message, $m) && isset($_GET['redirect']) && $_GET['redirect'] == 'no') |
|
106 |
{ |
|
107 |
preg_match('#^\#redirect \[\[(.+)\]\]#', $message, $m); |
|
108 |
$m[1] = str_replace(' ', '_', $m[1]); |
|
109 |
$message = preg_replace('#\#redirect \[\[(.+)\]\]#', '<nowiki><div class="mdg-infobox"><table border="0" width="100%" cellspacing="0" cellpadding="0"><tr><td valign="top"><img alt="Cute wet-floor icon" src="'.scriptPath.'/images/redirector.png" /></td><td valign="top" style="padding-left: 10px;"><b>This page is a <i>redirector</i>.</b><br />This means that this page will not show its own content by default. Instead it will display the contents of the page it redirects to.<br /><br />To create a redirect page, make the <i>first characters</i> in the page content <tt>#redirect [[Page_ID]]</tt>. For more information, see the Enano <a href="http://enanocms.org/Help:Wiki_formatting">Wiki formatting guide</a>.<br /><br />This page redirects to <a href="'.makeUrl($m[1]).'">'.$paths->pages[$m[1]]['name'].'</a>.</td></tr></table></div><br /><hr style="margin-left: 1em; width: 200px;" /></nowiki>', $message); |
|
110 |
} |
|
111 |
$session->disallow_password_grab(); |
|
112 |
return ($render) ? RenderMan::render($message, $wiki, $smilies, $filter_links) : $message; |
|
113 |
} |
|
114 |
||
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
|
115 |
public static function getTemplate($id, $parms) |
1 | 116 |
{ |
117 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
118 |
if(!isset($paths->pages[$paths->nslist['Template'].$id])) |
|
119 |
{ |
|
120 |
return '[['.$paths->nslist['Template'].$id.']]'; |
|
121 |
} |
|
122 |
if(isset($paths->template_cache[$id])) |
|
123 |
{ |
|
124 |
$text = $paths->template_cache[$id]; |
|
125 |
} |
|
126 |
else |
|
127 |
{ |
|
128 |
$text = RenderMan::getPage($id, 'Template', 0, true, true, 0); |
|
129 |
$paths->template_cache[$id] = $text; |
|
130 |
} |
|
131 |
||
132 |
$text = preg_replace('/<noinclude>(.*?)<\/noinclude>/is', '', $text); |
|
133 |
$text = preg_replace('/<nodisplay>(.*?)<\/nodisplay>/is', '\\1', $text); |
|
134 |
||
135 |
preg_match_all('#\(_([0-9]+)_\)#', $text, $matchlist); |
|
136 |
||
137 |
foreach($matchlist[1] as $m) |
|
138 |
{ |
|
139 |
if(isset($parms[((int)$m)+1])) |
|
140 |
{ |
|
141 |
$p = $parms[((int)$m)+1]; |
|
142 |
} |
|
143 |
else |
|
144 |
{ |
|
145 |
$p = '<b>Notice:</b> RenderMan::getTemplate(): Parameter '.$m.' is not set'; |
|
146 |
} |
|
147 |
$text = str_replace('(_'.$m.'_)', $p, $text); |
|
717
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
148 |
$text = str_replace('{{' . ( $m + 1 ) . '}}', $p, $text); |
1 | 149 |
} |
150 |
$text = RenderMan::include_templates($text); |
|
151 |
return $text; |
|
152 |
} |
|
153 |
||
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
|
154 |
public static function fetch_template_text($id) |
1 | 155 |
{ |
156 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
157 |
if(!isset($paths->pages[$paths->nslist['Template'].$id])) |
|
158 |
{ |
|
159 |
return '[['.$paths->nslist['Template'].$id.']]'; |
|
160 |
} |
|
161 |
if(isset($paths->template_cache[$id])) |
|
162 |
{ |
|
163 |
$text = $paths->template_cache[$id]; |
|
164 |
} |
|
165 |
else |
|
166 |
{ |
|
167 |
$text = RenderMan::getPage($id, 'Template', 0, false, false, false, false); |
|
168 |
$paths->template_cache[$id] = $text; |
|
169 |
} |
|
170 |
||
171 |
if ( is_string($text) ) |
|
172 |
{ |
|
173 |
$text = preg_replace('/<noinclude>(.*?)<\/noinclude>/is', '', $text); |
|
174 |
$text = preg_replace('/<nodisplay>(.*?)<\/nodisplay>/is', '\\1', $text); |
|
175 |
} |
|
176 |
||
177 |
return $text; |
|
178 |
} |
|
179 |
||
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
|
180 |
public static function render($text, $wiki = 1, $smilies = true, $filter_links = true) |
1 | 181 |
{ |
182 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
183 |
if($smilies) |
|
184 |
{ |
|
185 |
$text = RenderMan::smilieyize($text); |
|
186 |
} |
|
187 |
if($wiki == 1) |
|
188 |
{ |
|
189 |
$text = RenderMan::next_gen_wiki_format($text); |
|
190 |
} |
|
191 |
elseif($wiki == 2) |
|
192 |
{ |
|
193 |
$text = $template->tplWikiFormat($text); |
|
194 |
} |
|
195 |
return $text; |
|
196 |
} |
|
197 |
||
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
|
198 |
public static function PlainTextRender($text, $wiki = 1, $smilies = false, $filter_links = true) |
1 | 199 |
{ |
200 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
201 |
if($smilies) |
|
202 |
{ |
|
203 |
$text = RenderMan::smilieyize($text); |
|
204 |
} |
|
205 |
if($wiki == 1) |
|
206 |
{ |
|
207 |
$text = RenderMan::next_gen_wiki_format($text, true); |
|
208 |
} |
|
209 |
elseif($wiki == 2) |
|
210 |
{ |
|
211 |
$text = $template->tplWikiFormat($text); |
|
212 |
} |
|
213 |
return $text; |
|
214 |
} |
|
215 |
||
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
|
216 |
public static function next_gen_wiki_format($text, $plaintext = false, $filter_links = true, $do_params = false) |
1 | 217 |
{ |
218 |
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
|
219 |
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
|
220 |
|
592 | 221 |
require_once(ENANO_ROOT.'/includes/wikiformat.php'); |
222 |
require_once(ENANO_ROOT.'/includes/wikiengine/Tables.php'); |
|
223 |
||
382
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
parents:
377
diff
changeset
|
224 |
profiler_log("RenderMan: starting wikitext render"); |
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
parents:
377
diff
changeset
|
225 |
|
1 | 226 |
$random_id = md5( time() . mt_rand() ); |
227 |
||
228 |
// Strip out <nowiki> sections and PHP code |
|
229 |
||
407
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
230 |
$nw = preg_match_all('#<nowiki>(.*?)<\/nowiki>#is', $text, $nowiki); |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
231 |
|
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
232 |
for($i=0;$i<sizeof($nowiki[1]);$i++) |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
233 |
{ |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
234 |
$text = str_replace('<nowiki>'.$nowiki[1][$i].'</nowiki>', '{NOWIKI:'.$random_id.':'.$i.'}', $text); |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
235 |
} |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
236 |
|
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
237 |
$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
|
238 |
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
|
239 |
{ |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
240 |
eval($cmd); |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
241 |
} |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
242 |
|
1 | 243 |
$php = preg_match_all('#<\?php(.*?)\?>#is', $text, $phpsec); |
244 |
||
245 |
for($i=0;$i<sizeof($phpsec[1]);$i++) |
|
246 |
{ |
|
247 |
$text = str_replace('<?php'.$phpsec[1][$i].'?>', '{PHP:'.$random_id.':'.$i.'}', $text); |
|
248 |
} |
|
249 |
||
250 |
$text = preg_replace('/<noinclude>(.*?)<\/noinclude>/is', '\\1', $text); |
|
251 |
if ( $paths->namespace == 'Template' ) |
|
252 |
{ |
|
253 |
$text = preg_replace('/<nodisplay>(.*?)<\/nodisplay>/is', '', $text); |
|
254 |
} |
|
255 |
||
717
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
256 |
preg_match_all('/<lang code="([a-z0-9_-]+)">([\w\W]+?)<\/lang>/', $text, $langmatch); |
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
|
257 |
foreach ( $langmatch[0] as $i => $match ) |
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
|
258 |
{ |
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
|
259 |
if ( $langmatch[1][$i] == $lang->lang_code ) |
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
|
260 |
{ |
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
|
261 |
$text = str_replace_once($match, $langmatch[2][$i], $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
|
262 |
} |
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
|
263 |
else |
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
|
264 |
{ |
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
|
265 |
$text = str_replace_once($match, '', $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
|
266 |
} |
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
|
267 |
} |
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
|
268 |
|
163 | 269 |
$code = $plugins->setHook('render_wikiformat_pre'); |
270 |
foreach ( $code as $cmd ) |
|
271 |
{ |
|
272 |
eval($cmd); |
|
273 |
} |
|
274 |
||
715 | 275 |
//$template_regex = "/\{\{([^\]]+?)((\n([ ]*?)[A-z0-9]+([ ]*?)=([ ]*?)(.+?))*)\}\}/is"; |
276 |
$template_regex = "/\{\{(.+)((\n|\|[ ]*([A-z0-9]+)[ ]*=[ ]*(.+))*)\}\}/isU"; |
|
277 |
$i = 0; |
|
278 |
while ( preg_match($template_regex, $text) ) |
|
279 |
{ |
|
280 |
$i++; |
|
281 |
if ( $i == 5 ) |
|
282 |
break; |
|
283 |
$text = RenderMan::include_templates($text); |
|
284 |
} |
|
285 |
||
1 | 286 |
if ( !$plaintext ) |
287 |
{ |
|
288 |
// Process images |
|
142
ca9118d9c0f2
Rebrand as 1.0.2 (Coblynau); internal links are now parsed by RenderMan::parse_internal_links()
Dan
parents:
136
diff
changeset
|
289 |
$text = RenderMan::process_image_tags($text, $taglist); |
66
52017732bc20
Added "raw" option to embedded images to make complex clickables easier
Dan
parents:
65
diff
changeset
|
290 |
$text = RenderMan::process_imgtags_stage2($text, $taglist); |
1 | 291 |
} |
292 |
||
293 |
if($do_params) |
|
294 |
{ |
|
295 |
preg_match_all('#\(_([0-9]+)_\)#', $text, $matchlist); |
|
296 |
foreach($matchlist[1] as $m) |
|
297 |
{ |
|
298 |
$text = str_replace('(_'.$m.'_)', $paths->getParam((int)$m), $text); |
|
299 |
} |
|
300 |
} |
|
301 |
||
335
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
326
diff
changeset
|
302 |
// Before shipping it out to the renderer, replace spaces in between headings and paragraphs: |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
326
diff
changeset
|
303 |
$text = preg_replace('/<\/(h[0-9]|div|p)>([\s]+)<(h[0-9]|div|p)( .+?)?>/i', '</\\1><\\3\\4>', $text); |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
326
diff
changeset
|
304 |
|
1 | 305 |
$text = process_tables($text); |
142
ca9118d9c0f2
Rebrand as 1.0.2 (Coblynau); internal links are now parsed by RenderMan::parse_internal_links()
Dan
parents:
136
diff
changeset
|
306 |
$text = RenderMan::parse_internal_links($text); |
1 | 307 |
|
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
|
308 |
$wiki = Text_Wiki::singleton('Mediawiki'); |
1 | 309 |
if($plaintext) |
310 |
{ |
|
311 |
$wiki->setRenderConf('Plain', 'wikilink', 'view_url', contentPath); |
|
312 |
$result = $wiki->transform($text, 'Plain'); |
|
313 |
} |
|
314 |
else |
|
315 |
{ |
|
316 |
$wiki->setRenderConf('Xhtml', 'wikilink', 'view_url', contentPath); |
|
317 |
$wiki->setRenderConf('Xhtml', 'Url', 'css_descr', 'external'); |
|
318 |
$result = $wiki->transform($text, 'Xhtml'); |
|
319 |
} |
|
320 |
||
163 | 321 |
// HTML fixes |
322 |
$result = preg_replace('#<tr>([\s]*?)<\/tr>#is', '', $result); |
|
323 |
$result = preg_replace('#<p>([\s]*?)<\/p>#is', '', $result); |
|
324 |
$result = preg_replace('#<br />([\s]*?)<table#is', '<table', $result); |
|
325 |
$result = str_replace("<pre><code>\n", "<pre><code>", $result); |
|
326 |
$result = preg_replace("/<p><table([^>]*?)><\/p>/", "<table\\1>", $result); |
|
327 |
$result = str_replace("<br />\n</td>", "\n</td>", $result); |
|
328 |
$result = str_replace("<p><tr>", "<tr>", $result); |
|
329 |
$result = str_replace("<tr><br />", "<tr>", $result); |
|
330 |
$result = str_replace("</tr><br />", "</tr>", $result); |
|
331 |
$result = str_replace("</table><br />", "</table>", $result); |
|
332 |
$result = preg_replace('/<\/table>$/', "</table><br /><br />", $result); |
|
333 |
$result = str_replace("<p></div></p>", "</div>", $result); |
|
334 |
$result = str_replace("<p></table></p>", "</table>", $result); |
|
335 |
||
336 |
$code = $plugins->setHook('render_wikiformat_post'); |
|
337 |
foreach ( $code as $cmd ) |
|
338 |
{ |
|
339 |
eval($cmd); |
|
340 |
} |
|
37 | 341 |
|
1 | 342 |
// Reinsert <nowiki> sections |
343 |
for($i=0;$i<$nw;$i++) |
|
344 |
{ |
|
345 |
$result = str_replace('{NOWIKI:'.$random_id.':'.$i.'}', $nowiki[1][$i], $result); |
|
346 |
} |
|
347 |
||
348 |
// Reinsert PHP |
|
349 |
for($i=0;$i<$php;$i++) |
|
350 |
{ |
|
351 |
$result = str_replace('{PHP:'.$random_id.':'.$i.'}', '<?php'.$phpsec[1][$i].'?>', $result); |
|
352 |
} |
|
353 |
||
382
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
parents:
377
diff
changeset
|
354 |
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
|
355 |
|
1 | 356 |
return $result; |
357 |
||
358 |
} |
|
359 |
||
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
|
360 |
public static function wikiFormat($message, $filter_links = true, $do_params = false, $plaintext = false) |
163 | 361 |
{ |
1 | 362 |
global $db, $session, $paths, $template, $plugins; // Common objects |
363 |
||
364 |
return RenderMan::next_gen_wiki_format($message, $plaintext, $filter_links, $do_params); |
|
365 |
||
366 |
$random_id = md5( time() . mt_rand() ); |
|
367 |
||
368 |
// Strip out <nowiki> sections |
|
369 |
$nw = preg_match_all('#<nowiki>(.*?)<\/nowiki>#is', $message, $nowiki); |
|
370 |
||
371 |
if(!$plaintext) |
|
372 |
{ |
|
373 |
||
374 |
//return '<pre>'.print_r($nowiki,true).'</pre>'; |
|
375 |
||
376 |
for($i=0;$i<sizeof($nowiki[1]);$i++) |
|
377 |
{ |
|
378 |
$message = str_replace('<nowiki>'.$nowiki[1][$i].'</nowiki>', '{NOWIKI:'.$random_id.':'.$i.'}', $message); |
|
379 |
} |
|
380 |
||
381 |
$message = preg_replace('/<noinclude>(.*?)<\/noinclude>/is', '\\1', $message); |
|
382 |
||
383 |
//return '<pre>'.htmlspecialchars($message).'</pre>'; |
|
384 |
||
35 | 385 |
$message = RenderMan::process_image_tags($message); |
1 | 386 |
|
387 |
} |
|
388 |
||
389 |
if($do_params) |
|
390 |
{ |
|
391 |
preg_match_all('#\(_([0-9]+)_\)#', $message, $matchlist); |
|
392 |
foreach($matchlist[1] as $m) |
|
393 |
{ |
|
394 |
$message = str_replace('(_'.$m.'_)', $paths->getParam((int)$m), $message); |
|
395 |
} |
|
396 |
} |
|
397 |
||
398 |
$message = RenderMan::include_templates($message); |
|
399 |
||
400 |
// Reinsert <nowiki> sections |
|
401 |
for($i=0;$i<$nw;$i++) |
|
402 |
{ |
|
403 |
$message = str_replace('{NOWIKI:'.$random_id.':'.$i.'}', '<nowiki>'.$nowiki[1][$i].'</nowiki>', $message); |
|
404 |
} |
|
405 |
||
406 |
$message = process_tables($message); |
|
407 |
//if($message2 != $message) return '<pre>'.htmlspecialchars($message2).'</pre>'; |
|
408 |
//$message = str_replace(array('<table>', '</table>'), array('<nowiki><table>', '</table></nowiki>'), $message); |
|
409 |
||
410 |
$wiki =& Text_Wiki::singleton('Mediawiki'); |
|
411 |
if($plaintext) |
|
412 |
{ |
|
413 |
$wiki->setRenderConf('Plain', 'wikilink', 'view_url', contentPath); |
|
414 |
$result = $wiki->transform($message, 'Plain'); |
|
415 |
} else { |
|
416 |
$wiki->setRenderConf('Xhtml', 'wikilink', 'view_url', contentPath); |
|
417 |
$wiki->setRenderConf('Xhtml', 'Url', 'css_descr', 'external'); |
|
418 |
$result = $wiki->transform($message, 'Xhtml'); |
|
419 |
} |
|
420 |
||
421 |
// HTML fixes |
|
422 |
$result = preg_replace('#<tr>([\s]*?)<\/tr>#is', '', $result); |
|
423 |
$result = preg_replace('#<p>([\s]*?)<\/p>#is', '', $result); |
|
424 |
$result = preg_replace('#<br />([\s]*?)<table#is', '<table', $result); |
|
425 |
$result = str_replace("<pre><code>\n", "<pre><code>", $result); |
|
426 |
$result = preg_replace("/<p><table([^>]*?)><\/p>/", "<table\\1>", $result); |
|
427 |
$result = str_replace("<br />\n</td>", "\n</td>", $result); |
|
428 |
$result = str_replace("<p><tr>", "<tr>", $result); |
|
429 |
$result = str_replace("<tr><br />", "<tr>", $result); |
|
430 |
$result = str_replace("</tr><br />", "</tr>", $result); |
|
431 |
$result = str_replace("</table></p>", "</table>", $result); |
|
432 |
$result = str_replace("</table><br />", "</table>", $result); |
|
433 |
$result = preg_replace('/<\/table>$/', "</table><br /><br />", $result); |
|
163 | 434 |
$result = str_replace("<p></div></p>", "</div>", $result); |
435 |
$result = str_replace("<p></table></p>", "</table>", $result); |
|
1 | 436 |
|
437 |
$result = str_replace('<nowiki>', '<nowiki>', $result); |
|
438 |
$result = str_replace('</nowiki>', '</nowiki>', $result); |
|
439 |
||
440 |
return $result; |
|
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 destroy_javascript($message, $_php = false) |
1 | 444 |
{ |
445 |
$message = preg_replace('#<(script|object|applet|embed|iframe|frame|form|input|select)(.*?)>#is', '<\\1\\2>', $message); |
|
446 |
$message = preg_replace('#</(script|object|applet|embed|iframe|frame|form|input|select)(.*?)>#is', '</\\1\\2>', $message); |
|
447 |
$message = preg_replace('#(javascript|script|activex|chrome|about|applet):#is', '\\1:', $message); |
|
448 |
if ( $_php ) |
|
449 |
{ |
|
450 |
// Left in only for compatibility |
|
451 |
$message = preg_replace('#<(.*?)>#is', '<\\1>', $message); |
|
452 |
$message = preg_replace('#<(.*?)>#is', '<\\1>', $message); |
|
453 |
$message = preg_replace('#<(\?|\?php|%)(.*?)(\?|%)>#is', '<\\1\\2\\3>', $message); |
|
454 |
// strip <a href="foo" onclick="bar();">-type attacks |
|
455 |
$message = preg_replace('#<([a-zA-Z:\-]+) (.*?)on([A-Za-z]*)=(.*?)>#is', '<\\1\\2on\\3=\\4>', $message); |
|
456 |
} |
|
457 |
return $message; |
|
458 |
} |
|
459 |
||
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
|
460 |
public static function strip_php($message) |
1 | 461 |
{ |
462 |
return RenderMan::destroy_javascript($message, true); |
|
463 |
} |
|
464 |
||
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
|
465 |
public static function sanitize_html($text) |
1 | 466 |
{ |
467 |
$text = htmlspecialchars($text); |
|
91 | 468 |
$allowed_tags = Array('b', 'i', 'u', 'pre', 'code', 'tt', 'br', 'p', 'nowiki', '!--([\w\W]+)--'); |
1 | 469 |
foreach($allowed_tags as $t) |
470 |
{ |
|
471 |
$text = preg_replace('#<'.$t.'>(.*?)</'.$t.'>#is', '<'.$t.'>\\1</'.$t.'>', $text); |
|
472 |
$text = preg_replace('#<'.$t.' />#is', '<'.$t.' />', $text); |
|
473 |
$text = preg_replace('#<'.$t.'>#is', '<'.$t.'>', $text); |
|
474 |
} |
|
475 |
return $text; |
|
476 |
} |
|
477 |
||
91 | 478 |
/** |
479 |
* Parses internal links (wikilinks) in a block of text. |
|
480 |
* @param string Text to process |
|
592 | 481 |
* @param string Optional. If included will be used as a template instead of using the default syntax. |
91 | 482 |
* @return string |
483 |
*/ |
|
484 |
||
592 | 485 |
public static function parse_internal_links($text, $tplcode = false) |
91 | 486 |
{ |
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
|
487 |
global $db, $session, $paths, $template, $plugins; // Common objects |
91 | 488 |
|
592 | 489 |
if ( is_string($tplcode) ) |
490 |
{ |
|
491 |
$parser = $template->makeParserText($tplcode); |
|
492 |
} |
|
493 |
||
91 | 494 |
// stage 1 - links with alternate text |
495 |
preg_match_all('/\[\[([^\[\]<>\{\}\|]+)\|(.+?)\]\]/', $text, $matches); |
|
496 |
foreach ( $matches[0] as $i => $match ) |
|
497 |
{ |
|
498 |
list($page_id, $namespace) = RenderMan::strToPageID($matches[1][$i]); |
|
715 | 499 |
if ( ($pos = strrpos($page_id, '#')) !== false ) |
500 |
{ |
|
501 |
$hash = substr($page_id, $pos); |
|
502 |
$page_id = substr($page_id, 0, $pos); |
|
503 |
} |
|
504 |
else |
|
505 |
{ |
|
506 |
$hash = ''; |
|
507 |
} |
|
91 | 508 |
$pid_clean = $paths->nslist[$namespace] . sanitize_page_id($page_id); |
509 |
||
715 | 510 |
$url = makeUrl($pid_clean, false, true) . $hash; |
91 | 511 |
$inner_text = $matches[2][$i]; |
512 |
$quot = '"'; |
|
513 |
$exists = ( isPage($pid_clean) ) ? '' : ' class="wikilink-nonexistent"'; |
|
514 |
||
592 | 515 |
if ( $tplcode ) |
516 |
{ |
|
517 |
$parser->assign_vars(array( |
|
518 |
'HREF' => $url, |
|
519 |
'FLAGS' => $exists, |
|
520 |
'TEXT' => $inner_text |
|
521 |
)); |
|
522 |
$link = $parser->run(); |
|
523 |
} |
|
524 |
else |
|
525 |
{ |
|
526 |
$link = "<a href={$quot}{$url}{$quot}{$exists}>{$inner_text}</a>"; |
|
527 |
} |
|
91 | 528 |
|
529 |
$text = str_replace($match, $link, $text); |
|
530 |
} |
|
531 |
||
532 |
// stage 2 - links with no alternate text |
|
533 |
preg_match_all('/\[\[([^\[\]<>\{\}\|]+)\]\]/', $text, $matches); |
|
534 |
foreach ( $matches[0] as $i => $match ) |
|
535 |
{ |
|
536 |
list($page_id, $namespace) = RenderMan::strToPageID($matches[1][$i]); |
|
537 |
$pid_clean = $paths->nslist[$namespace] . sanitize_page_id($page_id); |
|
538 |
||
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
|
539 |
$url = makeUrl($pid_clean, false, true); |
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
|
540 |
$inner_text = ( isPage($pid_clean) ) ? htmlspecialchars(get_page_title($pid_clean)) : htmlspecialchars($matches[1][$i]); |
91 | 541 |
$quot = '"'; |
542 |
$exists = ( isPage($pid_clean) ) ? '' : ' class="wikilink-nonexistent"'; |
|
543 |
||
592 | 544 |
if ( $tplcode ) |
545 |
{ |
|
546 |
$parser->assign_vars(array( |
|
547 |
'HREF' => $url, |
|
548 |
'FLAGS' => $exists, |
|
549 |
'TEXT' => $inner_text |
|
550 |
)); |
|
551 |
$link = $parser->run(); |
|
552 |
} |
|
553 |
else |
|
554 |
{ |
|
555 |
$link = "<a href={$quot}{$url}{$quot}{$exists}>{$inner_text}</a>"; |
|
556 |
} |
|
91 | 557 |
|
558 |
$text = str_replace($match, $link, $text); |
|
559 |
} |
|
560 |
||
561 |
return $text; |
|
562 |
} |
|
563 |
||
1 | 564 |
/** |
565 |
* 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
|
566 |
* @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
|
567 |
* @example |
1 | 568 |
* <code> |
63
2c57d3018a88
Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents:
37
diff
changeset
|
569 |
foo = lorem ipsum |
2c57d3018a88
Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents:
37
diff
changeset
|
570 |
bar = dolor sit amet |
1 | 571 |
* </code> |
572 |
* @return array Example: |
|
573 |
* [foo] => lorem ipsum |
|
574 |
* [bar] => dolor sit amet |
|
575 |
*/ |
|
576 |
||
717
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
577 |
public static function parse_template_vars($input, $newlinemode = true) |
1 | 578 |
{ |
717
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
579 |
$parms = array(); |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
580 |
$input = trim($input); |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
581 |
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
|
582 |
{ |
717
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
583 |
$result = preg_match_all('/ |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
584 |
(?:^|[\s]*)\|? # start of parameter - string start or series of spaces |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
585 |
[ ]* |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
586 |
(?: |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
587 |
([A-z0-9_]+) # variable name |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
588 |
[ ]* = [ ]* # assignment |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
589 |
)? # this is optional - if the parameter name is not given, a numerical index is assigned |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
590 |
(.+) # value |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
591 |
/x', trim($input), $matches); |
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
|
592 |
} |
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
|
593 |
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
|
594 |
{ |
717
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
595 |
$result = preg_match_all('/ |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
596 |
(?:^|[ ]*)\| # start of parameter - string start or series of spaces |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
597 |
[ ]* |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
598 |
(?: |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
599 |
([A-z0-9_]+) # variable name |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
600 |
[ ]* = [ ]* # assignment |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
601 |
)? # name section is optional - if the parameter name is not given, a numerical index is assigned |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
602 |
([^\|]+|.+?\n[ ]*\|) # value |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
603 |
/x', trim($input), $matches); |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
604 |
} |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
605 |
if ( $result ) |
1 | 606 |
{ |
717
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
607 |
$pi = 0; |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
608 |
for ( $i = 0; $i < count($matches[0]); $i++ ) |
1 | 609 |
{ |
717
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
610 |
$matches[1][$i] = trim($matches[1][$i]); |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
611 |
$parmname = !empty($matches[1][$i]) ? $matches[1][$i] : strval(++$pi); |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
612 |
$parms[ $parmname ] = $matches[2][$i]; |
1 | 613 |
} |
614 |
} |
|
615 |
return $parms; |
|
616 |
} |
|
617 |
||
618 |
/** |
|
619 |
* 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
|
620 |
* Updated in 1.0.2 to also parse template tags in the format of {{Foo |a = b |b = c |c = therefore, a}} |
1 | 621 |
* @param string The text to process |
622 |
* @return string Formatted text |
|
623 |
* @example |
|
624 |
* <code> |
|
625 |
$text = '{{Template |
|
717
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
626 |
| parm1 = Foo |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
627 |
| parm2 = Bar |
1 | 628 |
}}'; |
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
|
629 |
$text = RenderMan::include_templates($text); |
1 | 630 |
* </code> |
631 |
*/ |
|
632 |
||
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
|
633 |
public static function include_templates($text) |
1 | 634 |
{ |
635 |
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
|
636 |
// $template_regex = "/\{\{([^\]]+?)((\n([ ]*?)[A-z0-9]+([ ]*?)=([ ]*?)(.+?))*)\}\}/is"; |
717
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
637 |
// matches: |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
638 |
// 1 - template name |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
639 |
// 2 - parameter section |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
640 |
$template_regex = "/ |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
641 |
\{\{ # opening |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
642 |
([^\n\t\a\r]+) # template name |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
643 |
((?:(?:[\s]+\|?)[ ]*(?:[A-z0-9_]+)[ ]*=[ ]*?(?:.+))*) # parameters |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
644 |
\}\} # closing |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
645 |
/isxU"; |
1 | 646 |
if ( $count = preg_match_all($template_regex, $text, $matches) ) |
647 |
{ |
|
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
|
648 |
//die('<pre>' . print_r($matches, true) . '</pre>'); |
1 | 649 |
for ( $i = 0; $i < $count; $i++ ) |
650 |
{ |
|
63
2c57d3018a88
Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents:
37
diff
changeset
|
651 |
$matches[1][$i] = sanitize_page_id($matches[1][$i]); |
717
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
652 |
$newlinemode = ( substr($matches[2][$i], 0, 1) == "\n" ); |
1 | 653 |
$parmsection = trim($matches[2][$i]); |
654 |
if ( !empty($parmsection) ) |
|
655 |
{ |
|
717
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
656 |
$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
|
657 |
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
|
658 |
// 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
|
659 |
$parms = array(); |
1 | 660 |
} |
661 |
else |
|
662 |
{ |
|
663 |
$parms = Array(); |
|
664 |
} |
|
665 |
if ( $tpl_code = RenderMan::fetch_template_text($matches[1][$i]) ) |
|
666 |
{ |
|
667 |
$parser = $template->makeParserText($tpl_code); |
|
668 |
$parser->assign_vars($parms); |
|
669 |
$text = str_replace($matches[0][$i], $parser->run(), $text); |
|
670 |
} |
|
671 |
} |
|
672 |
} |
|
673 |
return $text; |
|
674 |
} |
|
675 |
||
676 |
/** |
|
677 |
* Preprocesses an HTML text string prior to being sent to MySQL. |
|
678 |
* @param string $text |
|
679 |
* @param bool $strip_all_php - if true, strips all PHP regardless of user permissions. Else, strips PHP only if user level < USER_LEVEL_ADMIN. |
|
680 |
*/ |
|
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
|
681 |
public static function preprocess_text($text, $strip_all_php = true, $sqlescape = true) |
1 | 682 |
{ |
683 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
684 |
$random_id = md5( time() . mt_rand() ); |
|
685 |
||
407
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
686 |
$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
|
687 |
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
|
688 |
{ |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
689 |
eval($cmd); |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
690 |
} |
1 | 691 |
|
692 |
$can_do_php = ( $session->get_permissions('php_in_pages') && !$strip_all_php ); |
|
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
|
693 |
$can_do_html = $session->get_permissions('html_in_pages'); |
1 | 694 |
|
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
|
695 |
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
|
696 |
{ |
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
|
697 |
$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
|
698 |
} |
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
|
699 |
else if ( !$can_do_html && !$can_do_php ) |
1 | 700 |
{ |
24 | 701 |
$text = sanitize_html($text, true); |
1 | 702 |
// If we can't do PHP, we can't do Javascript either. |
703 |
$text = RenderMan::destroy_javascript($text); |
|
704 |
} |
|
705 |
||
706 |
// Strip out <nowiki> sections and PHP code |
|
707 |
||
708 |
$php = preg_match_all('#(<|<)\?php(.*?)\?(>|>)#is', $text, $phpsec); |
|
709 |
||
710 |
//die('<pre>'.htmlspecialchars(print_r($phpsec, true))."\n".htmlspecialchars(print_r($text, true)).'</pre>'); |
|
711 |
||
712 |
for($i=0;$i<sizeof($phpsec[1]);$i++) |
|
713 |
{ |
|
714 |
$text = str_replace($phpsec[0][$i], '{PHP:'.$random_id.':'.$i.'}', $text); |
|
715 |
} |
|
716 |
||
717 |
$nw = preg_match_all('#<nowiki>(.*?)<\/nowiki>#is', $text, $nowiki); |
|
718 |
||
719 |
for($i=0;$i<sizeof($nowiki[1]);$i++) |
|
720 |
{ |
|
721 |
$text = str_replace('<nowiki>'.$nowiki[1][$i].'</nowiki>', '{NOWIKI:'.$random_id.':'.$i.'}', $text); |
|
722 |
} |
|
723 |
||
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
|
724 |
$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
|
725 |
$text = str_replace('~~~~', "[[User:$session->username|$session->username]] ".enano_date('G:i, j F Y (T)'), $text); |
1 | 726 |
$text = str_replace('~~~', "[[User:$session->username|$session->username]] ", $text); |
727 |
||
407
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
728 |
$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
|
729 |
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
|
730 |
{ |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
731 |
eval($cmd); |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
732 |
} |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
733 |
|
1 | 734 |
// Reinsert <nowiki> sections |
735 |
for($i=0;$i<$nw;$i++) |
|
736 |
{ |
|
737 |
$text = str_replace('{NOWIKI:'.$random_id.':'.$i.'}', '<nowiki>'.$nowiki[1][$i].'</nowiki>', $text); |
|
738 |
} |
|
739 |
// Reinsert PHP |
|
740 |
for($i=0;$i<$php;$i++) |
|
741 |
{ |
|
742 |
$phsec = ''.$phpsec[1][$i].'?php'.$phpsec[2][$i].'?'.$phpsec[3][$i].''; |
|
743 |
if ( $strip_all_php ) |
|
744 |
$phsec = htmlspecialchars($phsec); |
|
745 |
$text = str_replace('{PHP:'.$random_id.':'.$i.'}', $phsec, $text); |
|
746 |
} |
|
747 |
||
748 |
$text = ( $sqlescape ) ? $db->escape($text) : $text; |
|
749 |
||
750 |
return $text; |
|
751 |
} |
|
752 |
||
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
|
753 |
public static function smilieyize($text, $complete_urls = false) |
1 | 754 |
{ |
755 |
||
756 |
$random_id = md5( time() . mt_rand() ); |
|
757 |
||
758 |
// Smileys array - eventually this will be fetched from the database by |
|
759 |
// RenderMan::initSmileys during initialization, but it will all be hardcoded for beta 2 |
|
760 |
||
761 |
$smileys = Array( |
|
762 |
'O:-)' => 'face-angel.png', |
|
763 |
'O:)' => 'face-angel.png', |
|
764 |
'O=)' => 'face-angel.png', |
|
765 |
':-)' => 'face-smile.png', |
|
766 |
':)' => 'face-smile.png', |
|
767 |
'=)' => 'face-smile-big.png', |
|
768 |
':-(' => 'face-sad.png', |
|
769 |
':(' => 'face-sad.png', |
|
770 |
';(' => 'face-sad.png', |
|
771 |
':-O' => 'face-surprise.png', |
|
772 |
';-)' => 'face-wink.png', |
|
773 |
';)' => 'face-wink.png', |
|
774 |
'8-)' => 'face-glasses.png', |
|
775 |
'8)' => 'face-glasses.png', |
|
776 |
':-D' => 'face-grin.png', |
|
777 |
':D' => 'face-grin.png', |
|
778 |
'=D' => 'face-grin.png', |
|
779 |
':-*' => 'face-kiss.png', |
|
780 |
':*' => 'face-kiss.png', |
|
781 |
'=*' => 'face-kiss.png', |
|
782 |
':\'(' => 'face-crying.png', |
|
783 |
':-|' => 'face-plain.png', |
|
784 |
':-\\' => 'face-plain.png', |
|
785 |
':-/' => 'face-plain.png', |
|
786 |
':joke:' => 'face-plain.png', |
|
787 |
']:->' => '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
|
788 |
']:->' => 'face-devil-grin.png', |
1 | 789 |
':kiss:' => 'face-kiss.png', |
790 |
':-P' => 'face-tongue-out.png', |
|
791 |
':P' => 'face-tongue-out.png', |
|
792 |
':-p' => 'face-tongue-out.png', |
|
793 |
':p' => 'face-tongue-out.png', |
|
794 |
':-X' => 'face-sick.png', |
|
795 |
':X' => 'face-sick.png', |
|
796 |
':sick:' => 'face-sick.png', |
|
797 |
':-]' => 'face-oops.png', |
|
798 |
':]' => 'face-oops.png', |
|
799 |
':oops:' => 'face-oops.png', |
|
800 |
':-[' => 'face-embarassed.png', |
|
801 |
':[' => 'face-embarassed.png' |
|
802 |
); |
|
803 |
/* |
|
804 |
$keys = array_keys($smileys); |
|
805 |
foreach($keys as $k) |
|
806 |
{ |
|
807 |
$regex1 = '#([\W]+)'.preg_quote($k).'([\s\n\r\.]+)#s'; |
|
808 |
$regex2 = '\\1<img alt="'.$k.'" title="'.$k.'" src="'.scriptPath.'/images/smilies/'.$smileys[$k].'" style="border: 0;" />\\2'; |
|
809 |
$text = preg_replace($regex1, $regex2, $text); |
|
810 |
} |
|
811 |
*/ |
|
812 |
||
813 |
// Strip out <nowiki> sections |
|
814 |
//return '<pre>'.htmlspecialchars($text).'</pre>'; |
|
815 |
$nw = preg_match_all('#<nowiki>(.*?)<\/nowiki>#is', $text, $nowiki); |
|
816 |
||
817 |
for($i=0;$i<sizeof($nowiki[1]);$i++) |
|
818 |
{ |
|
819 |
$text = str_replace('<nowiki>'.$nowiki[1][$i].'</nowiki>', '{NOWIKI:'.$random_id.':'.$i.'}', $text); |
|
820 |
} |
|
821 |
||
822 |
$keys = array_keys($smileys); |
|
823 |
foreach($keys as $k) |
|
824 |
{ |
|
391
85f91037cd4f
Localization is FINISHED, DAMN IT HELLAH YEAH! OVER WITH! Man, it feels to get that off my chest. Release is in under 48 hours, folks. And we're ready for it.
Dan
parents:
387
diff
changeset
|
825 |
$t = hexencode($k, ' ', ''); |
85f91037cd4f
Localization is FINISHED, DAMN IT HELLAH YEAH! OVER WITH! Man, it feels to get that off my chest. Release is in under 48 hours, folks. And we're ready for it.
Dan
parents:
387
diff
changeset
|
826 |
$t = trim($t); |
1 | 827 |
$t = explode(' ', $t); |
828 |
$s = ''; |
|
829 |
foreach($t as $b) |
|
830 |
{ |
|
831 |
$s.='&#x'.$b.';'; |
|
832 |
} |
|
833 |
$pfx = ( $complete_urls ) ? 'http' . ( isset($_SERVER['HTTPS']) ? 's' : '' ) . '://'.$_SERVER['HTTP_HOST'] : ''; |
|
834 |
$text = str_replace(' '.$k, ' <nowiki><img title="'.$s.'" alt="'.$s.'" src="'.$pfx.scriptPath.'/images/smilies/'.$smileys[$k].'" style="border: 0;" /></nowiki>', $text); |
|
835 |
} |
|
836 |
//*/ |
|
837 |
||
838 |
// Reinsert <nowiki> sections |
|
839 |
for($i=0;$i<$nw;$i++) |
|
840 |
{ |
|
841 |
$text = str_replace('{NOWIKI:'.$random_id.':'.$i.'}', '<nowiki>'.$nowiki[1][$i].'</nowiki>', $text); |
|
842 |
} |
|
843 |
||
844 |
return $text; |
|
845 |
} |
|
846 |
||
847 |
/* |
|
848 |
* **** DEPRECATED **** |
|
849 |
* Replaces some critical characters in a string with MySQL-safe equivalents |
|
850 |
* @param $text string the text to escape |
|
851 |
* @return array key 0 is the escaped text, key 1 is the character tag |
|
852 |
* / |
|
853 |
||
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
|
854 |
public static function escape_page_text($text) |
1 | 855 |
{ |
856 |
$char_tag = md5(microtime() . mt_rand()); |
|
857 |
$text = str_replace("'", "{APOS:$char_tag}", $text); |
|
858 |
$text = str_replace('"', "{QUOT:$char_tag}", $text); |
|
859 |
$text = str_replace("\\", "{SLASH:$char_tag}", $text); |
|
860 |
return Array($text, $char_tag); |
|
861 |
} |
|
862 |
*/ |
|
863 |
||
864 |
/* **** DEPRECATED **** |
|
865 |
* Reverses the result of RenderMan::escape_page_text(). |
|
866 |
* @param $text string the text to unescape |
|
867 |
* @param $char_tag string the character tag |
|
868 |
* @return string |
|
869 |
* / |
|
870 |
||
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
|
871 |
public static function unescape_page_text($text, $char_tag) |
1 | 872 |
{ |
873 |
$text = str_replace("{APOS:$char_tag}", "'", $text); |
|
874 |
$text = str_replace("{QUOT:$char_tag}", '"', $text); |
|
875 |
$text = str_replace("{SLASH:$char_tag}", "\\", $text); |
|
876 |
return $text; |
|
877 |
} |
|
878 |
*/ |
|
879 |
||
880 |
/** |
|
881 |
* Generates a summary of the differences between two texts, and formats it as XHTML. |
|
882 |
* @param $str1 string the first block of text |
|
883 |
* @param $str2 string the second block of text |
|
884 |
* @return string |
|
885 |
*/ |
|
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
|
886 |
public static function diff($str1, $str2) |
1 | 887 |
{ |
888 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
592 | 889 |
require_once(ENANO_ROOT.'/includes/diff.php'); |
1 | 890 |
$str1 = explode("\n", $str1); |
891 |
$str2 = explode("\n", $str2); |
|
892 |
$diff = new Diff($str1, $str2); |
|
893 |
$renderer = new TableDiffFormatter(); |
|
894 |
return '<table class="diff">'.$renderer->format($diff).'</table>'; |
|
895 |
} |
|
896 |
||
35 | 897 |
/** |
898 |
* Changes wikitext image tags to HTML. |
|
899 |
* @param string The wikitext to process |
|
37 | 900 |
* @param array Will be overwritten with the list of HTML tags (the system uses tokens for TextWiki compatibility) |
35 | 901 |
* @return string |
902 |
*/ |
|
903 |
||
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
|
904 |
public static function process_image_tags($text, &$taglist) |
35 | 905 |
{ |
906 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
907 |
||
37 | 908 |
$s_delim = "\xFF"; |
909 |
$f_delim = "\xFF"; |
|
910 |
$taglist = array(); |
|
911 |
||
35 | 912 |
// 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
|
913 |
$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
|
914 |
$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
|
915 |
\[\[ # 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
|
916 |
:' . $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
|
917 |
(?:(?:\|(?:.+?))*) # 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
|
918 |
\]\] # 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
|
919 |
/ix'; |
35 | 920 |
|
921 |
preg_match_all($regex, $text, $matches); |
|
922 |
||
923 |
foreach ( $matches[0] as $i => $match ) |
|
924 |
{ |
|
925 |
||
926 |
$full_tag =& $matches[0][$i]; |
|
927 |
$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
|
928 |
|
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
|
929 |
// 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
|
930 |
$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
|
931 |
$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
|
932 |
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
|
933 |
{ |
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
|
934 |
$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
|
935 |
$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
|
936 |
} |
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
|
937 |
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
|
938 |
{ |
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
|
939 |
// 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
|
940 |
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
|
941 |
} |
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
|
942 |
|
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
|
943 |
// 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
|
944 |
$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
|
945 |
$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
|
946 |
$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
|
947 |
$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
|
948 |
$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
|
949 |
$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
|
950 |
|
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
|
951 |
// 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
|
952 |
$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
|
953 |
// 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
|
954 |
$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
|
955 |
$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
|
956 |
// 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
|
957 |
$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
|
958 |
|
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
|
959 |
// 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
|
960 |
// 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
|
961 |
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
|
962 |
{ |
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
|
963 |
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
|
964 |
{ |
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
|
965 |
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
|
966 |
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
|
967 |
$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
|
968 |
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
|
969 |
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
|
970 |
$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
|
971 |
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
|
972 |
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
|
973 |
$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
|
974 |
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
|
975 |
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
|
976 |
// 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
|
977 |
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
|
978 |
{ |
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
|
979 |
$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
|
980 |
$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
|
981 |
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
|
982 |
} |
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
|
983 |
// not the height, so see if a plugin took this over |
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
|
984 |
// this hook requires plugins to return true if they modified anythin |
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
|
985 |
$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
|
986 |
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
|
987 |
{ |
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
|
988 |
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
|
989 |
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
|
990 |
} |
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
|
991 |
// 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
|
992 |
// 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
|
993 |
$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
|
994 |
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
|
995 |
} |
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
|
996 |
} |
35 | 997 |
|
998 |
if ( !isPage( $paths->nslist['File'] . $filename ) ) |
|
999 |
{ |
|
66
52017732bc20
Added "raw" option to embedded images to make complex clickables easier
Dan
parents:
65
diff
changeset
|
1000 |
$text = str_replace($full_tag, '[[' . makeUrlNS('File', $filename) . ']]', $text); |
35 | 1001 |
continue; |
1002 |
} |
|
1003 |
||
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
|
1004 |
if ( $scale_type == 'thumb' ) |
35 | 1005 |
{ |
1006 |
$r_width = 225; |
|
1007 |
$r_height = 225; |
|
1008 |
||
1009 |
$url = makeUrlNS('Special', 'DownloadFile/' . $filename, 'preview&width=' . $r_width . '&height=' . $r_height, true); |
|
1010 |
} |
|
1011 |
else if ( !empty($width) && !empty($height) ) |
|
1012 |
{ |
|
1013 |
$r_width = $width; |
|
1014 |
$r_height = $height; |
|
1015 |
||
1016 |
$url = makeUrlNS('Special', 'DownloadFile/' . $filename, 'preview&width=' . $r_width . '&height=' . $r_height, true); |
|
1017 |
} |
|
1018 |
else |
|
1019 |
{ |
|
1020 |
$url = makeUrlNS('Special', 'DownloadFile/' . $filename); |
|
1021 |
} |
|
1022 |
||
1023 |
$img_tag = '<img src="' . $url . '" '; |
|
1024 |
||
65 | 1025 |
// if ( isset($r_width) && isset($r_height) && $scale_type != '|thumb' ) |
1026 |
// { |
|
66
52017732bc20
Added "raw" option to embedded images to make complex clickables easier
Dan
parents:
65
diff
changeset
|
1027 |
// $img_tag .= 'width="' . $r_width . '" height="' . $r_height . '" '; |
65 | 1028 |
// } |
35 | 1029 |
|
66
52017732bc20
Added "raw" option to embedded images to make complex clickables easier
Dan
parents:
65
diff
changeset
|
1030 |
$img_tag .= 'style="border-width: 0px; /* background-color: white; */" '; |
35 | 1031 |
|
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
|
1032 |
$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
|
1033 |
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
|
1034 |
{ |
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
|
1035 |
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
|
1036 |
} |
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
|
1037 |
|
35 | 1038 |
$img_tag .= '/>'; |
1039 |
||
1040 |
$complete_tag = ''; |
|
1041 |
||
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
|
1042 |
if ( !empty($scale_type) && !$raw_display ) |
35 | 1043 |
{ |
1044 |
$complete_tag .= '<div class="thumbnail" '; |
|
1045 |
$clear_text = ''; |
|
1046 |
if ( !empty($clear) ) |
|
1047 |
{ |
|
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
|
1048 |
$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
|
1049 |
$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
|
1050 |
$clear_text .= "float: $side; margin-$opposite: 20px; width: {$r_width}px;"; |
35 | 1051 |
$complete_tag .= 'style="' . $clear_text . '" '; |
1052 |
} |
|
1053 |
$complete_tag .= '>'; |
|
1054 |
||
1055 |
$complete_tag .= '<a href="' . makeUrlNS('File', $filename) . '" style="display: block;">'; |
|
1056 |
$complete_tag .= $img_tag; |
|
1057 |
$complete_tag .= '</a>'; |
|
1058 |
||
1059 |
$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>'; |
|
1060 |
||
1061 |
if ( !empty($caption) ) |
|
1062 |
{ |
|
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
|
1063 |
$complete_tag .= $mag_button . $caption; |
35 | 1064 |
} |
1065 |
||
1066 |
$complete_tag .= '</div>'; |
|
1067 |
} |
|
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
|
1068 |
else if ( $raw_display ) |
66
52017732bc20
Added "raw" option to embedded images to make complex clickables easier
Dan
parents:
65
diff
changeset
|
1069 |
{ |
67 | 1070 |
$complete_tag .= "$img_tag"; |
1071 |
$taglist[$i] = $complete_tag; |
|
1072 |
||
1073 |
$repl = "{$s_delim}e_img_{$i}{$f_delim}"; |
|
1074 |
$text = str_replace($full_tag, $repl, $text); |
|
1075 |
continue; |
|
66
52017732bc20
Added "raw" option to embedded images to make complex clickables easier
Dan
parents:
65
diff
changeset
|
1076 |
} |
35 | 1077 |
else |
1078 |
{ |
|
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
|
1079 |
$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
|
1080 |
$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
|
1081 |
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
|
1082 |
{ |
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
|
1083 |
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
|
1084 |
} |
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
|
1085 |
$complete_tag .= '>'; |
35 | 1086 |
$complete_tag .= $img_tag; |
1087 |
$complete_tag .= '</a>'; |
|
1088 |
} |
|
1089 |
||
37 | 1090 |
$complete_tag .= "\n\n"; |
1091 |
$taglist[$i] = $complete_tag; |
|
35 | 1092 |
|
37 | 1093 |
$pos = strpos($text, $full_tag); |
35 | 1094 |
|
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
|
1095 |
/* |
35 | 1096 |
while(true) |
1097 |
{ |
|
1098 |
$check1 = substr($text, $pos, 3); |
|
1099 |
$check2 = substr($text, $pos, 1); |
|
1100 |
if ( $check1 == '<p>' || $pos == 0 || $check2 == "\n" ) |
|
1101 |
{ |
|
1102 |
// die('found at pos '.$pos); |
|
1103 |
break; |
|
1104 |
} |
|
1105 |
$pos--; |
|
1106 |
} |
|
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
|
1107 |
*/ |
35 | 1108 |
|
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
|
1109 |
/* |
37 | 1110 |
$repl = "{$s_delim}e_img_{$i}{$f_delim}"; |
1111 |
$text = substr($text, 0, $pos) . $repl . substr($text, $pos); |
|
35 | 1112 |
|
1113 |
$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
|
1114 |
*/ |
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
|
1115 |
$text = str_replace_once($full_tag, $complete_tag, $text); |
35 | 1116 |
|
1117 |
unset($full_tag, $filename, $scale_type, $width, $height, $clear, $caption, $r_width, $r_height); |
|
1118 |
||
1119 |
} |
|
1120 |
||
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
|
1121 |
// 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
|
1122 |
// 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
|
1123 |
|
35 | 1124 |
return $text; |
1125 |
} |
|
1126 |
||
37 | 1127 |
/** |
1128 |
* Finalizes processing of image tags. |
|
1129 |
* @param string The preprocessed text |
|
1130 |
* @param array The list of image tags created by RenderMan::process_image_tags() |
|
1131 |
*/ |
|
1132 |
||
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
|
1133 |
public static function process_imgtags_stage2($text, $taglist) |
37 | 1134 |
{ |
1135 |
$s_delim = "\xFF"; |
|
1136 |
$f_delim = "\xFF"; |
|
1137 |
foreach ( $taglist as $i => $tag ) |
|
1138 |
{ |
|
1139 |
$repl = "{$s_delim}e_img_{$i}{$f_delim}"; |
|
1140 |
$text = str_replace($repl, $tag, $text); |
|
1141 |
} |
|
1142 |
return $text; |
|
1143 |
} |
|
1144 |
||
1 | 1145 |
} |
1146 |
||
1147 |
?> |