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