author | Dan |
Sat, 23 Aug 2008 16:02:07 -0400 | |
changeset 702 | 15cd41fd8a05 |
parent 685 | 17ebe24cdf85 |
child 715 | 29663506e85c |
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); |
|
148 |
} |
|
149 |
$text = RenderMan::include_templates($text); |
|
150 |
return $text; |
|
151 |
} |
|
152 |
||
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
|
153 |
public static function fetch_template_text($id) |
1 | 154 |
{ |
155 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
156 |
if(!isset($paths->pages[$paths->nslist['Template'].$id])) |
|
157 |
{ |
|
158 |
return '[['.$paths->nslist['Template'].$id.']]'; |
|
159 |
} |
|
160 |
if(isset($paths->template_cache[$id])) |
|
161 |
{ |
|
162 |
$text = $paths->template_cache[$id]; |
|
163 |
} |
|
164 |
else |
|
165 |
{ |
|
166 |
$text = RenderMan::getPage($id, 'Template', 0, false, false, false, false); |
|
167 |
$paths->template_cache[$id] = $text; |
|
168 |
} |
|
169 |
||
170 |
if ( is_string($text) ) |
|
171 |
{ |
|
172 |
$text = preg_replace('/<noinclude>(.*?)<\/noinclude>/is', '', $text); |
|
173 |
$text = preg_replace('/<nodisplay>(.*?)<\/nodisplay>/is', '\\1', $text); |
|
174 |
} |
|
175 |
||
176 |
return $text; |
|
177 |
} |
|
178 |
||
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
|
179 |
public static function render($text, $wiki = 1, $smilies = true, $filter_links = true) |
1 | 180 |
{ |
181 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
182 |
if($smilies) |
|
183 |
{ |
|
184 |
$text = RenderMan::smilieyize($text); |
|
185 |
} |
|
186 |
if($wiki == 1) |
|
187 |
{ |
|
188 |
$text = RenderMan::next_gen_wiki_format($text); |
|
189 |
} |
|
190 |
elseif($wiki == 2) |
|
191 |
{ |
|
192 |
$text = $template->tplWikiFormat($text); |
|
193 |
} |
|
194 |
return $text; |
|
195 |
} |
|
196 |
||
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
|
197 |
public static function PlainTextRender($text, $wiki = 1, $smilies = false, $filter_links = true) |
1 | 198 |
{ |
199 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
200 |
if($smilies) |
|
201 |
{ |
|
202 |
$text = RenderMan::smilieyize($text); |
|
203 |
} |
|
204 |
if($wiki == 1) |
|
205 |
{ |
|
206 |
$text = RenderMan::next_gen_wiki_format($text, true); |
|
207 |
} |
|
208 |
elseif($wiki == 2) |
|
209 |
{ |
|
210 |
$text = $template->tplWikiFormat($text); |
|
211 |
} |
|
212 |
return $text; |
|
213 |
} |
|
214 |
||
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
|
215 |
public static function next_gen_wiki_format($text, $plaintext = false, $filter_links = true, $do_params = false) |
1 | 216 |
{ |
217 |
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
|
218 |
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
|
219 |
|
592 | 220 |
require_once(ENANO_ROOT.'/includes/wikiformat.php'); |
221 |
require_once(ENANO_ROOT.'/includes/wikiengine/Tables.php'); |
|
222 |
||
382
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
parents:
377
diff
changeset
|
223 |
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
|
224 |
|
1 | 225 |
$random_id = md5( time() . mt_rand() ); |
226 |
||
227 |
// Strip out <nowiki> sections and PHP code |
|
228 |
||
407
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
229 |
$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
|
230 |
|
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
231 |
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
|
232 |
{ |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
233 |
$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
|
234 |
} |
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 |
$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
|
237 |
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
|
238 |
{ |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
239 |
eval($cmd); |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
240 |
} |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
241 |
|
1 | 242 |
$php = preg_match_all('#<\?php(.*?)\?>#is', $text, $phpsec); |
243 |
||
244 |
for($i=0;$i<sizeof($phpsec[1]);$i++) |
|
245 |
{ |
|
246 |
$text = str_replace('<?php'.$phpsec[1][$i].'?>', '{PHP:'.$random_id.':'.$i.'}', $text); |
|
247 |
} |
|
248 |
||
249 |
$text = preg_replace('/<noinclude>(.*?)<\/noinclude>/is', '\\1', $text); |
|
250 |
if ( $paths->namespace == 'Template' ) |
|
251 |
{ |
|
252 |
$text = preg_replace('/<nodisplay>(.*?)<\/nodisplay>/is', '', $text); |
|
253 |
} |
|
254 |
||
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
|
255 |
preg_match_all('/<lang code="([a-z0-9_]+)">([\w\W]+?)<\/lang>/', $text, $langmatch); |
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
|
256 |
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
|
257 |
{ |
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 |
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
|
259 |
{ |
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 |
$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
|
261 |
} |
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 |
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
|
263 |
{ |
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 |
$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
|
265 |
} |
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 |
|
163 | 268 |
$code = $plugins->setHook('render_wikiformat_pre'); |
269 |
foreach ( $code as $cmd ) |
|
270 |
{ |
|
271 |
eval($cmd); |
|
272 |
} |
|
273 |
||
1 | 274 |
if ( !$plaintext ) |
275 |
{ |
|
276 |
// 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
|
277 |
$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
|
278 |
$text = RenderMan::process_imgtags_stage2($text, $taglist); |
1 | 279 |
} |
280 |
||
281 |
if($do_params) |
|
282 |
{ |
|
283 |
preg_match_all('#\(_([0-9]+)_\)#', $text, $matchlist); |
|
284 |
foreach($matchlist[1] as $m) |
|
285 |
{ |
|
286 |
$text = str_replace('(_'.$m.'_)', $paths->getParam((int)$m), $text); |
|
287 |
} |
|
288 |
} |
|
289 |
||
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
|
290 |
//$template_regex = "/\{\{([^\]]+?)((\n([ ]*?)[A-z0-9]+([ ]*?)=([ ]*?)(.+?))*)\}\}/is"; |
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
|
291 |
$template_regex = "/\{\{(.+)((\n|\|[ ]*([A-z0-9]+)[ ]*=[ ]*(.+))*)\}\}/isU"; |
63
2c57d3018a88
Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents:
37
diff
changeset
|
292 |
$i = 0; |
2c57d3018a88
Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents:
37
diff
changeset
|
293 |
while ( preg_match($template_regex, $text) ) |
2c57d3018a88
Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents:
37
diff
changeset
|
294 |
{ |
2c57d3018a88
Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents:
37
diff
changeset
|
295 |
$i++; |
2c57d3018a88
Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents:
37
diff
changeset
|
296 |
if ( $i == 5 ) |
2c57d3018a88
Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents:
37
diff
changeset
|
297 |
break; |
2c57d3018a88
Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents:
37
diff
changeset
|
298 |
$text = RenderMan::include_templates($text); |
2c57d3018a88
Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents:
37
diff
changeset
|
299 |
} |
1 | 300 |
|
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
|
301 |
// 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
|
302 |
$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
|
303 |
|
1 | 304 |
$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
|
305 |
$text = RenderMan::parse_internal_links($text); |
1 | 306 |
|
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
|
307 |
$wiki = Text_Wiki::singleton('Mediawiki'); |
1 | 308 |
if($plaintext) |
309 |
{ |
|
310 |
$wiki->setRenderConf('Plain', 'wikilink', 'view_url', contentPath); |
|
311 |
$result = $wiki->transform($text, 'Plain'); |
|
312 |
} |
|
313 |
else |
|
314 |
{ |
|
315 |
$wiki->setRenderConf('Xhtml', 'wikilink', 'view_url', contentPath); |
|
316 |
$wiki->setRenderConf('Xhtml', 'Url', 'css_descr', 'external'); |
|
317 |
$result = $wiki->transform($text, 'Xhtml'); |
|
318 |
} |
|
319 |
||
163 | 320 |
// HTML fixes |
321 |
$result = preg_replace('#<tr>([\s]*?)<\/tr>#is', '', $result); |
|
322 |
$result = preg_replace('#<p>([\s]*?)<\/p>#is', '', $result); |
|
323 |
$result = preg_replace('#<br />([\s]*?)<table#is', '<table', $result); |
|
324 |
$result = str_replace("<pre><code>\n", "<pre><code>", $result); |
|
325 |
$result = preg_replace("/<p><table([^>]*?)><\/p>/", "<table\\1>", $result); |
|
326 |
$result = str_replace("<br />\n</td>", "\n</td>", $result); |
|
327 |
$result = str_replace("<p><tr>", "<tr>", $result); |
|
328 |
$result = str_replace("<tr><br />", "<tr>", $result); |
|
329 |
$result = str_replace("</tr><br />", "</tr>", $result); |
|
330 |
$result = str_replace("</table><br />", "</table>", $result); |
|
331 |
$result = preg_replace('/<\/table>$/', "</table><br /><br />", $result); |
|
332 |
$result = str_replace("<p></div></p>", "</div>", $result); |
|
333 |
$result = str_replace("<p></table></p>", "</table>", $result); |
|
334 |
||
335 |
$code = $plugins->setHook('render_wikiformat_post'); |
|
336 |
foreach ( $code as $cmd ) |
|
337 |
{ |
|
338 |
eval($cmd); |
|
339 |
} |
|
37 | 340 |
|
1 | 341 |
// Reinsert <nowiki> sections |
342 |
for($i=0;$i<$nw;$i++) |
|
343 |
{ |
|
344 |
$result = str_replace('{NOWIKI:'.$random_id.':'.$i.'}', $nowiki[1][$i], $result); |
|
345 |
} |
|
346 |
||
347 |
// Reinsert PHP |
|
348 |
for($i=0;$i<$php;$i++) |
|
349 |
{ |
|
350 |
$result = str_replace('{PHP:'.$random_id.':'.$i.'}', '<?php'.$phpsec[1][$i].'?>', $result); |
|
351 |
} |
|
352 |
||
382
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
parents:
377
diff
changeset
|
353 |
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
|
354 |
|
1 | 355 |
return $result; |
356 |
||
357 |
} |
|
358 |
||
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
|
359 |
public static function wikiFormat($message, $filter_links = true, $do_params = false, $plaintext = false) |
163 | 360 |
{ |
1 | 361 |
global $db, $session, $paths, $template, $plugins; // Common objects |
362 |
||
363 |
return RenderMan::next_gen_wiki_format($message, $plaintext, $filter_links, $do_params); |
|
364 |
||
365 |
$random_id = md5( time() . mt_rand() ); |
|
366 |
||
367 |
// Strip out <nowiki> sections |
|
368 |
$nw = preg_match_all('#<nowiki>(.*?)<\/nowiki>#is', $message, $nowiki); |
|
369 |
||
370 |
if(!$plaintext) |
|
371 |
{ |
|
372 |
||
373 |
//return '<pre>'.print_r($nowiki,true).'</pre>'; |
|
374 |
||
375 |
for($i=0;$i<sizeof($nowiki[1]);$i++) |
|
376 |
{ |
|
377 |
$message = str_replace('<nowiki>'.$nowiki[1][$i].'</nowiki>', '{NOWIKI:'.$random_id.':'.$i.'}', $message); |
|
378 |
} |
|
379 |
||
380 |
$message = preg_replace('/<noinclude>(.*?)<\/noinclude>/is', '\\1', $message); |
|
381 |
||
382 |
//return '<pre>'.htmlspecialchars($message).'</pre>'; |
|
383 |
||
35 | 384 |
$message = RenderMan::process_image_tags($message); |
1 | 385 |
|
386 |
} |
|
387 |
||
388 |
if($do_params) |
|
389 |
{ |
|
390 |
preg_match_all('#\(_([0-9]+)_\)#', $message, $matchlist); |
|
391 |
foreach($matchlist[1] as $m) |
|
392 |
{ |
|
393 |
$message = str_replace('(_'.$m.'_)', $paths->getParam((int)$m), $message); |
|
394 |
} |
|
395 |
} |
|
396 |
||
397 |
$message = RenderMan::include_templates($message); |
|
398 |
||
399 |
// Reinsert <nowiki> sections |
|
400 |
for($i=0;$i<$nw;$i++) |
|
401 |
{ |
|
402 |
$message = str_replace('{NOWIKI:'.$random_id.':'.$i.'}', '<nowiki>'.$nowiki[1][$i].'</nowiki>', $message); |
|
403 |
} |
|
404 |
||
405 |
$message = process_tables($message); |
|
406 |
//if($message2 != $message) return '<pre>'.htmlspecialchars($message2).'</pre>'; |
|
407 |
//$message = str_replace(array('<table>', '</table>'), array('<nowiki><table>', '</table></nowiki>'), $message); |
|
408 |
||
409 |
$wiki =& Text_Wiki::singleton('Mediawiki'); |
|
410 |
if($plaintext) |
|
411 |
{ |
|
412 |
$wiki->setRenderConf('Plain', 'wikilink', 'view_url', contentPath); |
|
413 |
$result = $wiki->transform($message, 'Plain'); |
|
414 |
} else { |
|
415 |
$wiki->setRenderConf('Xhtml', 'wikilink', 'view_url', contentPath); |
|
416 |
$wiki->setRenderConf('Xhtml', 'Url', 'css_descr', 'external'); |
|
417 |
$result = $wiki->transform($message, 'Xhtml'); |
|
418 |
} |
|
419 |
||
420 |
// HTML fixes |
|
421 |
$result = preg_replace('#<tr>([\s]*?)<\/tr>#is', '', $result); |
|
422 |
$result = preg_replace('#<p>([\s]*?)<\/p>#is', '', $result); |
|
423 |
$result = preg_replace('#<br />([\s]*?)<table#is', '<table', $result); |
|
424 |
$result = str_replace("<pre><code>\n", "<pre><code>", $result); |
|
425 |
$result = preg_replace("/<p><table([^>]*?)><\/p>/", "<table\\1>", $result); |
|
426 |
$result = str_replace("<br />\n</td>", "\n</td>", $result); |
|
427 |
$result = str_replace("<p><tr>", "<tr>", $result); |
|
428 |
$result = str_replace("<tr><br />", "<tr>", $result); |
|
429 |
$result = str_replace("</tr><br />", "</tr>", $result); |
|
430 |
$result = str_replace("</table></p>", "</table>", $result); |
|
431 |
$result = str_replace("</table><br />", "</table>", $result); |
|
432 |
$result = preg_replace('/<\/table>$/', "</table><br /><br />", $result); |
|
163 | 433 |
$result = str_replace("<p></div></p>", "</div>", $result); |
434 |
$result = str_replace("<p></table></p>", "</table>", $result); |
|
1 | 435 |
|
436 |
$result = str_replace('<nowiki>', '<nowiki>', $result); |
|
437 |
$result = str_replace('</nowiki>', '</nowiki>', $result); |
|
438 |
||
439 |
return $result; |
|
440 |
} |
|
441 |
||
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
|
442 |
public static function destroy_javascript($message, $_php = false) |
1 | 443 |
{ |
444 |
$message = preg_replace('#<(script|object|applet|embed|iframe|frame|form|input|select)(.*?)>#is', '<\\1\\2>', $message); |
|
445 |
$message = preg_replace('#</(script|object|applet|embed|iframe|frame|form|input|select)(.*?)>#is', '</\\1\\2>', $message); |
|
446 |
$message = preg_replace('#(javascript|script|activex|chrome|about|applet):#is', '\\1:', $message); |
|
447 |
if ( $_php ) |
|
448 |
{ |
|
449 |
// Left in only for compatibility |
|
450 |
$message = preg_replace('#<(.*?)>#is', '<\\1>', $message); |
|
451 |
$message = preg_replace('#<(.*?)>#is', '<\\1>', $message); |
|
452 |
$message = preg_replace('#<(\?|\?php|%)(.*?)(\?|%)>#is', '<\\1\\2\\3>', $message); |
|
453 |
// strip <a href="foo" onclick="bar();">-type attacks |
|
454 |
$message = preg_replace('#<([a-zA-Z:\-]+) (.*?)on([A-Za-z]*)=(.*?)>#is', '<\\1\\2on\\3=\\4>', $message); |
|
455 |
} |
|
456 |
return $message; |
|
457 |
} |
|
458 |
||
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
|
459 |
public static function strip_php($message) |
1 | 460 |
{ |
461 |
return RenderMan::destroy_javascript($message, true); |
|
462 |
} |
|
463 |
||
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
|
464 |
public static function sanitize_html($text) |
1 | 465 |
{ |
466 |
$text = htmlspecialchars($text); |
|
91 | 467 |
$allowed_tags = Array('b', 'i', 'u', 'pre', 'code', 'tt', 'br', 'p', 'nowiki', '!--([\w\W]+)--'); |
1 | 468 |
foreach($allowed_tags as $t) |
469 |
{ |
|
470 |
$text = preg_replace('#<'.$t.'>(.*?)</'.$t.'>#is', '<'.$t.'>\\1</'.$t.'>', $text); |
|
471 |
$text = preg_replace('#<'.$t.' />#is', '<'.$t.' />', $text); |
|
472 |
$text = preg_replace('#<'.$t.'>#is', '<'.$t.'>', $text); |
|
473 |
} |
|
474 |
return $text; |
|
475 |
} |
|
476 |
||
91 | 477 |
/** |
478 |
* Parses internal links (wikilinks) in a block of text. |
|
479 |
* @param string Text to process |
|
592 | 480 |
* @param string Optional. If included will be used as a template instead of using the default syntax. |
91 | 481 |
* @return string |
482 |
*/ |
|
483 |
||
592 | 484 |
public static function parse_internal_links($text, $tplcode = false) |
91 | 485 |
{ |
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
|
486 |
global $db, $session, $paths, $template, $plugins; // Common objects |
91 | 487 |
|
592 | 488 |
if ( is_string($tplcode) ) |
489 |
{ |
|
490 |
$parser = $template->makeParserText($tplcode); |
|
491 |
} |
|
492 |
||
91 | 493 |
// stage 1 - links with alternate text |
494 |
preg_match_all('/\[\[([^\[\]<>\{\}\|]+)\|(.+?)\]\]/', $text, $matches); |
|
495 |
foreach ( $matches[0] as $i => $match ) |
|
496 |
{ |
|
497 |
list($page_id, $namespace) = RenderMan::strToPageID($matches[1][$i]); |
|
498 |
$pid_clean = $paths->nslist[$namespace] . sanitize_page_id($page_id); |
|
499 |
||
500 |
$url = makeUrl($pid_clean, false, true); |
|
501 |
$inner_text = $matches[2][$i]; |
|
502 |
$quot = '"'; |
|
503 |
$exists = ( isPage($pid_clean) ) ? '' : ' class="wikilink-nonexistent"'; |
|
504 |
||
592 | 505 |
if ( $tplcode ) |
506 |
{ |
|
507 |
$parser->assign_vars(array( |
|
508 |
'HREF' => $url, |
|
509 |
'FLAGS' => $exists, |
|
510 |
'TEXT' => $inner_text |
|
511 |
)); |
|
512 |
$link = $parser->run(); |
|
513 |
} |
|
514 |
else |
|
515 |
{ |
|
516 |
$link = "<a href={$quot}{$url}{$quot}{$exists}>{$inner_text}</a>"; |
|
517 |
} |
|
91 | 518 |
|
519 |
$text = str_replace($match, $link, $text); |
|
520 |
} |
|
521 |
||
522 |
// stage 2 - links with no alternate text |
|
523 |
preg_match_all('/\[\[([^\[\]<>\{\}\|]+)\]\]/', $text, $matches); |
|
524 |
foreach ( $matches[0] as $i => $match ) |
|
525 |
{ |
|
526 |
list($page_id, $namespace) = RenderMan::strToPageID($matches[1][$i]); |
|
527 |
$pid_clean = $paths->nslist[$namespace] . sanitize_page_id($page_id); |
|
528 |
||
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
|
529 |
$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
|
530 |
$inner_text = ( isPage($pid_clean) ) ? htmlspecialchars(get_page_title($pid_clean)) : htmlspecialchars($matches[1][$i]); |
91 | 531 |
$quot = '"'; |
532 |
$exists = ( isPage($pid_clean) ) ? '' : ' class="wikilink-nonexistent"'; |
|
533 |
||
592 | 534 |
if ( $tplcode ) |
535 |
{ |
|
536 |
$parser->assign_vars(array( |
|
537 |
'HREF' => $url, |
|
538 |
'FLAGS' => $exists, |
|
539 |
'TEXT' => $inner_text |
|
540 |
)); |
|
541 |
$link = $parser->run(); |
|
542 |
} |
|
543 |
else |
|
544 |
{ |
|
545 |
$link = "<a href={$quot}{$url}{$quot}{$exists}>{$inner_text}</a>"; |
|
546 |
} |
|
91 | 547 |
|
548 |
$text = str_replace($match, $link, $text); |
|
549 |
} |
|
550 |
||
551 |
return $text; |
|
552 |
} |
|
553 |
||
1 | 554 |
/** |
555 |
* 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
|
556 |
* @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
|
557 |
* @example |
1 | 558 |
* <code> |
63
2c57d3018a88
Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents:
37
diff
changeset
|
559 |
foo = lorem ipsum |
2c57d3018a88
Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents:
37
diff
changeset
|
560 |
bar = dolor sit amet |
1 | 561 |
* </code> |
562 |
* @return array Example: |
|
563 |
* [foo] => lorem ipsum |
|
564 |
* [bar] => dolor sit amet |
|
565 |
*/ |
|
566 |
||
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
|
567 |
public static function parse_template_vars($input) |
1 | 568 |
{ |
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
|
569 |
if ( !preg_match('/^(\|[ ]*([A-z0-9_]+)([ ]*)=([ ]*)(.+?))*$/is', trim($input)) ) |
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
|
570 |
{ |
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
|
571 |
$using_pipes = false; |
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
|
572 |
$input = explode("\n", trim( $input )); |
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
|
573 |
} |
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
|
574 |
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
|
575 |
{ |
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
|
576 |
$using_pipes = true; |
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
|
577 |
$input = substr($input, 1); |
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
|
578 |
$input = explode("|", trim( $input )); |
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
|
579 |
} |
1 | 580 |
$parms = Array(); |
581 |
$current_line = ''; |
|
582 |
$current_parm = ''; |
|
583 |
foreach ( $input as $num => $line ) |
|
584 |
{ |
|
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
|
585 |
if ( preg_match('/^[ ]*([A-z0-9_]+)([ ]*)=([ ]*)(.+?)$/is', $line, $matches) ) |
1 | 586 |
{ |
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
|
587 |
$parm =& $matches[1]; |
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
|
588 |
$text =& $matches[4]; |
1 | 589 |
if ( $parm == $current_parm ) |
590 |
{ |
|
591 |
$current_line .= $text; |
|
592 |
} |
|
593 |
else |
|
594 |
{ |
|
595 |
// New parameter |
|
596 |
if ( $current_parm != '' ) |
|
597 |
$parms[$current_parm] = $current_line; |
|
598 |
$current_line = $text; |
|
599 |
$current_parm = $parm; |
|
600 |
} |
|
601 |
} |
|
602 |
else if ( $num == 0 ) |
|
603 |
{ |
|
604 |
// Syntax error |
|
605 |
return false; |
|
606 |
} |
|
607 |
else |
|
608 |
{ |
|
609 |
$current_line .= "\n$line"; |
|
610 |
} |
|
611 |
} |
|
612 |
if ( !empty($current_parm) && !empty($current_line) ) |
|
613 |
{ |
|
614 |
$parms[$current_parm] = $current_line; |
|
615 |
} |
|
616 |
return $parms; |
|
617 |
} |
|
618 |
||
619 |
/** |
|
620 |
* 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
|
621 |
* Updated in 1.0.2 to also parse template tags in the format of {{Foo |a = b |b = c |c = therefore, a}} |
1 | 622 |
* @param string The text to process |
623 |
* @return string Formatted text |
|
624 |
* @example |
|
625 |
* <code> |
|
626 |
$text = '{{Template |
|
627 |
parm1 = Foo |
|
628 |
parm2 = Bar |
|
629 |
}}'; |
|
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
|
630 |
$text = RenderMan::include_templates($text); |
1 | 631 |
* </code> |
632 |
*/ |
|
633 |
||
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
|
634 |
public static function include_templates($text) |
1 | 635 |
{ |
636 |
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
|
637 |
// $template_regex = "/\{\{([^\]]+?)((\n([ ]*?)[A-z0-9]+([ ]*?)=([ ]*?)(.+?))*)\}\}/is"; |
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
|
638 |
$template_regex = "/\{\{(.+)(((\n|[ ]*\|)[ ]*([A-z0-9]+)[ ]*=[ ]*(.+))*)\}\}/isU"; |
1 | 639 |
if ( $count = preg_match_all($template_regex, $text, $matches) ) |
640 |
{ |
|
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
|
641 |
//die('<pre>' . print_r($matches, true) . '</pre>'); |
1 | 642 |
for ( $i = 0; $i < $count; $i++ ) |
643 |
{ |
|
63
2c57d3018a88
Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents:
37
diff
changeset
|
644 |
$matches[1][$i] = sanitize_page_id($matches[1][$i]); |
1 | 645 |
$parmsection = trim($matches[2][$i]); |
646 |
if ( !empty($parmsection) ) |
|
647 |
{ |
|
648 |
$parms = RenderMan::parse_template_vars($parmsection); |
|
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
|
649 |
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
|
650 |
// 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
|
651 |
$parms = array(); |
1 | 652 |
} |
653 |
else |
|
654 |
{ |
|
655 |
$parms = Array(); |
|
656 |
} |
|
657 |
if ( $tpl_code = RenderMan::fetch_template_text($matches[1][$i]) ) |
|
658 |
{ |
|
659 |
$parser = $template->makeParserText($tpl_code); |
|
660 |
$parser->assign_vars($parms); |
|
661 |
$text = str_replace($matches[0][$i], $parser->run(), $text); |
|
662 |
} |
|
663 |
} |
|
664 |
} |
|
665 |
return $text; |
|
666 |
} |
|
667 |
||
668 |
/** |
|
669 |
* Preprocesses an HTML text string prior to being sent to MySQL. |
|
670 |
* @param string $text |
|
671 |
* @param bool $strip_all_php - if true, strips all PHP regardless of user permissions. Else, strips PHP only if user level < USER_LEVEL_ADMIN. |
|
672 |
*/ |
|
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
|
673 |
public static function preprocess_text($text, $strip_all_php = true, $sqlescape = true) |
1 | 674 |
{ |
675 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
676 |
$random_id = md5( time() . mt_rand() ); |
|
677 |
||
407
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
678 |
$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
|
679 |
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
|
680 |
{ |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
681 |
eval($cmd); |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
682 |
} |
1 | 683 |
|
684 |
$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
|
685 |
$can_do_html = $session->get_permissions('html_in_pages'); |
1 | 686 |
|
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
|
687 |
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
|
688 |
{ |
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
|
689 |
$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
|
690 |
} |
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
|
691 |
else if ( !$can_do_html && !$can_do_php ) |
1 | 692 |
{ |
24 | 693 |
$text = sanitize_html($text, true); |
1 | 694 |
// If we can't do PHP, we can't do Javascript either. |
695 |
$text = RenderMan::destroy_javascript($text); |
|
696 |
} |
|
697 |
||
698 |
// Strip out <nowiki> sections and PHP code |
|
699 |
||
700 |
$php = preg_match_all('#(<|<)\?php(.*?)\?(>|>)#is', $text, $phpsec); |
|
701 |
||
702 |
//die('<pre>'.htmlspecialchars(print_r($phpsec, true))."\n".htmlspecialchars(print_r($text, true)).'</pre>'); |
|
703 |
||
704 |
for($i=0;$i<sizeof($phpsec[1]);$i++) |
|
705 |
{ |
|
706 |
$text = str_replace($phpsec[0][$i], '{PHP:'.$random_id.':'.$i.'}', $text); |
|
707 |
} |
|
708 |
||
709 |
$nw = preg_match_all('#<nowiki>(.*?)<\/nowiki>#is', $text, $nowiki); |
|
710 |
||
711 |
for($i=0;$i<sizeof($nowiki[1]);$i++) |
|
712 |
{ |
|
713 |
$text = str_replace('<nowiki>'.$nowiki[1][$i].'</nowiki>', '{NOWIKI:'.$random_id.':'.$i.'}', $text); |
|
714 |
} |
|
715 |
||
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
|
716 |
$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
|
717 |
$text = str_replace('~~~~', "[[User:$session->username|$session->username]] ".enano_date('G:i, j F Y (T)'), $text); |
1 | 718 |
$text = str_replace('~~~', "[[User:$session->username|$session->username]] ", $text); |
719 |
||
407
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
720 |
$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
|
721 |
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
|
722 |
{ |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
723 |
eval($cmd); |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
724 |
} |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
725 |
|
1 | 726 |
// Reinsert <nowiki> sections |
727 |
for($i=0;$i<$nw;$i++) |
|
728 |
{ |
|
729 |
$text = str_replace('{NOWIKI:'.$random_id.':'.$i.'}', '<nowiki>'.$nowiki[1][$i].'</nowiki>', $text); |
|
730 |
} |
|
731 |
// Reinsert PHP |
|
732 |
for($i=0;$i<$php;$i++) |
|
733 |
{ |
|
734 |
$phsec = ''.$phpsec[1][$i].'?php'.$phpsec[2][$i].'?'.$phpsec[3][$i].''; |
|
735 |
if ( $strip_all_php ) |
|
736 |
$phsec = htmlspecialchars($phsec); |
|
737 |
$text = str_replace('{PHP:'.$random_id.':'.$i.'}', $phsec, $text); |
|
738 |
} |
|
739 |
||
740 |
$text = ( $sqlescape ) ? $db->escape($text) : $text; |
|
741 |
||
742 |
return $text; |
|
743 |
} |
|
744 |
||
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
|
745 |
public static function smilieyize($text, $complete_urls = false) |
1 | 746 |
{ |
747 |
||
748 |
$random_id = md5( time() . mt_rand() ); |
|
749 |
||
750 |
// Smileys array - eventually this will be fetched from the database by |
|
751 |
// RenderMan::initSmileys during initialization, but it will all be hardcoded for beta 2 |
|
752 |
||
753 |
$smileys = Array( |
|
754 |
'O:-)' => 'face-angel.png', |
|
755 |
'O:)' => 'face-angel.png', |
|
756 |
'O=)' => 'face-angel.png', |
|
757 |
':-)' => 'face-smile.png', |
|
758 |
':)' => 'face-smile.png', |
|
759 |
'=)' => 'face-smile-big.png', |
|
760 |
':-(' => 'face-sad.png', |
|
761 |
':(' => 'face-sad.png', |
|
762 |
';(' => 'face-sad.png', |
|
763 |
':-O' => 'face-surprise.png', |
|
764 |
';-)' => 'face-wink.png', |
|
765 |
';)' => 'face-wink.png', |
|
766 |
'8-)' => 'face-glasses.png', |
|
767 |
'8)' => 'face-glasses.png', |
|
768 |
':-D' => 'face-grin.png', |
|
769 |
':D' => 'face-grin.png', |
|
770 |
'=D' => 'face-grin.png', |
|
771 |
':-*' => 'face-kiss.png', |
|
772 |
':*' => 'face-kiss.png', |
|
773 |
'=*' => 'face-kiss.png', |
|
774 |
':\'(' => 'face-crying.png', |
|
775 |
':-|' => 'face-plain.png', |
|
776 |
':-\\' => 'face-plain.png', |
|
777 |
':-/' => 'face-plain.png', |
|
778 |
':joke:' => 'face-plain.png', |
|
779 |
']:->' => '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
|
780 |
']:->' => 'face-devil-grin.png', |
1 | 781 |
':kiss:' => 'face-kiss.png', |
782 |
':-P' => 'face-tongue-out.png', |
|
783 |
':P' => 'face-tongue-out.png', |
|
784 |
':-p' => 'face-tongue-out.png', |
|
785 |
':p' => 'face-tongue-out.png', |
|
786 |
':-X' => 'face-sick.png', |
|
787 |
':X' => 'face-sick.png', |
|
788 |
':sick:' => 'face-sick.png', |
|
789 |
':-]' => 'face-oops.png', |
|
790 |
':]' => 'face-oops.png', |
|
791 |
':oops:' => 'face-oops.png', |
|
792 |
':-[' => 'face-embarassed.png', |
|
793 |
':[' => 'face-embarassed.png' |
|
794 |
); |
|
795 |
/* |
|
796 |
$keys = array_keys($smileys); |
|
797 |
foreach($keys as $k) |
|
798 |
{ |
|
799 |
$regex1 = '#([\W]+)'.preg_quote($k).'([\s\n\r\.]+)#s'; |
|
800 |
$regex2 = '\\1<img alt="'.$k.'" title="'.$k.'" src="'.scriptPath.'/images/smilies/'.$smileys[$k].'" style="border: 0;" />\\2'; |
|
801 |
$text = preg_replace($regex1, $regex2, $text); |
|
802 |
} |
|
803 |
*/ |
|
804 |
||
805 |
// Strip out <nowiki> sections |
|
806 |
//return '<pre>'.htmlspecialchars($text).'</pre>'; |
|
807 |
$nw = preg_match_all('#<nowiki>(.*?)<\/nowiki>#is', $text, $nowiki); |
|
808 |
||
809 |
for($i=0;$i<sizeof($nowiki[1]);$i++) |
|
810 |
{ |
|
811 |
$text = str_replace('<nowiki>'.$nowiki[1][$i].'</nowiki>', '{NOWIKI:'.$random_id.':'.$i.'}', $text); |
|
812 |
} |
|
813 |
||
814 |
$keys = array_keys($smileys); |
|
815 |
foreach($keys as $k) |
|
816 |
{ |
|
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
|
817 |
$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
|
818 |
$t = trim($t); |
1 | 819 |
$t = explode(' ', $t); |
820 |
$s = ''; |
|
821 |
foreach($t as $b) |
|
822 |
{ |
|
823 |
$s.='&#x'.$b.';'; |
|
824 |
} |
|
825 |
$pfx = ( $complete_urls ) ? 'http' . ( isset($_SERVER['HTTPS']) ? 's' : '' ) . '://'.$_SERVER['HTTP_HOST'] : ''; |
|
826 |
$text = str_replace(' '.$k, ' <nowiki><img title="'.$s.'" alt="'.$s.'" src="'.$pfx.scriptPath.'/images/smilies/'.$smileys[$k].'" style="border: 0;" /></nowiki>', $text); |
|
827 |
} |
|
828 |
//*/ |
|
829 |
||
830 |
// Reinsert <nowiki> sections |
|
831 |
for($i=0;$i<$nw;$i++) |
|
832 |
{ |
|
833 |
$text = str_replace('{NOWIKI:'.$random_id.':'.$i.'}', '<nowiki>'.$nowiki[1][$i].'</nowiki>', $text); |
|
834 |
} |
|
835 |
||
836 |
return $text; |
|
837 |
} |
|
838 |
||
839 |
/* |
|
840 |
* **** DEPRECATED **** |
|
841 |
* Replaces some critical characters in a string with MySQL-safe equivalents |
|
842 |
* @param $text string the text to escape |
|
843 |
* @return array key 0 is the escaped text, key 1 is the character tag |
|
844 |
* / |
|
845 |
||
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
|
846 |
public static function escape_page_text($text) |
1 | 847 |
{ |
848 |
$char_tag = md5(microtime() . mt_rand()); |
|
849 |
$text = str_replace("'", "{APOS:$char_tag}", $text); |
|
850 |
$text = str_replace('"', "{QUOT:$char_tag}", $text); |
|
851 |
$text = str_replace("\\", "{SLASH:$char_tag}", $text); |
|
852 |
return Array($text, $char_tag); |
|
853 |
} |
|
854 |
*/ |
|
855 |
||
856 |
/* **** DEPRECATED **** |
|
857 |
* Reverses the result of RenderMan::escape_page_text(). |
|
858 |
* @param $text string the text to unescape |
|
859 |
* @param $char_tag string the character tag |
|
860 |
* @return string |
|
861 |
* / |
|
862 |
||
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
|
863 |
public static function unescape_page_text($text, $char_tag) |
1 | 864 |
{ |
865 |
$text = str_replace("{APOS:$char_tag}", "'", $text); |
|
866 |
$text = str_replace("{QUOT:$char_tag}", '"', $text); |
|
867 |
$text = str_replace("{SLASH:$char_tag}", "\\", $text); |
|
868 |
return $text; |
|
869 |
} |
|
870 |
*/ |
|
871 |
||
872 |
/** |
|
873 |
* Generates a summary of the differences between two texts, and formats it as XHTML. |
|
874 |
* @param $str1 string the first block of text |
|
875 |
* @param $str2 string the second block of text |
|
876 |
* @return string |
|
877 |
*/ |
|
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
|
878 |
public static function diff($str1, $str2) |
1 | 879 |
{ |
880 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
592 | 881 |
require_once(ENANO_ROOT.'/includes/diff.php'); |
1 | 882 |
$str1 = explode("\n", $str1); |
883 |
$str2 = explode("\n", $str2); |
|
884 |
$diff = new Diff($str1, $str2); |
|
885 |
$renderer = new TableDiffFormatter(); |
|
886 |
return '<table class="diff">'.$renderer->format($diff).'</table>'; |
|
887 |
} |
|
888 |
||
35 | 889 |
/** |
890 |
* Changes wikitext image tags to HTML. |
|
891 |
* @param string The wikitext to process |
|
37 | 892 |
* @param array Will be overwritten with the list of HTML tags (the system uses tokens for TextWiki compatibility) |
35 | 893 |
* @return string |
894 |
*/ |
|
895 |
||
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
|
896 |
public static function process_image_tags($text, &$taglist) |
35 | 897 |
{ |
898 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
899 |
||
37 | 900 |
$s_delim = "\xFF"; |
901 |
$f_delim = "\xFF"; |
|
902 |
$taglist = array(); |
|
903 |
||
35 | 904 |
// 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
|
905 |
$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
|
906 |
$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
|
907 |
\[\[ # 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
|
908 |
:' . $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
|
909 |
(?:(?:\|(?:.+?))*) # 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
|
910 |
\]\] # 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
|
911 |
/ix'; |
35 | 912 |
|
913 |
preg_match_all($regex, $text, $matches); |
|
914 |
||
915 |
foreach ( $matches[0] as $i => $match ) |
|
916 |
{ |
|
917 |
||
918 |
$full_tag =& $matches[0][$i]; |
|
919 |
$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
|
920 |
|
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
|
921 |
// 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
|
922 |
$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
|
923 |
$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
|
924 |
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
|
925 |
{ |
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
|
926 |
$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
|
927 |
$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
|
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 |
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
|
930 |
{ |
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 |
// 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
|
932 |
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
|
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 |
|
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 |
// 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
|
936 |
$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
|
937 |
$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
|
938 |
$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
|
939 |
$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
|
940 |
$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
|
941 |
$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
|
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 |
// 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
|
944 |
$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
|
945 |
// 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
|
946 |
$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
|
947 |
$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
|
948 |
// 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
|
949 |
$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
|
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 |
// 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
|
952 |
// 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
|
953 |
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
|
954 |
{ |
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 |
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
|
956 |
{ |
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 |
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
|
958 |
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
|
959 |
$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
|
960 |
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
|
961 |
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
|
962 |
$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
|
963 |
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
|
964 |
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
|
965 |
$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
|
966 |
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
|
967 |
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
|
968 |
// 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
|
969 |
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
|
970 |
{ |
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 |
$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
|
972 |
$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
|
973 |
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
|
974 |
} |
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 |
// 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
|
976 |
// 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
|
977 |
$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
|
978 |
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
|
979 |
{ |
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 |
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
|
981 |
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
|
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 |
// 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
|
984 |
// 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
|
985 |
$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
|
986 |
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
|
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 |
} |
35 | 989 |
|
990 |
if ( !isPage( $paths->nslist['File'] . $filename ) ) |
|
991 |
{ |
|
66
52017732bc20
Added "raw" option to embedded images to make complex clickables easier
Dan
parents:
65
diff
changeset
|
992 |
$text = str_replace($full_tag, '[[' . makeUrlNS('File', $filename) . ']]', $text); |
35 | 993 |
continue; |
994 |
} |
|
995 |
||
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
|
996 |
if ( $scale_type == 'thumb' ) |
35 | 997 |
{ |
998 |
$r_width = 225; |
|
999 |
$r_height = 225; |
|
1000 |
||
1001 |
$url = makeUrlNS('Special', 'DownloadFile/' . $filename, 'preview&width=' . $r_width . '&height=' . $r_height, true); |
|
1002 |
} |
|
1003 |
else if ( !empty($width) && !empty($height) ) |
|
1004 |
{ |
|
1005 |
$r_width = $width; |
|
1006 |
$r_height = $height; |
|
1007 |
||
1008 |
$url = makeUrlNS('Special', 'DownloadFile/' . $filename, 'preview&width=' . $r_width . '&height=' . $r_height, true); |
|
1009 |
} |
|
1010 |
else |
|
1011 |
{ |
|
1012 |
$url = makeUrlNS('Special', 'DownloadFile/' . $filename); |
|
1013 |
} |
|
1014 |
||
1015 |
$img_tag = '<img src="' . $url . '" '; |
|
1016 |
||
65 | 1017 |
// if ( isset($r_width) && isset($r_height) && $scale_type != '|thumb' ) |
1018 |
// { |
|
66
52017732bc20
Added "raw" option to embedded images to make complex clickables easier
Dan
parents:
65
diff
changeset
|
1019 |
// $img_tag .= 'width="' . $r_width . '" height="' . $r_height . '" '; |
65 | 1020 |
// } |
35 | 1021 |
|
66
52017732bc20
Added "raw" option to embedded images to make complex clickables easier
Dan
parents:
65
diff
changeset
|
1022 |
$img_tag .= 'style="border-width: 0px; /* background-color: white; */" '; |
35 | 1023 |
|
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
|
1024 |
$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
|
1025 |
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
|
1026 |
{ |
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
|
1027 |
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
|
1028 |
} |
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
|
1029 |
|
35 | 1030 |
$img_tag .= '/>'; |
1031 |
||
1032 |
$complete_tag = ''; |
|
1033 |
||
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
|
1034 |
if ( !empty($scale_type) && !$raw_display ) |
35 | 1035 |
{ |
1036 |
$complete_tag .= '<div class="thumbnail" '; |
|
1037 |
$clear_text = ''; |
|
1038 |
if ( !empty($clear) ) |
|
1039 |
{ |
|
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
|
1040 |
$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
|
1041 |
$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
|
1042 |
$clear_text .= "float: $side; margin-$opposite: 20px; width: {$r_width}px;"; |
35 | 1043 |
$complete_tag .= 'style="' . $clear_text . '" '; |
1044 |
} |
|
1045 |
$complete_tag .= '>'; |
|
1046 |
||
1047 |
$complete_tag .= '<a href="' . makeUrlNS('File', $filename) . '" style="display: block;">'; |
|
1048 |
$complete_tag .= $img_tag; |
|
1049 |
$complete_tag .= '</a>'; |
|
1050 |
||
1051 |
$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>'; |
|
1052 |
||
1053 |
if ( !empty($caption) ) |
|
1054 |
{ |
|
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
|
1055 |
$complete_tag .= $mag_button . $caption; |
35 | 1056 |
} |
1057 |
||
1058 |
$complete_tag .= '</div>'; |
|
1059 |
} |
|
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
|
1060 |
else if ( $raw_display ) |
66
52017732bc20
Added "raw" option to embedded images to make complex clickables easier
Dan
parents:
65
diff
changeset
|
1061 |
{ |
67 | 1062 |
$complete_tag .= "$img_tag"; |
1063 |
$taglist[$i] = $complete_tag; |
|
1064 |
||
1065 |
$repl = "{$s_delim}e_img_{$i}{$f_delim}"; |
|
1066 |
$text = str_replace($full_tag, $repl, $text); |
|
1067 |
continue; |
|
66
52017732bc20
Added "raw" option to embedded images to make complex clickables easier
Dan
parents:
65
diff
changeset
|
1068 |
} |
35 | 1069 |
else |
1070 |
{ |
|
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
|
1071 |
$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
|
1072 |
$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
|
1073 |
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
|
1074 |
{ |
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
|
1075 |
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
|
1076 |
} |
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
|
1077 |
$complete_tag .= '>'; |
35 | 1078 |
$complete_tag .= $img_tag; |
1079 |
$complete_tag .= '</a>'; |
|
1080 |
} |
|
1081 |
||
37 | 1082 |
$complete_tag .= "\n\n"; |
1083 |
$taglist[$i] = $complete_tag; |
|
35 | 1084 |
|
37 | 1085 |
$pos = strpos($text, $full_tag); |
35 | 1086 |
|
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
|
1087 |
/* |
35 | 1088 |
while(true) |
1089 |
{ |
|
1090 |
$check1 = substr($text, $pos, 3); |
|
1091 |
$check2 = substr($text, $pos, 1); |
|
1092 |
if ( $check1 == '<p>' || $pos == 0 || $check2 == "\n" ) |
|
1093 |
{ |
|
1094 |
// die('found at pos '.$pos); |
|
1095 |
break; |
|
1096 |
} |
|
1097 |
$pos--; |
|
1098 |
} |
|
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
|
1099 |
*/ |
35 | 1100 |
|
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
|
1101 |
/* |
37 | 1102 |
$repl = "{$s_delim}e_img_{$i}{$f_delim}"; |
1103 |
$text = substr($text, 0, $pos) . $repl . substr($text, $pos); |
|
35 | 1104 |
|
1105 |
$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
|
1106 |
*/ |
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 |
$text = str_replace_once($full_tag, $complete_tag, $text); |
35 | 1108 |
|
1109 |
unset($full_tag, $filename, $scale_type, $width, $height, $clear, $caption, $r_width, $r_height); |
|
1110 |
||
1111 |
} |
|
1112 |
||
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
|
1113 |
// 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
|
1114 |
// 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
|
1115 |
|
35 | 1116 |
return $text; |
1117 |
} |
|
1118 |
||
37 | 1119 |
/** |
1120 |
* Finalizes processing of image tags. |
|
1121 |
* @param string The preprocessed text |
|
1122 |
* @param array The list of image tags created by RenderMan::process_image_tags() |
|
1123 |
*/ |
|
1124 |
||
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
|
1125 |
public static function process_imgtags_stage2($text, $taglist) |
37 | 1126 |
{ |
1127 |
$s_delim = "\xFF"; |
|
1128 |
$f_delim = "\xFF"; |
|
1129 |
foreach ( $taglist as $i => $tag ) |
|
1130 |
{ |
|
1131 |
$repl = "{$s_delim}e_img_{$i}{$f_delim}"; |
|
1132 |
$text = str_replace($repl, $tag, $text); |
|
1133 |
} |
|
1134 |
return $text; |
|
1135 |
} |
|
1136 |
||
1 | 1137 |
} |
1138 |
||
1139 |
?> |