[Phplib-commit] CVS: php-lib/doc/sgml 05-tree.sgml,1.1,1.2
Brought to you by:
nhruby,
richardarcher
From: Richard A. <ric...@us...> - 2001-08-16 05:04:25
|
Update of /cvsroot/phplib/php-lib/doc/sgml In directory usw-pr-cvs1:/tmp/cvs-serv32668 Modified Files: 05-tree.sgml Log Message: Bring into sync with -stable Fix up the directory tree example: enable sessions so the array is persistent PHP3 and PHP4 compatible undeclared variable warnings And clean up whitespace in the SGML code. Index: 05-tree.sgml =================================================================== RCS file: /cvsroot/phplib/php-lib/doc/sgml/05-tree.sgml,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** 05-tree.sgml 1999/07/16 21:45:40 1.1 --- 05-tree.sgml 2001/08/16 05:04:22 1.2 *************** *** 2,12 **** <sect1>Tree ! <p> ! The Tree class can render tree structures such as directory hierarchies and menu structures as HTML. The structure must be given to Tree as an nested array of arrays of arbitrary depth. - <p> - The idea of Tree is, that there are several mathematical models a tree could be viewed: One model is a data structure like nested arrays or a pointer --- 2,10 ---- <sect1>Tree ! ! <p>The Tree class can render tree structures such as directory hierarchies and menu structures as HTML. The structure must be given to Tree as an nested array of arrays of arbitrary depth. The idea of Tree is, that there are several mathematical models a tree could be viewed: One model is a data structure like nested arrays or a pointer *************** *** 17,22 **** sense). - <p> - To generate HTML-code from a tree-structure it is like this: You need at the end a one-dimensional string, which tells the browser what to do. The --- 15,18 ---- *************** *** 26,33 **** be generated. - <sect2>Instance variables <p> - <table> <tabular ca=""> --- 22,27 ---- *************** *** 42,50 **** <sect2>Instance methods - <p> <sect3>Accessible instance methods <p> - <descrip> <tag>build_tree()</tag> --- 36,42 ---- *************** *** 57,62 **** <tag>go_trough_tree($key="",$path="",$depth=0,$lcount=0,$pcount=0)</tag> - <p> This is the most important function of this class. It will call the output functions in the right order with the correct parameters. --- 49,54 ---- <tag>go_trough_tree($key="",$path="",$depth=0,$lcount=0,$pcount=0)</tag> + <p> This is the most important function of this class. It will call the output functions in the right order with the correct parameters. *************** *** 66,71 **** <tag>path_to_index (&$path,$key="")</tag> ! <P> ! This function is mostly used internally, but could be useful for you to generate <tt/$this->tree/. This function generates a PHP3 associate array-index string from a path, which is also --- 58,63 ---- <tag>path_to_index (&$path,$key="")</tag> ! ! <p>This function is mostly used internally, but could be useful for you to generate <tt/$this->tree/. This function generates a PHP3 associate array-index string from a path, which is also *************** *** 122,127 **** associate key to the tree described by path. - - <tag>starttree ()</tag> <p> --- 114,117 ---- *************** *** 159,163 **** Called when leaving tree. - </descrip> --- 149,152 ---- *************** *** 191,198 **** </code></tscreen> This is a completely recursive structure and I think, it is clear, how to create it with a recursive call of a function. If not, see the example below. - <p> One little quirk has to be explained, because it is a little --- 180,187 ---- </code></tscreen> + <p> This is a completely recursive structure and I think, it is clear, how to create it with a recursive call of a function. If not, see the example below. One little quirk has to be explained, because it is a little *************** *** 204,208 **** "Array" (perhaps something that should be changed). - <P> The output of this example if you don't change the output-functions will look like this: --- 193,196 ---- *************** *** 237,247 **** <sect2>Example <p> ! ! My example is just going trough the directory structure of your hard disk. <p> - The following code could read it: - <tscreen><code> class dir_Tree extends Tree { var $classname = "dir_Tree"; --- 225,246 ---- <sect2>Example <p> ! This example recursively reads in the directory structure of your hard disk. ! It allows you to flap in and out whole subdirectory trees. ! The $flap_out array must be persistent, so we use sessions and ! register it as a session variable. <p> <tscreen><code> + <? + // Uncomment these includes if necessary + // include("prepend.php3"); + // include "tree.inc"; + + // Session handling straight out of the demo + page_open(array("sess" => "Example_Session")); + + if (!isset($flap_out)) { $flap_out=array(); }; + $sess->register("flap_out"); + class dir_Tree extends Tree { var $classname = "dir_Tree"; *************** *** 251,255 **** function build_tree ($path=".") { ! $this->tree=$this->recurs_dir($path,0); } --- 250,254 ---- function build_tree ($path=".") { ! $this->tree=$this->recurs_dir($path,0); } *************** *** 264,273 **** while ( $name=readdir($d) ) { ! $pathname=$path . $this->delimiter . $name; ! if (is_dir($pathname) && !ereg("\.\.?",$pathname)) { if (isset($flap_out[$pathname])) { ! $array[$name]=$this->recurs_dir($pathname,$depth+1); } ! # ATTENTION: It is IMPORTANT fill the [0] array # *after* filling the rest of the array! $array[$name][0]=$pathname; --- 263,272 ---- while ( $name=readdir($d) ) { ! $pathname=$path . $this->delimiter . $name; ! if (is_dir($pathname) && !ereg("\\.\\.?",$pathname)) { if (isset($flap_out[$pathname])) { ! $array[$name]=$this->recurs_dir($pathname,$depth+1); } ! # ATTENTION: It is IMPORTANT fill the [0] array # *after* filling the rest of the array! $array[$name][0]=$pathname; *************** *** 284,298 **** ## FLAPPING IN and OUT ## This is used to create an array which includes ! ## all sub-paths which should be showed ! ## function flapping ($path) { ! GLOBAL $flap_out; if ($path) { ! if (is_dir($path)) { ! if (isset($flap_out[$path])) { ! unset($flap_out[$path]); } else { ! $flap_out[$path]=$name; } } --- 283,297 ---- ## FLAPPING IN and OUT ## This is used to create an array which includes ! ## all sub-paths which should be shown ! ## function flapping ($path) { ! GLOBAL $flap_out; if ($path) { ! if (is_dir($path)) { ! if (isset($flap_out[$path])) { ! unset($flap_out[$path]); } else { ! $flap_out[$path]=""; } } *************** *** 302,309 **** $t= new dir_Tree; ! $t->flapping($val); ## $val is given by GET-method, see *tree()-functions ! $t->build_tree(); ! $t->go_through_tree(); ! print $t->outp; </code></tscreen> --- 301,312 ---- $t= new dir_Tree; ! $t->flapping($val); ## $val is given by GET-method, see *tree()-functions ! $t->build_tree(); ! $t->go_through_tree(); ! print $t->outp; ! ! page_close() ! ! ?> </code></tscreen> *************** *** 320,332 **** <tt/$delimiter/-string. This cannot be solved correctly and you have to look for it when you create the tree. ! <P> The same thing is with the value [0] (zero) of a sub-array. This element is always used as the attribute of the parent element. ! <P> A good tip: when you build your tree recursively then the [0]-index must be filled <em/after/ the subtree is returned from recursive call. See in the example above what I mean. I think it's a PHP3 specialty. ! <P> Also it is possible that not every name could be inserted into the associate index-field (Control-chars etc.), but this is untested. --- 323,335 ---- <tt/$delimiter/-string. This cannot be solved correctly and you have to look for it when you create the tree. ! The same thing is with the value [0] (zero) of a sub-array. This element is always used as the attribute of the parent element. ! A good tip: when you build your tree recursively then the [0]-index must be filled <em/after/ the subtree is returned from recursive call. See in the example above what I mean. I think it's a PHP3 specialty. ! Also it is possible that not every name could be inserted into the associate index-field (Control-chars etc.), but this is untested. |