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