A functionally powerful PHP tree (directory tree can do the same as the Windows Explorer)

zhaozj2021-02-16  73

A functionally powerful PHP tree (directory tree can do the same as the Windows Explorer)

By QETO.com (attempt to interconnection - Internet application pioneer)

PHP Tree Class.

Tree Level * // * Tree [x] [1] -> Image link * // * Tree [x] [2] - > image query * // * Tree [x] [3] -> item text * // * Tree [x] [4] -> item link * // * Tree [x] [5] -> link query * / / * Tree [x] [6] -> link target * // * Tree [x] [7] -> text image * // * Tree [x] [8] -> last item in subtree * // ** ************************************************** /

VAR $ P = ""; // String Like B_Encode ('0 | 1 | 3 |') var $ expresss = array (); // Like Array (0 => 0, 1 => 1, 2 => 3, 4 =>) VAR $ expand = array (); var $ visible = array (); var $ IMG_DIR = ""; // Tree images Dirvar $ max_depth = 0; // Tree Maximum Depthvar $ text_width = 100; var $ ev_link = True;

VAR $ images = array (); / *********************************************************** **** // * Images ['Expand'] -> Expand * // * Images ['Collapse'] -> Collapse * ///////////-> Vertline * // * Images ['PARALLINE '] -> paralline * /// * Images [' split '] -> split * // * Images [' end '] -> End * // * Images [' Leaf '] -> Leaf * // * Images [ 'Space'] -> Space * // ********************************************************* ***** /

Var $ HTML; // Output String

// Class Constructorfunction Treeelist ($ TREE, $ Exp = ", $ IMG_DIR =", $ images = array ()) {$ this-> Tree = $ Tree; for ($ I = 0; $ i tree); $ i ) {$ this-> expand [$ I] = 0; $ this-> Visible [$ I] = 0; $ this-> Tree [$ I] [8] = 0; } $ this-> p = $ exp;

// if ($ exp! = ") $ this-> explevels = evtern (" | ", b_decode ($ exp)); if ($ exp! =") $ this-> explevels = evtern ("|" , $ exp); if (! is_ARRAY ($ this-> expresss) $ this-> expresss = array (); sort ($ this-> explevels); reset ($ this-> expresss); $ this-> setExpand (); $ this-> setvisible (); $ this-> setimagesDir ($ IMG_DIR); $ this-> settreeImages ($ this-> gettreemaxDepth ();

// private methodsfunction setExpand () {$ I = 0; while ($ this-> expresss)) {$ this-> explevels [$ this-> expresss [$ I]] = 1; $ i ; }

Function setvisible () {$ this-> Visible [0] = 1; // root is always visiblefor ($ i = 0; $ 1-> expresss); $ i ) {$ n = $ this- > Explevels [$ I]; IF ($ this-> Visible [$ n] == 1) && ($ this-> expand [$ n] == 1)) {$ j = $ n 1; while $ this-> Tree [$ j] [0]> $ this-> Tree [$ n] [0]) {= f ($ this-> tree [$ j] [0] == $ this-> tree [$ n] [0] 1) $ this-> visible [$ j] = 1; $ j ;}}}}

Function gettreeMaxDepth () {$ this-> max_depth = 0; for ($ I = 0; $ I <-> Tree); $ i ) {ified ($ this-> Tree [$ I] [0] > $ this-> max_depth) {$ this-> max_depth = $ this-> Tree [$ I] [0];}}}

Function gettreelist () {$ lastlevel = $ this-> max_depth; for ($ i = count ($ this-> Tree) -1; $ i> = 0; $ i -) {ified ($ this-> Tree [ $ I] [0] $ Lastlevel) {for ($ j = $ this-> Tree [$ I] [0] 1; $ j <= $ = $> -> max_depth; $ j ) {$ seat [$ j ] = 0;}} f ($ i) [$ this-> Tree [$ I] [0]] == 0) {$ Levels [$ THIS-> Tree [$ I] [0]] = 1; $ THIS -> Tree [$ I] [8] = 1;} else {$ this-> Tree [$ I] [8] = 0;} $ lastlevel = $ this-> Tree [$ I] [0];}

For ($ I = 0; $ I <$-> Max_Depth; $ I ) $ levels [$ I] = 1; $ this-> max_depth ;

$ this-> html = "/ n

/ N"; $ this-> html. = " / n"; $ this-> html. = "/ T / N ";

// Vertical Lines from Higher Levels $ I = 0; IF ($ CNT == 0) $ this-> html. = "/ t

/ n "; For ($ I = 0; $ I <$-> max_depth; $ i ) $ this-> html. =" / t / n ";

$ this-> html. = "/ t

/ n";

