Overview

Packages

  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Datatype
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
  • 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

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