Commit | Line | Data |
---|---|---|
0337d704 | 1 | <?php |
2 | /*************************************************************************** | |
2ab75571 | 3 | * Copyright (C) 2003-2010 Polytechnique.org * |
0337d704 | 4 | * http://opensource.polytechnique.org/ * |
5 | * * | |
6 | * This program is free software; you can redistribute it and/or modify * | |
7 | * it under the terms of the GNU General Public License as published by * | |
8 | * the Free Software Foundation; either version 2 of the License, or * | |
9 | * (at your option) any later version. * | |
10 | * * | |
11 | * This program is distributed in the hope that it will be useful, * | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
14 | * GNU General Public License for more details. * | |
15 | * * | |
16 | * You should have received a copy of the GNU General Public License * | |
17 | * along with this program; if not, write to the Free Software * | |
18 | * Foundation, Inc., * | |
19 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * | |
20 | ***************************************************************************/ | |
21 | ||
5640f093 FB |
22 | if (!@include_once 'smarty/libs/Smarty.class.php') { |
23 | require_once 'smarty/Smarty.class.php'; | |
24 | } | |
0337d704 | 25 | |
04334c61 | 26 | abstract class PlPage extends Smarty |
0337d704 | 27 | { |
2b1ee50b | 28 | private $_page_type; |
29 | private $_tpl; | |
30 | private $_errors; | |
31 | private $_failure; | |
4a8a1e0a | 32 | private $_jsonVars; |
0337d704 | 33 | |
04334c61 | 34 | // {{{ function PlPage() |
0337d704 | 35 | |
abde67b1 | 36 | public function __construct() |
0337d704 | 37 | { |
2b1ee50b | 38 | parent::Smarty(); |
0337d704 | 39 | |
2b1ee50b | 40 | global $globals; |
796aea34 | 41 | |
abe7e055 | 42 | $this->caching = false; |
43 | $this->config_overwrite = false; | |
44 | $this->use_sub_dirs = false; | |
a33955e4 FB |
45 | $this->template_dir = $globals->spoolroot . '/templates/'; |
46 | $this->compile_dir = $globals->spoolroot . '/spool/templates_c/'; | |
47 | array_unshift($this->plugins_dir, | |
48 | $globals->spoolroot . '/core/plugins/', | |
49 | $globals->spoolroot . '/plugins/'); | |
50 | $this->config_dir = $globals->spoolroot . '/configs/'; | |
0337d704 | 51 | |
b5e56a71 | 52 | $this->compile_check = !empty($globals->debug) || $globals->smarty_autocompile; |
0337d704 | 53 | |
71a753d3 | 54 | $this->_errors = array('errors' => array()); |
4a8a1e0a | 55 | $this->_jsonVars = array(); |
860fdaec | 56 | $this->_failure = false; |
0337d704 | 57 | |
fe556813 | 58 | if ($globals->mode != 'rw') { |
d27380cd AA |
59 | $this->trigError("En raison d'une maintenance, une partie des fonctionnalités du site est" |
60 | . " actuellement désactivée, en particulier aucune donnée ne sera sauvegardée"); | |
fe556813 | 61 | } |
0337d704 | 62 | $this->register_prefilter('at_to_globals'); |
0337d704 | 63 | } |
64 | ||
65 | // }}} | |
66 | // {{{ function changeTpl() | |
67 | ||
2b1ee50b | 68 | public function changeTpl($tpl, $type = SKINNED) |
0337d704 | 69 | { |
91ebb7ff FB |
70 | $this->_tpl = $tpl; |
71 | $this->_page_type = $type; | |
72 | $this->assign('pl_tpl', $tpl); | |
0337d704 | 73 | } |
74 | ||
75 | // }}} | |
7cb40d85 FB |
76 | // {{{ function getCoreTpl() |
77 | ||
78 | public static function getCoreTpl($tpl) | |
79 | { | |
80 | global $globals; | |
81 | return $globals->spoolroot . '/core/templates/' . $tpl; | |
82 | } | |
83 | ||
84 | // }}} | |
85 | // {{{ function coreTpl() | |
86 | ||
87 | /** Use a template from the core. | |
88 | */ | |
89 | public function coreTpl($tpl, $type = SKINNED) | |
90 | { | |
91 | global $globals; | |
92 | $this->changeTpl(self::getCoreTpl($tpl), $type); | |
93 | } | |
94 | ||
95 | // }}} | |
e654517d | 96 | // {{{ function raw() |
97 | ||
98 | public function raw() | |
99 | { | |
100 | global $globals; | |
101 | $this->assign('globals', $globals); | |
102 | return $this->fetch($this->_tpl); | |
103 | } | |
104 | ||
105 | // }}} | |
0337d704 | 106 | // {{{ function _run() |
107 | ||
2b1ee50b | 108 | protected function _run($skin) |
0337d704 | 109 | { |
80d0423e | 110 | global $globals, $platal, $TIME_BEGIN; |
36f114ef | 111 | |
732e5855 | 112 | Platal::session()->close(); |
36f114ef | 113 | |
e654517d | 114 | $this->register_prefilter('trimwhitespace'); |
115 | $this->register_prefilter('form_force_encodings'); | |
7a3f546b | 116 | $this->register_prefilter('wiki_include'); |
7cb40d85 | 117 | $this->register_prefilter('core_include'); |
b6ec30c5 | 118 | $this->register_prefilter('if_rewrites'); |
91ebb7ff FB |
119 | $this->assign('pl_triggers', $this->_errors); |
120 | $this->assign('pl_errors', $this->nb_errs()); | |
121 | $this->assign('pl_failure', $this->_failure); | |
80d0423e | 122 | $this->assign_by_ref('platal', $platal); |
08d7cc45 | 123 | $this->assign_by_ref('globals', $globals); |
a3a049fc | 124 | |
4a8a1e0a | 125 | if (Env::has('json') && count($this->_jsonVars)) { |
126 | return $this->jsonDisplay(); | |
127 | } | |
eaf30d86 | 128 | |
7299bfce FB |
129 | $display = Env::s('display'); |
130 | if ($display == 'light' && $this->_page_type == SKINNED) { | |
8a105df2 | 131 | $this->_page_type = SIMPLE; |
7299bfce | 132 | } elseif ($display == 'raw') { |
8a105df2 | 133 | $this->_page_type = NO_SKIN; |
7299bfce | 134 | } elseif ($display == 'full') { |
8a105df2 | 135 | $this->_page_typ = SKINNED; |
136 | } | |
137 | ||
d58e3be0 SJ |
138 | if ($this->_page_type == SIMPLE) { |
139 | $this->assign('simple', true); | |
140 | } else { | |
141 | $this->assign('simple', false); | |
142 | } | |
143 | ||
62a66dfc | 144 | switch ($this->_page_type) { |
145 | case NO_SKIN: | |
81e9c63f | 146 | if (!($globals->debug & DEBUG_SMARTY)) { |
147 | error_reporting(0); | |
148 | } | |
0337d704 | 149 | $this->display($this->_tpl); |
150 | exit; | |
62a66dfc | 151 | |
152 | case SIMPLE: | |
62a66dfc | 153 | case SKINNED: |
b4ee37a4 FB |
154 | $this->register_modifier('escape_html', 'escape_html'); |
155 | $this->default_modifiers = Array('@escape_html'); | |
0337d704 | 156 | } |
5aa58639 FB |
157 | if (S::i('auth') <= AUTH_PUBLIC) { |
158 | $this->register_outputfilter('hide_emails'); | |
159 | } | |
493b6abe | 160 | header("Accept-Charset: utf-8"); |
4a8a1e0a | 161 | if (Env::v('forceXml')) { |
a286fc7a | 162 | pl_content_headers("text/xml"); |
4a8a1e0a | 163 | } |
b4315e15 | 164 | |
165 | if (!$globals->debug) { | |
6995a9b9 | 166 | error_reporting(0); |
b4315e15 | 167 | $this->display($skin); |
168 | exit; | |
169 | } | |
a3a049fc | 170 | |
7da8ef90 | 171 | $this->assign('validate', true); |
81e9c63f | 172 | if (!($globals->debug & DEBUG_SMARTY)) { |
173 | error_reporting(0); | |
174 | } | |
040a594c | 175 | $START_SMARTY = microtime(true); |
b4315e15 | 176 | $result = $this->fetch($skin); |
040a594c FB |
177 | $ttime = sprintf('Temps total: %.02fs (Smarty %.02fs) - Mémoire totale : %dKo<br />', |
178 | microtime(true) - $TIME_BEGIN, microtime(true) - $START_SMARTY, | |
179 | memory_get_peak_usage(true) / 1024); | |
b4ee37a4 FB |
180 | if ($globals->debug & DEBUG_BT) { |
181 | PlBacktrace::clean(); | |
182 | $this->assign_by_ref('backtraces', PlBacktrace::$bt); | |
7cb40d85 FB |
183 | $result = str_replace('@@BACKTRACE@@', |
184 | $this->fetch(self::getCoreTpl('backtrace.tpl')), | |
185 | $result); | |
b4ee37a4 FB |
186 | } else { |
187 | $result = str_replace('@@BACKTRACE@@', '', $result); | |
188 | } | |
0337d704 | 189 | |
b4ee37a4 | 190 | $replc = "<span class='erreur'>VALIDATION HTML INACTIVE</span><br />"; |
81e9c63f | 191 | if ($globals->debug & DEBUG_VALID) { |
b4315e15 | 192 | $fd = fopen($this->compile_dir."/valid.html","w"); |
193 | fwrite($fd, $result); | |
194 | fclose($fd); | |
a3a049fc | 195 | |
b4315e15 | 196 | exec($globals->spoolroot."/bin/devel/xhtml.validate.pl ".$this->compile_dir."/valid.html", $val); |
197 | foreach ($val as $h) { | |
198 | if (preg_match("/^X-W3C-Validator-Errors: (\d+)$/", $h, $m)) { | |
199 | $replc = '<span style="color: #080;">HTML OK</span><br />'; | |
200 | if ($m[1]) { | |
201 | $replc = "<span class='erreur'><a href='http://validator.w3.org/check?uri={$globals->baseurl}" | |
202 | ."/valid.html&ss=1#result'>{$m[1]} ERREUR(S) !!!</a></span><br />"; | |
0337d704 | 203 | } |
b4315e15 | 204 | break; |
0337d704 | 205 | } |
206 | } | |
0337d704 | 207 | } |
208 | ||
b4315e15 | 209 | echo str_replace("@HOOK@", $ttime.$replc, $result); |
0337d704 | 210 | exit; |
211 | } | |
212 | ||
1490093c | 213 | abstract public function run(); |
214 | ||
0337d704 | 215 | // }}} |
0337d704 | 216 | // {{{ function nb_errs() |
217 | ||
2b1ee50b | 218 | public function nb_errs() |
0337d704 | 219 | { |
71a753d3 | 220 | return count($this->_errors['errors']); |
0337d704 | 221 | } |
222 | ||
223 | // }}} | |
224 | // {{{ function trig() | |
225 | ||
a7d35093 | 226 | private function trig($msg, $type = 'errors') |
0337d704 | 227 | { |
71a753d3 FB |
228 | if (!isset($this->_errors[$type])) { |
229 | $this->_errors[$type] = array(); | |
230 | } | |
231 | $this->_errors[$type][] = $msg; | |
232 | } | |
233 | ||
234 | public function trigError($msg) | |
235 | { | |
236 | $this->trig($msg, 'errors'); | |
237 | } | |
238 | ||
e00bc67e FB |
239 | public function trigWarning($msg) |
240 | { | |
241 | $this->trig($msg, 'warnings'); | |
242 | } | |
243 | ||
71a753d3 FB |
244 | public function trigSuccess($msg) |
245 | { | |
246 | $this->trig($msg, 'success'); | |
0337d704 | 247 | } |
248 | ||
249 | // }}} | |
8adfe956 RB |
250 | // {{{ function trigRedirect |
251 | ||
252 | // Acts as trig(), but replaces the template with a simple one displaying | |
253 | // the error messages and a "continue" link. | |
254 | private function trigRedirect($msg, $continue, $type = 'errors') | |
255 | { | |
256 | $this->trig($msg, $type); | |
257 | $this->coreTpl('msgredirect.tpl'); | |
258 | $this->assign('continue', $continue); | |
259 | $this->run(); | |
260 | } | |
261 | ||
262 | public function trigErrorRedirect($msg, $continue) | |
263 | { | |
264 | $this->trigRedirect($msg, $continue, 'errors'); | |
265 | } | |
266 | ||
267 | public function trigWarningRedirect($msg, $continue) | |
268 | { | |
269 | $this->trigRedirect($msg, $continue, 'warnings'); | |
270 | } | |
271 | ||
272 | public function trigSuccessRedirect($msg, $continue) | |
273 | { | |
274 | $this->trigRedirect($msg, $continue, 'success'); | |
275 | } | |
276 | ||
277 | // }}} | |
0337d704 | 278 | // {{{ function kill() |
279 | ||
ca476935 | 280 | public function kill($msg, $type = 'errors') |
0337d704 | 281 | { |
36f472dc FB |
282 | // PHP is used on command line... do not run the whole page stuff. |
283 | if (php_sapi_name() == 'cli') { | |
284 | echo $msg . "\n"; | |
fc2cfa65 | 285 | exit(-1); |
36f472dc FB |
286 | } |
287 | ||
90eba1aa | 288 | global $platal; |
289 | ||
ca476935 | 290 | $this->trig($msg, $type); |
0fcbe8d0 | 291 | $this->_failure = true; |
0337d704 | 292 | $this->run(); |
293 | } | |
294 | ||
ca476935 SJ |
295 | public function killError($msg) |
296 | { | |
297 | $this->kill($msg, 'errors'); | |
298 | } | |
299 | ||
300 | public function killWarning($msg) | |
301 | { | |
302 | $this->kill($msg, 'warnings'); | |
303 | } | |
304 | ||
305 | public function killSuccess($msg) | |
306 | { | |
307 | $this->kill($msg, 'success'); | |
308 | } | |
309 | ||
0337d704 | 310 | // }}} |
9902e47b FB |
311 | // {{{ function setTitle |
312 | ||
313 | public function setTitle($title) | |
314 | { | |
380e2a5a FB |
315 | global $globals; |
316 | if (isset($globals->core->sitename)) { | |
317 | $title = $globals->core->sitename . ' :: ' . $title; | |
318 | } | |
9902e47b FB |
319 | $this->assign('pl_title', $title); |
320 | } | |
321 | ||
322 | // }}} | |
0337d704 | 323 | // {{{ function addJsLink |
324 | ||
47a44ed0 | 325 | public function addJsLink($filename, $static_content = true) |
0337d704 | 326 | { |
47a44ed0 VZ |
327 | if ($static_content) { |
328 | $this->append('pl_js', pl_static_content_path("javascript/", $filename)); | |
329 | } else { | |
330 | $this->append('pl_js', "javascript/$filename"); | |
331 | } | |
0337d704 | 332 | } |
333 | ||
334 | // }}} | |
335 | // {{{ function addCssLink | |
336 | ||
2b1ee50b | 337 | public function addCssLink($path) |
0337d704 | 338 | { |
91ebb7ff | 339 | $this->append('pl_css', $path); |
0337d704 | 340 | } |
341 | ||
342 | // }}} | |
1e9a1d99 AA |
343 | // {{{ function addLink |
344 | ||
345 | public function addLink($rel, $path) | |
346 | { | |
347 | $this->append('pl_link', array('rel' => $rel, 'href' => $path)); | |
348 | } | |
349 | ||
350 | ||
351 | // }}} | |
ea626742 | 352 | // {{{ function addCssInline |
353 | ||
2b1ee50b | 354 | public function addCssInline($css) |
ea626742 | 355 | { |
356 | if (!empty($css)) { | |
91ebb7ff | 357 | $this->append('pl_inline_css', $css); |
eaf30d86 | 358 | } |
ea626742 | 359 | } |
360 | ||
361 | // }}} | |
162370e7 | 362 | // {{{ function setRssLink |
363 | ||
2b1ee50b | 364 | public function setRssLink($title, $path) |
162370e7 | 365 | { |
91ebb7ff | 366 | $this->assign('pl_rss', array('title' => $title, 'href' => $path)); |
162370e7 | 367 | } |
368 | ||
369 | // }}} | |
4a8a1e0a | 370 | // {{{ function jsonDisplay |
371 | protected function jsonDisplay() | |
372 | { | |
a286fc7a | 373 | pl_content_headers("text/javascript"); |
641802fe R |
374 | if (!empty($GLOBALS['pl_errors'])) { |
375 | $this->jsonAssign('pl_errors', join("\n", $GLOBALS['pl_errors'])); | |
376 | $GLOBALS['pl_errors'] = array(); | |
377 | } | |
b00a702a | 378 | array_walk_recursive($this->_jsonVars, "escape_XDB"); |
4a8a1e0a | 379 | $jsonbegin = Env::v('jsonBegin'); |
380 | $jsonend = Env::v('jsonEnd'); | |
381 | if (Env::has('jsonVar')) { | |
382 | $jsonbegin = Env::v('jsonVar').' = '; | |
383 | $jsonend = ';'; | |
384 | } elseif (Env::has('jsonFunc')) { | |
385 | $jsonbegin = Env::v('jsonFunc').'('; | |
386 | $jsonend = ');'; | |
387 | } | |
388 | echo $jsonbegin, json_encode($this->_jsonVars), $jsonend; | |
389 | exit; | |
390 | } | |
391 | // }}} | |
392 | // {{{ function jsonAssign | |
393 | public function jsonAssign($var, $value) | |
394 | { | |
395 | $this->_jsonVars[$var] = $value; | |
396 | } | |
fba760d2 | 397 | |
398 | // }}} | |
4a8a1e0a | 399 | } |
400 | ||
b00a702a | 401 | function escape_XDB(&$item, $key) |
4a8a1e0a | 402 | { |
b00a702a | 403 | if ($item instanceof XDBIterator) { |
4a8a1e0a | 404 | $expanded = array(); |
405 | while ($a = $item->next()) { | |
406 | $expanded[] = $a; | |
407 | } | |
408 | $item = $expanded; | |
409 | } | |
0337d704 | 410 | } |
411 | ||
b76f0797 | 412 | // {{{ function escape_html () |
413 | ||
414 | /** | |
415 | * default smarty plugin, used to auto-escape dangerous html. | |
eaf30d86 | 416 | * |
b76f0797 | 417 | * < --> < |
418 | * > --> > | |
419 | * " --> " | |
420 | * & not followed by some entity --> & | |
421 | */ | |
422 | function escape_html($string) | |
423 | { | |
424 | if (is_string($string)) { | |
c1895524 | 425 | return htmlspecialchars($string, ENT_QUOTES, 'UTF-8'); |
b76f0797 | 426 | } else { |
c1895524 | 427 | return $string; |
b76f0797 | 428 | } |
429 | } | |
430 | ||
431 | // }}} | |
432 | // {{{ function at_to_globals() | |
433 | ||
434 | /** | |
435 | * helper | |
436 | */ | |
437 | ||
438 | function _to_globals($s) { | |
439 | global $globals; | |
440 | $t = explode('.',$s); | |
441 | if (count($t) == 1) { | |
442 | return var_export($globals->$t[0],true); | |
443 | } else { | |
444 | return var_export($globals->$t[0]->$t[1],true); | |
445 | } | |
446 | } | |
447 | ||
448 | /** | |
449 | * compilation plugin used to import $globals confing through #globals.foo.bar# directives | |
450 | */ | |
451 | ||
452 | function at_to_globals($tpl_source, &$smarty) | |
453 | { | |
454 | return preg_replace('/#globals\.([a-zA-Z0-9_.]+?)#/e', '_to_globals(\'\\1\')', $tpl_source); | |
7cb40d85 | 455 | } |
b76f0797 | 456 | |
7cb40d85 FB |
457 | // }}} |
458 | // {{{ function trimwhitespace | |
b76f0797 | 459 | |
7cb40d85 FB |
460 | function trimwhitespace($source, &$smarty) |
461 | { | |
462 | $tags = '(script|pre|textarea)'; | |
463 | preg_match_all("!<$tags.*?>.*?</(\\1)>!ius", $source, $tagsmatches); | |
464 | $source = preg_replace("!<$tags.*?>.*?</(\\1)>!ius", "&&&tags&&&", $source); | |
b76f0797 | 465 | |
7cb40d85 FB |
466 | // remove all leading spaces, tabs and carriage returns NOT |
467 | // preceeded by a php close tag. | |
468 | $source = preg_replace('/((?<!\?>)\n)[\s]+/m', '\1', $source); | |
469 | $source = preg_replace("!&&&tags&&&!e", 'array_shift($tagsmatches[0])', $source); | |
b76f0797 | 470 | |
7cb40d85 FB |
471 | return $source; |
472 | } | |
b76f0797 | 473 | |
7cb40d85 FB |
474 | // }}} |
475 | // {{{ function wiki_include | |
7a3f546b | 476 | |
477 | function wiki_include($source, &$smarty) | |
478 | { | |
7cb40d85 | 479 | global $globals; |
7a3f546b | 480 | return preg_replace('/\{include( [^}]*)? wiki=([^} ]+)(.*?)\}/ui', |
7cb40d85 FB |
481 | '{include\1 file="' . $globals->spoolroot . '/spool/wiki.d/cache_\2.tpl"\3 included=1}', |
482 | $source); | |
483 | } | |
484 | ||
485 | function core_include($source, &$smarty) | |
486 | { | |
487 | global $globals; | |
488 | return preg_replace('/\{include( [^}]*)? core=([^} ]+)(.*?)\}/ui', | |
489 | '{include\1 file="' . $globals->spoolroot . '/core/templates/\2"\3}', | |
7a3f546b | 490 | $source); |
491 | } | |
492 | ||
493 | // }}} | |
908db125 FB |
494 | //{{{ function hasPerm |
495 | ||
b6ec30c5 | 496 | function if_rewrites($source, &$smarty) |
908db125 | 497 | { |
a2efe30f FB |
498 | $perms = 'isset($smarty.session.user|smarty:nodefaults) && $smarty.session.user'; |
499 | return preg_replace(array('/\{(else)?if([^}]*) (\!?)hasPerms?\(([^)]+)\)([^}]*)\}/', | |
500 | '/\{(else)?if([^}]*) (\!?)t\(([^)]+)\)([^}]*)\}/'), | |
501 | array('{\1if\2 \3(' . $perms . '->checkPerms(\4))\5}', | |
502 | '{\1if\2 \3(isset(\4|smarty:nodefaults) && (\4|smarty:nodefaults))\5}'), | |
7cb40d85 | 503 | $source); |
908db125 FB |
504 | } |
505 | ||
506 | // }}} | |
edc636b8 | 507 | // {{{ |
508 | ||
509 | function form_force_encodings($source, &$smarty) | |
510 | { | |
511 | return preg_replace('/<form[^\w]/', | |
a7de4ef7 | 512 | '\0 accept-charset="utf-8" ', |
edc636b8 | 513 | $source); |
514 | } | |
515 | ||
516 | // }}} | |
bf2e1ab0 | 517 | // {{{ function hide_emails |
518 | ||
519 | function _hide_email($source) | |
520 | { | |
1bd2bc7e | 521 | $source = str_replace("\n", '', $source); |
6b8d257b | 522 | return '<script type="text/javascript">//<![CDATA[' . "\n" . |
91ebb7ff FB |
523 | 'Nix.decode("' . addslashes(str_rot13($source)) . '");' . "\n" . |
524 | '//]]></script>'; | |
bf2e1ab0 | 525 | } |
526 | ||
527 | function hide_emails($source, &$smarty) | |
528 | { | |
a18afbdc | 529 | if (!strpos($source, '@')) { |
530 | return $source; | |
531 | } | |
532 | ||
bf2e1ab0 | 533 | //prevent email replacement in <script> and <textarea> |
120bd636 | 534 | $tags = '(script|textarea|select)'; |
abe7e055 | 535 | preg_match_all("!<$tags.*?>.*?</(\\1)>!ius", $source, $tagsmatches); |
536 | $source = preg_replace("!<$tags.*?>.*?</(\\1)>!ius", "&&&tags&&&", $source); | |
bf2e1ab0 | 537 | |
538 | //catch all emails in <a href="mailto:..."> | |
a14159bf | 539 | preg_match_all("!<a[^>]+href=[\"'][^\"']*[-a-z0-9+_.]+@[-a-z0-9_.]+[^\"']*[\"'].*?>.*?</a>!ius", $source, $ahref); |
540 | $source = preg_replace("!<a[^>]+href=[\"'][^\"']*[-a-z0-9+_.]+@[-a-z0-9_.]+[^\"']*[\"'].*?>.*?</a>!ius", '&&&ahref&&&', $source); | |
bf2e1ab0 | 541 | |
542 | //prevant replacement in tag attributes | |
abe7e055 | 543 | preg_match_all("!<[^>]+[-a-z0-9_+.]+@[-a-z0-9_.]+.+?>!ius", $source, $misc); |
544 | $source = preg_replace("!<[^>]+[-a-z0-9_+.]+@[-a-z0-9_.]+.+?>!ius", '&&&misc&&&', $source); | |
bf2e1ab0 | 545 | |
546 | //catch ! | |
eaf30d86 | 547 | $source = preg_replace('!([-a-z0-9_+.]+@[-a-z0-9_.]+)!iue', '_hide_email("\1")', $source); |
bf2e1ab0 | 548 | $source = preg_replace('!&&&ahref&&&!e', '_hide_email(array_shift($ahref[0]))', $source); |
bf2e1ab0 | 549 | |
550 | // restore data | |
2456ea61 | 551 | $source = preg_replace('!&&&misc&&&!e', 'array_shift($misc[0])', $source); |
120bd636 | 552 | $source = preg_replace("!&&&tags&&&!e", 'array_shift($tagsmatches[0])', $source); |
bf2e1ab0 | 553 | |
554 | return $source; | |
555 | } | |
556 | ||
557 | // }}} | |
b76f0797 | 558 | |
a7de4ef7 | 559 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
0337d704 | 560 | ?> |