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