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