1 <?php
2 // PHP Layers Menu 3.2.0-rc (C) 2001-2004 Marco Pratesi - http://www.marcopratesi.it/
4 /**
5 * This file contains the code of the LayersMenu class.
6 * @package PHPLayersMenu
7 */
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 {
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;
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;
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;
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();
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';
175 $this->header = '';
176 $this->listl = '';
177 $this->father_keys = '';
178 $this->father_vals = '';
179 $this->moveLayers = '';
180 $this->_firstLevelMenu = array();
181 $this->footer = '';
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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_name] = false;
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[$cnt] = false;
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_name] = true;
446 }
447 $this->tree[$cnt]['iconsrc'] = $this->tree[$cnt]['parsed_icon'];
448 $this->tree[$cnt]['iconalt'] = 'O';
449 }
450 }
451 }
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);
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 }
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 function newHorizontalMenu(
497 $menu_name = '' // non consistent default...
498 )
499 {
500 if (!isset($this->_firstItem[$menu_name]) || !isset($this->_lastItem[$menu_name])) {
501 $this->error("newHorizontalMenu: the first/last item of the menu '$menu_name' is not defined; please check if you have parsed its menu data.");
502 return 0;
503 }
505 $this->parseCommon($menu_name);
507 $t = new Template_PHPLIB();
508 $t->setFile('tplfile', $this->horizontalMenuTpl);
509 $t->setBlock('tplfile', 'template', 'template_blck');
510 $t->setBlock('template', 'horizontal_menu_cell', 'horizontal_menu_cell_blck');
511 $t->setVar('horizontal_menu_cell_blck', '');
512 $t->setBlock('horizontal_menu_cell', 'cell_link', 'cell_link_blck');
513 $t->setVar('cell_link_blck', '');
514 $t->setBlock('cell_link', 'cell_icon', 'cell_icon_blck');
515 $t->setVar('cell_icon_blck', '');
516 $t->setBlock('cell_link', 'cell_arrow', 'cell_arrow_blck');
517 $t->setVar('cell_arrow_blck', '');
519 $t_sub = new Template_PHPLIB();
520 $t_sub->setFile('tplfile', $this->subMenuTpl);
521 $t_sub->setBlock('tplfile', 'sub_menu_cell', 'sub_menu_cell_blck');
522 $t_sub->setVar('sub_menu_cell_blck', '');
523 $t_sub->setBlock('sub_menu_cell', 'cell_icon', 'cell_icon_blck');
524 $t_sub->setVar('cell_icon_blck', '');
525 $t_sub->setBlock('sub_menu_cell', 'cell_arrow', 'cell_arrow_blck');
526 $t_sub->setVar('cell_arrow_blck', '');
527 $t_sub->setBlock('tplfile', 'separator', 'separator_blck');
528 $t_sub->setVar('separator_blck', '');
530 $this->_firstLevelMenu[$menu_name] = '';
532 $foobar = $this->_firstItem[$menu_name];
533 $this->moveLayers .= "\tvar " . $menu_name . "TOP = getOffsetTop('" . $menu_name . "L" . $foobar . "');\n";
534 $this->moveLayers .= "\tvar " . $menu_name . "HEIGHT = getOffsetHeight('" . $menu_name . "L" . $foobar . "');\n";
536 for ($cnt=$this->_firstItem[$menu_name]; $cnt<=$this->_lastItem[$menu_name]; $cnt++) { // this counter scans all nodes of the new menu
537 if ($this->tree[$cnt]['not_a_leaf']) {
538 // geometrical parameters are assigned to the new layer, related to the above mentioned children
539 if ($this->tree[$cnt]['child_of_root_node']) {
540 $this->moveLayers .= "\tsetTop('" . $this->tree[$cnt]['layer_label'] . "', " . $menu_name . "TOP + " . $menu_name . "HEIGHT);\n";
541 $this->moveLayers .= "\tmoveLayerX1('" . $this->tree[$cnt]['layer_label'] . "', '" . $menu_name . "');\n";
542 }
543 }
545 if ($this->tree[$cnt]['child_of_root_node']) {
546 if ($this->tree[$cnt]['text'] == '---') {
547 continue;
548 }
549 if ($this->tree[$cnt]['not_a_leaf']) {
550 $this->tree[$cnt]['onmouseover'] = ' onmouseover="moveLayerX1(' . "'" . $this->tree[$cnt]['layer_label'] . "', '" . $menu_name . "') ; LMPopUp('" . $this->tree[$cnt]['layer_label'] . "'" . ', false);"';
551 } else {
552 $this->tree[$cnt]['onmouseover'] = ' onmouseover="shutdown();"';
553 }
554 $t->setVar(array(
555 'menu_layer_label' => $menu_name . $this->tree[$cnt]['layer_label'],
556 'imgwww' => $this->imgwww,
557 'transparent' => $this->transparentIcon,
558 'href' => $this->tree[$cnt]['parsed_href'],
559 'onmouseover' => $this->tree[$cnt]['onmouseover'],
560 'title' => $this->tree[$cnt]['parsed_title'],
561 'target' => $this->tree[$cnt]['parsed_target'],
562 'text' => $this->tree[$cnt]['text'],
563 'downsrc' => $this->downArrowImg['src'],
564 'downwidth' => $this->downArrowImg['width'],
565 'downheight' => $this->downArrowImg['height']
566 ));
567 if ($this->tree[$cnt]['parsed_icon'] != '') {
568 $t->setVar(array(
569 'iconsrc' => $this->tree[$cnt]['iconsrc'],
570 'iconwidth' => $this->tree[$cnt]['iconwidth'],
571 'iconheight' => $this->tree[$cnt]['iconheight'],
572 'iconalt' => $this->tree[$cnt]['iconalt'],
573 ));
574 $t->parse('cell_icon_blck', 'cell_icon');
575 } else {
576 $t->setVar('cell_icon_blck', '');
577 }
578 if ($this->tree[$cnt]['not_a_leaf']) {
579 $t->parse('cell_arrow_blck', 'cell_arrow');
580 } else {
581 $t->setVar('cell_arrow_blck', '');
582 }
583 $foobar = $t->parse('cell_link_blck', 'cell_link');
584 $t->setVar(array(
585 'cellwidth' => $this->abscissaStep,
586 'cell_link_blck' => $foobar
587 ));
588 $t->parse('horizontal_menu_cell_blck', 'horizontal_menu_cell', true);
589 } else {
590 if ($this->tree[$cnt]['text'] == '---') {
591 $this->tree[$this->tree[$cnt]['father_node']]['layer_content'] .= $t_sub->parse('separator_blck', 'separator');
592 continue;
593 }
594 if ($this->tree[$cnt]['not_a_leaf']) {
595 $this->tree[$cnt]['onmouseover'] = ' onmouseover="moveLayerX(' . "'" . $this->tree[$cnt]['layer_label'] . "') ; moveLayerY('" . $this->tree[$cnt]['layer_label'] . "') ; LMPopUp('" . $this->tree[$cnt]['layer_label'] . "'". ', false);"';
596 } else {
597 $this->tree[$cnt]['onmouseover'] = ' onmouseover="LMPopUp(' . "'" . $this->tree[$this->tree[$cnt]['father_node']]['layer_label'] . "'" . ', true);"';
598 }
599 $t_sub->setVar(array(
600 'imgwww' => $this->imgwww,
601 'transparent' => $this->transparentIcon,
602 'href' => $this->tree[$cnt]['parsed_href'],
603 'refid' => 'ref' . $this->tree[$cnt]['layer_label'],
604 'onmouseover' => $this->tree[$cnt]['onmouseover'],
605 'title' => $this->tree[$cnt]['parsed_title'],
606 'target' => $this->tree[$cnt]['parsed_target'],
607 'text' => $this->tree[$cnt]['text'],
608 'arrowsrc' => $this->forwardArrowImg['src'],
609 'arrowwidth' => $this->forwardArrowImg['width'],
610 'arrowheight' => $this->forwardArrowImg['height']
611 ));
612 if ($this->_hasIcons[$this->tree[$cnt]['father_node']]) {
613 $t_sub->setVar(array(
614 'iconsrc' => $this->tree[$cnt]['iconsrc'],
615 'iconwidth' => $this->tree[$cnt]['iconwidth'],
616 'iconheight' => $this->tree[$cnt]['iconheight'],
617 'iconalt' => $this->tree[$cnt]['iconalt']
618 ));
619 $t_sub->parse('cell_icon_blck', 'cell_icon');
620 } else {
621 $t_sub->setVar('cell_icon_blck', '');
622 }
623 if ($this->tree[$cnt]['not_a_leaf']) {
624 $t_sub->parse('cell_arrow_blck', 'cell_arrow');
625 } else {
626 $t_sub->setVar('cell_arrow_blck', '');
627 }
628 $this->tree[$this->tree[$cnt]['father_node']]['layer_content'] .= $t_sub->parse('sub_menu_cell_blck', 'sub_menu_cell');
629 }
630 } // end of the "for" cycle scanning all nodes
632 $foobar = $this->_firstLevelCnt[$menu_name] * $this->abscissaStep;
633 $t->setVar('menuwidth', $foobar);
634 $t->setVar(array(
635 'layer_label' => $menu_name,
636 'menubody' => $this->_firstLevelMenu[$menu_name]
637 ));
638 $this->_firstLevelMenu[$menu_name] = $t->parse('template_blck', 'template');
640 $this->_updateFooter($menu_name);
642 return $this->_firstLevelMenu[$menu_name];
643 }
645 /**
646 * Method to preparare a vertical menu.
647 *
648 * This method processes items of a menu to prepare the corresponding
649 * vertical menu code updating many variables; it returns the code
650 * of the corresponding _firstLevelMenu
651 *
652 * @access public
653 * @param string $menu_name the name of the menu whose items have to be processed
654 * @return string
655 */
656 function newVerticalMenu(
657 $menu_name = '' // non consistent default...
658 )
659 {
660 if (!isset($this->_firstItem[$menu_name]) || !isset($this->_lastItem[$menu_name])) {
661 $this->error("newVerticalMenu: the first/last item of the menu '$menu_name' is not defined; please check if you have parsed its menu data.");
662 return 0;
663 }
665 $this->parseCommon($menu_name);
667 $t = new Template_PHPLIB();
668 $t->setFile('tplfile', $this->verticalMenuTpl);
669 $t->setBlock('tplfile', 'template', 'template_blck');
670 $t->setBlock('template', 'vertical_menu_box', 'vertical_menu_box_blck');
671 $t->setVar('vertical_menu_box_blck', '');
672 $t->setBlock('vertical_menu_box', 'vertical_menu_cell', 'vertical_menu_cell_blck');
673 $t->setVar('vertical_menu_cell_blck', '');
674 $t->setBlock('vertical_menu_cell', 'cell_icon', 'cell_icon_blck');
675 $t->setVar('cell_icon_blck', '');
676 $t->setBlock('vertical_menu_cell', 'cell_arrow', 'cell_arrow_blck');
677 $t->setVar('cell_arrow_blck', '');
678 $t->setBlock('vertical_menu_box', 'separator', 'separator_blck');
679 $t->setVar('separator_blck', '');
681 $t_sub = new Template_PHPLIB();
682 $t_sub->setFile('tplfile', $this->subMenuTpl);
683 $t_sub->setBlock('tplfile', 'sub_menu_cell', 'sub_menu_cell_blck');
684 $t_sub->setVar('sub_menu_cell_blck', '');
685 $t_sub->setBlock('sub_menu_cell', 'cell_icon', 'cell_icon_blck');
686 $t_sub->setVar('cell_icon_blck', '');
687 $t_sub->setBlock('sub_menu_cell', 'cell_arrow', 'cell_arrow_blck');
688 $t_sub->setVar('cell_arrow_blck', '');
689 $t_sub->setBlock('tplfile', 'separator', 'separator_blck');
690 $t_sub->setVar('separator_blck', '');
692 $this->_firstLevelMenu[$menu_name] = '';
694 $this->moveLayers .= "\tvar " . $menu_name . "TOP = getOffsetTop('" . $menu_name . "');\n";
695 $this->moveLayers .= "\tvar " . $menu_name . "LEFT = getOffsetLeft('" . $menu_name . "');\n";
696 $this->moveLayers .= "\tvar " . $menu_name . "WIDTH = getOffsetWidth('" . $menu_name . "');\n";
698 for ($cnt=$this->_firstItem[$menu_name]; $cnt<=$this->_lastItem[$menu_name]; $cnt++) { // this counter scans all nodes of the new menu
699 if ($this->tree[$cnt]['not_a_leaf']) {
700 // geometrical parameters are assigned to the new layer, related to the above mentioned children
701 if ($this->tree[$cnt]['child_of_root_node']) {
702 $this->moveLayers .= "\tsetLeft('" . $this->tree[$cnt]['layer_label'] . "', " . $menu_name . "LEFT + " . $menu_name . "WIDTH - menuRightShift);\n";
703 }
704 }
706 if ($this->tree[$cnt]['child_of_root_node']) {
707 if ($this->tree[$cnt]['text'] == '---') {
708 $this->_firstLevelMenu[$menu_name] .= $t->parse('separator_blck', 'separator');
709 continue;
710 }
711 if ($this->tree[$cnt]['not_a_leaf']) {
712 $this->tree[$cnt]['onmouseover'] = ' onmouseover="moveLayerX(' . "'" . $this->tree[$cnt]['layer_label'] . "') ; moveLayerY('" . $this->tree[$cnt]['layer_label'] . "') ; LMPopUp('" . $this->tree[$cnt]['layer_label'] . "'" . ', false);"';
713 } else {
714 $this->tree[$cnt]['onmouseover'] = ' onmouseover="shutdown();"';
715 }
716 $t->setVar(array(
717 'imgwww' => $this->imgwww,
718 'transparent' => $this->transparentIcon,
719 'href' => $this->tree[$cnt]['parsed_href'],
720 'refid' => 'ref' . $this->tree[$cnt]['layer_label'],
721 'onmouseover' => $this->tree[$cnt]['onmouseover'],
722 'title' => $this->tree[$cnt]['parsed_title'],
723 'target' => $this->tree[$cnt]['parsed_target'],
724 'text' => $this->tree[$cnt]['text'],
725 'arrowsrc' => $this->forwardArrowImg['src'],
726 'arrowwidth' => $this->forwardArrowImg['width'],
727 'arrowheight' => $this->forwardArrowImg['height']
728 ));
729 if ($this->_hasIcons[$menu_name]) {
730 $t->setVar(array(
731 'iconsrc' => $this->tree[$cnt]['iconsrc'],
732 'iconwidth' => $this->tree[$cnt]['iconwidth'],
733 'iconheight' => $this->tree[$cnt]['iconheight'],
734 'iconalt' => $this->tree[$cnt]['iconalt']
735 ));
736 $t->parse('cell_icon_blck', 'cell_icon');
737 } else {
738 $t->setVar('cell_icon_blck', '');
739 }
740 if ($this->tree[$cnt]['not_a_leaf']) {
741 $t->parse('cell_arrow_blck', 'cell_arrow');
742 } else {
743 $t->setVar('cell_arrow_blck', '');
744 }
745 $this->_firstLevelMenu[$menu_name] .= $t->parse('vertical_menu_cell_blck', 'vertical_menu_cell');
746 } else {
747 if ($this->tree[$cnt]['text'] == '---') {
748 $this->tree[$this->tree[$cnt]['father_node']]['layer_content'] .= $t_sub->parse('separator_blck', 'separator');
749 continue;
750 }
751 if ($this->tree[$cnt]['not_a_leaf']) {
752 $this->tree[$cnt]['onmouseover'] = ' onmouseover="moveLayerX(' . "'" . $this->tree[$cnt]['layer_label'] . "') ; moveLayerY('" . $this->tree[$cnt]['layer_label'] . "') ; LMPopUp('" . $this->tree[$cnt]['layer_label'] . "'" . ', false);"';
753 } else {
754 $this->tree[$cnt]['onmouseover'] = ' onmouseover="LMPopUp(' . "'" . $this->tree[$this->tree[$cnt]['father_node']]['layer_label'] . "'" . ', true);"';
755 }
756 $t_sub->setVar(array(
757 'imgwww' => $this->imgwww,
758 'transparent' => $this->transparentIcon,
759 'href' => $this->tree[$cnt]['parsed_href'],
760 'refid' => 'ref' . $this->tree[$cnt]['layer_label'],
761 'onmouseover' => $this->tree[$cnt]['onmouseover'],
762 'title' => $this->tree[$cnt]['parsed_title'],
763 'target' => $this->tree[$cnt]['parsed_target'],
764 'text' => $this->tree[$cnt]['text'],
765 'arrowsrc' => $this->forwardArrowImg['src'],
766 'arrowwidth' => $this->forwardArrowImg['width'],
767 'arrowheight' => $this->forwardArrowImg['height']
768 ));
769 if ($this->_hasIcons[$this->tree[$cnt]['father_node']]) {
770 $t_sub->setVar(array(
771 'iconsrc' => $this->tree[$cnt]['iconsrc'],
772 'iconwidth' => $this->tree[$cnt]['iconwidth'],
773 'iconheight' => $this->tree[$cnt]['iconheight'],
774 'iconalt' => $this->tree[$cnt]['iconalt']
775 ));
776 $t_sub->parse('cell_icon_blck', 'cell_icon');
777 } else {
778 $t_sub->setVar('cell_icon_blck', '');
779 }
780 if ($this->tree[$cnt]['not_a_leaf']) {
781 $t_sub->parse('cell_arrow_blck', 'cell_arrow');
782 } else {
783 $t_sub->setVar('cell_arrow_blck', '');
784 }
785 $this->tree[$this->tree[$cnt]['father_node']]['layer_content'] .= $t_sub->parse('sub_menu_cell_blck', 'sub_menu_cell');
786 }
787 } // end of the "for" cycle scanning all nodes
789 $t->setVar(array(
790 'menu_name' => $menu_name,
791 'vertical_menu_cell_blck' => $this->_firstLevelMenu[$menu_name],
792 'separator_blck' => ''
793 ));
794 $this->_firstLevelMenu[$menu_name] = $t->parse('vertical_menu_box_blck', 'vertical_menu_box');
795 $t->setVar('abscissaStep', $this->abscissaStep);
796 $t->setVar(array(
797 'layer_label' => $menu_name,
798 'vertical_menu_box_blck' => $this->_firstLevelMenu[$menu_name]
799 ));
800 $this->_firstLevelMenu[$menu_name] = $t->parse('template_blck', 'template');
802 $this->_updateFooter($menu_name);
804 return $this->_firstLevelMenu[$menu_name];
805 }
807 /**
808 * Method to prepare the header.
809 *
810 * This method obtains the header using collected informations
811 * and the suited JavaScript template; it returns the code of the header
812 *
813 * @access public
814 * @return string
815 */
816 function makeHeader()
817 {
818 $t = new Template_PHPLIB();
819 $this->listl = 'listl = [' . substr($this->listl, 1) . '];';
820 $this->father_keys = 'father_keys = [' . substr($this->father_keys, 1) . '];';
821 $this->father_vals = 'father_vals = [' . substr($this->father_vals, 1) . '];';
822 $t->setFile('tplfile', $this->libjsdir . 'layersmenu-header.ijs');
823 $t->setVar(array(
824 'packageName' => $this->_packageName,
825 'version' => $this->version,
826 'copyright' => $this->copyright,
827 'author' => $this->author,
828 'menuTopShift' => $this->menuTopShift,
829 'menuRightShift'=> $this->menuRightShift,
830 'menuLeftShift' => $this->menuLeftShift,
831 'thresholdY' => $this->thresholdY,
832 'abscissaStep' => $this->abscissaStep,
833 'listl' => $this->listl,
834 'nodesCount' => $this->_nodesCount,
835 'father_keys' => $this->father_keys,
836 'father_vals' => $this->father_vals,
837 'moveLayers' => $this->moveLayers
838 ));
839 $this->header = $t->parse('out', 'tplfile');
840 $this->_headerHasBeenMade = true;
841 return $this->header;
842 }
844 /**
845 * Method that returns the code of the header
846 * @access public
847 * @return string
848 */
849 function getHeader()
850 {
851 if (!$this->_headerHasBeenMade) {
852 $this->makeHeader();
853 }
854 return $this->header;
855 }
857 /**
858 * Method that prints the code of the header
859 * @access public
860 * @return void
861 */
862 function printHeader()
863 {
864 print $this->getHeader();
865 }
867 /**
868 * Method that returns the code of the requested _firstLevelMenu
869 * @access public
870 * @param string $menu_name the name of the menu whose _firstLevelMenu
871 * has to be returned
872 * @return string
873 */
874 function getMenu($menu_name)
875 {
876 return $this->_firstLevelMenu[$menu_name];
877 }
879 /**
880 * Method that prints the code of the requested _firstLevelMenu
881 * @access public
882 * @param string $menu_name the name of the menu whose _firstLevelMenu
883 * has to be printed
884 * @return void
885 */
886 function printMenu($menu_name)
887 {
888 print $this->_firstLevelMenu[$menu_name];
889 }
891 /**
892 * Method to prepare the footer.
893 *
894 * This method obtains the footer using collected informations
895 * and the suited JavaScript template; it returns the code of the footer
896 *
897 * @access public
898 * @return string
899 */
900 function makeFooter()
901 {
902 $t = new Template_PHPLIB();
903 $t->setFile('tplfile', $this->libjsdir . 'layersmenu-footer.ijs');
904 $t->setVar(array(
905 'packageName' => $this->_packageName,
906 'version' => $this->version,
907 'copyright' => $this->copyright,
908 'author' => $this->author,
909 'footer' => $this->footer
911 ));
912 $this->footer = $t->parse('out', 'tplfile');
913 $this->_footerHasBeenMade = true;
914 return $this->footer;
915 }
917 /**
918 * Method that returns the code of the footer
919 * @access public
920 * @return string
921 */
922 function getFooter()
923 {
924 if (!$this->_footerHasBeenMade) {
925 $this->makeFooter();
926 }
927 return $this->footer;
928 }
930 /**
931 * Method that prints the code of the footer
932 * @access public
933 * @return void
934 */
935 function printFooter()
936 {
937 print $this->getFooter();
938 }
940 } /* END OF CLASS */
942 ?>