rank - $r2->rank); } function to_js_str($s) { if((string)((int)($s))==$s) return((int)($s)); $s = addslashes(stripslashes($s)); $s = str_replace("\r\n", '\n', $s); $s = str_replace("\n", '\n', $s); return "'$s'"; } /** this class represents One rule of filtering */ class Rule { /** rank of the rule */ var $rank; /** all the matches that the Rule use */ var $matches; /** all the actions that the Rule use */ var $actions; /** name of the rule */ var $name; /** true if we must stop if the rule matches */ var $block; /** true if all matches must match, false if only one is enough */ var $all; function Rule($_rank,$_flags,$_name) { $this->matches = array(); $this->actions = array(); $this->rank = $_rank; $this->name = $_name; $this->all = (stristr($_flags,'all')!==false); $this->block = (stristr($_flags,'block')!==false); } function sql_get_actions($_uid, $_rid) { global $philter; $left_joins = ""; foreach($philter->config['action_plugins'] as $plug) $left_joins .= $plug->sql_get(); $bd = bd()."actions"; $sql = mysql_query("SELECT * FROM $bd WHERE $bd.uid='$_uid' AND $bd.rid='$_rid' ".$left_joins); while($t = mysql_fetch_assoc($sql)) $this->actions[] = $philter->config['action_plugins'][$t['pid']]->sql_to_data($t); } function sql_get_matches($_uid, $_rid) { global $philter; $left_joins = ""; foreach($philter->config['match_plugins'] as $plug) $left_joins .= $plug->sql_get(); $bd = bd()."matches"; $sql = mysql_query("SELECT * FROM $bd WHERE $bd.uid='$_uid' AND $bd.rid='$_rid' ".$left_joins); if($_rid) while($t = mysql_fetch_assoc($sql)) $this->matches[] = $philter->config['match_plugins'][$t['pid']]->sql_to_data($t); else while($t = mysql_fetch_assoc($sql)) $this->matches[] = $philter->config['global_plugins'][$t['pid']]->sql_to_data($t); } function move_to($_new_rank, $_uid, $_rid) { if($this->rank == $_new_rank) return; $this->rank = $_new_rank; mysql_query("UPDATE ".bd()."rules SET rank='$_new_rank' WHERE uid='$_uid' AND rid='$_rid'"); } function to_string() { return ""; } function sql_clean($_uid, $_rid) { global $philter; mysql_query("DELETE FROM ".bd()."rules WHERE uid='$_uid' AND rid='$_rid'"); mysql_query("DELETE FROM ".bd()."actions WHERE uid='$_uid' AND rid='$_rid'"); mysql_query("DELETE FROM ".bd()."matches WHERE uid='$_uid' AND rid='$_rid'"); foreach($philter->config['action_plugins'] as $plug) $plug->sql_clean($_uid, $_rid); foreach($philter->config['match_plugins'] as $plug) $plug->sql_clean($_uid, $_rid); } function sql_store($_uid, $_rid) { global $philter; $flags = Array(); if($this->all) $flags[] = 'all'; if($this->block) $flags[] = 'block'; $flags = implode(',',$flags); $this->sql_clean($_uid,$_rid); mysql_query("INSERT INTO ".bd()."rules SET uid='$_uid',rid='$_rid',rank='{$this->rank}',flags='$flags',name='{$this->name}'"); if($_rid) { foreach($this->matches as $match) $philter->config['match_plugins'][$match[0]]->sql_store($_uid, $_rid, $match); foreach($this->actions as $action) $philter->config['action_plugins'][$action[0]]->sql_store($_uid, $_rid, $action); } else foreach($this->matches as $match) $philter->config['global_plugins'][$match[0]]->sql_store($_uid, $_rid, $match); } function to_js() { $matches = array(); ksort($this->matches); foreach($this->matches as $data) { $data = array_map('to_js_str', $data); $matches[] = '[' . implode(',', $data) . ']'; } $matches = '['.implode(',',$matches).']'; $actions = array(); foreach($this->actions as $data) { $data = array_map('to_js_str', $data); $actions[] = '[' . implode(',', $data) . ']'; } $actions = '['.implode(',',$actions).']'; return "{ all: ".($this->all ? "1" : "0") .", block: ".($this->block ? "1" : "0") .", name: '{$this->name}', matches: ".$matches .", actions: ".$actions." }"; } } /******************************************************************************** * $Id$ * vim: set expandtab shiftwidth=4 tabstop=4 softtabstop=4 textwidth=100: ********************************************************************************/ ?>