CMS  Version 3.9
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 
47 class PageView
48 {
49  var $page;
50  var $template;
51 
53  {
54  $this->page = $page;
55  $this->template = $template;
56  }
57 
58  function drawView()
59  {
60  global $config;
61  global $method;
62  global $user;
63  global $script;
64  global $styles;
65  global $breadcrumbs;
66  global $dialogs;
67  global $page;
68  global $site;
69  global $menu_identifier;
70  global $identifier;
71  global $section;
72  global $css_cache_timestamp;
73  global $fontawesome;
74 
75  $page = $this->page; // Pass through to code include
76  $site = $page->Site();
77  if(!$site)
78  $site = Site::getSite(); // Pass through to code include
79 
80  $bodyClass = $this->page->getBodyClass();
81 
82  $template = $this->page->getTemplate();
83 
84  $template = ComponentManager::fireEvent("PreProcessPage", $template);
85 
86  $template = str_replace("{body_class}", $bodyClass, $template);
87 
88  $template = preg_replace("/\\{([\w\d:_]+)\\}/", "{_{_[$1]_}_}", $template);
89 
90  // If the page has a PHP code include, execute it and insert the contents
91 
92  if ($this->page->php_code_file)
93  {
94  $output = Fakoli::evaluateFile($this->page->php_code_file);
95  $this->page->description .= $output;
96 
97  }
98 
99  $this->page->description = ComponentManager::fireEvent("PostProcessContent", $this->page->description);
100 
101  if (Settings::getValue("settings", "enable_inline_editing") && Settings::checkPermission("settings", "editor_roles"))
102  {
103  $versioningControls = ComponentManager::fireEvent("RenderVersioningControls", $this->page);
104  $versioningEnabled = Settings::getValue("settings", "enable_content_versioning") ? "1" : "0";
105 
106  $this->page->description .= "<p id='inline_editing' class='inline_editor_toolbar'><a href='#' class='edit' onclick='new PageManager().editPage({$this->page->page_id}, $versioningEnabled); return false;'>Edit</a>{$versioningControls}</p>";
107  }
108 
109  // Populate template fields from the Page object.
110 
111  foreach($this->page->getFields() as $field => $type)
112  {
113  $template = str_replace("{_{_[".$field."]_}_}", $this->page->$field, $template);
114  }
115 
116  $qs = $_SERVER['QUERY_STRING'];
117  $identifier = $_REQUEST["identifier"];
118 
119  $qs = preg_replace("/identifier=[\\w_]+&*/", "", $qs);
120  $qs = preg_replace("/_style=\\w+&*/", "", $qs);
121 
122  // JDG 2/8/2012 - remove "/" before identifier so that it resolves to correct section
123  $printLink = "{$this->page->identifier}".appendToQueryString($qs, "_style=print");
124 
125  $template = str_replace("{_{_[printIcon]_}_}",
126  "<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>",
127  $template);
128 
129  // Populate the template with the appropriate menu(s).
130 
131  $menuPositions = array();
132 
133  preg_match_all("/\\{_\\{_\\[menu:(.*?)\\]_\\}_\\}/", $template, $menuPositions, PREG_SET_ORDER);
134 
135  $menus = indexedQuery(Menu, "WHERE site_id={$this->page->site_id}", "identifier");
136 
137  foreach($menuPositions as $position)
138  {
139  $output = "";
140 
141  trace("Substituting Menu at Position {$position[0]} {$position[1]}", 3);
142 
143  if (array_key_exists($position[1], $menus))
144  {
145  $view = new MenuView($menus[$position[1]]);
146  $menuBody = $view->drawView();
147  if ($menuBody)
148  {
149  $menuCSSClass = $menus[$position[1]]->container_css_class;;
150  $menuCSSClass = $menuCSSClass ? " class='{$menuCSSClass}'" : "";
151  $output .= "<div id='$position[1]'{$menuCSSClass}>";
152  $output .= $menuBody;
153  $output .= "</div>";
154  }
155  }
156 
157  $template = str_replace($position[0], $output, $template);
158  }
159 
160 
161 
162  // Populate the template with associated modules for the page at the correct positions.
163 
164  $positions = array();
165 
166  preg_match_all("/\\{_\\{_\\[position:(.*?)\\]_\\}_\\}/", $template, $positions, PREG_SET_ORDER);
167 
168  $modules = $this->page->getModulesByPosition();
169 
170  foreach($positions as $position)
171  {
172  $output = "";
173 
174  trace("Substituting at Position {$position[0]} {$position[1]}", 3);
175 
176  if (array_key_exists($position[1], $modules))
177  {
178  $output .= "<div id='$position[1]'>";
179 
180  foreach($modules[$position[1]] as $module)
181  {
183  $output .= $view->drawView();
184  }
185 
186  $output .= "</div>";
187  }
188 
189  $template = str_replace($position[0], $output, $template);
190  }
191 
192  // Direct inclusion of module by path
193  // Generally discouraged, but sometimes the best solution
194 
195  $inclusions = array();
196  preg_match_all("/\{include:(.*?\.inc)\}/", $template, $inclusions, PREG_SET_ORDER);
197 
198  foreach($inclusions as $inclusion)
199  {
200  $output = Fakoli::evaluateFile($inclusion[1]);
201  $template = str_replace($inclusion[0], $output, $template);
202  }
203 
204  // Pull in the script and style dependencies defined by the components
205 
208 
209  $script = ComponentManager::fireEvent("PostProcessScript", $script);
210  $styles = ComponentManager::fireEvent("PostProcessStyles", $styles);
211 
212  // Populate global variable references
213 
214  $vars = array();
215 
216  preg_match_all("/\\{_\\{_\\[var:(.*?)\\]_\\}_\\}/", $template, $vars, PREG_SET_ORDER);
217 
218  foreach($vars as $var)
219  {
220  $expr = $var[0];
221  $name = $var[1];
222  $template = str_replace($expr, $$name, $template);
223  }
224 
225  // Populate stored value references
226 
227  $gets = array();
228 
229  preg_match_all("/\\{_\\{_\\[get:(.*?)\\]_\\}_\\}/", $template, $gets, PREG_SET_ORDER);
230  foreach($gets as $get)
231  {
232  $expr = $get[0];
233  $name = $get[1];
234  $value = Fakoli::get($name);
235 
236  $template = str_replace($expr, $value, $template);
237  }
238 
239 
240  $template = str_replace("{_{_[", "{", $template);
241  $template = str_replace("]_}_}", "}", $template);
242 
243  $template = ComponentManager::fireEvent("PostProcessPage", $template);
244 
245  if ($config['prettyURLs'] === false)
246  {
247  $template = preg_replace("/(href|src|action)=(['\"])\\/?([\\w\\d_]+?)\\?/i", "$1=$2/page.php?identifier=$3&", $template);
248  $template = preg_replace("/(href|src|action)=(['\"])\\/?([\\w\\d_]+?)[\"']/i", "$1=$2/page.php?identifier=$3$2", $template);
249  $template = preg_replace("/go\\(([\"'])\\/?([\\w\\d_]+?)\\?/", "go($1/page.php?identifier=$2&", $template);
250  $template = preg_replace("/go\\(([\"'])\\/?([\\w\\d_]+?)[\"']/", "go($1/page.php?identifier=$2$1", $template);
251 
252  }
253 
254  return $template;
255  }
256 }
257 ?>
$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 getStyles()
Returns the HTML link tags for CSS files specified by the registered components in their manifest fil...
Definition: core.inc:603
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 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
Definition: menus.inc:41
static create($module)
Definition: module_view.inc:62
PageView generates the page content, substituting page fields, menus and associated modules into an H...
Definition: page_view.inc:48
$page
The Page object that we are viewing.
Definition: page_view.inc:49
PageView($page, $template)
Definition: page_view.inc:52
$template
The layout template used to render the page.
Definition: page_view.inc:50
drawView()
Definition: page_view.inc:58
static getValue($component, $name)
Retrieve the value of the specified Setting.
Definition: settings.inc:104
static checkPermission($component, $name, $account=null)
Check whether a user has a specific permission.
Definition: settings.inc:241
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