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