author | Dan |
Fri, 29 May 2009 16:37:32 -0400 | |
changeset 1011 | 96119a79cf81 |
parent 1003 | 28e2f75d66fd |
child 1027 | 98c052fc3337 |
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 |
||
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
45 |
$page = new PageProcessor($page_id, $namespace); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
46 |
$text = $page->fetch_text(); |
1 | 47 |
|
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
48 |
if ( !$render ) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
49 |
return $text; |
1 | 50 |
|
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
51 |
$text = self::render($text, $wiki, $smilies, $filter_links); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
52 |
return $text; |
1 | 53 |
} |
54 |
||
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
|
55 |
public static function getTemplate($id, $parms) |
1 | 56 |
{ |
57 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
953
323c4cd1aa37
Made some more changes to the way namespaces are handled, for optimization purposes. This is a bit of a structural reorganization: $paths->pages is obsoleted in its entirety; calculating page existence and metadata is now the job of the Namespace_* backend class. There are many things in PageProcessor that should be reorganized, and page actions in general should really be rethought. This is probably the beginning of a long process that will be taking place over the course of the betas.
Dan
parents:
832
diff
changeset
|
58 |
if ( !isPage($paths->get_pathskey($id, 'Template')) ) |
1 | 59 |
{ |
60 |
return '[['.$paths->nslist['Template'].$id.']]'; |
|
61 |
} |
|
62 |
if(isset($paths->template_cache[$id])) |
|
63 |
{ |
|
64 |
$text = $paths->template_cache[$id]; |
|
65 |
} |
|
66 |
else |
|
67 |
{ |
|
953
323c4cd1aa37
Made some more changes to the way namespaces are handled, for optimization purposes. This is a bit of a structural reorganization: $paths->pages is obsoleted in its entirety; calculating page existence and metadata is now the job of the Namespace_* backend class. There are many things in PageProcessor that should be reorganized, and page actions in general should really be rethought. This is probably the beginning of a long process that will be taking place over the course of the betas.
Dan
parents:
832
diff
changeset
|
68 |
$page = new PageProcessor($id, 'Template'); |
323c4cd1aa37
Made some more changes to the way namespaces are handled, for optimization purposes. This is a bit of a structural reorganization: $paths->pages is obsoleted in its entirety; calculating page existence and metadata is now the job of the Namespace_* backend class. There are many things in PageProcessor that should be reorganized, and page actions in general should really be rethought. This is probably the beginning of a long process that will be taking place over the course of the betas.
Dan
parents:
832
diff
changeset
|
69 |
$text = $page->fetch_text(); |
1 | 70 |
$paths->template_cache[$id] = $text; |
71 |
} |
|
72 |
||
73 |
$text = preg_replace('/<noinclude>(.*?)<\/noinclude>/is', '', $text); |
|
74 |
$text = preg_replace('/<nodisplay>(.*?)<\/nodisplay>/is', '\\1', $text); |
|
75 |
||
76 |
preg_match_all('#\(_([0-9]+)_\)#', $text, $matchlist); |
|
77 |
||
78 |
foreach($matchlist[1] as $m) |
|
79 |
{ |
|
80 |
if(isset($parms[((int)$m)+1])) |
|
81 |
{ |
|
82 |
$p = $parms[((int)$m)+1]; |
|
83 |
} |
|
84 |
else |
|
85 |
{ |
|
86 |
$p = '<b>Notice:</b> RenderMan::getTemplate(): Parameter '.$m.' is not set'; |
|
87 |
} |
|
88 |
$text = str_replace('(_'.$m.'_)', $p, $text); |
|
717
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
89 |
$text = str_replace('{{' . ( $m + 1 ) . '}}', $p, $text); |
1 | 90 |
} |
91 |
$text = RenderMan::include_templates($text); |
|
92 |
return $text; |
|
93 |
} |
|
94 |
||
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
|
95 |
public static function fetch_template_text($id) |
1 | 96 |
{ |
97 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
745
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
98 |
$fetch_ns = 'Template'; |
953
323c4cd1aa37
Made some more changes to the way namespaces are handled, for optimization purposes. This is a bit of a structural reorganization: $paths->pages is obsoleted in its entirety; calculating page existence and metadata is now the job of the Namespace_* backend class. There are many things in PageProcessor that should be reorganized, and page actions in general should really be rethought. This is probably the beginning of a long process that will be taking place over the course of the betas.
Dan
parents:
832
diff
changeset
|
99 |
if ( !isPage($paths->get_pathskey($id, 'Template')) ) |
1 | 100 |
{ |
745
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
101 |
// Transclusion of another page |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
102 |
// 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
|
103 |
$nssep = substr($paths->nslist['Special'], -1); |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
104 |
$nslist = $paths->nslist; |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
105 |
foreach ( $nslist as &$ns ) |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
106 |
{ |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
107 |
if ( $ns == '' ) |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
108 |
$ns = $nssep; |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
109 |
} |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
110 |
$prefixlist = array_flip($nslist); |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
111 |
foreach ( $nslist as &$ns ) |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
112 |
{ |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
113 |
$ns = preg_quote($ns); |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
114 |
} |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
115 |
$nslist = implode('|', $nslist); |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
116 |
if ( preg_match("/^($nslist)(.*?)$/", $id, $match) ) |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
117 |
{ |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
118 |
// 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
|
119 |
if ( isset($prefixlist[$match[1]]) ) |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
120 |
{ |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
121 |
$new_id = $paths->nslist[ $prefixlist[$match[1]] ] . sanitize_page_id($match[2]); |
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
122 |
if ( !isPage($new_id) ) |
745
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
123 |
{ |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
124 |
return "[[$new_id]]"; |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
125 |
} |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
126 |
$fetch_ns = $prefixlist[$match[1]]; |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
127 |
$id = sanitize_page_id($match[2]); |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
128 |
} |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
129 |
} |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
130 |
else |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
131 |
{ |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
132 |
return '[['.$paths->nslist['Template'].$id.']]'; |
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
133 |
} |
1 | 134 |
} |
135 |
if(isset($paths->template_cache[$id])) |
|
136 |
{ |
|
137 |
$text = $paths->template_cache[$id]; |
|
138 |
} |
|
139 |
else |
|
140 |
{ |
|
745
0a3866f74faa
Added full all-namespace transclusion support in RenderMan
Dan
parents:
717
diff
changeset
|
141 |
$text = RenderMan::getPage($id, $fetch_ns, 0, false, false, false, false); |
1 | 142 |
$paths->template_cache[$id] = $text; |
143 |
} |
|
144 |
||
145 |
if ( is_string($text) ) |
|
146 |
{ |
|
147 |
$text = preg_replace('/<noinclude>(.*?)<\/noinclude>/is', '', $text); |
|
148 |
$text = preg_replace('/<nodisplay>(.*?)<\/nodisplay>/is', '\\1', $text); |
|
149 |
} |
|
150 |
||
151 |
return $text; |
|
152 |
} |
|
153 |
||
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
154 |
/** |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
155 |
* Renders a glob of text. Note that this is PHP-safe, so if returned text (or rather, "?>" . $returned) has PHP it can be eval'ed. |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
156 |
* @param string Text to render |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
157 |
* @param int Render parameters - see constants.php |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
158 |
* @return string Rendered text |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
159 |
*/ |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
160 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
161 |
public static function render($text, $flags = RENDER_WIKI_DEFAULT, $smilies = true) |
1 | 162 |
{ |
163 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
164 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
165 |
if ( !$smilies ) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
166 |
$flags |= RENDER_NOSMILIES; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
167 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
168 |
if ( $flags & ~RENDER_NOSMILIES ) |
1 | 169 |
{ |
170 |
$text = RenderMan::smilieyize($text); |
|
171 |
} |
|
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
172 |
if ( $flags & RENDER_WIKI_DEFAULT ) |
1 | 173 |
{ |
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
174 |
$text = RenderMan::next_gen_wiki_format($text, $flags); |
1 | 175 |
} |
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
176 |
else if ( $flags & RENDER_WIKI_TEMPLATE ) |
1 | 177 |
{ |
178 |
$text = $template->tplWikiFormat($text); |
|
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
179 |
} |
1 | 180 |
return $text; |
181 |
} |
|
182 |
||
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
183 |
private static function next_gen_wiki_format($text, $flags = 0) |
1 | 184 |
{ |
185 |
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
|
186 |
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
|
187 |
|
592 | 188 |
require_once(ENANO_ROOT.'/includes/wikiformat.php'); |
189 |
require_once(ENANO_ROOT.'/includes/wikiengine/Tables.php'); |
|
190 |
||
382
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
parents:
377
diff
changeset
|
191 |
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
|
192 |
|
1 | 193 |
$random_id = md5( time() . mt_rand() ); |
194 |
||
195 |
// Strip out <nowiki> sections and PHP code |
|
196 |
||
407
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
197 |
$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
|
198 |
|
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
199 |
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
|
200 |
{ |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
201 |
$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
|
202 |
} |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
203 |
|
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
204 |
$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
|
205 |
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
|
206 |
{ |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
207 |
eval($cmd); |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
208 |
} |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
209 |
|
1 | 210 |
$php = preg_match_all('#<\?php(.*?)\?>#is', $text, $phpsec); |
211 |
||
212 |
for($i=0;$i<sizeof($phpsec[1]);$i++) |
|
213 |
{ |
|
214 |
$text = str_replace('<?php'.$phpsec[1][$i].'?>', '{PHP:'.$random_id.':'.$i.'}', $text); |
|
215 |
} |
|
216 |
||
217 |
$text = preg_replace('/<noinclude>(.*?)<\/noinclude>/is', '\\1', $text); |
|
218 |
if ( $paths->namespace == 'Template' ) |
|
219 |
{ |
|
220 |
$text = preg_replace('/<nodisplay>(.*?)<\/nodisplay>/is', '', $text); |
|
221 |
} |
|
222 |
||
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
223 |
if ( !($flags & RENDER_BLOCKONLY) ) |
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
|
224 |
{ |
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
225 |
preg_match_all('/<lang (?:code|id)="([a-z0-9_-]+)">([\w\W]+?)<\/lang>/', $text, $langmatch); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
226 |
foreach ( $langmatch[0] as $i => $match ) |
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
|
227 |
{ |
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
228 |
if ( $langmatch[1][$i] == $lang->lang_code ) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
229 |
{ |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
230 |
$text = str_replace_once($match, $langmatch[2][$i], $text); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
231 |
} |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
232 |
else |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
233 |
{ |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
234 |
$text = str_replace_once($match, '', $text); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
235 |
} |
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
|
236 |
} |
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
|
237 |
|
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
238 |
$code = $plugins->setHook('render_wikiformat_pre'); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
239 |
foreach ( $code as $cmd ) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
240 |
{ |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
241 |
eval($cmd); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
242 |
} |
163 | 243 |
|
715 | 244 |
//$template_regex = "/\{\{([^\]]+?)((\n([ ]*?)[A-z0-9]+([ ]*?)=([ ]*?)(.+?))*)\}\}/is"; |
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
245 |
$template_regex = "/\{\{(.+)((\n|\|[ ]*([A-z0-9]+)[ ]*=[ ]*(.+))*)\}\}/isU"; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
246 |
$i = 0; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
247 |
while ( preg_match($template_regex, $text) ) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
248 |
{ |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
249 |
$i++; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
250 |
if ( $i == 5 ) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
251 |
break; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
252 |
$text = RenderMan::include_templates($text); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
253 |
} |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
254 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
255 |
$code = $plugins->setHook('render_wikiformat_posttemplates'); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
256 |
foreach ( $code as $cmd ) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
257 |
{ |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
258 |
eval($cmd); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
259 |
} |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
260 |
|
1 | 261 |
// 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
|
262 |
$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
|
263 |
$text = RenderMan::process_imgtags_stage2($text, $taglist); |
1 | 264 |
} |
265 |
||
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
|
266 |
// 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
|
267 |
$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
|
268 |
|
1 | 269 |
$text = process_tables($text); |
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
270 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
271 |
if ( !($flags & RENDER_BLOCKONLY) ) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
272 |
$text = RenderMan::parse_internal_links($text); |
1 | 273 |
|
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
|
274 |
$wiki = Text_Wiki::singleton('Mediawiki'); |
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
275 |
$wiki->setRenderConf('Xhtml', 'wikilink', 'view_url', contentPath); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
276 |
$wiki->setRenderConf('Xhtml', 'Url', 'css_descr', 'external'); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
277 |
if ( $flags & RENDER_BLOCKONLY ) |
1 | 278 |
{ |
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
279 |
$wiki->disableRule('Freelink'); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
280 |
$wiki->disableRule('Url'); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
281 |
$wiki->disableRule('Toc'); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
282 |
$wiki->disableRule('Image'); |
1 | 283 |
} |
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
284 |
else if ( $flags & RENDER_INLINEONLY ) |
1 | 285 |
{ |
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
286 |
foreach ( array('code', 'html', 'raw', 'include', 'embed', 'horiz', 'break', 'blockquote', 'list', 'newline', 'paragraph', 'revise', 'tighten') as $rule ) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
287 |
{ |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
288 |
$wiki->disableRule($rule); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
289 |
} |
1 | 290 |
} |
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
291 |
$result = $wiki->transform($text, 'Xhtml'); |
1 | 292 |
|
163 | 293 |
// HTML fixes |
294 |
$result = preg_replace('#<tr>([\s]*?)<\/tr>#is', '', $result); |
|
295 |
$result = preg_replace('#<p>([\s]*?)<\/p>#is', '', $result); |
|
296 |
$result = preg_replace('#<br />([\s]*?)<table#is', '<table', $result); |
|
297 |
$result = str_replace("<pre><code>\n", "<pre><code>", $result); |
|
298 |
$result = preg_replace("/<p><table([^>]*?)><\/p>/", "<table\\1>", $result); |
|
299 |
$result = str_replace("<br />\n</td>", "\n</td>", $result); |
|
300 |
$result = str_replace("<p><tr>", "<tr>", $result); |
|
301 |
$result = str_replace("<tr><br />", "<tr>", $result); |
|
302 |
$result = str_replace("</tr><br />", "</tr>", $result); |
|
303 |
$result = str_replace("</table><br />", "</table>", $result); |
|
304 |
$result = preg_replace('/<\/table>$/', "</table><br /><br />", $result); |
|
305 |
$result = str_replace("<p></div></p>", "</div>", $result); |
|
306 |
$result = str_replace("<p></table></p>", "</table>", $result); |
|
307 |
||
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
308 |
if ( !($flags & RENDER_BLOCKONLY) ) |
163 | 309 |
{ |
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
310 |
$code = $plugins->setHook('render_wikiformat_post'); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
311 |
foreach ( $code as $cmd ) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
312 |
{ |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
313 |
eval($cmd); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
314 |
} |
163 | 315 |
} |
37 | 316 |
|
1 | 317 |
// Reinsert <nowiki> sections |
318 |
for($i=0;$i<$nw;$i++) |
|
319 |
{ |
|
320 |
$result = str_replace('{NOWIKI:'.$random_id.':'.$i.'}', $nowiki[1][$i], $result); |
|
321 |
} |
|
322 |
||
323 |
// Reinsert PHP |
|
324 |
for($i=0;$i<$php;$i++) |
|
325 |
{ |
|
326 |
$result = str_replace('{PHP:'.$random_id.':'.$i.'}', '<?php'.$phpsec[1][$i].'?>', $result); |
|
327 |
} |
|
328 |
||
382
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
parents:
377
diff
changeset
|
329 |
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
|
330 |
|
1 | 331 |
return $result; |
332 |
||
333 |
} |
|
334 |
||
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
|
335 |
public static function wikiFormat($message, $filter_links = true, $do_params = false, $plaintext = false) |
163 | 336 |
{ |
1 | 337 |
global $db, $session, $paths, $template, $plugins; // Common objects |
338 |
||
339 |
return RenderMan::next_gen_wiki_format($message, $plaintext, $filter_links, $do_params); |
|
340 |
} |
|
341 |
||
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
|
342 |
public static function destroy_javascript($message, $_php = false) |
1 | 343 |
{ |
344 |
$message = preg_replace('#<(script|object|applet|embed|iframe|frame|form|input|select)(.*?)>#is', '<\\1\\2>', $message); |
|
345 |
$message = preg_replace('#</(script|object|applet|embed|iframe|frame|form|input|select)(.*?)>#is', '</\\1\\2>', $message); |
|
346 |
$message = preg_replace('#(javascript|script|activex|chrome|about|applet):#is', '\\1:', $message); |
|
347 |
if ( $_php ) |
|
348 |
{ |
|
349 |
// Left in only for compatibility |
|
350 |
$message = preg_replace('#<(.*?)>#is', '<\\1>', $message); |
|
351 |
$message = preg_replace('#<(.*?)>#is', '<\\1>', $message); |
|
352 |
$message = preg_replace('#<(\?|\?php|%)(.*?)(\?|%)>#is', '<\\1\\2\\3>', $message); |
|
353 |
// strip <a href="foo" onclick="bar();">-type attacks |
|
354 |
$message = preg_replace('#<([a-zA-Z:\-]+) (.*?)on([A-Za-z]*)=(.*?)>#is', '<\\1\\2on\\3=\\4>', $message); |
|
355 |
} |
|
356 |
return $message; |
|
357 |
} |
|
358 |
||
371
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
parents:
345
diff
changeset
|
359 |
public static function strip_php($message) |
1 | 360 |
{ |
361 |
return RenderMan::destroy_javascript($message, true); |
|
362 |
} |
|
363 |
||
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
|
364 |
public static function sanitize_html($text) |
1 | 365 |
{ |
366 |
$text = htmlspecialchars($text); |
|
91 | 367 |
$allowed_tags = Array('b', 'i', 'u', 'pre', 'code', 'tt', 'br', 'p', 'nowiki', '!--([\w\W]+)--'); |
1 | 368 |
foreach($allowed_tags as $t) |
369 |
{ |
|
370 |
$text = preg_replace('#<'.$t.'>(.*?)</'.$t.'>#is', '<'.$t.'>\\1</'.$t.'>', $text); |
|
371 |
$text = preg_replace('#<'.$t.' />#is', '<'.$t.' />', $text); |
|
372 |
$text = preg_replace('#<'.$t.'>#is', '<'.$t.'>', $text); |
|
373 |
} |
|
374 |
return $text; |
|
375 |
} |
|
376 |
||
91 | 377 |
/** |
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
378 |
* Reverse-renders a blob of text (converts it from XHTML back to wikitext) by using parser hints and educated guesses. |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
379 |
* @param string XHTML |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
380 |
* @return string Wikitext |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
381 |
*/ |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
382 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
383 |
public static function reverse_render($text) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
384 |
{ |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
385 |
// convert \r\n to \n |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
386 |
$text = str_replace("\r\n", "\n", $text); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
387 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
388 |
// Separate certain block level elements onto their own lines. This tidies up the tag |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
389 |
// soup that TinyMCE sometimes produces. |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
390 |
$block_elements = array('h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'div', 'table', 'ul', 'pre'); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
391 |
$block_elements = implode('|', $block_elements); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
392 |
$regex = "#(</(?:$block_elements)>)\n?<($block_elements)(>| .+?>)#i"; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
393 |
$text = preg_replace($regex, "$1\n\n<$2$3", $text); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
394 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
395 |
$text = self::reverse_process_parser_hints($text); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
396 |
$text = self::reverse_process_headings($text); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
397 |
$text = self::reverse_process_lists($text); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
398 |
$text = self::reverse_process_tables($text); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
399 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
400 |
// Lastly, strip out paragraph tags. |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
401 |
$text = preg_replace('|^ *<p>(.+?)</p> *$|m', "\\1", $text); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
402 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
403 |
return $text; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
404 |
} |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
405 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
406 |
public static function reverse_process_parser_hints($text) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
407 |
{ |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
408 |
global $db, $session, $paths, $template, $plugins; // Common objects |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
409 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
410 |
if ( !preg_match_all('|<!--#([a-z0-9_]+)(?: (.+?))?-->([\w\W]*?)<!--#/\\1-->|s', $text, $matches) ) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
411 |
return $text; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
412 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
413 |
foreach ( $matches[0] as $i => $match ) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
414 |
{ |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
415 |
$tag =& $matches[1][$i]; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
416 |
$attribs =& $matches[2][$i]; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
417 |
$inner =& $matches[3][$i]; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
418 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
419 |
$attribs = self::reverse_process_hint_attribs($attribs); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
420 |
switch($tag) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
421 |
{ |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
422 |
case 'smiley': |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
423 |
case 'internallink': |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
424 |
case 'imagelink': |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
425 |
if ( isset($attribs['code']) ) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
426 |
{ |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
427 |
$text = str_replace($match, $attribs['code'], $text); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
428 |
} |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
429 |
else if ( isset($attribs['src']) ) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
430 |
{ |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
431 |
$text = str_replace($match, $attribs['src'], $text); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
432 |
} |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
433 |
break; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
434 |
} |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
435 |
} |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
436 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
437 |
return $text; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
438 |
} |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
439 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
440 |
public static function reverse_process_hint_attribs($attribs) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
441 |
{ |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
442 |
$return = array(); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
443 |
if ( !preg_match_all('/([a-z0-9_-]+)="([^"]+?)"/', $attribs, $matches) ) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
444 |
return array(); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
445 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
446 |
foreach ( $matches[0] as $i => $match ) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
447 |
{ |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
448 |
$name =& $matches[1][$i]; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
449 |
$value =& $matches[2][$i]; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
450 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
451 |
$value = base64_decode($value); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
452 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
453 |
$return[$name] = $value; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
454 |
} |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
455 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
456 |
return $return; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
457 |
} |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
458 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
459 |
/** |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
460 |
* Escapes a string so that it's safe to use as an attribute in a parser hint. |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
461 |
* @param string |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
462 |
* @return string |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
463 |
*/ |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
464 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
465 |
public static function escape_parser_hint_attrib($text) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
466 |
{ |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
467 |
return base64_encode($text); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
468 |
} |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
469 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
470 |
public static function reverse_process_headings($text) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
471 |
{ |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
472 |
if ( !preg_match_all('|^<h([1-6])(?: id="toc[0-9]+")?>(.*?)</h\\1>$|m', $text, $matches) ) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
473 |
return $text; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
474 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
475 |
foreach ( $matches[0] as $i => $match ) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
476 |
{ |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
477 |
// generate heading tag |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
478 |
$heading_size = intval($matches[1][$i]); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
479 |
$eq = ''; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
480 |
for ( $j = 0; $j < $heading_size; $j++ ) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
481 |
$eq .= '='; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
482 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
483 |
$heading =& $matches[2][$i]; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
484 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
485 |
$tag = "$eq $heading $eq"; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
486 |
$text = str_replace($match, $tag, $text); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
487 |
} |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
488 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
489 |
return $text; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
490 |
} |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
491 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
492 |
public static function reverse_process_lists($text) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
493 |
{ |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
494 |
if ( !preg_match('!(</?(?:ul|ol|li)>)!', $text) ) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
495 |
return $text; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
496 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
497 |
$split = preg_split('!(</?(?:ul|ol|li)>)!', $text, -1, PREG_SPLIT_DELIM_CAPTURE); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
498 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
499 |
$stack_height = 0; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
500 |
$current_list = ''; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
501 |
$old_current_list = ''; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
502 |
$spaces = ''; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
503 |
$marker = '*'; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
504 |
$list_id = 0; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
505 |
$just_terminated = false; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
506 |
foreach ( $split as $tag ) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
507 |
{ |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
508 |
switch($tag) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
509 |
{ |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
510 |
case '<ul>': |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
511 |
case '<ol>': |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
512 |
$stack_height++; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
513 |
$just_terminated = false; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
514 |
if ( $stack_height > 1 ) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
515 |
$spaces .= $marker; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
516 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
517 |
$marker = ( $tag == 'ol' ) ? '#' : '*'; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
518 |
if ( $stack_height > 1 ) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
519 |
$current_list .= "\n"; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
520 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
521 |
break; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
522 |
case '</ul>': |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
523 |
case '</ol>': |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
524 |
$stack_height--; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
525 |
$spaces = substr($spaces, 1); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
526 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
527 |
if ( $stack_height == 0 ) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
528 |
{ |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
529 |
// rotate |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
530 |
$text = str_replace_once("{$old_current_list}{$tag}", trim($current_list), $text); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
531 |
$current_list = ''; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
532 |
$old_current_list = ''; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
533 |
} |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
534 |
$just_terminated = true; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
535 |
break; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
536 |
case '<li>': |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
537 |
if ( $stack_height < 1 ) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
538 |
break; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
539 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
540 |
$current_list .= "{$spaces}{$marker} "; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
541 |
break; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
542 |
case '</li>': |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
543 |
if ( $stack_height < 1 ) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
544 |
break; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
545 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
546 |
if ( !$just_terminated ) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
547 |
$current_list .= "\n"; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
548 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
549 |
$just_terminated = false; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
550 |
break; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
551 |
default: |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
552 |
if ( $stack_height > 0 ) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
553 |
{ |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
554 |
$current_list .= trim($tag); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
555 |
} |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
556 |
break; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
557 |
} |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
558 |
if ( $stack_height > 0 ) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
559 |
{ |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
560 |
$old_current_list .= $tag; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
561 |
} |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
562 |
} |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
563 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
564 |
return $text; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
565 |
} |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
566 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
567 |
public static function reverse_process_tables($text) |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
568 |
{ |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
569 |
return $text; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
570 |
} |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
571 |
|
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
572 |
/** |
91 | 573 |
* Parses internal links (wikilinks) in a block of text. |
574 |
* @param string Text to process |
|
592 | 575 |
* @param string Optional. If included will be used as a template instead of using the default syntax. |
971
bc8f3ab74e5e
Render / Template: No longer does exist checks for wikilinks on sidebar
Dan
parents:
953
diff
changeset
|
576 |
* @param bool If false, does not add wikilink-nonexistent or check for exsistence of pages. Can reduce DB queries; defualts to true. |
1003
28e2f75d66fd
Class "currentpage" is now added to all internal links, including sidebar buttons, if the link points to the current page.
Dan
parents:
971
diff
changeset
|
577 |
* @param string Page ID. If specified, class="currentpage" will be added to links if they match the given page ID and namespace |
28e2f75d66fd
Class "currentpage" is now added to all internal links, including sidebar buttons, if the link points to the current page.
Dan
parents:
971
diff
changeset
|
578 |
* @param string Namespace. If specified, class="currentpage" will be added to links if they match the given page ID and namespace |
91 | 579 |
* @return string |
580 |
*/ |
|
581 |
||
1003
28e2f75d66fd
Class "currentpage" is now added to all internal links, including sidebar buttons, if the link points to the current page.
Dan
parents:
971
diff
changeset
|
582 |
public static function parse_internal_links($text, $tplcode = false, $do_exist_check = true, $match_page_id = false, $match_namespace = false) |
91 | 583 |
{ |
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
|
584 |
global $db, $session, $paths, $template, $plugins; // Common objects |
91 | 585 |
|
592 | 586 |
if ( is_string($tplcode) ) |
587 |
{ |
|
588 |
$parser = $template->makeParserText($tplcode); |
|
589 |
} |
|
590 |
||
91 | 591 |
// stage 1 - links with alternate text |
592 |
preg_match_all('/\[\[([^\[\]<>\{\}\|]+)\|(.+?)\]\]/', $text, $matches); |
|
593 |
foreach ( $matches[0] as $i => $match ) |
|
594 |
{ |
|
595 |
list($page_id, $namespace) = RenderMan::strToPageID($matches[1][$i]); |
|
715 | 596 |
if ( ($pos = strrpos($page_id, '#')) !== false ) |
597 |
{ |
|
598 |
$hash = substr($page_id, $pos); |
|
599 |
$page_id = substr($page_id, 0, $pos); |
|
600 |
} |
|
601 |
else |
|
602 |
{ |
|
603 |
$hash = ''; |
|
604 |
} |
|
91 | 605 |
$pid_clean = $paths->nslist[$namespace] . sanitize_page_id($page_id); |
606 |
||
715 | 607 |
$url = makeUrl($pid_clean, false, true) . $hash; |
91 | 608 |
$inner_text = $matches[2][$i]; |
609 |
$quot = '"'; |
|
971
bc8f3ab74e5e
Render / Template: No longer does exist checks for wikilinks on sidebar
Dan
parents:
953
diff
changeset
|
610 |
$exists = ( ($do_exist_check && isPage($pid_clean)) || !$do_exist_check ) ? '' : ' class="wikilink-nonexistent"'; |
91 | 611 |
|
1003
28e2f75d66fd
Class "currentpage" is now added to all internal links, including sidebar buttons, if the link points to the current page.
Dan
parents:
971
diff
changeset
|
612 |
if ( $match_page_id && $match_namespace && $pid_clean === $paths->get_pathskey($match_page_id, $match_namespace) ) |
28e2f75d66fd
Class "currentpage" is now added to all internal links, including sidebar buttons, if the link points to the current page.
Dan
parents:
971
diff
changeset
|
613 |
$exists .= ' class="currentpage"'; |
28e2f75d66fd
Class "currentpage" is now added to all internal links, including sidebar buttons, if the link points to the current page.
Dan
parents:
971
diff
changeset
|
614 |
|
592 | 615 |
if ( $tplcode ) |
616 |
{ |
|
617 |
$parser->assign_vars(array( |
|
618 |
'HREF' => $url, |
|
619 |
'FLAGS' => $exists, |
|
620 |
'TEXT' => $inner_text |
|
621 |
)); |
|
622 |
$link = $parser->run(); |
|
623 |
} |
|
624 |
else |
|
625 |
{ |
|
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
626 |
$omatch = self::escape_parser_hint_attrib($match); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
627 |
$link = "<!--#internallink src=\"$omatch\" --><a href={$quot}{$url}{$quot}{$exists}>{$inner_text}</a><!--#/internallink-->"; |
592 | 628 |
} |
91 | 629 |
|
630 |
$text = str_replace($match, $link, $text); |
|
631 |
} |
|
632 |
||
633 |
// stage 2 - links with no alternate text |
|
634 |
preg_match_all('/\[\[([^\[\]<>\{\}\|]+)\]\]/', $text, $matches); |
|
635 |
foreach ( $matches[0] as $i => $match ) |
|
636 |
{ |
|
637 |
list($page_id, $namespace) = RenderMan::strToPageID($matches[1][$i]); |
|
638 |
$pid_clean = $paths->nslist[$namespace] . sanitize_page_id($page_id); |
|
639 |
||
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
|
640 |
$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
|
641 |
$inner_text = ( isPage($pid_clean) ) ? htmlspecialchars(get_page_title($pid_clean)) : htmlspecialchars($matches[1][$i]); |
91 | 642 |
$quot = '"'; |
971
bc8f3ab74e5e
Render / Template: No longer does exist checks for wikilinks on sidebar
Dan
parents:
953
diff
changeset
|
643 |
$exists = ( ($do_exist_check && isPage($pid_clean)) || !$do_exist_check ) ? '' : ' class="wikilink-nonexistent"'; |
91 | 644 |
|
1003
28e2f75d66fd
Class "currentpage" is now added to all internal links, including sidebar buttons, if the link points to the current page.
Dan
parents:
971
diff
changeset
|
645 |
if ( $match_page_id && $match_namespace && $pid_clean === $paths->get_pathskey($match_page_id, $match_namespace) ) |
28e2f75d66fd
Class "currentpage" is now added to all internal links, including sidebar buttons, if the link points to the current page.
Dan
parents:
971
diff
changeset
|
646 |
$exists .= ' class="currentpage"'; |
28e2f75d66fd
Class "currentpage" is now added to all internal links, including sidebar buttons, if the link points to the current page.
Dan
parents:
971
diff
changeset
|
647 |
|
592 | 648 |
if ( $tplcode ) |
649 |
{ |
|
650 |
$parser->assign_vars(array( |
|
651 |
'HREF' => $url, |
|
652 |
'FLAGS' => $exists, |
|
653 |
'TEXT' => $inner_text |
|
654 |
)); |
|
655 |
$link = $parser->run(); |
|
656 |
} |
|
657 |
else |
|
658 |
{ |
|
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
659 |
$omatch = self::escape_parser_hint_attrib($match); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
660 |
$link = "<!--#internallink src=\"$omatch\" --><a href={$quot}{$url}{$quot}{$exists}>{$inner_text}</a><!--#/internallink-->"; |
592 | 661 |
} |
91 | 662 |
|
663 |
$text = str_replace($match, $link, $text); |
|
664 |
} |
|
665 |
||
666 |
return $text; |
|
667 |
} |
|
668 |
||
1 | 669 |
/** |
670 |
* 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
|
671 |
* @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
|
672 |
* @example |
1 | 673 |
* <code> |
63
2c57d3018a88
Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents:
37
diff
changeset
|
674 |
foo = lorem ipsum |
2c57d3018a88
Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents:
37
diff
changeset
|
675 |
bar = dolor sit amet |
1 | 676 |
* </code> |
677 |
* @return array Example: |
|
678 |
* [foo] => lorem ipsum |
|
679 |
* [bar] => dolor sit amet |
|
680 |
*/ |
|
681 |
||
717
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
682 |
public static function parse_template_vars($input, $newlinemode = true) |
1 | 683 |
{ |
717
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
684 |
$parms = array(); |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
685 |
$input = trim($input); |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
686 |
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
|
687 |
{ |
717
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
688 |
$result = preg_match_all('/ |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
689 |
(?:^|[\s]*)\|? # start of parameter - string start or series of spaces |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
690 |
[ ]* |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
691 |
(?: |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
692 |
([A-z0-9_]+) # variable name |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
693 |
[ ]* = [ ]* # assignment |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
694 |
)? # 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
|
695 |
(.+) # value |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
696 |
/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
|
697 |
} |
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
|
698 |
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
|
699 |
{ |
717
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
700 |
$result = preg_match_all('/ |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
701 |
(?:^|[ ]*)\| # start of parameter - string start or series of spaces |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
702 |
[ ]* |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
703 |
(?: |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
704 |
([A-z0-9_]+) # variable name |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
705 |
[ ]* = [ ]* # assignment |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
706 |
)? # 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
|
707 |
([^\|]+|.+?\n[ ]*\|) # value |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
708 |
/x', trim($input), $matches); |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
709 |
} |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
710 |
if ( $result ) |
1 | 711 |
{ |
717
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
712 |
$pi = 0; |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
713 |
for ( $i = 0; $i < count($matches[0]); $i++ ) |
1 | 714 |
{ |
717
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
715 |
$matches[1][$i] = trim($matches[1][$i]); |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
716 |
$parmname = !empty($matches[1][$i]) ? $matches[1][$i] : strval(++$pi); |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
717 |
$parms[ $parmname ] = $matches[2][$i]; |
1 | 718 |
} |
719 |
} |
|
720 |
return $parms; |
|
721 |
} |
|
722 |
||
723 |
/** |
|
724 |
* 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
|
725 |
* Updated in 1.0.2 to also parse template tags in the format of {{Foo |a = b |b = c |c = therefore, a}} |
1 | 726 |
* @param string The text to process |
727 |
* @return string Formatted text |
|
728 |
* @example |
|
729 |
* <code> |
|
730 |
$text = '{{Template |
|
717
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
731 |
| parm1 = Foo |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
732 |
| parm2 = Bar |
1 | 733 |
}}'; |
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
|
734 |
$text = RenderMan::include_templates($text); |
1 | 735 |
* </code> |
736 |
*/ |
|
737 |
||
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
|
738 |
public static function include_templates($text) |
1 | 739 |
{ |
740 |
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
|
741 |
// $template_regex = "/\{\{([^\]]+?)((\n([ ]*?)[A-z0-9]+([ ]*?)=([ ]*?)(.+?))*)\}\}/is"; |
717
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
742 |
// matches: |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
743 |
// 1 - template name |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
744 |
// 2 - parameter section |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
745 |
$template_regex = "/ |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
746 |
\{\{ # opening |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
747 |
([^\n\t\a\r]+) # template name |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
748 |
((?:(?:[\s]+\|?)[ ]*(?:[A-z0-9_]+)[ ]*=[ ]*?(?:.+))*) # parameters |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
749 |
\}\} # closing |
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
750 |
/isxU"; |
1 | 751 |
if ( $count = preg_match_all($template_regex, $text, $matches) ) |
752 |
{ |
|
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
|
753 |
//die('<pre>' . print_r($matches, true) . '</pre>'); |
1 | 754 |
for ( $i = 0; $i < $count; $i++ ) |
755 |
{ |
|
63
2c57d3018a88
Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
Dan
parents:
37
diff
changeset
|
756 |
$matches[1][$i] = sanitize_page_id($matches[1][$i]); |
717
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
757 |
$newlinemode = ( substr($matches[2][$i], 0, 1) == "\n" ); |
1 | 758 |
$parmsection = trim($matches[2][$i]); |
759 |
if ( !empty($parmsection) ) |
|
760 |
{ |
|
717
236360cf79a0
Made template inclusion wikisyntax fully MediaWiki-compatible
Dan
parents:
715
diff
changeset
|
761 |
$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
|
762 |
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
|
763 |
// 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
|
764 |
$parms = array(); |
1 | 765 |
} |
766 |
else |
|
767 |
{ |
|
768 |
$parms = Array(); |
|
769 |
} |
|
770 |
if ( $tpl_code = RenderMan::fetch_template_text($matches[1][$i]) ) |
|
771 |
{ |
|
772 |
$parser = $template->makeParserText($tpl_code); |
|
773 |
$parser->assign_vars($parms); |
|
774 |
$text = str_replace($matches[0][$i], $parser->run(), $text); |
|
775 |
} |
|
776 |
} |
|
777 |
} |
|
778 |
return $text; |
|
779 |
} |
|
780 |
||
781 |
/** |
|
782 |
* Preprocesses an HTML text string prior to being sent to MySQL. |
|
783 |
* @param string $text |
|
784 |
* @param bool $strip_all_php - if true, strips all PHP regardless of user permissions. Else, strips PHP only if user level < USER_LEVEL_ADMIN. |
|
785 |
*/ |
|
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
|
786 |
public static function preprocess_text($text, $strip_all_php = true, $sqlescape = true) |
1 | 787 |
{ |
788 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
789 |
$random_id = md5( time() . mt_rand() ); |
|
790 |
||
407
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
791 |
$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
|
792 |
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
|
793 |
{ |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
794 |
eval($cmd); |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
795 |
} |
1 | 796 |
|
797 |
$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
|
798 |
$can_do_html = $session->get_permissions('html_in_pages'); |
1 | 799 |
|
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
|
800 |
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
|
801 |
{ |
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
|
802 |
$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
|
803 |
} |
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
|
804 |
else if ( !$can_do_html && !$can_do_php ) |
1 | 805 |
{ |
24 | 806 |
$text = sanitize_html($text, true); |
1 | 807 |
// If we can't do PHP, we can't do Javascript either. |
808 |
$text = RenderMan::destroy_javascript($text); |
|
809 |
} |
|
810 |
||
811 |
// Strip out <nowiki> sections and PHP code |
|
812 |
||
813 |
$php = preg_match_all('#(<|<)\?php(.*?)\?(>|>)#is', $text, $phpsec); |
|
814 |
||
815 |
//die('<pre>'.htmlspecialchars(print_r($phpsec, true))."\n".htmlspecialchars(print_r($text, true)).'</pre>'); |
|
816 |
||
817 |
for($i=0;$i<sizeof($phpsec[1]);$i++) |
|
818 |
{ |
|
819 |
$text = str_replace($phpsec[0][$i], '{PHP:'.$random_id.':'.$i.'}', $text); |
|
820 |
} |
|
821 |
||
822 |
$nw = preg_match_all('#<nowiki>(.*?)<\/nowiki>#is', $text, $nowiki); |
|
823 |
||
824 |
for($i=0;$i<sizeof($nowiki[1]);$i++) |
|
825 |
{ |
|
826 |
$text = str_replace('<nowiki>'.$nowiki[1][$i].'</nowiki>', '{NOWIKI:'.$random_id.':'.$i.'}', $text); |
|
827 |
} |
|
828 |
||
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
|
829 |
$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
|
830 |
$text = str_replace('~~~~', "[[User:$session->username|$session->username]] ".enano_date('G:i, j F Y (T)'), $text); |
1 | 831 |
$text = str_replace('~~~', "[[User:$session->username|$session->username]] ", $text); |
832 |
||
407
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
833 |
$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
|
834 |
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
|
835 |
{ |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
836 |
eval($cmd); |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
837 |
} |
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
391
diff
changeset
|
838 |
|
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
839 |
// gently apply some reverse-processing to allow Text_Wiki to do magic with TOCs and stuff |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
840 |
$text = self::reverse_process_headings($text); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
841 |
|
1 | 842 |
// Reinsert <nowiki> sections |
843 |
for($i=0;$i<$nw;$i++) |
|
844 |
{ |
|
845 |
$text = str_replace('{NOWIKI:'.$random_id.':'.$i.'}', '<nowiki>'.$nowiki[1][$i].'</nowiki>', $text); |
|
846 |
} |
|
847 |
// Reinsert PHP |
|
848 |
for($i=0;$i<$php;$i++) |
|
849 |
{ |
|
850 |
$phsec = ''.$phpsec[1][$i].'?php'.$phpsec[2][$i].'?'.$phpsec[3][$i].''; |
|
851 |
if ( $strip_all_php ) |
|
852 |
$phsec = htmlspecialchars($phsec); |
|
853 |
$text = str_replace('{PHP:'.$random_id.':'.$i.'}', $phsec, $text); |
|
854 |
} |
|
855 |
||
856 |
$text = ( $sqlescape ) ? $db->escape($text) : $text; |
|
857 |
||
858 |
return $text; |
|
859 |
} |
|
860 |
||
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
|
861 |
public static function smilieyize($text, $complete_urls = false) |
1 | 862 |
{ |
863 |
||
864 |
$random_id = md5( time() . mt_rand() ); |
|
865 |
||
866 |
// Smileys array - eventually this will be fetched from the database by |
|
867 |
// RenderMan::initSmileys during initialization, but it will all be hardcoded for beta 2 |
|
868 |
||
869 |
$smileys = Array( |
|
870 |
'O:-)' => 'face-angel.png', |
|
871 |
'O:)' => 'face-angel.png', |
|
872 |
'O=)' => 'face-angel.png', |
|
873 |
':-)' => 'face-smile.png', |
|
874 |
':)' => 'face-smile.png', |
|
875 |
'=)' => 'face-smile-big.png', |
|
876 |
':-(' => 'face-sad.png', |
|
877 |
':(' => 'face-sad.png', |
|
878 |
';(' => 'face-sad.png', |
|
879 |
':-O' => 'face-surprise.png', |
|
880 |
';-)' => 'face-wink.png', |
|
881 |
';)' => 'face-wink.png', |
|
882 |
'8-)' => 'face-glasses.png', |
|
883 |
'8)' => 'face-glasses.png', |
|
884 |
':-D' => 'face-grin.png', |
|
885 |
':D' => 'face-grin.png', |
|
886 |
'=D' => 'face-grin.png', |
|
887 |
':-*' => 'face-kiss.png', |
|
888 |
':*' => 'face-kiss.png', |
|
889 |
'=*' => 'face-kiss.png', |
|
890 |
':\'(' => 'face-crying.png', |
|
891 |
':-|' => 'face-plain.png', |
|
892 |
':-\\' => 'face-plain.png', |
|
893 |
':-/' => 'face-plain.png', |
|
894 |
':joke:' => 'face-plain.png', |
|
895 |
']:->' => '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
|
896 |
']:->' => 'face-devil-grin.png', |
1 | 897 |
':kiss:' => 'face-kiss.png', |
898 |
':-P' => 'face-tongue-out.png', |
|
899 |
':P' => 'face-tongue-out.png', |
|
900 |
':-p' => 'face-tongue-out.png', |
|
901 |
':p' => 'face-tongue-out.png', |
|
902 |
':-X' => 'face-sick.png', |
|
903 |
':X' => 'face-sick.png', |
|
904 |
':sick:' => 'face-sick.png', |
|
905 |
':-]' => 'face-oops.png', |
|
906 |
':]' => 'face-oops.png', |
|
907 |
':oops:' => 'face-oops.png', |
|
908 |
':-[' => 'face-embarassed.png', |
|
909 |
':[' => 'face-embarassed.png' |
|
910 |
); |
|
911 |
||
912 |
// Strip out <nowiki> sections |
|
913 |
//return '<pre>'.htmlspecialchars($text).'</pre>'; |
|
914 |
$nw = preg_match_all('#<nowiki>(.*?)<\/nowiki>#is', $text, $nowiki); |
|
915 |
||
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
916 |
for ( $i = 0; $i < count($nowiki[1]); $i++ ) |
1 | 917 |
{ |
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
918 |
$text = str_replace('<nowiki>' . $nowiki[1][$i] . '</nowiki>', '{NOWIKI:'.$random_id.':'.$i.'}', $text); |
1 | 919 |
} |
920 |
||
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
921 |
foreach ( $smileys as $smiley => $smiley_path ) |
1 | 922 |
{ |
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
923 |
$hex_smiley = hexencode($smiley, '&#x', ';'); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
924 |
$pfx = ( $complete_urls ) ? get_server_url() : ''; |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
925 |
$text = str_replace(' ' . $smiley, |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
926 |
' <!--#smiley code="' . self::escape_parser_hint_attrib($smiley) . '"--><nowiki> |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
927 |
<!-- The above is a reverse-parser hint --> |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
928 |
<img title="' . $hex_smiley . '" alt="' . $hex_smiley . '" src="' . $pfx . scriptPath . '/images/smilies/' . $smiley_path . '" |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
929 |
style="border: 0;" /> |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
930 |
</nowiki><!--#/smiley-->', $text); |
1 | 931 |
} |
932 |
//*/ |
|
933 |
||
934 |
// Reinsert <nowiki> sections |
|
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
935 |
for ( $i = 0; $i < $nw; $i++ ) |
1 | 936 |
{ |
937 |
$text = str_replace('{NOWIKI:'.$random_id.':'.$i.'}', '<nowiki>'.$nowiki[1][$i].'</nowiki>', $text); |
|
938 |
} |
|
939 |
||
940 |
return $text; |
|
941 |
} |
|
942 |
||
943 |
/** |
|
944 |
* Generates a summary of the differences between two texts, and formats it as XHTML. |
|
945 |
* @param $str1 string the first block of text |
|
946 |
* @param $str2 string the second block of text |
|
947 |
* @return string |
|
948 |
*/ |
|
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
|
949 |
public static function diff($str1, $str2) |
1 | 950 |
{ |
951 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
592 | 952 |
require_once(ENANO_ROOT.'/includes/diff.php'); |
1 | 953 |
$str1 = explode("\n", $str1); |
954 |
$str2 = explode("\n", $str2); |
|
955 |
$diff = new Diff($str1, $str2); |
|
956 |
$renderer = new TableDiffFormatter(); |
|
957 |
return '<table class="diff">'.$renderer->format($diff).'</table>'; |
|
958 |
} |
|
959 |
||
35 | 960 |
/** |
961 |
* Changes wikitext image tags to HTML. |
|
962 |
* @param string The wikitext to process |
|
37 | 963 |
* @param array Will be overwritten with the list of HTML tags (the system uses tokens for TextWiki compatibility) |
35 | 964 |
* @return string |
965 |
*/ |
|
966 |
||
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
|
967 |
public static function process_image_tags($text, &$taglist) |
35 | 968 |
{ |
969 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
970 |
||
37 | 971 |
$s_delim = "\xFF"; |
972 |
$f_delim = "\xFF"; |
|
973 |
$taglist = array(); |
|
974 |
||
35 | 975 |
// 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
|
976 |
$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
|
977 |
$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
|
978 |
\[\[ # 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
|
979 |
:' . $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
|
980 |
(?:(?:\|(?:.+?))*) # 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
|
981 |
\]\] # 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
|
982 |
/ix'; |
35 | 983 |
|
984 |
preg_match_all($regex, $text, $matches); |
|
985 |
||
986 |
foreach ( $matches[0] as $i => $match ) |
|
987 |
{ |
|
988 |
||
989 |
$full_tag =& $matches[0][$i]; |
|
990 |
$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
|
991 |
|
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets 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 |
// 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
|
993 |
$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
|
994 |
$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
|
995 |
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
|
996 |
{ |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets 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 |
$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
|
998 |
$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
|
999 |
} |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets 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 |
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
|
1001 |
{ |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets 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 |
// 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
|
1003 |
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
|
1004 |
} |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets 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 |
|
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets 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 |
// 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
|
1007 |
$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
|
1008 |
$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
|
1009 |
$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
|
1010 |
$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
|
1011 |
$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
|
1012 |
$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
|
1013 |
|
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets 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 |
// 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
|
1015 |
$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
|
1016 |
// 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
|
1017 |
$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
|
1018 |
$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
|
1019 |
// 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
|
1020 |
$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
|
1021 |
|
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets 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 |
// 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
|
1023 |
// 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
|
1024 |
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
|
1025 |
{ |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets 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 |
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
|
1027 |
{ |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets 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 |
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
|
1029 |
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
|
1030 |
$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
|
1031 |
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
|
1032 |
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
|
1033 |
$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
|
1034 |
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
|
1035 |
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
|
1036 |
$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
|
1037 |
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
|
1038 |
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
|
1039 |
// 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
|
1040 |
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
|
1041 |
{ |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1042 |
$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
|
1043 |
$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
|
1044 |
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
|
1045 |
} |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1046 |
// not the height, so see if a plugin took this over |
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
1047 |
// this hook requires plugins to return true if they modified anything |
569
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1048 |
$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
|
1049 |
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
|
1050 |
{ |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1051 |
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
|
1052 |
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
|
1053 |
} |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1054 |
// 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
|
1055 |
// 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
|
1056 |
$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
|
1057 |
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
|
1058 |
} |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1059 |
} |
35 | 1060 |
|
1061 |
if ( !isPage( $paths->nslist['File'] . $filename ) ) |
|
1062 |
{ |
|
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
1063 |
$text = str_replace($full_tag, '[[' . $paths->nslist['File'] . $filename . ']]', $text); |
35 | 1064 |
continue; |
1065 |
} |
|
1066 |
||
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
|
1067 |
if ( $scale_type == 'thumb' ) |
35 | 1068 |
{ |
1069 |
$r_width = 225; |
|
1070 |
$r_height = 225; |
|
1071 |
||
1072 |
$url = makeUrlNS('Special', 'DownloadFile/' . $filename, 'preview&width=' . $r_width . '&height=' . $r_height, true); |
|
1073 |
} |
|
1074 |
else if ( !empty($width) && !empty($height) ) |
|
1075 |
{ |
|
1076 |
$r_width = $width; |
|
1077 |
$r_height = $height; |
|
1078 |
||
1079 |
$url = makeUrlNS('Special', 'DownloadFile/' . $filename, 'preview&width=' . $r_width . '&height=' . $r_height, true); |
|
1080 |
} |
|
1081 |
else |
|
1082 |
{ |
|
1083 |
$url = makeUrlNS('Special', 'DownloadFile/' . $filename); |
|
1084 |
} |
|
1085 |
||
1086 |
$img_tag = '<img src="' . $url . '" '; |
|
1087 |
||
65 | 1088 |
// if ( isset($r_width) && isset($r_height) && $scale_type != '|thumb' ) |
1089 |
// { |
|
66
52017732bc20
Added "raw" option to embedded images to make complex clickables easier
Dan
parents:
65
diff
changeset
|
1090 |
// $img_tag .= 'width="' . $r_width . '" height="' . $r_height . '" '; |
65 | 1091 |
// } |
35 | 1092 |
|
66
52017732bc20
Added "raw" option to embedded images to make complex clickables easier
Dan
parents:
65
diff
changeset
|
1093 |
$img_tag .= 'style="border-width: 0px; /* background-color: white; */" '; |
35 | 1094 |
|
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
|
1095 |
$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
|
1096 |
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
|
1097 |
{ |
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
|
1098 |
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
|
1099 |
} |
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
|
1100 |
|
35 | 1101 |
$img_tag .= '/>'; |
1102 |
||
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
1103 |
$s_full_tag = self::escape_parser_hint_attrib($full_tag); |
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
1104 |
$complete_tag = '<!--#imagelink src="' . $s_full_tag . '" -->'; |
35 | 1105 |
|
569
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1106 |
if ( !empty($scale_type) && !$raw_display ) |
35 | 1107 |
{ |
1108 |
$complete_tag .= '<div class="thumbnail" '; |
|
1109 |
$clear_text = ''; |
|
1110 |
if ( !empty($clear) ) |
|
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 |
$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
|
1113 |
$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
|
1114 |
$clear_text .= "float: $side; margin-$opposite: 20px; width: {$r_width}px;"; |
35 | 1115 |
$complete_tag .= 'style="' . $clear_text . '" '; |
1116 |
} |
|
1117 |
$complete_tag .= '>'; |
|
1118 |
||
1119 |
$complete_tag .= '<a href="' . makeUrlNS('File', $filename) . '" style="display: block;">'; |
|
1120 |
$complete_tag .= $img_tag; |
|
1121 |
$complete_tag .= '</a>'; |
|
1122 |
||
1123 |
$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>'; |
|
1124 |
||
1125 |
if ( !empty($caption) ) |
|
1126 |
{ |
|
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
|
1127 |
$complete_tag .= $mag_button . $caption; |
35 | 1128 |
} |
1129 |
||
1130 |
$complete_tag .= '</div>'; |
|
1131 |
} |
|
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
|
1132 |
else if ( $raw_display ) |
66
52017732bc20
Added "raw" option to embedded images to make complex clickables easier
Dan
parents:
65
diff
changeset
|
1133 |
{ |
67 | 1134 |
$complete_tag .= "$img_tag"; |
1135 |
$taglist[$i] = $complete_tag; |
|
1136 |
||
1137 |
$repl = "{$s_delim}e_img_{$i}{$f_delim}"; |
|
1138 |
$text = str_replace($full_tag, $repl, $text); |
|
1139 |
continue; |
|
66
52017732bc20
Added "raw" option to embedded images to make complex clickables easier
Dan
parents:
65
diff
changeset
|
1140 |
} |
35 | 1141 |
else |
1142 |
{ |
|
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
|
1143 |
$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
|
1144 |
$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
|
1145 |
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
|
1146 |
{ |
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
|
1147 |
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
|
1148 |
} |
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
|
1149 |
$complete_tag .= '>'; |
35 | 1150 |
$complete_tag .= $img_tag; |
1151 |
$complete_tag .= '</a>'; |
|
1152 |
} |
|
1153 |
||
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
1154 |
$complete_tag .= "<!--#/imagelink-->"; |
37 | 1155 |
$taglist[$i] = $complete_tag; |
35 | 1156 |
|
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
parents:
801
diff
changeset
|
1157 |
/* |
37 | 1158 |
$pos = strpos($text, $full_tag); |
35 | 1159 |
|
1160 |
while(true) |
|
1161 |
{ |
|
1162 |
$check1 = substr($text, $pos, 3); |
|
1163 |
$check2 = substr($text, $pos, 1); |
|
1164 |
if ( $check1 == '<p>' || $pos == 0 || $check2 == "\n" ) |
|
1165 |
{ |
|
1166 |
// die('found at pos '.$pos); |
|
1167 |
break; |
|
1168 |
} |
|
1169 |
$pos--; |
|
1170 |
} |
|
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
|
1171 |
*/ |
35 | 1172 |
|
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
|
1173 |
/* |
37 | 1174 |
$repl = "{$s_delim}e_img_{$i}{$f_delim}"; |
1175 |
$text = substr($text, 0, $pos) . $repl . substr($text, $pos); |
|
35 | 1176 |
|
1177 |
$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
|
1178 |
*/ |
6ba792bc9071
Updated image tag parser a bit. Handles recursion of brackets properly now, allows custom parameters from plugins, and takes parameters in any order due to new keyword-based parser
Dan
parents:
536
diff
changeset
|
1179 |
$text = str_replace_once($full_tag, $complete_tag, $text); |
35 | 1180 |
|
1181 |
unset($full_tag, $filename, $scale_type, $width, $height, $clear, $caption, $r_width, $r_height); |
|
1182 |
||
1183 |
} |
|
1184 |
||
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
|
1185 |
// 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
|
1186 |
// 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
|
1187 |
|
35 | 1188 |
return $text; |
1189 |
} |
|
1190 |
||
37 | 1191 |
/** |
1192 |
* Finalizes processing of image tags. |
|
1193 |
* @param string The preprocessed text |
|
1194 |
* @param array The list of image tags created by RenderMan::process_image_tags() |
|
1195 |
*/ |
|
1196 |
||
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
|
1197 |
public static function process_imgtags_stage2($text, $taglist) |
37 | 1198 |
{ |
1199 |
$s_delim = "\xFF"; |
|
1200 |
$f_delim = "\xFF"; |
|
1201 |
foreach ( $taglist as $i => $tag ) |
|
1202 |
{ |
|
1203 |
$repl = "{$s_delim}e_img_{$i}{$f_delim}"; |
|
1204 |
$text = str_replace($repl, $tag, $text); |
|
1205 |
} |
|
1206 |
return $text; |
|
1207 |
} |
|
1208 |
||
1 | 1209 |
} |
1210 |
||
1211 |
?> |