Fixed bug #12420: Log deprecated method calls (to be removed in TYPO3 4.5)
[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::_GPmerged($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 (preg_match('/(.*)(<a[^>]*>)(.*)/i',$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 foreach ($items as $k => $v) {
644 $cells[]='
645 <td'.($this->piVars['mode']==$k?$this->pi_classParam('modeSelector-SCell'):'').'><p>'.
646 $this->pi_linkTP_keepPIvars(htmlspecialchars($v),array('mode'=>$k),$this->pi_isOnlyFields($this->pi_isOnlyFields)).
647 '</p></td>';
648 }
649
650 $sTables = '
651
652 <!--
653 Mode selector (menu for list):
654 -->
655 <div'.$this->pi_classParam('modeSelector').'>
656 <'.trim('table '.$tableParams).'>
657 <tr>
658 '.implode('',$cells).'
659 </tr>
660 </table>
661 </div>';
662
663 return $sTables;
664 }
665
666 /**
667 * Returns the list of items based on the input SQL result pointer
668 * For each result row the internal var, $this->internal['currentRow'], is set with the row returned.
669 * $this->pi_list_header() makes the header row for the list
670 * $this->pi_list_row() is used for rendering each row
671 * 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.
672 *
673 * @param pointer Result pointer to a SQL result which can be traversed.
674 * @param string Attributes for the table tag which is wrapped around the table rows containing the list
675 * @return string Output HTML, wrapped in <div>-tags with a class attribute
676 * @see pi_list_row(), pi_list_header()
677 */
678 function pi_list_makelist($res,$tableParams='') {
679 // Make list table header:
680 $tRows=array();
681 $this->internal['currentRow']='';
682 $tRows[] = $this->pi_list_header();
683
684 // Make list table rows
685 $c=0;
686 while($this->internal['currentRow'] = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
687 $tRows[] = $this->pi_list_row($c);
688 $c++;
689 }
690
691 $out = '
692
693 <!--
694 Record list:
695 -->
696 <div'.$this->pi_classParam('listrow').'>
697 <'.trim('table '.$tableParams).'>
698 '.implode('',$tRows).'
699 </table>
700 </div>';
701
702 return $out;
703 }
704
705 /**
706 * Returns a list row. Get data from $this->internal['currentRow'];
707 * (Dummy)
708 * 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.
709 *
710 * @param integer Row counting. Starts at 0 (zero). Used for alternating class values in the output rows.
711 * @return string HTML output, a table row with a class attribute set (alternative based on odd/even rows)
712 */
713 function pi_list_row($c) {
714 // Dummy
715 return '<tr'.($c%2 ? $this->pi_classParam('listrow-odd') : '').'><td><p>[dummy row]</p></td></tr>';
716 }
717
718 /**
719 * Returns a list header row.
720 * (Dummy)
721 * 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.
722 *
723 * @return string HTML output, a table row with a class attribute set
724 */
725 function pi_list_header() {
726 return '<tr'.$this->pi_classParam('listrow-header').'><td><p>[dummy header row]</p></td></tr>';
727 }
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743 /***************************
744 *
745 * Stylesheet, CSS
746 *
747 **************************/
748
749
750 /**
751 * Returns a class-name prefixed with $this->prefixId and with all underscores substituted to dashes (-)
752 *
753 * @param string The class name (or the END of it since it will be prefixed by $this->prefixId.'-')
754 * @return string The combined class name (with the correct prefix)
755 */
756 function pi_getClassName($class) {
757 return str_replace('_','-',$this->prefixId).($this->prefixId?'-':'').$class;
758 }
759
760 /**
761 * Returns the class-attribute with the correctly prefixed classname
762 * Using pi_getClassName()
763 *
764 * @param string The class name(s) (suffix) - separate multiple classes with commas
765 * @param string Additional class names which should not be prefixed - separate multiple classes with commas
766 * @return string A "class" attribute with value and a single space char before it.
767 * @see pi_getClassName()
768 */
769 function pi_classParam($class, $addClasses='') {
770 $output = '';
771 foreach (t3lib_div::trimExplode(',',$class) as $v) {
772 $output.= ' '.$this->pi_getClassName($v);
773 }
774 foreach (t3lib_div::trimExplode(',',$addClasses) as $v) {
775 $output.= ' '.$v;
776 }
777 return ' class="'.trim($output).'"';
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 * @deprecated since TYPO3 3.6, this function will be removed in TYPO3 4.5, 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 * @obsolete
789 * @private
790 */
791 function pi_setClassStyle($class,$data,$selector='') {
792 t3lib_div::logDeprecatedFunction();
793
794 $GLOBALS['TSFE']->setCSS($this->pi_getClassName($class).($selector?' '.$selector:''),'.'.$this->pi_getClassName($class).($selector?' '.$selector:'').' {'.$data.'}');
795 }
796
797 /**
798 * Wraps the input string in a <div> tag with the class attribute set to the prefixId.
799 * 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.
800 *
801 * @param string HTML content to wrap in the div-tags with the "main class" of the plugin
802 * @return string HTML content wrapped, ready to return to the parent object.
803 */
804 function pi_wrapInBaseClass($str) {
805 $content = '<div class="'.str_replace('_','-',$this->prefixId).'">
806 '.$str.'
807 </div>
808 ';
809
810 if(!$GLOBALS['TSFE']->config['config']['disablePrefixComment']) {
811 $content = '
812
813
814 <!--
815
816 BEGIN: Content of extension "'.$this->extKey.'", plugin "'.$this->prefixId.'"
817
818 -->
819 '.$content.'
820 <!-- END: Content of extension "'.$this->extKey.'", plugin "'.$this->prefixId.'" -->
821
822 ';
823 }
824
825 return $content;
826 }
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844 /***************************
845 *
846 * Frontend editing: Edit panel, edit icons
847 *
848 **************************/
849
850 /**
851 * Returns the Backend User edit panel for the $row from $tablename
852 *
853 * @param array Record array.
854 * @param string Table name
855 * @param string A label to show with the panel.
856 * @param array TypoScript parameters to pass along to the EDITPANEL content Object that gets rendered. The property "allow" WILL get overridden/set though.
857 * @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).
858 * @see tslib_cObj::EDITPANEL()
859 */
860 function pi_getEditPanel($row='',$tablename='',$label='',$conf=Array()) {
861 $panel='';
862 if (!$row || !$tablename) {
863 $row = $this->internal['currentRow'];
864 $tablename = $this->internal['currentTable'];
865 }
866
867 if ($GLOBALS['TSFE']->beUserLogin) {
868 // Create local cObj if not set:
869 if (!is_object($this->pi_EPtemp_cObj)) {
870 $this->pi_EPtemp_cObj = t3lib_div::makeInstance('tslib_cObj');
871 $this->pi_EPtemp_cObj->setParent($this->cObj->data,$this->cObj->currentRecord);
872 }
873
874 // Initialize the cObj object with current row
875 $this->pi_EPtemp_cObj->start($row,$tablename);
876
877 // Setting TypoScript values in the $conf array. See documentation in TSref for the EDITPANEL cObject.
878 $conf['allow'] = 'edit,new,delete,move,hide';
879 $panel = $this->pi_EPtemp_cObj->cObjGetSingle('EDITPANEL',$conf,'editpanel');
880 }
881
882 if ($panel) {
883 if ($label) {
884 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 -->';
885 } else return '<!-- BEGIN: EDIT PANEL -->'.$panel.'<!-- END: EDIT PANEL -->';
886 } else return $label;
887 }
888
889 /**
890 * Adds edit-icons to the input content.
891 * tslib_cObj::editIcons used for rendering
892 *
893 * @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)
894 * @param string The list of fields to edit when the icon is clicked.
895 * @param string Title for the edit icon.
896 * @param array Table record row
897 * @param string Table name
898 * @param array Conf array
899 * @return string The processed content
900 * @see tslib_cObj::editIcons()
901 */
902 function pi_getEditIcon($content,$fields,$title='',$row='',$tablename='',$oConf=array()) {
903 if ($GLOBALS['TSFE']->beUserLogin){
904 if (!$row || !$tablename) {
905 $row = $this->internal['currentRow'];
906 $tablename = $this->internal['currentTable'];
907 }
908 $conf=array_merge(array(
909 'beforeLastTag'=>1,
910 'iconTitle' => $title
911 ),$oConf);
912 $content=$this->cObj->editIcons($content,$tablename.':'.$fields,$conf,$tablename.':'.$row['uid'],$row,'&viewUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI')));
913 }
914 return $content;
915 }
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933 /***************************
934 *
935 * Localization, locallang functions
936 *
937 **************************/
938
939
940 /**
941 * Returns the localized label of the LOCAL_LANG key, $key
942 * Notice that for debugging purposes prefixes for the output values can be set with the internal vars ->LLtestPrefixAlt and ->LLtestPrefix
943 *
944 * @param string The key from the LOCAL_LANG array for which to return the value.
945 * @param string Alternative string to return IF no value is found set for the key, neither for the local language nor the default.
946 * @param boolean If true, the output label is passed through htmlspecialchars()
947 * @return string The value from LOCAL_LANG.
948 */
949 function pi_getLL($key,$alt='',$hsc=FALSE) {
950 // The "from" charset of csConv() is only set for strings from TypoScript via _LOCAL_LANG
951 if (isset($this->LOCAL_LANG[$this->LLkey][$key])) {
952 $word = $GLOBALS['TSFE']->csConv($this->LOCAL_LANG[$this->LLkey][$key], $this->LOCAL_LANG_charset[$this->LLkey][$key]);
953 } elseif ($this->altLLkey && isset($this->LOCAL_LANG[$this->altLLkey][$key])) {
954 $word = $GLOBALS['TSFE']->csConv($this->LOCAL_LANG[$this->altLLkey][$key], $this->LOCAL_LANG_charset[$this->altLLkey][$key]);
955 } elseif (isset($this->LOCAL_LANG['default'][$key])) {
956 $word = $this->LOCAL_LANG['default'][$key]; // No charset conversion because default is english and thereby ASCII
957 } else {
958 $word = $this->LLtestPrefixAlt.$alt;
959 }
960
961 $output = $this->LLtestPrefix.$word;
962 if ($hsc) $output = htmlspecialchars($output);
963
964 return $output;
965 }
966
967 /**
968 * Loads local-language values by looking for a "locallang.php" file in the plugin class directory ($this->scriptRelPath) and if found includes it.
969 * Also locallang values set in the TypoScript property "_LOCAL_LANG" are merged onto the values found in the "locallang.php" file.
970 *
971 * @return void
972 */
973 function pi_loadLL() {
974 if (!$this->LOCAL_LANG_loaded && $this->scriptRelPath) {
975 $basePath = 'EXT:' . $this->extKey . '/' . dirname($this->scriptRelPath) . '/locallang.xml';
976
977 // Read the strings in the required charset (since TYPO3 4.2)
978 $this->LOCAL_LANG = t3lib_div::readLLfile($basePath,$this->LLkey,$GLOBALS['TSFE']->renderCharset);
979 if ($this->altLLkey) {
980 $tempLOCAL_LANG = t3lib_div::readLLfile($basePath,$this->altLLkey);
981 $this->LOCAL_LANG = array_merge(is_array($this->LOCAL_LANG) ? $this->LOCAL_LANG : array(),$tempLOCAL_LANG);
982 }
983
984 // Overlaying labels from TypoScript (including fictitious language keys for non-system languages!):
985 $confLL = $this->conf['_LOCAL_LANG.'];
986 if (is_array($confLL)) {
987 foreach ($confLL as $k => $lA) {
988 if (is_array($lA)) {
989 $k = substr($k,0,-1);
990 foreach($lA as $llK => $llV) {
991 if (!is_array($llV)) {
992 $this->LOCAL_LANG[$k][$llK] = $llV;
993 // 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
994 $this->LOCAL_LANG_charset[$k][$llK] = $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'] ? $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'] : $GLOBALS['TSFE']->csConvObj->charSetArray[$k];
995 }
996 }
997 }
998 }
999 }
1000 }
1001 $this->LOCAL_LANG_loaded = 1;
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 *
1028 * Database, queries
1029 *
1030 **************************/
1031
1032 /**
1033 * 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'])
1034 * Set $count to 1 if you wish to get a count(*) query for selecting the number of results.
1035 * Notice that the query will use $this->conf['pidList'] and $this->conf['recursive'] to generate a PID list within which to search for records.
1036 *
1037 * @param string See pi_exec_query()
1038 * @param boolean See pi_exec_query()
1039 * @param string See pi_exec_query()
1040 * @param mixed See pi_exec_query()
1041 * @param string See pi_exec_query()
1042 * @param string See pi_exec_query()
1043 * @param string See pi_exec_query()
1044 * @param boolean If set, the function will return the query not as a string but array with the various parts.
1045 * @return mixed The query build.
1046 * @access private
1047 * @deprecated since TYPO3 3.6, this function will be removed in TYPO3 4.5, use pi_exec_query() instead!
1048 */
1049 function pi_list_query($table,$count=0,$addWhere='',$mm_cat='',$groupBy='',$orderBy='',$query='',$returnQueryArray=FALSE) {
1050
1051 // Begin Query:
1052 if (!$query) {
1053 // Fetches the list of PIDs to select from.
1054 // TypoScript property .pidList is a comma list of pids. If blank, current page id is used.
1055 // 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.
1056 $pidList = $this->pi_getPidList($this->conf['pidList'],$this->conf['recursive']);
1057 if (is_array($mm_cat)) {
1058 $query='FROM '.$table.','.$mm_cat['table'].','.$mm_cat['mmtable'].chr(10).
1059 ' WHERE '.$table.'.uid='.$mm_cat['mmtable'].'.uid_local AND '.$mm_cat['table'].'.uid='.$mm_cat['mmtable'].'.uid_foreign '.chr(10).
1060 (strcmp($mm_cat['catUidList'],'')?' AND '.$mm_cat['table'].'.uid IN ('.$mm_cat['catUidList'].')':'').chr(10).
1061 ' AND '.$table.'.pid IN ('.$pidList.')'.chr(10).
1062 $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!
1063 } else {
1064 $query='FROM '.$table.' WHERE pid IN ('.$pidList.')'.chr(10).
1065 $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!
1066 }
1067 }
1068
1069 // Split the "FROM ... WHERE" string so we get the WHERE part and TABLE names separated...:
1070 list($TABLENAMES,$WHERE) = spliti('WHERE', trim($query), 2);
1071 $TABLENAMES = trim(substr(trim($TABLENAMES),5));
1072 $WHERE = trim($WHERE);
1073
1074 // Add '$addWhere'
1075 if ($addWhere) {$WHERE.=' '.$addWhere.chr(10);}
1076
1077 // Search word:
1078 if ($this->piVars['sword'] && $this->internal['searchFieldList']) {
1079 $WHERE.=$this->cObj->searchWhere($this->piVars['sword'],$this->internal['searchFieldList'],$table).chr(10);
1080 }
1081
1082 if ($count) {
1083 $queryParts = array(
1084 'SELECT' => 'count(*)',
1085 'FROM' => $TABLENAMES,
1086 'WHERE' => $WHERE,
1087 'GROUPBY' => '',
1088 'ORDERBY' => '',
1089 'LIMIT' => ''
1090 );
1091 } else {
1092 // Order by data:
1093 if (!$orderBy && $this->internal['orderBy']) {
1094 if (t3lib_div::inList($this->internal['orderByList'],$this->internal['orderBy'])) {
1095 $orderBy = 'ORDER BY '.$table.'.'.$this->internal['orderBy'].($this->internal['descFlag']?' DESC':'');
1096 }
1097 }
1098
1099 // Limit data:
1100 $pointer = $this->piVars['pointer'];
1101 $pointer = intval($pointer);
1102 $results_at_a_time = t3lib_div::intInRange($this->internal['results_at_a_time'],1,1000);
1103 $LIMIT = ($pointer*$results_at_a_time).','.$results_at_a_time;
1104
1105 // Add 'SELECT'
1106 $queryParts = array(
1107 'SELECT' => $this->pi_prependFieldsWithTable($table,$this->pi_listFields),
1108 'FROM' => $TABLENAMES,
1109 'WHERE' => $WHERE,
1110 'GROUPBY' => $GLOBALS['TYPO3_DB']->stripGroupBy($groupBy),
1111 'ORDERBY' => $GLOBALS['TYPO3_DB']->stripOrderBy($orderBy),
1112 'LIMIT' => $LIMIT
1113 );
1114 }
1115
1116 $query = $GLOBALS['TYPO3_DB']->SELECTquery (
1117 $queryParts['SELECT'],
1118 $queryParts['FROM'],
1119 $queryParts['WHERE'],
1120 $queryParts['GROUPBY'],
1121 $queryParts['ORDERBY'],
1122 $queryParts['LIMIT']
1123 );
1124 return $returnQueryArray ? $queryParts : $query;
1125 }
1126
1127 /**
1128 * 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'])
1129 * Set $count to 1 if you wish to get a count(*) query for selecting the number of results.
1130 * Notice that the query will use $this->conf['pidList'] and $this->conf['recursive'] to generate a PID list within which to search for records.
1131 *
1132 * @param string The table name to make the query for.
1133 * @param boolean If set, you will get a "count(*)" query back instead of field selecting
1134 * @param string Additional WHERE clauses (should be starting with " AND ....")
1135 * @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.
1136 * @param string If set, this is added as a " GROUP BY ...." part of the query.
1137 * @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']
1138 * @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!
1139 * @return pointer SQL result pointer
1140 */
1141 function pi_exec_query($table,$count=0,$addWhere='',$mm_cat='',$groupBy='',$orderBy='',$query='') {
1142 $queryParts = $this->pi_list_query($table,$count,$addWhere,$mm_cat,$groupBy,$orderBy,$query, TRUE);
1143
1144 return $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
1145 }
1146
1147 /**
1148 * Returns the row $uid from $table
1149 * (Simply calling $GLOBALS['TSFE']->sys_page->checkRecord())
1150 *
1151 * @param string The table name
1152 * @param integer The uid of the record from the table
1153 * @param boolean If $checkPage is set, it's required that the page on which the record resides is accessible
1154 * @return array If record is found, an array. Otherwise false.
1155 */
1156 function pi_getRecord($table,$uid,$checkPage=0) {
1157 return $GLOBALS['TSFE']->sys_page->checkRecord($table,$uid,$checkPage);
1158 }
1159
1160 /**
1161 * Returns a commalist of page ids for a query (eg. 'WHERE pid IN (...)')
1162 *
1163 * @param string $pid_list is a comma list of page ids (if empty current page is used)
1164 * @param integer $recursive is an integer >=0 telling how deep to dig for pids under each entry in $pid_list
1165 * @return string List of PID values (comma separated)
1166 */
1167 function pi_getPidList($pid_list, $recursive = 0) {
1168 if (!strcmp($pid_list, '')) {
1169 $pid_list = $GLOBALS['TSFE']->id;
1170 }
1171
1172 $recursive = t3lib_div::intInRange($recursive, 0);
1173
1174 $pid_list_arr = array_unique(t3lib_div::trimExplode(',', $pid_list, 1));
1175 $pid_list = array();
1176
1177 foreach($pid_list_arr as $val) {
1178 $val = t3lib_div::intInRange($val, 0);
1179 if ($val) {
1180 $_list = $this->cObj->getTreeList(-1 * $val, $recursive);
1181 if ($_list) {
1182 $pid_list[] = $_list;
1183 }
1184 }
1185 }
1186
1187 return implode(',', $pid_list);
1188 }
1189
1190 /**
1191 * Having a comma list of fields ($fieldList) this is prepended with the $table.'.' name
1192 *
1193 * @param string Table name to prepend
1194 * @param string List of fields where each element will be prepended with the table name given.
1195 * @return string List of fields processed.
1196 */
1197 function pi_prependFieldsWithTable($table,$fieldList) {
1198 $list=t3lib_div::trimExplode(',',$fieldList,1);
1199 $return=array();
1200 foreach ($list as $listItem) {
1201 $return[]=$table.'.'.$listItem;
1202 }
1203 return implode(',',$return);
1204 }
1205
1206 /**
1207 * Will select all records from the "category table", $table, and return them in an array.
1208 *
1209 * @param string The name of the category table to select from.
1210 * @param integer The page from where to select the category records.
1211 * @param string Optional additional WHERE clauses put in the end of the query. DO NOT PUT IN GROUP BY, ORDER BY or LIMIT!
1212 * @param string Optional GROUP BY field(s), if none, supply blank string.
1213 * @param string Optional ORDER BY field(s), if none, supply blank string.
1214 * @param string Optional LIMIT value ([begin,]max), if none, supply blank string.
1215 * @return array The array with the category records in.
1216 */
1217 function pi_getCategoryTableContents($table,$pid,$whereClause='',$groupBy='',$orderBy='',$limit='') {
1218 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
1219 '*',
1220 $table,
1221 'pid='.intval($pid).
1222 $this->cObj->enableFields($table).' '.
1223 $whereClause, // whereClauseMightContainGroupOrderBy
1224 $groupBy,
1225 $orderBy,
1226 $limit
1227 );
1228 $outArr = array();
1229 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
1230 $outArr[$row['uid']] = $row;
1231 }
1232 $GLOBALS['TYPO3_DB']->sql_free_result($res);
1233 return $outArr;
1234 }
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247 /***************************
1248 *
1249 * Various
1250 *
1251 **************************/
1252
1253 /**
1254 * 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.
1255 * Notice that this function will only work as long as values are integers.
1256 *
1257 * @param string List of fields (keys from piVars) to evaluate on
1258 * @param integer Limit for the values.
1259 * @return boolean Returns true (1) if conditions are met.
1260 */
1261 function pi_isOnlyFields($fList,$lowerThan=-1) {
1262 $lowerThan = $lowerThan==-1 ? $this->pi_lowerThan : $lowerThan;
1263
1264 $fList = t3lib_div::trimExplode(',',$fList,1);
1265 $tempPiVars = $this->piVars;
1266 foreach ($fList as $k) {
1267 if (!t3lib_div::testInt($tempPiVars[$k]) || $tempPiVars[$k]<$lowerThan) unset($tempPiVars[$k]);
1268 }
1269 if (!count($tempPiVars)) return 1;
1270 }
1271
1272 /**
1273 * Returns true if the array $inArray contains only values allowed to be cached based on the configuration in $this->pi_autoCacheFields
1274 * Used by ->pi_linkTP_keepPIvars
1275 * This is an advanced form of evaluation of whether a URL should be cached or not.
1276 *
1277 * @param array An array with piVars values to evaluate
1278 * @return boolean Returns true (1) if conditions are met.
1279 * @see pi_linkTP_keepPIvars()
1280 */
1281 function pi_autoCache($inArray) {
1282 if (is_array($inArray)) {
1283 foreach ($inArray as $fN => $fV) {
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 ?>