CMS  Version 3.9
menu_view.inc
Go to the documentation of this file.
1 <?php
7 /**************************************************************
8 
9  Copyright (c) 2010 Sonjara, Inc
10 
11  Permission is hereby granted, free of charge, to any person
12  obtaining a copy of this software and associated documentation
13  files (the "Software"), to deal in the Software without
14  restriction, including without limitation the rights to use,
15  copy, modify, merge, publish, distribute, sublicense, and/or sell
16  copies of the Software, and to permit persons to whom the
17  Software is furnished to do so, subject to the following
18  conditions:
19 
20  The above copyright notice and this permission notice shall be
21  included in all copies or substantial portions of the Software.
22 
23  Except as contained in this notice, the name(s) of the above
24  copyright holders shall not be used in advertising or otherwise
25  to promote the sale, use or other dealings in this Software
26  without prior written authorization.
27 
28  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
30  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
32  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
33  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
34  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
35  OTHER DEALINGS IN THE SOFTWARE.
36 
37 *****************************************************************/
38 
39 /**************************************************************
40 
41 Title: module_view.php
42 
43 Description: To view the menu.
44 
45 author Reshma Joshi for Sonjara, Inc.
46 
47 date: 11/09
48 
49 ***************************************************************/
50 
51 Fakoli::using("page", "component", "settings");
52 
53 class MenuView
54 {
55  var $m;
56  var $pages;
58 
59  function MenuView($m)
60  {
61  $this->m = $m;
62 
63  $this->pages = IndexedQuery::create(Page)
64  ->constraints("WHERE site_id=:s")
65  ->indexBy("identifier")
66  ->filter(new InclusionFilter("page_id", "identifier", "published", "role"))
67  ->bind(":s", $this->m->site_id)
68  ->execute();
69 
70  $this->componentPages = IndexedQuery::create(ComponentPage)
71  ->indexBy("identifier")
72  ->execute();
73  }
74 
75  function getLink($menuItem)
76  {
77  if (!checkRole($menuItem->role) || !Settings::checkPermissions($menuItem->permissions)) return null;
78 
79  if ($menuItem->required_parameters)
80  {
81  $params = explode(",", $menuItem->required_parameters);
82 
83  foreach($params as $param)
84  {
85  if (!isset($_GET[$param])) return null;
86  }
87  }
88 
89  if (!MenuManager::testFlags($menuItem->display_flags)) return null;
90 
91  // If the URL field is set explicitly, use that
92  if ($menuItem->url)
93  {
94  if (startsWith($menuItem->url, "http://") || startsWith($menuItem->url, "https://"))
95  {
96  return $menuItem->url;
97  }
98 
99  $link = $menuItem->url;
100  if ($this->queryString) $link .= $this->queryString;
101  return $link;
102  }
103 
104  if ($menuItem->identifier)
105  {
106  if (array_key_exists($menuItem->identifier, $this->pages))
107  {
108  $page = $this->pages[$menuItem->identifier];
109  if (!$page->published)
110  {
111  // No link if the page is unpublished, or the user role doesn't match.
112  return null;
113  }
114 
115  $link = $menuItem->identifier;
116  if ($this->queryString) $link .= $this->queryString;
117  return $link;
118  }
119  else if (array_key_exists($menuItem->identifier, $this->componentPages))
120  {
121  $page = $this->componentPages[$menuItem->identifier];
122 
123  // JDG - remove check role on page 12/14/2011
124  // Allow menu item link to show even if user can't get to page
125  if (!$page->enabled)
126  {
127  // No link if the component page is unpublished.
128  return null;
129  }
130 
131  $link = $menuItem->identifier;
132  if ($this->queryString) $link .= $this->queryString;
133  return $link;
134  }
135  else
136  {
137  return null;
138  }
139  }
140 
141  // No related page or URL - use a placeholder link.
142  return "#";
143  }
144 
145  function getItemCSS($m)
146  {
147  global $menu_identifier;
148  global $identifier;
149  global $section;
150 
151  $classes = array();
152 
153  if ($this->m->highlight_current_item)
154  {
155  if ($m->identifier == $identifier || ($menu_identifier && $m->identifier == $menu_identifier))
156  {
157  $classes[] = "current";
158  }
159  }
160 
161  if ($this->m->highlight_current_section && $m->identifier == $section->default_page)
162  {
163  $classes[] = "current";
164  }
165 
166  if ($m->css_class)
167  {
168  $classes[] = $m->css_class;
169  }
170 
171  return count($classes) > 0 ? " class='".implode(" ", $classes)."'" : "";
172  }
173 
174  function drawView()
175  {
176  global $script;
177 
178  // JDG 2/4/2011 - remove FakoliMenu for now b/c of placement issue
179  /*
180  $script .= <<<ENDSCRIPT
181 <script type="text/javascript">
182 window.addEvent('domready', function() { new FakoliMenu('{$this->m->identifier}'); });
183 </script>
184 ENDSCRIPT;
185 */
186  $startspan = $this->m->wrap_menu_items ? "<span>" : "";
187  $endspan = $this->m->wrap_menu_items ? "</span>" : "";
188 
189  $gmenus = regroupList($this->m->MenuItems("WHERE published=1 ORDER BY sort_order"), "parent_id");
190  if (count($gmenus) == 0) return;
191 
192  ob_start();
193 
194  $css = ($this->m->css_class) ? " class='{$this->m->css_class}'" : "";
195  echo "<ul{$css}>"; // has end tag
196  $found = false;
197 
198  foreach($gmenus[0] as $m)
199  {
200 
201  if ( preg_match('/^\\-\\-*/', $m->title) )
202  {
203  echo "<li><hr/></li>";
204  $found = true;
205  }
206  else
207  {
208  $link = $this->getLink($m);
209  if ($link) $found = true;
210 
211  $mTitle = $m->custom_format ? $m->format($m->custom_format) : $m->title;
212 
213  if(!$gmenus[$m->menu_item_id])
214  {
215  if ($link) echo "<li".$this->getItemCSS($m).">{$startspan}<a href='$link'>$mTitle</a>{$endspan}</li>"; // has et
216  }
217  else
218  {
219  if ($link)
220  {
221  echo "<li".$this->getItemCSS($m).">{$startspan}<a href='$link'>$mTitle</a>"; // no li et
222  if (array_key_exists($m->menu_item_id, $gmenus))
223  {
224  echo "<ul>"; // no ul et
225  foreach ($gmenus[$m->menu_item_id] as $submenu)
226  {
227  $link = $this->getLink($submenu);
228 
229  $smTitle = $submenu->custom_format ? $submenu->format($submenu->custom_format) : $submenu->title;
230 
231  if ($link)
232  {
233  echo "<li".$this->getItemCSS($submenu)."><a href='$link'>$smTitle</a>"; // only one level;
234  if($gmenus[$submenu->menu_item_id])
235  {
236  echo "<ul>";
237  foreach ($gmenus[$submenu->menu_item_id] as $subsubmenu)
238  {
239  $link = $this->getLink($subsubmenu);
240  $ssmTitle = $subsubmenu->custom_format ? $subsubmenu->format($subsubmenu->custom_format) : $subsubmenu->title;
241 
242  if ($link) echo "<li".$this->getItemCSS($subsubmenu)."><a href='$link'>$ssmTitle</a></li>"; // level 3 menus GOOD
243  }
244  echo "</ul>"; // end ul for level 3 //GOOD
245  }
246  else
247  {
248  echo "</li>"; //end tag for level 2 good
249  }
250  }
251  }
252 
253  echo "</ul>";
254  echo $endspan;
255  echo "</li>";
256  }
257  }
258  }
259  }
260  } # main foreach
261 
262  echo "</ul>"; // top level ul
263 
264  $out = ob_get_contents();
265  ob_end_clean();
266 
267  return ($found) ? $out : "";
268  }
269 }
270  ?>
$section
Definition: event_form.inc:44
$page
Definition: help.inc:39
$out
Definition: page.inc:66
$menuItem
static using()
Import the datamodels, views and manifest for the specified component(s).
Definition: core.inc:116
static testFlags($flags)
getItemCSS($m)
Definition: menu_view.inc:145
MenuView($m)
Definition: menu_view.inc:59
$componentPages
Definition: menu_view.inc:57
getLink($menuItem)
Definition: menu_view.inc:75
Definition: page.inc:43
static checkPermissions($permissions, $account=null)
Check all the permissions specified in the given string.
Definition: settings.inc:270
$identifier
Definition: rss.inc:37