plainmenu.inc.php 7.6 KB

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