Documentation is available at menu.class.php
1 <?php
2 /**
3 * @author Jan H. Andersen <jha@ipwsystems.dk>
4 * @author Martin R. Larsen <mrl@ipwsystems.dk>
5 * @copyright {@link http://www.ipwsystems.dk/ IPW Systems a.s}
6 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
7 * @package METAjour
8 * @subpackage extension
9 * $Id: menu.class.php,v 1.4 2005/02/07 10:16:44 jan Exp $
10 */
11
12 require_once($system_path."extension/basicextension.class.php");
13 require_once($system_path."core/structureclass.php");
14 require_once($system_path."core/structureelementclass.php");
15 require_once($system_path."core/templateclass.php");
16
17 class ext_menu extends basicextension {
18
19 var $structureobj ;
20 var $structureread = false;
21
22 function ext_menu() {
23 $this->basicextension();
24 $this->extname = 'menu';
25 $this->structureobj = new structure;
26 }
27
28 function readstructure() {
29 if (!$this->structureread) {;
30 $objectid = $this->structureobj->locatebyname($this->extconfigset);
31 if ($objectid) {
32 $this->structureobj->readobject($objectid);
33 $this->structureread = true;
34 }
35 }
36 }
37
38 function cacheallowed() {
39 // Don't allow caching, if user is logged in
40 if ($this->userhandler->GetLevel() > 0) return false;
41
42 $this->readstructure();
43
44 // To allow caching the structure must have a template attached
45 if ($this->structureobj->elements[0]['templateid']) {
46 $this->settemplate($this->structureobj->elements[0]['templateid']);
47 }
48
49 if ($this->templatefile == '') return false;
50
51 // And caching must be allowed
52 $cacheallowed = $this->structureobj->elements[0]['cacheallowed'];
53 return $cacheallowed;
54 }
55
56 function cachelifetime() {
57 return $this->structureobj->elements[0]['cachelifetime'];
58 }
59
60 function iscached() {
61 return ($this->templatefile) ? $this->smarty->is_cached($this->templatefile, $this->cacheid()) : false;
62 }
63
64 function cacheid() {
65 return md5($this->structureobj->preflanguage);
66 }
67
68 function getconfparams($params) {
69 if (isset($params['cf'])) $this->extconfigset = $params['cf'];
70 if (isset($params['objectid'])) $this->extconfig['objectid'] = $params['objectid'];
71 if (isset($params['cmd'])) $this->extcmd = $params['cmd'];
72 }
73
74 function getstructure($parent, $level=0, $overruleparent=0, $parentids) {
75 global $_documents $_structure
76
77 # Note that this method is addressed directly by showpage.php
78 # when using documents with attached structures
79
80 # Moved here to enable that showpage can call this method
81 # directly without calling _do method
82
83 if (!isset($_structure)) {
84 $_structure = new structureelement;
85 $_structure->readallobjectsbyparentid();
86 }
87
88 if (!isset($_documents)) {
89 $_documents = new document;
90 $_documents->readallobjectsbyobjectid(0);
91 }
92
93 $z = 0;
94 if (sizeof($_structure->elements[$parent]) > 0) {
95 $this->extresult[0]['parentlist'][$this->parentcnt] = $parent;
96 $this->parentcnt++;
97 if ($this->cnt-1 >= 0)
98 $this->extresult[$this->cnt-1]['children'] = sizeof($_structure->elements[$parent]);
99 }
100
101 while ($z < sizeof($_structure->elements[$parent])) {
102 $extresult =& $this->extresult[$this->cnt];
103 $element =& $_structure->elements[$parent][$z];
104 $extresult = $element;
105 $extresult['level'] = $level;
106 $extresult['level0'] = $level - 1;
107
108 if (
109 ('' == $element['name'] || !isset($element['name'])) && '' <> $element['pageid']) {
110 $extresult['name'] = $_documents->elements[$element['pageid']]['name'];
111 }
112 # 'description' is obsolete, but we keep it for compatibility
113 $extresult['description'] = $extresult['name'];
114 $extresult['docaccess'] = 1;
115 $extresult['urltype'] = 0;
116
117 ## 'urltype' == 0 if structureelement is "empty", e.g. a node element
118
119 if (($element['pageid'] != '') AND ($element['pageid'] != '0')) {
120 ## 'urltype' == 1 if 'url' points to an internal page
121 $extresult['url'] = 'showpage.php?pageid=' . $element['pageid'];
122 if (!isset($_documents->elements[$element['pageid']])) {
123 $extresult['docaccess'] = 0;
124 }
125
126 $extresult['urltype'] = 1;
127 }
128
129 if (($element['binfile1'] != '') AND ($element['binfile1'] != '0')) {
130 ## 'urltype' == 1 if 'url' points to an internal file
131 $extresult['url'] = 'getfile.php?objectid=' . $element['binfile1'];
132 $extresult['urltype'] = 1;
133 }
134
135 if ($element['url'] != "") {
136 ## 'urltype' == 2 if 'url' points to an external page
137 $extresult['url'] = str_replace(' ', '%20', $extresult['url']);
138 $extresult['urltype'] = 2;
139 }
140
141 if (!in_array($parent, $parentids))
142 $parentids[] = $parent;
143
144 $extresult['parent'] = $parent;
145 $extresult['parents'] = $parentids;
146
147 if ($overruleparent != 0) $extresult['parent'] = $overruleparent;
148
149 $extresult['children'] = 0;
150 #$extresult['id'] = $element['objectid'];
151
152 $this->cnt++;
153
154 if ($element['structureid'] <> 0) {
155 $this->getstructure($element['structureid'], $level+1, $element['objectid'], $parentids);
156 } else {
157 if ($element['haschild']) $this->getstructure($element['objectid'], $level+1, 0, $parentids);
158 }
159
160 $z++;
161 }
162 }
163
164
165 function _do() {
166 $this->cnt = 0;
167 $this->parentcnt = 0;
168 if (!$this->structureread) {;
169 $objectid = $this->structureobj->locatebyname($this->extconfigset);
170 if ($objectid) {
171 $this->structureobj->readobject($objectid);
172 $this->structureread = true;
173 }
174 }
175
176 switch ($this->extcmd) {
177
178 default:
179
180 $id = false;
181
182 if (isset($_REQUST['only'])) {
183 $id = $_REQUEST['only'];
184 } else {
185 if (isset($this->extconfig['objectid'])) {
186 $id = $this->extconfig['objectid'];
187 } else {
188 $structureobj = new structure;
189 $id = $structureobj->locatebyname($this->extconfigset);
190 }
191 }
192 if ($id) $this->getstructure($id, 1, 0, array());
193 $this->extresult[0]['parentlist'][] = NULL; #strange error : temporary fix
194
195 } #switch
196 }
197
198
199 }
200 ?>
Documentation generated on Thu, 9 Jun 2005 06:52:50 +0200 by phpDocumentor 1.2.3