[BUGFIX] Make PageRenderer work with USER_INT plugins
[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 // Constants for the part to be rendered
40 const PART_COMPLETE = 0;
41 const PART_HEADER = 1;
42 const PART_FOOTER = 2;
43
44 // Available adapters for extJs
45 const EXTJS_ADAPTER_JQUERY = 'jquery';
46 const EXTJS_ADAPTER_PROTOTYPE = 'prototype';
47 const EXTJS_ADAPTER_YUI = 'yui';
48
49 // jQuery Core version that is shipped with TYPO3
50 const JQUERY_VERSION_LATEST = '1.8.0';
51
52 // jQuery namespace options
53 const JQUERY_NAMESPACE_NONE = 'none';
54 const JQUERY_NAMESPACE_DEFAULT = 'jQuery';
55 const JQUERY_NAMESPACE_DEFAULT_NOCONFLICT = 'defaultNoConflict';
56
57 /**
58 * @var boolean
59 */
60 protected $compressJavascript = FALSE;
61
62 /**
63 * @var boolean
64 */
65 protected $compressCss = FALSE;
66
67 /**
68 * @var boolean
69 */
70 protected $removeLineBreaksFromTemplate = FALSE;
71
72 /**
73 * @var boolean
74 */
75 protected $concatenateFiles = FALSE;
76
77 /**
78 * @var boolean
79 */
80 protected $concatenateJavascript = FALSE;
81
82 /**
83 * @var boolean
84 */
85 protected $concatenateCss = FALSE;
86
87 /**
88 * @var boolean
89 */
90 protected $moveJsFromHeaderToFooter = FALSE;
91
92 /**
93 * @var t3lib_cs
94 */
95 protected $csConvObj;
96
97 /**
98 * @var t3lib_l10n_Locales
99 */
100 protected $locales;
101
102 /**
103 * The language key
104 * Two character string or 'default'
105 *
106 * @var string
107 */
108 protected $lang;
109
110 /**
111 * @var t3lib_Compressor
112 */
113 protected $compressor;
114
115 // Arrays containing associative array for the included files
116
117 /**
118 * @var array
119 */
120 protected $jsFiles = array();
121
122 /**
123 * @var array
124 */
125 protected $jsFooterFiles = array();
126
127 /**
128 * @var array
129 */
130 protected $jsLibs = array();
131
132 /**
133 * @var array
134 */
135 protected $jsFooterLibs = array();
136
137 /**
138 * @var array
139 */
140 protected $cssFiles = array();
141
142 /**
143 * The title of the page
144 *
145 * @var string
146 */
147 protected $title;
148
149 /**
150 * Charset for the rendering
151 *
152 * @var string
153 */
154 protected $charSet;
155
156 /**
157 * @var string
158 */
159 protected $favIcon;
160
161 /**
162 * @var string
163 */
164 protected $baseUrl;
165
166 /**
167 * @var boolean
168 */
169 protected $renderXhtml = TRUE;
170
171
172 // Static header blocks
173
174 /**
175 * @var string
176 */
177 protected $xmlPrologAndDocType = '';
178
179 /**
180 * @var array
181 */
182 protected $metaTags = array();
183
184 /**
185 * @var array
186 */
187 protected $inlineComments = array();
188
189 /**
190 * @var array
191 */
192 protected $headerData = array();
193
194 /**
195 * @var array
196 */
197 protected $footerData = array();
198
199 /**
200 * @var string
201 */
202 protected $titleTag = '<title>|</title>';
203
204 /**
205 * @var string
206 */
207 protected $metaCharsetTag = '<meta http-equiv="Content-Type" content="text/html; charset=|" />';
208
209 /**
210 * @var string
211 */
212 protected $htmlTag = '<html>';
213
214 /**
215 * @var string
216 */
217 protected $headTag = '<head>';
218
219 /**
220 * @var string
221 */
222 protected $baseUrlTag = '<base href="|" />';
223
224 /**
225 * @var string
226 */
227 protected $iconMimeType = '';
228
229 /**
230 * @var string
231 */
232 protected $shortcutTag = '<link rel="shortcut icon" href="%1$s"%2$s />
233 <link rel="icon" href="%1$s"%2$s />';
234
235 // Static inline code blocks
236
237 /**
238 * @var array
239 */
240 protected $jsInline = array();
241
242 /**
243 * @var array
244 */
245 protected $jsFooterInline = array();
246
247 /**
248 * @var array
249 */
250 protected $extOnReadyCode = array();
251
252 /**
253 * @var array
254 */
255 protected $cssInline = array();
256
257 /**
258 * @var string
259 */
260 protected $bodyContent;
261
262 /**
263 * @var string
264 */
265 protected $templateFile;
266
267 /**
268 * @var array
269 */
270 protected $jsLibraryNames = array('prototype', 'scriptaculous', 'extjs');
271
272 // Paths to contibuted libraries
273
274 /**
275 * @var string
276 */
277 protected $prototypePath = 'contrib/prototype/';
278
279 /**
280 * @var string
281 */
282 protected $scriptaculousPath = 'contrib/scriptaculous/';
283
284 /**
285 * @var string
286 */
287 protected $extCorePath = 'contrib/extjs/';
288
289 /**
290 * @var string
291 */
292 protected $extJsPath = 'contrib/extjs/';
293
294 /**
295 * @var string
296 */
297 protected $svgPath = 'contrib/websvg/';
298
299 /**
300 * The local directory where one can find jQuery versions and plugins
301 *
302 * @var string
303 */
304 protected $jQueryPath = 'contrib/jquery/';
305
306 // Internal flags for JS-libraries
307
308 /**
309 * This array holds all jQuery versions that should be included in the
310 * current page.
311 * Each version is described by "source", "version" and "namespace"
312 *
313 * The namespace of every particular version is the key
314 * of that array, because only one version per namespace can exist.
315 *
316 * The type "source" describes where the jQuery core should be included from
317 * currently, TYPO3 supports "local" (make use of jQuery path), "google",
318 * "jquery" and "msn".
319 * Currently there are downsides to "local" and "jquery", as "local" only
320 * supports the latest/shipped jQuery core out of the box, and
321 * "jquery" does not have SSL support.
322 *
323 * @var array
324 */
325 protected $jQueryVersions = array();
326
327 /**
328 * Array of jQuery version numbers shipped with the core
329 *
330 * @var array
331 */
332 protected $availableLocalJqueryVersions = array(
333 self::JQUERY_VERSION_LATEST,
334 );
335
336 /**
337 * Array of jQuery CDNs with placeholders
338 *
339 * @var array
340 */
341 protected $jQueryCdnUrls = array(
342 'google' => '//ajax.googleapis.com/ajax/libs/jquery/%1$s/jquery%2$s.js',
343 'msn' => '//ajax.aspnetcdn.com/ajax/jQuery/jquery-%1$s%2$s.js',
344 'jquery' => 'http://code.jquery.com/jquery-%1$s%2$s.js',
345 );
346
347 /**
348 * @var boolean
349 */
350 protected $addPrototype = FALSE;
351
352 /**
353 * @var boolean
354 */
355 protected $addScriptaculous = FALSE;
356
357 /**
358 * @var array
359 */
360 protected $addScriptaculousModules = array('builder' => FALSE, 'effects' => FALSE, 'dragdrop' => FALSE, 'controls' => FALSE, 'slider' => FALSE);
361
362 /**
363 * @var boolean
364 */
365 protected $addExtJS = FALSE;
366
367 /**
368 * @var boolean
369 */
370 protected $addExtCore = FALSE;
371
372 /**
373 * @var string
374 */
375 protected $extJSadapter = 'ext/ext-base.js';
376
377 /**
378 * @var boolean
379 */
380 protected $extDirectCodeAdded = FALSE;
381
382 /**
383 * @var boolean
384 */
385 protected $enableExtJsDebug = FALSE;
386
387 /**
388 * @var boolean
389 */
390 protected $enableExtCoreDebug = FALSE;
391
392 /**
393 * @var boolean
394 */
395 protected $enableJqueryDebug = FALSE;
396
397 /**
398 * @var boolean
399 */
400 protected $extJStheme = TRUE;
401
402 /**
403 * @var boolean
404 */
405 protected $extJScss = TRUE;
406
407 /**
408 * @var boolean
409 */
410 protected $enableExtJSQuickTips = FALSE;
411
412 /**
413 * @var array
414 */
415 protected $inlineLanguageLabels = array();
416
417 /**
418 * @var array
419 */
420 protected $inlineLanguageLabelFiles = array();
421
422 /**
423 * @var array
424 */
425 protected $inlineSettings = array();
426
427 /**
428 * @var array
429 */
430 protected $inlineJavascriptWrap = array();
431
432 /**
433 * Saves error messages generated during compression
434 *
435 * @var string
436 */
437 protected $compressError = '';
438
439 /**
440 * Is empty string for HTML and ' /' for XHTML rendering
441 *
442 * @var string
443 */
444 protected $endingSlash = '';
445
446 /**
447 * SVG library
448 *
449 * @var boolean
450 */
451 protected $addSvg = FALSE;
452
453 /**
454 * @var boolean
455 */
456 protected $enableSvgDebug = FALSE;
457
458 /**
459 * Used by BE modules
460 *
461 * @var null|string
462 */
463 public $backPath;
464
465 /**
466 * @param string $templateFile Declare the used template file. Omit this parameter will use default template
467 * @param string $backPath Relative path to typo3-folder. It varies for BE modules, in FE it will be typo3/
468 */
469 public function __construct($templateFile = '', $backPath = NULL) {
470
471 $this->reset();
472 $this->csConvObj = t3lib_div::makeInstance('t3lib_cs');
473 $this->locales = t3lib_div::makeInstance('t3lib_l10n_Locales');
474
475 if (strlen($templateFile)) {
476 $this->templateFile = $templateFile;
477 }
478 $this->backPath = isset($backPath) ? $backPath : $GLOBALS['BACK_PATH'];
479
480 $this->inlineJavascriptWrap = array(
481 '<script type="text/javascript">' . LF . '/*<![CDATA[*/' . LF . '<!-- ' . LF,
482 '// -->' . LF . '/*]]>*/' . LF . '</script>' . LF
483 );
484 $this->inlineCssWrap = array(
485 '<style type="text/css">' . LF . '/*<![CDATA[*/' . LF . '<!-- ' . LF,
486 '-->' . LF . '/*]]>*/' . LF . '</style>' . LF
487 );
488 }
489
490 /**
491 * Reset all vars to initial values
492 *
493 * @return void
494 */
495 protected function reset() {
496 $this->templateFile = TYPO3_mainDir . 'templates/template_page_backend.html';
497 $this->jsFiles = array();
498 $this->jsFooterFiles = array();
499 $this->jsInline = array();
500 $this->jsFooterInline = array();
501 $this->jsLibs = array();
502 $this->cssFiles = array();
503 $this->cssInline = array();
504 $this->metaTags = array();
505 $this->inlineComments = array();
506 $this->headerData = array();
507 $this->footerData = array();
508 $this->extOnReadyCode = array();
509 $this->jQueryVersions = array();
510 }
511
512 /*****************************************************/
513 /* */
514 /* Public Setters */
515 /* */
516 /* */
517 /*****************************************************/
518
519 /**
520 * Sets the title
521 *
522 * @param string $title title of webpage
523 * @return void
524 */
525 public function setTitle($title) {
526 $this->title = $title;
527 }
528
529 /**
530 * Enables/disables rendering of XHTML code
531 *
532 * @param boolean $enable Enable XHTML
533 * @return void
534 */
535 public function setRenderXhtml($enable) {
536 $this->renderXhtml = $enable;
537 }
538
539 /**
540 * Sets xml prolog and docType
541 *
542 * @param string $xmlPrologAndDocType Complete tags for xml prolog and docType
543 * @return void
544 */
545 public function setXmlPrologAndDocType($xmlPrologAndDocType) {
546 $this->xmlPrologAndDocType = $xmlPrologAndDocType;
547 }
548
549 /**
550 * Sets meta charset
551 *
552 * @param string $charSet Used charset
553 * @return void
554 */
555 public function setCharSet($charSet) {
556 $this->charSet = $charSet;
557 }
558
559 /**
560 * Sets language
561 *
562 * @param string $lang Used language
563 * @return void
564 */
565 public function setLanguage($lang) {
566 $this->lang = $lang;
567 }
568
569 /**
570 * Set the meta charset tag
571 *
572 * @param string $metaCharsetTag
573 * @return void
574 */
575 public function setMetaCharsetTag($metaCharsetTag) {
576 $this->metaCharsetTag = $metaCharsetTag;
577 }
578
579 /**
580 * Sets html tag
581 *
582 * @param string $htmlTag Html tag
583 * @return void
584 */
585 public function setHtmlTag($htmlTag) {
586 $this->htmlTag = $htmlTag;
587 }
588
589 /**
590 * Sets HTML head tag
591 *
592 * @param string $headTag HTML head tag
593 * @return void
594 */
595 public function setHeadTag($headTag) {
596 $this->headTag = $headTag;
597 }
598
599 /**
600 * Sets favicon
601 *
602 * @param string $favIcon
603 * @return void
604 */
605 public function setFavIcon($favIcon) {
606 $this->favIcon = $favIcon;
607 }
608
609 /**
610 * Sets icon mime type
611 *
612 * @param string $iconMimeType
613 * @return void
614 */
615 public function setIconMimeType($iconMimeType) {
616 $this->iconMimeType = $iconMimeType;
617 }
618
619 /**
620 * Sets HTML base URL
621 *
622 * @param string $baseUrl HTML base URL
623 * @return void
624 */
625 public function setBaseUrl($baseUrl) {
626 $this->baseUrl = $baseUrl;
627 }
628
629 /**
630 * Sets template file
631 *
632 * @param string $file
633 * @return void
634 */
635 public function setTemplateFile($file) {
636 $this->templateFile = $file;
637 }
638
639 /**
640 * Sets back path
641 *
642 * @param string $backPath
643 * @return void
644 */
645 public function setBackPath($backPath) {
646 $this->backPath = $backPath;
647 }
648
649 /**
650 * Sets Content for Body
651 *
652 * @param string $content
653 * @return void
654 */
655 public function setBodyContent($content) {
656 $this->bodyContent = $content;
657 }
658
659 /**
660 * Sets path to prototype library (relative to typo3 directory)
661 *
662 * @param string $path Path to prototype library
663 * @return void
664 */
665 public function setPrototypePath($path) {
666 $this->prototypePath = $path;
667 }
668
669 /**
670 * Sets Path for scriptaculous library (relative to typo3 directory)
671 *
672 * @param string $path
673 * @return void
674 */
675 public function setScriptaculousPath($path) {
676 $this->scriptaculousPath = $path;
677 }
678
679 /**
680 * Sets Path for Ext Core library (relative to typo3 directory)
681 *
682 * @param string $path
683 * @return void
684 */
685 public function setExtCorePath($path) {
686 $this->extCorePath = $path;
687 }
688
689 /**
690 * Sets Path for ExtJs library (relative to typo3 directory)
691 *
692 * @param string $path
693 * @return void
694 */
695 public function setExtJsPath($path) {
696 $this->extJsPath = $path;
697 }
698
699 /**
700 * Sets Path for SVG library (websvg)
701 *
702 * @param string $path
703 * @return void
704 */
705 public function setSvgPath($path) {
706 $this->svgPath = $path;
707 }
708
709 /*****************************************************/
710 /* */
711 /* Public Enablers / Disablers */
712 /* */
713 /* */
714 /*****************************************************/
715
716 /**
717 * Enables MoveJsFromHeaderToFooter
718 * @return void
719 */
720 public function enableMoveJsFromHeaderToFooter() {
721 $this->moveJsFromHeaderToFooter = TRUE;
722 }
723
724 /**
725 * Disables MoveJsFromHeaderToFooter
726 * @return void
727 */
728 public function disableMoveJsFromHeaderToFooter() {
729 $this->moveJsFromHeaderToFooter = FALSE;
730 }
731
732 /**
733 * Enables compression of javascript
734 * @return void
735 */
736 public function enableCompressJavascript() {
737 $this->compressJavascript = TRUE;
738 }
739
740 /**
741 * Disables compression of javascript
742 * @return void
743 */
744 public function disableCompressJavascript() {
745 $this->compressJavascript = FALSE;
746 }
747
748 /**
749 * Enables compression of css
750 * @return void
751 */
752 public function enableCompressCss() {
753 $this->compressCss = TRUE;
754 }
755
756 /**
757 * Disables compression of css
758 * @return void
759 */
760 public function disableCompressCss() {
761 $this->compressCss = FALSE;
762 }
763
764 /**
765 * Enables concatenation of js and css files
766 * @return void
767 */
768 public function enableConcatenateFiles() {
769 $this->concatenateFiles = TRUE;
770 }
771
772 /**
773 * Disables concatenation of js and css files
774 * @return void
775 */
776 public function disableConcatenateFiles() {
777 $this->concatenateFiles = FALSE;
778 }
779
780 /**
781 * Enables concatenation of js files
782 * @return void
783 */
784 public function enableConcatenateJavascript() {
785 $this->concatenateJavascript = TRUE;
786 }
787
788 /**
789 * Disables concatenation of js files
790 * @return void
791 */
792 public function disableConcatenateJavascript() {
793 $this->concatenateJavascript = FALSE;
794 }
795
796 /**
797 * Enables concatenation of css files
798 * @return void
799 */
800 public function enableConcatenateCss() {
801 $this->concatenateCss = TRUE;
802 }
803
804 /**
805 * Disables concatenation of css files
806 * @return void
807 */
808 public function disableConcatenateCss() {
809 $this->concatenateCss = FALSE;
810 }
811
812 /**
813 * Sets removal of all line breaks in template
814 * @return void
815 */
816 public function enableRemoveLineBreaksFromTemplate() {
817 $this->removeLineBreaksFromTemplate = TRUE;
818 }
819
820 /**
821 * Unsets removal of all line breaks in template
822 * @return void
823 */
824 public function disableRemoveLineBreaksFromTemplate() {
825 $this->removeLineBreaksFromTemplate = FALSE;
826 }
827
828 /**
829 * Enables Debug Mode
830 * This is a shortcut to switch off all compress/concatenate features to enable easier debug
831 * @return void
832 */
833 public function enableDebugMode() {
834 $this->compressJavascript = FALSE;
835 $this->compressCss = FALSE;
836 $this->concatenateFiles = FALSE;
837 $this->removeLineBreaksFromTemplate = FALSE;
838 $this->enableExtCoreDebug = TRUE;
839 $this->enableExtJsDebug = TRUE;
840 $this->enableJqueryDebug = TRUE;
841 $this->enableSvgDebug = TRUE;
842 }
843
844 /*****************************************************/
845 /* */
846 /* Public Getters */
847 /* */
848 /* */
849 /*****************************************************/
850
851 /**
852 * Gets the title
853 *
854 * @return string $title Title of webpage
855 */
856 public function getTitle() {
857 return $this->title;
858 }
859
860 /**
861 * Gets the charSet
862 *
863 * @return string $charSet
864 */
865 public function getCharSet() {
866 return $this->charSet;
867 }
868
869 /**
870 * Gets the language
871 *
872 * @return string $lang
873 */
874 public function getLanguage() {
875 return $this->lang;
876 }
877
878 /**
879 * Returns rendering mode XHTML or HTML
880 *
881 * @return boolean TRUE if XHTML, FALSE if HTML
882 */
883 public function getRenderXhtml() {
884 return $this->renderXhtml;
885 }
886
887 /**
888 * Gets html tag
889 *
890 * @return string $htmlTag Html tag
891 */
892 public function getHtmlTag() {
893 return $this->htmlTag;
894 }
895
896 /**
897 * Get meta charset
898 *
899 * @return string
900 */
901 public function getMetaCharsetTag() {
902 return $this->metaCharsetTag;
903 }
904
905 /**
906 * Gets head tag
907 *
908 * @return string $tag Head tag
909 */
910 public function getHeadTag() {
911 return $this->headTag;
912 }
913
914 /**
915 * Gets favicon
916 *
917 * @return string $favIcon
918 */
919 public function getFavIcon() {
920 return $this->favIcon;
921 }
922
923 /**
924 * Gets icon mime type
925 *
926 * @return string $iconMimeType
927 */
928 public function getIconMimeType() {
929 return $this->iconMimeType;
930 }
931
932 /**
933 * Gets HTML base URL
934 *
935 * @return string $url
936 */
937 public function getBaseUrl() {
938 return $this->baseUrl;
939 }
940
941 /**
942 * Gets template file
943 *
944 * @return string
945 */
946 public function getTemplateFile() {
947 return $this->templateFile;
948 }
949
950 /**
951 * Gets MoveJsFromHeaderToFooter
952 *
953 * @return boolean
954 */
955 public function getMoveJsFromHeaderToFooter() {
956 return $this->moveJsFromHeaderToFooter;
957 }
958
959 /**
960 * Gets compress of javascript
961 *
962 * @return boolean
963 */
964 public function getCompressJavascript() {
965 return $this->compressJavascript;
966 }
967
968 /**
969 * Gets compress of css
970 *
971 * @return boolean
972 */
973 public function getCompressCss() {
974 return $this->compressCss;
975 }
976
977 /**
978 * Gets concatenate of js and css files
979 *
980 * @return boolean
981 */
982 public function getConcatenateFiles() {
983 return $this->concatenateFiles;
984 }
985
986 /**
987 * Gets concatenate of js files
988 *
989 * @return boolean
990 */
991 public function getConcatenateJavascript() {
992 return $this->concatenateJavascript;
993 }
994
995 /**
996 * Gets concatenate of css files
997 *
998 * @return boolean
999 */
1000 public function getConcatenateCss() {
1001 return $this->concatenateCss;
1002 }
1003
1004 /**
1005 * Gets remove of empty lines from template
1006 *
1007 * @return boolean
1008 */
1009 public function getRemoveLineBreaksFromTemplate() {
1010 return $this->removeLineBreaksFromTemplate;
1011 }
1012
1013 /**
1014 * Gets content for body
1015 *
1016 * @return string
1017 */
1018 public function getBodyContent() {
1019 return $this->bodyContent;
1020 }
1021
1022 /**
1023 * Gets Path for prototype library (relative to typo3 directory)
1024 *
1025 * @return string
1026 */
1027 public function getPrototypePath() {
1028 return $this->prototypePath;
1029 }
1030
1031 /**
1032 * Gets Path for scriptaculous library (relative to typo3 directory)
1033 *
1034 * @return string
1035 */
1036 public function getScriptaculousPath() {
1037 return $this->scriptaculousPath;
1038 }
1039
1040 /**
1041 * Gets Path for Ext Core library (relative to typo3 directory)
1042 *
1043 * @return string
1044 */
1045 public function getExtCorePath() {
1046 return $this->extCorePath;
1047 }
1048
1049 /**
1050 * Gets Path for ExtJs library (relative to typo3 directory)
1051 *
1052 * @return string
1053 */
1054 public function getExtJsPath() {
1055 return $this->extJsPath;
1056 }
1057
1058 /**
1059 * Gets Path for SVG library (relative to typo3 directory)
1060 *
1061 * @return string
1062 */
1063 public function getSvgPath() {
1064 return $this->svgPath;
1065 }
1066
1067 /**
1068 * Gets the inline language labels.
1069 *
1070 * @return array The inline language labels
1071 */
1072 public function getInlineLanguageLabels() {
1073 return $this->inlineLanguageLabels;
1074 }
1075
1076 /**
1077 * Gets the inline language files
1078 *
1079 * @return array
1080 */
1081 public function getInlineLanguageLabelFiles() {
1082 return $this->inlineLanguageLabelFiles;
1083 }
1084
1085 /*****************************************************/
1086 /* */
1087 /* Public Functions to add Data */
1088 /* */
1089 /* */
1090 /*****************************************************/
1091
1092 /**
1093 * Adds meta data
1094 *
1095 * @param string $meta Meta data (complete metatag)
1096 * @return void
1097 */
1098 public function addMetaTag($meta) {
1099 if (!in_array($meta, $this->metaTags)) {
1100 $this->metaTags[] = $meta;
1101 }
1102 }
1103
1104 /**
1105 * Adds inline HTML comment
1106 *
1107 * @param string $comment
1108 * @return void
1109 */
1110 public function addInlineComment($comment) {
1111 if (!in_array($comment, $this->inlineComments)) {
1112 $this->inlineComments[] = $comment;
1113 }
1114 }
1115
1116 /**
1117 * Adds header data
1118 *
1119 * @param string $data Free header data for HTML header
1120 * @return void
1121 */
1122 public function addHeaderData($data) {
1123 if (!in_array($data, $this->headerData)) {
1124 $this->headerData[] = $data;
1125 }
1126 }
1127
1128 /**
1129 * Adds footer data
1130 *
1131 * @param string $data Free header data for HTML header
1132 * @return void
1133 */
1134 public function addFooterData($data) {
1135 if (!in_array($data, $this->footerData)) {
1136 $this->footerData[] = $data;
1137 }
1138 }
1139
1140 /**
1141 * Adds JS Library. JS Library block is rendered on top of the JS files.
1142 *
1143 * @param string $name Arbitrary identifier
1144 * @param string $file File name
1145 * @param string $type Content Type
1146 * @param boolean $compress Flag if library should be compressed
1147 * @param boolean $forceOnTop Flag if added library should be inserted at begin of this block
1148 * @param string $allWrap
1149 * @param boolean $excludeFromConcatenation
1150 * @return void
1151 */
1152 public function addJsLibrary($name, $file, $type = 'text/javascript', $compress = FALSE, $forceOnTop = FALSE, $allWrap = '', $excludeFromConcatenation = FALSE) {
1153 if (!$type) {
1154 $type = 'text/javascript';
1155 }
1156 if (!in_array(strtolower($name), $this->jsLibs)) {
1157 $this->jsLibs[strtolower($name)] = array(
1158 'file' => $file,
1159 'type' => $type,
1160 'section' => self::PART_HEADER,
1161 'compress' => $compress,
1162 'forceOnTop' => $forceOnTop,
1163 'allWrap' => $allWrap,
1164 'excludeFromConcatenation' => $excludeFromConcatenation,
1165 );
1166 }
1167 }
1168
1169 /**
1170 * Adds JS Library to Footer. JS Library block is rendered on top of the Footer JS files.
1171 *
1172 * @param string $name Arbitrary identifier
1173 * @param string $file File name
1174 * @param string $type Content Type
1175 * @param boolean $compress Flag if library should be compressed
1176 * @param boolean $forceOnTop Flag if added library should be inserted at begin of this block
1177 * @param string $allWrap
1178 * @param boolean $excludeFromConcatenation
1179 * @return void
1180 */
1181 public function addJsFooterLibrary($name, $file, $type = 'text/javascript', $compress = FALSE, $forceOnTop = FALSE, $allWrap = '', $excludeFromConcatenation = FALSE) {
1182 if (!$type) {
1183 $type = 'text/javascript';
1184 }
1185 if (!in_array(strtolower($name), $this->jsLibs)) {
1186 $this->jsLibs[strtolower($name)] = array(
1187 'file' => $file,
1188 'type' => $type,
1189 'section' => self::PART_FOOTER,
1190 'compress' => $compress,
1191 'forceOnTop' => $forceOnTop,
1192 'allWrap' => $allWrap,
1193 'excludeFromConcatenation' => $excludeFromConcatenation,
1194 );
1195 }
1196 }
1197
1198 /**
1199 * Adds JS file
1200 *
1201 * @param string $file File name
1202 * @param string $type Content Type
1203 * @param boolean $compress
1204 * @param boolean $forceOnTop
1205 * @param string $allWrap
1206 * @param boolean $excludeFromConcatenation
1207 * @return void
1208 */
1209 public function addJsFile($file, $type = 'text/javascript', $compress = TRUE, $forceOnTop = FALSE, $allWrap = '', $excludeFromConcatenation = FALSE) {
1210 if (!$type) {
1211 $type = 'text/javascript';
1212 }
1213 if (!isset($this->jsFiles[$file])) {
1214 if (strpos($file, 'ajax.php?') !== FALSE) {
1215 $compress = FALSE;
1216 }
1217 $this->jsFiles[$file] = array(
1218 'file' => $file,
1219 'type' => $type,
1220 'section' => self::PART_HEADER,
1221 'compress' => $compress,
1222 'forceOnTop' => $forceOnTop,
1223 'allWrap' => $allWrap,
1224 'excludeFromConcatenation' => $excludeFromConcatenation,
1225 );
1226 }
1227 }
1228
1229 /**
1230 * Adds JS file to footer
1231 *
1232 * @param string $file File name
1233 * @param string $type Content Type
1234 * @param boolean $compress
1235 * @param boolean $forceOnTop
1236 * @param string $allWrap
1237 * @param boolean $excludeFromConcatenation
1238 * @return void
1239 */
1240 public function addJsFooterFile($file, $type = 'text/javascript', $compress = TRUE, $forceOnTop = FALSE, $allWrap = '', $excludeFromConcatenation = FALSE) {
1241 if (!$type) {
1242 $type = 'text/javascript';
1243 }
1244 if (!isset($this->jsFiles[$file])) {
1245 if (strpos($file, 'ajax.php?') !== FALSE) {
1246 $compress = FALSE;
1247 }
1248 $this->jsFiles[$file] = array(
1249 'file' => $file,
1250 'type' => $type,
1251 'section' => self::PART_FOOTER,
1252 'compress' => $compress,
1253 'forceOnTop' => $forceOnTop,
1254 'allWrap' => $allWrap,
1255 'excludeFromConcatenation' => $excludeFromConcatenation,
1256 );
1257 }
1258 }
1259
1260 /**
1261 * Adds JS inline code
1262 *
1263 * @param string $name
1264 * @param string $block
1265 * @param boolean $compress
1266 * @param boolean $forceOnTop
1267 * @return void
1268 */
1269 public function addJsInlineCode($name, $block, $compress = TRUE, $forceOnTop = FALSE) {
1270 if (!isset($this->jsInline[$name]) && !empty($block)) {
1271 $this->jsInline[$name] = array(
1272 'code' => $block . LF,
1273 'section' => self::PART_HEADER,
1274 'compress' => $compress,
1275 'forceOnTop' => $forceOnTop
1276 );
1277 }
1278 }
1279
1280 /**
1281 * Adds JS inline code to footer
1282 *
1283 * @param string $name
1284 * @param string $block
1285 * @param boolean $compress
1286 * @param boolean $forceOnTop
1287 * @return void
1288 */
1289 public function addJsFooterInlineCode($name, $block, $compress = TRUE, $forceOnTop = FALSE) {
1290 if (!isset($this->jsInline[$name]) && !empty($block)) {
1291 $this->jsInline[$name] = array(
1292 'code' => $block . LF,
1293 'section' => self::PART_FOOTER,
1294 'compress' => $compress,
1295 'forceOnTop' => $forceOnTop
1296 );
1297 }
1298 }
1299
1300 /**
1301 * Adds Ext.onready code, which will be wrapped in Ext.onReady(function() {...});
1302 *
1303 * @param string $block Javascript code
1304 * @param boolean $forceOnTop Position of the javascript code (TRUE for putting it on top, default is FALSE = bottom)
1305 * @return void
1306 */
1307 public function addExtOnReadyCode($block, $forceOnTop = FALSE) {
1308 if (!in_array($block, $this->extOnReadyCode)) {
1309 if ($forceOnTop) {
1310 array_unshift($this->extOnReadyCode, $block);
1311 } else {
1312 $this->extOnReadyCode[] = $block;
1313 }
1314 }
1315 }
1316
1317 /**
1318 * Adds the ExtDirect code
1319 *
1320 * @param array $filterNamespaces Limit the output to defined namespaces. If empty, all namespaces are generated
1321 * @return void
1322 */
1323 public function addExtDirectCode(array $filterNamespaces = array()) {
1324 if ($this->extDirectCodeAdded) {
1325 return;
1326 }
1327 $this->extDirectCodeAdded = TRUE;
1328
1329 if (count($filterNamespaces) === 0) {
1330 $filterNamespaces = array('TYPO3');
1331 }
1332
1333 // For ExtDirect we need flash message support
1334 $this->addJsFile(t3lib_div::resolveBackPath($this->backPath . '../t3lib/js/extjs/ux/flashmessages.js'));
1335
1336 // Add language labels for ExtDirect
1337 if (TYPO3_MODE === 'FE') {
1338 $this->addInlineLanguageLabelArray(array(
1339 'extDirect_timeoutHeader' => $GLOBALS['TSFE']->sL('LLL:EXT:lang/locallang_misc.xml:extDirect_timeoutHeader'),
1340 'extDirect_timeoutMessage' => $GLOBALS['TSFE']->sL('LLL:EXT:lang/locallang_misc.xml:extDirect_timeoutMessage'),
1341 ));
1342 } else {
1343 $this->addInlineLanguageLabelArray(array(
1344 'extDirect_timeoutHeader' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_misc.xml:extDirect_timeoutHeader'),
1345 'extDirect_timeoutMessage' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_misc.xml:extDirect_timeoutMessage'),
1346 ));
1347 }
1348
1349 $token = $api = '';
1350 if (TYPO3_MODE === 'BE') {
1351 $formprotection = t3lib_formprotection_Factory::get();
1352 $token = $formprotection->generateToken('extDirect');
1353 }
1354
1355 /** @var $extDirect t3lib_extjs_ExtDirectApi */
1356 $extDirect = t3lib_div::makeInstance('t3lib_extjs_ExtDirectApi');
1357 $api = $extDirect->getApiPhp($filterNamespaces);
1358 if ($api) {
1359 $this->addJsInlineCode('TYPO3ExtDirectAPI', $api, FALSE);
1360 }
1361 // Note: we need to iterate thru the object, because the addProvider method
1362 // does this only with multiple arguments
1363 $this->addExtOnReadyCode('
1364 (function() {
1365 TYPO3.ExtDirectToken = "' . $token . '";
1366 for (var api in Ext.app.ExtDirectAPI) {
1367 var provider = Ext.Direct.addProvider(Ext.app.ExtDirectAPI[api]);
1368 provider.on("beforecall", function(provider, transaction, meta) {
1369 if (transaction.data) {
1370 transaction.data[transaction.data.length] = TYPO3.ExtDirectToken;
1371 } else {
1372 transaction.data = [TYPO3.ExtDirectToken];
1373 }
1374 });
1375
1376 provider.on("call", function(provider, transaction, meta) {
1377 if (transaction.isForm) {
1378 transaction.params.securityToken = TYPO3.ExtDirectToken;
1379 }
1380 });
1381 }
1382 })();
1383
1384 var extDirectDebug = function(message, header, group) {
1385 var TYPO3ViewportInstance = null;
1386
1387 if (top && top.TYPO3 && typeof top.TYPO3.Backend === "object") {
1388 TYPO3ViewportInstance = top.TYPO3.Backend;
1389 } else if (typeof TYPO3 === "object" && typeof TYPO3.Backend === "object") {
1390 TYPO3ViewportInstance = TYPO3.Backend;
1391 }
1392
1393 if (TYPO3ViewportInstance !== null) {
1394 TYPO3ViewportInstance.DebugConsole.addTab(message, header, group);
1395 } else if (typeof console === "object") {
1396 console.log(message);
1397 } else {
1398 document.write(message);
1399 }
1400 };
1401
1402 Ext.Direct.on("exception", function(event) {
1403 if (event.code === Ext.Direct.exceptions.TRANSPORT && !event.where) {
1404 TYPO3.Flashmessage.display(
1405 TYPO3.Severity.error,
1406 TYPO3.l10n.localize("extDirect_timeoutHeader"),
1407 TYPO3.l10n.localize("extDirect_timeoutMessage"),
1408 30
1409 );
1410 } else {
1411 var backtrace = "";
1412 if (event.code === "parse") {
1413 extDirectDebug(
1414 "<p>" + event.xhr.responseText + "<\/p>",
1415 event.type,
1416 "ExtDirect - Exception"
1417 );
1418 } else if (event.code === "router") {
1419 TYPO3.Flashmessage.display(
1420 TYPO3.Severity.error,
1421 event.code,
1422 event.message,
1423 30
1424 );
1425 } else if (event.where) {
1426 backtrace = "<p style=\"margin-top: 20px;\">" +
1427 "<strong>Backtrace:<\/strong><br \/>" +
1428 event.where.replace(/#/g, "<br \/>#") +
1429 "<\/p>";
1430 extDirectDebug(
1431 "<p>" + event.message + "<\/p>" + backtrace,
1432 event.method,
1433 "ExtDirect - Exception"
1434 );
1435 }
1436
1437
1438 }
1439 });
1440
1441 Ext.Direct.on("event", function(event, provider) {
1442 if (typeof event.debug !== "undefined" && event.debug !== "") {
1443 extDirectDebug(event.debug, event.method, "ExtDirect - Debug");
1444 }
1445 });
1446 ',
1447 TRUE
1448 );
1449 }
1450
1451 /**
1452 * Adds CSS file
1453 *
1454 * @param string $file
1455 * @param string $rel
1456 * @param string $media
1457 * @param string $title
1458 * @param boolean $compress
1459 * @param boolean $forceOnTop
1460 * @param string $allWrap
1461 * @param boolean $excludeFromConcatenation
1462 * @return void
1463 */
1464 public function addCssFile($file, $rel = 'stylesheet', $media = 'all', $title = '', $compress = TRUE, $forceOnTop = FALSE, $allWrap = '', $excludeFromConcatenation = FALSE) {
1465 if (!isset($this->cssFiles[$file])) {
1466 $this->cssFiles[$file] = array(
1467 'file' => $file,
1468 'rel' => $rel,
1469 'media' => $media,
1470 'title' => $title,
1471 'compress' => $compress,
1472 'forceOnTop' => $forceOnTop,
1473 'allWrap' => $allWrap,
1474 'excludeFromConcatenation' => $excludeFromConcatenation,
1475 );
1476 }
1477 }
1478
1479 /**
1480 * Adds CSS inline code
1481 *
1482 * @param string $name
1483 * @param string $block
1484 * @param boolean $compress
1485 * @param boolean $forceOnTop
1486 * @return void
1487 */
1488 public function addCssInlineBlock($name, $block, $compress = FALSE, $forceOnTop = FALSE) {
1489 if (!isset($this->cssInline[$name]) && !empty($block)) {
1490 $this->cssInline[$name] = array(
1491 'code' => $block,
1492 'compress' => $compress,
1493 'forceOnTop' => $forceOnTop
1494 );
1495 }
1496 }
1497
1498 /**
1499 * Call this function if you need to include the jQuery library
1500 *
1501 * @param null|string $version The jQuery version that should be included, either "latest" or any available version
1502 * @param null|string $source The location of the jQuery source, can be "local", "google", "msn", "jquery" or just an URL to your jQuery lib
1503 * @param string $namespace The namespace in which the jQuery object of the specific version should be stored.
1504 * @return void
1505 * @throws UnexpectedValueException
1506 */
1507 public function loadJquery($version = NULL, $source = NULL, $namespace = self::JQUERY_NAMESPACE_DEFAULT) {
1508 // Set it to the version that is shipped with the TYPO3 core
1509 if ($version === NULL || $version === 'latest') {
1510 $version = self::JQUERY_VERSION_LATEST;
1511 }
1512
1513 // Check if the source is set, otherwise set it to "default"
1514 if ($source === NULL) {
1515 $source = 'local';
1516 }
1517
1518 if ($source === 'local' && !in_array($version, $this->availableLocalJqueryVersions)) {
1519 throw new UnexpectedValueException('The requested jQuery version is not available in the local filesystem.', 1341505305);
1520 }
1521
1522 if (!ctype_alnum($namespace)) {
1523 throw new UnexpectedValueException('The requested namespace contains non alphanumeric characters.', 1341571604);
1524 }
1525
1526 $this->jQueryVersions[$namespace] = array(
1527 'version' => $version,
1528 'source' => $source,
1529 );
1530 }
1531
1532 /**
1533 * Call function if you need the prototype library
1534 *
1535 * @return void
1536 */
1537 public function loadPrototype() {
1538 $this->addPrototype = TRUE;
1539 }
1540
1541 /**
1542 * Call function if you need the Scriptaculous library
1543 *
1544 * @param string $modules Add modules you need. use "all" if you need complete modules
1545 * @return void
1546 */
1547 public function loadScriptaculous($modules = 'all') {
1548 // Scriptaculous require prototype, so load prototype too.
1549 $this->addPrototype = TRUE;
1550 $this->addScriptaculous = TRUE;
1551 if ($modules) {
1552 if ($modules == 'all') {
1553 foreach ($this->addScriptaculousModules as $key => $value) {
1554 $this->addScriptaculousModules[$key] = TRUE;
1555 }
1556 } else {
1557 $mods = t3lib_div::trimExplode(',', $modules);
1558 foreach ($mods as $mod) {
1559 if (isset($this->addScriptaculousModules[strtolower($mod)])) {
1560 $this->addScriptaculousModules[strtolower($mod)] = TRUE;
1561 }
1562 }
1563 }
1564 }
1565 }
1566
1567 /**
1568 * call this function if you need the extJS library
1569 *
1570 * @param boolean $css Flag, if set the ext-css will be loaded
1571 * @param boolean $theme Flag, if set the ext-theme "grey" will be loaded
1572 * @param string $adapter Choose alternative adapter, possible values: yui, prototype, jquery
1573 * @return void
1574 */
1575 public function loadExtJS($css = TRUE, $theme = TRUE, $adapter = '') {
1576 if ($adapter) {
1577 // Empty $adapter will always load the ext adapter
1578 switch (t3lib_div::strtolower(trim($adapter))) {
1579 case self::EXTJS_ADAPTER_YUI :
1580 $this->extJSadapter = 'yui/ext-yui-adapter.js';
1581 break;
1582 case self::EXTJS_ADAPTER_PROTOTYPE :
1583 $this->extJSadapter = 'prototype/ext-prototype-adapter.js';
1584 break;
1585 case self::EXTJS_ADAPTER_JQUERY :
1586 $this->extJSadapter = 'jquery/ext-jquery-adapter.js';
1587 break;
1588 }
1589 }
1590 $this->addExtJS = TRUE;
1591 $this->extJStheme = $theme;
1592 $this->extJScss = $css;
1593 }
1594
1595 /**
1596 * Enables ExtJs QuickTips
1597 * Need extJs loaded
1598 *
1599 * @return void
1600 */
1601 public function enableExtJSQuickTips() {
1602 $this->enableExtJSQuickTips = TRUE;
1603 }
1604
1605 /**
1606 * Call function if you need the ExtCore library
1607 *
1608 * @return void
1609 */
1610 public function loadExtCore() {
1611 $this->addExtCore = TRUE;
1612 }
1613
1614 /**
1615 * Call function if you need the SVG library
1616 *
1617 * @return void
1618 */
1619 public function loadSvg() {
1620 $this->addSvg = TRUE;
1621 }
1622
1623 /**
1624 * Call this function to load debug version of ExtJS. Use this for development only
1625 * @return void
1626 */
1627 public function enableSvgDebug() {
1628 $this->enableSvgDebug = TRUE;
1629 }
1630
1631 /**
1632 * Call this function to force flash usage with SVG library
1633 * @return void
1634 */
1635 public function svgForceFlash() {
1636 $this->addMetaTag('<meta name="svg.render.forceflash" content="true" />');
1637 }
1638
1639 /**
1640 * Call this function to load debug version of ExtJS. Use this for development only
1641 * @return void
1642 */
1643 public function enableExtJsDebug() {
1644 $this->enableExtJsDebug = TRUE;
1645 }
1646
1647 /**
1648 * Call this function to load debug version of ExtCore. Use this for development only
1649 * @return void
1650 */
1651 public function enableExtCoreDebug() {
1652 $this->enableExtCoreDebug = TRUE;
1653 }
1654
1655 /**
1656 * Adds Javascript Inline Label. This will occur in TYPO3.lang - object
1657 * The label can be used in scripts with TYPO3.lang.<key>
1658 * Need extJs loaded
1659 *
1660 * @param string $key
1661 * @param string $value
1662 * @return void
1663 */
1664 public function addInlineLanguageLabel($key, $value) {
1665 $this->inlineLanguageLabels[$key] = $value;
1666 }
1667
1668 /**
1669 * Adds Javascript Inline Label Array. This will occur in TYPO3.lang - object
1670 * The label can be used in scripts with TYPO3.lang.<key>
1671 * Array will be merged with existing array.
1672 * Need extJs loaded
1673 *
1674 * @param array $array
1675 * @return void
1676 */
1677 public function addInlineLanguageLabelArray(array $array) {
1678 $this->inlineLanguageLabels = array_merge($this->inlineLanguageLabels, $array);
1679 }
1680
1681 /**
1682 * Gets labels to be used in JavaScript fetched from a locallang file.
1683 *
1684 * @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.
1685 * @param string $selectionPrefix Prefix to select the correct labels (default: '')
1686 * @param string $stripFromSelectionName Sub-prefix to be removed from label names in the result (default: '')
1687 * @param integer $errorMode Error mode (when file could not be found): 0 - syslog entry, 1 - do nothing, 2 - throw an exception
1688 * @return void
1689 */
1690 public function addInlineLanguageLabelFile($fileRef, $selectionPrefix = '', $stripFromSelectionName = '', $errorMode = 0) {
1691 $index = md5($fileRef . $selectionPrefix . $stripFromSelectionName);
1692 if ($fileRef && !isset($this->inlineLanguageLabelFiles[$index])) {
1693 $this->inlineLanguageLabelFiles[$index] = array(
1694 'fileRef' => $fileRef,
1695 'selectionPrefix' => $selectionPrefix,
1696 'stripFromSelectionName' => $stripFromSelectionName,
1697 'errorMode' => $errorMode
1698 );
1699 }
1700 }
1701
1702
1703 /**
1704 * Adds Javascript Inline Setting. This will occur in TYPO3.settings - object
1705 * The label can be used in scripts with TYPO3.setting.<key>
1706 * Need extJs loaded
1707 *
1708 * @param string $namespace
1709 * @param string $key
1710 * @param string $value
1711 * @return void
1712 */
1713 public function addInlineSetting($namespace, $key, $value) {
1714 if ($namespace) {
1715 if (strpos($namespace, '.')) {
1716 $parts = explode('.', $namespace);
1717 $a = &$this->inlineSettings;
1718 foreach ($parts as $part) {
1719 $a = &$a[$part];
1720 }
1721 $a[$key] = $value;
1722 } else {
1723 $this->inlineSettings[$namespace][$key] = $value;
1724 }
1725 } else {
1726 $this->inlineSettings[$key] = $value;
1727 }
1728 }
1729
1730 /**
1731 * Adds Javascript Inline Setting. This will occur in TYPO3.settings - object
1732 * The label can be used in scripts with TYPO3.setting.<key>
1733 * Array will be merged with existing array.
1734 * Need extJs loaded
1735 *
1736 * @param string $namespace
1737 * @param array $array
1738 * @return void
1739 */
1740 public function addInlineSettingArray($namespace, array $array) {
1741 if ($namespace) {
1742 if (strpos($namespace, '.')) {
1743 $parts = explode('.', $namespace);
1744 $a = &$this->inlineSettings;
1745 foreach ($parts as $part) {
1746 $a = &$a[$part];
1747 }
1748 $a = array_merge((array) $a, $array);
1749 } else {
1750 $this->inlineSettings[$namespace] = array_merge((array) $this->inlineSettings[$namespace], $array);
1751 }
1752 } else {
1753 $this->inlineSettings = array_merge($this->inlineSettings, $array);
1754 }
1755 }
1756
1757 /**
1758 * Adds content to body content
1759 *
1760 * @param string $content
1761 * @return void
1762 */
1763 public function addBodyContent($content) {
1764 $this->bodyContent .= $content;
1765 }
1766
1767 /*****************************************************/
1768 /* */
1769 /* Render Functions */
1770 /* */
1771 /*****************************************************/
1772
1773 /**
1774 * Render the section (Header or Footer)
1775 *
1776 * @param integer $part Section which should be rendered: self::PART_COMPLETE, self::PART_HEADER or self::PART_FOOTER
1777 * @return string Content of rendered section
1778 */
1779 public function render($part = self::PART_COMPLETE) {
1780 $this->prepareRendering();
1781
1782 list(
1783 $jsLibs,
1784 $jsFiles,
1785 $jsFooterFiles,
1786 $cssFiles,
1787 $jsInline,
1788 $cssInline,
1789 $jsFooterInline,
1790 $jsFooterLibs
1791 ) = $this->renderJavaScriptAndCss();
1792
1793 $metaTags = implode(LF, $this->metaTags);
1794 $markerArray = $this->getPreparedMarkerArray($jsLibs, $jsFiles, $jsFooterFiles, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs, $metaTags);
1795 $template = $this->getTemplateForPart($part);
1796 $this->reset();
1797
1798 return trim(t3lib_parsehtml::substituteMarkerArray($template, $markerArray, '###|###'));
1799 }
1800
1801 /**
1802 * Render the page but not the JavaScript and CSS Files
1803 *
1804 * @param string $substituteHash The hash that is used for the placehoder markers
1805 * @access private
1806 * @return string Content of rendered section
1807 */
1808 public function renderPageWithUncachedObjects($substituteHash) {
1809 $this->prepareRendering();
1810
1811 $markerArray = $this->getPreparedMarkerArrayForPageWithUncachedObjects($substituteHash);
1812 $template = $this->getTemplateForPart(self::PART_COMPLETE);
1813
1814 return trim(t3lib_parsehtml::substituteMarkerArray($template, $markerArray, '###|###'));
1815 }
1816
1817 /**
1818 * Renders the JavaScript and CSS files that have been added during processing
1819 * of uncached content objects (USER_INT, COA_INT)
1820 *
1821 * @param string $cachedPageContent
1822 * @param string $substituteHash The hash that is used for the placehoder markers
1823 * @access private
1824 * @return string
1825 */
1826 public function renderJavaScriptAndCssForProcessingOfUncachedContentObjects($cachedPageContent, $substituteHash) {
1827 $this->prepareRendering();
1828
1829 list(
1830 $jsLibs,
1831 $jsFiles,
1832 $jsFooterFiles,
1833 $cssFiles,
1834 $jsInline,
1835 $cssInline,
1836 $jsFooterInline,
1837 $jsFooterLibs
1838 ) = $this->renderJavaScriptAndCss();
1839
1840 $markerArray = array(
1841 '<!-- ###CSS_INCLUDE' . $substituteHash . '### -->' => $cssFiles,
1842 '<!-- ###CSS_INLINE' . $substituteHash . '### -->' => $cssInline,
1843 '<!-- ###JS_INLINE' . $substituteHash . '### -->' => $jsInline,
1844 '<!-- ###JS_INCLUDE' . $substituteHash . '### -->' => $jsFiles,
1845 '<!-- ###JS_LIBS' . $substituteHash . '### -->' => $jsLibs,
1846 '<!-- ###HEADERDATA' . $substituteHash . '### -->' => implode(LF, $this->headerData),
1847 '<!-- ###FOOTERDATA' . $substituteHash . '### -->' => implode(LF, $this->footerData),
1848 '<!-- ###JS_LIBS_FOOTER' . $substituteHash . '### -->' => $jsFooterLibs,
1849 '<!-- ###JS_INCLUDE_FOOTER' . $substituteHash . '### -->' => $jsFooterFiles,
1850 '<!-- ###JS_INLINE_FOOTER' . $substituteHash . '### -->' => $jsFooterInline,
1851 );
1852
1853 foreach ($markerArray as $placeHolder => $content) {
1854 $cachedPageContent = str_replace($placeHolder, $content, $cachedPageContent);
1855 }
1856
1857
1858 $this->reset();
1859
1860 return $cachedPageContent;
1861 }
1862
1863 /**
1864 * Remove ending slashes from static header block
1865 * if the page is beeing rendered as html (not xhtml)
1866 * and define property $this->endingSlash for further use
1867 *
1868 * @return void
1869 */
1870 protected function prepareRendering() {
1871 if ($this->getRenderXhtml()) {
1872 $this->endingSlash = ' /';
1873 } else {
1874 $this->metaCharsetTag = str_replace(' />', '>', $this->metaCharsetTag);
1875 $this->baseUrlTag = str_replace(' />', '>', $this->baseUrlTag);
1876 $this->shortcutTag = str_replace(' />', '>', $this->shortcutTag);
1877
1878 $this->endingSlash = '';
1879 }
1880 }
1881
1882 /**
1883 * Renders all JavaScript and CSS
1884 *
1885 * @return array<string>
1886 */
1887 protected function renderJavaScriptAndCss() {
1888 $this->executePreRenderHook();
1889
1890 $mainJsLibs = $this->renderMainJavaScriptLibraries();
1891
1892 if ($this->concatenateFiles || $this->concatenateJavascript || $this->concatenateCss) {
1893 // Do the file concatenation
1894 $this->doConcatenate();
1895 }
1896 if ($this->compressCss || $this->compressJavascript) {
1897 // Do the file compression
1898 $this->doCompress();
1899 }
1900
1901 $this->executeRenderPostTransformHook();
1902
1903 $cssFiles = $this->renderCssFiles();
1904 $cssInline = $this->renderCssInline();
1905 list($jsLibs, $jsFooterLibs) = $this->renderAdditionalJavaScriptLibraries();
1906 list($jsFiles, $jsFooterFiles) = $this->renderJavaScriptFiles();
1907 list($jsInline, $jsFooterInline) = $this->renderInlineJavaScript();
1908
1909 $jsLibs = $mainJsLibs . $jsLibs;
1910
1911 if ($this->moveJsFromHeaderToFooter) {
1912 $jsFooterLibs = $jsLibs . LF . $jsFooterLibs;
1913 $jsLibs = '';
1914 $jsFooterFiles = $jsFiles . LF . $jsFooterFiles;
1915 $jsFiles = '';
1916 $jsFooterInline = $jsInline . LF . $jsFooterInline;
1917 $jsInline = '';
1918 }
1919
1920 $this->executePostRenderHook($jsLibs, $jsFiles, $jsFooterFiles, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs);
1921
1922 return array($jsLibs, $jsFiles, $jsFooterFiles, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs);
1923 }
1924
1925 /**
1926 * Fills the marker array with the given strings and trims each value
1927 *
1928 * @param $jsLibs string
1929 * @param $jsFiles string
1930 * @param $jsFooterFiles string
1931 * @param $cssFiles string
1932 * @param $jsInline string
1933 * @param $cssInline string
1934 * @param $jsFooterInline string
1935 * @param $jsFooterLibs string
1936 * @param $metaTags string
1937 * @return array Marker array
1938 */
1939 protected function getPreparedMarkerArray($jsLibs, $jsFiles, $jsFooterFiles, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs, $metaTags) {
1940 $markerArray = array(
1941 'XMLPROLOG_DOCTYPE' => $this->xmlPrologAndDocType,
1942 'HTMLTAG' => $this->htmlTag,
1943 'HEADTAG' => $this->headTag,
1944 'METACHARSET' => $this->charSet ? str_replace('|', htmlspecialchars($this->charSet), $this->metaCharsetTag) : '',
1945 'INLINECOMMENT' => $this->inlineComments ? LF . LF . '<!-- ' . LF . implode(LF, $this->inlineComments) . '-->' . LF . LF : '',
1946 'BASEURL' => $this->baseUrl ? str_replace('|', $this->baseUrl, $this->baseUrlTag) : '',
1947 'SHORTCUT' => $this->favIcon ? sprintf($this->shortcutTag, htmlspecialchars($this->favIcon), $this->iconMimeType) : '',
1948 'CSS_INCLUDE' => $cssFiles,
1949 'CSS_INLINE' => $cssInline,
1950 'JS_INLINE' => $jsInline,
1951 'JS_INCLUDE' => $jsFiles,
1952 'JS_LIBS' => $jsLibs,
1953 'TITLE' => $this->title ? str_replace('|', htmlspecialchars($this->title), $this->titleTag) : '',
1954 'META' => $metaTags,
1955 'HEADERDATA' => $this->headerData ? implode(LF, $this->headerData) : '',
1956 'FOOTERDATA' => $this->footerData ? implode(LF, $this->footerData) : '',
1957 'JS_LIBS_FOOTER' => $jsFooterLibs,
1958 'JS_INCLUDE_FOOTER' => $jsFooterFiles,
1959 'JS_INLINE_FOOTER' => $jsFooterInline,
1960 'BODY' => $this->bodyContent,
1961 );
1962 $markerArray = array_map('trim', $markerArray);
1963
1964 return $markerArray;
1965 }
1966
1967 /**
1968 * Fills the marker array with the given strings and trims each value
1969 *
1970 * @param string $substituteHash The hash that is used for the placehoder markers
1971 * @return array Marker array
1972 */
1973 protected function getPreparedMarkerArrayForPageWithUncachedObjects($substituteHash) {
1974 $markerArray = array(
1975 'XMLPROLOG_DOCTYPE' => $this->xmlPrologAndDocType,
1976 'HTMLTAG' => $this->htmlTag,
1977 'HEADTAG' => $this->headTag,
1978 'METACHARSET' => $this->charSet ? str_replace('|', htmlspecialchars($this->charSet), $this->metaCharsetTag) : '',
1979 'INLINECOMMENT' => $this->inlineComments ? LF . LF . '<!-- ' . LF . implode(LF, $this->inlineComments) . '-->' . LF . LF : '',
1980 'BASEURL' => $this->baseUrl ? str_replace('|', $this->baseUrl, $this->baseUrlTag) : '',
1981 'SHORTCUT' => $this->favIcon ? sprintf($this->shortcutTag, htmlspecialchars($this->favIcon), $this->iconMimeType) : '',
1982 'TITLE' => $this->title ? str_replace('|', htmlspecialchars($this->title), $this->titleTag) : '',
1983 'META' => implode(LF, $this->metaTags),
1984 'BODY' => $this->bodyContent,
1985 'CSS_INCLUDE' => '<!-- ###CSS_INCLUDE' . $substituteHash . '### -->',
1986 'CSS_INLINE' => '<!-- ###CSS_INLINE' . $substituteHash . '### -->',
1987 'JS_INLINE' => '<!-- ###JS_INLINE' . $substituteHash . '### -->',
1988 'JS_INCLUDE' => '<!-- ###JS_INCLUDE' . $substituteHash . '### -->',
1989 'JS_LIBS' => '<!-- ###JS_LIBS' . $substituteHash . '### -->',
1990 'HEADERDATA' => '<!-- ###HEADERDATA' . $substituteHash . '### -->',
1991 'FOOTERDATA' => '<!-- ###FOOTERDATA' . $substituteHash . '### -->',
1992 'JS_LIBS_FOOTER' => '<!-- ###JS_LIBS_FOOTER' . $substituteHash . '### -->',
1993 'JS_INCLUDE_FOOTER' => '<!-- ###JS_INCLUDE_FOOTER' . $substituteHash . '### -->',
1994 'JS_INLINE_FOOTER' => '<!-- ###JS_INLINE_FOOTER' . $substituteHash . '### -->',
1995 );
1996 $markerArray = array_map('trim', $markerArray);
1997
1998 return $markerArray;
1999 }
2000
2001 /**
2002 * Reads the template file and returns the requested part as string
2003 *
2004 * @param integer $part
2005 * @return string
2006 */
2007 protected function getTemplateForPart($part) {
2008 $templateFile = t3lib_div::getFileAbsFileName($this->templateFile, TRUE);
2009 $template = t3lib_div::getUrl($templateFile);
2010
2011 if ($this->removeLineBreaksFromTemplate) {
2012 $template = strtr($template, array(LF => '', CR => ''));
2013 }
2014 if ($part != self::PART_COMPLETE) {
2015 $templatePart = explode('###BODY###', $template);
2016 $template = $templatePart[$part - 1];
2017 }
2018
2019 return $template;
2020 }
2021
2022 /**
2023 * Helper function for render the main JavaScript libraries,
2024 * currently: jQuery, prototype, SVG, ExtJs
2025 *
2026 * @return string Content with JavaScript libraries
2027 */
2028 protected function renderMainJavaScriptLibraries() {
2029 $out = '';
2030
2031 if ($this->addSvg) {
2032 $out .= '<script src="' . $this->processJsFile($this->backPath . $this->svgPath . 'svg.js') .
2033 '" data-path="' . $this->backPath . $this->svgPath .
2034 '"' . ($this->enableSvgDebug ? ' data-debug="true"' : '') . '></script>';
2035 }
2036
2037 // Include jQuery Core for each namespace, depending on the version and source
2038 if (!empty($this->jQueryVersions)) {
2039 foreach ($this->jQueryVersions as $namespace => $jQueryVersion) {
2040 $out .= $this->renderJqueryScriptTag(
2041 $jQueryVersion['version'],
2042 $jQueryVersion['source'],
2043 $namespace
2044 );
2045 }
2046 }
2047
2048 if ($this->addPrototype) {
2049 $out .= '<script src="' . $this->processJsFile($this->backPath . $this->prototypePath . 'prototype.js') .
2050 '" type="text/javascript"></script>' . LF;
2051 unset($this->jsFiles[$this->backPath . $this->prototypePath . 'prototype.js']);
2052 }
2053
2054 if ($this->addScriptaculous) {
2055 $mods = array();
2056 foreach ($this->addScriptaculousModules as $key => $value) {
2057 if ($this->addScriptaculousModules[$key]) {
2058 $mods[] = $key;
2059 }
2060 }
2061 // Resolve dependencies
2062 if (in_array('dragdrop', $mods) || in_array('controls', $mods)) {
2063 $mods = array_merge(array('effects'), $mods);
2064 }
2065
2066 if (count($mods)) {
2067 foreach ($mods as $module) {
2068 $out .= '<script src="' . $this->processJsFile($this->backPath .
2069 $this->scriptaculousPath . $module . '.js') . '" type="text/javascript"></script>' . LF;
2070 unset($this->jsFiles[$this->backPath . $this->scriptaculousPath . $module . '.js']);
2071 }
2072 }
2073 $out .= '<script src="' . $this->processJsFile($this->backPath . $this->scriptaculousPath .
2074 'scriptaculous.js') . '" type="text/javascript"></script>' . LF;
2075 unset($this->jsFiles[$this->backPath . $this->scriptaculousPath . 'scriptaculous.js']);
2076 }
2077
2078 // Include extCore, but only if ExtJS is not included
2079 if ($this->addExtCore && !$this->addExtJS) {
2080 $out .= '<script src="' . $this->processJsFile($this->backPath .
2081 $this->extCorePath . 'ext-core' . ($this->enableExtCoreDebug ? '-debug' : '') . '.js') .
2082 '" type="text/javascript"></script>' . LF;
2083 unset($this->jsFiles[$this->backPath . $this->extCorePath . 'ext-core' . ($this->enableExtCoreDebug ? '-debug' : '') . '.js']);
2084 }
2085
2086 // Include extJS
2087 if ($this->addExtJS) {
2088 // Use the base adapter all the time
2089 $out .= '<script src="' . $this->processJsFile($this->backPath . $this->extJsPath .
2090 'adapter/' . ($this->enableExtJsDebug ?
2091 str_replace('.js', '-debug.js', $this->extJSadapter) : $this->extJSadapter)) .
2092 '" type="text/javascript"></script>' . LF;
2093 $out .= '<script src="' . $this->processJsFile($this->backPath . $this->extJsPath .
2094 'ext-all' . ($this->enableExtJsDebug ? '-debug' : '') . '.js') .
2095 '" type="text/javascript"></script>' . LF;
2096
2097 // Add extJS localization
2098 // Load standard ISO mapping and modify for use with ExtJS
2099 $localeMap = $this->locales->getIsoMapping();
2100 $localeMap[''] = 'en';
2101 $localeMap['default'] = 'en';
2102 // Greek
2103 $localeMap['gr'] = 'el_GR';
2104 // Norwegian Bokmaal
2105 $localeMap['no'] = 'no_BO';
2106 // Swedish
2107 $localeMap['se'] = 'se_SV';
2108
2109 $extJsLang = isset($localeMap[$this->lang]) ? $localeMap[$this->lang] : $this->lang;
2110 // TODO autoconvert file from UTF8 to current BE charset if necessary!!!!
2111 $extJsLocaleFile = $this->extJsPath . 'locale/ext-lang-' . $extJsLang . '.js';
2112 if (file_exists(PATH_typo3 . $extJsLocaleFile)) {
2113 $out .= '<script src="' . $this->processJsFile($this->backPath .
2114 $extJsLocaleFile) . '" type="text/javascript" charset="utf-8"></script>' . LF;
2115 }
2116
2117 // Remove extjs from JScodeLibArray
2118 unset(
2119 $this->jsFiles[$this->backPath . $this->extJsPath . 'ext-all.js'],
2120 $this->jsFiles[$this->backPath . $this->extJsPath . 'ext-all-debug.js']
2121 );
2122 }
2123
2124 if (count($this->inlineLanguageLabelFiles)) {
2125 foreach ($this->inlineLanguageLabelFiles as $languageLabelFile) {
2126 $this->includeLanguageFileForInline(
2127 $languageLabelFile['fileRef'],
2128 $languageLabelFile['selectionPrefix'],
2129 $languageLabelFile['stripFromSelectionName'],
2130 $languageLabelFile['$errorMode']
2131 );
2132 }
2133 }
2134 unset($this->inlineLanguageLabelFiles);
2135
2136 // Convert labels/settings back to UTF-8 since json_encode() only works with UTF-8:
2137 if ($this->getCharSet() !== 'utf-8') {
2138 if ($this->inlineLanguageLabels) {
2139 $this->csConvObj->convArray($this->inlineLanguageLabels, $this->getCharSet(), 'utf-8');
2140 }
2141 if ($this->inlineSettings) {
2142 $this->csConvObj->convArray($this->inlineSettings, $this->getCharSet(), 'utf-8');
2143 }
2144 }
2145
2146 $inlineSettings = $this->inlineLanguageLabels ? 'TYPO3.lang = ' . json_encode($this->inlineLanguageLabels) . ';' : '';
2147 $inlineSettings .= $this->inlineSettings ? 'TYPO3.settings = ' . json_encode($this->inlineSettings) . ';' : '';
2148
2149 if ($this->addExtCore || $this->addExtJS) {
2150 // Set clear.gif, move it on top, add handler code
2151 $code = '';
2152 if (count($this->extOnReadyCode)) {
2153 foreach ($this->extOnReadyCode as $block) {
2154 $code .= $block;
2155 }
2156 }
2157
2158 $out .= $this->inlineJavascriptWrap[0] . '
2159 Ext.ns("TYPO3");
2160 Ext.BLANK_IMAGE_URL = "' . htmlspecialchars(t3lib_div::locationHeaderUrl($this->backPath . 'gfx/clear.gif')) . '";' . LF .
2161 $inlineSettings .
2162 'Ext.onReady(function() {' .
2163 ($this->enableExtJSQuickTips ? 'Ext.QuickTips.init();' . LF : '') . $code .
2164 ' });' . $this->inlineJavascriptWrap[1];
2165 unset ($this->extOnReadyCode);
2166
2167 // Include TYPO3.l10n object
2168 if (TYPO3_MODE === 'BE') {
2169 $out .= '<script src="' . $this->processJsFile($this->backPath . 'sysext/lang/res/js/be/typo3lang.js') . '" type="text/javascript" charset="utf-8"></script>' . LF;
2170 }
2171
2172 if ($this->extJStheme) {
2173 if (isset($GLOBALS['TBE_STYLES']['extJS']['theme'])) {
2174 $this->addCssFile($this->backPath . $GLOBALS['TBE_STYLES']['extJS']['theme'], 'stylesheet', 'all', '', TRUE, TRUE);
2175 } else {
2176 $this->addCssFile($this->backPath . $this->extJsPath . 'resources/css/xtheme-blue.css', 'stylesheet', 'all', '', TRUE, TRUE);
2177 }
2178 }
2179 if ($this->extJScss) {
2180 if (isset($GLOBALS['TBE_STYLES']['extJS']['all'])) {
2181 $this->addCssFile($this->backPath . $GLOBALS['TBE_STYLES']['extJS']['all'], 'stylesheet', 'all', '', TRUE, TRUE);
2182 } else {
2183 $this->addCssFile($this->backPath . $this->extJsPath . 'resources/css/ext-all-notheme.css', 'stylesheet', 'all', '', TRUE, TRUE);
2184 }
2185 }
2186 } else {
2187 if ($inlineSettings) {
2188 $out .= $this->inlineJavascriptWrap[0] . $inlineSettings . $this->inlineJavascriptWrap[1];
2189 }
2190 }
2191
2192 return $out;
2193 }
2194
2195 /**
2196 * Renders the HTML script tag for the given jQuery version.
2197 *
2198 * @param string $version The jQuery version that should be included, either "latest" or any available version
2199 * @param string $source The location of the jQuery source, can be "local", "google", "msn" or "jquery"
2200 * @param string $namespace The namespace in which the jQuery object of the specific version should be stored
2201 * @return string
2202 */
2203 protected function renderJqueryScriptTag($version, $source, $namespace) {
2204
2205 switch (TRUE) {
2206 case isset($this->jQueryCdnUrls[$source]):
2207 if ($this->enableJqueryDebug) {
2208 $minifyPart = '';
2209 } else {
2210 $minifyPart = '.min';
2211 }
2212 $jQueryFileName = sprintf($this->jQueryCdnUrls[$source], $version, $minifyPart);
2213 break;
2214
2215 // Local source - include the latest
2216 case $source === 'local':
2217 $jQueryFileName = $this->backPath . $this->jQueryPath . 'jquery-' . rawurlencode($version);
2218
2219 if ($this->enableJqueryDebug) {
2220 $jQueryFileName .= '.js';
2221 } else {
2222 $jQueryFileName .= '.min.js';
2223 }
2224 break;
2225 // No special key found, assume the source is a valid URL to a jQuery library
2226 default:
2227 $jQueryFileName = $source;
2228 }
2229
2230 // Include the jQuery Core
2231 $scriptTag = '<script src="' . htmlspecialchars($jQueryFileName) . '" type="text/javascript"></script>' . LF;
2232
2233 // Set the noConflict mode to be available via "TYPO3.jQuery" in all installations
2234
2235 switch ($namespace) {
2236 case self::JQUERY_NAMESPACE_DEFAULT_NOCONFLICT:
2237 $scriptTag .= t3lib_div::wrapJS(
2238 'jQuery.noConflict();'
2239 );
2240 break;
2241 case self::JQUERY_NAMESPACE_NONE:
2242 break;
2243 case self::JQUERY_NAMESPACE_DEFAULT:
2244 default:
2245 $scriptTag .= t3lib_div::wrapJS(
2246 'var TYPO3 = TYPO3 || {}; TYPO3.' . $namespace . ' = jQuery.noConflict(true);'
2247 );
2248 break;
2249 }
2250
2251 return $scriptTag;
2252 }
2253
2254 /**
2255 * Render CSS files
2256 *
2257 * @return string
2258 */
2259 protected function renderCssFiles() {
2260 $cssFiles = '';
2261 if (count($this->cssFiles)) {
2262 foreach ($this->cssFiles as $file => $properties) {
2263 $file = t3lib_div::resolveBackPath($file);
2264 $file = t3lib_div::createVersionNumberedFilename($file);
2265 $tag = '<link rel="' . htmlspecialchars($properties['rel']) .
2266 '" type="text/css" href="' . htmlspecialchars($file) .
2267 '" media="' . htmlspecialchars($properties['media']) .
2268 '"' . ($properties['title'] ? ' title="' . htmlspecialchars($properties['title']) . '"' : '') . $this->endingSlash . '>';
2269 if ($properties['allWrap'] && strpos($properties['allWrap'], '|') !== FALSE) {
2270 $tag = str_replace('|', $tag, $properties['allWrap']);
2271 }
2272 if ($properties['forceOnTop']) {
2273 $cssFiles = $tag . LF . $cssFiles;
2274 } else {
2275 $cssFiles .= LF . $tag;
2276 }
2277 }
2278 }
2279
2280 return $cssFiles;
2281 }
2282
2283 /**
2284 * Render inline CSS
2285 *
2286 * @return string
2287 */
2288 protected function renderCssInline() {
2289 $cssInline = '';
2290 if (count($this->cssInline)) {
2291 foreach ($this->cssInline as $name => $properties) {
2292 if ($properties['forceOnTop']) {
2293 $cssInline = '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF . $cssInline;
2294 } else {
2295 $cssInline .= '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF;
2296 }
2297 }
2298 $cssInline = $this->inlineCssWrap[0] . $cssInline . $this->inlineCssWrap[1];
2299 }
2300
2301 return $cssInline;
2302 }
2303
2304 /**
2305 * Render JavaScipt libraries
2306 *
2307 * @return array<string> jsLibs and jsFooterLibs strings
2308 */
2309 protected function renderAdditionalJavaScriptLibraries() {
2310 $jsLibs = '';
2311 $jsFooterLibs = '';
2312 if (count($this->jsLibs)) {
2313 foreach ($this->jsLibs as $properties) {
2314 $properties['file'] = t3lib_div::resolveBackPath($properties['file']);
2315 $properties['file'] = t3lib_div::createVersionNumberedFilename($properties['file']);
2316 $tag = '<script src="' . htmlspecialchars($properties['file']) . '" type="' . htmlspecialchars($properties['type']) . '"></script>';
2317 if ($properties['allWrap'] && strpos($properties['allWrap'], '|') !== FALSE) {
2318 $tag = str_replace('|', $tag, $properties['allWrap']);
2319 }
2320 if ($properties['forceOnTop']) {
2321 if ($properties['section'] === self::PART_HEADER) {
2322 $jsLibs = $tag . LF . $jsLibs;
2323 } else {
2324 $jsFooterLibs = $tag . LF . $jsFooterLibs;
2325 }
2326 } else {
2327 if ($properties['section'] === self::PART_HEADER) {
2328 $jsLibs .= LF . $tag;
2329 } else {
2330 $jsFooterLibs .= LF . $tag;
2331 }
2332 }
2333 }
2334 }
2335 if ($this->moveJsFromHeaderToFooter) {
2336 $jsFooterLibs = $jsLibs . LF . $jsFooterLibs;
2337 $jsLibs = '';
2338 }
2339
2340 return array($jsLibs, $jsFooterLibs);
2341 }
2342
2343 /**
2344 * Render JavaScript files
2345 *
2346 * @return array<string> jsFiles and jsFooterFiles strings
2347 */
2348 protected function renderJavaScriptFiles() {
2349 $jsFiles = '';
2350 $jsFooterFiles = '';
2351 if (count($this->jsFiles)) {
2352 foreach ($this->jsFiles as $file => $properties) {
2353 $file = t3lib_div::resolveBackPath($file);
2354 $file = t3lib_div::createVersionNumberedFilename($file);
2355 $tag = '<script src="' . htmlspecialchars($file) . '" type="' . htmlspecialchars($properties['type']) . '"></script>';
2356 if ($properties['allWrap'] && strpos($properties['allWrap'], '|') !== FALSE) {
2357 $tag = str_replace('|', $tag, $properties['allWrap']);
2358 }
2359 if ($properties['forceOnTop']) {
2360 if ($properties['section'] === self::PART_HEADER) {
2361 $jsFiles = $tag . LF . $jsFiles;
2362 } else {
2363 $jsFooterFiles = $tag . LF . $jsFooterFiles;
2364 }
2365 } else {
2366 if ($properties['section'] === self::PART_HEADER) {
2367 $jsFiles .= LF . $tag;
2368 } else {
2369 $jsFooterFiles .= LF . $tag;
2370 }
2371 }
2372 }
2373 }
2374 if ($this->moveJsFromHeaderToFooter) {
2375 $jsFooterFiles = $jsFiles . LF . $jsFooterFiles;
2376 $jsFiles = '';
2377 }
2378
2379 return array($jsFiles, $jsFooterFiles);
2380 }
2381
2382 /**
2383 * Render inline JavaScript
2384 *
2385 * @return array<string> jsInline and jsFooterInline string
2386 */
2387 protected function renderInlineJavaScript() {
2388 $jsInline = '';
2389 $jsFooterInline = '';
2390 if (count($this->jsInline)) {
2391 foreach ($this->jsInline as $name => $properties) {
2392 if ($properties['forceOnTop']) {
2393 if ($properties['section'] === self::PART_HEADER) {
2394 $jsInline = '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF . $jsInline;
2395 } else {
2396 $jsFooterInline = '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF . $jsFooterInline;
2397 }
2398 } else {
2399 if ($properties['section'] === self::PART_HEADER) {
2400 $jsInline .= '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF;
2401 } else {
2402 $jsFooterInline .= '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF;
2403 }
2404 }
2405 }
2406 }
2407 if ($jsInline) {
2408 $jsInline = $this->inlineJavascriptWrap[0] . $jsInline . $this->inlineJavascriptWrap[1];
2409 }
2410
2411 if ($jsFooterInline) {
2412 $jsFooterInline = $this->inlineJavascriptWrap[0] . $jsFooterInline . $this->inlineJavascriptWrap[1];
2413 }
2414 if ($this->moveJsFromHeaderToFooter) {
2415 $jsFooterInline = $jsInline . LF . $jsFooterInline;
2416 $jsInline = '';
2417 }
2418
2419 return array($jsInline, $jsFooterInline);
2420 }
2421
2422 /**
2423 * Include language file for inline usage
2424 *
2425 * @param string $fileRef
2426 * @param string $selectionPrefix
2427 * @param string $stripFromSelectionName
2428 * @param integer $errorMode
2429 * @return void
2430 * @throws RuntimeException
2431 */
2432 protected function includeLanguageFileForInline($fileRef, $selectionPrefix = '', $stripFromSelectionName = '', $errorMode = 0) {
2433 if (!isset($this->lang) || !isset($this->charSet)) {
2434 throw new RuntimeException('Language and character encoding are not set.', 1284906026);
2435 }
2436
2437 $labelsFromFile = array();
2438 $allLabels = t3lib_div::readLLfile($fileRef, $this->lang, $this->charSet, $errorMode);
2439
2440 // Regular expression to strip the selection prefix and possibly something from the label name:
2441 $labelPattern = '#^' . preg_quote($selectionPrefix, '#') . '(' . preg_quote($stripFromSelectionName, '#') . ')?#';
2442
2443 if ($allLabels !== FALSE) {
2444 // Merge language specific translations:
2445 if ($this->lang !== 'default' && isset($allLabels[$this->lang])) {
2446 $labels = array_merge($allLabels['default'], $allLabels[$this->lang]);
2447 } else {
2448 $labels = $allLabels['default'];
2449 }
2450
2451 // Iterate through all locallang labels:
2452 foreach ($labels as $label => $value) {
2453 if ($selectionPrefix === '') {
2454 $labelsFromFile[$label] = $value;
2455 } elseif (strpos($label, $selectionPrefix) === 0) {
2456 $key = preg_replace($labelPattern, '', $label);
2457 $labelsFromFile[$label] = $value;
2458 }
2459 }
2460
2461 $this->inlineLanguageLabels = array_merge($this->inlineLanguageLabels, $labelsFromFile);
2462 }
2463 }
2464
2465 /*****************************************************/
2466 /* */
2467 /* Tools */
2468 /* */
2469 /*****************************************************/
2470
2471 /**
2472 * Concatenate files into one file
2473 * registered handler
2474 *
2475 * @return void
2476 */
2477 protected function doConcatenate() {
2478 $this->doConcatenateCss();
2479 $this->doConcatenateJavaScript();
2480 }
2481
2482 /**
2483 * Concatenate JavaScript files according to the configuration.
2484 *
2485 * @return void
2486 */
2487 protected function doConcatenateJavaScript() {
2488 if ($this->concatenateFiles || $this->concatenateJavascript) {
2489 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsConcatenateHandler'])) {
2490 // use external concatenation routine
2491 $params = array(
2492 'jsLibs' => &$this->jsLibs,
2493 'jsFiles' => &$this->jsFiles,
2494 'jsFooterFiles' => &$this->jsFooterFiles,
2495 'headerData' => &$this->headerData,
2496 'footerData' => &$this->footerData,
2497 );
2498 t3lib_div::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsConcatenateHandler'], $params, $this);
2499 } else {
2500 $this->jsLibs = $this->getCompressor()->concatenateJsFiles($this->jsLibs);
2501 $this->jsFiles = $this->getCompressor()->concatenateJsFiles($this->jsFiles);
2502 $this->jsFooterFiles = $this->getCompressor()->concatenateJsFiles($this->jsFooterFiles);
2503 }
2504 }
2505 }
2506
2507 /**
2508 * Concatenate CSS files according to configuration.
2509 *
2510 * @return void
2511 */
2512 protected function doConcatenateCss() {
2513 if ($this->concatenateFiles || $this->concatenateCss) {
2514 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssConcatenateHandler'])) {
2515 // use external concatenation routine
2516 $params = array(
2517 'cssFiles' => &$this->cssFiles,
2518 'headerData' => &$this->headerData,
2519 'footerData' => &$this->footerData,
2520 );
2521 t3lib_div::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssConcatenateHandler'], $params, $this);
2522 } else {
2523 $cssOptions = array();
2524 if (TYPO3_MODE === 'BE') {
2525 $cssOptions = array('baseDirectories' => $GLOBALS['TBE_TEMPLATE']->getSkinStylesheetDirectories());
2526 }
2527 $this->cssFiles = $this->getCompressor()->concatenateCssFiles($this->cssFiles, $cssOptions);
2528 }
2529 }
2530 }
2531
2532 /**
2533 * Compresses inline code
2534 *
2535 * @return void
2536 */
2537 protected function doCompress() {
2538 $this->doCompressJavaScript();
2539 $this->doCompressCss();
2540 }
2541
2542 /**
2543 * Compresses CSS according to configuration.
2544 *
2545 * @return void
2546 */
2547 protected function doCompressCss() {
2548 if ($this->compressCss) {
2549 // Use external compression routine
2550 $params = array(
2551 'cssInline' => &$this->cssInline,
2552 'cssFiles' => &$this->cssFiles,
2553 'headerData' => &$this->headerData,
2554 'footerData' => &$this->footerData,
2555 );
2556
2557 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssCompressHandler'])) {
2558 // use external concatenation routine
2559 t3lib_div::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssCompressHandler'], $params, $this);
2560 } else {
2561 $this->cssFiles = $this->getCompressor()->compressCssFiles($this->cssFiles);
2562 }
2563 }
2564 }
2565
2566 /**
2567 * Compresses JavaScript according to configuration.
2568 *
2569 * @return void
2570 */
2571 protected function doCompressJavaScript() {
2572 if ($this->compressJavascript) {
2573 if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsCompressHandler'])) {
2574 // Use external compression routine
2575 $params = array(
2576 'jsInline' => &$this->jsInline,
2577 'jsFooterInline' => &$this->jsFooterInline,
2578 'jsLibs' => &$this->jsLibs,
2579 'jsFiles' => &$this->jsFiles,
2580 'jsFooterFiles' => &$this->jsFooterFiles,
2581 'headerData' => &$this->headerData,
2582 'footerData' => &$this->footerData,
2583 );
2584 t3lib_div::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsCompressHandler'], $params, $this);
2585 } else {
2586 // Traverse the arrays, compress files
2587 if (count($this->jsInline)) {
2588 foreach ($this->jsInline as $name => $properties) {
2589 if ($properties['compress']) {
2590 $error = '';
2591 $this->jsInline[$name]['code'] = t3lib_div::minifyJavaScript($properties['code'], $error);
2592 if ($error) {
2593 $this->compressError .= 'Error with minify JS Inline Block "' . $name . '": ' . $error . LF;
2594 }
2595 }
2596 }
2597 }
2598 $this->jsLibs = $this->getCompressor()->compressJsFiles($this->jsLibs);
2599 $this->jsFiles = $this->getCompressor()->compressJsFiles($this->jsFiles);
2600 $this->jsFooterFiles = $this->getCompressor()->compressJsFiles($this->jsFooterFiles);
2601 }
2602 }
2603 }
2604
2605 /**
2606 * Returns instance of t3lib_Compressor
2607 *
2608 * @return t3lib_Compressor Instance of t3lib_Compressor
2609 */
2610 protected function getCompressor() {
2611 if ($this->compressor === NULL) {
2612 $this->compressor = t3lib_div::makeInstance('t3lib_Compressor');
2613 }
2614 return $this->compressor;
2615 }
2616
2617 /**
2618 * Processes a Javascript file dependent on the current context
2619 *
2620 * Adds the version number for Frontend, compresses the file for Backend
2621 *
2622 * @param string $filename Filename
2623 * @return string New filename
2624 */
2625 protected function processJsFile($filename) {
2626 switch (TYPO3_MODE) {
2627 case 'FE':
2628 if ($this->compressJavascript) {
2629 $filename = $this->getCompressor()->compressJsFile($filename);
2630 } else {
2631 $filename = t3lib_div::createVersionNumberedFilename($filename);
2632 }
2633 break;
2634 case 'BE':
2635 if ($this->compressJavascript) {
2636 $filename = $this->getCompressor()->compressJsFile($filename);
2637 }
2638 break;
2639 }
2640 return $filename;
2641 }
2642
2643 /*****************************************************/
2644 /* */
2645 /* Hooks */
2646 /* */
2647 /*****************************************************/
2648
2649 /**
2650 * Execute PreRenderHook for possible manuipulation
2651 *
2652 * @return void
2653 */
2654 protected function executePreRenderHook() {
2655 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-preProcess'])) {
2656 $params = array(
2657 'jsLibs' => &$this->jsLibs,
2658 'jsFooterLibs' => &$this->jsFooterLibs,
2659 'jsFiles' => &$this->jsFiles,
2660 'jsFooterFiles' => &$this->jsFooterFiles,
2661 'cssFiles' => &$this->cssFiles,
2662 'headerData' => &$this->headerData,
2663 'footerData' => &$this->footerData,
2664 'jsInline' => &$this->jsInline,
2665 'jsFooterInline' => &$this->jsFooterInline,
2666 'cssInline' => &$this->cssInline,
2667 );
2668 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-preProcess'] as $hook) {
2669 t3lib_div::callUserFunction($hook, $params, $this);
2670 }
2671 }
2672 }
2673
2674 /**
2675 * PostTransform for possible manuipulation of concatenated and compressed files
2676 *
2677 * @return void
2678 */
2679 protected function executeRenderPostTransformHook() {
2680 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postTransform'])) {
2681 $params = array('jsLibs' => &$this->jsLibs,
2682 'jsFooterLibs' => &$this->jsFooterLibs,
2683 'jsFiles' => &$this->jsFiles,
2684 'jsFooterFiles' => &$this->jsFooterFiles,
2685 'cssFiles' => &$this->cssFiles,
2686 'headerData' => &$this->headerData,
2687 'footerData' => &$this->footerData,
2688 'jsInline' => &$this->jsInline,
2689 'jsFooterInline' => &$this->jsFooterInline,
2690 'cssInline' => &$this->cssInline,
2691 );
2692 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postTransform'] as $hook) {
2693 t3lib_div::callUserFunction($hook, $params, $this);
2694 }
2695 }
2696 }
2697
2698 /**
2699 * Execute postRenderHook for possible manipulation
2700 *
2701 * @param $jsLibs string
2702 * @param $jsFiles string
2703 * @param $jsFooterFiles string
2704 * @param $cssFiles string
2705 * @param $jsInline string
2706 * @param $cssInline string
2707 * @param $jsFooterInline string
2708 * @param $jsFooterLibs string
2709 *
2710 * @return void
2711 */
2712 protected function executePostRenderHook(&$jsLibs, &$jsFiles, &$jsFooterFiles, &$cssFiles, &$jsInline, &$cssInline, &$jsFooterInline, &$jsFooterLibs) {
2713 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postProcess'])) {
2714 $params = array(
2715 'jsLibs' => &$jsLibs,
2716 'jsFiles' => &$jsFiles,
2717 'jsFooterFiles' => &$jsFooterFiles,
2718 'cssFiles' => &$cssFiles,
2719 'headerData' => &$this->headerData,
2720 'footerData' => &$this->footerData,
2721 'jsInline' => &$jsInline,
2722 'cssInline' => &$cssInline,
2723 'xmlPrologAndDocType' => &$this->xmlPrologAndDocType,
2724 'htmlTag' => &$this->htmlTag,
2725 'headTag' => &$this->headTag,
2726 'charSet' => &$this->charSet,
2727 'metaCharsetTag' => &$this->metaCharsetTag,
2728 'shortcutTag' => &$this->shortcutTag,
2729 'inlineComments' => &$this->inlineComments,
2730 'baseUrl' => &$this->baseUrl,
2731 'baseUrlTag' => &$this->baseUrlTag,
2732 'favIcon' => &$this->favIcon,
2733 'iconMimeType' => &$this->iconMimeType,
2734 'titleTag' => &$this->titleTag,
2735 'title' => &$this->title,
2736 'metaTags' => &$this->metaTags,
2737 'jsFooterInline' => &$jsFooterInline,
2738 'jsFooterLibs' => &$jsFooterLibs,
2739 'bodyContent' => &$this->bodyContent
2740 );
2741 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-postProcess'] as $hook) {
2742 t3lib_div::callUserFunction($hook, $params, $this);
2743 }
2744 }
2745 }
2746 }
2747
2748 ?>