obsolete
[old-projects.git] / philter / philter / include / philter.inc.php
CommitLineData
dd8de1ec
PH
1<?php
2/********************************************************************************
3* include/philter.inc.php : Philter base class
4* -----------------------
5*
6* This file is part of the philter distribution
7* Copyright: See COPYING files that comes with this distribution
8********************************************************************************/
9
10require_once("include/core.inc.php");
11
12/** Philter base configuration class
13 * This is the base class of Philter.
14 */
15class Philter {
16 /** philter configuration.
17 * @see config.inc.php
18 */
19 var $config;
20 /** error string */
21 var $err;
22
23 /** constructor */
24 function Philter() {
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(),
70944c71
PH
30 'global_plugin' => array(),
31 'i18n' => array()
dd8de1ec 32 );
4956445b 33 $this->err = "";
dd8de1ec
PH
34 }
35
70944c71
PH
36 /** returns the i18n string
37 * @param $_index the index of the string
38 * @returns the string or false
39 */
40 function i18n($_index) {
41 if(isset($this->confg[$_index]))
42 return $this->confg[$_index];
43 return false;
44 }
45
dd8de1ec
PH
46 /** returns the error.
47 * @return the error string
48 */
49 function error() {
50 return $this->err;
51 }
52
53 /** sets the error string.
54 * @return nothing
55 */
56 function set_error($_err) {
57 $this->err = $_err;
58 }
59
60 /** returns the database persistent connection link.
61 * it's a shortname for $this->config['db']['link']
62 * @returns a mysql resource
63 */
64 function link() { return $this->config['db']['link']; }
65
66 /** init the link to the database */
67 function pconnect() {
68 $this->config['db']['link'] =
69 mysql_pconnect(
70 $this->config['db']['host'],
71 $this->config['db']['user'],
72 $this->config['db']['pass']
73 );
74 mysql_select_db($this->config['db']['name'], $this->link());
75 }
76
77 /** function that writes the procmailrc.
78 * @return true if all is ok
79 */
80 function write_procmailrc() {
81 // TODO
82 return true;
83 }
84
85 /** function that register a new Plugin
86 * @param $_plugin an instance of the plugin
87 * @return true if all is ok, read error() else
88 */
89 function register_plugin($_plugin) {
90 if($rtti = $_plugin->rtti()) {
91 if(is_subclass_of($_plugin, 'matchplugin')) {
92 if($_plugin->is_global()) {
93 $this->err = "Philter::register_plugin : this plugin is global";
94 return false;
95 }
96 $index = 'match_plugins';
97 } elseif(is_subclass_of($_plugin, 'actionplugin')) {
98 $index = 'action_plugins';
99 } else {
100 $this->err = "Philter::register_plugin : bad object";
101 return false;
102 }
103
104 if(isset($this->config[$index][$rtti])) {
105 $this->err = "Philter::register_plugin : a plugin is already registerd";
106 return false;
107 }
108
109 $this->config[$index][$rtti] = $_plugin;
110 return true;
111 }
112
113 $this->err = "Philter::register_plugin : rtti is 0, this is an abstract class";
114 return false;
115 }
116
117 /** function that register plugin as a global rule
118 * @param $_plugin an instance of the plugin
119 * @return true if all is ok, read error() else
120 */
121 function register_global_plugin($_plugin) {
122 if($rtti = $_plugin->rtti()) {
123 if(!is_subclass_of($_plugin, 'matchplugin')) {
124 $this->err = "Philter::register_global_plugin : bad object";
125 return false;
126 }
127
128 if(!$_plugin->is_global()) {
129 $this->err = "Philter::register_global_plugin : this plugin is not global";
130 return false;
131 }
132
133 if(isset($this->config['global_plugin'][$rtti])) {
134 $this->err = "Philter::register_global_plugin : a plugin is already registerd";
135 return false;
136 }
137
138 $this->config['global_plugin'][$rtti] = $_plugin;
139 return true;
140 }
141
142 $this->err = "Philter::register_global_plugin : rtti is 0, this is an abstract class";
143 return false;
144 }
145}
146
147/********************************************************************************
148* $Id$
149* vim: set expandtab shiftwidth=4 tabstop=4 softtabstop=4 textwidth=100:
150********************************************************************************/
151?>