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