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