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