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
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • PHP
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • 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) && cString::findFirstPos(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 (cString::findFirstPos(trim($script), 'http') === 0 || cString::findFirstPos(trim($script), '<script') === 0 || cString::findFirstPos(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 (cString::findFirstPos($stylesheet, 'http') === 0 || cString::findFirstPos($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:      *
653:      * @return string|void
654:      * @throws cInvalidArgumentException
655:      */
656:     public function render($template = NULL, $return = false) {
657: 
658:         if ($template == NULL) {
659:             $template = $this->_contentTemplate;
660:         }
661: 
662:         // Render some parts like meta tags, scripts, styles, etc...
663:         $this->_renderMetaTags();
664:         $this->_renderScripts();
665:         $this->_renderStyles();
666: 
667:         // Set body class attribute values
668:         $this->_pageTemplate->set('s', 'PAGECLASS', implode(' ', $this->_bodyClassNames));
669: 
670:         // Get all messages for the content
671:         $text = $this->_renderContentMessages();
672:         if (cString::getStringLength(trim($text)) > 0) {
673:             $this->_skipTemplateCheck = true;
674:         }
675: 
676:         if (!$this->_abort) {
677:             if (count($this->_objects) == 0) {
678:                 $output = $this->_renderTemplate($template);
679:             } else {
680:                 $output = $this->_renderObjects();
681:             }
682:             $this->_pageTemplate->set('s', 'CONTENT', $text . $output);
683:         } else {
684:             $this->_pageTemplate->set('s', 'CONTENT', $text);
685:         }
686: 
687:         return $this->_pageTemplate->generate($this->_pageBase, $return);
688:     }
689: 
690:     /**
691:      * Renders set meta tags and adds them to _pageTemplate property.
692:      */
693:     protected function _renderMetaTags() {
694:         // render the meta tags
695:         // NB! We don't produce xhtml in the backend
696:         // $produceXhtml = getEffectiveSetting('generator', 'xhtml', 'false');
697:         $produceXhtml = false;
698:         $meta = '';
699:         foreach ($this->_metaTags as $metaTag) {
700:             $tag = '<meta';
701:             foreach ($metaTag as $key => $value) {
702:                 $tag .= ' ' . $key . '="' . $value . '"';
703:             }
704:             if ($produceXhtml) {
705:                 $tag .= ' /';
706:             }
707:             $tag .= ">\n";
708:             $meta .= $tag;
709:         }
710:         if (!empty($meta)) {
711:             $this->_pageTemplate->set('s', 'META', $meta);
712:         } else {
713:             $this->_pageTemplate->set('s', 'META', '');
714:         }
715:     }
716: 
717:     /**
718:      * Renders set scripts and adds them to _pageTemplate property.
719:      */
720:     protected function _renderScripts() {
721:         $strscript = $this->_subnav . "\n" . $this->_markScript . "\n";
722:         foreach ($this->_scripts as $script) {
723:             if (cString::findFirstPos($script, 'http') === 0 || cString::findFirstPos($script, '//') === 0) {
724:                 $strscript .= '<script type="text/javascript" src="' . $script . '"></script>' . "\n";
725:             } else if (cString::findFirstPos($script, '<script') === false) {
726:                 $strscript .= '<script type="text/javascript" src="scripts/' . $script . '"></script>' . "\n";
727:             } else {
728:                 $strscript .= $script;
729:             }
730:         }
731:         $this->_pageTemplate->set('s', 'SCRIPTS', $strscript);
732:     }
733: 
734:     /**
735:      * Renders set styles and adds them to _pageTemplate property.
736:      */
737:     protected function _renderStyles() {
738:         $strstyle = '';
739:         foreach ($this->_styles as $style) {
740:             if (cString::findFirstPos($style, 'http') === 0 || cString::findFirstPos($style, '//') === 0) {
741:                 $strstyle .= '<link href="' . $style . '" type="text/css" rel="stylesheet">' . "\n";
742:             } else {
743:                 $strstyle .= '<link href="styles/' . $style . '" type="text/css" rel="stylesheet">' . "\n";
744:             }
745:         }
746:         $this->_pageTemplate->set('s', 'STYLES', $strstyle);
747:     }
748: 
749:     /**
750:      * Renders text for all available content messages and returns the
751:      * assembled message string.
752:      *
753:      * @return string
754:      */
755:     protected function _renderContentMessages() {
756:         global $notification;
757: 
758:         // Get messages from cRegistry
759:         $okMessages = cRegistry::getOkMessages();
760:         foreach ($okMessages as $message) {
761:             $this->displayOk($message);
762:         }
763: 
764:         $infoMessages = cRegistry::getInfoMessages();
765:         foreach ($infoMessages as $message) {
766:             $this->displayInfo($message);
767:         }
768: 
769:         $errorMessages = cRegistry::getErrorMessages();
770:         foreach ($errorMessages as $message) {
771:             $this->displayError($message);
772:         }
773: 
774:         $warningMessages = cRegistry::getWarningMessages();
775:         foreach ($warningMessages as $message) {
776:             $this->displayWarning($message);
777:         }
778: 
779:         $text = '';
780:         if ($this->_ok != '') {
781:             $text .= $notification->returnNotification('ok', $this->_ok) . '<br>';
782:         }
783:         if ($this->_info != '') {
784:             $text .= $notification->returnNotification('info', $this->_info) . '<br>';
785:         }
786:         if ($this->_warning != '') {
787:             $text .= $notification->returnNotification('warning', $this->_warning) . '<br>';
788:         }
789:         if ($this->_error != '') {
790:             $text .= $notification->returnNotification('error', $this->_error) . '<br>';
791:         }
792: 
793:         return $text;
794:     }
795: 
796:     /**
797:      * Loops through all defined objects, calls their render function,
798:      * collects the output of the objects and returns it back.
799:      *
800:      * @return string
801:      */
802:     protected function _renderObjects() {
803:         $output = '';
804: 
805:         foreach ($this->_objects as $obj) {
806:             if (is_string($obj)) {
807:                 $output .= $obj;
808:             }
809: 
810:             if (!method_exists($obj, 'render')) {
811:                 continue;
812:             }
813: 
814:             // Ridiculous workaround because some objects return
815:             // code if the parameter is true and some return the
816:             // code if the parameter is false.
817:             $oldOutput = $output;
818: 
819:             // We don't want any code outside the body (in case the
820:             // object outputs directly we will catch this output).
821:             ob_start();
822:             $output .= $obj->render(false);
823: 
824:             // We get the code either directly or via the output
825:             $output .= ob_get_contents();
826:             if ($oldOutput == $output) {
827:                 cWarning(__FILE__, __LINE__, "Rendering this object (" . print_r($obj, true) . ") doesn't seem to have any effect.");
828:             }
829:             ob_end_clean();
830:         }
831: 
832:         return $output;
833:     }
834: 
835:     /**
836:      * Renders template of a page or of a plugin and returns the output back.
837:      *
838:      * @param cTemplate $template
839:      * @return string
840:      * @throws cInvalidArgumentException
841:      */
842:     protected function _renderTemplate($template) {
843:         global $perm, $currentuser, $notification;
844: 
845:         $cfg = cRegistry::getConfig();
846: 
847:         $file = '';
848:         if ($this->_pluginName == '') {
849:             $file = $cfg['path']['templates'] . 'template.' . $this->_pageName . '.html';
850:         } else {
851:             $file = $cfg['path']['plugins'] . $this->_pluginName . '/templates/template.' . $this->_pageName . '.html';
852:         }
853: 
854:         $output = '';
855:         // Warning message for not existing resources
856:         if (!$this->_skipTemplateCheck && $perm->isSysadmin($currentuser) && !cFileHandler::exists($file)) {
857:             $output .= $notification->returnNotification('warning', i18n("The requested resource") . " <strong>template." . $this->_pageName . ".html</strong> " . i18n("was not found")) . '<br>';
858:         }
859: 
860:         if (cFileHandler::exists($file)) {
861:             $output .= $template->generate($file, true);
862:         } else {
863:             $output .= '';
864:         }
865: 
866:         return $output;
867:     }
868: 
869:     /**
870:      * Returns only the path and name of the given file.
871:      *
872:      * Some JS or CSS file URLs may contain a query part, like
873:      * "/path/to/file.js.php?contenido=12234" and this function returns
874:      * only the path part "/path/to/file.js.php" of it.
875:      *
876:      * @param string $file
877:      * @return string
878:      */
879:     protected function _getRealFilePathName($file) {
880:         $tmp = explode('?', $file);
881:         return $tmp[0];
882:     }
883: 
884: }
885: 
CMS CONTENIDO 4.10.0 API documentation generated by ApiGen 2.8.0