CMS  Version 3.9
breadcrumbs_manager.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: breadcrumbs.inc
42  *
43  * Description: Display location (not path) breadcrumbs
44  * based on the calling script's identifier and its match
45  * to the site hierarchy chart as specified in site_map
46  * table.
47  *
48  * To add breadcrumbs to your pages:
49  * 1) Add {position:breadcrumbs} to your template, if not already there.
50  * 2) Create code module "Breadcrumbs" linked to site_map module
51  * breadcrumbs, set to global position "breadcrumbs"
52  *
53  * author: Janice Gallant for Sonjara, Inc.
54  *
55  * date: 10/9/10
56  *
57  ***************************************************************/
58 
59 Fakoli::using("site_map");
60 
61 
63 {
65  var $qs;
66  var $url;
67 
68  static $overrideCurrentPage = null;
69  function __construct()
70  {
71  $qs = getCleanQueryString();
72  $this->url = $this->getLink();
73 
74  trace("Breadcrumb url $this->url", 3);
75  $this->qs = preg_replace("/_style=\\w+&*/", "", $qs);
76 
77  $this->breadcrumbs = $this->getTrail();
78  }
79 
87  function getTrail()
88  {
89  $currentSiteMapPage = $this->findPage();
90  trace("Breadcrumbs:: currentSiteMapPage id {$currentSiteMapPage->url}", 3);
91 
92  if(!$currentSiteMapPage)
93  {
94  return "";
95  }
96 
97  $upTreePages = $this->walkUpTree($currentSiteMapPage);
98 
99  $breadcrumbs = $this->walkDownTree($upTreePages);
100 
101  return $breadcrumbs;
102  }
103 
104 
111  function findPage()
112  {
114 
115  $pages = Query::create(SiteMap, "WHERE url =:url")
116  ->bind(":url", $url)
117  ->execute();
118 
119  return (count($pages)) ? $pages[0] : null;
120  }
121 
129  function walkUpTree($currentSiteMapPage)
130  {
131  $upTreePages = array();
132  if(!$currentSiteMapPage) return $upTreePages;
133 
134  $currPage = clone $currentSiteMapPage;
135  // walk up the tree to get all parents of the page
136  while(isset($currPage))
137  {
138  array_push($upTreePages, $currPage);
139  $currPage = $currPage->Parent();
140  }
141 
142  return $upTreePages;
143  }
144 
152  function walkDownTree($upTreePages)
153  {
154  $breadcrumbs = "";
155 
156  if(count($upTreePages) < 2) return $breadcrumbs;
157 
158  $downTreePages = array_reverse($upTreePages);
159 
160  $idx = 0;
161  $last = count($downTreePages) - 1;
162 
163  foreach($downTreePages as $downTreePage)
164  {
165  // Only need qs if this is not the first page
166  // and not the last. Last page is just title, not link
167  if($idx < $last)
168  {
169  $link = ($idx > 0 AND $this->qs) ? "$downTreePage->url?{$this->qs}" : $downTreePage->url;
170  $title = $downTreePage->page_title;
171  $breadcrumbs .= "<a href=\"{$link}\">{$title}</a> &raquo;\n";
172  }
173  else
174  {
175  $breadcrumbs .= $downTreePage->page_title . "\n";
176  }
177 
178  $idx++;
179  }
180 
181  return $breadcrumbs;
182  }
183 
184  function getLink($identifier = null)
185  {
186  global $section;
187 
188  if (!$identifier) $identifier = $_REQUEST["identifier"];
189 
190  if ($section->section == "/")
191  $url = "/$identifier";
192  else
193  $url = "/{$section->section}/$identifier";
194 
195  return $url;
196  }
197 
198 }
199 ?>
$section
Definition: event_form.inc:44
static $overrideCurrentPage
walkUpTree($currentSiteMapPage)
Traverse up the tree through each parent url to find the root.
findPage()
Get the server's url and query the SiteMap table for a match.
getLink($identifier=null)
walkDownTree($upTreePages)
No need to show breadcrumbs if there is just one single node in the tree path.
getTrail()
Gather the breadcrumb trail.
static using()
Import the datamodels, views and manifest for the specified component(s).
Definition: core.inc:116
$pages
Definition: export.inc:38
$identifier
Definition: rss.inc:37