X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fdiogenes.text.inc.php;fp=include%2Fdiogenes.text.inc.php;h=76ef7d96e835eebf8eca875973d23e026efb5788;hb=d950012fd97be05390aa91c7671b7e7f73293880;hp=0000000000000000000000000000000000000000;hpb=8d31b5f1a0404e279c644c26d3e75e2f5f35cf99;p=diogenes.git diff --git a/include/diogenes.text.inc.php b/include/diogenes.text.inc.php new file mode 100644 index 0000000..76ef7d9 --- /dev/null +++ b/include/diogenes.text.inc.php @@ -0,0 +1,127 @@ + 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; + } + } + + return $output; +} + + +/** Unprotect base64 blocks. + */ +function textUnprotectTags($prot_open, $prot_close, $input) +{ + $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("/^$prot_open(.+)$prot_close$/", $block, $match)) { + $output .= base64_decode($match[1]); + } else { + $output .= $block; + } + } + + return $output; +} + + +/** Protect HTML code from Textism. + */ +function htmlProtectFromTextism($input) +{ + return textProtectTag("", "<\/protect>", "{NOP:", ":NOP}", $input); +} + + +/** Restore HTML code that was protected from Textism. + */ +function htmlUnprotectFromTextism($input) +{ + $input = textUnprotectTags("

\s*{NOP:", ":NOP}\s*<\/p>", $input); + $input = textUnprotectTags("{NOP:", ":NOP}", $input); + return preg_replace('/<\/?protect>/', "", $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) +{ + return html_accent(preg_replace("/<(br|img|input|p)( [^\/]*)?\/>/","<\$1\$2>",$input)); +} + + +/** Restore XHTML-compliant tags. + */ +function htmlToXhtml($input) +{ + return preg_replace("/<(br|img|input)( [^>]+)?>/","<\$1\$2/>",$input); +} + + +?>