add 'scripts' directory
[diogenes.git] / include / Plugin / Skel.php
... / ...
CommitLineData
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
22require_once 'System.php';
23
24/** Recursive stripslashes.
25 *
26 * @param $value
27 */
28function stripslashes_recurse($value)
29{
30 $value = is_array($value) ?
31 array_map('stripslashes_recurse', $value) :
32 stripslashes($value);
33 return $value;
34}
35
36
37/** This class describes a Diogenes plugin.
38 */
39class Diogenes_Plugin_Skel {
40 /** Plugin type (object, filter) */
41 var $type;
42
43 /** Array of plugin parameters */
44 var $params = array();
45
46 /** Plugin name */
47 var $name = "Plugin_Skel";
48
49 /** Plugin description */
50 var $description = "Plugin skeleton";
51
52 /** Plugin version */
53 var $version = "0.1";
54
55 /** Position of the plugin */
56 var $pos;
57
58 /** Is the plugin active ? */
59 var $active = 0;
60
61
62 /** Is the plugin allowed with respect to a given write permission on a page ?
63 *
64 * @param $wperms
65 */
66 function allow_wperms($wperms)
67 {
68 return ($wperms != 'public');
69 }
70
71
72 /** Set plugin parameters.
73 *
74 * @param $params
75 */
76 function setParams($params)
77 {
78 $bits = explode("\0", $params);
79 foreach ($bits as $bit)
80 {
81 $frags = explode("=", $bit, 2);
82 $key = $frags[0];
83 $val = isset($frags[1]) ? $frags[1] : '';
84 if (isset($this->params[$key])) {
85 $this->params[$key] = $val;
86 }
87 }
88 }
89
90
91 /** Erase parameters from database.
92 *
93 * @param $barrel
94 * @param $page
95 */
96 function eraseParams($barrel = '', $page = 0)
97 {
98 global $globals;
99
100 //echo $this->name . " : deleteParams($barrel, $page)<br/>\n";
101 $globals->db->query("delete from diogenes_plugin where plugin='{$this->name}' and barrel='$barrel' and page='$page'");
102
103 $this->active = 0;
104 unset($this->pos);
105 foreach ($this->params as $key => $val)
106 {
107 $this->params[$key] = '';
108 }
109 }
110
111
112 /** Store parameters to database.
113 *
114 * @param $barrel
115 * @param $page
116 * @param $pos
117 */
118 function writeParams($barrel = '', $page = 0, $pos = 0)
119 {
120 global $globals;
121
122 $this->pos = $pos;
123 $this->active = 1;
124
125 $params = '';
126 foreach ($this->params as $key => $val)
127 {
128 //echo $this->name . " $key=$val<br/>";
129 $params .= "$key=$val\0";
130 }
131 $globals->db->query("replace into diogenes_plugin set plugin='{$this->name}', barrel='$barrel', page='$page', pos='$pos', params='$params'");
132 }
133
134
135 /** Dump parameters to a table.
136 */
137 function dump()
138 {
139 $plugentr = array();
140
141 // copy over properties
142 $props = array('active', 'name', 'params', 'description', 'version', 'type', 'pos');
143 foreach ($props as $prop)
144 {
145 if (isset($this->$prop))
146 {
147 $plugentr[$prop] = stripslashes_recurse($this->$prop);
148 }
149 }
150 return $plugentr;
151 }
152
153}
154
155?>