* Removed misc/mod_rewrite.htaccess and misc/php_optimized.htaccess and replaced...
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / tslib / class.tslib_pibase.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2005 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_charset = Array(); // Local Language content charset for individual labels (overriding)
155 var $LOCAL_LANG_loaded = 0; // Flag that tells if the locallang file has been fetch (or tried to be fetched) already.
156 var $LLkey='default'; // Pointer to the language to use.
157 var $altLLkey=''; // Pointer to alternative fall-back language to use.
158 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.
159 var $LLtestPrefixAlt=''; // Save as LLtestPrefix, but additional prefix for the alternative value in getLL() function calls
160
161 var $pi_isOnlyFields = 'mode,pointer';
162 var $pi_alwaysPrev = 0;
163 var $pi_lowerThan = 5;
164 var $pi_moreParams='';
165 var $pi_listFields='*';
166
167 var $pi_autoCacheFields=array();
168 var $pi_autoCacheEn=0;
169
170 var $pi_USER_INT_obj = FALSE; // If set, then links are 1) not using cHash and 2) not allowing pages to be cached. (Set this for all USER_INT plugins!)
171 var $pi_checkCHash = FALSE; // If set, then caching is disabled if piVars are incoming while no cHash was set (Set this for all USER plugins!)
172
173 /**
174 * Should normally be set in the main function with the TypoScript content passed to the method.
175 *
176 * $conf[LOCAL_LANG][_key_] is reserved for Local Language overrides.
177 * $conf[userFunc] / $conf[includeLibs] reserved for setting up the USER / USER_INT object. See TSref
178 */
179 var $conf = Array();
180
181 // internal, don't mess with...
182 var $pi_EPtemp_cObj;
183 var $pi_tmpPageId=0;
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201 /***************************
202 *
203 * Init functions
204 *
205 **************************/
206
207 /**
208 * Class Constructor (true constructor)
209 * Initializes $this->piVars if $this->prefixId is set to any value
210 * Will also set $this->LLkey based on the config.language setting.
211 *
212 * @return void
213 */
214 function tslib_pibase() {
215
216 // Setting piVars:
217 if ($this->prefixId) {
218 $this->piVars = t3lib_div::GParrayMerged($this->prefixId);
219
220 // cHash mode check
221 // IMPORTANT FOR CACHED PLUGINS (USER cObject): As soon as you generate cached plugin output which depends on parameters (eg. seeing the details of a news item) you MUST check if a cHash value is set.
222 // Background: The function call will check if a cHash parameter was sent with the URL because only if it was the page may be cached. If no cHash was found the function will simply disable caching to avoid unpredictable caching behaviour. In any case your plugin can generate the expected output and the only risk is that the content may not be cached. A missing cHash value is considered a mistake in the URL resulting from either URL manipulation, "realurl" "grayzones" etc. The problem is rare (more frequent with "realurl") but when it occurs it is very puzzling!
223 if ($this->pi_checkCHash && count($this->piVars)) {
224 $GLOBALS['TSFE']->reqCHash();
225 }
226 }
227 if ($GLOBALS['TSFE']->config['config']['language']) {
228 $this->LLkey = $GLOBALS['TSFE']->config['config']['language'];
229 if ($GLOBALS['TSFE']->config['config']['language_alt']) {
230 $this->altLLkey = $GLOBALS['TSFE']->config['config']['language_alt'];
231 }
232 }
233 }
234
235 /**
236 * If internal TypoScript property "_DEFAULT_PI_VARS." is set then it will merge the current $this->piVars array onto these default values.
237 *
238 * @return void
239 */
240 function pi_setPiVarDefaults() {
241 if (is_array($this->conf['_DEFAULT_PI_VARS.'])) {
242 $this->piVars = t3lib_div::array_merge_recursive_overrule($this->conf['_DEFAULT_PI_VARS.'],is_array($this->piVars)?$this->piVars:array());
243 }
244 }
245
246
247
248
249
250
251
252
253
254
255
256
257
258 /***************************
259 *
260 * Link functions
261 *
262 **************************/
263
264 /**
265 * Get URL to some page.
266 * Returns the URL to page $id with $target and an array of additional url-parameters, $urlParameters
267 * Simple example: $this->pi_getPageLink(123) to get the URL for page-id 123.
268 *
269 * The function basically calls $this->cObj->getTypoLink_URL()
270 *
271 * @param integer Page id
272 * @param string Target value to use. Affects the &type-value of the URL, defaults to current.
273 * @param array Additional URL parameters to set (key/value pairs)
274 * @return string The resulting URL
275 * @see pi_linkToPage()
276 */
277 function pi_getPageLink($id,$target='',$urlParameters=array()) {
278 return $this->cObj->getTypoLink_URL($id,$urlParameters,$target); // ?$target:$GLOBALS['TSFE']->sPre
279 }
280
281 /**
282 * Link a string to some page.
283 * Like pi_getPageLink() but takes a string as first parameter which will in turn be wrapped with the URL including target attribute
284 * 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)
285 *
286 * @param string The content string to wrap in <a> tags
287 * @param integer Page id
288 * @param string Target value to use. Affects the &type-value of the URL, defaults to current.
289 * @param array Additional URL parameters to set (key/value pairs)
290 * @return string The input string wrapped in <a> tags with the URL and target set.
291 * @see pi_getPageLink(), tslib_cObj::getTypoLink()
292 */
293 function pi_linkToPage($str,$id,$target='',$urlParameters=array()) {
294 return $this->cObj->getTypoLink($str,$id,$urlParameters,$target); // ?$target:$GLOBALS['TSFE']->sPre
295 }
296
297 /**
298 * Link string to the current page.
299 * Returns the $str wrapped in <a>-tags with a link to the CURRENT page, but with $urlParameters set as extra parameters for the page.
300 *
301 * @param string The content string to wrap in <a> tags
302 * @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.
303 * @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.
304 * @param integer Alternative page ID for the link. (By default this function links to the SAME page!)
305 * @return string The input string wrapped in <a> tags
306 * @see pi_linkTP_keepPIvars(), tslib_cObj::typoLink()
307 */
308 function pi_linkTP($str,$urlParameters=array(),$cache=0,$altPageId=0) {
309 $conf=array();
310 $conf['useCacheHash'] = $this->pi_USER_INT_obj ? 0 : $cache;
311 $conf['no_cache'] = $this->pi_USER_INT_obj ? 0 : !$cache;
312 $conf['parameter'] = $altPageId ? $altPageId : ($this->pi_tmpPageId ? $this->pi_tmpPageId : $GLOBALS['TSFE']->id);
313 $conf['additionalParams'] = $this->conf['parent.']['addParams'].t3lib_div::implodeArrayForUrl('',$urlParameters,'',1).$this->pi_moreParams;
314
315 return $this->cObj->typoLink($str, $conf);
316 }
317
318 /**
319 * Link a string to the current page while keeping currently set values in piVars.
320 * Like pi_linkTP, but $urlParameters is by default set to $this->piVars with $overrulePIvars overlaid.
321 * 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.
322 *
323 * @param string The content string to wrap in <a> tags
324 * @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)
325 * @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.
326 * @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[]"
327 * @param integer Alternative page ID for the link. (By default this function links to the SAME page!)
328 * @return string The input string wrapped in <a> tags
329 * @see pi_linkTP()
330 */
331 function pi_linkTP_keepPIvars($str,$overrulePIvars=array(),$cache=0,$clearAnyway=0,$altPageId=0) {
332 if (is_array($this->piVars) && is_array($overrulePIvars) && !$clearAnyway) {
333 $piVars = $this->piVars;
334 unset($piVars['DATA']);
335 $overrulePIvars = t3lib_div::array_merge_recursive_overrule($piVars,$overrulePIvars);
336 if ($this->pi_autoCacheEn) {
337 $cache = $this->pi_autoCache($overrulePIvars);
338 }
339 }
340 $res = $this->pi_linkTP($str,Array($this->prefixId=>$overrulePIvars),$cache,$altPageId);
341 return $res;
342 }
343
344 /**
345 * Get URL to the current page while keeping currently set values in piVars.
346 * Same as pi_linkTP_keepPIvars but returns only the URL from the link.
347 *
348 * @param array See pi_linkTP_keepPIvars
349 * @param boolean See pi_linkTP_keepPIvars
350 * @param boolean See pi_linkTP_keepPIvars
351 * @param integer See pi_linkTP_keepPIvars
352 * @return string The URL ($this->cObj->lastTypoLinkUrl)
353 * @see pi_linkTP_keepPIvars()
354 */
355 function pi_linkTP_keepPIvars_url($overrulePIvars=array(),$cache=0,$clearAnyway=0,$altPageId=0) {
356 $this->pi_linkTP_keepPIvars('|',$overrulePIvars,$cache,$clearAnyway,$altPageId);
357 return $this->cObj->lastTypoLinkUrl;
358 }
359
360 /**
361 * Wraps the $str in a link to a single display of the record (using piVars[showUid])
362 * Uses pi_linkTP for the linking
363 *
364 * @param string The content string to wrap in <a> tags
365 * @param integer UID of the record for which to display details (basically this will become the value of [showUid]
366 * @param boolean See pi_linkTP_keepPIvars
367 * @param array Array of values to override in the current piVars. Same as $overrulePIvars in pi_linkTP_keepPIvars
368 * @param boolean If true, only the URL is returned, not a full link
369 * @param integer Alternative page ID for the link. (By default this function links to the SAME page!)
370 * @return string The input string wrapped in <a> tags
371 * @see pi_linkTP(), pi_linkTP_keepPIvars()
372 */
373 function pi_list_linkSingle($str,$uid,$cache=FALSE,$mergeArr=array(),$urlOnly=FALSE,$altPageId=0) {
374 if ($this->prefixId) {
375 if ($cache) {
376 $overrulePIvars=$uid?array('showUid'=>$uid):Array();
377 $overrulePIvars=array_merge($overrulePIvars,$mergeArr);
378 $str = $this->pi_linkTP($str,Array($this->prefixId=>$overrulePIvars),$cache,$altPageId);
379 } else {
380 $overrulePIvars=array('showUid'=>$uid?$uid:'');
381 $overrulePIvars=array_merge($overrulePIvars,$mergeArr);
382 $str = $this->pi_linkTP_keepPIvars($str,$overrulePIvars,$cache,0,$altPageId);
383 }
384
385 // If urlOnly flag, return only URL as it has recently be generated.
386 if ($urlOnly) {
387 $str = $this->cObj->lastTypoLinkUrl;
388 }
389 }
390 return $str;
391 }
392
393 /**
394 * 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
395 *
396 * @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.
397 * @param string Window name for the pop-up window
398 * @param string Window parameters, see the default list for inspiration
399 * @return string The processed input string, modified IF a <a> tag was found
400 */
401 function pi_openAtagHrefInJSwindow($str,$winName='',$winParams='width=670,height=500,status=0,menubar=0,scrollbars=1,resizable=1') {
402 if (eregi('(.*)(<a[^>]*>)(.*)',$str,$match)) {
403 $aTagContent = t3lib_div::get_tag_attributes($match[2]);
404 $match[2]='<a href="#" onclick="'.
405 htmlspecialchars('vHWin=window.open(\''.$GLOBALS['TSFE']->baseUrlWrap($aTagContent['href']).'\',\''.($winName?$winName:md5($aTagContent['href'])).'\',\''.$winParams.'\');vHWin.focus();return false;').
406 '">';
407 $str=$match[1].$match[2].$match[3];
408 }
409 return $str;
410 }
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425 /***************************
426 *
427 * Functions for listing, browsing, searching etc.
428 *
429 **************************/
430
431 /**
432 * 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.
433 * Using $this->piVars['pointer'] as pointer to the page to display. Can be overwritten with another string ($pointerName) to make it possible to have more than one pagebrowser on a page)
434 * 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.
435 * Using $this->internal['dontLinkActivePage'] as switch if the active (current) page should be displayed as pure text or as a link to itself
436 * Using $this->internal['showFirstLast'] as switch if the two links named "<< First" and "LAST >>" will be shown and point to the first or last page.
437 * Using $this->internal['pagefloat']: this defines were the current page is shown in the list of pages in the Pagebrowser. If this var is an integer it will be interpreted as position in the list of pages. If its value is the keyword "center" the current page will be shown in the middle of the pagelist.
438 * Using $this->internal['showRange']: this var switches the display of the pagelinks from pagenumbers to ranges f.e.: 1-5 6-10 11-15... instead of 1 2 3...
439 * Using $this->pi_isOnlyFields: this holds a comma-separated list of fieldnames which - if they are among the GETvars - will not disable caching for the page with pagebrowser.
440 *
441 * The third parameter is an array with several wraps for the parts of the pagebrowser. The following elements will be recognized:
442 * disabledLinkWrap, inactiveLinkWrap, activeLinkWrap, browseLinksWrap, showResultsWrap, showResultsNumbersWrap, browseBoxWrap.
443 *
444 * If $wrapArr['showResultsNumbersWrap'] is set, the formatting string is expected to hold template markers (###FROM###, ###TO###, ###OUT_OF###, ###FROM_TO###, ###CURRENT_PAGE###, ###TOTAL_PAGES###)
445 * otherwise the formatting sting is expected to hold sprintf-markers (%s) for from, to, outof (in that sequence)
446 *
447 * @param integer determines how the results of the pagerowser will be shown. See description below
448 * @param string Attributes for the table tag which is wrapped around the table cells containing the browse links
449 * @param array Array with elements to overwrite the default $wrapper-array.
450 * @param string varname for the pointer.
451 * @param boolean enable htmlspecialchars() for the pi_getLL function (set this to FALSE if you want f.e use images instead of text for links like 'previous' and 'next').
452 * @return string Output HTML-Table, wrapped in <div>-tags with a class attribute (if $wrapArr is not passed,
453 * otherwise wrapping is totally controlled/modified by this array
454 */
455 function pi_list_browseresults($showResultCount=1,$tableParams='',$wrapArr=array(), $pointerName = 'pointer', $hscText = TRUE) {
456
457 // example $wrapArr-array how it could be traversed from an extension
458 /* $wrapArr = array(
459 'browseBoxWrap' => '<div class="browseBoxWrap">|</div>',
460 'showResultsWrap' => '<div class="showResultsWrap">|</div>',
461 'browseLinksWrap' => '<div class="browseLinksWrap">|</div>',
462 'showResultsNumbersWrap' => '<span class="showResultsNumbersWrap">|</span>',
463 'disabledLinkWrap' => '<span class="disabledLinkWrap">|</span>',
464 'inactiveLinkWrap' => '<span class="inactiveLinkWrap">|</span>',
465 'activeLinkWrap' => '<span class="activeLinkWrap">|</span>'
466 ); */
467
468 // Initializing variables:
469 $pointer = intval($this->piVars[$pointerName]);
470 $count = intval($this->internal['res_count']);
471 $results_at_a_time = t3lib_div::intInRange($this->internal['results_at_a_time'],1,1000);
472 $totalPages = ceil($count/$results_at_a_time);
473 $maxPages = t3lib_div::intInRange($this->internal['maxPages'],1,100);
474 $pi_isOnlyFields = $this->pi_isOnlyFields($this->pi_isOnlyFields);
475
476 // $showResultCount determines how the results of the pagerowser will be shown.
477 // If set to 0: only the result-browser will be shown
478 // 1: (default) the text "Displaying results..." and the result-browser will be shown.
479 // 2: only the text "Displaying results..." will be shown
480 $showResultCount = intval($showResultCount);
481
482 // if this is set, two links named "<< First" and "LAST >>" will be shown and point to the very first or last page.
483 $showFirstLast = $this->internal['showFirstLast'];
484
485 // if this has a value the "previous" button is always visible (will be forced if "showFirstLast" is set)
486 $alwaysPrev = $showFirstLast?1:$this->pi_alwaysPrev;
487
488 if (isset($this->internal['pagefloat'])) {
489 if (strtoupper($this->internal['pagefloat']) == 'CENTER') {
490 $pagefloat = ceil(($maxPages - 1)/2);
491 } else {
492 // pagefloat set as integer. 0 = left, value >= $this->internal['maxPages'] = right
493 $pagefloat = t3lib_div::intInRange($this->internal['pagefloat'],-1,$maxPages-1);
494 }
495 } else {
496 $pagefloat = -1; // pagefloat disabled
497 }
498
499 // default values for "traditional" wrapping with a table. Can be overwritten by vars from $wrapArr
500 $wrapper['disabledLinkWrap'] = '<td nowrap="nowrap"><p>|</p></td>';
501 $wrapper['inactiveLinkWrap'] = '<td nowrap="nowrap"><p>|</p></td>';
502 $wrapper['activeLinkWrap'] = '<td'.$this->pi_classParam('browsebox-SCell').' nowrap="nowrap"><p>|</p></td>';
503 $wrapper['browseLinksWrap'] = trim('<table '.$tableParams).'><tr>|</tr></table>';
504 $wrapper['showResultsWrap'] = '<p>|</p>';
505 $wrapper['browseBoxWrap'] = '
506 <!--
507 List browsing box:
508 -->
509 <div '.$this->pi_classParam('browsebox').'>
510 |
511 </div>';
512
513 // now overwrite all entries in $wrapper which are also in $wrapArr
514 $wrapper = array_merge($wrapper,$wrapArr);
515
516 if ($showResultCount != 2) { //show pagebrowser
517 if ($pagefloat > -1) {
518 $lastPage = min($totalPages,max($pointer+1 + $pagefloat,$maxPages));
519 $firstPage = max(0,$lastPage-$maxPages);
520 } else {
521 $firstPage = 0;
522 $lastPage = t3lib_div::intInRange($totalPages,1,$maxPages);
523 }
524 $links=array();
525
526 // Make browse-table/links:
527 if ($showFirstLast) { // Link to first page
528 if ($pointer>0) {
529 $links[]=$this->cObj->wrap($this->pi_linkTP_keepPIvars($this->pi_getLL('pi_list_browseresults_first','<< First',$hscText),array($pointerName => null),$pi_isOnlyFields),$wrapper['inactiveLinkWrap']);
530 } else {
531 $links[]=$this->cObj->wrap($this->pi_getLL('pi_list_browseresults_first','<< First',$hscText),$wrapper['disabledLinkWrap']);
532 }
533 }
534 if ($alwaysPrev>=0) { // Link to previous page
535 if ($pointer>0) {
536 $links[]=$this->cObj->wrap($this->pi_linkTP_keepPIvars($this->pi_getLL('pi_list_browseresults_prev','< Previous',$hscText),array($pointerName => ($pointer-1?$pointer-1:'')),$pi_isOnlyFields),$wrapper['inactiveLinkWrap']);
537 } elseif ($alwaysPrev) {
538 $links[]=$this->cObj->wrap($this->pi_getLL('pi_list_browseresults_prev','< Previous',$hscText),$wrapper['disabledLinkWrap']);
539 }
540 }
541 for($a=$firstPage;$a<$lastPage;$a++) { // Links to pages
542 if ($this->internal['showRange']) {
543 $pageText = (($a*$results_at_a_time)+1).'-'.min($count,(($a+1)*$results_at_a_time));
544 } else {
545 $pageText = trim($this->pi_getLL('pi_list_browseresults_page','Page',$hscText).' '.($a+1));
546 }
547 if ($pointer == $a) { // current page
548 if ($this->internal['dontLinkActivePage']) {
549 $links[] = $this->cObj->wrap($pageText,$wrapper['activeLinkWrap']);
550 } else {
551 $links[] = $this->cObj->wrap($this->pi_linkTP_keepPIvars($pageText,array($pointerName => ($a?$a:'')),$pi_isOnlyFields),$wrapper['activeLinkWrap']);
552 }
553 } else {
554 $links[] = $this->cObj->wrap($this->pi_linkTP_keepPIvars($pageText,array($pointerName => ($a?$a:'')),$pi_isOnlyFields),$wrapper['inactiveLinkWrap']);
555 }
556 }
557 if ($pointer<$totalPages-1 || $showFirstLast) {
558 if ($pointer==$totalPages-1) { // Link to next page
559 $links[]=$this->cObj->wrap($this->pi_getLL('pi_list_browseresults_next','Next >',$hscText),$wrapper['disabledLinkWrap']);
560 } else {
561 $links[]=$this->cObj->wrap($this->pi_linkTP_keepPIvars($this->pi_getLL('pi_list_browseresults_next','Next >',$hscText),array($pointerName => $pointer+1),$pi_isOnlyFields),$wrapper['inactiveLinkWrap']);
562 }
563 }
564 if ($showFirstLast) { // Link to last page
565 if ($pointer<$totalPages-1) {
566 $links[]=$this->cObj->wrap($this->pi_linkTP_keepPIvars($this->pi_getLL('pi_list_browseresults_last','Last >>',$hscText),array($pointerName => $totalPages-1),$pi_isOnlyFields),$wrapper['inactiveLinkWrap']);
567 } else {
568 $links[]=$this->cObj->wrap($this->pi_getLL('pi_list_browseresults_last','Last >>',$hscText),$wrapper['disabledLinkWrap']);
569 }
570 }
571 $theLinks = $this->cObj->wrap(implode(chr(10),$links),$wrapper['browseLinksWrap']);
572 } else {
573 $theLinks = '';
574 }
575
576 $pR1 = $pointer*$results_at_a_time+1;
577 $pR2 = $pointer*$results_at_a_time+$results_at_a_time;
578
579 if ($showResultCount) {
580 if ($wrapper['showResultsNumbersWrap']) {
581 // this will render the resultcount in a more flexible way using markers (new in TYPO3 3.8.0).
582 // the formatting string is expected to hold template markers (see function header). Example: 'Displaying results ###FROM### to ###TO### out of ###OUT_OF###'
583
584 $markerArray['###FROM###'] = $this->cObj->wrap($this->internal['res_count'] > 0 ? $pR1 : 0,$wrapper['showResultsNumbersWrap']);
585 $markerArray['###TO###'] = $this->cObj->wrap(min($this->internal['res_count'],$pR2),$wrapper['showResultsNumbersWrap']);
586 $markerArray['###OUT_OF###'] = $this->cObj->wrap($this->internal['res_count'],$wrapper['showResultsNumbersWrap']);
587 $markerArray['###FROM_TO###'] = $this->cObj->wrap(($this->internal['res_count'] > 0 ? $pR1 : 0).' '.$this->pi_getLL('pi_list_browseresults_to','to').' '.min($this->internal['res_count'],$pR2),$wrapper['showResultsNumbersWrap']);
588 $markerArray['###CURRENT_PAGE###'] = $this->cObj->wrap($pointer+1,$wrapper['showResultsNumbersWrap']);
589 $markerArray['###TOTAL_PAGES###'] = $this->cObj->wrap($totalPages,$wrapper['showResultsNumbersWrap']);
590 // substitute markers
591 $resultCountMsg = $this->cObj->substituteMarkerArray($this->pi_getLL('pi_list_browseresults_displays','Displaying results ###FROM### to ###TO### out of ###OUT_OF###'),$markerArray);
592 } else {
593 // render the resultcount in the "traditional" way using sprintf
594 $resultCountMsg = sprintf(
595 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>')),
596 $count > 0 ? $pR1 : 0,
597 min($count,$pR2),
598 $count);
599 }
600 $resultCountMsg = $this->cObj->wrap($resultCountMsg,$wrapper['showResultsWrap']);
601 } else {
602 $resultCountMsg = '';
603 }
604
605 $sTables = $this->cObj->wrap($resultCountMsg.$theLinks,$wrapper['browseBoxWrap']);
606
607 return $sTables;
608 }
609
610 /**
611 * Returns a Search box, sending search words to piVars "sword" and setting the "no_cache" parameter as well in the form.
612 * Submits the search request to the current REQUEST_URI
613 *
614 * @param string Attributes for the table tag which is wrapped around the table cells containing the search box
615 * @return string Output HTML, wrapped in <div>-tags with a class attribute
616 */
617 function pi_list_searchBox($tableParams='') {
618 // Search box design:
619 $sTables = '
620
621 <!--
622 List search box:
623 -->
624 <div'.$this->pi_classParam('searchbox').'>
625 <form action="'.htmlspecialchars(t3lib_div::getIndpEnv('REQUEST_URI')).'" method="post" style="margin: 0 0 0 0;">
626 <'.trim('table '.$tableParams).'>
627 <tr>
628 <td><input type="text" name="'.$this->prefixId.'[sword]" value="'.htmlspecialchars($this->piVars['sword']).'"'.$this->pi_classParam('searchbox-sword').' /></td>
629 <td><input type="submit" value="'.$this->pi_getLL('pi_list_searchBox_search','Search',TRUE).'"'.$this->pi_classParam('searchbox-button').' />'.
630 '<input type="hidden" name="no_cache" value="1" />'.
631 '<input type="hidden" name="'.$this->prefixId.'[pointer]" value="" />'.
632 '</td>
633 </tr>
634 </table>
635 </form>
636 </div>';
637
638 return $sTables;
639 }
640
641 /**
642 * Returns a mode selector; a little menu in a table normally put in the top of the page/list.
643 *
644 * @param array Key/Value pairs for the menu; keys are the piVars[mode] values and the "values" are the labels for them.
645 * @param string Attributes for the table tag which is wrapped around the table cells containing the menu
646 * @return string Output HTML, wrapped in <div>-tags with a class attribute
647 */
648 function pi_list_modeSelector($items=array(),$tableParams='') {
649 $cells=array();
650 reset($items);
651 while(list($k,$v)=each($items)) {
652 $cells[]='
653 <td'.($this->piVars['mode']==$k?$this->pi_classParam('modeSelector-SCell'):'').'><p>'.
654 $this->pi_linkTP_keepPIvars(htmlspecialchars($v),array('mode'=>$k),$this->pi_isOnlyFields($this->pi_isOnlyFields)).
655 '</p></td>';
656 }
657
658 $sTables = '
659
660 <!--
661 Mode selector (menu for list):
662 -->
663 <div'.$this->pi_classParam('modeSelector').'>
664 <'.trim('table '.$tableParams).'>
665 <tr>
666 '.implode('',$cells).'
667 </tr>
668 </table>
669 </div>';
670
671 return $sTables;
672 }
673
674 /**
675 * Returns the list of items based on the input SQL result pointer
676 * For each result row the internal var, $this->internal['currentRow'], is set with the row returned.
677 * $this->pi_list_header() makes the header row for the list
678 * $this->pi_list_row() is used for rendering each row
679 * 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.
680 *
681 * @param pointer Result pointer to a SQL result which can be traversed.
682 * @param string Attributes for the table tag which is wrapped around the table rows containing the list
683 * @return string Output HTML, wrapped in <div>-tags with a class attribute
684 * @see pi_list_row(), pi_list_header()
685 */
686 function pi_list_makelist($res,$tableParams='') {
687 // Make list table header:
688 $tRows=array();
689 $this->internal['currentRow']='';
690 $tRows[] = $this->pi_list_header();
691
692 // Make list table rows
693 $c=0;
694 while($this->internal['currentRow'] = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
695 $tRows[] = $this->pi_list_row($c);
696 $c++;
697 }
698
699 $out = '
700
701 <!--
702 Record list:
703 -->
704 <div'.$this->pi_classParam('listrow').'>
705 <'.trim('table '.$tableParams).'>
706 '.implode('',$tRows).'
707 </table>
708 </div>';
709
710 return $out;
711 }
712
713 /**
714 * Returns a list row. Get data from $this->internal['currentRow'];
715 * (Dummy)
716 * 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.
717 *
718 * @param integer Row counting. Starts at 0 (zero). Used for alternating class values in the output rows.
719 * @return string HTML output, a table row with a class attribute set (alternative based on odd/even rows)
720 */
721 function pi_list_row($c) {
722 // Dummy
723 return '<tr'.($c%2 ? $this->pi_classParam('listrow-odd') : '').'><td><p>[dummy row]</p></td></tr>';
724 }
725
726 /**
727 * Returns a list header row.
728 * (Dummy)
729 * 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.
730 *
731 * @return string HTML output, a table row with a class attribute set
732 */
733 function pi_list_header() {
734 return '<tr'.$this->pi_classParam('listrow-header').'><td><p>[dummy header row]</p></td></tr>';
735 }
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751 /***************************
752 *
753 * Stylesheet, CSS
754 *
755 **************************/
756
757
758 /**
759 * Returns a class-name prefixed with $this->prefixId and with all underscores substituted to dashes (-)
760 *
761 * @param string The class name (or the END of it since it will be prefixed by $this->prefixId.'-')
762 * @return string The combined class name (with the correct prefix)
763 */
764 function pi_getClassName($class) {
765 return str_replace('_','-',$this->prefixId).($this->prefixId?'-':'').$class;
766 }
767
768 /**
769 * Returns the class-attribute with the correctly prefixed classname
770 * Using pi_getClassName()
771 *
772 * @param string The class name (suffix)
773 * @return string A "class" attribute with value and a single space char before it.
774 * @see pi_getClassName()
775 */
776 function pi_classParam($class) {
777 return ' class="'.$this->pi_getClassName($class).'"';
778 }
779
780 /**
781 * Sets CSS style-data for the $class-suffix (prefixed by pi_getClassName())
782 *
783 * @param string $class: Class suffix, see pi_getClassName
784 * @param string $data: CSS data
785 * @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
786 * @return void
787 * @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.
788 * @private
789 */
790 function pi_setClassStyle($class,$data,$selector='') {
791 $GLOBALS['TSFE']->setCSS($this->pi_getClassName($class).($selector?' '.$selector:''),'.'.$this->pi_getClassName($class).($selector?' '.$selector:'').' {'.$data.'}');
792 }
793
794 /**
795 * Wraps the input string in a <div> tag with the class attribute set to the prefixId.
796 * 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.
797 *
798 * @param string HTML content to wrap in the div-tags with the "main class" of the plugin
799 * @return string HTML content wrapped, ready to return to the parent object.
800 */
801 function pi_wrapInBaseClass($str) {
802 $content = '<div class="'.str_replace('_','-',$this->prefixId).'">
803 '.$str.'
804 </div>
805 ';
806
807 if(!$GLOBALS['TSFE']->config['config']['disablePrefixComment']) {
808 $content = '
809
810
811 <!--
812
813 BEGIN: Content of extension "'.$this->extKey.'", plugin "'.$this->prefixId.'"
814
815 -->
816 '.$content.'
817 <!-- END: Content of extension "'.$this->extKey.'", plugin "'.$this->prefixId.'" -->
818
819 ';
820 }
821
822 return $content;
823 }
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841 /***************************
842 *
843 * Frontend editing: Edit panel, edit icons
844 *
845 **************************/
846
847 /**
848 * Returns the Backend User edit panel for the $row from $tablename
849 *
850 * @param array Record array.
851 * @param string Table name
852 * @param string A label to show with the panel.
853 * @param array TypoScript parameters to pass along to the EDITPANEL content Object that gets rendered. The property "allow" WILL get overridden/set though.
854 * @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).
855 * @see tslib_cObj::EDITPANEL()
856 */
857 function pi_getEditPanel($row='',$tablename='',$label='',$conf=Array()) {
858 $panel='';
859 if (!$row || !$tablename) {
860 $row = $this->internal['currentRow'];
861 $tablename = $this->internal['currentTable'];
862 }
863
864 if ($GLOBALS['TSFE']->beUserLogin) {
865 // Create local cObj if not set:
866 if (!is_object($this->pi_EPtemp_cObj)) {
867 $this->pi_EPtemp_cObj = t3lib_div::makeInstance('tslib_cObj');
868 $this->pi_EPtemp_cObj->setParent($this->cObj->data,$this->cObj->currentRecord);
869 }
870
871 // Initialize the cObj object with current row
872 $this->pi_EPtemp_cObj->start($row,$tablename);
873
874 // Setting TypoScript values in the $conf array. See documentation in TSref for the EDITPANEL cObject.
875 $conf['allow'] = 'edit,new,delete,move,hide';
876 $panel = $this->pi_EPtemp_cObj->cObjGetSingle('EDITPANEL',$conf,'editpanel');
877 }
878
879 if ($panel) {
880 if ($label) {
881 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 -->';
882 } else return '<!-- BEGIN: EDIT PANEL -->'.$panel.'<!-- END: EDIT PANEL -->';
883 } else return $label;
884 }
885
886 /**
887 * Adds edit-icons to the input content.
888 * tslib_cObj::editIcons used for rendering
889 *
890 * @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)
891 * @param string The list of fields to edit when the icon is clicked.
892 * @param string Title for the edit icon.
893 * @param array Table record row
894 * @param string Table name
895 * @param array Conf array
896 * @return string The processed content
897 * @see tslib_cObj::editIcons()
898 */
899 function pi_getEditIcon($content,$fields,$title='',$row='',$tablename='',$oConf=array()) {
900 if ($GLOBALS['TSFE']->beUserLogin){
901 if (!$row || !$tablename) {
902 $row = $this->internal['currentRow'];
903 $tablename = $this->internal['currentTable'];
904 }
905 $conf=array_merge(array(
906 'beforeLastTag'=>1,
907 'iconTitle' => $title
908 ),$oConf);
909 $content=$this->cObj->editIcons($content,$tablename.':'.$fields,$conf,$tablename.':'.$row['uid'],$row,'&viewUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI')));
910 }
911 return $content;
912 }
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930 /***************************
931 *
932 * Localization, locallang functions
933 *
934 **************************/
935
936
937 /**
938 * Returns the localized label of the LOCAL_LANG key, $key
939 * Notice that for debugging purposes prefixes for the output values can be set with the internal vars ->LLtestPrefixAlt and ->LLtestPrefix
940 *
941 * @param string The key from the LOCAL_LANG array for which to return the value.
942 * @param string Alternative string to return IF no value is found set for the key, neither for the local language nor the default.
943 * @param boolean If true, the output label is passed through htmlspecialchars()
944 * @return string The value from LOCAL_LANG.
945 */
946 function pi_getLL($key,$alt='',$hsc=FALSE) {
947 if (isset($this->LOCAL_LANG[$this->LLkey][$key])) {
948 $word = $GLOBALS['TSFE']->csConv($this->LOCAL_LANG[$this->LLkey][$key], $this->LOCAL_LANG_charset[$this->LLkey][$key]); // The "from" charset is normally empty and thus it will convert from the charset of the system language, but if it is set (see ->pi_loadLL()) it will be used.
949 } elseif ($this->altLLkey && isset($this->LOCAL_LANG[$this->altLLkey][$key])) {
950 $word = $GLOBALS['TSFE']->csConv($this->LOCAL_LANG[$this->altLLkey][$key], $this->LOCAL_LANG_charset[$this->altLLkey][$key]); // The "from" charset is normally empty and thus it will convert from the charset of the system language, but if it is set (see ->pi_loadLL()) it will be used.
951 } elseif (isset($this->LOCAL_LANG['default'][$key])) {
952 $word = $this->LOCAL_LANG['default'][$key]; // No charset conversion because default is english and thereby ASCII
953 } else {
954 $word = $this->LLtestPrefixAlt.$alt;
955 }
956
957 $output = $this->LLtestPrefix.$word;
958 if ($hsc) $output = htmlspecialchars($output);
959
960 return $output;
961 }
962
963 /**
964 * Loads local-language values by looking for a "locallang.php" file in the plugin class directory ($this->scriptRelPath) and if found includes it.
965 * Also locallang values set in the TypoScript property "_LOCAL_LANG" are merged onto the values found in the "locallang.php" file.
966 *
967 * @return void
968 */
969 function pi_loadLL() {
970 if (!$this->LOCAL_LANG_loaded && $this->scriptRelPath) {
971 $basePath = t3lib_extMgm::extPath($this->extKey).dirname($this->scriptRelPath).'/locallang.php';
972
973 // php or xml as source: In any case the charset will be that of the system language.
974 // However, this function guarantees only return output for default language plus the specified language (which is different from how 3.7.0 dealt with it)
975 $this->LOCAL_LANG = t3lib_div::readLLfile($basePath,$this->LLkey);
976 if ($this->altLLkey) {
977 $tempLOCAL_LANG = t3lib_div::readLLfile($basePath,$this->altLLkey);
978 $this->LOCAL_LANG = array_merge(is_array($this->LOCAL_LANG) ? $this->LOCAL_LANG : array(),$tempLOCAL_LANG);
979 }
980
981 // Overlaying labels from TypoScript (including fictitious language keys for non-system languages!):
982 if (is_array($this->conf['_LOCAL_LANG.'])) {
983 reset($this->conf['_LOCAL_LANG.']);
984 while(list($k,$lA)=each($this->conf['_LOCAL_LANG.'])) {
985 if (is_array($lA)) {
986 $k = substr($k,0,-1);
987 foreach($lA as $llK => $llV) {
988 if (!is_array($llV)) {
989 $this->LOCAL_LANG[$k][$llK] = $llV;
990 if ($k != 'default') {
991 $this->LOCAL_LANG_charset[$k][$llK] = $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset']; // For labels coming from the TypoScript (database) the charset is assumed to be "forceCharset" and if that is not set, assumed to be that of the individual system languages (thus no conversion)
992 }
993 }
994 }
995 }
996 }
997 }
998 }
999 $this->LOCAL_LANG_loaded = 1;
1000 }
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024 /***************************
1025 *
1026 * Database, queries
1027 *
1028 **************************/
1029
1030 /**
1031 * 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'])
1032 * Set $count to 1 if you wish to get a count(*) query for selecting the number of results.
1033 * Notice that the query will use $this->conf['pidList'] and $this->conf['recursive'] to generate a PID list within which to search for records.
1034 *
1035 * @param string See pi_exec_query()
1036 * @param boolean See pi_exec_query()
1037 * @param string See pi_exec_query()
1038 * @param mixed See pi_exec_query()
1039 * @param string See pi_exec_query()
1040 * @param string See pi_exec_query()
1041 * @param string See pi_exec_query()
1042 * @param boolean If set, the function will return the query not as a string but array with the various parts.
1043 * @return mixed The query build.
1044 * @access private
1045 * @depreciated Use pi_exec_query() instead!
1046 */
1047 function pi_list_query($table,$count=0,$addWhere='',$mm_cat='',$groupBy='',$orderBy='',$query='',$returnQueryArray=FALSE) {
1048
1049 // Begin Query:
1050 if (!$query) {
1051 // Fetches the list of PIDs to select from.
1052 // TypoScript property .pidList is a comma list of pids. If blank, current page id is used.
1053 // 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.
1054 $pidList = $this->pi_getPidList($this->conf['pidList'],$this->conf['recursive']);
1055 if (is_array($mm_cat)) {
1056 $query='FROM '.$table.','.$mm_cat['table'].','.$mm_cat['mmtable'].chr(10).
1057 ' WHERE '.$table.'.uid='.$mm_cat['mmtable'].'.uid_local AND '.$mm_cat['table'].'.uid='.$mm_cat['mmtable'].'.uid_foreign '.chr(10).
1058 (strcmp($mm_cat['catUidList'],'')?' AND '.$mm_cat['table'].'.uid IN ('.$mm_cat['catUidList'].')':'').chr(10).
1059 ' AND '.$table.'.pid IN ('.$pidList.')'.chr(10).
1060 $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!
1061 } else {
1062 $query='FROM '.$table.' WHERE pid IN ('.$pidList.')'.chr(10).
1063 $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!
1064 }
1065 }
1066
1067 // Split the "FROM ... WHERE" string so we get the WHERE part and TABLE names separated...:
1068 list($TABLENAMES,$WHERE) = spliti('WHERE', trim($query), 2);
1069 $TABLENAMES = trim(substr(trim($TABLENAMES),5));
1070 $WHERE = trim($WHERE);
1071
1072 // Add '$addWhere'
1073 if ($addWhere) {$WHERE.=' '.$addWhere.chr(10);}
1074
1075 // Search word:
1076 if ($this->piVars['sword'] && $this->internal['searchFieldList']) {
1077 $WHERE.=$this->cObj->searchWhere($this->piVars['sword'],$this->internal['searchFieldList'],$table).chr(10);
1078 }
1079
1080 if ($count) {
1081 $queryParts = array(
1082 'SELECT' => 'count(*)',
1083 'FROM' => $TABLENAMES,
1084 'WHERE' => $WHERE,
1085 'GROUPBY' => '',
1086 'ORDERBY' => '',
1087 'LIMIT' => ''
1088 );
1089 } else {
1090 // Order by data:
1091 if (!$orderBy && $this->internal['orderBy']) {
1092 if (t3lib_div::inList($this->internal['orderByList'],$this->internal['orderBy'])) {
1093 $orderBy = 'ORDER BY '.$table.'.'.$this->internal['orderBy'].($this->internal['descFlag']?' DESC':'');
1094 }
1095 }
1096
1097 // Limit data:
1098 $pointer = $this->piVars['pointer'];
1099 $pointer = intval($pointer);
1100 $results_at_a_time = t3lib_div::intInRange($this->internal['results_at_a_time'],1,1000);
1101 $LIMIT = ($pointer*$results_at_a_time).','.$results_at_a_time;
1102
1103 // Add 'SELECT'
1104 $queryParts = array(
1105 'SELECT' => $this->pi_prependFieldsWithTable($table,$this->pi_listFields),
1106 'FROM' => $TABLENAMES,
1107 'WHERE' => $WHERE,
1108 'GROUPBY' => $GLOBALS['TYPO3_DB']->stripGroupBy($groupBy),
1109 'ORDERBY' => $GLOBALS['TYPO3_DB']->stripOrderBy($orderBy),
1110 'LIMIT' => $LIMIT
1111 );
1112 }
1113
1114 $query = $GLOBALS['TYPO3_DB']->SELECTquery (
1115 $queryParts['SELECT'],
1116 $queryParts['FROM'],
1117 $queryParts['WHERE'],
1118 $queryParts['GROUPBY'],
1119 $queryParts['ORDERBY'],
1120 $queryParts['LIMIT']
1121 );
1122 return $returnQueryArray ? $queryParts : $query;
1123 }
1124
1125 /**
1126 * 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'])
1127 * Set $count to 1 if you wish to get a count(*) query for selecting the number of results.
1128 * Notice that the query will use $this->conf['pidList'] and $this->conf['recursive'] to generate a PID list within which to search for records.
1129 *
1130 * @param string The table name to make the query for.
1131 * @param boolean If set, you will get a "count(*)" query back instead of field selecting
1132 * @param string Additional WHERE clauses (should be starting with " AND ....")
1133 * @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.
1134 * @param string If set, this is added as a " GROUP BY ...." part of the query.
1135 * @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']
1136 * @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!
1137 * @return pointer SQL result pointer
1138 */
1139 function pi_exec_query($table,$count=0,$addWhere='',$mm_cat='',$groupBy='',$orderBy='',$query='') {
1140 $queryParts = $this->pi_list_query($table,$count,$addWhere,$mm_cat,$groupBy,$orderBy,$query, TRUE);
1141
1142 return $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
1143 }
1144
1145 /**
1146 * Returns the row $uid from $table
1147 * (Simply calling $GLOBALS['TSFE']->sys_page->checkRecord())
1148 *
1149 * @param string The table name
1150 * @param integer The uid of the record from the table
1151 * @param boolean If $checkPage is set, it's required that the page on which the record resides is accessible
1152 * @return array If record is found, an array. Otherwise false.
1153 */
1154 function pi_getRecord($table,$uid,$checkPage=0) {
1155 return $GLOBALS['TSFE']->sys_page->checkRecord($table,$uid,$checkPage);
1156 }
1157
1158 /**
1159 * Returns a commalist of page ids for a query (eg. 'WHERE pid IN (...)')
1160 *
1161 * @param string $pid_list is a comma list of page ids (if empty current page is used)
1162 * @param integer $recursive is an integer >=0 telling how deep to dig for pids under each entry in $pid_list
1163 * @return string List of PID values (comma separated)
1164 */
1165 function pi_getPidList($pid_list,$recursive=0) {
1166 if (!strcmp($pid_list,'')) $pid_list = $GLOBALS['TSFE']->id;
1167 $recursive = t3lib_div::intInRange($recursive,0);
1168
1169 $pid_list_arr = array_unique(t3lib_div::trimExplode(',',$pid_list,1));
1170 $pid_list = array();
1171
1172 foreach($pid_list_arr as $val) {
1173 $val = t3lib_div::intInRange($val,0);
1174 if ($val) {
1175 $_list = $this->cObj->getTreeList(-1*$val, $recursive);
1176 if ($_list) $pid_list[] = $_list;
1177 }
1178 }
1179
1180 return implode(',', $pid_list);
1181 }
1182
1183 /**
1184 * Having a comma list of fields ($fieldList) this is prepended with the $table.'.' name
1185 *
1186 * @param string Table name to prepend
1187 * @param string List of fields where each element will be prepended with the table name given.
1188 * @return string List of fields processed.
1189 */
1190 function pi_prependFieldsWithTable($table,$fieldList) {
1191 $list=t3lib_div::trimExplode(',',$fieldList,1);
1192 $return=array();
1193 while(list(,$listItem)=each($list)) {
1194 $return[]=$table.'.'.$listItem;
1195 }
1196 return implode(',',$return);
1197 }
1198
1199 /**
1200 * Will select all records from the "category table", $table, and return them in an array.
1201 *
1202 * @param string The name of the category table to select from.
1203 * @param integer The page from where to select the category records.
1204 * @param string Optional additional WHERE clauses put in the end of the query. DO NOT PUT IN GROUP BY, ORDER BY or LIMIT!
1205 * @param string Optional GROUP BY field(s), if none, supply blank string.
1206 * @param string Optional ORDER BY field(s), if none, supply blank string.
1207 * @param string Optional LIMIT value ([begin,]max), if none, supply blank string.
1208 * @return array The array with the category records in.
1209 */
1210 function pi_getCategoryTableContents($table,$pid,$whereClause='',$groupBy='',$orderBy='',$limit='') {
1211 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
1212 '*',
1213 $table,
1214 'pid='.intval($pid).
1215 $this->cObj->enableFields($table).' '.
1216 $whereClause, // whereClauseMightContainGroupOrderBy
1217 $groupBy,
1218 $orderBy,
1219 $limit
1220 );
1221 $outArr = array();
1222 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
1223 $outArr[$row['uid']] = $row;
1224 }
1225 $GLOBALS['TYPO3_DB']->sql_free_result($res);
1226 return $outArr;
1227 }
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240 /***************************
1241 *
1242 * Various
1243 *
1244 **************************/
1245
1246 /**
1247 * 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.
1248 * Notice that this function will only work as long as values are integers.
1249 *
1250 * @param string List of fields (keys from piVars) to evaluate on
1251 * @param integer Limit for the values.
1252 * @return boolean Returns true (1) if conditions are met.
1253 */
1254 function pi_isOnlyFields($fList,$lowerThan=-1) {
1255 $lowerThan = $lowerThan==-1 ? $this->pi_lowerThan : $lowerThan;
1256
1257 $fList = t3lib_div::trimExplode(',',$fList,1);
1258 $tempPiVars = $this->piVars;
1259 while(list(,$k)=each($fList)) {
1260 if (!t3lib_div::testInt($tempPiVars[$k]) || $tempPiVars[$k]<$lowerThan) unset($tempPiVars[$k]);
1261 }
1262 if (!count($tempPiVars)) return 1;
1263 }
1264
1265 /**
1266 * Returns true if the array $inArray contains only values allowed to be cached based on the configuration in $this->pi_autoCacheFields
1267 * Used by ->pi_linkTP_keepPIvars
1268 * This is an advanced form of evaluation of whether a URL should be cached or not.
1269 *
1270 * @param array An array with piVars values to evaluate
1271 * @return boolean Returns true (1) if conditions are met.
1272 * @see pi_linkTP_keepPIvars()
1273 */
1274 function pi_autoCache($inArray) {
1275 if (is_array($inArray)) {
1276 reset($inArray);
1277 while(list($fN,$fV)=each($inArray)) {
1278 if (!strcmp($inArray[$fN],'')) {
1279 unset($inArray[$fN]);
1280 } elseif (is_array($this->pi_autoCacheFields[$fN])) {
1281 if (is_array($this->pi_autoCacheFields[$fN]['range'])
1282 && intval($inArray[$fN])>=intval($this->pi_autoCacheFields[$fN]['range'][0])
1283 && intval($inArray[$fN])<=intval($this->pi_autoCacheFields[$fN]['range'][1])) {
1284 unset($inArray[$fN]);
1285 }
1286 if (is_array($this->pi_autoCacheFields[$fN]['list'])
1287 && in_array($inArray[$fN],$this->pi_autoCacheFields[$fN]['list'])) {
1288 unset($inArray[$fN]);
1289 }
1290 }
1291 }
1292 }
1293 if (!count($inArray)) return 1;
1294 }
1295
1296 /**
1297 * 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.
1298 * This is useful for rendering of content in RTE fields where the transformation mode is set to "ts_css" or so.
1299 * Notice that this requires the use of "css_styled_content" to work right.
1300 *
1301 * @param string The input text string to process
1302 * @return string The processed string
1303 * @see tslib_cObj::parseFunc()
1304 */
1305 function pi_RTEcssText($str) {
1306 $parseFunc = $GLOBALS['TSFE']->tmpl->setup['lib.']['parseFunc_RTE.'];
1307 if (is_array($parseFunc)) $str = $this->cObj->parseFunc($str, $parseFunc);
1308 return $str;
1309 }
1310
1311
1312
1313
1314
1315 /*******************************
1316 *
1317 * FlexForms related functions
1318 *
1319 *******************************/
1320
1321 /**
1322 * Converts $this->cObj->data['pi_flexform'] from XML string to flexForm array.
1323 *
1324 * @return void
1325 */
1326 function pi_initPIflexForm() {
1327 // Converting flexform data into array:
1328 if (!is_array($this->cObj->data['pi_flexform']) && $this->cObj->data['pi_flexform']) {
1329 $this->cObj->data['pi_flexform'] = t3lib_div::xml2array($this->cObj->data['pi_flexform']);
1330 if (!is_array($this->cObj->data['pi_flexform'])) $this->cObj->data['pi_flexform']=array();
1331 }
1332 }
1333
1334 /**
1335 * Return value from somewhere inside a FlexForm structure
1336 *
1337 * @param array FlexForm data
1338 * @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.
1339 * @param string Sheet pointer, eg. "sDEF"
1340 * @param string Language pointer, eg. "lDEF"
1341 * @param string Value pointer, eg. "vDEF"
1342 * @return string The content.
1343 */
1344 function pi_getFFvalue($T3FlexForm_array,$fieldName,$sheet='sDEF',$lang='lDEF',$value='vDEF') {
1345 $sheetArray = is_array($T3FlexForm_array) ? $T3FlexForm_array['data'][$sheet][$lang] : '';
1346 if (is_array($sheetArray)) {
1347 return $this->pi_getFFvalueFromSheetArray($sheetArray,explode('/',$fieldName),$value);
1348 }
1349 }
1350
1351 /**
1352 * Returns part of $sheetArray pointed to by the keys in $fieldNameArray
1353 *
1354 * @param array Multidimensiona array, typically FlexForm contents
1355 * @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...)
1356 * @param string Value for outermost key, typ. "vDEF" depending on language.
1357 * @return mixed The value, typ. string.
1358 * @access private
1359 * @see pi_getFFvalue()
1360 */
1361 function pi_getFFvalueFromSheetArray($sheetArray,$fieldNameArr,$value) {
1362
1363 $tempArr=$sheetArray;
1364 foreach($fieldNameArr as $k => $v) {
1365 if (t3lib_div::testInt($v)) {
1366 if (is_array($tempArr)) {
1367 $c=0;
1368 foreach($tempArr as $values) {
1369 if ($c==$v) {
1370 #debug($values);
1371 $tempArr=$values;
1372 break;
1373 }
1374 $c++;
1375 }
1376 }
1377 } else {
1378 $tempArr = $tempArr[$v];
1379 }
1380 }
1381 return $tempArr[$value];
1382 }
1383 }
1384
1385 // NO extension of class - does not make sense here.
1386 ?>