Added Feature #12066: Added constants throughout the core for LF, CR, TAB (Thanks...
[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 * @param boolean forces the output of the page browser if you set this option to "true" (otherwise it's only drawn if enough entries are available)
447 * @return string Output HTML-Table, wrapped in <div>-tags with a class attribute (if $wrapArr is not passed,
448 */
449 function pi_list_browseresults($showResultCount=1, $tableParams='', $wrapArr=array(), $pointerName='pointer', $hscText=TRUE, $forceOutput=FALSE) {
450
451 // example $wrapArr-array how it could be traversed from an extension
452 /* $wrapArr = array(
453 'browseBoxWrap' => '<div class="browseBoxWrap">|</div>',
454 'showResultsWrap' => '<div class="showResultsWrap">|</div>',
455 'browseLinksWrap' => '<div class="browseLinksWrap">|</div>',
456 'showResultsNumbersWrap' => '<span class="showResultsNumbersWrap">|</span>',
457 'disabledLinkWrap' => '<span class="disabledLinkWrap">|</span>',
458 'inactiveLinkWrap' => '<span class="inactiveLinkWrap">|</span>',
459 'activeLinkWrap' => '<span class="activeLinkWrap">|</span>'
460 ); */
461
462 // Initializing variables:
463 $pointer = intval($this->piVars[$pointerName]);
464 $count = intval($this->internal['res_count']);
465 $results_at_a_time = t3lib_div::intInRange($this->internal['results_at_a_time'],1,1000);
466 $totalPages = ceil($count/$results_at_a_time);
467 $maxPages = t3lib_div::intInRange($this->internal['maxPages'],1,100);
468 $pi_isOnlyFields = $this->pi_isOnlyFields($this->pi_isOnlyFields);
469
470 if (!$forceOutput && $count <= $results_at_a_time) {
471 return '';
472 }
473
474 // $showResultCount determines how the results of the pagerowser will be shown.
475 // If set to 0: only the result-browser will be shown
476 // 1: (default) the text "Displaying results..." and the result-browser will be shown.
477 // 2: only the text "Displaying results..." will be shown
478 $showResultCount = intval($showResultCount);
479
480 // if this is set, two links named "<< First" and "LAST >>" will be shown and point to the very first or last page.
481 $showFirstLast = $this->internal['showFirstLast'];
482
483 // if this has a value the "previous" button is always visible (will be forced if "showFirstLast" is set)
484 $alwaysPrev = $showFirstLast?1:$this->pi_alwaysPrev;
485
486 if (isset($this->internal['pagefloat'])) {
487 if (strtoupper($this->internal['pagefloat']) == 'CENTER') {
488 $pagefloat = ceil(($maxPages - 1)/2);
489 } else {
490 // pagefloat set as integer. 0 = left, value >= $this->internal['maxPages'] = right
491 $pagefloat = t3lib_div::intInRange($this->internal['pagefloat'],-1,$maxPages-1);
492 }
493 } else {
494 $pagefloat = -1; // pagefloat disabled
495 }
496
497 // default values for "traditional" wrapping with a table. Can be overwritten by vars from $wrapArr
498 $wrapper['disabledLinkWrap'] = '<td nowrap="nowrap"><p>|</p></td>';
499 $wrapper['inactiveLinkWrap'] = '<td nowrap="nowrap"><p>|</p></td>';
500 $wrapper['activeLinkWrap'] = '<td'.$this->pi_classParam('browsebox-SCell').' nowrap="nowrap"><p>|</p></td>';
501 $wrapper['browseLinksWrap'] = trim('<table '.$tableParams).'><tr>|</tr></table>';
502 $wrapper['showResultsWrap'] = '<p>|</p>';
503 $wrapper['browseBoxWrap'] = '
504 <!--
505 List browsing box:
506 -->
507 <div '.$this->pi_classParam('browsebox').'>
508 |
509 </div>';
510
511 // now overwrite all entries in $wrapper which are also in $wrapArr
512 $wrapper = array_merge($wrapper,$wrapArr);
513
514 if ($showResultCount != 2) { //show pagebrowser
515 if ($pagefloat > -1) {
516 $lastPage = min($totalPages,max($pointer+1 + $pagefloat,$maxPages));
517 $firstPage = max(0,$lastPage-$maxPages);
518 } else {
519 $firstPage = 0;
520 $lastPage = t3lib_div::intInRange($totalPages,1,$maxPages);
521 }
522 $links=array();
523
524 // Make browse-table/links:
525 if ($showFirstLast) { // Link to first page
526 if ($pointer>0) {
527 $links[]=$this->cObj->wrap($this->pi_linkTP_keepPIvars($this->pi_getLL('pi_list_browseresults_first','<< First',$hscText),array($pointerName => null),$pi_isOnlyFields),$wrapper['inactiveLinkWrap']);
528 } else {
529 $links[]=$this->cObj->wrap($this->pi_getLL('pi_list_browseresults_first','<< First',$hscText),$wrapper['disabledLinkWrap']);
530 }
531 }
532 if ($alwaysPrev>=0) { // Link to previous page
533 if ($pointer>0) {
534 $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']);
535 } elseif ($alwaysPrev) {
536 $links[]=$this->cObj->wrap($this->pi_getLL('pi_list_browseresults_prev','< Previous',$hscText),$wrapper['disabledLinkWrap']);
537 }
538 }
539 for($a=$firstPage;$a<$lastPage;$a++) { // Links to pages
540 if ($this->internal['showRange']) {
541 $pageText = (($a*$results_at_a_time)+1).'-'.min($count,(($a+1)*$results_at_a_time));
542 } else {
543 $pageText = trim($this->pi_getLL('pi_list_browseresults_page','Page',$hscText).' '.($a+1));
544 }
545 if ($pointer == $a) { // current page
546 if ($this->internal['dontLinkActivePage']) {
547 $links[] = $this->cObj->wrap($pageText,$wrapper['activeLinkWrap']);
548 } else {
549 $links[] = $this->cObj->wrap($this->pi_linkTP_keepPIvars($pageText,array($pointerName => ($a?$a:'')),$pi_isOnlyFields),$wrapper['activeLinkWrap']);
550 }
551 } else {
552 $links[] = $this->cObj->wrap($this->pi_linkTP_keepPIvars($pageText,array($pointerName => ($a?$a:'')),$pi_isOnlyFields),$wrapper['inactiveLinkWrap']);
553 }
554 }
555 if ($pointer<$totalPages-1 || $showFirstLast) {
556 if ($pointer>=$totalPages-1) { // Link to next page
557 $links[]=$this->cObj->wrap($this->pi_getLL('pi_list_browseresults_next','Next >',$hscText),$wrapper['disabledLinkWrap']);
558 } else {
559 $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']);
560 }
561 }
562 if ($showFirstLast) { // Link to last page
563 if ($pointer<$totalPages-1) {
564 $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']);
565 } else {
566 $links[]=$this->cObj->wrap($this->pi_getLL('pi_list_browseresults_last','Last >>',$hscText),$wrapper['disabledLinkWrap']);
567 }
568 }
569 $theLinks = $this->cObj->wrap(implode(LF,$links),$wrapper['browseLinksWrap']);
570 } else {
571 $theLinks = '';
572 }
573
574 $pR1 = $pointer*$results_at_a_time+1;
575 $pR2 = $pointer*$results_at_a_time+$results_at_a_time;
576
577 if ($showResultCount) {
578 if ($wrapper['showResultsNumbersWrap']) {
579 // this will render the resultcount in a more flexible way using markers (new in TYPO3 3.8.0).
580 // the formatting string is expected to hold template markers (see function header). Example: 'Displaying results ###FROM### to ###TO### out of ###OUT_OF###'
581
582 $markerArray['###FROM###'] = $this->cObj->wrap($this->internal['res_count'] > 0 ? $pR1 : 0,$wrapper['showResultsNumbersWrap']);
583 $markerArray['###TO###'] = $this->cObj->wrap(min($this->internal['res_count'],$pR2),$wrapper['showResultsNumbersWrap']);
584 $markerArray['###OUT_OF###'] = $this->cObj->wrap($this->internal['res_count'],$wrapper['showResultsNumbersWrap']);
585 $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']);
586 $markerArray['###CURRENT_PAGE###'] = $this->cObj->wrap($pointer+1,$wrapper['showResultsNumbersWrap']);
587 $markerArray['###TOTAL_PAGES###'] = $this->cObj->wrap($totalPages,$wrapper['showResultsNumbersWrap']);
588 // substitute markers
589 $resultCountMsg = $this->cObj->substituteMarkerArray($this->pi_getLL('pi_list_browseresults_displays','Displaying results ###FROM### to ###TO### out of ###OUT_OF###'),$markerArray);
590 } else {
591 // render the resultcount in the "traditional" way using sprintf
592 $resultCountMsg = sprintf(
593 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>')),
594 $count > 0 ? $pR1 : 0,
595 min($count,$pR2),
596 $count);
597 }
598 $resultCountMsg = $this->cObj->wrap($resultCountMsg,$wrapper['showResultsWrap']);
599 } else {
600 $resultCountMsg = '';
601 }
602
603 $sTables = $this->cObj->wrap($resultCountMsg.$theLinks,$wrapper['browseBoxWrap']);
604
605 return $sTables;
606 }
607
608 /**
609 * Returns a Search box, sending search words to piVars "sword" and setting the "no_cache" parameter as well in the form.
610 * Submits the search request to the current REQUEST_URI
611 *
612 * @param string Attributes for the table tag which is wrapped around the table cells containing the search box
613 * @return string Output HTML, wrapped in <div>-tags with a class attribute
614 */
615 function pi_list_searchBox($tableParams='') {
616 // Search box design:
617 $sTables = '
618
619 <!--
620 List search box:
621 -->
622 <div'.$this->pi_classParam('searchbox').'>
623 <form action="'.htmlspecialchars(t3lib_div::getIndpEnv('REQUEST_URI')).'" method="post" style="margin: 0 0 0 0;">
624 <'.trim('table '.$tableParams).'>
625 <tr>
626 <td><input type="text" name="'.$this->prefixId.'[sword]" value="'.htmlspecialchars($this->piVars['sword']).'"'.$this->pi_classParam('searchbox-sword').' /></td>
627 <td><input type="submit" value="'.$this->pi_getLL('pi_list_searchBox_search','Search',TRUE).'"'.$this->pi_classParam('searchbox-button').' />'.
628 '<input type="hidden" name="no_cache" value="1" />'.
629 '<input type="hidden" name="'.$this->prefixId.'[pointer]" value="" />'.
630 '</td>
631 </tr>
632 </table>
633 </form>
634 </div>';
635
636 return $sTables;
637 }
638
639 /**
640 * Returns a mode selector; a little menu in a table normally put in the top of the page/list.
641 *
642 * @param array Key/Value pairs for the menu; keys are the piVars[mode] values and the "values" are the labels for them.
643 * @param string Attributes for the table tag which is wrapped around the table cells containing the menu
644 * @return string Output HTML, wrapped in <div>-tags with a class attribute
645 */
646 function pi_list_modeSelector($items=array(),$tableParams='') {
647 $cells=array();
648 foreach ($items as $k => $v) {
649 $cells[]='
650 <td'.($this->piVars['mode']==$k?$this->pi_classParam('modeSelector-SCell'):'').'><p>'.
651 $this->pi_linkTP_keepPIvars(htmlspecialchars($v),array('mode'=>$k),$this->pi_isOnlyFields($this->pi_isOnlyFields)).
652 '</p></td>';
653 }
654
655 $sTables = '
656
657 <!--
658 Mode selector (menu for list):
659 -->
660 <div'.$this->pi_classParam('modeSelector').'>
661 <'.trim('table '.$tableParams).'>
662 <tr>
663 '.implode('',$cells).'
664 </tr>
665 </table>
666 </div>';
667
668 return $sTables;
669 }
670
671 /**
672 * Returns the list of items based on the input SQL result pointer
673 * For each result row the internal var, $this->internal['currentRow'], is set with the row returned.
674 * $this->pi_list_header() makes the header row for the list
675 * $this->pi_list_row() is used for rendering each row
676 * 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.
677 *
678 * @param pointer Result pointer to a SQL result which can be traversed.
679 * @param string Attributes for the table tag which is wrapped around the table rows containing the list
680 * @return string Output HTML, wrapped in <div>-tags with a class attribute
681 * @see pi_list_row(), pi_list_header()
682 */
683 function pi_list_makelist($res,$tableParams='') {
684 // Make list table header:
685 $tRows=array();
686 $this->internal['currentRow']='';
687 $tRows[] = $this->pi_list_header();
688
689 // Make list table rows
690 $c=0;
691 while($this->internal['currentRow'] = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
692 $tRows[] = $this->pi_list_row($c);
693 $c++;
694 }
695
696 $out = '
697
698 <!--
699 Record list:
700 -->
701 <div'.$this->pi_classParam('listrow').'>
702 <'.trim('table '.$tableParams).'>
703 '.implode('',$tRows).'
704 </table>
705 </div>';
706
707 return $out;
708 }
709
710 /**
711 * Returns a list row. Get data from $this->internal['currentRow'];
712 * (Dummy)
713 * 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.
714 *
715 * @param integer Row counting. Starts at 0 (zero). Used for alternating class values in the output rows.
716 * @return string HTML output, a table row with a class attribute set (alternative based on odd/even rows)
717 */
718 function pi_list_row($c) {
719 // Dummy
720 return '<tr'.($c%2 ? $this->pi_classParam('listrow-odd') : '').'><td><p>[dummy row]</p></td></tr>';
721 }
722
723 /**
724 * Returns a list header row.
725 * (Dummy)
726 * 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.
727 *
728 * @return string HTML output, a table row with a class attribute set
729 */
730 function pi_list_header() {
731 return '<tr'.$this->pi_classParam('listrow-header').'><td><p>[dummy header row]</p></td></tr>';
732 }
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748 /***************************
749 *
750 * Stylesheet, CSS
751 *
752 **************************/
753
754
755 /**
756 * Returns a class-name prefixed with $this->prefixId and with all underscores substituted to dashes (-)
757 *
758 * @param string The class name (or the END of it since it will be prefixed by $this->prefixId.'-')
759 * @return string The combined class name (with the correct prefix)
760 */
761 function pi_getClassName($class) {
762 return str_replace('_','-',$this->prefixId).($this->prefixId?'-':'').$class;
763 }
764
765 /**
766 * Returns the class-attribute with the correctly prefixed classname
767 * Using pi_getClassName()
768 *
769 * @param string The class name(s) (suffix) - separate multiple classes with commas
770 * @param string Additional class names which should not be prefixed - separate multiple classes with commas
771 * @return string A "class" attribute with value and a single space char before it.
772 * @see pi_getClassName()
773 */
774 function pi_classParam($class, $addClasses='') {
775 $output = '';
776 foreach (t3lib_div::trimExplode(',',$class) as $v) {
777 $output.= ' '.$this->pi_getClassName($v);
778 }
779 foreach (t3lib_div::trimExplode(',',$addClasses) as $v) {
780 $output.= ' '.$v;
781 }
782 return ' class="'.trim($output).'"';
783 }
784
785 /**
786 * Sets CSS style-data for the $class-suffix (prefixed by pi_getClassName())
787 *
788 * @param string $class: Class suffix, see pi_getClassName
789 * @param string $data: CSS data
790 * @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
791 * @return void
792 * @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.
793 * @obsolete
794 * @private
795 */
796 function pi_setClassStyle($class,$data,$selector='') {
797 t3lib_div::logDeprecatedFunction();
798
799 $GLOBALS['TSFE']->setCSS($this->pi_getClassName($class).($selector?' '.$selector:''),'.'.$this->pi_getClassName($class).($selector?' '.$selector:'').' {'.$data.'}');
800 }
801
802 /**
803 * Wraps the input string in a <div> tag with the class attribute set to the prefixId.
804 * 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.
805 *
806 * @param string HTML content to wrap in the div-tags with the "main class" of the plugin
807 * @return string HTML content wrapped, ready to return to the parent object.
808 */
809 function pi_wrapInBaseClass($str) {
810 $content = '<div class="'.str_replace('_','-',$this->prefixId).'">
811 '.$str.'
812 </div>
813 ';
814
815 if(!$GLOBALS['TSFE']->config['config']['disablePrefixComment']) {
816 $content = '
817
818
819 <!--
820
821 BEGIN: Content of extension "'.$this->extKey.'", plugin "'.$this->prefixId.'"
822
823 -->
824 '.$content.'
825 <!-- END: Content of extension "'.$this->extKey.'", plugin "'.$this->prefixId.'" -->
826
827 ';
828 }
829
830 return $content;
831 }
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849 /***************************
850 *
851 * Frontend editing: Edit panel, edit icons
852 *
853 **************************/
854
855 /**
856 * Returns the Backend User edit panel for the $row from $tablename
857 *
858 * @param array Record array.
859 * @param string Table name
860 * @param string A label to show with the panel.
861 * @param array TypoScript parameters to pass along to the EDITPANEL content Object that gets rendered. The property "allow" WILL get overridden/set though.
862 * @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).
863 * @see tslib_cObj::EDITPANEL()
864 */
865 function pi_getEditPanel($row='',$tablename='',$label='',$conf=Array()) {
866 $panel='';
867 if (!$row || !$tablename) {
868 $row = $this->internal['currentRow'];
869 $tablename = $this->internal['currentTable'];
870 }
871
872 if ($GLOBALS['TSFE']->beUserLogin) {
873 // Create local cObj if not set:
874 if (!is_object($this->pi_EPtemp_cObj)) {
875 $this->pi_EPtemp_cObj = t3lib_div::makeInstance('tslib_cObj');
876 $this->pi_EPtemp_cObj->setParent($this->cObj->data,$this->cObj->currentRecord);
877 }
878
879 // Initialize the cObj object with current row
880 $this->pi_EPtemp_cObj->start($row,$tablename);
881
882 // Setting TypoScript values in the $conf array. See documentation in TSref for the EDITPANEL cObject.
883 $conf['allow'] = 'edit,new,delete,move,hide';
884 $panel = $this->pi_EPtemp_cObj->cObjGetSingle('EDITPANEL',$conf,'editpanel');
885 }
886
887 if ($panel) {
888 if ($label) {
889 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 -->';
890 } else return '<!-- BEGIN: EDIT PANEL -->'.$panel.'<!-- END: EDIT PANEL -->';
891 } else return $label;
892 }
893
894 /**
895 * Adds edit-icons to the input content.
896 * tslib_cObj::editIcons used for rendering
897 *
898 * @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)
899 * @param string The list of fields to edit when the icon is clicked.
900 * @param string Title for the edit icon.
901 * @param array Table record row
902 * @param string Table name
903 * @param array Conf array
904 * @return string The processed content
905 * @see tslib_cObj::editIcons()
906 */
907 function pi_getEditIcon($content,$fields,$title='',$row='',$tablename='',$oConf=array()) {
908 if ($GLOBALS['TSFE']->beUserLogin){
909 if (!$row || !$tablename) {
910 $row = $this->internal['currentRow'];
911 $tablename = $this->internal['currentTable'];
912 }
913 $conf=array_merge(array(
914 'beforeLastTag'=>1,
915 'iconTitle' => $title
916 ),$oConf);
917 $content=$this->cObj->editIcons($content,$tablename.':'.$fields,$conf,$tablename.':'.$row['uid'],$row,'&viewUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI')));
918 }
919 return $content;
920 }
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938 /***************************
939 *
940 * Localization, locallang functions
941 *
942 **************************/
943
944
945 /**
946 * Returns the localized label of the LOCAL_LANG key, $key
947 * Notice that for debugging purposes prefixes for the output values can be set with the internal vars ->LLtestPrefixAlt and ->LLtestPrefix
948 *
949 * @param string The key from the LOCAL_LANG array for which to return the value.
950 * @param string Alternative string to return IF no value is found set for the key, neither for the local language nor the default.
951 * @param boolean If true, the output label is passed through htmlspecialchars()
952 * @return string The value from LOCAL_LANG.
953 */
954 function pi_getLL($key,$alt='',$hsc=FALSE) {
955 // The "from" charset of csConv() is only set for strings from TypoScript via _LOCAL_LANG
956 if (isset($this->LOCAL_LANG[$this->LLkey][$key])) {
957 $word = $GLOBALS['TSFE']->csConv($this->LOCAL_LANG[$this->LLkey][$key], $this->LOCAL_LANG_charset[$this->LLkey][$key]);
958 } elseif ($this->altLLkey && isset($this->LOCAL_LANG[$this->altLLkey][$key])) {
959 $word = $GLOBALS['TSFE']->csConv($this->LOCAL_LANG[$this->altLLkey][$key], $this->LOCAL_LANG_charset[$this->altLLkey][$key]);
960 } elseif (isset($this->LOCAL_LANG['default'][$key])) {
961 $word = $this->LOCAL_LANG['default'][$key]; // No charset conversion because default is english and thereby ASCII
962 } else {
963 $word = $this->LLtestPrefixAlt.$alt;
964 }
965
966 $output = $this->LLtestPrefix.$word;
967 if ($hsc) $output = htmlspecialchars($output);
968
969 return $output;
970 }
971
972 /**
973 * Loads local-language values by looking for a "locallang.php" file in the plugin class directory ($this->scriptRelPath) and if found includes it.
974 * Also locallang values set in the TypoScript property "_LOCAL_LANG" are merged onto the values found in the "locallang.php" file.
975 *
976 * @return void
977 */
978 function pi_loadLL() {
979 if (!$this->LOCAL_LANG_loaded && $this->scriptRelPath) {
980 $basePath = 'EXT:' . $this->extKey . '/' . dirname($this->scriptRelPath) . '/locallang.xml';
981
982 // Read the strings in the required charset (since TYPO3 4.2)
983 $this->LOCAL_LANG = t3lib_div::readLLfile($basePath,$this->LLkey,$GLOBALS['TSFE']->renderCharset);
984 if ($this->altLLkey) {
985 $tempLOCAL_LANG = t3lib_div::readLLfile($basePath,$this->altLLkey);
986 $this->LOCAL_LANG = array_merge(is_array($this->LOCAL_LANG) ? $this->LOCAL_LANG : array(),$tempLOCAL_LANG);
987 }
988
989 // Overlaying labels from TypoScript (including fictitious language keys for non-system languages!):
990 $confLL = $this->conf['_LOCAL_LANG.'];
991 if (is_array($confLL)) {
992 foreach ($confLL as $k => $lA) {
993 if (is_array($lA)) {
994 $k = substr($k,0,-1);
995 foreach($lA as $llK => $llV) {
996 if (!is_array($llV)) {
997 $this->LOCAL_LANG[$k][$llK] = $llV;
998 // 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
999 $this->LOCAL_LANG_charset[$k][$llK] = $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'] ? $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'] : $GLOBALS['TSFE']->csConvObj->charSetArray[$k];
1000 }
1001 }
1002 }
1003 }
1004 }
1005 }
1006 $this->LOCAL_LANG_loaded = 1;
1007 }
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031 /***************************
1032 *
1033 * Database, queries
1034 *
1035 **************************/
1036
1037 /**
1038 * 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'])
1039 * Set $count to 1 if you wish to get a count(*) query for selecting the number of results.
1040 * Notice that the query will use $this->conf['pidList'] and $this->conf['recursive'] to generate a PID list within which to search for records.
1041 *
1042 * @param string See pi_exec_query()
1043 * @param boolean See pi_exec_query()
1044 * @param string See pi_exec_query()
1045 * @param mixed See pi_exec_query()
1046 * @param string See pi_exec_query()
1047 * @param string See pi_exec_query()
1048 * @param string See pi_exec_query()
1049 * @param boolean If set, the function will return the query not as a string but array with the various parts.
1050 * @return mixed The query build.
1051 * @access private
1052 * @deprecated since TYPO3 3.6, this function will be removed in TYPO3 4.5, use pi_exec_query() instead!
1053 */
1054 function pi_list_query($table,$count=0,$addWhere='',$mm_cat='',$groupBy='',$orderBy='',$query='',$returnQueryArray=FALSE) {
1055
1056 // Begin Query:
1057 if (!$query) {
1058 // Fetches the list of PIDs to select from.
1059 // TypoScript property .pidList is a comma list of pids. If blank, current page id is used.
1060 // 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.
1061 $pidList = $this->pi_getPidList($this->conf['pidList'],$this->conf['recursive']);
1062 if (is_array($mm_cat)) {
1063 $query='FROM '.$table.','.$mm_cat['table'].','.$mm_cat['mmtable'].LF.
1064 ' WHERE '.$table.'.uid='.$mm_cat['mmtable'].'.uid_local AND '.$mm_cat['table'].'.uid='.$mm_cat['mmtable'].'.uid_foreign '.LF.
1065 (strcmp($mm_cat['catUidList'],'')?' AND '.$mm_cat['table'].'.uid IN ('.$mm_cat['catUidList'].')':'').LF.
1066 ' AND '.$table.'.pid IN ('.$pidList.')'.LF.
1067 $this->cObj->enableFields($table).LF; // 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!
1068 } else {
1069 $query='FROM '.$table.' WHERE pid IN ('.$pidList.')'.LF.
1070 $this->cObj->enableFields($table).LF; // 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!
1071 }
1072 }
1073
1074 // Split the "FROM ... WHERE" string so we get the WHERE part and TABLE names separated...:
1075 list($TABLENAMES, $WHERE) = preg_split('/WHERE/i', trim($query), 2);
1076 $TABLENAMES = trim(substr(trim($TABLENAMES),5));
1077 $WHERE = trim($WHERE);
1078
1079 // Add '$addWhere'
1080 if ($addWhere) {$WHERE.=' '.$addWhere.LF;}
1081
1082 // Search word:
1083 if ($this->piVars['sword'] && $this->internal['searchFieldList']) {
1084 $WHERE.=$this->cObj->searchWhere($this->piVars['sword'],$this->internal['searchFieldList'],$table).LF;
1085 }
1086
1087 if ($count) {
1088 $queryParts = array(
1089 'SELECT' => 'count(*)',
1090 'FROM' => $TABLENAMES,
1091 'WHERE' => $WHERE,
1092 'GROUPBY' => '',
1093 'ORDERBY' => '',
1094 'LIMIT' => ''
1095 );
1096 } else {
1097 // Order by data:
1098 if (!$orderBy && $this->internal['orderBy']) {
1099 if (t3lib_div::inList($this->internal['orderByList'],$this->internal['orderBy'])) {
1100 $orderBy = 'ORDER BY '.$table.'.'.$this->internal['orderBy'].($this->internal['descFlag']?' DESC':'');
1101 }
1102 }
1103
1104 // Limit data:
1105 $pointer = $this->piVars['pointer'];
1106 $pointer = intval($pointer);
1107 $results_at_a_time = t3lib_div::intInRange($this->internal['results_at_a_time'],1,1000);
1108 $LIMIT = ($pointer*$results_at_a_time).','.$results_at_a_time;
1109
1110 // Add 'SELECT'
1111 $queryParts = array(
1112 'SELECT' => $this->pi_prependFieldsWithTable($table,$this->pi_listFields),
1113 'FROM' => $TABLENAMES,
1114 'WHERE' => $WHERE,
1115 'GROUPBY' => $GLOBALS['TYPO3_DB']->stripGroupBy($groupBy),
1116 'ORDERBY' => $GLOBALS['TYPO3_DB']->stripOrderBy($orderBy),
1117 'LIMIT' => $LIMIT
1118 );
1119 }
1120
1121 $query = $GLOBALS['TYPO3_DB']->SELECTquery (
1122 $queryParts['SELECT'],
1123 $queryParts['FROM'],
1124 $queryParts['WHERE'],
1125 $queryParts['GROUPBY'],
1126 $queryParts['ORDERBY'],
1127 $queryParts['LIMIT']
1128 );
1129 return $returnQueryArray ? $queryParts : $query;
1130 }
1131
1132 /**
1133 * 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'])
1134 * Set $count to 1 if you wish to get a count(*) query for selecting the number of results.
1135 * Notice that the query will use $this->conf['pidList'] and $this->conf['recursive'] to generate a PID list within which to search for records.
1136 *
1137 * @param string The table name to make the query for.
1138 * @param boolean If set, you will get a "count(*)" query back instead of field selecting
1139 * @param string Additional WHERE clauses (should be starting with " AND ....")
1140 * @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.
1141 * @param string If set, this is added as a " GROUP BY ...." part of the query.
1142 * @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']
1143 * @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!
1144 * @return pointer SQL result pointer
1145 */
1146 function pi_exec_query($table,$count=0,$addWhere='',$mm_cat='',$groupBy='',$orderBy='',$query='') {
1147 $queryParts = $this->pi_list_query($table,$count,$addWhere,$mm_cat,$groupBy,$orderBy,$query, TRUE);
1148
1149 return $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
1150 }
1151
1152 /**
1153 * Returns the row $uid from $table
1154 * (Simply calling $GLOBALS['TSFE']->sys_page->checkRecord())
1155 *
1156 * @param string The table name
1157 * @param integer The uid of the record from the table
1158 * @param boolean If $checkPage is set, it's required that the page on which the record resides is accessible
1159 * @return array If record is found, an array. Otherwise false.
1160 */
1161 function pi_getRecord($table,$uid,$checkPage=0) {
1162 return $GLOBALS['TSFE']->sys_page->checkRecord($table,$uid,$checkPage);
1163 }
1164
1165 /**
1166 * Returns a commalist of page ids for a query (eg. 'WHERE pid IN (...)')
1167 *
1168 * @param string $pid_list is a comma list of page ids (if empty current page is used)
1169 * @param integer $recursive is an integer >=0 telling how deep to dig for pids under each entry in $pid_list
1170 * @return string List of PID values (comma separated)
1171 */
1172 function pi_getPidList($pid_list, $recursive = 0) {
1173 if (!strcmp($pid_list, '')) {
1174 $pid_list = $GLOBALS['TSFE']->id;
1175 }
1176
1177 $recursive = t3lib_div::intInRange($recursive, 0);
1178
1179 $pid_list_arr = array_unique(t3lib_div::trimExplode(',', $pid_list, 1));
1180 $pid_list = array();
1181
1182 foreach($pid_list_arr as $val) {
1183 $val = t3lib_div::intInRange($val, 0);
1184 if ($val) {
1185 $_list = $this->cObj->getTreeList(-1 * $val, $recursive);
1186 if ($_list) {
1187 $pid_list[] = $_list;
1188 }
1189 }
1190 }
1191
1192 return implode(',', $pid_list);
1193 }
1194
1195 /**
1196 * Having a comma list of fields ($fieldList) this is prepended with the $table.'.' name
1197 *
1198 * @param string Table name to prepend
1199 * @param string List of fields where each element will be prepended with the table name given.
1200 * @return string List of fields processed.
1201 */
1202 function pi_prependFieldsWithTable($table,$fieldList) {
1203 $list=t3lib_div::trimExplode(',',$fieldList,1);
1204 $return=array();
1205 foreach ($list as $listItem) {
1206 $return[]=$table.'.'.$listItem;
1207 }
1208 return implode(',',$return);
1209 }
1210
1211 /**
1212 * Will select all records from the "category table", $table, and return them in an array.
1213 *
1214 * @param string The name of the category table to select from.
1215 * @param integer The page from where to select the category records.
1216 * @param string Optional additional WHERE clauses put in the end of the query. DO NOT PUT IN GROUP BY, ORDER BY or LIMIT!
1217 * @param string Optional GROUP BY field(s), if none, supply blank string.
1218 * @param string Optional ORDER BY field(s), if none, supply blank string.
1219 * @param string Optional LIMIT value ([begin,]max), if none, supply blank string.
1220 * @return array The array with the category records in.
1221 */
1222 function pi_getCategoryTableContents($table,$pid,$whereClause='',$groupBy='',$orderBy='',$limit='') {
1223 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
1224 '*',
1225 $table,
1226 'pid='.intval($pid).
1227 $this->cObj->enableFields($table).' '.
1228 $whereClause, // whereClauseMightContainGroupOrderBy
1229 $groupBy,
1230 $orderBy,
1231 $limit
1232 );
1233 $outArr = array();
1234 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
1235 $outArr[$row['uid']] = $row;
1236 }
1237 $GLOBALS['TYPO3_DB']->sql_free_result($res);
1238 return $outArr;
1239 }
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252 /***************************
1253 *
1254 * Various
1255 *
1256 **************************/
1257
1258 /**
1259 * 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.
1260 * Notice that this function will only work as long as values are integers.
1261 *
1262 * @param string List of fields (keys from piVars) to evaluate on
1263 * @param integer Limit for the values.
1264 * @return boolean Returns true (1) if conditions are met.
1265 */
1266 function pi_isOnlyFields($fList,$lowerThan=-1) {
1267 $lowerThan = $lowerThan==-1 ? $this->pi_lowerThan : $lowerThan;
1268
1269 $fList = t3lib_div::trimExplode(',',$fList,1);
1270 $tempPiVars = $this->piVars;
1271 foreach ($fList as $k) {
1272 if (!t3lib_div::testInt($tempPiVars[$k]) || $tempPiVars[$k]<$lowerThan) unset($tempPiVars[$k]);
1273 }
1274 if (!count($tempPiVars)) return 1;
1275 }
1276
1277 /**
1278 * Returns true if the array $inArray contains only values allowed to be cached based on the configuration in $this->pi_autoCacheFields
1279 * Used by ->pi_linkTP_keepPIvars
1280 * This is an advanced form of evaluation of whether a URL should be cached or not.
1281 *
1282 * @param array An array with piVars values to evaluate
1283 * @return boolean Returns true (1) if conditions are met.
1284 * @see pi_linkTP_keepPIvars()
1285 */
1286 function pi_autoCache($inArray) {
1287 if (is_array($inArray)) {
1288 foreach ($inArray as $fN => $fV) {
1289 if (!strcmp($inArray[$fN],'')) {
1290 unset($inArray[$fN]);
1291 } elseif (is_array($this->pi_autoCacheFields[$fN])) {
1292 if (is_array($this->pi_autoCacheFields[$fN]['range'])
1293 && intval($inArray[$fN])>=intval($this->pi_autoCacheFields[$fN]['range'][0])
1294 && intval($inArray[$fN])<=intval($this->pi_autoCacheFields[$fN]['range'][1])) {
1295 unset($inArray[$fN]);
1296 }
1297 if (is_array($this->pi_autoCacheFields[$fN]['list'])
1298 && in_array($inArray[$fN],$this->pi_autoCacheFields[$fN]['list'])) {
1299 unset($inArray[$fN]);
1300 }
1301 }
1302 }
1303 }
1304 if (!count($inArray)) return 1;
1305 }
1306
1307 /**
1308 * 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.
1309 * This is useful for rendering of content in RTE fields where the transformation mode is set to "ts_css" or so.
1310 * Notice that this requires the use of "css_styled_content" to work right.
1311 *
1312 * @param string The input text string to process
1313 * @return string The processed string
1314 * @see tslib_cObj::parseFunc()
1315 */
1316 function pi_RTEcssText($str) {
1317 $parseFunc = $GLOBALS['TSFE']->tmpl->setup['lib.']['parseFunc_RTE.'];
1318 if (is_array($parseFunc)) $str = $this->cObj->parseFunc($str, $parseFunc);
1319 return $str;
1320 }
1321
1322
1323
1324
1325
1326 /*******************************
1327 *
1328 * FlexForms related functions
1329 *
1330 *******************************/
1331
1332 /**
1333 * Converts $this->cObj->data['pi_flexform'] from XML string to flexForm array.
1334 *
1335 * @param string Field name to convert
1336 * @return void
1337 */
1338 function pi_initPIflexForm($field='pi_flexform') {
1339 // Converting flexform data into array:
1340 if (!is_array($this->cObj->data[$field]) && $this->cObj->data[$field]) {
1341 $this->cObj->data[$field] = t3lib_div::xml2array($this->cObj->data[$field]);
1342 if (!is_array($this->cObj->data[$field])) $this->cObj->data[$field]=array();
1343 }
1344 }
1345
1346 /**
1347 * Return value from somewhere inside a FlexForm structure
1348 *
1349 * @param array FlexForm data
1350 * @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.
1351 * @param string Sheet pointer, eg. "sDEF"
1352 * @param string Language pointer, eg. "lDEF"
1353 * @param string Value pointer, eg. "vDEF"
1354 * @return string The content.
1355 */
1356 function pi_getFFvalue($T3FlexForm_array,$fieldName,$sheet='sDEF',$lang='lDEF',$value='vDEF') {
1357 $sheetArray = is_array($T3FlexForm_array) ? $T3FlexForm_array['data'][$sheet][$lang] : '';
1358 if (is_array($sheetArray)) {
1359 return $this->pi_getFFvalueFromSheetArray($sheetArray,explode('/',$fieldName),$value);
1360 }
1361 }
1362
1363 /**
1364 * Returns part of $sheetArray pointed to by the keys in $fieldNameArray
1365 *
1366 * @param array Multidimensiona array, typically FlexForm contents
1367 * @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...)
1368 * @param string Value for outermost key, typ. "vDEF" depending on language.
1369 * @return mixed The value, typ. string.
1370 * @access private
1371 * @see pi_getFFvalue()
1372 */
1373 function pi_getFFvalueFromSheetArray($sheetArray,$fieldNameArr,$value) {
1374
1375 $tempArr=$sheetArray;
1376 foreach($fieldNameArr as $k => $v) {
1377 if (t3lib_div::testInt($v)) {
1378 if (is_array($tempArr)) {
1379 $c=0;
1380 foreach($tempArr as $values) {
1381 if ($c==$v) {
1382 #debug($values);
1383 $tempArr=$values;
1384 break;
1385 }
1386 $c++;
1387 }
1388 }
1389 } else {
1390 $tempArr = $tempArr[$v];
1391 }
1392 }
1393 return $tempArr[$value];
1394 }
1395 }
1396
1397 // NO extension of class - does not make sense here.
1398
1399 ?>