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