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