layersmenu.inc.php 28 KB

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