more plugin fixups
authorJeremy Laine <jeremy.laine@m4x.org>
Sat, 20 May 2006 21:53:38 +0000 (21:53 +0000)
committerJeremy Laine <jeremy.laine@m4x.org>
Sat, 20 May 2006 21:53:38 +0000 (21:53 +0000)
include/Plugin/Editor.php
include/Plugin/Skel.php
include/Plugins.php
templates/plugin-editor.tpl

index f0b283d..e6006b8 100644 (file)
@@ -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    
index 0116d10..f457c5d 100644 (file)
@@ -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 ?
    *
index c2f4423..181db12 100644 (file)
@@ -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']})<br/>\n";
+      if ($plugentry['status'] & PLUG_ACTIVE)
+      {
+        //echo "cachedActive : adding $plugname<br/>\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 "<pre>".var_encode_text($p_node)."</pre>";
+    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']})<br/>\n";
+      if (!($plugentry['status'] & PLUG_LOCK) || !$barrel)
       {
+        //echo "cachedEditable : adding $plugname<br/>\n";
         $available[$plugname] = $plugentry;
-      }
+  //    }
     }
     return $available;
+*/
   }
 
 
@@ -180,20 +193,20 @@ class Diogenes_Plugins
     {
       //echo "Processing plugin '$plugin' for &lt;{$node->name}&gt;<br/>\n";
       $outval = '';
-      if ($parentval['status'] != PLUG_DISABLED)
+      if (($parentval['status'] & PLUG_ACTIVE) || !($parentval['status'] & PLUG_LOCK))
       {
-        //echo "* plugin available/enabled at parent level<br/>\n";
+        //echo "* plugin '$plugin' not locked off parent level<br/>\n";
         $outval = $parentval;
         if (is_array($node->data[$plugin]))
         {
           //echo "** plugin set at current level<br/>\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<br/>\n";
             $outval['status'] = $node->data[$plugin]['status'];
           } else {
-            //echo "*** plugin forced on at parent level<br/>\n";
+            $outval['status'] = $parentval['status'];
           }
         } else {
           //echo "** plugin unset at current level<br/>\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);
       }
     }
   }
index 2ab20de..dcccbbe 100644 (file)
 {foreach from=$plugins key=plugtype item=plugarr}
 <table class="light" style="width:80%">
 <tr>
-  <th colspan="3">{$plugtype} {$msg_plugedit_plugins}</th>
+  <th colspan="2">{$plugtype} {$msg_plugedit_plugins}</th>
 </tr>
 {foreach from=$plugarr item=plug}
 <tr class="odd">
-  <td style="width:30px"><img class="fileicon" src="{$plug.icon}"/>&nbsp;{$plug.name}&nbsp;v{$plug.version}
-  </td>
+  <td><img class="fileicon" src="{$plug.icon}"/>&nbsp;{$plug.name}&nbsp;v{$plug.version}</td>
   <td>
-{if !$readonly}
+{if $plug.readonly}
+    status {$plug.status}
+{else}
     <select name="{$plug.name}_status">{html_options options=$statusvals selected=$plug.status}</select>
     <a class="action"{if $plug.move_up}href="javascript:move_up('{$plug.name}');"{/if}>{$msg_move_up}</a>&nbsp;<a class="action"{if $plug.move_down}href="javascript:move_down('{$plug.name}');"{/if}>{$msg_move_down}</a>
 {/if}
   </td>
 </tr>
 <tr>
-{if $show_params}
   <td><div class="description">{$plug.description}</div></td>
-  <td colspan="2">
+  <td>
+{if $show_params}
     <table class="plugparams">
 {foreach from=$plug.params key=key item=val}
     <tr>
@@ -54,8 +55,8 @@
     </tr>
 {/foreach}
     </table>
+{/if}
   </td>
-{/if}  
 </tr>
 {/foreach}
 </table>