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()
34 /** returns the error.
35 * @return the error string
41 /** sets the error string.
44 function set_error($_err) {
48 /** returns the database persistent connection link.
49 * it's a shortname for $this->config['db']['link']
50 * @returns a mysql resource
52 function link() { return $this->config
['db']['link']; }
54 /** init the link to the database */
56 $this->config
['db']['link'] =
58 $this->config
['db']['host'],
59 $this->config
['db']['user'],
60 $this->config
['db']['pass']
62 mysql_select_db($this->config
['db']['name'], $this->link());
65 /** function that writes the procmailrc.
66 * @return true if all is ok
68 function write_procmailrc() {
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
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";
84 $index = 'match_plugins';
85 } elseif(is_subclass_of($_plugin, 'actionplugin')) {
86 $index = 'action_plugins';
88 $this->err
= "Philter::register_plugin : bad object";
92 if(isset($this->config
[$index][$rtti])) {
93 $this->err
= "Philter::register_plugin : a plugin is already registerd";
97 $this->config
[$index][$rtti] = $_plugin;
101 $this->err
= "Philter::register_plugin : rtti is 0, this is an abstract class";
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
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";
116 if(!$_plugin->is_global()) {
117 $this->err
= "Philter::register_global_plugin : this plugin is not global";
121 if(isset($this->config
['global_plugin'][$rtti])) {
122 $this->err
= "Philter::register_global_plugin : a plugin is already registerd";
126 $this->config
['global_plugin'][$rtti] = $_plugin;
130 $this->err
= "Philter::register_global_plugin : rtti is 0, this is an abstract class";
135 /********************************************************************************
137 * vim: set expandtab shiftwidth=4 tabstop=4 softtabstop=4 textwidth=100:
138 ********************************************************************************/