b46a255451691a7dc4a3b0b9e7f676863b4c5009
2 /********************************************************************************
3 * include/filter.inc.php : The complete Filter Object
4 * ----------------------
6 * This file is part of the philter distribution
7 * Copyright: See COPYING files that comes with this distribution
8 ********************************************************************************/
18 function Filter($_uid) {
21 $this->rules
= array();
23 $sql = mysql_query("SELECT rank,rid,flags,name FROM ".bd()."rules WHERE uid='$_uid' ORDER BY rank");
24 while(list($_rank,$_rid,$_flags,$_name) = mysql_fetch_row($sql)) {
25 $this->rules
[$_rid] = new Rule($_rank,$_flags,$_name);
26 $this->rules
[$_rid]->sql_get_matches($_uid,$_rid);
27 $this->rules
[$_rid]->sql_get_actions($_uid,$_rid);
31 function get_global_data($_plug_id) {
32 if(isset($this->rules
[0]))
33 foreach($this->rules
[0]->matches
as $match)
34 if($match[0] == $_plug_id)
36 return(Array($_plug_id,0));
39 function set_global_data($_plug_id, $data) {
40 if(!isset($this->rules
[0]))
41 $this->rules
[0] = new Rule(0,'','GLOBAL');
42 foreach($this->rules
[0]->matches
as $id=>$match)
43 if($match[0] == $_plug_id) {
44 $this->rules
[0]->matches
[$id] = $data;
47 $this->rules
[0]->matches
[] = $data;
50 function to_string() {
52 . "|formail -I'X-Philter-Or'\n"
55 foreach($this->rules
as $id=>$rule)
57 $res .= $rule->to_string();
62 function delete_rule($_rid) {
63 $rk = $this->rules
[$_rid]->rank
;
64 $this->rules
[$_rid]->sql_clean($this->uid
, $_rid);
65 unset($this->rules
[$_rid]);
67 mysql_query("UPDATE ".bd()."rules SET rank=rank-1 WHERE uid='{$this->uid}' and rank>$rk");
70 function new_rule_id() {
72 while(array_key_exists($i,$this->rules
))
77 function handle_form() {
80 $rule_id = ($_POST['rule']['id'] ?
$_POST['rule']['id'] : $this->new_rule_id());
81 $rank = (isset($this->rules
[$rule_id]) ?
$this->rules
[$rule_id]->rank
: count($this->rules
)+
1);
84 if($_POST['rule']['all']) $flags[] = 'all';
85 if(isset($_POST['rule']['block'])) $flags[] = 'block';
86 $flags = implode(',', $flags);
88 $my_rule = new Rule($rank,$flags,$_POST['rule']['name']);
90 // we create the $matches real array
91 if(isset($_POST['rule']['matches']))
92 foreach($_POST['rule']['matches'] as $data)
93 if(array_key_exists(0, $data))
94 $my_rule->matches
[] = $data;
96 // we create the $actions real array
97 if(isset($_POST['rule']['actions']))
98 foreach($_POST['rule']['actions'] as $data)
99 if(array_key_exists(0, $data))
100 $my_rule->actions
[] = $data;
102 if(!count($my_rule->actions
) && !count($my_rule->matches
)) {
103 $philter->set_error(_i18n('filter_err_empty'));
107 $my_rule->sql_store(get_user_id(),$rule_id);
109 $_POST['rule']['id'] = $rule_id;
110 $this->rules
[$rule_id] = $my_rule;
115 $res = "filter[0] = { all: 1, block:1, name:'"._i18n('new_rule')."', matches: [], actions: [] };\n";
117 foreach($this->rules
as $id=>$rule)
119 $res .= "filter[$id] = ".$rule->to_js().";\n";
126 /********************************************************************************
128 * vim: set expandtab shiftwidth=4 tabstop=4 softtabstop=4 textwidth=100:
129 ********************************************************************************/