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