CMS  Version 3.9
site_map_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 
59 Fakoli::using("component", "page", "menu", "site_map");
60 
68 {
69  var $pages = array();
70  var $map = array();
71  var $currentContent = array();
72 
73  static $titleFields = array(
74  "Blogs" => "title",
75  "Calendars" => "name",
76  "Document Libraries" => "name",
77  "Component Pages" => "page_title",
78  "Forums" => "title",
79  "Image Galleries" => "gallery_name",
80  "Link Libraries" => "name",
81  "Pages" => "page_title",
82  "Video Galleries" => "gallery_name",
83  );
84 
88  function __construct()
89  {
90  $this->map = IndexedQuery::create(SiteMap, "", "url")->execute();
91 
92  if(!is_array($this->map))
93  {
94  $this->map = array();
95  }
96  }
97 
98  static function updateSiteMap()
99  {
100  trace("SiteMapManager processing method updateSiteMap", 3);
101 
102  $mgr = new SiteMapManager();
103  $mgr->update();
104  }
105 
106  function update()
107  {
108  $this->saveNewContentToSiteMap();
110  $this->setHierarchyFromMenuItems();
111  }
112 
113  /*
114  * Before deleting a page...
115  *
116  * If the page is a leaf, then we don't need to
117  * do anything.
118  *
119  * If the page has a child and parent, link all
120  * the children to its parent.
121  *
122  * If the page has no parent but does have children,
123  * set the parent_url of its children to blank.
124  */
126  {
127  $parent = $siteMapPage->Parent();
128 
129  $children = $siteMapPage->Children();
130  if(count($children) > 0)
131  {
132  foreach($children as $child)
133  {
134  $child->parent_url = ($parent AND $parent->url) ?
135  $parent->url : "";
136  $child->save();
137  }
138  }
139  $siteMapPage->delete();
140  }
141 
147  {
148  $indexedMap = $this->map;
149 
150  $menuItems = GroupedQuery::create(MenuItem, "WHERE menu_id IN (SELECT menu_id FROM menu WHERE identifier='global')", "url")
151  ->execute();
152 
153  if(!count($menuItems)) return;
154 
155  foreach($menuItems as $url => $urlItems)
156  {
157  if(array_key_exists($url, $indexedMap))
158  {
159  $siteMapPage = $indexedMap[$url];
160 
161  if(!is_array($urlItems)) $urlItems = array($urlItems);
162 
163  foreach($urlItems as $menuItem)
164  {
165  $parent = $menuItem->Parent();
166  if(!$parent || $parent->url == $siteMapPage->url) continue;
167 
168  if($parent AND $parent->url != $siteMapPage->parent_url)
169  {
170  $siteMapPage->parent_url = $parent->url;
171  $siteMapPage->published = true;
172  $siteMapPage->sort_order = $menuItem->sort_order;
173  $siteMapPage->filter = new InclusionFilter("parent_url", "published");
174  $siteMapPage->save();
175  break;
176  }
177  }
178  }
179  }
180  }
181 
187  {
188  foreach($this->map as $url => $siteMapPage)
189  {
190  if(array_search($url, $this->currentContent) === FALSE)
191  {
193  }
194  }
195  }
196 
197 
202  function getTitle($content, $type, $item)
203  {
204  if ($content->override_page_title)
205  {
206  $title = $content->override_page_title;
207  }
208  else if(array_key_exists($type, SiteMapManager::$titleFields))
209  {
211  $title = $item->$field;
212  }
213  else
214  {
215  $title = prettify($item->identifier);
216  }
217 
218  return $title;
219  }
220 
226  {
227  $itemsByType = array();
229 
230  $sections = Query::create(Section, "ORDER BY section")->execute();
231 
232  foreach($sections as $section)
233  {
234  $content = $section->Content("ORDER BY identifier");
235  $contentByIdentifier = reindexList($content, "identifier");
236 
237  // e.g., type is Component Pages and items are all component pages
238  foreach($itemsByType as $type => $items)
239  {
240  foreach($items as $item)
241  {
242  if (!$item->identifier || !array_key_exists($item->identifier, $contentByIdentifier)) continue;
243 
244  trace(get_class($item). " - ".$item->identifier, 3);
245 
246  $content = $contentByIdentifier[$item->identifier];
247  $url = $this->getLink($section, $item->identifier);
248  $page_title = $this->getTitle($content, $type, $item);
249 
250  $siteMapPage = new SiteMap();
251  if(array_key_exists($url, $this->map))
252  {
253  $siteMapPage = $this->map[$url];
254  if($page_title != $siteMapPage->page_title)
255  {
256  $siteMapPage->page_title = $page_title;
257  $siteMapPage->filter = new InclusionFilter("page_title");
258  $siteMapPage->save();
259  }
260  }
261  else
262  {
263  $siteMapPage->url = $url;
264  $siteMapPage->published = true;
265  $siteMapPage->page_title = $page_title;
266  $siteMapPage->save();
267  $this->map[$siteMapPage->url] = $siteMapPage;
268  }
269 
270  $this->currentContent[] = $siteMapPage->url;
271  }
272  }
273  }
274  }
275 
277  {
278  $types = array();
279 
280  foreach($itemsByType as $type => $items)
281  {
282  foreach($items as $item)
283  {
284  $types[$item->identifier] = $type;
285  }
286  }
287 
288  return $types;
289  }
290 
292  {
293  if ($section->section == "/")
294  $url = "/$identifier";
295  else
296  $url = "/{$section->section}/$identifier";
297 
298  return $url;
299  }
300 
301 
302  static function upgradeComponent($version)
303  {
304  $mgr = new SiteMapUpgradeManager();
305  $mgr->upgrade($version);
306  }
307 
309  {
311  return true;
312  }
313 }
314 
315 
317 {
318  function __construct()
319  {
320  }
321 
322  function export()
323  {
324  $xml .= "\n<SiteMapMap>";
325  $xml .= SerializationManager::serialize(SiteMap, "ORDER BY site_map_id");
326  $xml .= "\n</SiteMapMap>";
327  return $xml;
328  }
329 
330  function import($doc, $tx)
331  {
333  }
334 }
335 
336 
338 {
343  static function formatURL($siteMapPage)
344  {
345  if(!$siteMapPage->isLeaf())
346  {
347  return $siteMapPage->format("<b>{url}</b>");
348  }
349 
350  return $siteMapPage->format("{url}");
351  }
352 }
353 ?>
$section
Definition: event_form.inc:44
$menuItem
$menuItems
Definition: menu_items.inc:50
$parent
Definition: templates.inc:42
static fireEvent($event, $parameter=null, $mustBeConsumed=false)
Fire an event to all subscribers as detailed in their manifests.
static using()
Import the datamodels, views and manifest for the specified component(s).
Definition: core.inc:116
Section DataItem, defining the data model for sections within a site.
Definition: section.inc:45
static serialize($class, $constraint="")
Serializes the specified DataItems to XML.
registerHandler($component, $title, $handler)
Registers a serialization handler for a component.
static unserialize($class, $doc, $tx, $save=true)
Instantiates DataItems from the supplied XML document and stores them in the database.
static formatURL($siteMapPage)
Scans the application home directory and PHP include path and builds the component and administration...
saveNewContentToSiteMap()
Gather all CMS content and if an item is not already in the site map, add it.
deleteSiteMapPage($siteMapPage)
categorizeItemTypes($itemsByType)
__construct()
Creates a new ComponentManager object.
removeOldContentFromSiteMap()
Check if the SiteMap contains records of content that has been removed from the site.
static updateSiteMap()
getLink($section, $identifier)
static upgradeComponent($version)
static registerSerializationHandler()
setHierarchyFromMenuItems()
Default the hierarchy of pages to the global menu's hierarchy.
getTitle($content, $type, $item)
Given an instance of a CMS content item, get the title.
$itemsByType
$identifier
Definition: rss.inc:37
if(! $blog->published||! $blog->enable_rss_feed||!checkRole($blog->allow_read)) $url
Definition: rss.inc:58
$types
$siteMapPage
if(array_key_exists("HTTP_IF_MODIFIED_SINCE", $_SERVER)) $content
Definition: styles.css.inc:24