$ CNT = 0; While ($ CNT <-> Tree)) {IF ($ this-> Visible [$ CNT]) {// Start New Row $ this-> HTML. = "

/ n"; while ($ I <$ This-> Tree [$ CNT] [0] -1) {IF ($ levels [$ I] == 1) $ this-> html. = "/ t images ["vertline"]. "/"> / n "; else $ this-> html. =" / t Images [Space "]." / "style = 'Height: 100%; Width: 100%'> / n"; $ i ;} // Corner At End of Subtree Or T-splitif ($ this -> Tree [$ CNT] [8] == 1) {IF ($ CNT! = 0) $ this-> html. = "/ t Images [ "END"]. "/"> / n "; / * else $ this-> html. =" / t / n "; * / $ levels [$ This-> Tree [$ CNT] [0] -1] = 0;} else {$ this-> html. = "/ t images ["split" ]. "/"> / n "; $ levels [$ this-> Tree [$ CNT] [0] -1] = 1;}

// Node (with subtree) or Leaf ($ this-> Tree [$ CNT 1] [0]> $ this-> Tree [$ CNT] [0]) {// create Expand / Collapse Parameters $ I = 0; $ params = "? p ="; $ params1 = ""; while ($ I <-> expand) {if (($ this-> expand [$ i] == 1) && ($ CNT! = $ I) || ($ I-> EXPAND [$ I] == 0 && $ CNT == $ i)) {$ params1 = $ params1. $ I; $ params1 = $ params1 "|";} $ i ;} // $ params = $ params.b_encode ($ params1). "&". $ this-> Tree [$ CNT] [3]; $ params = $ params. $ params1. "&" $ this-> Tree [$ CNT] [2]; if ($ this-> Tree [$ CNT] [1] == "") $ Script = $ PATH_INFO; ELSE $ Script = $ this-> Tree [$ CNT] [1];

IF ($ THIS-> Expand [$ CNT] == 0) IF ($ THIS-> Exp_Link) $ THIS-> HTML. = "/ T

images [" expand "]." / "border = no> / n"; Else $ this-> HTML. = "/ t / n "; elseif ($ this-> exp_link) $ this -> html. = "/ t images [" collapse "]." / "." / "Border = no> / n"; Else $ this-> html. = "/ t images [" collapse "]. "/" border = no> / n ";} else {// Tree Leaf $ this-> html. =" / t Images [" Leaf "]." / "> / n";} IF ($ this-> Tree [$ CNT] [7]! = "") {IF ($ this-> Tree [$ CNT] [4 ] == "" "$ this-> html. =" / t ". $ this-> Tree [$ CNT] [7]." / n "; else $ this-> HTML. = "/ t p. "&". $ THIS -> Tree [$ CNT] [5]. "/" Target = / "". $ this-> Tree [$ CNT] [6]. "/"> ". $ this-> Tree [$ CNT] [7 ]. " / n"; $ TMPCOLSPAN = 0;} else {$ tmpcolspan = 1;} // Output item textif ($ this-> Tree [$ CNT] [4] == " ") $ this-> html. =" /t Tree [$ CNT] [0] $ TMPCOLSPAN). "Valign =

Bottom> "$ this-> Tree [$ CNT] [3]." / n "; Else $ this-> html. =" / t

Tree [$ CNT] [5]. "/" Target = / "". $ this-> Tree [$ CNT] [6]. "/"> ". $ this-> Tree [$ CNT] [3]. " "; // end $ this-> html. = " / n";} // visible

$ CNT ;} $ this-> html. = " / N";

// public methodsfunction setTextWidth ($ w) {$ this-> text_width = $ w;}

Function setExpandLink ($ r = true) {$ this-> exp_link = $ r;}

Function setImagesDir ($ dir) {$ this-> IMG_DIR = $ dir;}

Function SettreeImages ($ iF (is_ARRAY ($ images)) {if ($ this)> 1) {$ this-> images = array ("expand" => $ this-> img_dir. $ images [' Expand '], "Collapse" => $ this-> img_dir. $ images [' collapse '], "vertline" => $ this-> img_dir. $ images [' Vertline '], "PARALLINE" => $ THIS- > img_dir. $ images ['paralline'], "split" => $ this-> img_dir. $ images ['split'], "end" => $ this-> img_dir. $ images ['end'], " Leaf "=> $ this-> img_dir. $ images ['Leaf']," Space "=> $ this-> img_dir. $ images ['Space']);} else {$ this-> images = array (" Expand "=> $ this-> img_dir." Tree_expand.gif "," collapse "=> $ this-> img_dir." Tree_collapse.gif "," Vertline "=> $ this-> img_dir." Tree_vertline.gif ", "paralline" => $ this-> img_dir. "Tree_PARALLINE.GIF", "split" => $ this-> img_dir. "Tree_Split.gif", "end" => $ this-> img_dir. "Tree_end.gif" , // "Leaf" => $ this-> img_dir. "leaf" => $ this-> img_dir. "Tree_PARALLINE.GIF", "space" => $ this-> img_dir. "Tree_Space .gif ");}} else {die (" class treelist: images setup error! ");}} Function Output () {$ this-> gettreelist (); return $ t His-> html;}}

?>

转载请注明原文地址:https://www.9cbs.com/read-17898.html

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.043, SQL: 9