Only changes to function indexes, comments and stripping of trailing whitespace in...
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / tslib / class.tslib_pibase.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2004 Kasper Skaarhoj (kasper@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 * This script contains the parent class, 'pibase', providing an API with the most basic methods for frontend plugins
29 *
30 * $Id$
31 * Revised for TYPO3 3.6 June/2003 by Kasper Skaarhoj
32 * XHTML compliant
33 *
34 * @author Kasper Skaarhoj <kasper@typo3.com>
35 */
36 /**
37 * [CLASS/FUNCTION INDEX of SCRIPT]
38 *
39 *
40 *
41 * 132: class tslib_pibase
42 *
43 * SECTION: Init functions
44 * 211: function tslib_pibase()
45 * 225: function pi_setPiVarDefaults()
46 *
47 * SECTION: Link functions
48 * 264: function pi_getPageLink($id,$target='',$urlParameters=array())
49 * 280: function pi_linkToPage($str,$id,$target='',$urlParameters=array())
50 * 295: function pi_linkTP($str,$urlParameters=array(),$cache=0,$altPageId=0)
51 * 318: function pi_linkTP_keepPIvars($str,$overrulePIvars=array(),$cache=0,$clearAnyway=0,$altPageId=0)
52 * 342: function pi_linkTP_keepPIvars_url($overrulePIvars=array(),$cache=0,$clearAnyway=0,$altPageId=0)
53 * 360: function pi_list_linkSingle($str,$uid,$cache=FALSE,$mergeArr=array(),$urlOnly=FALSE,$altPageId=0)
54 * 388: function pi_openAtagHrefInJSwindow($str,$winName='',$winParams='width=670,height=500,status=0,menubar=0,scrollbars=1,resizable=1')
55 *
56 * SECTION: Functions for listing, browsing, searching etc.
57 * 428: function pi_list_browseresults($showResultCount=1,$tableParams='')
58 * 500: function pi_list_searchBox($tableParams='')
59 * 528: function pi_list_modeSelector($items=array(),$tableParams='')
60 * 566: function pi_list_makelist($res,$tableParams='')
61 * 601: function pi_list_row($c)
62 * 613: function pi_list_header()
63 *
64 * SECTION: Stylesheet, CSS
65 * 644: function pi_getClassName($class)
66 * 656: function pi_classParam($class)
67 * 670: function pi_setClassStyle($class,$data,$selector='')
68 * 681: function pi_wrapInBaseClass($str)
69 *
70 * SECTION: Frontend editing: Edit panel, edit icons
71 * 730: function pi_getEditPanel($row='',$tablename='',$label='',$conf=Array())
72 * 772: function pi_getEditIcon($content,$fields,$title='',$row='',$tablename='',$oConf=array())
73 *
74 * SECTION: Localization, locallang functions
75 * 819: function pi_getLL($key,$alt='',$hsc=FALSE)
76 * 840: function pi_loadLL()
77 *
78 * SECTION: Database, queries
79 * 905: function pi_list_query($table,$count=0,$addWhere='',$mm_cat='',$groupBy='',$orderBy='',$query='',$returnQueryArray=FALSE)
80 * 997: function pi_exec_query($table,$count=0,$addWhere='',$mm_cat='',$groupBy='',$orderBy='',$query='')
81 * 1012: function pi_getRecord($table,$uid,$checkPage=0)
82 * 1023: function pi_getPidList($pid_list,$recursive=0)
83 * 1048: function pi_prependFieldsWithTable($table,$fieldList)
84 * 1068: function pi_getCategoryTableContents($table,$pid,$whereClause='',$groupBy='',$orderBy='',$limit='')
85 *
86 * SECTION: Various
87 * 1112: function pi_isOnlyFields($fList,$lowerThan=-1)
88 * 1132: function pi_autoCache($inArray)
89 * 1163: function pi_RTEcssText($str)
90 *
91 * SECTION: FlexForms related functions
92 * 1184: function pi_initPIflexForm()
93 * 1202: function pi_getFFvalue($T3FlexForm_array,$fieldName,$sheet='sDEF',$lang='lDEF',$value='vDEF')
94 * 1219: function pi_getFFvalueFromSheetArray($sheetArray,$fieldNameArr,$value)
95 *
96 * TOTAL FUNCTIONS: 35
97 * (This index is automatically created/updated by the extension "extdeveval")
98 *
99 */
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122 /**
123 * Base class for frontend plugins
124 * Most modern frontend plugins are extension classes of this one.
125 * This class contains functions which assists these plugins in creating lists, searching, displaying menus, page-browsing (next/previous/1/2/3) and handling links.
126 * Functions are all prefixed "pi_" which is reserved for this class. Those functions can of course be overridden in the extension classes (that is the point...)
127 *
128 * @author Kasper Skaarhoj <kasper@typo3.com>
129 * @package TYPO3
130 * @subpackage tslib
131 */
132 class tslib_pibase {
133
134 // Reserved variables:
135 var $cObj; // The backReference to the mother cObj object set at call time
136 var $prefixId; // Should be same as classname of the plugin, used for CSS classes, variables
137 var $scriptRelPath; // Path to the plugin class script relative to extension directory, eg. 'pi1/class.tx_newfaq_pi1.php'
138 var $extKey; // Extension key.
139 var $piVars = Array ( // This is the incomming array by name $this->prefixId merged between POST and GET, POST taking precedence. Eg. if the class name is 'tx_myext' then the content of this array will be whatever comes into &tx_myext[...]=...
140 'pointer' => '', // Used as a pointer for lists
141 'mode' => '', // List mode
142 'sword' => '', // Search word
143 'sort' => '', // [Sorting column]:[ASC=0/DESC=1]
144 );
145 var $internal = Array( // Used internally for general storage of values between methods
146 'res_count' => 0, // Total query count
147 'results_at_a_time' => 20, // pi_list_browseresults(): Show number of results at a time
148 'maxPages' => 10, // pi_list_browseresults(): Max number of 'Page 1 - Page 2 - ...' in the list browser
149 'currentRow' => Array(), // Current result row
150 'currentTable' => '', // Current table
151 );
152
153 var $LOCAL_LANG = Array(); // Local Language content
154 var $LOCAL_LANG_loaded = 0; // Flag that tells if the locallang file has been fetch (or tried to be fetched) already.
155 var $LLkey='default'; // Pointer to the language to use.
156 var $LLtestPrefix=''; // You can set this during development to some value that makes it easy for you to spot all labels that ARe delivered by the getLL function.
157 var $LLtestPrefixAlt=''; // Save as LLtestPrefix, but additional prefix for the alternative value in getLL() function calls
158
159 var $pi_isOnlyFields = 'mode,pointer';
160 var $pi_alwaysPrev = 0;
161 var $pi_lowerThan = 5;
162 var $pi_moreParams='';
163 var $pi_listFields='*';
164
165 var $pi_autoCacheFields=array();
166 var $pi_autoCacheEn=0;
167
168 var $pi_USER_INT_obj = 0; // If set, then links are 1) not using cHash and 2) allowing pages to be cached.
169
170 /**
171 * Should normally be set in the main function with the TypoScript content passed to the method.
172 *
173 * $conf[LOCAL_LANG][_key_] is reserved for Local Language overrides.
174 * $conf[userFunc] / $conf[includeLibs] reserved for setting up the USER / USER_INT object. See TSref
175 */
176 var $conf = Array();
177
178 // internal, don't mess with...
179 var $pi_EPtemp_cObj;
180 var $pi_tmpPageId=0;
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198 /***************************
199 *
200 * Init functions
201 *
202 **************************/
203
204 /**
205 * Class Constructor (true constructor)
206 * Initializes $this->piVars if $this->prefixId is set to any value
207 * Will also set $this->LLkey based on the config.language setting.
208 *
209 * @return void
210 */
211 function tslib_pibase() {
212 if ($this->prefixId) {
213 $this->piVars = t3lib_div::GParrayMerged($this->prefixId);
214 }
215 if ($GLOBALS['TSFE']->config['config']['language']) {
216 $this->LLkey = $GLOBALS['TSFE']->config['config']['language'];
217 }
218 }
219
220 /**
221 * If internal TypoScript property "_DEFAULT_PI_VARS." is set then it will merge the current $this->piVars array onto these default values.
222 *
223 * @return void
224 */
225 function pi_setPiVarDefaults() {
226 if (is_array($this->conf['_DEFAULT_PI_VARS.'])) {
227 $this->piVars = t3lib_div::array_merge_recursive_overrule($this->conf['_DEFAULT_PI_VARS.'],is_array($this->piVars)?$this->piVars:array());
228 }
229 }
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245 /***************************
246 *
247 * Link functions
248 *
249 **************************/
250
251 /**
252 * Get URL to some page.
253 * Returns the URL to page $id with $target and an array of additional url-parameters, $urlParameters
254 * Simple example: $this->pi_getPageLink(123) to get the URL for page-id 123.
255 *
256 * The function basically calls $this->cObj->getTypoLink_URL()
257 *
258 * @param integer Page id
259 * @param string Target value to use. Affects the &type-value of the URL, defaults to current.
260 * @param array Additional URL parameters to set (key/value pairs)
261 * @return string The resulting URL
262 * @see pi_linkToPage()
263 */
264 function pi_getPageLink($id,$target='',$urlParameters=array()) {
265 return $this->cObj->getTypoLink_URL($id,$urlParameters,$target); // ?$target:$GLOBALS['TSFE']->sPre
266 }
267
268 /**
269 * Link a string to some page.
270 * Like pi_getPageLink() but takes a string as first parameter which will in turn be wrapped with the URL including target attribute
271 * Simple example: $this->pi_linkToPage('My link', 123) to get something like <a href="index.php?id=123&type=1">My link</a> (or <a href="123.1.html">My link</a> if simulateStaticDocuments is set)
272 *
273 * @param string The content string to wrap in <a> tags
274 * @param integer Page id
275 * @param string Target value to use. Affects the &type-value of the URL, defaults to current.
276 * @param array Additional URL parameters to set (key/value pairs)
277 * @return string The input string wrapped in <a> tags with the URL and target set.
278 * @see pi_getPageLink(), tslib_cObj::getTypoLink()
279 */
280 function pi_linkToPage($str,$id,$target='',$urlParameters=array()) {
281 return $this->cObj->getTypoLink($str,$id,$urlParameters,$target); // ?$target:$GLOBALS['TSFE']->sPre
282 }
283
284 /**
285 * Link string to the current page.
286 * Returns the $str wrapped in <a>-tags with a link to the CURRENT page, but with $urlParameters set as extra parameters for the page.
287 *
288 * @param string The content string to wrap in <a> tags
289 * @param array Array with URL parameters as key/value pairs. They will be "imploded" and added to the list of parameters defined in the plugins TypoScript property "parent.addParams" plus $this->pi_moreParams.
290 * @param boolean If $cache is set (0/1), the page is asked to be cached by a &cHash value (unless the current plugin using this class is a USER_INT). Otherwise the no_cache-parameter will be a part of the link.
291 * @param integer Alternative page ID for the link. (By default this function links to the SAME page!)
292 * @return string The input string wrapped in <a> tags
293 * @see pi_linkTP_keepPIvars(), tslib_cObj::typoLink()
294 */
295 function pi_linkTP($str,$urlParameters=array(),$cache=0,$altPageId=0) {
296 $conf=array();
297 $conf['useCacheHash'] = $this->pi_USER_INT_obj ? 0 : $cache;
298 $conf['no_cache'] = $this->pi_USER_INT_obj ? 0 : !$cache;
299 $conf['parameter'] = $altPageId ? $altPageId : ($this->pi_tmpPageId ? $this->pi_tmpPageId : $GLOBALS['TSFE']->id);
300 $conf['additionalParams'] = $this->conf['parent.']['addParams'].t3lib_div::implodeArrayForUrl('',$urlParameters,'',1).$this->pi_moreParams;
301
302 return $this->cObj->typoLink($str, $conf);
303 }
304
305 /**
306 * Link a string to the current page while keeping currently set values in piVars.
307 * Like pi_linkTP, but $urlParameters is by default set to $this->piVars with $overrulePIvars overlaid.
308 * This means any current entries from this->piVars are passed on (except the key "DATA" which will be unset before!) and entries in $overrulePIvars will OVERRULE the current in the link.
309 *
310 * @param string The content string to wrap in <a> tags
311 * @param array Array of values to override in the current piVars. Contrary to pi_linkTP the keys in this array must correspond to the real piVars array and therefore NOT be prefixed with the $this->prefixId string. Further, if a value is a blank string it means the piVar key will not be a part of the link (unset)
312 * @param boolean If $cache is set, the page is asked to be cached by a &cHash value (unless the current plugin using this class is a USER_INT). Otherwise the no_cache-parameter will be a part of the link.
313 * @param boolean If set, then the current values of piVars will NOT be preserved anyways... Practical if you want an easy way to set piVars without having to worry about the prefix, "tx_xxxxx[]"
314 * @param integer Alternative page ID for the link. (By default this function links to the SAME page!)
315 * @return string The input string wrapped in <a> tags
316 * @see pi_linkTP()
317 */
318 function pi_linkTP_keepPIvars($str,$overrulePIvars=array(),$cache=0,$clearAnyway=0,$altPageId=0) {
319 if (is_array($this->piVars) && is_array($overrulePIvars) && !$clearAnyway) {
320 $piVars = $this->piVars;
321 unset($piVars['DATA']);
322 $overrulePIvars = t3lib_div::array_merge_recursive_overrule($piVars,$overrulePIvars);
323 if ($this->pi_autoCacheEn) {
324 $cache = $this->pi_autoCache($overrulePIvars);
325 }
326 }
327 $res = $this->pi_linkTP($str,Array($this->prefixId=>$overrulePIvars),$cache,$altPageId);
328 return $res;
329 }
330
331 /**
332 * Get URL to the current page while keeping currently set values in piVars.
333 * Same as pi_linkTP_keepPIvars but returns only the URL from the link.
334 *
335 * @param array See pi_linkTP_keepPIvars
336 * @param boolean See pi_linkTP_keepPIvars
337 * @param boolean See pi_linkTP_keepPIvars
338 * @param integer See pi_linkTP_keepPIvars
339 * @return string The URL ($this->cObj->lastTypoLinkUrl)
340 * @see pi_linkTP_keepPIvars()
341 */
342 function pi_linkTP_keepPIvars_url($overrulePIvars=array(),$cache=0,$clearAnyway=0,$altPageId=0) {
343 $this->pi_linkTP_keepPIvars('|',$overrulePIvars,$cache,$clearAnyway,$altPageId);
344 return $this->cObj->lastTypoLinkUrl;
345 }
346
347 /**
348 * Wraps the $str in a link to a single display of the record (using piVars[showUid])
349 * Uses pi_linkTP for the linking
350 *
351 * @param string The content string to wrap in <a> tags
352 * @param integer UID of the record for which to display details (basically this will become the value of [showUid]
353 * @param boolean See pi_linkTP_keepPIvars
354 * @param array Array of values to override in the current piVars. Same as $overrulePIvars in pi_linkTP_keepPIvars
355 * @param boolean If true, only the URL is returned, not a full link
356 * @param integer Alternative page ID for the link. (By default this function links to the SAME page!)
357 * @return string The input string wrapped in <a> tags
358 * @see pi_linkTP(), pi_linkTP_keepPIvars()
359 */
360 function pi_list_linkSingle($str,$uid,$cache=FALSE,$mergeArr=array(),$urlOnly=FALSE,$altPageId=0) {
361 if ($this->prefixId) {
362 if ($cache) {
363 $overrulePIvars=$uid?array('showUid'=>$uid):Array();
364 $overrulePIvars=array_merge($overrulePIvars,$mergeArr);
365 $str = $this->pi_linkTP($str,Array($this->prefixId=>$overrulePIvars),$cache,$altPageId);
366 } else {
367 $overrulePIvars=array('showUid'=>$uid?$uid:'');
368 $overrulePIvars=array_merge($overrulePIvars,$mergeArr);
369 $str = $this->pi_linkTP_keepPIvars($str,$overrulePIvars,$cache,0,$altPageId);
370 }
371
372 // If urlOnly flag, return only URL as it has recently be generated.
373 if ($urlOnly) {
374 $str = $this->cObj->lastTypoLinkUrl;
375 }
376 }
377 return $str;
378 }
379
380 /**
381 * Will change the href value from <a> in the input string and turn it into an onclick event that will open a new window with the URL
382 *
383 * @param string The string to process. This should be a string already wrapped/including a <a> tag which will be modified to contain an onclick handler. Only the attributes "href" and "onclick" will be left.
384 * @param string Window name for the pop-up window
385 * @param string Window parameters, see the default list for inspiration
386 * @return string The processed input string, modified IF a <a> tag was found
387 */
388 function pi_openAtagHrefInJSwindow($str,$winName='',$winParams='width=670,height=500,status=0,menubar=0,scrollbars=1,resizable=1') {
389 if (eregi('(.*)(<a[^>]*>)(.*)',$str,$match)) {
390 $aTagContent = t3lib_div::get_tag_attributes($match[2]);
391 $match[2]='<a href="#" onclick="'.
392 htmlspecialchars('vHWin=window.open(\''.$aTagContent['href'].'\',\''.($winName?$winName:md5($aTagContent['href'])).'\',\''.$winParams.'\');vHWin.focus();return false;').
393 '">';
394 $str=$match[1].$match[2].$match[3];
395 }
396 return $str;
397 }
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413 /***************************
414 *
415 * Functions for listing, browsing, searching etc.
416 *
417 **************************/
418
419 /**
420 * Returns a results browser. This means a bar of page numbers plus a "previous" and "next" link. For each entry in the bar the piVars "pointer" will be pointing to the "result page" to show.
421 * Using $this->piVars['pointer'] as pointer to the page to display
422 * Using $this->internal['res_count'], $this->internal['results_at_a_time'] and $this->internal['maxPages'] for count number, how many results to show and the max number of pages to include in the browse bar.
423 *
424 * @param boolean If set (default) the text "Displaying results..." will be show, otherwise not.
425 * @param string Attributes for the table tag which is wrapped around the table cells containing the browse links
426 * @return string Output HTML, wrapped in <div>-tags with a class attribute
427 */
428 function pi_list_browseresults($showResultCount=1,$tableParams='') {
429
430 // Initializing variables:
431 $pointer=$this->piVars['pointer'];
432 $count=$this->internal['res_count'];
433 $results_at_a_time = t3lib_div::intInRange($this->internal['results_at_a_time'],1,1000);
434 $maxPages = t3lib_div::intInRange($this->internal['maxPages'],1,100);
435 $max = t3lib_div::intInRange(ceil($count/$results_at_a_time),1,$maxPages);
436 $pointer=intval($pointer);
437 $links=array();
438
439 // Make browse-table/links:
440 if ($this->pi_alwaysPrev>=0) {
441 if ($pointer>0) {
442 $links[]='
443 <td nowrap="nowrap"><p>'.$this->pi_linkTP_keepPIvars($this->pi_getLL('pi_list_browseresults_prev','< Previous',TRUE),array('pointer'=>($pointer-1?$pointer-1:'')),0).'</p></td>';
444 } elseif ($this->pi_alwaysPrev) {
445 $links[]='
446 <td nowrap="nowrap"><p>'.$this->pi_getLL('pi_list_browseresults_prev','< Previous',TRUE).'</p></td>';
447 }
448 }
449 for($a=0;$a<$max;$a++) {
450 $links[]='
451 <td'.($pointer==$a?$this->pi_classParam('browsebox-SCell'):'').' nowrap="nowrap"><p>'.
452 $this->pi_linkTP_keepPIvars(trim($this->pi_getLL('pi_list_browseresults_page','Page',TRUE).' '.($a+1)),array('pointer'=>($a?$a:'')),$this->pi_isOnlyFields($this->pi_isOnlyFields)).
453 '</p></td>';
454 }
455 if ($pointer<ceil($count/$results_at_a_time)-1) {
456 $links[]='
457 <td nowrap="nowrap"><p>'.
458 $this->pi_linkTP_keepPIvars($this->pi_getLL('pi_list_browseresults_next','Next >',TRUE),array('pointer'=>$pointer+1)).
459 '</p></td>';
460 }
461
462 $pR1 = $pointer*$results_at_a_time+1;
463 $pR2 = $pointer*$results_at_a_time+$results_at_a_time;
464 $sTables = '
465
466 <!--
467 List browsing box:
468 -->
469 <div'.$this->pi_classParam('browsebox').'>'.
470 ($showResultCount ? '
471 <p>'.
472 ($this->internal['res_count'] ?
473 sprintf(
474 str_replace('###SPAN_BEGIN###','<span'.$this->pi_classParam('browsebox-strong').'>',$this->pi_getLL('pi_list_browseresults_displays','Displaying results ###SPAN_BEGIN###%s to %s</span> out of ###SPAN_BEGIN###%s</span>')),
475 $this->internal['res_count'] > 0 ? $pR1 : 0,
476 min(array($this->internal['res_count'],$pR2)),
477 $this->internal['res_count']
478 ) :
479 $this->pi_getLL('pi_list_browseresults_noResults','Sorry, no items were found.')).'</p>':''
480 ).
481 '
482
483 <'.trim('table '.$tableParams).'>
484 <tr>
485 '.implode('',$links).'
486 </tr>
487 </table>
488 </div>';
489
490 return $sTables;
491 }
492
493 /**
494 * Returns a Search box, sending search words to piVars "sword" and setting the "no_cache" parameter as well in the form.
495 * Submits the search request to the current REQUEST_URI
496 *
497 * @param string Attributes for the table tag which is wrapped around the table cells containing the search box
498 * @return string Output HTML, wrapped in <div>-tags with a class attribute
499 */
500 function pi_list_searchBox($tableParams='') {
501 // Search box design:
502 $sTables = '
503
504 <!--
505 List search box:
506 -->
507 <div'.$this->pi_classParam('searchbox').'>
508 <form action="'.htmlspecialchars(t3lib_div::getIndpEnv('REQUEST_URI')).'" method="post" style="margin: 0 0 0 0;">
509 <'.trim('table '.$tableParams).'>
510 <tr>
511 <td><input type="text" name="'.$this->prefixId.'[sword]" value="'.htmlspecialchars($this->piVars['sword']).'"'.$this->pi_classParam('searchbox-sword').' /></td>
512 <td><input type="submit" value="'.$this->pi_getLL('pi_list_searchBox_search','Search',TRUE).'"'.$this->pi_classParam('searchbox-button').' /><input type="hidden" name="no_cache" value="1" /></td>
513 </tr>
514 </table>
515 </form>
516 </div>';
517
518 return $sTables;
519 }
520
521 /**
522 * Returns a mode selector; a little menu in a table normally put in the top of the page/list.
523 *
524 * @param array Key/Value pairs for the menu; keys are the piVars[mode] values and the "values" are the labels for them.
525 * @param string Attributes for the table tag which is wrapped around the table cells containing the menu
526 * @return string Output HTML, wrapped in <div>-tags with a class attribute
527 */
528 function pi_list_modeSelector($items=array(),$tableParams='') {
529 $cells=array();
530 reset($items);
531 while(list($k,$v)=each($items)) {
532 $cells[]='
533 <td'.($this->piVars['mode']==$k?$this->pi_classParam('modeSelector-SCell'):'').'><p>'.
534 $this->pi_linkTP_keepPIvars(htmlspecialchars($v),array('mode'=>$k),$this->pi_isOnlyFields($this->pi_isOnlyFields)).
535 '</p></td>';
536 }
537
538 $sTables = '
539
540 <!--
541 Mode selector (menu for list):
542 -->
543 <div'.$this->pi_classParam('modeSelector').'>
544 <'.trim('table '.$tableParams).'>
545 <tr>
546 '.implode('',$cells).'
547 </tr>
548 </table>
549 </div>';
550
551 return $sTables;
552 }
553
554 /**
555 * Returns the list of items based on the input SQL result pointer
556 * For each result row the internal var, $this->internal['currentRow'], is set with the row returned.
557 * $this->pi_list_header() makes the header row for the list
558 * $this->pi_list_row() is used for rendering each row
559 * Notice that these two functions are typically ALWAYS defined in the extension class of the plugin since they are directly concerned with the specific layout for that plugins purpose.
560 *
561 * @param pointer Result pointer to a SQL result which can be traversed.
562 * @param string Attributes for the table tag which is wrapped around the table rows containing the list
563 * @return string Output HTML, wrapped in <div>-tags with a class attribute
564 * @see pi_list_row(), pi_list_header()
565 */
566 function pi_list_makelist($res,$tableParams='') {
567 // Make list table header:
568 $tRows=array();
569 $this->internal['currentRow']='';
570 $tRows[] = $this->pi_list_header();
571
572 // Make list table rows
573 $c=0;
574 while($this->internal['currentRow'] = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
575 $tRows[] = $this->pi_list_row($c);
576 $c++;
577 }
578
579 $out = '
580
581 <!--
582 Record list:
583 -->
584 <div'.$this->pi_classParam('listrow').'>
585 <'.trim('table '.$tableParams).'>
586 '.implode('',$tRows).'
587 </table>
588 </div>';
589
590 return $out;
591 }
592
593 /**
594 * Returns a list row. Get data from $this->internal['currentRow'];
595 * (Dummy)
596 * Notice: This function should ALWAYS be defined in the extension class of the plugin since it is directly concerned with the specific layout of the listing for your plugins purpose.
597 *
598 * @param integer Row counting. Starts at 0 (zero). Used for alternating class values in the output rows.
599 * @return string HTML output, a table row with a class attribute set (alternative based on odd/even rows)
600 */
601 function pi_list_row($c) {
602 // Dummy
603 return '<tr'.($c%2 ? $this->pi_classParam('listrow-odd') : '').'><td><p>[dummy row]</p></td></tr>';
604 }
605
606 /**
607 * Returns a list header row.
608 * (Dummy)
609 * Notice: This function should ALWAYS be defined in the extension class of the plugin since it is directly concerned with the specific layout of the listing for your plugins purpose.
610 *
611 * @return string HTML output, a table row with a class attribute set
612 */
613 function pi_list_header() {
614 return '<tr'.$this->pi_classParam('listrow-header').'><td><p>[dummy header row]</p></td></tr>';
615 }
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631 /***************************
632 *
633 * Stylesheet, CSS
634 *
635 **************************/
636
637
638 /**
639 * Returns a class-name prefixed with $this->prefixId and with all underscores substituted to dashes (-)
640 *
641 * @param string The class name (or the END of it since it will be prefixed by $this->prefixId.'-')
642 * @return string The combined class name (with the correct prefix)
643 */
644 function pi_getClassName($class) {
645 return str_replace('_','-',$this->prefixId).($this->prefixId?'-':'').$class;
646 }
647
648 /**
649 * Returns the class-attribute with the correctly prefixed classname
650 * Using pi_getClassName()
651 *
652 * @param string The class name (suffix)
653 * @return string A "class" attribute with value and a single space char before it.
654 * @see pi_getClassName()
655 */
656 function pi_classParam($class) {
657 return ' class="'.$this->pi_getClassName($class).'"';
658 }
659
660 /**
661 * Sets CSS style-data for the $class-suffix (prefixed by pi_getClassName())
662 *
663 * @param string $class: Class suffix, see pi_getClassName
664 * @param string $data: CSS data
665 * @param string If $selector is set to any CSS selector, eg 'P' or 'H1' or 'TABLE' then the style $data will regard those HTML-elements only
666 * @return void
667 * @depreciated I think this function should not be used (and probably isn't used anywhere). It was a part of a concept which was left behind quite quickly.
668 * @private
669 */
670 function pi_setClassStyle($class,$data,$selector='') {
671 $GLOBALS['TSFE']->setCSS($this->pi_getClassName($class).($selector?' '.$selector:''),'.'.$this->pi_getClassName($class).($selector?' '.$selector:'').' {'.$data.'}');
672 }
673
674 /**
675 * Wraps the input string in a <div> tag with the class attribute set to the prefixId.
676 * All content returned from your plugins should be returned through this function so all content from your plugin is encapsulated in a <div>-tag nicely identifying the content of your plugin.
677 *
678 * @param string HTML content to wrap in the div-tags with the "main class" of the plugin
679 * @return string HTML content wrapped, ready to return to the parent object.
680 */
681 function pi_wrapInBaseClass($str) {
682 return '
683
684
685 <!--
686
687 BEGIN: Content of extension "'.$this->extKey.'", plugin "'.$this->prefixId.'"
688
689 -->
690 <div class="'.str_replace('_','-',$this->prefixId).'">
691 '.$str.'
692 </div>
693 <!-- END: Content of extension "'.$this->extKey.'", plugin "'.$this->prefixId.'" -->
694
695 ';
696 }
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714 /***************************
715 *
716 * Frontend editing: Edit panel, edit icons
717 *
718 **************************/
719
720 /**
721 * Returns the Backend User edit panel for the $row from $tablename
722 *
723 * @param array Record array.
724 * @param string Table name
725 * @param string A label to show with the panel.
726 * @param array TypoScript parameters to pass along to the EDITPANEL content Object that gets rendered. The property "allow" WILL get overridden/set though.
727 * @return string Returns false/blank if no BE User login and of course if the panel is not shown for other reasons. Otherwise the HTML for the panel (a table).
728 * @see tslib_cObj::EDITPANEL()
729 */
730 function pi_getEditPanel($row='',$tablename='',$label='',$conf=Array()) {
731 $panel='';
732 if (!$row || !$tablename) {
733 $row = $this->internal['currentRow'];
734 $tablename = $this->internal['currentTable'];
735 }
736
737 if ($GLOBALS['TSFE']->beUserLogin) {
738 // Create local cObj if not set:
739 if (!is_object($this->pi_EPtemp_cObj)) {
740 $this->pi_EPtemp_cObj = t3lib_div::makeInstance('tslib_cObj');
741 $this->pi_EPtemp_cObj->setParent($this->cObj->data,$this->cObj->currentRecord);
742 }
743
744 // Initialize the cObj object with current row
745 $this->pi_EPtemp_cObj->start($row,$tablename);
746
747 // Setting TypoScript values in the $conf array. See documentation in TSref for the EDITPANEL cObject.
748 $conf['allow'] = 'edit,new,delete,move,hide';
749 $panel = $this->pi_EPtemp_cObj->cObjGetSingle('EDITPANEL',$conf,'editpanel');
750 }
751
752 if ($panel) {
753 if ($label) {
754 return '<!-- BEGIN: EDIT PANEL --><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td valign="top">'.$label.'</td><td valign="top" align="right">'.$panel.'</td></tr></table><!-- END: EDIT PANEL -->';
755 } else return '<!-- BEGIN: EDIT PANEL -->'.$panel.'<!-- END: EDIT PANEL -->';
756 } else return $label;
757 }
758
759 /**
760 * Adds edit-icons to the input content.
761 * tslib_cObj::editIcons used for rendering
762 *
763 * @param string HTML content to add icons to. The icons will be put right after the last content part in the string (that means before the ending series of HTML tags)
764 * @param string The list of fields to edit when the icon is clicked.
765 * @param string Title for the edit icon.
766 * @param array Table record row
767 * @param string Table name
768 * @param array Conf array
769 * @return string The processed content
770 * @see tslib_cObj::editIcons()
771 */
772 function pi_getEditIcon($content,$fields,$title='',$row='',$tablename='',$oConf=array()) {
773 if ($GLOBALS['TSFE']->beUserLogin){
774 if (!$row || !$tablename) {
775 $row = $this->internal['currentRow'];
776 $tablename = $this->internal['currentTable'];
777 }
778 $conf=array_merge(array(
779 'beforeLastTag'=>1,
780 'iconTitle' => $title
781 ),$oConf);
782 $content=$this->cObj->editIcons($content,$tablename.':'.$fields,$conf,$tablename.':'.$row['uid'],$row,'&viewUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI')));
783 }
784 return $content;
785 }
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803 /***************************
804 *
805 * Localization, locallang functions
806 *
807 **************************/
808
809
810 /**
811 * Returns the localized label of the LOCAL_LANG key, $key
812 * Notice that for debugging purposes prefixes for the output values can be set with the internal vars ->LLtestPrefixAlt and ->LLtestPrefix
813 *
814 * @param string The key from the LOCAL_LANG array for which to return the value.
815 * @param string Alternative string to return IF no value is found set for the key, neither for the local language nor the default.
816 * @param boolean If true, the output label is passed through htmlspecialchars()
817 * @return string The value from LOCAL_LANG.
818 */
819 function pi_getLL($key,$alt='',$hsc=FALSE) {
820 if (isset($this->LOCAL_LANG[$this->LLkey][$key])) {
821 $word = $GLOBALS['TSFE']->csConv($this->LOCAL_LANG[$this->LLkey][$key]);
822 } elseif (isset($this->LOCAL_LANG['default'][$key])) {
823 $word = $this->LOCAL_LANG['default'][$key];
824 } else {
825 $word = $this->LLtestPrefixAlt.$alt;
826 }
827
828 $output = $this->LLtestPrefix.$word;
829 if ($hsc) $output = htmlspecialchars($output);
830
831 return $output;
832 }
833
834 /**
835 * Loads local-language values by looking for a "locallang.php" file in the plugin class directory ($this->scriptRelPath) and if found includes it.
836 * Also locallang values set in the TypoScript property "_LOCAL_LANG" are merged onto the values found in the "locallang.php" file.
837 *
838 * @return void
839 */
840 function pi_loadLL() {
841 if (!$this->LOCAL_LANG_loaded && $this->scriptRelPath) {
842 $basePath = t3lib_extMgm::siteRelPath($this->extKey).dirname($this->scriptRelPath).'/locallang.php';
843 if (@is_file($basePath)) {
844 include('./'.$basePath);
845 $this->LOCAL_LANG = $LOCAL_LANG;
846 if (is_array($this->conf['_LOCAL_LANG.'])) {
847 reset($this->conf['_LOCAL_LANG.']);
848 while(list($k,$lA)=each($this->conf['_LOCAL_LANG.'])) {
849 if (is_array($lA)) {
850 $k = substr($k,0,-1);
851 $this->LOCAL_LANG[$k] = t3lib_div::array_merge_recursive_overrule(is_array($this->LOCAL_LANG[$k])?$this->LOCAL_LANG[$k]:array(), $lA);
852 }
853 }
854 }
855 }
856 }
857 $this->LOCAL_LANG_loaded = 1;
858 }
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882 /***************************
883 *
884 * Database, queries
885 *
886 **************************/
887
888 /**
889 * Makes a standard query for listing of records based on standard input vars from the 'browser' ($this->internal['results_at_a_time'] and $this->piVars['pointer']) and 'searchbox' ($this->piVars['sword'] and $this->internal['searchFieldList'])
890 * Set $count to 1 if you wish to get a count(*) query for selecting the number of results.
891 * Notice that the query will use $this->conf['pidList'] and $this->conf['recursive'] to generate a PID list within which to search for records.
892 *
893 * @param string See pi_exec_query()
894 * @param boolean See pi_exec_query()
895 * @param string See pi_exec_query()
896 * @param mixed See pi_exec_query()
897 * @param string See pi_exec_query()
898 * @param string See pi_exec_query()
899 * @param string See pi_exec_query()
900 * @param boolean If set, the function will return the query not as a string but array with the various parts.
901 * @return mixed The query build.
902 * @access private
903 * @depreciated Use pi_exec_query() instead!
904 */
905 function pi_list_query($table,$count=0,$addWhere='',$mm_cat='',$groupBy='',$orderBy='',$query='',$returnQueryArray=FALSE) {
906
907 // Begin Query:
908 if (!$query) {
909 // Fetches the list of PIDs to select from.
910 // TypoScript property .pidList is a comma list of pids. If blank, current page id is used.
911 // TypoScript property .recursive is a int+ which determines how many levels down from the pids in the pid-list subpages should be included in the select.
912 $pidList = $this->pi_getPidList($this->conf['pidList'],$this->conf['recursive']);
913 if (is_array($mm_cat)) {
914 $query='FROM '.$table.','.$mm_cat['table'].','.$mm_cat['mmtable'].chr(10).
915 ' WHERE '.$table.'.uid='.$mm_cat['mmtable'].'.uid_local AND '.$mm_cat['table'].'.uid='.$mm_cat['mmtable'].'.uid_foreign '.chr(10).
916 (strcmp($mm_cat['catUidList'],'')?' AND '.$mm_cat['table'].'.uid IN ('.$mm_cat['catUidList'].')':'').chr(10).
917 ' AND '.$table.'.pid IN ('.$pidList.')'.chr(10).
918 $this->cObj->enableFields($table).chr(10); // This adds WHERE-clauses that ensures deleted, hidden, starttime/endtime/access records are NOT selected, if they should not! Almost ALWAYS add this to your queries!
919 } else {
920 $query='FROM '.$table.' WHERE pid IN ('.$pidList.')'.chr(10).
921 $this->cObj->enableFields($table).chr(10); // This adds WHERE-clauses that ensures deleted, hidden, starttime/endtime/access records are NOT selected, if they should not! Almost ALWAYS add this to your queries!
922 }
923 }
924
925 // Split the "FROM ... WHERE" string so we get the WHERE part and TABLE names separated...:
926 list($TABLENAMES,$WHERE) = spliti('WHERE', trim($query), 2);
927 $TABLENAMES = trim(substr(trim($TABLENAMES),5));
928 $WHERE = trim($WHERE);
929
930 // Add '$addWhere'
931 if ($addWhere) {$WHERE.=' '.$addWhere.chr(10);}
932
933 // Search word:
934 if ($this->piVars['sword'] && $this->internal['searchFieldList']) {
935 $WHERE.=$this->cObj->searchWhere($this->piVars['sword'],$this->internal['searchFieldList'],$table).chr(10);
936 }
937
938 if ($count) {
939 $queryParts = array(
940 'SELECT' => 'count(*)',
941 'FROM' => $TABLENAMES,
942 'WHERE' => $WHERE,
943 'GROUPBY' => '',
944 'ORDERBY' => '',
945 'LIMIT' => ''
946 );
947 } else {
948 // Order by data:
949 if (!$orderBy) {
950 if (t3lib_div::inList($this->internal['orderByList'],$this->internal['orderBy'])) {
951 $orderBy = 'ORDER BY '.$table.'.'.$this->internal['orderBy'].($this->internal['descFlag']?' DESC':'');
952 }
953 }
954
955 // Limit data:
956 $pointer = $this->piVars['pointer'];
957 $pointer = intval($pointer);
958 $results_at_a_time = t3lib_div::intInRange($this->internal['results_at_a_time'],1,1000);
959 $LIMIT = ($pointer*$results_at_a_time).','.$results_at_a_time;
960
961 // Add 'SELECT'
962 $queryParts = array(
963 'SELECT' => $this->pi_prependFieldsWithTable($table,$this->pi_listFields),
964 'FROM' => $TABLENAMES,
965 'WHERE' => $WHERE,
966 'GROUPBY' => $GLOBALS['TYPO3_DB']->stripGroupBy($groupBy),
967 'ORDERBY' => $GLOBALS['TYPO3_DB']->stripOrderBy($orderBy),
968 'LIMIT' => $LIMIT
969 );
970 }
971
972 $query = $GLOBALS['TYPO3_DB']->SELECTquery (
973 $queryParts['SELECT'],
974 $queryParts['FROM'],
975 $queryParts['WHERE'],
976 $queryParts['GROUPBY'],
977 $queryParts['ORDERBY'],
978 $queryParts['LIMIT']
979 );
980 return $returnQueryArray ? $queryParts : $query;
981 }
982
983 /**
984 * Executes a standard SELECT query for listing of records based on standard input vars from the 'browser' ($this->internal['results_at_a_time'] and $this->piVars['pointer']) and 'searchbox' ($this->piVars['sword'] and $this->internal['searchFieldList'])
985 * Set $count to 1 if you wish to get a count(*) query for selecting the number of results.
986 * Notice that the query will use $this->conf['pidList'] and $this->conf['recursive'] to generate a PID list within which to search for records.
987 *
988 * @param string The table name to make the query for.
989 * @param boolean If set, you will get a "count(*)" query back instead of field selecting
990 * @param string Additional WHERE clauses (should be starting with " AND ....")
991 * @param mixed If an array, then it must contain the keys "table", "mmtable" and (optionally) "catUidList" defining a table to make a MM-relation to in the query (based on fields uid_local and uid_foreign). If not array, the query will be a plain query looking up data in only one table.
992 * @param string If set, this is added as a " GROUP BY ...." part of the query.
993 * @param string If set, this is added as a " ORDER BY ...." part of the query. The default is that an ORDER BY clause is made based on $this->internal['orderBy'] and $this->internal['descFlag'] where the orderBy field must be found in $this->internal['orderByList']
994 * @param string If set, this is taken as the first part of the query instead of what is created internally. Basically this should be a query starting with "FROM [table] WHERE ... AND ...". The $addWhere clauses and all the other stuff is still added. Only the tables and PID selecting clauses are bypassed. May be depreciated in the future!
995 * @return pointer SQL result pointer
996 */
997 function pi_exec_query($table,$count=0,$addWhere='',$mm_cat='',$groupBy='',$orderBy='',$query='') {
998 $queryParts = $this->pi_list_query($table,$count,$addWhere,$mm_cat,$groupBy,$orderBy,$query, TRUE);
999
1000 return $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
1001 }
1002
1003 /**
1004 * Returns the row $uid from $table
1005 * (Simply calling $GLOBALS['TSFE']->sys_page->checkRecord())
1006 *
1007 * @param string The table name
1008 * @param integer The uid of the record from the table
1009 * @param boolean If $checkPage is set, it's required that the page on which the record resides is accessible
1010 * @return array If record is found, an array. Otherwise false.
1011 */
1012 function pi_getRecord($table,$uid,$checkPage=0) {
1013 return $GLOBALS['TSFE']->sys_page->checkRecord($table,$uid,$checkPage);
1014 }
1015
1016 /**
1017 * Returns a commalist of page ids for a query (eg. 'WHERE pid IN (...)')
1018 *
1019 * @param string $pid_list is a comma list of page ids (if empty current page is used)
1020 * @param integer $recursive is an integer >=0 telling how deep to dig for pids under each entry in $pid_list
1021 * @return string List of PID values (comma separated)
1022 */
1023 function pi_getPidList($pid_list,$recursive=0) {
1024 if (!strcmp($pid_list,'')) $pid_list = $GLOBALS['TSFE']->id;
1025 $recursive = t3lib_div::intInRange($recursive,0);
1026
1027 $pid_list_arr = array_unique(t3lib_div::trimExplode(',',$pid_list,1));
1028 $pid_list = array();
1029
1030 foreach($pid_list_arr as $val) {
1031 $val = t3lib_div::intInRange($val,0);
1032 if ($val) {
1033 $_list = $this->cObj->getTreeList(-1*$val, $recursive);
1034 if ($_list) $pid_list[] = $_list;
1035 }
1036 }
1037
1038 return implode(',', $pid_list);
1039 }
1040
1041 /**
1042 * Having a comma list of fields ($fieldList) this is prepended with the $table.'.' name
1043 *
1044 * @param string Table name to prepend
1045 * @param string List of fields where each element will be prepended with the table name given.
1046 * @return string List of fields processed.
1047 */
1048 function pi_prependFieldsWithTable($table,$fieldList) {
1049 $list=t3lib_div::trimExplode(',',$fieldList,1);
1050 $return=array();
1051 while(list(,$listItem)=each($list)) {
1052 $return[]=$table.'.'.$listItem;
1053 }
1054 return implode(',',$return);
1055 }
1056
1057 /**
1058 * Will select all records from the "category table", $table, and return them in an array.
1059 *
1060 * @param string The name of the category table to select from.
1061 * @param integer The page from where to select the category records.
1062 * @param string Optional additional WHERE clauses put in the end of the query. DO NOT PUT IN GROUP BY, ORDER BY or LIMIT!
1063 * @param string Optional GROUP BY field(s), if none, supply blank string.
1064 * @param string Optional ORDER BY field(s), if none, supply blank string.
1065 * @param string Optional LIMIT value ([begin,]max), if none, supply blank string.
1066 * @return array The array with the category records in.
1067 */
1068 function pi_getCategoryTableContents($table,$pid,$whereClause='',$groupBy='',$orderBy='',$limit='') {
1069 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
1070 '*',
1071 $table,
1072 'pid='.intval($pid).
1073 $this->cObj->enableFields($table).' '.
1074 $whereClause, // whereClauseMightContainGroupOrderBy
1075 $groupBy,
1076 $orderBy,
1077 $limit
1078 );
1079 $outArr = array();
1080 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
1081 $outArr[$row['uid']] = $row;
1082 }
1083 $GLOBALS['TYPO3_DB']->sql_free_result($res);
1084 return $outArr;
1085 }
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098 /***************************
1099 *
1100 * Various
1101 *
1102 **************************/
1103
1104 /**
1105 * Returns true if the piVars array has ONLY those fields entered that is set in the $fList (commalist) AND if none of those fields value is greater than $lowerThan field if they are integers.
1106 * Notice that this function will only work as long as values are integers.
1107 *
1108 * @param string List of fields (keys from piVars) to evaluate on
1109 * @param integer Limit for the values.
1110 * @return boolean Returns true (1) if conditions are met.
1111 */
1112 function pi_isOnlyFields($fList,$lowerThan=-1) {
1113 $lowerThan = $lowerThan==-1 ? $this->pi_lowerThan : $lowerThan;
1114
1115 $fList = t3lib_div::trimExplode(',',$fList,1);
1116 $tempPiVars = $this->piVars;
1117 while(list(,$k)=each($fList)) {
1118 if (!t3lib_div::testInt($tempPiVars[$k]) || $tempPiVars[$k]<$lowerThan) unset($tempPiVars[$k]);
1119 }
1120 if (!count($tempPiVars)) return 1;
1121 }
1122
1123 /**
1124 * Returns true if the array $inArray contains only values allowed to be cached based on the configuration in $this->pi_autoCacheFields
1125 * Used by ->pi_linkTP_keepPIvars
1126 * This is an advanced form of evaluation of whether a URL should be cached or not.
1127 *
1128 * @param array An array with piVars values to evaluate
1129 * @return boolean Returns true (1) if conditions are met.
1130 * @see pi_linkTP_keepPIvars()
1131 */
1132 function pi_autoCache($inArray) {
1133 if (is_array($inArray)) {
1134 reset($inArray);
1135 while(list($fN,$fV)=each($inArray)) {
1136 if (!strcmp($inArray[$fN],'')) {
1137 unset($inArray[$fN]);
1138 } elseif (is_array($this->pi_autoCacheFields[$fN])) {
1139 if (is_array($this->pi_autoCacheFields[$fN]['range'])
1140 && intval($inArray[$fN])>=intval($this->pi_autoCacheFields[$fN]['range'][0])
1141 && intval($inArray[$fN])<=intval($this->pi_autoCacheFields[$fN]['range'][1])) {
1142 unset($inArray[$fN]);
1143 }
1144 if (is_array($this->pi_autoCacheFields[$fN]['list'])
1145 && in_array($inArray[$fN],$this->pi_autoCacheFields[$fN]['list'])) {
1146 unset($inArray[$fN]);
1147 }
1148 }
1149 }
1150 }
1151 if (!count($inArray)) return 1;
1152 }
1153
1154 /**
1155 * Will process the input string with the parseFunc function from tslib_cObj based on configuration set in "lib.parseFunc_RTE" in the current TypoScript template.
1156 * This is useful for rendering of content in RTE fields where the transformation mode is set to "ts_css" or so.
1157 * Notice that this requires the use of "css_styled_content" to work right.
1158 *
1159 * @param string The input text string to process
1160 * @return string The processed string
1161 * @see tslib_cObj::parseFunc()
1162 */
1163 function pi_RTEcssText($str) {
1164 $parseFunc = $GLOBALS['TSFE']->tmpl->setup['lib.']['parseFunc_RTE.'];
1165 if (is_array($parseFunc)) $str = $this->cObj->parseFunc($str, $parseFunc);
1166 return $str;
1167 }
1168
1169
1170
1171
1172
1173 /*******************************
1174 *
1175 * FlexForms related functions
1176 *
1177 *******************************/
1178
1179 /**
1180 * Converts $this->cObj->data['pi_flexform'] from XML string to flexForm array.
1181 *
1182 * @return void
1183 */
1184 function pi_initPIflexForm() {
1185 // Converting flexform data into array:
1186 if (!is_array($this->cObj->data['pi_flexform']) && $this->cObj->data['pi_flexform']) {
1187 $this->cObj->data['pi_flexform'] = t3lib_div::xml2array($this->cObj->data['pi_flexform']);
1188 if (!is_array($this->cObj->data['pi_flexform'])) $this->cObj->data['pi_flexform']=array();
1189 }
1190 }
1191
1192 /**
1193 * Return value from somewhere inside a FlexForm structure
1194 *
1195 * @param array FlexForm data
1196 * @param string Field name to extract. Can be given like "test/el/2/test/el/field_templateObject" where each part will dig a level deeper in the FlexForm data.
1197 * @param string Sheet pointer, eg. "sDEF"
1198 * @param string Language pointer, eg. "lDEF"
1199 * @param string Value pointer, eg. "vDEF"
1200 * @return string The content.
1201 */
1202 function pi_getFFvalue($T3FlexForm_array,$fieldName,$sheet='sDEF',$lang='lDEF',$value='vDEF') {
1203 $sheetArray = $T3FlexForm_array['data'][$sheet][$lang];
1204 if (is_array($sheetArray)) {
1205 return $this->pi_getFFvalueFromSheetArray($sheetArray,explode('/',$fieldName),$value);
1206 }
1207 }
1208
1209 /**
1210 * Returns part of $sheetArray pointed to by the keys in $fieldNameArray
1211 *
1212 * @param array Multidimensiona array, typically FlexForm contents
1213 * @param array Array where each value points to a key in the FlexForms content - the input array will have the value returned pointed to by these keys. All integer keys will not take their integer counterparts, but rather traverse the current position in the array an return element number X (whether this is right behavior is not settled yet...)
1214 * @param string Value for outermost key, typ. "vDEF" depending on language.
1215 * @return mixed The value, typ. string.
1216 * @access private
1217 * @see pi_getFFvalue()
1218 */
1219 function pi_getFFvalueFromSheetArray($sheetArray,$fieldNameArr,$value) {
1220
1221 $tempArr=$sheetArray;
1222 foreach($fieldNameArr as $k => $v) {
1223 if (t3lib_div::testInt($v)) {
1224 if (is_array($tempArr)) {
1225 $c=0;
1226 foreach($tempArr as $values) {
1227 if ($c==$v) {
1228 #debug($values);
1229 $tempArr=$values;
1230 break;
1231 }
1232 $c++;
1233 }
1234 }
1235 } else {
1236 $tempArr = $tempArr[$v];
1237 }
1238 }
1239 return $tempArr[$value];
1240 }
1241 }
1242
1243 // NO extension of class - does not make sense here.
1244 ?>