CMS  Version 3.9
component_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 require_once realpath(dirname(__FILE__)."/../../../../framework/data_item.inc");
40 
41 class ComponentPage extends DataItem
42 {
43  var $primary_key = "component_page_id";
44  var $table = "component_page";
45 
46  var $default_format = "{identifier}";
47 
48  // Fields
49  var $fields = array("component_page_id" => Number,
50  "identifier" => String,
51  "server_path" => String,
52  "component" => String,
53  "page_title" => String,
54  "template" => String,
55  "role" => String,
56  "enabled" => Boolean,
57  "scanned" => Boolean,
58  "site_id" => Number
59  );
60 
61  // Relations
62  var $relations = array(
63  "Component" => Component,
64  "Site" => Site
65  );
66 
67  function Component()
68  {
69  return Component::getComponent($this->component);
70  }
71 
72  function Site()
73  {
74  return $this->getRelated(Site);
75  }
76 
77  function ComponentPageModuleXrefs($constraint = "ORDER BY position, sort_order")
78  {
79  return $this->getRelatedList(ComponentPageModuleXref, "", $constraint);
80  }
81 
82  function Modules($constraint = "ORDER BY position, sort_order")
83  {
84  return $this->crossReference(Module, ComponentPageModuleXref, $constraint);
85  }
86 
87 
88  function getModulesByPosition($constraint = "ORDER BY position, sort_order")
89  {
90  global $section;
91  global $identifier;
92 
93  $join = new InnerJoin();
94  $join->add(Module);
95  $join->add(ComponentPageModuleXref);
96 
97  $result = $join->groupedQuery("WHERE component_page_id={$this->component_page_id} $constraint", "ComponentPageModuleXref.position");
98  $modules = extractGroupedJoinResults(Module, $result);
99 
100  // If no modules have been set, use the section defaults
101  if (count($modules) == 0 && $section)
102  {
103  $content = $section->getContent($identifier);
104  if ($content) $modules = $content->getModulesByPosition($constraint);
105  }
106 
107  if (count($modules) == 0 && $section)
108  {
109  $modules = $section->getModulesByPosition($constraint);
110  }
111 
112  // Merge in global modules
113  $globals = groupedQuery(Module, "WHERE global=1", "global_position");
114  foreach($globals as $position => $modulesAtPosition)
115  {
116  if (array_key_exists($position, $modules))
117  {
118  $modules[$position] = removeDuplicates(array_merge($modulesAtPosition, $modules[$position]));
119  }
120  else
121  {
122  $modules[$position] = $modulesAtPosition;
123  }
124  }
125 
126  return $modules;
127  }
128 
129  function getTitle()
130  {
131  trace("TITLE: $this->page_title", 3);
132  global $section;
133 
135 
136  if ($section)
137  {
138  $content = $section->getContent($this->identifier);
139  if ($content && $content->override_page_title) $title = $content->override_page_title;
140  }
141 
142  if (!$title) $title = prettify($this->page->identifier);
143 
144  trace("TITLE: $title", 3);
145  return $title;
146  }
147 
148  function getBodyClass()
149  {
151 
152  global $section;
153  if ($section)
154  {
155  $content = $section->getContent($this->identifier);
156  if ($content) return $content->body_class ? $content->body_class : $section->default_body_class;
157  }
158 
159  return "";
160  }
161 
166  function getTemplate()
167  {
168  global $config;
169  global $section;
170 
171  $style = $_REQUEST["_style"];
172  $site = $this->Site();
173  if(!$site)
174  {
175  $site = Site::getSite();
176  }
177 
178  $templateFile = "";
179 
180  switch($style)
181  {
182  case 'print':
183  $templateFile = $site->print_template;
184  break;
185 
186  case 'popup':
187  $templateFile = $site->popup_template;
188  break;
189 
190  case 'mobile':
191  $templateFile = $site->mobile_template;
192 
193  case 'nude':
194  return "{var:script}\n{description}";
195  }
196 
197  if ($section)
198  {
199  if (!$templateFile) $templateFile = $section->getTemplateFile($this->identifier);
200  }
201 
202  if (!$templateFile) $templateFile = $this->template;
203  if (!$templateFile) $templateFile = $site->default_template;
204 
205  $templateFile = ComponentManager::fireEvent("OverrideTemplate", $templateFile);
206 
207  $base = $site->getThemeDirectory();
208  trace("{$base}/{$templateFile}", 3);
209  $template = file_get_contents("{$base}/{$templateFile}");
210 
211  return $template;
212  }
213 
214 
219  function getPositions()
220  {
221  $template = $this->getTemplate();
222 
223  $positionMatches = array();
224 
225  preg_match_all("/\{position:(.*?)\}/", $template, $positionMatches, PREG_PATTERN_ORDER);
226 
227  $positions = $positionMatches[1];
228  sort($positions);
229  return $positions;
230  }
231 
232  static function findByIdentifier($identifier, $constraint = "")
233  {
234  $constraint = preg_replace("/^\s*WHERE\s+/i", "AND ", $constraint);
235 
236  $match = Query::create(ComponentPage, "WHERE identifier=:id $constraint")
237  ->bind(":id", $identifier)
238  ->executeSingle();
239 
240  return $match;
241  }
242 }
243 
244 
245 
246 class ComponentPageModuleXref extends DataItem
247 {
248  var $table = "component_page_module_xref";
249  var $primary_key = "join_id";
250 
251  // Fields
252  var $fields = array("join_id" => Number,
253  "component_page_id" => Number,
254  "module_id" => Number,
255  "position" => String,
256  "sort_order" => Number);
257 
258  // Relations
259 
260  var $relations = array( "Page" => ComponentPage,
261  "Module" => Module);
262 
263  function Page()
264  {
265  return $this->getRelated(Page);
266  }
267 
268  function Module()
269  {
270  return $this->getRelated(Module);
271  }
272 }?>
$constraint
$tabs page
$section
Definition: event_form.inc:44
$base
Definition: delete.inc:45
static getComponent($name)
Definition: component.inc:91
static fireEvent($event, $parameter=null, $mustBeConsumed=false)
Fire an event to all subscribers as detailed in their manifests.
ComponentPageModuleXrefs($constraint="ORDER BY position, sort_order")
getModulesByPosition($constraint="ORDER BY position, sort_order")
Modules($constraint="ORDER BY position, sort_order")
getTemplate()
Loads the template associated with this page.
getPositions()
Retrieves an array of the position names defined in the template for this page.
static findByIdentifier($identifier, $constraint="")
static $bodyClass
Override for the body class of the page currently being served.
Definition: core.inc:89
Defines the Module class.
Definition: module.inc:57
Definition: page.inc:43
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
$result
$positions
$identifier
Definition: rss.inc:37
if(array_key_exists("HTTP_IF_MODIFIED_SINCE", $_SERVER)) $content
Definition: styles.css.inc:24