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 | ); | |
32 | } | |
33 | ||
34 | /** returns the error. | |
35 | * @return the error string | |
36 | */ | |
37 | function error() { | |
38 | return $this->err; | |
39 | } | |
40 | ||
41 | /** sets the error string. | |
42 | * @return nothing | |
43 | */ | |
44 | function set_error($_err) { | |
45 | $this->err = $_err; | |
46 | } | |
47 | ||
48 | /** returns the database persistent connection link. | |
49 | * it's a shortname for $this->config['db']['link'] | |
50 | * @returns a mysql resource | |
51 | */ | |
52 | function link() { return $this->config['db']['link']; } | |
53 | ||
54 | /** init the link to the database */ | |
55 | function pconnect() { | |
56 | $this->config['db']['link'] = | |
57 | mysql_pconnect( | |
58 | $this->config['db']['host'], | |
59 | $this->config['db']['user'], | |
60 | $this->config['db']['pass'] | |
61 | ); | |
62 | mysql_select_db($this->config['db']['name'], $this->link()); | |
63 | } | |
64 | ||
65 | /** function that writes the procmailrc. | |
66 | * @return true if all is ok | |
67 | */ | |
68 | function write_procmailrc() { | |
69 | // TODO | |
70 | return true; | |
71 | } | |
72 | ||
73 | /** function that register a new Plugin | |
74 | * @param $_plugin an instance of the plugin | |
75 | * @return true if all is ok, read error() else | |
76 | */ | |
77 | function register_plugin($_plugin) { | |
78 | if($rtti = $_plugin->rtti()) { | |
79 | if(is_subclass_of($_plugin, 'matchplugin')) { | |
80 | if($_plugin->is_global()) { | |
81 | $this->err = "Philter::register_plugin : this plugin is global"; | |
82 | return false; | |
83 | } | |
84 | $index = 'match_plugins'; | |
85 | } elseif(is_subclass_of($_plugin, 'actionplugin')) { | |
86 | $index = 'action_plugins'; | |
87 | } else { | |
88 | $this->err = "Philter::register_plugin : bad object"; | |
89 | return false; | |
90 | } | |
91 | ||
92 | if(isset($this->config[$index][$rtti])) { | |
93 | $this->err = "Philter::register_plugin : a plugin is already registerd"; | |
94 | return false; | |
95 | } | |
96 | ||
97 | $this->config[$index][$rtti] = $_plugin; | |
98 | return true; | |
99 | } | |
100 | ||
101 | $this->err = "Philter::register_plugin : rtti is 0, this is an abstract class"; | |
102 | return false; | |
103 | } | |
104 | ||
105 | /** function that register plugin as a global rule | |
106 | * @param $_plugin an instance of the plugin | |
107 | * @return true if all is ok, read error() else | |
108 | */ | |
109 | function register_global_plugin($_plugin) { | |
110 | if($rtti = $_plugin->rtti()) { | |
111 | if(!is_subclass_of($_plugin, 'matchplugin')) { | |
112 | $this->err = "Philter::register_global_plugin : bad object"; | |
113 | return false; | |
114 | } | |
115 | ||
116 | if(!$_plugin->is_global()) { | |
117 | $this->err = "Philter::register_global_plugin : this plugin is not global"; | |
118 | return false; | |
119 | } | |
120 | ||
121 | if(isset($this->config['global_plugin'][$rtti])) { | |
122 | $this->err = "Philter::register_global_plugin : a plugin is already registerd"; | |
123 | return false; | |
124 | } | |
125 | ||
126 | $this->config['global_plugin'][$rtti] = $_plugin; | |
127 | return true; | |
128 | } | |
129 | ||
130 | $this->err = "Philter::register_global_plugin : rtti is 0, this is an abstract class"; | |
131 | return false; | |
132 | } | |
133 | } | |
134 | ||
135 | /******************************************************************************** | |
136 | * $Id$ | |
137 | * vim: set expandtab shiftwidth=4 tabstop=4 softtabstop=4 textwidth=100: | |
138 | ********************************************************************************/ | |
139 | ?> |