CMS  Version 3.9
ComponentPageView Class Reference

ComponentPageView generates the page content for a component page, substituting page fields, menus and associated modules into an HTML template. More...

Public Member Functions

 __construct ($page, $template="")
 Creates a new ComponentPageView object. More...
 
 drawView ()
 Renders the page. More...
 

Static Public Member Functions

static renderPage ($identifier)
 Renders the component page that matches the specified identifier. More...
 

Public Attributes

 $page
 The ComponentPage object that we are viewing. More...
 
 $template
 The layout template used to render the page. More...
 

Detailed Description

ComponentPageView generates the page content for a component page, substituting page fields, menus and associated modules into an HTML template.

Author
andy

Definition at line 48 of file component_page_view.inc.

Constructor & Destructor Documentation

◆ __construct()

ComponentPageView::__construct (   $page,
  $template = "" 
)

Creates a new ComponentPageView object.

Parameters
ComponentPage$pagethe page to be displayed
string$templatethe template to use (default is to use the template specified by the ComponentPage object)

Definition at line 82 of file component_page_view.inc.

83  {
84  $this->page = $page;
85  $this->template = $template;
86  }
$tabs page
$template
The layout template used to render the page.
$page
The ComponentPage object that we are viewing.

Member Function Documentation

◆ drawView()

ComponentPageView::drawView ( )

Renders the page.

Definition at line 91 of file component_page_view.inc.

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  }
$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.
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 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
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

◆ renderPage()

static ComponentPageView::renderPage (   $identifier)
static

Renders the component page that matches the specified identifier.

Automatically redirects to login if the user doesn't have correct permissions.

Parameters
string$identifierthe identifier of the component page

Definition at line 56 of file component_page_view.inc.

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  }
static findByIdentifier($identifier, $constraint="")
ComponentPageView generates the page content for a component page, substituting page fields,...
static storeRedirectPage()
Store the page from which a user has been redirected when prompted to login or create an account.
Definition: login.inc:493

Member Data Documentation

◆ $page

ComponentPageView::$page

The ComponentPage object that we are viewing.

Definition at line 73 of file component_page_view.inc.

◆ $template

ComponentPageView::$template

The layout template used to render the page.

Definition at line 74 of file component_page_view.inc.


The documentation for this class was generated from the following file: