uw Thu Mar 22 10:38:33 2001 EDT Modified files: /php4/pear/Experimental/HTML Menu_Browser.php Log: Finished it, works for me. Index: php4/pear/Experimental/HTML/Menu_Browser.php diff -u php4/pear/Experimental/HTML/Menu_Browser.php:1.1 php4/pear/Experimental/HTML/Menu_Browser.php:1.2 --- php4/pear/Experimental/HTML/Menu_Browser.php:1.1 Tue Mar 20 15:45:31 2001 +++ php4/pear/Experimental/HTML/Menu_Browser.php Thu Mar 22 10:38:32 2001 @@ -16,16 +16,36 @@ // | Authors: Ulf Wendel <[EMAIL PROTECTED]> | // +----------------------------------------------------------------------+ // -// $Id: Menu_Browser.php,v 1.1 2001/03/20 23:45:31 uw Exp $ +// $Id: Menu_Browser.php,v 1.2 2001/03/22 18:38:32 uw Exp $ /** -* Simple filesystem browser that can be used to generated menu (3) hashes. +* Simple filesystem browser that can be used to generated menu (3) hashes based on +the directory structure. * -* Together with menu (3) you can use this browser to generate simple -* fusebox like systems. +* Together with menu (3) and the (userland) cache you can use this +* browser to generate simple fusebox like applications / content systems. * +* Let the menubrowser scan your document root and generate a menu (3) structure +* hash which maps the directory structure, pass it to menu's setMethod() and +optionally +* wrap the cache around all this to save script runs. If you do so, it looks +* like this: +* +* // document root directory +* define("DOC_ROOT", "/home/server/www.example.com/"); +* +* // instantiate the menubrowser +* $browser = new menubrowser(DOC_ROOT); +* +* // instantiate menu (3) +* $menu = new menu($browser->getMenu()); +* +* // output the sitemap +* $menu->show("sitemap"); +* +* Now, use e.g. simple XML files to store your content and additional menu +informations +* (title!). Subclass exploreFile() depending on your file format. +* * @author Ulf Wendel <[EMAIL PROTECTED]> -* @version $Id: Menu_Browser.php,v 1.1 2001/03/20 23:45:31 uw Exp $ +* @version $Id: Menu_Browser.php,v 1.2 2001/03/22 18:38:32 uw Exp $ */ class menubrowser { @@ -83,14 +103,6 @@ /** - * List of files in the menu hash. - * - * @var array - */ - var $files = array(); - - - /** * Creates the object and optionally sets the directoryto scan. * * @param string @@ -139,7 +151,7 @@ $this->files = array(); $this->menu = $this->browse($this->dir); - $this->addFileInfo(); + $this->menu = $this->addFileInfo($this->menu); return $this->menu; } // end func getMenu @@ -154,8 +166,8 @@ * @return array */ function browse($dir, $id = 0, $noindex = false) { + $struct = array(); - $dh = opendir($dir); while ($file = readdir($dh)) { if ("." == $file || ".." == $file) @@ -170,8 +182,7 @@ $id++; $struct[$id]["url"] = $ffile . $this->index_file; - - $this->files[] = $ffile . $this->index_file; + $sub = $this->browse($ffile, $id + 1, true); if (0 != count($sub)) $struct[$id]["sub"] = $sub; @@ -184,7 +195,6 @@ && !($noindex && $this->index_file == $file) ) { $id++; $struct[$id]["url"] = $dir . $file; - $this->files[] = $dir . $file; } } @@ -195,17 +205,52 @@ } // end func browse - function addFileInfo() { - - foreach ($this->files as $k => $file) { - $this->exploreFile($file); + /** + * Adds further informations to the menu hash gathered from the files in it + * + * @var array Menu hash to examine + * @return array Modified menu hash with the new informations + */ + function addFileInfo($menu) { + + // no foreach - it works on a copy - the recursive + // structure requires already lots of memory + reset($menu); + while (list($id, $data) = each($menu)) { + + $menu[$id] = array_merge($data, $this->exploreFile($data["url"])); + if (isset($data["sub"])) + $menu[$id]["sub"] = $this->addFileInfo($data["sub"]); + } + + return $menu; + } // end func addFileInfo + + + /** + * Returns additional menu informations decoded in the file that appears in the +menu. + * + * You should subclass this method to make it work with your own + * file formats. I used a simple XML format to store the content. + * + * @param string filename + */ + function exploreFile($file) { + + $xml = join("", @file($file)); + if (!$xml) + return array(); + + $doc = xmldoc($xml); + $xpc = xpath_new_context($doc); + + $menu = xpath_eval($xpc, "//menu"); + $node = &$menu->nodeset[0]; - } + return array("title" => $node->content); + } // end func exploreFile - function exploreFile() { - - } } // end class menubrowser ?> -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]