d6ae0759a814b31b4343f555da362e90f3c4f39c
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); }
13 function _i18n($_index) { global $philter; return $philter->i18n($_index); }
15 /** Philter base configuration class
16 * This is the base class of Philter.
19 /** philter configuration.
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(),
33 'global_plugins' => array(),
39 /** returns the i18n string
40 * @param $_index the index of the string
41 * @returns the string or false
43 function i18n($_index) {
44 if(isset($this->config
['i18n'][$_index]))
45 return $this->config
['i18n'][$_index];
49 /** returns the error.
50 * @return the error string
56 /** sets the error string.
59 function set_error($_err) {
63 /** returns the database persistent connection link.
64 * it's a shortname for $this->config['db']['link']
65 * @returns a mysql resource
67 function link() { return $this->config
['db']['link']; }
69 /** init the link to the database */
71 $this->config
['db']['link'] =
73 $this->config
['db']['host'],
74 $this->config
['db']['user'],
75 $this->config
['db']['pass']
77 mysql_select_db($this->config
['db']['name'], $this->link());
80 /** function that writes the procmailrc.
81 * @return true if all is ok
83 function write_procmailrc() {
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
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";
99 $index = 'match_plugins';
100 } elseif(is_subclass_of($_plugin, 'actionplugin')) {
101 $index = 'action_plugins';
103 $this->err
= "Philter::register_plugin : bad object";
107 if(isset($this->config
[$index][$rtti])) {
108 $this->err
= "Philter::register_plugin : a plugin is already registerd";
112 $this->config
[$index][$rtti] = $_plugin;
116 $this->err
= "Philter::register_plugin : rtti is 0, this is an abstract class";
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
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";
131 if(!$_plugin->is_global()) {
132 $this->err
= "Philter::register_global_plugin : this plugin is not global";
136 if(isset($this->config
['global_plugins'][$rtti])) {
137 $this->err
= "Philter::register_global_plugin : a plugin is already registerd";
141 $this->config
['global_plugins'][$rtti] = $_plugin;
145 $this->err
= "Philter::register_global_plugin : rtti is 0, this is an abstract class";
150 /********************************************************************************
152 * vim: set expandtab shiftwidth=4 tabstop=4 softtabstop=4 textwidth=100:
153 ********************************************************************************/