Source for file MenuBrowser.php
Documentation is available at MenuBrowser.php
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2003 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Author: Ulf Wendel <ulf.wendel@phpdoc.de> |
// +----------------------------------------------------------------------+
// $Id: MenuBrowser.php,v 1.4 2003/09/15 17:24:38 avb 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
* 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
* // 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());
* $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 <ulf.wendel@phpdoc.de>
* @version $Revision: 1.4 $
* Filesuffix of your XML files.
* @see HTML_MenuBrowser()
* Number of characters of the file suffix.
* @see HTML_MenuBrowser()
* Filename (without suffix) of your index / start pages.
* @see HTML_MenuBrowser()
* Full filename of your index / start pages.
* @see $file_suffix, $index
* 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
* name clashes with the ids.
* Menu (3)'s setMenu() hash.
* Creates the object and optionally sets the directory to scan.
* @param string Directory to scan
* @param string Filename of index pages
* @param string Suffix for files containing the additional data
* Sets the directory to scan.
* @param string directory to scan
* Sets the prefix for every id in the menu hash.
* Returns a hash to be used with menu(3)'s setMenu().
* @param string directory to scan
* @param string id prefix
function getMenu($dir = '', $prefix = '')
// drop the result of previous runs
* 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
function browse($dir, $id = 0 , $noindex = false )
if ('.' == $file || '..' == $file) {
$sub = $this->browse($ffile, $id + 1 , true );
$struct[$this->id_prefix . $id]['sub'] = $sub;
$struct[$this->id_prefix . $id]['url'] = $dir . $file;
* Adds further informations to the menu hash gathered from the files in it
* @param array Menu hash to examine
* @return array Modified menu hash with the new informations
// no foreach - it works on a copy - the recursive
// structure requires already lots of memory
while (list ($id, $data) = each($menu)) {
if (isset ($data['sub'])) {
* 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.
$xpc = xpath_new_context ($doc);
$menu = xpath_eval ($xpc, '//menu');
$node = &$menu->nodeset [0 ];
return array ('title' => $node->content );
Documentation generated on Mon, 11 Mar 2019 10:16:40 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|