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

Source for file plainmenu.inc.php

Documentation is available at plainmenu.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 PlainMenu class.
  6. @package PHPLayersMenu
  7. */
  8.  
  9. /**
  10. * This is the PlainMenu 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.  It provides plain menus, that to do not require JavaScript to work.
  13. *
  14. @version 3.2.0-rc
  15. @package PHPLayersMenu
  16. */
  17. class PlainMenu extends LayersMenuCommon
  18. {
  19.  
  20. /**
  21. * The template to be used for the Plain Menu
  22. */
  23. /**
  24. * An array where we store the Plain Menu code for each menu
  25. @access private
  26. @var array 
  27. */
  28. var $_plainMenu;
  29.  
  30. /**
  31. * The template to be used for the Horizontal Plain Menu
  32. */
  33. /**
  34. * An array where we store the Horizontal Plain Menu code for each menu
  35. @access private
  36. @var array 
  37. */
  38. var $_horizontalPlainMenu;
  39.  
  40. /**
  41. * The constructor method; it initializates some variables
  42. @return void 
  43. */
  44. function PlainMenu()
  45. {
  46.     $this->LayersMenuCommon();
  47.  
  48.     $this->plainMenuTpl = $this->tpldir 'layersmenu-plain_menu.ihtml';
  49.     $this->_plainMenu array();
  50.  
  51.     $this->horizontalPlainMenuTpl = $this->tpldir 'layersmenu-horizontal_plain_menu.ihtml';
  52.     $this->_horizontalPlainMenu array();
  53. }
  54.  
  55. /**
  56. * The method to set the dirroot directory
  57. @access public
  58. @return boolean 
  59. */
  60. function setDirroot($dirroot)
  61. {
  62.     $oldtpldir $this->tpldir;
  63.     if ($foobar $this->setDirrootCommon($dirroot)) {
  64.         $this->updateTpldir($oldtpldir);
  65.     }
  66.     return $foobar;
  67. }
  68.  
  69. /**
  70. * The method to set the tpldir directory
  71. @access public
  72. @return boolean 
  73. */
  74. function setTpldir($tpldir)
  75. {
  76.     $oldtpldir $this->tpldir;
  77.     if ($foobar $this->setTpldirCommon($tpldir)) {
  78.         $this->updateTpldir($oldtpldir);
  79.     }
  80.     return $foobar;
  81. }
  82.  
  83. /**
  84. * The method to update the templates directory path to the new tpldir
  85. @access private
  86. @return void 
  87. */
  88. function updateTpldir($oldtpldir)
  89. {
  90.     $oldlength strlen($oldtpldir);
  91.     $foobar strpos($this->plainMenuTpl$oldtpldir);
  92.     if (!($foobar === false || $foobar != 0)) {
  93.         $this->plainMenuTpl = $this->tpldir substr($this->plainMenuTpl$oldlength);
  94.     }
  95.     $foobar strpos($this->horizontalPlainMenuTpl$oldtpldir);
  96.     if (!($foobar === false || $foobar != 0)) {
  97.         $this->horizontalPlainMenuTpl = $this->tpldir substr($this->horizontalPlainMenuTpl$oldlength);
  98.     }
  99. }
  100.  
  101. /**
  102. * The method to set plainMenuTpl
  103. @access public
  104. @return boolean 
  105. */
  106. function setPlainMenuTpl($plainMenuTpl)
  107. {
  108.     if (str_replace('/'''$plainMenuTpl== $plainMenuTpl{
  109.         $plainMenuTpl $this->tpldir $plainMenuTpl;
  110.     }
  111.     if (!file_exists($plainMenuTpl)) {
  112.         $this->error("setPlainMenuTpl: file $plainMenuTpl does not exist.");
  113.         return false;
  114.     }
  115.     $this->plainMenuTpl = $plainMenuTpl;
  116.     return true;
  117. }
  118.  
  119. /**
  120. * Method to prepare a new Plain Menu.
  121. *
  122. * This method processes items of a menu to prepare and return
  123. * the corresponding Plain Menu code.
  124. *
  125. @access public
  126. @param string $menu_name the name of the menu whose items have to be processed
  127. @return string 
  128. */
  129. function newPlainMenu(
  130.     $menu_name ''    // non consistent default...
  131.     )
  132. {
  133.     $plain_menu_blck '';
  134.     $t new Template_PHPLIB();
  135.     $t->setFile('tplfile'$this->plainMenuTpl);
  136.     $t->setBlock('tplfile''template''template_blck');
  137.     $t->setBlock('template''plain_menu_cell''plain_menu_cell_blck');
  138.     $t->setVar('plain_menu_cell_blck''');
  139.     for ($cnt=$this->_firstItem[$menu_name]$cnt<=$this->_lastItem[$menu_name]$cnt++{
  140.         if ($this->tree[$cnt]['text'== '---'{
  141.             continue;    // separators are significant only for layers-based menus
  142.         }
  143.         $nbsp '';
  144.         for ($i=1$i<$this->tree[$cnt]['level']$i++{
  145.             $nbsp .= '&nbsp;&nbsp;&nbsp;';
  146.         }
  147.         $t->setVar(array(
  148.             'nbsp'        => $nbsp,
  149.             'href'        => $this->tree[$cnt]['parsed_href'],
  150.             'title'        => $this->tree[$cnt]['parsed_title'],
  151.             'target'    => $this->tree[$cnt]['parsed_target'],
  152.             'text'        => $this->tree[$cnt]['parsed_text']
  153.         ));
  154.         $plain_menu_blck .= $t->parse('plain_menu_cell_blck''plain_menu_cell'false);
  155.     }
  156.     $t->setVar('plain_menu_cell_blck'$plain_menu_blck);
  157.     $this->_plainMenu[$menu_name$t->parse('template_blck''template');
  158.  
  159.     return $this->_plainMenu[$menu_name];
  160. }
  161.  
  162. /**
  163. * Method that returns the code of the requested Plain Menu
  164. @access public
  165. @param string $menu_name the name of the menu whose Plain Menu code
  166. *    has to be returned
  167. @return string 
  168. */
  169. function getPlainMenu($menu_name)
  170. {
  171.     return $this->_plainMenu[$menu_name];
  172. }
  173.  
  174. /**
  175. * Method that prints the code of the requested Plain Menu
  176. @access public
  177. @param string $menu_name the name of the menu whose Plain Menu code
  178. *    has to be printed
  179. @return void 
  180. */
  181. function printPlainMenu($menu_name)
  182. {
  183.     print $this->_plainMenu[$menu_name];
  184. }
  185.  
  186. /**
  187. * The method to set horizontalPlainMenuTpl
  188. @access public
  189. @return boolean 
  190. */
  191. function setHorizontalPlainMenuTpl($horizontalPlainMenuTpl)
  192. {
  193.     if (str_replace('/'''$horizontalPlainMenuTpl== $horizontalPlainMenuTpl{
  194.         $horizontalPlainMenuTpl $this->tpldir $horizontalPlainMenuTpl;
  195.     }
  196.     if (!file_exists($horizontalPlainMenuTpl)) {
  197.         $this->error("setHorizontalPlainMenuTpl: file $horizontalPlainMenuTpl does not exist.");
  198.         return false;
  199.     }
  200.     $this->horizontalPlainMenuTpl $horizontalPlainMenuTpl;
  201.     return true;
  202. }
  203.  
  204. /**
  205. * Method to prepare a new Horizontal Plain Menu.
  206. *
  207. * This method processes items of a menu to prepare and return
  208. * the corresponding Horizontal Plain Menu code.
  209. *
  210. @access public
  211. @param string $menu_name the name of the menu whose items have to be processed
  212. @return string 
  213. */
  214.     $menu_name ''    // non consistent default...
  215.     )
  216. {
  217.     $horizontal_plain_menu_blck '';
  218.     $t new Template_PHPLIB();
  219.     $t->setFile('tplfile'$this->horizontalPlainMenuTpl);
  220.     $t->setBlock('tplfile''template''template_blck');
  221.     $t->setBlock('template''horizontal_plain_menu_cell''horizontal_plain_menu_cell_blck');
  222.     $t->setVar('horizontal_plain_menu_cell_blck''');
  223.     $t->setBlock('horizontal_plain_menu_cell''plain_menu_cell''plain_menu_cell_blck');    
  224.     $t->setVar('plain_menu_cell_blck''');
  225.     for ($cnt=$this->_firstItem[$menu_name]$cnt<=$this->_lastItem[$menu_name]$cnt++{
  226.         if ($this->tree[$cnt]['text'== '---'{
  227.             continue;    // separators are significant only for layers-based menus
  228.         }
  229.         if ($this->tree[$cnt]['level'== && $cnt $this->_firstItem[$menu_name]{
  230.             $t->parse('horizontal_plain_menu_cell_blck''horizontal_plain_menu_cell'true);
  231.             $t->setVar('plain_menu_cell_blck''');
  232.         }
  233.         $nbsp '';
  234.         for ($i=1$i<$this->tree[$cnt]['level']$i++{
  235.             $nbsp .= '&nbsp;&nbsp;&nbsp;';
  236.         }
  237.         $t->setVar(array(
  238.             'nbsp'        => $nbsp,
  239.             'href'        => $this->tree[$cnt]['parsed_href'],
  240.             'title'        => $this->tree[$cnt]['parsed_title'],
  241.             'target'    => $this->tree[$cnt]['parsed_target'],
  242.             'text'        => $this->tree[$cnt]['parsed_text']
  243.         ));
  244.         $t->parse('plain_menu_cell_blck''plain_menu_cell'true);
  245.     }
  246.     $t->parse('horizontal_plain_menu_cell_blck''horizontal_plain_menu_cell'true);
  247.     $this->_horizontalPlainMenu[$menu_name$t->parse('template_blck''template');
  248.  
  249.     return $this->_horizontalPlainMenu[$menu_name];
  250. }
  251.  
  252. /**
  253. * Method that returns the code of the requested Horizontal Plain Menu
  254. @access public
  255. @param string $menu_name the name of the menu whose Horizontal Plain Menu code
  256. *    has to be returned
  257. @return string 
  258. */
  259. function getHorizontalPlainMenu($menu_name)
  260. {
  261.     return $this->_horizontalPlainMenu[$menu_name];
  262. }
  263.  
  264. /**
  265. * Method that prints the code of the requested Horizontal Plain Menu
  266. @access public
  267. @param string $menu_name the name of the menu whose Horizontal Plain Menu code
  268. *    has to be printed
  269. @return void 
  270. */
  271. function printHorizontalPlainMenu($menu_name)
  272. {
  273.     print $this->_horizontalPlainMenu[$menu_name];
  274. }
  275.  
  276. /* END OF CLASS */
  277.  
  278. ?>

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