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