Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentRssCreator
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

  • cGuiBackendHelpbox
  • cGuiFileOverview
  • cGuiFoldingRow
  • cGuiList
  • cGuiMenu
  • cGuiNavigation
  • cGuiNotification
  • cGuiObjectPager
  • cGuiPage
  • cGuiScrollList
  • cGuiSourceEditor
  • cGuiTableForm
  • cGuiTree
  • cPager
  • cTemplate
  • cTree
  • cTreeItem
  • NoteLink
  • NoteList
  • NoteListItem
  • NoteView
  • TODOLink
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: 
  3: /**
  4:  * This file contains the generic page GUI class.
  5:  *
  6:  * @package Core
  7:  * @subpackage GUI
  8:  *
  9:  * @author Mischa Holz
 10:  * @copyright four for business AG <www.4fb.de>
 11:  * @license http://www.contenido.org/license/LIZENZ.txt
 12:  * @link http://www.4fb.de
 13:  * @link http://www.contenido.org
 14:  */
 15: 
 16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 17: 
 18: /**
 19:  * Generic page GUI class.
 20:  *
 21:  * Manages HTML pages and provides functions for rendering them.
 22:  *
 23:  * @package Core
 24:  * @subpackage GUI
 25:  */
 26: class cGuiPage {
 27: 
 28:     /**
 29:      * The name of the page.
 30:      * This will be used to load the template, stylesheets and scripts.
 31:      *
 32:      * @var string
 33:      */
 34:     protected $_pageName;
 35: 
 36:     /**
 37:      * The name of the plugin of the current webpage.
 38:      *
 39:      * @var string
 40:      */
 41:     protected $_pluginName;
 42: 
 43:     /**
 44:      * The general page template.
 45:      *
 46:      * @var cTemplate
 47:      */
 48:     protected $_pageTemplate;
 49: 
 50:     /**
 51:      * The file used generate the page.
 52:      *
 53:      * @var string
 54:      */
 55:     protected $_pageBase;
 56: 
 57:     /**
 58:      * The template for everything that is inside the body.
 59:      * This is usually template.PAGENAME.html.
 60:      *
 61:      * @var cTemplate
 62:      */
 63:     protected $_contentTemplate;
 64: 
 65:     /**
 66:      * An array of script names (inside /scripts/) which will be
 67:      * included in the final page.
 68:      *
 69:      * @var array
 70:      */
 71:     protected $_scripts;
 72: 
 73:     /**
 74:      * An array of stylesheets (inside /styles/) which will be included
 75:      * in the final page.
 76:      *
 77:      * @var array
 78:      */
 79:     protected $_styles;
 80: 
 81:     /**
 82:      * The script to set the subnavigation.
 83:      * This will be included in the final page.
 84:      *
 85:      * @var string
 86:      */
 87:     protected $_subnav;
 88: 
 89:     /**
 90:      * The script to markup the current submenu item.
 91:      * This will be included in the final page.
 92:      *
 93:      * @var string
 94:      */
 95:     protected $_markScript;
 96: 
 97:     /**
 98:      * An error message which will be used to display an error with the
 99:      * help of cGuiNotification.
100:      *
101:      * @var string
102:      */
103:     protected $_error;
104: 
105:     /**
106:      * A warning which will be used to display an error with the help of
107:      * cGuiNotification.
108:      *
109:      * @var string
110:      */
111:     protected $_warning;
112: 
113:     /**
114:      * An info which will be used to display an error with the help of
115:      * cGuiNotification.
116:      *
117:      * @var string
118:      */
119:     protected $_info;
120: 
121:     /**
122:      * A ok which will be used to display an error with the help of
123:      * cGuiNotification.
124:      *
125:      * @var string
126:      */
127:     protected $_ok;
128: 
129:     /**
130:      * If true, just display the message and don't render the template.
131:      *
132:      * @var bool
133:      */
134:     protected $_abort;
135: 
136:     /**
137:      * An array of cHTML objects which will be rendered instead of
138:      * filling a template.
139:      *
140:      * @var array
141:      */
142:     protected $_objects;
143: 
144:     /**
145:      * Array of arrays where each array contains information about a
146:      * meta tag.
147:      *
148:      * @var array
149:      */
150:     protected $_metaTags;
151: 
152:     /**
153:      * Array of class attribute values for body tag.
154:      *
155:      * @var array
156:      */
157:     protected $_bodyClassNames;
158: 
159: 
160:     /**
161:      * Scripts and styles subfolder for cGuiPage objects.
162:      *
163:      * @var string
164:      */
165:     protected $_filesDirectory;
166: 
167:     /**
168:      * Whether the template exist check should be skipped or not.
169:      *
170:      * @var bool
171:      */
172:     protected $_skipTemplateCheck = false;
173: 
174:     /**
175:      * Constructor to create an instance of this class.
176:      *
177:      * The constructor initializes the class and tries to get the
178:      * encoding from the currently selected language.
179:      *
180:      * It will also add every script in the form of /scripts/*.PAGENAME.js
181:      * and every stylesheet in the form of /styles/*.PAGENAME.css to the
182:      * page as well as /scripts/PAGENAME.js and /styles/PAGENAME.css.
183:      *
184:      * @param string $pageName
185:      *         The name of the page which will be used to load
186:      *         corresponding stylesheets, templates and scripts.
187:      * @param string $pluginName [optional]
188:      *         The name of the plugin in which the site is run
189:      * @param string $subMenu [optional]
190:      *         The number of the submenu which should be highlighted
191:      *         when this page is shown.
192:      */
193:     public function __construct($pageName, $pluginName = '', $subMenu = '') {
194:         global $lang, $cfg, $sess;
195: 
196:         $this->_pageName = $pageName;
197:         $this->_pluginName = $pluginName;
198:         $this->_pageTemplate = new cTemplate();
199:         $this->_contentTemplate = new cTemplate();
200:         $this->_scripts = array();
201:         $this->_styles = array();
202:         $this->_subnav = '';
203:         $this->_markScript = '';
204:         $this->_error = '';
205:         $this->_warning = '';
206:         $this->_info = '';
207:         $this->_abort = false;
208:         $this->_objects = array();
209:         $this->_metaTags = array();
210:         $this->_bodyClassNames = array();
211: 
212:         // Try to extract the current CONTENIDO language
213:         $clang = new cApiLanguage($lang);
214: 
215:         if ($clang->isLoaded()) {
216:             $this->setEncoding($clang->get('encoding'));
217:         }
218: 
219:         // use default page base
220:         $this->setPageBase();
221: 
222:         $this->_pageTemplate->set('s', 'SUBMENU', $subMenu);
223:         $this->_pageTemplate->set('s', 'PAGENAME', $pageName);
224:         $pageid = str_replace('.', '_', $pageName);
225:         $this->_pageTemplate->set('s', 'PAGENAME', $pageName);
226:         $this->_pageTemplate->set('s', 'PAGEID', $pageid);
227: 
228:         $this->addBodyClassName('page_generic');
229:         $this->addBodyClassName('page_' . $pageid);
230: 
231:         $scriptDir = '';
232:         $styleDir = '';
233:         if($pluginName != '') {
234:             $this->_filesDirectory = '';
235:             $scriptDir = cRegistry::getBackendPath() . $cfg['path']['plugins'] . $pluginName . '/' . $cfg['path']['scripts'];
236:             $styleDir = cRegistry::getBackendPath() . $cfg['path']['plugins'] . $pluginName . '/' . $cfg['path']['styles'];
237:         } else {
238:             $this->_filesDirectory = 'includes/';
239:             $scriptDir = $cfg['path']['scripts_includes'];
240:             $styleDir = $cfg['path']['styles_includes'];
241:         }
242: 
243:         if (cFileHandler::exists($styleDir . $pageName . '.css')) {
244:             $this->addStyle($this->_filesDirectory . $pageName . '.css');
245:         }
246: 
247:         /* @var $stylefile SplFileInfo */
248:         if(cFileHandler::exists($styleDir)) {
249:             foreach (new DirectoryIterator($styleDir) as $stylefile) {
250:                 if (cString::endsWith($stylefile->getFilename(), '.' . $pageName . '.css')) {
251:                     $this->addStyle($this->_filesDirectory . $stylefile->getFilename());
252:                 }
253:             }
254:         }
255: 
256:         if (cFileHandler::exists($scriptDir . $pageName . '.js')) {
257:             $this->addScript($this->_filesDirectory . $pageName . '.js');
258:         }
259: 
260:         /* @var $scriptfile SplFileInfo */
261:         if(cFileHandler::exists($scriptDir)) {
262:             foreach (new DirectoryIterator($scriptDir) as $scriptfile) {
263:                 if (cString::endsWith($scriptfile->getFilename(), '.' . $pageName . '.js')) {
264:                     $this->addScript($this->_filesDirectory . $scriptfile->getFilename());
265:                 }
266:             }
267:         }
268:     }
269: 
270:     /**
271:      * Adds a script to the website - path can be absolute, relative to
272:      * the plugin scripts folder and relative to the CONTENIDO scripts
273:      * folder.
274:      *
275:      * NOTE: This function will also add inline JavaScript in the form
276:      * of "<script...". However this shouldn't be used.
277:      *
278:      * If the page was constructed in a plugin and the plugin name was
279:      * given in the constructor it will find the JS script in
280:      * plugins/PLUGINNAME/scripts/ too.
281:      *
282:      * @param string $script
283:      *         The filename of the script. It has to reside in /scripts/
284:      *         in order to be found.
285:      */
286:     public function addScript($script) {
287:         global $perm, $currentuser;
288: 
289:         $script = trim($script);
290:         if (empty($script)) {
291:             return;
292:         }
293: 
294:         $cfg = cRegistry::getConfig();
295:         $backendUrl = cRegistry::getBackendUrl();
296:         $backendPath = cRegistry::getBackendPath();
297:         $filePathName = $this->_getRealFilePathName($script);
298: 
299:         // Warning message for not existing resources
300:         if($perm->isSysadmin($currentuser) && strpos(trim($script), '<script') === false &&
301:            ((!empty($this->_pluginName) && !cFileHandler::exists($backendPath . $cfg['path']['plugins'] . $this->_pluginName . '/' . $cfg['path']['scripts'] . $script)) &&
302:            (!cFileHandler::exists($backendPath . $cfg['path']['scripts'] . $filePathName)))) {
303:             $this->displayWarning(i18n("The requested resource") . " <strong>" . $filePathName . "</strong> " . i18n("was not found"));
304:         }
305: 
306:         if (strpos(trim($script), 'http') === 0 || strpos(trim($script), '<script') === 0 || strpos(trim($script), '//') === 0) {
307:             // the given script path is absolute
308:             if(!in_array($script, $this->_scripts)) {
309:                 $this->_scripts[] = $script;
310:             }
311:         } else if (!empty($this->_pluginName) && cFileHandler::exists($backendPath . $cfg['path']['plugins'] . $this->_pluginName . '/' . $cfg['path']['scripts'] . $filePathName)) {
312:             // the given script path is relative to the plugin scripts folder
313:             $fullpath = $backendUrl . $cfg['path']['plugins'] . $this->_pluginName . '/' . $cfg['path']['scripts'] . $script;
314:             if(!in_array($fullpath, $this->_scripts)) {
315:                 $this->_scripts[] = $fullpath;
316:             }
317:         } else if (cFileHandler::exists($backendPath . $cfg['path']['scripts'] . $filePathName)) {
318:             // the given script path is relative to the CONTENIDO scripts folder
319:             $fullpath = $backendUrl . $cfg['path']['scripts'] . $script;
320: 
321:             if(!in_array($fullpath, $this->_scripts)) {
322:                 $this->_scripts[] = $fullpath;
323:             }
324:         }
325:     }
326: 
327:     /**
328:      * Adds a stylesheet to the website - path can be absolute, relative
329:      * to the plugin stylesheets folder and relative to the CONTENIDO
330:      * stylesheets folder.
331:      *
332:      * @param string $stylesheet
333:      *         The filename of the stylesheet. It has to reside in
334:      *         /styles/ in order to be found.
335:      */
336:     public function addStyle($stylesheet) {
337:         global $perm, $currentuser;
338: 
339:         $stylesheet = trim($stylesheet);
340:         if (empty($stylesheet)) {
341:             return;
342:         }
343: 
344:         $cfg = cRegistry::getConfig();
345:         $backendUrl = cRegistry::getBackendUrl();
346:         $backendPath = cRegistry::getBackendPath();
347:         $filePathName = $this->_getRealFilePathName($stylesheet);
348: 
349:         // Warning message for not existing resources
350:         if($perm->isSysadmin($currentuser) && ((!empty($this->_pluginName) && !cFileHandler::exists($backendPath . $cfg['path']['plugins'] . $this->_pluginName . '/' . $cfg['path']['styles'] . $stylesheet))) ||
351:            (empty($this->_pluginName) && !cFileHandler::exists($backendPath . $cfg['path']['styles'] . $filePathName))) {
352:             $this->displayWarning(i18n("The requested resource") . " <strong>" . $filePathName . "</strong> " . i18n("was not found"));
353:         }
354: 
355:         if (strpos($stylesheet, 'http') === 0 || strpos($stylesheet, '//') === 0) {
356:             // the given stylesheet path is absolute
357:             if(!in_array($stylesheet, $this->_styles)) {
358:                 $this->_styles[] = $stylesheet;
359:             }
360:         } else if (!empty($this->_pluginName) && cFileHandler::exists($backendPath . $cfg['path']['plugins'] . $this->_pluginName . '/' . $cfg['path']['styles'] . $filePathName)) {
361:             // the given stylesheet path is relative to the plugin stylesheets
362:             // folder
363:             $fullpath = $backendUrl . $cfg['path']['plugins'] . $this->_pluginName . '/' . $cfg['path']['styles'] . $stylesheet;
364:             if(!in_array($fullpath, $this->_styles)) {
365:                 $this->_styles[] = $fullpath;
366:             }
367:         } else if (cFileHandler::exists($backendPath . $cfg['path']['styles'] . $filePathName)) {
368:             // the given stylesheet path is relative to the CONTENIDO
369:             // stylesheets folder
370:             $fullpath = $backendUrl . $cfg['path']['styles'] . $stylesheet;
371:             if(!in_array($fullpath, $this->_styles)) {
372:                 $this->_styles[] = $fullpath;
373:             }
374:         }
375:     }
376: 
377:     /**
378:      * Adds a meta tag to the website.
379:      *
380:      * @param array $meta
381:      *         Associative array with the meta tag attributes
382:      * @throws cInvalidArgumentException
383:      *         if an invalid attribute for the meta tag has been given
384:      */
385:     public function addMeta(array $meta) {
386:         $allowedAttributes = array(
387:             'charset',
388:             'content',
389:             'http-equiv',
390:             'name',
391:             'itemprop'
392:         );
393:         foreach ($meta as $key => $value) {
394:             if (!in_array($key, $allowedAttributes)) {
395:                 throw new cInvalidArgumentException('Unallowed attribute for meta tag given - meta tag will be ignored!');
396:             }
397:         }
398:         $this->_metaTags[] = $meta;
399:     }
400: 
401:     /**
402:      * Adds class attribute value to the body tag.
403:      *
404:      * @param string $className
405:      */
406:     public function addBodyClassName($className) {
407:         if (!in_array($className, $this->_bodyClassNames)) {
408:             $this->_bodyClassNames[] = $className;
409:         }
410:     }
411: 
412:     /**
413:      * Loads the subnavigation of the current area upon rendering.
414:      *
415:      * @param string $additional [optional]
416:      *         Additional parameters the subnavigation might need.
417:      *         These have to look like "key=value&key2=value2..."
418:      * @param string $aarea [optional]
419:      *         The area of the subnavigation.
420:      *         If none is given the current area will be loaded.
421:      */
422:     public function setSubnav($additional = '', $aarea = '') {
423:         global $area, $sess;
424: 
425:         if ($aarea == '') {
426:             $aarea = $area;
427:         }
428: 
429:         $this->_subnav = '
430:         <script type="text/javascript">
431:         Con.getFrame("right_top").location.href = "' . $sess->url("main.php?area={$aarea}&frame=3&{$additional}") . '";
432:         </script>
433:         ';
434:     }
435: 
436:     /**
437:      * Adds the reload script for the left_bottom frame to the website.
438:      */
439:     public function setReload() {
440:         $this->_scripts[] = 'reload.js';
441:     }
442: 
443:     /**
444:      * Adds JavaScript to the page to reload a certain frame.
445:      *
446:      * @param string $frameName
447:      *         Name of the frame
448:      * @param string|array $updatedParameters [optional]
449:      *         Either an array with keys that will be passed to
450:      *         Con.UtilUrl.replaceParams OR a string containing
451:      *         the new href of the frame.
452:      */
453:     public function reloadFrame($frameName, $updatedParameters = null) {
454:         if(is_array($updatedParameters)) {
455:             $updateString = '';
456:             foreach($updatedParameters as $key => $value) {
457:                 $updateString .= $key . ': "' . $value . '"';
458:             }
459:             $this->_scripts[] = '<script type="text/javascript">
460:                                     (function(Con, $) {
461:                                         var frame = Con.getFrame(\'' . $frameName . '\');
462:                                         if (frame) {
463:                                             frame.location.href = Con.UtilUrl.replaceParams(frame.location.href, {' . $updateString . '});
464:                                         }
465:                                     })(Con, Con.$);
466:                                 </script>';
467:         } else {
468:             $this->_scripts[] = '<script type="text/javascript">
469:             (function(Con, $) {
470:                 var frame = Con.getFrame("' . $frameName . '");
471:                 if (frame) {
472:                     frame.location.href = "' . $updatedParameters .'";
473:                 }
474:             })(Con, Con.$);
475:             </script>';
476:         }
477:     }
478: 
479:     /**
480:      * Sets the markscript.
481:      *
482:      * @param string $item
483:      *         The number of the submenu which should be marked.
484:      */
485:     public function setMarkScript($item) {
486:         $this->_markScript = markSubMenuItem($item, true);
487:     }
488: 
489:     /**
490:      * Sets the encoding of the website.
491:      *
492:      * @param string $encoding
493:      *         An encoding which should be valid to use in the meta tag
494:      */
495:     public function setEncoding($encoding) {
496:         if (empty($encoding)) {
497:             return;
498:         }
499:         $this->_metaTags[] = array(
500:             'http-equiv' => 'Content-type',
501:             'content' => 'text/html;charset=' . $encoding
502:         );
503:     }
504: 
505:     /**
506:      * Applies a value to a key in the content template.
507:      *
508:      * @see cTemplate::set()
509:      * @param string $type
510:      *         Either "s" or "d" for "static" or "dynamic" values
511:      * @param string $key
512:      *         The key which should be replaced
513:      * @param string $value
514:      *         The value which should replace the key
515:      */
516:     public function set($type, $key, $value) {
517:         $this->_contentTemplate->set($type, $key, $value);
518:     }
519: 
520:     /**
521:      * Function to specify the file used to generate the page template.
522:      *
523:      * @param string $filename [optional]
524:      *         the page base file
525:      */
526:     public function setPageBase($filename = '') {
527:         if ('' === $filename) {
528:             $cfg = cRegistry::getConfig();
529:             $this->_pageBase = $cfg['path']['templates'] . $cfg['templates']['generic_page'];
530:         } else {
531:             $this->_pageBase = $filename;
532:         }
533:     }
534: 
535:     /**
536:      * Calls the next() method on the content template.
537:      *
538:      * @see cTemplate::next()
539:      */
540:     public function next() {
541:         $this->_contentTemplate->next();
542:     }
543: 
544:     /**
545:      * After calling this the page will only display messages and not
546:      * render the content template.
547:      *
548:      * NOTE: You still have to call render() to actually show any messages.
549:      */
550:     public function abortRendering() {
551:         $this->_abort = true;
552:     }
553: 
554:     /**
555:      * Displays an error message and aborts rendering after that.
556:      *
557:      * NOTE: You still have to call render() to actually show any messages.
558:      *
559:      * @param string $msg
560:      *         A message
561:      */
562:     public function displayCriticalError($msg) {
563:         $this->_error = $msg;
564:         $this->_abort = true;
565:     }
566: 
567:     /**
568:      * Displays an error but the rendering of the content template will
569:      * continue.
570:      *
571:      * @param string $msg
572:      *         A message
573:      */
574:     public function displayError($msg) {
575:         $this->_error .= $msg . '<br>';
576:     }
577: 
578:     /**
579:      * Displays a warning.
580:      *
581:      * @param string $msg
582:      *         The warning
583:      */
584:     public function displayWarning($msg) {
585:         $this->_warning .= $msg . '<br>';
586:     }
587: 
588:     /**
589:      * Displays an info.
590:      *
591:      * @param string $msg
592:      *         The info message
593:      */
594:     public function displayInfo($msg) {
595:         $this->_info .= $msg . '<br>';
596:     }
597: 
598:     /**
599:      * Display a ok.
600:      *
601:      * @param string $msg
602:      *         The ok message
603:      */
604:     public function displayOk($msg) {
605:         $this->_ok .= $msg . '<br>';
606:     }
607: 
608:     /**
609:      * Sets an array (or a single object) of cHTML objects which build up the
610:      * site instead of a content template.
611:      *
612:      * NOTE: All these objects must have a render() method or else they
613:      * won't be shown.
614:      *
615:      * @param array|object $objects
616:      *         An array of objects
617:      */
618:     public function setContent($objects) {
619:         if (!is_array($objects)) {
620:             $objects = array(
621:                 $objects
622:             );
623:         }
624:         $this->_objects = $objects;
625:     }
626: 
627:     /**
628:      * Appends all cHTML objects in an array (or a single object) which
629:      * build up the site instead of a content template.
630:      *
631:      * NOTE: All these objects must have a render() method or else they
632:      * won't be shown.
633:      *
634:      * @param array|object $objects
635:      *         An array of objects or a single object
636:      */
637:     public function appendContent($objects) {
638:         if (!is_array($objects)) {
639:             $this->_objects[] = $objects;
640:         } else {
641:             $this->_objects = array_merge($this->_objects, $objects);
642:         }
643:     }
644: 
645:     /**
646:      * Renders the page and either prints it or returns it.
647:      *
648:      * @param cTemplate|NULL $template [optional]
649:      *         If set, use this content template instead of the default one
650:      * @param bool $return [optional]
651:      *         If true, the page will be returned instead of echoed
652:      * @return string|void
653:      */
654:     public function render($template = NULL, $return = false) {
655: 
656:         if ($template == NULL) {
657:             $template = $this->_contentTemplate;
658:         }
659: 
660:         // Render some parts like meta tags, scripts, styles, etc...
661:         $this->_renderMetaTags();
662:         $this->_renderScripts();
663:         $this->_renderStyles();
664: 
665:         // Set body class attribute values
666:         $this->_pageTemplate->set('s', 'PAGECLASS', implode(' ', $this->_bodyClassNames));
667: 
668:         // Get all messages for the content
669:         $text = $this->_renderContentMessages();
670:         if (strlen(trim($text)) > 0) {
671:             $this->_skipTemplateCheck = true;
672:         }
673: 
674:         if (!$this->_abort) {
675:             if (count($this->_objects) == 0) {
676:                 $output = $this->_renderTemplate($template);
677:             } else {
678:                 $output = $this->_renderObjects();
679:             }
680:             $this->_pageTemplate->set('s', 'CONTENT', $text . $output);
681:         } else {
682:             $this->_pageTemplate->set('s', 'CONTENT', $text);
683:         }
684: 
685:         return $this->_pageTemplate->generate($this->_pageBase, $return);
686:     }
687: 
688:     /**
689:      * Renders set meta tags and adds them to _pageTemplate property.
690:      */
691:     protected function _renderMetaTags() {
692:         // render the meta tags
693:         // NB! We don't produce xhtml in the backend
694:         // $produceXhtml = getEffectiveSetting('generator', 'xhtml', 'false');
695:         $produceXhtml = false;
696:         $meta = '';
697:         foreach ($this->_metaTags as $metaTag) {
698:             $tag = '<meta';
699:             foreach ($metaTag as $key => $value) {
700:                 $tag .= ' ' . $key . '="' . $value . '"';
701:             }
702:             if ($produceXhtml) {
703:                 $tag .= ' /';
704:             }
705:             $tag .= ">\n";
706:             $meta .= $tag;
707:         }
708:         if (!empty($meta)) {
709:             $this->_pageTemplate->set('s', 'META', $meta);
710:         } else {
711:             $this->_pageTemplate->set('s', 'META', '');
712:         }
713:     }
714: 
715:     /**
716:      * Renders set scripts and adds them to _pageTemplate property.
717:      */
718:     protected function _renderScripts() {
719:         $strscript = $this->_subnav . "\n" . $this->_markScript . "\n";
720:         foreach ($this->_scripts as $script) {
721:             if (strpos($script, 'http') === 0 || strpos($script, '//') === 0) {
722:                 $strscript .= '<script type="text/javascript" src="' . $script . '"></script>' . "\n";
723:             } else if (strpos($script, '<script') === false) {
724:                 $strscript .= '<script type="text/javascript" src="scripts/' . $script . '"></script>' . "\n";
725:             } else {
726:                 $strscript .= $script;
727:             }
728:         }
729:         $this->_pageTemplate->set('s', 'SCRIPTS', $strscript);
730:     }
731: 
732:     /**
733:      * Renders set styles and adds them to _pageTemplate property.
734:      */
735:     protected function _renderStyles() {
736:         $strstyle = '';
737:         foreach ($this->_styles as $style) {
738:             if (strpos($style, 'http') === 0 || strpos($style, '//') === 0) {
739:                 $strstyle .= '<link href="' . $style . '" type="text/css" rel="stylesheet">' . "\n";
740:             } else {
741:                 $strstyle .= '<link href="styles/' . $style . '" type="text/css" rel="stylesheet">' . "\n";
742:             }
743:         }
744:         $this->_pageTemplate->set('s', 'STYLES', $strstyle);
745:     }
746: 
747:     /**
748:      * Renders text for all available content messages and returns the
749:      * assembled message string.
750:      *
751:      * @return string
752:      */
753:     protected function _renderContentMessages() {
754:         global $notification;
755: 
756:         // Get messages from cRegistry
757:         $okMessages = cRegistry::getOkMessages();
758:         foreach ($okMessages as $message) {
759:             $this->displayOk($message);
760:         }
761: 
762:         $infoMessages = cRegistry::getInfoMessages();
763:         foreach ($infoMessages as $message) {
764:             $this->displayInfo($message);
765:         }
766: 
767:         $errorMessages = cRegistry::getErrorMessages();
768:         foreach ($errorMessages as $message) {
769:             $this->displayError($message);
770:         }
771: 
772:         $warningMessages = cRegistry::getWarningMessages();
773:         foreach ($warningMessages as $message) {
774:             $this->displayWarning($message);
775:         }
776: 
777:         $text = '';
778:         if ($this->_ok != '') {
779:             $text .= $notification->returnNotification('ok', $this->_ok) . '<br>';
780:         }
781:         if ($this->_info != '') {
782:             $text .= $notification->returnNotification('info', $this->_info) . '<br>';
783:         }
784:         if ($this->_warning != '') {
785:             $text .= $notification->returnNotification('warning', $this->_warning) . '<br>';
786:         }
787:         if ($this->_error != '') {
788:             $text .= $notification->returnNotification('error', $this->_error) . '<br>';
789:         }
790: 
791:         return $text;
792:     }
793: 
794:     /**
795:      * Loops through all defined objects, calls their render function,
796:      * collects the output of the objects and returns it back.
797:      *
798:      * @return string
799:      */
800:     protected function _renderObjects() {
801:         $output = '';
802: 
803:         foreach ($this->_objects as $obj) {
804:             if (is_string($obj)) {
805:                 $output .= $obj;
806:             }
807: 
808:             if (!method_exists($obj, 'render')) {
809:                 continue;
810:             }
811: 
812:             // Ridiculous workaround because some objects return
813:             // code if the parameter is true and some return the
814:             // code if the parameter is false.
815:             $oldOutput = $output;
816: 
817:             // We don't want any code outside the body (in case the
818:             // object outputs directly we will catch this output).
819:             ob_start();
820:             $output .= $obj->render(false);
821: 
822:             // We get the code either directly or via the output
823:             $output .= ob_get_contents();
824:             if ($oldOutput == $output) {
825:                 cWarning(__FILE__, __LINE__, "Rendering this object (" . print_r($obj, true) . ") doesn't seem to have any effect.");
826:             }
827:             ob_end_clean();
828:         }
829: 
830:         return $output;
831:     }
832: 
833:     /**
834:      * Renders template of a page or of a plugin and returns the output back.
835:      *
836:      * @param cTemplate $template
837:      * @return string
838:      */
839:     protected function _renderTemplate($template) {
840:         global $perm, $currentuser, $notification;
841: 
842:         $cfg = cRegistry::getConfig();
843: 
844:         $file = '';
845:         if ($this->_pluginName == '') {
846:             $file = $cfg['path']['templates'] . 'template.' . $this->_pageName . '.html';
847:         } else {
848:             $file = $cfg['path']['plugins'] . $this->_pluginName . '/templates/template.' . $this->_pageName . '.html';
849:         }
850: 
851:         $output = '';
852:         // Warning message for not existing resources
853:         if (!$this->_skipTemplateCheck && $perm->isSysadmin($currentuser) && !cFileHandler::exists($file)) {
854:             $output .= $notification->returnNotification('warning', i18n("The requested resource") . " <strong>template." . $this->_pageName . ".html</strong> " . i18n("was not found")) . '<br>';
855:         }
856: 
857:         if (cFileHandler::exists($file)) {
858:             $output .= $template->generate($file, true);
859:         } else {
860:             $output .= '';
861:         }
862: 
863:         return $output;
864:     }
865: 
866:     /**
867:      * Returns only the path and name of the given file.
868:      *
869:      * Some JS or CSS file URLs may contain a query part, like
870:      * "/path/to/file.js.php?contenido=12234" and this function returns
871:      * only the path part "/path/to/file.js.php" of it.
872:      *
873:      * @param string $file
874:      * @return string
875:      */
876:     protected function _getRealFilePathName($file) {
877:         $tmp = explode('?', $file);
878:         return $tmp[0];
879:     }
880: 
881: }
882: 
CMS CONTENIDO 4.9.11 API documentation generated by ApiGen 2.8.0