ca0b2a822402727da4b599d1b2e6f426ca8fe9e8
2 /********************************************************************************
3 * include/philter.inc.php : Philter base class
4 * -----------------------
6 * This file is part of the philter distribution
7 * Copyright: See COPYING files that comes with this distribution
8 ********************************************************************************/
10 require_once("include/core.inc.php");
12 /** Philter base configuration class
13 * This is the base class of Philter.
16 /** philter configuration.
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(),
36 /** returns the i18n string
37 * @param $_index the index of the string
38 * @returns the string or false
40 function i18n($_index) {
41 if(isset($this->confg
[$_index]))
42 return $this->confg
[$_index];
46 /** returns the error.
47 * @return the error string
53 /** sets the error string.
56 function set_error($_err) {
60 /** returns the database persistent connection link.
61 * it's a shortname for $this->config['db']['link']
62 * @returns a mysql resource
64 function link() { return $this->config
['db']['link']; }
66 /** init the link to the database */
68 $this->config
['db']['link'] =
70 $this->config
['db']['host'],
71 $this->config
['db']['user'],
72 $this->config
['db']['pass']
74 mysql_select_db($this->config
['db']['name'], $this->link());
77 /** function that writes the procmailrc.
78 * @return true if all is ok
80 function write_procmailrc() {
85 /** function that register a new Plugin
86 * @param $_plugin an instance of the plugin
87 * @return true if all is ok, read error() else
89 function register_plugin($_plugin) {
90 if($rtti = $_plugin->rtti()) {
91 if(is_subclass_of($_plugin, 'matchplugin')) {
92 if($_plugin->is_global()) {
93 $this->err
= "Philter::register_plugin : this plugin is global";
96 $index = 'match_plugins';
97 } elseif(is_subclass_of($_plugin, 'actionplugin')) {
98 $index = 'action_plugins';
100 $this->err
= "Philter::register_plugin : bad object";
104 if(isset($this->config
[$index][$rtti])) {
105 $this->err
= "Philter::register_plugin : a plugin is already registerd";
109 $this->config
[$index][$rtti] = $_plugin;
113 $this->err
= "Philter::register_plugin : rtti is 0, this is an abstract class";
117 /** function that register plugin as a global rule
118 * @param $_plugin an instance of the plugin
119 * @return true if all is ok, read error() else
121 function register_global_plugin($_plugin) {
122 if($rtti = $_plugin->rtti()) {
123 if(!is_subclass_of($_plugin, 'matchplugin')) {
124 $this->err
= "Philter::register_global_plugin : bad object";
128 if(!$_plugin->is_global()) {
129 $this->err
= "Philter::register_global_plugin : this plugin is not global";
133 if(isset($this->config
['global_plugin'][$rtti])) {
134 $this->err
= "Philter::register_global_plugin : a plugin is already registerd";
138 $this->config
['global_plugin'][$rtti] = $_plugin;
142 $this->err
= "Philter::register_global_plugin : rtti is 0, this is an abstract class";
147 /********************************************************************************
149 * vim: set expandtab shiftwidth=4 tabstop=4 softtabstop=4 textwidth=100:
150 ********************************************************************************/