File: plainmenu.inc.php

package info (click to toggle)
libphp-phplayersmenu 3.2.0rc-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,236 kB
  • ctags: 695
  • sloc: php: 2,676; makefile: 68; sh: 20
file content (281 lines) | stat: -rw-r--r-- 7,831 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
<?php
// PHP Layers Menu 3.2.0-rc (C) 2001-2004 Marco Pratesi - http://www.marcopratesi.it/

/**
* This file contains the code of the PlainMenu class.
* @package PHPLayersMenu
*/

/**
* This is the PlainMenu class of the PHP Layers Menu library.
*
* 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.
*
* @version 3.2.0-rc
* @package PHPLayersMenu
*/
class PlainMenu extends LayersMenuCommon
{

/**
* The template to be used for the Plain Menu
*/
var $plainMenuTpl;
/**
* An array where we store the Plain Menu code for each menu
* @access private
* @var array
*/
var $_plainMenu;

/**
* The template to be used for the Horizontal Plain Menu
*/
var $horizontalPlainMenuTpl;
/**
* An array where we store the Horizontal Plain Menu code for each menu
* @access private
* @var array
*/
var $_horizontalPlainMenu;

/**
* The constructor method; it initializates some variables
* @return void
*/
function PlainMenu()
{
	$this->LayersMenuCommon();

	$this->plainMenuTpl = $this->tpldir . 'layersmenu-plain_menu.ihtml';
	$this->_plainMenu = array();

	$this->horizontalPlainMenuTpl = $this->tpldir . 'layersmenu-horizontal_plain_menu.ihtml';
	$this->_horizontalPlainMenu = array();
}

/**
* The method to set the dirroot directory
* @access public
* @return boolean
*/
function setDirroot($dirroot)
{
	$oldtpldir = $this->tpldir;
	if ($foobar = $this->setDirrootCommon($dirroot)) {
		$this->updateTpldir($oldtpldir);
	}
	return $foobar;
}

/**
* The method to set the tpldir directory
* @access public
* @return boolean
*/
function setTpldir($tpldir)
{
	$oldtpldir = $this->tpldir;
	if ($foobar = $this->setTpldirCommon($tpldir)) {
		$this->updateTpldir($oldtpldir);
	}
	return $foobar;
}

/**
* The method to update the templates directory path to the new tpldir
* @access private
* @return void
*/
function updateTpldir($oldtpldir)
{
	$oldlength = strlen($oldtpldir);
	$foobar = strpos($this->plainMenuTpl, $oldtpldir);
	if (!($foobar === false || $foobar != 0)) {
		$this->plainMenuTpl = $this->tpldir . substr($this->plainMenuTpl, $oldlength);
	}
	$foobar = strpos($this->horizontalPlainMenuTpl, $oldtpldir);
	if (!($foobar === false || $foobar != 0)) {
		$this->horizontalPlainMenuTpl = $this->tpldir . substr($this->horizontalPlainMenuTpl, $oldlength);
	}
}

/**
* The method to set plainMenuTpl
* @access public
* @return boolean
*/
function setPlainMenuTpl($plainMenuTpl)
{
	if (str_replace('/', '', $plainMenuTpl) == $plainMenuTpl) {
		$plainMenuTpl = $this->tpldir . $plainMenuTpl;
	}
	if (!file_exists($plainMenuTpl)) {
		$this->error("setPlainMenuTpl: file $plainMenuTpl does not exist.");
		return false;
	}
	$this->plainMenuTpl = $plainMenuTpl;
	return true;
}

/**
* Method to prepare a new Plain Menu.
*
* This method processes items of a menu to prepare and return
* the corresponding Plain Menu code.
*
* @access public
* @param string $menu_name the name of the menu whose items have to be processed
* @return string
*/
function newPlainMenu(
	$menu_name = ''	// non consistent default...
	)
{
	$plain_menu_blck = '';
	$t = new Template_PHPLIB();
	$t->setFile('tplfile', $this->plainMenuTpl);
	$t->setBlock('tplfile', 'template', 'template_blck');
	$t->setBlock('template', 'plain_menu_cell', 'plain_menu_cell_blck');
	$t->setVar('plain_menu_cell_blck', '');
	for ($cnt=$this->_firstItem[$menu_name]; $cnt<=$this->_lastItem[$menu_name]; $cnt++) {
		if ($this->tree[$cnt]['text'] == '---') {
			continue;	// separators are significant only for layers-based menus
		}
		$nbsp = '';
		for ($i=1; $i<$this->tree[$cnt]['level']; $i++) {
			$nbsp .= '&nbsp;&nbsp;&nbsp;';
		}
		$t->setVar(array(
			'nbsp'		=> $nbsp,
			'href'		=> $this->tree[$cnt]['parsed_href'],
			'title'		=> $this->tree[$cnt]['parsed_title'],
			'target'	=> $this->tree[$cnt]['parsed_target'],
			'text'		=> $this->tree[$cnt]['parsed_text']
		));
		$plain_menu_blck .= $t->parse('plain_menu_cell_blck', 'plain_menu_cell', false);
	}
	$t->setVar('plain_menu_cell_blck', $plain_menu_blck);
	$this->_plainMenu[$menu_name] = $t->parse('template_blck', 'template');

	return $this->_plainMenu[$menu_name];
}

/**
* Method that returns the code of the requested Plain Menu
* @access public
* @param string $menu_name the name of the menu whose Plain Menu code
*   has to be returned
* @return string
*/
function getPlainMenu($menu_name)
{
	return $this->_plainMenu[$menu_name];
}

/**
* Method that prints the code of the requested Plain Menu
* @access public
* @param string $menu_name the name of the menu whose Plain Menu code
*   has to be printed
* @return void
*/
function printPlainMenu($menu_name)
{
	print $this->_plainMenu[$menu_name];
}

/**
* The method to set horizontalPlainMenuTpl
* @access public
* @return boolean
*/
function setHorizontalPlainMenuTpl($horizontalPlainMenuTpl)
{
	if (str_replace('/', '', $horizontalPlainMenuTpl) == $horizontalPlainMenuTpl) {
		$horizontalPlainMenuTpl = $this->tpldir . $horizontalPlainMenuTpl;
	}
	if (!file_exists($horizontalPlainMenuTpl)) {
		$this->error("setHorizontalPlainMenuTpl: file $horizontalPlainMenuTpl does not exist.");
		return false;
	}
	$this->horizontalPlainMenuTpl = $horizontalPlainMenuTpl;
	return true;
}

/**
* Method to prepare a new Horizontal Plain Menu.
*
* This method processes items of a menu to prepare and return
* the corresponding Horizontal Plain Menu code.
*
* @access public
* @param string $menu_name the name of the menu whose items have to be processed
* @return string
*/
function newHorizontalPlainMenu(
	$menu_name = ''	// non consistent default...
	)
{
	$horizontal_plain_menu_blck = '';
	$t = new Template_PHPLIB();
	$t->setFile('tplfile', $this->horizontalPlainMenuTpl);
	$t->setBlock('tplfile', 'template', 'template_blck');
	$t->setBlock('template', 'horizontal_plain_menu_cell', 'horizontal_plain_menu_cell_blck');
	$t->setVar('horizontal_plain_menu_cell_blck', '');
	$t->setBlock('horizontal_plain_menu_cell', 'plain_menu_cell', 'plain_menu_cell_blck');	
	$t->setVar('plain_menu_cell_blck', '');
	for ($cnt=$this->_firstItem[$menu_name]; $cnt<=$this->_lastItem[$menu_name]; $cnt++) {
		if ($this->tree[$cnt]['text'] == '---') {
			continue;	// separators are significant only for layers-based menus
		}
		if ($this->tree[$cnt]['level'] == 1 && $cnt > $this->_firstItem[$menu_name]) {
			$t->parse('horizontal_plain_menu_cell_blck', 'horizontal_plain_menu_cell', true);
			$t->setVar('plain_menu_cell_blck', '');
		}
		$nbsp = '';
		for ($i=1; $i<$this->tree[$cnt]['level']; $i++) {
			$nbsp .= '&nbsp;&nbsp;&nbsp;';
		}
		$t->setVar(array(
			'nbsp'		=> $nbsp,
			'href'		=> $this->tree[$cnt]['parsed_href'],
			'title'		=> $this->tree[$cnt]['parsed_title'],
			'target'	=> $this->tree[$cnt]['parsed_target'],
			'text'		=> $this->tree[$cnt]['parsed_text']
		));
		$t->parse('plain_menu_cell_blck', 'plain_menu_cell', true);
	}
	$t->parse('horizontal_plain_menu_cell_blck', 'horizontal_plain_menu_cell', true);
	$this->_horizontalPlainMenu[$menu_name] = $t->parse('template_blck', 'template');

	return $this->_horizontalPlainMenu[$menu_name];
}

/**
* Method that returns the code of the requested Horizontal Plain Menu
* @access public
* @param string $menu_name the name of the menu whose Horizontal Plain Menu code
*   has to be returned
* @return string
*/
function getHorizontalPlainMenu($menu_name)
{
	return $this->_horizontalPlainMenu[$menu_name];
}

/**
* Method that prints the code of the requested Horizontal Plain Menu
* @access public
* @param string $menu_name the name of the menu whose Horizontal Plain Menu code
*   has to be printed
* @return void
*/
function printHorizontalPlainMenu($menu_name)
{
	print $this->_horizontalPlainMenu[$menu_name];
}

} /* END OF CLASS */

?>