4bc79bde7c45717932d73d85b7b0244799642522
[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 (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 * 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 <kasperYYYY@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 * 531: function pi_list_modeSelector($items=array(),$tableParams='')
60 * 569: function pi_list_makelist($res,$tableParams='')
61 * 604: function pi_list_row($c)
62 * 616: function pi_list_header()
63 *
64 * SECTION: Stylesheet, CSS
65 * 647: function pi_getClassName($class)
66 * 659: function pi_classParam($class)
67 * 673: function pi_setClassStyle($class,$data,$selector='')
68 * 684: function pi_wrapInBaseClass($str)
69 *
70 * SECTION: Frontend editing: Edit panel, edit icons
71 * 733: function pi_getEditPanel($row='',$tablename='',$label='',$conf=Array())
72 * 775: function pi_getEditIcon($content,$fields,$title='',$row='',$tablename='',$oConf=array())
73 *
74 * SECTION: Localization, locallang functions
75 * 822: function pi_getLL($key,$alt='',$hsc=FALSE)
76 * 843: function pi_loadLL()
77 *
78 * SECTION: Database, queries
79 * 908: function pi_list_query($table,$count=0,$addWhere='',$mm_cat='',$groupBy='',$orderBy='',$query='',$returnQueryArray=FALSE)
80 * 1000: function pi_exec_query($table,$count=0,$addWhere='',$mm_cat='',$groupBy='',$orderBy='',$query='')
81 * 1015: function pi_getRecord($table,$uid,$checkPage=0)
82 * 1026: function pi_getPidList($pid_list,$recursive=0)
83 * 1051: function pi_prependFieldsWithTable($table,$fieldList)
84 * 1071: function pi_getCategoryTableContents($table,$pid,$whereClause='',$groupBy='',$orderBy='',$limit='')
85 *
86 * SECTION: Various
87 * 1115: function pi_isOnlyFields($fList,$lowerThan=-1)
88 * 1135: function pi_autoCache($inArray)
89 * 1166: function pi_RTEcssText($str)
90 *
91 * SECTION: FlexForms related functions
92 * 1187: function pi_initPIflexForm()
93 * 1205: function pi_getFFvalue($T3FlexForm_array,$fieldName,$sheet='sDEF',$lang='lDEF',$value='vDEF')
94 * 1222: 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 <kasperYYYY@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(\''.$GLOBALS['TSFE']->baseUrlWrap($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').' />'.
513 '<input type="hidden" name="no_cache" value="1" />'.
514 '<input type="hidden" name="'.$this->prefixId.'[pointer]" value="" />'.
515 '</td>
516 </tr>
517 </table>
518 </form>
519 </div>';
520
521 return $sTables;
522 }
523
524 /**
525 * Returns a mode selector; a little menu in a table normally put in the top of the page/list.
526 *
527 * @param array Key/Value pairs for the menu; keys are the piVars[mode] values and the "values" are the labels for them.
528 * @param string Attributes for the table tag which is wrapped around the table cells containing the menu
529 * @return string Output HTML, wrapped in <div>-tags with a class attribute
530 */
531 function pi_list_modeSelector($items=array(),$tableParams='') {
532 $cells=array();
533 reset($items);
534 while(list($k,$v)=each($items)) {
535 $cells[]='
536 <td'.($this->piVars['mode']==$k?$this->pi_classParam('modeSelector-SCell'):'').'><p>'.
537 $this->pi_linkTP_keepPIvars(htmlspecialchars($v),array('mode'=>$k),$this->pi_isOnlyFields($this->pi_isOnlyFields)).
538 '</p></td>';
539 }
540
541 $sTables = '
542
543 <!--
544 Mode selector (menu for list):
545 -->
546 <div'.$this->pi_classParam('modeSelector').'>
547 <'.trim('table '.$tableParams).'>
548 <tr>
549 '.implode('',$cells).'
550 </tr>
551 </table>
552 </div>';
553
554 return $sTables;
555 }
556
557 /**
558 * Returns the list of items based on the input SQL result pointer
559 * For each result row the internal var, $this->internal['currentRow'], is set with the row returned.
560 * $this->pi_list_header() makes the header row for the list
561 * $this->pi_list_row() is used for rendering each row
562 * 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.
563 *
564 * @param pointer Result pointer to a SQL result which can be traversed.
565 * @param string Attributes for the table tag which is wrapped around the table rows containing the list
566 * @return string Output HTML, wrapped in <div>-tags with a class attribute
567 * @see pi_list_row(), pi_list_header()
568 */
569 function pi_list_makelist($res,$tableParams='') {
570 // Make list table header:
571 $tRows=array();
572 $this->internal['currentRow']='';
573 $tRows[] = $this->pi_list_header();
574
575 // Make list table rows
576 $c=0;
577 while($this->internal['currentRow'] = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
578 $tRows[] = $this->pi_list_row($c);
579 $c++;
580 }
581
582 $out = '
583
584 <!--
585 Record list:
586 -->
587 <div'.$this->pi_classParam('listrow').'>
588 <'.trim('table '.$tableParams).'>
589 '.implode('',$tRows).'
590 </table>
591 </div>';
592
593 return $out;
594 }
595
596 /**
597 * Returns a list row. Get data from $this->internal['currentRow'];
598 * (Dummy)
599 * 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.
600 *
601 * @param integer Row counting. Starts at 0 (zero). Used for alternating class values in the output rows.
602 * @return string HTML output, a table row with a class attribute set (alternative based on odd/even rows)
603 */
604 function pi_list_row($c) {
605 // Dummy
606 return '<tr'.($c%2 ? $this->pi_classParam('listrow-odd') : '').'><td><p>[dummy row]</p></td></tr>';
607 }
608
609 /**
610 * Returns a list header row.
611 * (Dummy)
612 * 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.
613 *
614 * @return string HTML output, a table row with a class attribute set
615 */
616 function pi_list_header() {
617 return '<tr'.$this->pi_classParam('listrow-header').'><td><p>[dummy header row]</p></td></tr>';
618 }
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634 /***************************
635 *
636 * Stylesheet, CSS
637 *
638 **************************/
639
640
641 /**
642 * Returns a class-name prefixed with $this->prefixId and with all underscores substituted to dashes (-)
643 *
644 * @param string The class name (or the END of it since it will be prefixed by $this->prefixId.'-')
645 * @return string The combined class name (with the correct prefix)
646 */
647 function pi_getClassName($class) {
648 return str_replace('_','-',$this->prefixId).($this->prefixId?'-':'').$class;
649 }
650
651 /**
652 * Returns the class-attribute with the correctly prefixed classname
653 * Using pi_getClassName()
654 *
655 * @param string The class name (suffix)
656 * @return string A "class" attribute with value and a single space char before it.
657 * @see pi_getClassName()
658 */
659 function pi_classParam($class) {
660 return ' class="'.$this->pi_getClassName($class).'"';
661 }
662
663 /**
664 * Sets CSS style-data for the $class-suffix (prefixed by pi_getClassName())
665 *
666 * @param string $class: Class suffix, see pi_getClassName
667 * @param string $data: CSS data
668 * @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
669 * @return void
670 * @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.
671 * @private
672 */
673 function pi_setClassStyle($class,$data,$selector='') {
674 $GLOBALS['TSFE']->setCSS($this->pi_getClassName($class).($selector?' '.$selector:''),'.'.$this->pi_getClassName($class).($selector?' '.$selector:'').' {'.$data.'}');
675 }
676
677 /**
678 * Wraps the input string in a <div> tag with the class attribute set to the prefixId.
679 * 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.
680 *
681 * @param string HTML content to wrap in the div-tags with the "main class" of the plugin
682 * @return string HTML content wrapped, ready to return to the parent object.
683 */
684 function pi_wrapInBaseClass($str) {
685 return '
686
687
688 <!--
689
690 BEGIN: Content of extension "'.$this->extKey.'", plugin "'.$this->prefixId.'"
691
692 -->
693 <div class="'.str_replace('_','-',$this->prefixId).'">
694 '.$str.'
695 </div>
696 <!-- END: Content of extension "'.$this->extKey.'", plugin "'.$this->prefixId.'" -->
697
698 ';
699 }
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717 /***************************
718 *
719 * Frontend editing: Edit panel, edit icons
720 *
721 **************************/
722
723 /**
724 * Returns the Backend User edit panel for the $row from $tablename
725 *
726 * @param array Record array.
727 * @param string Table name
728 * @param string A label to show with the panel.
729 * @param array TypoScript parameters to pass along to the EDITPANEL content Object that gets rendered. The property "allow" WILL get overridden/set though.
730 * @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).
731 * @see tslib_cObj::EDITPANEL()
732 */
733 function pi_getEditPanel($row='',$tablename='',$label='',$conf=Array()) {
734 $panel='';
735 if (!$row || !$tablename) {
736 $row = $this->internal['currentRow'];
737 $tablename = $this->internal['currentTable'];
738 }
739
740 if ($GLOBALS['TSFE']->beUserLogin) {
741 // Create local cObj if not set:
742 if (!is_object($this->pi_EPtemp_cObj)) {
743 $this->pi_EPtemp_cObj = t3lib_div::makeInstance('tslib_cObj');
744 $this->pi_EPtemp_cObj->setParent($this->cObj->data,$this->cObj->currentRecord);
745 }
746
747 // Initialize the cObj object with current row
748 $this->pi_EPtemp_cObj->start($row,$tablename);
749
750 // Setting TypoScript values in the $conf array. See documentation in TSref for the EDITPANEL cObject.
751 $conf['allow'] = 'edit,new,delete,move,hide';
752 $panel = $this->pi_EPtemp_cObj->cObjGetSingle('EDITPANEL',$conf,'editpanel');
753 }
754
755 if ($panel) {
756 if ($label) {
757 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 -->';
758 } else return '<!-- BEGIN: EDIT PANEL -->'.$panel.'<!-- END: EDIT PANEL -->';
759 } else return $label;
760 }
761
762 /**
763 * Adds edit-icons to the input content.
764 * tslib_cObj::editIcons used for rendering
765 *
766 * @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)
767 * @param string The list of fields to edit when the icon is clicked.
768 * @param string Title for the edit icon.
769 * @param array Table record row
770 * @param string Table name
771 * @param array Conf array
772 * @return string The processed content
773 * @see tslib_cObj::editIcons()
774 */
775 function pi_getEditIcon($content,$fields,$title='',$row='',$tablename='',$oConf=array()) {
776 if ($GLOBALS['TSFE']->beUserLogin){
777 if (!$row || !$tablename) {
778 $row = $this->internal['currentRow'];
779 $tablename = $this->internal['currentTable'];
780 }
781 $conf=array_merge(array(
782 'beforeLastTag'=>1,
783 'iconTitle' => $title
784 ),$oConf);
785 $content=$this->cObj->editIcons($content,$tablename.':'.$fields,$conf,$tablename.':'.$row['uid'],$row,'&viewUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI')));
786 }
787 return $content;
788 }
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806 /***************************
807 *
808 * Localization, locallang functions
809 *
810 **************************/
811
812
813 /**
814 * Returns the localized label of the LOCAL_LANG key, $key
815 * Notice that for debugging purposes prefixes for the output values can be set with the internal vars ->LLtestPrefixAlt and ->LLtestPrefix
816 *
817 * @param string The key from the LOCAL_LANG array for which to return the value.
818 * @param string Alternative string to return IF no value is found set for the key, neither for the local language nor the default.
819 * @param boolean If true, the output label is passed through htmlspecialchars()
820 * @return string The value from LOCAL_LANG.
821 */
822 function pi_getLL($key,$alt='',$hsc=FALSE) {
823 if (isset($this->LOCAL_LANG[$this->LLkey][$key])) {
824 $word = $GLOBALS['TSFE']->csConv($this->LOCAL_LANG[$this->LLkey][$key]);
825 } elseif (isset($this->LOCAL_LANG['default'][$key])) {
826 $word = $this->LOCAL_LANG['default'][$key];
827 } else {
828 $word = $this->LLtestPrefixAlt.$alt;
829 }
830
831 $output = $this->LLtestPrefix.$word;
832 if ($hsc) $output = htmlspecialchars($output);
833
834 return $output;
835 }
836
837 /**
838 * Loads local-language values by looking for a "locallang.php" file in the plugin class directory ($this->scriptRelPath) and if found includes it.
839 * Also locallang values set in the TypoScript property "_LOCAL_LANG" are merged onto the values found in the "locallang.php" file.
840 *
841 * @return void
842 */
843 function pi_loadLL() {
844 if (!$this->LOCAL_LANG_loaded && $this->scriptRelPath) {
845 $basePath = t3lib_extMgm::siteRelPath($this->extKey).dirname($this->scriptRelPath).'/locallang.php';
846 if (@is_file($basePath)) {
847 include('./'.$basePath);
848 $this->LOCAL_LANG = $LOCAL_LANG;
849 if (is_array($this->conf['_LOCAL_LANG.'])) {
850 reset($this->conf['_LOCAL_LANG.']);
851 while(list($k,$lA)=each($this->conf['_LOCAL_LANG.'])) {
852 if (is_array($lA)) {
853 $k = substr($k,0,-1);
854 $this->LOCAL_LANG[$k] = t3lib_div::array_merge_recursive_overrule(is_array($this->LOCAL_LANG[$k])?$this->LOCAL_LANG[$k]:array(), $lA);
855 }
856 }
857 }
858 }
859 }
860 $this->LOCAL_LANG_loaded = 1;
861 }
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885 /***************************
886 *
887 * Database, queries
888 *
889 **************************/
890
891 /**
892 * 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'])
893 * Set $count to 1 if you wish to get a count(*) query for selecting the number of results.
894 * Notice that the query will use $this->conf['pidList'] and $this->conf['recursive'] to generate a PID list within which to search for records.
895 *
896 * @param string See pi_exec_query()
897 * @param boolean See pi_exec_query()
898 * @param string See pi_exec_query()
899 * @param mixed See pi_exec_query()
900 * @param string See pi_exec_query()
901 * @param string See pi_exec_query()
902 * @param string See pi_exec_query()
903 * @param boolean If set, the function will return the query not as a string but array with the various parts.
904 * @return mixed The query build.
905 * @access private
906 * @depreciated Use pi_exec_query() instead!
907 */
908 function pi_list_query($table,$count=0,$addWhere='',$mm_cat='',$groupBy='',$orderBy='',$query='',$returnQueryArray=FALSE) {
909
910 // Begin Query:
911 if (!$query) {
912 // Fetches the list of PIDs to select from.
913 // TypoScript property .pidList is a comma list of pids. If blank, current page id is used.
914 // 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.
915 $pidList = $this->pi_getPidList($this->conf['pidList'],$this->conf['recursive']);
916 if (is_array($mm_cat)) {
917 $query='FROM '.$table.','.$mm_cat['table'].','.$mm_cat['mmtable'].chr(10).
918 ' WHERE '.$table.'.uid='.$mm_cat['mmtable'].'.uid_local AND '.$mm_cat['table'].'.uid='.$mm_cat['mmtable'].'.uid_foreign '.chr(10).
919 (strcmp($mm_cat['catUidList'],'')?' AND '.$mm_cat['table'].'.uid IN ('.$mm_cat['catUidList'].')':'').chr(10).
920 ' AND '.$table.'.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 } else {
923 $query='FROM '.$table.' WHERE pid IN ('.$pidList.')'.chr(10).
924 $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!
925 }
926 }
927
928 // Split the "FROM ... WHERE" string so we get the WHERE part and TABLE names separated...:
929 list($TABLENAMES,$WHERE) = spliti('WHERE', trim($query), 2);
930 $TABLENAMES = trim(substr(trim($TABLENAMES),5));
931 $WHERE = trim($WHERE);
932
933 // Add '$addWhere'
934 if ($addWhere) {$WHERE.=' '.$addWhere.chr(10);}
935
936 // Search word:
937 if ($this->piVars['sword'] && $this->internal['searchFieldList']) {
938 $WHERE.=$this->cObj->searchWhere($this->piVars['sword'],$this->internal['searchFieldList'],$table).chr(10);
939 }
940
941 if ($count) {
942 $queryParts = array(
943 'SELECT' => 'count(*)',
944 'FROM' => $TABLENAMES,
945 'WHERE' => $WHERE,
946 'GROUPBY' => '',
947 'ORDERBY' => '',
948 'LIMIT' => ''
949 );
950 } else {
951 // Order by data:
952 if (!$orderBy) {
953 if (t3lib_div::inList($this->internal['orderByList'],$this->internal['orderBy'])) {
954 $orderBy = 'ORDER BY '.$table.'.'.$this->internal['orderBy'].($this->internal['descFlag']?' DESC':'');
955 }
956 }
957
958 // Limit data:
959 $pointer = $this->piVars['pointer'];
960 $pointer = intval($pointer);
961 $results_at_a_time = t3lib_div::intInRange($this->internal['results_at_a_time'],1,1000);
962 $LIMIT = ($pointer*$results_at_a_time).','.$results_at_a_time;
963
964 // Add 'SELECT'
965 $queryParts = array(
966 'SELECT' => $this->pi_prependFieldsWithTable($table,$this->pi_listFields),
967 'FROM' => $TABLENAMES,
968 'WHERE' => $WHERE,
969 'GROUPBY' => $GLOBALS['TYPO3_DB']->stripGroupBy($groupBy),
970 'ORDERBY' => $GLOBALS['TYPO3_DB']->stripOrderBy($orderBy),
971 'LIMIT' => $LIMIT
972 );
973 }
974
975 $query = $GLOBALS['TYPO3_DB']->SELECTquery (
976 $queryParts['SELECT'],
977 $queryParts['FROM'],
978 $queryParts['WHERE'],
979 $queryParts['GROUPBY'],
980 $queryParts['ORDERBY'],
981 $queryParts['LIMIT']
982 );
983 return $returnQueryArray ? $queryParts : $query;
984 }
985
986 /**
987 * 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'])
988 * Set $count to 1 if you wish to get a count(*) query for selecting the number of results.
989 * Notice that the query will use $this->conf['pidList'] and $this->conf['recursive'] to generate a PID list within which to search for records.
990 *
991 * @param string The table name to make the query for.
992 * @param boolean If set, you will get a "count(*)" query back instead of field selecting
993 * @param string Additional WHERE clauses (should be starting with " AND ....")
994 * @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.
995 * @param string If set, this is added as a " GROUP BY ...." part of the query.
996 * @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']
997 * @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!
998 * @return pointer SQL result pointer
999 */
1000 function pi_exec_query($table,$count=0,$addWhere='',$mm_cat='',$groupBy='',$orderBy='',$query='') {
1001 $queryParts = $this->pi_list_query($table,$count,$addWhere,$mm_cat,$groupBy,$orderBy,$query, TRUE);
1002
1003 return $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
1004 }
1005
1006 /**
1007 * Returns the row $uid from $table
1008 * (Simply calling $GLOBALS['TSFE']->sys_page->checkRecord())
1009 *
1010 * @param string The table name
1011 * @param integer The uid of the record from the table
1012 * @param boolean If $checkPage is set, it's required that the page on which the record resides is accessible
1013 * @return array If record is found, an array. Otherwise false.
1014 */
1015 function pi_getRecord($table,$uid,$checkPage=0) {
1016 return $GLOBALS['TSFE']->sys_page->checkRecord($table,$uid,$checkPage);
1017 }
1018
1019 /**
1020 * Returns a commalist of page ids for a query (eg. 'WHERE pid IN (...)')
1021 *
1022 * @param string $pid_list is a comma list of page ids (if empty current page is used)
1023 * @param integer $recursive is an integer >=0 telling how deep to dig for pids under each entry in $pid_list
1024 * @return string List of PID values (comma separated)
1025 */
1026 function pi_getPidList($pid_list,$recursive=0) {
1027 if (!strcmp($pid_list,'')) $pid_list = $GLOBALS['TSFE']->id;
1028 $recursive = t3lib_div::intInRange($recursive,0);
1029
1030 $pid_list_arr = array_unique(t3lib_div::trimExplode(',',$pid_list,1));
1031 $pid_list = array();
1032
1033 foreach($pid_list_arr as $val) {
1034 $val = t3lib_div::intInRange($val,0);
1035 if ($val) {
1036 $_list = $this->cObj->getTreeList(-1*$val, $recursive);
1037 if ($_list) $pid_list[] = $_list;
1038 }
1039 }
1040
1041 return implode(',', $pid_list);
1042 }
1043
1044 /**
1045 * Having a comma list of fields ($fieldList) this is prepended with the $table.'.' name
1046 *
1047 * @param string Table name to prepend
1048 * @param string List of fields where each element will be prepended with the table name given.
1049 * @return string List of fields processed.
1050 */
1051 function pi_prependFieldsWithTable($table,$fieldList) {
1052 $list=t3lib_div::trimExplode(',',$fieldList,1);
1053 $return=array();
1054 while(list(,$listItem)=each($list)) {
1055 $return[]=$table.'.'.$listItem;
1056 }
1057 return implode(',',$return);
1058 }
1059
1060 /**
1061 * Will select all records from the "category table", $table, and return them in an array.
1062 *
1063 * @param string The name of the category table to select from.
1064 * @param integer The page from where to select the category records.
1065 * @param string Optional additional WHERE clauses put in the end of the query. DO NOT PUT IN GROUP BY, ORDER BY or LIMIT!
1066 * @param string Optional GROUP BY field(s), if none, supply blank string.
1067 * @param string Optional ORDER BY field(s), if none, supply blank string.
1068 * @param string Optional LIMIT value ([begin,]max), if none, supply blank string.
1069 * @return array The array with the category records in.
1070 */
1071 function pi_getCategoryTableContents($table,$pid,$whereClause='',$groupBy='',$orderBy='',$limit='') {
1072 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
1073 '*',
1074 $table,
1075 'pid='.intval($pid).
1076 $this->cObj->enableFields($table).' '.
1077 $whereClause, // whereClauseMightContainGroupOrderBy
1078 $groupBy,
1079 $orderBy,
1080 $limit
1081 );
1082 $outArr = array();
1083 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
1084 $outArr[$row['uid']] = $row;
1085 }
1086 $GLOBALS['TYPO3_DB']->sql_free_result($res);
1087 return $outArr;
1088 }
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101 /***************************
1102 *
1103 * Various
1104 *
1105 **************************/
1106
1107 /**
1108 * 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.
1109 * Notice that this function will only work as long as values are integers.
1110 *
1111 * @param string List of fields (keys from piVars) to evaluate on
1112 * @param integer Limit for the values.
1113 * @return boolean Returns true (1) if conditions are met.
1114 */
1115 function pi_isOnlyFields($fList,$lowerThan=-1) {
1116 $lowerThan = $lowerThan==-1 ? $this->pi_lowerThan : $lowerThan;
1117
1118 $fList = t3lib_div::trimExplode(',',$fList,1);
1119 $tempPiVars = $this->piVars;
1120 while(list(,$k)=each($fList)) {
1121 if (!t3lib_div::testInt($tempPiVars[$k]) || $tempPiVars[$k]<$lowerThan) unset($tempPiVars[$k]);
1122 }
1123 if (!count($tempPiVars)) return 1;
1124 }
1125
1126 /**
1127 * Returns true if the array $inArray contains only values allowed to be cached based on the configuration in $this->pi_autoCacheFields
1128 * Used by ->pi_linkTP_keepPIvars
1129 * This is an advanced form of evaluation of whether a URL should be cached or not.
1130 *
1131 * @param array An array with piVars values to evaluate
1132 * @return boolean Returns true (1) if conditions are met.
1133 * @see pi_linkTP_keepPIvars()
1134 */
1135 function pi_autoCache($inArray) {
1136 if (is_array($inArray)) {
1137 reset($inArray);
1138 while(list($fN,$fV)=each($inArray)) {
1139 if (!strcmp($inArray[$fN],'')) {
1140 unset($inArray[$fN]);
1141 } elseif (is_array($this->pi_autoCacheFields[$fN])) {
1142 if (is_array($this->pi_autoCacheFields[$fN]['range'])
1143 && intval($inArray[$fN])>=intval($this->pi_autoCacheFields[$fN]['range'][0])
1144 && intval($inArray[$fN])<=intval($this->pi_autoCacheFields[$fN]['range'][1])) {
1145 unset($inArray[$fN]);
1146 }
1147 if (is_array($this->pi_autoCacheFields[$fN]['list'])
1148 && in_array($inArray[$fN],$this->pi_autoCacheFields[$fN]['list'])) {
1149 unset($inArray[$fN]);
1150 }
1151 }
1152 }
1153 }
1154 if (!count($inArray)) return 1;
1155 }
1156
1157 /**
1158 * 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.
1159 * This is useful for rendering of content in RTE fields where the transformation mode is set to "ts_css" or so.
1160 * Notice that this requires the use of "css_styled_content" to work right.
1161 *
1162 * @param string The input text string to process
1163 * @return string The processed string
1164 * @see tslib_cObj::parseFunc()
1165 */
1166 function pi_RTEcssText($str) {
1167 $parseFunc = $GLOBALS['TSFE']->tmpl->setup['lib.']['parseFunc_RTE.'];
1168 if (is_array($parseFunc)) $str = $this->cObj->parseFunc($str, $parseFunc);
1169 return $str;
1170 }
1171
1172
1173
1174
1175
1176 /*******************************
1177 *
1178 * FlexForms related functions
1179 *
1180 *******************************/
1181
1182 /**
1183 * Converts $this->cObj->data['pi_flexform'] from XML string to flexForm array.
1184 *
1185 * @return void
1186 */
1187 function pi_initPIflexForm() {
1188 // Converting flexform data into array:
1189 if (!is_array($this->cObj->data['pi_flexform']) && $this->cObj->data['pi_flexform']) {
1190 $this->cObj->data['pi_flexform'] = t3lib_div::xml2array($this->cObj->data['pi_flexform']);
1191 if (!is_array($this->cObj->data['pi_flexform'])) $this->cObj->data['pi_flexform']=array();
1192 }
1193 }
1194
1195 /**
1196 * Return value from somewhere inside a FlexForm structure
1197 *
1198 * @param array FlexForm data
1199 * @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.
1200 * @param string Sheet pointer, eg. "sDEF"
1201 * @param string Language pointer, eg. "lDEF"
1202 * @param string Value pointer, eg. "vDEF"
1203 * @return string The content.
1204 */
1205 function pi_getFFvalue($T3FlexForm_array,$fieldName,$sheet='sDEF',$lang='lDEF',$value='vDEF') {
1206 $sheetArray = $T3FlexForm_array['data'][$sheet][$lang];
1207 if (is_array($sheetArray)) {
1208 return $this->pi_getFFvalueFromSheetArray($sheetArray,explode('/',$fieldName),$value);
1209 }
1210 }
1211
1212 /**
1213 * Returns part of $sheetArray pointed to by the keys in $fieldNameArray
1214 *
1215 * @param array Multidimensiona array, typically FlexForm contents
1216 * @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...)
1217 * @param string Value for outermost key, typ. "vDEF" depending on language.
1218 * @return mixed The value, typ. string.
1219 * @access private
1220 * @see pi_getFFvalue()
1221 */
1222 function pi_getFFvalueFromSheetArray($sheetArray,$fieldNameArr,$value) {
1223
1224 $tempArr=$sheetArray;
1225 foreach($fieldNameArr as $k => $v) {
1226 if (t3lib_div::testInt($v)) {
1227 if (is_array($tempArr)) {
1228 $c=0;
1229 foreach($tempArr as $values) {
1230 if ($c==$v) {
1231 #debug($values);
1232 $tempArr=$values;
1233 break;
1234 }
1235 $c++;
1236 }
1237 }
1238 } else {
1239 $tempArr = $tempArr[$v];
1240 }
1241 }
1242 return $tempArr[$value];
1243 }
1244 }
1245
1246 // NO extension of class - does not make sense here.
1247 ?>