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