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