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