Commit | Line | Data |
---|---|---|
6855525e JL |
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'; | |
56aefc1e JL |
23 | require_once 'Tree/Node.php'; |
24 | ||
25 | define('PLUG_DISABLED', 0); | |
16e8fac2 JL |
26 | define('PLUG_ACTIVE', 1); |
27 | define('PLUG_LOCK', 2); | |
7aff44b2 | 28 | define('PLUG_SET', 4); |
6855525e JL |
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) */ | |
56aefc1e | 47 | var $type = ''; |
6855525e JL |
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 */ | |
56aefc1e | 62 | var $pos = 0; |
6855525e | 63 | |
56aefc1e | 64 | /** The plugin status (disabled, available, active) */ |
16e8fac2 | 65 | var $status = PLUG_DISABLED; |
7aff44b2 | 66 | |
6855525e JL |
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 | } | |
6855525e | 75 | |
b2c16bf3 JL |
76 | |
77 | /** Declare a plugin parameter. | |
78 | */ | |
79 | function declareParam($key, $val) | |
80 | { | |
7aff44b2 | 81 | $this->params[$key]['value'] = $val; |
b2c16bf3 JL |
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 | { | |
7aff44b2 | 97 | return isset($this->params[$key]['value']) ? $this->params[$key]['value'] : ''; |
b2c16bf3 | 98 | } |
56aefc1e JL |
99 | |
100 | ||
b2c16bf3 JL |
101 | /** Set the value of a parameter of the plugin. |
102 | */ | |
103 | function setParamValue($key, $val) | |
104 | { | |
7aff44b2 JL |
105 | if (isset($this->params[$key]['value'])) { |
106 | $this->params[$key]['value'] = $val; | |
b2c16bf3 JL |
107 | } |
108 | } | |
56aefc1e JL |
109 | |
110 | ||
6855525e JL |
111 | /** Erase parameters from database. |
112 | * | |
113 | * @param $barrel | |
114 | * @param $page | |
115 | */ | |
56aefc1e | 116 | function eraseParameters($barrel = '', $page = 0) |
6855525e JL |
117 | { |
118 | global $globals; | |
b2c16bf3 | 119 | //echo $this->name . " : eraseParams($barrel, $page)<br/>\n"; |
6855525e | 120 | $globals->db->query("delete from diogenes_plugin where plugin='{$this->name}' and barrel='$barrel' and page='$page'"); |
56aefc1e | 121 | |
6855525e | 122 | unset($this->pos); |
b2c16bf3 | 123 | foreach ($this->getParamNames() as $key) |
6855525e | 124 | { |
b2c16bf3 JL |
125 | //echo "$this->name : erasing param<br/>\n"; |
126 | $this->setParamValue($key, ''); | |
6855525e JL |
127 | } |
128 | } | |
56aefc1e JL |
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 | { | |
7aff44b2 | 139 | $this->setParamValue($key, $val['value']); |
56aefc1e JL |
140 | } |
141 | } | |
142 | ||
143 | ||
6855525e JL |
144 | /** Store parameters to database. |
145 | * | |
146 | * @param $barrel | |
147 | * @param $page | |
56aefc1e | 148 | * @param $pos |
6855525e | 149 | */ |
56aefc1e | 150 | function toDatabase($barrel = '', $page = 0, $pos = 0) |
6855525e JL |
151 | { |
152 | global $globals; | |
153 | ||
154 | $this->pos = $pos; | |
56aefc1e JL |
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'"); | |
6855525e | 158 | } |
56aefc1e JL |
159 | |
160 | ||
6855525e JL |
161 | /** Dump parameters to a table. |
162 | */ | |
56aefc1e | 163 | function toArray() |
6855525e JL |
164 | { |
165 | $plugentr = array(); | |
166 | ||
167 | // copy over properties | |
56aefc1e | 168 | $props = array('status', 'name', 'params', 'description', 'version', 'type', 'pos'); |
6855525e JL |
169 | foreach ($props as $prop) |
170 | { | |
56aefc1e JL |
171 | $plugentr[$prop] = stripslashes_recurse($this->$prop); |
172 | } | |
6855525e JL |
173 | return $plugentr; |
174 | } | |
56aefc1e | 175 | |
6855525e JL |
176 | } |
177 | ||
178 | ?> |