From 16e8fac27cb4f25e8fcfcb30358d5486b4d8f809 Mon Sep 17 00:00:00 2001 From: Jeremy Laine Date: Sat, 20 May 2006 21:53:38 +0000 Subject: [PATCH] more plugin fixups --- include/Plugin/Editor.php | 64 ++++++++++++++++++++------------------------- include/Plugin/Skel.php | 6 ++--- include/Plugins.php | 35 ++++++++++++++++++------- templates/plugin-editor.tpl | 15 ++++++----- 4 files changed, 64 insertions(+), 56 deletions(-) diff --git a/include/Plugin/Editor.php b/include/Plugin/Editor.php index f0b283d..e6006b8 100644 --- a/include/Plugin/Editor.php +++ b/include/Plugin/Editor.php @@ -66,16 +66,14 @@ class Diogenes_Plugin_Editor { $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : ''; $target = isset($_REQUEST['plug_target']) ? $_REQUEST['plug_target'] : ''; - // load all available plugins - $cachefile = $globals->plugins->cacheFile($this->plug_barrel); - // if the tree cache does not exits try to init it + $cachefile = $globals->plugins->cacheFile($this->plug_barrel); if(!file_exists($cachefile)) { $globals->plugins->compileCache($this->plug_barrel, $page); } $cache = $globals->plugins->readCache($cachefile, $this->plug_barrel); - $available = $globals->plugins->cachedAvailable($cache, $this->plug_barrel, $this->plug_page); + $available = $globals->plugins->cachedVisible($cache, $this->plug_barrel, $this->plug_page); // handle updates $rebuild_cache = 0; @@ -172,58 +170,52 @@ 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->cachedAvailable($cache, $this->plug_barrel, $this->plug_page); + $available = $globals->plugins->cachedVisible($cache, $this->plug_barrel, $this->plug_page); } // get dump of plugins to fill out form $page->assign('plug_barrel', $this->plug_barrel); $page->assign('plug_page', $this->plug_page); - $plugs = array(); + $ro_plugs = array(); + $rw_plugs_on = array(); + $rw_plugs_off = array(); // start by adding the active plugins foreach ($available as $plugname => $plugcache) { - if ($plugcache['status'] == PLUG_ACTIVE) + $plugentry = $plugcache; + $plugentry['icon'] = $globals->icons->get_action_icon('plugins'); + $type = $plugentry['type']; + + if ($plugentry['status'] & PLUG_LOCK) { - $plugentry = $plugcache; - $plugentry['icon'] = $globals->icons->get_action_icon('plugins'); - $type = $plugentry['type']; - if (!empty($plugs[$type])) { - $plugentry['move_up'] = 1; - $last = count($plugs[$type]) - 1; - $plugs[$type][$last]['move_down'] = 1; - } else { - $plugs[$type] = array(); - } - array_push($plugs[$type], $plugentry); + $o_plugs =& $ro_plugs; + $plugentry['readonly'] = 1; + } else { + if ($plugentry['status'] & PLUG_ACTIVE) + $o_plugs =& $rw_plugs_on; + else + $o_plugs =& $rw_plugs_off; } - } - // next we add the inactive plugins - if (!$this->readonly) - { - foreach ($available as $plugname => $plugcache) - { - if ( ($plugcache['status'] == PLUG_AVAILABLE) || - (($plugcache['status'] == PLUG_DISABLED) && !$this->plug_barrel) ) - { - $plugentry = $plugcache; - $plugentry['icon'] = $globals->icons->get_action_icon('plugins'); - $type = $plugentry['type']; - if (empty($plugs[$type])) { - $plugs[$type] = array(); - } - array_push($plugs[$type], $plugentry); - } + if (!empty($o_plugs[$type])) { + $plugentry['move_up'] = 1; + $last = count($o_plugs[$type]) - 1; + $o_plugs[$type][$last]['move_down'] = 1; + } else { + $o_plugs[$type] = array(); } + array_push($o_plugs[$type], $plugentry); } + // next we add the inactive plugins + $plugs = array_merge_recursive($rw_plugs_on, $rw_plugs_off); $page->assign('plugins', $plugs); // values $page->assign('show_params', $this->show_params); $page->assign('readonly',$this->readonly); - $statusvals = array(0 => 'disabled', '1' => 'available', 2 => 'enabled'); + $statusvals = array(0 => 'off', 1 => 'on', 2 => 'off (lock)', 3 => 'on (lock)'); $page->assign('statusvals', $statusvals); // translations diff --git a/include/Plugin/Skel.php b/include/Plugin/Skel.php index 0116d10..f457c5d 100644 --- a/include/Plugin/Skel.php +++ b/include/Plugin/Skel.php @@ -23,8 +23,8 @@ require_once 'System.php'; require_once 'Tree/Node.php'; define('PLUG_DISABLED', 0); -define('PLUG_AVAILABLE', 1); -define('PLUG_ACTIVE', 2); +define('PLUG_ACTIVE', 1); +define('PLUG_LOCK', 2); /** Recursive stripslashes. * @@ -61,7 +61,7 @@ class Diogenes_Plugin_Skel { var $pos = 0; /** The plugin status (disabled, available, active) */ - var $status = PLUG_AVAILABLE; + var $status = PLUG_DISABLED; /** Is the plugin allowed with respect to a given write permission on a page ? * diff --git a/include/Plugins.php b/include/Plugins.php index c2f4423..181db12 100644 --- a/include/Plugins.php +++ b/include/Plugins.php @@ -118,12 +118,21 @@ class Diogenes_Plugins * * @param $cache * @param $barrel - * @param $page + * @param $page */ function cachedActive($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"; + if ($plugentry['status'] & PLUG_ACTIVE) + { + //echo "cachedActive : adding $plugname
\n"; + $plugins[$plugname] = $plugentry; + } + } return $plugins; } @@ -135,19 +144,23 @@ class Diogenes_Plugins * @param $barrel * @param $page */ - function cachedAvailable($cache, $barrel, $page) + function cachedVisible($cache, $barrel, $page) { $p_node = $this->cacheGetPageNode($cache, $barrel, $page); - //echo "
".var_encode_text($p_node)."
"; + return $p_node->data; +/* + $available = array(); foreach ($p_node->data as $plugname => $plugentry) { - $plugfile = $this->plugdir."/".$plugname.".php"; - if (file_exists($plugfile) and (!$barrel || ($plugentry['status'] != PLUG_DISABLED))) + //echo "cachedEditable : examining $plugname (status {$plugentry['status']})
\n"; + if (!($plugentry['status'] & PLUG_LOCK) || !$barrel) { + //echo "cachedEditable : adding $plugname
\n"; $available[$plugname] = $plugentry; - } + // } } return $available; +*/ } @@ -180,20 +193,20 @@ class Diogenes_Plugins { //echo "Processing plugin '$plugin' for <{$node->name}>
\n"; $outval = ''; - if ($parentval['status'] != PLUG_DISABLED) + if (($parentval['status'] & PLUG_ACTIVE) || !($parentval['status'] & PLUG_LOCK)) { - //echo "* plugin available/enabled at parent level
\n"; + //echo "* plugin '$plugin' not locked off parent level
\n"; $outval = $parentval; if (is_array($node->data[$plugin])) { //echo "** plugin set at current level
\n"; $outval['pos'] = $node->data[$plugin]['pos']; $outval['params'] = $node->data[$plugin]['params']; - if ($parentval['status'] == PLUG_AVAILABLE) { + if (!($parentval['status'] & PLUG_LOCK)) { //echo "*** plugin status set to DB-specified value
\n"; $outval['status'] = $node->data[$plugin]['status']; } else { - //echo "*** plugin forced on at parent level
\n"; + $outval['status'] = $parentval['status']; } } else { //echo "** plugin unset at current level
\n"; @@ -295,12 +308,14 @@ class Diogenes_Plugins if ($barrel) { $dump_node = $globals_out_node->getChild($barrel); $dump_node->writeFile($this->cachefile($barrel)); + $dump_node->writeFile($this->cachefile($barrel).".txt", NODE_DUMP_TEXT); } else { $globals_out_node->writeFile($this->cachefile($barrel), NODE_DUMP_NOCHILDREN); $globals_out_node->writeFile($this->cachefile($barrel).".txt", NODE_DUMP_NOCHILDREN | NODE_DUMP_TEXT); foreach ($globals_out_node->children as $c_barrel => $dump_node) { $dump_node->writeFile($this->cachefile($c_barrel)); + $dump_node->writeFile($this->cachefile($c_barrel).".txt", NODE_DUMP_TEXT); } } } diff --git a/templates/plugin-editor.tpl b/templates/plugin-editor.tpl index 2ab20de..dcccbbe 100644 --- a/templates/plugin-editor.tpl +++ b/templates/plugin-editor.tpl @@ -29,23 +29,24 @@ {foreach from=$plugins key=plugtype item=plugarr} - + {foreach from=$plugarr item=plug} - + -{if $show_params} - -{/if} {/foreach}
{$plugtype} {$msg_plugedit_plugins}{$plugtype} {$msg_plugedit_plugins}
 {$plug.name} v{$plug.version} -  {$plug.name} v{$plug.version} -{if !$readonly} +{if $plug.readonly} + status {$plug.status} +{else} {$msg_move_up} {$msg_move_down} {/if}
{$plug.description}
+ +{if $show_params} {foreach from=$plug.params key=key item=val} @@ -54,8 +55,8 @@ {/foreach}
+{/if}
-- 2.1.4