[FEATURE] Make the image quality definable per sourceCollection
[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['quality']) || isset($sourceConfiguration['quality.'])) {
1631 $imageQuality = isset($sourceConfiguration['quality']) ? $sourceConfiguration['quality'] : '';
1632 if (isset($sourceConfiguration['quality.'])) {
1633 $imageQuality = $this->stdWrap($sourceConfiguration['quality'], $sourceConfiguration['quality.']);
1634 }
1635 if ($imageQuality) {
1636 $sourceRenderConfiguration['file.']['params'] = '-quality ' . (int)$imageQuality;
1637 }
1638 }
1639
1640 if (isset($sourceConfiguration['pixelDensity'])) {
1641 $pixelDensity = (int)$this->stdWrap($sourceConfiguration['pixelDensity'], $sourceConfiguration['pixelDensity.']);
1642 } else {
1643 $pixelDensity = 1;
1644 }
1645 $dimensionKeys = array('width', 'height', 'maxW', 'minW', 'maxH', 'minH');
1646 foreach ($dimensionKeys as $dimensionKey) {
1647 $dimension = $this->stdWrap($sourceConfiguration[$dimensionKey], $sourceConfiguration[$dimensionKey . '.']);
1648 if (!$dimension) {
1649 $dimension = $this->stdWrap($conf['file.'][$dimensionKey], $conf['file.'][$dimensionKey . '.']);
1650 }
1651 if ($dimension) {
1652 if (strstr($dimension, 'c') !== FALSE && ($dimensionKey === 'width' || $dimensionKey === 'height')) {
1653 $dimensionParts = explode('c', $dimension, 2);
1654 $dimension = (int)($dimensionParts[0] * $pixelDensity) . 'c';
1655 if ($dimensionParts[1]) {
1656 $dimension .= $dimensionParts[1];
1657 }
1658 } else {
1659 $dimension = (int)($dimension * $pixelDensity);
1660 }
1661 $sourceRenderConfiguration['file.'][$dimensionKey] = $dimension;
1662 // Remove the stdWrap properties for dimension as they have been processed already above.
1663 unset($sourceRenderConfiguration['file.'][$dimensionKey . '.']);
1664 }
1665 }
1666 $sourceInfo = $this->getImgResource($sourceRenderConfiguration['file'], $sourceRenderConfiguration['file.']);
1667 if ($sourceInfo) {
1668 $sourceConfiguration['width'] = $sourceInfo[0];
1669 $sourceConfiguration['height'] = $sourceInfo[1];
1670 $sourceConfiguration['src'] = htmlspecialchars($tsfe->absRefPrefix . $sourceInfo[3]);
1671 $sourceConfiguration['selfClosingTagSlash'] = (!empty($tsfe->xhtmlDoctype) ? ' /' : '');
1672
1673 $oneSourceCollection = $this->substituteMarkerArray($sourceLayout, $sourceConfiguration, '###|###', TRUE, TRUE);
1674
1675 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['getImageSourceCollection'])) {
1676 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['getImageSourceCollection'] as $classData) {
1677 $hookObject = GeneralUtility::getUserObj($classData);
1678 if (!$hookObject instanceof ContentObjectOneSourceCollectionHookInterface) {
1679 throw new \UnexpectedValueException(
1680 '$hookObject must implement interface ' . ContentObjectOneSourceCollectionHookInterface::class,
1681 1380007853
1682 );
1683 }
1684 $oneSourceCollection = $hookObject->getOneSourceCollection((array)$sourceRenderConfiguration, (array)$sourceConfiguration, $oneSourceCollection, $this);
1685 }
1686 }
1687
1688 $sourceCollection .= $oneSourceCollection;
1689 }
1690 }
1691 }
1692 return $sourceCollection;
1693 }
1694
1695 /**
1696 * Wraps the input string in link-tags that opens the image in a new window.
1697 *
1698 * @param string $string String to wrap, probably an <img> tag
1699 * @param string|File|FileReference $imageFile The original image file
1700 * @param array $conf TypoScript properties for the "imageLinkWrap" function
1701 * @return string The input string, $string, wrapped as configured.
1702 * @see cImage()
1703 */
1704 public function imageLinkWrap($string, $imageFile, $conf) {
1705 $enable = isset($conf['enable.']) ? $this->stdWrap($conf['enable'], $conf['enable.']) : $conf['enable'];
1706 if (!$enable) {
1707 return $string;
1708 }
1709 $content = $this->typolink($string, $conf['typolink.']);
1710 if (isset($conf['file.'])) {
1711 $imageFile = $this->stdWrap($imageFile, $conf['file.']);
1712 }
1713
1714 if ($imageFile instanceof File) {
1715 $file = $imageFile;
1716 } elseif ($imageFile instanceof FileReference) {
1717 $file = $imageFile->getOriginalFile();
1718 } else {
1719 if (MathUtility::canBeInterpretedAsInteger($imageFile)) {
1720 $file = ResourceFactory::getInstance()->getFileObject((int)$imageFile);
1721 } else {
1722 $file = ResourceFactory::getInstance()->getFileObjectFromCombinedIdentifier($imageFile);
1723 }
1724 }
1725
1726 // Create imageFileLink if not created with typolink
1727 if ($content == $string) {
1728 $parameterNames = array('width', 'height', 'effects', 'bodyTag', 'title', 'wrap');
1729 $parameters = array();
1730 $sample = isset($conf['sample.']) ? $this->stdWrap($conf['sample'], $conf['sample.']) : $conf['sample'];
1731 if ($sample) {
1732 $parameters['sample'] = 1;
1733 }
1734 foreach ($parameterNames as $parameterName) {
1735 if (isset($conf[$parameterName . '.'])) {
1736 $conf[$parameterName] = $this->stdWrap($conf[$parameterName], $conf[$parameterName . '.']);
1737 }
1738 if (isset($conf[$parameterName]) && $conf[$parameterName]) {
1739 $parameters[$parameterName] = $conf[$parameterName];
1740 }
1741 }
1742 $parametersEncoded = base64_encode(serialize($parameters));
1743 $hmac = GeneralUtility::hmac(implode('|', array($file->getUid(), $parametersEncoded)));
1744 $params = '&md5=' . $hmac;
1745 foreach (str_split($parametersEncoded, 64) as $index => $chunk) {
1746 $params .= '&parameters' . rawurlencode('[') . $index . rawurlencode(']') . '=' . rawurlencode($chunk);
1747 }
1748 $url = $this->getTypoScriptFrontendController()->absRefPrefix . 'index.php?eID=tx_cms_showpic&file=' . $file->getUid() . $params;
1749 $directImageLink = isset($conf['directImageLink.']) ? $this->stdWrap($conf['directImageLink'], $conf['directImageLink.']) : $conf['directImageLink'];
1750 if ($directImageLink) {
1751 $imgResourceConf = array(
1752 'file' => $imageFile,
1753 'file.' => $conf
1754 );
1755 $url = $this->cObjGetSingle('IMG_RESOURCE', $imgResourceConf);
1756 if (!$url) {
1757 // If no imagemagick / gm is available
1758 $url = $imageFile;
1759 }
1760 }
1761 // Create TARGET-attribute only if the right doctype is used
1762 if (!GeneralUtility::inList('xhtml_strict,xhtml_11,xhtml_2', $this->getTypoScriptFrontendController()->xhtmlDoctype)) {
1763 $target = isset($conf['target.']) ? $this->stdWrap($conf['target'], $conf['target.']) : $conf['target'];
1764 if ($target) {
1765 $target = sprintf(' target="%s"', $target);
1766 } else {
1767 $target = ' target="thePicture"';
1768 }
1769 } else {
1770 $target = '';
1771 }
1772 $a1 = '';
1773 $a2 = '';
1774 $conf['JSwindow'] = isset($conf['JSwindow.']) ? $this->stdWrap($conf['JSwindow'], $conf['JSwindow.']) : $conf['JSwindow'];
1775 if ($conf['JSwindow']) {
1776 if ($conf['JSwindow.']['altUrl'] || $conf['JSwindow.']['altUrl.']) {
1777 $altUrl = isset($conf['JSwindow.']['altUrl.']) ? $this->stdWrap($conf['JSwindow.']['altUrl'], $conf['JSwindow.']['altUrl.']) : $conf['JSwindow.']['altUrl'];
1778 if ($altUrl) {
1779 $url = $altUrl . ($conf['JSwindow.']['altUrl_noDefaultParams'] ? '' : '?file=' . rawurlencode($imageFile) . $params);
1780 }
1781 }
1782
1783 $processedFile = $file->process('Image.CropScaleMask', $conf);
1784 $JSwindowExpand = isset($conf['JSwindow.']['expand.']) ? $this->stdWrap($conf['JSwindow.']['expand'], $conf['JSwindow.']['expand.']) : $conf['JSwindow.']['expand'];
1785 $offset = GeneralUtility::intExplode(',', $JSwindowExpand . ',');
1786 $newWindow = isset($conf['JSwindow.']['newWindow.']) ? $this->stdWrap($conf['JSwindow.']['newWindow'], $conf['JSwindow.']['newWindow.']) : $conf['JSwindow.']['newWindow'];
1787 $onClick = 'openPic('
1788 . GeneralUtility::quoteJSvalue($this->getTypoScriptFrontendController()->baseUrlWrap($url)) . ','
1789 . '\'' . ($newWindow ? md5($url) : 'thePicture') . '\','
1790 . GeneralUtility::quoteJSvalue('width=' . ($processedFile->getProperty('width') + $offset[0])
1791 . ',height=' . ($processedFile->getProperty('height') + $offset[1]) . ',status=0,menubar=0')
1792 . '); return false;';
1793 $a1 = '<a href="' . htmlspecialchars($url) . '" onclick="' . htmlspecialchars($onClick) . '"' . $target . $this->getTypoScriptFrontendController()->ATagParams . '>';
1794 $a2 = '</a>';
1795 $this->getTypoScriptFrontendController()->setJS('openPic');
1796 } else {
1797 $conf['linkParams.']['parameter'] = $url;
1798 $string = $this->typoLink($string, $conf['linkParams.']);
1799 }
1800 if (isset($conf['stdWrap.'])) {
1801 $string = $this->stdWrap($string, $conf['stdWrap.']);
1802 }
1803 $content = $a1 . $string . $a2;
1804 }
1805 return $content;
1806 }
1807
1808 /**
1809 * Returns content of a file. If it's an image the content of the file is not returned but rather an image tag is.
1810 *
1811 * @param string $fName The filename, being a TypoScript resource data type
1812 * @param string $addParams Additional parameters (attributes). Default is empty alt and title tags.
1813 * @return string If jpg,gif,jpeg,png: returns image_tag with picture in. If html,txt: returns content string
1814 * @see FILE()
1815 */
1816 public function fileResource($fName, $addParams = 'alt="" title=""') {
1817 $tsfe = $this->getTypoScriptFrontendController();
1818 $incFile = $tsfe->tmpl->getFileName($fName);
1819 if ($incFile && file_exists($incFile)) {
1820 $fileinfo = GeneralUtility::split_fileref($incFile);
1821 if (GeneralUtility::inList('jpg,gif,jpeg,png', $fileinfo['fileext'])) {
1822 $imgFile = $incFile;
1823 $imgInfo = @getImageSize($imgFile);
1824 return '<img src="' . $tsfe->absRefPrefix . $imgFile . '" width="' . $imgInfo[0] . '" height="' . $imgInfo[1] . '"' . $this->getBorderAttr(' border="0"') . ' ' . $addParams . ' />';
1825 } elseif (filesize($incFile) < 1024 * 1024) {
1826 return $tsfe->tmpl->fileContent($incFile);
1827 }
1828 }
1829 return '';
1830 }
1831
1832 /**
1833 * Sets the SYS_LASTCHANGED timestamp if input timestamp is larger than current value.
1834 * The SYS_LASTCHANGED timestamp can be used by various caching/indexing applications to determine if the page has new content.
1835 * Therefore you should call this function with the last-changed timestamp of any element you display.
1836 *
1837 * @param int $tstamp Unix timestamp (number of seconds since 1970)
1838 * @return void
1839 * @see TypoScriptFrontendController::setSysLastChanged()
1840 */
1841 public function lastChanged($tstamp) {
1842 $tstamp = (int)$tstamp;
1843 $tsfe = $this->getTypoScriptFrontendController();
1844 if ($tstamp > (int)$tsfe->register['SYS_LASTCHANGED']) {
1845 $tsfe->register['SYS_LASTCHANGED'] = $tstamp;
1846 }
1847 }
1848
1849 /**
1850 * Wraps the input string by the $wrap value and implements the "linkWrap" data type as well.
1851 * 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.
1852 *
1853 * @param string $content Input string
1854 * @param string $wrap A string where the first two parts separated by "|" (vertical line) will be wrapped around the input string
1855 * @return string Wrapped output string
1856 * @see wrap(), cImage(), FILE()
1857 */
1858 public function linkWrap($content, $wrap) {
1859 $wrapArr = explode('|', $wrap);
1860 if (preg_match('/\\{([0-9]*)\\}/', $wrapArr[0], $reg)) {
1861 if ($uid = $this->getTypoScriptFrontendController()->tmpl->rootLine[$reg[1]]['uid']) {
1862 $wrapArr[0] = str_replace($reg[0], $uid, $wrapArr[0]);
1863 }
1864 }
1865 return trim($wrapArr[0]) . $content . trim($wrapArr[1]);
1866 }
1867
1868 /**
1869 * An abstraction method which creates an alt or title parameter for an HTML img, applet, area or input element and the FILE content element.
1870 * From the $conf array it implements the properties "altText", "titleText" and "longdescURL"
1871 *
1872 * @param array $conf TypoScript configuration properties
1873 * @param bool $longDesc If set, the longdesc attribute will be generated - must only be used for img elements!
1874 * @return string Parameter string containing alt and title parameters (if any)
1875 * @see IMGTEXT(), FILE(), FORM(), cImage(), filelink()
1876 */
1877 public function getAltParam($conf, $longDesc = TRUE) {
1878 $altText = isset($conf['altText.']) ? trim($this->stdWrap($conf['altText'], $conf['altText.'])) : trim($conf['altText']);
1879 $titleText = isset($conf['titleText.']) ? trim($this->stdWrap($conf['titleText'], $conf['titleText.'])) : trim($conf['titleText']);
1880 if (isset($conf['longdescURL.']) && $this->getTypoScriptFrontendController()->config['config']['doctype'] != 'html5') {
1881 $longDescUrl = $this->typoLink_URL($conf['longdescURL.']);
1882 } else {
1883 $longDescUrl = trim($conf['longdescURL']);
1884 }
1885 // "alt":
1886 $altParam = ' alt="' . htmlspecialchars($altText) . '"';
1887 // "title":
1888 $emptyTitleHandling = isset($conf['emptyTitleHandling.']) ? $this->stdWrap($conf['emptyTitleHandling'], $conf['emptyTitleHandling.']) : $conf['emptyTitleHandling'];
1889 // Choices: 'keepEmpty' | 'useAlt' | 'removeAttr'
1890 if ($titleText || $emptyTitleHandling == 'keepEmpty') {
1891 $altParam .= ' title="' . htmlspecialchars($titleText) . '"';
1892 } elseif (!$titleText && $emptyTitleHandling == 'useAlt') {
1893 $altParam .= ' title="' . htmlspecialchars($altText) . '"';
1894 }
1895 // "longDesc" URL
1896 if ($longDesc) {
1897 $altParam .= ' longdesc="' . htmlspecialchars(strip_tags($longDescUrl)) . '"';
1898 }
1899 return $altParam;
1900 }
1901
1902 /**
1903 * Removes forbidden characters and spaces from name/id attributes in the form tag and formfields
1904 *
1905 * @param string $name Input string
1906 * @return string the cleaned string
1907 * @see FORM()
1908 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8, the method is moved to FormContentObject
1909 */
1910 public function cleanFormName($name) {
1911 GeneralUtility::logDeprecatedFunction();
1912 // Turn data[x][y] into data:x:y:
1913 $name = preg_replace('/\\[|\\]\\[?/', ':', trim($name));
1914 // Remove illegal chars like _
1915 return preg_replace('#[^:a-zA-Z0-9]#', '', $name);
1916 }
1917
1918 /**
1919 * An abstraction method to add parameters to an A tag.
1920 * Uses the ATagParams property.
1921 *
1922 * @param array $conf TypoScript configuration properties
1923 * @param bool|int $addGlobal If set, will add the global config.ATagParams to the link
1924 * @return string String containing the parameters to the A tag (if non empty, with a leading space)
1925 * @see IMGTEXT(), filelink(), makelinks(), typolink()
1926 */
1927 public function getATagParams($conf, $addGlobal = 1) {
1928 $aTagParams = '';
1929 if ($conf['ATagParams.']) {
1930 $aTagParams = ' ' . $this->stdWrap($conf['ATagParams'], $conf['ATagParams.']);
1931 } elseif ($conf['ATagParams']) {
1932 $aTagParams = ' ' . $conf['ATagParams'];
1933 }
1934 if ($addGlobal) {
1935 $aTagParams = ' ' . trim($this->getTypoScriptFrontendController()->ATagParams . $aTagParams);
1936 }
1937 // Extend params
1938 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'])) {
1939 $_params = array(
1940 'conf' => &$conf,
1941 'aTagParams' => &$aTagParams
1942 );
1943 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['getATagParamsPostProc'] as $objRef) {
1944 $processor =& GeneralUtility::getUserObj($objRef);
1945 $aTagParams = $processor->process($_params, $this);
1946 }
1947 }
1948
1949 $aTagParams = trim($aTagParams);
1950 if (!empty($aTagParams)) {
1951 $aTagParams = ' ' . $aTagParams;
1952 }
1953
1954 return $aTagParams;
1955 }
1956
1957 /**
1958 * All extension links should ask this function for additional properties to their tags.
1959 * Designed to add for instance an "onclick" property for site tracking systems.
1960 *
1961 * @param string $URL URL of the website
1962 * @param string $TYPE
1963 * @return string The additional tag properties
1964 */
1965 public function extLinkATagParams($URL, $TYPE) {
1966 $out = '';
1967 if ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['extLinkATagParamsHandler']) {
1968 $extLinkATagParamsHandler = GeneralUtility::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['extLinkATagParamsHandler']);
1969 if (method_exists($extLinkATagParamsHandler, 'main')) {
1970 $out .= trim($extLinkATagParamsHandler->main($URL, $TYPE, $this));
1971 }
1972 }
1973 return trim($out) ? ' ' . trim($out) : '';
1974 }
1975
1976 /***********************************************
1977 *
1978 * HTML template processing functions
1979 *
1980 ***********************************************/
1981 /**
1982 * Returns a subpart from the input content stream.
1983 * A subpart is a part of the input stream which is encapsulated in a
1984 * string matching the input string, $marker. If this string is found
1985 * inside of HTML comment tags the start/end points of the content block
1986 * returned will be that right outside that comment block.
1987 * Example: The contennt string is
1988 * "Hello <!--###sub1### begin--> World. How are <!--###sub1### end--> you?"
1989 * If $marker is "###sub1###" then the content returned is
1990 * " World. How are ". The input content string could just as well have
1991 * been "Hello ###sub1### World. How are ###sub1### you?" and the result
1992 * would be the same
1993 * Wrapper for \TYPO3\CMS\Core\Utility\MarkerBasedTemplateService::getSubpart which behaves identical
1994 *
1995 * @param string $content The content stream, typically HTML template content.
1996 * @param string $marker The marker string, typically on the form "###[the marker string]###
1997 * @return string The subpart found, if found.
1998 */
1999 public function getSubpart($content, $marker) {
2000 return $this->templateService->getSubpart($content, $marker);
2001 }
2002
2003 /**
2004 * Substitute subpart in input template stream.
2005 * This function substitutes a subpart in $content with the content of
2006 * $subpartContent.
2007 * Wrapper for \TYPO3\CMS\Core\Utility\MarkerBasedTemplateService::substituteSubpart which behaves identical
2008 *
2009 * @param string $content The content stream, typically HTML template content.
2010 * @param string $marker The marker string, typically on the form "###[the marker string]###
2011 * @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.
2012 * @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!
2013 * @return string The processed HTML content string.
2014 */
2015 public function substituteSubpart($content, $marker, $subpartContent, $recursive = 1) {
2016 return $this->templateService->substituteSubpart($content, $marker, $subpartContent, $recursive);
2017 }
2018
2019 /**
2020 * Substitues multiple subparts at once
2021 *
2022 * @param string $content The content stream, typically HTML template content.
2023 * @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.
2024 * @return string The processed HTML content string.
2025 */
2026 public function substituteSubpartArray($content, array $subpartsContent) {
2027 return $this->templateService->substituteSubpartArray($content, $subpartsContent);
2028 }
2029
2030 /**
2031 * Substitutes a marker string in the input content
2032 * (by a simple str_replace())
2033 *
2034 * @param string $content The content stream, typically HTML template content.
2035 * @param string $marker The marker string, typically on the form "###[the marker string]###
2036 * @param mixed $markContent The content to insert instead of the marker string found.
2037 * @return string The processed HTML content string.
2038 * @see substituteSubpart()
2039 */
2040 public function substituteMarker($content, $marker, $markContent) {
2041 return $this->templateService->substituteMarker($content, $marker, $markContent);
2042 }
2043
2044 /**
2045 * Multi substitution function with caching.
2046 *
2047 * This function should be a one-stop substitution function for working
2048 * with HTML-template. It does not substitute by str_replace but by
2049 * splitting. This secures that the value inserted does not themselves
2050 * contain markers or subparts.
2051 *
2052 * Note that the "caching" won't cache the content of the substition,
2053 * but only the splitting of the template in various parts. So if you
2054 * want only one cache-entry per template, make sure you always pass the
2055 * exact same set of marker/subpart keys. Else you will be flooding the
2056 * users cache table.
2057 *
2058 * This function takes three kinds of substitutions in one:
2059 * $markContentArray is a regular marker-array where the 'keys' are
2060 * substituted in $content with their values
2061 *
2062 * $subpartContentArray works exactly like markContentArray only is whole
2063 * subparts substituted and not only a single marker.
2064 *
2065 * $wrappedSubpartContentArray is an array of arrays with 0/1 keys where
2066 * the subparts pointed to by the main key is wrapped with the 0/1 value
2067 * alternating.
2068 *
2069 * @param string $content The content stream, typically HTML template content.
2070 * @param array $markContentArray Regular marker-array where the 'keys' are substituted in $content with their values
2071 * @param array $subpartContentArray Exactly like markContentArray only is whole subparts substituted and not only a single marker.
2072 * @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.
2073 * @return string The output content stream
2074 * @see substituteSubpart(), substituteMarker(), substituteMarkerInObject(), TEMPLATE()
2075 */
2076 public function substituteMarkerArrayCached($content, array $markContentArray = NULL, array $subpartContentArray = NULL, array $wrappedSubpartContentArray = NULL) {
2077 $timeTracker = $this->getTimeTracker();
2078 $timeTracker->push('substituteMarkerArrayCached');
2079 // If not arrays then set them
2080 if (is_null($markContentArray)) {
2081 // Plain markers
2082 $markContentArray = array();
2083 }
2084 if (is_null($subpartContentArray)) {
2085 // Subparts being directly substituted
2086 $subpartContentArray = array();
2087 }
2088 if (is_null($wrappedSubpartContentArray)) {
2089 // Subparts being wrapped
2090 $wrappedSubpartContentArray = array();
2091 }
2092 // Finding keys and check hash:
2093 $sPkeys = array_keys($subpartContentArray);
2094 $wPkeys = array_keys($wrappedSubpartContentArray);
2095 $aKeys = array_merge(array_keys($markContentArray), $sPkeys, $wPkeys);
2096 if (empty($aKeys)) {
2097 $timeTracker->pull();
2098 return $content;
2099 }
2100 asort($aKeys);
2101 $storeKey = md5('substituteMarkerArrayCached_storeKey:' . serialize(array(
2102 $content,
2103 $aKeys
2104 )));
2105 if ($this->substMarkerCache[$storeKey]) {
2106 $storeArr = $this->substMarkerCache[$storeKey];
2107 $timeTracker->setTSlogMessage('Cached', 0);
2108 } else {
2109 $storeArrDat = $this->getTypoScriptFrontendController()->sys_page->getHash($storeKey);
2110 if (is_array($storeArrDat)) {
2111 $storeArr = $storeArrDat;
2112 // Setting cache:
2113 $this->substMarkerCache[$storeKey] = $storeArr;
2114 $timeTracker->setTSlogMessage('Cached from DB', 0);
2115 } else {
2116 // Initialize storeArr
2117 $storeArr = array();
2118 // Finding subparts and substituting them with the subpart as a marker
2119 foreach ($sPkeys as $sPK) {
2120 $content = $this->substituteSubpart($content, $sPK, $sPK);
2121 }
2122 // Finding subparts and wrapping them with markers
2123 foreach ($wPkeys as $wPK) {
2124 $content = $this->substituteSubpart($content, $wPK, array(
2125 $wPK,
2126 $wPK
2127 ));
2128 }
2129 // Traverse keys and quote them for reg ex.
2130 foreach ($aKeys as $tK => $tV) {
2131 $aKeys[$tK] = preg_quote($tV, '/');
2132 }
2133 $regex = '/' . implode('|', $aKeys) . '/';
2134 // Doing regex's
2135 $storeArr['c'] = preg_split($regex, $content);
2136 preg_match_all($regex, $content, $keyList);
2137 $storeArr['k'] = $keyList[0];
2138 // Setting cache:
2139 $this->substMarkerCache[$storeKey] = $storeArr;
2140 // Storing the cached data:
2141 $this->getTypoScriptFrontendController()->sys_page->storeHash($storeKey, $storeArr, 'substMarkArrayCached');
2142 $timeTracker->setTSlogMessage('Parsing', 0);
2143 }
2144 }
2145 // Substitution/Merging:
2146 // Merging content types together, resetting
2147 $valueArr = array_merge($markContentArray, $subpartContentArray, $wrappedSubpartContentArray);
2148 $wSCA_reg = array();
2149 $content = '';
2150 // Traversing the keyList array and merging the static and dynamic content
2151 foreach ($storeArr['k'] as $n => $keyN) {
2152 $content .= $storeArr['c'][$n];
2153 if (!is_array($valueArr[$keyN])) {
2154 $content .= $valueArr[$keyN];
2155 } else {
2156 $content .= $valueArr[$keyN][(int)$wSCA_reg[$keyN] % 2];
2157 $wSCA_reg[$keyN]++;
2158 }
2159 }
2160 $content .= $storeArr['c'][count($storeArr['k'])];
2161 $timeTracker->pull();
2162 return $content;
2163 }
2164
2165 /**
2166 * Traverses the input $markContentArray array and for each key the marker
2167 * by the same name (possibly wrapped and in upper case) will be
2168 * substituted with the keys value in the array.
2169 *
2170 * This is very useful if you have a data-record to substitute in some
2171 * content. In particular when you use the $wrap and $uppercase values to
2172 * pre-process the markers. Eg. a key name like "myfield" could effectively
2173 * be represented by the marker "###MYFIELD###" if the wrap value
2174 * was "###|###" and the $uppercase boolean TRUE.
2175 *
2176 * @param string $content The content stream, typically HTML template content.
2177 * @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.
2178 * @param string $wrap A wrap value - [part 1] | [part 2] - for the markers before substitution
2179 * @param bool $uppercase If set, all marker string substitution is done with upper-case markers.
2180 * @param bool $deleteUnused If set, all unused marker are deleted.
2181 * @return string The processed output stream
2182 * @see substituteMarker(), substituteMarkerInObject(), TEMPLATE()
2183 */
2184 public function substituteMarkerArray($content, array $markContentArray, $wrap = '', $uppercase = FALSE, $deleteUnused = FALSE) {
2185 return $this->templateService->substituteMarkerArray($content, $markContentArray, $wrap, $uppercase, $deleteUnused);
2186 }
2187
2188 /**
2189 * Substitute marker array in an array of values
2190 *
2191 * @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)
2192 * @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.
2193 * @return mixed The processed input variable.
2194 * @see substituteMarker()
2195 */
2196 public function substituteMarkerInObject(&$tree, array $markContentArray) {
2197 if (is_array($tree)) {
2198 foreach ($tree as $key => $value) {
2199 $this->substituteMarkerInObject($tree[$key], $markContentArray);
2200 }
2201 } else {
2202 $tree = $this->substituteMarkerArray($tree, $markContentArray);
2203 }
2204 return $tree;
2205 }
2206
2207 /**
2208 * Replaces all markers and subparts in a template with the content provided in the structured array.
2209 *
2210 * @param string $content
2211 * @param array $markersAndSubparts
2212 * @param string $wrap
2213 * @param bool $uppercase
2214 * @param bool $deleteUnused
2215 * @return string
2216 */
2217 public function substituteMarkerAndSubpartArrayRecursive($content, array $markersAndSubparts, $wrap = '', $uppercase = FALSE, $deleteUnused = FALSE) {
2218 return $this->templateService->substituteMarkerAndSubpartArrayRecursive($content, $markersAndSubparts, $wrap, $uppercase, $deleteUnused);
2219 }
2220
2221 /**
2222 * Adds elements to the input $markContentArray based on the values from
2223 * the fields from $fieldList found in $row
2224 *
2225 * @param array $markContentArray Array with key/values being marker-strings/substitution values.
2226 * @param array $row An array with keys found in the $fieldList (typically a record) which values should be moved to the $markContentArray
2227 * @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)
2228 * @param bool $nl2br If set, all values added to $markContentArray will be nl2br()'ed
2229 * @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 "###
2230 * @param bool $HSC If set, all values are passed through htmlspecialchars() - RECOMMENDED to avoid most obvious XSS and maintain XHTML compliance.
2231 * @return array The modified $markContentArray
2232 */
2233 public function fillInMarkerArray(array $markContentArray, array $row, $fieldList = '', $nl2br = TRUE, $prefix = 'FIELD_', $HSC = FALSE) {
2234 $tsfe = $this->getTypoScriptFrontendController();
2235 if ($fieldList) {
2236 $fArr = GeneralUtility::trimExplode(',', $fieldList, TRUE);
2237 foreach ($fArr as $field) {
2238 $markContentArray['###' . $prefix . $field . '###'] = $nl2br ? nl2br($row[$field], !empty($tsfe->xhtmlDoctype)) : $row[$field];
2239 }
2240 } else {
2241 if (is_array($row)) {
2242 foreach ($row as $field => $value) {
2243 if (!MathUtility::canBeInterpretedAsInteger($field)) {
2244 if ($HSC) {
2245 $value = htmlspecialchars($value);
2246 }
2247 $markContentArray['###' . $prefix . $field . '###'] = $nl2br ? nl2br($value, !empty($tsfe->xhtmlDoctype)) : $value;
2248 }
2249 }
2250 }
2251 }
2252 return $markContentArray;
2253 }
2254
2255 /**
2256 * Sets the current file object during iterations over files.
2257 *
2258 * @param File $fileObject The file object.
2259 */
2260 public function setCurrentFile($fileObject) {
2261 $this->currentFile = $fileObject;
2262 }
2263
2264 /**
2265 * Gets the current file object during iterations over files.
2266 *
2267 * @return File The current file object.
2268 */
2269 public function getCurrentFile() {
2270 return $this->currentFile;
2271 }
2272
2273 /***********************************************
2274 *
2275 * "stdWrap" + sub functions
2276 *
2277 ***********************************************/
2278 /**
2279 * The "stdWrap" function. This is the implementation of what is known as "stdWrap properties" in TypoScript.
2280 * Basically "stdWrap" performs some processing of a value based on properties in the input $conf array(holding the TypoScript "stdWrap properties")
2281 * 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.
2282 *
2283 * If $this->alternativeData is an array it's used instead of the $this->data array in ->getData
2284 *
2285 * @param string $content Input value undergoing processing in this function. Possibly substituted by other values fetched from another source.
2286 * @param array $conf TypoScript "stdWrap properties".
2287 * @return string The processed input value
2288 */
2289 public function stdWrap($content = '', $conf = array()) {
2290 // If there is any hook object, activate all of the process and override functions.
2291 // The hook interface ContentObjectStdWrapHookInterface takes care that all 4 methods exist.
2292 if ($this->stdWrapHookObjects) {
2293 $conf['stdWrapPreProcess'] = 1;
2294 $conf['stdWrapOverride'] = 1;
2295 $conf['stdWrapProcess'] = 1;
2296 $conf['stdWrapPostProcess'] = 1;
2297 }
2298
2299 if (!is_array($conf) || !$conf) {
2300 return $content;
2301 }
2302
2303 // Cache handling
2304 if (is_array($conf['cache.'])) {
2305 $conf['cache.']['key'] = $this->stdWrap($conf['cache.']['key'], $conf['cache.']['key.']);
2306 $conf['cache.']['tags'] = $this->stdWrap($conf['cache.']['tags'], $conf['cache.']['tags.']);
2307 $conf['cache.']['lifetime'] = $this->stdWrap($conf['cache.']['lifetime'], $conf['cache.']['lifetime.']);
2308 $conf['cacheRead'] = 1;
2309 $conf['cacheStore'] = 1;
2310 }
2311 // Check, which of the available stdWrap functions is needed for the current conf Array
2312 // and keep only those but still in the same order
2313 $sortedConf = array_intersect_key($this->stdWrapOrder, $conf);
2314 // Functions types that should not make use of nested stdWrap function calls to avoid conflicts with internal TypoScript used by these functions
2315 $stdWrapDisabledFunctionTypes = 'cObject,functionName,stdWrap';
2316 // Additional Array to check whether a function has already been executed
2317 $isExecuted = array();
2318 // Additional switch to make sure 'required', 'if' and 'fieldRequired'
2319 // will still stop rendering immediately in case they return FALSE
2320 $this->stdWrapRecursionLevel++;
2321 $this->stopRendering[$this->stdWrapRecursionLevel] = FALSE;
2322 // execute each function in the predefined order
2323 foreach ($sortedConf as $stdWrapName => $functionType) {
2324 // eliminate the second key of a pair 'key'|'key.' to make sure functions get called only once and check if rendering has been stopped
2325 if (!$isExecuted[$stdWrapName] && !$this->stopRendering[$this->stdWrapRecursionLevel]) {
2326 $functionName = rtrim($stdWrapName, '.');
2327 $functionProperties = $functionName . '.';
2328 // If there is any code on the next level, check if it contains "official" stdWrap functions
2329 // if yes, execute them first - will make each function stdWrap aware
2330 // so additional stdWrap calls within the functions can be removed, since the result will be the same
2331 // exception: the recursive stdWrap function and cObject will still be using their own stdWrap call, since it modifies the content and not a property
2332 if ($functionName !== 'stdWrap' && !empty($conf[$functionProperties]) && !GeneralUtility::inList($stdWrapDisabledFunctionTypes, $functionType)) {
2333 if (array_intersect_key($this->stdWrapOrder, $conf[$functionProperties])) {
2334 $conf[$functionName] = $this->stdWrap($conf[$functionName], $conf[$functionProperties]);
2335 }
2336 }
2337 // Check if key is still containing something, since it might have been changed by next level stdWrap before
2338 if ((isset($conf[$functionName]) || $conf[$functionProperties]) && ($functionType !== 'boolean' || $conf[$functionName])) {
2339 // Get just that part of $conf that is needed for the particular function
2340 $singleConf = array(
2341 $functionName => $conf[$functionName],
2342 $functionProperties => $conf[$functionProperties]
2343 );
2344 // In this special case 'spaceBefore' and 'spaceAfter' need additional stuff from 'space.''
2345 if ($functionName === 'spaceBefore' || $functionName === 'spaceAfter') {
2346 $singleConf['space.'] = $conf['space.'];
2347 }
2348 // Hand over the whole $conf array to the stdWrapHookObjects
2349 if ($functionType === 'hook') {
2350 $singleConf = $conf;
2351 }
2352 // Add both keys - with and without the dot - to the set of executed functions
2353 $isExecuted[$functionName] = TRUE;
2354 $isExecuted[$functionProperties] = TRUE;
2355 // Call the function with the prefix stdWrap_ to make sure nobody can execute functions just by adding their name to the TS Array
2356 $functionName = 'stdWrap_' . $functionName;
2357 $content = $this->{$functionName}($content, $singleConf);
2358 } elseif ($functionType == 'boolean' && !$conf[$functionName]) {
2359 $isExecuted[$functionName] = TRUE;
2360 $isExecuted[$functionProperties] = TRUE;
2361 }
2362 }
2363 }
2364 unset($this->stopRendering[$this->stdWrapRecursionLevel]);
2365 $this->stdWrapRecursionLevel--;
2366
2367 return $content;
2368 }
2369
2370 /**
2371 * Gets a configuration value by passing them through stdWrap first and taking a default value if stdWrap doesn't yield a result.
2372 *
2373 * @param string $key The config variable key (from TS array).
2374 * @param array $config The TypoScript array.
2375 * @param string $defaultValue Optional default value.
2376 * @return string Value of the config variable
2377 */
2378 public function stdWrapValue($key, array $config, $defaultValue = '') {
2379 if (isset($config[$key])) {
2380 if (!isset($config[$key . '.'])) {
2381 return $config[$key];
2382 }
2383 } elseif (isset($config[$key . '.'])) {
2384 $config[$key] = '';
2385 } else {
2386 return $defaultValue;
2387 }
2388 $stdWrapped = $this->stdWrap($config[$key], $config[$key . '.']);
2389 return $stdWrapped ?: $defaultValue;
2390 }
2391
2392 /**
2393 * stdWrap pre process hook
2394 * can be used by extensions authors to modify the behaviour of stdWrap functions to their needs
2395 * this hook will execute functions before any other stdWrap function can modify anything
2396 *
2397 * @param string $content Input value undergoing processing in these functions.
2398 * @param array $conf All stdWrap properties, not just the ones for a particular function.
2399 * @return string The processed input value
2400 */
2401 public function stdWrap_stdWrapPreProcess($content = '', $conf = array()) {
2402 foreach ($this->stdWrapHookObjects as $hookObject) {
2403 /** @var ContentObjectStdWrapHookInterface $hookObject */
2404 $content = $hookObject->stdWrapPreProcess($content, $conf, $this);
2405 }
2406 return $content;
2407 }
2408
2409 /**
2410 * Check if content was cached before (depending on the given cache key)
2411 *
2412 * @param string $content Input value undergoing processing in these functions.
2413 * @param array $conf All stdWrap properties, not just the ones for a particular function.
2414 * @return string The processed input value
2415 */
2416 public function stdWrap_cacheRead($content = '', $conf = array()) {
2417 if (!isset($conf['cache.'])) {
2418 return $content;
2419 }
2420 $result = $this->getFromCache($conf['cache.']);
2421 return $result === FALSE ? $content : $result;
2422 }
2423
2424 /**
2425 * Add tags to page cache (comma-separated list)
2426 *
2427 * @param string $content Input value undergoing processing in these functions.
2428 * @param array $conf All stdWrap properties, not just the ones for a particular function.
2429 * @return string The processed input value
2430 */
2431 public function stdWrap_addPageCacheTags($content = '', $conf = array()) {
2432 $tags = isset($conf['addPageCacheTags.'])
2433 ? $this->stdWrap($conf['addPageCacheTags'], $conf['addPageCacheTags.'])
2434 : $conf['addPageCacheTags'];
2435 if (!empty($tags)) {
2436 $cacheTags = GeneralUtility::trimExplode(',', $tags, TRUE);
2437 $this->getTypoScriptFrontendController()->addCacheTags($cacheTags);
2438 }
2439 return $content;
2440 }
2441
2442 /**
2443 * setContentToCurrent
2444 * actually it just does the contrary: Sets the value of 'current' based on current content
2445 *
2446 * @param string $content Input value undergoing processing in this function.
2447 * @return string The processed input value
2448 */
2449 public function stdWrap_setContentToCurrent($content = '') {
2450 $this->data[$this->currentValKey] = $content;
2451 return $content;
2452 }
2453
2454 /**
2455 * setCurrent
2456 * Sets the value of 'current' based on the outcome of stdWrap operations
2457 *
2458 * @param string $content Input value undergoing processing in this function.
2459 * @param array $conf stdWrap properties for setCurrent.
2460 * @return string The processed input value
2461 */
2462 public function stdWrap_setCurrent($content = '', $conf = array()) {
2463 $this->data[$this->currentValKey] = $conf['setCurrent'];
2464 return $content;
2465 }
2466
2467 /**
2468 * lang
2469 * Translates content based on the language currently used by the FE
2470 *
2471 * @param string $content Input value undergoing processing in this function.
2472 * @param array $conf stdWrap properties for lang.
2473 * @return string The processed input value
2474 */
2475 public function stdWrap_lang($content = '', $conf = array()) {
2476 $tsfe = $this->getTypoScriptFrontendController();
2477 if (isset($conf['lang.']) && $tsfe->config['config']['language'] && isset($conf['lang.'][$tsfe->config['config']['language']])) {
2478 $content = $conf['lang.'][$tsfe->config['config']['language']];
2479 }
2480 return $content;
2481 }
2482
2483 /**
2484 * data
2485 * Gets content from different sources based on getText functions, makes use of alternativeData, when set
2486 *
2487 * @param string $content Input value undergoing processing in this function.
2488 * @param array $conf stdWrap properties for data.
2489 * @return string The processed input value
2490 */
2491 public function stdWrap_data($content = '', $conf = array()) {
2492 $content = $this->getData($conf['data'], is_array($this->alternativeData) ? $this->alternativeData : $this->data);
2493 // This must be unset directly after
2494 $this->alternativeData = '';
2495 return $content;
2496 }
2497
2498 /**
2499 * field
2500 * Gets content from a DB field
2501 *
2502 * @param string $content Input value undergoing processing in this function.
2503 * @param array $conf stdWrap properties for field.
2504 * @return string The processed input value
2505 */
2506 public function stdWrap_field($content = '', $conf = array()) {
2507 return $this->getFieldVal($conf['field']);
2508 }
2509
2510 /**
2511 * current
2512 * Gets content that has been perviously set as 'current'
2513 * Can be set via setContentToCurrent or setCurrent or will be set automatically i.e. inside the split function
2514 *
2515 * @param string $content Input value undergoing processing in this function.
2516 * @param array $conf stdWrap properties for current.
2517 * @return string The processed input value
2518 */
2519 public function stdWrap_current($content = '', $conf = array()) {
2520 return $this->data[$this->currentValKey];
2521 }
2522
2523 /**
2524 * cObject
2525 * Will replace the content with the value of an official TypoScript cObject
2526 * like TEXT, COA, HMENU
2527 *
2528 * @param string $content Input value undergoing processing in this function.
2529 * @param array $conf stdWrap properties for cObject.
2530 * @return string The processed input value
2531 */
2532 public function stdWrap_cObject($content = '', $conf = array()) {
2533 return $this->cObjGetSingle($conf['cObject'], $conf['cObject.'], '/stdWrap/.cObject');
2534 }
2535
2536 /**
2537 * numRows
2538 * Counts the number of returned records of a DB operation
2539 * makes use of select internally
2540 *
2541 * @param string $content Input value undergoing processing in this function.
2542 * @param array $conf stdWrap properties for numRows.
2543 * @return string The processed input value
2544 */
2545 public function stdWrap_numRows($content = '', $conf = array()) {
2546 return $this->numRows($conf['numRows.']);
2547 }
2548
2549 /**
2550 * filelist
2551 * Will create a list of files based on some additional parameters
2552 *
2553 * @param string $content Input value undergoing processing in this function.
2554 * @param array $conf stdWrap properties for filelist.
2555 * @return string The processed input value
2556 */
2557 public function stdWrap_filelist($content = '', $conf = array()) {
2558 return $this->filelist($conf['filelist']);
2559 }
2560
2561 /**
2562 * preUserFunc
2563 * Will execute a user public function before the content will be modified by any other stdWrap function
2564 *
2565 * @param string $content Input value undergoing processing in this function.
2566 * @param array $conf stdWrap properties for preUserFunc.
2567 * @return string The processed input value
2568 */
2569 public function stdWrap_preUserFunc($content = '', $conf = array()) {
2570 return $this->callUserFunction($conf['preUserFunc'], $conf['preUserFunc.'], $content);
2571 }
2572
2573 /**
2574 * stdWrap override hook
2575 * can be used by extensions authors to modify the behaviour of stdWrap functions to their needs
2576 * this hook will execute functions on existing content but still before the content gets modified or replaced
2577 *
2578 * @param string $content Input value undergoing processing in these functions.
2579 * @param array $conf All stdWrap properties, not just the ones for a particular function.
2580 * @return string The processed input value
2581 */
2582 public function stdWrap_stdWrapOverride($content = '', $conf = array()) {
2583 foreach ($this->stdWrapHookObjects as $hookObject) {
2584 /** @var ContentObjectStdWrapHookInterface $hookObject */
2585 $content = $hookObject->stdWrapOverride($content, $conf, $this);
2586 }
2587 return $content;
2588 }
2589
2590 /**
2591 * override
2592 * Will override the current value of content with its own value'
2593 *
2594 * @param string $content Input value undergoing processing in this function.
2595 * @param array $conf stdWrap properties for override.
2596 * @return string The processed input value
2597 */
2598 public function stdWrap_override($content = '', $conf = array()) {
2599 if (trim($conf['override'])) {
2600 $content = $conf['override'];
2601 }
2602 return $content;
2603 }
2604
2605 /**
2606 * preIfEmptyListNum
2607 * Gets a value off a CSV list before the following ifEmpty check
2608 * 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
2609 *
2610 * @param string $content Input value undergoing processing in this function.
2611 * @param array $conf stdWrap properties for preIfEmptyListNum.
2612 * @return string The processed input value
2613 */
2614 public function stdWrap_preIfEmptyListNum($content = '', $conf = array()) {
2615 return $this->listNum($content, $conf['preIfEmptyListNum'], $conf['preIfEmptyListNum.']['splitChar']);
2616 }
2617
2618 /**
2619 * ifNull
2620 * Will set content to a replacement value in case the value of content is NULL
2621 *
2622 * @param string|NULL $content Input value undergoing processing in this function.
2623 * @param array $conf stdWrap properties for ifNull.
2624 * @return string The processed input value
2625 */
2626 public function stdWrap_ifNull($content = '', $conf = array()) {
2627 return $content !== NULL ? $content : $conf['ifNull'];
2628 }
2629
2630 /**
2631 * ifEmpty
2632 * Will set content to a replacement value in case the trimmed value of content returns FALSE
2633 * 0 (zero) will be replaced as well
2634 *
2635 * @param string $content Input value undergoing processing in this function.
2636 * @param array $conf stdWrap properties for ifEmpty.
2637 * @return string The processed input value
2638 */
2639 public function stdWrap_ifEmpty($content = '', $conf = array()) {
2640 if (!trim($content)) {
2641 $content = $conf['ifEmpty'];
2642 }
2643 return $content;
2644 }
2645
2646 /**
2647 * ifBlank
2648 * Will set content to a replacement value in case the trimmed value of content has no length
2649 * 0 (zero) will not be replaced
2650 *
2651 * @param string $content Input value undergoing processing in this function.
2652 * @param array $conf stdWrap properties for ifBlank.
2653 * @return string The processed input value
2654 */
2655 public function stdWrap_ifBlank($content = '', $conf = array()) {
2656 if (trim($content) === '') {
2657 $content = $conf['ifBlank'];
2658 }
2659 return $content;
2660 }
2661
2662 /**
2663 * listNum
2664 * Gets a value off a CSV list after ifEmpty check
2665 * Might return an empty value in case the CSV does not contain a value at the position given by listNum
2666 * Use preIfEmptyListNum to avoid that behaviour
2667 *
2668 * @param string $content Input value undergoing processing in this function.
2669 * @param array $conf stdWrap properties for listNum.
2670 * @return string The processed input value
2671 */
2672 public function stdWrap_listNum($content = '', $conf = array()) {
2673 return $this->listNum($content, $conf['listNum'], $conf['listNum.']['splitChar']);
2674 }
2675
2676 /**
2677 * trim
2678 * Cuts off any whitespace at the beginning and the end of the content
2679 *
2680 * @param string $content Input value undergoing processing in this function.
2681 * @return string The processed input value
2682 */
2683 public function stdWrap_trim($content = '') {
2684 return trim($content);
2685 }
2686
2687 /**
2688 * strPad
2689 * Will return a string padded left/right/on both sides, based on configuration given as stdWrap properties
2690 *
2691 * @param string $content Input value undergoing processing in this function.
2692 * @param array $conf stdWrap properties for strPad.
2693 * @return string The processed input value
2694 */
2695 public function stdWrap_strPad($content = '', $conf = array()) {
2696 // Must specify a length in conf for this to make sense
2697 $length = 0;
2698 // Padding with space is PHP-default
2699 $padWith = ' ';
2700 // Padding on the right side is PHP-default
2701 $padType = STR_PAD_RIGHT;
2702 if (!empty($conf['strPad.']['length'])) {
2703 $length = isset($conf['strPad.']['length.']) ? $this->stdWrap($conf['strPad.']['length'], $conf['strPad.']['length.']) : $conf['strPad.']['length'];
2704 $length = (int)$length;
2705 }
2706 if (isset($conf['strPad.']['padWith']) && (string)$conf['strPad.']['padWith'] !== '') {
2707 $padWith = isset($conf['strPad.']['padWith.']) ? $this->stdWrap($conf['strPad.']['padWith'], $conf['strPad.']['padWith.']) : $conf['strPad.']['padWith'];
2708 }
2709 if (!empty($conf['strPad.']['type'])) {
2710 $type = isset($conf['strPad.']['type.']) ? $this->stdWrap($conf['strPad.']['type'], $conf['strPad.']['type.']) : $conf['strPad.']['type'];
2711 if (strtolower($type) === 'left') {
2712 $padType = STR_PAD_LEFT;
2713 } elseif (strtolower($type) === 'both') {
2714 $padType = STR_PAD_BOTH;
2715 }
2716 }
2717 return str_pad($content, $length, $padWith, $padType);
2718 }
2719
2720 /**
2721 * stdWrap
2722 * A recursive call of the stdWrap function set
2723 * This enables the user to execute stdWrap functions in another than the predefined order
2724 * It modifies the content, not the property
2725 * while the new feature of chained stdWrap functions modifies the property and not the content
2726 *
2727 * @param string $content Input value undergoing processing in this function.
2728 * @param array $conf stdWrap properties for stdWrap.
2729 * @return string The processed input value
2730 */
2731 public function stdWrap_stdWrap($content = '', $conf = array()) {
2732 return $this->stdWrap($content, $conf['stdWrap.']);
2733 }
2734
2735 /**
2736 * stdWrap process hook
2737 * can be used by extensions authors to modify the behaviour of stdWrap functions to their needs
2738 * this hook executes functions directly after the recursive stdWrap function call but still before the content gets modified
2739 *
2740 * @param string $content Input value undergoing processing in these functions.
2741 * @param array $conf All stdWrap properties, not just the ones for a particular function.
2742 * @return string The processed input value
2743 */
2744 public function stdWrap_stdWrapProcess($content = '', $conf = array()) {
2745 foreach ($this->stdWrapHookObjects as $hookObject) {
2746 /** @var ContentObjectStdWrapHookInterface $hookObject */
2747 $content = $hookObject->stdWrapProcess($content, $conf, $this);
2748 }
2749 return $content;
2750 }
2751
2752 /**
2753 * required
2754 * Will immediately stop rendering and return an empty value
2755 * when there is no content at this point
2756 *
2757 * @param string $content Input value undergoing processing in this function.
2758 * @return string The processed input value
2759 */
2760 public function stdWrap_required($content = '') {
2761 if ((string)$content === '') {
2762 $content = '';
2763 $this->stopRendering[$this->stdWrapRecursionLevel] = TRUE;
2764 }
2765 return $content;
2766 }
2767
2768 /**
2769 * if
2770 * Will immediately stop rendering and return an empty value
2771 * when the result of the checks returns FALSE
2772 *
2773 * @param string $content Input value undergoing processing in this function.
2774 * @param array $conf stdWrap properties for if.
2775 * @return string The processed input value
2776 */
2777 public function stdWrap_if($content = '', $conf = array()) {
2778 if (empty($conf['if.']) || $this->checkIf($conf['if.'])) {
2779 return $content;
2780 }
2781 $this->stopRendering[$this->stdWrapRecursionLevel] = TRUE;
2782 return '';
2783 }
2784
2785 /**
2786 * fieldRequired
2787 * Will immediately stop rendering and return an empty value
2788 * when there is no content in the field given by fieldRequired
2789 *
2790 * @param string $content Input value undergoing processing in this function.
2791 * @param array $conf stdWrap properties for fieldRequired.
2792 * @return string The processed input value
2793 */
2794 public function stdWrap_fieldRequired($content = '', $conf = array()) {
2795 if (!trim($this->data[$conf['fieldRequired']])) {
2796 $content = '';
2797 $this->stopRendering[$this->stdWrapRecursionLevel] = TRUE;
2798 }
2799 return $content;
2800 }
2801
2802 /**
2803 * csConv
2804 * Will convert the current chracter set of the content to the one given in csConv
2805 *
2806 * @param string $content Input value undergoing processing in this function.
2807 * @param array $conf stdWrap properties for csConv.
2808 * @return string The processed input value
2809 */
2810 public function stdWrap_csConv($content = '', $conf = array()) {
2811 return $this->getTypoScriptFrontendController()->csConv($content, $conf['csConv']);
2812 }
2813
2814 /**
2815 * parseFunc
2816 * Will parse the content based on functions given as stdWrap properties
2817 * Heavily used together with RTE based content
2818 *
2819 * @param string $content Input value undergoing processing in this function.
2820 * @param array $conf stdWrap properties for parseFunc.
2821 * @return string The processed input value
2822 */
2823 public function stdWrap_parseFunc($content = '', $conf = array()) {
2824 return $this->parseFunc($content, $conf['parseFunc.'], $conf['parseFunc']);
2825 }
2826
2827 /**
2828 * HTMLparser
2829 * Will parse HTML content based on functions given as stdWrap properties
2830 * Heavily used together with RTE based content
2831 *
2832 * @param string $content Input value undergoing processing in this function.
2833 * @param array $conf stdWrap properties for HTMLparser.
2834 * @return string The processed input value
2835 */
2836 public function stdWrap_HTMLparser($content = '', $conf = array()) {
2837 if (is_array($conf['HTMLparser.'])) {
2838 $content = $this->HTMLparser_TSbridge($content, $conf['HTMLparser.']);
2839 }
2840 return $content;
2841 }
2842
2843 /**