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