[BUGFIX] Re-enable absolute external links
[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 $theValue = $this->imageLinkWrap($theValue, $info['originalFile'], $conf['imageLinkWrap.']);
1315 }
1316 $wrap = isset($conf['wrap.']) ? $this->stdWrap($conf['wrap'], $conf['wrap.']) : $conf['wrap'];
1317 if ($wrap) {
1318 $theValue = $this->wrap($theValue, $conf['wrap']);
1319 }
1320 return $theValue;
1321 }
1322
1323 /**
1324 * Returns the 'border' attribute for an <img> tag only if the doctype is not xhtml_strict, xhtml_11, xhtml_2 or html5
1325 * or if the config parameter 'disableImgBorderAttr' is not set.
1326 *
1327 * @param string $borderAttr The border attribute
1328 * @return string The border attribute
1329 * @todo Define visibility
1330 */
1331 public function getBorderAttr($borderAttr) {
1332 if (!GeneralUtility::inList('xhtml_strict,xhtml_11,xhtml_2', $GLOBALS['TSFE']->xhtmlDoctype) && $GLOBALS['TSFE']->config['config']['doctype'] != 'html5' && !$GLOBALS['TSFE']->config['config']['disableImgBorderAttr']) {
1333 return $borderAttr;
1334 }
1335 }
1336
1337 /**
1338 * Returns the html-template for rendering the image-Tag if no template is defined via typoscript the
1339 * default <img> tag template is returned
1340 *
1341 * @param string $layoutKey rendering key
1342 * @param array $conf TypoScript configuration properties
1343 * @return string
1344 */
1345 public function getImageTagTemplate($layoutKey, $conf) {
1346 if ($layoutKey && isset($conf['layout.']) && isset($conf['layout.'][$layoutKey . '.'])) {
1347 $imageTagLayout = $this->stdWrap($conf['layout.'][$layoutKey . '.']['element'], $conf['layout.'][$layoutKey . '.']['element.']);
1348 } else {
1349 $imageTagLayout = '<img src="###SRC###" width="###WIDTH###" height="###HEIGHT###" ###PARAMS### ###ALTPARAMS### ###BORDER######SELFCLOSINGTAGSLASH###>';
1350 }
1351 return $imageTagLayout;
1352 }
1353
1354 /**
1355 * Render alternate sources for the image tag. If no source collection is given an empty string is returned.
1356 *
1357 * @param string $layoutKey rendering key
1358 * @param array $conf TypoScript configuration properties
1359 * @param string $file
1360 * @throws \UnexpectedValueException
1361 * @return string
1362 */
1363 public function getImageSourceCollection($layoutKey, $conf, $file) {
1364 $sourceCollection = '';
1365 if ($layoutKey && $conf['sourceCollection.'] && ($conf['layout.'][$layoutKey . '.']['source'] || $conf['layout.'][$layoutKey . '.']['source.'])) {
1366
1367 // find active sourceCollection
1368 $activeSourceCollections = array();
1369 foreach ($conf['sourceCollection.'] as $sourceCollectionKey => $sourceCollectionConfiguration) {
1370 if (substr($sourceCollectionKey, -1) == '.') {
1371 if (empty($sourceCollectionConfiguration['if.']) || $this->checkIf($sourceCollectionConfiguration['if.'])) {
1372 $activeSourceCollections[] = $sourceCollectionConfiguration;
1373 }
1374 }
1375 }
1376
1377 // apply option split to configurations
1378 $srcLayoutOptionSplitted = $GLOBALS['TSFE']->tmpl->splitConfArray($conf['layout.'][$layoutKey . '.'], count($activeSourceCollections));
1379
1380 // render sources
1381 foreach ($activeSourceCollections as $key => $sourceConfiguration) {
1382 $sourceLayout = $this->stdWrap($srcLayoutOptionSplitted[$key]['source'], $srcLayoutOptionSplitted[$key]['source.']);
1383
1384 $sourceRenderConfiguration = array (
1385 'file' => $file,
1386 'file.' => $conf['file.']
1387 );
1388
1389 if (isset($sourceConfiguration['pixelDensity'])) {
1390 $pixelDensity = (int)$this->stdWrap($sourceConfiguration['pixelDensity'], $sourceConfiguration['pixelDensity.']);
1391 } else {
1392 $pixelDensity = 1;
1393 }
1394 $dimensionKeys = array('width', 'height', 'maxW', 'minW', 'maxH', 'minH');
1395 foreach ($dimensionKeys as $dimensionKey) {
1396 $dimension = $this->stdWrap($sourceConfiguration[$dimensionKey], $sourceConfiguration[$dimensionKey . '.']);
1397 if (!$dimension) {
1398 $dimension = $this->stdWrap($conf['file.'][$dimensionKey], $conf['file.'][$dimensionKey . '.']);
1399 }
1400 if ($dimension) {
1401 if (strstr($dimension, 'c') !== FALSE && ($dimensionKey === 'width' || $dimensionKey === 'height')) {
1402 $dimensionParts = explode('c', $dimension, 2);
1403 $dimension = (int)($dimensionParts[0] * $pixelDensity) . 'c';
1404 if ($dimensionParts[1]) {
1405 $dimension .= $dimensionParts[1];
1406 }
1407 } else {
1408 $dimension = (int)($dimension * $pixelDensity);
1409 }
1410 $sourceRenderConfiguration['file.'][$dimensionKey] = $dimension;
1411 // Remove the stdWrap properties for dimension as they have been processed already above.
1412 unset($sourceRenderConfiguration['file.'][$dimensionKey . '.']);
1413 }
1414 }
1415 $sourceInfo = $this->getImgResource($sourceRenderConfiguration['file'], $sourceRenderConfiguration['file.']);
1416 if ($sourceInfo) {
1417 $sourceConfiguration['width'] = $sourceInfo[0];
1418 $sourceConfiguration['height'] = $sourceInfo[1];
1419 $sourceConfiguration['src'] = htmlspecialchars($GLOBALS['TSFE']->absRefPrefix . $sourceInfo[3]);
1420 $sourceConfiguration['selfClosingTagSlash'] = (!empty($GLOBALS['TSFE']->xhtmlDoctype) ? ' /' : '');
1421
1422 $oneSourceCollection = $this->substituteMarkerArray($sourceLayout, $sourceConfiguration, '###|###', TRUE, TRUE);
1423
1424 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['getImageSourceCollection'])) {
1425 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['getImageSourceCollection'] as $classData) {
1426 $hookObject = GeneralUtility::getUserObj($classData);
1427 if (!$hookObject instanceof ContentObjectOneSourceCollectionHookInterface) {
1428 throw new \UnexpectedValueException(
1429 '$hookObject must implement interface TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectOneSourceCollectionHookInterface',
1430 1380007853
1431 );
1432 }
1433 $oneSourceCollection = $hookObject->getOneSourceCollection((array) $sourceRenderConfiguration, (array) $sourceConfiguration, $oneSourceCollection, $this);
1434 }
1435 }
1436
1437 $sourceCollection .= $oneSourceCollection;
1438 }
1439 }
1440 }
1441 return $sourceCollection;
1442 }
1443
1444 /**
1445 * Wraps the input string in link-tags that opens the image in a new window.
1446 *
1447 * @param string $string String to wrap, probably an <img> tag
1448 * @param string|\TYPO3\CMS\Core\Resource\File|\TYPO3\CMS\Core\Resource\FileReference $imageFile The original image file
1449 * @param array $conf TypoScript properties for the "imageLinkWrap" function
1450 * @return string The input string, $string, wrapped as configured.
1451 * @see cImage()
1452 * @todo Define visibility
1453 */
1454 public function imageLinkWrap($string, $imageFile, $conf) {
1455 $a1 = '';
1456 $a2 = '';
1457 $content = $string;
1458 $enable = isset($conf['enable.']) ? $this->stdWrap($conf['enable'], $conf['enable.']) : $conf['enable'];
1459 if ($enable) {
1460 $content = $this->typolink($string, $conf['typolink.']);
1461 if (isset($conf['file.'])) {
1462 $imageFile = $this->stdWrap($imageFile, $conf['file.']);
1463 }
1464
1465 if ($imageFile instanceof \TYPO3\CMS\Core\Resource\File) {
1466 $file = $imageFile;
1467 } elseif ($imageFile instanceof \TYPO3\CMS\Core\Resource\FileReference) {
1468 $file = $imageFile->getOriginalFile();
1469 } else {
1470 if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($imageFile)) {
1471 $file = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getFileObject((int)$imageFile);
1472 } else {
1473 $file = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getFileObjectFromCombinedIdentifier($imageFile);
1474 }
1475 }
1476
1477 // Create imageFileLink if not created with typolink
1478 if ($content == $string) {
1479 $parameterNames = array('width', 'height', 'effects', 'bodyTag', 'title', 'wrap');
1480 $parameters = array();
1481 $sample = isset($conf['sample.']) ? $this->stdWrap($conf['sample'], $conf['sample.']) : $conf['sample'];
1482 if ($sample) {
1483 $parameters['sample'] = 1;
1484 }
1485 foreach ($parameterNames as $parameterName) {
1486 if (isset($conf[$parameterName . '.'])) {
1487 $conf[$parameterName] = $this->stdWrap($conf[$parameterName], $conf[$parameterName . '.']);
1488 }
1489 if (isset($conf[$parameterName]) && $conf[$parameterName]) {
1490 $parameters[$parameterName] = $conf[$parameterName];
1491 }
1492 }
1493 $parametersEncoded = base64_encode(serialize($parameters));
1494 $hmac = GeneralUtility::hmac(implode('|', array($file->getUid(), $parametersEncoded)));
1495 $params = '&md5=' . $hmac;
1496 foreach (str_split($parametersEncoded, 64) as $index => $chunk) {
1497 $params .= '&parameters' . rawurlencode('[') . $index . rawurlencode(']') . '=' . rawurlencode($chunk);
1498 }
1499 $url = $GLOBALS['TSFE']->absRefPrefix . 'index.php?eID=tx_cms_showpic&file=' . $file->getUid() . $params;
1500 $directImageLink = isset($conf['directImageLink.']) ? $this->stdWrap($conf['directImageLink'], $conf['directImageLink.']) : $conf['directImageLink'];
1501 if ($directImageLink) {
1502 $imgResourceConf = array(
1503 'file' => $imageFile,
1504 'file.' => $conf
1505 );
1506 $url = $this->IMG_RESOURCE($imgResourceConf);
1507 if (!$url) {
1508 // If no imagemagick / gm is available
1509 $url = $imageFile;
1510 }
1511 }
1512 // Create TARGET-attribute only if the right doctype is used
1513 if (!GeneralUtility::inList('xhtml_strict,xhtml_11,xhtml_2', $GLOBALS['TSFE']->xhtmlDoctype)) {
1514 $target = isset($conf['target.']) ? $this->stdWrap($conf['target'], $conf['target.']) : $conf['target'];
1515 if ($target) {
1516 $target = sprintf(' target="%s"', $target);
1517 } else {
1518 $target = ' target="thePicture"';
1519 }
1520 } else {
1521 $target = '';
1522 }
1523 $conf['JSwindow'] = isset($conf['JSwindow.']) ? $this->stdWrap($conf['JSwindow'], $conf['JSwindow.']) : $conf['JSwindow'];
1524 if ($conf['JSwindow']) {
1525 if ($conf['JSwindow.']['altUrl'] || $conf['JSwindow.']['altUrl.']) {
1526 $altUrl = isset($conf['JSwindow.']['altUrl.']) ? $this->stdWrap($conf['JSwindow.']['altUrl'], $conf['JSwindow.']['altUrl.']) : $conf['JSwindow.']['altUrl'];
1527 if ($altUrl) {
1528 $url = $altUrl . ($conf['JSwindow.']['altUrl_noDefaultParams'] ? '' : '?file=' . rawurlencode($imageFile) . $params);
1529 }
1530 }
1531
1532 $processedFile = $file->process('Image.CropScaleMask', $conf);
1533 $JSwindowExpand = isset($conf['JSwindow.']['expand.']) ? $this->stdWrap($conf['JSwindow.']['expand'], $conf['JSwindow.']['expand.']) : $conf['JSwindow.']['expand'];
1534 $offset = GeneralUtility::intExplode(',', $JSwindowExpand . ',');
1535 $newWindow = isset($conf['JSwindow.']['newWindow.']) ? $this->stdWrap($conf['JSwindow.']['newWindow'], $conf['JSwindow.']['newWindow.']) : $conf['JSwindow.']['newWindow'];
1536 $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 . '>';
1537 $a2 = '</a>';
1538 $GLOBALS['TSFE']->setJS('openPic');
1539 } else {
1540 $conf['linkParams.']['parameter'] = $url;
1541 $string = $this->typoLink($string, $conf['linkParams.']);
1542 }
1543 if (isset($conf['stdWrap.'])) {
1544 $string = $this->stdWrap($string, $conf['stdWrap.']);
1545 }
1546 $content = $a1 . $string . $a2;
1547 }
1548 }
1549 return $content;
1550 }
1551
1552 /**
1553 * Returns content of a file. If it's an image the content of the file is not returned but rather an image tag is.
1554 *
1555 * @param string $fName The filename, being a TypoScript resource data type
1556 * @param string $addParams Additional parameters (attributes). Default is empty alt and title tags.
1557 * @return string If jpg,gif,jpeg,png: returns image_tag with picture in. If html,txt: returns content string
1558 * @see FILE()
1559 * @todo Define visibility
1560 */
1561 public function fileResource($fName, $addParams = 'alt="" title=""') {
1562 $incFile = $GLOBALS['TSFE']->tmpl->getFileName($fName);
1563 if ($incFile && file_exists($incFile)) {
1564 $fileinfo = GeneralUtility::split_fileref($incFile);
1565 if (GeneralUtility::inList('jpg,gif,jpeg,png', $fileinfo['fileext'])) {
1566 $imgFile = $incFile;
1567 $imgInfo = @getImageSize($imgFile);
1568 return '<img src="' . $GLOBALS['TSFE']->absRefPrefix . $imgFile . '" width="' . $imgInfo[0] . '" height="' . $imgInfo[1] . '"' . $this->getBorderAttr(' border="0"') . ' ' . $addParams . ' />';
1569 } elseif (filesize($incFile) < 1024 * 1024) {
1570 return $GLOBALS['TSFE']->tmpl->fileContent($incFile);
1571 }
1572 }
1573 }
1574
1575 /**
1576 * Sets the SYS_LASTCHANGED timestamp if input timestamp is larger than current value.
1577 * The SYS_LASTCHANGED timestamp can be used by various caching/indexing applications to determine if the page has new content.
1578 * Therefore you should call this function with the last-changed timestamp of any element you display.
1579 *
1580 * @param integer $tstamp Unix timestamp (number of seconds since 1970)
1581 * @return void
1582 * @see \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::setSysLastChanged()
1583 * @todo Define visibility
1584 */
1585 public function lastChanged($tstamp) {
1586 $tstamp = (int)$tstamp;
1587 if ($tstamp > (int)$GLOBALS['TSFE']->register['SYS_LASTCHANGED']) {
1588 $GLOBALS['TSFE']->register['SYS_LASTCHANGED'] = $tstamp;
1589 }
1590 }
1591
1592 /**
1593 * Wraps the input string by the $wrap value and implements the "linkWrap" data type as well.
1594 * 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.
1595 *
1596 * @param string $content Input string
1597 * @param string $wrap A string where the first two parts separated by "|" (vertical line) will be wrapped around the input string
1598 * @return string Wrapped output string
1599 * @see wrap(), cImage(), FILE()
1600 * @todo Define visibility
1601 */
1602 public function linkWrap($content, $wrap) {
1603 $wrapArr = explode('|', $wrap);
1604 if (preg_match('/\\{([0-9]*)\\}/', $wrapArr[0], $reg)) {
1605 if ($uid = $GLOBALS['TSFE']->tmpl->rootLine[$reg[1]]['uid']) {
1606 $wrapArr[0] = str_replace($reg[0], $uid, $wrapArr[0]);
1607 }
1608 }
1609 return trim($wrapArr[0]) . $content . trim($wrapArr[1]);
1610 }
1611
1612 /**
1613 * An abstraction method which creates an alt or title parameter for an HTML img, applet, area or input element and the FILE content element.
1614 * From the $conf array it implements the properties "altText", "titleText" and "longdescURL"
1615 *
1616 * @param array $conf TypoScript configuration properties
1617 * @param boolean $longDesc If set, the longdesc attribute will be generated - must only be used for img elements!
1618 * @return string Parameter string containing alt and title parameters (if any)
1619 * @see IMGTEXT(), FILE(), FORM(), cImage(), filelink()
1620 * @todo Define visibility
1621 */
1622 public function getAltParam($conf, $longDesc = TRUE) {
1623 $altText = isset($conf['altText.']) ? trim($this->stdWrap($conf['altText'], $conf['altText.'])) : trim($conf['altText']);
1624 $titleText = isset($conf['titleText.']) ? trim($this->stdWrap($conf['titleText'], $conf['titleText.'])) : trim($conf['titleText']);
1625 if (isset($conf['longdescURL.']) && $GLOBALS['TSFE']->config['config']['doctype'] != 'html5') {
1626 $longDesc = $this->typoLink_URL($conf['longdescURL.']);
1627 } else {
1628 $longDesc = trim($conf['longdescURL']);
1629 }
1630 // "alt":
1631 $altParam = ' alt="' . htmlspecialchars($altText) . '"';
1632 // "title":
1633 $emptyTitleHandling = 'useAlt';
1634 $emptyTitleHandling = isset($conf['emptyTitleHandling.']) ? $this->stdWrap($conf['emptyTitleHandling'], $conf['emptyTitleHandling.']) : $conf['emptyTitleHandling'];
1635 // Choices: 'keepEmpty' | 'useAlt' | 'removeAttr'
1636 if ($titleText || $emptyTitleHandling == 'keepEmpty') {
1637 $altParam .= ' title="' . htmlspecialchars($titleText) . '"';
1638 } elseif (!$titleText && $emptyTitleHandling == 'useAlt') {
1639 $altParam .= ' title="' . htmlspecialchars($altText) . '"';
1640 }
1641 // "longDesc" URL
1642 if ($longDesc) {
1643 $altParam .= ' longdesc="' . htmlspecialchars(strip_tags($longDesc)) . '"';
1644 }
1645 return $altParam;
1646 }
1647
1648 /**
1649 * Removes forbidden characters and spaces from name/id attributes in the form tag and formfields
1650 *
1651 * @param string $name Input string
1652 * @return string the cleaned string
1653 * @see FORM()
1654 * @todo Define visibility
1655 */
1656 public function cleanFormName($name) {
1657 // Turn data[x][y] into data:x:y:
1658 $name = preg_replace('/\\[|\\]\\[?/', ':', trim($name));
1659 // Remove illegal chars like _
1660 return preg_replace('#[^:a-zA-Z0-9]#', '', $name);
1661 }
1662
1663 /**
1664 * An abstraction method to add parameters to an A tag.
1665 * Uses the ATagParams property.
1666 *
1667 * @param array $conf TypoScript configuration properties
1668 * @param boolean $addGlobal If set, will add the global config.ATagParams to the link
1669 * @return string String containing the parameters to the A tag (if non empty, with a leading space)
1670 * @see IMGTEXT(), filelink(), makelinks(), typolink()
1671 * @todo Define visibility
1672 */
1673 public function getATagParams($conf, $addGlobal = 1) {
1674 $aTagParams = '';
1675 if ($conf['ATagParams.']) {
1676 $aTagParams = ' ' . $this->stdWrap($conf['ATagParams'], $conf['ATagParams.']);
1677 } elseif ($conf['ATagParams']) {
1678 $aTagParams = ' ' . $conf['ATagParams'];
1679 }
1680 if ($addGlobal) {
1681 $aTagParams = ' ' . trim(($GLOBALS['TSFE']->ATagParams . $aTagParams));
1682 }
1683 // Extend params
1684 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'])) {
1685 $_params = array(
1686 'conf' => &$conf,
1687 'aTagParams' => &$aTagParams
1688 );
1689 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['getATagParamsPostProc'] as $objRef) {
1690 $processor =& GeneralUtility::getUserObj($objRef);
1691 $aTagParams = $processor->process($_params, $this);
1692 }
1693 }
1694
1695 $aTagParams = trim($aTagParams);
1696 if (!empty($aTagParams)) {
1697 $aTagParams = ' ' . $aTagParams;
1698 }
1699
1700 return $aTagParams;
1701 }
1702
1703 /**
1704 * All extension links should ask this function for additional properties to their tags.
1705 * Designed to add for instance an "onclick" property for site tracking systems.
1706 *
1707 * @param string $URL URL of the website
1708 * @param string $TYPE
1709 * @return string The additional tag properties
1710 * @todo Define visibility
1711 */
1712 public function extLinkATagParams($URL, $TYPE) {
1713 $out = '';
1714 if ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['extLinkATagParamsHandler']) {
1715 $extLinkATagParamsHandler = GeneralUtility::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['extLinkATagParamsHandler']);
1716 if (method_exists($extLinkATagParamsHandler, 'main')) {
1717 $out .= trim($extLinkATagParamsHandler->main($URL, $TYPE, $this));
1718 }
1719 }
1720 return trim($out) ? ' ' . trim($out) : '';
1721 }
1722
1723 /***********************************************
1724 *
1725 * HTML template processing functions
1726 *
1727 ***********************************************/
1728 /**
1729 * Returns a subpart from the input content stream.
1730 * A subpart is a part of the input stream which is encapsulated in a
1731 * string matching the input string, $marker. If this string is found
1732 * inside of HTML comment tags the start/end points of the content block
1733 * returned will be that right outside that comment block.
1734 * Example: The contennt string is
1735 * "Hello <!--###sub1### begin--> World. How are <!--###sub1### end--> you?"
1736 * If $marker is "###sub1###" then the content returned is
1737 * " World. How are ". The input content string could just as well have
1738 * been "Hello ###sub1### World. How are ###sub1### you?" and the result
1739 * would be the same
1740 * Wrapper for \TYPO3\CMS\Core\Html\HtmlParser::getSubpart which behaves identical
1741 *
1742 * @param string $content The content stream, typically HTML template content.
1743 * @param string $marker The marker string, typically on the form "###[the marker string]###
1744 * @return string The subpart found, if found.
1745 */
1746 public function getSubpart($content, $marker) {
1747 return \TYPO3\CMS\Core\Html\HtmlParser::getSubpart($content, $marker);
1748 }
1749
1750 /**
1751 * Substitute subpart in input template stream.
1752 * This function substitutes a subpart in $content with the content of
1753 * $subpartContent.
1754 * Wrapper for \TYPO3\CMS\Core\Html\HtmlParser::substituteSubpart which behaves identical
1755 *
1756 * @param string $content The content stream, typically HTML template content.
1757 * @param string $marker The marker string, typically on the form "###[the marker string]###
1758 * @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.
1759 * @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!
1760 * @return string The processed HTML content string.
1761 */
1762 public function substituteSubpart($content, $marker, $subpartContent, $recursive = 1) {
1763 return \TYPO3\CMS\Core\Html\HtmlParser::substituteSubpart($content, $marker, $subpartContent, $recursive);
1764 }
1765
1766 /**
1767 * Substitues multiple subparts at once
1768 *
1769 * @param string $content The content stream, typically HTML template content.
1770 * @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.
1771 * @return string The processed HTML content string.
1772 */
1773 public function substituteSubpartArray($content, array $subpartsContent) {
1774 return \TYPO3\CMS\Core\Html\HtmlParser::substituteSubpartArray($content, $subpartsContent);
1775 }
1776
1777 /**
1778 * Substitutes a marker string in the input content
1779 * (by a simple str_replace())
1780 *
1781 * @param string $content The content stream, typically HTML template content.
1782 * @param string $marker The marker string, typically on the form "###[the marker string]###
1783 * @param mixed $markContent The content to insert instead of the marker string found.
1784 * @return string The processed HTML content string.
1785 * @see substituteSubpart()
1786 */
1787 public function substituteMarker($content, $marker, $markContent) {
1788 return \TYPO3\CMS\Core\Html\HtmlParser::substituteMarker($content, $marker, $markContent);
1789 }
1790
1791 /**
1792 * Multi substitution function with caching.
1793 *
1794 * This function should be a one-stop substitution function for working
1795 * with HTML-template. It does not substitute by str_replace but by
1796 * splitting. This secures that the value inserted does not themselves
1797 * contain markers or subparts.
1798 *
1799 * Note that the "caching" won't cache the content of the substition,
1800 * but only the splitting of the template in various parts. So if you
1801 * want only one cache-entry per template, make sure you always pass the
1802 * exact same set of marker/subpart keys. Else you will be flooding the
1803 * users cache table.
1804 *
1805 * This function takes three kinds of substitutions in one:
1806 * $markContentArray is a regular marker-array where the 'keys' are
1807 * substituted in $content with their values
1808 *
1809 * $subpartContentArray works exactly like markContentArray only is whole
1810 * subparts substituted and not only a single marker.
1811 *
1812 * $wrappedSubpartContentArray is an array of arrays with 0/1 keys where
1813 * the subparts pointed to by the main key is wrapped with the 0/1 value
1814 * alternating.
1815 *
1816 * @param string $content The content stream, typically HTML template content.
1817 * @param array $markContentArray Regular marker-array where the 'keys' are substituted in $content with their values
1818 * @param array $subpartContentArray Exactly like markContentArray only is whole subparts substituted and not only a single marker.
1819 * @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.
1820 * @return string The output content stream
1821 * @see substituteSubpart(), substituteMarker(), substituteMarkerInObject(), TEMPLATE()
1822 */
1823 public function substituteMarkerArrayCached($content, array $markContentArray = NULL, array $subpartContentArray = NULL, array $wrappedSubpartContentArray = NULL) {
1824 $GLOBALS['TT']->push('substituteMarkerArrayCached');
1825 // If not arrays then set them
1826 if (is_null($markContentArray)) {
1827 // Plain markers
1828 $markContentArray = array();
1829 }
1830 if (is_null($subpartContentArray)) {
1831 // Subparts being directly substituted
1832 $subpartContentArray = array();
1833 }
1834 if (is_null($wrappedSubpartContentArray)) {
1835 // Subparts being wrapped
1836 $wrappedSubpartContentArray = array();
1837 }
1838 // Finding keys and check hash:
1839 $sPkeys = array_keys($subpartContentArray);
1840 $wPkeys = array_keys($wrappedSubpartContentArray);
1841 $aKeys = array_merge(array_keys($markContentArray), $sPkeys, $wPkeys);
1842 if (!count($aKeys)) {
1843 $GLOBALS['TT']->pull();
1844 return $content;
1845 }
1846 asort($aKeys);
1847 $storeKey = md5('substituteMarkerArrayCached_storeKey:' . serialize(array(
1848 $content,
1849 $aKeys
1850 )));
1851 if ($this->substMarkerCache[$storeKey]) {
1852 $storeArr = $this->substMarkerCache[$storeKey];
1853 $GLOBALS['TT']->setTSlogMessage('Cached', 0);
1854 } else {
1855 $storeArrDat = $GLOBALS['TSFE']->sys_page->getHash($storeKey);
1856 if (is_array($storeArrDat)) {
1857 $storeArr = $storeArrDat;
1858 // Setting cache:
1859 $this->substMarkerCache[$storeKey] = $storeArr;
1860 $GLOBALS['TT']->setTSlogMessage('Cached from DB', 0);
1861 } else {
1862 // Initialize storeArr
1863 $storeArr = array();
1864 // Finding subparts and substituting them with the subpart as a marker
1865 foreach ($sPkeys as $sPK) {
1866 $content = $this->substituteSubpart($content, $sPK, $sPK);
1867 }
1868 // Finding subparts and wrapping them with markers
1869 foreach ($wPkeys as $wPK) {
1870 $content = $this->substituteSubpart($content, $wPK, array(
1871 $wPK,
1872 $wPK
1873 ));
1874 }
1875 // Traverse keys and quote them for reg ex.
1876 foreach ($aKeys as $tK => $tV) {
1877 $aKeys[$tK] = preg_quote($tV, '/');
1878 }
1879 $regex = '/' . implode('|', $aKeys) . '/';
1880 // Doing regex's
1881 $storeArr['c'] = preg_split($regex, $content);
1882 preg_match_all($regex, $content, $keyList);
1883 $storeArr['k'] = $keyList[0];
1884 // Setting cache:
1885 $this->substMarkerCache[$storeKey] = $storeArr;
1886 // Storing the cached data:
1887 $GLOBALS['TSFE']->sys_page->storeHash($storeKey, $storeArr, 'substMarkArrayCached');
1888 $GLOBALS['TT']->setTSlogMessage('Parsing', 0);
1889 }
1890 }
1891 // Substitution/Merging:
1892 // Merging content types together, resetting
1893 $valueArr = array_merge($markContentArray, $subpartContentArray, $wrappedSubpartContentArray);
1894 $wSCA_reg = array();
1895 $content = '';
1896 // Traversing the keyList array and merging the static and dynamic content
1897 foreach ($storeArr['k'] as $n => $keyN) {
1898 $content .= $storeArr['c'][$n];
1899 if (!is_array($valueArr[$keyN])) {
1900 $content .= $valueArr[$keyN];
1901 } else {
1902 $content .= $valueArr[$keyN][(int)$wSCA_reg[$keyN] % 2];
1903 $wSCA_reg[$keyN]++;
1904 }
1905 }
1906 $content .= $storeArr['c'][count($storeArr['k'])];
1907 $GLOBALS['TT']->pull();
1908 return $content;
1909 }
1910
1911 /**
1912 * Traverses the input $markContentArray array and for each key the marker
1913 * by the same name (possibly wrapped and in upper case) will be
1914 * substituted with the keys value in the array.
1915 *
1916 * This is very useful if you have a data-record to substitute in some
1917 * content. In particular when you use the $wrap and $uppercase values to
1918 * pre-process the markers. Eg. a key name like "myfield" could effectively
1919 * be represented by the marker "###MYFIELD###" if the wrap value
1920 * was "###|###" and the $uppercase boolean TRUE.
1921 *
1922 * @param string $content The content stream, typically HTML template content.
1923 * @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.
1924 * @param string $wrap A wrap value - [part 1] | [part 2] - for the markers before substitution
1925 * @param boolean $uppercase If set, all marker string substitution is done with upper-case markers.
1926 * @param boolean $deleteUnused If set, all unused marker are deleted.
1927 * @return string The processed output stream
1928 * @see substituteMarker(), substituteMarkerInObject(), TEMPLATE()
1929 */
1930 public function substituteMarkerArray($content, array $markContentArray, $wrap = '', $uppercase = FALSE, $deleteUnused = FALSE) {
1931 return \TYPO3\CMS\Core\Html\HtmlParser::substituteMarkerArray($content, $markContentArray, $wrap, $uppercase, $deleteUnused);
1932 }
1933
1934 /**
1935 * Substitute marker array in an array of values
1936 *
1937 * @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)
1938 * @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.
1939 * @return mixed The processed input variable.
1940 * @see substituteMarker()
1941 */
1942 public function substituteMarkerInObject(&$tree, array $markContentArray) {
1943 if (is_array($tree)) {
1944 foreach ($tree as $key => $value) {
1945 $this->substituteMarkerInObject($tree[$key], $markContentArray);
1946 }
1947 } else {
1948 $tree = $this->substituteMarkerArray($tree, $markContentArray);
1949 }
1950 return $tree;
1951 }
1952
1953 /**
1954 * Replaces all markers and subparts in a template with the content provided in the structured array.
1955 *
1956 * @param string $content
1957 * @param array $markersAndSubparts
1958 * @param string $wrap
1959 * @param boolean $uppercase
1960 * @param boolean $deleteUnused
1961 * @return string
1962 */
1963 public function substituteMarkerAndSubpartArrayRecursive($content, array $markersAndSubparts, $wrap = '', $uppercase = FALSE, $deleteUnused = FALSE) {
1964 return \TYPO3\CMS\Core\Html\HtmlParser::substituteMarkerAndSubpartArrayRecursive($content, $markersAndSubparts, $wrap, $uppercase, $deleteUnused);
1965 }
1966
1967 /**
1968 * Adds elements to the input $markContentArray based on the values from
1969 * the fields from $fieldList found in $row
1970 *
1971 * @param array $markContentArray Array with key/values being marker-strings/substitution values.
1972 * @param array $row An array with keys found in the $fieldList (typically a record) which values should be moved to the $markContentArray
1973 * @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)
1974 * @param boolean $nl2br If set, all values added to $markContentArray will be nl2br()'ed
1975 * @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 "###
1976 * @param boolean $HSC If set, all values are passed through htmlspecialchars() - RECOMMENDED to avoid most obvious XSS and maintain XHTML compliance.
1977 * @return array The modified $markContentArray
1978 */
1979 public function fillInMarkerArray(array $markContentArray, array $row, $fieldList = '', $nl2br = TRUE, $prefix = 'FIELD_', $HSC = FALSE) {
1980 if ($fieldList) {
1981 $fArr = GeneralUtility::trimExplode(',', $fieldList, TRUE);
1982 foreach ($fArr as $field) {
1983 $markContentArray['###' . $prefix . $field . '###'] = $nl2br ? nl2br($row[$field], !empty($GLOBALS['TSFE']->xhtmlDoctype)) : $row[$field];
1984 }
1985 } else {
1986 if (is_array($row)) {
1987 foreach ($row as $field => $value) {
1988 if (!\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($field)) {
1989 if ($HSC) {
1990 $value = htmlspecialchars($value);
1991 }
1992 $markContentArray['###' . $prefix . $field . '###'] = $nl2br ? nl2br($value, !empty($GLOBALS['TSFE']->xhtmlDoctype)) : $value;
1993 }
1994 }
1995 }
1996 }
1997 return $markContentArray;
1998 }
1999
2000 /**
2001 * Sets the current file object during iterations over files.
2002 *
2003 * @param \TYPO3\CMS\Core\Resource\File $fileObject The file object.
2004 */
2005 public function setCurrentFile($fileObject) {
2006 $this->currentFile = $fileObject;
2007 }
2008
2009 /**
2010 * Gets the current file object during iterations over files.
2011 *
2012 * @return \TYPO3\CMS\Core\Resource\File The current file object.
2013 */
2014 public function getCurrentFile() {
2015 return $this->currentFile;
2016 }
2017
2018 /***********************************************
2019 *
2020 * "stdWrap" + sub functions
2021 *
2022 ***********************************************/
2023 /**
2024 * The "stdWrap" function. This is the implementation of what is known as "stdWrap properties" in TypoScript.
2025 * Basically "stdWrap" performs some processing of a value based on properties in the input $conf array(holding the TypoScript "stdWrap properties")
2026 * 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.
2027 *
2028 * If $this->alternativeData is an array it's used instead of the $this->data array in ->getData
2029 *
2030 * @param string $content Input value undergoing processing in this function. Possibly substituted by other values fetched from another source.
2031 * @param array $conf TypoScript "stdWrap properties".
2032 * @return string The processed input value
2033 */
2034 public function stdWrap($content = '', $conf = array()) {
2035 // If there is any hook object, activate all of the process and override functions.
2036 // The hook interface ContentObjectStdWrapHookInterface takes care that all 4 methods exist.
2037 if ($this->stdWrapHookObjects) {
2038 $conf['stdWrapPreProcess'] = 1;
2039 $conf['stdWrapOverride'] = 1;
2040 $conf['stdWrapProcess'] = 1;
2041 $conf['stdWrapPostProcess'] = 1;
2042 }
2043
2044 if (!is_array($conf) || !$conf) {
2045 return $content;
2046 }
2047
2048 // Cache handling
2049 if (is_array($conf['cache.'])) {
2050 $conf['cache.']['key'] = $this->stdWrap($conf['cache.']['key'], $conf['cache.']['key.']);
2051 $conf['cache.']['tags'] = $this->stdWrap($conf['cache.']['tags'], $conf['cache.']['tags.']);
2052 $conf['cache.']['lifetime'] = $this->stdWrap($conf['cache.']['lifetime'], $conf['cache.']['lifetime.']);
2053 $conf['cacheRead'] = 1;
2054 $conf['cacheStore'] = 1;
2055 }
2056 // Check, which of the available stdWrap functions is needed for the current conf Array
2057 // and keep only those but still in the same order
2058 $sortedConf = array_intersect_key($this->stdWrapOrder, $conf);
2059 // Functions types that should not make use of nested stdWrap function calls to avoid conflicts with internal TypoScript used by these functions
2060 $stdWrapDisabledFunctionTypes = 'cObject,functionName,stdWrap';
2061 // Additional Array to check whether a function has already been executed
2062 $isExecuted = array();
2063 // Additional switch to make sure 'required', 'if' and 'fieldRequired'
2064 // will still stop rendering immediately in case they return FALSE
2065 $this->stdWrapRecursionLevel++;
2066 $this->stopRendering[$this->stdWrapRecursionLevel] = FALSE;
2067 // execute each function in the predefined order
2068 foreach ($sortedConf as $stdWrapName => $functionType) {
2069 // eliminate the second key of a pair 'key'|'key.' to make sure functions get called only once and check if rendering has been stopped
2070 if (!$isExecuted[$stdWrapName] && !$this->stopRendering[$this->stdWrapRecursionLevel]) {
2071 $functionName = rtrim($stdWrapName, '.');
2072 $functionProperties = $functionName . '.';
2073 // If there is any code one the next level, check if it contains "official" stdWrap functions
2074 // if yes, execute them first - will make each function stdWrap aware
2075 // so additional stdWrap calls within the functions can be removed, since the result will be the same
2076 // exception: the recursive stdWrap function and cObject will still be using their own stdWrap call, since it modifies the content and not a property
2077 if (count($conf[$functionProperties]) && !GeneralUtility::inList($stdWrapDisabledFunctionTypes, $functionType)) {
2078 if (array_intersect_key($this->stdWrapOrder, $conf[$functionProperties])) {
2079 $conf[$functionName] = $this->stdWrap($conf[$functionName], $conf[$functionProperties]);
2080 }
2081 }
2082 // Check if key is still containing something, since it might have been changed by next level stdWrap before
2083 if ((isset($conf[$functionName]) || $conf[$functionProperties]) && ($functionType !== 'boolean' || $conf[$functionName])) {
2084 // Get just that part of $conf that is needed for the particular function
2085 $singleConf = array(
2086 $functionName => $conf[$functionName],
2087 $functionProperties => $conf[$functionProperties]
2088 );
2089 // In this special case 'spaceBefore' and 'spaceAfter' need additional stuff from 'space.''
2090 if ($functionName === 'spaceBefore' || $functionName === 'spaceAfter') {
2091 $singleConf['space.'] = $conf['space.'];
2092 }
2093 // Hand over the whole $conf array to the stdWrapHookObjects
2094 if ($functionType === 'hook') {
2095 $singleConf = $conf;
2096 }
2097 // Add both keys - with and without the dot - to the set of executed functions
2098 $isExecuted[$functionName] = TRUE;
2099 $isExecuted[$functionProperties] = TRUE;
2100 // Call the function with the prefix stdWrap_ to make sure nobody can execute functions just by adding their name to the TS Array
2101 $functionName = 'stdWrap_' . $functionName;
2102 $content = $this->{$functionName}($content, $singleConf);
2103 } elseif ($functionType == 'boolean' && !$conf[$functionName]) {
2104 $isExecuted[$functionName] = TRUE;
2105 $isExecuted[$functionProperties] = TRUE;
2106 }
2107 }
2108 }
2109 unset($this->stopRendering[$this->stdWrapRecursionLevel]);
2110 $this->stdWrapRecursionLevel--;
2111
2112 return $content;
2113 }
2114
2115 /**
2116 * Gets a configuration value by passing them through stdWrap first and taking a default value if stdWrap doesn't yield a result.
2117 *
2118 * @param string $key The config variable key (from TS array).
2119 * @param array $config The TypoScript array.
2120 * @param string $defaultValue Optional default value.
2121 * @return string Value of the config variable
2122 */
2123 public function stdWrapValue($key, array $config, $defaultValue = '') {
2124 if (isset($config[$key])) {
2125 if (!isset($config[$key . '.'])) {
2126 return $config[$key];
2127 }
2128 } elseif (isset($config[$key . '.'])) {
2129 $config[$key] = '';
2130 } else {
2131 return $defaultValue;
2132 }
2133 $stdWrapped = $this->stdWrap($config[$key], $config[$key . '.']);
2134 return $stdWrapped ?: $defaultValue;
2135 }
2136
2137 /**
2138 * stdWrap pre process hook
2139 * can be used by extensions authors to modify the behaviour of stdWrap functions to their needs
2140 * this hook will execute functions before any other stdWrap function can modify anything
2141 *
2142 * @param string $content Input value undergoing processing in these functions.
2143 * @param array $conf All stdWrap properties, not just the ones for a particular function.
2144 * @return string The processed input value
2145 */
2146 public function stdWrap_stdWrapPreProcess($content = '', $conf = array()) {
2147 foreach ($this->stdWrapHookObjects as $hookObject) {
2148 $content = $hookObject->stdWrapPreProcess($content, $conf, $this);
2149 }
2150 return $content;
2151 }
2152
2153 /**
2154 * Check if content was cached before (depending on the given cache key)
2155 *
2156 * @param string $content Input value undergoing processing in these functions.
2157 * @param array $conf All stdWrap properties, not just the ones for a particular function.
2158 * @return string The processed input value
2159 */
2160 public function stdWrap_cacheRead($content = '', $conf = array()) {
2161 if (!empty($conf['cache.']['key'])) {
2162 /** @var $cacheFrontend \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend */
2163 $cacheFrontend = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('cache_hash');
2164 if ($cacheFrontend && $cacheFrontend->has($conf['cache.']['key'])) {
2165 $content = $cacheFrontend->get($conf['cache.']['key']);
2166 $this->stopRendering[$this->stdWrapRecursionLevel] = TRUE;
2167 }
2168 }
2169 return $content;
2170 }
2171
2172 /**
2173 * Add tags to page cache (comma-separated list)
2174 *
2175 * @param string $content Input value undergoing processing in these functions.
2176 * @param array $conf All stdWrap properties, not just the ones for a particular function.
2177 * @return string The processed input value
2178 */
2179 public function stdWrap_addPageCacheTags($content = '', $conf = array()) {
2180 $tags = isset($conf['addPageCacheTags.'])
2181 ? $this->stdWrap($conf['addPageCacheTags'], $conf['addPageCacheTags.'])
2182 : $conf['addPageCacheTags'];
2183 if (!empty($tags)) {
2184 $cacheTags = GeneralUtility::trimExplode(',', $tags, TRUE);
2185 $GLOBALS['TSFE']->addCacheTags($cacheTags);
2186 }
2187 return $content;
2188 }
2189
2190 /**
2191 * setContentToCurrent
2192 * actually it just does the contrary: Sets the value of 'current' based on current content
2193 *
2194 * @param string $content Input value undergoing processing in this function.
2195 * @param array $conf stdWrap properties for setContentToCurrent.
2196 * @return string The processed input value
2197 */
2198 public function stdWrap_setContentToCurrent($content = '', $conf = array()) {
2199 $this->data[$this->currentValKey] = $content;
2200 return $content;
2201 }
2202
2203 /**
2204 * setCurrent
2205 * Sets the value of 'current' based on the outcome of stdWrap operations
2206 *
2207 * @param string $content Input value undergoing processing in this function.
2208 * @param array $conf stdWrap properties for setCurrent.
2209 * @return string The processed input value
2210 */
2211 public function stdWrap_setCurrent($content = '', $conf = array()) {
2212 $this->data[$this->currentValKey] = $conf['setCurrent'];
2213 return $content;
2214 }
2215
2216 /**
2217 * lang
2218 * Translates content based on the language currently used by the FE
2219 *
2220 * @param string $content Input value undergoing processing in this function.
2221 * @param array $conf stdWrap properties for lang.
2222 * @return string The processed input value
2223 */
2224 public function stdWrap_lang($content = '', $conf = array()) {
2225 if (isset($conf['lang.']) && $GLOBALS['TSFE']->config['config']['language'] && isset($conf['lang.'][$GLOBALS['TSFE']->config['config']['language']])) {
2226 $content = $conf['lang.'][$GLOBALS['TSFE']->config['config']['language']];
2227 }
2228 return $content;
2229 }
2230
2231 /**
2232 * data
2233 * Gets content from different sources based on getText functions, makes use of alternativeData, when set
2234 *
2235 * @param string $content Input value undergoing processing in this function.
2236 * @param array $conf stdWrap properties for data.
2237 * @return string The processed input value
2238 */
2239 public function stdWrap_data($content = '', $conf = array()) {
2240 $content = $this->getData($conf['data'], is_array($this->alternativeData) ? $this->alternativeData : $this->data);
2241 // This must be unset directly after
2242 $this->alternativeData = '';
2243 return $content;
2244 }
2245
2246 /**
2247 * field
2248 * Gets content from a DB field
2249 *
2250 * @param string $content Input value undergoing processing in this function.
2251 * @param array $conf stdWrap properties for field.
2252 * @return string The processed input value
2253 */
2254 public function stdWrap_field($content = '', $conf = array()) {
2255 return $this->getFieldVal($conf['field']);
2256 }
2257
2258 /**
2259 * current
2260 * Gets content that has been perviously set as 'current'
2261 * Can be set via setContentToCurrent or setCurrent or will be set automatically i.e. inside the split function
2262 *
2263 * @param string $content Input value undergoing processing in this function.
2264 * @param array $conf stdWrap properties for current.
2265 * @return string The processed input value
2266 */
2267 public function stdWrap_current($content = '', $conf = array()) {
2268 return $this->data[$this->currentValKey];
2269 }
2270
2271 /**
2272 * cObject
2273 * Will replace the content with the value of a any official TypoScript cObject
2274 * like TEXT, COA, HMENU
2275 *
2276 * @param string $content Input value undergoing processing in this function.
2277 * @param array $conf stdWrap properties for cObject.
2278 * @return string The processed input value
2279 */
2280 public function stdWrap_cObject($content = '', $conf = array()) {
2281 return $this->cObjGetSingle($conf['cObject'], $conf['cObject.'], '/stdWrap/.cObject');
2282 }
2283
2284 /**
2285 * numRows
2286 * Counts the number of returned records of a DB operation
2287 * makes use of select internally
2288 *
2289 * @param string $content Input value undergoing processing in this function.
2290 * @param array $conf stdWrap properties for numRows.
2291 * @return string The processed input value
2292 */
2293 public function stdWrap_numRows($content = '', $conf = array()) {
2294 return $this->numRows($conf['numRows.']);
2295 }
2296
2297 /**
2298 * filelist
2299 * Will create a list of files based on some additional parameters
2300 *
2301 * @param string $content Input value undergoing processing in this function.
2302 * @param array $conf stdWrap properties for filelist.
2303 * @return string The processed input value
2304 */
2305 public function stdWrap_filelist($content = '', $conf = array()) {
2306 return $this->filelist($conf['filelist']);
2307 }
2308
2309 /**
2310 * preUserFunc
2311 * Will execute a user public function before the content will be modified by any other stdWrap function
2312 *
2313 * @param string $content Input value undergoing processing in this function.
2314 * @param array $conf stdWrap properties for preUserFunc.
2315 * @return string The processed input value
2316 */
2317 public function stdWrap_preUserFunc($content = '', $conf = array()) {
2318 return $this->callUserFunction($conf['preUserFunc'], $conf['preUserFunc.'], $content);
2319 }
2320
2321 /**
2322 * stdWrap override hook
2323 * can be used by extensions authors to modify the behaviour of stdWrap functions to their needs
2324 * this hook will execute functions on existing content but still before the content gets modified or replaced
2325 *
2326 * @param string $content Input value undergoing processing in these functions.
2327 * @param array $conf All stdWrap properties, not just the ones for a particular function.
2328 * @return string The processed input value
2329 */
2330 public function stdWrap_stdWrapOverride($content = '', $conf = array()) {
2331 foreach ($this->stdWrapHookObjects as $hookObject) {
2332 $content = $hookObject->stdWrapOverride($content, $conf, $this);
2333 }
2334 return $content;
2335 }
2336
2337 /**
2338 * override
2339 * Will override the current value of content with its own value'
2340 *
2341 * @param string $content Input value undergoing processing in this function.
2342 * @param array $conf stdWrap properties for override.
2343 * @return string The processed input value
2344 */
2345 public function stdWrap_override($content = '', $conf = array()) {
2346 if (trim($conf['override'])) {
2347 $content = $conf['override'];
2348 }
2349 return $content;
2350 }
2351
2352 /**
2353 * preIfEmptyListNum
2354 * Gets a value off a CSV list before the following ifEmpty check
2355 * 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
2356 *
2357 * @param string $content Input value undergoing processing in this function.
2358 * @param array $conf stdWrap properties for preIfEmptyListNum.
2359 * @return string The processed input value
2360 */
2361 public function stdWrap_preIfEmptyListNum($content = '', $conf = array()) {
2362 return $this->listNum($content, $conf['preIfEmptyListNum'], $conf['preIfEmptyListNum.']['splitChar']);
2363 }
2364
2365 /**
2366 * ifNull
2367 * Will set content to a replacement value in case the value of content is NULL
2368 *
2369 * @param string|NULL $content Input value undergoing processing in this function.
2370 * @param array $conf stdWrap properties for ifNull.
2371 * @return string The processed input value
2372 */
2373 public function stdWrap_ifNull($content = '', $conf = array()) {
2374 return $content !== NULL ? $content : $conf['ifNull'];
2375 }
2376
2377 /**
2378 * ifEmpty
2379 * Will set content to a replacement value in case the trimmed value of content returns FALSE
2380 * 0 (zero) will be replaced as well
2381 *
2382 * @param string $content Input value undergoing processing in this function.
2383 * @param array $conf stdWrap properties for ifEmpty.
2384 * @return string The processed input value
2385 */
2386 public function stdWrap_ifEmpty($content = '', $conf = array()) {
2387 if (!trim($content)) {
2388 $content = $conf['ifEmpty'];
2389 }
2390 return $content;
2391 }
2392
2393 /**
2394 * ifBlank
2395 * Will set content to a replacement value in case the trimmed value of content has no length
2396 * 0 (zero) will not be replaced
2397 *
2398 * @param string $content Input value undergoing processing in this function.
2399 * @param array $conf stdWrap properties for ifBlank.
2400 * @return string The processed input value
2401 */
2402 public function stdWrap_ifBlank($content = '', $conf = array()) {
2403 if (!strlen(trim($content))) {
2404 $content = $conf['ifBlank'];
2405 }
2406 return $content;
2407 }
2408
2409 /**
2410 * listNum
2411 * Gets a value off a CSV list after ifEmpty check
2412 * Might return an empty value in case the CSV does not contain a value at the position given by listNum
2413 * Use preIfEmptyListNum to avoid that behaviour
2414 *
2415 * @param string $content Input value undergoing processing in this function.
2416 * @param array $conf stdWrap properties for listNum.
2417 * @return string The processed input value
2418 */
2419 public function stdWrap_listNum($content = '', $conf = array()) {
2420 return $this->listNum($content, $conf['listNum'], $conf['listNum.']['splitChar']);
2421 }
2422
2423 /**
2424 * trim
2425 * Cuts off any whitespace at the beginning and the end of the content
2426 *
2427 * @param string $content Input value undergoing processing in this function.
2428 * @param array $conf stdWrap properties for trim.
2429 * @return string The processed input value
2430 */
2431 public function stdWrap_trim($content = '', $conf = array()) {
2432 return trim($content);
2433 }
2434
2435 /**
2436 * strPad
2437 * Will return a string padded left/right/on both sides, based on configuration given as stdWrap properties
2438 *
2439 * @param string $content Input value undergoing processing in this function.
2440 * @param array $conf stdWrap properties for strPad.
2441 * @return string The processed input value
2442 */
2443 public function stdWrap_strPad($content = '', $conf = array()) {
2444 // Must specify a length in conf for this to make sense
2445 $length = 0;
2446 // Padding with space is PHP-default
2447 $padWith = ' ';
2448 // Padding on the right side is PHP-default
2449 $padType = STR_PAD_RIGHT;
2450 if (!empty($conf['strPad.']['length'])) {
2451 $length = isset($conf['strPad.']['length.']) ? $this->stdWrap($conf['strPad.']['length'], $conf['strPad.']['length.']) : $conf['strPad.']['length'];
2452 $length = (int)$length;
2453 }
2454 if (isset($conf['strPad.']['padWith']) && strlen($conf['strPad.']['padWith']) > 0) {
2455 $padWith = isset($conf['strPad.']['padWith.']) ? $this->stdWrap($conf['strPad.']['padWith'], $conf['strPad.']['padWith.']) : $conf['strPad.']['padWith'];
2456 }
2457 if (!empty($conf['strPad.']['type'])) {
2458 $type = isset($conf['strPad.']['type.']) ? $this->stdWrap($conf['strPad.']['type'], $conf['strPad.']['type.']) : $conf['strPad.']['type'];
2459 if (strtolower($type) === 'left') {
2460 $padType = STR_PAD_LEFT;
2461 } elseif (strtolower($type) === 'both') {
2462 $padType = STR_PAD_BOTH;
2463 }
2464 }
2465 $content = str_pad($content, $length, $padWith, $padType);
2466 return $content;
2467 }
2468
2469 /**
2470 * stdWrap
2471 * A recursive call of the stdWrap function set
2472 * This enables the user to execute stdWrap functions in another than the predefined order
2473 * It modifies the content, not the property
2474 * while the new feature of chained stdWrap functions modifies the property and not the content
2475 *
2476 * @param string $content Input value undergoing processing in this function.
2477 * @param array $conf stdWrap properties for stdWrap.
2478 * @return string The processed input value
2479 */
2480 public function stdWrap_stdWrap($content = '', $conf = array()) {
2481 return $this->stdWrap($content, $conf['stdWrap.']);
2482 }
2483
2484 /**
2485 * stdWrap process hook
2486 * can be used by extensions authors to modify the behaviour of stdWrap functions to their needs
2487 * this hook executes functions directly after the recursive stdWrap function call but still before the content gets modified
2488 *
2489 * @param string $content Input value undergoing processing in these functions.
2490 * @param array $conf All stdWrap properties, not just the ones for a particular function.
2491 * @return string The processed input value
2492 */
2493 public function stdWrap_stdWrapProcess($content = '', $conf = array()) {
2494 foreach ($this->stdWrapHookObjects as $hookObject) {
2495 $content = $hookObject->stdWrapProcess($content, $conf, $this);
2496 }
2497 return $content;
2498 }
2499
2500 /**
2501 * required
2502 * Will immediately stop rendering and return an empty value
2503 * when there is no content at this point
2504 *
2505 * @param string $content Input value undergoing processing in this function.
2506 * @param array $conf stdWrap properties for required.
2507 * @return string The processed input value
2508 */
2509 public function stdWrap_required($content = '', $conf = array()) {
2510 if ((string) $content === '') {
2511 $content = '';
2512 $this->stopRendering[$this->stdWrapRecursionLevel] = TRUE;
2513 }
2514 return $content;
2515 }
2516
2517 /**
2518 * if
2519 * Will immediately stop rendering and return an empty value
2520 * when the result of the checks returns FALSE
2521 *
2522 * @param string $content Input value undergoing processing in this function.
2523 * @param array $conf stdWrap properties for if.
2524 * @return string The processed input value
2525 */
2526 public function stdWrap_if($content = '', $conf = array()) {
2527 if (empty($conf['if.']) || $this->checkIf($conf['if.'])) {
2528 return $content;
2529 }
2530 $this->stopRendering[$this->stdWrapRecursionLevel] = TRUE;
2531 return '';
2532 }
2533
2534 /**
2535 * fieldRequired
2536 * Will immediately stop rendering and return an empty value
2537 * when there is no content in the field given by fieldRequired
2538 *
2539 * @param string $content Input value undergoing processing in this function.
2540 * @param array $conf stdWrap properties for fieldRequired.
2541 * @return string The processed input value
2542 */
2543 public function stdWrap_fieldRequired($content = '', $conf = array()) {
2544 if (!trim($this->data[$conf['fieldRequired']])) {
2545 $content = '';
2546 $this->stopRendering[$this->stdWrapRecursionLevel] = TRUE;
2547 }
2548 return $content;
2549 }
2550
2551 /**
2552 * csConv
2553 * Will convert the current chracter set of the content to the one given in csConv
2554 *
2555 * @param string $content Input value undergoing processing in this function.
2556 * @param array $conf stdWrap properties for csConv.
2557 * @return string The processed input value
2558 */
2559 public function stdWrap_csConv($content = '', $conf = array()) {
2560 return $GLOBALS['TSFE']->csConv($content, $conf['csConv']);
2561 }
2562
2563 /**
2564 * parseFunc
2565 * Will parse the content based on functions given as stdWrap properties
2566 * Heavily used together with RTE based content
2567 *
2568 * @param string $content Input value undergoing processing in this function.
2569 * @param array $conf stdWrap properties for parseFunc.
2570 * @return string The processed input value
2571 */
2572 public function stdWrap_parseFunc($content = '', $conf = array()) {
2573 return $this->parseFunc($content, $conf['parseFunc.'], $conf['parseFunc']);
2574 }
2575
2576 /**
2577 * HTMLparser
2578 * Will parse HTML content based on functions given as stdWrap properties
2579 * Heavily used together with RTE based content
2580 *
2581 * @param string $content Input value undergoing processing in this function.
2582 * @param array $conf stdWrap properties for HTMLparser.
2583 * @return string The processed input value
2584 */
2585 public function stdWrap_HTMLparser($content = '', $conf = array()) {
2586 if (is_array($conf['HTMLparser.'])) {
2587 $content = $this->HTMLparser_TSbridge($content, $conf['HTMLparser.']);
2588 }
2589 return $content;
2590 }
2591
2592 /**
2593 * split
2594 * Will split the content by a given token and treat the results separately
2595 * Automatically fills 'current' with a single result
2596 *
2597 * @param string $content Input value undergoing processing in this function.
2598 * @param array $conf stdWrap properties for split.
2599 * @return string The processed input value
2600 */
2601 public function stdWrap_split($content = '', $conf = array()) {
2602 return $this->splitObj($content, $conf['split.']);
2603 }
2604
2605 /**
2606 * replacement
2607 * Will execute replacements on the content (optionally with preg-regex)
2608 *
2609 * @param string $content Input value undergoing processing in this function.
2610 * @param array $conf stdWrap properties for replacement.
2611 * @return string The processed input value
2612 */
2613 public function stdWrap_replacement($content = '', $conf = array()) {
2614 return $this->replacement($content, $conf['replacement.']);
2615 }
2616
2617 /**
2618 * prioriCalc
2619 * Will use the content as a mathematical term and calculate the result
2620 * Can be set to 1 to just get a calculated value or 'intval' to get the integer of the result
2621 *
2622 * @param string $content Input value undergoing processing in this function.
2623 * @param array $conf stdWrap properties for prioriCalc.
2624 * @return string The processed input value
2625 */
2626 public function stdWrap_prioriCalc($content = '', $conf = array()) {
2627 $content = \TYPO3\CMS\Core\Utility\MathUtility::calculateWithParentheses($content);
2628 if ($conf['prioriCalc'] == 'intval') {
2629 $content = (int)$content;
2630 }
2631 return $content;
2632 }
2633
2634 /**
2635 * char
2636 * Will return a character based on its position within the current character set
2637 *
2638 * @param string $content Input value undergoing processing in this function.
2639 * @param array $conf stdWrap properties for char.
2640 * @return string The processed input value
2641 */
2642 public function stdWrap_char($content = '', $conf = array()) {
2643 return chr((int)$conf['char']);
2644 }
2645
2646 /**
2647 * intval
2648 * Will return an integer value of the current content
2649 *
2650 * @param string $content Input value undergoing processing in this function.
2651 * @param array $conf stdWrap properties for intval.
2652 * @return string The processed input value
2653 */
2654 public function stdWrap_intval($content = '', $conf = array()) {
2655 return (int)$content;
2656 }
2657
2658 /**
2659 * Will return a hashed value of the current content
2660 *
2661 * @param string $content Input value undergoing processing in this function.
2662 * @param array $conf stdWrap properties for hash.
2663 * @return string The processed input value
2664 * @link http://php.net/manual/de/function.hash-algos.php for a list of supported hash algorithms
2665 */
2666 public function stdWrap_hash($content = '', array $conf = array()) {
2667 $algorithm = isset($conf['hash.']) ? $this->stdWrap($conf['hash'], $conf['hash.']) : $conf['hash'];
2668 if (function_exists('hash') && in_array($algorithm, hash_algos())) {
2669 $content = hash($algorithm, $content);
2670 } else {
2671 // Non-existing hashing algorithm
2672 $content = '';
2673 }
2674 return $content;
2675 }
2676
2677 /**
2678 * stdWrap_round will return a rounded number with ceil(), floor() or round(), defaults to round()
2679 * Only the english number format is supported . (dot) as decimal point
2680 *
2681 * @param string $content Input value undergoing processing in this function.
2682 * @param array $conf stdWrap properties for round.
2683 * @return string The processed input value
2684 */
2685 public function stdWrap_round($content = '', $conf = array()) {
2686 return $this->round($content, $conf['round.']);
2687 }
2688
2689 /**
2690 * numberFormat
2691 * Will return a formatted number based on configuration given as stdWrap properties
2692 *
2693 * @param string $content Input value undergoing processing in this function.
2694 * @param array $conf stdWrap properties for numberFormat.
2695 * @return string The processed input value
2696 */
2697 public function stdWrap_numberFormat($content = '', $conf = array()) {
2698 return $this->numberFormat($content, $conf['numberFormat.']);
2699 }
2700
2701 /**
2702 * expandList
2703 * Will return a formatted number based on configuration given as stdWrap properties
2704 *
2705 * @param string $content Input value undergoing processing in this function.
2706 * @param array $conf stdWrap properties for expandList.
2707 * @return string The processed input value
2708 */
2709 public function stdWrap_expandList($content = '', $conf = array()) {
2710 return GeneralUtility::expandList($content);
2711 }
2712
2713 /**
2714 * date
2715 * Will return a formatted date based on configuration given according to PHP date/gmdate properties
2716 * Will return gmdate when the property GMT returns TRUE
2717 *
2718 * @param string $content Input value undergoing processing in this function.
2719 * @param array $conf stdWrap properties for date.
2720 * @return string The processed input value
2721 */
2722 public function stdWrap_date($content = '', $conf = array()) {
2723 // Check for zero length string to mimic default case of date/gmdate.
2724 $content = $content == '' ? $GLOBALS['EXEC_TIME'] : (int)$content;
2725 $content = $conf['date.']['GMT'] ? gmdate($conf['date'], $content) : date($conf['date'], $content);
2726 return $content;
2727 }
2728
2729 /**
2730 * strftime
2731 * Will return a formatted date based on configuration given according to PHP strftime/gmstrftime properties
2732 * Will return gmstrftime when the property GMT returns TRUE
2733 *
2734 * @param string $content Input value undergoing processing in this function.
2735 * @param array $conf stdWrap properties for strftime.
2736 * @return string The processed input value
2737 */
2738 public function stdWrap_strftime($content = '', $conf = array()) {
2739 // Check for zero length string to mimic default case of strtime/gmstrftime
2740 $content = $content == '' ? $GLOBALS['EXEC_TIME'] : (int)$content;
2741 $content = $conf['strftime.']['GMT'] ? gmstrftime($conf['strftime'], $content) : strftime($conf['strftime'], $content);
2742 $tmp_charset = $conf['strftime.']['charset'] ? $conf['strftime.']['charset'] : $GLOBALS['TSFE']->localeCharset;
2743 if ($tmp_charset) {
2744 $content = $GLOBALS['TSFE']->csConv($content, $tmp_charset);
2745 }
2746 return $content;
2747 }
2748
2749 /**
2750 * age
2751 * Will return the age of a given timestamp based on configuration given by stdWrap properties
2752 *
2753 * @param string $content Input value undergoing processing in this function.
2754 * @param array $conf stdWrap properties for age.
2755 * @return string The processed input value
2756 */
2757 public function stdWrap_age($content = '', $conf = array()) {
2758 return $this->calcAge($GLOBALS['EXEC_TIME'] - $content, $conf['age']);
2759 }
2760
2761 /**
2762 * case
2763 * Will transform the content to be upper or lower case only
2764 * Leaves HTML tags untouched
2765 *
2766 * @param string $content Input value undergoing processing in this function.
2767 * @param array $conf stdWrap properties for case.
2768 * @return string The processed input value
2769 */
2770 public function stdWrap_case($content = '', $conf = array()) {
2771 return $this->HTMLcaseshift($content, $conf['case']);
2772 }
2773
2774 /**
2775 * bytes
2776 * Will return the size of a given number in Bytes *
2777 *
2778 * @param string $content Input value undergoing processing in this function.
2779 * @param array $conf stdWrap properties for bytes.
2780 * @return string The processed input value
2781 */
2782 public function stdWrap_bytes($content = '', $conf = array()) {
2783 return GeneralUtility::formatSize($content, $conf['bytes.']['labels']);
2784 }
2785
2786 /**
2787 * substring
2788 * Will return a substring based on position information given by stdWrap properties
2789 *
2790 * @param string $content Input value undergoing processing in this function.
2791 * @param array $conf stdWrap properties for substring.
2792 * @return string The processed input value
2793 */
2794 public function stdWrap_substring($content = '', $conf = array()) {
2795 return $this->substring($content, $conf['substring']);
2796 }
2797
2798 /**
2799 * removeBadHTML
2800 * Removes HTML tags based on stdWrap properties
2801 *
2802 * @param string $content Input value undergoing processing in this function.
2803 * @param array $conf stdWrap properties for removeBadHTML.
2804 * @return string The processed input value
2805 */
2806 public function stdWrap_removeBadHTML($content = '', $conf = array()) {
2807 return $this->removeBadHTML($content, $conf['removeBadHTML.']);
2808 }
2809
2810 /**
2811 * cropHTML
2812 * Crops content to a given size while leaving HTML tags untouched
2813 *
2814 * @param string $content Input value undergoing processing in this function.
2815 * @param array $conf stdWrap properties for cropHTML.
2816 * @return string The processed input value
2817 */
2818 public function stdWrap_cropHTML($content = '', $conf = array()) {
2819 return $this->cropHTML($content, $conf['cropHTML']);
2820 }
2821
2822 /**
2823 * stripHtml
2824 * Copmletely removes HTML tags from content
2825 *
2826 * @param string $content Input value undergoing processing in this function.
2827 * @param array $conf stdWrap properties for stripHtml.
2828 * @return string The processed input value
2829 */
2830 public function stdWrap_stripHtml($content = '', $conf = array()) {
2831 return strip_tags($content);
2832 }
2833
2834 /**
2835 * crop
2836 * Crops content to a given size without caring about HTML tags
2837 *
2838 * @param string $content Input value undergoing processing in this function.
2839 * @param array $conf stdWrap properties for crop.
2840 * @return string The processed input value
2841 */
2842 public function stdWrap_crop($content = '', $conf = array()) {
2843 return $this->crop($content, $conf['crop']);
2844 }
2845
2846 /**
2847 * rawUrlEncode
2848 * Encodes content to be used within URLs
2849 *
2850 * @param string $content Input value undergoing processing in this function.
2851 * @param array $conf stdWrap properties for rawUrlEncode.
2852 * @return string The processed input value
2853 */
2854 public function stdWrap_rawUrlEncode($content = '', $conf = array()) {
2855 return rawurlencode($content);
2856 }
2857
2858 /**
2859 * htmlSpecialChars
2860 * Transforms HTML tags to readable text by replacing special characters with their HTML entity
2861 * When preserveEntities returns TRUE, existing entities will be left untouched
2862 *
2863 * @param string $content Input value undergoing processing in this function.
2864 * @param array $conf stdWrap properties for htmlSpecalChars.
2865 * @return string The processed input value
2866 */
2867 public function stdWrap_htmlSpecialChars($content = '', $conf = array()) {
2868 if (!empty($conf['htmlSpecialChars.']['preserveEntities'])) {
2869 $content = htmlspecialchars($content, ENT_COMPAT, 'UTF-8', FALSE);
2870 } else {
2871 $content = htmlspecialchars($content);
2872 }
2873 return $content;
2874 }
2875
2876 /**
2877 * encodeForJavaScriptValue
2878 * Escapes content to be used inside JavaScript strings. No quotes are added around the value
2879 * as this can easily be done in TypoScript
2880 *
2881 * @param string $content Input value undergoing processing in this function
2882 * @param array $conf stdWrap properties for encodeForJavaScriptValue
2883 * @return string The processed input value
2884 */
2885 public function stdWrap_encodeForJavaScriptValue($content = '', $conf = array()) {
2886 return GeneralUtility::quoteJSvalue($content);