diogenes.text.inc.php

00001 <?php
00002 /*
00003  * Copyright (C) 2003-2006 Polytechnique.org
00004  * http://opensource.polytechnique.org/
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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 ?>

Generated on Fri Jan 11 01:20:08 2008 for Diogenes by  doxygen 1.5.1