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