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
  • Smarty
    • Cacher
    • Compiler
    • Config
    • Debug
    • PluginsBlock
    • PluginsFilter
    • PluginsFunction
    • PluginsInternal
    • PluginsModifier
    • PluginsModifierCompiler
    • PluginsShared
    • Security
    • Template
    • TemplateResources
  • Swift
    • ByteStream
    • CharacterStream
    • Encoder
    • Events
    • KeyCache
    • Mailer
    • Mime
    • Plugins
    • Transport

Classes

  • Swift_FailoverTransport
  • Swift_LoadBalancedTransport
  • Swift_MailTransport
  • Swift_Plugins_Loggers_ArrayLogger
  • Swift_Plugins_Loggers_EchoLogger
  • Swift_SendmailTransport
  • Swift_SmtpTransport
  • Swift_Transport_AbstractSmtpTransport
  • Swift_Transport_Esmtp_Auth_CramMd5Authenticator
  • Swift_Transport_Esmtp_Auth_LoginAuthenticator
  • Swift_Transport_Esmtp_Auth_PlainAuthenticator
  • Swift_Transport_Esmtp_AuthHandler
  • Swift_Transport_EsmtpTransport
  • Swift_Transport_FailoverTransport
  • Swift_Transport_LoadBalancedTransport
  • Swift_Transport_MailTransport
  • Swift_Transport_SendmailTransport
  • Swift_Transport_SimpleMailInvoker
  • Swift_Transport_StreamBuffer

Interfaces

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