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