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