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