[TASK] Clean up phpDoc comments in t3lib classes
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_pagerenderer.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009-2011 Steffen Kamper <info@sk-typo3.de>
6 * (c) 2011 Kai Vogel <kai.vogel@speedprogs.de>
7 * All rights reserved
8 *
9 * This script is part of the TYPO3 project. The TYPO3 project is
10 * free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * The GNU General Public License can be found at
16 * http://www.gnu.org/copyleft/gpl.html.
17 * A copy is found in the textfile GPL.txt and important notices to the license
18 * from the author is found in LICENSE.txt distributed with these scripts.
19 *
20 *
21 * This script is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * This copyright notice MUST APPEAR in all copies of the script!
27 ***************************************************************/
28
29 /**
30 * TYPO3 pageRender class (new in TYPO3 4.3.0)
31 * This class render the HTML of a webpage, usable for BE and FE
32 *
33 * @author Steffen Kamper <info@sk-typo3.de>
34 * @author Kai Vogel <kai.vogel@speedprogs.de>
35 * @package TYPO3
36 * @subpackage t3lib
37 */
38 class t3lib_PageRenderer implements t3lib_Singleton {
39
40 protected $compressJavascript = FALSE;
41 protected $compressCss = FALSE;
42 protected $removeLineBreaksFromTemplate = FALSE;
43
44 protected $concatenateFiles = FALSE;
45 protected $concatenateJavascript = FALSE;
46 protected $concatenateCss = FALSE;
47
48 protected $moveJsFromHeaderToFooter = FALSE;
49
50 /** @var t3lib_cs $csConvObj */
51 protected $csConvObj;
52 /** @var t3lib_l10n_Locales */
53 protected $locales;
54 protected $lang;
55
56 /** @var t3lib_Compressor $compressor */
57 protected $compressor;
58
59 // Arrays containing associative array for the included files
60 protected $jsFiles = array();
61 protected $jsFooterFiles = array();
62 protected $jsLibs = array();
63 protected $jsFooterLibs = array();
64 protected $cssFiles = array();
65
66 protected $title;
67 protected $charSet;
68 protected $favIcon;
69 protected $baseUrl;
70
71 protected $renderXhtml = TRUE;
72
73 // Static header blocks
74 protected $xmlPrologAndDocType = '';
75 protected $metaTags = array();
76 protected $inlineComments = array();
77 protected $headerData = array();
78 protected $footerData = array();
79 protected $titleTag = '<title>|</title>';
80 protected $metaCharsetTag = '<meta http-equiv="Content-Type" content="text/html; charset=|" />';
81 protected $htmlTag = '<html>';
82 protected $headTag = '<head>';
83 protected $baseUrlTag = '<base href="|" />';
84 protected $iconMimeType = '';
85 protected $shortcutTag = '<link rel="shortcut icon" href="%1$s"%2$s />
86 <link rel="icon" href="%1$s"%2$s />';
87
88 // Static inline code blocks
89 protected $jsInline = array();
90 protected $jsFooterInline = array();
91 protected $extOnReadyCode = array();
92 protected $cssInline = array();
93
94 protected $bodyContent;
95
96 protected $templateFile;
97
98 protected $jsLibraryNames = array('prototype', 'scriptaculous', 'extjs');
99
100 const PART_COMPLETE = 0;
101 const PART_HEADER = 1;
102 const PART_FOOTER = 2;
103
104 // Paths to contibuted libraries
105 protected $prototypePath = 'contrib/prototype/';
106 protected $scriptaculousPath = 'contrib/scriptaculous/';
107 protected $extCorePath = 'contrib/extjs/';
108 protected $extJsPath = 'contrib/extjs/';
109 protected $svgPath = 'contrib/websvg/';
110
111
112 // Internal flags for JS-libraries
113 protected $addPrototype = FALSE;
114 protected $addScriptaculous = FALSE;
115 protected $addScriptaculousModules = array('builder' => FALSE, 'effects' => FALSE, 'dragdrop' => FALSE, 'controls' => FALSE, 'slider' => FALSE);
116 protected $addExtJS = FALSE;
117 protected $addExtCore = FALSE;
118 protected $extJSadapter = 'ext/ext-base.js';
119 protected $extDirectCodeAdded = FALSE;
120
121 protected $enableExtJsDebug = FALSE;
122 protected $enableExtCoreDebug = FALSE;
123
124 // Available adapters for extJs
125 const EXTJS_ADAPTER_JQUERY = 'jquery';
126 const EXTJS_ADAPTER_PROTOTYPE = 'prototype';
127 const EXTJS_ADAPTER_YUI = 'yui';
128
129 protected $extJStheme = TRUE;
130 protected $extJScss = TRUE;
131
132 protected $enableExtJSQuickTips = FALSE;
133
134 protected $inlineLanguageLabels = array();
135 protected $inlineLanguageLabelFiles = array();
136 protected $inlineSettings = array();
137
138 protected $inlineJavascriptWrap = array();
139
140 // Saves error messages generated during compression
141 protected $compressError = '';
142
143 // SVG library
144 protected $addSvg = FALSE;
145 protected $enableSvgDebug = FALSE;
146
147 // Used by BE modules
148 public $backPath;
149
150 /**
151 * Constructor
152 *
153 * @param string $templateFile Declare the used template file. Omit this parameter will use default template
154 * @param string $backPath Relative path to typo3-folder. It varies for BE modules, in FE it will be typo3/
155 */
156 public function __construct($templateFile = '', $backPath = NULL) {
157
158 $this->reset();
159 $this->csConvObj = t3lib_div::makeInstance('t3lib_cs');
160 $this->locales = t3lib_div::makeInstance('t3lib_l10n_Locales');
161
162 if (strlen($templateFile)) {
163 $this->templateFile = $templateFile;
164 }
165 $this->backPath = isset($backPath) ? $backPath : $GLOBALS['BACK_PATH'];
166
167 $this->inlineJavascriptWrap = array(
168 '<script type="text/javascript">' . LF . '/*<![CDATA[*/' . LF . '<!-- ' . LF,
169 '// -->' . LF . '/*]]>*/' . LF . '</script>' . LF
170 );
171 $this->inlineCssWrap = array(
172 '<style type="text/css">' . LF . '/*<![CDATA[*/' . LF . '<!-- ' . LF,
173 '-->' . LF . '/*]]>*/' . LF . '</style>' . LF
174 );
175 }
176
177 /**
178 * reset all vars to initial values
179 *
180 * @return void
181 */
182 protected function reset() {
183 $this->templateFile = TYPO3_mainDir . 'templates/template_page_backend.html';
184 $this->jsFiles = array();
185 $this->jsFooterFiles = array();
186 $this->jsInline = array();
187 $this->jsFooterInline = array();
188 $this->jsLibs = array();
189 $this->cssFiles = array();
190 $this->cssInline = array();
191 $this->metaTags = array();
192 $this->inlineComments = array();
193 $this->headerData = array();
194 $this->footerData = array();
195 $this->extOnReadyCode = array();
196 }
197
198 /*****************************************************/
199 /* */
200 /* Public Setters */
201 /* */
202 /* */
203 /*****************************************************/
204
205 /**
206 * Sets the title
207 *
208 * @param string $title title of webpage
209 * @return void
210 */
211 public function setTitle($title) {
212 $this->title = $title;
213 }
214
215 /**
216 * Enables/disables rendering of XHTML code
217 *
218 * @param boolean $enable Enable XHTML
219 * @return void
220 */
221 public function setRenderXhtml($enable) {
222 $this->renderXhtml = $enable;
223 }
224
225 /**
226 * Sets xml prolog and docType
227 *
228 * @param string $xmlPrologAndDocType Complete tags for xml prolog and docType
229 * @return void
230 */
231 public function setXmlPrologAndDocType($xmlPrologAndDocType) {
232 $this->xmlPrologAndDocType = $xmlPrologAndDocType;
233 }
234
235 /**
236 * Sets meta charset
237 *
238 * @param string $charSet Used charset
239 * @return void
240 */
241 public function setCharSet($charSet) {
242 $this->charSet = $charSet;
243 }
244
245 /**
246 * Sets language
247 *
248 * @param string $lang Used language
249 * @return void
250 */
251 public function setLanguage($lang) {
252 $this->lang = $lang;
253 }
254
255 /**
256 * Set the meta charset tag
257 *
258 * @param string $metaCharsetTag
259 * @return void
260 */
261 public function setMetaCharsetTag($metaCharsetTag) {
262 $this->metaCharsetTag = $metaCharsetTag;
263 }
264
265 /**
266 * Sets html tag
267 *
268 * @param string $htmlTag Html tag
269 * @return void
270 */
271 public function setHtmlTag($htmlTag) {
272 $this->htmlTag = $htmlTag;
273 }
274
275 /**
276 * Sets HTML head tag
277 *
278 * @param string $headTag HTML head tag
279 * @return void
280 */
281 public function setHeadTag($headTag) {
282 $this->headTag = $headTag;
283 }
284
285 /**
286 * Sets favicon
287 *
288 * @param string $favIcon
289 * @return void
290 */
291 public function setFavIcon($favIcon) {
292 $this->favIcon = $favIcon;
293 }
294
295 /**
296 * Sets icon mime type
297 *
298 * @param string $iconMimeType
299 * @return void
300 */
301 public function setIconMimeType($iconMimeType) {
302 $this->iconMimeType = $iconMimeType;
303 }
304
305 /**
306 * Sets HTML base URL
307 *
308 * @param string $baseUrl HTML base URL
309 * @return void
310 */
311 public function setBaseUrl($baseUrl) {
312 $this->baseUrl = $baseUrl;
313 }
314
315 /**
316 * Sets template file
317 *
318 * @param string $file
319 * @return void
320 */
321 public function setTemplateFile($file) {
322 $this->templateFile = $file;
323 }
324
325 /**
326 * Sets back path
327 *
328 * @param string $backPath
329 * @return void
330 */
331 public function setBackPath($backPath) {
332 $this->backPath = $backPath;
333 }
334
335 /**
336 * Sets Content for Body
337 *
338 * @param string $content
339 * @return void
340 */
341 public function setBodyContent($content) {
342 $this->bodyContent = $content;
343 }
344
345 /**
346 * Sets path to prototype library (relative to typo3 directory)
347 *
348 * @param string $path Path to prototype library
349 * @return void
350 */
351 public function setPrototypePath($path) {
352 $this->prototypePath = $path;
353 }
354
355 /**
356 * Sets Path for scriptaculous library (relative to typo3 directory)
357 *
358 * @param string $path
359 * @return void
360 */
361 public function setScriptaculousPath($path) {
362 $this->scriptaculousPath = $path;
363 }
364
365 /**
366 * Sets Path for Ext Core library (relative to typo3 directory)
367 *
368 * @param string $path
369 * @return void
370 */
371 public function setExtCorePath($path) {
372 $this->extCorePath = $path;
373 }
374
375 /**
376 * Sets Path for ExtJs library (relative to typo3 directory)
377 *
378 * @param string $path
379 * @return void
380 */
381 public function setExtJsPath($path) {
382 $this->extJsPath = $path;
383 }
384
385 /**
386 * Sets Path for SVG library (websvg)
387 *
388 * @param string $path
389 * @return void
390 */
391 public function setSvgPath($path) {
392 $this->svgPath = $path;
393 }
394
395 /*****************************************************/
396 /* */
397 /* Public Enablers / Disablers */
398 /* */
399 /* */
400 /*****************************************************/
401
402 /**
403 * Enables MoveJsFromHeaderToFooter
404 * @return void
405 */
406 public function enableMoveJsFromHeaderToFooter() {
407 $this->moveJsFromHeaderToFooter = TRUE;
408 }
409
410 /**
411 * Disables MoveJsFromHeaderToFooter
412 * @return void
413 */
414 public function disableMoveJsFromHeaderToFooter() {
415 $this->moveJsFromHeaderToFooter = FALSE;
416 }
417
418 /**
419 * Enables compression of javascript
420 * @return void
421 */
422 public function enableCompressJavascript() {
423 $this->compressJavascript = TRUE;
424 }
425
426 /**
427 * Disables compression of javascript
428 * @return void
429 */
430 public function disableCompressJavascript() {
431 $this->compressJavascript = FALSE;
432 }
433
434 /**
435 * Enables compression of css
436 * @return void
437 */
438 public function enableCompressCss() {
439 $this->compressCss = TRUE;
440 }
441
442 /**
443 * Disables compression of css
444 * @return void
445 */
446 public function disableCompressCss() {
447 $this->compressCss = FALSE;
448 }
449
450 /**
451 * Enables concatenation of js and css files
452 * @return void
453 */
454 public function enableConcatenateFiles() {
455 $this->concatenateFiles = TRUE;
456 }
457
458 /**
459 * Disables concatenation of js and css files
460 * @return void
461 */
462 public function disableConcatenateFiles() {
463 $this->concatenateFiles = FALSE;
464 }
465
466 /**
467 * Enables concatenation of js files
468 * @return void
469 */
470 public function enableConcatenateJavascript() {
471 $this->concatenateJavascript = TRUE;
472 }
473
474 /**
475 * Disables concatenation of js files
476 * @return void
477 */
478 public function disableConcatenateJavascript() {
479 $this->concatenateJavascript = FALSE;
480 }
481
482 /**
483 * Enables concatenation of css files
484 * @return void
485 */
486 public function enableConcatenateCss() {
487 $this->concatenateCss = TRUE;
488 }
489
490 /**
491 * Disables concatenation of css files
492 * @return void
493 */
494 public function disableConcatenateCss() {
495 $this->concatenateCss = FALSE;
496 }
497
498 /**
499 * Sets removal of all line breaks in template
500 * @return void
501 */
502 public function enableRemoveLineBreaksFromTemplate() {
503 $this->removeLineBreaksFromTemplate = TRUE;
504 }
505
506 /**
507 * Unsets removal of all line breaks in template
508 * @return void
509 */
510 public function disableRemoveLineBreaksFromTemplate() {
511 $this->removeLineBreaksFromTemplate = FALSE;
512 }
513
514 /**
515 * Enables Debug Mode
516 * This is a shortcut to switch off all compress/concatenate features to enable easier debug
517 * @return void
518 */
519 public function enableDebugMode() {
520 $this->compressJavascript = FALSE;
521 $this->compressCss = FALSE;
522 $this->concatenateFiles = FALSE;
523 $this->removeLineBreaksFromTemplate = FALSE;
524 $this->enableExtCoreDebug = TRUE;
525 $this->enableExtJsDebug = TRUE;
526 $this->enableSvgDebug = TRUE;
527 }
528
529 /*****************************************************/
530 /* */
531 /* Public Getters */
532 /* */
533 /* */
534 /*****************************************************/
535
536 /**
537 * Gets the title
538 *
539 * @return string $title Title of webpage
540 */
541 public function getTitle() {
542 return $this->title;
543 }
544
545 /**
546 * Gets the charSet
547 *
548 * @return string $charSet
549 */
550 public function getCharSet() {
551 return $this->charSet;
552 }
553
554 /**
555 * Gets the language
556 *
557 * @return string $lang
558 */
559 public function getLanguage() {
560 return $this->lang;
561 }
562
563 /**
564 * Returns rendering mode XHTML or HTML
565 *
566 * @return boolean TRUE if XHTML, FALSE if HTML
567 */
568 public function getRenderXhtml() {
569 return $this->renderXhtml;
570 }
571
572 /**
573 * Gets html tag
574 *
575 * @return string $htmlTag Html tag
576 */
577 public function getHtmlTag() {
578 return $this->htmlTag;
579 }
580
581 /**
582 * Get meta charset
583 *
584 * @return string
585 */
586 public function getMetaCharsetTag() {
587 return $this->metaCharsetTag;
588 }
589
590 /**
591 * Gets head tag
592 *
593 * @return string $tag Head tag
594 */
595 public function getHeadTag() {
596 return $this->headTag;
597 }
598
599 /**
600 * Gets favicon
601 *
602 * @return string $favIcon
603 */
604 public function getFavIcon() {
605 return $this->favIcon;
606 }
607
608 /**
609 * Gets icon mime type
610 *
611 * @return string $iconMimeType
612 */
613 public function getIconMimeType() {
614 return $this->iconMimeType;
615 }
616
617 /**
618 * Gets HTML base URL
619 *
620 * @return string $url
621 */
622 public function getBaseUrl() {
623 return $this->baseUrl;
624 }
625
626 /**
627 * Gets template file
628 *
629 * @return string
630 */
631 public function getTemplateFile() {
632 return $this->templateFile;
633 }
634
635 /**
636 * Gets MoveJsFromHeaderToFooter
637 *
638 * @return boolean
639 */
640 public function getMoveJsFromHeaderToFooter() {
641 return $this->moveJsFromHeaderToFooter;
642 }
643
644 /**
645 * Gets compress of javascript
646 *
647 * @return boolean
648 */
649 public function getCompressJavascript() {
650 return $this->compressJavascript;
651 }
652
653 /**
654 * Gets compress of css
655 *
656 * @return boolean
657 */
658 public function getCompressCss() {
659 return $this->compressCss;
660 }
661
662 /**
663 * Gets concatenate of js and css files
664 *
665 * @return boolean
666 */
667 public function getConcatenateFiles() {
668 return $this->concatenateFiles;
669 }
670
671 /**
672 * Gets concatenate of js files
673 *
674 * @return boolean
675 */
676 public function getConcatenateJavascript() {
677 return $this->concatenateJavascript;
678 }
679
680 /**
681 * Gets concatenate of css files
682 *
683 * @return boolean
684 */
685 public function getConcatenateCss() {
686 return $this->concatenateCss;
687 }
688
689 /**
690 * Gets remove of empty lines from template
691 *
692 * @return boolean
693 */
694 public function getRemoveLineBreaksFromTemplate() {
695 return $this->removeLineBreaksFromTemplate;
696 }
697
698 /**
699 * Gets content for body
700 *
701 * @return string
702 */
703 public function getBodyContent() {
704 return $this->bodyContent;
705 }
706
707 /**
708 * Gets Path for prototype library (relative to typo3 directory)
709 *
710 * @return string
711 */
712 public function getPrototypePath() {
713 return $this->prototypePath;
714 }
715
716 /**
717 * Gets Path for scriptaculous library (relative to typo3 directory)
718 *
719 * @return string
720 */
721 public function getScriptaculousPath() {
722 return $this->scriptaculousPath;
723 }
724
725 /**
726 * Gets Path for Ext Core library (relative to typo3 directory)
727 *
728 * @return string
729 */
730 public function getExtCorePath() {
731 return $this->extCorePath;
732 }
733
734 /**
735 * Gets Path for ExtJs library (relative to typo3 directory)
736 *
737 * @return string
738 */
739 public function getExtJsPath() {
740 return $this->extJsPath;
741 }
742
743 /**
744 * Gets Path for SVG library (relative to typo3 directory)
745 *
746 * @return string
747 */
748 public function getSvgPath() {
749 return $this->svgPath;
750 }
751
752 /**
753 * Gets the inline language labels.
754 *
755 * @return array The inline language labels
756 */
757 public function getInlineLanguageLabels() {
758 return $this->inlineLanguageLabels;
759 }
760
761 /**
762 * Gets the inline language files
763 *
764 * @return array
765 */
766 public function getInlineLanguageLabelFiles() {
767 return $this->inlineLanguageLabelFiles;
768 }
769
770 /*****************************************************/
771 /* */
772 /* Public Function to add Data */
773 /* */
774 /* */
775 /*****************************************************/
776
777 /**
778 * Adds meta data
779 *
780 * @param string $meta Meta data (complete metatag)
781 * @return void
782 */
783 public function addMetaTag($meta) {
784 if (!in_array($meta, $this->metaTags)) {
785 $this->metaTags[] = $meta;
786 }
787 }
788
789 /**
790 * Adds inline HTML comment
791 *
792 * @param string $comment
793 * @return void
794 */
795 public function addInlineComment($comment) {
796 if (!in_array($comment, $this->inlineComments)) {
797 $this->inlineComments[] = $comment;
798 }
799 }
800
801 /**
802 * Adds header data
803 *
804 * @param string $data Free header data for HTML header
805 * @return void
806 */
807 public function addHeaderData($data) {
808 if (!in_array($data, $this->headerData)) {
809 $this->headerData[] = $data;
810 }
811 }
812
813 /**
814 * Adds footer data
815 *
816 * @param string $data Free header data for HTML header
817 * @return void
818 */
819 public function addFooterData($data) {
820 if (!in_array($data, $this->footerData)) {
821 $this->footerData[] = $data;
822 }
823 }
824
825 /**
826 * Adds JS Library. JS Library block is rendered on top of the JS files.
827 *
828 * @param string $name Arbitrary identifier
829 * @param string $file File name
830 * @param string $type Content Type
831 * @param boolean $compress Flag if library should be compressed
832 * @param boolean $forceOnTop Flag if added library should be inserted at begin of this block
833 * @param string $allWrap
834 * @param boolean $excludeFromConcatenation
835 * @return void
836 */
837 public function addJsLibrary($name, $file, $type = 'text/javascript', $compress = FALSE, $forceOnTop = FALSE, $allWrap = '', $excludeFromConcatenation = FALSE) {
838 if (!$type) {
839 $type = 'text/javascript';
840 }
841 if (!in_array(strtolower($name), $this->jsLibs)) {
842 $this->jsLibs[strtolower($name)] = array(
843 'file' => $file,
844 'type' => $type,
845 'section' => self::PART_HEADER,
846 'compress' => $compress,
847 'forceOnTop' => $forceOnTop,
848 'allWrap' => $allWrap,
849 'excludeFromConcatenation' => $excludeFromConcatenation,
850 );
851 }
852 }
853
854 /**
855 * Adds JS Library to Footer. JS Library block is rendered on top of the Footer JS files.
856 *
857 * @param string $name Arbitrary identifier
858 * @param string $file File name
859 * @param string $type Content Type
860 * @param boolean $compress Flag if library should be compressed
861 * @param boolean $forceOnTop Flag if added library should be inserted at begin of this block
862 * @param string $allWrap
863 * @param boolean $excludeFromConcatenation
864 * @return void
865 */
866 public function addJsFooterLibrary($name, $file, $type = 'text/javascript', $compress = FALSE, $forceOnTop = FALSE, $allWrap = '', $excludeFromConcatenation = FALSE) {
867 if (!$type) {
868 $type = 'text/javascript';
869 }
870 if (!in_array(strtolower($name), $this->jsLibs)) {
871 $this->jsLibs[strtolower($name)] = array(
872 'file' => $file,
873 'type' => $type,
874 'section' => self::PART_FOOTER,
875 'compress' => $compress,
876 'forceOnTop' => $forceOnTop,
877 'allWrap' => $allWrap,
878 'excludeFromConcatenation' => $excludeFromConcatenation,
879 );
880 }
881 }
882
883 /**
884 * Adds JS file
885 *
886 * @param string $file File name
887 * @param string $type Content Type
888 * @param boolean $compress
889 * @param boolean $forceOnTop
890 * @param string $allWrap
891 * @param boolean $excludeFromConcatenation
892 * @return void
893 */
894 public function addJsFile($file, $type = 'text/javascript', $compress = TRUE, $forceOnTop = FALSE, $allWrap = '', $excludeFromConcatenation = FALSE) {
895 if (!$type) {
896 $type = 'text/javascript';
897 }
898 if (!isset($this->jsFiles[$file])) {
899 if (strpos($file, 'ajax.php?') !== FALSE) {
900 $compress = FALSE;
901 }
902 $this->jsFiles[$file] = array(
903 'file' => $file,
904 'type' => $type,
905 'section' => self::PART_HEADER,
906 'compress' => $compress,
907 'forceOnTop' => $forceOnTop,
908 'allWrap' => $allWrap,
909 'excludeFromConcatenation' => $excludeFromConcatenation,
910 );
911 }
912 }
913
914 /**
915 * Adds JS file to footer
916 *
917 * @param string $file File name
918 * @param string $type Content Type
919 * @param boolean $compress
920 * @param boolean $forceOnTop
921 * @param string $allWrap
922 * @param boolean $excludeFromConcatenation
923 * @return void
924 */
925 public function addJsFooterFile($file, $type = 'text/javascript', $compress = TRUE, $forceOnTop = FALSE, $allWrap = '', $excludeFromConcatenation = FALSE) {
926 if (!$type) {
927 $type = 'text/javascript';
928 }
929 if (!isset($this->jsFiles[$file])) {
930 if (strpos($file, 'ajax.php?') !== FALSE) {
931 $compress = FALSE;
932 }
933 $this->jsFiles[$file] = array(
934 'file' => $file,
935 'type' => $type,
936 'section' => self::PART_FOOTER,
937 'compress' => $compress,
938 'forceOnTop' => $forceOnTop,
939 'allWrap' => $allWrap,
940 'excludeFromConcatenation' => $excludeFromConcatenation,
941 );
942 }
943 }
944
945 /**
946 * Adds JS inline code
947 *
948 * @param string $name
949 * @param string $block
950 * @param boolean $compress
951 * @param boolean $forceOnTop
952 * @return void
953 */
954 public function addJsInlineCode($name, $block, $compress = TRUE, $forceOnTop = FALSE) {
955 if (!isset($this->jsInline[$name]) && !empty($block)) {
956 $this->jsInline[$name] = array(
957 'code' => $block . LF,
958 'section' => self::PART_HEADER,
959 'compress' => $compress,
960 'forceOnTop' => $forceOnTop
961 );
962 }
963 }
964
965 /**
966 * Adds JS inline code to footer
967 *
968 * @param string $name
969 * @param string $block
970 * @param boolean $compress
971 * @param boolean $forceOnTop
972 * @return void
973 */
974 public function addJsFooterInlineCode($name, $block, $compress = TRUE, $forceOnTop = FALSE) {
975 if (!isset($this->jsInline[$name]) && !empty($block)) {
976 $this->jsInline[$name] = array(
977 'code' => $block . LF,
978 'section' => self::PART_FOOTER,
979 'compress' => $compress,
980 'forceOnTop' => $forceOnTop
981 );
982 }
983 }
984
985 /**
986 * Adds Ext.onready code, which will be wrapped in Ext.onReady(function() {...});
987 *
988 * @param string $block Javascript code
989 * @param boolean $forceOnTop Position of the javascript code (TRUE for putting it on top, default is FALSE = bottom)
990 * @return void
991 */
992 public function addExtOnReadyCode($block, $forceOnTop = FALSE) {
993 if (!in_array($block, $this->extOnReadyCode)) {
994 if ($forceOnTop) {
995 array_unshift($this->extOnReadyCode, $block);
996 } else {
997 $this->extOnReadyCode[] = $block;
998 }
999 }
1000 }
1001
1002 /**
1003 * Adds the ExtDirect code
1004 *
1005 * @param array $filterNamespaces Limit the output to defined namespaces. If empty, all namespaces are generated
1006 * @return void
1007 */
1008 public function addExtDirectCode(array $filterNamespaces = array()) {
1009 if ($this->extDirectCodeAdded) {
1010 return;
1011 }
1012 $this->extDirectCodeAdded = TRUE;
1013
1014 if (count($filterNamespaces) === 0) {
1015 $filterNamespaces = array('TYPO3');
1016 }
1017
1018 // For ExtDirect we need flash message support
1019 $this->addJsFile(t3lib_div::resolveBackPath($this->backPath . '../t3lib/js/extjs/ux/flashmessages.js'));
1020
1021 // Add language labels for ExtDirect
1022 if (TYPO3_MODE === 'FE') {
1023 $this->addInlineLanguageLabelArray(array(
1024 'extDirect_timeoutHeader' => $GLOBALS['TSFE']->sL('LLL:EXT:lang/locallang_misc.xml:extDirect_timeoutHeader'),
1025 'extDirect_timeoutMessage' => $GLOBALS['TSFE']->sL('LLL:EXT:lang/locallang_misc.xml:extDirect_timeoutMessage'),
1026 ));
1027 } else {
1028 $this->addInlineLanguageLabelArray(array(
1029 'extDirect_timeoutHeader' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_misc.xml:extDirect_timeoutHeader'),
1030 'extDirect_timeoutMessage' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_misc.xml:extDirect_timeoutMessage'),
1031 ));
1032 }
1033
1034 $token = $api = '';
1035 if (TYPO3_MODE === 'BE') {
1036 $formprotection = t3lib_formprotection_Factory::get();
1037 $token = $formprotection->generateToken('extDirect');
1038 }
1039
1040 /** @var $extDirect t3lib_extjs_ExtDirectApi */
1041 $extDirect = t3lib_div::makeInstance('t3lib_extjs_ExtDirectApi');
1042 $api = $extDirect->getApiPhp($filterNamespaces);
1043 if ($api) {
1044 $this->addJsInlineCode('TYPO3ExtDirectAPI', $api, FALSE);
1045 }
1046 // Note: we need to iterate thru the object, because the addProvider method
1047 // does this only with multiple arguments
1048 $this->addExtOnReadyCode('
1049 (function() {
1050 TYPO3.ExtDirectToken = "' . $token . '";
1051 for (var api in Ext.app.ExtDirectAPI) {
1052 var provider = Ext.Direct.addProvider(Ext.app.ExtDirectAPI[api]);
1053 provider.on("beforecall", function(provider, transaction, meta) {
1054 if (transaction.data) {
1055 transaction.data[transaction.data.length] = TYPO3.ExtDirectToken;
1056 } else {
1057 transaction.data = [TYPO3.ExtDirectToken];
1058 }
1059 });
1060
1061 provider.on("call", function(provider, transaction, meta) {
1062 if (transaction.isForm) {
1063 transaction.params.securityToken = TYPO3.ExtDirectToken;
1064 }
1065 });
1066 }
1067 })();
1068
1069 var extDirectDebug = function(message, header, group) {
1070 var TYPO3ViewportInstance = null;
1071
1072 if (top && top.TYPO3 && typeof top.TYPO3.Backend === "object") {
1073 TYPO3ViewportInstance = top.TYPO3.Backend;
1074 } else if (typeof TYPO3 === "object" && typeof TYPO3.Backend === "object") {
1075 TYPO3ViewportInstance = TYPO3.Backend;
1076 }
1077
1078 if (TYPO3ViewportInstance !== null) {
1079 TYPO3ViewportInstance.DebugConsole.addTab(message, header, group);
1080 } else if (typeof console === "object") {
1081 console.log(message);
1082 } else {
1083 document.write(message);
1084 }
1085 };
1086
1087 Ext.Direct.on("exception", function(event) {
1088 if (event.code === Ext.Direct.exceptions.TRANSPORT && !event.where) {
1089 TYPO3.Flashmessage.display(
1090 TYPO3.Severity.error,
1091 TYPO3.l10n.localize("extDirect_timeoutHeader"),
1092 TYPO3.l10n.localize("extDirect_timeoutMessage"),
1093 30
1094 );
1095 } else {
1096 var backtrace = "";
1097 if (event.code === "parse") {
1098 extDirectDebug(
1099 "<p>" + event.xhr.responseText + "<\/p>",
1100 event.type,
1101 "ExtDirect - Exception"
1102 );
1103 } else if (event.code === "router") {
1104 TYPO3.Flashmessage.display(
1105 TYPO3.Severity.error,
1106 event.code,
1107 event.message,
1108 30
1109 );
1110 } else if (event.where) {
1111 backtrace = "<p style=\"margin-top: 20px;\">" +
1112 "<strong>Backtrace:<\/strong><br \/>" +
1113 event.where.replace(/#/g, "<br \/>#") +
1114 "<\/p>";
1115 extDirectDebug(
1116 "<p>" + event.message + "<\/p>" + backtrace,
1117 event.method,
1118 "ExtDirect - Exception"
1119 );
1120 }
1121
1122
1123 }
1124 });
1125
1126 Ext.Direct.on("event", function(event, provider) {
1127 if (typeof event.debug !== "undefined" && event.debug !== "") {
1128 extDirectDebug(event.debug, event.method, "ExtDirect - Debug");
1129 }
1130 });
1131 ',
1132 TRUE
1133 );
1134 }
1135
1136 /**
1137 * Adds CSS file
1138 *
1139 * @param string $file
1140 * @param string $rel
1141 * @param string $media
1142 * @param string $title
1143 * @param boolean $compress
1144 * @param boolean $forceOnTop
1145 * @param string $allWrap
1146 * @param boolean $excludeFromConcatenation
1147 * @return void
1148 */
1149 public function addCssFile($file, $rel = 'stylesheet', $media = 'all', $title = '', $compress = TRUE, $forceOnTop = FALSE, $allWrap = '', $excludeFromConcatenation = FALSE) {
1150 if (!isset($this->cssFiles[$file])) {
1151 $this->cssFiles[$file] = array(
1152 'file' => $file,
1153 'rel' => $rel,
1154 'media' => $media,
1155 'title' => $title,
1156 'compress' => $compress,
1157 'forceOnTop' => $forceOnTop,
1158 'allWrap' => $allWrap,
1159 'excludeFromConcatenation' => $excludeFromConcatenation,
1160 );
1161 }
1162 }
1163
1164 /**
1165 * Adds CSS inline code
1166 *
1167 * @param string $name
1168 * @param string $block
1169 * @param boolean $compress
1170 * @param boolean $forceOnTop
1171 * @return void
1172 */
1173 public function addCssInlineBlock($name, $block, $compress = FALSE, $forceOnTop = FALSE) {
1174 if (!isset($this->cssInline[$name]) && !empty($block)) {
1175 $this->cssInline[$name] = array(
1176 'code' => $block,
1177 'compress' => $compress,
1178 'forceOnTop' => $forceOnTop
1179 );
1180 }
1181 }
1182
1183 /**
1184 * Call function if you need the prototype library
1185 *
1186 * @return void
1187 */
1188 public function loadPrototype() {
1189 $this->addPrototype = TRUE;
1190 }
1191
1192 /**
1193 * Call function if you need the Scriptaculous library
1194 *
1195 * @param string $modules Add modules you need. use "all" if you need complete modules
1196 * @return void
1197 */
1198 public function loadScriptaculous($modules = 'all') {
1199 // Scriptaculous require prototype, so load prototype too.
1200 $this->addPrototype = TRUE;
1201 $this->addScriptaculous = TRUE;
1202 if ($modules) {
1203 if ($modules == 'all') {
1204 foreach ($this->addScriptaculousModules as $key => $value) {
1205 $this->addScriptaculousModules[$key] = TRUE;
1206 }
1207 } else {
1208 $mods = t3lib_div::trimExplode(',', $modules);
1209 foreach ($mods as $mod) {
1210 if (isset($this->addScriptaculousModules[strtolower($mod)])) {
1211 $this->addScriptaculousModules[strtolower($mod)] = TRUE;
1212 }
1213 }
1214 }
1215 }
1216 }
1217
1218 /**
1219 * call this function if you need the extJS library
1220 *
1221 * @param boolean $css Flag, if set the ext-css will be loaded
1222 * @param boolean $theme Flag, if set the ext-theme "grey" will be loaded
1223 * @param string $adapter Choose alternative adapter, possible values: yui, prototype, jquery
1224 * @return void
1225 */
1226 public function loadExtJS($css = TRUE, $theme = TRUE, $adapter = '') {
1227 if ($adapter) {
1228 // Empty $adapter will always load the ext adapter
1229 switch (t3lib_div::strtolower(trim($adapter))) {
1230 case self::EXTJS_ADAPTER_YUI :
1231 $this->extJSadapter = 'yui/ext-yui-adapter.js';
1232 break;
1233 case self::EXTJS_ADAPTER_PROTOTYPE :
1234 $this->extJSadapter = 'prototype/ext-prototype-adapter.js';
1235 break;
1236 case self::EXTJS_ADAPTER_JQUERY :
1237 $this->extJSadapter = 'jquery/ext-jquery-adapter.js';
1238 break;
1239 }
1240 }
1241 $this->addExtJS = TRUE;
1242 $this->extJStheme = $theme;
1243 $this->extJScss = $css;
1244 }
1245
1246 /**
1247 * Enables ExtJs QuickTips
1248 * Need extJs loaded
1249 *
1250 * @return void
1251 */
1252 public function enableExtJSQuickTips() {
1253 $this->enableExtJSQuickTips = TRUE;
1254 }
1255
1256 /**
1257 * Call function if you need the ExtCore library
1258 *
1259 * @return void
1260 */
1261 public function loadExtCore() {
1262 $this->addExtCore = TRUE;
1263 }
1264
1265 /**
1266 * Call function if you need the SVG library
1267 *
1268 * @return void
1269 */
1270 public function loadSvg() {
1271 $this->addSvg = TRUE;
1272 }
1273
1274 /**
1275 * Call this function to load debug version of ExtJS. Use this for development only
1276 * @return void
1277 */
1278 public function enableSvgDebug() {
1279 $this->enableSvgDebug = TRUE;
1280 }
1281
1282 /**
1283 * Call this function to force flash usage with SVG library
1284 * @return void
1285 */
1286 public function svgForceFlash() {
1287 $this->addMetaTag('<meta name="svg.render.forceflash" content="true" />');
1288 }
1289
1290 /**
1291 * Call this function to load debug version of ExtJS. Use this for development only
1292 * @return void
1293 */
1294 public function enableExtJsDebug() {
1295 $this->enableExtJsDebug = TRUE;
1296 }
1297
1298 /**
1299 * Call this function to load debug version of ExtCore. Use this for development only
1300 * @return void
1301 */
1302 public function enableExtCoreDebug() {
1303 $this->enableExtCoreDebug = TRUE;
1304 }
1305
1306 /**
1307 * Adds Javascript Inline Label. This will occur in TYPO3.lang - object
1308 * The label can be used in scripts with TYPO3.lang.<key>
1309 * Need extJs loaded
1310 *
1311 * @param string $key
1312 * @param string $value
1313 * @return void
1314 */
1315 public function addInlineLanguageLabel($key, $value) {
1316 $this->inlineLanguageLabels[$key] = $value;
1317 }
1318
1319 /**
1320 * Adds Javascript Inline Label Array. This will occur in TYPO3.lang - object
1321 * The label can be used in scripts with TYPO3.lang.<key>
1322 * Array will be merged with existing array.
1323 * Need extJs loaded
1324 *
1325 * @param array $array
1326 * @return void
1327 */
1328 public function addInlineLanguageLabelArray(array $array) {
1329 $this->inlineLanguageLabels = array_merge($this->inlineLanguageLabels, $array);
1330 }
1331
1332 /**
1333 * Gets labels to be used in JavaScript fetched from a locallang file.
1334 *
1335 * @param string $fileRef Input is a file-reference (see t3lib_div::getFileAbsFileName). That file is expected to be a 'locallang.xml' file containing a valid XML TYPO3 language structure.
1336 * @param string $selectionPrefix Prefix to select the correct labels (default: '')
1337 * @param string $stripFromSelectionName Sub-prefix to be removed from label names in the result (default: '')
1338 * @param integer $errorMode Error mode (when file could not be found): 0 - syslog entry, 1 - do nothing, 2 - throw an exception
1339 * @return void
1340 */
1341 public function addInlineLanguageLabelFile($fileRef, $selectionPrefix = '', $stripFromSelectionName = '', $errorMode = 0) {
1342 $index = md5($fileRef . $selectionPrefix . $stripFromSelectionName);
1343 if ($fileRef && !isset($this->inlineLanguageLabelFiles[$index])) {
1344 $this->inlineLanguageLabelFiles[$index] = array(
1345 'fileRef' => $fileRef,
1346 'selectionPrefix' => $selectionPrefix,
1347 'stripFromSelectionName' => $stripFromSelectionName,
1348 'errorMode' => $errorMode
1349 );
1350 }
1351 }
1352
1353
1354 /**
1355 * Adds Javascript Inline Setting. This will occur in TYPO3.settings - object
1356 * The label can be used in scripts with TYPO3.setting.<key>
1357 * Need extJs loaded
1358 *
1359 * @param string $namespace
1360 * @param string $key
1361 * @param string $value
1362 * @return void
1363 */
1364 public function addInlineSetting($namespace, $key, $value) {
1365 if ($namespace) {
1366 if (strpos($namespace, '.')) {
1367 $parts = explode('.', $namespace);
1368 $a = &$this->inlineSettings;
1369 foreach ($parts as $part) {
1370 $a = &$a[$part];
1371 }
1372 $a[$key] = $value;
1373 } else {
1374 $this->inlineSettings[$namespace][$key] = $value;
1375 }
1376 } else {
1377 $this->inlineSettings[$key] = $value;
1378 }
1379 }
1380
1381 /**
1382 * Adds Javascript Inline Setting. This will occur in TYPO3.settings - object
1383 * The label can be used in scripts with TYPO3.setting.<key>
1384 * Array will be merged with existing array.
1385 * Need extJs loaded
1386 *
1387 * @param string $namespace
1388 * @param array $array
1389 * @return void
1390 */
1391 public function addInlineSettingArray($namespace, array $array) {
1392 if ($namespace) {
1393 if (strpos($namespace, '.')) {
1394 $parts = explode('.', $namespace);
1395 $a = &$this->inlineSettings;
1396 foreach ($parts as $part) {
1397 $a = &$a[$part];
1398 }
1399 $a = array_merge((array) $a, $array);
1400 } else {
1401 $this->inlineSettings[$namespace] = array_merge((array) $this->inlineSettings[$namespace], $array);
1402 }
1403 } else {
1404 $this->inlineSettings = array_merge($this->inlineSettings, $array);
1405 }
1406 }
1407
1408 /**
1409 * Adds content to body content
1410 *
1411 * @param string $content
1412 * @return void
1413 */
1414 public function addBodyContent($content) {
1415 $this->bodyContent .= $content;
1416 }
1417
1418 /*****************************************************/
1419 /* */
1420 /* Render Functions */
1421 /* */
1422 /* */
1423 /*****************************************************/
1424
1425 /**
1426 * render the section (Header or Footer)
1427 *
1428 * @param integer $part Section which should be rendered: self::PART_COMPLETE, self::PART_HEADER or self::PART_FOOTER
1429 * @return string Content of rendered section
1430 */
1431 public function render($part = self::PART_COMPLETE) {
1432
1433 $jsFiles = '';
1434 $cssFiles = '';
1435 $cssInline = '';
1436 $jsInline = '';
1437 $jsFooterInline = '';
1438 $jsFooterLibs = '';
1439 $jsFooterFiles = '';
1440
1441 // PreRenderHook for possible manuipulation
1442 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-preProcess'])) {
1443 $params = array(
1444 'jsLibs' => &$this->jsLibs,
1445 'jsFooterLibs' => &$this->jsFooterLibs,
1446 'jsFiles' => &$this->jsFiles,
1447 'jsFooterFiles' => &$this->jsFooterFiles,
1448 'cssFiles' => &$this->cssFiles,
1449 'headerData' => &$this->headerData,
1450 'footerData' => &$this->footerData,
1451 'jsInline' => &$this->jsInline,
1452 'jsFooterInline' => &$this->jsFooterInline,
1453 'cssInline' => &$this->cssInline,
1454 );
1455 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-preProcess'] as $hook) {
1456 t3lib_div::callUserFunction($hook, $params, $this);
1457 }
1458 }
1459
1460 $jsLibs = $this->renderJsLibraries();
1461
1462 if ($this->concatenateFiles || $this->concatenateJavascript || $this->concatenateCss) {
1463 // Do the file concatenation
1464 $this->doConcatenate();
1465 }
1466 if ($this->compressCss || $this->compressJavascript) {
1467 // Do the file compression
1468 $this->doCompress();
1469 }
1470 // PostTransform for possible manuipulation of concatenated and compressed files
1471 if(is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postTransform'])) {
1472 $params = array(
1473 'jsLibs' => &$this->jsLibs,
1474 'jsFooterLibs' => &$this->jsFooterLibs,
1475 'jsFiles' => &$this->jsFiles,
1476 'jsFooterFiles' => &$this->jsFooterFiles,
1477 'cssFiles' => &$this->cssFiles,
1478 'headerData' => &$this->headerData,
1479 'footerData' => &$this->footerData,
1480 'jsInline' => &$this->jsInline,
1481 'jsFooterInline' => &$this->jsFooterInline,
1482 'cssInline' => &$this->cssInline,
1483 );
1484 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postTransform'] as $hook) {
1485 t3lib_div::callUserFunction($hook, $params, $this);
1486 }
1487 }
1488 $metaTags = implode(LF, $this->metaTags);
1489
1490 // Remove ending slashes from static header block
1491 // if the page is beeing rendered as html (not xhtml)
1492 // and define variable $endingSlash for further use
1493 if ($this->getRenderXhtml()) {
1494 $endingSlash = ' /';
1495 } else {
1496 $this->metaCharsetTag = str_replace(' />', '>', $this->metaCharsetTag);
1497 $this->baseUrlTag = str_replace(' />', '>', $this->baseUrlTag);
1498 $this->shortcutTag = str_replace(' />', '>', $this->shortcutTag);
1499 $endingSlash = '';
1500 }
1501
1502 if (count($this->cssFiles)) {
1503 foreach ($this->cssFiles as $name => $properties) {
1504 $properties['file'] = t3lib_div::resolveBackPath($properties['file']);
1505 $properties['file'] = t3lib_div::createVersionNumberedFilename($properties['file']);
1506 $tag = '<link rel="' . htmlspecialchars($properties['rel']) . '" type="text/css" href="' .
1507 htmlspecialchars($properties['file']) . '" media="' . htmlspecialchars($properties['media']) . '"' .
1508 ($properties['title'] ? ' title="' . htmlspecialchars($properties['title']) . '"' : '') .
1509 $endingSlash . '>';
1510 if ($properties['allWrap'] && strpos($properties['allWrap'], '|') !== FALSE) {
1511 $tag = str_replace('|', $tag, $properties['allWrap']);
1512 }
1513 if ($properties['forceOnTop']) {
1514 $cssFiles = $tag . LF . $cssFiles;
1515 } else {
1516 $cssFiles .= LF . $tag;
1517 }
1518 }
1519 }
1520
1521 if (count($this->cssInline)) {
1522 foreach ($this->cssInline as $name => $properties) {
1523 if ($properties['forceOnTop']) {
1524 $cssInline = '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF . $cssInline;
1525 } else {
1526 $cssInline .= '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF;
1527 }
1528 }
1529 $cssInline = $this->inlineCssWrap[0] . $cssInline . $this->inlineCssWrap[1];
1530 }
1531
1532 if (count($this->jsLibs)) {
1533 foreach ($this->jsLibs as $name => $properties) {
1534 $properties['file'] = t3lib_div::resolveBackPath($properties['file']);
1535 $properties['file'] = t3lib_div::createVersionNumberedFilename($properties['file']);
1536 $tag = '<script src="' . htmlspecialchars($properties['file']) . '" type="' . htmlspecialchars($properties['type']) . '"></script>';
1537 if ($properties['allWrap'] && strpos($properties['allWrap'], '|') !== FALSE) {
1538 $tag = str_replace('|', $tag, $properties['allWrap']);
1539 }
1540 if ($properties['forceOnTop']) {
1541 if ($properties['section'] === self::PART_HEADER) {
1542 $jsLibs = $tag . LF . $jsLibs;
1543 } else {
1544 $jsFooterLibs = $tag . LF . $jsFooterLibs;
1545 }
1546 } else {
1547 if ($properties['section'] === self::PART_HEADER) {
1548 $jsLibs .= LF . $tag;
1549 } else {
1550 $jsFooterLibs .= LF . $tag;
1551 }
1552 }
1553 }
1554 }
1555
1556 if (count($this->jsFiles)) {
1557 foreach ($this->jsFiles as $name => $properties) {
1558 $properties['file'] = t3lib_div::resolveBackPath($properties['file']);
1559 $properties['file'] = t3lib_div::createVersionNumberedFilename($properties['file']);
1560 $tag = '<script src="' . htmlspecialchars($properties['file']) . '" type="' . htmlspecialchars($properties['type']) . '"></script>';
1561 if ($properties['allWrap'] && strpos($properties['allWrap'], '|') !== FALSE) {
1562 $tag = str_replace('|', $tag, $properties['allWrap']);
1563 }
1564 if ($properties['forceOnTop']) {
1565 if ($properties['section'] === self::PART_HEADER) {
1566 $jsFiles = $tag . LF . $jsFiles;
1567 } else {
1568 $jsFooterFiles = $tag . LF . $jsFooterFiles;
1569 }
1570 } else {
1571 if ($properties['section'] === self::PART_HEADER) {
1572 $jsFiles .= LF . $tag;
1573 } else {
1574 $jsFooterFiles .= LF . $tag;
1575 }
1576 }
1577 }
1578 }
1579
1580 if (count($this->jsInline)) {
1581 foreach ($this->jsInline as $name => $properties) {
1582 if ($properties['forceOnTop']) {
1583 if ($properties['section'] === self::PART_HEADER) {
1584 $jsInline = '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF . $jsInline;
1585 } else {
1586 $jsFooterInline = '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF . $jsFooterInline;
1587 }
1588 } else {
1589 if ($properties['section'] === self::PART_HEADER) {
1590 $jsInline .= '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF;
1591 } else {
1592 $jsFooterInline .= '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF;
1593 }
1594 }
1595 }
1596 }
1597
1598
1599 if ($jsInline) {
1600 $jsInline = $this->inlineJavascriptWrap[0] . $jsInline . $this->inlineJavascriptWrap[1];
1601 }
1602
1603 if ($jsFooterInline) {
1604 $jsFooterInline = $this->inlineJavascriptWrap[0] . $jsFooterInline . $this->inlineJavascriptWrap[1];
1605 }
1606
1607
1608 // Get template
1609 $templateFile = t3lib_div::getFileAbsFileName($this->templateFile, TRUE);
1610 $template = t3lib_div::getUrl($templateFile);
1611
1612 if ($this->removeLineBreaksFromTemplate) {
1613 $template = strtr($template, array(LF => '', CR => ''));
1614 }
1615 if ($part != self::PART_COMPLETE) {
1616 $templatePart = explode('###BODY###', $template);
1617 $template = $templatePart[$part - 1];
1618 }
1619
1620 if ($this->moveJsFromHeaderToFooter) {
1621 $jsFooterLibs = $jsLibs . LF . $jsFooterLibs;
1622 $jsLibs = '';
1623 $jsFooterFiles = $jsFiles . LF . $jsFooterFiles;
1624 $jsFiles = '';
1625 $jsFooterInline = $jsInline . LF . $jsFooterInline;
1626 $jsInline = '';
1627 }
1628
1629 // PostRenderHook for possible manipulation
1630 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postProcess'])) {
1631 $params = array (
1632 'jsLibs' => &$jsLibs,
1633 'jsFiles' => &$jsFiles,
1634 'jsFooterFiles' => &$jsFooterFiles,
1635 'cssFiles' => &$cssFiles,
1636 'headerData' => &$this->headerData,
1637 'footerData' => &$this->footerData,
1638 'jsInline' => &$jsInline,
1639 'cssInline' => &$cssInline,
1640 'xmlPrologAndDocType' => &$this->xmlPrologAndDocType,
1641 'htmlTag' => &$this->htmlTag,
1642 'headTag' => &$this->headTag,
1643 'charSet' => &$this->charSet,
1644 'metaCharsetTag' => &$this->metaCharsetTag,
1645 'shortcutTag' => &$this->shortcutTag,
1646 'inlineComments' => &$this->inlineComments,
1647 'baseUrl' => &$this->baseUrl,
1648 'baseUrlTag' => &$this->baseUrlTag,
1649 'favIcon' => &$this->favIcon,
1650 'iconMimeType' => &$this->iconMimeType,
1651 'titleTag' => &$this->titleTag,
1652 'title' => &$this->title,
1653 'metaTags' => &$metaTags,
1654 'jsFooterInline' => &$jsFooterInline,
1655 'jsFooterLibs' => &$jsFooterLibs,
1656 'bodyContent' => &$this->bodyContent,
1657 );
1658 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postProcess'] as $hook) {
1659 t3lib_div::callUserFunction($hook, $params, $this);
1660 }
1661 }
1662
1663 $markerArray = array(
1664 'XMLPROLOG_DOCTYPE' => $this->xmlPrologAndDocType,
1665 'HTMLTAG' => $this->htmlTag,
1666 'HEADTAG' => $this->headTag,
1667 'METACHARSET' => $this->charSet ? str_replace('|', htmlspecialchars($this->charSet), $this->metaCharsetTag) : '',
1668 'INLINECOMMENT' => $this->inlineComments ? LF . LF . '<!-- ' . LF . implode(LF, $this->inlineComments) . '-->' . LF . LF : '',
1669 'BASEURL' => $this->baseUrl ? str_replace('|', $this->baseUrl, $this->baseUrlTag) : '',
1670 'SHORTCUT' => $this->favIcon ? sprintf($this->shortcutTag, htmlspecialchars($this->favIcon), $this->iconMimeType) : '',
1671 'CSS_INCLUDE' => $cssFiles,
1672 'CSS_INLINE' => $cssInline,
1673 'JS_INLINE' => $jsInline,
1674 'JS_INCLUDE' => $jsFiles,
1675 'JS_LIBS' => $jsLibs,
1676 'TITLE' => $this->title ? str_replace('|', htmlspecialchars($this->title), $this->titleTag) : '',
1677 'META' => $metaTags,
1678 'HEADERDATA' => $this->headerData ? implode(LF, $this->headerData) : '',
1679 'FOOTERDATA' => $this->footerData ? implode(LF, $this->footerData) : '',
1680 'JS_LIBS_FOOTER' => $jsFooterLibs,
1681 'JS_INCLUDE_FOOTER' => $jsFooterFiles,
1682 'JS_INLINE_FOOTER' => $jsFooterInline,
1683 'BODY' => $this->bodyContent,
1684 );
1685
1686 $markerArray = array_map('trim', $markerArray);
1687
1688 $this->reset();
1689 return trim(t3lib_parsehtml::substituteMarkerArray($template, $markerArray, '###|###'));
1690 }
1691
1692 /**
1693 * helper function for render the javascript libraries
1694 *
1695 * @return string Content with javascript libraries
1696 */
1697 protected function renderJsLibraries() {
1698 $out = '';
1699
1700 if ($this->addSvg) {
1701 $out .= '<script src="' . $this->processJsFile($this->backPath . $this->svgPath . 'svg.js') .
1702 '" data-path="' . $this->backPath . $this->svgPath .
1703 '"' . ($this->enableSvgDebug ? ' data-debug="true"' : '') . '></script>';
1704 }
1705
1706 if ($this->addPrototype) {
1707 $out .= '<script src="' . $this->processJsFile($this->backPath . $this->prototypePath . 'prototype.js') .
1708 '" type="text/javascript"></script>' . LF;
1709 unset($this->jsFiles[$this->backPath . $this->prototypePath . 'prototype.js']);
1710 }
1711
1712 if ($this->addScriptaculous) {
1713 $mods = array();
1714 foreach ($this->addScriptaculousModules as $key => $value) {
1715 if ($this->addScriptaculousModules[$key]) {
1716 $mods[] = $key;
1717 }
1718 }
1719 // Resolve dependencies
1720 if (in_array('dragdrop', $mods) || in_array('controls', $mods)) {
1721 $mods = array_merge(array('effects'), $mods);
1722 }
1723
1724 if (count($mods)) {
1725 foreach ($mods as $module) {
1726 $out .= '<script src="' . $this->processJsFile($this->backPath .
1727 $this->scriptaculousPath . $module . '.js') . '" type="text/javascript"></script>' . LF;
1728 unset($this->jsFiles[$this->backPath . $this->scriptaculousPath . $module . '.js']);
1729 }
1730 }
1731 $out .= '<script src="' . $this->processJsFile($this->backPath . $this->scriptaculousPath .
1732 'scriptaculous.js') . '" type="text/javascript"></script>' . LF;
1733 unset($this->jsFiles[$this->backPath . $this->scriptaculousPath . 'scriptaculous.js']);
1734 }
1735
1736 // Include extCore, but only if ExtJS is not included
1737 if ($this->addExtCore && !$this->addExtJS) {
1738 $out .= '<script src="' . $this->processJsFile($this->backPath .
1739 $this->extCorePath . 'ext-core' . ($this->enableExtCoreDebug ? '-debug' : '') . '.js') .
1740 '" type="text/javascript"></script>' . LF;
1741 unset($this->jsFiles[$this->backPath . $this->extCorePath . 'ext-core' . ($this->enableExtCoreDebug ? '-debug' : '') . '.js']);
1742 }
1743
1744 // Include extJS
1745 if ($this->addExtJS) {
1746 // Use the base adapter all the time
1747 $out .= '<script src="' . $this->processJsFile($this->backPath . $this->extJsPath .
1748 'adapter/' . ($this->enableExtJsDebug ?
1749 str_replace('.js', '-debug.js', $this->extJSadapter) : $this->extJSadapter)) .
1750 '" type="text/javascript"></script>' . LF;
1751 $out .= '<script src="' . $this->processJsFile($this->backPath . $this->extJsPath .
1752 'ext-all' . ($this->enableExtJsDebug ? '-debug' : '') . '.js') .
1753 '" type="text/javascript"></script>' . LF;
1754
1755 // Add extJS localization
1756 // Load standard ISO mapping and modify for use with ExtJS
1757 $localeMap = $this->locales->getIsoMapping();
1758 $localeMap[''] = 'en';
1759 $localeMap['default'] = 'en';
1760 // Greek
1761 $localeMap['gr'] = 'el_GR';
1762 // Norwegian Bokmaal
1763 $localeMap['no'] = 'no_BO';
1764 // Swedish
1765 $localeMap['se'] = 'se_SV';
1766
1767
1768 $extJsLang = isset($localeMap[$this->lang]) ? $localeMap[$this->lang] : $this->lang;
1769 // TODO autoconvert file from UTF8 to current BE charset if necessary!!!!
1770 $extJsLocaleFile = $this->extJsPath . 'locale/ext-lang-' . $extJsLang . '.js';
1771 if (file_exists(PATH_typo3 . $extJsLocaleFile)) {
1772 $out .= '<script src="' . $this->processJsFile($this->backPath .
1773 $extJsLocaleFile) . '" type="text/javascript" charset="utf-8"></script>' . LF;
1774 }
1775
1776 // Remove extjs from JScodeLibArray
1777 unset(
1778 $this->jsFiles[$this->backPath . $this->extJsPath . 'ext-all.js'],
1779 $this->jsFiles[$this->backPath . $this->extJsPath . 'ext-all-debug.js']
1780 );
1781 }
1782
1783 if (count($this->inlineLanguageLabelFiles)) {
1784 foreach ($this->inlineLanguageLabelFiles as $languageLabelFile) {
1785 $this->includeLanguageFileForInline(
1786 $languageLabelFile['fileRef'],
1787 $languageLabelFile['selectionPrefix'],
1788 $languageLabelFile['stripFromSelectionName'],
1789 $languageLabelFile['$errorMode']
1790 );
1791 }
1792 }
1793 unset($this->inlineLanguageLabelFiles);
1794
1795 // Convert labels/settings back to UTF-8 since json_encode() only works with UTF-8:
1796 if ($this->getCharSet() !== 'utf-8') {
1797 if ($this->inlineLanguageLabels) {
1798 $this->csConvObj->convArray($this->inlineLanguageLabels, $this->getCharSet(), 'utf-8');
1799 }
1800 if ($this->inlineSettings) {
1801 $this->csConvObj->convArray($this->inlineSettings, $this->getCharSet(), 'utf-8');
1802 }
1803 }
1804
1805 $inlineSettings = $this->inlineLanguageLabels ? 'TYPO3.lang = ' . json_encode($this->inlineLanguageLabels) . ';' : '';
1806 $inlineSettings .= $this->inlineSettings ? 'TYPO3.settings = ' . json_encode($this->inlineSettings) . ';' : '';
1807
1808 if ($this->addExtCore || $this->addExtJS) {
1809 // Set clear.gif, move it on top, add handler code
1810 $code = '';
1811 if (count($this->extOnReadyCode)) {
1812 foreach ($this->extOnReadyCode as $block) {
1813 $code .= $block;
1814 }
1815 }
1816
1817 $out .= $this->inlineJavascriptWrap[0] . '
1818 Ext.ns("TYPO3");
1819 Ext.BLANK_IMAGE_URL = "' . htmlspecialchars(t3lib_div::locationHeaderUrl($this->backPath . 'gfx/clear.gif')) . '";' . LF .
1820 $inlineSettings .
1821 'Ext.onReady(function() {' .
1822 ($this->enableExtJSQuickTips ? 'Ext.QuickTips.init();' . LF : '') . $code .
1823 ' });' . $this->inlineJavascriptWrap[1];
1824 unset ($this->extOnReadyCode);
1825
1826 // Include TYPO3.l10n object
1827 if (TYPO3_MODE === 'BE') {
1828 $out .= '<script src="' . $this->processJsFile($this->backPath . 'sysext/lang/res/js/be/typo3lang.js') . '" type="text/javascript" charset="utf-8"></script>' . LF;
1829 }
1830
1831 if ($this->extJStheme) {
1832 if (isset($GLOBALS['TBE_STYLES']['extJS']['theme'])) {
1833 $this->addCssFile($this->backPath . $GLOBALS['TBE_STYLES']['extJS']['theme'], 'stylesheet', 'all', '', TRUE, TRUE);
1834 } else {
1835 $this->addCssFile($this->backPath . $this->extJsPath . 'resources/css/xtheme-blue.css', 'stylesheet', 'all', '', TRUE, TRUE);
1836 }
1837 }
1838 if ($this->extJScss) {
1839 if (isset($GLOBALS['TBE_STYLES']['extJS']['all'])) {
1840 $this->addCssFile($this->backPath . $GLOBALS['TBE_STYLES']['extJS']['all'], 'stylesheet', 'all', '', TRUE, TRUE);
1841 } else {
1842 $this->addCssFile($this->backPath . $this->extJsPath . 'resources/css/ext-all-notheme.css', 'stylesheet', 'all', '', TRUE, TRUE);
1843 }
1844 }
1845 } else {
1846 if ($inlineSettings) {
1847 $out .= $this->inlineJavascriptWrap[0] . $inlineSettings . $this->inlineJavascriptWrap[1];
1848 }
1849 }
1850
1851 return $out;
1852 }
1853
1854 /**
1855 * Include language file for inline usage
1856 *
1857 * @param string $fileRef
1858 * @param string $selectionPrefix
1859 * @param string $stripFromSelectionName
1860 * @param integer $errorMode
1861 * @return void
1862 */
1863 protected function includeLanguageFileForInline($fileRef, $selectionPrefix = '', $stripFromSelectionName = '', $errorMode = 0) {
1864 if (!isset($this->lang) || !isset($this->charSet)) {
1865 throw new RuntimeException('Language and character encoding are not set.', 1284906026);
1866 }
1867
1868 $labelsFromFile = array();
1869 $allLabels = t3lib_div::readLLfile($fileRef, $this->lang, $this->charSet, $errorMode);
1870
1871 // Regular expression to strip the selection prefix and possibly something from the label name:
1872 $labelPattern = '#^' . preg_quote($selectionPrefix, '#') . '(' . preg_quote($stripFromSelectionName, '#') . ')?#';
1873
1874 if ($allLabels !== FALSE) {
1875 // Merge language specific translations:
1876 if ($this->lang !== 'default' && isset($allLabels[$this->lang])) {
1877 $labels = array_merge($allLabels['default'], $allLabels[$this->lang]);
1878 } else {
1879 $labels = $allLabels['default'];
1880 }
1881
1882 // Iterate through all locallang labels:
1883 foreach ($labels as $label => $value) {
1884 if ($selectionPrefix === '') {
1885 $labelsFromFile[$label] = $value;
1886 } elseif (strpos($label, $selectionPrefix) === 0) {
1887 $key = preg_replace($labelPattern, '', $label);
1888 $labelsFromFile[$label] = $value;
1889 }
1890 }
1891
1892 $this->inlineLanguageLabels = array_merge($this->inlineLanguageLabels, $labelsFromFile);
1893 }
1894 }
1895
1896 /*****************************************************/
1897 /* */
1898 /* Tools */
1899 /* */
1900 /* */
1901 /*****************************************************/
1902
1903 /**
1904 * Concatenate files into one file
1905 * registered handler
1906 *
1907 * @return void
1908 */
1909 protected function doConcatenate() {
1910 $this->doConcatenateCss();
1911 $this->doConcatenateJavaScript();
1912 }
1913
1914 /**
1915 * Concatenate JavaScript files according to the configuration.
1916 *
1917 * @return void
1918 */
1919 protected function doConcatenateJavaScript() {
1920 if ($this->concatenateFiles || $this->concatenateJavascript) {
1921 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsConcatenateHandler'])) {
1922 // use external concatenation routine
1923 $params = array(
1924 'jsLibs' => &$this->jsLibs,
1925 'jsFiles' => &$this->jsFiles,
1926 'jsFooterFiles' => &$this->jsFooterFiles,
1927 'headerData' => &$this->headerData,
1928 'footerData' => &$this->footerData,
1929 );
1930 t3lib_div::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsConcatenateHandler'], $params, $this);
1931 } else {
1932 $this->jsLibs = $this->getCompressor()->concatenateJsFiles($this->jsLibs);
1933 $this->jsFiles = $this->getCompressor()->concatenateJsFiles($this->jsFiles);
1934 $this->jsFooterFiles = $this->getCompressor()->concatenateJsFiles($this->jsFooterFiles);
1935 }
1936 }
1937 }
1938
1939 /**
1940 * Concatenate CSS files according to configuration.
1941 *
1942 * @return void
1943 */
1944 protected function doConcatenateCss() {
1945 if ($this->concatenateFiles || $this->concatenateCss) {
1946 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssConcatenateHandler'])) {
1947 // use external concatenation routine
1948 $params = array(
1949 'cssFiles' => &$this->cssFiles,
1950 'headerData' => &$this->headerData,
1951 'footerData' => &$this->footerData,
1952 );
1953 t3lib_div::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssConcatenateHandler'], $params, $this);
1954 } else {
1955 $cssOptions = array();
1956 if (TYPO3_MODE === 'BE') {
1957 $cssOptions = array('baseDirectories' => $GLOBALS['TBE_TEMPLATE']->getSkinStylesheetDirectories());
1958 }
1959 $this->cssFiles = $this->getCompressor()->concatenateCssFiles($this->cssFiles, $cssOptions);
1960 }
1961 }
1962 }
1963
1964 /**
1965 * Compresses inline code
1966 *
1967 * @return void
1968 */
1969 protected function doCompress() {
1970 $this->doCompressJavaScript();
1971 $this->doCompressCss();
1972 }
1973
1974 /**
1975 * Compresses CSS according to configuration.
1976 *
1977 * @return void
1978 */
1979 protected function doCompressCss() {
1980 if ($this->compressCss) {
1981 // Use external compression routine
1982 $params = array(
1983 'cssInline' => &$this->cssInline,
1984 'cssFiles' => &$this->cssFiles,
1985 'headerData' => &$this->headerData,
1986 'footerData' => &$this->footerData,
1987 );
1988
1989 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssCompressHandler'])) {
1990 // use external concatenation routine
1991 t3lib_div::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssCompressHandler'], $params, $this);
1992 } else {
1993 $this->cssFiles = $this->getCompressor()->compressCssFiles($this->cssFiles);
1994 }
1995 }
1996 }
1997
1998 /**
1999 * Compresses JavaScript according to configuration.
2000 *
2001 * @return void
2002 */
2003 protected function doCompressJavaScript() {
2004 if ($this->compressJavascript) {
2005 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsCompressHandler'])) {
2006 // Use external compression routine
2007 $params = array(
2008 'jsInline' => &$this->jsInline,
2009 'jsFooterInline' => &$this->jsFooterInline,
2010 'jsLibs' => &$this->jsLibs,
2011 'jsFiles' => &$this->jsFiles,
2012 'jsFooterFiles' => &$this->jsFooterFiles,
2013 'headerData' => &$this->headerData,
2014 'footerData' => &$this->footerData,
2015 );
2016 t3lib_div::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsCompressHandler'], $params, $this);
2017 } else {
2018 // Traverse the arrays, compress files
2019 if (count($this->jsInline)) {
2020 foreach ($this->jsInline as $name => $properties) {
2021 if ($properties['compress']) {
2022 $error = '';
2023 $this->jsInline[$name]['code'] = t3lib_div::minifyJavaScript($properties['code'], $error);
2024 if ($error) {
2025 $this->compressError .= 'Error with minify JS Inline Block "' . $name . '": ' . $error . LF;
2026 }
2027 }
2028 }
2029 }
2030 $this->jsLibs = $this->getCompressor()->compressJsFiles($this->jsLibs);
2031 $this->jsFiles = $this->getCompressor()->compressJsFiles($this->jsFiles);
2032 $this->jsFooterFiles = $this->getCompressor()->compressJsFiles($this->jsFooterFiles);
2033 }
2034 }
2035 }
2036
2037 /**
2038 * Returns instance of t3lib_Compressor
2039 *
2040 * @return t3lib_Compressor Instance of t3lib_Compressor
2041 */
2042 protected function getCompressor() {
2043 if ($this->compressor === NULL) {
2044 $this->compressor = t3lib_div::makeInstance('t3lib_Compressor');
2045 }
2046 return $this->compressor;
2047 }
2048
2049 /**
2050 * Processes a Javascript file dependent on the current context
2051 *
2052 * Adds the version number for Frontend, compresses the file for Backend
2053 *
2054 * @param string $filename Filename
2055 * @return string New filename
2056 */
2057 protected function processJsFile($filename) {
2058 switch (TYPO3_MODE) {
2059 case 'FE':
2060 if ($this->compressJavascript) {
2061 $filename = $this->getCompressor()->compressJsFile($filename);
2062 } else {
2063 $filename = t3lib_div::createVersionNumberedFilename($filename);
2064 }
2065 break;
2066 case 'BE':
2067 if ($this->compressJavascript) {
2068 $filename = $this->getCompressor()->compressJsFile($filename);
2069 }
2070 break;
2071 }
2072 return $filename;
2073 }
2074 }
2075
2076 ?>