cvs: php4 /pear/HTML Menu_Browser.php

From: Date: Mon, 03 Sep 2001 16:25:30 +0000
Subject: cvs: php4 /pear/HTML Menu_Browser.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-774@lists.php.net to get a copy of this message
cox Mon Sep 3 12:25:30 2001 EDT Modified files: /php4/pear/HTML Menu_Browser.php Log: some style/ws

Index: php4/pear/HTML/Menu_Browser.php diff -u php4/pear/HTML/Menu_Browser.php:1.2 php4/pear/HTML/Menu_Browser.php:1.3 --- php4/pear/HTML/Menu_Browser.php:1.2 Wed Aug 8 09:53:47 2001 +++ php4/pear/HTML/Menu_Browser.php Mon Sep 3 12:25:30 2001 @@ -16,14 +16,14 @@ // | Authors: Ulf Wendel <ulf.wendel@phpdoc.de> | // +----------------------------------------------------------------------+ // -// $Id: Menu_Browser.php,v 1.2 2001/08/08 13:53:47 sebastian Exp $ +// $Id: Menu_Browser.php,v 1.3 2001/09/03 16:25:30 cox Exp $ /** * Simple filesystem browser that can be used to generated menu (3) hashes based on the directory structure. -* -* Together with menu (3) and the (userland) cache you can use this +* +* 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 @@ -31,7 +31,7 @@ * * // document root directory * define('DOC_ROOT', '/home/server/www.example.com/'); -* +* * // instantiate the menubrowser * $browser = new menubrowser(DOC_ROOT); * @@ -40,18 +40,18 @@ * * // 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. -* +* (title!). Subclass exploreFile() depending on your file format. +* * @author Ulf Wendel <ulf.wendel@phpdoc.de> -* @version $Id: Menu_Browser.php,v 1.2 2001/08/08 13:53:47 sebastian Exp $ +* @version $Id: Menu_Browser.php,v 1.3 2001/09/03 16:25:30 cox Exp $ */ class HTML_Menu_Browser { /** * Filesuffix of your XML files. - * - * @var string + * + * @var string * @see menubrowser() */ var $file_suffix = 'xml'; @@ -66,8 +66,8 @@ /** * Filename (without suffix) of your index / start pages. - * - * @var string + * + * @var string * @see menubrowser() */ var $index = 'index'; @@ -82,7 +82,7 @@ /** * Directory to scan. - * + * * @var string * @see setDirectory() */ @@ -90,11 +90,11 @@ /** * Prefix for every menu hash entry. - * - * Set the ID prefix if you want to merge the browser menu - * hash with another (static) menu hash so that there're no + * + * Set the ID prefix if you want to merge the browser menu + * hash with another (static) menu hash so that there're no * name clashes with the ids. - * + * * @var string * @see setIDPrefix() */ @@ -102,31 +102,31 @@ /** * Menu (3)'s setMenu() hash. - * + * * @var array */ var $menu = array(); /** - * Creates the object and optionally sets the directory to scan. - * + * Creates the object and optionally sets the directory to scan. + * * @param string * @see $dir */ function HTML_Menu_Browser($dir = '', $index = '', $file_suffix = '') { if ($dir) - $this->dir = $dir; + $this->dir = $dir; if ($index) - $this->index = $index; + $this->index = $index; if ($file_suffix) $this->file_suffix = $file_suffix; - - $this->index_file = $this->index . '.' . $this->file_suffix; + + $this->index_file = $this->index . '.' . $this->file_suffix; $this->file_suffix_length = strlen($this->file_suffix); } /** - * Sets the directory to scan. + * Sets the directory to scan. * * @param string directory to scan * @access public @@ -137,7 +137,7 @@ /** * Sets the prefix for every id in the menu hash. - * + * * @param string * @access public */ @@ -146,7 +146,7 @@ } /** - * Returns a hash to be used with menu(3)'s setMenu(). + * Returns a hash to be used with menu(3)'s setMenu(). * * @param string directory to scan * @param string id prefix @@ -158,54 +158,53 @@ if ($prefix) $this->setIDPrefix($prefix); - // drop the result of previous runs - $this->files = array(); - + // drop the result of previous runs + $this->files = array(); + $this->menu = $this->browse($this->dir); $this->menu = $this->addFileInfo($this->menu); - + return $this->menu; } /** - * Recursive function that does the scan and builds the menu (3) hash. + * Recursive function that does the scan and builds the menu (3) hash. * * @param string directory to scan * @param integer entry id - used only for recursion * @param boolean ??? - used only for recursion * @return array */ - function browse($dir, $id = 0, $noindex = false) { - $struct = array(); - $dh = opendir($dir); - while ($file = readdir($dh)) { - if ('.' == $file || '..' == $file) - continue; - - $ffile = $dir . $file; - if (is_dir($file)) { - - $ffile .= '/'; - - if (file_exists($ffile . $this->index_file)) { - - $id++; - $struct[$this->id_prefix . $id]['url'] = $ffile . $this->index_file; - - $sub = $this->browse($ffile, $id + 1, true); - if (0 != count($sub)) - $struct[$this->id_prefix . $id]['sub'] = $sub; - } - } else { - if ($this->file_suffix == substr($file, strlen($file) - $this->file_suffix_length, $this->file_suffix_length) - && !($noindex && $this->index_file == $file) ) { - $id++; - $struct[$this->id_prefix . $id]['url'] = $dir . $file; - } + function browse($dir, $id = 0, $noindex = false) + { + $struct = array(); + $dh = opendir($dir); + while ($file = readdir($dh)) { + if ('.' == $file || '..' == $file) { + continue; + } + $ffile = $dir . $file; + if (is_dir($file)) { + $ffile .= '/'; + if (file_exists($ffile . $this->index_file)) { + $id++; + $struct[$this->id_prefix . $id]['url'] = $ffile . $this->index_file; + + $sub = $this->browse($ffile, $id + 1, true); + if (0 != count($sub)) { + $struct[$this->id_prefix . $id]['sub'] = $sub; + } + } + } else { + if ($this->file_suffix == substr($file, strlen($file) - $this->file_suffix_length, $this->file_suffix_length) + && !($noindex && $this->index_file == $file) ) + { + $id++; + $struct[$this->id_prefix . $id]['url'] = $dir . $file; + } + } } - } - - return $struct; + return $struct; } /** @@ -215,8 +214,8 @@ * @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 + // 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'])); @@ -224,15 +223,15 @@ $menu[$id]['sub'] = $this->addFileInfo($data['sub']); } - return $menu; + return $menu; } /** * 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 + * + * 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) {
« previous php.pear.cvs (#774) next »