2bb2b17f33d0b8761d4dd15fa7f29f41652ea94e
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / RecordList / AbstractRecordList.php
1 <?php
2 namespace TYPO3\CMS\Backend\RecordList;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider;
18 use TYPO3\CMS\Backend\Routing\UriBuilder;
19 use TYPO3\CMS\Core\Database\ConnectionPool;
20 use TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction;
21 use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
22 use TYPO3\CMS\Core\Imaging\Icon;
23 use TYPO3\CMS\Core\Imaging\IconFactory;
24 use TYPO3\CMS\Core\Localization\LanguageService;
25 use TYPO3\CMS\Core\Utility\GeneralUtility;
26
27 /**
28 * Library with a single function addElement that returns table
29 * rows based on some input.
30 *
31 * Base for class listing of database records and files in the
32 * modules Web>List and File>Filelist
33 * @deprecated since TYPO3 v9, will be removed in TYPO3 v10
34 */
35 abstract class AbstractRecordList
36 {
37 /**
38 * @var int
39 * @deprecated since TYPO3 v9, will be removed in TYPO3 v10
40 */
41 protected $id = 0;
42
43 /**
44 * default Max items shown
45 *
46 * @var int
47 * @deprecated since TYPO3 v9, will be removed in TYPO3 v10
48 */
49 public $iLimit = 10;
50
51 /**
52 * OBSOLETE - NOT USED ANYMORE. leftMargin
53 *
54 * @var int
55 * @deprecated since TYPO3 v9, will be removed in TYPO3 v10
56 */
57 public $leftMargin = 0;
58
59 /**
60 * @var int
61 * @deprecated since TYPO3 v9, will be removed in TYPO3 v10
62 */
63 public $showIcon = 1;
64
65 /**
66 * @var int
67 * @deprecated since TYPO3 v9, will be removed in TYPO3 v10
68 */
69 public $no_noWrap = 0;
70
71 /**
72 * If set this is <td> CSS-classname for odd columns in addElement. Used with db_layout / pages section
73 *
74 * @var string
75 * @deprecated since TYPO3 v9, will be removed in TYPO3 v10
76 */
77 public $oddColumnsCssClass = '';
78
79 /**
80 * Decides the columns shown. Filled with values that refers to the keys of the data-array. $this->fieldArray[0] is the title column.
81 *
82 * @var array
83 * @deprecated since TYPO3 v9, will be removed in TYPO3 v10
84 */
85 public $fieldArray = [];
86
87 /**
88 * Keys are fieldnames and values are td-parameters to add in addElement(), please use $addElement_tdCSSClass for CSS-classes;
89 *
90 * @var array
91 * @deprecated since TYPO3 v9, will be removed in TYPO3 v10
92 */
93 public $addElement_tdParams = [];
94
95 /**
96 * Keys are fieldnames and values are td-css-classes to add in addElement();
97 *
98 * @var array
99 * @deprecated since TYPO3 v9, will be removed in TYPO3 v10
100 */
101 public $addElement_tdCssClass = [];
102
103 /**
104 * Not used in this class - but maybe extension classes...
105 * Max length of strings
106 *
107 * @var int
108 * @deprecated since TYPO3 v9, will be removed in TYPO3 v10
109 */
110 public $fixedL = 30;
111
112 /**
113 * Script URL
114 *
115 * @var string
116 * @deprecated since TYPO3 v9, will be removed in TYPO3 v10
117 */
118 public $thisScript = '';
119
120 /**
121 * Set to zero, if you don't want a left-margin with addElement function
122 *
123 * @var int
124 * @deprecated since TYPO3 v9, will be removed in TYPO3 v10
125 */
126 public $setLMargin = 1;
127
128 /**
129 * Counter increased for each element. Used to index elements for the JavaScript-code that transfers to the clipboard
130 *
131 * @var int
132 * @deprecated since TYPO3 v9, will be removed in TYPO3 v10
133 */
134 public $counter = 0;
135
136 /**
137 * This could be set to the total number of items. Used by the fwd_rew_navigation...
138 *
139 * @var string
140 * @deprecated since TYPO3 v9, will be removed in TYPO3 v10
141 */
142 public $totalItems = '';
143
144 /**
145 * Internal (used in this class.)
146 *
147 * @var int
148 * @deprecated since TYPO3 v9, will be removed in TYPO3 v10
149 */
150 public $firstElementNumber = 0;
151
152 /**
153 * @var int
154 * @deprecated since TYPO3 v9, will be removed in TYPO3 v10
155 */
156 public $eCounter = 0;
157
158 /**
159 * String with accumulated HTML content
160 *
161 * @var string
162 * @deprecated since TYPO3 v9, will be removed in TYPO3 v10
163 */
164 public $HTMLcode = '';
165
166 /**
167 * Contains page translation languages
168 *
169 * @var array
170 * @deprecated since TYPO3 v9, will be removed in TYPO3 v10
171 */
172 public $pageOverlays = [];
173
174 /**
175 * Contains sys language icons and titles
176 *
177 * @var array
178 * @deprecated since TYPO3 v9, will be removed in TYPO3 v10
179 */
180 public $languageIconTitles = [];
181
182 /**
183 * @var TranslationConfigurationProvider
184 * @deprecated since TYPO3 v9, will be removed in TYPO3 v10
185 */
186 public $translateTools;
187
188 /**
189 * @var IconFactory
190 * @deprecated since TYPO3 v9, will be removed in TYPO3 v10
191 */
192 protected $iconFactory;
193
194 /**
195 * Constructor
196 * @deprecated since TYPO3 v9, will be removed in TYPO3 v10
197 */
198 public function __construct()
199 {
200 GeneralUtility::logDeprecatedFunction();
201 if (isset($GLOBALS['BE_USER']->uc['titleLen']) && $GLOBALS['BE_USER']->uc['titleLen'] > 0) {
202 $this->fixedL = $GLOBALS['BE_USER']->uc['titleLen'];
203 }
204 $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
205 $this->getTranslateTools();
206 $this->determineScriptUrl();
207 }
208
209 /**
210 * Sets the script url depending on being a module or script request
211 * @deprecated since TYPO3 v9, will be removed in TYPO3 v10
212 */
213 protected function determineScriptUrl()
214 {
215 if ($routePath = GeneralUtility::_GP('route')) {
216 $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
217 $this->thisScript = (string)$uriBuilder->buildUriFromRoutePath($routePath);
218 } else {
219 $this->thisScript = GeneralUtility::getIndpEnv('SCRIPT_NAME');
220 }
221 }
222
223 /**
224 * @return string
225 * @deprecated since TYPO3 v9, will be removed in TYPO3 v10
226 */
227 protected function getThisScript()
228 {
229 return strpos($this->thisScript, '?') === false ? $this->thisScript . '?' : $this->thisScript . '&';
230 }
231
232 /**
233 * Returns a table-row with the content from the fields in the input data array.
234 * OBS: $this->fieldArray MUST be set! (represents the list of fields to display)
235 *
236 * @param int $h Is an integer >=0 and denotes how tall an element is. Set to '0' makes a halv line, -1 = full line, set to 1 makes a 'join' and above makes 'line'
237 * @param string $icon Is the <img>+<a> of the record. If not supplied the first 'join'-icon will be a 'line' instead
238 * @param array $data Is the dataarray, record with the fields. Notice: These fields are (currently) NOT htmlspecialchar'ed before being wrapped in <td>-tags
239 * @param string $rowParams Is insert in the <tr>-tags. Must carry a ' ' as first character
240 * @param string $_ OBSOLETE - NOT USED ANYMORE. $lMargin is the leftMargin (int)
241 * @param string $_2 OBSOLETE - NOT USED ANYMORE. Is the HTML <img>-tag for an alternative 'gfx/ol/line.gif'-icon (used in the top)
242 * @param string $colType Defines the tag being used for the columns. Default is td.
243 * @return string HTML content for the table row
244 * @deprecated since TYPO3 v9, will be removed in TYPO3 v10
245 */
246 public function addElement($h, $icon, $data, $rowParams = '', $_ = '', $_2 = '', $colType = 'td')
247 {
248 $colType = ($colType === 'th') ? 'th' : 'td';
249 $noWrap = $this->no_noWrap ? '' : ' nowrap';
250 // Start up:
251 $l10nParent = isset($data['_l10nparent_']) ? (int)$data['_l10nparent_'] : 0;
252 $out = '
253 <!-- Element, begin: -->
254 <tr ' . $rowParams . ' data-uid="' . (int)$data['uid'] . '" data-l10nparent="' . $l10nParent . '">';
255 // Show icon and lines
256 if ($this->showIcon) {
257 $out .= '
258 <' . $colType . ' class="col-icon nowrap">';
259 if (!$h) {
260 $out .= '&nbsp;';
261 } else {
262 for ($a = 0; $a < $h; $a++) {
263 if (!$a) {
264 if ($icon) {
265 $out .= $icon;
266 }
267 }
268 }
269 }
270 $out .= '</' . $colType . '>
271 ';
272 }
273 // Init rendering.
274 $colsp = '';
275 $lastKey = '';
276 $c = 0;
277 $ccount = 0;
278 // __label is used as the label key to circumvent problems with uid used as label (see #67756)
279 // as it was introduced later on, check if it really exists before using it
280 $fields = $this->fieldArray;
281 if ($colType === 'td' && array_key_exists('__label', $data)) {
282 $fields[0] = '__label';
283 }
284 // Traverse field array which contains the data to present:
285 foreach ($fields as $vKey) {
286 if (isset($data[$vKey])) {
287 if ($lastKey) {
288 $cssClass = $this->addElement_tdCssClass[$lastKey];
289 if ($this->oddColumnsCssClass && $ccount % 2 == 0) {
290 $cssClass = implode(' ', [$this->addElement_tdCssClass[$lastKey], $this->oddColumnsCssClass]);
291 }
292 $out .= '
293 <' . $colType . ' class="' . $cssClass . $noWrap . '"' . $colsp . $this->addElement_tdParams[$lastKey] . '>' . $data[$lastKey] . '</' . $colType . '>';
294 }
295 $lastKey = $vKey;
296 $c = 1;
297 $ccount++;
298 } else {
299 if (!$lastKey) {
300 $lastKey = $vKey;
301 }
302 $c++;
303 }
304 if ($c > 1) {
305 $colsp = ' colspan="' . $c . '"';
306 } else {
307 $colsp = '';
308 }
309 }
310 if ($lastKey) {
311 $cssClass = $this->addElement_tdCssClass[$lastKey];
312 if ($this->oddColumnsCssClass) {
313 $cssClass = implode(' ', [$this->addElement_tdCssClass[$lastKey], $this->oddColumnsCssClass]);
314 }
315 $out .= '
316 <' . $colType . ' class="' . $cssClass . $noWrap . '"' . $colsp . $this->addElement_tdParams[$lastKey] . '>' . $data[$lastKey] . '</' . $colType . '>';
317 }
318 // End row
319 $out .= '
320 </tr>';
321 // Return row.
322 return $out;
323 }
324
325 /**
326 * Dummy function, used to write the top of a table listing.
327 * @deprecated since TYPO3 v9, will be removed in TYPO3 v10
328 */
329 public function writeTop()
330 {
331 }
332
333 /**
334 * Creates a forward/reverse button based on the status of ->eCounter, ->firstElementNumber, ->iLimit
335 *
336 * @param string $table Table name
337 * @return array array([boolean], [HTML]) where [boolean] is 1 for reverse element, [HTML] is the table-row code for the element
338 * @deprecated since TYPO3 v9, will be removed in TYPO3 v10
339 */
340 public function fwd_rwd_nav($table = '')
341 {
342 $code = '';
343 if ($this->eCounter >= $this->firstElementNumber && $this->eCounter < $this->firstElementNumber + $this->iLimit) {
344 if ($this->firstElementNumber && $this->eCounter == $this->firstElementNumber) {
345 // Reverse
346 $theData = [];
347 $titleCol = $this->fieldArray[0];
348 $theData[$titleCol] = $this->fwd_rwd_HTML('fwd', $this->eCounter, $table);
349 $code = $this->addElement(1, '', $theData, 'class="fwd_rwd_nav"');
350 }
351 return [1, $code];
352 }
353 if ($this->eCounter == $this->firstElementNumber + $this->iLimit) {
354 // Forward
355 $theData = [];
356 $titleCol = $this->fieldArray[0];
357 $theData[$titleCol] = $this->fwd_rwd_HTML('rwd', $this->eCounter, $table);
358 $code = $this->addElement(1, '', $theData, 'class="fwd_rwd_nav"');
359 }
360 return [0, $code];
361 }
362
363 /**
364 * Creates the button with link to either forward or reverse
365 *
366 * @param string $type Type: "fwd" or "rwd
367 * @param int $pointer Pointer
368 * @param string $table Table name
369 * @return string
370 * @access private
371 * @deprecated since TYPO3 v9, will be removed in TYPO3 v10
372 */
373 public function fwd_rwd_HTML($type, $pointer, $table = '')
374 {
375 $content = '';
376 $tParam = $table ? '&table=' . rawurlencode($table) : '';
377 switch ($type) {
378 case 'fwd':
379 $href = $this->listURL() . '&pointer=' . ($pointer - $this->iLimit) . $tParam;
380 $content = '<a href="' . htmlspecialchars($href) . '">' . $this->iconFactory->getIcon('actions-move-up', Icon::SIZE_SMALL)->render() . '</a> <i>[1 - ' . $pointer . ']</i>';
381 break;
382 case 'rwd':
383 $href = $this->listURL() . '&pointer=' . $pointer . $tParam;
384 $content = '<a href="' . htmlspecialchars($href) . '">' . $this->iconFactory->getIcon('actions-move-down', Icon::SIZE_SMALL)->render() . '</a> <i>[' . ($pointer + 1) . ' - ' . $this->totalItems . ']</i>';
385 break;
386 }
387 return $content;
388 }
389
390 /**
391 * Creates the URL to this script, including all relevant GPvars
392 *
393 * @param string $altId Alternative id value. Enter blank string for the current id ($this->id)
394 * @param string $table Table name to display. Enter "-1" for the current table.
395 * @param string $exclList Comma separated list of fields NOT to include ("sortField", "sortRev" or "firstElementNumber")
396 * @return string URL
397 * @deprecated since TYPO3 v9, will be removed in TYPO3 v10
398 */
399 public function listURL($altId = '', $table = '-1', $exclList = '')
400 {
401 return $this->getThisScript() . 'id=' . ($altId !== '' ? $altId : $this->id);
402 }
403
404 /**
405 * Returning JavaScript for ClipBoard functionality.
406 *
407 * @return string
408 * @deprecated since TYPO3 v9, will be removed in TYPO3 v10
409 */
410 public function CBfunctions()
411 {
412 return '
413 // checkOffCB()
414 function checkOffCB(listOfCBnames, link) { //
415 var checkBoxes, flag, i;
416 var checkBoxes = listOfCBnames.split(",");
417 if (link.rel === "") {
418 link.rel = "allChecked";
419 flag = true;
420 } else {
421 link.rel = "";
422 flag = false;
423 }
424 for (i = 0; i < checkBoxes.length; i++) {
425 setcbValue(checkBoxes[i], flag);
426 }
427 }
428 // cbValue()
429 function cbValue(CBname) { //
430 var CBfullName = "CBC["+CBname+"]";
431 return (document.dblistForm[CBfullName] && document.dblistForm[CBfullName].checked ? 1 : 0);
432 }
433 // setcbValue()
434 function setcbValue(CBname,flag) { //
435 CBfullName = "CBC["+CBname+"]";
436 if(document.dblistForm[CBfullName]) {
437 document.dblistForm[CBfullName].checked = flag ? "on" : 0;
438 }
439 }
440
441 ';
442 }
443
444 /**
445 * Initializes page languages and icons
446 * @deprecated since TYPO3 v9, will be removed in TYPO3 v10
447 */
448 public function initializeLanguages()
449 {
450 // Look up page overlays:
451 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
452 ->getQueryBuilderForTable('pages_language_overlay');
453 $queryBuilder->getRestrictions()
454 ->removeAll()
455 ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
456 ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
457 $result = $queryBuilder
458 ->select('*')
459 ->from('pages_language_overlay')
460 ->where(
461 $queryBuilder->expr()->andX(
462 $queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($this->id, \PDO::PARAM_INT)),
463 $queryBuilder->expr()->gt('sys_language_uid', $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT))
464 )
465 )
466 ->execute();
467
468 $this->pageOverlays = [];
469 while ($row = $result->fetch()) {
470 $this->pageOverlays[$row['sys_language_uid']] = $row;
471 }
472
473 $this->languageIconTitles = $this->getTranslateTools()->getSystemLanguages($this->id);
474 }
475
476 /**
477 * Return the icon for the language
478 *
479 * @param int $sys_language_uid Sys language uid
480 * @param bool $addAsAdditionalText If set to true, only the flag is returned
481 * @return string Language icon
482 * @deprecated since TYPO3 v9, will be removed in TYPO3 v10
483 */
484 public function languageFlag($sys_language_uid, $addAsAdditionalText = true)
485 {
486 $out = '';
487 $title = htmlspecialchars($this->languageIconTitles[$sys_language_uid]['title']);
488 if ($this->languageIconTitles[$sys_language_uid]['flagIcon']) {
489 $out .= '<span title="' . $title . '">' . $this->iconFactory->getIcon($this->languageIconTitles[$sys_language_uid]['flagIcon'], Icon::SIZE_SMALL)->render() . '</span>';
490 if (!$addAsAdditionalText) {
491 return $out;
492 }
493 $out .= '&nbsp;';
494 }
495 $out .= $title;
496 return $out;
497 }
498
499 /**
500 * Gets an instance of TranslationConfigurationProvider
501 *
502 * @return TranslationConfigurationProvider
503 * @deprecated since TYPO3 v9, will be removed in TYPO3 v10
504 */
505 protected function getTranslateTools()
506 {
507 if (!isset($this->translateTools)) {
508 $this->translateTools = GeneralUtility::makeInstance(TranslationConfigurationProvider::class);
509 }
510 return $this->translateTools;
511 }
512
513 /**
514 * Generates HTML code for a Reference tooltip out of
515 * sys_refindex records you hand over
516 *
517 * @param int $references number of records from sys_refindex table
518 * @param string $launchViewParameter JavaScript String, which will be passed as parameters to top.launchView
519 * @return string
520 * @deprecated since TYPO3 v9, will be removed in TYPO3 v10
521 */
522 protected function generateReferenceToolTip($references, $launchViewParameter = '')
523 {
524 if (!$references) {
525 $htmlCode = '-';
526 } else {
527 $htmlCode = '<a href="#"';
528 if ($launchViewParameter !== '') {
529 $htmlCode .= ' onclick="' . htmlspecialchars(('top.launchView(' . $launchViewParameter . '); return false;')) . '"';
530 }
531 $htmlCode .= ' title="' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang.xlf:show_references') . ' (' . $references . ')') . '">';
532 $htmlCode .= $references;
533 $htmlCode .= '</a>';
534 }
535 return $htmlCode;
536 }
537
538 /**
539 * Returns the language service
540 * @return LanguageService
541 * @deprecated since TYPO3 v9, will be removed in TYPO3 v10
542 */
543 protected function getLanguageService()
544 {
545 return $GLOBALS['LANG'];
546 }
547 }