X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fdiogenes.text.inc.php;fp=include%2Fdiogenes.compose.inc.php;h=7f415d6434b43d5b26bd86e0fa07a2596bb31dd9;hb=e2e369d67aae533cf6e53a5e535807f70dde825f;hp=1d5bef0b04c9a2ede9aa86486d3bc4fa79ef148e;hpb=b59c4ad4f97aee951de81b7d84d823b2a1868138;p=diogenes.git diff --git a/include/diogenes.compose.inc.php b/include/diogenes.text.inc.php similarity index 50% rename from include/diogenes.compose.inc.php rename to include/diogenes.text.inc.php index 1d5bef0..7f415d6 100644 --- a/include/diogenes.compose.inc.php +++ b/include/diogenes.text.inc.php @@ -1,6 +1,6 @@ )/",$input,-1,PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); + $splits = preg_split("/($tag_open|$tag_close)/",$input,-1,PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); + $output = ""; - + $depth = 0; while ($block = array_shift($splits)) { - if ($block == "") - die("phpProtect : parse error"); - $output .= "{PHP:".base64_encode($code).":PHP}"; + if (preg_match("/^$tag_open$/", $block)) { + if ($depth == 0) { + $save = ""; + } + $save .= $block; + $depth++; + } else if ($depth > 0) { + $save .= $block; + if (preg_match("/^$tag_close$/", $block)) + { + $depth--; + if ($depth == 0) + { + $output .= $prot_open.base64_encode($save).$prot_close; + $save = ""; + } + } } else { $output .= $block; } @@ -44,16 +55,16 @@ function phpProtect($input) } -/** Unprotect PHP code. +/** Unprotect base64 blocks. */ -function phpUnprotect($input) +function textUnprotectTags($prot_open, $prot_close, $input) { - $splits = preg_split("/({PHP:.+:PHP})/",$input,-1,PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); + $splits = preg_split("/($prot_open.+$prot_close)/",$input,-1,PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); $output = ""; foreach ($splits as $block) { - if (preg_match("/{PHP:(.+):PHP}/",$block,$match)) { - $output .= ""; + if (preg_match("/^$prot_open(.+)$prot_close$/", $block, $match)) { + $output .= base64_decode($match[1]); } else { $output .= $block; } @@ -63,6 +74,38 @@ function phpUnprotect($input) } +/** Protect HTML code from Textism. + */ +function htmlProtectFromTextism($input) +{ + return textProtectTag("]*>", "<\/table>", "{NOP:", ":NOP}", $input); +} + + +/** Restore HTML code that was protected from Textism. + */ +function htmlUnprotectFromTextism($input) +{ + return textUnprotectTags("{NOP:", ":NOP}", $input); +} + + +/** Protect PHP code. + */ +function phpProtect($input) +{ + return textProtectTag("<\?php", "\?>", "{PHP:", ":PHP}", $input); +} + + +/** Unprotect PHP code. + */ +function phpUnprotect($input) +{ + return textUnprotectTags("{PHP:", ":PHP}", $input); +} + + /** Convert XHTML-compliant tags to plain HTML. */ function xhtmlToHtml($input) @@ -78,4 +121,5 @@ function htmlToXhtml($input) return preg_replace("/<(br|img|input)( [^>]+)?>/","<\$1\$2/>",$input); } + ?>