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