more work on the plugins system
[diogenes.git] / include / Plugins.php
index c2f4423..120e22c 100644 (file)
@@ -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
@@ -118,12 +98,21 @@ class Diogenes_Plugins
    *
    * @param $cache
    * @param $barrel
-   * @param $page   
+   * @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 "cacheGetActive : examining $plugname (status {$plugentry['status']})<br/>\n";
+      if ($plugentry['status'] & PLUG_ACTIVE)
+      {
+        //echo "cacheGetActive : adding $plugname<br/>\n";
+        $plugins[$plugname] = $plugentry;
+      }
+    }
     return $plugins;
   }
 
@@ -135,19 +124,10 @@ class Diogenes_Plugins
    * @param $barrel
    * @param $page
    */
-  function cachedAvailable($cache, $barrel, $page)
+  function cacheGetVisible($cache, $barrel, $page)
   {
     $p_node = $this->cacheGetPageNode($cache, $barrel, $page);
-    //echo "<pre>".var_encode_text($p_node)."</pre>";
-    foreach ($p_node->data as $plugname => $plugentry)
-    {
-      $plugfile = $this->plugdir."/".$plugname.".php";
-      if (file_exists($plugfile) and (!$barrel || ($plugentry['status'] != PLUG_DISABLED)))
-      {
-        $available[$plugname] = $plugentry;
-      }
-    }
-    return $available;
+    return $p_node->data;
   }
 
 
@@ -180,20 +160,19 @@ 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]))
+        if ((is_array($node->data[$plugin])) && ($node->data[$plugin]['status'] & PLUG_SET))
         {
           //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";
@@ -249,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))
     {
@@ -258,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]."<br/>";
@@ -295,12 +273,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);
       }
     }
   }
@@ -328,9 +308,6 @@ class Diogenes_Plugins
     if (is_array($plugentry))
       $plug_h->fromArray($plugentry);
 
-    $plug_log = $plug_h->toArray();
-    //$pluglog['name'] = 'foo';
-    array_push($this->log, $plug_log);
     return $plug_h;
   }
     
@@ -360,9 +337,7 @@ class Diogenes_Plugins
     {
       $trclass = $odd ? ' class="odd"' : '';
       $out .= "<tr><th colspan=\"2\">{$val['name']} v{$val['version']}</th></tr>\n";
-      if (isset($val['pos'])) {
-        $out .= "<tr><td>position</td><td>{$val['pos']}</td></tr>\n";
-      }
+      $out .= "<tr><td>status</td><td>{$val['status']}</td></tr>\n";
       $out .= "<tr$trclass><td>type</td><td>{$val['type']}</td></tr>\n";
       $out .= "<tr$trclass><td>description</td><td>{$val['description']}</td></tr>\n";
       if (!empty($val['params'])) {