add an RSS feed to describe a barrel's recent changes
[diogenes.git] / include / Plugin / Skel.php
1 <?php
2 /*
3 * Copyright (C) 2003-2004 Polytechnique.org
4 * http://opensource.polytechnique.org/
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 // dependency on PEAR
22 require_once 'System.php';
23 require_once 'Tree/Node.php';
24
25 define('PLUG_DISABLED', 0);
26 define('PLUG_ACTIVE', 1);
27 define('PLUG_LOCK', 2);
28 define('PLUG_SET', 4);
29
30 /** Recursive stripslashes.
31 *
32 * @param $value
33 */
34 function stripslashes_recurse($value)
35 {
36 $value = is_array($value) ?
37 array_map('stripslashes_recurse', $value) :
38 stripslashes($value);
39 return $value;
40 }
41
42
43 /** This class describes a Diogenes plugin.
44 */
45 class Diogenes_Plugin_Skel {
46 /** Plugin type (object, filter) */
47 var $type = '';
48
49 /** Array of plugin parameters */
50 var $params = array();
51
52 /** Plugin name */
53 var $name = "Plugin_Skel";
54
55 /** Plugin description */
56 var $description = "Plugin skeleton";
57
58 /** Plugin version */
59 var $version = "0.1";
60
61 /** Position of the plugin */
62 var $pos = 0;
63
64 /** The plugin status (disabled, available, active) */
65 var $status = PLUG_DISABLED;
66
67 /** Is the plugin allowed with respect to a given write permission on a page ?
68 *
69 * @param $wperms
70 */
71 function allow_wperms($wperms)
72 {
73 return ($wperms != 'public');
74 }
75
76
77 /** Declare a plugin parameter.
78 */
79 function declareParam($key, $val)
80 {
81 $this->params[$key]['value'] = $val;
82 }
83
84
85 /** Return an array of parameter names.
86 */
87 function getParamNames()
88 {
89 return array_keys($this->params);
90 }
91
92
93 /** Return the value of a parameter of the plugin.
94 */
95 function getParamValue($key)
96 {
97 return isset($this->params[$key]['value']) ? $this->params[$key]['value'] : '';
98 }
99
100
101 /** Set the value of a parameter of the plugin.
102 */
103 function setParamValue($key, $val)
104 {
105 if (isset($this->params[$key]['value'])) {
106 $this->params[$key]['value'] = $val;
107 }
108 }
109
110
111 /** Erase parameters from database.
112 *
113 * @param $barrel
114 * @param $page
115 */
116 function eraseParameters($barrel = '', $page = 0)
117 {
118 global $globals;
119 //echo $this->name . " : eraseParams($barrel, $page)<br/>\n";
120 $globals->db->query("delete from diogenes_plugin where plugin='{$this->name}' and barrel='$barrel' and page='$page'");
121
122 unset($this->pos);
123 foreach ($this->getParamNames() as $key)
124 {
125 //echo "$this->name : erasing param<br/>\n";
126 $this->setParamValue($key, '');
127 }
128 }
129
130
131 /** Read parameters from an array.
132 */
133 function fromArray($plugentry)
134 {
135 $this->pos = $plugentry['pos'];
136 $this->status = $plugentry['status'];
137 foreach ($plugentry['params'] as $key => $val)
138 {
139 $this->setParamValue($key, $val['value']);
140 }
141 }
142
143
144 /** Store parameters to database.
145 *
146 * @param $barrel
147 * @param $page
148 * @param $pos
149 */
150 function toDatabase($barrel = '', $page = 0, $pos = 0)
151 {
152 global $globals;
153
154 $this->pos = $pos;
155 $params = var_encode_bin($this->params);
156 //echo "toDatabase called for '{$this->name}' in barrel '$barrel' (status : {$this->status}, params : '$params')<br/>";
157 $globals->db->query("replace into diogenes_plugin set plugin='{$this->name}', status='{$this->status}', barrel='$barrel', page='$page', pos='$pos', params='$params'");
158 }
159
160
161 /** Dump parameters to a table.
162 */
163 function toArray()
164 {
165 $plugentr = array();
166
167 // copy over properties
168 $props = array('status', 'name', 'params', 'description', 'version', 'type', 'pos');
169 foreach ($props as $prop)
170 {
171 $plugentr[$prop] = stripslashes_recurse($this->$prop);
172 }
173 return $plugentr;
174 }
175
176 }
177
178 ?>