Commit | Line | Data |
---|---|---|
dd8de1ec PH |
1 | <?php |
2 | /******************************************************************************** | |
3 | * include/philter.inc.php : Philter base class | |
4 | * ----------------------- | |
5 | * | |
6 | * This file is part of the philter distribution | |
7 | * Copyright: See COPYING files that comes with this distribution | |
8 | ********************************************************************************/ | |
9 | ||
10 | require_once("include/core.inc.php"); | |
11 | ||
12 | /** Philter base configuration class | |
13 | * This is the base class of Philter. | |
14 | */ | |
15 | class Philter { | |
16 | /** philter configuration. | |
17 | * @see config.inc.php | |
18 | */ | |
19 | var $config; | |
20 | /** error string */ | |
21 | var $err; | |
22 | ||
23 | /** constructor */ | |
24 | function Philter() { | |
25 | $this->config = array( | |
26 | 'db' => array('host', 'name', 'user', 'pwd', 'link'), | |
27 | 'path' => array('procmail', 'spool'), | |
28 | 'match_plugins' => array(), | |
29 | 'action_plugins' => array(), | |
30 | 'global_plugin' => array() | |
31 | ); | |
4956445b | 32 | $this->err = ""; |
dd8de1ec PH |
33 | } |
34 | ||
35 | /** returns the error. | |
36 | * @return the error string | |
37 | */ | |
38 | function error() { | |
39 | return $this->err; | |
40 | } | |
41 | ||
42 | /** sets the error string. | |
43 | * @return nothing | |
44 | */ | |
45 | function set_error($_err) { | |
46 | $this->err = $_err; | |
47 | } | |
48 | ||
49 | /** returns the database persistent connection link. | |
50 | * it's a shortname for $this->config['db']['link'] | |
51 | * @returns a mysql resource | |
52 | */ | |
53 | function link() { return $this->config['db']['link']; } | |
54 | ||
55 | /** init the link to the database */ | |
56 | function pconnect() { | |
57 | $this->config['db']['link'] = | |
58 | mysql_pconnect( | |
59 | $this->config['db']['host'], | |
60 | $this->config['db']['user'], | |
61 | $this->config['db']['pass'] | |
62 | ); | |
63 | mysql_select_db($this->config['db']['name'], $this->link()); | |
64 | } | |
65 | ||
66 | /** function that writes the procmailrc. | |
67 | * @return true if all is ok | |
68 | */ | |
69 | function write_procmailrc() { | |
70 | // TODO | |
71 | return true; | |
72 | } | |
73 | ||
74 | /** function that register a new Plugin | |
75 | * @param $_plugin an instance of the plugin | |
76 | * @return true if all is ok, read error() else | |
77 | */ | |
78 | function register_plugin($_plugin) { | |
79 | if($rtti = $_plugin->rtti()) { | |
80 | if(is_subclass_of($_plugin, 'matchplugin')) { | |
81 | if($_plugin->is_global()) { | |
82 | $this->err = "Philter::register_plugin : this plugin is global"; | |
83 | return false; | |
84 | } | |
85 | $index = 'match_plugins'; | |
86 | } elseif(is_subclass_of($_plugin, 'actionplugin')) { | |
87 | $index = 'action_plugins'; | |
88 | } else { | |
89 | $this->err = "Philter::register_plugin : bad object"; | |
90 | return false; | |
91 | } | |
92 | ||
93 | if(isset($this->config[$index][$rtti])) { | |
94 | $this->err = "Philter::register_plugin : a plugin is already registerd"; | |
95 | return false; | |
96 | } | |
97 | ||
98 | $this->config[$index][$rtti] = $_plugin; | |
99 | return true; | |
100 | } | |
101 | ||
102 | $this->err = "Philter::register_plugin : rtti is 0, this is an abstract class"; | |
103 | return false; | |
104 | } | |
105 | ||
106 | /** function that register plugin as a global rule | |
107 | * @param $_plugin an instance of the plugin | |
108 | * @return true if all is ok, read error() else | |
109 | */ | |
110 | function register_global_plugin($_plugin) { | |
111 | if($rtti = $_plugin->rtti()) { | |
112 | if(!is_subclass_of($_plugin, 'matchplugin')) { | |
113 | $this->err = "Philter::register_global_plugin : bad object"; | |
114 | return false; | |
115 | } | |
116 | ||
117 | if(!$_plugin->is_global()) { | |
118 | $this->err = "Philter::register_global_plugin : this plugin is not global"; | |
119 | return false; | |
120 | } | |
121 | ||
122 | if(isset($this->config['global_plugin'][$rtti])) { | |
123 | $this->err = "Philter::register_global_plugin : a plugin is already registerd"; | |
124 | return false; | |
125 | } | |
126 | ||
127 | $this->config['global_plugin'][$rtti] = $_plugin; | |
128 | return true; | |
129 | } | |
130 | ||
131 | $this->err = "Philter::register_global_plugin : rtti is 0, this is an abstract class"; | |
132 | return false; | |
133 | } | |
134 | } | |
135 | ||
136 | /******************************************************************************** | |
137 | * $Id$ | |
138 | * vim: set expandtab shiftwidth=4 tabstop=4 softtabstop=4 textwidth=100: | |
139 | ********************************************************************************/ | |
140 | ?> |