8874dcdd0dc8f299816b2841115433f6845bd1b4
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 function i18n($_index) { global $philter; echo $philter->i18n($_index); }
14 /** Philter base configuration class
15 * This is the base class of Philter.
18 /** philter configuration.
27 $this->config
= array(
28 'db' => array('host', 'name', 'user', 'pwd', 'link'),
29 'path' => array('procmail', 'spool'),
30 'match_plugins' => array(),
31 'action_plugins' => array(),
32 'global_plugin' => array(),
38 /** returns the i18n string
39 * @param $_index the index of the string
40 * @returns the string or false
42 function i18n($_index) {
43 if(isset($this->config
['i18n'][$_index]))
44 return $this->config
['i18n'][$_index];
48 /** returns the error.
49 * @return the error string
55 /** sets the error string.
58 function set_error($_err) {
62 /** returns the database persistent connection link.
63 * it's a shortname for $this->config['db']['link']
64 * @returns a mysql resource
66 function link() { return $this->config
['db']['link']; }
68 /** init the link to the database */
70 $this->config
['db']['link'] =
72 $this->config
['db']['host'],
73 $this->config
['db']['user'],
74 $this->config
['db']['pass']
76 mysql_select_db($this->config
['db']['name'], $this->link());
79 /** function that writes the procmailrc.
80 * @return true if all is ok
82 function write_procmailrc() {
87 /** function that register a new Plugin
88 * @param $_plugin an instance of the plugin
89 * @return true if all is ok, read error() else
91 function register_plugin($_plugin) {
92 if($rtti = $_plugin->rtti()) {
93 if(is_subclass_of($_plugin, 'matchplugin')) {
94 if($_plugin->is_global()) {
95 $this->err
= "Philter::register_plugin : this plugin is global";
98 $index = 'match_plugins';
99 } elseif(is_subclass_of($_plugin, 'actionplugin')) {
100 $index = 'action_plugins';
102 $this->err
= "Philter::register_plugin : bad object";
106 if(isset($this->config
[$index][$rtti])) {
107 $this->err
= "Philter::register_plugin : a plugin is already registerd";
111 $this->config
[$index][$rtti] = $_plugin;
115 $this->err
= "Philter::register_plugin : rtti is 0, this is an abstract class";
119 /** function that register plugin as a global rule
120 * @param $_plugin an instance of the plugin
121 * @return true if all is ok, read error() else
123 function register_global_plugin($_plugin) {
124 if($rtti = $_plugin->rtti()) {
125 if(!is_subclass_of($_plugin, 'matchplugin')) {
126 $this->err
= "Philter::register_global_plugin : bad object";
130 if(!$_plugin->is_global()) {
131 $this->err
= "Philter::register_global_plugin : this plugin is not global";
135 if(isset($this->config
['global_plugin'][$rtti])) {
136 $this->err
= "Philter::register_global_plugin : a plugin is already registerd";
140 $this->config
['global_plugin'][$rtti] = $_plugin;
144 $this->err
= "Philter::register_global_plugin : rtti is 0, this is an abstract class";
149 /********************************************************************************
151 * vim: set expandtab shiftwidth=4 tabstop=4 softtabstop=4 textwidth=100:
152 ********************************************************************************/