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