3 * Copyright (C) 2003-2004 Polytechnique.org
4 * http://opensource.polytechnique.org/
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.
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.
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
22 require_once 'System.php';
23 require_once 'Tree/Node.php';
25 define('PLUG_DISABLED', 0);
26 define('PLUG_ACTIVE', 1);
27 define('PLUG_LOCK', 2);
28 define('PLUG_SET', 4);
30 /** Recursive stripslashes.
34 function stripslashes_recurse($value)
36 $value = is_array($value) ?
37 array_map('stripslashes_recurse', $value) :
43 /** This class describes a Diogenes plugin.
45 class Diogenes_Plugin_Skel
{
46 /** Plugin type (object, filter) */
49 /** Array of plugin parameters */
50 var $params = array();
53 var $name = "Plugin_Skel";
55 /** Plugin description */
56 var $description = "Plugin skeleton";
61 /** Position of the plugin */
64 /** The plugin status (disabled, available, active) */
65 var $status = PLUG_DISABLED
;
67 /** Is the plugin allowed with respect to a given write permission on a page ?
71 function allow_wperms($wperms)
73 return ($wperms != 'public');
77 /** Declare a plugin parameter.
79 function declareParam($key, $val)
81 $this->params
[$key]['value'] = $val;
85 /** Return an array of parameter names.
87 function getParamNames()
89 return array_keys($this->params
);
93 /** Return the value of a parameter of the plugin.
95 function getParamValue($key)
97 return isset($this->params
[$key]['value']) ?
$this->params
[$key]['value'] : '';
101 /** Set the value of a parameter of the plugin.
103 function setParamValue($key, $val)
105 if (isset($this->params
[$key]['value'])) {
106 $this->params
[$key]['value'] = $val;
111 /** Erase parameters from database.
116 function eraseParameters($barrel = '', $page = 0)
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'");
123 foreach ($this->getParamNames() as $key)
125 //echo "$this->name : erasing param<br/>\n";
126 $this->setParamValue($key, '');
131 /** Read parameters from an array.
133 function fromArray($plugentry)
135 $this->pos
= $plugentry['pos'];
136 $this->status
= $plugentry['status'];
137 foreach ($plugentry['params'] as $key => $val)
139 $this->setParamValue($key, $val['value']);
144 /** Store parameters to database.
150 function toDatabase($barrel = '', $page = 0, $pos = 0)
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'");
161 /** Dump parameters to a table.
167 // copy over properties
168 $props = array('status', 'name', 'params', 'description', 'version', 'type', 'pos');
169 foreach ($props as $prop)
171 $plugentr[$prop] = stripslashes_recurse($this->$prop);