e6006b8c3d35f436f8e174e71148cd1aa34b5de1
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';
25 /** This class provides a configuration tool for Diogenes plugins.
27 class Diogenes_Plugin_Editor
{
28 /** Should we show plugins parameters? */
31 /** Should editing functions be disabled? */
32 var $readonly = false
;
34 /** The alias of the barrel we are working on. */
37 /** The PID of the page we are working on. */
40 /** The write permissions of the page we are working on. */
41 var $plug_page_wperms;
43 /** Construct a new plugin editor.
47 * @param $plug_page_wperms
49 function Diogenes_Plugin_Editor($plug_barrel, $plug_page, $plug_page_wperms = '')
51 $this->plug_barrel
= $plug_barrel;
52 $this->plug_page
= $plug_page;
53 $this->plug_page_wperms
= $plug_page_wperms;
57 /** Run the plugin editor.
62 function run(&$page, $outputvar = '')
66 $action = isset($_REQUEST['action']) ?
$_REQUEST['action'] : '';
67 $target = isset($_REQUEST['plug_target']) ?
$_REQUEST['plug_target'] : '';
69 // if the tree cache does not exits try to init it
70 $cachefile = $globals->plugins
->cacheFile($this->plug_barrel
);
71 if(!file_exists($cachefile))
73 $globals->plugins
->compileCache($this->plug_barrel
, $page);
75 $cache = $globals->plugins
->readCache($cachefile, $this->plug_barrel
);
76 $available = $globals->plugins
->cachedVisible($cache, $this->plug_barrel
, $this->plug_page
);
81 case "move_up": case "move_down":
82 if ($this->readonly
) die("Sorry, this plugin view is read-only.");
84 $delta = ($action == "move_down") ?
1 : -1;
85 $page->info("moving plugin '$target'..");
86 $plugcache_a = $globals->plugins
->cacheGet($cache, $this->plug_barrel
, $this->plug_page
, $target);
87 $plug_a =& $globals->plugins
->load($plugcache_a['name'], $plugcache_a);
89 if (is_object($plug_a) && ($plug_a->active
)) {
90 $old_pos = $plug_a->pos
;
91 $plugcache_b = $globals->plugins
->cacheGetAtPos($cache, $this->plug_barrel
, $this->plug_page
, $old_pos +
$delta);
93 if (is_array($plugcache_b))
95 $plug_b =& $globals->plugins
->load($plugcache_b['name'], $plugcache_b);
97 // swap the current plugin and the next plugin
98 if (is_object($plug_b) && ($plug_b->active
))
100 $plug_a->toDatabase($this->plug_barrel
, $this->plug_page
, $old_pos +
$delta);
101 $plug_b->toDatabase($this->plug_barrel
, $this->plug_page
, $old_pos);
109 if ($this->readonly
) die("Sorry, this plugin view is read-only.");
110 foreach ($available as $plugin => $plugentry)
112 // check we have a valid cache entry
113 if (!is_array($plugentry)) {
114 $page->info("could not find plugin '$plugin' in cache for barrel '{$this->plug_barrel}'");
118 $plug_h =& $globals->plugins
->load($plugin, $plugentry);
119 if (!is_object($plug_h)) {
120 $page->info("could not load plugin '$plugin' in cache for barrel '{$this->plug_barrel}'");
124 if ($pos !== false
) {
125 // check the plugin is allowed in the current context
126 if ($this->plug_barrel
and $this->plug_page
) {
127 $wperms = $this->plug_page_wperms
;
129 // $page->info("checking plugin '$plugin' vs. write permissions '$wperms'..");
130 if (!$plug_h->allow_wperms($wperms))
132 $page->info("plugin '$plugin' is not allowed with write permissions '$wperms'!");
137 // retrieve parameters from REQUEST
138 if (isset($_REQUEST[$plug_h->name
."_status"]))
140 $plug_h->status
= $_REQUEST[$plug_h->name
."_status"];
142 foreach ($plug_h->getParamNames() as $key)
144 if (isset($_REQUEST[$plug_h->name
."_".$key])) {
145 $plug_h->setParamValue($key, $_REQUEST[$plug_h->name
."_".$key]);
149 // write parameters to database
150 $plug_h->toDatabase($this->plug_barrel
, $this->plug_page
, $pos);
157 // if necessary, rebuild the plugin cache
161 if ($this->plug_barrel
)
163 if ($this->plug_page
)
165 $page->log('page_plugins', $this->plug_barrel
.":".$this->plug_page
);
167 $page->log('barrel_plugins', $this->plug_barrel
.":*");
170 // rebuild plugin cache
171 $globals->plugins
->compileCache($this->plug_barrel
, $page);
172 $cache = $globals->plugins
->readCache($cachefile, $this->plug_barrel
);
173 $available = $globals->plugins
->cachedVisible($cache, $this->plug_barrel
, $this->plug_page
);
176 // get dump of plugins to fill out form
177 $page->assign('plug_barrel', $this->plug_barrel
);
178 $page->assign('plug_page', $this->plug_page
);
180 $rw_plugs_on = array();
181 $rw_plugs_off = array();
183 // start by adding the active plugins
184 foreach ($available as $plugname => $plugcache)
186 $plugentry = $plugcache;
187 $plugentry['icon'] = $globals->icons
->get_action_icon('plugins');
188 $type = $plugentry['type'];
190 if ($plugentry['status'] & PLUG_LOCK
)
192 $o_plugs =& $ro_plugs;
193 $plugentry['readonly'] = 1;
195 if ($plugentry['status'] & PLUG_ACTIVE
)
196 $o_plugs =& $rw_plugs_on;
198 $o_plugs =& $rw_plugs_off;
201 if (!empty($o_plugs[$type])) {
202 $plugentry['move_up'] = 1;
203 $last = count($o_plugs[$type]) - 1;
204 $o_plugs[$type][$last]['move_down'] = 1;
206 $o_plugs[$type] = array();
208 array_push($o_plugs[$type], $plugentry);
211 // next we add the inactive plugins
212 $plugs = array_merge_recursive($rw_plugs_on, $rw_plugs_off);
213 $page->assign('plugins', $plugs);
216 $page->assign('show_params', $this->show_params
);
217 $page->assign('readonly',$this->readonly
);
218 $statusvals = array(0 => 'off', 1 => 'on', 2 => 'off (lock)', 3 => 'on (lock)');
219 $page->assign('statusvals', $statusvals);
222 $page->assign('msg_submit', __("Submit"));
223 $page->assign('msg_plugedit_plugin', __("plugin"));
224 $page->assign('msg_plugedit_plugins', __("plugins"));
225 $page->assign('msg_plugedit_description', __("description"));
226 $page->assign('msg_plugedit_parameters', __("parameters"));
227 $page->assign('msg_move_up', __("move up"));
228 $page->assign('msg_move_down', __("move down"));
230 // if requested, assign the content to be displayed
231 if (!empty($outputvar)) {
232 $page->assign($outputvar, $page->fetch('plugin-editor.tpl'));
237 /** Do not display plugin parameters.
239 * @param $hide boolean
241 function hide_params($hide)
243 $this->show_params
= !$hide;