X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2FPlugin%2FSkel.php;h=19c58a8b32f8d0f41fab743e88b5e8230dbd07ba;hb=079abc36d07da9049a0e1ae1878238a66d4d8bc8;hp=7e8654675d506be156de6af1b2e27da8fcc0cc04;hpb=b2c16bf312cd037e252e568974a5523407e42099;p=diogenes.git
diff --git a/include/Plugin/Skel.php b/include/Plugin/Skel.php
index 7e86546..19c58a8 100644
--- a/include/Plugin/Skel.php
+++ b/include/Plugin/Skel.php
@@ -20,6 +20,12 @@
// dependency on PEAR
require_once 'System.php';
+require_once 'Tree/Node.php';
+
+define('PLUG_DISABLED', 0);
+define('PLUG_ACTIVE', 1);
+define('PLUG_LOCK', 2);
+define('PLUG_SET', 4);
/** Recursive stripslashes.
*
@@ -38,7 +44,7 @@ function stripslashes_recurse($value)
*/
class Diogenes_Plugin_Skel {
/** Plugin type (object, filter) */
- var $type;
+ var $type = '';
/** Array of plugin parameters */
var $params = array();
@@ -53,12 +59,11 @@ class Diogenes_Plugin_Skel {
var $version = "0.1";
/** Position of the plugin */
- var $pos;
-
- /** Is the plugin active ? */
- var $active = 0;
-
+ var $pos = 0;
+ /** The plugin status (disabled, available, active) */
+ var $status = PLUG_DISABLED;
+
/** Is the plugin allowed with respect to a given write permission on a page ?
*
* @param $wperms
@@ -73,7 +78,7 @@ class Diogenes_Plugin_Skel {
*/
function declareParam($key, $val)
{
- $this->params[$key] = $val;
+ $this->params[$key]['value'] = $val;
}
@@ -89,56 +94,31 @@ class Diogenes_Plugin_Skel {
*/
function getParamValue($key)
{
- return isset($this->params[$key]) ? $this->params[$key] : '';
+ return isset($this->params[$key]['value']) ? $this->params[$key]['value'] : '';
}
-
-
+
+
/** Set the value of a parameter of the plugin.
*/
function setParamValue($key, $val)
{
- if (isset($this->params[$key])) {
- //echo "$this->name : Calling setParamValue($key, $val)
\n";
- $this->params[$key] = $val;
- } else {
- //echo "$this->name : skipping setParamValue($key, $val)
\n";
+ if (isset($this->params[$key]['value'])) {
+ $this->params[$key]['value'] = $val;
}
}
-
-
- /** Set plugin parameters.
- *
- * @param $params
- */
- function setParams($params)
- {
- $bits = explode("\0", $params);
- foreach ($bits as $bit)
- {
- $frags = explode("=", $bit, 2);
- $key = $frags[0];
- if (!empty($key))
- {
- $val = isset($frags[1]) ? $frags[1] : '';
- $this->setParamValue($key, $val);
- }
- }
- }
-
-
+
+
/** Erase parameters from database.
*
* @param $barrel
* @param $page
*/
- function eraseParams($barrel = '', $page = 0)
+ function eraseParameters($barrel = '', $page = 0)
{
global $globals;
-
//echo $this->name . " : eraseParams($barrel, $page)
\n";
$globals->db->query("delete from diogenes_plugin where plugin='{$this->name}' and barrel='$barrel' and page='$page'");
-
- $this->active = 0;
+
unset($this->pos);
foreach ($this->getParamNames() as $key)
{
@@ -146,50 +126,53 @@ class Diogenes_Plugin_Skel {
$this->setParamValue($key, '');
}
}
-
-
+
+
+ /** Read parameters from an array.
+ */
+ function fromArray($plugentry)
+ {
+ $this->pos = $plugentry['pos'];
+ $this->status = $plugentry['status'];
+ foreach ($plugentry['params'] as $key => $val)
+ {
+ $this->setParamValue($key, $val['value']);
+ }
+ }
+
+
/** Store parameters to database.
*
* @param $barrel
* @param $page
- * @param $pos
+ * @param $pos
*/
- function writeParams($barrel = '', $page = 0, $pos = 0)
+ function toDatabase($barrel = '', $page = 0, $pos = 0)
{
global $globals;
$this->pos = $pos;
- $this->active = 1;
-
- $params = '';
- foreach ($this->getParamNames() as $key)
- {
- $val = $this->getParamValue($key);
- //echo "$this->name : $key = $val
\n";
- $params .= "$key=$val\0";
- }
- $globals->db->query("replace into diogenes_plugin set plugin='{$this->name}', barrel='$barrel', page='$page', pos='$pos', params='$params'");
+ $params = var_encode_bin($this->params);
+ //echo "toDatabase called for '{$this->name}' in barrel '$barrel' (status : {$this->status}, params : '$params')
";
+ $globals->db->query("replace into diogenes_plugin set plugin='{$this->name}', status='{$this->status}', barrel='$barrel', page='$page', pos='$pos', params='$params'");
}
-
-
+
+
/** Dump parameters to a table.
*/
- function dump()
+ function toArray()
{
$plugentr = array();
// copy over properties
- $props = array('active', 'name', 'params', 'description', 'version', 'type', 'pos');
+ $props = array('status', 'name', 'params', 'description', 'version', 'type', 'pos');
foreach ($props as $prop)
{
- if (isset($this->$prop))
- {
- $plugentr[$prop] = stripslashes_recurse($this->$prop);
- }
- }
+ $plugentr[$prop] = stripslashes_recurse($this->$prop);
+ }
return $plugentr;
}
-
+
}
?>