uw Tue Mar 20 15:45:33 2001 EDT
Added files:
/php4/pear/Experimental/HTML Menu_Browser.php
Log:
Warning: alpha code!
A simple filesystem scanner/browser that maps the filesystem structure into a menu
hash so that you can build simple fusebox (?) like systems. Sebastian can you help me
with the coding guides etc ?
Index: php4/pear/Experimental/HTML/Menu_Browser.php
+++ php4/pear/Experimental/HTML/Menu_Browser.php
<?php
//
// +----------------------------------------------------------------------+
// | PHP version 4.0 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2001 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 |
// | [EMAIL PROTECTED] so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Ulf Wendel <[EMAIL PROTECTED]> |
// +----------------------------------------------------------------------+
//
// $Id: Menu_Browser.php,v 1.1 2001/03/20 23:45:31 uw Exp $
/**
* Simple filesystem browser that can be used to generated menu (3) hashes.
*
* Together with menu (3) you can use this browser to generate simple
* fusebox like systems.
*
* @author Ulf Wendel <[EMAIL PROTECTED]>
* @version $Id: Menu_Browser.php,v 1.1 2001/03/20 23:45:31 uw Exp $
*/
class menubrowser {
/**
* Filesuffix of your XML files.
*
* @var string
* @see menubrowser()
*/
var $file_suffix = "xml";
/**
* Number of characters of the file suffix.
*
* @var int
* @see menubrowser()
*/
var $file_suffix_length = 3;
/**
* Filename (without suffix) of your index / start pages.
*
* @var string
* @see menubrowser()
*/
var $index = "index";
/**
* Full filename of your index / start pages.
*
* @var string
* @see $file_suffix, $index
*/
var $index_file = "";
/**
* Directory to scan.
*
* @var string
* @see setDirectory()
*/
var $dir = "";
/**
* Menu (3)'s setMenu() hash.
*
* @var array
*/
var $menu = array();
/**
* List of files in the menu hash.
*
* @var array
*/
var $files = array();
/**
* Creates the object and optionally sets the directoryto scan.
*
* @param string
* @see $dir
*/
function menubrowser($dir = "", $index = "", $file_suffix = "") {
if ($dir)
$this->dir = $dir;
if ($index)
$this->index = $index;
if ($file_suffix)
$this->file_suffix = $file_suffix;
$this->index_file = $this->index . "." . $this->file_suffix;
$this->file_suffix_length = strlen($this->file_suffix);
} // end constructor
/**
* Sets the directory to scan.
*
* @param string directory to scan
* @access public
*/
function setDirectory($dir) {
$this->dir = $dir;
} // end func setDirectory
/**
* Returns a hash to be used with menu(3)'s setMenu().
*
* @param string directory to scan
* @access public
*/
function getMenu($dir = "") {
if ($dir)
$this->setDirectory($dir);
// drop the result of previous runs
$this->files = array();
$this->menu = $this->browse($this->dir);
$this->addFileInfo();
return $this->menu;
} // end func getMenu
/**
* 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[$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;
}
} else {
if ($this->file_suffix == substr($file, strlen($file) -
$this->file_suffix_length, $this->file_suffix_length)
&& !($noindex && $this->index_file == $file) ) {
$id++;
$struct[$id]["url"] = $dir . $file;
$this->files[] = $dir . $file;
}
}
}
return $struct;
} // end func browse
function addFileInfo() {
foreach ($this->files as $k => $file) {
$this->exploreFile($file);
}
}
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]