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