00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 require_once 'diogenes/diogenes.misc.inc.php';
00022
00025 function textProtectTag($tag_open, $tag_close, $prot_open, $prot_close, $input)
00026 {
00027 $splits = preg_split("/($tag_open|$tag_close)/",$input,-1,PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
00028
00029 $output = "";
00030 $depth = 0;
00031 while ($block = array_shift($splits)) {
00032 if (preg_match("/^$tag_open$/", $block)) {
00033 if ($depth == 0) {
00034 $save = "";
00035 }
00036 $save .= $block;
00037 $depth++;
00038 } else if ($depth > 0) {
00039 $save .= $block;
00040 if (preg_match("/^$tag_close$/", $block))
00041 {
00042 $depth--;
00043 if ($depth == 0)
00044 {
00045 $output .= $prot_open.base64_encode($save).$prot_close;
00046 $save = "";
00047 }
00048 }
00049 } else {
00050 $output .= $block;
00051 }
00052 }
00053
00054 return $output;
00055 }
00056
00057
00060 function textUnprotectTags($prot_open, $prot_close, $input)
00061 {
00062 $splits = preg_split("/($prot_open.+$prot_close)/",$input,-1,PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
00063 $output = "";
00064
00065 foreach ($splits as $block) {
00066 if (preg_match("/^$prot_open(.+)$prot_close$/", $block, $match)) {
00067 $output .= base64_decode($match[1]);
00068 } else {
00069 $output .= $block;
00070 }
00071 }
00072
00073 return $output;
00074 }
00075
00076
00079 function htmlProtectFromTextism($input)
00080 {
00081 return textProtectTag("<protect>", "<\/protect>", "{NOP:", ":NOP}", $input);
00082 }
00083
00084
00087 function htmlUnprotectFromTextism($input)
00088 {
00089 $input = textUnprotectTags("<p>\s*{NOP:", ":NOP}\s*<\/p>", $input);
00090 $input = textUnprotectTags("{NOP:", ":NOP}", $input);
00091 return preg_replace('/<\/?protect>/', "", $input);
00092 }
00093
00094
00097 function phpProtect($input)
00098 {
00099 return textProtectTag("<\?php", "\?>", "{PHP:", ":PHP}", $input);
00100 }
00101
00102
00105 function phpUnprotect($input)
00106 {
00107 return textUnprotectTags("{PHP:", ":PHP}", $input);
00108 }
00109
00110
00113 function xhtmlToHtml($input)
00114 {
00115 return html_accent(preg_replace("/<(br|img|input|p)( [^\/]*)?\/>/","<\$1\$2>",$input));
00116 }
00117
00118
00121 function htmlToXhtml($input)
00122 {
00123 return preg_replace("/<(br|img|input)( [^>]+)?>/","<\$1\$2/>",$input);
00124 }
00125
00126
00127 ?>