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