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