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