2 namespace TYPO3\CMS\Backend\RecordList
;
5 * This file is part of the TYPO3 CMS project.
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.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
17 use TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider
;
18 use TYPO3\CMS\Backend\Routing\Router
;
19 use TYPO3\CMS\Backend\Routing\UriBuilder
;
20 use TYPO3\CMS\Backend\Utility\BackendUtility
;
21 use TYPO3\CMS\Core\Database\ConnectionPool
;
22 use TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction
;
23 use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction
;
24 use TYPO3\CMS\Core\Imaging\Icon
;
25 use TYPO3\CMS\Core\Imaging\IconFactory
;
26 use TYPO3\CMS\Core\Utility\GeneralUtility
;
27 use TYPO3\CMS\Lang\LanguageService
;
30 * Library with a single function addElement that returns table
31 * rows based on some input.
33 * Base for class listing of database records and files in the
34 * modules Web>List and File>Filelist
36 abstract class AbstractRecordList
44 * default Max items shown
51 * OBSOLETE - NOT USED ANYMORE. leftMargin
55 public $leftMargin = 0;
65 public $no_noWrap = 0;
68 * If set this is <td> CSS-classname for odd columns in addElement. Used with db_layout / pages section
72 public $oddColumnsCssClass = '';
75 * Decides the columns shown. Filled with values that refers to the keys of the data-array. $this->fieldArray[0] is the title column.
79 public $fieldArray = [];
82 * Keys are fieldnames and values are td-parameters to add in addElement(), please use $addElement_tdCSSClass for CSS-classes;
86 public $addElement_tdParams = [];
89 * Keys are fieldnames and values are td-css-classes to add in addElement();
93 public $addElement_tdCssClass = [];
96 * Not used in this class - but maybe extension classes...
97 * Max length of strings
108 public $thisScript = '';
111 * Set to zero, if you don't want a left-margin with addElement function
115 public $setLMargin = 1;
118 * Counter increased for each element. Used to index elements for the JavaScript-code that transfers to the clipboard
125 * This could be set to the total number of items. Used by the fwd_rew_navigation...
129 public $totalItems = '';
132 * Internal (used in this class.)
136 public $firstElementNumber = 0;
141 public $eCounter = 0;
144 * String with accumulated HTML content
148 public $HTMLcode = '';
151 * Contains page translation languages
155 public $pageOverlays = [];
158 * Contains sys language icons and titles
162 public $languageIconTitles = [];
165 * @var TranslationConfigurationProvider
167 public $translateTools;
172 protected $iconFactory;
177 public function __construct()
179 if (isset($GLOBALS['BE_USER']->uc
['titleLen']) && $GLOBALS['BE_USER']->uc
['titleLen'] > 0) {
180 $this->fixedL
= $GLOBALS['BE_USER']->uc
['titleLen'];
182 $this->iconFactory
= GeneralUtility
::makeInstance(IconFactory
::class);
183 $this->getTranslateTools();
184 $this->determineScriptUrl();
188 * Sets the script url depending on being a module or script request
190 protected function determineScriptUrl()
192 if ($routePath = GeneralUtility
::_GP('route')) {
193 $router = GeneralUtility
::makeInstance(Router
::class);
194 $route = $router->match($routePath);
195 $uriBuilder = GeneralUtility
::makeInstance(UriBuilder
::class);
196 $this->thisScript
= (string)$uriBuilder->buildUriFromRoute($route->getOption('_identifier'));
197 } elseif ($moduleName = GeneralUtility
::_GP('M')) {
198 $this->thisScript
= BackendUtility
::getModuleUrl($moduleName);
200 $this->thisScript
= GeneralUtility
::getIndpEnv('SCRIPT_NAME');
207 protected function getThisScript()
209 return strpos($this->thisScript
, '?') === false ?
$this->thisScript
. '?' : $this->thisScript
. '&';
213 * Returns a table-row with the content from the fields in the input data array.
214 * OBS: $this->fieldArray MUST be set! (represents the list of fields to display)
216 * @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'
217 * @param string $icon Is the <img>+<a> of the record. If not supplied the first 'join'-icon will be a 'line' instead
218 * @param array $data Is the dataarray, record with the fields. Notice: These fields are (currently) NOT htmlspecialchar'ed before being wrapped in <td>-tags
219 * @param string $rowParams Is insert in the <tr>-tags. Must carry a ' ' as first character
220 * @param string $_ OBSOLETE - NOT USED ANYMORE. $lMargin is the leftMargin (int)
221 * @param string $_ OBSOLETE - NOT USED ANYMORE. Is the HTML <img>-tag for an alternative 'gfx/ol/line.gif'-icon (used in the top)
222 * @param string $colType Defines the tag being used for the columns. Default is td.
223 * @return string HTML content for the table row
225 public function addElement($h, $icon, $data, $rowParams = '', $_ = '', $_2 = '', $colType = 'td')
227 $colType = ($colType === 'th') ?
'th' : 'td';
228 $noWrap = $this->no_noWrap ?
'' : ' nowrap="nowrap"';
230 $l10nParent = isset($data['_l10nparent_']) ?
(int)$data['_l10nparent_'] : 0;
232 <!-- Element, begin: -->
233 <tr ' . $rowParams . ' data-uid="' . (int)$data['uid'] . '" data-l10nparent="' . $l10nParent . '">';
234 // Show icon and lines
235 if ($this->showIcon
) {
237 <' . $colType . ' nowrap="nowrap" class="col-icon">';
241 for ($a = 0; $a < $h; $a++
) {
250 $out .= '</' . $colType . '>
258 // __label is used as the label key to circumvent problems with uid used as label (see #67756)
259 // as it was introduced later on, check if it really exists before using it
260 $fields = $this->fieldArray
;
261 if ($colType === 'td' && array_key_exists('__label', $data)) {
262 $fields[0] = '__label';
264 // Traverse field array which contains the data to present:
265 foreach ($fields as $vKey) {
266 if (isset($data[$vKey])) {
268 $cssClass = $this->addElement_tdCssClass
[$lastKey];
269 if ($this->oddColumnsCssClass
&& $ccount %
2 == 0) {
270 $cssClass = implode(' ', [$this->addElement_tdCssClass
[$lastKey], $this->oddColumnsCssClass
]);
273 <' . $colType . $noWrap . ' class="' . $cssClass . '"' . $colsp . $this->addElement_tdParams
[$lastKey] . '>' . $data[$lastKey] . '</' . $colType . '>';
285 $colsp = ' colspan="' . $c . '"';
291 $cssClass = $this->addElement_tdCssClass
[$lastKey];
292 if ($this->oddColumnsCssClass
) {
293 $cssClass = implode(' ', [$this->addElement_tdCssClass
[$lastKey], $this->oddColumnsCssClass
]);
296 <' . $colType . $noWrap . ' class="' . $cssClass . '"' . $colsp . $this->addElement_tdParams
[$lastKey] . '>' . $data[$lastKey] . '</' . $colType . '>';
306 * Dummy function, used to write the top of a table listing.
310 public function writeTop()
315 * Creates a forward/reverse button based on the status of ->eCounter, ->firstElementNumber, ->iLimit
317 * @param string $table Table name
318 * @return array array([boolean], [HTML]) where [boolean] is 1 for reverse element, [HTML] is the table-row code for the element
320 public function fwd_rwd_nav($table = '')
323 if ($this->eCounter
>= $this->firstElementNumber
&& $this->eCounter
< $this->firstElementNumber +
$this->iLimit
) {
324 if ($this->firstElementNumber
&& $this->eCounter
== $this->firstElementNumber
) {
327 $titleCol = $this->fieldArray
[0];
328 $theData[$titleCol] = $this->fwd_rwd_HTML('fwd', $this->eCounter
, $table);
329 $code = $this->addElement(1, '', $theData, 'class="fwd_rwd_nav"');
333 if ($this->eCounter
== $this->firstElementNumber +
$this->iLimit
) {
336 $titleCol = $this->fieldArray
[0];
337 $theData[$titleCol] = $this->fwd_rwd_HTML('rwd', $this->eCounter
, $table);
338 $code = $this->addElement(1, '', $theData, 'class="fwd_rwd_nav"');
345 * Creates the button with link to either forward or reverse
347 * @param string $type Type: "fwd" or "rwd
348 * @param int $pointer Pointer
349 * @param string $table Table name
353 public function fwd_rwd_HTML($type, $pointer, $table = '')
356 $tParam = $table ?
'&table=' . rawurlencode($table) : '';
359 $href = $this->listURL() . '&pointer=' . ($pointer - $this->iLimit
) . $tParam;
360 $content = '<a href="' . htmlspecialchars($href) . '">' . $this->iconFactory
->getIcon('actions-move-up', Icon
::SIZE_SMALL
)->render() . '</a> <i>[1 - ' . $pointer . ']</i>';
363 $href = $this->listURL() . '&pointer=' . $pointer . $tParam;
364 $content = '<a href="' . htmlspecialchars($href) . '">' . $this->iconFactory
->getIcon('actions-move-down', Icon
::SIZE_SMALL
)->render() . '</a> <i>[' . ($pointer +
1) . ' - ' . $this->totalItems
. ']</i>';
371 * Creates the URL to this script, including all relevant GPvars
373 * @param string $altId Alternative id value. Enter blank string for the current id ($this->id)
374 * @param string $table Table name to display. Enter "-1" for the current table.
375 * @param string $exclList Comma separated list of fields NOT to include ("sortField", "sortRev" or "firstElementNumber")
378 public function listURL($altId = '', $table = '-1', $exclList = '')
380 return $this->getThisScript() . 'id=' . ($altId !== '' ?
$altId : $this->id
);
384 * Returning JavaScript for ClipBoard functionality.
388 public function CBfunctions()
392 function checkOffCB(listOfCBnames, link) { //
393 var checkBoxes, flag, i;
394 var checkBoxes = listOfCBnames.split(",");
395 if (link.rel === "") {
396 link.rel = "allChecked";
402 for (i = 0; i < checkBoxes.length; i++) {
403 setcbValue(checkBoxes[i], flag);
407 function cbValue(CBname) { //
408 var CBfullName = "CBC["+CBname+"]";
409 return (document.dblistForm[CBfullName] && document.dblistForm[CBfullName].checked ? 1 : 0);
412 function setcbValue(CBname,flag) { //
413 CBfullName = "CBC["+CBname+"]";
414 if(document.dblistForm[CBfullName]) {
415 document.dblistForm[CBfullName].checked = flag ? "on" : 0;
423 * Initializes page languages and icons
427 public function initializeLanguages()
429 // Look up page overlays:
430 $queryBuilder = GeneralUtility
::makeInstance(ConnectionPool
::class)
431 ->getQueryBuilderForTable('pages_language_overlay');
432 $queryBuilder->getRestrictions()
434 ->add(GeneralUtility
::makeInstance(DeletedRestriction
::class))
435 ->add(GeneralUtility
::makeInstance(BackendWorkspaceRestriction
::class));
436 $result = $queryBuilder
438 ->from('pages_language_overlay')
439 ->where($queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($this->id
, \PDO
::PARAM_INT
)))
442 $this->pageOverlays
= [];
443 while ($row = $result->fetch()) {
444 $this->pageOverlays
[$row['sys_language_uid']] = $row;
447 $this->languageIconTitles
= $this->getTranslateTools()->getSystemLanguages($this->id
);
451 * Return the icon for the language
453 * @param int $sys_language_uid Sys language uid
454 * @param bool $addAsAdditionalText If set to true, only the flag is returned
455 * @return string Language icon
457 public function languageFlag($sys_language_uid, $addAsAdditionalText = true)
460 $title = htmlspecialchars($this->languageIconTitles
[$sys_language_uid]['title']);
461 if ($this->languageIconTitles
[$sys_language_uid]['flagIcon']) {
462 $out .= '<span title="' . $title . '">' . $this->iconFactory
->getIcon($this->languageIconTitles
[$sys_language_uid]['flagIcon'], Icon
::SIZE_SMALL
)->render() . '</span>';
463 if (!$addAsAdditionalText) {
473 * Gets an instance of TranslationConfigurationProvider
475 * @return TranslationConfigurationProvider
477 protected function getTranslateTools()
479 if (!isset($this->translateTools
)) {
480 $this->translateTools
= GeneralUtility
::makeInstance(TranslationConfigurationProvider
::class);
482 return $this->translateTools
;
486 * Generates HTML code for a Reference tooltip out of
487 * sys_refindex records you hand over
489 * @param int $references number of records from sys_refindex table
490 * @param string $launchViewParameter JavaScript String, which will be passed as parameters to top.launchView
493 protected function generateReferenceToolTip($references, $launchViewParameter = '')
498 $htmlCode = '<a href="#"';
499 if ($launchViewParameter !== '') {
500 $htmlCode .= ' onclick="' . htmlspecialchars(('top.launchView(' . $launchViewParameter . '); return false;')) . '"';
502 $htmlCode .= ' title="' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang.xlf:show_references') . ' (' . $references . ')') . '">';
503 $htmlCode .= $references;
510 * Returns the language service
511 * @return LanguageService
513 protected function getLanguageService()
515 return $GLOBALS['LANG'];