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()
35 /** returns the error.
36 * @return the error string
42 /** sets the error string.
45 function set_error($_err) {
49 /** returns the database persistent connection link.
50 * it's a shortname for $this->config['db']['link']
51 * @returns a mysql resource
53 function link() { return $this->config
['db']['link']; }
55 /** init the link to the database */
57 $this->config
['db']['link'] =
59 $this->config
['db']['host'],
60 $this->config
['db']['user'],
61 $this->config
['db']['pass']
63 mysql_select_db($this->config
['db']['name'], $this->link());
66 /** function that writes the procmailrc.
67 * @return true if all is ok
69 function write_procmailrc() {
74 /** function that register a new Plugin
75 * @param $_plugin an instance of the plugin
76 * @return true if all is ok, read error() else
78 function register_plugin($_plugin) {
79 if($rtti = $_plugin->rtti()) {
80 if(is_subclass_of($_plugin, 'matchplugin')) {
81 if($_plugin->is_global()) {
82 $this->err
= "Philter::register_plugin : this plugin is global";
85 $index = 'match_plugins';
86 } elseif(is_subclass_of($_plugin, 'actionplugin')) {
87 $index = 'action_plugins';
89 $this->err
= "Philter::register_plugin : bad object";
93 if(isset($this->config
[$index][$rtti])) {
94 $this->err
= "Philter::register_plugin : a plugin is already registerd";
98 $this->config
[$index][$rtti] = $_plugin;
102 $this->err
= "Philter::register_plugin : rtti is 0, this is an abstract class";
106 /** function that register plugin as a global rule
107 * @param $_plugin an instance of the plugin
108 * @return true if all is ok, read error() else
110 function register_global_plugin($_plugin) {
111 if($rtti = $_plugin->rtti()) {
112 if(!is_subclass_of($_plugin, 'matchplugin')) {
113 $this->err
= "Philter::register_global_plugin : bad object";
117 if(!$_plugin->is_global()) {
118 $this->err
= "Philter::register_global_plugin : this plugin is not global";
122 if(isset($this->config
['global_plugin'][$rtti])) {
123 $this->err
= "Philter::register_global_plugin : a plugin is already registerd";
127 $this->config
['global_plugin'][$rtti] = $_plugin;
131 $this->err
= "Philter::register_global_plugin : rtti is 0, this is an abstract class";
136 /********************************************************************************
138 * vim: set expandtab shiftwidth=4 tabstop=4 softtabstop=4 textwidth=100:
139 ********************************************************************************/