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); | |
6855525e JL |
28 | |
29 | /** Recursive stripslashes. | |
30 | * | |
31 | * @param $value | |
32 | */ | |
33 | function stripslashes_recurse($value) | |
34 | { | |
35 | $value = is_array($value) ? | |
36 | array_map('stripslashes_recurse', $value) : | |
37 | stripslashes($value); | |
38 | return $value; | |
39 | } | |
40 | ||
41 | ||
42 | /** This class describes a Diogenes plugin. | |
43 | */ | |
44 | class Diogenes_Plugin_Skel { | |
45 | /** Plugin type (object, filter) */ | |
56aefc1e | 46 | var $type = ''; |
6855525e JL |
47 | |
48 | /** Array of plugin parameters */ | |
49 | var $params = array(); | |
50 | ||
51 | /** Plugin name */ | |
52 | var $name = "Plugin_Skel"; | |
53 | ||
54 | /** Plugin description */ | |
55 | var $description = "Plugin skeleton"; | |
56 | ||
57 | /** Plugin version */ | |
58 | var $version = "0.1"; | |
59 | ||
60 | /** Position of the plugin */ | |
56aefc1e | 61 | var $pos = 0; |
6855525e | 62 | |
56aefc1e | 63 | /** The plugin status (disabled, available, active) */ |
16e8fac2 | 64 | var $status = PLUG_DISABLED; |
6855525e JL |
65 | |
66 | /** Is the plugin allowed with respect to a given write permission on a page ? | |
67 | * | |
68 | * @param $wperms | |
69 | */ | |
70 | function allow_wperms($wperms) | |
71 | { | |
72 | return ($wperms != 'public'); | |
73 | } | |
6855525e | 74 | |
b2c16bf3 JL |
75 | |
76 | /** Declare a plugin parameter. | |
77 | */ | |
78 | function declareParam($key, $val) | |
79 | { | |
80 | $this->params[$key] = $val; | |
81 | } | |
82 | ||
83 | ||
84 | /** Return an array of parameter names. | |
85 | */ | |
86 | function getParamNames() | |
87 | { | |
88 | return array_keys($this->params); | |
89 | } | |
90 | ||
91 | ||
92 | /** Return the value of a parameter of the plugin. | |
93 | */ | |
94 | function getParamValue($key) | |
95 | { | |
96 | return isset($this->params[$key]) ? $this->params[$key] : ''; | |
97 | } | |
56aefc1e JL |
98 | |
99 | ||
b2c16bf3 JL |
100 | /** Set the value of a parameter of the plugin. |
101 | */ | |
102 | function setParamValue($key, $val) | |
103 | { | |
104 | if (isset($this->params[$key])) { | |
b2c16bf3 JL |
105 | $this->params[$key] = $val; |
106 | } else { | |
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 | { | |
139 | $this->setParamValue($key, $val); | |
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 | ?> |