PHPLayersMenu
[ class tree: PHPLayersMenu ] [ index: PHPLayersMenu ] [ all elements ]

Source for file layersmenu-common.inc.php

Documentation is available at layersmenu-common.inc.php

  1. <?php
  2. // PHP Layers Menu 3.2.0-rc (C) 2001-2004 Marco Pratesi - http://www.marcopratesi.it/
  3.  
  4. /**
  5. * This file contains the code of the LayersMenuCommon class.
  6. @package PHPLayersMenu
  7. */
  8.  
  9. /**
  10. * This is the "common" class of the PHP Layers Menu library.
  11. *
  12. * You need to include PEAR.php and DB.php if (and only if) you want to use the DB support provided by ths class.
  13. *
  14. @version 3.2.0-rc
  15. @package PHPLayersMenu
  16. */
  17. {
  18.  
  19. /**
  20. * The name of the package
  21. @access private
  22. @var string 
  23. */
  24. var $_packageName;
  25. /**
  26. * The version of the package
  27. @access private
  28. @var string 
  29. */
  30. var $version;
  31. /**
  32. * The copyright of the package
  33. @access private
  34. @var string 
  35. */
  36. var $copyright;
  37. /**
  38. * The author of the package
  39. @access private
  40. @var string 
  41. */
  42. var $author;
  43.  
  44. /**
  45. * URL to be prepended to the menu hrefs
  46. @access private
  47. @var string 
  48. */
  49. var $prependedUrl '';
  50. /**
  51. * Do you want that code execution halts on error?
  52. @access private
  53. @var string 
  54. */
  55. var $haltOnError 'yes';
  56.  
  57. /**
  58. * The base directory where the package is installed
  59. @access private
  60. @var string 
  61. */
  62. var $dirroot;
  63. /**
  64. * The "libjs" directory of the package
  65. @access private
  66. @var string 
  67. */
  68. var $libjsdir;
  69. /**
  70. * The directory where images related to the menu can be found
  71. @access private
  72. @var string 
  73. */
  74. var $imgdir;
  75. /**
  76. * The http path corresponding to imgdir
  77. @access private
  78. @var string 
  79. */
  80. var $imgwww;
  81. /**
  82. * The directory where icons of menu items can be found
  83. @access private
  84. @var string 
  85. */
  86. var $icondir;
  87. /**
  88. * The http path corresponding to icondir
  89. @access private
  90. @var string 
  91. */
  92. var $iconwww;
  93. /**
  94. * This array may contain width and height of all icons
  95. @access private
  96. @var integer 
  97. */
  98. var $iconsize array();
  99. /**
  100. * If this var is false, width and height of icons have to be detected; if this var is true, width and height of icons are not detected and are retrieved from the iconsize array
  101. @access private
  102. @var boolean 
  103. */
  104. var $issetIconsize false;
  105. /**
  106. * The directory where templates can be found
  107. @access private
  108. @var string 
  109. */
  110. var $tpldir;
  111. /**
  112. * The string containing the menu structure
  113. @access private
  114. @var string 
  115. */
  116. var $menuStructure;
  117.  
  118. /**
  119. * It counts nodes for all menus
  120. @access private
  121. @var integer 
  122. */
  123. var $_nodesCount;
  124. /**
  125. * A multi-dimensional array to store informations for each menu entry
  126. @access private
  127. @var array 
  128. */
  129. var $tree;
  130. /**
  131. * A multi-dimensional array used only with the DB support; for each $menu_name, it stores the $cnt associated to each item id
  132. *
  133. * This array is needed for selection of the current item
  134. * through the corresponding id (see the DB table structure)
  135. * as, internally, items are stored, sorted and addressed in terms of $cnt
  136. *
  137. @access private
  138. @var array 
  139. */
  140. var $treecnt;
  141. /**
  142. * The maximum hierarchical level of menu items
  143. @access private
  144. @var integer 
  145. */
  146. var $_maxLevel;
  147. /**
  148. * An array that counts the number of first level items for each menu
  149. @access private
  150. @var array 
  151. */
  152. var $_firstLevelCnt;
  153. /**
  154. * An array containing the number identifying the first item of each menu
  155. @access private
  156. @var array 
  157. */
  158. var $_firstItem;
  159. /**
  160. * An array containing the number identifying the last item of each menu
  161. @access private
  162. @var array 
  163. */
  164. var $_lastItem;
  165.  
  166. /**
  167. * Data Source Name: the connection string for PEAR DB
  168. @access private
  169. @var string 
  170. */
  171. var $dsn 'pgsql://dbuser:dbpass@dbhost/dbname';
  172. /**
  173. * DB connections are either persistent or not persistent
  174. @access private
  175. @var boolean 
  176. */
  177. var $persistent false;
  178. /**
  179. * Name of the table storing data describing the menu
  180. @access private
  181. @var string 
  182. */
  183. var $tableName 'phplayersmenu';
  184. /**
  185. * Name of the i18n table corresponding to $tableName
  186. @access private
  187. @var string 
  188. */
  189. var $tableName_i18n 'phplayersmenu_i18n';
  190. /**
  191. * Names of fields of the table storing data describing the menu
  192. *
  193. * default field names correspond to the same field names foreseen
  194. * by the menu structure format
  195. *
  196. @access private
  197. @var array 
  198. */
  199. var $tableFields array(
  200.     'id'        => 'id',
  201.     'parent_id'    => 'parent_id',
  202.     'text'        => 'text',
  203.     'href'        => 'href',
  204.     'title'        => 'title',
  205.     'icon'        => 'icon',
  206.     'target'    => 'target',
  207.     'orderfield'    => 'orderfield',
  208.     'expanded'    => 'expanded'
  209. );
  210. /**
  211. * Names of fields of the i18n table corresponding to $tableName
  212. @access private
  213. @var array 
  214. */
  215. var $tableFields_i18n array(
  216.     'language'    => 'language',
  217.     'id'        => 'id',
  218.     'text'        => 'text',
  219.     'title'        => 'title'
  220. );
  221. /**
  222. * A temporary array to store data retrieved from the DB and to perform the depth-first search
  223. @access private
  224. @var array 
  225. */
  226. var $_tmpArray array();
  227.  
  228. /**
  229. * The constructor method; it initializates the menu system
  230. @return void 
  231. */
  232. function LayersMenuCommon()
  233. {
  234.     $this->_packageName 'PHP Layers Menu';
  235.     $this->version '3.2.0-rc';
  236.     $this->copyright '(C) 2001-2004';
  237.     $this->author 'Marco Pratesi - http://www.marcopratesi.it/';
  238.  
  239.     $this->prependedUrl '';
  240.  
  241.     $this->dirroot './';
  242.     $this->libjsdir './libjs/';
  243.     $this->imgdir './menuimages/';
  244.     $this->imgwww 'menuimages/';
  245.     $this->icondir './menuicons/';
  246.     $this->iconwww 'menuicons/';
  247.     $this->tpldir './templates/';
  248.     $this->menuStructure '';
  249.     $this->separator '|';
  250.  
  251.     $this->_nodesCount 0;
  252.     $this->tree array();
  253.     $this->treecnt array();
  254.     $this->_maxLevel array();
  255.     $this->_firstLevelCnt array();
  256.     $this->_firstItem array();
  257.     $this->_lastItem array();
  258. }
  259.  
  260. /**
  261. * The method to set the prepended URL
  262. @access public
  263. @return boolean 
  264. */
  265. function setPrependedUrl($prependedUrl)
  266. {
  267.     // We do not perform any check
  268.     $this->prependedUrl $prependedUrl;
  269.     return true;
  270. }
  271.  
  272. /**
  273. * The method to set the dirroot directory
  274. @access public
  275. @return boolean 
  276. */
  277. function setDirrootCommon($dirroot)
  278. {
  279.     if (!is_dir($dirroot)) {
  280.         $this->error("setDirroot: $dirroot is not a directory.");
  281.         return false;
  282.     }
  283.     if (substr($dirroot-1!= '/'{
  284.         $dirroot .= '/';
  285.     }
  286.     $oldlength strlen($this->dirroot);
  287.     $foobar strpos($this->libjsdir$this->dirroot);
  288.     if (!($foobar === false || $foobar != 0)) {
  289.         $this->libjsdir $dirroot substr($this->libjsdir$oldlength);
  290.     }
  291.     $foobar strpos($this->imgdir$this->dirroot);
  292.     if (!($foobar === false || $foobar != 0)) {
  293.         $this->imgdir $dirroot substr($this->imgdir$oldlength);
  294.     }
  295.     $foobar strpos($this->icondir$this->dirroot);
  296.     if (!($foobar === false || $foobar != 0)) {
  297.         $this->icondir $dirroot substr($this->icondir$oldlength);
  298.     }
  299.     $foobar strpos($this->tpldir$this->dirroot);
  300.     if (!($foobar === false || $foobar != 0)) {
  301.         $this->tpldir $dirroot substr($this->tpldir$oldlength);
  302.     }
  303.     $this->dirroot $dirroot;
  304.     return true;
  305. }
  306.  
  307. /**
  308. * The method to set the libjsdir directory
  309. @access public
  310. @return boolean 
  311. */
  312. function setLibjsdir($libjsdir)
  313. {
  314.     if ($libjsdir != '' && substr($libjsdir-1!= '/'{
  315.         $libjsdir .= '/';
  316.     }
  317.     if ($libjsdir == '' || substr($libjsdir01!= '/'{
  318.         $foobar strpos($libjsdir$this->dirroot);
  319.         if ($foobar === false || $foobar != 0{
  320.             $libjsdir $this->dirroot $libjsdir;
  321.         }
  322.     }
  323.     if (!is_dir($libjsdir)) {
  324.         $this->error("setLibjsdir: $libjsdir is not a directory.");
  325.         return false;
  326.     }
  327.     $this->libjsdir $libjsdir;
  328.     return true;
  329. }
  330.  
  331. /**
  332. * The method to set the imgdir directory
  333. @access public
  334. @return boolean 
  335. */
  336. function setImgdir($imgdir)
  337. {
  338.     if ($imgdir != '' && substr($imgdir-1!= '/'{
  339.         $imgdir .= '/';
  340.     }
  341.     if ($imgdir == '' || substr($imgdir01!= '/'{
  342.         $foobar strpos($imgdir$this->dirroot);
  343.         if ($foobar === false || $foobar != 0{
  344.             $imgdir $this->dirroot $imgdir;
  345.         }
  346.     }
  347.     if (!is_dir($imgdir)) {
  348.         $this->error("setImgdir: $imgdir is not a directory.");
  349.         return false;
  350.     }
  351.     $this->imgdir $imgdir;
  352.     return true;
  353. }
  354.  
  355. /**
  356. * The method to set imgwww
  357. @access public
  358. @return void 
  359. */
  360. function setImgwww($imgwww)
  361. {
  362.     if ($imgwww != '' && substr($imgwww-1!= '/'{
  363.         $imgwww .= '/';
  364.     }
  365.     $this->imgwww $imgwww;
  366. }
  367.  
  368. /**
  369. * The method to set the icondir directory
  370. @access public
  371. @return boolean 
  372. */
  373. function setIcondir($icondir)
  374. {
  375.     if ($icondir != '' && substr($icondir-1!= '/'{
  376.         $icondir .= '/';
  377.     }
  378.     if ($icondir == '' || substr($icondir01!= '/'{
  379.         $foobar strpos($icondir$this->dirroot);
  380.         if ($foobar === false || $foobar != 0{
  381.             $icondir $this->dirroot $icondir;
  382.         }
  383.     }
  384.     if (!is_dir($icondir)) {
  385.         $this->error("setIcondir: $icondir is not a directory.");
  386.         return false;
  387.     }
  388.     $this->icondir $icondir;
  389.     return true;
  390. }
  391.  
  392. /**
  393. * The method to set iconwww
  394. @access public
  395. @return void 
  396. */
  397. function setIconwww($iconwww)
  398. {
  399.     if ($iconwww != '' && substr($iconwww-1!= '/'{
  400.         $iconwww .= '/';
  401.     }
  402.     $this->iconwww $iconwww;
  403. }
  404.  
  405. /**
  406. * The method to set the iconsize array
  407. @access public
  408. @return void 
  409. */
  410. function setIconsize($width$height)
  411. {
  412.     $this->iconsize['width'($width == (int) $width$width 0;
  413.     $this->iconsize['height'($height == (int) $height$height 0;
  414.     $this->issetIconsize true;
  415. }
  416.  
  417. /**
  418. * The method to unset the iconsize array
  419. @access public
  420. @return void 
  421. */
  422. function unsetIconsize()
  423. {
  424.     unset($this->iconsize['width']);
  425.     unset($this->iconsize['height']);
  426.     $this->issetIconsize false;
  427. }
  428.  
  429. /**
  430. * The method to set the tpldir directory
  431. @access public
  432. @return boolean 
  433. */
  434. function setTpldirCommon($tpldir)
  435. {
  436.     if ($tpldir != '' && substr($tpldir-1!= '/'{
  437.         $tpldir .= '/';
  438.     }
  439.     if ($tpldir == '' || substr($tpldir01!= '/'{
  440.         $foobar strpos($tpldir$this->dirroot);
  441.         if ($foobar === false || $foobar != 0{
  442.             $tpldir $this->dirroot $tpldir;
  443.         }
  444.     }
  445.     if (!is_dir($tpldir)) {
  446.         $this->error("setTpldir: $tpldir is not a directory.");
  447.         return false;
  448.     }
  449.     $this->tpldir $tpldir;
  450.     return true;
  451. }
  452.  
  453. /**
  454. * The method to read the menu structure from a file
  455. @access public
  456. @param string $tree_file the menu structure file
  457. @return boolean 
  458. */
  459. function setMenuStructureFile($tree_file)
  460. {
  461.     if (!($fd fopen($tree_file'r'))) {
  462.         $this->error("setMenuStructureFile: unable to open file $tree_file.");
  463.         return false;
  464.     }
  465.     $this->menuStructure '';
  466.     while ($buffer fgets($fd4096)) {
  467.         $buffer ereg_replace(chr(13)''$buffer);    // Microsoft Stupidity Suppression
  468.         $this->menuStructure .= $buffer;
  469.     }
  470.     fclose($fd);
  471.     if ($this->menuStructure == ''{
  472.         $this->error("setMenuStructureFile: $tree_file is empty.");
  473.         return false;
  474.     }
  475.     return true;
  476. }
  477.  
  478. /**
  479. * The method to set the menu structure passing it through a string
  480. @access public
  481. @param string $tree_string the menu structure string
  482. @return boolean 
  483. */
  484. function setMenuStructureString($tree_string)
  485. {
  486.     $this->menuStructure ereg_replace(chr(13)''$tree_string);    // Microsoft Stupidity Suppression
  487.     if ($this->menuStructure == ''{
  488.         $this->error('setMenuStructureString: empty string.');
  489.         return false;
  490.     }
  491.     return true;
  492. }
  493.  
  494. /**
  495. * The method to set the value of separator
  496. @access public
  497. @return void 
  498. */
  499. function setSeparator($separator)
  500. {
  501.     $this->separator $separator;
  502. }
  503.  
  504. /**
  505. * The method to set parameters for the DB connection
  506. @access public
  507. @param string $dns Data Source Name: the connection string for PEAR DB
  508. @param bool $persistent DB connections are either persistent or not persistent
  509. @return boolean 
  510. */
  511. function setDBConnParms($dsn$persistent=false)
  512. {
  513.     if (!is_string($dsn)) {
  514.         $this->error('initdb: $dsn is not an string.');
  515.         return false;
  516.     }
  517.     if (!is_bool($persistent)) {
  518.         $this->error('initdb: $persistent is not a boolean.');
  519.         return false;
  520.     }
  521.     $this->dsn $dsn;
  522.     $this->persistent $persistent;
  523.     return true;
  524. }
  525.  
  526. /**
  527. * The method to set the name of the table storing data describing the menu
  528. @access public
  529. @param string 
  530. @return boolean 
  531. */
  532. function setTableName($tableName)
  533. {
  534.     if (!is_string($tableName)) {
  535.         $this->error('setTableName: $tableName is not a string.');
  536.         return false;
  537.     }
  538.     $this->tableName $tableName;
  539.     return true;
  540. }
  541.  
  542. /**
  543. * The method to set the name of the i18n table corresponding to $tableName
  544. @access public
  545. @param string 
  546. @return boolean 
  547. */
  548. function setTableName_i18n($tableName_i18n)
  549. {
  550.     if (!is_string($tableName_i18n)) {
  551.         $this->error('setTableName_i18n: $tableName_i18n is not a string.');
  552.         return false;
  553.     }
  554.     $this->tableName_i18n $tableName_i18n;
  555.     return true;
  556. }
  557.  
  558. /**
  559. * The method to set names of fields of the table storing data describing the menu
  560. @access public
  561. @param array 
  562. @return boolean 
  563. */
  564. function setTableFields($tableFields)
  565. {
  566.     if (!is_array($tableFields)) {
  567.         $this->error('setTableFields: $tableFields is not an array.');
  568.         return false;
  569.     }
  570.     if (count($tableFields== 0{
  571.         $this->error('setTableFields: $tableFields is a zero-length array.');
  572.         return false;
  573.     }
  574.     reset ($tableFields);
  575.     while (list($key$valueeach($tableFields)) {
  576.         $this->tableFields[$key($value == ''"''" $value;
  577.     }
  578.     return true;
  579. }
  580.  
  581. /**
  582. * The method to set names of fields of the i18n table corresponding to $tableName
  583. @access public
  584. @param array 
  585. @return boolean 
  586. */
  587. function setTableFields_i18n($tableFields_i18n)
  588. {
  589.     if (!is_array($tableFields_i18n)) {
  590.         $this->error('setTableFields_i18n: $tableFields_i18n is not an array.');
  591.         return false;
  592.     }
  593.     if (count($tableFields_i18n== 0{
  594.         $this->error('setTableFields_i18n: $tableFields_i18n is a zero-length array.');
  595.         return false;
  596.     }
  597.     reset ($tableFields_i18n);
  598.     while (list($key$valueeach($tableFields_i18n)) {
  599.         $this->tableFields_i18n[$key($value == ''"''" $value;
  600.     }
  601.     return true;
  602. }
  603.  
  604. /**
  605. * The method to parse the current menu structure and correspondingly update related variables
  606. @access public
  607. @param string $menu_name the name to be attributed to the menu
  608. *    whose structure has to be parsed
  609. @return void 
  610. */
  611.     $menu_name ''    // non consistent default...
  612.     )
  613. {
  614.     $this->_maxLevel[$menu_name0;
  615.     $this->_firstLevelCnt[$menu_name0;
  616.     $this->_firstItem[$menu_name$this->_nodesCount 1;
  617.     $cnt $this->_firstItem[$menu_name];
  618.     $menuStructure $this->menuStructure;
  619.  
  620.     /* *********************************************** */
  621.     /* Partially based on a piece of code taken from   */
  622.     /* TreeMenu 1.1 - Bjorge Dijkstra (bjorge@gmx.net) */
  623.     /* *********************************************** */
  624.  
  625.     while ($menuStructure != ''{
  626.         $before_cr strcspn($menuStructure"\n");
  627.         $buffer substr($menuStructure0$before_cr);
  628.         $menuStructure substr($menuStructure$before_cr+1);
  629.         if (substr($buffer01== '#'{
  630.             continue;    // commented item line...
  631.         }
  632.         $tmp rtrim($buffer);
  633.         $node explode($this->separator$tmp);
  634.         for ($i=count($node)$i<=6$i++{
  635.             $node[$i'';
  636.         }
  637.         $this->tree[$cnt]['level'strlen($node[0]);
  638.         $this->tree[$cnt]['text'$node[1];
  639.         $this->tree[$cnt]['href'$node[2];
  640.         $this->tree[$cnt]['title'$node[3];
  641.         $this->tree[$cnt]['icon'$node[4];
  642.         $this->tree[$cnt]['target'$node[5];
  643.         $this->tree[$cnt]['expanded'$node[6];
  644.         $cnt++;
  645.     }
  646.  
  647.     /* *********************************************** */
  648.  
  649.     $this->_lastItem[$menu_namecount($this->tree);
  650.     $this->_nodesCount $this->_lastItem[$menu_name];
  651.     $this->tree[$this->_lastItem[$menu_name]+1]['level'0;
  652.     $this->_postParse($menu_name);
  653. }
  654.  
  655. /**
  656. * The method to parse the current menu table and correspondingly update related variables
  657. @access public
  658. @param string $menu_name the name to be attributed to the menu
  659. *    whose structure has to be parsed
  660. @param string $language i18n language; either omit it or pass
  661. *    an empty string ('') if you do not want to use any i18n table
  662. @return void 
  663. */
  664. function scanTableForMenu(
  665.     $menu_name ''// non consistent default...
  666.     $language ''
  667.     )
  668. {
  669.     $this->_maxLevel[$menu_name0;
  670.     $this->_firstLevelCnt[$menu_name0;
  671.     unset($this->tree[$this->_nodesCount+1]);
  672.     $this->_firstItem[$menu_name$this->_nodesCount 1;
  673. /* BEGIN BENCHMARK CODE
  674. $time_start = $this->_getmicrotime();
  675. /* END BENCHMARK CODE */
  676.     $db DB::connect($this->dsn$this->persistent);
  677.     if (DB::isError($db)) {
  678.         $this->error('scanTableForMenu: ' $db->getMessage());
  679.     }
  680.     $dbresult $db->query('
  681.         SELECT ' .
  682.             $this->tableFields['id'' AS id, ' .
  683.             $this->tableFields['parent_id'' AS parent_id, ' .
  684.             $this->tableFields['text'' AS text, ' .
  685.             $this->tableFields['href'' AS href, ' .
  686.             $this->tableFields['title'' AS title, ' .
  687.             $this->tableFields['icon'' AS icon, ' .
  688.             $this->tableFields['target'' AS target, ' .
  689.             $this->tableFields['expanded'' AS expanded
  690.         FROM ' $this->tableName '
  691.         WHERE ' $this->tableFields['id'' <> 1
  692.         ORDER BY ' $this->tableFields['orderfield'', ' $this->tableFields['text'' ASC
  693.     ');
  694.     $this->_tmpArray array();
  695.     while ($dbresult->fetchInto($rowDB_FETCHMODE_ASSOC)) {
  696.         $this->_tmpArray[$row['id']]['parent_id'$row['parent_id'];
  697.         $this->_tmpArray[$row['id']]['text'$row['text'];
  698.         $this->_tmpArray[$row['id']]['href'$row['href'];
  699.         $this->_tmpArray[$row['id']]['title'$row['title'];
  700.         $this->_tmpArray[$row['id']]['icon'$row['icon'];
  701.         $this->_tmpArray[$row['id']]['target'$row['target'];
  702.         $this->_tmpArray[$row['id']]['expanded'$row['expanded'];
  703.     }
  704.     if ($language != ''{
  705.         $dbresult $db->query('
  706.             SELECT ' .
  707.                 $this->tableFields_i18n['id'' AS id, ' .
  708.                 $this->tableFields_i18n['text'' AS text, ' .
  709.                 $this->tableFields_i18n['title'' AS title
  710.             FROM ' $this->tableName_i18n '
  711.             WHERE ' $this->tableFields_i18n['id'' <> 1
  712.                 AND ' $this->tableFields_i18n['language'' = ' "'$language''
  713.         ');
  714.         while ($dbresult->fetchInto($rowDB_FETCHMODE_ASSOC)) {
  715.             if (isset($this->_tmpArray[$row['id']])) {
  716.                 $this->_tmpArray[$row['id']]['text'$row['text'];
  717.                 $this->_tmpArray[$row['id']]['title'$row['title'];
  718.             }
  719.         }
  720.     }
  721.     unset($dbresult);
  722.     unset($row);
  723.     $this->_depthFirstSearch($menu_name$this->_tmpArray11);
  724. /* BEGIN BENCHMARK CODE
  725. $time_end = $this->_getmicrotime();
  726. $time = $time_end - $time_start;
  727. print "TIME ELAPSED = $time\n<br>";
  728. /* END BENCHMARK CODE */
  729.     $this->_lastItem[$menu_namecount($this->tree);
  730.     $this->_nodesCount $this->_lastItem[$menu_name];
  731.     $this->tree[$this->_lastItem[$menu_name]+1]['level'0;
  732.     $this->_postParse($menu_name);
  733. }
  734.  
  735. function _getmicrotime()
  736. {
  737.     list($usec$secexplode(' 'microtime());
  738.     return ((float) $usec + (float) $sec);
  739. }
  740.  
  741. /**
  742. * Recursive method to perform the depth-first search of the tree data taken from the current menu table
  743. @access private
  744. @param string $menu_name the name to be attributed to the menu
  745. *    whose structure has to be parsed
  746. @param array $tmpArray the temporary array that stores data to perform
  747. *    the depth-first search
  748. @param integer $parent_id id of the item whose children have
  749. *    to be searched for
  750. @param integer $level the hierarchical level of children to be searched for
  751. @return void 
  752. */
  753. function _depthFirstSearch($menu_name$tmpArray$parent_id=1$level=1)
  754. {
  755.     reset ($tmpArray);
  756.     while (list($id$foobareach($tmpArray)) {
  757.         if ($foobar['parent_id'== $parent_id{
  758.             unset($tmpArray[$id]);
  759.             unset($this->_tmpArray[$id]);
  760.             $cnt count($this->tree1;
  761.             $this->tree[$cnt]['level'$level;
  762.             $this->tree[$cnt]['text'$foobar['text'];
  763.             $this->tree[$cnt]['href'$foobar['href'];
  764.             $this->tree[$cnt]['title'$foobar['title'];
  765.             $this->tree[$cnt]['icon'$foobar['icon'];
  766.             $this->tree[$cnt]['target'$foobar['target'];
  767.             $this->tree[$cnt]['expanded'$foobar['expanded'];
  768.             $this->treecnt[$menu_name][$id$cnt;
  769.             unset($foobar);
  770.             if ($id != $parent_id{
  771.                 $this->_depthFirstSearch($menu_name$this->_tmpArray$id$level+1);
  772.             }
  773.         }
  774.     }
  775. }
  776.  
  777. /**
  778. * A method providing parsing needed after both file/string parsing and DB table parsing
  779. @access private
  780. @param string $menu_name the name of the menu for which the parsing
  781. *    has to be performed
  782. @return void 
  783. */
  784. function _postParse(
  785.     $menu_name ''    // non consistent default...
  786.     )
  787. {
  788.     for ($cnt=$this->_firstItem[$menu_name]$cnt<=$this->_lastItem[$menu_name]$cnt++{    // this counter scans all nodes of the new menu
  789.         $this->tree[$cnt]['child_of_root_node'($this->tree[$cnt]['level'== 1);
  790.         $this->tree[$cnt]['parsed_text'stripslashes($this->tree[$cnt]['text']);
  791.         $this->tree[$cnt]['parsed_href'(ereg_replace(' '''$this->tree[$cnt]['href']== '''#' $this->prependedUrl $this->tree[$cnt]['href'];
  792.         $this->tree[$cnt]['parsed_title'($this->tree[$cnt]['title'== '''' ' title="' stripslashes($this->tree[$cnt]['title']'"';
  793.         $fooimg $this->icondir $this->tree[$cnt]['icon'];
  794.         if ($this->tree[$cnt]['icon'!= '' && (substr($this->tree[$cnt]['icon']07== 'http://' || substr($this->tree[$cnt]['icon']08== 'https://')) {
  795.             $this->tree[$cnt]['parsed_icon'$this->tree[$cnt]['icon'];
  796.             if ($this->issetIconsize{
  797.                 $this->tree[$cnt]['iconwidth'$this->iconsize['width'];
  798.                 $this->tree[$cnt]['iconheight'$this->iconsize['height'];
  799.             else {
  800.                 $foobar getimagesize($this->tree[$cnt]['icon']);
  801.                 $this->tree[$cnt]['iconwidth'$foobar[0];
  802.                 $this->tree[$cnt]['iconheight'$foobar[1];
  803.             }
  804.         elseif ($this->tree[$cnt]['icon'!= '' && file_exists($fooimg)) {
  805.             $this->tree[$cnt]['parsed_icon'$this->iconwww $this->tree[$cnt]['icon'];
  806.             if ($this->issetIconsize{
  807.                 $this->tree[$cnt]['iconwidth'$this->iconsize['width'];
  808.                 $this->tree[$cnt]['iconheight'$this->iconsize['height'];
  809.             else {
  810.                 $foobar getimagesize($fooimg);
  811.                 $this->tree[$cnt]['iconwidth'$foobar[0];
  812.                 $this->tree[$cnt]['iconheight'$foobar[1];
  813.             }
  814.         else {
  815.             $this->tree[$cnt]['parsed_icon''';
  816.         }
  817.         $this->tree[$cnt]['parsed_target'($this->tree[$cnt]['target'== '''' ' target="' $this->tree[$cnt]['target''"';
  818. //        $this->tree[$cnt]['expanded'] = ($this->tree[$cnt]['expanded'] == '') ? 0 : $this->tree[$cnt]['expanded'];
  819.         $this->_maxLevel[$menu_namemax($this->_maxLevel[$menu_name]$this->tree[$cnt]['level']);
  820.         if ($this->tree[$cnt]['level'== 1{
  821.             $this->_firstLevelCnt[$menu_name]++;
  822.         }
  823.     }
  824. }
  825.  
  826. /**
  827. * A method to replace strings in all URLs (hrefs) of a menu
  828. @access public
  829. @param string $menu_name the name of the menu for which the replacement
  830. *    has to be performed
  831. @param string $string the string to be replaced
  832. @param string $value the replacement string
  833. @return void 
  834. */
  835. function replaceStringInUrls($menu_name$string$value)
  836. {
  837.     for ($cnt=$this->_firstItem[$menu_name]$cnt<=$this->_lastItem[$menu_name]$cnt++{    // this counter scans all nodes of the new menu
  838.         $this->tree[$cnt]['parsed_href'str_replace($string$value$this->tree[$cnt]['parsed_href']);
  839.     }
  840. }
  841.  
  842. /**
  843. * A method to set the same target for all links of a menu
  844. @access public
  845. @param string $menu_name the name of the menu for which the targets
  846. *    have to be set
  847. @param string $target the target to be set for all links
  848. *    of the $menu_name menu
  849. @return void 
  850. */
  851. function setLinksTargets($menu_name$target)
  852. {
  853.     for ($cnt=$this->_firstItem[$menu_name]$cnt<=$this->_lastItem[$menu_name]$cnt++{    // this counter scans all nodes of the new menu
  854.         $this->tree[$cnt]['parsed_target'' target="' $target '"';
  855.     }
  856. }
  857.  
  858. /**
  859. * A method to select the current item of $menu_name in terms of $cnt, i.e., very likely, in terms of its line number in the corresponding menu structure file (excluding from the count commented out lines, if any)
  860. @access public
  861. @param string $menu_name the name of the menu for which the current item
  862. *    has to be selected
  863. @param integer $count the line number of the current item
  864. *    in the corresponding menu structure file
  865. *    (excluding from the count commented out lines, if any)
  866. @return void 
  867. */
  868. function setSelectedItemByCount($menu_name$count)
  869. {
  870.     if ($count 1{
  871.         $this->error("setSelectedItemByCount: the \$count argument is $count, but \$count can not be lower than 1");
  872.         return;
  873.     }
  874.     if ($count $this->_lastItem[$menu_name$this->_firstItem[$menu_name1{
  875.         $this->error("setSelectedItemByCount: the \$count argument is $count and is larger than the number of items of the '$menu_name' menu");
  876.         return;
  877.     }
  878.     $cnt $this->_firstItem[$menu_name$count 1;
  879.     $this->tree[$cnt]['selected'true;
  880. }
  881.  
  882. /**
  883. * A method to select the current item of $menu_name in terms of the corresponding id (see the DB table structure); obviously, this method can be used only together with the DB support
  884. @access public
  885. @param string $menu_name the name of the menu for which the current item
  886. *    has to be selected
  887. @param integer $id the id of the current item in the corresponding DB table
  888. @return void 
  889. */
  890. function setSelectedItemById($menu_name$id)
  891. {
  892.     if (!isset($this->treecnt[$menu_name][$id])) {
  893.         $this->error("setSelectedItemById: there is not any item with \$id = $id in the '$menu_name' menu");
  894.         return;
  895.     }
  896.     $cnt $this->treecnt[$menu_name][$id];
  897.     $this->tree[$cnt]['selected'true;
  898. }
  899.  
  900. /**
  901. * A method to select the current item of $menu_name specifying a string that occurs in the current URL
  902. @access public
  903. @param string $menu_name the name of the menu for which the current item
  904. *    has to be selected
  905. @param string $url a string that occurs in the current URL
  906. @return void 
  907. */
  908. function setSelectedItemByUrl($menu_name$url)
  909. {
  910.     for ($cnt=$this->_firstItem[$menu_name]$cnt<=$this->_lastItem[$menu_name]$cnt++{  // this counter scans all nodes of the new menu
  911.         if (!(strpos($this->tree[$cnt]['parsed_href']$url=== false)) {
  912.             $this->tree[$cnt]['selected'true;
  913.             break;
  914.         }
  915.     }
  916. }
  917.  
  918. /**
  919. * A method to select the current item of $menu_name specifying a regular expression that matches (a substring of) the current URL; just the same as the setSelectedItemByUrl() method, but using eregi() instead of strpos()
  920. @access public
  921. @param string $menu_name the name of the menu for which the current item
  922. *    has to be selected
  923. @param string $url_eregi the regular expression that matches
  924. *    (a substring of) the current URL
  925. @return void 
  926. */
  927. function setSelectedItemByUrlEregi($menu_name$url_eregi)
  928. {
  929.     for ($cnt=$this->_firstItem[$menu_name]$cnt<=$this->_lastItem[$menu_name]$cnt++{  // this counter scans all nodes of the new menu
  930.         if (eregi($url_eregi$this->tree[$cnt]['parsed_href'])) {
  931.             $this->tree[$cnt]['selected'true;
  932.             break;
  933.         }
  934.     }
  935. }
  936.  
  937. /**
  938. * Method to handle errors
  939. @access private
  940. @param string $errormsg the error message
  941. @return void 
  942. */
  943. function error($errormsg)
  944. {
  945.     print "<b>LayersMenu Error:</b> $errormsg<br />\n";
  946.     if ($this->haltOnError == 'yes'{
  947.         die("<b>Halted.</b><br />\n");
  948.     }
  949. }
  950.  
  951. /* END OF CLASS */
  952.  
  953. ?>

Documentation generated on Fri, 18 Jul 2008 21:47:21 +0200 by phpDocumentor 1.4.1