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