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