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