- <?
- /**
- * @package tree-node
- * @filesource
- * @see HTML_TREE_NODE_PAGE_PATH.'/Tree.php'
- * @copyright (c) http://Finn-Rasmussen.com
- * @license http://Finn-Rasmussen.com/license/ myPHP License conditions
- * @author http://Finn-Rasmussen.com
- * @version 1.9
- * @since 21-oct-2005
- */
-
- /**
- * The required files
- */
- require_once(HTML_PATH.'/Html.php');
- require_once(HTML_TREE_NODE_UTIL_PATH.'/Node.php');
- require_once(HTML_TREE_NODE_VIEW_PATH.'/NodeView.php');
- require_once(HTML_FILE_UTIL_PATH.'/Dir.php');
- if (defined('HTML_TABLE_COMPONENT_PATH')) {
- require_once(HTML_TABLE_COMPONENT_PATH.'/TableHeader.php');
- }
- if (defined('HTML_UTIL_COMPONENT_PATH')) {
- require_once(HTML_UTIL_COMPONENT_PATH.'/Server.php');
- }
-
- /**
- * The Tree class builds a complete navigation tree
- * <code>
- * Usage:
- * $tree = new Tree($path,$text,$width,$class);
- * print $tree->getHtml();
- * Or
- * Tree::display($path,$text,$width,$class);
- * </code>
- * @package tree-node
- */
-
- class Tree extends Html {
- /**
- * @var String $text The text of the table header
- */
- var $text = '';
-
- /**
- * @var String $width The width of the table header
- */
- var $width = '';
-
- /**
- * @var String $class The CSS class name
- */
- var $class = '';
-
- /**
- * Constructor
- * @param String $path The path to use for the tree
- * @param String $text The text of the table header
- * @param String $width The width of the table header
- * @param String $class The CSS class to use
- */
- function Tree($path='',$text='',$width='',$class='') {
- $this->Html();
- $this->text = $text !=''?$text :TREE_NODE_TEXT;
- $this->width = $width!=''?$width:TREE_NODE_WIDTH;
- $this->class = $class!=''?$class:TREE_NODE_CSS;
- if ($path!='') {
- $this->add($this->buildNode($path));
- } else {
- $this->add($this->buildNode($_SERVER['DOCUMENT_ROOT']));
- }
- }
-
- /**
- * Build the tree
- * @param String $path The path to build
- * @param int $level The level of the node
- * @return Node The Node to be build
- */
- function buildNode($path,$level=0) {
- //print "$path,$level<br />";
- $node = new Node();
- $cwd = Dir::getCwd();
- $thedir = new Dir($path);
- $thedir->cd(); // YOU MUST CHANGE TO THE DIRECTORY, in order to get it up and running
- if ($thedir->open()) {
- $level++;
- while (false !== ($dirname = $thedir->read())) {
- if (is_dir($dirname)) {
- $pathdirname = $path.'/'.$dirname;
- if (@file_exists($pathdirname.'/'.CONTENT_FILE_NAME)) {
- switch ($dirname) {
- case '.' :
- if ($level===1) {
- $node->add(new NodeView(basename(getcwd()),$thedir->getUrl($path),IMAGE_HOME,$level));
- }
- break;
- case '..':
- if ($level===1) {
- $node->add(new NodeView(LINK_TEXT_UP,$dirname,IMAGE_PLUS,$level));
- }
- break;
- default:
- $image = IMAGE_DOC;
- $indexFileName = $_SERVER['SCRIPT_NAME'];
- if (defined('HTML_UTIL_COMPONENT_PATH')) {
- $indexFileName = Server::getScriptName();
- }
- if ($thedir->getUrl($pathdirname).INDEX_FILE_NAME==$indexFileName) {
- $image = IMAGE_MINUS;
- }
- $node->add(new NodeView($dirname,$thedir->getUrl($pathdirname),$image,$level));
- $node->add($this->buildNode(Dir::getCwd().'/'.$dirname,$level));
- break;
- }
- } else {
- // Ignore directories without a CONTENT_FILE_NAME
- }
- } else {
- //print "ignore $dirname<br />";
- }
- }
- $thedir->close();
- } else {
- print "error open $path<br />";
- }
- $thedir->cd($cwd); // Restore
- return $node;
- }
-
- /**
- * Get the html for the whole tree and all its nodes
- * @return String The html
- */
- function getHtml() {
- $html = $this->html;
- if (TREE_NODE_SHOW & TREE_NODE_SHOW_LEFT || TREE_NODE_SHOW & TREE_NODE_SHOW_CENTER || TREE_NODE_SHOW & TREE_NODE_SHOW_RIGHT) {
- if (defined('CREATE_RUNTIME_KERNEL') && CREATE_RUNTIME_KERNEL) {
- $html .= '<?$tree = new Tree();print $tree->getHtml();?>';
- } else {
- if (defined('HTML_TABLE_COMPONENT_PATH')) {
- $tableheader = new TableHeader($this->text,$this->width);
- $html .= $tableheader->getHtml();
- }
- $blank = new Images(IMAGE_BLANK,$this->width,'1','',"$this->class");
- $html .= $this->getElements()."<br />\r\n"; // As html
- }
- } else {
- if (defined('LOG_LEVEL') && LOG_LEVEL & LOG_LEVEL_DEBUG) {
- print "<!-- ".$this->getClassName()." is disabled -->\r\n";
- }
- }
- return $html;
- }
-
- /**
- * Display html
- * <code>
- * Usage:
- * Tree::display($path,$text,$width,$class);
- * </code>
- * @static
- * @param String $path The path to use for the tree
- * @param String $text The text of the table header
- * @param String $width The width of the table header
- * @param String $class The CSS class to use
- */
- function display($path='',$text='',$width='',$class='') {
- $html = new Tree($path,$text,$width,$class);
- $html->addHtml();
- }
- }
- ?>