1 : <?php
2 : /**
3 : * PHPDevShell is a RAD Framework aimed at developing administrative applications.
4 : *
5 : * @package PHPDevShell
6 : * @link http://www.phpdevshell.org
7 : * @copyright Copyright (C) 2007 Jason Schoeman, All rights reserved.
8 : * @license GNU/LGPL, see readme/licensed_under_lgpl or http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
9 : *
10 : * Copyright notice: See readme/notice
11 : * By using PHPDevShell you agree to notice and license, if you dont agree to this notice/license you are not allowed to use PHPDevShell.
12 : *
13 : */
14 : class PHPDS_template extends template
15 1 : {
16 : /**
17 : * Adds content to head of page.
18 : * @var string
19 : */
20 : public $modifyHead = '';
21 : /**
22 : * Modify Output Text Logo
23 : * @var mixed
24 : */
25 : public $modifyOutputTextLogo = false;
26 : /**
27 : * Modify Output Logo
28 : * @var mixed
29 : */
30 : public $modifyOutputLogo = false;
31 : /**
32 : * Modify Output Time
33 : * @var mixed
34 : */
35 : public $modifyOutputTime = false;
36 : /**
37 : * Modify Output Login Link.
38 : * @var mixed
39 : */
40 : public $modifyOutputLoginLink = false;
41 : /**
42 : * Modify Output User.
43 : * @var mixed
44 : */
45 : public $modifyOutputUser = false;
46 : /**
47 : * Modify Output Role.
48 : * @var mixed
49 : */
50 : public $modifyOutputRole = false;
51 : /**
52 : * Modify Output Group.
53 : * @var mixed
54 : */
55 : public $modifyOutputGroup = false;
56 : /**
57 : * Modify Output Title.
58 : * @var mixed
59 : */
60 : public $modifyOutputTitle = false;
61 : /**
62 : * Modify Output Menu.
63 : * @var mixed
64 : */
65 : public $modifyOutputMenu = false;
66 : /**
67 : * Modify Output Breadcrumbs.
68 : * @var mixed
69 : */
70 : public $modifyOutputBreadcrumbs = false;
71 : /**
72 : * Modify Output Footer.
73 : * @var mixed
74 : */
75 : public $modifyOutputFooter = false;
76 : /**
77 : * Modify Output Controller.
78 : * @var mixed
79 : */
80 : public $modifyOutputController = false;
81 : /**
82 : * Modify Output Controller content.
83 : * @var string
84 : */
85 : public $controller;
86 : /**
87 : * This variable is used to activate a stop script command, it will be used to end a script immediately while still finishing compiling the template.
88 : *
89 : * Usage Example :
90 : * <code>
91 : * // This wil make the script stop (not PHPDevShell) while still finishing the template to the end.
92 : * $template->stopScript = array('type'=>'auth','message'=>'The script stopped cause I wanted it to.');
93 : * </code>
94 : *
95 : * @var array
96 : */
97 : public $stopScript;
98 : /**
99 : * Assign this variable if you would like to debug your script, it will show on critical errors as well.
100 : * It will parse anything that is assigned to it.
101 : *
102 : * @var string
103 : */
104 : public $debugStr = false;
105 : /**
106 : * Use this to have global available variables throughout scripts. For instance in hooks.
107 : *
108 : * @var array
109 : */
110 : public $global;
111 : /**
112 : * Use this to have global available variables throughout scripts. For instance in hooks.
113 : *
114 : * @var array
115 : */
116 : public $skipLogin = false;
117 : /**
118 : * Contains module html sniplets.
119 : *
120 : * @var array
121 : */
122 : public $module = array();
123 :
124 : /**
125 : * Name of the Theme to use (previously known as template)
126 : * @since v3.1.0
127 : * @var string
128 : */
129 : public $templateName;
130 :
131 : /**
132 : * Sends a message to login form.
133 : * @var string
134 : */
135 : public $loginMessage;
136 :
137 : /**
138 : * Repository of data pieces to be used by the actual Theme code
139 : * @since v3.1.0
140 : * @var array
141 : */
142 : protected $pieces;
143 :
144 : /**
145 : * Content Distribution Network.
146 : * If you are running a very large site, you might want to consider running a dedicated light http server (httpdlight, nginx) that
147 : * only serves static content like images and static files, call it a CDN if you like.
148 : * By adding a host here 'http://192.34.22.33/project/cdn', all images etc, of PHPDevShell will be loaded from this address.
149 : * @var string
150 : */
151 : protected $CDN;
152 :
153 : /**
154 : * Run default, custom or no template.
155 : *
156 : * @version 1.2
157 : * @date 20100520 (v1.1) (greg) added merging with modules from the configuration array
158 : * @date 20110308 (v1.2) greg) allows the new style controller to alter the current template to be used
159 : * @author Jason Schoeman
160 : */
161 : public function runTemplate ()
162 : {
163 0 : $configuration = $this->configuration;
164 0 : if (empty($this->templateName))
165 0 : $this->templateName = 'theme.php';
166 :
167 0 : if (empty($configuration['static_content_host'])) {
168 0 : $this->CDN = $this->configuration['absolute_url'];
169 0 : } else {
170 0 : $this->CDN = $this->configuration['static_content_host'];
171 : }
172 :
173 :
174 : // Create preferred template dir.
175 0 : $template_dir = 'themes/'.$configuration['template_folder'].'/';
176 :
177 : // Check if we have a module file.
178 0 : if (!$this->core->loadFile($template_dir . 'modules.php')) {
179 : // Load modules file.
180 0 : $this->core->loadFile('themes/cloud/modules.php');
181 0 : }
182 : // allow override and additions in the configuration file
183 0 : if (!empty($configuration['modules']) && is_array($configuration['modules'])) {
184 0 : $this->module = array_merge($this->module, $configuration['modules']);
185 0 : }
186 :
187 : try {
188 : // the output buffer is used here to catch anything output but the controller in order to include it in the template
189 0 : $this->startBuffering();
190 :
191 : // old-style compatibility: either we have a new style controller (which should be executed now)
192 : // or the the template will execute the script at the next step
193 0 : if (empty($this->module['bc']) || ($this->module['bc'] != 2)) {
194 : // This will pre-load the controller and save it.
195 0 : $this->executeController();
196 0 : } else {
197 0 : $this->core->loadFile($template_dir.'language/core.lang.php');
198 : }
199 :
200 0 : if (empty($this->controller)) {
201 0 : $this->controller = ob_get_clean();
202 0 : } else {
203 0 : PU_cleanBuffers();
204 : }
205 0 : } catch (Exception $e) {
206 0 : PU_cleanBuffers();
207 0 : if (is_a($e, 'PHPDS_securityException')) {
208 0 : $this->templateName = 'login.php';
209 0 : } else if (is_a($e, 'PHPDS_pageException404')) {
210 0 : $this->templateName = '404.php';
211 0 : } else if (is_a($e, 'PHPDS_securityException403')) {
212 0 : $this->templateName = '403.php';
213 0 : } else throw $e;
214 : }
215 :
216 : // at this time nothing is supposed to be output yet
217 :
218 0 : if (!empty($this->templateName)) {
219 : try {
220 : // the output buffer is used here to delay the template output, in case we need to send some headers (for example FirePHP)
221 : // Content buffer.
222 0 : $this->startBuffering();
223 :
224 : // first we try the template file with the given name
225 0 : $result = $this->core->loadFile($template_dir.$this->templateName);
226 : // if not found, let's try the default file
227 0 : if (false === $result) {
228 0 : $result = $this->core->loadFile($template_dir.'main.php');
229 0 : }
230 :
231 0 : if (false === $result) {
232 0 : throw new PHPDS_exception('Fix me, I can\'t find the custom template!');
233 : }
234 :
235 0 : ob_end_flush();
236 0 : } catch (Exception $e) {
237 0 : PU_cleanBuffers();
238 0 : throw $e;
239 : }
240 0 : } elseif (is_string($this->controller)) {
241 0 : print $this->controller;
242 0 : }
243 0 : }
244 :
245 :
246 : protected function startBuffering()
247 : {
248 0 : if (!PU_isAJAX(false) && !empty($this->configuration['gzip'])) {
249 0 : @ob_start("ob_gzhandler");
250 0 : } else {
251 0 : ob_start();
252 : }
253 0 : }
254 :
255 : /**
256 : * Will add any css path to the <head></head> tags of your document.
257 : *
258 : * @param string $cssRelativePath
259 : */
260 : public function addCssFileToHead ($cssRelativePath = '', $media='screen, projection') {
261 0 : $this->modifyHead .= '<link rel="stylesheet" href="' . $this->CDN . '/' . $cssRelativePath . '" media="' . $media . '" />';
262 0 : }
263 :
264 : /**
265 : * Will add any js path to the <head></head> tags of your document.
266 : *
267 : * @param string $jsRelativePath
268 : */
269 : public function addJsFileToHead ($jsRelativePath = '') {
270 0 : $this->modifyHead .= '<script type="text/javascript" src="' . $this->CDN . '/' . $jsRelativePath . '"></script>';
271 0 : }
272 :
273 : /**
274 : * Will add any content to the <head></head> tags of your document.
275 : *
276 : * @param string $extraHead
277 : */
278 : public function addToHead ($extraHead = '') {
279 0 : $this->modifyHead .= $extraHead;
280 0 : }
281 :
282 : /**
283 : * Will add any js to the <head></head> tags of your document adding script tags.
284 : *
285 : * @param string $js
286 : */
287 : public function addJsToHead ($js = '') {
288 0 : $this->modifyHead .= '<script type="text/javascript">' . $js . '</script>';
289 0 : }
290 :
291 : /**
292 : * Will add any css to the <head></head> tags of your document adding script tags.
293 : *
294 : * @param string $css
295 : */
296 : public function addCSSToHead ($css = '') {
297 0 : $this->modifyHead .= '<style>' . $css . '</style>';
298 0 : }
299 :
300 : /**
301 : * Changes head output.
302 : * @param boolean $return
303 : * @return string
304 : */
305 : public function outputHead ($return = false) {
306 : // Check if we should return or print.
307 0 : if ($return == false) {
308 : // Simply output charset.
309 0 : print $this->modifyHead;
310 0 : } else {
311 0 : return $this->modifyHead;
312 : }
313 0 : }
314 :
315 : /**
316 : * Outputs current language identifier being used.
317 : *
318 : * @author Jason Schoeman
319 : */
320 : public function outputLanguage ($return = false)
321 : {
322 : // Check if we should return or print.
323 0 : if ($return == false) {
324 : // Simply output charset.
325 0 : print $this->configuration['language'];
326 0 : } else {
327 0 : return $this->configuration['language'];
328 : }
329 0 : }
330 :
331 : /**
332 : * Outputs charset.
333 : *
334 : * @author Jason Schoeman
335 : */
336 : public function outputCharset ($return = false)
337 : {
338 : // Check if we should return or print.
339 0 : if ($return == false) {
340 : // Simply output charset.
341 0 : print $this->configuration['charset'];
342 0 : } else {
343 0 : return $this->configuration['charset'];
344 : }
345 0 : }
346 :
347 : /**
348 : * Outputs the active scripts title.
349 : *
350 : * @author Jason Schoeman
351 : */
352 : public function outputTitle ()
353 : {
354 : // Check if output should be modified.
355 0 : if ($this->modifyOutputTitle == false) {
356 0 : $navigation = $this->navigation->navigation;
357 0 : if (isset($navigation[$this->configuration['m']]['menu_name'])) {
358 0 : print $navigation[$this->configuration['m']]['menu_name'] . ' - ' . $this->configuration['scripts_name_version'];
359 0 : } else {
360 0 : print $this->stopScript['message'];
361 : }
362 0 : } else {
363 0 : print $this->modifyOutputTitle;
364 : }
365 0 : }
366 :
367 : /**
368 : * This returns/prints the skin for inside theme usage.
369 : *
370 : * @param mixed default is print, can be set true, print, return.
371 : * @return string Skin.
372 : * @author Jason Schoeman
373 : */
374 : public function outputSkin ($return = 'print')
375 : {
376 : // Create HTML.
377 0 : $html = $this->configuration['skin'];
378 :
379 : // Return or print to browser.
380 0 : if ($return === 'print' || $return == false) {
381 0 : print $html;
382 0 : } else if ($return === 'return' || $return == true) {
383 0 : return $html;
384 : }
385 0 : }
386 :
387 : /**
388 : * This returns/prints the absolute url for inside theme usage.
389 : *
390 : * @param mixed default is print, can be set true, print, return.
391 : * @return string Absolute url.
392 : * @author Jason Schoeman
393 : */
394 : public function outputAbsoluteURL ($return = 'print')
395 : {
396 : // Return or print to browser.
397 0 : if ($return === 'print' || $return == false) {
398 0 : print $this->CDN;
399 0 : } else if ($return === 'return' || $return == true) {
400 0 : return $this->CDN;
401 : }
402 0 : }
403 :
404 : /**
405 : * This returns/prints the meta keywords for inside theme usage.
406 : *
407 : * @param mixed default is print, can be set true, print, return.
408 : * @return string Meta Keywords.
409 : * @author Jason Schoeman
410 : */
411 : public function outputMetaKeywords ($return = 'print')
412 : {
413 : // Create HTML.
414 0 : $html = $this->configuration['meta_keywords'];
415 :
416 : // Return or print to browser.
417 0 : if ($return === 'print' || $return == false) {
418 0 : print $html;
419 0 : } else if ($return === 'return' || $return == true) {
420 0 : return $html;
421 : }
422 0 : }
423 :
424 : /**
425 : * This returns/prints the meta description for inside theme usage.
426 : *
427 : * @param mixed default is print, can be set true, print, return.
428 : * @return string Meta Description.
429 : * @author Jason Schoeman
430 : */
431 : public function outputMetaDescription ($return = 'print')
432 : {
433 : // Create HTML.
434 0 : $html = $this->configuration['meta_description'];
435 :
436 : // Return or print to browser.
437 0 : if ($return === 'print' || $return == false) {
438 0 : print $html;
439 0 : } else if ($return === 'return' || $return == true) {
440 0 : return $html;
441 : }
442 0 : }
443 :
444 : /**
445 : * Print a string via a module and returns the result
446 : *
447 : *
448 : * @param string $moduleName the module to use
449 : * @param string $string the string to print (several strings can be provided)
450 : * @date 20100920 (v1.0) (greg) created
451 : * @version 1.0
452 : * @author greg
453 : */
454 : public function modPrint($moduleName) // more arguments can be provided
455 : {
456 0 : $strings = func_get_args();
457 0 : $dep = array_shift($strings); // get rid of module name
458 0 : $result = empty($this->module[$moduleName]) ? implode($strings) : PU_sprintfn($this->module[$moduleName], $strings);
459 0 : return $result;
460 : }
461 :
462 : /**
463 : * Gets the desired logo and displays it. This method will try its best to deliver a logo, whatever the case.
464 : *
465 : * @author Jason Schoeman
466 : */
467 : public function outputLogo ()
468 : {
469 0 : if ($this->modifyOutputLogo == false) {
470 : // First we need to see if we will be using the custom logo.
471 0 : if (! empty($this->configuration['custom_logo'])) {
472 : // Give him his custom logo.
473 0 : $logo = $this->modPrint('logo', $this->CDN . '/', $this->CDN . '/' . $this->configuration['custom_logo'], $this->configuration['scripts_name_version'], $this->configuration['scripts_name_version']);
474 0 : } else {
475 : // Ok so we have no set logo, does the developer want a custom logo?
476 0 : if (! empty($this->db->pluginLogo)) {
477 : // Ok lets get the logo that the user wishes to display.
478 0 : $logo = $this->modPrint('logo', $this->CDN . '/', "{$this->CDN}/plugins/{$this->db->pluginLogo}/images/logo.png", $this->configuration['scripts_name_version'], $this->configuration['scripts_name_version']);
479 0 : } else if (! empty($this->configuration['scripts_name_version'])) {
480 0 : $logo = '<h1>' . $this->configuration['scripts_name_version'] . '</h1>';
481 0 : } else {
482 : // Oops we have no logo, so lets just default to the orginal PHPDevShell logo.
483 0 : $logo = $this->modPrint('logo', $this->CDN . '/', "{$this->CDN}/plugins/PHPDevShell/images/logo.png", $this->configuration['scripts_name_version'], $this->configuration['scripts_name_version']);
484 : }
485 : }
486 : // Ok return the logo.
487 0 : print $logo;
488 0 : } else {
489 0 : print $this->modifyOutputLogo;
490 : }
491 0 : }
492 :
493 : /**
494 : * Acquire script identification image or logo.
495 : *
496 : * @param string $menu_link
497 : * @param string $active_plugin
498 : */
499 : public function scriptLogo ($menu_link, $active_plugin, $alias = null)
500 : {
501 : // Find last occurance.
502 0 : $filename_from = strrchr($menu_link, '/');
503 0 : if (empty($filename_from)) $filename_from = $menu_link;
504 : // Set image name.
505 0 : $image_name = ltrim($this->core->rightTrim($filename_from, '.php'), '/');
506 : // Create image url.
507 0 : $img_url_alias =!empty($alias) ? "plugins/$active_plugin/images/$alias.png": '';
508 0 : $img_url = "plugins/$active_plugin/images/$image_name.png";
509 0 : $image_url_plugin_default = "plugins/$active_plugin/images/default.png";
510 : // Lets check if image exists, if not, we need to set it to use default.
511 0 : if ($img_url_alias && file_exists($img_url_alias)) {
512 0 : return $this->CDN . '/' . $img_url_alias;
513 0 : } elseif (file_exists($img_url)) {
514 0 : return $this->CDN . '/' . $img_url;
515 0 : } elseif (file_exists($image_url_plugin_default)) {
516 0 : return $this->CDN . '/' . $image_url_plugin_default;
517 : } else {
518 0 : return $this->CDN . '/plugins/PHPDevShell/images/default.png';
519 : }
520 : }
521 :
522 : /**
523 : * Sets template time.
524 : *
525 : * @author Jason Schoeman
526 : */
527 : public function outputTime ()
528 : {
529 : // Check if output should be modified.
530 0 : if ($this->modifyOutputTime == false) {
531 : // Output active info.
532 0 : print $this->core->formatTimeDate($this->configuration['time']);
533 0 : } else {
534 0 : print $this->modifyOutputTime;
535 : }
536 0 : }
537 :
538 : /**
539 : * Sets template login link.
540 : *
541 : * @author Jason Schoeman
542 : */
543 : public function outputLoginLink ()
544 : {
545 0 : $navigation = $this->navigation;
546 0 : $configuration = $this->configuration;
547 :
548 : // Check if output should be modified.
549 0 : if ($this->modifyOutputLoginLink == false) {
550 0 : if ($this->user->isLoggedIn()) {
551 0 : $login_information = sprintf('<a href="%s"><div id="logged-in" class="loginlink"><span></span>%s</div></a>', $navigation->buildURL($configuration['loginandout'], 'logout=1'), $configuration['user_display_name']);
552 0 : } else {
553 0 : $inoutpage = isset($navigation->navigation[$configuration['loginandout']]) ?
554 0 : $navigation->navigation[$configuration['loginandout']]['menu_name'] : ___('Login');
555 0 : $login_information = sprintf('<a href="%s"><div id="logged-out" class="loginlink"><span></span>' . $inoutpage . '</div></a>', $navigation->buildURL($configuration['loginandout']));
556 : }
557 : // Output active info.
558 0 : print $login_information;
559 0 : } else {
560 0 : print $this->modifyOutputLoginLink;
561 : }
562 0 : }
563 :
564 : /**
565 : * Sets template role.
566 : *
567 : * @author Jason Schoeman
568 : */
569 : public function outputRole ()
570 : {
571 : // Check if output should be modified.
572 0 : if ($this->modifyOutputRole == false) {
573 : // Set active role.
574 0 : $active_role = '';
575 0 : if ($this->user->isLoggedIn())
576 0 : $active_role = sprintf(___('%s Role, '), $this->configuration['user_role_name']);
577 : // Output active info.
578 0 : print $active_role;
579 0 : } else {
580 0 : print $this->modifyOutputRole;
581 : }
582 0 : }
583 :
584 : /**
585 : * Sets template group.
586 : *
587 : * @author Jason Schoeman
588 : */
589 : public function outputGroup ()
590 : {
591 : // Check if output should be modified.
592 0 : if ($this->modifyOutputGroup == false) {
593 : // Set active role.
594 0 : $active_group = '';
595 0 : if ($this->user->isLoggedIn())
596 0 : $active_group = sprintf(___('%s Group, '), $this->configuration['user_group_name']);
597 : // Output active info.
598 0 : print $active_group;
599 0 : } else {
600 0 : print $this->modifyOutputGroup;
601 : }
602 0 : }
603 :
604 : /**
605 : * This returns/prints an image of the current script running.
606 : *
607 : * @param boolean Default is false, if set true, the heading will return instead of print.
608 : * @return string Returns image tag with image url.
609 : * @author Jason Schoeman
610 : */
611 : public function outputScriptIcon ($return = false)
612 : {
613 0 : $navigation = $this->navigation->navigation;
614 : // Create script logo ////////////////////////////////////////////////////////////////////////////
615 0 : if (! empty($navigation[$this->configuration['m']]['menu_id'])) {
616 0 : $script_logo_url = $this->scriptLogo($navigation[$this->configuration['m']]['menu_link'], $navigation[$this->configuration['m']]['plugin']);
617 : //////////////////////////////////////////////////////////////////////////////////////////////////
618 0 : $menu_name = $navigation[$this->configuration['m']]['menu_name'];
619 : // Create HTML.
620 0 : $html = $this->modPrint('scriptIcon', $script_logo_url, $menu_name);
621 : // Return or print to browser.
622 0 : if ($return == false) {
623 0 : print $html;
624 0 : } else if ($return == true) {
625 0 : return $html;
626 : }
627 0 : } else {
628 0 : return false;
629 : }
630 0 : }
631 :
632 : /**
633 : * Returns "breadcrumbs" to the template system. Intended to be used by the engine.
634 : *
635 : * @author Jason Schoeman
636 : */
637 : public function outputBreadcrumbs ()
638 : {
639 : // Check if output should be modified.
640 0 : if ($this->modifyOutputBreadcrumbs == false) {
641 0 : print $this->navigation->createBreadcrumbs();
642 0 : } else {
643 0 : print $this->modifyOutputBreadcrumbs;
644 : }
645 0 : }
646 :
647 : /**
648 : * Returns "menus" to the template system. Intended to be used by the engine.
649 : *
650 : * @author Jason Schoeman
651 : */
652 : public function outputMenu ()
653 : {
654 : // Check if output should be modified.
655 0 : if ($this->modifyOutputMenu == false) {
656 0 : print $this->navigation->createMenuStructure();
657 0 : } else {
658 0 : print $this->modifyOutputMenu;
659 : }
660 0 : }
661 :
662 : /**
663 : * Returns "output script" to the template system. Intended to be used by the engine.
664 : *
665 : * @author Jason Schoeman
666 : */
667 : public function outputScript ()
668 : {
669 0 : $this->outputController();
670 0 : }
671 :
672 : /**
673 : * Returns "output script" to the template system. Intended to be used by the engine.
674 : *
675 : * @author Jason Schoeman
676 : */
677 : public function outputController ()
678 : {
679 0 : if ($this->modifyOutputController == false) {
680 0 : print $this->controller;
681 0 : } else {
682 0 : print $this->modifyOutputController;
683 : }
684 0 : }
685 :
686 : /**
687 : * Sets template system logo or name.
688 : *
689 : * @author Jason Schoeman
690 : */
691 : public function outputTextLogo ()
692 : {
693 : // Check if output should be modified.
694 0 : if ($this->modifyOutputTextLogo == false) {
695 : // Output active info.
696 0 : print $this->configuration['scripts_name_version'];
697 0 : } else {
698 0 : print $this->modifyOutputTextLogo;
699 : }
700 0 : }
701 :
702 : /**
703 : * Returns the last footer string to the template system. Intended to be used by the engine.
704 : *
705 : * @author Jason Schoeman
706 : */
707 : public function outputFooter ()
708 : {
709 : // Check if output should be modified.
710 0 : if ($this->modifyOutputFooter == false) {
711 0 : print $this->configuration['footer_notes'];
712 0 : } else {
713 0 : print $this->modifyOutputFooter;
714 : }
715 0 : }
716 :
717 : /**
718 : * This returns/prints a heading discription of the script being executed. Intended to be used by the developer.
719 : *
720 : * @version 1.1
721 : *
722 : * @date 20110309 (v1.1) (greg) changed to use the pieces repository
723 : * @date 20110309 (v1.2) (jason) good idea but it wont work as heading is not mandatory in controllers.
724 : *
725 : * @param string This is the message that will be displayed as the heading.
726 : * @return nothing
727 : * @author Jason Schoeman
728 : */
729 : public function heading ($heading, $return = 'print')
730 : {
731 0 : $html = $this->modPrint('heading', $heading);
732 : // Return or print to browser.
733 0 : if ($return === 'print' || $return == false) {
734 0 : print $html;
735 0 : } else if ($return === 'return' || $return == true) {
736 0 : return $html;
737 : }
738 0 : }
739 :
740 : /**
741 : * This returns/prints info of the script being executed. Intended to be used by the developer.
742 : *
743 : * @version 1.1
744 : *
745 : * @date 20110309 (v1.1) (greg) changed to use the pieces repository
746 : * @date 20110309 (v1.2) (jason) good idea but it wont work as info is not mandatory in controllers.
747 : *
748 : * @param string This is the message that will be displayed as the info.
749 : * @return nothing
750 : * @author Jason Schoeman
751 : */
752 : public function info ($information, $return = 'print')
753 : {
754 : // Create HTML.
755 0 : $html = $this->modPrint('info', $information);
756 : // Return or print to browser.
757 0 : if ($return === 'print' || $return == false) {
758 0 : print $html;
759 0 : } else if ($return === 'return' || $return == true) {
760 0 : return $html;
761 : }
762 0 : }
763 :
764 : /**
765 : * This method will load given png icon from icon database,
766 : *
767 : * @param string Icon name without extention.
768 : * @param Title of given image.
769 : * @param int The size folder to look within.
770 : * @param string If an alternative class must be added to image.
771 : * @param string File type.
772 : * @param boolean Default is false, if set true, the heading will return instead of print.
773 : */
774 : public function icon($name, $title=false, $size=16, $class='icon', $type='.png', $return=true)
775 : {
776 0 : $navigation = $this->navigation->navigation;
777 : // Create icon dir.
778 0 : $script_url = $this->CDN . '/themes/' . $navigation[$this->configuration['m']]['template_folder'] . '/images/icons-' . $size . '/' . $name . $type;
779 0 : if (empty ($title))
780 0 : $title = '';
781 : // Create HTML.
782 0 : $html = $this->modPrint('icon', $script_url, $title, $class);
783 :
784 : // Return or print to browser.
785 0 : if ($return == false) {
786 0 : print $html;
787 0 : } else if ($return == true) {
788 0 : return $html;
789 : }
790 0 : }
791 :
792 : /**
793 : * This returns/prints a warning message regarding the active script. Intended to be used by the developer.
794 : *
795 : * @param string This is the message that will be displayed.
796 : * @param mixed default is print, can be set true, print, return.
797 : * @param mixed default is log, can be set true, print, return.
798 : * @return string Warning string.
799 : * @author Jason Schoeman
800 : */
801 : public function warning ($warning, $return = 'print', $log = 'log')
802 : {
803 0 : if ($log === true || $log == 'log') {
804 : // Log types are : ////////////////
805 : // 1 = OK /////////////////////////
806 : // 2 = Warning ////////////////////
807 : // 3 = Critical ///////////////////
808 : // 4 = Log-in /////////////////////
809 : // 5 = Log-out ////////////////////
810 : ///////////////////////////////////
811 0 : $log_type = 2; ////////////////////
812 : // Log the event //////////////////
813 0 : $this->db->logArray[] = array('log_type' => $log_type , 'log_description' => $warning);
814 0 : }
815 : // Create HTML.
816 0 : $html = $this->modPrint('warning', $warning);
817 : // Return or print to browser.
818 0 : if ($return === 'print' || $return == false) {
819 0 : print $html;
820 0 : } else if ($return === 'return' || $return == true) {
821 0 : return $html;
822 : }
823 0 : }
824 :
825 : /**
826 : * This returns/prints a ok message regarding the active script. Intended to be used by the developer.
827 : *
828 : * @param string This is the message that will be displayed.
829 : * @param mixed default is print, can be set true, print, return.
830 : * @param mixed default is log, can be set true, print, return.
831 : * @return string Ok string.
832 : * @author Jason Schoeman
833 : */
834 : public function ok ($ok, $return = 'print', $log = 'log')
835 : {
836 0 : if ($log === true || $log == 'log') {
837 : // Log types are : ////////////////
838 : // 1 = OK /////////////////////////
839 : // 2 = Warning ////////////////////
840 : // 3 = Critical ///////////////////
841 : // 4 = Log-in /////////////////////
842 : // 5 = Log-out ////////////////////
843 : ///////////////////////////////////
844 0 : $log_type = 1; ////////////////////
845 : // Log the event //////////////////
846 0 : $this->db->logArray[] = array('log_type' => $log_type , 'log_description' => $ok);
847 0 : }
848 : // Create HTML.
849 0 : $html = $this->modPrint('ok', $ok);
850 : // Return or print to browser.
851 0 : if ($return === 'print' || $return == false) {
852 0 : print $html;
853 0 : } else if ($return === 'return' || $return == true) {
854 0 : return $html;
855 : }
856 0 : }
857 :
858 : /**
859 : * This returns/prints a error message regarding the active script. Intended to be used by the developer where exceptions are caught.
860 : *
861 : * @param string This is the message that will be displayed.
862 : * @param mixed default is print, can be set true, print, return.
863 : * @param mixed default is log, can be set true, print, return.
864 : * @return string Error string.
865 : * @author Jason Schoeman
866 : */
867 : public function error ($error, $return = 'print', $log = 'log')
868 : {
869 0 : if ($log === true || $log == 'log') {
870 : // Log types are : ////////////////
871 : // 1 = OK /////////////////////////
872 : // 2 = Warning ////////////////////
873 : // 3 = Critical ///////////////////
874 : // 4 = Log-in /////////////////////
875 : // 5 = Log-out ////////////////////
876 : // 6 = Error //////////////////////
877 : ///////////////////////////////////
878 0 : $log_type = 6; ////////////////////
879 : // Log the event //////////////////
880 0 : $this->db->logArray[] = array('log_type' => $log_type , 'log_description' => $error);
881 0 : }
882 : // Create HTML.
883 0 : $html = $this->modPrint('error', $error);
884 : // Return or print to browser.
885 0 : if ($return === 'print' || $return == false) {
886 0 : print $html;
887 0 : } else if ($return === 'return' || $return == true) {
888 0 : return $html;
889 : }
890 0 : }
891 :
892 : /**
893 : * This returns/prints a critical message regarding the active script. Intended to be used by the developer.
894 : *
895 : * @param string This is the message that will be displayed.
896 : * @param mixed default is print, can be set true, print, return.
897 : * @param mixed default is log, can be set true, print, return.
898 : * @return string Critical string.
899 : * @author Jason Schoeman
900 : */
901 : public function critical ($critical, $return = 'print', $log = 'log', $mail = 'mailadmin')
902 : {
903 0 : $navigation = $this->navigation->navigation;
904 0 : if ($log === true || $log == 'log') {
905 : // Log types are : ////////////////
906 : // 1 = OK /////////////////////////
907 : // 2 = Warning ////////////////////
908 : // 3 = Critical ///////////////////
909 : // 4 = Log-in /////////////////////
910 : // 5 = Log-out ////////////////////
911 : ///////////////////////////////////
912 0 : $log_type = 3; ////////////////////
913 : // Log the event //////////////////
914 0 : $this->db->logArray[] = array('log_type' => $log_type , 'log_description' => $critical);
915 0 : }
916 : // Check if we need to email admin.
917 0 : if ($this->configuration['email_critical']) {
918 : // Subject.
919 0 : $subject = sprintf(___("CRITICAL ERROR NOTIFICATION %s"), $this->configuration['scripts_name_version']);
920 : // Message.
921 0 : $broke_script = $navigation[$this->configuration['m']]['menu_name'];
922 0 : $broken_url = $this->configuration['absolute_url'] . '/index.php?m=' . $this->configuration['m'];
923 0 : $message = sprintf(___("Dear Admin,\r\n\r\nTHERE WAS A CRITICAL ERROR IN %s:\r\n\r\n%s\r\n\r\nClick on url to access broken script called %s:\r\n%s\r\n\r\nScript error occurred for user:\r\n%s"), $this->configuration['scripts_name_version'], $critical, $broke_script, $broken_url, $this->configuration['user_display_name']);
924 0 : if ($mail === true || $mail == 'mailadmin') {
925 : // Initiate email class.
926 0 : $email = $this->factory('mailer');
927 : // Ok we can now send the critical email message.
928 0 : $email->sendmail("{$this->configuration['setting_admin_email']}", $subject, $message);
929 0 : }
930 0 : }
931 : // Create HTML.
932 0 : $html = $this->modPrint('critical', $critical);
933 :
934 : // Return or print to browser.
935 0 : if ($return === 'print' || $return == false) {
936 0 : print $html;
937 0 : } else if ($return === 'return' || $return == true) {
938 0 : return $html;
939 : }
940 0 : }
941 :
942 : /**
943 : * This returns/prints a notice of the script being executed. Intended to be used by the developer.
944 : *
945 : * @param string This is the message that will be displayed.
946 : * @param mixed default is print, can be set true, print, return.
947 : * @return string Notice string.
948 : * @author Jason Schoeman
949 : */
950 : public function notice ($notice, $return = 'print')
951 : {
952 : // Create HTML.
953 0 : $html = $this->modPrint('notice', $notice);
954 :
955 : // Return or print to browser.
956 0 : if ($return === 'print' || $return == false) {
957 0 : print $html;
958 0 : } else if ($return === 'return' || $return == true) {
959 0 : return $html;
960 : }
961 0 : }
962 :
963 : /**
964 : * This returns/prints a busy of the script being executed. Intended to be used by the developer.
965 : *
966 : * @param string This is the message that will be displayed.
967 : * @param mixed default is print, can be set true, print, return.
968 : * @return string Busy string.
969 : * @author Jason Schoeman
970 : */
971 : public function busy ($busy, $return = 'print')
972 : {
973 : // Create HTML.
974 0 : $html = $this->modPrint('busy', $busy);
975 :
976 : // Return or print to browser.
977 0 : if ($return === 'print' || $return == false) {
978 0 : print $html;
979 0 : } else if ($return === 'return' || $return == true) {
980 0 : return $html;
981 : }
982 0 : }
983 :
984 : /**
985 : * This returns/prints a message of the script being executed. Intended to be used by the developer.
986 : *
987 : * @param string This is the message that will be displayed.
988 : * @param mixed default is print, can be set true, print, return.
989 : * @return string Message string.
990 : * @author Jason Schoeman
991 : */
992 : public function message ($message, $return = 'print')
993 : {
994 : // Create HTML.
995 0 : $html = $this->modPrint('message', $message);
996 :
997 : // Return or print to browser.
998 0 : if ($return === 'print' || $return == false) {
999 0 : print $html;
1000 0 : } else if ($return === 'return' || $return == true) {
1001 0 : return $html;
1002 : }
1003 0 : }
1004 :
1005 : /**
1006 : * This returns/prints a note of the script being executed. Intended to be used by the developer.
1007 : *
1008 : * @param string This is the message that will be displayed.
1009 : * @param mixed default is print, can be set true, print, return.
1010 : * @return string Note string.
1011 : * @author Jason Schoeman
1012 : */
1013 : public function note ($note, $return = 'print')
1014 : {
1015 : // Create HTML.
1016 0 : $html = $this->modPrint('note', $note);
1017 :
1018 : // Return or print to browser.
1019 0 : if ($return === 'print' || $return == false) {
1020 0 : print $html;
1021 0 : } else if ($return === 'return' || $return == true) {
1022 0 : return $html;
1023 : }
1024 0 : }
1025 :
1026 : /**
1027 : * This returns/prints a heading of the script being executed. Intended to be used by the developer.
1028 : *
1029 : * @param string This is the message that will be displayed.
1030 : * @param mixed default is print, can be set true, print, return.
1031 : * @return string Heading string.
1032 : * @author Jason Schoeman
1033 : */
1034 : public function scripthead ($scripthead, $return = 'print')
1035 : {
1036 : // Create HTML.
1037 0 : $html = $this->modPrint('scripthead', $scripthead);
1038 :
1039 : // Return or print to browser.
1040 0 : if ($return === 'print' || $return == false) {
1041 0 : print $html;
1042 0 : } else if ($return === 'return' || $return == true) {
1043 0 : return $html;
1044 : }
1045 0 : }
1046 :
1047 : /**
1048 : * This creates an the [i] when over with mouse a popup with a message appears, this can be placed anywhere. Intended to be used by the developer.
1049 : *
1050 : * @param string The message to diplay when mouse goes over the [i].
1051 : * @param boolean Sets to print out confirm link instead of return.
1052 : * @author Jason Schoeman
1053 : */
1054 : public function tip ($text, $print = false)
1055 : {
1056 : // This is yet another IE Fix !
1057 0 : $text_clean = preg_replace('/"/', '', $text);
1058 0 : $info = $this->modPrint('tooltip', $text_clean);
1059 0 : if ($print == false) {
1060 0 : return $info;
1061 : } else {
1062 0 : print $info;
1063 : }
1064 0 : }
1065 :
1066 : /**
1067 : * This function support output_script by looking deeper into menu structure to find last linked menu item that is not linked to another.
1068 : *
1069 : * @param integer $extended_menu_id
1070 : * @return integer
1071 : */
1072 : public function extendMenuLoop ($extended_menu_id)
1073 : {
1074 : // Assign extention value.
1075 0 : $extend_more = $this->navigation->navigation[$extended_menu_id]['extend'];
1076 : // Check if we should look higher up for a working menu id and prevent endless looping.
1077 0 : if (! empty($extend_more) && ($extended_menu_id != $this->navigation->navigation[$extend_more]['extend'])) {
1078 0 : $this->extendMenuLoop($extend_more);
1079 0 : } else {
1080 : // Final check, to see if we had an endless loop that still has an extention.
1081 0 : if (! empty($this->navigation->navigation[$extended_menu_id]['extend'])) {
1082 0 : if (! empty($this->navigation->navigation[$extended_menu_id]['parent_menu_id'])) {
1083 : // Lets look even higher up now that we jumped the endless loop.
1084 0 : $this->extendMenuLoop($this->navigation->navigation[$extended_menu_id]['parent_menu_id']);
1085 0 : } else {
1086 : // We now have no other choice but to show default home page.
1087 0 : $this->extended_menu_id = 0;
1088 : }
1089 0 : } else {
1090 0 : $this->extended_menu_id = $extended_menu_id;
1091 : }
1092 : }
1093 0 : }
1094 :
1095 : /**
1096 : * Executes the controller.
1097 : *
1098 : * @author Jason Schoeman
1099 : */
1100 : public function executeController()
1101 : {
1102 0 : $this->view = '';
1103 0 : $navigation = $this->navigation->navigation;
1104 0 : $configuration = $this->configuration;
1105 :
1106 : ////////////////////////////////////////////////////////////////////////////////////////
1107 : // Start SQL transactions.
1108 0 : $this->db->startTransaction();
1109 : // Are we in demo mode?
1110 0 : if ($configuration['demo_mode'] == true) {
1111 0 : if ($configuration['user_role'] != $configuration['root_role']) {
1112 : // Show demo mode message for end user.
1113 0 : $this->notice(sprintf(___('%s is currently in a demo mode state, no actual database transactions will occur.'), $configuration['scripts_name_version']));
1114 0 : } else {
1115 : // Show demo mode message for root user.
1116 0 : $this->notice(sprintf(___('%s is currently in a demo mode state, only Root users are able to save database transactions.'), $configuration['scripts_name_version']));
1117 : }
1118 0 : }
1119 : // Load script to buffer.
1120 0 : if (! empty($navigation[$configuration['m']]['menu_id'])) {
1121 : // We need to assign active menu_id.
1122 0 : $menu_id = $configuration['m'];
1123 : // Determine correct menu action.
1124 0 : switch ($navigation[$configuration['m']]['menu_type']) {
1125 : // Plugin File.
1126 0 : case 1:
1127 : // Do case.
1128 0 : $menu_case = 1;
1129 0 : break;
1130 : // Link.
1131 0 : case 2:
1132 0 : break;
1133 : // Jump.
1134 0 : case 3:
1135 0 : break;
1136 : // External File.
1137 0 : case 4:
1138 : // Do case.
1139 0 : $menu_case = 4;
1140 0 : break;
1141 : // HTTP URL.
1142 0 : case 5:
1143 : // Do case.
1144 0 : $menu_case = 5;
1145 0 : break;
1146 : // Placeholder.
1147 0 : case 6:
1148 0 : break;
1149 : // iFrame.
1150 0 : case 7:
1151 : // Do case.
1152 0 : $menu_case = 7;
1153 0 : break;
1154 : // Cronjob.
1155 0 : case 8:
1156 : // Do case.
1157 0 : $menu_case = 8;
1158 0 : break;
1159 0 : default:
1160 : // Do case.
1161 0 : $menu_case = 1;
1162 0 : break;
1163 0 : }
1164 : ///////////////////////////////////
1165 : // Do further checking on links. //
1166 : ///////////////////////////////////
1167 0 : if (empty($menu_case)) {
1168 : // So we have some kind of link, we now need to see what kind of link we have.
1169 : // Get menu extended data.
1170 0 : $extend = $navigation[$menu_id]['extend'];
1171 : // Get menu type.
1172 0 : if (!empty($navigation[$extend]['menu_type'])) {
1173 0 : $linked_menu_type = $navigation[$extend]['menu_type'];
1174 0 : } else {
1175 0 : throw new PHPDS_exception(sprintf(___('I had a problem extending menu item %s, it does not seem to exist.'), $extend));
1176 : }
1177 : // We now have the linked menu type and can now work accordingly.
1178 : // Determine correct menu action.
1179 : switch ($linked_menu_type) {
1180 : // Plugin File.
1181 0 : case 1:
1182 : // Do case.
1183 0 : $menu_case = 1;
1184 : // We need to assign active menu_id.
1185 0 : $menu_id = $extend;
1186 0 : break;
1187 : // Link.
1188 0 : case 2:
1189 : // Do case.
1190 0 : $menu_case = 2;
1191 : // We need to assign active menu_id.
1192 0 : $this->extendMenuLoop($navigation[$extend]['extend']);
1193 0 : $menu_id = $this->extended_menu_id;
1194 0 : break;
1195 : // Jump.
1196 0 : case 3:
1197 : // Do case.
1198 0 : $menu_case = 2;
1199 : // We need to assign active menu_id.
1200 0 : $this->extendMenuLoop($navigation[$extend]['extend']);
1201 0 : $menu_id = $this->extended_menu_id;
1202 0 : break;
1203 : // External File.
1204 0 : case 4:
1205 : // Do case.
1206 0 : $menu_case = 4;
1207 : // We need to assign active menu_id.
1208 0 : $menu_id = $extend;
1209 0 : break;
1210 : // HTTP URL.
1211 0 : case 5:
1212 : // Do case.
1213 0 : $menu_case = 5;
1214 : // We need to assign active menu_id.
1215 0 : $menu_id = $extend;
1216 0 : break;
1217 : // Placeholder.
1218 0 : case 6:
1219 : // Do case.
1220 0 : $menu_case = 2;
1221 : // We need to assign active menu_id.
1222 0 : $this->extendMenuLoop($navigation[$extend]['extend']);
1223 0 : $menu_id = $this->extended_menu_id;
1224 0 : break;
1225 : // iFrame.
1226 0 : case 7:
1227 : // Do case.
1228 0 : $menu_case = 7;
1229 : // We need to assign active menu_id.
1230 0 : $menu_id = $extend;
1231 0 : break;
1232 : // Cronjob.
1233 0 : case 8:
1234 : // Do case.
1235 0 : $menu_case = 8;
1236 : // We need to assign active menu_id.
1237 0 : $menu_id = $extend;
1238 0 : break;
1239 0 : default:
1240 : // Do case.
1241 0 : $menu_case = 1;
1242 : // We need to assign active menu_id.
1243 0 : $menu_id = $extend;
1244 0 : break;
1245 0 : }
1246 0 : }
1247 : // Execute repeated menu cases.
1248 : switch ($menu_case) {
1249 : // Plugin Script.
1250 0 : case 1:
1251 0 : $this->loadControllerFile($menu_id);
1252 0 : break;
1253 : // Link, Jump, Placeholder.
1254 0 : case 2:
1255 : // Is this an empty menu item?
1256 0 : if (empty($menu_id)) {
1257 : // Lets take user to the front page as last option.
1258 : // Get correct frontpage id.
1259 0 : ($this->user->isLoggedIn()) ? $menu_id = $configuration['front_page_id_in'] : $menu_id = $configuration['front_page_id'];
1260 0 : }
1261 0 : $this->loadControllerFile($menu_id);
1262 0 : break;
1263 : // External File.
1264 0 : case 4:
1265 : // Require external file.
1266 0 : if (!$this->core->loadFile($navigation[$menu_id]['menu_link'])) {
1267 0 : PHPDS_exception(sprintf(___('File could not be found, I tried to execute filename : %s'), $navigation[$menu_id]['menu_link']));
1268 0 : }
1269 0 : break;
1270 : // HTTP URL.
1271 0 : case 5:
1272 : // Redirect to external http url.
1273 0 : $this->ok(sprintf(___('You are now being redirected to an external url, %s'), $navigation[$menu_id]['menu_link']), false, false);
1274 0 : $this->navigation->redirect($navigation[$menu_id]['menu_link']);
1275 0 : break;
1276 : // iFrame.
1277 0 : case 7:
1278 : // Clean up height.
1279 0 : $height = preg_replace('/px/i', '', $navigation[$menu_id]['extend']);
1280 : // Create Iframe.
1281 0 : $this->HTML = $this-> modPrint('iframe', $navigation[$menu_id]['menu_link'], $height, '100%');
1282 0 : break;
1283 : // Cronjob.
1284 0 : case 8:
1285 : // Require script.
1286 0 : if (!$this->loadControllerFile($menu_id)) {
1287 0 : $time_now = time();
1288 : // Update last execution.
1289 0 : $this->db->invokeQuery('TEMPLATE_cronExecutionLogQuery', $time_now, $menu_id);
1290 : // Always log manual touched cronjobs.
1291 0 : $this->ok(sprintf(___('Cronjob %s executed manually.'), $navigation[$menu_id]['menu_name']));
1292 0 : }
1293 0 : break;
1294 : }
1295 : // This is used for debugging scripts.
1296 : // It will always show if $template->debugStr is set.
1297 0 : ($this->debugStr) ? $this->notice($this->debugStr) : null;
1298 : // Print HEREDOC HTML.
1299 0 : if (! empty($this->HTML)) print $this->HTML;
1300 0 : } else {
1301 0 : $this->stopScript = array('type'=>'auth','message'=>___('Authentication Required'));
1302 : }
1303 0 : if (isset($this->stopScript)) {
1304 : // Roll back current transaction.
1305 0 : $this->db->invokeQuery('TEMPLATE_rollbackQuery');
1306 0 : switch ($this->stopScript['type']) {
1307 0 : case 'auth':
1308 0 : throw new PHPDS_securityException($this->stopScript['message']);
1309 : break;
1310 :
1311 0 : case '404':
1312 0 : throw new PHPDS_pageException404($this->stopScript['message'],$this->stopScript['type']);
1313 : break;
1314 :
1315 0 : case '403':
1316 0 : throw new PHPDS_securityException403($this->stopScript['message'],$this->stopScript['type']);
1317 : break;
1318 :
1319 0 : default:
1320 0 : throw new PHPDS_securityException($this->stopScript['message'],$this->stopScript['type']);
1321 : break;
1322 0 : }
1323 : }
1324 : // End database transactions.
1325 0 : $this->db->endTransaction();
1326 0 : }
1327 :
1328 : /**
1329 : * Will attempt to load controller file from various locations.
1330 : *
1331 : * @version 1.0.1
1332 : *
1333 : * @date 20100917 (v1.0) (Jason)
1334 : * @date 20110308 (v1.0.1) (greg) loadFile returns an exact false when the file is not found
1335 : *
1336 : * @author Jason Schoeman
1337 : * @param int
1338 : */
1339 : public function loadControllerFile ($menu_id, $include_model = false)
1340 : {
1341 0 : $navigation = $this->navigation->navigation;
1342 0 : $core = $this->core;
1343 : // Set plugin folder.
1344 :
1345 0 : if (!empty($navigation[$menu_id])) {
1346 0 : $plugin_folder = $navigation[$menu_id]['plugin_folder'];
1347 : // Do we want to include the model.
1348 0 : if ($include_model) {
1349 0 : if ($include_model === true) $include_model = 'query';
1350 0 : $core->loadFile($plugin_folder . 'models/' . preg_replace("/.php/", '.' . $include_model . '.php', $navigation[$menu_id]['menu_link']));
1351 0 : }
1352 : // Set active script directory.
1353 0 : $active_dir = $plugin_folder . '%s' . $navigation[$menu_id]['menu_link'];
1354 : // Require script.
1355 0 : if ($core->loadFile(sprintf($active_dir, 'controllers/')) !== false) return true;
1356 0 : if ($core->loadFile(sprintf($active_dir, '')) !== false) return true;
1357 0 : }
1358 0 : if (empty($this->stopScript)) {
1359 0 : throw new PHPDS_exception(sprintf(___('The controller of menu id %d could not be found, I tried to execute filename : "%s"'), $menu_id, sprintf($active_dir, '{controllers/}')));
1360 : }
1361 0 : return false;
1362 : }
1363 :
1364 : /**
1365 : * Login heading messages.
1366 : *
1367 : * @author Jason Schoeman
1368 : */
1369 : public function loginFormHeading($return = false)
1370 : {
1371 0 : $HTML = '';
1372 0 : $message= '';
1373 0 : if (! empty($this->loginMessage))
1374 0 : $message = $this->notice(___($this->loginMessage), 'return');
1375 :
1376 : // Create headings for login.
1377 0 : if (! empty($this->stopScript)) {
1378 0 : $HTML .= $this->heading(___('Authentication Required'), 'return');
1379 0 : $HTML .= $message;
1380 0 : } else {
1381 : // Get some default settings.
1382 0 : $settings = $this->db->getSettings(array('login_message'));
1383 :
1384 : // Check if we have a login message to display.
1385 0 : if (! empty($settings['login_message'])) {
1386 0 : $login_message = $this->message(___($settings['login_message']), 'return');
1387 0 : } else {
1388 0 : $login_message = '';
1389 : }
1390 :
1391 0 : $HTML .= $this->heading(___('Login'), 'return');
1392 0 : $HTML .= $login_message;
1393 0 : $HTML .= $message;
1394 : }
1395 :
1396 0 : if ($return == false) {
1397 0 : print $HTML;
1398 0 : } else {
1399 0 : return $HTML;
1400 : }
1401 0 : }
1402 :
1403 : /**
1404 : * Executes the login.
1405 : *
1406 : * @author Jason Schoeman
1407 : */
1408 : public function loginForm($return = false)
1409 : {
1410 0 : $HTML = $this->factory('StandardLogin')->loginForm($return);
1411 :
1412 0 : if ($return == false) {
1413 0 : print $HTML;
1414 0 : } else {
1415 0 : return $HTML;
1416 : }
1417 0 : }
1418 :
1419 : /**
1420 : * Get and return the supposed to run template.
1421 : *
1422 : * @return string if not found, return default.
1423 : * @author Jason Schoeman
1424 : */
1425 : public function getTemplate ()
1426 : {
1427 : // Check if the menu has a defined template.
1428 0 : if (! empty($this->navigation->navigation[$this->configuration['m']]['template_folder'])) {
1429 0 : $settings['default_template'] = $this->navigation->navigation[$this->configuration['m']]['template_folder'];
1430 0 : } else {
1431 : // If not check if the gui system settings was set with a default template.
1432 0 : $settings['default_template'] = $this->configuration['default_template'];
1433 : }
1434 :
1435 : // Return the complete template.
1436 0 : return $settings['default_template'];
1437 : }
1438 :
1439 : /**
1440 : * Gets the correct location of a tpl file, will return full path, can be a view.tpl or view.tpl.php files.
1441 : *
1442 : * @param string $load_view
1443 : * @param string $plugin_override If another plugin is to be used in the directory.
1444 : */
1445 : public function getTpl($load_view=false, $plugin_override=false)
1446 : {
1447 0 : $configuration = $this->configuration;
1448 0 : $navigation = $this->navigation;
1449 0 : $core = $this->core;
1450 :
1451 : // Menu link.
1452 0 : if (empty($navigation->navigation[$configuration['m']]['extend'])) {
1453 0 : $menu_link = $navigation->navigation[$configuration['m']]['menu_link'];
1454 0 : } else {
1455 0 : $menu_link = $navigation->navigation[$navigation->navigation[$configuration['m']]['extend']]['menu_link'];
1456 : // Set plugin for this menu item.
1457 0 : $plugin_extend = $navigation->navigation[$navigation->navigation[$configuration['m']]['extend']]['plugin'];
1458 : }
1459 : // Do template engine.
1460 0 : if (empty($plugin_override) && empty($plugin_extend)) {
1461 0 : $plugin_folder = $configuration['absolute_path'] . 'plugins/' . $core->activePlugin() . '/';
1462 0 : } else if (! empty($plugin_override)) {
1463 0 : $plugin_folder = $configuration['absolute_path'] . 'plugins/' . $plugin_override . '/';
1464 0 : } else if (! empty($plugin_extend)) {
1465 0 : $plugin_folder = $configuration['absolute_path'] . 'plugins/' . $plugin_extend . '/';
1466 0 : }
1467 :
1468 : // Do we have a custom template file?
1469 0 : if (empty($load_view) && !empty($navigation->navigation[$configuration['m']]['layout'])) {
1470 0 : $load_view = $navigation->navigation[$configuration['m']]['layout'];
1471 0 : }
1472 : // Check if we have a template file otherwise use default.
1473 0 : if (empty($load_view)) {
1474 0 : $tpl_dir = str_replace($menu_link, '%s/' . str_replace('.php', '.tpl', $menu_link), $plugin_folder . $menu_link);
1475 0 : } else {
1476 0 : $link = strrchr($menu_link, '/');
1477 0 : if (empty($link)) {
1478 0 : $tpl_dir = $plugin_folder . '%s/' . $load_view;
1479 0 : } else {
1480 0 : $link = str_replace($link, '', $menu_link);
1481 0 : $tpl_dir = $plugin_folder . '%s/' . $link . '/' . $load_view;
1482 : }
1483 : }
1484 : // Log to firephp.
1485 0 : $this->_log(__('Loading Template Layout : ', 'core.lang') . $tpl_dir);
1486 : // Return file location.
1487 0 : if (file_exists(sprintf($tpl_dir, 'views'))) {
1488 0 : $tpldir = sprintf($tpl_dir, 'views');
1489 0 : return $tpldir;
1490 : // Perhaps we have a php template.
1491 0 : } else if (file_exists(sprintf($tpl_dir . '.php', 'views'))) {
1492 0 : return sprintf($tpl_dir . '.php', 'views');
1493 : } else {
1494 0 : return false;
1495 : }
1496 : }
1497 :
1498 : /**
1499 : * Prints the number of queries used to the gui.
1500 : *
1501 : * @param string $count_queries
1502 : */
1503 : public function debugInfo ()
1504 : {
1505 0 : if (! empty($this->db->countQueries)) {
1506 0 : $count_queries = $this->db->countQueries;
1507 0 : } else {
1508 0 : $count_queries = 0;
1509 : }
1510 0 : if ($this->configuration['queries_count']) {
1511 0 : if (!empty($this->templateName)) {
1512 0 : $memory_used = memory_get_peak_usage();
1513 0 : $queries_used = sprintf('(Queries Used : %s) - (PHP Memory Used : %s Mb)', $count_queries, number_format($memory_used / 1000000, 2, '.', ' '));
1514 0 : print $this->modPrint('queries_count', $queries_used);
1515 0 : }
1516 0 : }
1517 0 : }
1518 :
1519 : /**
1520 : * Convert all HTML entities to their applicable characters.
1521 : *
1522 : * @param string $string_to_decode
1523 : * @return string
1524 : */
1525 : public function htmlEntityDecode ($string_to_decode)
1526 : {
1527 : // Decode characters.
1528 0 : return html_entity_decode($string_to_decode, ENT_QUOTES, $this->configuration['charset']);
1529 : }
1530 :
1531 : /**
1532 : * returns a piece from the repository, optionnaly throught a module
1533 : *
1534 : * @version 1.0
1535 : * @since v3.1.0
1536 : * @author greg <greg@phpdevshell.org>
1537 : * @date 20110309 (v1.0) (greg) added
1538 : *
1539 : * @param $name string, the name of the piece to fetch
1540 : * @param $module string or boolean, (optionnal) the name of the module to use, true to use a module with the piece name, false not to use a module
1541 : */
1542 : public function getPiece($name, $module = false)
1543 : {
1544 0 : $data = isset($this->pieces[$name]) ? $this->pieces[$name] : '';
1545 0 : if ($module) {
1546 0 : if ($module === true) {
1547 0 : $module = $name;
1548 0 : }
1549 0 : return $this->modPrint($module, $data);
1550 : } else {
1551 0 : return $data;
1552 : }
1553 : }
1554 :
1555 : /**
1556 : * insert a piece into the repository
1557 : *
1558 : * @version 1.0
1559 : * @since v3.1.0
1560 : * @author greg <greg@phpdevshell.org>
1561 : * @date 20110309 (v1.0) (greg) added
1562 : *
1563 : * @param $name string, the name of the piece to add
1564 : * @param $data string, the raw content of the piece
1565 : */
1566 : public function setPiece($name, $data = null)
1567 : {
1568 0 : $this->pieces[$name] = $data;
1569 0 : }
1570 :
1571 :
1572 : /**
1573 : * Ability to call and display notifications pushed to the notification system.
1574 : *
1575 : * @version 1.0
1576 : * @since v3.0.5
1577 : * @date 20110706 (v1.0) (greg) added
1578 : */
1579 : public function outputNotifications()
1580 : {
1581 0 : $notifications = $this->notif->fetch();
1582 :
1583 0 : if (! empty($notifications)) {
1584 0 : foreach($notifications as $notification) {
1585 0 : $this->info($notification);
1586 0 : }
1587 0 : }
1588 0 : }
1589 : }
1590 :
1591 : /**
1592 : * Creates a language tooltip string and prints it out to the template.
1593 : *
1594 : * @param string $info_mark
1595 : */
1596 1 : function tip ($text)
1597 : {
1598 0 : global $template;
1599 0 : $template->tip(_($text), true);
1600 0 : }
1601 : /**
1602 : * Creates a language tooltip string inside a text domain and prints it out to the template.
1603 : *
1604 : * @param string $info_mark
1605 : */
1606 1 : function dtip ($text, $domain)
1607 : {
1608 0 : global $template;
1609 0 : $template->tip(dgettext($domain, $text), true);
1610 0 : }
|