author | Dan |
Sun, 25 Jan 2009 20:35:06 -0500 | |
changeset 823 | 4596c40aaa94 |
parent 801 | eb8b23f11744 |
child 832 | 7152ca0a0ce9 |
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 |
|
801
eb8b23f11744
Two big commits in one day I know, but redid password storage to use HMAC-SHA1. Consolidated much AES processing to three core methods in session that should handle everything automagically. Installation works; upgrades should. Rebranded as 1.1.6.
Dan
parents:
800
diff
changeset
|
5 |
* Version 1.1.6 (Caoineag beta 1) |
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); |
|
800
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
798
diff
changeset
|
52 |
if ( !$perms ) |
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
798
diff
changeset
|
53 |
{ |
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
798
diff
changeset
|
54 |
$session->init_permissions(); |
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
798
diff
changeset
|
55 |
$perms = $session->fetch_page_acl($page_id, $namespace); |
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
798
diff
changeset
|
56 |
}; |
1 | 57 |
} |
58 |
||
59 |
if(!$perms->get_permissions('read')) |
|
60 |
return 'Access denied ('.$paths->nslist[$namespace].$page_id.')'; |
|
61 |
||
457
d823e49e2e4e
Fixed: RenderMan::getPage() failing with access denial when fetching template and view_source results in deny
Dan
parents:
322
diff
changeset
|
62 |
if($namespace != 'Template' && ($wiki == 0 || $render == false)) |
1 | 63 |
{ |
64 |
if(!$perms->get_permissions('view_source')) |
|
65 |
{ |
|
66 |
return 'Access denied ('.$paths->nslist[$namespace].$page_id.')'; |
|
67 |
} |
|
68 |
} |
|
69 |
||
70 |
$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).'\';'); |
|
71 |
if ( !$q ) |
|
72 |
{ |
|
73 |
$db->_die('Method called was: RenderMan::getPage(\''.$page_id.'\', \''.$namespace.'\');.'); |
|
74 |
} |
|
75 |
if ( $db->numrows() < 1 ) |
|
76 |
{ |
|
77 |
return false; |
|
78 |
} |
|
79 |
$row = $db->fetchrow(); |
|
80 |
$db->free_result(); |
|
81 |
||
82 |
$message = $row['page_text']; |
|
83 |
$chartag = $row['char_tag']; |
|
84 |
unset($row); // Free some memory |
|
85 |
||
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
|
86 |
if ( preg_match("#^\#redirect \[\[([^\]\r\n\a\t]+?)\]\]#", $message, $m) && $redir && ( !isset($_GET['redirect']) || ( isset($_GET['redirect']) && $_GET['redirect'] != 'no' ) ) ) |
1 | 87 |
{ |
88 |
$old = $paths->cpage; |
|
89 |
$a = RenderMan::strToPageID($m[1]); |
|
90 |
$a[0] = str_replace(' ', '_', $a[0]); |
|
91 |
||
92 |
$pageid = str_replace(' ', '_', $paths->nslist[$a[1]] . $a[0]); |
|
93 |
$paths->page = $pageid; |
|
94 |
$paths->cpage = $paths->pages[$pageid]; |
|
95 |
//die('<pre>'.print_r($paths->cpage,true).'</pre>'); |
|
96 |
||
97 |
unset($template); |
|
98 |
unset($GLOBALS['template']); |
|
99 |
||
100 |
$GLOBALS['template'] = new template(); |
|
101 |
global $template; |
|
102 |
||
103 |
$template->template(); // Tear down and rebuild the template parser |
|
104 |
$template->load_theme($session->theme, $session->style); |
|
105 |
||
106 |
$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 */); |
|
107 |
||
108 |
return $data; |
|
109 |
} |
|
110 |
else if(preg_match('#^\#redirect \[\[(.+?)\]\]#', $message, $m) && isset($_GET['redirect']) && $_GET['redirect'] == 'no') |
|
111 |
{ |
|
112 |
preg_match('#^\#redirect \[\[(.+)\]\]#', $message, $m); |
|
113 |
$m[1] = str_replace(' ', '_', $m[1]); |
|
114 |
$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); |
|
115 |
} |
|
116 |
$session->disallow_password_grab(); |
|
117 |
return ($render) ? RenderMan::render($message, $wiki, $smilies, $filter_links) : $message; |
|
118 |
} |
|
119 |
||
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
|
120 |
public static function getTemplate($id, $parms) |
1 | 121 |
{ |
122 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
123 |
if(!isset($paths->pages[$paths->nslist['Template'].$id])) |
|
124 |
{ |
|
125 |
return '[['.$paths->nslist['Template'].$id.']]'; |
|
126 |
} |
|
127 |
if(isset($paths->template_cache[$id])) |
|
128 |
{ |
|
129 |
$text = $paths->template_cache[$id]; |
|
130 |
} |
|
131 |
else |
|
132 |
{ |
|
133 |
$text = RenderMan::getPage($id, 'Template', 0, true, true, 0); |
|
134 |
$paths->template_cache[$id] = $text; |
|
135 |
} |
|
136 |
||
137 |
$text = preg_replace('/<noinclude>(.*?)<\/noinclude>/is', '', $text); |
|
138 |
$text = preg_replace('/<nodisplay>(.*?)<\/nodisplay>/is', '\\1', $text); |
|
139 |
||
140 |
preg_match_all('#\(_([0-9]+)_\)#', $text, $matchlist); |
|
141 |
||
142 |
foreach($matchlist[1] as $m) |
|
143 |
{ |
|
144 |
if(isset($parms[((int)$m)+1])) |
|
145 |
{ |
|
146 |
$p = $parms[((int)$m)+1]; |
|
147 |
} |
|
148 |
else |
|
149 |
{ |
|
150 |
$p = '<b>Notice:</b> RenderMan::getTemplate(): Parameter '.$m.' is not set'; |
|
151 |
} |
|
152 |
$text = str_replace('(_'.$m.'_)', $p, $text); |
|
717
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
153 |
$text = str_replace('{{' . ( $m + 1 ) . '}}', $p, $text); |
1 | 154 |
} |
155 |
$text = RenderMan::include_templates($text); |
|
156 |
return $text; |
|
157 |
} |
|
158 |
||
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
|
159 |
public static function fetch_template_text($id) |
1 | 160 |
{ |
161 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
745
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
162 |
$fetch_ns = 'Template'; |
1 | 163 |
if(!isset($paths->pages[$paths->nslist['Template'].$id])) |
164 |
{ |
|
745
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
165 |
// Transclusion of another page |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
166 |
// 1.1.5: Now You, Too, Can Be A Template, Even If You're Just A Plain Old Article! (TM) |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
167 |
$nssep = substr($paths->nslist['Special'], -1); |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
168 |
$nslist = $paths->nslist; |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
169 |
foreach ( $nslist as &$ns ) |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
170 |
{ |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
171 |
if ( $ns == '' ) |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
172 |
$ns = $nssep; |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
173 |
} |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
174 |
$prefixlist = array_flip($nslist); |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
175 |
foreach ( $nslist as &$ns ) |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
176 |
{ |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
177 |
$ns = preg_quote($ns); |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
178 |
} |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
179 |
$nslist = implode('|', $nslist); |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
180 |
if ( preg_match("/^($nslist)(.*?)$/", $id, $match) ) |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
181 |
{ |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
182 |
// in practice this should always be true but just to be safe... |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
183 |
if ( isset($prefixlist[$match[1]]) ) |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
184 |
{ |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
185 |
$new_id = $paths->nslist[ $prefixlist[$match[1]] ] . sanitize_page_id($match[2]); |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
186 |
if ( !isset($paths->pages[$new_id]) ) |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
187 |
{ |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
188 |
return "[[$new_id]]"; |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
189 |
} |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
190 |
$fetch_ns = $prefixlist[$match[1]]; |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
191 |
$id = sanitize_page_id($match[2]); |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
192 |
} |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
193 |
} |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
194 |
else |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
195 |
{ |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
196 |
return '[['.$paths->nslist['Template'].$id.']]'; |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
197 |
} |
1 | 198 |
} |
199 |
if(isset($paths->template_cache[$id])) |
|
200 |
{ |
|
201 |
$text = $paths->template_cache[$id]; |
|
202 |
} |
|
203 |
else |
|
204 |
{ |
|
745
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
205 |
$text = RenderMan::getPage($id, $fetch_ns, 0, false, false, false, false); |
1 | 206 |
$paths->template_cache[$id] = $text; |
207 |
} |
|
208 |
||
209 |
if ( is_string($text) ) |
|
210 |
{ |
|
211 |
$text = preg_replace('/<noinclude>(.*?)<\/noinclude>/is', '', $text); |
|
212 |
$text = preg_replace('/<nodisplay>(.*?)<\/nodisplay>/is', '\\1', $text); |
|
213 |
} |
|
214 |
||
215 |
return $text; |
|
216 |
} |
|
217 |
||
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
|
218 |
public static function render($text, $wiki = 1, $smilies = true, $filter_links = true) |
1 | 219 |
{ |
220 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
221 |
if($smilies) |
|
222 |
{ |
|
223 |
$text = RenderMan::smilieyize($text); |
|
224 |
} |
|
225 |
if($wiki == 1) |
|
226 |
{ |
|
227 |
$text = RenderMan::next_gen_wiki_format($text); |
|
228 |
} |
|
229 |
elseif($wiki == 2) |
|
230 |
{ |
|
231 |
$text = $template->tplWikiFormat($text); |
|
232 |
} |
|
233 |
return $text; |
|
234 |
} |
|
235 |
||
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
|
236 |
public static function PlainTextRender($text, $wiki = 1, $smilies = false, $filter_links = true) |
1 | 237 |
{ |
238 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
239 |
if($smilies) |
|
240 |
{ |
|
241 |
$text = RenderMan::smilieyize($text); |
|
242 |
} |
|
243 |
if($wiki == 1) |
|
244 |
{ |
|
245 |
$text = RenderMan::next_gen_wiki_format($text, true); |
|
246 |
} |
|
247 |
elseif($wiki == 2) |
|
248 |
{ |
|
249 |
$text = $template->tplWikiFormat($text); |
|
250 |
} |
|
251 |
return $text; |
|
252 |
} |
|
253 |
||
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
|
254 |
public static function next_gen_wiki_format($text, $plaintext = false, $filter_links = true, $do_params = false) |
1 | 255 |
{ |
256 |
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
|
257 |
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
|
258 |
|
592 | 259 |
require_once(ENANO_ROOT.'/includes/wikiformat.php'); |
260 |
require_once(ENANO_ROOT.'/includes/wikiengine/Tables.php'); |
|
261 |
||
382
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
parents:
377
diff
changeset
|
262 |
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
|
263 |
|
1 | 264 |
$random_id = md5( time() . mt_rand() ); |
265 |
||
266 |
// Strip out <nowiki> sections and PHP code |
|
267 |
||
407
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
268 |
$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
|
269 |
|
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
270 |
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
|
271 |
{ |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
272 |
$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
|
273 |
} |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
274 |
|
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
275 |
$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
|
276 |
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
|
277 |
{ |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
278 |
eval($cmd); |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
279 |
} |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
280 |
|
1 | 281 |
$php = preg_match_all('#<\?php(.*?)\?>#is', $text, $phpsec); |
282 |
||
283 |
for($i=0;$i<sizeof($phpsec[1]);$i++) |
|
284 |
{ |
|
285 |
$text = str_replace('<?php'.$phpsec[1][$i].'?>', '{PHP:'.$random_id.':'.$i.'}', $text); |
|
286 |
} |
|
287 |
||
288 |
$text = preg_replace('/<noinclude>(.*?)<\/noinclude>/is', '\\1', $text); |
|
289 |
if ( $paths->namespace == 'Template' ) |
|
290 |
{ |
|
291 |
$text = preg_replace('/<nodisplay>(.*?)<\/nodisplay>/is', '', $text); |
|
292 |
} |
|
293 |
||
798
ddfc1b554a08
Redid error handler (it was causing some problems with gzip enabled)
Dan
parents:
745
diff
changeset
|
294 |
preg_match_all('/<lang (?:code|id)="([a-z0-9_-]+)">([\w\W]+?)<\/lang>/', $text, $langmatch); |
377
bb3e6c3bd4f4
Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
parents:
371
diff
changeset
|
295 |
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
|
296 |
{ |
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
|
297 |
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
|
298 |
{ |
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
|
299 |
$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
|
300 |
} |
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
|
301 |
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
|
302 |
{ |
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
|
303 |
$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
|
304 |
} |
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
|
305 |
} |
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
|
306 |
|
163 | 307 |
$code = $plugins->setHook('render_wikiformat_pre'); |
308 |
foreach ( $code as $cmd ) |
|
309 |
{ |
|
310 |
eval($cmd); |
|
311 |
} |
|
312 |
||
715 | 313 |
//$template_regex = "/\{\{([^\]]+?)((\n([ ]*?)[A-z0-9]+([ ]*?)=([ ]*?)(.+?))*)\}\}/is"; |
314 |
$template_regex = "/\{\{(.+)((\n|\|[ ]*([A-z0-9]+)[ ]*=[ ]*(.+))*)\}\}/isU"; |
|
315 |
$i = 0; |
|
316 |
while ( preg_match($template_regex, $text) ) |
|
317 |
{ |
|
318 |
$i++; |
|
319 |
if ( $i == 5 ) |
|
320 |
break; |
|
321 |
$text = RenderMan::include_templates($text); |
|
322 |
} |
|
323 |
||
798
ddfc1b554a08
Redid error handler (it was causing some problems with gzip enabled)
Dan
parents:
745
diff
changeset
|
324 |
$code = $plugins->setHook('render_wikiformat_posttemplates'); |
ddfc1b554a08
Redid error handler (it was causing some problems with gzip enabled)
Dan
parents:
745
diff
changeset
|
325 |
foreach ( $code as $cmd ) |
ddfc1b554a08
Redid error handler (it was causing some problems with gzip enabled)
Dan
parents:
745
diff
changeset
|
326 |
{ |
ddfc1b554a08
Redid error handler (it was causing some problems with gzip enabled)
Dan
parents:
745
diff
changeset
|
327 |
eval($cmd); |
ddfc1b554a08
Redid error handler (it was causing some problems with gzip enabled)
Dan
parents:
745
diff
changeset
|
328 |
} |
ddfc1b554a08
Redid error handler (it was causing some problems with gzip enabled)
Dan
parents:
745
diff
changeset
|
329 |
|
1 | 330 |
if ( !$plaintext ) |
331 |
{ |
|
332 |
// 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
|
333 |
$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
|
334 |
$text = RenderMan::process_imgtags_stage2($text, $taglist); |
1 | 335 |
} |
336 |
||
337 |
if($do_params) |
|
338 |
{ |
|
339 |
preg_match_all('#\(_([0-9]+)_\)#', $text, $matchlist); |
|
340 |
foreach($matchlist[1] as $m) |
|
341 |
{ |
|
342 |
$text = str_replace('(_'.$m.'_)', $paths->getParam((int)$m), $text); |
|
343 |
} |
|
344 |
} |
|
345 |
||
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
|
346 |
// 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
|
347 |
$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
|
348 |
|
1 | 349 |
$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
|
350 |
$text = RenderMan::parse_internal_links($text); |
1 | 351 |
|
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
|
352 |
$wiki = Text_Wiki::singleton('Mediawiki'); |
1 | 353 |
if($plaintext) |
354 |
{ |
|
355 |
$wiki->setRenderConf('Plain', 'wikilink', 'view_url', contentPath); |
|
356 |
$result = $wiki->transform($text, 'Plain'); |
|
357 |
} |
|
358 |
else |
|
359 |
{ |
|
360 |
$wiki->setRenderConf('Xhtml', 'wikilink', 'view_url', contentPath); |
|
361 |
$wiki->setRenderConf('Xhtml', 'Url', 'css_descr', 'external'); |
|
362 |
$result = $wiki->transform($text, 'Xhtml'); |
|
363 |
} |
|
364 |
||
163 | 365 |
// HTML fixes |
366 |
$result = preg_replace('#<tr>([\s]*?)<\/tr>#is', '', $result); |
|
367 |
$result = preg_replace('#<p>([\s]*?)<\/p>#is', '', $result); |
|
368 |
$result = preg_replace('#<br />([\s]*?)<table#is', '<table', $result); |
|
369 |
$result = str_replace("<pre><code>\n", "<pre><code>", $result); |
|
370 |
$result = preg_replace("/<p><table([^>]*?)><\/p>/", "<table\\1>", $result); |
|
371 |
$result = str_replace("<br />\n</td>", "\n</td>", $result); |
|
372 |
$result = str_replace("<p><tr>", "<tr>", $result); |
|
373 |
$result = str_replace("<tr><br />", "<tr>", $result); |
|
374 |
$result = str_replace("</tr><br />", "</tr>", $result); |
|
375 |
$result = str_replace("</table><br />", "</table>", $result); |
|
376 |
$result = preg_replace('/<\/table>$/', "</table><br /><br />", $result); |
|
377 |
$result = str_replace("<p></div></p>", "</div>", $result); |
|
378 |
$result = str_replace("<p></table></p>", "</table>", $result); |
|
379 |
||
380 |
$code = $plugins->setHook('render_wikiformat_post'); |
|
381 |
foreach ( $code as $cmd ) |
|
382 |
{ |
|
383 |
eval($cmd); |
|
384 |
} |
|
37 | 385 |
|
1 | 386 |
// Reinsert <nowiki> sections |
387 |
for($i=0;$i<$nw;$i++) |
|
388 |
{ |
|
389 |
$result = str_replace('{NOWIKI:'.$random_id.':'.$i.'}', $nowiki[1][$i], $result); |
|
390 |
} |
|
391 |
||
392 |
// Reinsert PHP |
|
393 |
for($i=0;$i<$php;$i++) |
|
394 |
{ |
|
395 |
$result = str_replace('{PHP:'.$random_id.':'.$i.'}', '<?php'.$phpsec[1][$i].'?>', $result); |
|
396 |
} |
|
397 |
||
382
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
parents:
377
diff
changeset
|
398 |
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
|
399 |
|
1 | 400 |
return $result; |
401 |
||
402 |
} |
|
403 |
||
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
|
404 |
public static function wikiFormat($message, $filter_links = true, $do_params = false, $plaintext = false) |
163 | 405 |
{ |
1 | 406 |
global $db, $session, $paths, $template, $plugins; // Common objects |
407 |
||
408 |
return RenderMan::next_gen_wiki_format($message, $plaintext, $filter_links, $do_params); |
|
409 |
||
410 |
$random_id = md5( time() . mt_rand() ); |
|
411 |
||
412 |
// Strip out <nowiki> sections |
|
413 |
$nw = preg_match_all('#<nowiki>(.*?)<\/nowiki>#is', $message, $nowiki); |
|
414 |
||
415 |
if(!$plaintext) |
|
416 |
{ |
|
417 |
||
418 |
//return '<pre>'.print_r($nowiki,true).'</pre>'; |
|
419 |
||
420 |
for($i=0;$i<sizeof($nowiki[1]);$i++) |
|
421 |
{ |
|
422 |
$message = str_replace('<nowiki>'.$nowiki[1][$i].'</nowiki>', '{NOWIKI:'.$random_id.':'.$i.'}', $message); |
|
423 |
} |
|
424 |
||
425 |
$message = preg_replace('/<noinclude>(.*?)<\/noinclude>/is', '\\1', $message); |
|
426 |
||
427 |
//return '<pre>'.htmlspecialchars($message).'</pre>'; |
|
428 |
||
35 | 429 |
$message = RenderMan::process_image_tags($message); |
1 | 430 |
|
431 |
} |
|
432 |
||
433 |
if($do_params) |
|
434 |
{ |
|
435 |
preg_match_all('#\(_([0-9]+)_\)#', $message, $matchlist); |
|
436 |
foreach($matchlist[1] as $m) |
|
437 |
{ |
|
438 |
$message = str_replace('(_'.$m.'_)', $paths->getParam((int)$m), $message); |
|
439 |
} |
|
440 |
} |
|
441 |
||
442 |
$message = RenderMan::include_templates($message); |
|
443 |
||
444 |
// Reinsert <nowiki> sections |
|
445 |
for($i=0;$i<$nw;$i++) |
|
446 |
{ |
|
447 |
$message = str_replace('{NOWIKI:'.$random_id.':'.$i.'}', '<nowiki>'.$nowiki[1][$i].'</nowiki>', $message); |
|
448 |
} |
|
449 |
||
450 |
$message = process_tables($message); |
|
451 |
//if($message2 != $message) return '<pre>'.htmlspecialchars($message2).'</pre>'; |
|
452 |
//$message = str_replace(array('<table>', '</table>'), array('<nowiki><table>', '</table></nowiki>'), $message); |
|
453 |
||
454 |
$wiki =& Text_Wiki::singleton('Mediawiki'); |
|
455 |
if($plaintext) |
|
456 |
{ |
|
457 |
$wiki->setRenderConf('Plain', 'wikilink', 'view_url', contentPath); |
|
458 |
$result = $wiki->transform($message, 'Plain'); |
|
459 |
} else { |
|
460 |
$wiki->setRenderConf('Xhtml', 'wikilink', 'view_url', contentPath); |
|
461 |
$wiki->setRenderConf('Xhtml', 'Url', 'css_descr', 'external'); |
|
462 |
$result = $wiki->transform($message, 'Xhtml'); |
|
463 |
} |
|
464 |
||
465 |
// HTML fixes |
|
466 |
$result = preg_replace('#<tr>([\s]*?)<\/tr>#is', '', $result); |
|
467 |
$result = preg_replace('#<p>([\s]*?)<\/p>#is', '', $result); |
|
468 |
$result = preg_replace('#<br />([\s]*?)<table#is', '<table', $result); |
|
469 |
$result = str_replace("<pre><code>\n", "<pre><code>", $result); |
|
470 |
$result = preg_replace("/<p><table([^>]*?)><\/p>/", "<table\\1>", $result); |
|
471 |
$result = str_replace("<br />\n</td>", "\n</td>", $result); |
|
472 |
$result = str_replace("<p><tr>", "<tr>", $result); |
|
473 |
$result = str_replace("<tr><br />", "<tr>", $result); |
|
474 |
$result = str_replace("</tr><br />", "</tr>", $result); |
|
475 |
$result = str_replace("</table></p>", "</table>", $result); |
|
476 |
$result = str_replace("</table><br />", "</table>", $result); |
|
477 |
$result = preg_replace('/<\/table>$/', "</table><br /><br />", $result); |
|
163 | 478 |
$result = str_replace("<p></div></p>", "</div>", $result); |
479 |
$result = str_replace("<p></table></p>", "</table>", $result); |
|
1 | 480 |
|
481 |
$result = str_replace('<nowiki>', '<nowiki>', $result); |
|
482 |
$result = str_replace('</nowiki>', '</nowiki>', $result); |
|
483 |
||
484 |
return $result; |
|
485 |
} |
|
486 |
||
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
|
487 |
public static function destroy_javascript($message, $_php = false) |
1 | 488 |
{ |
489 |
$message = preg_replace('#<(script|object|applet|embed|iframe|frame|form|input|select)(.*?)>#is', '<\\1\\2>', $message); |
|
490 |
$message = preg_replace('#</(script|object|applet|embed|iframe|frame|form|input|select)(.*?)>#is', '</\\1\\2>', $message); |
|
491 |
$message = preg_replace('#(javascript|script|activex|chrome|about|applet):#is', '\\1:', $message); |
|
492 |
if ( $_php ) |
|
493 |
{ |
|
494 |
// Left in only for compatibility |
|
495 |
$message = preg_replace('#<(.*?)>#is', '<\\1>', $message); |
|
496 |
$message = preg_replace('#<(.*?)>#is', '<\\1>', $message); |
|
497 |
$message = preg_replace('#<(\?|\?php|%)(.*?)(\?|%)>#is', '<\\1\\2\\3>', $message); |
|
498 |
// strip <a href="foo" onclick="bar();">-type attacks |
|
499 |
$message = preg_replace('#<([a-zA-Z:\-]+) (.*?)on([A-Za-z]*)=(.*?)>#is', '<\\1\\2on\\3=\\4>', $message); |
|
500 |
} |
|
501 |
return $message; |
|
502 |
} |
|
503 |
||
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
|
504 |
public static function strip_php($message) |
1 | 505 |
{ |
506 |
return RenderMan::destroy_javascript($message, true); |
|
507 |
} |
|
508 |
||
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
|
509 |
public static function sanitize_html($text) |
1 | 510 |
{ |
511 |
$text = htmlspecialchars($text); |
|
91 | 512 |
$allowed_tags = Array('b', 'i', 'u', 'pre', 'code', 'tt', 'br', 'p', 'nowiki', '!--([\w\W]+)--'); |
1 | 513 |
foreach($allowed_tags as $t) |
514 |
{ |
|
515 |
$text = preg_replace('#<'.$t.'>(.*?)</'.$t.'>#is', '<'.$t.'>\\1</'.$t.'>', $text); |
|
516 |
$text = preg_replace('#<'.$t.' />#is', '<'.$t.' />', $text); |
|
517 |
$text = preg_replace('#<'.$t.'>#is', '<'.$t.'>', $text); |
|
518 |
} |
|
519 |
return $text; |
|
520 |
} |
|
521 |
||
91 | 522 |
/** |
523 |
* Parses internal links (wikilinks) in a block of text. |
|
524 |
* @param string Text to process |
|
592 | 525 |
* @param string Optional. If included will be used as a template instead of using the default syntax. |
91 | 526 |
* @return string |
527 |
*/ |
|
528 |
||
592 | 529 |
public static function parse_internal_links($text, $tplcode = false) |
91 | 530 |
{ |
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
|
531 |
global $db, $session, $paths, $template, $plugins; // Common objects |
91 | 532 |
|
592 | 533 |
if ( is_string($tplcode) ) |
534 |
{ |
|
535 |
$parser = $template->makeParserText($tplcode); |
|
536 |
} |
|
537 |
||
91 | 538 |
// stage 1 - links with alternate text |
539 |
preg_match_all('/\[\[([^\[\]<>\{\}\|]+)\|(.+?)\]\]/', $text, $matches); |
|
540 |
foreach ( $matches[0] as $i => $match ) |
|
541 |
{ |
|
542 |
list($page_id, $namespace) = RenderMan::strToPageID($matches[1][$i]); |
|
715 | 543 |
if ( ($pos = strrpos($page_id, '#')) !== false ) |
544 |
{ |
|
545 |
$hash = substr($page_id, $pos); |
|
546 |
$page_id = substr($page_id, 0, $pos); |
|
547 |
} |
|
548 |
else |
|
549 |
{ |
|
550 |
$hash = ''; |
|
551 |
} |
|
91 | 552 |
$pid_clean = $paths->nslist[$namespace] . sanitize_page_id($page_id); |
553 |
||
715 | 554 |
$url = makeUrl($pid_clean, false, true) . $hash; |
91 | 555 |
$inner_text = $matches[2][$i]; |
556 |
$quot = '"'; |
|
557 |
$exists = ( isPage($pid_clean) ) ? '' : ' class="wikilink-nonexistent"'; |
|
558 |
||
592 | 559 |
if ( $tplcode ) |
560 |
{ |
|
561 |
$parser->assign_vars(array( |
|
562 |
'HREF' => $url, |
|
563 |
'FLAGS' => $exists, |
|
564 |
'TEXT' => $inner_text |
|
565 |
)); |
|
566 |
$link = $parser->run(); |
|
567 |
} |
|
568 |
else |
|
569 |
{ |
|
570 |
$link = "<a href={$quot}{$url}{$quot}{$exists}>{$inner_text}</a>"; |
|
571 |
} |
|
91 | 572 |
|
573 |
$text = str_replace($match, $link, $text); |
|
574 |
} |
|
575 |
||
576 |
// stage 2 - links with no alternate text |
|
577 |
preg_match_all('/\[\[([^\[\]<>\{\}\|]+)\]\]/', $text, $matches); |
|
578 |
foreach ( $matches[0] as $i => $match ) |
|
579 |
{ |
|
580 |
list($page_id, $namespace) = RenderMan::strToPageID($matches[1][$i]); |
|
581 |
$pid_clean = $paths->nslist[$namespace] . sanitize_page_id($page_id); |
|
582 |
||
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
|
583 |
$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
|
584 |
$inner_text = ( isPage($pid_clean) ) ? htmlspecialchars(get_page_title($pid_clean)) : htmlspecialchars($matches[1][$i]); |
91 | 585 |
$quot = '"'; |
586 |
$exists = ( isPage($pid_clean) ) ? '' : ' class="wikilink-nonexistent"'; |
|
587 |
||
592 | 588 |
if ( $tplcode ) |
589 |
{ |
|
590 |
$parser->assign_vars(array( |
|
591 |
'HREF' => $url, |
|
592 |
'FLAGS' => $exists, |
|
593 |
'TEXT' => $inner_text |
|
594 |
)); |
|
595 |
$link = $parser->run(); |
|
596 |
} |
|
597 |
else |
|
598 |
{ |
|
599 |
$link = "<a href={$quot}{$url}{$quot}{$exists}>{$inner_text}</a>"; |
|
600 |
} |
|
91 | 601 |
|
602 |
$text = str_replace($match, $link, $text); |
|
603 |
} |
|
604 |
||
605 |
return $text; |
|
606 |
} |
|
607 |
||
1 | 608 |
/** |
609 |
* 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
|
610 |
* @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
|
611 |
* @example |
1 | 612 |
* <code> |
63
2c57d3018a88
Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents:
37
diff
changeset
|
613 |
foo = lorem ipsum |
2c57d3018a88
Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents:
37
diff
changeset
|
614 |
bar = dolor sit amet |
1 | 615 |
* </code> |
616 |
* @return array Example: |
|
617 |
* [foo] => lorem ipsum |
|
618 |
* [bar] => dolor sit amet |
|
619 |
*/ |
|
620 |
||
717
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
621 |
public static function parse_template_vars($input, $newlinemode = true) |
1 | 622 |
{ |
717
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
623 |
$parms = array(); |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
624 |
$input = trim($input); |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
625 |
if ( $newlinemode ) |
174
4c5c2b66a34d
SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents:
163
diff
changeset
|
626 |
{ |
717
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
627 |
$result = preg_match_all('/ |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
628 |
(?:^|[\s]*)\|? # start of parameter - string start or series of spaces |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
629 |
[ ]* |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
630 |
(?: |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
631 |
([A-z0-9_]+) # variable name |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
632 |
[ ]* = [ ]* # assignment |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
633 |
)? # this is optional - if the parameter name is not given, a numerical index is assigned |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
634 |
(.+) # value |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
635 |
/x', trim($input), $matches); |
174
4c5c2b66a34d
SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents:
163
diff
changeset
|
636 |
} |
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 |
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
|
638 |
{ |
717
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
639 |
$result = preg_match_all('/ |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
640 |
(?:^|[ ]*)\| # start of parameter - string start or series of spaces |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
641 |
[ ]* |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
642 |
(?: |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
643 |
([A-z0-9_]+) # variable name |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
644 |
[ ]* = [ ]* # assignment |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
645 |
)? # name section is optional - if the parameter name is not given, a numerical index is assigned |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
646 |
([^\|]+|.+?\n[ ]*\|) # value |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
647 |
/x', trim($input), $matches); |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
648 |
} |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
649 |
if ( $result ) |
1 | 650 |
{ |
717
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
651 |
$pi = 0; |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
652 |
for ( $i = 0; $i < count($matches[0]); $i++ ) |
1 | 653 |
{ |
717
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
654 |
$matches[1][$i] = trim($matches[1][$i]); |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
655 |
$parmname = !empty($matches[1][$i]) ? $matches[1][$i] : strval(++$pi); |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
656 |
$parms[ $parmname ] = $matches[2][$i]; |
1 | 657 |
} |
658 |
} |
|
659 |
return $parms; |
|
660 |
} |
|
661 |
||
662 |
/** |
|
663 |
* 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
|
664 |
* Updated in 1.0.2 to also parse template tags in the format of {{Foo |a = b |b = c |c = therefore, a}} |
1 | 665 |
* @param string The text to process |
666 |
* @return string Formatted text |
|
667 |
* @example |
|
668 |
* <code> |
|
669 |
$text = '{{Template |
|
717
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
670 |
| parm1 = Foo |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
671 |
| parm2 = Bar |
1 | 672 |
}}'; |
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
|
673 |
$text = RenderMan::include_templates($text); |
1 | 674 |
* </code> |
675 |
*/ |
|
676 |
||
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
|
677 |
public static function include_templates($text) |
1 | 678 |
{ |
679 |
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
|
680 |
// $template_regex = "/\{\{([^\]]+?)((\n([ ]*?)[A-z0-9]+([ ]*?)=([ ]*?)(.+?))*)\}\}/is"; |
717
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
681 |
// matches: |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
682 |
// 1 - template name |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
683 |
// 2 - parameter section |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
684 |
$template_regex = "/ |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
685 |
\{\{ # opening |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
686 |
([^\n\t\a\r]+) # template name |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
687 |
((?:(?:[\s]+\|?)[ ]*(?:[A-z0-9_]+)[ ]*=[ ]*?(?:.+))*) # parameters |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
688 |
\}\} # closing |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
689 |
/isxU"; |
1 | 690 |
if ( $count = preg_match_all($template_regex, $text, $matches) ) |
691 |
{ |
|
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
|
692 |
//die('<pre>' . print_r($matches, true) . '</pre>'); |
1 | 693 |
for ( $i = 0; $i < $count; $i++ ) |
694 |
{ |
|
63
2c57d3018a88
Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents:
37
diff
changeset
|
695 |
$matches[1][$i] = sanitize_page_id($matches[1][$i]); |
717
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
696 |
$newlinemode = ( substr($matches[2][$i], 0, 1) == "\n" ); |
1 | 697 |
$parmsection = trim($matches[2][$i]); |
698 |
if ( !empty($parmsection) ) |
|
699 |
{ |
|
717
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
700 |
$parms = RenderMan::parse_template_vars($parmsection, $newlinemode); |
174
4c5c2b66a34d
SECURITY: remove debug message in session manager; implemented alternate MediaWiki syntax for template embedding; added Adobe Spry for "shake" effect on unsuccessful login
Dan
parents:
163
diff
changeset
|
701 |
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
|
702 |
// 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
|
703 |
$parms = array(); |
1 | 704 |
} |
705 |
else |
|
706 |
{ |
|
707 |
$parms = Array(); |
|
708 |
} |
|
709 |
if ( $tpl_code = RenderMan::fetch_template_text($matches[1][$i]) ) |
|
710 |
{ |
|
711 |
$parser = $template->makeParserText($tpl_code); |
|
712 |
$parser->assign_vars($parms); |
|
713 |
$text = str_replace($matches[0][$i], $parser->run(), $text); |
|
714 |
} |
|
715 |
} |
|
716 |
} |
|
717 |
return $text; |
|
718 |
} |
|
719 |
||
720 |
/** |
|
721 |
* Preprocesses an HTML text string prior to being sent to MySQL. |
|
722 |
* @param string $text |
|
723 |
* @param bool $strip_all_php - if true, strips all PHP regardless of user permissions. Else, strips PHP only if user level < USER_LEVEL_ADMIN. |
|
724 |
*/ |
|
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
|
725 |
public static function preprocess_text($text, $strip_all_php = true, $sqlescape = true) |
1 | 726 |
{ |
727 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
728 |
$random_id = md5( time() . mt_rand() ); |
|
729 |
||
407
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
730 |
$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
|
731 |
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
|
732 |
{ |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
733 |
eval($cmd); |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
734 |
} |
1 | 735 |
|
736 |
$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
|
737 |
$can_do_html = $session->get_permissions('html_in_pages'); |
1 | 738 |
|
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
|
739 |
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
|
740 |
{ |
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
|
741 |
$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
|
742 |
} |
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
|
743 |
else if ( !$can_do_html && !$can_do_php ) |
1 | 744 |
{ |
24 | 745 |
$text = sanitize_html($text, true); |
1 | 746 |
// If we can't do PHP, we can't do Javascript either. |
747 |
$text = RenderMan::destroy_javascript($text); |
|
748 |
} |
|
749 |
||
750 |
// Strip out <nowiki> sections and PHP code |
|
751 |
||
752 |
$php = preg_match_all('#(<|<)\?php(.*?)\?(>|>)#is', $text, $phpsec); |
|
753 |
||
754 |
//die('<pre>'.htmlspecialchars(print_r($phpsec, true))."\n".htmlspecialchars(print_r($text, true)).'</pre>'); |
|
755 |
||
756 |
for($i=0;$i<sizeof($phpsec[1]);$i++) |
|
757 |
{ |
|
758 |
$text = str_replace($phpsec[0][$i], '{PHP:'.$random_id.':'.$i.'}', $text); |
|
759 |
} |
|
760 |
||
761 |
$nw = preg_match_all('#<nowiki>(.*?)<\/nowiki>#is', $text, $nowiki); |
|
762 |
||
763 |
for($i=0;$i<sizeof($nowiki[1]);$i++) |
|
764 |
{ |
|
765 |
$text = str_replace('<nowiki>'.$nowiki[1][$i].'</nowiki>', '{NOWIKI:'.$random_id.':'.$i.'}', $text); |
|
766 |
} |
|
767 |
||
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
|
768 |
$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
|
769 |
$text = str_replace('~~~~', "[[User:$session->username|$session->username]] ".enano_date('G:i, j F Y (T)'), $text); |
1 | 770 |
$text = str_replace('~~~', "[[User:$session->username|$session->username]] ", $text); |
771 |
||
407
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
772 |
$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
|
773 |
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
|
774 |
{ |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
775 |
eval($cmd); |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
776 |
} |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
777 |
|
1 | 778 |
// Reinsert <nowiki> sections |
779 |
for($i=0;$i<$nw;$i++) |
|
780 |
{ |
|
781 |
$text = str_replace('{NOWIKI:'.$random_id.':'.$i.'}', '<nowiki>'.$nowiki[1][$i].'</nowiki>', $text); |
|
782 |
} |
|
783 |
// Reinsert PHP |
|
784 |
for($i=0;$i<$php;$i++) |
|
785 |
{ |
|
786 |
$phsec = ''.$phpsec[1][$i].'?php'.$phpsec[2][$i].'?'.$phpsec[3][$i].''; |
|
787 |
if ( $strip_all_php ) |
|
788 |
$phsec = htmlspecialchars($phsec); |
|
789 |
$text = str_replace('{PHP:'.$random_id.':'.$i.'}', $phsec, $text); |
|
790 |
} |
|
791 |
||
792 |
$text = ( $sqlescape ) ? $db->escape($text) : $text; |
|
793 |
||
794 |
return $text; |
|
795 |
} |
|
796 |
||
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
|
797 |
public static function smilieyize($text, $complete_urls = false) |
1 | 798 |
{ |
799 |
||
800 |
$random_id = md5( time() . mt_rand() ); |
|
801 |
||
802 |
// Smileys array - eventually this will be fetched from the database by |
|
803 |
// RenderMan::initSmileys during initialization, but it will all be hardcoded for beta 2 |
|
804 |
||
805 |
$smileys = Array( |
|
806 |
'O:-)' => 'face-angel.png', |
|
807 |
'O:)' => 'face-angel.png', |
|
808 |
'O=)' => 'face-angel.png', |
|
809 |
':-)' => 'face-smile.png', |
|
810 |
':)' => 'face-smile.png', |
|
811 |
'=)' => 'face-smile-big.png', |
|
812 |
':-(' => 'face-sad.png', |
|
813 |
':(' => 'face-sad.png', |
|
814 |
';(' => 'face-sad.png', |
|
815 |
':-O' => 'face-surprise.png', |
|
816 |
';-)' => 'face-wink.png', |
|
817 |
';)' => 'face-wink.png', |
|
818 |
'8-)' => 'face-glasses.png', |
|
819 |
'8)' => 'face-glasses.png', |
|
820 |
':-D' => 'face-grin.png', |
|
821 |
':D' => 'face-grin.png', |
|
822 |
'=D' => 'face-grin.png', |
|
823 |
':-*' => 'face-kiss.png', |
|
824 |
':*' => 'face-kiss.png', |
|
825 |
'=*' => 'face-kiss.png', |
|
826 |
':\'(' => 'face-crying.png', |
|
827 |
':-|' => 'face-plain.png', |
|
828 |
':-\\' => 'face-plain.png', |
|
829 |
':-/' => 'face-plain.png', |
|
830 |
':joke:' => 'face-plain.png', |
|
831 |
']:->' => '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
|
832 |
']:->' => 'face-devil-grin.png', |
1 | 833 |
':kiss:' => 'face-kiss.png', |
834 |
':-P' => 'face-tongue-out.png', |
|
835 |
':P' => 'face-tongue-out.png', |
|
836 |
':-p' => 'face-tongue-out.png', |
|
837 |
':p' => 'face-tongue-out.png', |
|
838 |
':-X' => 'face-sick.png', |
|
839 |
':X' => 'face-sick.png', |
|
840 |
':sick:' => 'face-sick.png', |
|
841 |
':-]' => 'face-oops.png', |
|
842 |
':]' => 'face-oops.png', |
|
843 |
':oops:' => 'face-oops.png', |
|
844 |
':-[' => 'face-embarassed.png', |
|
845 |
':[' => 'face-embarassed.png' |
|
846 |
); |
|
847 |
/* |
|
848 |
$keys = array_keys($smileys); |
|
849 |
foreach($keys as $k) |
|
850 |
{ |
|
851 |
$regex1 = '#([\W]+)'.preg_quote($k).'([\s\n\r\.]+)#s'; |
|
852 |
$regex2 = '\\1<img alt="'.$k.'" title="'.$k.'" src="'.scriptPath.'/images/smilies/'.$smileys[$k].'" style="border: 0;" />\\2'; |
|
853 |
$text = preg_replace($regex1, $regex2, $text); |
|
854 |
} |
|
855 |
*/ |
|
856 |
||
857 |
// Strip out <nowiki> sections |
|
858 |
//return '<pre>'.htmlspecialchars($text).'</pre>'; |
|
859 |
$nw = preg_match_all('#<nowiki>(.*?)<\/nowiki>#is', $text, $nowiki); |
|
860 |
||
861 |
for($i=0;$i<sizeof($nowiki[1]);$i++) |
|
862 |
{ |
|
863 |
$text = str_replace('<nowiki>'.$nowiki[1][$i].'</nowiki>', '{NOWIKI:'.$random_id.':'.$i.'}', $text); |
|
864 |
} |
|
865 |
||
866 |
$keys = array_keys($smileys); |
|
867 |
foreach($keys as $k) |
|
868 |
{ |
|
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
|
869 |
$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
|
870 |
$t = trim($t); |
1 | 871 |
$t = explode(' ', $t); |
872 |
$s = ''; |
|
873 |
foreach($t as $b) |
|
874 |
{ |
|
875 |
$s.='&#x'.$b.';'; |
|
876 |
} |
|
877 |
$pfx = ( $complete_urls ) ? 'http' . ( isset($_SERVER['HTTPS']) ? 's' : '' ) . '://'.$_SERVER['HTTP_HOST'] : ''; |
|
878 |
$text = str_replace(' '.$k, ' <nowiki><img title="'.$s.'" alt="'.$s.'" src="'.$pfx.scriptPath.'/images/smilies/'.$smileys[$k].'" style="border: 0;" /></nowiki>', $text); |
|
879 |
} |
|
880 |
//*/ |
|
881 |
||
882 |
// Reinsert <nowiki> sections |
|
883 |
for($i=0;$i<$nw;$i++) |
|
884 |
{ |
|
885 |
$text = str_replace('{NOWIKI:'.$random_id.':'.$i.'}', '<nowiki>'.$nowiki[1][$i].'</nowiki>', $text); |
|
886 |
} |
|
887 |
||
888 |
return $text; |
|
889 |
} |
|
890 |
||
891 |
/* |
|
892 |
* **** DEPRECATED **** |
|
893 |
* Replaces some critical characters in a string with MySQL-safe equivalents |
|
894 |
* @param $text string the text to escape |
|
895 |
* @return array key 0 is the escaped text, key 1 is the character tag |
|
896 |
* / |
|
897 |
||
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
|
898 |
public static function escape_page_text($text) |
1 | 899 |
{ |
900 |
$char_tag = md5(microtime() . mt_rand()); |
|
901 |
$text = str_replace("'", "{APOS:$char_tag}", $text); |
|
902 |
$text = str_replace('"', "{QUOT:$char_tag}", $text); |
|
903 |
$text = str_replace("\\", "{SLASH:$char_tag}", $text); |
|
904 |
return Array($text, $char_tag); |
|
905 |
} |
|
906 |
*/ |
|
907 |
||
908 |
/* **** DEPRECATED **** |
|
909 |
* Reverses the result of RenderMan::escape_page_text(). |
|
910 |
* @param $text string the text to unescape |
|
911 |
* @param $char_tag string the character tag |
|
912 |
* @return string |
|
913 |
* / |
|
914 |
||
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
|
915 |
public static function unescape_page_text($text, $char_tag) |
1 | 916 |
{ |
917 |
$text = str_replace("{APOS:$char_tag}", "'", $text); |
|
918 |
$text = str_replace("{QUOT:$char_tag}", '"', $text); |
|
919 |
$text = str_replace("{SLASH:$char_tag}", "\\", $text); |
|
920 |
return $text; |
|
921 |
} |
|
922 |
*/ |
|
923 |
||
924 |
/** |
|
925 |
* Generates a summary of the differences between two texts, and formats it as XHTML. |
|
926 |
* @param $str1 string the first block of text |
|
927 |
* @param $str2 string the second block of text |
|
928 |
* @return string |
|
929 |
*/ |
|
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
|
930 |
public static function diff($str1, $str2) |
1 | 931 |
{ |
932 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
592 | 933 |
require_once(ENANO_ROOT.'/includes/diff.php'); |
1 | 934 |
$str1 = explode("\n", $str1); |
935 |
$str2 = explode("\n", $str2); |
|
936 |
$diff = new Diff($str1, $str2); |
|
937 |
$renderer = new TableDiffFormatter(); |
|
938 |
return '<table class="diff">'.$renderer->format($diff).'</table>'; |
|
939 |
} |
|
940 |
||
35 | 941 |
/** |
942 |
* Changes wikitext image tags to HTML. |
|
943 |
* @param string The wikitext to process |
|
37 | 944 |
* @param array Will be overwritten with the list of HTML tags (the system uses tokens for TextWiki compatibility) |
35 | 945 |
* @return string |
946 |
*/ |
|
947 |
||
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
|
948 |
public static function process_image_tags($text, &$taglist) |
35 | 949 |
{ |
950 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
951 |
||
37 | 952 |
$s_delim = "\xFF"; |
953 |
$f_delim = "\xFF"; |
|
954 |
$taglist = array(); |
|
955 |
||
35 | 956 |
// 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
|
957 |
$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
|
958 |
$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
|
959 |
\[\[ # 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
|
960 |
:' . $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
|
961 |
(?:(?:\|(?:.+?))*) # 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
|
962 |
\]\] # 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
|
963 |
/ix'; |
35 | 964 |
|
965 |
preg_match_all($regex, $text, $matches); |
|
966 |
||
967 |
foreach ( $matches[0] as $i => $match ) |
|
968 |
{ |
|
969 |
||
970 |
$full_tag =& $matches[0][$i]; |
|
971 |
$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
|
972 |
|
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets 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 |
// 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
|
974 |
$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
|
975 |
$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
|
976 |
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
|
977 |
{ |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets 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 |
$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
|
979 |
$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
|
980 |
} |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets 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 |
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
|
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 |
// 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
|
984 |
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
|
985 |
} |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets 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 |
|
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets 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 |
// 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
|
988 |
$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
|
989 |
$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
|
990 |
$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
|
991 |
$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
|
992 |
$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
|
993 |
$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
|
994 |
|
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
995 |
// 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
|
996 |
$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
|
997 |
// 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
|
998 |
$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
|
999 |
$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
|
1000 |
// 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
|
1001 |
$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
|
1002 |
|
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1003 |
// 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
|
1004 |
// 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
|
1005 |
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
|
1006 |
{ |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1007 |
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
|
1008 |
{ |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1009 |
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
|
1010 |
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
|
1011 |
$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
|
1012 |
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
|
1013 |
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
|
1014 |
$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
|
1015 |
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
|
1016 |
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
|
1017 |
$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
|
1018 |
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
|
1019 |
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
|
1020 |
// 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
|
1021 |
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
|
1022 |
{ |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1023 |
$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
|
1024 |
$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
|
1025 |
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
|
1026 |
} |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1027 |
// 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
|
1028 |
// 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
|
1029 |
$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
|
1030 |
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
|
1031 |
{ |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1032 |
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
|
1033 |
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
|
1034 |
} |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1035 |
// 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
|
1036 |
// 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
|
1037 |
$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
|
1038 |
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
|
1039 |
} |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets 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 |
} |
35 | 1041 |
|
1042 |
if ( !isPage( $paths->nslist['File'] . $filename ) ) |
|
1043 |
{ |
|
66
52017732bc20
Added "raw" option to embedded images to make complex clickables easier
Dan
parents:
65
diff
changeset
|
1044 |
$text = str_replace($full_tag, '[[' . makeUrlNS('File', $filename) . ']]', $text); |
35 | 1045 |
continue; |
1046 |
} |
|
1047 |
||
569
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1048 |
if ( $scale_type == 'thumb' ) |
35 | 1049 |
{ |
1050 |
$r_width = 225; |
|
1051 |
$r_height = 225; |
|
1052 |
||
1053 |
$url = makeUrlNS('Special', 'DownloadFile/' . $filename, 'preview&width=' . $r_width . '&height=' . $r_height, true); |
|
1054 |
} |
|
1055 |
else if ( !empty($width) && !empty($height) ) |
|
1056 |
{ |
|
1057 |
$r_width = $width; |
|
1058 |
$r_height = $height; |
|
1059 |
||
1060 |
$url = makeUrlNS('Special', 'DownloadFile/' . $filename, 'preview&width=' . $r_width . '&height=' . $r_height, true); |
|
1061 |
} |
|
1062 |
else |
|
1063 |
{ |
|
1064 |
$url = makeUrlNS('Special', 'DownloadFile/' . $filename); |
|
1065 |
} |
|
1066 |
||
1067 |
$img_tag = '<img src="' . $url . '" '; |
|
1068 |
||
65 | 1069 |
// if ( isset($r_width) && isset($r_height) && $scale_type != '|thumb' ) |
1070 |
// { |
|
66
52017732bc20
Added "raw" option to embedded images to make complex clickables easier
Dan
parents:
65
diff
changeset
|
1071 |
// $img_tag .= 'width="' . $r_width . '" height="' . $r_height . '" '; |
65 | 1072 |
// } |
35 | 1073 |
|
66
52017732bc20
Added "raw" option to embedded images to make complex clickables easier
Dan
parents:
65
diff
changeset
|
1074 |
$img_tag .= 'style="border-width: 0px; /* background-color: white; */" '; |
35 | 1075 |
|
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
|
1076 |
$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
|
1077 |
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
|
1078 |
{ |
7c68a18a27be
AJAX comments are now paginated; plugin manager can now show system plugins; typo in installer corrected; links in oxygen/stpatty/admin footers changed to "About Enano" page; 1.0.1 release candidate
Dan
parents:
73
diff
changeset
|
1079 |
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
|
1080 |
} |
7c68a18a27be
AJAX comments are now paginated; plugin manager can now show system plugins; typo in installer corrected; links in oxygen/stpatty/admin footers changed to "About Enano" page; 1.0.1 release candidate
Dan
parents:
73
diff
changeset
|
1081 |
|
35 | 1082 |
$img_tag .= '/>'; |
1083 |
||
1084 |
$complete_tag = ''; |
|
1085 |
||
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
|
1086 |
if ( !empty($scale_type) && !$raw_display ) |
35 | 1087 |
{ |
1088 |
$complete_tag .= '<div class="thumbnail" '; |
|
1089 |
$clear_text = ''; |
|
1090 |
if ( !empty($clear) ) |
|
1091 |
{ |
|
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
|
1092 |
$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
|
1093 |
$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
|
1094 |
$clear_text .= "float: $side; margin-$opposite: 20px; width: {$r_width}px;"; |
35 | 1095 |
$complete_tag .= 'style="' . $clear_text . '" '; |
1096 |
} |
|
1097 |
$complete_tag .= '>'; |
|
1098 |
||
1099 |
$complete_tag .= '<a href="' . makeUrlNS('File', $filename) . '" style="display: block;">'; |
|
1100 |
$complete_tag .= $img_tag; |
|
1101 |
$complete_tag .= '</a>'; |
|
1102 |
||
1103 |
$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>'; |
|
1104 |
||
1105 |
if ( !empty($caption) ) |
|
1106 |
{ |
|
569
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1107 |
$complete_tag .= $mag_button . $caption; |
35 | 1108 |
} |
1109 |
||
1110 |
$complete_tag .= '</div>'; |
|
1111 |
} |
|
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
|
1112 |
else if ( $raw_display ) |
66
52017732bc20
Added "raw" option to embedded images to make complex clickables easier
Dan
parents:
65
diff
changeset
|
1113 |
{ |
67 | 1114 |
$complete_tag .= "$img_tag"; |
1115 |
$taglist[$i] = $complete_tag; |
|
1116 |
||
1117 |
$repl = "{$s_delim}e_img_{$i}{$f_delim}"; |
|
1118 |
$text = str_replace($full_tag, $repl, $text); |
|
1119 |
continue; |
|
66
52017732bc20
Added "raw" option to embedded images to make complex clickables easier
Dan
parents:
65
diff
changeset
|
1120 |
} |
35 | 1121 |
else |
1122 |
{ |
|
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
|
1123 |
$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
|
1124 |
$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
|
1125 |
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
|
1126 |
{ |
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
|
1127 |
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
|
1128 |
} |
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
|
1129 |
$complete_tag .= '>'; |
35 | 1130 |
$complete_tag .= $img_tag; |
1131 |
$complete_tag .= '</a>'; |
|
1132 |
} |
|
1133 |
||
37 | 1134 |
$complete_tag .= "\n\n"; |
1135 |
$taglist[$i] = $complete_tag; |
|
35 | 1136 |
|
37 | 1137 |
$pos = strpos($text, $full_tag); |
35 | 1138 |
|
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
|
1139 |
/* |
35 | 1140 |
while(true) |
1141 |
{ |
|
1142 |
$check1 = substr($text, $pos, 3); |
|
1143 |
$check2 = substr($text, $pos, 1); |
|
1144 |
if ( $check1 == '<p>' || $pos == 0 || $check2 == "\n" ) |
|
1145 |
{ |
|
1146 |
// die('found at pos '.$pos); |
|
1147 |
break; |
|
1148 |
} |
|
1149 |
$pos--; |
|
1150 |
} |
|
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
|
1151 |
*/ |
35 | 1152 |
|
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
|
1153 |
/* |
37 | 1154 |
$repl = "{$s_delim}e_img_{$i}{$f_delim}"; |
1155 |
$text = substr($text, 0, $pos) . $repl . substr($text, $pos); |
|
35 | 1156 |
|
1157 |
$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
|
1158 |
*/ |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1159 |
$text = str_replace_once($full_tag, $complete_tag, $text); |
35 | 1160 |
|
1161 |
unset($full_tag, $filename, $scale_type, $width, $height, $clear, $caption, $r_width, $r_height); |
|
1162 |
||
1163 |
} |
|
1164 |
||
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
|
1165 |
// 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
|
1166 |
// 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
|
1167 |
|
35 | 1168 |
return $text; |
1169 |
} |
|
1170 |
||
37 | 1171 |
/** |
1172 |
* Finalizes processing of image tags. |
|
1173 |
* @param string The preprocessed text |
|
1174 |
* @param array The list of image tags created by RenderMan::process_image_tags() |
|
1175 |
*/ |
|
1176 |
||
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
|
1177 |
public static function process_imgtags_stage2($text, $taglist) |
37 | 1178 |
{ |
1179 |
$s_delim = "\xFF"; |
|
1180 |
$f_delim = "\xFF"; |
|
1181 |
foreach ( $taglist as $i => $tag ) |
|
1182 |
{ |
|
1183 |
$repl = "{$s_delim}e_img_{$i}{$f_delim}"; |
|
1184 |
$text = str_replace($repl, $tag, $text); |
|
1185 |
} |
|
1186 |
return $text; |
|
1187 |
} |
|
1188 |
||
1 | 1189 |
} |
1190 |
||
1191 |
?> |