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 function set_advanced() { $_SESSION['philter_adv'] = true
; }
40 function del_advanced() { unset($_SESSION['philter_adv']); }
41 function is_advanced() { return isset($_SESSION['philter_adv']); }
43 /** returns the i18n string
44 * @param $_index the index of the string
45 * @returns the string or false
47 function i18n($_index) {
48 if(isset($this->config
['i18n'][$_index]))
49 return $this->config
['i18n'][$_index];
53 /** returns the error.
54 * @return the error string
60 /** sets the error string.
63 function set_error($_err) {
67 /** returns the database persistent connection link.
68 * it's a shortname for $this->config['db']['link']
69 * @returns a mysql resource
71 function link() { return $this->config
['db']['link']; }
73 /** init the link to the database */
75 $this->config
['db']['link'] =
77 $this->config
['db']['host'],
78 $this->config
['db']['user'],
79 $this->config
['db']['pass']
81 mysql_select_db($this->config
['db']['name'], $this->link());
84 /** function that writes the procmailrc.
85 * @return true if all is ok
87 function write_procmailrc() {
92 /** function that register a new Plugin
93 * @param $_plugin an instance of the plugin
94 * @return true if all is ok, read error() else
96 function register_plugin($_plugin) {
97 if($rtti = $_plugin->rtti()) {
98 if(is_subclass_of($_plugin, 'matchplugin')) {
99 if($_plugin->is_global()) {
100 $this->err
= "Philter::register_plugin : this plugin is global";
103 $index = 'match_plugins';
104 } elseif(is_subclass_of($_plugin, 'actionplugin')) {
105 $index = 'action_plugins';
107 $this->err
= "Philter::register_plugin : bad object";
111 if(isset($this->config
[$index][$rtti])) {
112 $this->err
= "Philter::register_plugin : a plugin is already registerd";
116 $this->config
[$index][$rtti] = $_plugin;
120 $this->err
= "Philter::register_plugin : rtti is 0, this is an abstract class";
124 /** function that register plugin as a global rule
125 * @param $_plugin an instance of the plugin
126 * @return true if all is ok, read error() else
128 function register_global_plugin($_plugin) {
129 if($rtti = $_plugin->rtti()) {
130 if(!is_subclass_of($_plugin, 'matchplugin')) {
131 $this->err
= "Philter::register_global_plugin : bad object";
135 if(!$_plugin->is_global()) {
136 $this->err
= "Philter::register_global_plugin : this plugin is not global";
140 if(isset($this->config
['global_plugins'][$rtti])) {
141 $this->err
= "Philter::register_global_plugin : a plugin is already registerd";
145 $this->config
['global_plugins'][$rtti] = $_plugin;
149 $this->err
= "Philter::register_global_plugin : rtti is 0, this is an abstract class";
154 /********************************************************************************
156 * vim: set expandtab shiftwidth=4 tabstop=4 softtabstop=4 textwidth=100:
157 ********************************************************************************/