3 * Copyright (C) 2003-2004 Polytechnique.org
4 * http://opensource.polytechnique.org/
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 require_once 'diogenes/diogenes.misc.inc.php';
26 function phpProtect($input)
28 $splits = preg_split("/(<\?php|\?>)/",$input,-1,PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY
);
31 while ($block = array_shift($splits)) {
32 if ($block == "<?php") {
33 $code = array_shift($splits);
34 $end = array_shift($splits);
36 die("phpProtect : parse error");
37 $output .= "{PHP:".base64_encode($code).":PHP}";
47 /** Unprotect PHP code.
49 function phpUnprotect($input)
51 $splits = preg_split("/({PHP:.+:PHP})/",$input,-1,PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY
);
54 foreach ($splits as $block) {
55 if (preg_match("/{PHP:(.+):PHP}/",$block,$match)) {
56 $output .= "<?php".base64_decode($match[1])."?>";
66 /** Convert XHTML-compliant tags to plain HTML.
68 function xhtmlToHtml($input)
70 return html_accent(preg_replace("/<(br|img|input|p)( [^\/]*)?\/>/","<\$1\$2>",$input));
74 /** Restore XHTML-compliant tags.
76 function htmlToXhtml($input)
78 return preg_replace("/<(br|img|input)( [^>]+)?>/","<\$1\$2/>",$input);