Top  Branding  Banner 
blank.gif
blank.gif
triangle.gif Du er her: /  Forsiden  /  Kildekoden  /  Tree-node  /  Tree   Login nu   Login
blank.gif
««« Se kilde koden
blank.gif
tl.gif Cms tr.gif tl.gif Component tr.gif tl.gif Db tr.gif tl.gif Db-basket tr.gif tl.gif Db-login tr.gif tl.gif Db-customer tr.gif tl.gif Db-select tr.gif tl.gif Jquery tr.gif tl.gif Form-elements tr.gif tl.gif Menu-fisheye tr.gif tl.gif Template tr.gif tls.gif     Tree-node  trs.gif tl.gif Validator tr.gif
blank.gif
blank.gif
arrow-headline.gif Index
MenuLink  MenuLeft  
Tilbage

Skjul: Navn

Tree.php


Vis: Sample code, tutorial

Tree, Sample code, tutorial

Sådan benyttes komponenten Tree klassen

Først skal du inkludere den fil der beskriver komponenten, som en klasse fil

  • <?
    require_once(HTML_PACKAGE_PATH.'/Tree.php');
    ?>

Dernæst kan du enten benytte komponenten som et taglib (statiske metoder):

  • <?
    Tree
    ::display($param1$param2$param3, ...);
    ?>

eller du kan lave en instance af komponenten og benytte metoderne direkte:

  • <?
    $object 
    = new Tree($param1$param2$param3, ...);
    print 
    $object->getHtml();
    ?>

Skjul: Sådan vises komponenten

Tree, Sådan vises komponenten

Sådan vises komponenten Tree klassen


Vis: PHP source code

Tree, PHP source code

Den fulde PHP kildekode for Tree klassen

<?php
/**
 * @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.11
 * @since 27-nov-2009
 */

/**
 * The required files
 */
require_once(HTML_BASE_COMMON_PATH.'/Html.php');
require_once(
HTML_BASIC_UTIL_PATH.'/Message.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
     */
    
protected $text '';

    
/**
     * @var String $width The width of the table header
     */
    
protected $width '';

    
/**
     * @var String $class The CSS class name
     */
    
protected $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 __construct($path=''$text=''$width=''$class='') {
        
parent::__construct();
        
$this->text  $text  != ''?$text :TREE_NODE_TEXT;
        
$this->width $width != ''?$width:TREE_NODE_WIDTH;
        
$this->class $class != ''?$class:CSS_TREE_NODE;
        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 />\r\n";
        
$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;
                                }
                                
//$msg = $thedir->getUrl($pathdirname)." ? $pathdirname<br />\r\n";
                                //Message::add($msg, __FILE__, __LINE__);
                                
$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
                        // Message::add($msg, __FILE__, __LINE__);
                    
}
                } else {
                    
//print "ignore $dirname<br />";
                    // Message::add($msg, __FILE__, __LINE__);
                
}
            }
            
$thedir->close();
        } else {
            
$msg "error open $path<br />";
            
Message::add($msg__FILE____LINE__);
        }
        
$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_CENTER TREE_NODE_SHOW_RIGHT) ) {
            if (
CACHE_TREE_NODE && $this->getCacheFileName(CACHE_TREE_NODE_PATH) != '' && file_exists($this->getCacheFileName(CACHE_TREE_NODE_PATH))) {
                
$html .= $this->content($this->getCacheFileName(CACHE_TREE_NODE_PATH));
            } else {
                if (
defined('CREATE_RUNTIME_KERNEL') && CREATE_RUNTIME_KERNEL) {
                    
$html .= '<?php$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 .= '<div class="'.$this->class.'">';
                    
$html .= $this->getElements()."</div>\r\n"// As html
                
}
                if (
CACHE_TREE_NODE) {
                    
$this->save($htmlCACHE_TREE_NODE_PATH);
                }
             }
        } else {
            if (
defined('DEBUG_LEVEL_SHOW_INFO') && DEBUG_LEVEL DEBUG_LEVEL_SHOW_INFO) {
                
$html .= "<!-- ".$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
     */
    
public static function display($path=''$text=''$width=''$class='') {
        
$html = new Tree($path$text$width$class);
        
$html->addHtml();
    }
}
?>

Vis: HTML source code

Tree, HTML source code

Den fulde HTML kildekode for Tree klassen

<?
<!-- DEBUGTree -->
<!-- 
Tree is disabled -->

?>

Vis: Class methods

Tree, Class methods

Her er 'klasse metoderne' for Tree klassen:

  • __construct
  • buildNode
  • getHtml
  • display
  • setObject
  • set
  • get
  • getAttribute
  • getTag
  • add
  • getSizeof
  • getElement
  • getElements
  • getToogle
  • getMaximize
  • getMinimize
  • newTriangle
  • getStartHtml
  • getEndHtml
  • showsource
  • getClassName
  • getMsg
  • addHtml
  • __toString
  • getCacheFileName
  • save
  • content

Vis: Object vars

Tree, Object vars

Her er 'objekt variable' for Tree klassen:

  • html =>
  • sql =>

MenuRight 
triangle.gif

Dansk

Deutch

English (UK)

France

Italy

Norsk

Svensk

English (USA)


 
blank.gif
MenuBottom 
triangle.gif Copyright @ 1999-2010 www.Finn-Rasmussen.com Powered by myPHP Version (5.3.3-7+squeeze9) 1.11
blank.gif