includes/functions.php
changeset 825 9d5c04c1414f
parent 817 880c4b7eb658
child 832 7152ca0a0ce9
equal deleted inserted replaced
817:880c4b7eb658 825:9d5c04c1414f
  2159     $byte = '(&\\#([0]*){0,7}' . $ch1 . ';|\\\\([0]*){0,7}' . $ch1 . ';|\\\\([0]*){0,7}' . $ch2 . ';|&\\#x([0]*){0,7}' . $ch2 . ';|%([0]*){0,7}' . $ch2 . '|' . preg_quote($chr) . ')';
  2159     $byte = '(&\\#([0]*){0,7}' . $ch1 . ';|\\\\([0]*){0,7}' . $ch1 . ';|\\\\([0]*){0,7}' . $ch2 . ';|&\\#x([0]*){0,7}' . $ch2 . ';|%([0]*){0,7}' . $ch2 . '|' . preg_quote($chr) . ')';
  2160     $ret .= $byte;
  2160     $ret .= $byte;
  2161     $ret .= '([\s]){0,2}';
  2161     $ret .= '([\s]){0,2}';
  2162   }
  2162   }
  2163   return $ret;
  2163   return $ret;
       
  2164 }
       
  2165 
       
  2166 /**
       
  2167  * Portal function allowing spam-filtering plugins.
       
  2168  * Hooking guide:
       
  2169  *   - Attach to spam_check
       
  2170  *   - Return either true or false - true if the message is spam-free, false if it fails your test
       
  2171  * @example
       
  2172  <code>
       
  2173  $plugins->attachHook('spam_check', 'return my_spam_check($string);');
       
  2174  function my_spam_check($string)
       
  2175  {
       
  2176    if ( stristr($string, 'viagra') )
       
  2177      return false;
       
  2178    
       
  2179    return true;
       
  2180  }
       
  2181  </code>
       
  2182  * @param string String to check for spam
       
  2183  * @param string Author name
       
  2184  * @param string Author e-mail
       
  2185  * @param string Author website
       
  2186  * @param string Author IP
       
  2187  * @return bool
       
  2188  */
       
  2189 
       
  2190 function spamalyze($string, $name = false, $email = false, $url = false, $ip = false)
       
  2191 {
       
  2192   global $db, $session, $paths, $template, $plugins; // Common objects
       
  2193   if ( !$ip )
       
  2194     $ip =& $_SERVER['REMOTE_ADDR'];
       
  2195   
       
  2196   $code = $plugins->setHook('spam_check');
       
  2197   foreach ( $code as $cmd )
       
  2198   {
       
  2199     $result = eval($cmd);
       
  2200     if ( !$result )
       
  2201       return false;
       
  2202   }
       
  2203   return true;
  2164 }
  2204 }
  2165 
  2205 
  2166 /**
  2206 /**
  2167  * Paginates (breaks into multiple pages) a MySQL result resource, which is treated as unbuffered.
  2207  * Paginates (breaks into multiple pages) a MySQL result resource, which is treated as unbuffered.
  2168  * @param resource The MySQL result resource. This should preferably be an unbuffered query.
  2208  * @param resource The MySQL result resource. This should preferably be an unbuffered query.