7e8654675d506be156de6af1b2e27da8fcc0cc04
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';
24 /** Recursive stripslashes.
28 function stripslashes_recurse($value)
30 $value = is_array($value) ?
31 array_map('stripslashes_recurse', $value) :
37 /** This class describes a Diogenes plugin.
39 class Diogenes_Plugin_Skel
{
40 /** Plugin type (object, filter) */
43 /** Array of plugin parameters */
44 var $params = array();
47 var $name = "Plugin_Skel";
49 /** Plugin description */
50 var $description = "Plugin skeleton";
55 /** Position of the plugin */
58 /** Is the plugin active ? */
62 /** Is the plugin allowed with respect to a given write permission on a page ?
66 function allow_wperms($wperms)
68 return ($wperms != 'public');
72 /** Declare a plugin parameter.
74 function declareParam($key, $val)
76 $this->params
[$key] = $val;
80 /** Return an array of parameter names.
82 function getParamNames()
84 return array_keys($this->params
);
88 /** Return the value of a parameter of the plugin.
90 function getParamValue($key)
92 return isset($this->params
[$key]) ?
$this->params
[$key] : '';
96 /** Set the value of a parameter of the plugin.
98 function setParamValue($key, $val)
100 if (isset($this->params
[$key])) {
101 //echo "$this->name : Calling setParamValue($key, $val)<br/>\n";
102 $this->params
[$key] = $val;
104 //echo "$this->name : skipping setParamValue($key, $val)<br/>\n";
109 /** Set plugin parameters.
113 function setParams($params)
115 $bits = explode("\0", $params);
116 foreach ($bits as $bit)
118 $frags = explode("=", $bit, 2);
122 $val = isset($frags[1]) ?
$frags[1] : '';
123 $this->setParamValue($key, $val);
129 /** Erase parameters from database.
134 function eraseParams($barrel = '', $page = 0)
138 //echo $this->name . " : eraseParams($barrel, $page)<br/>\n";
139 $globals->db
->query("delete from diogenes_plugin where plugin='{$this->name}' and barrel='$barrel' and page='$page'");
143 foreach ($this->getParamNames() as $key)
145 //echo "$this->name : erasing param<br/>\n";
146 $this->setParamValue($key, '');
151 /** Store parameters to database.
157 function writeParams($barrel = '', $page = 0, $pos = 0)
165 foreach ($this->getParamNames() as $key)
167 $val = $this->getParamValue($key);
168 //echo "$this->name : $key = $val<br/>\n";
169 $params .= "$key=$val\0";
171 $globals->db
->query("replace into diogenes_plugin set plugin='{$this->name}', barrel='$barrel', page='$page', pos='$pos', params='$params'");
175 /** Dump parameters to a table.
181 // copy over properties
182 $props = array('active', 'name', 'params', 'description', 'version', 'type', 'pos');
183 foreach ($props as $prop)
185 if (isset($this->$prop))
187 $plugentr[$prop] = stripslashes_recurse($this->$prop);