includes/functions.php
changeset 593 4f9bec0d65c1
parent 592 27377179fe58
child 599 52bffa6c499f
equal deleted inserted replaced
592:27377179fe58 593:4f9bec0d65c1
  1946 function sanitize_html($html, $filter_php = true)
  1946 function sanitize_html($html, $filter_php = true)
  1947 {
  1947 {
  1948   // Random seed for substitution
  1948   // Random seed for substitution
  1949   $rand_seed = md5( sha1(microtime()) . mt_rand() );
  1949   $rand_seed = md5( sha1(microtime()) . mt_rand() );
  1950   
  1950   
       
  1951   // We need MediaWiki
       
  1952   require_once(ENANO_ROOT . '/includes/wikiengine/Tables.php');
       
  1953   
  1951   // Strip out comments that are already escaped
  1954   // Strip out comments that are already escaped
  1952   preg_match_all('/<!--(.*?)-->/', $html, $comment_match);
  1955   preg_match_all('/<!--(.*?)-->/', $html, $comment_match);
  1953   $i = 0;
  1956   $i = 0;
  1954   foreach ( $comment_match[0] as $comment )
  1957   foreach ( $comment_match[0] as $comment )
  1955   {
  1958   {
  2819  */
  2822  */
  2820 
  2823 
  2821 function str_replace_once($needle, $thread, $haystack)
  2824 function str_replace_once($needle, $thread, $haystack)
  2822 {
  2825 {
  2823   $needle_len = strlen($needle);
  2826   $needle_len = strlen($needle);
  2824   for ( $i = 0; $i < strlen($haystack); $i++ )
  2827   if ( $pos = strstr($haystack, $needle) )
  2825   {
  2828   {
  2826     $test = substr($haystack, $i, $needle_len);
  2829     $upto = substr($haystack, 0, ( strlen($haystack) - strlen($pos) ));
  2827     if ( $test == $needle )
  2830     $from = substr($pos, $needle_len);
  2828     {
  2831     return "{$upto}{$thread}{$from}";
  2829       // Got it!
       
  2830       $upto = substr($haystack, 0, $i);
       
  2831       $from = substr($haystack, ( $i + $needle_len ));
       
  2832       $new_haystack = "{$upto}{$thread}{$from}";
       
  2833       return $new_haystack;
       
  2834     }
       
  2835   }
  2832   }
  2836   return $haystack;
  2833   return $haystack;
  2837 }
  2834 }
  2838 
  2835 
  2839 /**
  2836 /**