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 | |
8a105df2 | 129 | if (Env::v('display') == 'light') { |
130 | $this->_page_type = SIMPLE; | |
131 | } elseif (Env::v('display') == 'raw') { | |
132 | $this->_page_type = NO_SKIN; | |
133 | } elseif (Env::v('display') == 'full') { | |
134 | $this->_page_typ = SKINNED; | |
135 | } | |
136 | ||
d58e3be0 SJ |
137 | if ($this->_page_type == SIMPLE) { |
138 | $this->assign('simple', true); | |
139 | } else { | |
140 | $this->assign('simple', false); | |
141 | } | |
142 | ||
62a66dfc | 143 | switch ($this->_page_type) { |
144 | case NO_SKIN: | |
81e9c63f | 145 | if (!($globals->debug & DEBUG_SMARTY)) { |
146 | error_reporting(0); | |
147 | } | |
0337d704 | 148 | $this->display($this->_tpl); |
149 | exit; | |
62a66dfc | 150 | |
151 | case SIMPLE: | |
62a66dfc | 152 | case SKINNED: |
b4ee37a4 FB |
153 | $this->register_modifier('escape_html', 'escape_html'); |
154 | $this->default_modifiers = Array('@escape_html'); | |
0337d704 | 155 | } |
5aa58639 FB |
156 | if (S::i('auth') <= AUTH_PUBLIC) { |
157 | $this->register_outputfilter('hide_emails'); | |
158 | } | |
493b6abe | 159 | header("Accept-Charset: utf-8"); |
4a8a1e0a | 160 | if (Env::v('forceXml')) { |
a286fc7a | 161 | pl_content_headers("text/xml"); |
4a8a1e0a | 162 | } |
b4315e15 | 163 | |
164 | if (!$globals->debug) { | |
6995a9b9 | 165 | error_reporting(0); |
b4315e15 | 166 | $this->display($skin); |
167 | exit; | |
168 | } | |
a3a049fc | 169 | |
7da8ef90 | 170 | $this->assign('validate', true); |
81e9c63f | 171 | if (!($globals->debug & DEBUG_SMARTY)) { |
172 | error_reporting(0); | |
173 | } | |
040a594c | 174 | $START_SMARTY = microtime(true); |
b4315e15 | 175 | $result = $this->fetch($skin); |
040a594c FB |
176 | $ttime = sprintf('Temps total: %.02fs (Smarty %.02fs) - Mémoire totale : %dKo<br />', |
177 | microtime(true) - $TIME_BEGIN, microtime(true) - $START_SMARTY, | |
178 | memory_get_peak_usage(true) / 1024); | |
b4ee37a4 FB |
179 | if ($globals->debug & DEBUG_BT) { |
180 | PlBacktrace::clean(); | |
181 | $this->assign_by_ref('backtraces', PlBacktrace::$bt); | |
7cb40d85 FB |
182 | $result = str_replace('@@BACKTRACE@@', |
183 | $this->fetch(self::getCoreTpl('backtrace.tpl')), | |
184 | $result); | |
b4ee37a4 FB |
185 | } else { |
186 | $result = str_replace('@@BACKTRACE@@', '', $result); | |
187 | } | |
0337d704 | 188 | |
b4ee37a4 | 189 | $replc = "<span class='erreur'>VALIDATION HTML INACTIVE</span><br />"; |
81e9c63f | 190 | if ($globals->debug & DEBUG_VALID) { |
b4315e15 | 191 | $fd = fopen($this->compile_dir."/valid.html","w"); |
192 | fwrite($fd, $result); | |
193 | fclose($fd); | |
a3a049fc | 194 | |
b4315e15 | 195 | exec($globals->spoolroot."/bin/devel/xhtml.validate.pl ".$this->compile_dir."/valid.html", $val); |
196 | foreach ($val as $h) { | |
197 | if (preg_match("/^X-W3C-Validator-Errors: (\d+)$/", $h, $m)) { | |
198 | $replc = '<span style="color: #080;">HTML OK</span><br />'; | |
199 | if ($m[1]) { | |
200 | $replc = "<span class='erreur'><a href='http://validator.w3.org/check?uri={$globals->baseurl}" | |
201 | ."/valid.html&ss=1#result'>{$m[1]} ERREUR(S) !!!</a></span><br />"; | |
0337d704 | 202 | } |
b4315e15 | 203 | break; |
0337d704 | 204 | } |
205 | } | |
0337d704 | 206 | } |
207 | ||
b4315e15 | 208 | echo str_replace("@HOOK@", $ttime.$replc, $result); |
0337d704 | 209 | exit; |
210 | } | |
211 | ||
1490093c | 212 | abstract public function run(); |
213 | ||
0337d704 | 214 | // }}} |
0337d704 | 215 | // {{{ function nb_errs() |
216 | ||
2b1ee50b | 217 | public function nb_errs() |
0337d704 | 218 | { |
71a753d3 | 219 | return count($this->_errors['errors']); |
0337d704 | 220 | } |
221 | ||
222 | // }}} | |
223 | // {{{ function trig() | |
224 | ||
a7d35093 | 225 | private function trig($msg, $type = 'errors') |
0337d704 | 226 | { |
71a753d3 FB |
227 | if (!isset($this->_errors[$type])) { |
228 | $this->_errors[$type] = array(); | |
229 | } | |
230 | $this->_errors[$type][] = $msg; | |
231 | } | |
232 | ||
233 | public function trigError($msg) | |
234 | { | |
235 | $this->trig($msg, 'errors'); | |
236 | } | |
237 | ||
e00bc67e FB |
238 | public function trigWarning($msg) |
239 | { | |
240 | $this->trig($msg, 'warnings'); | |
241 | } | |
242 | ||
71a753d3 FB |
243 | public function trigSuccess($msg) |
244 | { | |
245 | $this->trig($msg, 'success'); | |
0337d704 | 246 | } |
247 | ||
248 | // }}} | |
8adfe956 RB |
249 | // {{{ function trigRedirect |
250 | ||
251 | // Acts as trig(), but replaces the template with a simple one displaying | |
252 | // the error messages and a "continue" link. | |
253 | private function trigRedirect($msg, $continue, $type = 'errors') | |
254 | { | |
255 | $this->trig($msg, $type); | |
256 | $this->coreTpl('msgredirect.tpl'); | |
257 | $this->assign('continue', $continue); | |
258 | $this->run(); | |
259 | } | |
260 | ||
261 | public function trigErrorRedirect($msg, $continue) | |
262 | { | |
263 | $this->trigRedirect($msg, $continue, 'errors'); | |
264 | } | |
265 | ||
266 | public function trigWarningRedirect($msg, $continue) | |
267 | { | |
268 | $this->trigRedirect($msg, $continue, 'warnings'); | |
269 | } | |
270 | ||
271 | public function trigSuccessRedirect($msg, $continue) | |
272 | { | |
273 | $this->trigRedirect($msg, $continue, 'success'); | |
274 | } | |
275 | ||
276 | // }}} | |
0337d704 | 277 | // {{{ function kill() |
278 | ||
ca476935 | 279 | public function kill($msg, $type = 'errors') |
0337d704 | 280 | { |
36f472dc FB |
281 | // PHP is used on command line... do not run the whole page stuff. |
282 | if (php_sapi_name() == 'cli') { | |
283 | echo $msg . "\n"; | |
fc2cfa65 | 284 | exit(-1); |
36f472dc FB |
285 | } |
286 | ||
90eba1aa | 287 | global $platal; |
288 | ||
ca476935 | 289 | $this->trig($msg, $type); |
0fcbe8d0 | 290 | $this->_failure = true; |
0337d704 | 291 | $this->run(); |
292 | } | |
293 | ||
ca476935 SJ |
294 | public function killError($msg) |
295 | { | |
296 | $this->kill($msg, 'errors'); | |
297 | } | |
298 | ||
299 | public function killWarning($msg) | |
300 | { | |
301 | $this->kill($msg, 'warnings'); | |
302 | } | |
303 | ||
304 | public function killSuccess($msg) | |
305 | { | |
306 | $this->kill($msg, 'success'); | |
307 | } | |
308 | ||
0337d704 | 309 | // }}} |
9902e47b FB |
310 | // {{{ function setTitle |
311 | ||
312 | public function setTitle($title) | |
313 | { | |
380e2a5a FB |
314 | global $globals; |
315 | if (isset($globals->core->sitename)) { | |
316 | $title = $globals->core->sitename . ' :: ' . $title; | |
317 | } | |
9902e47b FB |
318 | $this->assign('pl_title', $title); |
319 | } | |
320 | ||
321 | // }}} | |
0337d704 | 322 | // {{{ function addJsLink |
323 | ||
47a44ed0 | 324 | public function addJsLink($filename, $static_content = true) |
0337d704 | 325 | { |
47a44ed0 VZ |
326 | if ($static_content) { |
327 | $this->append('pl_js', pl_static_content_path("javascript/", $filename)); | |
328 | } else { | |
329 | $this->append('pl_js', "javascript/$filename"); | |
330 | } | |
0337d704 | 331 | } |
332 | ||
333 | // }}} | |
334 | // {{{ function addCssLink | |
335 | ||
2b1ee50b | 336 | public function addCssLink($path) |
0337d704 | 337 | { |
91ebb7ff | 338 | $this->append('pl_css', $path); |
0337d704 | 339 | } |
340 | ||
341 | // }}} | |
1e9a1d99 AA |
342 | // {{{ function addLink |
343 | ||
344 | public function addLink($rel, $path) | |
345 | { | |
346 | $this->append('pl_link', array('rel' => $rel, 'href' => $path)); | |
347 | } | |
348 | ||
349 | ||
350 | // }}} | |
ea626742 | 351 | // {{{ function addCssInline |
352 | ||
2b1ee50b | 353 | public function addCssInline($css) |
ea626742 | 354 | { |
355 | if (!empty($css)) { | |
91ebb7ff | 356 | $this->append('pl_inline_css', $css); |
eaf30d86 | 357 | } |
ea626742 | 358 | } |
359 | ||
360 | // }}} | |
162370e7 | 361 | // {{{ function setRssLink |
362 | ||
2b1ee50b | 363 | public function setRssLink($title, $path) |
162370e7 | 364 | { |
91ebb7ff | 365 | $this->assign('pl_rss', array('title' => $title, 'href' => $path)); |
162370e7 | 366 | } |
367 | ||
368 | // }}} | |
4a8a1e0a | 369 | // {{{ function jsonDisplay |
370 | protected function jsonDisplay() | |
371 | { | |
a286fc7a | 372 | pl_content_headers("text/javascript"); |
641802fe R |
373 | if (!empty($GLOBALS['pl_errors'])) { |
374 | $this->jsonAssign('pl_errors', join("\n", $GLOBALS['pl_errors'])); | |
375 | $GLOBALS['pl_errors'] = array(); | |
376 | } | |
4a8a1e0a | 377 | array_walk_recursive($this->_jsonVars, "escape_xorgDB"); |
378 | $jsonbegin = Env::v('jsonBegin'); | |
379 | $jsonend = Env::v('jsonEnd'); | |
380 | if (Env::has('jsonVar')) { | |
381 | $jsonbegin = Env::v('jsonVar').' = '; | |
382 | $jsonend = ';'; | |
383 | } elseif (Env::has('jsonFunc')) { | |
384 | $jsonbegin = Env::v('jsonFunc').'('; | |
385 | $jsonend = ');'; | |
386 | } | |
387 | echo $jsonbegin, json_encode($this->_jsonVars), $jsonend; | |
388 | exit; | |
389 | } | |
390 | // }}} | |
391 | // {{{ function jsonAssign | |
392 | public function jsonAssign($var, $value) | |
393 | { | |
394 | $this->_jsonVars[$var] = $value; | |
395 | } | |
fba760d2 | 396 | |
397 | // }}} | |
4a8a1e0a | 398 | } |
399 | ||
400 | function escape_xorgDB(&$item, $key) | |
401 | { | |
7cb40d85 | 402 | if ($item instanceof XOrgDBIterator) { |
4a8a1e0a | 403 | $expanded = array(); |
404 | while ($a = $item->next()) { | |
405 | $expanded[] = $a; | |
406 | } | |
407 | $item = $expanded; | |
408 | } | |
0337d704 | 409 | } |
410 | ||
b76f0797 | 411 | // {{{ function escape_html () |
412 | ||
413 | /** | |
414 | * default smarty plugin, used to auto-escape dangerous html. | |
eaf30d86 | 415 | * |
b76f0797 | 416 | * < --> < |
417 | * > --> > | |
418 | * " --> " | |
419 | * & not followed by some entity --> & | |
420 | */ | |
421 | function escape_html($string) | |
422 | { | |
423 | if (is_string($string)) { | |
c1895524 | 424 | return htmlspecialchars($string, ENT_QUOTES, 'UTF-8'); |
b76f0797 | 425 | } else { |
c1895524 | 426 | return $string; |
b76f0797 | 427 | } |
428 | } | |
429 | ||
430 | // }}} | |
431 | // {{{ function at_to_globals() | |
432 | ||
433 | /** | |
434 | * helper | |
435 | */ | |
436 | ||
437 | function _to_globals($s) { | |
438 | global $globals; | |
439 | $t = explode('.',$s); | |
440 | if (count($t) == 1) { | |
441 | return var_export($globals->$t[0],true); | |
442 | } else { | |
443 | return var_export($globals->$t[0]->$t[1],true); | |
444 | } | |
445 | } | |
446 | ||
447 | /** | |
448 | * compilation plugin used to import $globals confing through #globals.foo.bar# directives | |
449 | */ | |
450 | ||
451 | function at_to_globals($tpl_source, &$smarty) | |
452 | { | |
453 | return preg_replace('/#globals\.([a-zA-Z0-9_.]+?)#/e', '_to_globals(\'\\1\')', $tpl_source); | |
7cb40d85 | 454 | } |
b76f0797 | 455 | |
7cb40d85 FB |
456 | // }}} |
457 | // {{{ function trimwhitespace | |
b76f0797 | 458 | |
7cb40d85 FB |
459 | function trimwhitespace($source, &$smarty) |
460 | { | |
461 | $tags = '(script|pre|textarea)'; | |
462 | preg_match_all("!<$tags.*?>.*?</(\\1)>!ius", $source, $tagsmatches); | |
463 | $source = preg_replace("!<$tags.*?>.*?</(\\1)>!ius", "&&&tags&&&", $source); | |
b76f0797 | 464 | |
7cb40d85 FB |
465 | // remove all leading spaces, tabs and carriage returns NOT |
466 | // preceeded by a php close tag. | |
467 | $source = preg_replace('/((?<!\?>)\n)[\s]+/m', '\1', $source); | |
468 | $source = preg_replace("!&&&tags&&&!e", 'array_shift($tagsmatches[0])', $source); | |
b76f0797 | 469 | |
7cb40d85 FB |
470 | return $source; |
471 | } | |
b76f0797 | 472 | |
7cb40d85 FB |
473 | // }}} |
474 | // {{{ function wiki_include | |
7a3f546b | 475 | |
476 | function wiki_include($source, &$smarty) | |
477 | { | |
7cb40d85 | 478 | global $globals; |
7a3f546b | 479 | return preg_replace('/\{include( [^}]*)? wiki=([^} ]+)(.*?)\}/ui', |
7cb40d85 FB |
480 | '{include\1 file="' . $globals->spoolroot . '/spool/wiki.d/cache_\2.tpl"\3 included=1}', |
481 | $source); | |
482 | } | |
483 | ||
484 | function core_include($source, &$smarty) | |
485 | { | |
486 | global $globals; | |
487 | return preg_replace('/\{include( [^}]*)? core=([^} ]+)(.*?)\}/ui', | |
488 | '{include\1 file="' . $globals->spoolroot . '/core/templates/\2"\3}', | |
7a3f546b | 489 | $source); |
490 | } | |
491 | ||
492 | // }}} | |
908db125 FB |
493 | //{{{ function hasPerm |
494 | ||
b6ec30c5 | 495 | function if_rewrites($source, &$smarty) |
908db125 | 496 | { |
b6ec30c5 FB |
497 | $perms = 'isset($smarty.session.perms|smarty:nodefaults) && $smarty.session.perms|smarty:nodefaults && $smarty.session.perms'; |
498 | return preg_replace(array('/\{if([^}]*) (\!?)hasPerms\(([^)]+)\)([^}]*)\}/', | |
499 | '/\{if([^}]*) (\!?)hasPerm\(([^)]+)\)([^}]*)\}/', | |
500 | '/\{if([^}]*) (\!?)t\(([^)]+)\)([^}]*)\}/'), | |
501 | array('{if\1 \2(' . $perms . '->hasFlagCombination(\3))\4}', | |
502 | '{if\1 \2(' . $perms . '->hasFlag(\3))\4}', | |
503 | '{if\1 \2(isset(\3|smarty:nodefaults) && (\3|smarty:nodefaults))\4}'), | |
7cb40d85 | 504 | $source); |
908db125 FB |
505 | } |
506 | ||
507 | // }}} | |
edc636b8 | 508 | // {{{ |
509 | ||
510 | function form_force_encodings($source, &$smarty) | |
511 | { | |
512 | return preg_replace('/<form[^\w]/', | |
a7de4ef7 | 513 | '\0 accept-charset="utf-8" ', |
edc636b8 | 514 | $source); |
515 | } | |
516 | ||
517 | // }}} | |
bf2e1ab0 | 518 | // {{{ function hide_emails |
519 | ||
520 | function _hide_email($source) | |
521 | { | |
1bd2bc7e | 522 | $source = str_replace("\n", '', $source); |
6b8d257b | 523 | return '<script type="text/javascript">//<![CDATA[' . "\n" . |
91ebb7ff FB |
524 | 'Nix.decode("' . addslashes(str_rot13($source)) . '");' . "\n" . |
525 | '//]]></script>'; | |
bf2e1ab0 | 526 | } |
527 | ||
528 | function hide_emails($source, &$smarty) | |
529 | { | |
a18afbdc | 530 | if (!strpos($source, '@')) { |
531 | return $source; | |
532 | } | |
533 | ||
bf2e1ab0 | 534 | //prevent email replacement in <script> and <textarea> |
120bd636 | 535 | $tags = '(script|textarea|select)'; |
abe7e055 | 536 | preg_match_all("!<$tags.*?>.*?</(\\1)>!ius", $source, $tagsmatches); |
537 | $source = preg_replace("!<$tags.*?>.*?</(\\1)>!ius", "&&&tags&&&", $source); | |
bf2e1ab0 | 538 | |
539 | //catch all emails in <a href="mailto:..."> | |
a14159bf | 540 | preg_match_all("!<a[^>]+href=[\"'][^\"']*[-a-z0-9+_.]+@[-a-z0-9_.]+[^\"']*[\"'].*?>.*?</a>!ius", $source, $ahref); |
541 | $source = preg_replace("!<a[^>]+href=[\"'][^\"']*[-a-z0-9+_.]+@[-a-z0-9_.]+[^\"']*[\"'].*?>.*?</a>!ius", '&&&ahref&&&', $source); | |
bf2e1ab0 | 542 | |
543 | //prevant replacement in tag attributes | |
abe7e055 | 544 | preg_match_all("!<[^>]+[-a-z0-9_+.]+@[-a-z0-9_.]+.+?>!ius", $source, $misc); |
545 | $source = preg_replace("!<[^>]+[-a-z0-9_+.]+@[-a-z0-9_.]+.+?>!ius", '&&&misc&&&', $source); | |
bf2e1ab0 | 546 | |
547 | //catch ! | |
eaf30d86 | 548 | $source = preg_replace('!([-a-z0-9_+.]+@[-a-z0-9_.]+)!iue', '_hide_email("\1")', $source); |
bf2e1ab0 | 549 | $source = preg_replace('!&&&ahref&&&!e', '_hide_email(array_shift($ahref[0]))', $source); |
bf2e1ab0 | 550 | |
551 | // restore data | |
2456ea61 | 552 | $source = preg_replace('!&&&misc&&&!e', 'array_shift($misc[0])', $source); |
120bd636 | 553 | $source = preg_replace("!&&&tags&&&!e", 'array_shift($tagsmatches[0])', $source); |
bf2e1ab0 | 554 | |
555 | return $source; | |
556 | } | |
557 | ||
558 | // }}} | |
b76f0797 | 559 | |
a7de4ef7 | 560 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
0337d704 | 561 | ?> |