CMS  Version 3.9
page.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 Fakoli::usingFile("framework/join.inc");
40 Fakoli::using("site", "search");
41 
42 class Page extends DataItem implements Searchable
43 {
44  // Fields
45  var $fields = array("page_id" => Number,
46  "identifier" => String,
47  "page_title" => String,
48  "description" => HTML,
49  "site_id" => Number,
50  "template" => String,
51  "meta_tag_description" => Text,
52  "meta_tag_keyword" => String,
53  "php_code_file" => String,
54  "role" => String,
55  "published" => Boolean,
56  "exclude_from_search" => Boolean,
57  "created_date" => Date,
58  "edited_date" => Timestamp,
59  "author" => String
60  );
61 
62  // Relations
63 
64  var $relations = array("PageModuleXrefs" => PageModuleXref,
65  "Modules" => Module,
66  "Site" => Site);
67 
68  var $versioned_fields = array("page_title", "description", "meta_tag_description", "meta_tag_keyword", "author");
69 
70  function PageModuleXrefs($constraint = "ORDER BY position, sort_order")
71  {
72  return $this->getRelatedList(PageModuleXref, "", $constraint);
73  }
74 
75  function Modules($constraint = "ORDER BY position, sort_order")
76  {
77  return $this->crossReference(Module, PageModuleXref, $constraint);
78  }
79 
80  function Site()
81  {
82  return $this->getRelated(Site);
83  }
84 
85  static function findByIdentifier($identifier)
86  {
87  $match = Query::create(Page, "WHERE identifier=:id")
88  ->bind(":id", $identifier)
89  ->executeSingle();
90 
91  return $match;
92  }
93 
94  function getModulesByPosition($constraint = "ORDER BY position, sort_order")
95  {
96  global $section;
97  global $identifier;
98 
99  $join = new InnerJoin();
100  $join->add(Module);
101  $join->add(PageModuleXref);
102 
103  $result = $join->groupedQuery("WHERE page_id={$this->page_id} $constraint", "PageModuleXref.position");
104  $modules = extractGroupedJoinResults(Module, $result);
105 
106  // If no modules have been set, use the section defaults
107  if (count($modules) == 0 && $section)
108  {
109  $content = $section->getContent($identifier);
110  if ($content) $modules = $content->getModulesByPosition($constraint);
111  }
112 
113  if (count($modules) == 0 && $section)
114  {
115  $modules = $section->getModulesByPosition($constraint);
116  }
117 
118  // Merge in global modules
119  $globals = groupedQuery(Module, "WHERE global=1", "global_position");
120  foreach($globals as $position => $modulesAtPosition)
121  {
122  if (array_key_exists($position, $modules))
123  {
124  $modules[$position] = removeDuplicates(array_merge($modulesAtPosition, $modules[$position]));
125  }
126  else
127  {
128  $modules[$position] = $modulesAtPosition;
129  }
130  }
131 
132  return $modules;
133  }
134 
135 
140  function getTemplate()
141  {
142  global $config;
143  global $section;
144 
145  $style = $_REQUEST["_style"];
146  $site = $this->Site();
147  if (!$site)
148  {
149  $site = Site::getSite();
150  }
151 
152  $templateFile = "";
153 
154  switch($style)
155  {
156  case 'print':
157  $templateFile = $site->print_template;
158  break;
159 
160  case 'popup':
161  $templateFile = $site->popup_template;
162  break;
163 
164  case 'mobile':
165  $templateFile = $site->mobile_template;
166 
167  case 'nude':
168  return "<h2>{page_title}</h2>{description}";
169  }
170 
171  if ($section)
172  {
173  if (!$templateFile) $templateFile = $section->getTemplateFile($this->identifier);
174  }
175 
176  if (!$templateFile) $templateFile = $this->template;
177  if (!$templateFile) $templateFile = $site->default_template;
178 
179  $templateFile = ComponentManager::fireEvent("OverrideTemplate", $templateFile);
180 
181  $base = $site->getThemeDirectory();
182  $template = file_get_contents("{$base}/{$templateFile}");
183 
184  return $template;
185  }
186 
191  function getPositions()
192  {
193  $template = $this->getTemplate();
194 
195  $positionMatches = array();
196 
197  preg_match_all("/\{position:(.*?)\}/", $template, $positionMatches, PREG_PATTERN_ORDER);
198 
199  $positions = $positionMatches[1];
200  sort($positions);
201  return $positions;
202  }
203 
204  function getBodyClass()
205  {
207 
208  global $section;
209  if ($section)
210  {
211  $content = $section->getContent($this->identifier);
212  if ($content) return $content->body_class ? $content->body_class : $section->default_body_class;
213  }
214 
215  return "";
216  }
217 
218  /*var $relations = array( "Region" => Region,
219  "Users" => SiteUser);
220 
221  function Region()
222  {
223  return $this->getRelated(Clinic);
224  }
225 
226  function Users()
227  {
228  return $this->getRelatedList(SiteUser);
229  }*/
230 
231  // Constructor
232  function Page()
233  {
234  $this->primary_key = "page_id";
235  $this->table = "page";
236 
237  $this->default_format = "{page_title}";
238 
239  $this->DataItem(func_get_args());
240  }
241 
242  function search($params, $range = null)
243  {
244  trace("Searching Pages", 3);
245 
246  if ($range)
247  {
248  $range = " AND {$this->primary_key} IN (".implode($range, ", ").")";
249  }
250 
251  if (is_object($params))
252  {
253  $search = clone $params;
254  $search->target = $this;
255  $search->remapField("title", "page_title");
256  $search->remapField("keywords", "meta_tag_keyword");
257  $search->remapField("publication_date", "created_date");
258 
259  if (!$search->get("text", "like"))
260  {
261  $search->secondaryFields("meta_tag_keyword", "description");
262  }
263 
264 
265  $constraint = $search->generateConstraint();
266  $constraint .= $constraint ? " AND published=1 AND exclude_from_search=0" : " WHERE published=1 AND exclude_from_search=0";
267  $constraint .= $range;
268 
269  $pages = Query::create(Page, $constraint)
270  ->execute();
271  }
272  else
273  {
274  $params = "%$params%";
275  $pages = Query::create(Page, "WHERE (page_title like :a OR description LIKE :b) AND published=1 AND exclude_from_search=0 $range")
276  ->bind(":a", $params, ":b", $params)
277  ->execute();
278  }
279 
281  }
282 }
283 
285 {
286  var $item;
287 
289  {
290  $this->item = $item;
291  }
292 
293  function getPrimaryKey() { return $this->item->getPrimaryKey(); }
294  function get($field) { return $this->item->get($field); }
295  function prettifyClassName($plural = false) { return $this->item->prettifyClassName($plural = false); }
296  function format($format) { return $this->item->format($format); }
297 
298  function relevance()
299  {
300  return 0.2;
301  }
302 
303  function title()
304  {
305  return $this->item->page_title;
306  }
307 
308  function date()
309  {
310  return $this->item->created_date;
311  }
312 
313  function summary()
314  {
315  $img = $this->formatIcon('/fakoli/richtext/images/hyperlink.gif', 'cms_page');
316 
317  if(Settings::getValue("search", "show_text_fragment"))
318  {
319  return $this->item->format("{$img}<h4>{page_title}</h4><p>{description:300}</p><a href='{identifier}'>Read More</a>");
320 
321  }
322  else
323  {
324  return $this->item->format("{$img}<h4><a href='{identifier}'>{page_title}</a></h4>");
325  }
326  }
327 }
328 
329 class PageModuleXref extends DataItem
330 {
331  // Fields
332  var $fields = array("join_id" => Number,
333  "page_id" => Number,
334  "module_id" => Number,
335  "position" => String,
336  "sort_order" => Number);
337 
338  // Relations
339 
340  var $relations = array( "Page" => Page,
341  "Module" => Module);
342 
343  function Page()
344  {
345  return $this->getRelated(Page);
346  }
347 
348  function Module()
349  {
350  return $this->getRelated(Module);
351  }
352 
353  function PageModuleXref()
354  {
355  $this->table = "page_module_xref";
356  $this->primary_key = "join_id";
357 
358  $this->DataItem(func_get_args());
359  }
360 }
361 
362 class PageSolrAdapter // Implements ISolrAdapter
363 {
364 
365  function getClass()
366  {
367  return Page;
368  }
369 
370  function getFilter()
371  {
372  return "WHERE published=1 AND exclude_from_search=0";
373  }
374 
375  function getTitleFormat()
376  {
377  return "{page_title:xml}";
378  }
379 
380  function getContentFormat()
381  {
382  return "{description:xml}";
383  }
384 
385  function getAuthorFormat()
386  {
387  return "{author:xml}";
388  }
389 
390  function getKeywordFormat()
391  {
392  return "{meta_tag_keyword:xml}";
393  }
394 
395  function wrap($item)
396  {
397  return new PageSearchResult($item);
398  }
399 }?>
$constraint
$range
Definition: error_log.inc:13
$section
Definition: event_form.inc:44
$base
Definition: delete.inc:45
formatIcon($icon, $alt)
Definition: searchable.inc:78
static fireEvent($event, $parameter=null, $mustBeConsumed=false)
Fire an event to all subscribers as detailed in their manifests.
static $bodyClass
Override for the body class of the page currently being served.
Definition: core.inc:89
static using()
Import the datamodels, views and manifest for the specified component(s).
Definition: core.inc:116
static usingFile()
Uses the specified framework file(s) from the framework directory.
Definition: core.inc:369
Defines the Module class.
Definition: module.inc:57
Definition: page.inc:43
getPositions()
Retrieves an array of the position names defined in the template for this page.
Definition: page.inc:191
$relations
Definition: page.inc:64
getBodyClass()
Definition: page.inc:204
search($params, $range=null)
DataItems must implement this method to provide search functionality.
Definition: page.inc:242
Site()
Definition: page.inc:80
$versioned_fields
Definition: page.inc:68
PageModuleXrefs($constraint="ORDER BY position, sort_order")
Definition: page.inc:70
getTemplate()
Loads the template associated with this page.
Definition: page.inc:140
static findByIdentifier($identifier)
Definition: page.inc:85
Page()
Definition: page.inc:232
$fields
Definition: page.inc:45
Modules($constraint="ORDER BY position, sort_order")
Definition: page.inc:75
getModulesByPosition($constraint="ORDER BY position, sort_order")
Definition: page.inc:94
PageModuleXref()
Definition: page.inc:353
format($format)
Definition: page.inc:296
PageSearchResult($item)
Definition: page.inc:288
prettifyClassName($plural=false)
Definition: page.inc:295
summary()
Display the item title and any other essential details for the item such as author and a create date.
Definition: page.inc:313
getAuthorFormat()
Definition: page.inc:385
getTitleFormat()
Definition: page.inc:375
wrap($item)
Definition: page.inc:395
getContentFormat()
Definition: page.inc:380
getKeywordFormat()
Definition: page.inc:390
static wrap($items, $resultClass)
static getValue($component, $name)
Retrieve the value of the specified Setting.
Definition: settings.inc:104
Definition: site.inc:40
static getSite()
Returns the Site object that describes the currently active site (i.e.
Definition: site.inc:103
global $config
Definition: import.inc:4
The Searchable interface must be implemented by any DataItem classes that want to be searchable via t...
Definition: searchable.inc:45
$result
$pages
Definition: export.inc:38
$positions
$identifier
Definition: rss.inc:37
if(array_key_exists("HTTP_IF_MODIFIED_SINCE", $_SERVER)) $content
Definition: styles.css.inc:24