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