update options menu to for RSS feed options
[diogenes.git] / include / diogenes.barrel.inc.php
index 366caff..f9f1acb 100644 (file)
@@ -21,6 +21,7 @@
 
 require_once 'diogenes.page.inc.php';
 require_once 'Barrel.php';
+require_once 'Barrel/Menu.php';
 
 /** This class is used to display a page of a Diogenes barrel,
  *  that is an RCS-managed website with a virtual directory
@@ -313,6 +314,10 @@ class DiogenesBarrel extends DiogenesPage
     // favicon
     if ($bbarrel->options->favicon)
       array_push($this->head, '<link rel="icon" href="'.$this->urlSite("", $bbarrel->options->favicon).'" type="image/png" />');
+
+    // RSS feed
+    if ($bbarrel->options->feed_enable)
+      array_push($this->head, '<link rel="alternate" type="application/rss+xml" title="'.stripslashes($bbarrel->options->title).'" href="'.$this->urlSite("admin", "rss").'" />');
   }
 
 
@@ -353,73 +358,9 @@ class DiogenesBarrel extends DiogenesPage
     if (!isset($this->table_menu))
       return;
    
-    // try to figure out the current MID from the current PID
-    // and build filiation
-    $filiation = array();
-    $res = $this->dbh->query("select MID from {$this->table_menu} where PID='$PID'");
-    while (list($MID) = mysql_fetch_row($res))
-      $filiation = $this->menuToRoot($MID, $filiation);
-    mysql_free_result($res);
-
     // add the user-defined part of the menu
-    $this->menu = array_merge($this->menu,$this->menuRecurse(0,$filiation,0));
-  }
-
-
-  /** Return the filiation to get to the root element.
-   *
-   * @param MID
-   * @param path
-   */
-  function menuToRoot($MID, $path) {
-    /* add ourself to the path */
-    array_push($path,$MID);
-
-    if ($MID) {
-      /* recursion */
-      $res = $this->dbh->query("select MIDpere from {$this->table_menu} where MID=$MID");
-      list($MIDpere) = mysql_fetch_row($res);
-      mysql_free_result($res);
-
-      return $this->menuToRoot($MIDpere, $path);
-    } else {
-      /* termination */
-      return $path;
-    }
-  }
-
-
-  /** Recursively add menu entries
-   *
-   * @param MIDpere
-   * @param filiation
-   * @param level
-   */
-  function menuRecurse($MIDpere, $filiation, $level) {
-    // the produced output
-    $out = array();
-
-    $res = $this->dbh->query("select m.MID,m.title,m.link,m.PID ".
-                       "from {$this->table_menu} as m ".
-                       "where MIDpere=$MIDpere order by ordre");
-
-    while(list($mid,$title,$link,$pid) = mysql_fetch_row($res)) {
-      $location = $this->barrel->getLocation($pid);
-//      echo "pid : $pid, location : $location<br/>";
-      $title = stripslashes($title);
-      $entry = htmlentities(stripslashes($title), ENT_QUOTES);
-      $link = $pid ? $this->urlSite($location) : $link;      
-      // decide whether this menu should be expanded
-      $expanded = ($this->barrel->options->menu_min_level == 0) || 
-                  ($level+1 < $this->barrel->options->menu_min_level) || 
-                   in_array($mid, $filiation);
-      array_push($out, array($level, $entry, $link, $expanded));      
-      $out = array_merge($out, $this->menuRecurse($mid, $filiation, $level+1));
-    }
-
-    // free MySQL result and return output
-    mysql_free_result($res);
-    return $out;
+    $bmenu = new Diogenes_Barrel_Menu($this->dbh, $this->table_menu);
+    $this->menu = array_merge($this->menu, $bmenu->makeMenu($PID, $this->barrel->options->menu_min_level, array($this, 'urlSiteByPid')));
   }
 
 
@@ -469,7 +410,7 @@ class DiogenesBarrel extends DiogenesPage
     }
     return $path;
   }
+
 
   /** Returns the URL to one of the barrel's pages relative to
    *  the current location.
@@ -484,6 +425,18 @@ class DiogenesBarrel extends DiogenesPage
     return strlen($url) ? $url : "./";
   }
 
+
+  /** Returns the URL to one of the barrel's pages relative to
+   *  the current location.
+   *
+   * @param dir
+   * @param file
+   */
+  function urlSiteByPid($PID, $file = '')
+  {
+    return $this->urlSite($this->barrel->getLocation($PID), $file);
+  }
+
 }
 
 ?>