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