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