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