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