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