CMS  Version 3.9
admin_page_view.inc
Go to the documentation of this file.
1 <?php
2 /**************************************************************
3 
4  Copyright (c) 2010 Sonjara, Inc
5 
6  Permission is hereby granted, free of charge, to any person
7  obtaining a copy of this software and associated documentation
8  files (the "Software"), to deal in the Software without
9  restriction, including without limitation the rights to use,
10  copy, modify, merge, publish, distribute, sublicense, and/or sell
11  copies of the Software, and to permit persons to whom the
12  Software is furnished to do so, subject to the following
13  conditions:
14 
15  The above copyright notice and this permission notice shall be
16  included in all copies or substantial portions of the Software.
17 
18  Except as contained in this notice, the name(s) of the above
19  copyright holders shall not be used in advertising or otherwise
20  to promote the sale, use or other dealings in this Software
21  without prior written authorization.
22 
23  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
25  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
27  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
28  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
30  OTHER DEALINGS IN THE SOFTWARE.
31 
32 *****************************************************************/
33 
39 {
41  var $page;
42 
44  {
45  if (!$identifier) $identifier = "index";
46  $this->identifier = $identifier;
47 
48  $this->page = Cache::get("fakoli_admin_pages_$identifier");
49  if ($this->page) return;
50 
51  $pages = Query::create(AdminPage, "WHERE identifier=:id")
52  ->bind(":id", $identifier)
53  ->execute();
54 
55  if (count($pages) != 1)
56  {
57  throw new FakoliException("Missing or ambiguous page identifier '$identifier'");
58  }
59 
60  $this->page = $pages[0];
61  Cache::put("fakoli_admin_pages_$identifier", $this->page);
62  }
63 
64 
65  function drawView()
66  {
67  global $config;
68  global $method;
69  global $user;
70  global $script;
71  global $styles;
72  global $dialogs;
73  global $page;
74  global $menu_item;
75  global $isAdmin;
76  global $fontawesome;
77 
78  global $auto_form_defaults;
79  $auto_form_defaults["default_layout"] = "table";
80 
81  $page = $this->page; // Pass through to code include
82 
83  $template = file_get_contents(Fakoli::resolveResource("/fakoli/admin.tpl"));
84 
85  //$template = ComponentManager::fireEvent("PreProcessPage", $template);
86 
87  ob_start();
88 
89  try
90  {
91  include $page->server_path;
92  }
93  catch(Exception $e)
94  {
95  echo $e->getMessage();
96  }
97 
98  $content = ob_get_contents();
99  ob_end_clean();
100 
101  //$content = ComponentManager::fireEvent("PostProcessContent", $content);
102 
103  $admin_menu = Fakoli::getAdminMenu();
104  $icons = Fakoli::getAdminIcons();
105 
106  $menu = $this->formatMenu($admin_menu, $icons);
107 
108  // If the script didn't provide a title, guess a reasonable default.
109 
110  if (!$title) $title = prettify(basename(substr($page->server_path, 0, -4)));
111 
112  // Pull in the script and style dependencies defined by the components
113 
116 
117  // Populate variable references
118 
119  $vars = array();
120 
121  preg_match_all("/\{var:(.*?)\}/", $template, $vars, PREG_SET_ORDER);
122 
123  foreach($vars as $var)
124  {
125  $expr = $var[0];
126  $name = $var[1];
127  $template = str_replace($expr, $$name, $template);
128  }
129 
130  $charset = strtolower(ini_get("default_charset"));
131  $template = str_replace("{default_charset}", $charset, $template);
132 
133  preg_match_all("/\{config:(.*?)\}/", $template, $vars, PREG_SET_ORDER);
134 
135  foreach($vars as $var)
136  {
137  $expr = $var[0];
138  $name = $var[1];
139  $template = str_replace($expr, $config[$name], $template);
140  }
141 
142  $component = $page->Component();
143 
144  $help = "<a href='#' onclick='popup(\"/action/admin/help?src={$component->name}&page={$page->identifier}\", \"help\", 940, 500, \"toolbar=0,location=0,scrollbars=1,resizable=1\"); return false;'> Help </a>";
145 
146  $template = str_replace("{help}", $help, $template);
147 
148  if ($config['prettyURLs'] === false)
149  {
150  $template = preg_replace("/(href|src|action)=(['\"])\\/?([\\w\\d_]+?)\\?/i", "$1=$2/page.php?identifier=$3&", $template);
151  $template = preg_replace("/(href|src|action)=(['\"])\\/?([\\w\\d_]+?)[\"']/i", "$1=$2/page.php?identifier=$3$2", $template);
152  $template = preg_replace("/go\\(([\"'])\\/?([\\w\\d_]+?)\\?/", "go($1/page.php?identifier=$2&", $template);
153  $template = preg_replace("/go\\(([\"'])\\/?([\\w\\d_]+?)[\"']/", "go($1/page.php?identifier=$2$1", $template);
154 
155  }
156 
157  //$template = ComponentManager::fireEvent("PostProcessPage", $template);
158 
159  echo $template;
160 
161  ComponentManager::fireEvent("RequestComplete");
162  }
163 
164  private function formatIcon($icon)
165  {
166  if (!$icon) return "<i class='fas fa-fw'></i>";
167  if (endsWith($icon, ".svg"))
168  {
169  return "<i class='fas fa-fw' style='background: url({$icon}) center center no-repeat; background-size: contain; height:1em'></i>";
170  }
171  else if (preg_match('/^fa.?\s/', $icon))
172  {
173  return "<i class='{$icon} fa-fw'></i>";
174  }
175  else
176  {
177  return "<i class='fas fa-{$icon} fa-fw'></i>";
178  }
179  }
180  function formatMenu($admin_menu, $icons)
181  {
182  global $menu_item;
183 
184  if (!$admin_menu) return "";
185 
186  ob_start();
187 
188  if (!$menu_item) $menu_item = basename($_SERVER['PHP_SELF']);
189 ?>
190 <div id="menu">
191 <?
192  $menuSectionIdx = 0;
193 
194  foreach($admin_menu as $section => $items)
195  {
196  $found = false;
197 
198  $icon = $this->formatIcon($icons[$section]);
199 
200  $submenu = " <h4 class=\"toggler atStart\">{$icon} {$section}</h4>\n <div class=\"atStart\">\n";
201 
202  foreach($items as $item => $properties)
203  {
204  if ($item == $menu_item)
205  {
206  $class = 'selectedadminitem';
207  $selectedMenuSectionIdx = $menuSectionIdx;
208  }
209  else
210  {
211  $class = 'adminmenuitem';
212  }
213 
214  $icon = $icons[$item];
215  if (!$icon) $icon = $properties["icon"];
216 
217  $icon = $this->formatIcon($icon);
218 
219  if (checkRole($properties["role"]))
220  {
221  $submenu .= "<a class='$class' href='{$properties['page']}{$menu_params}'>{$icon} {$item}</a>\n";
222  $found = true;
223  }
224  }
225 
226  $submenu .= "</div>";
227 
228  if ($found)
229  {
230  ++$menuSectionIdx;
231  echo $submenu;
232  }
233  }
234 ?>
235 </div>
236 <?
237  if (!$selectedMenuSectionIdx) $selectedMenuSectionIdx = 0;
238 
239  global $script;
240 
241  $script .= <<<ENDSCRIPT
242 
243 <script type="text/javascript">
244 window.addEvent('domready', function() {
245 
246  var accordion = new Accordion('h4.atStart', 'div.atStart', {
247 
248  opacity: false,
249  initialDisplayFx: false,
250  display: $selectedMenuSectionIdx,
251  onActive: function(toggler, element){
252  toggler.addClass("active");
253  },
254 
255  onBackground: function(toggler, element){
256  toggler.removeClass("active");
257  }
258  }, document.id('accordion'));
259 
260  });
261 </script>
262 ENDSCRIPT;
263  $menu = ob_get_contents();
264  ob_end_clean();
265  return $menu;
266  }
267 }
268 
$menu_item
$tabs page
$section
Definition: event_form.inc:44
$component
Definition: help.inc:38
$menu
Definition: menu_form.inc:47
$name
Definition: upload.inc:54
$icon
Definition: upload.inc:92
formatMenu($admin_menu, $icons)
AdminPageView($identifier)
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 resolveResource($resource, $component="")
Resolves the path to a web resource based on the PHP include path.
Definition: core.inc:850
static getScripts()
Returns the HTML scripts tags for Javascript files specified by the registered components in their ma...
Definition: core.inc:554
static getAdminIcons()
Builds the admin icon map.
Definition: core.inc:456
static getAdminMenu()
Builds the administration menu, combining menu items supplied by the registered components in their m...
Definition: core.inc:405
global $user
$fontawesome
Definition: core.inc:45
$method
Pull out a simple reference to the request method.
Definition: core.inc:1573
global $config
Definition: import.inc:4
$pages
Definition: export.inc:38
$styles
if(array_key_exists("HTTP_IF_MODIFIED_SINCE", $_SERVER)) $content
Definition: styles.css.inc:24