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