[BUGFIX] Restore registers before early returns
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Classes / ContentObject / ContentObjectRenderer.php
1 <?php
2 namespace TYPO3\CMS\Frontend\ContentObject;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 1999-2013 Kasper Skårhøj (kasperYYYY@typo3.com)
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the text file GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 *
29 ***************************************************************/
30
31 use TYPO3\CMS\Core\Utility\GeneralUtility;
32 use TYPO3\CMS\Core\Versioning\VersionState;
33
34 /**
35 * This class contains all main TypoScript features.
36 * This includes the rendering of TypoScript content objects (cObjects).
37 * Is the backbone of TypoScript Template rendering.
38 *
39 * There are lots of functions you can use from your include-scripts.
40 * The class is normally instantiated and referred to as "cObj".
41 * When you call your own PHP-code typically through a USER or USER_INT cObject then it is this class that instantiates the object and calls the main method. Before it does so it will set (if you are using classes) a reference to itself in the internal variable "cObj" of the object. Thus you can access all functions and data from this class by $this->cObj->... from within you classes written to be USER or USER_INT content objects.
42 *
43 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
44 */
45 class ContentObjectRenderer {
46
47 /**
48 * @todo Define visibility
49 */
50 public $align = array(
51 'center',
52 'right',
53 'left'
54 );
55
56 /**
57 * stdWrap functions in their correct order
58 *
59 * @see stdWrap()
60 * @todo Define visibility
61 */
62 public $stdWrapOrder = array(
63 'stdWrapPreProcess' => 'hook',
64 // this is a placeholder for the first Hook
65 'cacheRead' => 'hook',
66 // this is a placeholder for checking if the content is available in cache
67 'setContentToCurrent' => 'boolean',
68 'setContentToCurrent.' => 'array',
69 'addPageCacheTags' => 'string',
70 'addPageCacheTags.' => 'array',
71 'setCurrent' => 'string',
72 'setCurrent.' => 'array',
73 'lang.' => 'array',
74 'data' => 'getText',
75 'data.' => 'array',
76 'field' => 'fieldName',
77 'field.' => 'array',
78 'current' => 'boolean',
79 'current.' => 'array',
80 'cObject' => 'cObject',
81 'cObject.' => 'array',
82 'numRows.' => 'array',
83 'filelist' => 'dir',
84 'filelist.' => 'array',
85 'preUserFunc' => 'functionName',
86 'stdWrapOverride' => 'hook',
87 // this is a placeholder for the second Hook
88 'override' => 'string',
89 'override.' => 'array',
90 'preIfEmptyListNum' => 'listNum',
91 'preIfEmptyListNum.' => 'array',
92 'ifNull' => 'string',
93 'ifNull.' => 'array',
94 'ifEmpty' => 'string',
95 'ifEmpty.' => 'array',
96 'ifBlank' => 'string',
97 'ifBlank.' => 'array',
98 'listNum' => 'listNum',
99 'listNum.' => 'array',
100 'trim' => 'boolean',
101 'trim.' => 'array',
102 'strPad.' => 'array',
103 'stdWrap' => 'stdWrap',
104 'stdWrap.' => 'array',
105 'stdWrapProcess' => 'hook',
106 // this is a placeholder for the third Hook
107 'required' => 'boolean',
108 'required.' => 'array',
109 'if.' => 'array',
110 'fieldRequired' => 'fieldName',
111 'fieldRequired.' => 'array',
112 'csConv' => 'string',
113 'csConv.' => 'array',
114 'parseFunc' => 'objectpath',
115 'parseFunc.' => 'array',
116 'HTMLparser' => 'boolean',
117 'HTMLparser.' => 'array',
118 'split.' => 'array',
119 'replacement.' => 'array',
120 'prioriCalc' => 'boolean',
121 'prioriCalc.' => 'array',
122 'char' => 'integer',
123 'char.' => 'array',
124 'intval' => 'boolean',
125 'intval.' => 'array',
126 'hash' => 'string',
127 'hash.' => 'array',
128 'round' => 'boolean',
129 'round.' => 'array',
130 'numberFormat.' => 'array',
131 'expandList' => 'boolean',
132 'expandList.' => 'array',
133 'date' => 'dateconf',
134 'date.' => 'array',
135 'strftime' => 'strftimeconf',
136 'strftime.' => 'array',
137 'age' => 'boolean',
138 'age.' => 'array',
139 'case' => 'case',
140 'case.' => 'array',
141 'bytes' => 'boolean',
142 'bytes.' => 'array',
143 'substring' => 'parameters',
144 'substring.' => 'array',
145 'removeBadHTML' => 'boolean',
146 'removeBadHTML.' => 'array',
147 'cropHTML' => 'crop',
148 'cropHTML.' => 'array',
149 'stripHtml' => 'boolean',
150 'stripHtml.' => 'array',
151 'crop' => 'crop',
152 'crop.' => 'array',
153 'rawUrlEncode' => 'boolean',
154 'rawUrlEncode.' => 'array',
155 'htmlSpecialChars' => 'boolean',
156 'htmlSpecialChars.' => 'array',
157 'encodeForJavaScriptValue' => 'boolean',
158 'encodeForJavaScriptValue.' => 'array',
159 'doubleBrTag' => 'string',
160 'doubleBrTag.' => 'array',
161 'br' => 'boolean',
162 'br.' => 'array',
163 'brTag' => 'string',
164 'brTag.' => 'array',
165 'encapsLines.' => 'array',
166 'keywords' => 'boolean',
167 'keywords.' => 'array',
168 'innerWrap' => 'wrap',
169 'innerWrap.' => 'array',
170 'innerWrap2' => 'wrap',
171 'innerWrap2.' => 'array',
172 'fontTag' => 'wrap',
173 'fontTag.' => 'array',
174 'addParams.' => 'array',
175 'textStyle.' => 'array',
176 'tableStyle.' => 'array',
177 'filelink.' => 'array',
178 'preCObject' => 'cObject',
179 'preCObject.' => 'array',
180 'postCObject' => 'cObject',
181 'postCObject.' => 'array',
182 'wrapAlign' => 'align',
183 'wrapAlign.' => 'array',
184 'typolink.' => 'array',
185 'TCAselectItem.' => 'array',
186 'space' => 'space',
187 'space.' => 'array',
188 'spaceBefore' => 'int',
189 'spaceBefore.' => 'array',
190 'spaceAfter' => 'int',
191 'spaceAfter.' => 'array',
192 'wrap' => 'wrap',
193 'wrap.' => 'array',
194 'noTrimWrap' => 'wrap',
195 'noTrimWrap.' => 'array',
196 'wrap2' => 'wrap',
197 'wrap2.' => 'array',
198 'dataWrap' => 'dataWrap',
199 'dataWrap.' => 'array',
200 'prepend' => 'cObject',
201 'prepend.' => 'array',
202 'append' => 'cObject',
203 'append.' => 'array',
204 'wrap3' => 'wrap',
205 'wrap3.' => 'array',
206 'orderedStdWrap' => 'stdWrap',
207 'orderedStdWrap.' => 'array',
208 'outerWrap' => 'wrap',
209 'outerWrap.' => 'array',
210 'insertData' => 'boolean',
211 'insertData.' => 'array',
212 'offsetWrap' => 'space',
213 'offsetWrap.' => 'array',
214 'postUserFunc' => 'functionName',
215 'postUserFuncInt' => 'functionName',
216 'prefixComment' => 'string',
217 'prefixComment.' => 'array',
218 'editIcons' => 'string',
219 'editIcons.' => 'array',
220 'editPanel' => 'boolean',
221 'editPanel.' => 'array',
222 'cacheStore' => 'hook',
223 // this is a placeholder for storing the content in cache
224 'stdWrapPostProcess' => 'hook',
225 // this is a placeholder for the last Hook
226 'debug' => 'boolean',
227 'debug.' => 'array',
228 'debugFunc' => 'boolean',
229 'debugFunc.' => 'array',
230 'debugData' => 'boolean',
231 'debugData.' => 'array'
232 );
233
234 /**
235 * Class names for accordant content objects
236 *
237 * @var array
238 */
239 protected $contentObjectClassMapping = array(
240 'TEXT' => 'Text',
241 'CASE' => 'Case',
242 'CLEARGIF' => 'ClearGif',
243 'COBJ_ARRAY' => 'ContentObjectArray',
244 'COA' => 'ContentObjectArray',
245 'COA_INT' => 'ContentObjectArrayInternal',
246 'USER' => 'User',
247 'USER_INT' => 'UserInternal',
248 'FILE' => 'File',
249 'FILES' => 'Files',
250 'IMAGE' => 'Image',
251 'IMG_RESOURCE' => 'ImageResource',
252 'IMGTEXT' => 'ImageText',
253 'CONTENT' => 'Content',
254 'RECORDS' => 'Records',
255 'HMENU' => 'HierarchicalMenu',
256 'CTABLE' => 'ContentTable',
257 'OTABLE' => 'OffsetTable',
258 'COLUMNS' => 'Columns',
259 'HRULER' => 'HorizontalRuler',
260 'CASEFUNC' => 'Case',
261 'LOAD_REGISTER' => 'LoadRegister',
262 'RESTORE_REGISTER' => 'RestoreRegister',
263 'FORM' => 'Form',
264 'SEARCHRESULT' => 'SearchResult',
265 'TEMPLATE' => 'Template',
266 'FLUIDTEMPLATE' => 'FluidTemplate',
267 'MULTIMEDIA' => 'Multimedia',
268 'MEDIA' => 'Media',
269 'SWFOBJECT' => 'ShockwaveFlashObject',
270 'FLOWPLAYER' => 'FlowPlayer',
271 'QTOBJECT' => 'QuicktimeObject',
272 'SVG' => 'ScalableVectorGraphics',
273 'EDITPANEL' => 'EditPanel',
274 );
275
276 /**
277 * Holds ImageMagick parameters and extensions used for compression
278 *
279 * @see IMGTEXT()
280 * @todo Define visibility
281 */
282 public $image_compression = array(
283 10 => array(
284 'params' => '',
285 'ext' => 'gif'
286 ),
287 11 => array(
288 'params' => '-colors 128',
289 'ext' => 'gif'
290 ),
291 12 => array(
292 'params' => '-colors 64',
293 'ext' => 'gif'
294 ),
295 13 => array(
296 'params' => '-colors 32',
297 'ext' => 'gif'
298 ),
299 14 => array(
300 'params' => '-colors 16',
301 'ext' => 'gif'
302 ),
303 15 => array(
304 'params' => '-colors 8',
305 'ext' => 'gif'
306 ),
307 20 => array(
308 'params' => '-quality 100',
309 'ext' => 'jpg'
310 ),
311 21 => array(
312 'params' => '-quality 90',
313 'ext' => 'jpg'
314 ),
315 22 => array(
316 'params' => '-quality 80',
317 'ext' => 'jpg'
318 ),
319 23 => array(
320 'params' => '-quality 70',
321 'ext' => 'jpg'
322 ),
323 24 => array(
324 'params' => '-quality 60',
325 'ext' => 'jpg'
326 ),
327 25 => array(
328 'params' => '-quality 50',
329 'ext' => 'jpg'
330 ),
331 26 => array(
332 'params' => '-quality 40',
333 'ext' => 'jpg'
334 ),
335 27 => array(
336 'params' => '-quality 30',
337 'ext' => 'jpg'
338 ),
339 28 => array(
340 'params' => '-quality 20',
341 'ext' => 'jpg'
342 ),
343 30 => array(
344 'params' => '-colors 256',
345 'ext' => 'png'
346 ),
347 31 => array(
348 'params' => '-colors 128',
349 'ext' => 'png'
350 ),
351 32 => array(
352 'params' => '-colors 64',
353 'ext' => 'png'
354 ),
355 33 => array(
356 'params' => '-colors 32',
357 'ext' => 'png'
358 ),
359 34 => array(
360 'params' => '-colors 16',
361 'ext' => 'png'
362 ),
363 35 => array(
364 'params' => '-colors 8',
365 'ext' => 'png'
366 ),
367 39 => array(
368 'params' => '',
369 'ext' => 'png'
370 )
371 );
372
373 /**
374 * ImageMagick parameters for image effects
375 *
376 * @see IMGTEXT()
377 * @todo Define visibility
378 */
379 public $image_effects = array(
380 1 => '-rotate 90',
381 2 => '-rotate 270',
382 3 => '-rotate 180',
383 10 => '-colorspace GRAY',
384 11 => '-sharpen 70',
385 20 => '-normalize',
386 23 => '-contrast',
387 25 => '-gamma 1.3',
388 26 => '-gamma 0.8'
389 );
390
391 /**
392 * Loaded with the current data-record.
393 *
394 * If the instance of this class is used to render records from the database those records are found in this array.
395 * The function stdWrap has TypoScript properties that fetch field-data from this array.
396 *
397 * @see init()
398 * @todo Define visibility
399 */
400 public $data = array();
401
402 protected $table = '';
403
404 // Used for backup...
405 /**
406 * @todo Define visibility
407 */
408 public $oldData = array();
409
410 // If this is set with an array before stdWrap, it's used instead of $this->data in the data-property in stdWrap
411 /**
412 * @todo Define visibility
413 */
414 public $alternativeData = '';
415
416 // Used by the parseFunc function and is loaded with tag-parameters when parsing tags.
417 /**
418 * @todo Define visibility
419 */
420 public $parameters = array();
421
422 /**
423 * @todo Define visibility
424 */
425 public $currentValKey = 'currentValue_kidjls9dksoje';
426
427 // This is set to the [table]:[uid] of the record delivered in the $data-array, if the cObjects CONTENT or RECORD is in operation.
428 // Note that $GLOBALS['TSFE']->currentRecord is set to an equal value but always indicating the latest record rendered.
429 /**
430 * @todo Define visibility
431 */
432 public $currentRecord = '';
433
434 // Set in cObj->RECORDS and cObj->CONTENT to the current number of records selected in a query.
435 /**
436 * @todo Define visibility
437 */
438 public $currentRecordTotal = 0;
439
440 // Incremented in cObj->RECORDS and cObj->CONTENT before each record rendering.
441 /**
442 * @todo Define visibility
443 */
444 public $currentRecordNumber = 0;
445
446 // Incremented in parent cObj->RECORDS and cObj->CONTENT before each record rendering.
447 /**
448 * @todo Define visibility
449 */
450 public $parentRecordNumber = 0;
451
452 // If the ContentObjectRender was started from CONTENT, RECORD or SEARCHRESULT cObject's this array has two keys, 'data' and 'currentRecord' which indicates the record and data for the parent cObj.
453 /**
454 * @todo Define visibility
455 */
456 public $parentRecord = array();
457
458 // This may be set as a reference to the calling object of eg. cObjGetSingle. Anyway, just use it as you like. It's used in productsLib.inc for example.
459 /**
460 * @todo Define visibility
461 */
462 public $regObj;
463
464 // internal
465 // Is set to 1 if the instance of this cObj is executed from a *_INT plugin (see pagegen, bottom of document)
466 /**
467 * @todo Define visibility
468 */
469 public $INT_include = 0;
470
471 // This is used by checkPid, that checks if pages are accessible. The $checkPid_cache['page_uid'] is set TRUE or FALSE upon this check featuring a caching function for the next request.
472 /**
473 * @todo Define visibility
474 */
475 public $checkPid_cache = array();
476
477 /**
478 * @todo Define visibility
479 */
480 public $checkPid_badDoktypeList = '255';
481
482 // This will be set by typoLink() to the url of the most recent link created.
483 /**
484 * @todo Define visibility
485 */
486 public $lastTypoLinkUrl = '';
487
488 // DO. link target.
489 /**
490 * @todo Define visibility
491 */
492 public $lastTypoLinkTarget = '';
493
494 /**
495 * @todo Define visibility
496 */
497 public $lastTypoLinkLD = array();
498
499 // Caching substituteMarkerArrayCached function
500 /**
501 * @todo Define visibility
502 */
503 public $substMarkerCache = array();
504
505 // array that registers rendered content elements (or any table) to make sure they are not rendered recursively!
506 /**
507 * @todo Define visibility
508 */
509 public $recordRegister = array();
510
511 // Containing hooks for userdefined cObjects
512 /**
513 * @todo Define visibility
514 */
515 public $cObjHookObjectsArr = array();
516
517 // Containing hook objects for stdWrap
518 protected $stdWrapHookObjects = array();
519
520 // Containing hook objects for getImgResource
521 protected $getImgResourceHookObjects;
522
523 /**
524 * @var \TYPO3\CMS\Core\Resource\File Current file objects (during iterations over files)
525 */
526 protected $currentFile = NULL;
527
528 /**
529 * Set to TRUE by doConvertToUserIntObject() if USER object wants to become USER_INT
530 */
531 public $doConvertToUserIntObject = FALSE;
532
533 /**
534 * Indicates current object type. Can hold one of OBJECTTYPE_ constants or FALSE.
535 * The value is set and reset inside USER() function. Any time outside of
536 * USER() it is FALSE.
537 */
538 protected $userObjectType = FALSE;
539
540 /**
541 * Indicates that object type is USER.
542 *
543 * @see ContentObjectRender::$userObjectType
544 */
545 const OBJECTTYPE_USER_INT = 1;
546 /**
547 * Indicates that object type is USER.
548 *
549 * @see ContentObjectRender::$userObjectType
550 */
551 const OBJECTTYPE_USER = 2;
552 /**
553 * Class constructor.
554 * Well, it has to be called manually since it is not a real constructor function.
555 * So after making an instance of the class, call this function and pass to it a database record and the tablename from where the record is from. That will then become the "current" record loaded into memory and accessed by the .fields property found in eg. stdWrap.
556 *
557 * @param array $data The record data that is rendered.
558 * @param string $table The table that the data record is from.
559 * @return void
560 * @todo Define visibility
561 */
562 public function start($data, $table = '') {
563 global $TYPO3_CONF_VARS;
564 if ($TYPO3_CONF_VARS['FE']['activateContentAdapter'] && is_array($data) && !empty($data) && !empty($table)) {
565 \TYPO3\CMS\Core\Resource\Service\FrontendContentAdapterService::modifyDBRow($data, $table);
566 }
567 $this->data = $data;
568 $this->table = $table;
569 $this->currentRecord = $table ? $table . ':' . $this->data['uid'] : '';
570 $this->parameters = array();
571 if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_content.php']['cObjTypeAndClass'])) {
572 foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_content.php']['cObjTypeAndClass'] as $classArr) {
573 $this->cObjHookObjectsArr[$classArr[0]] = GeneralUtility::getUserObj($classArr[1]);
574 }
575 }
576 $this->stdWrapHookObjects = array();
577 if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_content.php']['stdWrap'])) {
578 foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_content.php']['stdWrap'] as $classData) {
579 $hookObject = GeneralUtility::getUserObj($classData);
580 if (!$hookObject instanceof \TYPO3\CMS\Frontend\ContentObject\ContentObjectStdWrapHookInterface) {
581 throw new \UnexpectedValueException($classData . ' must implement interface TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectStdWrapHookInterface', 1195043965);
582 }
583 $this->stdWrapHookObjects[] = $hookObject;
584 }
585 }
586 if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_content.php']['postInit'])) {
587 foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_content.php']['postInit'] as $classData) {
588 $postInitializationProcessor = GeneralUtility::getUserObj($classData);
589 if (!$postInitializationProcessor instanceof \TYPO3\CMS\Frontend\ContentObject\ContentObjectPostInitHookInterface) {
590 throw new \UnexpectedValueException($classData . ' must implement interface TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectPostInitHookInterface', 1274563549);
591 }
592 $postInitializationProcessor->postProcessContentObjectInitialization($this);
593 }
594 }
595 }
596
597 /**
598 * Returns the current table
599 *
600 * @return string
601 */
602 public function getCurrentTable() {
603 return $this->table;
604 }
605
606 /**
607 * Gets the 'getImgResource' hook objects.
608 * The first call initializes the accordant objects.
609 *
610 * @return array The 'getImgResource' hook objects (if any)
611 */
612 protected function getGetImgResourceHookObjects() {
613 if (!isset($this->getImgResourceHookObjects)) {
614 $this->getImgResourceHookObjects = array();
615 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['getImgResource'])) {
616 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['getImgResource'] as $classData) {
617 $hookObject = GeneralUtility::getUserObj($classData);
618 if (!$hookObject instanceof \TYPO3\CMS\Frontend\ContentObject\ContentObjectGetImageResourceHookInterface) {
619 throw new \UnexpectedValueException('$hookObject must implement interface TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectGetImageResourceHookInterface', 1218636383);
620 }
621 $this->getImgResourceHookObjects[] = $hookObject;
622 }
623 }
624 }
625 return $this->getImgResourceHookObjects;
626 }
627
628 /**
629 * Sets the internal variable parentRecord with information about current record.
630 * If the ContentObjectRender was started from CONTENT, RECORD or SEARCHRESULT cObject's this array has two keys, 'data' and 'currentRecord' which indicates the record and data for the parent cObj.
631 *
632 * @param array $data The record array
633 * @param string $currentRecord This is set to the [table]:[uid] of the record delivered in the $data-array, if the cObjects CONTENT or RECORD is in operation. Note that $GLOBALS['TSFE']->currentRecord is set to an equal value but always indicating the latest record rendered.
634 * @return void
635 * @access private
636 * @todo Define visibility
637 */
638 public function setParent($data, $currentRecord) {
639 $this->parentRecord = array(
640 'data' => $data,
641 'currentRecord' => $currentRecord
642 );
643 }
644
645 /***********************************************
646 *
647 * CONTENT_OBJ:
648 *
649 ***********************************************/
650 /**
651 * Returns the "current" value.
652 * The "current" value is just an internal variable that can be used by functions to pass a single value on to another function later in the TypoScript processing.
653 * It's like "load accumulator" in the good old C64 days... basically a "register" you can use as you like.
654 * The TSref will tell if functions are setting this value before calling some other object so that you know if it holds any special information.
655 *
656 * @return mixed The "current" value
657 * @todo Define visibility
658 */
659 public function getCurrentVal() {
660 return $this->data[$this->currentValKey];
661 }
662
663 /**
664 * Sets the "current" value.
665 *
666 * @param mixed $value The variable that you want to set as "current
667 * @return void
668 * @see getCurrentVal()
669 * @todo Define visibility
670 */
671 public function setCurrentVal($value) {
672 $this->data[$this->currentValKey] = $value;
673 }
674
675 /**
676 * Rendering of a "numerical array" of cObjects from TypoScript
677 * Will call ->cObjGetSingle() for each cObject found and accumulate the output.
678 *
679 * @param array $setup array with cObjects as values.
680 * @param string $addKey A prefix for the debugging information
681 * @return string Rendered output from the cObjects in the array.
682 * @see cObjGetSingle()
683 * @todo Define visibility
684 */
685 public function cObjGet($setup, $addKey = '') {
686 if (is_array($setup)) {
687 $sKeyArray = \TYPO3\CMS\Core\TypoScript\TemplateService::sortedKeyList($setup);
688 $content = '';
689 foreach ($sKeyArray as $theKey) {
690 $theValue = $setup[$theKey];
691 if ((int)$theKey && strpos($theKey, '.') === FALSE) {
692 $conf = $setup[$theKey . '.'];
693 $content .= $this->cObjGetSingle($theValue, $conf, $addKey . $theKey);
694 }
695 }
696 return $content;
697 }
698 }
699
700 /**
701 * Renders a content object
702 *
703 * @param string $name The content object name, eg. "TEXT" or "USER" or "IMAGE
704 * @param array $conf The array with TypoScript properties for the content object
705 * @param string $TSkey A string label used for the internal debugging tracking.
706 * @return string cObject output
707 * @throws \UnexpectedValueException
708 * @todo Define visibility
709 */
710 public function cObjGetSingle($name, $conf, $TSkey = '__') {
711 global $TYPO3_CONF_VARS;
712 $content = '';
713 // Checking that the function is not called eternally. This is done by interrupting at a depth of 100
714 $GLOBALS['TSFE']->cObjectDepthCounter--;
715 if ($GLOBALS['TSFE']->cObjectDepthCounter > 0) {
716 $name = trim($name);
717 if ($GLOBALS['TT']->LR) {
718 $GLOBALS['TT']->push($TSkey, $name);
719 }
720 // Checking if the COBJ is a reference to another object. (eg. name of 'blabla.blabla = < styles.something')
721 if ($name[0] === '<') {
722 $key = trim(substr($name, 1));
723 $cF = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\TypoScript\\Parser\\TypoScriptParser');
724 // $name and $conf is loaded with the referenced values.
725 $old_conf = $conf;
726 list($name, $conf) = $cF->getVal($key, $GLOBALS['TSFE']->tmpl->setup);
727 if (is_array($old_conf) && count($old_conf)) {
728 $conf = array_replace_recursive($conf, $old_conf);
729 }
730 // Getting the cObject
731 $GLOBALS['TT']->incStackPointer();
732 $content .= $this->cObjGetSingle($name, $conf, $key);
733 $GLOBALS['TT']->decStackPointer();
734 } else {
735 $hooked = FALSE;
736 // Application defined cObjects
737 if (!empty($this->cObjHookObjectsArr[$name])) {
738 $hookObj = $this->cObjHookObjectsArr[$name];
739 if (method_exists($hookObj, 'cObjGetSingleExt')) {
740 $content .= $hookObj->cObjGetSingleExt($name, $conf, $TSkey, $this);
741 $hooked = TRUE;
742 }
743 }
744 if (!$hooked) {
745 $contentObject = $this->getContentObject($name);
746 if ($contentObject) {
747 $content .= $contentObject->render($conf);
748 } else {
749 // Call hook functions for extra processing
750 if ($name && is_array($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_content.php']['cObjTypeAndClassDefault'])) {
751 foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_content.php']['cObjTypeAndClassDefault'] as $classData) {
752 $hookObject = GeneralUtility::getUserObj($classData);
753 if (!$hookObject instanceof \TYPO3\CMS\Frontend\ContentObject\ContentObjectGetSingleHookInterface) {
754 throw new \UnexpectedValueException('$hookObject must implement interface TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectGetSingleHookInterface', 1195043731);
755 }
756 /** @var $hookObject \TYPO3\CMS\Frontend\ContentObject\ContentObjectGetSingleHookInterface */
757 $content .= $hookObject->getSingleContentObject($name, (array) $conf, $TSkey, $this);
758 }
759 } else {
760 // Log error in AdminPanel
761 $warning = sprintf('Content Object "%s" does not exist', $name);
762 $GLOBALS['TT']->setTSlogMessage($warning, 2);
763 }
764 }
765 }
766 }
767 if ($GLOBALS['TT']->LR) {
768 $GLOBALS['TT']->pull($content);
769 }
770 }
771 // Increasing on exit...
772 $GLOBALS['TSFE']->cObjectDepthCounter++;
773 return $content;
774 }
775
776 /**
777 * Returns a new content object of type $name.
778 *
779 * @param string $name
780 * @return NULL|AbstractContentObject
781 */
782 public function getContentObject($name) {
783 if (!isset($this->contentObjectClassMapping[$name])) {
784 return NULL;
785 }
786 $fullyQualifiedClassName = 'TYPO3\\CMS\\Frontend\\ContentObject\\' . $this->contentObjectClassMapping[$name] . 'ContentObject';
787 return GeneralUtility::makeInstance($fullyQualifiedClassName, $this);
788 }
789
790 /********************************************
791 *
792 * Functions rendering content objects (cObjects)
793 *
794 ********************************************/
795
796 /**
797 * Rendering the cObject, FLOWPLAYER
798 *
799 * @param array $conf Array of TypoScript properties
800 * @return string Output
801 * @todo Define visibility
802 */
803 public function FLOWPLAYER($conf) {
804 return $this->getContentObject('FLOWPLAYER')->render($conf);
805 }
806
807 /**
808 * Rendering the cObject, TEXT
809 *
810 * @param array $conf Array of TypoScript properties
811 * @return string Output
812 * @todo Define visibility
813 */
814 public function TEXT($conf) {
815 return $this->getContentObject('TEXT')->render($conf);
816 }
817
818 /**
819 * Rendering the cObject, CLEARGIF
820 *
821 * @param array $conf Array of TypoScript properties
822 * @return string Output
823 * @todo Define visibility
824 */
825 public function CLEARGIF($conf) {
826 return $this->getContentObject('CLEARGIF')->render($conf);
827 }
828
829 /**
830 * Rendering the cObject, COBJ_ARRAY / COA and COBJ_ARRAY_INT
831 *
832 * @param array $conf Array of TypoScript properties
833 * @param string $ext If "INT" then the cObject is a "COBJ_ARRAY_INT" (non-cached), otherwise just "COBJ_ARRAY" (cached)
834 * @return string Output
835 * @todo Define visibility
836 */
837 public function COBJ_ARRAY($conf, $ext = '') {
838 if ($ext === 'INT') {
839 return $this->getContentObject('COA_INT')->render($conf);
840 } else {
841 return $this->getContentObject('COA')->render($conf);
842 }
843 }
844
845 /**
846 * Rendering the cObject, USER and USER_INT
847 *
848 * @param array $conf Array of TypoScript properties
849 * @param string $ext If "INT" then the cObject is a "USER_INT" (non-cached), otherwise just "USER" (cached)
850 * @return string Output
851 * @todo Define visibility
852 */
853 public function USER($conf, $ext = '') {
854 if ($ext === 'INT') {
855 return $this->getContentObject('USER_INT')->render($conf);
856 } else {
857 return $this->getContentObject('USER')->render($conf);
858 }
859 }
860
861 /**
862 * Retrieves a type of object called as USER or USER_INT. Object can detect their
863 * type by using this call. It returns OBJECTTYPE_USER_INT or OBJECTTYPE_USER depending on the
864 * current object execution. In all other cases it will return FALSE to indicate
865 * a call out of context.
866 *
867 * @return mixed One of OBJECTTYPE_ class constants or FALSE
868 */
869 public function getUserObjectType() {
870 return $this->userObjectType;
871 }
872
873 /**
874 * Sets the user object type
875 *
876 * @param mixed $userObjectType
877 * @return void
878 */
879 public function setUserObjectType($userObjectType) {
880 $this->userObjectType = $userObjectType;
881 }
882
883 /**
884 * Requests the current USER object to be converted to USER_INT.
885 *
886 * @return void
887 */
888 public function convertToUserIntObject() {
889 if ($this->userObjectType !== self::OBJECTTYPE_USER) {
890 $GLOBALS['TT']->setTSlogMessage('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer::convertToUserIntObject() ' . 'is called in the wrong context or for the wrong object type', 2);
891 } else {
892 $this->doConvertToUserIntObject = TRUE;
893 }
894 }
895
896 /**
897 * Rendering the cObject, FILE
898 *
899 * @param array $conf Array of TypoScript properties
900 * @return string Output
901 * @todo Define visibility
902 */
903 public function FILE($conf) {
904 return $this->getContentObject('FILE')->render($conf);
905 }
906
907 /**
908 * Rendering the cObject, FILES
909 *
910 * @param array $conf Array of TypoScript properties
911 * @return string Output
912 * @todo Define visibility
913 */
914 public function FILES($conf) {
915 return $this->getContentObject('FILES')->render($conf);
916 }
917
918 /**
919 * Rendering the cObject, IMAGE
920 *
921 * @param array $conf Array of TypoScript properties
922 * @return string Output
923 * @see cImage()
924 * @todo Define visibility
925 */
926 public function IMAGE($conf) {
927 return $this->getContentObject('IMAGE')->render($conf);
928 }
929
930 /**
931 * Rendering the cObject, IMG_RESOURCE
932 *
933 * @param array $conf Array of TypoScript properties
934 * @return string Output
935 * @see getImgResource()
936 * @todo Define visibility
937 */
938 public function IMG_RESOURCE($conf) {
939 return $this->getContentObject('IMG_RESOURCE')->render($conf);
940 }
941
942 /**
943 * Rendering the cObject, IMGTEXT
944 *
945 * @param array $conf Array of TypoScript properties
946 * @return string Output
947 * @todo Define visibility
948 */
949 public function IMGTEXT($conf) {
950 return $this->getContentObject('IMGTEXT')->render($conf);
951 }
952
953 /**
954 * Rendering the cObject, CONTENT
955 *
956 * @param array $conf Array of TypoScript properties
957 * @return string Output
958 * @todo Define visibility
959 */
960 public function CONTENT($conf) {
961 return $this->getContentObject('CONTENT')->render($conf);
962 }
963
964 /**
965 * Rendering the cObject, RECORDS
966 *
967 * @param array $conf Array of TypoScript properties
968 * @return string Output
969 * @todo Define visibility
970 */
971 public function RECORDS($conf) {
972 return $this->getContentObject('RECORDS')->render($conf);
973 }
974
975 /**
976 * Rendering the cObject, HMENU
977 *
978 * @param array $conf Array of TypoScript properties
979 * @return string Output
980 * @todo Define visibility
981 */
982 public function HMENU($conf) {
983 return $this->getContentObject('HMENU')->render($conf);
984 }
985
986 /**
987 * Rendering the cObject, CTABLE
988 *
989 * @param array $conf Array of TypoScript properties
990 * @return string Output
991 * @todo Define visibility
992 */
993 public function CTABLE($conf) {
994 return $this->getContentObject('CTABLE')->render($conf);
995 }
996
997 /**
998 * Rendering the cObject, OTABLE
999 *
1000 * @param array $conf Array of TypoScript properties
1001 * @return string Output
1002 * @todo Define visibility
1003 */
1004 public function OTABLE($conf) {
1005 return $this->getContentObject('OTABLE')->render($conf);
1006 }
1007
1008 /**
1009 * Rendering the cObject, COLUMNS
1010 *
1011 * @param array $conf Array of TypoScript properties
1012 * @return string Output
1013 * @todo Define visibility
1014 */
1015 public function COLUMNS($conf) {
1016 return $this->getContentObject('COLUMNS')->render($conf);
1017 }
1018
1019 /**
1020 * Rendering the cObject, HRULER
1021 *
1022 * @param array $conf Array of TypoScript properties
1023 * @return string Output
1024 * @todo Define visibility
1025 */
1026 public function HRULER($conf) {
1027 return $this->getContentObject('HRULER')->render($conf);
1028 }
1029
1030 /**
1031 * Rendering the cObject, CASE
1032 *
1033 * @param array $conf Array of TypoScript properties
1034 * @return string Output
1035 * @todo Define visibility
1036 */
1037 public function CASEFUNC($conf) {
1038 return $this->getContentObject('CASE')->render($conf);
1039 }
1040
1041 /**
1042 * Rendering the cObject, LOAD_REGISTER and RESTORE_REGISTER
1043 * NOTICE: This cObject does NOT return any content since it just sets internal data based on the TypoScript properties.
1044 *
1045 * @param array $conf Array of TypoScript properties
1046 * @param string $name If "RESTORE_REGISTER" then the cObject rendered is "RESTORE_REGISTER", otherwise "LOAD_REGISTER
1047 * @return string Empty string (the cObject only sets internal data!)
1048 * @todo Define visibility
1049 */
1050 public function LOAD_REGISTER($conf, $name) {
1051 if ($name === 'RESTORE_REGISTER') {
1052 return $this->getContentObject('RESTORE_REGISTER')->render();
1053 } else {
1054 return $this->getContentObject('LOAD_REGISTER')->render($conf);
1055 }
1056 }
1057
1058 /**
1059 * Rendering the cObject, FORM
1060 *
1061 * @param array $conf Array of TypoScript properties
1062 * @param array $formData Alternative formdata overriding whatever comes from TypoScript
1063 * @return string Output
1064 * @todo Define visibility
1065 */
1066 public function FORM($conf, $formData = '') {
1067 return $this->getContentObject('FORM')->render($conf, $formData);
1068 }
1069
1070 /**
1071 * Rendering the cObject, SEARCHRESULT
1072 *
1073 * @param array $conf Array of TypoScript properties
1074 * @return string Output
1075 * @todo Define visibility
1076 */
1077 public function SEARCHRESULT($conf) {
1078 return $this->getContentObject('SEARCHRESULT')->render($conf);
1079 }
1080
1081 /**
1082 * Rendering the cObject, TEMPLATE
1083 *
1084 * @param array $conf Array of TypoScript properties
1085 * @return string Output
1086 * @see substituteMarkerArrayCached()
1087 * @todo Define visibility
1088 */
1089 public function TEMPLATE($conf) {
1090 return $this->getContentObject('TEMPLATE')->render($conf);
1091 }
1092
1093 /**
1094 * Rendering the cObject, FLUIDTEMPLATE
1095 *
1096 * @param array $conf Array of TypoScript properties
1097 * @return string the HTML output
1098 * @author Steffen Ritter <info@steffen-ritter.net>
1099 * @author Benjamin Mack <benni@typo3.org>
1100 */
1101 protected function FLUIDTEMPLATE(array $conf) {
1102 return $this->getContentObject('FLUIDTEMPLATE')->render($conf);
1103 }
1104
1105 /**
1106 * Rendering the cObject, MULTIMEDIA
1107 *
1108 * @param array $conf Array of TypoScript properties
1109 * @return string Output
1110 * @todo Define visibility
1111 */
1112 public function MULTIMEDIA($conf) {
1113 return $this->getContentObject('MULTIMEDIA')->render($conf);
1114 }
1115
1116 /**
1117 * Rendering the cObject, MEDIA
1118 *
1119 * @param array $conf Array of TypoScript properties
1120 * @return string Output
1121 */
1122 public function MEDIA($conf) {
1123 return $this->getContentObject('MEDIA')->render($conf);
1124 }
1125
1126 /**
1127 * Rendering the cObject, SWFOBJECT
1128 *
1129 * @param array $conf Array of TypoScript properties
1130 * @return string Output
1131 */
1132 public function SWFOBJECT($conf) {
1133 return $this->getContentObject('SWFOBJECT')->render($conf);
1134 }
1135
1136 /**
1137 * Rendering the cObject, QTOBJECT
1138 *
1139 * @param array $conf Array of TypoScript properties
1140 * @return string Output
1141 */
1142 public function QTOBJECT($conf) {
1143 return $this->getContentObject('QTOBJECT')->render($conf);
1144 }
1145
1146 /**
1147 * Rendering the cObject, SVG
1148 *
1149 * @param array $conf Array of TypoScript properties
1150 * @return string Output
1151 */
1152 public function SVG($conf) {
1153 return $this->getContentObject('SVG')->render($conf);
1154 }
1155
1156 /************************************
1157 *
1158 * Various helper functions for content objects:
1159 *
1160 ************************************/
1161 /**
1162 * Converts a given config in Flexform to a conf-array
1163 *
1164 * @param string|array $flexData Flexform data
1165 * @param array $conf Array to write the data into, by reference
1166 * @param boolean $recursive Is set if called recursive. Don't call function with this parameter, it's used inside the function only
1167 * @return void
1168 */
1169 public function readFlexformIntoConf($flexData, &$conf, $recursive = FALSE) {
1170 if ($recursive === FALSE && is_string($flexData)) {
1171 $flexData = GeneralUtility::xml2array($flexData, 'T3');
1172 }
1173 if (isset($flexData['data']['sDEF']['lDEF'])) {
1174 $flexData = $flexData['data']['sDEF']['lDEF'];
1175 }
1176 if (!is_array($flexData)) {
1177 return;
1178 }
1179 foreach ($flexData as $key => $value) {
1180 if (!is_array($value)) {
1181 continue;
1182 }
1183 if (isset($value['el'])) {
1184 if (is_array($value['el']) && count($value['el']) > 0) {
1185 foreach ($value['el'] as $ekey => $element) {
1186 if (isset($element['vDEF'])) {
1187 $conf[$ekey] = $element['vDEF'];
1188 } else {
1189 if (is_array($element)) {
1190 $this->readFlexformIntoConf($element, $conf[$key][key($element)][$ekey], TRUE);
1191 } else {
1192 $this->readFlexformIntoConf($element, $conf[$key][$ekey], TRUE);
1193 }
1194 }
1195 }
1196 } else {
1197 $this->readFlexformIntoConf($value['el'], $conf[$key], TRUE);
1198 }
1199 }
1200 if (isset($value['vDEF'])) {
1201 $conf[$key] = $value['vDEF'];
1202 }
1203 }
1204 }
1205
1206 /**
1207 * Returns all parents of the given PID (Page UID) list
1208 *
1209 * @param string $pidList A list of page Content-Element PIDs (Page UIDs) / stdWrap
1210 * @param array $pidConf stdWrap array for the list
1211 * @return string A list of PIDs
1212 * @access private
1213 * @todo Define visibility
1214 */
1215 public function getSlidePids($pidList, $pidConf) {
1216 $pidList = isset($pidConf) ? trim($this->stdWrap($pidList, $pidConf)) : trim($pidList);
1217 if ($pidList === '') {
1218 $pidList = 'this';
1219 }
1220 if (trim($pidList)) {
1221 $listArr = GeneralUtility::intExplode(',', str_replace('this', $GLOBALS['TSFE']->contentPid, $pidList));
1222 $listArr = $this->checkPidArray($listArr);
1223 }
1224 $pidList = array();
1225 if (is_array($listArr) && count($listArr)) {
1226 foreach ($listArr as $uid) {
1227 $page = $GLOBALS['TSFE']->sys_page->getPage($uid);
1228 if (!$page['is_siteroot']) {
1229 $pidList[] = $page['pid'];
1230 }
1231 }
1232 }
1233 return implode(',', $pidList);
1234 }
1235
1236 /**
1237 * Returns a default value for a form field in the FORM cObject.
1238 * Page CANNOT be cached because that would include the inserted value for the current user.
1239 *
1240 * @param boolean $noValueInsert If noValueInsert OR if the no_cache flag for this page is NOT set, the original default value is returned.
1241 * @param string $fieldName The POST var name to get default value for
1242 * @param string $defaultVal The current default value
1243 * @return string The default value, either from INPUT var or the current default, based on whether caching is enabled or not.
1244 * @access private
1245 * @todo Define visibility
1246 */
1247 public function getFieldDefaultValue($noValueInsert, $fieldName, $defaultVal) {
1248 if (!$GLOBALS['TSFE']->no_cache || !isset($_POST[$fieldName]) && !isset($_GET[$fieldName]) || $noValueInsert) {
1249 return $defaultVal;
1250 } else {
1251 return GeneralUtility::_GP($fieldName);
1252 }
1253 }
1254
1255 /**
1256 * Returns a <img> tag with the image file defined by $file and processed according to the properties in the TypoScript array.
1257 * Mostly this function is a sub-function to the IMAGE function which renders the IMAGE cObject in TypoScript.
1258 * This function is called by "$this->cImage($conf['file'], $conf);" from IMAGE().
1259 *
1260 * @param string $file File TypoScript resource
1261 * @param array $conf TypoScript configuration properties
1262 * @return string <img> tag, (possibly wrapped in links and other HTML) if any image found.
1263 * @access private
1264 * @see IMAGE()
1265 * @todo Define visibility
1266 */
1267 public function cImage($file, $conf) {
1268 $info = $this->getImgResource($file, $conf['file.']);
1269 $GLOBALS['TSFE']->lastImageInfo = $info;
1270 if (is_array($info)) {
1271 if (is_file(PATH_site . $info['3'])) {
1272 $source = GeneralUtility::rawUrlEncodeFP(GeneralUtility::png_to_gif_by_imagemagick($info[3]));
1273 $source = $GLOBALS['TSFE']->absRefPrefix . $source;
1274 } else {
1275 $source = $info[3];
1276 }
1277
1278 $layoutKey = $this->stdWrap($conf['layoutKey'], $conf['layoutKey.']);
1279 $imageTagTemplate = $this->getImageTagTemplate($layoutKey, $conf);
1280 $sourceCollection = $this->getImageSourceCollection($layoutKey, $conf, $file);
1281
1282 // This array is used to collect the image-refs on the page...
1283 $GLOBALS['TSFE']->imagesOnPage[] = $source;
1284 $altParam = $this->getAltParam($conf);
1285 $params = $this->stdWrapValue('params', $conf);
1286 if ($params !== '' && $params{0} !== ' ') {
1287 $params = ' ' . $params;
1288 }
1289
1290 $imageTagValues = array(
1291 'width' => $info[0],
1292 'height' => $info[1],
1293 'src' => htmlspecialchars($source),
1294 'params' => $params,
1295 'altParams' => $altParam,
1296 'border' => $this->getBorderAttr(' border="' . (int)$conf['border'] . '"'),
1297 'sourceCollection' => $sourceCollection,
1298 'selfClosingTagSlash' => (!empty($GLOBALS['TSFE']->xhtmlDoctype) ? ' /' : ''),
1299 );
1300
1301 $theValue = $this->substituteMarkerArray($imageTagTemplate, $imageTagValues, '###|###', TRUE, TRUE);
1302
1303 $linkWrap = isset($conf['linkWrap.']) ? $this->stdWrap($conf['linkWrap'], $conf['linkWrap.']) : $conf['linkWrap'];
1304 if ($linkWrap) {
1305 $theValue = $this->linkWrap($theValue, $linkWrap);
1306 } elseif ($conf['imageLinkWrap']) {
1307 $theValue = $this->imageLinkWrap($theValue, $info['originalFile'], $conf['imageLinkWrap.']);
1308 }
1309 $wrap = isset($conf['wrap.']) ? $this->stdWrap($conf['wrap'], $conf['wrap.']) : $conf['wrap'];
1310 if ($wrap) {
1311 $theValue = $this->wrap($theValue, $conf['wrap']);
1312 }
1313 return $theValue;
1314 }
1315 }
1316
1317 /**
1318 * Returns the 'border' attribute for an <img> tag only if the doctype is not xhtml_strict, xhtml_11, xhtml_2 or html5
1319 * or if the config parameter 'disableImgBorderAttr' is not set.
1320 *
1321 * @param string $borderAttr The border attribute
1322 * @return string The border attribute
1323 * @todo Define visibility
1324 */
1325 public function getBorderAttr($borderAttr) {
1326 if (!GeneralUtility::inList('xhtml_strict,xhtml_11,xhtml_2', $GLOBALS['TSFE']->xhtmlDoctype) && $GLOBALS['TSFE']->config['config']['doctype'] != 'html5' && !$GLOBALS['TSFE']->config['config']['disableImgBorderAttr']) {
1327 return $borderAttr;
1328 }
1329 }
1330
1331 /**
1332 * Returns the html-template for rendering the image-Tag if no template is defined via typoscript the
1333 * default <img> tag template is returned
1334 *
1335 * @param string $layoutKey rendering key
1336 * @param array $conf TypoScript configuration properties
1337 * @return string
1338 */
1339 public function getImageTagTemplate($layoutKey, $conf) {
1340 if ($layoutKey && isset($conf['layout.']) && isset($conf['layout.'][$layoutKey . '.'])) {
1341 $imageTagLayout = $this->stdWrap($conf['layout.'][$layoutKey . '.']['element'], $conf['layout.'][$layoutKey . '.']['element.']);
1342 } else {
1343 $imageTagLayout = '<img src="###SRC###" width="###WIDTH###" height="###HEIGHT###" ###PARAMS### ###ALTPARAMS### ###BORDER######SELFCLOSINGTAGSLASH###>';
1344 }
1345 return $imageTagLayout;
1346 }
1347
1348 /**
1349 * Render alternate sources for the image tag. If no source collection is given an empty string is returned.
1350 *
1351 * @param string $layoutKey rendering key
1352 * @param array $conf TypoScript configuration properties
1353 * @param string $file
1354 * @throws \UnexpectedValueException
1355 * @return string
1356 */
1357 public function getImageSourceCollection($layoutKey, $conf, $file) {
1358 $sourceCollection = '';
1359 if ($layoutKey && $conf['sourceCollection.'] && ($conf['layout.'][$layoutKey . '.']['source'] || $conf['layout.'][$layoutKey . '.']['source.'])) {
1360
1361 // find active sourceCollection
1362 $activeSourceCollections = array();
1363 foreach ($conf['sourceCollection.'] as $sourceCollectionKey => $sourceCollectionConfiguration) {
1364 if (substr($sourceCollectionKey, -1) == '.') {
1365 if (
1366 (isset($sourceCollectionConfiguration['if.']) && $this->checkIf($sourceCollectionConfiguration['if.']))
1367 || !isset($sourceCollectionConfiguration['if.'])
1368 ) {
1369 $activeSourceCollections[] = $sourceCollectionConfiguration;
1370 }
1371 }
1372 }
1373
1374 // apply option split to configurations
1375 $srcLayoutOptionSplitted = $GLOBALS['TSFE']->tmpl->splitConfArray($conf['layout.'][$layoutKey . '.'], count($activeSourceCollections));
1376
1377 // render sources
1378 foreach ($activeSourceCollections as $key => $sourceConfiguration) {
1379 $sourceLayout = $this->stdWrap($srcLayoutOptionSplitted[$key]['source'], $srcLayoutOptionSplitted[$key]['source.']);
1380
1381 $sourceRenderConfiguration = array (
1382 'file' => $file,
1383 'file.' => $conf['file.']
1384 );
1385
1386 if (isset($sourceConfiguration['pixelDensity'])) {
1387 $pixelDensity = (int)$this->stdWrap($sourceConfiguration['pixelDensity'], $sourceConfiguration['pixelDensity.']);
1388 } else {
1389 $pixelDensity = 1;
1390 }
1391 $dimensionKeys = array('width', 'height', 'maxW', 'minW', 'maxH', 'minH');
1392 foreach ($dimensionKeys as $dimensionKey) {
1393 $dimension = $this->stdWrap($sourceConfiguration[$dimensionKey], $sourceConfiguration[$dimensionKey . '.']);
1394 if (!$dimension) {
1395 $dimension = $this->stdWrap($conf['file.'][$dimensionKey], $conf['file.'][$dimensionKey . '.']);
1396 }
1397 if ($dimension) {
1398 if (strstr($dimension, 'c') !== FALSE && ($dimensionKey === 'width' || $dimensionKey === 'height')) {
1399 $dimensionParts = explode('c', $dimension, 2);
1400 $dimension = (int)($dimensionParts[0] * $pixelDensity) . 'c';
1401 if ($dimensionParts[1]) {
1402 $dimension .= $dimensionParts[1];
1403 }
1404 } else {
1405 $dimension = (int)($dimension * $pixelDensity);
1406 }
1407 $sourceRenderConfiguration['file.'][$dimensionKey] = $dimension;
1408 // Remove the stdWrap properties for dimension as they have been processed already above.
1409 unset($sourceRenderConfiguration['file.'][$dimensionKey . '.']);
1410 }
1411 }
1412 $sourceInfo = $this->getImgResource($sourceRenderConfiguration['file'], $sourceRenderConfiguration['file.']);
1413 $sourceConfiguration['width'] = $sourceInfo[0];
1414 $sourceConfiguration['height'] = $sourceInfo[1];
1415 $sourceConfiguration['src'] = htmlspecialchars($sourceInfo[3]);
1416 $sourceConfiguration['selfClosingTagSlash'] = (!empty($GLOBALS['TSFE']->xhtmlDoctype) ? ' /' : '');
1417
1418 $oneSourceCollection = $this->substituteMarkerArray($sourceLayout, $sourceConfiguration, '###|###', TRUE, TRUE);
1419
1420 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['getImageSourceCollection'])) {
1421 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['getImageSourceCollection'] as $classData) {
1422 $hookObject = GeneralUtility::getUserObj($classData);
1423 if (!$hookObject instanceof ContentObjectOneSourceCollectionHookInterface) {
1424 throw new \UnexpectedValueException(
1425 '$hookObject must implement interface TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectOneSourceCollectionHookInterface',
1426 1380007853
1427 );
1428 }
1429 /** @var $hookObject \TYPO3\CMS\Frontend\ContentObject\ContentObjectGetSingleHookInterface */
1430 $oneSourceCollection = $hookObject->getOneSourceCollection((array) $sourceRenderConfiguration, (array) $sourceConfiguration, $oneSourceCollection, $this);
1431 }
1432 }
1433
1434 $sourceCollection .= $oneSourceCollection;
1435 }
1436 }
1437 return $sourceCollection;
1438 }
1439
1440 /**
1441 * Wraps the input string in link-tags that opens the image in a new window.
1442 *
1443 * @param string $string String to wrap, probably an <img> tag
1444 * @param string|\TYPO3\CMS\Core\Resource\File|\TYPO3\CMS\Core\Resource\FileReference $imageFile The original image file
1445 * @param array $conf TypoScript properties for the "imageLinkWrap" function
1446 * @return string The input string, $string, wrapped as configured.
1447 * @see cImage()
1448 * @todo Define visibility
1449 */
1450 public function imageLinkWrap($string, $imageFile, $conf) {
1451 $a1 = '';
1452 $a2 = '';
1453 $content = $string;
1454 $enable = isset($conf['enable.']) ? $this->stdWrap($conf['enable'], $conf['enable.']) : $conf['enable'];
1455 if ($enable) {
1456 $content = $this->typolink($string, $conf['typolink.']);
1457 if (isset($conf['file.'])) {
1458 $imageFile = $this->stdWrap($imageFile, $conf['file.']);
1459 }
1460
1461 if ($imageFile instanceof \TYPO3\CMS\Core\Resource\File) {
1462 $file = $imageFile;
1463 } elseif ($imageFile instanceof \TYPO3\CMS\Core\Resource\FileReference) {
1464 $file = $imageFile->getOriginalFile();
1465 } else {
1466 if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($imageFile)) {
1467 $file = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getFileObject((int)$imageFile);
1468 } else {
1469 $file = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getFileObjectFromCombinedIdentifier($imageFile);
1470 }
1471 }
1472
1473 // Create imageFileLink if not created with typolink
1474 if ($content == $string) {
1475 $parameterNames = array('width', 'height', 'effects', 'bodyTag', 'title', 'wrap');
1476 $parameters = array();
1477 $sample = isset($conf['sample.']) ? $this->stdWrap($conf['sample'], $conf['sample.']) : $conf['sample'];
1478 if ($sample) {
1479 $parameters['sample'] = 1;
1480 }
1481 foreach ($parameterNames as $parameterName) {
1482 if (isset($conf[$parameterName . '.'])) {
1483 $conf[$parameterName] = $this->stdWrap($conf[$parameterName], $conf[$parameterName . '.']);
1484 }
1485 if (isset($conf[$parameterName]) && $conf[$parameterName]) {
1486 $parameters[$parameterName] = $conf[$parameterName];
1487 }
1488 }
1489 $parametersEncoded = base64_encode(serialize($parameters));
1490 $hmac = GeneralUtility::hmac(implode('|', array($file->getUid(), $parametersEncoded)));
1491 $params = '&md5=' . $hmac;
1492 foreach (str_split($parametersEncoded, 64) as $index => $chunk) {
1493 $params .= '&parameters' . rawurlencode('[') . $index . rawurlencode(']') . '=' . rawurlencode($chunk);
1494 }
1495 $url = $GLOBALS['TSFE']->absRefPrefix . 'index.php?eID=tx_cms_showpic&file=' . $file->getUid() . $params;
1496 $directImageLink = isset($conf['directImageLink.']) ? $this->stdWrap($conf['directImageLink'], $conf['directImageLink.']) : $conf['directImageLink'];
1497 if ($directImageLink) {
1498 $imgResourceConf = array(
1499 'file' => $imageFile,
1500 'file.' => $conf
1501 );
1502 $url = $this->IMG_RESOURCE($imgResourceConf);
1503 if (!$url) {
1504 // If no imagemagick / gm is available
1505 $url = $imageFile;
1506 }
1507 }
1508 // Create TARGET-attribute only if the right doctype is used
1509 if (!GeneralUtility::inList('xhtml_strict,xhtml_11,xhtml_2', $GLOBALS['TSFE']->xhtmlDoctype)) {
1510 $target = isset($conf['target.']) ? $this->stdWrap($conf['target'], $conf['target.']) : $conf['target'];
1511 if ($target) {
1512 $target = sprintf(' target="%s"', $target);
1513 } else {
1514 $target = ' target="thePicture"';
1515 }
1516 } else {
1517 $target = '';
1518 }
1519 $conf['JSwindow'] = isset($conf['JSwindow.']) ? $this->stdWrap($conf['JSwindow'], $conf['JSwindow.']) : $conf['JSwindow'];
1520 if ($conf['JSwindow']) {
1521 if ($conf['JSwindow.']['altUrl'] || $conf['JSwindow.']['altUrl.']) {
1522 $altUrl = isset($conf['JSwindow.']['altUrl.']) ? $this->stdWrap($conf['JSwindow.']['altUrl'], $conf['JSwindow.']['altUrl.']) : $conf['JSwindow.']['altUrl'];
1523 if ($altUrl) {
1524 $url = $altUrl . ($conf['JSwindow.']['altUrl_noDefaultParams'] ? '' : '?file=' . rawurlencode($imageFile) . $params);
1525 }
1526 }
1527
1528 $processedFile = $file->process('Image.CropScaleMask', $conf);
1529 $JSwindowExpand = isset($conf['JSwindow.']['expand.']) ? $this->stdWrap($conf['JSwindow.']['expand'], $conf['JSwindow.']['expand.']) : $conf['JSwindow.']['expand'];
1530 $offset = GeneralUtility::intExplode(',', $JSwindowExpand . ',');
1531 $newWindow = isset($conf['JSwindow.']['newWindow.']) ? $this->stdWrap($conf['JSwindow.']['newWindow'], $conf['JSwindow.']['newWindow.']) : $conf['JSwindow.']['newWindow'];
1532 $a1 = '<a href="' . htmlspecialchars($url) . '" onclick="' . htmlspecialchars(('openPic(\'' . $GLOBALS['TSFE']->baseUrlWrap($url) . '\',\'' . ($newWindow ? md5($url) : 'thePicture') . '\',\'width=' . ($processedFile->getProperty('width') + $offset[0]) . ',height=' . ($processedFile->getProperty('height') + $offset[1]) . ',status=0,menubar=0\'); return false;')) . '"' . $target . $GLOBALS['TSFE']->ATagParams . '>';
1533 $a2 = '</a>';
1534 $GLOBALS['TSFE']->setJS('openPic');
1535 } else {
1536 $conf['linkParams.']['parameter'] = $url;
1537 $string = $this->typoLink($string, $conf['linkParams.']);
1538 }
1539 if (isset($conf['stdWrap.'])) {
1540 $string = $this->stdWrap($string, $conf['stdWrap.']);
1541 }
1542 $content = $a1 . $string . $a2;
1543 }
1544 }
1545 return $content;
1546 }
1547
1548 /**
1549 * Returns content of a file. If it's an image the content of the file is not returned but rather an image tag is.
1550 *
1551 * @param string $fName The filename, being a TypoScript resource data type
1552 * @param string $addParams Additional parameters (attributes). Default is empty alt and title tags.
1553 * @return string If jpg,gif,jpeg,png: returns image_tag with picture in. If html,txt: returns content string
1554 * @see FILE()
1555 * @todo Define visibility
1556 */
1557 public function fileResource($fName, $addParams = 'alt="" title=""') {
1558 $incFile = $GLOBALS['TSFE']->tmpl->getFileName($fName);
1559 if ($incFile) {
1560 $fileinfo = GeneralUtility::split_fileref($incFile);
1561 if (GeneralUtility::inList('jpg,gif,jpeg,png', $fileinfo['fileext'])) {
1562 $imgFile = $incFile;
1563 $imgInfo = @getImageSize($imgFile);
1564 return '<img src="' . $GLOBALS['TSFE']->absRefPrefix . $imgFile . '" width="' . $imgInfo[0] . '" height="' . $imgInfo[1] . '"' . $this->getBorderAttr(' border="0"') . ' ' . $addParams . ' />';
1565 } elseif (filesize($incFile) < 1024 * 1024) {
1566 return $GLOBALS['TSFE']->tmpl->fileContent($incFile);
1567 }
1568 }
1569 }
1570
1571 /**
1572 * Sets the SYS_LASTCHANGED timestamp if input timestamp is larger than current value.
1573 * The SYS_LASTCHANGED timestamp can be used by various caching/indexing applications to determine if the page has new content.
1574 * Therefore you should call this function with the last-changed timestamp of any element you display.
1575 *
1576 * @param integer $tstamp Unix timestamp (number of seconds since 1970)
1577 * @return void
1578 * @see \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::setSysLastChanged()
1579 * @todo Define visibility
1580 */
1581 public function lastChanged($tstamp) {
1582 $tstamp = (int)$tstamp;
1583 if ($tstamp > (int)$GLOBALS['TSFE']->register['SYS_LASTCHANGED']) {
1584 $GLOBALS['TSFE']->register['SYS_LASTCHANGED'] = $tstamp;
1585 }
1586 }
1587
1588 /**
1589 * Wraps the input string by the $wrap value and implements the "linkWrap" data type as well.
1590 * The "linkWrap" data type means that this function will find any integer encapsulated in {} (curly braces) in the first wrap part and substitute it with the corresponding page uid from the rootline where the found integer is pointing to the key in the rootline. See link below.
1591 *
1592 * @param string $content Input string
1593 * @param string $wrap A string where the first two parts separated by "|" (vertical line) will be wrapped around the input string
1594 * @return string Wrapped output string
1595 * @see wrap(), cImage(), FILE()
1596 * @todo Define visibility
1597 */
1598 public function linkWrap($content, $wrap) {
1599 $wrapArr = explode('|', $wrap);
1600 if (preg_match('/\\{([0-9]*)\\}/', $wrapArr[0], $reg)) {
1601 if ($uid = $GLOBALS['TSFE']->tmpl->rootLine[$reg[1]]['uid']) {
1602 $wrapArr[0] = str_replace($reg[0], $uid, $wrapArr[0]);
1603 }
1604 }
1605 return trim($wrapArr[0]) . $content . trim($wrapArr[1]);
1606 }
1607
1608 /**
1609 * An abstraction method which creates an alt or title parameter for an HTML img, applet, area or input element and the FILE content element.
1610 * From the $conf array it implements the properties "altText", "titleText" and "longdescURL"
1611 *
1612 * @param array $conf TypoScript configuration properties
1613 * @param boolean $longDesc If set, the longdesc attribute will be generated - must only be used for img elements!
1614 * @return string Parameter string containing alt and title parameters (if any)
1615 * @see IMGTEXT(), FILE(), FORM(), cImage(), filelink()
1616 * @todo Define visibility
1617 */
1618 public function getAltParam($conf, $longDesc = TRUE) {
1619 $altText = isset($conf['altText.']) ? trim($this->stdWrap($conf['altText'], $conf['altText.'])) : trim($conf['altText']);
1620 $titleText = isset($conf['titleText.']) ? trim($this->stdWrap($conf['titleText'], $conf['titleText.'])) : trim($conf['titleText']);
1621 if (isset($conf['longdescURL.']) && $GLOBALS['TSFE']->config['config']['doctype'] != 'html5') {
1622 $longDesc = $this->typoLink_URL($conf['longdescURL.']);
1623 } else {
1624 $longDesc = trim($conf['longdescURL']);
1625 }
1626 // "alt":
1627 $altParam = ' alt="' . htmlspecialchars($altText) . '"';
1628 // "title":
1629 $emptyTitleHandling = 'useAlt';
1630 $emptyTitleHandling = isset($conf['emptyTitleHandling.']) ? $this->stdWrap($conf['emptyTitleHandling'], $conf['emptyTitleHandling.']) : $conf['emptyTitleHandling'];
1631 // Choices: 'keepEmpty' | 'useAlt' | 'removeAttr'
1632 if ($titleText || $emptyTitleHandling == 'keepEmpty') {
1633 $altParam .= ' title="' . htmlspecialchars($titleText) . '"';
1634 } elseif (!$titleText && $emptyTitleHandling == 'useAlt') {
1635 $altParam .= ' title="' . htmlspecialchars($altText) . '"';
1636 }
1637 // "longDesc" URL
1638 if ($longDesc) {
1639 $altParam .= ' longdesc="' . htmlspecialchars(strip_tags($longDesc)) . '"';
1640 }
1641 return $altParam;
1642 }
1643
1644 /**
1645 * Removes forbidden characters and spaces from name/id attributes in the form tag and formfields
1646 *
1647 * @param string $name Input string
1648 * @return string the cleaned string
1649 * @see FORM()
1650 * @todo Define visibility
1651 */
1652 public function cleanFormName($name) {
1653 // Turn data[x][y] into data:x:y:
1654 $name = preg_replace('/\\[|\\]\\[?/', ':', trim($name));
1655 // Remove illegal chars like _
1656 return preg_replace('#[^:a-zA-Z0-9]#', '', $name);
1657 }
1658
1659 /**
1660 * An abstraction method to add parameters to an A tag.
1661 * Uses the ATagParams property.
1662 *
1663 * @param array $conf TypoScript configuration properties
1664 * @param boolean $addGlobal If set, will add the global config.ATagParams to the link
1665 * @return string String containing the parameters to the A tag (if non empty, with a leading space)
1666 * @see IMGTEXT(), filelink(), makelinks(), typolink()
1667 * @todo Define visibility
1668 */
1669 public function getATagParams($conf, $addGlobal = 1) {
1670 $aTagParams = '';
1671 if ($conf['ATagParams.']) {
1672 $aTagParams = ' ' . $this->stdWrap($conf['ATagParams'], $conf['ATagParams.']);
1673 } elseif ($conf['ATagParams']) {
1674 $aTagParams = ' ' . $conf['ATagParams'];
1675 }
1676 if ($addGlobal) {
1677 $aTagParams = ' ' . trim(($GLOBALS['TSFE']->ATagParams . $aTagParams));
1678 }
1679 // Extend params
1680 if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['getATagParamsPostProc']) && is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['getATagParamsPostProc'])) {
1681 $_params = array(
1682 'conf' => &$conf,
1683 'aTagParams' => &$aTagParams
1684 );
1685 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['getATagParamsPostProc'] as $objRef) {
1686 $processor =& GeneralUtility::getUserObj($objRef);
1687 $aTagParams = $processor->process($_params, $this);
1688 }
1689 }
1690
1691 $aTagParams = trim($aTagParams);
1692 if (!empty($aTagParams)) {
1693 $aTagParams = ' ' . $aTagParams;
1694 }
1695
1696 return $aTagParams;
1697 }
1698
1699 /**
1700 * All extension links should ask this function for additional properties to their tags.
1701 * Designed to add for instance an "onclick" property for site tracking systems.
1702 *
1703 * @param string $URL URL of the website
1704 * @param string $TYPE
1705 * @return string The additional tag properties
1706 * @todo Define visibility
1707 */
1708 public function extLinkATagParams($URL, $TYPE) {
1709 $out = '';
1710 if ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['extLinkATagParamsHandler']) {
1711 $extLinkATagParamsHandler = GeneralUtility::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['extLinkATagParamsHandler']);
1712 if (method_exists($extLinkATagParamsHandler, 'main')) {
1713 $out .= trim($extLinkATagParamsHandler->main($URL, $TYPE, $this));
1714 }
1715 }
1716 return trim($out) ? ' ' . trim($out) : '';
1717 }
1718
1719 /***********************************************
1720 *
1721 * HTML template processing functions
1722 *
1723 ***********************************************/
1724 /**
1725 * Returns a subpart from the input content stream.
1726 * A subpart is a part of the input stream which is encapsulated in a
1727 * string matching the input string, $marker. If this string is found
1728 * inside of HTML comment tags the start/end points of the content block
1729 * returned will be that right outside that comment block.
1730 * Example: The contennt string is
1731 * "Hello <!--###sub1### begin--> World. How are <!--###sub1### end--> you?"
1732 * If $marker is "###sub1###" then the content returned is
1733 * " World. How are ". The input content string could just as well have
1734 * been "Hello ###sub1### World. How are ###sub1### you?" and the result
1735 * would be the same
1736 * Wrapper for \TYPO3\CMS\Core\Html\HtmlParser::getSubpart which behaves identical
1737 *
1738 * @param string $content The content stream, typically HTML template content.
1739 * @param string $marker The marker string, typically on the form "###[the marker string]###
1740 * @return string The subpart found, if found.
1741 */
1742 public function getSubpart($content, $marker) {
1743 return \TYPO3\CMS\Core\Html\HtmlParser::getSubpart($content, $marker);
1744 }
1745
1746 /**
1747 * Substitute subpart in input template stream.
1748 * This function substitutes a subpart in $content with the content of
1749 * $subpartContent.
1750 * Wrapper for \TYPO3\CMS\Core\Html\HtmlParser::substituteSubpart which behaves identical
1751 *
1752 * @param string $content The content stream, typically HTML template content.
1753 * @param string $marker The marker string, typically on the form "###[the marker string]###
1754 * @param mixed $subpartContent The content to insert instead of the subpart found. If a string, then just plain substitution happens (includes removing the HTML comments of the subpart if found). If $subpartContent happens to be an array, it's [0] and [1] elements are wrapped around the EXISTING content of the subpart (fetched by getSubpart()) thereby not removing the original content.
1755 * @param boolean $recursive If $recursive is set, the function calls itself with the content set to the remaining part of the content after the second marker. This means that proceding subparts are ALSO substituted!
1756 * @return string The processed HTML content string.
1757 */
1758 public function substituteSubpart($content, $marker, $subpartContent, $recursive = 1) {
1759 return \TYPO3\CMS\Core\Html\HtmlParser::substituteSubpart($content, $marker, $subpartContent, $recursive);
1760 }
1761
1762 /**
1763 * Substitues multiple subparts at once
1764 *
1765 * @param string $content The content stream, typically HTML template content.
1766 * @param array $subpartsContent The array of key/value pairs being subpart/content values used in the substitution. For each element in this array the function will substitute a subpart in the content stream with the content.
1767 * @return string The processed HTML content string.
1768 */
1769 public function substituteSubpartArray($content, array $subpartsContent) {
1770 return \TYPO3\CMS\Core\Html\HtmlParser::substituteSubpartArray($content, $subpartsContent);
1771 }
1772
1773 /**
1774 * Substitutes a marker string in the input content
1775 * (by a simple str_replace())
1776 *
1777 * @param string $content The content stream, typically HTML template content.
1778 * @param string $marker The marker string, typically on the form "###[the marker string]###
1779 * @param mixed $markContent The content to insert instead of the marker string found.
1780 * @return string The processed HTML content string.
1781 * @see substituteSubpart()
1782 */
1783 public function substituteMarker($content, $marker, $markContent) {
1784 return \TYPO3\CMS\Core\Html\HtmlParser::substituteMarker($content, $marker, $markContent);
1785 }
1786
1787 /**
1788 * Multi substitution function with caching.
1789 *
1790 * This function should be a one-stop substitution function for working
1791 * with HTML-template. It does not substitute by str_replace but by
1792 * splitting. This secures that the value inserted does not themselves
1793 * contain markers or subparts.
1794 *
1795 * Note that the "caching" won't cache the content of the substition,
1796 * but only the splitting of the template in various parts. So if you
1797 * want only one cache-entry per template, make sure you always pass the
1798 * exact same set of marker/subpart keys. Else you will be flooding the
1799 * users cache table.
1800 *
1801 * This function takes three kinds of substitutions in one:
1802 * $markContentArray is a regular marker-array where the 'keys' are
1803 * substituted in $content with their values
1804 *
1805 * $subpartContentArray works exactly like markContentArray only is whole
1806 * subparts substituted and not only a single marker.
1807 *
1808 * $wrappedSubpartContentArray is an array of arrays with 0/1 keys where
1809 * the subparts pointed to by the main key is wrapped with the 0/1 value
1810 * alternating.
1811 *
1812 * @param string $content The content stream, typically HTML template content.
1813 * @param array $markContentArray Regular marker-array where the 'keys' are substituted in $content with their values
1814 * @param array $subpartContentArray Exactly like markContentArray only is whole subparts substituted and not only a single marker.
1815 * @param array $wrappedSubpartContentArray An array of arrays with 0/1 keys where the subparts pointed to by the main key is wrapped with the 0/1 value alternating.
1816 * @return string The output content stream
1817 * @see substituteSubpart(), substituteMarker(), substituteMarkerInObject(), TEMPLATE()
1818 */
1819 public function substituteMarkerArrayCached($content, array $markContentArray = NULL, array $subpartContentArray = NULL, array $wrappedSubpartContentArray = NULL) {
1820 $GLOBALS['TT']->push('substituteMarkerArrayCached');
1821 // If not arrays then set them
1822 if (is_null($markContentArray)) {
1823 // Plain markers
1824 $markContentArray = array();
1825 }
1826 if (is_null($subpartContentArray)) {
1827 // Subparts being directly substituted
1828 $subpartContentArray = array();
1829 }
1830 if (is_null($wrappedSubpartContentArray)) {
1831 // Subparts being wrapped
1832 $wrappedSubpartContentArray = array();
1833 }
1834 // Finding keys and check hash:
1835 $sPkeys = array_keys($subpartContentArray);
1836 $wPkeys = array_keys($wrappedSubpartContentArray);
1837 $aKeys = array_merge(array_keys($markContentArray), $sPkeys, $wPkeys);
1838 if (!count($aKeys)) {
1839 $GLOBALS['TT']->pull();
1840 return $content;
1841 }
1842 asort($aKeys);
1843 $storeKey = md5('substituteMarkerArrayCached_storeKey:' . serialize(array(
1844 $content,
1845 $aKeys
1846 )));
1847 if ($this->substMarkerCache[$storeKey]) {
1848 $storeArr = $this->substMarkerCache[$storeKey];
1849 $GLOBALS['TT']->setTSlogMessage('Cached', 0);
1850 } else {
1851 $storeArrDat = $GLOBALS['TSFE']->sys_page->getHash($storeKey);
1852 if (is_array($storeArrDat)) {
1853 $storeArr = $storeArrDat;
1854 // Setting cache:
1855 $this->substMarkerCache[$storeKey] = $storeArr;
1856 $GLOBALS['TT']->setTSlogMessage('Cached from DB', 0);
1857 } else {
1858 // Initialize storeArr
1859 $storeArr = array();
1860 // Finding subparts and substituting them with the subpart as a marker
1861 foreach ($sPkeys as $sPK) {
1862 $content = $this->substituteSubpart($content, $sPK, $sPK);
1863 }
1864 // Finding subparts and wrapping them with markers
1865 foreach ($wPkeys as $wPK) {
1866 $content = $this->substituteSubpart($content, $wPK, array(
1867 $wPK,
1868 $wPK
1869 ));
1870 }
1871 // Traverse keys and quote them for reg ex.
1872 foreach ($aKeys as $tK => $tV) {
1873 $aKeys[$tK] = preg_quote($tV, '/');
1874 }
1875 $regex = '/' . implode('|', $aKeys) . '/';
1876 // Doing regex's
1877 $storeArr['c'] = preg_split($regex, $content);
1878 preg_match_all($regex, $content, $keyList);
1879 $storeArr['k'] = $keyList[0];
1880 // Setting cache:
1881 $this->substMarkerCache[$storeKey] = $storeArr;
1882 // Storing the cached data:
1883 $GLOBALS['TSFE']->sys_page->storeHash($storeKey, $storeArr, 'substMarkArrayCached');
1884 $GLOBALS['TT']->setTSlogMessage('Parsing', 0);
1885 }
1886 }
1887 // Substitution/Merging:
1888 // Merging content types together, resetting
1889 $valueArr = array_merge($markContentArray, $subpartContentArray, $wrappedSubpartContentArray);
1890 $wSCA_reg = array();
1891 $content = '';
1892 // Traversing the keyList array and merging the static and dynamic content
1893 foreach ($storeArr['k'] as $n => $keyN) {
1894 $content .= $storeArr['c'][$n];
1895 if (!is_array($valueArr[$keyN])) {
1896 $content .= $valueArr[$keyN];
1897 } else {
1898 $content .= $valueArr[$keyN][(int)$wSCA_reg[$keyN] % 2];
1899 $wSCA_reg[$keyN]++;
1900 }
1901 }
1902 $content .= $storeArr['c'][count($storeArr['k'])];
1903 $GLOBALS['TT']->pull();
1904 return $content;
1905 }
1906
1907 /**
1908 * Traverses the input $markContentArray array and for each key the marker
1909 * by the same name (possibly wrapped and in upper case) will be
1910 * substituted with the keys value in the array.
1911 *
1912 * This is very useful if you have a data-record to substitute in some
1913 * content. In particular when you use the $wrap and $uppercase values to
1914 * pre-process the markers. Eg. a key name like "myfield" could effectively
1915 * be represented by the marker "###MYFIELD###" if the wrap value
1916 * was "###|###" and the $uppercase boolean TRUE.
1917 *
1918 * @param string $content The content stream, typically HTML template content.
1919 * @param array $markContentArray The array of key/value pairs being marker/content values used in the substitution. For each element in this array the function will substitute a marker in the content stream with the content.
1920 * @param string $wrap A wrap value - [part 1] | [part 2] - for the markers before substitution
1921 * @param boolean $uppercase If set, all marker string substitution is done with upper-case markers.
1922 * @param boolean $deleteUnused If set, all unused marker are deleted.
1923 * @return string The processed output stream
1924 * @see substituteMarker(), substituteMarkerInObject(), TEMPLATE()
1925 */
1926 public function substituteMarkerArray($content, array $markContentArray, $wrap = '', $uppercase = FALSE, $deleteUnused = FALSE) {
1927 return \TYPO3\CMS\Core\Html\HtmlParser::substituteMarkerArray($content, $markContentArray, $wrap, $uppercase, $deleteUnused);
1928 }
1929
1930 /**
1931 * Substitute marker array in an array of values
1932 *
1933 * @param mixed $tree If string, then it just calls substituteMarkerArray. If array(and even multi-dim) then for each key/value pair the marker array will be substituted (by calling this function recursively)
1934 * @param array $markContentArray The array of key/value pairs being marker/content values used in the substitution. For each element in this array the function will substitute a marker in the content string/array values.
1935 * @return mixed The processed input variable.
1936 * @see substituteMarker()
1937 */
1938 public function substituteMarkerInObject(&$tree, array $markContentArray) {
1939 if (is_array($tree)) {
1940 foreach ($tree as $key => $value) {
1941 $this->substituteMarkerInObject($tree[$key], $markContentArray);
1942 }
1943 } else {
1944 $tree = $this->substituteMarkerArray($tree, $markContentArray);
1945 }
1946 return $tree;
1947 }
1948
1949 /**
1950 * Replaces all markers and subparts in a template with the content provided in the structured array.
1951 *
1952 * @param string $content
1953 * @param array $markersAndSubparts
1954 * @param string $wrap
1955 * @param boolean $uppercase
1956 * @param boolean $deleteUnused
1957 * @return string
1958 */
1959 public function substituteMarkerAndSubpartArrayRecursive($content, array $markersAndSubparts, $wrap = '', $uppercase = FALSE, $deleteUnused = FALSE) {
1960 return \TYPO3\CMS\Core\Html\HtmlParser::substituteMarkerAndSubpartArrayRecursive($content, $markersAndSubparts, $wrap, $uppercase, $deleteUnused);
1961 }
1962
1963 /**
1964 * Adds elements to the input $markContentArray based on the values from
1965 * the fields from $fieldList found in $row
1966 *
1967 * @param array $markContentArray Array with key/values being marker-strings/substitution values.
1968 * @param array $row An array with keys found in the $fieldList (typically a record) which values should be moved to the $markContentArray
1969 * @param string $fieldList A list of fields from the $row array to add to the $markContentArray array. If empty all fields from $row will be added (unless they are integers)
1970 * @param boolean $nl2br If set, all values added to $markContentArray will be nl2br()'ed
1971 * @param string $prefix Prefix string to the fieldname before it is added as a key in the $markContentArray. Notice that the keys added to the $markContentArray always start and end with "###
1972 * @param boolean $HSC If set, all values are passed through htmlspecialchars() - RECOMMENDED to avoid most obvious XSS and maintain XHTML compliance.
1973 * @return array The modified $markContentArray
1974 */
1975 public function fillInMarkerArray(array $markContentArray, array $row, $fieldList = '', $nl2br = TRUE, $prefix = 'FIELD_', $HSC = FALSE) {
1976 if ($fieldList) {
1977 $fArr = GeneralUtility::trimExplode(',', $fieldList, TRUE);
1978 foreach ($fArr as $field) {
1979 $markContentArray['###' . $prefix . $field . '###'] = $nl2br ? nl2br($row[$field], !empty($GLOBALS['TSFE']->xhtmlDoctype)) : $row[$field];
1980 }
1981 } else {
1982 if (is_array($row)) {
1983 foreach ($row as $field => $value) {
1984 if (!\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($field)) {
1985 if ($HSC) {
1986 $value = htmlspecialchars($value);
1987 }
1988 $markContentArray['###' . $prefix . $field . '###'] = $nl2br ? nl2br($value, !empty($GLOBALS['TSFE']->xhtmlDoctype)) : $value;
1989 }
1990 }
1991 }
1992 }
1993 return $markContentArray;
1994 }
1995
1996 /**
1997 * Sets the current file object during iterations over files.
1998 *
1999 * @param \TYPO3\CMS\Core\Resource\File $fileObject The file object.
2000 */
2001 public function setCurrentFile($fileObject) {
2002 $this->currentFile = $fileObject;
2003 }
2004
2005 /**
2006 * Gets the current file object during iterations over files.
2007 *
2008 * @return \TYPO3\CMS\Core\Resource\File The current file object.
2009 */
2010 public function getCurrentFile() {
2011 return $this->currentFile;
2012 }
2013
2014 /***********************************************
2015 *
2016 * "stdWrap" + sub functions
2017 *
2018 ***********************************************/
2019 /**
2020 * The "stdWrap" function. This is the implementation of what is known as "stdWrap properties" in TypoScript.
2021 * Basically "stdWrap" performs some processing of a value based on properties in the input $conf array(holding the TypoScript "stdWrap properties")
2022 * See the link below for a complete list of properties and what they do. The order of the table with properties found in TSref (the link) follows the actual order of implementation in this function.
2023 *
2024 * If $this->alternativeData is an array it's used instead of the $this->data array in ->getData
2025 *
2026 * @param string $content Input value undergoing processing in this function. Possibly substituted by other values fetched from another source.
2027 * @param array $conf TypoScript "stdWrap properties".
2028 * @return string The processed input value
2029 */
2030 public function stdWrap($content = '', $conf = array()) {
2031 // If there is any hook object, activate all of the process and override functions.
2032 // The hook interface ContentObjectStdWrapHookInterface takes care that all 4 methods exist.
2033 if ($this->stdWrapHookObjects) {
2034 $conf['stdWrapPreProcess'] = 1;
2035 $conf['stdWrapOverride'] = 1;
2036 $conf['stdWrapProcess'] = 1;
2037 $conf['stdWrapPostProcess'] = 1;
2038 }
2039
2040 if (!is_array($conf) || !$conf) {
2041 return $content;
2042 }
2043
2044 // Cache handling
2045 if (is_array($conf['cache.'])) {
2046 $conf['cache.']['key'] = $this->stdWrap($conf['cache.']['key'], $conf['cache.']['key.']);
2047 $conf['cache.']['tags'] = $this->stdWrap($conf['cache.']['tags'], $conf['cache.']['tags.']);
2048 $conf['cache.']['lifetime'] = $this->stdWrap($conf['cache.']['lifetime'], $conf['cache.']['lifetime.']);
2049 $conf['cacheRead'] = 1;
2050 $conf['cacheStore'] = 1;
2051 }
2052 // Check, which of the available stdWrap functions is needed for the current conf Array
2053 // and keep only those but still in the same order
2054 $sortedConf = array_intersect_key($this->stdWrapOrder, $conf);
2055 // Functions types that should not make use of nested stdWrap function calls to avoid conflicts with internal TypoScript used by these functions
2056 $stdWrapDisabledFunctionTypes = 'cObject,functionName,stdWrap';
2057 // Additional Array to check whether a function has already been executed
2058 $isExecuted = array();
2059 // Additional switch to make sure 'required', 'if' and 'fieldRequired'
2060 // will still stop rendering immediately in case they return FALSE
2061 $this->stdWrapRecursionLevel++;
2062 $this->stopRendering[$this->stdWrapRecursionLevel] = FALSE;
2063 // execute each function in the predefined order
2064 foreach ($sortedConf as $stdWrapName => $functionType) {
2065 // eliminate the second key of a pair 'key'|'key.' to make sure functions get called only once and check if rendering has been stopped
2066 if (!$isExecuted[$stdWrapName] && !$this->stopRendering[$this->stdWrapRecursionLevel]) {
2067 $functionName = rtrim($stdWrapName, '.');
2068 $functionProperties = $functionName . '.';
2069 // If there is any code one the next level, check if it contains "official" stdWrap functions
2070 // if yes, execute them first - will make each function stdWrap aware
2071 // so additional stdWrap calls within the functions can be removed, since the result will be the same
2072 // exception: the recursive stdWrap function and cObject will still be using their own stdWrap call, since it modifies the content and not a property
2073 if (count($conf[$functionProperties]) && !GeneralUtility::inList($stdWrapDisabledFunctionTypes, $functionType)) {
2074 if (array_intersect_key($this->stdWrapOrder, $conf[$functionProperties])) {
2075 $conf[$functionName] = $this->stdWrap($conf[$functionName], $conf[$functionProperties]);
2076 }
2077 }
2078 // Get just that part of $conf that is needed for the particular function
2079 $singleConf = array(
2080 $functionName => $conf[$functionName],
2081 $functionProperties => $conf[$functionProperties]
2082 );
2083 // In this special case 'spaceBefore' and 'spaceAfter' need additional stuff from 'space.''
2084 if ($functionName == 'spaceBefore' || $functionName == 'spaceAfter') {
2085 $singleConf['space.'] = $conf['space.'];
2086 }
2087 // Hand over the whole $conf array to the stdWrapHookObjects
2088 if ($functionType === 'hook') {
2089 $singleConf = $conf;
2090 }
2091 // Check if key is still containing something, since it might have been changed by next level stdWrap before
2092 if ((isset($conf[$functionName]) || $conf[$functionProperties]) && !($functionType == 'boolean' && !$conf[$functionName])) {
2093 // Add both keys - with and without the dot - to the set of executed functions
2094 $isExecuted[$functionName] = TRUE;
2095 $isExecuted[$functionProperties] = TRUE;
2096 // Call the function with the prefix stdWrap_ to make sure nobody can execute functions just by adding their name to the TS Array
2097 $functionName = 'stdWrap_' . $functionName;
2098 $content = $this->{$functionName}($content, $singleConf);
2099 } elseif ($functionType == 'boolean' && !$conf[$functionName]) {
2100 $isExecuted[$functionName] = TRUE;
2101 $isExecuted[$functionProperties] = TRUE;
2102 }
2103 }
2104 }
2105 unset($this->stopRendering[$this->stdWrapRecursionLevel]);
2106 $this->stdWrapRecursionLevel--;
2107
2108 return $content;
2109 }
2110
2111 /**
2112 * Gets a configuration value by passing them through stdWrap first and taking a default value if stdWrap doesn't yield a result.
2113 *
2114 * @param string $key The config variable key (from TS array).
2115 * @param array $config The TypoScript array.
2116 * @param string $defaultValue Optional default value.
2117 * @return string Value of the config variable
2118 */
2119 public function stdWrapValue($key, array $config, $defaultValue = '') {
2120 if (isset($config[$key])) {
2121 if (!isset($config[$key . '.'])) {
2122 return $config[$key];
2123 }
2124 } elseif (isset($config[$key . '.'])) {
2125 $config[$key] = '';
2126 } else {
2127 return $defaultValue;
2128 }
2129 $stdWrapped = $this->stdWrap($config[$key], $config[$key . '.']);
2130 return $stdWrapped ?: $defaultValue;
2131 }
2132
2133 /**
2134 * stdWrap pre process hook
2135 * can be used by extensions authors to modify the behaviour of stdWrap functions to their needs
2136 * this hook will execute functions before any other stdWrap function can modify anything
2137 *
2138 * @param string $content Input value undergoing processing in these functions.
2139 * @param array $conf All stdWrap properties, not just the ones for a particular function.
2140 * @return string The processed input value
2141 */
2142 public function stdWrap_stdWrapPreProcess($content = '', $conf = array()) {
2143 foreach ($this->stdWrapHookObjects as $hookObject) {
2144 $content = $hookObject->stdWrapPreProcess($content, $conf, $this);
2145 }
2146 return $content;
2147 }
2148
2149 /**
2150 * Check if content was cached before (depending on the given cache key)
2151 *
2152 * @param string $content Input value undergoing processing in these functions.
2153 * @param array $conf All stdWrap properties, not just the ones for a particular function.
2154 * @return string The processed input value
2155 */
2156 public function stdWrap_cacheRead($content = '', $conf = array()) {
2157 if (!empty($conf['cache.']['key'])) {
2158 /** @var $cacheFrontend \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend */
2159 $cacheFrontend = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('cache_hash');
2160 if ($cacheFrontend && $cacheFrontend->has($conf['cache.']['key'])) {
2161 $content = $cacheFrontend->get($conf['cache.']['key']);
2162 $this->stopRendering[$this->stdWrapRecursionLevel] = TRUE;
2163 }
2164 }
2165 return $content;
2166 }
2167
2168 /**
2169 * Add tags to page cache (comma-separated list)
2170 *
2171 * @param string $content Input value undergoing processing in these functions.
2172 * @param array $conf All stdWrap properties, not just the ones for a particular function.
2173 * @return string The processed input value
2174 */
2175 public function stdWrap_addPageCacheTags($content = '', $conf = array()) {
2176 $tags = isset($conf['addPageCacheTags.'])
2177 ? $this->stdWrap($conf['addPageCacheTags'], $conf['addPageCacheTags.'])
2178 : $conf['addPageCacheTags'];
2179 if (!empty($tags)) {
2180 $cacheTags = GeneralUtility::trimExplode(',', $tags, TRUE);
2181 $GLOBALS['TSFE']->addCacheTags($cacheTags);
2182 }
2183 return $content;
2184 }
2185
2186 /**
2187 * setContentToCurrent
2188 * actually it just does the contrary: Sets the value of 'current' based on current content
2189 *
2190 * @param string $content Input value undergoing processing in this function.
2191 * @param array $conf stdWrap properties for setContentToCurrent.
2192 * @return string The processed input value
2193 */
2194 public function stdWrap_setContentToCurrent($content = '', $conf = array()) {
2195 $this->data[$this->currentValKey] = $content;
2196 return $content;
2197 }
2198
2199 /**
2200 * setCurrent
2201 * Sets the value of 'current' based on the outcome of stdWrap operations
2202 *
2203 * @param string $content Input value undergoing processing in this function.
2204 * @param array $conf stdWrap properties for setCurrent.
2205 * @return string The processed input value
2206 */
2207 public function stdWrap_setCurrent($content = '', $conf = array()) {
2208 $this->data[$this->currentValKey] = $conf['setCurrent'];
2209 return $content;
2210 }
2211
2212 /**
2213 * lang
2214 * Translates content based on the language currently used by the FE
2215 *
2216 * @param string $content Input value undergoing processing in this function.
2217 * @param array $conf stdWrap properties for lang.
2218 * @return string The processed input value
2219 */
2220 public function stdWrap_lang($content = '', $conf = array()) {
2221 if (isset($conf['lang.']) && $GLOBALS['TSFE']->config['config']['language'] && isset($conf['lang.'][$GLOBALS['TSFE']->config['config']['language']])) {
2222 $content = $conf['lang.'][$GLOBALS['TSFE']->config['config']['language']];
2223 }
2224 return $content;
2225 }
2226
2227 /**
2228 * data
2229 * Gets content from different sources based on getText functions, makes use of alternativeData, when set
2230 *
2231 * @param string $content Input value undergoing processing in this function.
2232 * @param array $conf stdWrap properties for data.
2233 * @return string The processed input value
2234 */
2235 public function stdWrap_data($content = '', $conf = array()) {
2236 $content = $this->getData($conf['data'], is_array($this->alternativeData) ? $this->alternativeData : $this->data);
2237 // This must be unset directly after
2238 $this->alternativeData = '';
2239 return $content;
2240 }
2241
2242 /**
2243 * field
2244 * Gets content from a DB field
2245 *
2246 * @param string $content Input value undergoing processing in this function.
2247 * @param array $conf stdWrap properties for field.
2248 * @return string The processed input value
2249 */
2250 public function stdWrap_field($content = '', $conf = array()) {
2251 return $this->getFieldVal($conf['field']);
2252 }
2253
2254 /**
2255 * current
2256 * Gets content that has been perviously set as 'current'
2257 * Can be set via setContentToCurrent or setCurrent or will be set automatically i.e. inside the split function
2258 *
2259 * @param string $content Input value undergoing processing in this function.
2260 * @param array $conf stdWrap properties for current.
2261 * @return string The processed input value
2262 */
2263 public function stdWrap_current($content = '', $conf = array()) {
2264 return $this->data[$this->currentValKey];
2265 }
2266
2267 /**
2268 * cObject
2269 * Will replace the content with the value of a any official TypoScript cObject
2270 * like TEXT, COA, HMENU
2271 *
2272 * @param string $content Input value undergoing processing in this function.
2273 * @param array $conf stdWrap properties for cObject.
2274 * @return string The processed input value
2275 */
2276 public function stdWrap_cObject($content = '', $conf = array()) {
2277 return $this->cObjGetSingle($conf['cObject'], $conf['cObject.'], '/stdWrap/.cObject');
2278 }
2279
2280 /**
2281 * numRows
2282 * Counts the number of returned records of a DB operation
2283 * makes use of select internally
2284 *
2285 * @param string $content Input value undergoing processing in this function.
2286 * @param array $conf stdWrap properties for numRows.
2287 * @return string The processed input value
2288 */
2289 public function stdWrap_numRows($content = '', $conf = array()) {
2290 return $this->numRows($conf['numRows.']);
2291 }
2292
2293 /**
2294 * filelist
2295 * Will create a list of files based on some additional parameters
2296 *
2297 * @param string $content Input value undergoing processing in this function.
2298 * @param array $conf stdWrap properties for filelist.
2299 * @return string The processed input value
2300 */
2301 public function stdWrap_filelist($content = '', $conf = array()) {
2302 return $this->filelist($conf['filelist']);
2303 }
2304
2305 /**
2306 * preUserFunc
2307 * Will execute a user public function before the content will be modified by any other stdWrap function
2308 *
2309 * @param string $content Input value undergoing processing in this function.
2310 * @param array $conf stdWrap properties for preUserFunc.
2311 * @return string The processed input value
2312 */
2313 public function stdWrap_preUserFunc($content = '', $conf = array()) {
2314 return $this->callUserFunction($conf['preUserFunc'], $conf['preUserFunc.'], $content);
2315 }
2316
2317 /**
2318 * stdWrap override hook
2319 * can be used by extensions authors to modify the behaviour of stdWrap functions to their needs
2320 * this hook will execute functions on existing content but still before the content gets modified or replaced
2321 *
2322 * @param string $content Input value undergoing processing in these functions.
2323 * @param array $conf All stdWrap properties, not just the ones for a particular function.
2324 * @return string The processed input value
2325 */
2326 public function stdWrap_stdWrapOverride($content = '', $conf = array()) {
2327 foreach ($this->stdWrapHookObjects as $hookObject) {
2328 $content = $hookObject->stdWrapOverride($content, $conf, $this);
2329 }
2330 return $content;
2331 }
2332
2333 /**
2334 * override
2335 * Will override the current value of content with its own value'
2336 *
2337 * @param string $content Input value undergoing processing in this function.
2338 * @param array $conf stdWrap properties for override.
2339 * @return string The processed input value
2340 */
2341 public function stdWrap_override($content = '', $conf = array()) {
2342 if (trim($conf['override'])) {
2343 $content = $conf['override'];
2344 }
2345 return $content;
2346 }
2347
2348 /**
2349 * preIfEmptyListNum
2350 * Gets a value off a CSV list before the following ifEmpty check
2351 * Makes sure that the result of ifEmpty will be TRUE in case the CSV does not contain a value at the position given by preIfEmptyListNum
2352 *
2353 * @param string $content Input value undergoing processing in this function.
2354 * @param array $conf stdWrap properties for preIfEmptyListNum.
2355 * @return string The processed input value
2356 */
2357 public function stdWrap_preIfEmptyListNum($content = '', $conf = array()) {
2358 return $this->listNum($content, $conf['preIfEmptyListNum'], $conf['preIfEmptyListNum.']['splitChar']);
2359 }
2360
2361 /**
2362 * ifNull
2363 * Will set content to a replacement value in case the value of content is NULL
2364 *
2365 * @param string|NULL $content Input value undergoing processing in this function.
2366 * @param array $conf stdWrap properties for ifNull.
2367 * @return string|NULL The processed input value
2368 */
2369 public function stdWrap_ifNull($content = '', $conf = array()) {
2370 if ($content === NULL) {
2371 $content = $conf['ifNull'];
2372 }
2373 return $content;
2374 }
2375
2376 /**
2377 * ifEmpty
2378 * Will set content to a replacement value in case the trimmed value of content returns FALSE
2379 * 0 (zero) will be replaced as well
2380 *
2381 * @param string $content Input value undergoing processing in this function.
2382 * @param array $conf stdWrap properties for ifEmpty.
2383 * @return string The processed input value
2384 */
2385 public function stdWrap_ifEmpty($content = '', $conf = array()) {
2386 if (!trim($content)) {
2387 $content = $conf['ifEmpty'];
2388 }
2389 return $content;
2390 }
2391
2392 /**
2393 * ifBlank
2394 * Will set content to a replacement value in case the trimmed value of content has no length
2395 * 0 (zero) will not be replaced
2396 *
2397 * @param string $content Input value undergoing processing in this function.
2398 * @param array $conf stdWrap properties for ifBlank.
2399 * @return string The processed input value
2400 */
2401 public function stdWrap_ifBlank($content = '', $conf = array()) {
2402 if (!strlen(trim($content))) {
2403 $content = $conf['ifBlank'];
2404 }
2405 return $content;
2406 }
2407
2408 /**
2409 * listNum
2410 * Gets a value off a CSV list after ifEmpty check
2411 * Might return an empty value in case the CSV does not contain a value at the position given by listNum
2412 * Use preIfEmptyListNum to avoid that behaviour
2413 *
2414 * @param string $content Input value undergoing processing in this function.
2415 * @param array $conf stdWrap properties for listNum.
2416 * @return string The processed input value
2417 */
2418 public function stdWrap_listNum($content = '', $conf = array()) {
2419 return $this->listNum($content, $conf['listNum'], $conf['listNum.']['splitChar']);
2420 }
2421
2422 /**
2423 * trim
2424 * Cuts off any whitespace at the beginning and the end of the content
2425 *
2426 * @param string $content Input value undergoing processing in this function.
2427 * @param array $conf stdWrap properties for trim.
2428 * @return string The processed input value
2429 */
2430 public function stdWrap_trim($content = '', $conf = array()) {
2431 return trim($content);
2432 }
2433
2434 /**
2435 * strPad
2436 * Will return a string padded left/right/on both sides, based on configuration given as stdWrap properties
2437 *
2438 * @param string $content Input value undergoing processing in this function.
2439 * @param array $conf stdWrap properties for strPad.
2440 * @return string The processed input value
2441 */
2442 public function stdWrap_strPad($content = '', $conf = array()) {
2443 // Must specify a length in conf for this to make sense
2444 $length = 0;
2445 // Padding with space is PHP-default
2446 $padWith = ' ';
2447 // Padding on the right side is PHP-default
2448 $padType = STR_PAD_RIGHT;
2449 if (!empty($conf['strPad.']['length'])) {
2450 $length = isset($conf['strPad.']['length.']) ? $this->stdWrap($conf['strPad.']['length'], $conf['strPad.']['length.']) : $conf['strPad.']['length'];
2451 $length = (int)$length;
2452 }
2453 if (isset($conf['strPad.']['padWith']) && strlen($conf['strPad.']['padWith']) > 0) {
2454 $padWith = isset($conf['strPad.']['padWith.']) ? $this->stdWrap($conf['strPad.']['padWith'], $conf['strPad.']['padWith.']) : $conf['strPad.']['padWith'];
2455 }
2456 if (!empty($conf['strPad.']['type'])) {
2457 $type = isset($conf['strPad.']['type.']) ? $this->stdWrap($conf['strPad.']['type'], $conf['strPad.']['type.']) : $conf['strPad.']['type'];
2458 if (strtolower($type) === 'left') {
2459 $padType = STR_PAD_LEFT;
2460 } elseif (strtolower($type) === 'both') {
2461 $padType = STR_PAD_BOTH;
2462 }
2463 }
2464 $content = str_pad($content, $length, $padWith, $padType);
2465 return $content;
2466 }
2467
2468 /**
2469 * stdWrap
2470 * A recursive call of the stdWrap function set
2471 * This enables the user to execute stdWrap functions in another than the predefined order
2472 * It modifies the content, not the property
2473 * while the new feature of chained stdWrap functions modifies the property and not the content
2474 *
2475 * @param string $content Input value undergoing processing in this function.
2476 * @param array $conf stdWrap properties for stdWrap.
2477 * @return string The processed input value
2478 */
2479 public function stdWrap_stdWrap($content = '', $conf = array()) {
2480 return $this->stdWrap($content, $conf['stdWrap.']);
2481 }
2482
2483 /**
2484 * stdWrap process hook
2485 * can be used by extensions authors to modify the behaviour of stdWrap functions to their needs
2486 * this hook executes functions directly after the recursive stdWrap function call but still before the content gets modified
2487 *
2488 * @param string $content Input value undergoing processing in these functions.
2489 * @param array $conf All stdWrap properties, not just the ones for a particular function.
2490 * @return string The processed input value
2491 */
2492 public function stdWrap_stdWrapProcess($content = '', $conf = array()) {
2493 foreach ($this->stdWrapHookObjects as $hookObject) {
2494 $content = $hookObject->stdWrapProcess($content, $conf, $this);
2495 }
2496 return $content;
2497 }
2498
2499 /**
2500 * required
2501 * Will immediately stop rendering and return an empty value
2502 * when there is no content at this point
2503 *
2504 * @param string $content Input value undergoing processing in this function.
2505 * @param array $conf stdWrap properties for required.
2506 * @return string The processed input value
2507 */
2508 public function stdWrap_required($content = '', $conf = array()) {
2509 if ((string) $content === '') {
2510 $content = '';
2511 $this->stopRendering[$this->stdWrapRecursionLevel] = TRUE;
2512 }
2513 return $content;
2514 }
2515
2516 /**
2517 * if
2518 * Will immediately stop rendering and return an empty value
2519 * when the result of the checks returns FALSE
2520 *
2521 * @param string $content Input value undergoing processing in this function.
2522 * @param array $conf stdWrap properties for if.
2523 * @return string The processed input value
2524 */
2525 public function stdWrap_if($content = '', $conf = array()) {
2526 if (!$this->checkIf($conf['if.'])) {
2527 $content = '';
2528 $this->stopRendering[$this->stdWrapRecursionLevel] = TRUE;
2529 }
2530 return $content;
2531 }
2532
2533 /**
2534 * fieldRequired
2535 * Will immediately stop rendering and return an empty value
2536 * when there is no content in the field given by fieldRequired
2537 *
2538 * @param string $content Input value undergoing processing in this function.
2539 * @param array $conf stdWrap properties for fieldRequired.
2540 * @return string The processed input value
2541 */
2542 public function stdWrap_fieldRequired($content = '', $conf = array()) {
2543 if (!trim($this->data[$conf['fieldRequired']])) {
2544 $content = '';
2545 $this->stopRendering[$this->stdWrapRecursionLevel] = TRUE;
2546 }
2547 return $content;
2548 }
2549
2550 /**
2551 * csConv
2552 * Will convert the current chracter set of the content to the one given in csConv
2553 *
2554 * @param string $content Input value undergoing processing in this function.
2555 * @param array $conf stdWrap properties for csConv.
2556 * @return string The processed input value
2557 */
2558 public function stdWrap_csConv($content = '', $conf = array()) {
2559 return $GLOBALS['TSFE']->csConv($content, $conf['csConv']);
2560 }
2561
2562 /**
2563 * parseFunc
2564 * Will parse the content based on functions given as stdWrap properties
2565 * Heavily used together with RTE based content
2566 *
2567 * @param string $content Input value undergoing processing in this function.
2568 * @param array $conf stdWrap properties for parseFunc.
2569 * @return string The processed input value
2570 */
2571 public function stdWrap_parseFunc($content = '', $conf = array()) {
2572 return $this->parseFunc($content, $conf['parseFunc.'], $conf['parseFunc']);
2573 }
2574
2575 /**
2576 * HTMLparser
2577 * Will parse HTML content based on functions given as stdWrap properties
2578 * Heavily used together with RTE based content
2579 *
2580 * @param string $content Input value undergoing processing in this function.
2581 * @param array $conf stdWrap properties for HTMLparser.
2582 * @return string The processed input value
2583 */
2584 public function stdWrap_HTMLparser($content = '', $conf = array()) {
2585 if (is_array($conf['HTMLparser.'])) {
2586 $content = $this->HTMLparser_TSbridge($content, $conf['HTMLparser.']);
2587 }
2588 return $content;
2589 }
2590
2591 /**
2592 * split
2593 * Will split the content by a given token and treat the results separately
2594 * Automatically fills 'current' with a single result
2595 *
2596 * @param string $content Input value undergoing processing in this function.
2597 * @param array $conf stdWrap properties for split.
2598 * @return string The processed input value
2599 */
2600 public function stdWrap_split($content = '', $conf = array()) {
2601 return $this->splitObj($content, $conf['split.']);
2602 }
2603
2604 /**
2605 * replacement
2606 * Will execute replacements on the content (optionally with preg-regex)
2607 *
2608 * @param string $content Input value undergoing processing in this function.
2609 * @param array $conf stdWrap properties for replacement.
2610 * @return string The processed input value
2611 */
2612 public function stdWrap_replacement($content = '', $conf = array()) {
2613 return $this->replacement($content, $conf['replacement.']);
2614 }
2615
2616 /**
2617 * prioriCalc
2618 * Will use the content as a mathematical term and calculate the result
2619 * Can be set to 1 to just get a calculated value or 'intval' to get the integer of the result
2620 *
2621 * @param string $content Input value undergoing processing in this function.
2622 * @param array $conf stdWrap properties for prioriCalc.
2623 * @return string The processed input value
2624 */
2625 public function stdWrap_prioriCalc($content = '', $conf = array()) {
2626 $content = \TYPO3\CMS\Core\Utility\MathUtility::calculateWithParentheses($content);
2627 if ($conf['prioriCalc'] == 'intval') {
2628 $content = (int)$content;
2629 }
2630 return $content;
2631 }
2632
2633 /**
2634 * char
2635 * Will return a character based on its position within the current character set
2636 *
2637 * @param string $content Input value undergoing processing in this function.
2638 * @param array $conf stdWrap properties for char.
2639 * @return string The processed input value
2640 */
2641 public function stdWrap_char($content = '', $conf = array()) {
2642 return chr((int)$conf['char']);
2643 }
2644
2645 /**
2646 * intval
2647 * Will return an integer value of the current content
2648 *
2649 * @param string $content Input value undergoing processing in this function.
2650 * @param array $conf stdWrap properties for intval.
2651 * @return string The processed input value
2652 */
2653 public function stdWrap_intval($content = '', $conf = array()) {
2654 return (int)$content;
2655 }
2656
2657 /**
2658 * Will return a hashed value of the current content
2659 *
2660 * @param string $content Input value undergoing processing in this function.
2661 * @param array $conf stdWrap properties for hash.
2662 * @return string The processed input value
2663 * @link http://php.net/manual/de/function.hash-algos.php for a list of supported hash algorithms
2664 */
2665 public function stdWrap_hash($content = '', array $conf = array()) {
2666 $algorithm = isset($conf['hash.']) ? $this->stdWrap($conf['hash'], $conf['hash.']) : $conf['hash'];
2667 if (function_exists('hash') && in_array($algorithm, hash_algos())) {
2668 $content = hash($algorithm, $content);
2669 } else {
2670 // Non-existing hashing algorithm
2671 $content = '';
2672 }
2673 return $content;
2674 }
2675
2676 /**
2677 * stdWrap_round will return a rounded number with ceil(), floor() or round(), defaults to round()
2678 * Only the english number format is supported . (dot) as decimal point
2679 *
2680 * @param string $content Input value undergoing processing in this function.
2681 * @param array $conf stdWrap properties for round.
2682 * @return string The processed input value
2683 */
2684 public function stdWrap_round($content = '', $conf = array()) {
2685 return $this->round($content, $conf['round.']);
2686 }
2687
2688 /**
2689 * numberFormat
2690 * Will return a formatted number based on configuration given as stdWrap properties
2691 *
2692 * @param string $content Input value undergoing processing in this function.
2693 * @param array $conf stdWrap properties for numberFormat.
2694 * @return string The processed input value
2695 */
2696 public function stdWrap_numberFormat($content = '', $conf = array()) {
2697 return $this->numberFormat($content, $conf['numberFormat.']);
2698 }
2699
2700 /**
2701 * expandList
2702 * Will return a formatted number based on configuration given as stdWrap properties
2703 *
2704 * @param string $content Input value undergoing processing in this function.
2705 * @param array $conf stdWrap properties for expandList.
2706 * @return string The processed input value
2707 */
2708 public function stdWrap_expandList($content = '', $conf = array()) {
2709 return GeneralUtility::expandList($content);
2710 }
2711
2712 /**
2713 * date
2714 * Will return a formatted date based on configuration given according to PHP date/gmdate properties
2715 * Will return gmdate when the property GMT returns TRUE
2716 *
2717 * @param string $content Input value undergoing processing in this function.
2718 * @param array $conf stdWrap properties for date.
2719 * @return string The processed input value
2720 */
2721 public function stdWrap_date($content = '', $conf = array()) {
2722 // Check for zero length string to mimic default case of date/gmdate.
2723 $content = $content == '' ? $GLOBALS['EXEC_TIME'] : (int)$content;
2724 $content = $conf['date.']['GMT'] ? gmdate($conf['date'], $content) : date($conf['date'], $content);
2725 return $content;
2726 }
2727
2728 /**
2729 * strftime
2730 * Will return a formatted date based on configuration given according to PHP strftime/gmstrftime properties
2731 * Will return gmstrftime when the property GMT returns TRUE
2732 *
2733 * @param string $content Input value undergoing processing in this function.
2734 * @param array $conf stdWrap properties for strftime.
2735 * @return string The processed input value
2736 */
2737 public function stdWrap_strftime($content = '', $conf = array()) {
2738 // Check for zero length string to mimic default case of strtime/gmstrftime
2739 $content = $content == '' ? $GLOBALS['EXEC_TIME'] : (int)$content;
2740 $content = $conf['strftime.']['GMT'] ? gmstrftime($conf['strftime'], $content) : strftime($conf['strftime'], $content);
2741 $tmp_charset = $conf['strftime.']['charset'] ? $conf['strftime.']['charset'] : $GLOBALS['TSFE']->localeCharset;
2742 if ($tmp_charset) {
2743 $content = $GLOBALS['TSFE']->csConv($content, $tmp_charset);
2744 }
2745 return $content;
2746 }
2747
2748 /**
2749 * age
2750 * Will return the age of a given timestamp based on configuration given by stdWrap properties
2751 *
2752 * @param string $content Input value undergoing processing in this function.
2753 * @param array $conf stdWrap properties for age.
2754 * @return string The processed input value
2755 */
2756 public function stdWrap_age($content = '', $conf = array()) {
2757 return $this->calcAge($GLOBALS['EXEC_TIME'] - $content, $conf['age']);
2758 }
2759
2760 /**
2761 * case
2762 * Will transform the content to be upper or lower case only
2763 * Leaves HTML tags untouched
2764 *
2765 * @param string $content Input value undergoing processing in this function.
2766 * @param array $conf stdWrap properties for case.
2767 * @return string The processed input value
2768 */
2769 public function stdWrap_case($content = '', $conf = array()) {
2770 return $this->HTMLcaseshift($content, $conf['case']);
2771 }
2772
2773 /**
2774 * bytes
2775 * Will return the size of a given number in Bytes *
2776 *
2777 * @param string $content Input value undergoing processing in this function.
2778 * @param array $conf stdWrap properties for bytes.
2779 * @return string The processed input value
2780 */
2781 public function stdWrap_bytes($content = '', $conf = array()) {
2782 return GeneralUtility::formatSize($content, $conf['bytes.']['labels']);
2783 }
2784
2785 /**
2786 * substring
2787 * Will return a substring based on position information given by stdWrap properties
2788 *
2789 * @param string $content Input value undergoing processing in this function.
2790 * @param array $conf stdWrap properties for substring.
2791 * @return string The processed input value
2792 */
2793 public function stdWrap_substring($content = '', $conf = array()) {
2794 return $this->substring($content, $conf['substring']);
2795 }
2796
2797 /**
2798 * removeBadHTML
2799 * Removes HTML tags based on stdWrap properties
2800 *
2801 * @param string $content Input value undergoing processing in this function.
2802 * @param array $conf stdWrap properties for removeBadHTML.
2803 * @return string The processed input value
2804 */
2805 public function stdWrap_removeBadHTML($content = '', $conf = array()) {
2806 return $this->removeBadHTML($content, $conf['removeBadHTML.']);
2807 }
2808
2809 /**
2810 * cropHTML
2811 * Crops content to a given size while leaving HTML tags untouched
2812 *
2813 * @param string $content Input value undergoing processing in this function.
2814 * @param array $conf stdWrap properties for cropHTML.
2815 * @return string The processed input value
2816 */
2817 public function stdWrap_cropHTML($content = '', $conf = array()) {
2818 return $this->cropHTML($content, $conf['cropHTML']);
2819 }
2820
2821 /**
2822 * stripHtml
2823 * Copmletely removes HTML tags from content
2824 *
2825 * @param string $content Input value undergoing processing in this function.
2826 * @param array $conf stdWrap properties for stripHtml.
2827 * @return string The processed input value
2828 */
2829 public function stdWrap_stripHtml($content = '', $conf = array()) {
2830 return strip_tags($content);
2831 }
2832
2833 /**
2834 * crop
2835 * Crops content to a given size without caring about HTML tags
2836 *
2837 * @param string $content Input value undergoing processing in this function.
2838 * @param array $conf stdWrap properties for crop.
2839 * @return string The processed input value
2840 */
2841 public function stdWrap_crop($content = '', $conf = array()) {
2842 return $this->crop($content, $conf['crop']);
2843 }
2844
2845 /**
2846 * rawUrlEncode
2847 * Encodes content to be used within URLs
2848 *
2849 * @param string $content Input value undergoing processing