From: Jeremy Laine Date: Mon, 29 May 2006 07:09:37 +0000 (+0000) Subject: more work on the plugins system X-Git-Url: http://git.polytechnique.org/?p=diogenes.git;a=commitdiff_plain;h=7aff44b2a3193e43aedfd7bf7fc3801bcffcf3e0 more work on the plugins system --- diff --git a/Makefile b/Makefile index 5f230f2..9aa314b 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ # definitions -VERSION = 0.9.18.1 +VERSION = 0.9.19pre2 PKG_DIST = diogenes-$(VERSION) LIB_DIST = libdiogenes-$(VERSION) diff --git a/config/updatedb.php b/config/updatedb.php index c6f0be6..2e9a4a2 100755 --- a/config/updatedb.php +++ b/config/updatedb.php @@ -13,7 +13,7 @@ require_once("diogenes/diogenes.database-creator.inc.php"); class DiogenesDbInit extends DiogenesDatabaseCreator { /** database versions history */ - var $versions = array("0.9.9.3", "0.9.10", "0.9.12", "0.9.15", "0.9.16", "0.9.16+0.9.17pre15", "0.9.16+0.9.17pre19", "0.9.16+0.9.17pre21", "0.9.18+0.9.19pre1"); + var $versions = array("0.9.9.3", "0.9.10", "0.9.12", "0.9.15", "0.9.16", "0.9.16+0.9.17pre15", "0.9.16+0.9.17pre19", "0.9.16+0.9.17pre21", "0.9.18+0.9.19pre2"); /** * Upgrades the database from one version to the next @@ -214,11 +214,13 @@ class DiogenesDbInit extends DiogenesDatabaseCreator $this->dbh->query("INSERT INTO diogenes_logactions VALUES (16, 'page_plugins', 'the page plugins were modified');"); break; - case "0.9.18+0.9.19pre1": + case "0.9.18+0.9.19pre2": $this->info(" - adding 'status' field to 'diogenes_plugin' table"); $this->dbh->query("ALTER TABLE `diogenes_plugin` ADD `status` INT( 1 ) UNSIGNED NOT NULL default '0'"); - $this->dbh->query("update diogenes_plugin set status=1 where page=0"); - $this->dbh->query("update diogenes_plugin set status=2 where page!=0"); + $this->dbh->query("update diogenes_plugin set status=0 where page=0"); + $this->dbh->query("update diogenes_plugin set status=1 where page!=0"); + $this->info(" - removing 'pos' field to 'diogenes_plugin' table"); + $this->dbh->query("ALTER TABLE `diogenes_plugin` DROP `pos`"); break; default: diff --git a/htdocs/toplevel/plugins.php b/htdocs/toplevel/plugins.php index dee6ce2..e449f16 100644 --- a/htdocs/toplevel/plugins.php +++ b/htdocs/toplevel/plugins.php @@ -23,7 +23,7 @@ if ($barrel) /* plugin editor */ $editor = new Diogenes_Plugin_Editor($barrel, 0); -//$editor->hide_params(1); +$editor->set_mode(MODE_ROOT); $editor->run($page,'editor_content'); // translations diff --git a/include/Barrel.php b/include/Barrel.php index cc41014..aab8e3f 100644 --- a/include/Barrel.php +++ b/include/Barrel.php @@ -21,6 +21,7 @@ require_once 'Barrel/Page.php'; require_once 'Barrel/Options.php'; require_once 'diogenes/diogenes.flagset.inc.php'; +require_once 'Plugin/Skel.php'; /** This class describes a Diogenes Barrel. @@ -244,24 +245,6 @@ class Diogenes_Barrel } - /** List the plugins that are active in a given context - * - * @param $page - */ - function getPlugins($page = 0) - { - $plugins = array(); - foreach ($this->pluginsCache as $plug) - { - if ($plug['page'] == $page) - { - array_push($plugins, $plug); - } - } - return $plugins; - } - - /** Check whether the barrel has a given flag * * @param $flag @@ -326,7 +309,7 @@ class Diogenes_Barrel } - /** Load all plugins for the specified page. + /** Load all active plugins for the specified page. * * @param $bpage */ @@ -334,12 +317,11 @@ class Diogenes_Barrel { global $globals; - $plugins = $this->getPlugins($bpage->props['PID']); - + $plugins = $globals->plugins->cacheGetActive($this->pluginsCache, $this->alias, $page); $loaded = array(); - foreach ($plugins as $plugentry) + foreach ($plugins as $plugname => $plugentry) { - $loaded[$plugentry['plugin']] =& $globals->plugins->load($plugentry); + $loaded[$plugname] =& $globals->plugins->load($plugname, $plugentry); } return $loaded; } diff --git a/include/Barrel/Page.php b/include/Barrel/Page.php index d680bc4..baa9fcc 100644 --- a/include/Barrel/Page.php +++ b/include/Barrel/Page.php @@ -216,7 +216,7 @@ class Diogenes_Barrel_Page if ($props['PID']) { $cache = $globals->plugins->readCache($this->barrel->pluginsCacheFile, $this->barrel->alias); - $plugs_active = $globals->plugins->cachedActive($cache, $this->barrel->alias, $props['PID']); + $plugs_active = $globals->plugins->cacheGetActive($cache, $this->barrel->alias, $props['PID']); foreach($plugs_active as $plugentry) { $plug_h = $globals->plugins->load($plugentry); diff --git a/include/Plugin/Editor.php b/include/Plugin/Editor.php index d018ccf..22994db 100644 --- a/include/Plugin/Editor.php +++ b/include/Plugin/Editor.php @@ -21,16 +21,14 @@ // dependency on PEAR require_once 'System.php'; +define('MODE_NORMAL', 0); +define('MODE_ROOT', 1); +define('MODE_READONLY', 2); +define('MODE_NOPARAMS', 4); /** This class provides a configuration tool for Diogenes plugins. */ class Diogenes_Plugin_Editor { - /** Should we show plugins parameters? */ - var $show_params = 1; - - /** Should editing functions be disabled? */ - var $readonly = false; - /** The alias of the barrel we are working on. */ var $plug_barrel; @@ -39,6 +37,9 @@ class Diogenes_Plugin_Editor { /** The write permissions of the page we are working on. */ var $plug_page_wperms; + + /** The plugin editor mode */ + var $mode = MODE_NORMAL; /** Construct a new plugin editor. * @@ -73,40 +74,13 @@ class Diogenes_Plugin_Editor { $globals->plugins->compileCache($this->plug_barrel, $page); } $cache = $globals->plugins->readCache($cachefile, $this->plug_barrel); - $available = $globals->plugins->cachedVisible($cache, $this->plug_barrel, $this->plug_page); + $available = $globals->plugins->cacheGetVisible($cache, $this->plug_barrel, $this->plug_page); // handle updates $rebuild_cache = 0; switch ($action) { - case "move_up": case "move_down": - if ($this->readonly) die("Sorry, this plugin view is read-only."); - - $delta = ($action == "move_down") ? 1 : -1; - $page->info("moving plugin '$target'.."); - $plugcache_a = $globals->plugins->cacheGet($cache, $this->plug_barrel, $this->plug_page, $target); - $plug_a =& $globals->plugins->load($plugcache_a['name'], $plugcache_a); - - if (is_object($plug_a) && ($plug_a->active)) { - $old_pos = $plug_a->pos; - $plugcache_b = $globals->plugins->cacheGetAtPos($cache, $this->plug_barrel, $this->plug_page, $old_pos + $delta); - - if (is_array($plugcache_b)) - { - $plug_b =& $globals->plugins->load($plugcache_b['name'], $plugcache_b); - - // swap the current plugin and the next plugin - if (is_object($plug_b) && ($plug_b->active)) - { - $plug_a->toDatabase($this->plug_barrel, $this->plug_page, $old_pos + $delta); - $plug_b->toDatabase($this->plug_barrel, $this->plug_page, $old_pos); - } - } - } - $rebuild_cache = 1; - break; - case "update": - if ($this->readonly) die("Sorry, this plugin view is read-only."); + if ($this->mode & MODE_READONLY) die("Sorry, this plugin view is read-only."); foreach ($available as $plugin => $plugentry) { // check we have a valid cache entry @@ -136,7 +110,7 @@ class Diogenes_Plugin_Editor { // retrieve parameters from REQUEST if (isset($_REQUEST[$plug_h->name."_status"])) - { + { $plug_h->status = $_REQUEST[$plug_h->name."_status"]; } foreach ($plug_h->getParamNames() as $key) @@ -147,7 +121,12 @@ class Diogenes_Plugin_Editor { } // write parameters to database - $plug_h->toDatabase($this->plug_barrel, $this->plug_page, $pos); + if ($plug_h->status & PLUG_SET) + { + $plug_h->toDatabase($this->plug_barrel, $this->plug_page, $pos); + } else { + $plug_h->eraseParameters($this->plug_barrel, $his->plug_page); + } $rebuild_cache = 1; } } @@ -170,7 +149,7 @@ class Diogenes_Plugin_Editor { // rebuild plugin cache $globals->plugins->compileCache($this->plug_barrel, $page); $cache = $globals->plugins->readCache($cachefile, $this->plug_barrel); - $available = $globals->plugins->cachedVisible($cache, $this->plug_barrel, $this->plug_page); + $available = $globals->plugins->cacheGetVisible($cache, $this->plug_barrel, $this->plug_page); } // get dump of plugins to fill out form @@ -180,14 +159,19 @@ class Diogenes_Plugin_Editor { $rw_plugs_on = array(); $rw_plugs_off = array(); - // start by adding the active plugins + /* run over the plugins and split plugins into the following categories: + * - read-only, + * - read-write/active + * - read-write/inactive + */ foreach ($available as $plugname => $plugcache) { $plugentry = $plugcache; $plugentry['icon'] = $globals->icons->get_action_icon('plugins'); $type = $plugentry['type']; - if ($plugentry['status'] & PLUG_LOCK) + // FIXME : the test below needs to be refined + if (!($this->mode & MODE_ROOT) && ($plugentry['status'] & PLUG_LOCK)) { $o_plugs =& $ro_plugs; $plugentry['readonly'] = 1; @@ -198,19 +182,17 @@ class Diogenes_Plugin_Editor { $o_plugs =& $rw_plugs_off; } - if (!empty($o_plugs[$type])) { - $plugentry['move_up'] = 1; - $last = count($o_plugs[$type]) - 1; - $o_plugs[$type][$last]['move_down'] = 1; - } else { + if (empty($o_plugs[$type])) { $o_plugs[$type] = array(); } array_push($o_plugs[$type], $plugentry); } - // next we add the inactive plugins + // merge the different plugin categories into a global list $plugs = array_merge_recursive($rw_plugs_on, $rw_plugs_off); + $plugs = array_merge_recursive($plugs, $ro_plugs); $page->assign('plugins', $plugs); + // debugging foreach ($plugs as $p_type => $p_entries) { @@ -218,36 +200,42 @@ class Diogenes_Plugin_Editor { } // values - $page->assign('show_params', $this->show_params); - $page->assign('readonly',$this->readonly); - $statusvals = array(0 => 'off', 1 => 'on', 2 => 'off (lock)', 3 => 'on (lock)'); + $page->assign('show_params', !($this->mode & MODE_NOPARAMS)); + $page->assign('readonly', ($this->mode & MODE_READONLY)); + $statusvals = array( + PLUG_DISABLED => 'default', + PLUG_SET | PLUG_DISABLED => 'off', + PLUG_SET | PLUG_ACTIVE => 'on', + PLUG_SET | PLUG_DISABLED | PLUG_LOCK => 'off (lock)', + PLUG_SET | PLUG_ACTIVE | PLUG_LOCK => 'on (lock)', + ); + $rwstatusvals = $statusvals; + if (!($this->mode & MODE_ROOT)) { + unset($rwstatusvals[PLUG_SET | PLUG_DISABLED | PLUG_LOCK]); + unset($rwstatusvals[PLUG_SET | PLUG_ACTIVE | PLUG_LOCK]); + } $page->assign('statusvals', $statusvals); + $page->assign('rwstatusvals', $rwstatusvals); - // translations + // translations $page->assign('msg_submit', __("Submit")); - $page->assign('msg_plugedit_plugin', __("plugin")); + $page->assign('msg_plugedit_plugin', __("plugin")); $page->assign('msg_plugedit_plugins', __("plugins")); $page->assign('msg_plugedit_description', __("description")); $page->assign('msg_plugedit_parameters', __("parameters")); - $page->assign('msg_move_up', __("move up")); - $page->assign('msg_move_down', __("move down")); // if requested, assign the content to be displayed if (!empty($outputvar)) { $page->assign($outputvar, $page->fetch('plugin-editor.tpl')); } } - - - /** Do not display plugin parameters. - * - * @param $hide boolean + + /** Set the editor mode. */ - function hide_params($hide) + function set_mode($mode) { - $this->show_params = !$hide; + $this->mode = $mode; } - } ?> diff --git a/include/Plugin/Skel.php b/include/Plugin/Skel.php index f457c5d..19c58a8 100644 --- a/include/Plugin/Skel.php +++ b/include/Plugin/Skel.php @@ -25,6 +25,7 @@ require_once 'Tree/Node.php'; define('PLUG_DISABLED', 0); define('PLUG_ACTIVE', 1); define('PLUG_LOCK', 2); +define('PLUG_SET', 4); /** Recursive stripslashes. * @@ -62,7 +63,7 @@ class Diogenes_Plugin_Skel { /** 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 @@ -77,7 +78,7 @@ class Diogenes_Plugin_Skel { */ function declareParam($key, $val) { - $this->params[$key] = $val; + $this->params[$key]['value'] = $val; } @@ -93,7 +94,7 @@ 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'] : ''; } @@ -101,9 +102,8 @@ class Diogenes_Plugin_Skel { */ function setParamValue($key, $val) { - if (isset($this->params[$key])) { - $this->params[$key] = $val; - } else { + if (isset($this->params[$key]['value'])) { + $this->params[$key]['value'] = $val; } } @@ -136,7 +136,7 @@ class Diogenes_Plugin_Skel { $this->status = $plugentry['status']; foreach ($plugentry['params'] as $key => $val) { - $this->setParamValue($key, $val); + $this->setParamValue($key, $val['value']); } } diff --git a/include/Plugins.php b/include/Plugins.php index c998925..120e22c 100644 --- a/include/Plugins.php +++ b/include/Plugins.php @@ -61,6 +61,7 @@ class Diogenes_Plugins return $cachefile; } + /** Return the cache entry for specified plugin * * @param $cache @@ -75,27 +76,6 @@ class Diogenes_Plugins } - /** Return the cache entry for a plugin at a specified position - * - * @param $cache - * @param $barrel - * @param $page - * @param $pos - */ - function cacheGetAtPos($cache, $barrel, $page, $pos) - { - $p_node = $this->cacheGetPageNode($cache, $barrel, $page); - foreach ($p_node->data as $plugname => $plugentry) - { - if ($plugentry['pos'] == $pos) - { - $plugentry['plugin'] = $plugname; - return $plugentry; - } - } - } - - /** Return the cache entry for specified plugin * * @param $cache @@ -120,16 +100,16 @@ class Diogenes_Plugins * @param $barrel * @param $page */ - function cachedActive($cache, $barrel, $page) + function cacheGetActive($cache, $barrel, $page) { $p_node = $this->cacheGetPageNode($cache, $barrel, $page); $plugins = array(); foreach ($p_node->data as $plugname => $plugentry) { - //echo "cachedEditable : examining $plugname (status {$plugentry['status']})
\n"; + //echo "cacheGetActive : examining $plugname (status {$plugentry['status']})
\n"; if ($plugentry['status'] & PLUG_ACTIVE) { - //echo "cachedActive : adding $plugname
\n"; + //echo "cacheGetActive : adding $plugname
\n"; $plugins[$plugname] = $plugentry; } } @@ -144,23 +124,10 @@ class Diogenes_Plugins * @param $barrel * @param $page */ - function cachedVisible($cache, $barrel, $page) + function cacheGetVisible($cache, $barrel, $page) { $p_node = $this->cacheGetPageNode($cache, $barrel, $page); return $p_node->data; -/* - $available = array(); - foreach ($p_node->data as $plugname => $plugentry) - { - //echo "cachedEditable : examining $plugname (status {$plugentry['status']})
\n"; - if (!($plugentry['status'] & PLUG_LOCK) || !$barrel) - { - //echo "cachedEditable : adding $plugname
\n"; - $available[$plugname] = $plugentry; - // } - } - return $available; -*/ } @@ -197,10 +164,9 @@ class Diogenes_Plugins { //echo "* plugin '$plugin' not locked off parent level
\n"; $outval = $parentval; - if (is_array($node->data[$plugin])) + if ((is_array($node->data[$plugin])) && ($node->data[$plugin]['status'] & PLUG_SET)) { //echo "** plugin set at current level
\n"; - $outval['pos'] = $node->data[$plugin]['pos']; $outval['params'] = $node->data[$plugin]['params']; if (!($parentval['status'] & PLUG_LOCK)) { //echo "*** plugin status set to DB-specified value
\n"; @@ -262,7 +228,7 @@ class Diogenes_Plugins $dbcache = array(); $sql_limit = $barrel ? " where barrel='{$barrel}' or barrel=''" : ""; - $sql = "select barrel, page, plugin, status, pos, params from diogenes_plugin" . $sql_limit; + $sql = "select barrel, page, plugin, status, params from diogenes_plugin" . $sql_limit; $res = $this->dbh->query($sql); while($row = mysql_fetch_row($res)) { @@ -271,8 +237,7 @@ class Diogenes_Plugins $plugin = array_shift($row); $plugentry = array( 'status' => $row[0], - 'pos' => $row[1], - 'params' => ($row[2] ? var_decode_bin($row[2]) : array()) + 'params' => ($row[1] ? var_decode_bin($row[1]) : array()) ); $plug_h = $this->load($plugin, $plugentry); //echo "Got params from DB for '$plugin', barrel '$c_barrel', page '$c_page' : ".$row[2]."
"; @@ -373,9 +338,6 @@ class Diogenes_Plugins $trclass = $odd ? ' class="odd"' : ''; $out .= "{$val['name']} v{$val['version']}\n"; $out .= "status{$val['status']}\n"; - if (isset($val['pos'])) { - $out .= "position{$val['pos']}\n"; - } $out .= "type{$val['type']}\n"; $out .= "description{$val['description']}\n"; if (!empty($val['params'])) { diff --git a/include/Tree/Node.php b/include/Tree/Node.php index 9006ea7..2ff8edb 100644 --- a/include/Tree/Node.php +++ b/include/Tree/Node.php @@ -31,7 +31,7 @@ define('VAR_TYPE_NODE', 4); function var_encode_text($var, $level = 0, $no_children = FALSE, $tabstr = ' ', $eol = "\n") { - if (is_object($var) && (get_class($var) == 'Diogenes_Tree_Node')) { + if (is_object($var) && (strtolower(get_class($var)) == 'diogenes_tree_node')) { // node name $code = str_repeat($tabstr, $level) . "node : {$var->name}" . $eol; @@ -76,7 +76,7 @@ function var_encode_html($var, $level = 0, $no_children = FALSE) function var_encode_bin($var, $no_children = FALSE) { - if (is_object($var) && (get_class($var) == 'Diogenes_Tree_Node')) { + if (is_object($var) && (strtolower(get_class($var)) == 'diogenes_tree_node')) { $code = pack('C', VAR_TYPE_NODE); $code .= var_encode_bin($var->name); $code .= var_encode_bin($var->data); @@ -184,7 +184,7 @@ class Diogenes_Tree_Node { $bin = file_get_contents($filename); $node = var_decode_bin($bin); - if (!is_object($node) || get_class($node) != 'Diogenes_Tree_Node') + if (!is_object($node) || strtolower(get_class($node)) != 'diogenes_tree_node') { trigger_error('readFile : not a Diogenes_Tree_Node', E_USER_ERROR); } diff --git a/include/admin/plugins.php b/include/admin/plugins.php index c529c31..5ae4ae3 100644 --- a/include/admin/plugins.php +++ b/include/admin/plugins.php @@ -30,8 +30,7 @@ if ($dir != 0) /* plugin editor */ $editor = new Diogenes_Plugin_Editor($page->alias, $dir, $wperms); if ($dir == 0) { - $editor->readonly = 1; - $editor->hide_params(1); + $editor->set_mode(MODE_NOPARAMS); } $editor->run($page,'page_content'); $page->display(''); diff --git a/include/diogenes.barrel.inc.php b/include/diogenes.barrel.inc.php index d217a35..366caff 100644 --- a/include/diogenes.barrel.inc.php +++ b/include/diogenes.barrel.inc.php @@ -213,6 +213,7 @@ class DiogenesBarrel extends DiogenesPage $render_plugin = $plugobj; } } + // source page or pass it to a rendering plugin if (is_object($render_plugin)) { $content = $render_plugin->render($path); diff --git a/templates/plugin-editor.tpl b/templates/plugin-editor.tpl index dcccbbe..e5b485b 100644 --- a/templates/plugin-editor.tpl +++ b/templates/plugin-editor.tpl @@ -1,23 +1,4 @@ {if !$readonly} -{literal} - -{/literal} -
@@ -35,11 +16,10 @@  {$plug.name} v{$plug.version} -{if $plug.readonly} - status {$plug.status} +{if $readonly || $plug.readonly} + {$statusvals[$plug.status]} {else} - - {$msg_move_up} {$msg_move_down} + {/if} @@ -51,10 +31,12 @@ {foreach from=$plug.params key=key item=val} {$key} - + {/foreach} +{else} +   {/if}