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

Source for file layersmenu.inc.php

Documentation is available at layersmenu.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 LayersMenu class.
  6. @package PHPLayersMenu
  7. */
  8.  
  9. /**
  10. * This is the LayersMenu class of the PHP Layers Menu library.
  11. *
  12. * This class depends on the LayersMenuCommon class and on the PEAR conforming version of the PHPLib Template class, i.e. on HTML_Template_PHPLIB
  13. *
  14. @version 3.2.0-rc
  15. @package PHPLayersMenu
  16. */
  17. class LayersMenu extends LayersMenuCommon
  18. {
  19.  
  20. /**
  21. * The template to be used for the first level menu of a horizontal menu.
  22. *
  23. * The value of this variable is significant only when preparing
  24. * a horizontal menu.
  25. *
  26. @access private
  27. @var string 
  28. */
  29. var $horizontalMenuTpl;
  30. /**
  31. * The template to be used for the first level menu of a vertical menu.
  32. *
  33. * The value of this variable is significant only when preparing
  34. * a vertical menu.
  35. *
  36. @access private
  37. @var string 
  38. */
  39. var $verticalMenuTpl;
  40. /**
  41. * The template to be used for submenu layers
  42. @access private
  43. @var string 
  44. */
  45. var $subMenuTpl;
  46.  
  47. /**
  48. * A string containing the header needed to use the menu(s) in the page
  49. @access private
  50. @var string 
  51. */
  52. var $header;
  53. /**
  54. * This var tells if the header has been made or not
  55. @access private
  56. @var boolean 
  57. */
  58. var $_headerHasBeenMade false;
  59. /**
  60. * The JS vector to list layers
  61. @access private
  62. @var string 
  63. */
  64. var $listl;
  65. /**
  66. * The JS vector of keys to know the father of each layer
  67. @access private
  68. @var string 
  69. */
  70. var $father_keys;
  71. /**
  72. * The JS vector of vals to know the father of each layer
  73. @access private
  74. @var string 
  75. */
  76. var $father_vals;
  77. /**
  78. * The JS function to set initial positions of all layers
  79. @access private
  80. @var string 
  81. */
  82. var $moveLayers;
  83. /**
  84. * An array containing the code related to the first level menu of each menu
  85. @access private
  86. @var array 
  87. */
  88. var $_firstLevelMenu;
  89. /**
  90. * A string containing the footer needed to use the menu(s) in the page
  91. @access private
  92. @var string 
  93. */
  94. var $footer;
  95. /**
  96. * This var tells if the footer has been made or not
  97. @access private
  98. @var boolean 
  99. */
  100. var $_footerHasBeenMade false;
  101.  
  102. /**
  103. * The image used for forward arrows.
  104. @access private
  105. @var string 
  106. */
  107. var $forwardArrowImg;
  108. /**
  109. * The image used for down arrows.
  110. @access private
  111. @var string 
  112. */
  113. var $downArrowImg;
  114. /**
  115. * A 1x1 transparent icon.
  116. @access private
  117. @var string 
  118. */
  119. var $transparentIcon;
  120. /**
  121. * An array to keep trace of layers containing / not containing icons
  122. @access private
  123. @var array 
  124. */
  125. var $_hasIcons;
  126. /**
  127. * Top offset for positioning of sub menu layers
  128. @access private
  129. @var integer 
  130. */
  131. var $menuTopShift;
  132. /**
  133. * Right offset for positioning of sub menu layers
  134. @access private
  135. @var integer 
  136. */
  137. var $menuRightShift;
  138. /**
  139. * Left offset for positioning of sub menu layers
  140. @access private
  141. @var integer 
  142. */
  143. var $menuLeftShift;
  144. /**
  145. * Threshold for vertical repositioning of a layer
  146. @access private
  147. @var integer 
  148. */
  149. var $thresholdY;
  150. /**
  151. * Step for the left boundaries of layers
  152. @access private
  153. @var integer 
  154. */
  155. var $abscissaStep;
  156.  
  157. /**
  158. * The constructor method; it initializates the menu system
  159. @return void 
  160. */
  161. function LayersMenu(
  162.     $menuTopShift 6,    // Gtk2-like
  163.     $menuRightShift 7,    // Gtk2-like
  164.     $menuLeftShift 2,    // Gtk2-like
  165.     $thresholdY 5,
  166.     $abscissaStep 140
  167.     )
  168. {
  169.     $this->LayersMenuCommon();
  170.  
  171.     $this->horizontalMenuTpl $this->tpldir 'layersmenu-horizontal_menu.ihtml';
  172.     $this->verticalMenuTpl $this->tpldir 'layersmenu-vertical_menu.ihtml';
  173.     $this->subMenuTpl $this->tpldir 'layersmenu-sub_menu.ihtml';
  174.  
  175.     $this->header '';
  176.     $this->listl '';
  177.     $this->father_keys '';
  178.     $this->father_vals '';
  179.     $this->moveLayers '';
  180.     $this->_firstLevelMenu array();
  181.     $this->footer '';
  182.  
  183.     $this->transparentIcon 'transparent.png';
  184.     $this->_hasIcons array();
  185.     $this->forwardArrowImg['src''forward-arrow.png';
  186.     $this->forwardArrowImg['width'4;
  187.     $this->forwardArrowImg['height'7;
  188.     $this->downArrowImg['src''down-arrow.png';
  189.     $this->downArrowImg['width'9;
  190.     $this->downArrowImg['height'5;
  191.     $this->menuTopShift $menuTopShift;
  192.     $this->menuRightShift $menuRightShift;
  193.     $this->menuLeftShift $menuLeftShift;
  194.     $this->thresholdY $thresholdY;
  195.     $this->abscissaStep $abscissaStep;
  196. }
  197.  
  198. /**
  199. * The method to set the value of menuTopShift
  200. @access public
  201. @return void 
  202. */
  203. function setMenuTopShift($menuTopShift)
  204. {
  205.     $this->menuTopShift $menuTopShift;
  206. }
  207.  
  208. /**
  209. * The method to set the value of menuRightShift
  210. @access public
  211. @return void 
  212. */
  213. function setMenuRightShift($menuRightShift)
  214. {
  215.     $this->menuRightShift $menuRightShift;
  216. }
  217.  
  218. /**
  219. * The method to set the value of menuLeftShift
  220. @access public
  221. @return void 
  222. */
  223. function setMenuLeftShift($menuLeftShift)
  224. {
  225.     $this->menuLeftShift $menuLeftShift;
  226. }
  227.  
  228. /**
  229. * The method to set the value of thresholdY
  230. @access public
  231. @return void 
  232. */
  233. function setThresholdY($thresholdY)
  234. {
  235.     $this->thresholdY $thresholdY;
  236. }
  237.  
  238. /**
  239. * The method to set the value of abscissaStep
  240. @access public
  241. @return void 
  242. */
  243. function setAbscissaStep($abscissaStep)
  244. {
  245.     $this->abscissaStep $abscissaStep;
  246. }
  247.  
  248. /**
  249. * The method to set the dirroot directory
  250. @access public
  251. @return boolean 
  252. */
  253. function setDirroot($dirroot)
  254. {
  255.     $oldtpldir $this->tpldir;
  256.     if ($foobar $this->setDirrootCommon($dirroot)) {
  257.         $this->updateTpldir($oldtpldir);
  258.     }
  259.     return $foobar;
  260. }
  261.  
  262. /**
  263. * The method to set the tpldir directory
  264. @access public
  265. @return boolean 
  266. */
  267. function setTpldir($tpldir)
  268. {
  269.     $oldtpldir $this->tpldir;
  270.     if ($foobar $this->setTpldirCommon($tpldir)) {
  271.         $this->updateTpldir($oldtpldir);
  272.     }
  273.     return $foobar;
  274. }
  275.  
  276. /**
  277. * The method to update the templates directory path to the new tpldir
  278. @access private
  279. @return void 
  280. */
  281. function updateTpldir($oldtpldir)
  282. {
  283.     $oldlength strlen($oldtpldir);
  284.     $foobar strpos($this->horizontalMenuTpl$oldtpldir);
  285.     if (!($foobar === false || $foobar != 0)) {
  286.         $this->horizontalMenuTpl $this->tpldir substr($this->horizontalMenuTpl$oldlength);
  287.     }
  288.     $foobar strpos($this->verticalMenuTpl$oldtpldir);
  289.     if (!($foobar === false || $foobar != 0)) {
  290.         $this->verticalMenuTpl $this->tpldir substr($this->verticalMenuTpl$oldlength);
  291.     }
  292.     $foobar strpos($this->subMenuTpl$oldtpldir);
  293.     if (!($foobar === false || $foobar != 0)) {
  294.         $this->subMenuTpl $this->tpldir substr($this->subMenuTpl$oldlength);
  295.     }
  296. }
  297.  
  298. /**
  299. * The method to set horizontalMenuTpl
  300. @access public
  301. @return boolean 
  302. */
  303. function setHorizontalMenuTpl($horizontalMenuTpl)
  304. {
  305.     if (str_replace('/'''$horizontalMenuTpl== $horizontalMenuTpl{
  306.         $horizontalMenuTpl $this->tpldir $horizontalMenuTpl;
  307.     }
  308.     if (!file_exists($horizontalMenuTpl)) {
  309.         $this->error("setHorizontalMenuTpl: file $horizontalMenuTpl does not exist.");
  310.         return false;
  311.     }
  312.     $this->horizontalMenuTpl $horizontalMenuTpl;
  313.     return true;
  314. }
  315.  
  316. /**
  317. * The method to set verticalMenuTpl
  318. @access public
  319. @return boolean 
  320. */
  321. function setVerticalMenuTpl($verticalMenuTpl)
  322. {
  323.     if (str_replace('/'''$verticalMenuTpl== $verticalMenuTpl{
  324.         $verticalMenuTpl $this->tpldir $verticalMenuTpl;
  325.     }
  326.     if (!file_exists($verticalMenuTpl)) {
  327.         $this->error("setVerticalMenuTpl: file $verticalMenuTpl does not exist.");
  328.         return false;
  329.     }
  330.     $this->verticalMenuTpl $verticalMenuTpl;
  331.     return true;
  332. }
  333.  
  334. /**
  335. * The method to set subMenuTpl
  336. @access public
  337. @return boolean 
  338. */
  339. function setSubMenuTpl($subMenuTpl)
  340. {
  341.     if (str_replace('/'''$subMenuTpl== $subMenuTpl{
  342.         $subMenuTpl $this->tpldir $subMenuTpl;
  343.     }
  344.     if (!file_exists($subMenuTpl)) {
  345.         $this->error("setSubMenuTpl: file $subMenuTpl does not exist.");
  346.         return false;
  347.     }
  348.     $this->subMenuTpl $subMenuTpl;
  349.     return true;
  350. }
  351.  
  352. /**
  353. * A method to set transparentIcon
  354. @access public
  355. @param string $transparentIcon a transparentIcon filename (without the path)
  356. @return void 
  357. */
  358. function setTransparentIcon($transparentIcon)
  359. {
  360.     $this->transparentIcon $transparentIcon;
  361. }
  362.  
  363. /**
  364. * The method to set an image to be used for the forward arrow
  365. @access public
  366. @param string $forwardArrowImg the forward arrow image filename
  367. @return boolean 
  368. */
  369. function setForwardArrowImg($forwardArrowImg)
  370. {
  371.     if (!file_exists($this->imgdir $forwardArrowImg)) {
  372.         $this->error('setForwardArrowImg: file ' $this->imgdir $forwardArrowImg ' does not exist.');
  373.         return false;
  374.     }
  375.     $foobar getimagesize($this->imgdir $forwardArrowImg);
  376.     $this->forwardArrowImg['src'$forwardArrowImg;
  377.     $this->forwardArrowImg['width'$foobar[0];
  378.     $this->forwardArrowImg['height'$foobar[1];
  379.     return true;
  380. }
  381.  
  382. /**
  383. * The method to set an image to be used for the down arrow
  384. @access public
  385. @param string $downArrowImg the down arrow image filename
  386. @return boolean 
  387. */
  388. function setDownArrowImg($downArrowImg)
  389. {
  390.     if (!file_exists($this->imgdir $downArrowImg)) {
  391.         $this->error('setDownArrowImg: file ' $this->imgdir $downArrowImg ' does not exist.');
  392.         return false;
  393.     }
  394.     $foobar getimagesize($this->imgdir $downArrowImg);
  395.     $this->downArrowImg['src'$downArrowImg;
  396.     $this->downArrowImg['width'$foobar[0];
  397.     $this->downArrowImg['height'$foobar[1];
  398.     return true;
  399. }
  400.  
  401. /**
  402. * A method providing parsing needed both for horizontal and vertical menus; it can be useful also with the ProcessLayersMenu extended class
  403. @access public
  404. @param string $menu_name the name of the menu for which the parsing
  405. *    has to be performed
  406. @return void 
  407. */
  408. function parseCommon(
  409.     $menu_name ''    // non consistent default...
  410.     )
  411. {
  412.     $this->_hasIcons[$menu_namefalse;
  413.     for ($cnt=$this->_firstItem[$menu_name]$cnt<=$this->_lastItem[$menu_name]$cnt++{    // this counter scans all nodes of the new menu
  414.         $this->_hasIcons[$cntfalse;
  415.         $this->tree[$cnt]['layer_label'"L$cnt";
  416.         $current_node[$this->tree[$cnt]['level']] $cnt;
  417.         if (!$this->tree[$cnt]['child_of_root_node']{
  418.             $this->tree[$cnt]['father_node'$current_node[$this->tree[$cnt]['level']-1];
  419.             $this->father_keys .= ",'L$cnt'";
  420.             $this->father_vals .= ",'" $this->tree[$this->tree[$cnt]['father_node']]['layer_label'"'";
  421.         }
  422.         $this->tree[$cnt]['not_a_leaf'($this->tree[$cnt+1]['level']>$this->tree[$cnt]['level'&& $cnt<$this->_lastItem[$menu_name]);
  423.         // if the above condition is true, the node is not a leaf,
  424.         // hence it has at least a child; if it is false, the node is a leaf
  425.         if ($this->tree[$cnt]['not_a_leaf']{
  426.             // initialize the corresponding layer content trought a void string
  427.             $this->tree[$cnt]['layer_content''';
  428.             // the new layer is accounted for in the layers list
  429.             $this->listl .= ",'" $this->tree[$cnt]['layer_label'"'";
  430.         }
  431. /*
  432.         if ($this->tree[$cnt]['not_a_leaf']) {
  433.             $this->tree[$cnt]['parsed_href'] = '#';
  434.         }
  435. */
  436.         if ($this->tree[$cnt]['parsed_icon'== ''{
  437.             $this->tree[$cnt]['iconsrc'$this->imgwww $this->transparentIcon;
  438.             $this->tree[$cnt]['iconwidth'16;
  439.             $this->tree[$cnt]['iconheight'16;
  440.             $this->tree[$cnt]['iconalt'' ';
  441.         else {
  442.             if ($this->tree[$cnt]['level'1{
  443.                 $this->_hasIcons[$this->tree[$cnt]['father_node']] true;
  444.             else {
  445.                 $this->_hasIcons[$menu_nametrue;
  446.             }
  447.             $this->tree[$cnt]['iconsrc'$this->tree[$cnt]['parsed_icon'];
  448.             $this->tree[$cnt]['iconalt''O';
  449.         }
  450.     }
  451. }
  452.  
  453. /**
  454. * A method needed to update the footer both for horizontal and vertical menus
  455. @access private
  456. @param string $menu_name the name of the menu for which the updating
  457. *    has to be performed
  458. @return void 
  459. */
  460. function _updateFooter(
  461.     $menu_name ''    // non consistent default...
  462.     )
  463. {
  464.     $t new Template_PHPLIB();
  465.     $t->setFile('tplfile'$this->subMenuTpl);
  466.     $t->setBlock('tplfile''template''template_blck');
  467.     $t->setBlock('template''sub_menu_cell''sub_menu_cell_blck');
  468.     $t->setVar('sub_menu_cell_blck''');
  469.     $t->setBlock('template''separator''separator_blck');
  470.     $t->setVar('separator_blck''');
  471.     $t->setVar('abscissaStep'$this->abscissaStep);
  472.  
  473.     for ($cnt=$this->_firstItem[$menu_name]$cnt<=$this->_lastItem[$menu_name]$cnt++{
  474.         if ($this->tree[$cnt]['not_a_leaf']{
  475.             $t->setVar(array(
  476.                 'layer_label'        => $this->tree[$cnt]['layer_label'],
  477.                 'layer_title'        => $this->tree[$cnt]['text'],
  478.                 'sub_menu_cell_blck'    => $this->tree[$cnt]['layer_content']
  479.             ));
  480.             $this->footer .= $t->parse('template_blck''template');
  481.         }
  482.     }
  483. }
  484.  
  485. /**
  486. * Method to preparare a horizontal menu.
  487. *
  488. * This method processes items of a menu to prepare the corresponding
  489. * horizontal menu code updating many variables; it returns the code
  490. * of the corresponding _firstLevelMenu
  491. *
  492. @access public
  493. @param string $menu_name the name of the menu whose items have to be processed
  494. @return string 
  495. */
  496.     $menu_name ''    // non consistent default...
  497.     )
  498. {
  499.     if (!isset($this->_firstItem[$menu_name]|| !isset($this->_lastItem[$menu_name])) {
  500.         $this->error("newHorizontalMenu: the first/last item of the menu '$menu_name' is not defined; please check if you have parsed its menu data.");
  501.         return 0;
  502.     }
  503.  
  504.     $this->parseCommon($menu_name);
  505.  
  506.     $t = new Template_PHPLIB();
  507.     $t->setFile('tplfile', $this->horizontalMenuTpl);
  508.     $t->setBlock('tplfile', 'template', 'template_blck');
  509.     $t->setBlock('template', 'horizontal_menu_cell', 'horizontal_menu_cell_blck');
  510.     $t->setVar('horizontal_menu_cell_blck', '');
  511.     $t->setBlock('horizontal_menu_cell', 'cell_link', 'cell_link_blck');
  512.     $t->setVar('cell_link_blck', '');
  513.     $t->setBlock('cell_link', 'cell_icon', 'cell_icon_blck');
  514.     $t->setVar('cell_icon_blck', '');
  515.     $t->setBlock('cell_link', 'cell_arrow', 'cell_arrow_blck');
  516.     $t->setVar('cell_arrow_blck', '');
  517.  
  518.     $t_sub = new <a href="../Zikula 1.0.1/Template_PHPLIB.html">Template_PHPLIB</a>();
  519.     $t_sub->setFile('tplfile', $this->subMenuTpl);
  520.     $t_sub->setBlock('tplfile', 'sub_menu_cell', 'sub_menu_cell_blck');
  521.     $t_sub->setVar('sub_menu_cell_blck', '');
  522.     $t_sub->setBlock('sub_menu_cell', 'cell_icon', 'cell_icon_blck');
  523.     $t_sub->setVar('cell_icon_blck', '');
  524.     $t_sub->setBlock('sub_menu_cell', 'cell_arrow', 'cell_arrow_blck');
  525.     $t_sub->setVar('cell_arrow_blck', '');
  526.     $t_sub->setBlock('tplfile', 'separator', 'separator_blck');
  527.     $t_sub->setVar('separator_blck', '');
  528.  
  529.     $this->_firstLevelMenu[$menu_name] = '';
  530.  
  531.     $foobar = $this->_firstItem[$menu_name];
  532.     $this->moveLayers .= "\tvar " . $menu_name . "TOP = getOffsetTop('" . $menu_name . "L" . $foobar . "');\n";
  533.     $this->moveLayers .= "\tvar " . $menu_name . "HEIGHT = getOffsetHeight('" . $menu_name . "L" . $foobar . "');\n";
  534.  
  535.     for ($cnt=$this->_firstItem[$menu_name]; $cnt<=$this->_lastItem[$menu_name]; $cnt++) {    // this counter scans all nodes of the new menu
  536.         if ($this->tree[$cnt]['not_a_leaf']) {
  537.             // geometrical parameters are assigned to the new layer, related to the above mentioned children
  538.             if ($this->tree[$cnt]['child_of_root_node']) {
  539.                 $this->moveLayers .= "\tsetTop('" . $this->tree[$cnt]['layer_label'] . "', "  . $menu_name . "TOP + " . $menu_name . "HEIGHT);\n";
  540.                 $this->moveLayers .= "\tmoveLayerX1('" . $this->tree[$cnt]['layer_label'] . "', '" . $menu_name . "');\n";
  541.             }
  542.         }
  543.  
  544.         if ($this->tree[$cnt]['child_of_root_node']) {
  545.             if ($this->tree[$cnt]['text'] == '---') {
  546.                 continue;
  547.             }
  548.             if ($this->tree[$cnt]['not_a_leaf']) {
  549.                 $this->tree[$cnt]['onmouseover'] = ' onmouseover="moveLayerX1(' . "'" . $this->tree[$cnt]['layer_label'] . "', '" . $menu_name . "') ; LMPopUp('" . $this->tree[$cnt]['layer_label'] . "'" . ', false);"';
  550.             } else {
  551.                 $this->tree[$cnt]['onmouseover'] = ' onmouseover="shutdown();"';
  552.             }
  553.             $t->setVar(array(
  554.                 'menu_layer_label'    => $menu_name . $this->tree[$cnt]['layer_label'],
  555.                 'imgwww'        => $this->imgwww,
  556.                 'transparent'        => $this->transparentIcon,
  557.                 'href'            => $this->tree[$cnt]['parsed_href'],
  558.                 'onmouseover'        => $this->tree[$cnt]['onmouseover'],
  559.                 'title'            => $this->tree[$cnt]['parsed_title'],
  560.                 'target'        => $this->tree[$cnt]['parsed_target'],
  561.                 'text'            => $this->tree[$cnt]['text'],
  562.                 'downsrc'        => $this->downArrowImg['src'],
  563.                 'downwidth'        => $this->downArrowImg['width'],
  564.                 'downheight'        => $this->downArrowImg['height']
  565.             ));
  566.             if ($this->tree[$cnt]['parsed_icon'] != '') {
  567.                 $t->setVar(array(
  568.                     'iconsrc'    => $this->tree[$cnt]['iconsrc'],
  569.                     'iconwidth'    => $this->tree[$cnt]['iconwidth'],
  570.                     'iconheight'    => $this->tree[$cnt]['iconheight'],
  571.                     'iconalt'    => $this->tree[$cnt]['iconalt'],
  572.                 ));
  573.                 $t->parse('cell_icon_blck', 'cell_icon');
  574.             } else {
  575.                 $t->setVar('cell_icon_blck', '');
  576.             }
  577.             if ($this->tree[$cnt]['not_a_leaf']) {
  578.                 $t->parse('cell_arrow_blck', 'cell_arrow');
  579.             } else {
  580.                 $t->setVar('cell_arrow_blck', '');
  581.             }
  582.             $foobar = $t->parse('cell_link_blck', 'cell_link');
  583.             $t->setVar(array(
  584.                 'cellwidth'        => $this->abscissaStep,
  585.                 'cell_link_blck'    => $foobar
  586.             ));
  587.             $t->parse('horizontal_menu_cell_blck', 'horizontal_menu_cell', true);
  588.         } else {
  589.             if ($this->tree[$cnt]['text'] == '---') {
  590.                 $this->tree[$this->tree[$cnt]['father_node']]['layer_content'] .= $t_sub->parse('separator_blck', 'separator');
  591.                 continue;
  592.             }
  593.             if ($this->tree[$cnt]['not_a_leaf']) {
  594.                 $this->tree[$cnt]['onmouseover'] = ' onmouseover="moveLayerX(' . "'" . $this->tree[$cnt]['layer_label'] . "') ; moveLayerY('" . $this->tree[$cnt]['layer_label'] . "') ; LMPopUp('" . $this->tree[$cnt]['layer_label'] . "'"', false);"';
  595.             } else {
  596.                 $this->tree[$cnt]['onmouseover'] = ' onmouseover="LMPopUp(' . "'" . $this->tree[$this->tree[$cnt]['father_node']]['layer_label'] . "'" . ', true);"';
  597.             }
  598.             $t_sub->setVar(array(
  599.                 'imgwww'    => $this->imgwww,
  600.                 'transparent'    => $this->transparentIcon,
  601.                 'href'        => $this->tree[$cnt]['parsed_href'],
  602.                 'refid'        => 'ref' . $this->tree[$cnt]['layer_label'],
  603.                 'onmouseover'    => $this->tree[$cnt]['onmouseover'],
  604.                 'title'        => $this->tree[$cnt]['parsed_title'],
  605.                 'target'    => $this->tree[$cnt]['parsed_target'],
  606.                 'text'        => $this->tree[$cnt]['text'],
  607.                 'arrowsrc'    => $this->forwardArrowImg['src'],
  608.                 'arrowwidth'    => $this->forwardArrowImg['width'],
  609.                 'arrowheight'    => $this->forwardArrowImg['height']
  610.             ));
  611.             if ($this->_hasIcons[$this->tree[$cnt]['father_node']]) {
  612.                 $t_sub->setVar(array(
  613.                     'iconsrc'    => $this->tree[$cnt]['iconsrc'],
  614.                     'iconwidth'    => $this->tree[$cnt]['iconwidth'],
  615.                     'iconheight'    => $this->tree[$cnt]['iconheight'],
  616.                     'iconalt'    => $this->tree[$cnt]['iconalt']
  617.                 ));
  618.                 $t_sub->parse('cell_icon_blck', 'cell_icon');
  619.             } else {
  620.                 $t_sub->setVar('cell_icon_blck', '');
  621.             }
  622.             if ($this->tree[$cnt]['not_a_leaf']) {
  623.                 $t_sub->parse('cell_arrow_blck', 'cell_arrow');
  624.             } else {
  625.                 $t_sub->setVar('cell_arrow_blck', '');
  626.             }
  627.             $this->tree[$this->tree[$cnt]['father_node']]['layer_content'] .= $t_sub->parse('sub_menu_cell_blck', 'sub_menu_cell');
  628.         }
  629.     }    // end of the "for" cycle scanning all nodes
  630.     $foobar = $this->_firstLevelCnt[$menu_name] * $this->abscissaStep;
  631.     $t->setVar('menuwidth', $foobar);
  632.     $t->setVar(array(
  633.         'layer_label'    => $menu_name,
  634.         'menubody'    => $this->_firstLevelMenu[$menu_name]
  635.     ));
  636.     $this->_firstLevelMenu[$menu_name] = $t->parse('template_blck', 'template');
  637.  
  638.     $this->_updateFooter($menu_name);
  639.  
  640.     return $this->_firstLevelMenu[$menu_name];
  641. }
  642.  
  643. /**
  644. * Method to preparare a vertical menu.
  645. *
  646. * This method processes items of a menu to prepare the corresponding
  647. * vertical menu code updating many variables; it returns the code
  648. * of the corresponding _firstLevelMenu
  649. *
  650. @access public
  651. @param string $menu_name the name of the menu whose items have to be processed
  652. @return string 
  653. */
  654. function newVerticalMenu(
  655.     $menu_name = ''    // non consistent default...
  656.     )
  657. {
  658.     if (!isset($this->_firstItem[$menu_name]) || !isset($this->_lastItem[$menu_name])) {
  659.         $this->error("newVerticalMenu: the first/last item of the menu '$menu_name' is not defined; please check if you have parsed its menu data.");
  660.         return 0;
  661.     }
  662.  
  663.     $this->parseCommon($menu_name);
  664.  
  665.     $t = new Template_PHPLIB();
  666.     $t->setFile('tplfile', $this->verticalMenuTpl);
  667.     $t->setBlock('tplfile', 'template', 'template_blck');
  668.     $t->setBlock('template', 'vertical_menu_box', 'vertical_menu_box_blck');
  669.     $t->setVar('vertical_menu_box_blck', '');
  670.     $t->setBlock('vertical_menu_box', 'vertical_menu_cell', 'vertical_menu_cell_blck');
  671.     $t->setVar('vertical_menu_cell_blck', '');
  672.     $t->setBlock('vertical_menu_cell', 'cell_icon', 'cell_icon_blck');
  673.     $t->setVar('cell_icon_blck', '');
  674.     $t->setBlock('vertical_menu_cell', 'cell_arrow', 'cell_arrow_blck');
  675.     $t->setVar('cell_arrow_blck', '');
  676.     $t->setBlock('vertical_menu_box', 'separator', 'separator_blck');
  677.     $t->setVar('separator_blck', '');
  678.  
  679.     $t_sub = new <a href="../Zikula 1.0.1/Template_PHPLIB.html">Template_PHPLIB</a>();
  680.     $t_sub->setFile('tplfile', $this->subMenuTpl);
  681.     $t_sub->setBlock('tplfile', 'sub_menu_cell', 'sub_menu_cell_blck');
  682.     $t_sub->setVar('sub_menu_cell_blck', '');
  683.     $t_sub->setBlock('sub_menu_cell', 'cell_icon', 'cell_icon_blck');
  684.     $t_sub->setVar('cell_icon_blck', '');
  685.     $t_sub->setBlock('sub_menu_cell', 'cell_arrow', 'cell_arrow_blck');
  686.     $t_sub->setVar('cell_arrow_blck', '');
  687.     $t_sub->setBlock('tplfile', 'separator', 'separator_blck');
  688.     $t_sub->setVar('separator_blck', '');
  689.  
  690.     $this->_firstLevelMenu[$menu_name] = '';
  691.  
  692.     $this->moveLayers .= "\tvar " . $menu_name . "TOP = getOffsetTop('" . $menu_name . "');\n";
  693.     $this->moveLayers .= "\tvar " . $menu_name . "LEFT = getOffsetLeft('" . $menu_name . "');\n";
  694.     $this->moveLayers .= "\tvar " . $menu_name . "WIDTH = getOffsetWidth('" . $menu_name . "');\n";
  695.  
  696.     for ($cnt=$this->_firstItem[$menu_name]; $cnt<=$this->_lastItem[$menu_name]; $cnt++) {    // this counter scans all nodes of the new menu
  697.         if ($this->tree[$cnt]['not_a_leaf']) {
  698.             // geometrical parameters are assigned to the new layer, related to the above mentioned children
  699.             if ($this->tree[$cnt]['child_of_root_node']) {
  700.                 $this->moveLayers .= "\tsetLeft('" . $this->tree[$cnt]['layer_label'] . "', " . $menu_name . "LEFT + " . $menu_name . "WIDTH - menuRightShift);\n";
  701.             }
  702.         }
  703.  
  704.         if ($this->tree[$cnt]['child_of_root_node']) {
  705.             if ($this->tree[$cnt]['text'] == '---') {
  706.                 $this->_firstLevelMenu[$menu_name] .= $t->parse('separator_blck', 'separator');
  707.                 continue;
  708.             }
  709.             if ($this->tree[$cnt]['not_a_leaf']) {
  710.                 $this->tree[$cnt]['onmouseover'] = ' onmouseover="moveLayerX(' . "'" . $this->tree[$cnt]['layer_label'] . "') ; moveLayerY('" . $this->tree[$cnt]['layer_label'] . "') ; LMPopUp('" . $this->tree[$cnt]['layer_label'] . "'" . ', false);"';
  711.             } else {
  712.                 $this->tree[$cnt]['onmouseover'] = ' onmouseover="shutdown();"';
  713.             }
  714.             $t->setVar(array(
  715.                 'imgwww'    => $this->imgwww,
  716.                 'transparent'    => $this->transparentIcon,
  717.                 'href'        => $this->tree[$cnt]['parsed_href'],
  718.                 'refid'        => 'ref' . $this->tree[$cnt]['layer_label'],
  719.                 'onmouseover'    => $this->tree[$cnt]['onmouseover'],
  720.                 'title'        => $this->tree[$cnt]['parsed_title'],
  721.                 'target'    => $this->tree[$cnt]['parsed_target'],
  722.                 'text'        => $this->tree[$cnt]['text'],
  723.                 'arrowsrc'    => $this->forwardArrowImg['src'],
  724.                 'arrowwidth'    => $this->forwardArrowImg['width'],
  725.                 'arrowheight'    => $this->forwardArrowImg['height']
  726.             ));
  727.             if ($this->_hasIcons[$menu_name]) {
  728.                 $t->setVar(array(
  729.                     'iconsrc'    => $this->tree[$cnt]['iconsrc'],
  730.                     'iconwidth'    => $this->tree[$cnt]['iconwidth'],
  731.                     'iconheight'    => $this->tree[$cnt]['iconheight'],
  732.                     'iconalt'    => $this->tree[$cnt]['iconalt']
  733.                 ));
  734.                 $t->parse('cell_icon_blck', 'cell_icon');
  735.             } else {
  736.                 $t->setVar('cell_icon_blck', '');
  737.             }
  738.             if ($this->tree[$cnt]['not_a_leaf']) {
  739.                 $t->parse('cell_arrow_blck', 'cell_arrow');
  740.             } else {
  741.                 $t->setVar('cell_arrow_blck', '');
  742.             }
  743.             $this->_firstLevelMenu[$menu_name] .= $t->parse('vertical_menu_cell_blck', 'vertical_menu_cell');
  744.         } else {
  745.             if ($this->tree[$cnt]['text'] == '---') {
  746.                 $this->tree[$this->tree[$cnt]['father_node']]['layer_content'] .= $t_sub->parse('separator_blck', 'separator');
  747.                 continue;
  748.             }
  749.             if ($this->tree[$cnt]['not_a_leaf']) {
  750.                 $this->tree[$cnt]['onmouseover'] = ' onmouseover="moveLayerX(' . "'" . $this->tree[$cnt]['layer_label'] . "') ; moveLayerY('" . $this->tree[$cnt]['layer_label'] . "') ; LMPopUp('" . $this->tree[$cnt]['layer_label'] . "'" . ', false);"';
  751.             } else {
  752.                 $this->tree[$cnt]['onmouseover'] = ' onmouseover="LMPopUp(' . "'" . $this->tree[$this->tree[$cnt]['father_node']]['layer_label'] . "'" . ', true);"';
  753.             }
  754.             $t_sub->setVar(array(
  755.                 'imgwww'    => $this->imgwww,
  756.                 'transparent'    => $this->transparentIcon,
  757.                 'href'        => $this->tree[$cnt]['parsed_href'],
  758.                 'refid'        => 'ref' . $this->tree[$cnt]['layer_label'],
  759.                 'onmouseover'    => $this->tree[$cnt]['onmouseover'],
  760.                 'title'        => $this->tree[$cnt]['parsed_title'],
  761.                 'target'    => $this->tree[$cnt]['parsed_target'],
  762.                 'text'        => $this->tree[$cnt]['text'],
  763.                 'arrowsrc'    => $this->forwardArrowImg['src'],
  764.                 'arrowwidth'    => $this->forwardArrowImg['width'],
  765.                 'arrowheight'    => $this->forwardArrowImg['height']
  766.             ));
  767.             if ($this->_hasIcons[$this->tree[$cnt]['father_node']]) {
  768.                 $t_sub->setVar(array(
  769.                     'iconsrc'    => $this->tree[$cnt]['iconsrc'],
  770.                     'iconwidth'    => $this->tree[$cnt]['iconwidth'],
  771.                     'iconheight'    => $this->tree[$cnt]['iconheight'],
  772.                     'iconalt'    => $this->tree[$cnt]['iconalt']
  773.                 ));
  774.                 $t_sub->parse('cell_icon_blck', 'cell_icon');
  775.             } else {
  776.                 $t_sub->setVar('cell_icon_blck', '');
  777.             }
  778.             if ($this->tree[$cnt]['not_a_leaf']) {
  779.                 $t_sub->parse('cell_arrow_blck', 'cell_arrow');
  780.             } else {
  781.                 $t_sub->setVar('cell_arrow_blck', '');
  782.             }
  783.             $this->tree[$this->tree[$cnt]['father_node']]['layer_content'] .= $t_sub->parse('sub_menu_cell_blck', 'sub_menu_cell');
  784.         }
  785.     }    // end of the "for" cycle scanning all nodes
  786.     $t->setVar(array(
  787.         'menu_name'            => $menu_name,
  788.         'vertical_menu_cell_blck'    => $this->_firstLevelMenu[$menu_name],
  789.         'separator_blck'        => ''
  790.     ));
  791.     $this->_firstLevelMenu[$menu_name] = $t->parse('vertical_menu_box_blck', 'vertical_menu_box');
  792.     $t->setVar('abscissaStep', $this->abscissaStep);
  793.     $t->setVar(array(
  794.         'layer_label'            => $menu_name,
  795.         'vertical_menu_box_blck'    => $this->_firstLevelMenu[$menu_name]
  796.     ));
  797.     $this->_firstLevelMenu[$menu_name] = $t->parse('template_blck', 'template');
  798.  
  799.     $this->_updateFooter($menu_name);
  800.  
  801.     return $this->_firstLevelMenu[$menu_name];
  802. }
  803.  
  804. /**
  805. * Method to prepare the header.
  806. *
  807. * This method obtains the header using collected informations
  808. * and the suited JavaScript template; it returns the code of the header
  809. *
  810. @access public
  811. @return string 
  812. */
  813. function makeHeader()
  814. {
  815.     $t = new <a href="../Zikula 1.0.1/Template_PHPLIB.html">Template_PHPLIB</a>();
  816.     $this->listl = 'listl = [' . substr($this->listl, 1) . '];';
  817.     $this->father_keys = 'father_keys = [' . substr($this->father_keys, 1) . '];';
  818.     $this->father_vals = 'father_vals = [' . substr($this->father_vals, 1) . '];';
  819.     $t->setFile('tplfile', $this->libjsdir . 'layersmenu-header.ijs');
  820.     $t->setVar(array(
  821.         'packageName'    => $this->_packageName,
  822.         'version'    => $this->version,
  823.         'copyright'    => $this->copyright,
  824.         'author'    => $this->author,
  825.         'menuTopShift'    => $this->menuTopShift,
  826.         'menuRightShift'=> $this->menuRightShift,
  827.         'menuLeftShift'    => $this->menuLeftShift,
  828.         'thresholdY'    => $this->thresholdY,
  829.         'abscissaStep'    => $this->abscissaStep,
  830.         'listl'        => $this->listl,
  831.         'nodesCount'    => $this->_nodesCount,
  832.         'father_keys'    => $this->father_keys,
  833.         'father_vals'    => $this->father_vals,
  834.         'moveLayers'    => $this->moveLayers
  835.     ));
  836.     $this->header = $t->parse('out', 'tplfile');
  837.     $this->_headerHasBeenMade = true;
  838.     return $this->header;
  839. }
  840.  
  841. /**
  842. * Method that returns the code of the header
  843. @access public
  844. @return string 
  845. */
  846. function getHeader()
  847. {
  848.     if (!$this->_headerHasBeenMade) {
  849.         $this->makeHeader();
  850.     }
  851.     return $this->header;
  852. }
  853.  
  854. /**
  855. * Method that prints the code of the header
  856. @access public
  857. @return void 
  858. */
  859. function printHeader()
  860. {
  861.     print $this->getHeader();
  862. }
  863.  
  864. /**
  865. * Method that returns the code of the requested _firstLevelMenu
  866. @access public
  867. @param string $menu_name the name of the menu whose _firstLevelMenu
  868. *    has to be returned
  869. @return string 
  870. */
  871. function getMenu($menu_name)
  872. {
  873.     return $this->_firstLevelMenu[$menu_name];
  874. }
  875.  
  876. /**
  877. * Method that prints the code of the requested _firstLevelMenu
  878. @access public
  879. @param string $menu_name the name of the menu whose _firstLevelMenu
  880. *    has to be printed
  881. @return void 
  882. */
  883. function printMenu($menu_name)
  884. {
  885.     print $this->_firstLevelMenu[$menu_name];
  886. }
  887.  
  888. /**
  889. * Method to prepare the footer.
  890. *
  891. * This method obtains the footer using collected informations
  892. * and the suited JavaScript template; it returns the code of the footer
  893. *
  894. @access public
  895. @return string 
  896. */
  897. function makeFooter()
  898. {
  899.     $t = new <a href="../Zikula 1.0.1/Template_PHPLIB.html">Template_PHPLIB</a>();
  900.     $t->setFile('tplfile', $this->libjsdir . 'layersmenu-footer.ijs');
  901.     $t->setVar(array(
  902.         'packageName'    => $this->_packageName,
  903.         'version'    => $this->version,
  904.         'copyright'    => $this->copyright,
  905.         'author'    => $this->author,
  906.         'footer'    => $this->footer
  907.         
  908.     ));
  909.     $this->footer = $t->parse('out', 'tplfile');
  910.     $this->_footerHasBeenMade = true;
  911.     return $this->footer;
  912. }
  913.  
  914. /**
  915. * Method that returns the code of the footer
  916. @access public
  917. @return string 
  918. */
  919. function getFooter()
  920. {
  921.     if (!$this->_footerHasBeenMade) {
  922.         $this->makeFooter();
  923.     }
  924.     return $this->footer;
  925. }
  926.  
  927. /**
  928. * Method that prints the code of the footer
  929. @access public
  930. @return void 
  931. */
  932. function printFooter()
  933. {
  934.     print $this->getFooter();
  935. }
  936.  
  937. } /* END OF CLASS */
  938.  

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