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