CMS  Version 3.9
component_page_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 Fakoli::using("page", "menu", "module");
40 
49 {
56  static function renderPage($identifier)
57  {
59 
60  $pageView = new ComponentPageView($page, "{$page->template}.tpl");
61 
62  $page_role = $page->role;
63 
64  if (!checkRole($page->role))
65  {
67  redirect("/login");
68  }
69 
70  echo $pageView->drawView();
71  }
72 
73  var $page;
74  var $template;
75 
82  function __construct($page, $template = "")
83  {
84  $this->page = $page;
85  $this->template = $template;
86  }
87 
91  function drawView()
92  {
93  global $config;
94  global $method;
95  global $user;
96  global $script;
97  global $styles;
98  global $breadcrumbs;
99  global $dialogs;
100  global $page;
101  global $site;
102  global $section;
103  global $menu_identifier;
104  global $identifier;
105  global $section;
106  global $css_cache_timestamp;
107  global $fontawesome;
108 
109  $page = $this->page; // Pass through to code include
110 
111  if ($section)
112  {
113  $site = $section->Site();
114  }
115  else
116  {
117  $site = $page->Site();
118  }
119 
120  if(!$site)
121  $site = Site::getSite(); // Pass through to code include
122 
123  $template = $this->page->getTemplate();
124 
126 
127  try
128  {
129  $template = ComponentManager::fireEvent("PreProcessPage", $template);
130 
131  // If the page has a PHP code include, execute it and insert the contents
132 
133  ob_start();
134  include $page->server_path;
135  $output = ob_get_contents();
136  ob_end_clean();
137 
138  $output = ComponentManager::fireEvent("PostProcessContent", $output);
139  }
140  catch (DataNotFoundException $e)
141  {
142  // AJG: Wrap DataNotFoundExceptions so they don't show a 'this resource is disabled error
143  throw new FakoliException($e->getMessage());
144  }
145 
146  $this->page->description .= $output;
147 
149 
150  // Populate template fields from the Page object.
151 
152  $this->page->page_title = $this->page->getTitle();
153 
154  $bodyClass = $this->page->getBodyClass();
155 
156  foreach($this->page->getFields() as $field => $type)
157  {
158  $template = str_replace("{".$field."}", $this->page->get($field), $template);
159  }
160 
161  $template = str_replace("{body_class}", $bodyClass, $template);
162  $template = str_replace("{description}", $output, $template);
163  //if (!$title) $title = $this->page->getTitle();
164  //$template = str_replace("{page_title}", $title, $template);
165  $template = str_replace("{meta_tag_description}", $site->meta_tag_description, $template);
166  $template = str_replace("{meta_tag_keyword}", $site->meta_tag_keyword, $template);
167 
168  $qs = $_SERVER['QUERY_STRING'];
169  $identifier = $_REQUEST["identifier"];
170 
171  $qs = preg_replace("/identifier=[\\w_]+&*/", "", $qs);
172  $qs = preg_replace("/_style=\\w+&*/", "", $qs);
173 
174  // JDG 2/8/2012 - remove "/" before identifier so that it resolves to correct section
175  $printLink = "{$this->page->identifier}".appendToQueryString($qs, "_style=print");
176 
177  $template = str_replace("{printIcon}",
178  "<a href='$printLink' target='_blank'><img src='/fakoli/images/print.gif' style='display: inline-block; vertical-align: middle;border: none'></a>&nbsp;<a href='$printLink' target='_blank'>Print this Page</a>",
179  $template);
180 
181  // Populate the template with the appropriate menu(s).
182 
183  $menuPositions = array();
184 
185  preg_match_all("/\{menu:(.*?)\}/", $template, $menuPositions, PREG_SET_ORDER);
186 
187  $menus = indexedQuery(Menu, "WHERE site_id={$site->site_id}", "identifier");
188 
189  foreach($menuPositions as $position)
190  {
191  $output = "";
192 
193  trace("Substituting Menu at Position {$position[0]} {$position[1]}", 3);
194 
195  if (array_key_exists($position[1], $menus))
196  {
197  $view = new MenuView($menus[$position[1]]);
198  $menuBody = $view->drawView();
199  if ($menuBody)
200  {
201  $menuCSSClass = $menus[$position[1]]->container_css_class;;
202  $menuCSSClass = $menuCSSClass ? " class='{$menuCSSClass}'" : "";
203  $output .= "<div id='$position[1]'{$menuCSSClass}>";
204  $output .= $menuBody;
205  $output .= "</div>";
206  }
207  }
208 
209  $template = str_replace($position[0], $output, $template);
210  }
211 
212 
213 
214  // Populate the template with associated modules for the page at the correct positions.
215 
216  $positions = array();
217 
218  preg_match_all("/\{position:(.*?)\}/", $template, $positions, PREG_SET_ORDER);
219 
220  $modules = $this->page->getModulesByPosition();
221 
222  foreach($positions as $position)
223  {
224  $output = "";
225 
226  trace("Substituting at Position {$position[0]} {$position[1]}", 3);
227 
228  if (array_key_exists($position[1], $modules))
229  {
230  $output .= "<div id='$position[1]'>";
231 
232  foreach($modules[$position[1]] as $module)
233  {
235  $output .= $view->drawView();
236  }
237 
238  $output .= "</div>";
239  }
240 
241  $template = str_replace($position[0], $output, $template);
242  }
243 
244  // Direct inclusion of module by path
245  // Generally discouraged, but sometimes the best solution
246 
247  $inclusions = array();
248  preg_match_all("/\{include:(.*?\.inc)\}/", $template, $inclusions, PREG_SET_ORDER);
249 
250  foreach($inclusions as $inclusion)
251  {
252  trace("Substituting include $inclusion[1]",1);
253  $output = Fakoli::evaluateFile($inclusion[1]);
254  $template = str_replace($inclusion[0], $output, $template);
255  }
256 
257  // Pull in the script and style dependencies defined by the components
258 
259  if ($_REQUEST["_style"] != "nude")
260  {
263  }
264 
265  $script = ComponentManager::fireEvent("PostProcessScript", $script);
266  $styles = ComponentManager::fireEvent("PostProcessStyles", $styles);
267 
268  // Populate global variable references
269 
270  $vars = array();
271 
272  preg_match_all("/\{var:(.*?)\}/", $template, $vars, PREG_SET_ORDER);
273 
274  foreach($vars as $var)
275  {
276  $expr = $var[0];
277  $name = $var[1];
278  global ${$name};
279 
280  $template = str_replace($expr, ${$name}, $template);
281  }
282 
283  // Populate stored value references
284 
285  $gets = array();
286 
287  preg_match_all("/\{get:(.*?)\}/", $template, $gets, PREG_SET_ORDER);
288  foreach($gets as $get)
289  {
290  $expr = $get[0];
291  $name = $get[1];
292  $value = Fakoli::get($name);
293 
294  $template = str_replace($expr, $value, $template);
295  }
296 
297  if ($config['prettyURLs'] === false)
298  {
299  $template = preg_replace("/(href|src|action)=(['\"])\\/?([\\w\\d_]+?)\\?/i", "$1=$2/page.php?identifier=$3&", $template);
300  $template = preg_replace("/(href|src|action)=(['\"])\\/?([\\w\\d_]+?)[\"']/i", "$1=$2/page.php?identifier=$3$2", $template);
301  $template = preg_replace("/go\\(([\"'])\\/?([\\w\\d_]+?)\\?/", "go($1/page.php?identifier=$2&", $template);
302  $template = preg_replace("/go\\(([\"'])\\/?([\\w\\d_]+?)[\"']/", "go($1/page.php?identifier=$2$1", $template);
303 
304  }
305 
306  $template = ComponentManager::fireEvent("PostProcessPage", $template);
307 
308  return $template;
309  }
310 }
311 ?>
$tabs page
$section
Definition: event_form.inc:44
$view
Definition: help.inc:42
$name
Definition: upload.inc:54
static fireEvent($event, $parameter=null, $mustBeConsumed=false)
Fire an event to all subscribers as detailed in their manifests.
static findByIdentifier($identifier, $constraint="")
ComponentPageView generates the page content for a component page, substituting page fields,...
$template
The layout template used to render the page.
__construct($page, $template="")
Creates a new ComponentPageView object.
drawView()
Renders the page.
static renderPage($identifier)
Renders the component page that matches the specified identifier.
$page
The ComponentPage object that we are viewing.
FakoliException is the base exception class for all Fakoli errors.
Definition: core.inc:53
static getStyles()
Returns the HTML link tags for CSS files specified by the registered components in their manifest fil...
Definition: core.inc:603
static coreTraceLevel()
Change to the configured trace level for Fakoli core code.
Definition: core.inc:1346
static get($key)
Retrieves the value or object at the given key.
Definition: core.inc:109
static getScripts()
Returns the HTML scripts tags for Javascript files specified by the registered components in their ma...
Definition: core.inc:554
static applicationTraceLevel()
Change to the configured trace level for application code.
Definition: core.inc:1338
static using()
Import the datamodels, views and manifest for the specified component(s).
Definition: core.inc:116
static evaluateFile($filePath)
Evaluates a PHP include file and returns the generated content.
Definition: core.inc:650
static storeRedirectPage()
Store the page from which a user has been redirected when prompted to login or create an account.
Definition: login.inc:493
Definition: menus.inc:41
static create($module)
Definition: module_view.inc:62
static getSite()
Returns the Site object that describes the currently active site (i.e.
Definition: site.inc:103
global $user
$fontawesome
Definition: core.inc:45
$method
Pull out a simple reference to the request method.
Definition: core.inc:1573
$output
Definition: generate.inc:9
global $config
Definition: import.inc:4
$positions
$styles
$identifier
Definition: rss.inc:37