[TASK] Remove empty row in table below header
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / View / PageLayoutView.php
1 <?php
2 namespace TYPO3\CMS\Backend\View;
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\Controller\PageLayoutController;
18 use TYPO3\CMS\Backend\Template\DocumentTemplate;
19 use TYPO3\CMS\Backend\Utility\BackendUtility;
20 use TYPO3\CMS\Backend\Utility\IconUtility;
21 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
22 use TYPO3\CMS\Core\Database\DatabaseConnection;
23 use TYPO3\CMS\Core\Messaging\FlashMessage;
24 use TYPO3\CMS\Core\Utility\GeneralUtility;
25 use TYPO3\CMS\Core\Versioning\VersionState;
26 use TYPO3\CMS\Lang\LanguageService;
27
28 /**
29 * Child class for the Web > Page module
30 *
31 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
32 */
33 class PageLayoutView extends \TYPO3\CMS\Recordlist\RecordList\AbstractDatabaseRecordList {
34
35 /**
36 * If TRUE, users/groups are shown in the page info box.
37 *
38 * @var int
39 */
40 public $pI_showUser = 0;
41
42 /**
43 * The number of successive records to edit when showing content elements.
44 *
45 * @var int
46 */
47 public $nextThree = 3;
48
49 /**
50 * If TRUE, disables the edit-column icon for tt_content elements
51 *
52 * @var int
53 */
54 public $pages_noEditColumns = 0;
55
56 /**
57 * If TRUE, shows big buttons for editing page properties, moving, creating elements etc. in the columns view.
58 *
59 * @var int
60 */
61 public $option_showBigButtons = 1;
62
63 /**
64 * If TRUE, new-wizards are linked to rather than the regular new-element list.
65 *
66 * @var int
67 */
68 public $option_newWizard = 1;
69
70 /**
71 * If set to "1", will link a big button to content element wizard.
72 *
73 * @var int
74 */
75 public $ext_function = 0;
76
77 /**
78 * If TRUE, elements will have edit icons (probably this is whether the user has permission to edit the page content). Set externally.
79 *
80 * @var int
81 */
82 public $doEdit = 1;
83
84 /**
85 * Age prefixes for displaying times. May be set externally to localized values.
86 *
87 * @var string
88 */
89 public $agePrefixes = ' min| hrs| days| yrs| min| hour| day| year';
90
91 /**
92 * Array of tables to be listed by the Web > Page module in addition to the default tables.
93 *
94 * @var array
95 */
96 public $externalTables = array();
97
98 /**
99 * "Pseudo" Description -table name
100 *
101 * @var string
102 */
103 public $descrTable;
104
105 /**
106 * If set TRUE, the language mode of tt_content elements will be rendered with hard binding between
107 * default language content elements and their translations!
108 *
109 * @var bool
110 */
111 public $defLangBinding = FALSE;
112
113 /**
114 * External, static: Configuration of tt_content element display:
115 *
116 * @var array
117 */
118 public $tt_contentConfig = array(
119 'showInfo' => 1,
120 // Boolean: Display info-marks or not
121 'showCommands' => 1,
122 // Boolean: Display up/down arrows and edit icons for tt_content records
123 'single' => 1,
124 // Boolean: If set, the content of column(s) $this->tt_contentConfig['showSingleCol'] is shown in the total width of the page
125 'showAsGrid' => 0,
126 // Boolean: If set, the content of columns is shown in grid
127 'showSingleCol' => 0,
128 // The column(s) to show if single mode (under each other)
129 'languageCols' => 0,
130 'languageMode' => 0,
131 'languageColsPointer' => 0,
132 'showHidden' => 1,
133 // Displays hidden records as well
134 'sys_language_uid' => 0,
135 // Which language
136 'cols' => '1,0,2,3',
137 'activeCols' => '1,0,2,3'
138 // Which columns can be accessed by current BE user
139 );
140
141 /**
142 * Contains icon/title of pages which are listed in the tables menu (see getTableMenu() function )
143 *
144 * @var array
145 */
146 public $activeTables = array();
147
148 /**
149 * @var array
150 */
151 public $tt_contentData = array(
152 'nextThree' => array(),
153 'prev' => array(),
154 'next' => array()
155 );
156
157 /**
158 * Used to store labels for CTypes for tt_content elements
159 *
160 * @var array
161 */
162 public $CType_labels = array();
163
164 /**
165 * Used to store labels for the various fields in tt_content elements
166 *
167 * @var array
168 */
169 public $itemLabels = array();
170
171 /**
172 * Used to store the RTE setup of a particular page
173 *
174 * @var array
175 */
176 protected $rteSetup = array();
177
178 /**
179 * @var \TYPO3\CMS\Backend\Clipboard\Clipboard
180 */
181 protected $clipboard;
182
183 /**
184 * @var array
185 */
186 protected $plusPages = array();
187
188 /**
189 * User permissions
190 *
191 * @var int
192 */
193 public $ext_CALC_PERMS;
194
195 /*****************************************
196 *
197 * Renderings
198 *
199 *****************************************/
200 /**
201 * Adds the code of a single table
202 *
203 * @param string $table Table name
204 * @param int $id Current page id
205 * @return string HTML for listing.
206 */
207 public function getTable($table, $id) {
208 if (isset($this->externalTables[$table])) {
209 return $this->getExternalTables($id, $table);
210 } else {
211 // Branch out based on table name:
212 switch ($table) {
213 case 'pages':
214 return $this->getTable_pages($id);
215 break;
216 case 'tt_content':
217 return $this->getTable_tt_content($id);
218 break;
219 default:
220 return '';
221 }
222 }
223 }
224
225 /**
226 * Renders an external table from page id
227 *
228 * @param int $id Page id
229 * @param string $table Name of the table
230 * @return string HTML for the listing
231 */
232 public function getExternalTables($id, $table) {
233 $type = $this->getPageLayoutController()->MOD_SETTINGS[$table];
234 if (!isset($type)) {
235 $type = 0;
236 }
237 // eg. "name;title;email;company,image"
238 $fList = $this->externalTables[$table][$type]['fList'];
239 // The columns are separeted by comma ','.
240 // Values separated by semicolon ';' are shown in the same column.
241 $icon = $this->externalTables[$table][$type]['icon'];
242 $addWhere = $this->externalTables[$table][$type]['addWhere'];
243 // Create listing
244 $out = $this->makeOrdinaryList($table, $id, $fList, $icon, $addWhere);
245 return $out;
246 }
247
248 /**
249 * Renders records from the pages table from page id
250 * (Used to get information about the page tree content by "Web>Info"!)
251 *
252 * @param int $id Page id
253 * @return string HTML for the listing
254 */
255 public function getTable_pages($id) {
256 // Initializing:
257 $out = '';
258 // Select clause for pages:
259 $delClause = BackendUtility::deleteClause('pages') . ' AND ' . $this->getBackendUser()->getPagePermsClause(1);
260 // Select current page:
261 if (!$id) {
262 // The root has a pseudo record in pageinfo...
263 $row = $this->getPageLayoutController()->pageinfo;
264 } else {
265 $result = $this->getDatabase()->exec_SELECTquery('*', 'pages', 'uid=' . (int)$id . $delClause);
266 $row = $this->getDatabase()->sql_fetch_assoc($result);
267 BackendUtility::workspaceOL('pages', $row);
268 }
269 // If there was found a page:
270 if (is_array($row)) {
271 // Select which fields to show:
272 $pKey = $this->getPageLayoutController()->MOD_SETTINGS['pages'];
273 switch ($pKey) {
274 case 1:
275 $this->fieldArray = array('title','uid') + array_keys($this->cleanTableNames());
276 break;
277 case 2:
278 $this->fieldArray = array(
279 'title',
280 'uid',
281 'lastUpdated',
282 'newUntil',
283 'no_cache',
284 'cache_timeout',
285 'php_tree_stop',
286 'TSconfig',
287 'storage_pid',
288 'is_siteroot',
289 'fe_login_mode'
290 );
291 break;
292 default:
293 $this->fieldArray = array(
294 'title',
295 'uid',
296 'alias',
297 'starttime',
298 'endtime',
299 'fe_group',
300 'target',
301 'url',
302 'shortcut',
303 'shortcut_mode'
304 );
305 }
306 // Getting select-depth:
307 $depth = (int)$this->getPageLayoutController()->MOD_SETTINGS['pages_levels'];
308 // Overriding a few things:
309 $this->no_noWrap = 0;
310 // Items
311 $this->eCounter = $this->firstElementNumber;
312 // Creating elements:
313 list($flag, $code) = $this->fwd_rwd_nav();
314 $out .= $code;
315 $editUids = array();
316 if ($flag) {
317 // Getting children:
318 $theRows = array();
319 $theRows = $this->pages_getTree($theRows, $row['uid'], $delClause . BackendUtility::versioningPlaceholderClause('pages'), '', $depth);
320 if ($this->getBackendUser()->doesUserHaveAccess($row, 2)) {
321 $editUids[] = $row['uid'];
322 }
323 $out .= $this->pages_drawItem($row, $this->fieldArray);
324 // Traverse all pages selected:
325 foreach ($theRows as $sRow) {
326 if ($this->getBackendUser()->doesUserHaveAccess($sRow, 2)) {
327 $editUids[] = $sRow['uid'];
328 }
329 $out .= $this->pages_drawItem($sRow, $this->fieldArray);
330 }
331 $this->eCounter++;
332 }
333 // Header line is drawn
334 $theData = array();
335 $editIdList = implode(',', $editUids);
336 // Traverse fields (as set above) in order to create header values:
337 foreach ($this->fieldArray as $field) {
338 if ($editIdList && isset($GLOBALS['TCA']['pages']['columns'][$field]) && $field != 'uid' && !$this->pages_noEditColumns) {
339 $params = '&edit[pages][' . $editIdList . ']=edit&columnsOnly=' . $field . '&disHelp=1';
340 $iTitle = sprintf(
341 $this->getLanguageService()->getLL('editThisColumn'),
342 rtrim(trim($this->getLanguageService()->sL(BackendUtility::getItemLabel('pages', $field))), ':')
343 );
344 $eI = '<a href="#" onclick="' . htmlspecialchars(BackendUtility::editOnClick($params, $this->backPath, ''))
345 . '" title="' . htmlspecialchars($iTitle) . '">' . IconUtility::getSpriteIcon('actions-document-open') . '</a>';
346 } else {
347 $eI = '';
348 }
349 switch ($field) {
350 case 'title':
351 $theData[$field] = '&nbsp;<strong>'
352 . $this->getLanguageService()->sL($GLOBALS['TCA']['pages']['columns'][$field]['label'])
353 . '</strong>' . $eI;
354 break;
355 case 'uid':
356 $theData[$field] = '&nbsp;<strong>ID:</strong>';
357 break;
358 default:
359 if (substr($field, 0, 6) == 'table_') {
360 $f2 = substr($field, 6);
361 if ($GLOBALS['TCA'][$f2]) {
362 $theData[$field] = '&nbsp;' . IconUtility::getSpriteIconForRecord($f2, array(), array(
363 'title' => $this->getLanguageService()->sL($GLOBALS['TCA'][$f2]['ctrl']['title'], TRUE)
364 ));
365 }
366 } else {
367 $theData[$field] = '&nbsp;&nbsp;<strong>'
368 . $this->getLanguageService()->sL($GLOBALS['TCA']['pages']['columns'][$field]['label'], TRUE)
369 . '</strong>' . $eI;
370 }
371 }
372 }
373 // CSH:
374 $out = BackendUtility::cshItem($this->descrTable, ('func_' . $pKey)) . '
375 <table class="t3-table typo3-page-pages">' .
376 '<thead>' .
377 $this->addelement(1, '', $theData) .
378 '</thead>' .
379 '<tbody>' .
380 $out .
381 '</tbody>' .
382 '</table>';
383 }
384 return $out;
385 }
386
387 /**
388 * Renders Content Elements from the tt_content table from page id
389 *
390 * @param int $id Page id
391 * @return string HTML for the listing
392 */
393 public function getTable_tt_content($id) {
394 $this->initializeLanguages();
395 $this->initializeClipboard();
396 // Initialize:
397 $RTE = $this->getBackendUser()->isRTE();
398 $lMarg = 1;
399 $showHidden = $this->tt_contentConfig['showHidden'] ? '' : BackendUtility::BEenableFields('tt_content');
400 $pageTitleParamForAltDoc = '&recTitle=' . rawurlencode(BackendUtility::getRecordTitle('pages', BackendUtility::getRecordWSOL('pages', $id), TRUE));
401 /** @var $pageRenderer \TYPO3\CMS\Core\Page\PageRenderer */
402 $pageRenderer = $this->getPageLayoutController()->doc->getPageRenderer();
403 $pageRenderer->loadExtJs();
404 $pageRenderer->addJsFile($GLOBALS['BACK_PATH'] . 'sysext/cms/layout/js/typo3pageModule.js');
405 // Get labels for CTypes and tt_content element fields in general:
406 $this->CType_labels = array();
407 foreach ($GLOBALS['TCA']['tt_content']['columns']['CType']['config']['items'] as $val) {
408 $this->CType_labels[$val[1]] = $this->getLanguageService()->sL($val[0]);
409 }
410 $this->itemLabels = array();
411 foreach ($GLOBALS['TCA']['tt_content']['columns'] as $name => $val) {
412 $this->itemLabels[$name] = $this->getLanguageService()->sL($val['label']);
413 }
414 $languageColumn = array();
415 $out = '';
416 // Select display mode:
417 // MULTIPLE column display mode, side by side:
418 if (!$this->tt_contentConfig['single']) {
419 // Setting language list:
420 $langList = $this->tt_contentConfig['sys_language_uid'];
421 if ($this->tt_contentConfig['languageMode']) {
422 if ($this->tt_contentConfig['languageColsPointer']) {
423 $langList = '0,' . $this->tt_contentConfig['languageColsPointer'];
424 } else {
425 $langList = implode(',', array_keys($this->tt_contentConfig['languageCols']));
426 }
427 $languageColumn = array();
428 }
429 $langListArr = GeneralUtility::intExplode(',', $langList);
430 $defLanguageCount = array();
431 $defLangBinding = array();
432 // For each languages... :
433 // If not languageMode, then we'll only be through this once.
434 foreach ($langListArr as $lP) {
435 $lP = (int)$lP;
436 if (count($langListArr) === 1 || $lP === 0) {
437 $showLanguage = ' AND sys_language_uid IN (' . $lP . ',-1)';
438 } else {
439 $showLanguage = ' AND sys_language_uid=' . $lP;
440 }
441 $cList = explode(',', $this->tt_contentConfig['cols']);
442 $content = array();
443 $head = array();
444
445 // Select content records per column
446 $contentRecordsPerColumn = $this->getContentRecordsPerColumn('table', $id, array_values($cList), $showHidden . $showLanguage);
447 // For each column, render the content into a variable:
448 foreach ($cList as $key) {
449 if (!$lP) {
450 $defLanguageCount[$key] = array();
451 }
452 // Start wrapping div
453 $content[$key] .= '<div class="t3-page-ce-wrapper';
454 if (count($contentRecordsPerColumn[$key]) === 0) {
455 $content[$key] .= ' t3-page-ce-empty';
456 }
457 $content[$key] .= '">';
458 // Add new content at the top most position
459 $content[$key] .= '
460 <div class="t3-page-ce" id="' . str_replace('.', '', uniqid('', TRUE)) . '">
461 <div class="t3-page-ce-dropzone" id="colpos-' . $key . '-' . 'page-' . $id . '-' . uniqid('', TRUE) . '">
462 <div class="t3-page-ce-wrapper-new-ce">
463 <a href="#" onclick="' . htmlspecialchars($this->newContentElementOnClick($id, $key, $lP))
464 . '" title="' . $this->getLanguageService()->getLL('newRecordHere', TRUE) . '">'
465 . IconUtility::getSpriteIcon('actions-document-new') . '</a>
466 </div>
467 </div>
468 </div>
469 ';
470 $editUidList = '';
471 $rowArr = $contentRecordsPerColumn[$key];
472 $this->generateTtContentDataArray($rowArr);
473 foreach ((array)$rowArr as $rKey => $row) {
474 if ($this->tt_contentConfig['languageMode']) {
475 $languageColumn[$key][$lP] = $head[$key] . $content[$key];
476 if (!$this->defLangBinding) {
477 $languageColumn[$key][$lP] .= $this->newLanguageButton(
478 $this->getNonTranslatedTTcontentUids($defLanguageCount[$key], $id, $lP),
479 $lP
480 );
481 }
482 }
483 if (is_array($row) && !VersionState::cast($row['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)) {
484 $singleElementHTML = '';
485 if (!$lP && ($this->defLangBinding || $row['sys_language_uid'] != -1)) {
486 $defLanguageCount[$key][] = $row['uid'];
487 }
488 $editUidList .= $row['uid'] . ',';
489 $disableMoveAndNewButtons = $this->defLangBinding && $lP > 0;
490 if (!$this->tt_contentConfig['languageMode']) {
491 $singleElementHTML .= '<div class="t3-page-ce-dragitem" id="' . str_replace('.', '', uniqid('', TRUE)) . '">';
492 }
493 $singleElementHTML .= $this->tt_content_drawHeader(
494 $row,
495 $this->tt_contentConfig['showInfo'] ? 15 : 5,
496 $disableMoveAndNewButtons,
497 TRUE,
498 !$this->tt_contentConfig['languageMode']
499 );
500 $isRTE = $RTE && $this->isRTEforField('tt_content', $row, 'bodytext');
501 $innerContent = '<div ' . ($row['_ORIG_uid'] ? ' class="ver-element"' : '') . '>'
502 . $this->tt_content_drawItem($row, $isRTE) . '</div>';
503 $singleElementHTML .= '<div class="t3-page-ce-body-inner">' . $innerContent . '</div>'
504 . $this->tt_content_drawFooter($row);
505 // NOTE: this is the end tag for <div class="t3-page-ce-body">
506 // because of bad (historic) conception, starting tag has to be placed inside tt_content_drawHeader()
507 $singleElementHTML .= '</div>';
508 $statusHidden = $this->isDisabled('tt_content', $row) ? ' t3-page-ce-hidden' : '';
509 $singleElementHTML = '<div class="t3-page-ce' . $statusHidden . '" id="element-tt_content-'
510 . $row['uid'] . '">' . $singleElementHTML . '</div>';
511 if ($this->tt_contentConfig['languageMode']) {
512 $singleElementHTML .= '<div class="t3-page-ce">';
513 }
514 $singleElementHTML .= '<div class="t3-page-ce-dropzone" id="colpos-' . $key . '-' . 'page-' . $id .
515 '-' . str_replace('.', '', uniqid('', TRUE)) . '">';
516 // Add icon "new content element below"
517 if (!$disableMoveAndNewButtons) {
518 // New content element:
519 if ($this->option_newWizard) {
520 $onClick = 'window.location.href=\'db_new_content_el.php?id=' . $row['pid']
521 . '&sys_language_uid=' . $row['sys_language_uid'] . '&colPos=' . $row['colPos']
522 . '&uid_pid=' . -$row['uid'] .
523 '&returnUrl=' . rawurlencode(GeneralUtility::getIndpEnv('REQUEST_URI')) . '\';';
524 } else {
525 $params = '&edit[tt_content][' . -$row['uid'] . ']=new';
526 $onClick = BackendUtility::editOnClick($params, $this->backPath);
527 }
528 $singleElementHTML .= '
529 <div class="t3-page-ce-wrapper-new-ce">
530 <a href="#" onclick="' . htmlspecialchars($onClick) . '" title="'
531 . $this->getLanguageService()->getLL('newRecordHere', TRUE) . '">'
532 . IconUtility::getSpriteIcon('actions-document-new') . '</a>
533 </div>
534 ';
535 }
536 $singleElementHTML .= '</div></div>';
537 if ($this->defLangBinding && $this->tt_contentConfig['languageMode']) {
538 $defLangBinding[$key][$lP][$row[$lP ? 'l18n_parent' : 'uid']] = $singleElementHTML;
539 } else {
540 $content[$key] .= $singleElementHTML;
541 }
542 } else {
543 unset($rowArr[$rKey]);
544 }
545 }
546 $content[$key] .= '</div>';
547 // Add new-icon link, header:
548 $newP = $this->newContentElementOnClick($id, $key, $lP);
549 $colTitle = BackendUtility::getProcessedValue('tt_content', 'colPos', $key);
550 $tcaItems = GeneralUtility::callUserFunction('TYPO3\\CMS\\Backend\\View\\BackendLayoutView->getColPosListItemsParsed', $id, $this);
551 foreach ($tcaItems as $item) {
552 if ($item[1] == $key) {
553 $colTitle = $this->getLanguageService()->sL($item[0]);
554 }
555 }
556
557 $pasteP = array('colPos' => $key, 'sys_language_uid' => $lP);
558 $editParam = $this->doEdit && count($rowArr)
559 ? '&edit[tt_content][' . $editUidList . ']=edit' . $pageTitleParamForAltDoc
560 : '';
561 $head[$key] .= $this->tt_content_drawColHeader($colTitle, $editParam, $newP, $pasteP);
562 }
563 // For each column, fit the rendered content into a table cell:
564 $out = '';
565 if ($this->tt_contentConfig['languageMode']) {
566 // in language mode process the content elements, but only fill $languageColumn. output will be generated later
567 foreach ($cList as $key) {
568 $languageColumn[$key][$lP] = $head[$key] . $content[$key];
569 if (!$this->defLangBinding) {
570 $languageColumn[$key][$lP] .= $this->newLanguageButton(
571 $this->getNonTranslatedTTcontentUids($defLanguageCount[$key], $id, $lP),
572 $lP
573 );
574 }
575 }
576 } else {
577 $backendLayout = $this->getBackendLayoutView()->getSelectedBackendLayout($this->id);
578 // GRID VIEW:
579 $grid = '<div class="t3-gridContainer"><table border="0" cellspacing="0" cellpadding="0" width="100%" height="100%" class="t3-page-columns t3-gridTable">';
580 // Add colgroups
581 $colCount = (int)$backendLayout['__config']['backend_layout.']['colCount'];
582 $rowCount = (int)$backendLayout['__config']['backend_layout.']['rowCount'];
583 $grid .= '<colgroup>';
584 for ($i = 0; $i < $colCount; $i++) {
585 $grid .= '<col style="width:' . 100 / $colCount . '%"></col>';
586 }
587 $grid .= '</colgroup>';
588 // Cycle through rows
589 for ($row = 1; $row <= $rowCount; $row++) {
590 $rowConfig = $backendLayout['__config']['backend_layout.']['rows.'][$row . '.'];
591 if (!isset($rowConfig)) {
592 continue;
593 }
594 $grid .= '<tr>';
595 for ($col = 1; $col <= $colCount; $col++) {
596 $columnConfig = $rowConfig['columns.'][$col . '.'];
597 if (!isset($columnConfig)) {
598 continue;
599 }
600 // Which tt_content colPos should be displayed inside this cell
601 $columnKey = (int)$columnConfig['colPos'];
602 // Render the grid cell
603 $colSpan = (int)$columnConfig['colspan'];
604 $rowSpan = (int)$columnConfig['rowspan'];
605 $grid .= '<td valign="top"' .
606 ($colSpan > 0 ? ' colspan="' . $colSpan . '"' : '') .
607 ($rowSpan > 0 ? ' rowspan="' . $rowSpan . '"' : '') .
608 ' class="t3-gridCell t3-page-column t3-page-column-' . $columnKey .
609 ((!isset($columnConfig['colPos']) || $columnConfig['colPos'] === '') ? ' t3-gridCell-unassigned' : '') .
610 ((isset($columnConfig['colPos']) && $columnConfig['colPos'] !== '' && !$head[$columnKey]) || !GeneralUtility::inList($this->tt_contentConfig['activeCols'], $columnConfig['colPos']) ? ' t3-gridCell-restricted' : '') .
611 ($colSpan > 0 ? ' t3-gridCell-width' . $colSpan : '') .
612 ($rowSpan > 0 ? ' t3-gridCell-height' . $rowSpan : '') . '">';
613
614 // Draw the pre-generated header with edit and new buttons if a colPos is assigned.
615 // If not, a new header without any buttons will be generated.
616 if (
617 isset($columnConfig['colPos']) && $columnConfig['colPos'] !== '' && $head[$columnKey]
618 && GeneralUtility::inList($this->tt_contentConfig['activeCols'], $columnConfig['colPos'])
619 ) {
620 $grid .= $head[$columnKey] . $content[$columnKey];
621 } elseif (
622 isset($columnConfig['colPos']) && $columnConfig['colPos'] !== ''
623 && GeneralUtility::inList($this->tt_contentConfig['activeCols'], $columnConfig['colPos'])
624 ) {
625 $grid .= $this->tt_content_drawColHeader($this->getLanguageService()->getLL('noAccess'), '', '');
626 } elseif (
627 isset($columnConfig['colPos']) && $columnConfig['colPos'] !== ''
628 && !GeneralUtility::inList($this->tt_contentConfig['activeCols'], $columnConfig['colPos'])
629 ) {
630 $grid .= $this->tt_content_drawColHeader($this->getLanguageService()->sL($columnConfig['name']) .
631 ' (' . $this->getLanguageService()->getLL('noAccess') . ')', '', '');
632 } elseif (isset($columnConfig['name']) && strlen($columnConfig['name']) > 0) {
633 $grid .= $this->tt_content_drawColHeader($this->getLanguageService()->sL($columnConfig['name'])
634 . ' (' . $this->getLanguageService()->getLL('notAssigned') . ')', '', '');
635 } else {
636 $grid .= $this->tt_content_drawColHeader($this->getLanguageService()->getLL('notAssigned'), '', '');
637 }
638
639 $grid .= '</td>';
640 }
641 $grid .= '</tr>';
642 }
643 $out .= $grid . '</table></div>';
644 }
645 // CSH:
646 $out .= BackendUtility::cshItem($this->descrTable, 'columns_multi');
647 }
648 // If language mode, then make another presentation:
649 // Notice that THIS presentation will override the value of $out!
650 // But it needs the code above to execute since $languageColumn is filled with content we need!
651 if ($this->tt_contentConfig['languageMode']) {
652 // Get language selector:
653 $languageSelector = $this->languageSelector($id);
654 // Reset out - we will make new content here:
655 $out = '';
656 // Traverse languages found on the page and build up the table displaying them side by side:
657 $cCont = array();
658 $sCont = array();
659 foreach ($langListArr as $lP) {
660 // Header:
661 $lP = (int)$lP;
662 $cCont[$lP] = '
663 <td valign="top" class="t3-page-lang-column">
664 <h3>' . htmlspecialchars($this->tt_contentConfig['languageCols'][$lP]) . '</h3>
665 </td>';
666
667 // "View page" icon is added:
668 $onClick = BackendUtility::viewOnClick($this->id, $this->backPath, BackendUtility::BEgetRootLine($this->id), '', '', ('&L=' . $lP));
669 $viewLink = '<a href="#" onclick="' . htmlspecialchars($onClick) . '">' . IconUtility::getSpriteIcon('actions-document-view') . '</a>';
670 // Language overlay page header:
671 if ($lP) {
672 list($lpRecord) = BackendUtility::getRecordsByField('pages_language_overlay', 'pid', $id, 'AND sys_language_uid=' . $lP);
673 BackendUtility::workspaceOL('pages_language_overlay', $lpRecord);
674 $params = '&edit[pages_language_overlay][' . $lpRecord['uid'] . ']=edit&overrideVals[pages_language_overlay][sys_language_uid]=' . $lP;
675 $lPLabel = $this->getPageLayoutController()->doc->wrapClickMenuOnIcon(
676 IconUtility::getSpriteIconForRecord('pages_language_overlay', $lpRecord),
677 'pages_language_overlay',
678 $lpRecord['uid']
679 ) . $viewLink . ($this->getBackendUser()->check('tables_modify', 'pages_language_overlay')
680 ? '<a href="#" onclick="' . htmlspecialchars(BackendUtility::editOnClick($params, $this->backPath))
681 . '" title="' . $this->getLanguageService()->getLL('edit', TRUE) . '">'
682 . IconUtility::getSpriteIcon('actions-document-open') . '</a>'
683 : ''
684 ) . htmlspecialchars(GeneralUtility::fixed_lgd_cs($lpRecord['title'], 20));
685 } else {
686 $lPLabel = $viewLink;
687 }
688 $sCont[$lP] = '
689 <td nowrap="nowrap" class="t3-page-lang-column t3-page-lang-label">' . $lPLabel . '</td>';
690 }
691 // Add headers:
692 $out .= '<tr>' . implode($cCont) . '</tr>';
693 $out .= '<tr>' . implode($sCont) . '</tr>';
694 // Traverse previously built content for the columns:
695 foreach ($languageColumn as $cKey => $cCont) {
696 $out .= '
697 <tr>
698 <td valign="top" class="t3-gridCell t3-page-column t3-page-lang-column">' . implode(('</td>' . '
699 <td valign="top" class="t3-gridCell t3-page-column t3-page-lang-column">'), $cCont) . '</td>
700 </tr>';
701 if ($this->defLangBinding) {
702 // "defLangBinding" mode
703 foreach ($defLanguageCount[$cKey] as $defUid) {
704 $cCont = array();
705 foreach ($langListArr as $lP) {
706 $cCont[] = $defLangBinding[$cKey][$lP][$defUid] . $this->newLanguageButton(
707 $this->getNonTranslatedTTcontentUids(array($defUid), $id, $lP),
708 $lP
709 );
710 }
711 $out .= '
712 <tr>
713 <td valign="top" class="t3-page-lang-column">' . implode(('</td>' . '
714 <td valign="top" class="t3-page-lang-column">'), $cCont) . '</td>
715 </tr>';
716 }
717 // Create spacer:
718 $cCont = array_fill(0, count($langListArr), '&nbsp;');
719 $out .= '
720 <tr>
721 <td valign="top" class="t3-page-lang-column">' . implode(('</td>' . '
722 <td valign="top" class="t3-page-lang-column">'), $cCont) . '</td>
723 </tr>';
724 }
725 }
726 // Finally, wrap it all in a table and add the language selector on top of it:
727 $out = $languageSelector . '
728 <div class="t3-lang-gridContainer">
729 <table cellpadding="0" cellspacing="0" class="t3-page-langMode">
730 ' . $out . '
731 </table>
732 </div>';
733 // CSH:
734 $out .= BackendUtility::cshItem($this->descrTable, 'language_list');
735 }
736 } else {
737 // SINGLE column mode (columns shown beneath each other):
738 if ($this->tt_contentConfig['sys_language_uid'] == 0 || !$this->defLangBinding) {
739 // Initialize:
740 if ($this->defLangBinding && $this->tt_contentConfig['sys_language_uid'] == 0) {
741 $showLanguage = ' AND sys_language_uid IN (0,-1)';
742 $lP = 0;
743 } else {
744 $showLanguage = ' AND sys_language_uid=' . $this->tt_contentConfig['sys_language_uid'];
745 $lP = $this->tt_contentConfig['sys_language_uid'];
746 }
747 $cList = explode(',', $this->tt_contentConfig['showSingleCol']);
748 $out = '';
749 // Expand the table to some preset dimensions:
750 $out .= '
751 <tr>
752 <td><img src="clear.gif" width="' . $lMarg . '" height="1" alt="" /></td>
753 <td valign="top"><img src="clear.gif" width="150" height="1" alt="" /></td>
754 <td><img src="clear.gif" width="10" height="1" alt="" /></td>
755 <td valign="top"><img src="clear.gif" width="300" height="1" alt="" /></td>
756 </tr>';
757
758 // Select content records per column
759 $contentRecordsPerColumn = $this->getContentRecordsPerColumn('tt_content', $id, array_values($cList), $showHidden . $showLanguage);
760 // Traverse columns to display top-on-top
761 foreach ($cList as $counter => $key) {
762 $c = 0;
763 $rowArr = $contentRecordsPerColumn[$key];
764 $this->generateTtContentDataArray($rowArr);
765 $numberOfContentElementsInColumn = count($rowArr);
766 $rowOut = '';
767 // If it turns out that there are not content elements in the column, then display a big button which links directly to the wizard script:
768 if ($this->doEdit && $this->option_showBigButtons && !(int)$key && $numberOfContentElementsInColumn == 0) {
769 $onClick = 'window.location.href=\'db_new_content_el.php?id=' . $id . '&colPos=' . (int)$key
770 . '&sys_language_uid=' . $lP . '&uid_pid=' . $id . '&returnUrl='
771 . rawurlencode(GeneralUtility::getIndpEnv('REQUEST_URI')) . '\';';
772 $theNewButton = $this->getPageLayoutController()->doc->t3Button($onClick, $this->getLanguageService()->getLL('newPageContent'));
773 $theNewButton = '<img src="clear.gif" width="1" height="5" alt="" /><br />' . $theNewButton;
774 } else {
775 $theNewButton = '';
776 }
777 $editUidList = '';
778 // Traverse any selected elements:
779 foreach ($rowArr as $rKey => $row) {
780 if (is_array($row) && !VersionState::cast($row['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)) {
781 $c++;
782 $editUidList .= $row['uid'] . ',';
783 $isRTE = $RTE && $this->isRTEforField('tt_content', $row, 'bodytext');
784 // Create row output:
785 $rowOut .= '
786 <tr>
787 <td></td>
788 <td valign="top">' . $this->tt_content_drawHeader($row) . '</td>
789 <td>&nbsp;</td>
790 <td' . ($row['_ORIG_uid'] ? ' class="ver-element"' : '') . ' valign="top">'
791 . $this->tt_content_drawItem($row, $isRTE) . '</td>
792 </tr>';
793 // If the element was not the last element, add a divider line:
794 if ($c != $numberOfContentElementsInColumn) {
795 $rowOut .= '
796 <tr>
797 <td></td>
798 <td colspan="3"><img'
799 . IconUtility::skinImg($this->backPath, 'gfx/stiblet_medium2.gif', 'width="468" height="1"')
800 . ' class="c-divider" alt="" /></td>
801 </tr>';
802 }
803 } else {
804 unset($rowArr[$rKey]);
805 }
806 }
807 // Add spacer between sections in the vertical list
808 if ($counter) {
809 $out .= '
810 <tr>
811 <td></td>
812 <td colspan="3"><br /><br /><br /><br /></td>
813 </tr>';
814 }
815 // Add section header:
816 $newP = $this->newContentElementOnClick($id, $key, $this->tt_contentConfig['sys_language_uid']);
817 $pasteP = array('colPos' => $key, 'sys_language_uid' => $this->tt_contentConfig['sys_language_uid']);
818 $out .= '
819
820 <!-- Column header: -->
821 <tr>
822 <td></td>
823 <td valign="top" colspan="3">' . $this->tt_content_drawColHeader(
824 BackendUtility::getProcessedValue('tt_content', 'colPos', $key),
825 $this->doEdit && count($rowArr) ? '&edit[tt_content][' . $editUidList . ']=edit' . $pageTitleParamForAltDoc : '',
826 $newP,
827 $pasteP
828 ) . $theNewButton . '<br /></td>
829 </tr>';
830 // Finally, add the content from the records in this column:
831 $out .= $rowOut;
832 }
833 // Finally, wrap all table rows in one, big table:
834 $out = '
835 <table border="0" cellpadding="0" cellspacing="0" width="400" class="typo3-page-columnsMode">
836 ' . $out . '
837 </table>';
838 // CSH:
839 $out .= BackendUtility::cshItem($this->descrTable, 'columns_single');
840 } else {
841 $out = '<br/><br/>' . $this->getPageLayoutController()->doc->icons(1)
842 . 'Sorry, you cannot view a single language in this localization mode (Default Language Binding is enabled)<br/><br/>';
843 }
844 }
845 // Add the big buttons to page:
846 if ($this->option_showBigButtons) {
847 $bArray = array();
848 if (!$this->getPageLayoutController()->current_sys_language) {
849 if ($this->ext_CALC_PERMS & 2) {
850 $bArray[0] = $this->getPageLayoutController()->doc->t3Button(
851 BackendUtility::editOnClick('&edit[pages][' . $id . ']=edit', $this->backPath, ''),
852 $this->getLanguageService()->getLL('editPageProperties')
853 );
854 }
855 } else {
856 if ($this->doEdit && $this->getBackendUser()->check('tables_modify', 'pages_language_overlay')) {
857 list($languageOverlayRecord) = BackendUtility::getRecordsByField(
858 'pages_language_overlay',
859 'pid',
860 $id,
861 'AND sys_language_uid=' . (int)$this->getPageLayoutController()->current_sys_language
862 );
863 $bArray[0] = $this->getPageLayoutController()->doc->t3Button(
864 BackendUtility::editOnClick('&edit[pages_language_overlay][' . $languageOverlayRecord['uid'] . ']=edit',
865 $this->backPath, ''),
866 $this->getLanguageService()->getLL('editPageProperties_curLang')
867 );
868 }
869 }
870 if ($this->ext_CALC_PERMS & 4 || $this->ext_CALC_PERMS & 2) {
871 $bArray[1] = $this->getPageLayoutController()->doc->t3Button(
872 'window.location.href=\'' . $this->backPath . 'move_el.php?table=pages&uid=' . $id
873 . '&returnUrl=' . rawurlencode(GeneralUtility::getIndpEnv('REQUEST_URI')) . '\';',
874 $this->getLanguageService()->getLL('move_page')
875 );
876 }
877 if ($this->ext_CALC_PERMS & 8) {
878 $bArray[2] = $this->getPageLayoutController()->doc->t3Button(
879 'window.location.href=\'' . $this->backPath . 'db_new.php?id=' . $id
880 . '&pagesOnly=1&returnUrl=' . rawurlencode(GeneralUtility::getIndpEnv('REQUEST_URI')) . '\';',
881 $this->getLanguageService()->getLL('newPage2')
882 );
883 }
884 if ($this->doEdit && $this->ext_function == 1) {
885 $bArray[3] = $this->getPageLayoutController()->doc->t3Button(
886 'window.location.href=\'db_new_content_el.php?id=' . $id
887 . '&sys_language_uid=' . $this->getPageLayoutController()->current_sys_language
888 . '&returnUrl=' . rawurlencode(GeneralUtility::getIndpEnv('REQUEST_URI')) . '\';',
889 $this->getLanguageService()->getLL('newPageContent2')
890 );
891 }
892 $out = '
893 <table border="0" cellpadding="4" cellspacing="0" class="typo3-page-buttons">
894 <tr>
895 <td>' . implode('</td>
896 <td>', $bArray) . '</td>
897 <td>' . BackendUtility::cshItem($this->descrTable, 'button_panel') . '</td>
898 </tr>
899 </table>
900 <br />
901 ' . $out;
902 }
903 // Return content:
904 return $out;
905 }
906
907 /**
908 * Get backend layout configuration
909 *
910 * @return array
911 * @deprecated since TYPO3 CMS 6.2, will be removed two versions later
912 */
913 public function getBackendLayoutConfiguration() {
914 GeneralUtility::logDeprecatedFunction();
915 return $this->getBackendLayoutView()->getSelectedBackendLayout($this->id);
916 }
917
918 /**********************************
919 *
920 * Generic listing of items
921 *
922 **********************************/
923 /**
924 * Creates a standard list of elements from a table.
925 *
926 * @param string $table Table name
927 * @param int $id Page id.
928 * @param string $fList Comma list of fields to display
929 * @param bool $icon If TRUE, icon is shown
930 * @param string $addWhere Additional WHERE-clauses.
931 * @return string HTML table
932 */
933 public function makeOrdinaryList($table, $id, $fList, $icon = FALSE, $addWhere = '') {
934 // Initialize
935 $queryParts = $this->makeQueryArray($table, $id, $addWhere);
936 $this->setTotalItems($queryParts);
937 $dbCount = 0;
938 $result = FALSE;
939 // Make query for records if there were any records found in the count operation
940 if ($this->totalItems) {
941 $result = $this->getDatabase()->exec_SELECT_queryArray($queryParts);
942 // Will return FALSE, if $result is invalid
943 $dbCount = $this->getDatabase()->sql_num_rows($result);
944 }
945 // If records were found, render the list
946 if (!$dbCount) {
947 return '';
948 }
949 // Set fields
950 $out = '';
951 $this->fieldArray = GeneralUtility::trimExplode(',', '__cmds__,' . $fList . ',__editIconLink__', TRUE);
952 $theData = array();
953 $theData = $this->headerFields($this->fieldArray, $table, $theData);
954 // Title row
955 $localizedTableTitle = $this->getLanguageService()->sL($GLOBALS['TCA'][$table]['ctrl']['title'], TRUE);
956 $out .= '<tr class="t3-row-header">' . '<td nowrap="nowrap" class="col-icon"></td>'
957 . '<td nowrap="nowrap" colspan="' . (count($theData) - 2) . '"><span class="c-table">'
958 . $localizedTableTitle . '</span> (' . $dbCount . ')</td>' . '<td nowrap="nowrap" class="col-icon"></td>'
959 . '</tr>';
960 // Column's titles
961 if ($this->doEdit) {
962 $theData['__cmds__'] = '<a href="#" onclick="' . htmlspecialchars(BackendUtility::editOnClick(
963 '&edit[' . $table . '][' . $this->id . ']=new',
964 $this->backPath
965 )) . '" title="' . $this->getLanguageService()->getLL('new', TRUE) . '">'
966 . IconUtility::getSpriteIcon('actions-document-new') . '</a>';
967 }
968 $out .= $this->addelement(1, '', $theData, ' class="c-headLine"', 15);
969 // Render Items
970 $this->eCounter = $this->firstElementNumber;
971 while ($row = $this->getDatabase()->sql_fetch_assoc($result)) {
972 BackendUtility::workspaceOL($table, $row);
973 if (is_array($row)) {
974 list($flag, $code) = $this->fwd_rwd_nav();
975 $out .= $code;
976 if ($flag) {
977 $params = '&edit[' . $table . '][' . $row['uid'] . ']=edit';
978 $Nrow = array();
979 // Setting icons links
980 if ($icon) {
981 $Nrow['__cmds__'] = $this->getIcon($table, $row);
982 }
983 // Get values:
984 $Nrow = $this->dataFields($this->fieldArray, $table, $row, $Nrow);
985 // Attach edit icon
986 if ($this->doEdit) {
987 $Nrow['__editIconLink__'] = '<a href="#" onclick="' . htmlspecialchars(
988 BackendUtility::editOnClick($params, $this->backPath))
989 . '" title="' . $this->getLanguageService()->getLL('edit', TRUE) . '">'
990 . IconUtility::getSpriteIcon('actions-document-open') . '</a>';
991 } else {
992 $Nrow['__editIconLink__'] = $this->noEditIcon();
993 }
994 $out .= $this->addelement(1, '', $Nrow);
995 }
996 $this->eCounter++;
997 }
998 }
999 // Wrap it all in a table:
1000 $out = '
1001 <!--
1002 Standard list of table "' . $table . '"
1003 -->
1004 <table border="0" cellpadding="0" cellspacing="0" class="typo3-dblist">
1005 ' . $out . '
1006 </table>';
1007 return $out;
1008 }
1009
1010 /**
1011 * Adds content to all data fields in $out array
1012 *
1013 * Each field name in $fieldArr has a special feature which is that the field name can be specified as more field names.
1014 * Eg. "field1,field2;field3".
1015 * Field 2 and 3 will be shown in the same cell of the table separated by <br /> while field1 will have its own cell.
1016 *
1017 * @param array $fieldArr Array of fields to display
1018 * @param string $table Table name
1019 * @param array $row Record array
1020 * @param array $out Array to which the data is added
1021 * @return array $out array returned after processing.
1022 * @see makeOrdinaryList()
1023 */
1024 public function dataFields($fieldArr, $table, $row, $out = array()) {
1025 // Check table validity
1026 if (!isset($GLOBALS['TCA'][$table])) {
1027 return $out;
1028 }
1029
1030 $thumbsCol = $GLOBALS['TCA'][$table]['ctrl']['thumbnail'];
1031 // Traverse fields
1032 foreach ($fieldArr as $fieldName) {
1033 if ($GLOBALS['TCA'][$table]['columns'][$fieldName]) {
1034 // Each field has its own cell (if configured in TCA)
1035 // If the column is a thumbnail column:
1036 if ($fieldName == $thumbsCol) {
1037 $out[$fieldName] = $this->thumbCode($row, $table, $fieldName);
1038 } else {
1039 // ... otherwise just render the output:
1040 $out[$fieldName] = nl2br(htmlspecialchars(trim(GeneralUtility::fixed_lgd_cs(
1041 BackendUtility::getProcessedValue($table, $fieldName, $row[$fieldName], 0, 0, 0, $row['uid']),
1042 250)
1043 )));
1044 }
1045 } else {
1046 // Each field is separated by <br /> and shown in the same cell (If not a TCA field, then explode
1047 // the field name with ";" and check each value there as a TCA configured field)
1048 $theFields = explode(';', $fieldName);
1049 // Traverse fields, separated by ";" (displayed in a single cell).
1050 foreach ($theFields as $fName2) {
1051 if ($GLOBALS['TCA'][$table]['columns'][$fName2]) {
1052 $out[$fieldName] .= '<strong>' . $this->getLanguageService()->sL(
1053 $GLOBALS['TCA'][$table]['columns'][$fName2]['label'],
1054 TRUE
1055 ) . '</strong>' . '&nbsp;&nbsp;' . htmlspecialchars(GeneralUtility::fixed_lgd_cs(
1056 BackendUtility::getProcessedValue($table, $fName2, $row[$fName2], 0, 0, 0, $row['uid']),
1057 25
1058 )) . '<br />';
1059 }
1060 }
1061 }
1062 // If no value, add a nbsp.
1063 if (!$out[$fieldName]) {
1064 $out[$fieldName] = '&nbsp;';
1065 }
1066 // Wrap in dimmed-span tags if record is "disabled"
1067 if ($this->isDisabled($table, $row)) {
1068 $out[$fieldName] = '<span class="text-muted">' . $out[$fieldName] . '</span>';
1069 }
1070 }
1071 return $out;
1072 }
1073
1074 /**
1075 * Header fields made for the listing of records
1076 *
1077 * @param array $fieldArr Field names
1078 * @param string $table The table name
1079 * @param array $out Array to which the headers are added.
1080 * @return array $out returned after addition of the header fields.
1081 * @see makeOrdinaryList()
1082 */
1083 public function headerFields($fieldArr, $table, $out = array()) {
1084 foreach ($fieldArr as $fieldName) {
1085 $ll = $this->getLanguageService()->sL($GLOBALS['TCA'][$table]['columns'][$fieldName]['label'], TRUE);
1086 $out[$fieldName] = $ll ? $ll : '&nbsp;';
1087 }
1088 return $out;
1089 }
1090
1091 /**
1092 * Gets content records per column.
1093 * This is required for correct workspace overlays.
1094 *
1095 * @param string $table UNUSED (will always be queried from tt_content)
1096 * @param int $id Page Id to be used (not used at all, but part of the API, see $this->pidSelect)
1097 * @param array $columns colPos values to be considered to be shown
1098 * @param string $additionalWhereClause Additional where clause for database select
1099 * @return array Associative array for each column (colPos)
1100 */
1101 protected function getContentRecordsPerColumn($table, $id, array $columns, $additionalWhereClause = '') {
1102 $columns = array_map('intval', $columns);
1103 $contentRecordsPerColumn = array_fill_keys($columns, array());
1104
1105 $queryParts = $this->makeQueryArray('tt_content', $id, 'AND colPos IN (' . implode(',', $columns) . ')' . $additionalWhereClause);
1106 $result = $this->getDatabase()->exec_SELECT_queryArray($queryParts);
1107 // Traverse any selected elements and render their display code:
1108 $rowArr = $this->getResult($result);
1109
1110 foreach ($rowArr as $record) {
1111 $columnValue = $record['colPos'];
1112 $contentRecordsPerColumn[$columnValue][] = $record;
1113 }
1114
1115 return $contentRecordsPerColumn;
1116 }
1117
1118 /**********************************
1119 *
1120 * Additional functions; Pages
1121 *
1122 **********************************/
1123 /**
1124 * Adds pages-rows to an array, selecting recursively in the page tree.
1125 *
1126 * @param array $theRows Array which will accumulate page rows
1127 * @param int $pid Pid to select from
1128 * @param string $qWhere Query-where clause
1129 * @param string $treeIcons Prefixed icon code.
1130 * @param int $depth Depth (decreasing)
1131 * @return array $theRows, but with added rows.
1132 */
1133 public function pages_getTree($theRows, $pid, $qWhere, $treeIcons, $depth) {
1134 $depth--;
1135 if ($depth >= 0) {
1136 $res = $this->getDatabase()->exec_SELECTquery('*', 'pages', 'pid=' . (int)$pid . $qWhere, '', 'sorting');
1137 $c = 0;
1138 $rc = $this->getDatabase()->sql_num_rows($res);
1139 while ($row = $this->getDatabase()->sql_fetch_assoc($res)) {
1140 BackendUtility::workspaceOL('pages', $row);
1141 if (is_array($row)) {
1142 $c++;
1143 $row['treeIcons'] = $treeIcons . '<img' . IconUtility::skinImg(
1144 $this->backPath,
1145 'gfx/ol/join' . ($rc == $c ? 'bottom' : '') . '.gif',
1146 'width="18" height="16"'
1147 ) . ' alt="" />';
1148 $theRows[] = $row;
1149 // Get the branch
1150 $spaceOutIcons = '<img' . IconUtility::skinImg(
1151 $this->backPath,
1152 'gfx/ol/' . ($rc == $c ? 'blank.gif' : 'line.gif'),
1153 'width="18" height="16"'
1154 ) . ' alt="" />';
1155 $theRows = $this->pages_getTree($theRows, $row['uid'], $qWhere, $treeIcons . $spaceOutIcons, $row['php_tree_stop'] ? 0 : $depth);
1156 }
1157 }
1158 } else {
1159 $count = $this->getDatabase()->exec_SELECTcountRows('uid', 'pages', 'pid=' . (int)$pid . $qWhere);
1160 if ($count) {
1161 $this->plusPages[$pid] = $count;
1162 }
1163 }
1164 return $theRows;
1165 }
1166
1167 /**
1168 * Adds a list item for the pages-rendering
1169 *
1170 * @param array $row Record array
1171 * @param array $fieldArr Field list
1172 * @return string HTML for the item
1173 */
1174 public function pages_drawItem($row, $fieldArr) {
1175 // Initialization
1176 $theIcon = $this->getIcon('pages', $row);
1177 // Preparing and getting the data-array
1178 $theData = array();
1179 foreach ($fieldArr as $field) {
1180 switch ($field) {
1181 case 'title':
1182 $red = $this->plusPages[$row['uid']] ? '<font color="red"><strong>+&nbsp;</strong></font>' : '';
1183 $pTitle = htmlspecialchars(BackendUtility::getProcessedValue('pages', $field, $row[$field], 20));
1184 if ($red) {
1185 $pTitle = '<a href="'
1186 . htmlspecialchars($this->script . ((strpos($this->script, '?') !== FALSE) ? '&' : '?')
1187 . 'id=' . $row['uid']) . '">' . $pTitle . '</a>';
1188 }
1189 $theData[$field] = $row['treeIcons'] . $theIcon . $red . $pTitle . '&nbsp;&nbsp;';
1190 break;
1191 case 'php_tree_stop':
1192 // Intended fall through
1193 case 'TSconfig':
1194 $theData[$field] = $row[$field] ? '&nbsp;<strong>x</strong>' : '&nbsp;';
1195 break;
1196 case 'uid':
1197 if ($this->getBackendUser()->doesUserHaveAccess($row, 2)) {
1198 $params = '&edit[pages][' . $row['uid'] . ']=edit';
1199 $eI = '<a href="#" onclick="'
1200 . htmlspecialchars(BackendUtility::editOnClick($params, $this->backPath, ''))
1201 . '" title="' . $this->getLanguageService()->getLL('editThisPage', TRUE) . '">'
1202 . IconUtility::getSpriteIcon('actions-document-open') . '</a>';
1203 } else {
1204 $eI = '';
1205 }
1206 $theData[$field] = '<span align="right">' . $row['uid'] . $eI . '</span>';
1207 break;
1208 default:
1209 if (substr($field, 0, 6) == 'table_') {
1210 $f2 = substr($field, 6);
1211 if ($GLOBALS['TCA'][$f2]) {
1212 $c = $this->numberOfRecords($f2, $row['uid']);
1213 $theData[$field] = '&nbsp;&nbsp;' . ($c ? $c : '');
1214 }
1215 } else {
1216 $theData[$field] = '&nbsp;&nbsp;'
1217 . htmlspecialchars(BackendUtility::getProcessedValue('pages', $field, $row[$field]));
1218 }
1219 }
1220 }
1221 $this->addElement_tdParams['title'] = $row['_CSSCLASS'] ? ' class="' . $row['_CSSCLASS'] . '"' : '';
1222 return $this->addelement(1, '', $theData);
1223 }
1224
1225 /**********************************
1226 *
1227 * Additional functions; Content Elements
1228 *
1229 **********************************/
1230 /**
1231 * Draw header for a content element column:
1232 *
1233 * @param string $colName Column name
1234 * @param string $editParams Edit params (Syntax: &edit[...] for alt_doc.php)
1235 * @param string $newParams New element params (Syntax: &edit[...] for alt_doc.php) OBSOLETE
1236 * @param array|NULL $pasteParams Paste element params (i.e. array(colPos => 1, sys_language_uid => 2))
1237 * @return string HTML table
1238 */
1239 public function tt_content_drawColHeader($colName, $editParams, $newParams, array $pasteParams = NULL) {
1240 $iconsArr = array();
1241 // Create command links:
1242 if ($this->tt_contentConfig['showCommands']) {
1243 // Edit whole of column:
1244 if ($editParams) {
1245 $iconsArr['edit'] = '<a href="#" onclick="'
1246 . htmlspecialchars(BackendUtility::editOnClick($editParams, $this->backPath)) . '" title="'
1247 . $this->getLanguageService()->getLL('editColumn', TRUE) . '">'
1248 . IconUtility::getSpriteIcon('actions-document-open') . '</a>';
1249 }
1250 if ($pasteParams) {
1251 $elFromTable = $this->clipboard->elFromTable('tt_content');
1252 if (count($elFromTable)) {
1253 $iconsArr['paste'] = '<a href="'
1254 . htmlspecialchars($this->clipboard->pasteUrl('tt_content', $this->id, TRUE, $pasteParams))
1255 . '" onclick="' . htmlspecialchars(('return '
1256 . $this->clipboard->confirmMsg('pages', $this->pageRecord, 'into', $elFromTable, $colName)))
1257 . '" title="' . $this->getLanguageService()->getLL('clip_paste', TRUE) . '">'
1258 . IconUtility::getSpriteIcon('actions-document-paste-into') . '</a>';
1259 }
1260 }
1261 }
1262 $icons = '';
1263 if (count($iconsArr)) {
1264 $icons = '<div class="t3-page-colHeader-icons">' . implode('', $iconsArr) . '</div>';
1265 }
1266 // Create header row:
1267 $out = '<div class="t3-page-colHeader t3-row-header">
1268 ' . $icons . '
1269 <div class="t3-page-colHeader-label">' . htmlspecialchars($colName) . '</div>
1270 </div>';
1271 return $out;
1272 }
1273
1274 /**
1275 * Draw the footer for a single tt_content element
1276 *
1277 * @param array $row Record array
1278 * @return string HTML of the footer
1279 */
1280 protected function tt_content_drawFooter(array $row) {
1281 $content = '';
1282 // Get processed values:
1283 $info = array();
1284 $this->getProcessedValue('tt_content', 'starttime,endtime,fe_group,spaceBefore,spaceAfter', $row, $info);
1285 // Display info from records fields:
1286 if (count($info)) {
1287 $content = '<div class="t3-page-ce-info">
1288 ' . implode('<br />', $info) . '
1289 </div>';
1290 }
1291 // Wrap it
1292 if (!empty($content)) {
1293 $content = '<div class="t3-page-ce-footer">' . $content . '</div>';
1294 }
1295 return $content;
1296 }
1297
1298 /**
1299 * Draw the header for a single tt_content element
1300 *
1301 * @param array $row Record array
1302 * @param int $space Amount of pixel space above the header. UNUSED
1303 * @param bool $disableMoveAndNewButtons If set the buttons for creating new elements and moving up and down are not shown.
1304 * @param bool $langMode If set, we are in language mode and flags will be shown for languages
1305 * @param bool $dragDropEnabled If set the move button must be hidden
1306 * @return string HTML table with the record header.
1307 */
1308 public function tt_content_drawHeader($row, $space = 0, $disableMoveAndNewButtons = FALSE, $langMode = FALSE, $dragDropEnabled = FALSE) {
1309 $out = '';
1310 // If show info is set...;
1311 if ($this->tt_contentConfig['showInfo'] && $this->getBackendUser()->recordEditAccessInternals('tt_content', $row)) {
1312 // Render control panel for the element:
1313 if ($this->tt_contentConfig['showCommands'] && $this->doEdit) {
1314 // Edit content element:
1315 $params = '&edit[tt_content][' . $this->tt_contentData['nextThree'][$row['uid']] . ']=edit';
1316 $out .= '<a href="#" onclick="' . htmlspecialchars(BackendUtility::editOnClick(
1317 $params,
1318 $this->backPath,
1319 GeneralUtility::getIndpEnv('REQUEST_URI') . '#element-tt_content-' . $row['uid']
1320 )) . '" title="' . htmlspecialchars($this->nextThree > 1
1321 ? sprintf($this->getLanguageService()->getLL('nextThree'), $this->nextThree)
1322 : $this->getLanguageService()->getLL('edit'))
1323 . '">' . IconUtility::getSpriteIcon('actions-document-open') . '</a>';
1324 // Hide element:
1325 $hiddenField = $GLOBALS['TCA']['tt_content']['ctrl']['enablecolumns']['disabled'];
1326 if (
1327 $hiddenField && $GLOBALS['TCA']['tt_content']['columns'][$hiddenField]
1328 && (!$GLOBALS['TCA']['tt_content']['columns'][$hiddenField]['exclude']
1329 || $this->getBackendUser()->check('non_exclude_fields', 'tt_content:' . $hiddenField))
1330 ) {
1331 if ($row[$hiddenField]) {
1332 $value = 0;
1333 $label = 'unHide';
1334 } else {
1335 $value = 1;
1336 $label = 'hide';
1337 }
1338 $params = '&data[tt_content][' . ($row['_ORIG_uid'] ? $row['_ORIG_uid'] : $row['uid'])
1339 . '][' . $hiddenField . ']=' . $value;
1340 $out .= '<a href="' . htmlspecialchars($this->getPageLayoutController()->doc->issueCommand($params))
1341 . '" title="' . $this->getLanguageService()->getLL($label, TRUE) . '">'
1342 . IconUtility::getSpriteIcon('actions-edit-' . strtolower($label)) . '</a>';
1343 }
1344 // Delete
1345 $params = '&cmd[tt_content][' . $row['uid'] . '][delete]=1';
1346 $confirm = GeneralUtility::quoteJSvalue($this->getLanguageService()->getLL('deleteWarning')
1347 . BackendUtility::translationCount('tt_content', $row['uid'], (' '
1348 . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.translationsOfRecord')))
1349 );
1350 $out .= '<a href="' . htmlspecialchars($this->getPageLayoutController()->doc->issueCommand($params))
1351 . '" onclick="' . htmlspecialchars(('return confirm(' . $confirm . ');')) . '" title="'
1352 . $this->getLanguageService()->getLL('deleteItem', TRUE) . '">'
1353 . IconUtility::getSpriteIcon('actions-edit-delete') . '</a>';
1354 if (!$disableMoveAndNewButtons) {
1355 $moveButtonContent = '';
1356 $displayMoveButtons = FALSE;
1357 // Move element up:
1358 if ($this->tt_contentData['prev'][$row['uid']]) {
1359 $params = '&cmd[tt_content][' . $row['uid'] . '][move]=' . $this->tt_contentData['prev'][$row['uid']];
1360 $moveButtonContent .= '<a href="'
1361 . htmlspecialchars($this->getPageLayoutController()->doc->issueCommand($params))
1362 . '" title="' . $this->getLanguageService()->getLL('moveUp', TRUE) . '">'
1363 . IconUtility::getSpriteIcon('actions-move-up') . '</a>';
1364 if (!$dragDropEnabled) {
1365 $displayMoveButtons = TRUE;
1366 }
1367 } else {
1368 $moveButtonContent .= IconUtility::getSpriteIcon('empty-empty');
1369 }
1370 // Move element down:
1371 if ($this->tt_contentData['next'][$row['uid']]) {
1372 $params = '&cmd[tt_content][' . $row['uid'] . '][move]= ' . $this->tt_contentData['next'][$row['uid']];
1373 $moveButtonContent .= '<a href="'
1374 . htmlspecialchars($this->getPageLayoutController()->doc->issueCommand($params))
1375 . '" title="' . $this->getLanguageService()->getLL('moveDown', TRUE) . '">'
1376 . IconUtility::getSpriteIcon('actions-move-down') . '</a>';
1377 if (!$dragDropEnabled) {
1378 $displayMoveButtons = TRUE;
1379 }
1380 } else {
1381 $moveButtonContent .= IconUtility::getSpriteIcon('empty-empty');
1382 }
1383 if ($displayMoveButtons) {
1384 $out .= '<span class="t3-page-ce-icons-move">' . $moveButtonContent . '</span>';
1385 }
1386 }
1387 }
1388 }
1389 $additionalIcons = array();
1390 $additionalIcons[] = $this->getIcon('tt_content', $row) . ' ';
1391 $additionalIcons[] = $langMode ? $this->languageFlag($row['sys_language_uid'], FALSE) : '';
1392 // Get record locking status:
1393 if ($lockInfo = BackendUtility::isRecordLocked('tt_content', $row['uid'])) {
1394 $additionalIcons[] = '<a href="#" onclick="alert(' . GeneralUtility::quoteJSvalue($lockInfo['msg'])
1395 . ');return false;" title="' . htmlspecialchars($lockInfo['msg']) . '">'
1396 . IconUtility::getSpriteIcon('status-warning-in-use') . '</a>';
1397 }
1398 // Call stats information hook
1399 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['recStatInfoHooks'])) {
1400 $_params = array('tt_content', $row['uid'], &$row);
1401 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['recStatInfoHooks'] as $_funcRef) {
1402 $additionalIcons[] = GeneralUtility::callUserFunction($_funcRef, $_params, $this);
1403 }
1404 }
1405 // Wrap the whole header
1406 // NOTE: end-tag for <div class="t3-page-ce-body"> is in getTable_tt_content()
1407 return '<h4 class="t3-page-ce-header">
1408 <div class="t3-row-header">
1409 <span class="ce-icons-left">' . implode('', $additionalIcons) . '</span>
1410 <span class="ce-icons">
1411 ' . $out . '
1412 </span></div>
1413 </h4>
1414 <div class="t3-page-ce-body">';
1415 }
1416
1417 /**
1418 * Draws the preview content for a content element
1419 *
1420 * @param string $row Content element
1421 * @param bool $isRTE Set if the RTE link can be created.
1422 * @return string HTML
1423 * @throws \UnexpectedValueException
1424 */
1425 public function tt_content_drawItem($row, $isRTE = FALSE) {
1426 $out = '';
1427 $outHeader = '';
1428 // Make header:
1429 if ($row['header']) {
1430 $infoArr = array();
1431 $this->getProcessedValue('tt_content', 'header_position,header_layout,header_link', $row, $infoArr);
1432 $hiddenHeaderNote = '';
1433 // If header layout is set to 'hidden', display an accordant note:
1434 if ($row['header_layout'] == 100) {
1435 $hiddenHeaderNote = ' <em>[' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.hidden', TRUE) . ']</em>';
1436 }
1437 $outHeader = $row['date']
1438 ? htmlspecialchars($this->itemLabels['date'] . ' ' . BackendUtility::date($row['date'])) . '<br />'
1439 : '';
1440 $outHeader .= '<strong>' . $this->linkEditContent($this->renderText($row['header']), $row)
1441 . $hiddenHeaderNote . '</strong><br />';
1442 }
1443 // Make content:
1444 $infoArr = array();
1445 $drawItem = TRUE;
1446 // Hook: Render an own preview of a record
1447 $drawItemHooks = &$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['tt_content_drawItem'];
1448 if (is_array($drawItemHooks)) {
1449 foreach ($drawItemHooks as $hookClass) {
1450 $hookObject = GeneralUtility::getUserObj($hookClass);
1451 if (!$hookObject instanceof PageLayoutViewDrawItemHookInterface) {
1452 throw new \UnexpectedValueException('$hookObject must implement interface TYPO3\\CMS\\Backend\\View\\PageLayoutViewDrawItemHookInterface', 1218547409);
1453 }
1454 $hookObject->preProcess($this, $drawItem, $outHeader, $out, $row);
1455 }
1456 }
1457 // Draw preview of the item depending on its CType (if not disabled by previous hook):
1458 if ($drawItem) {
1459 switch ($row['CType']) {
1460 case 'header':
1461 if ($row['subheader']) {
1462 $out .= $this->linkEditContent($this->renderText($row['subheader']), $row) . '<br />';
1463 }
1464 break;
1465 case 'text':
1466
1467 case 'textpic':
1468
1469 case 'image':
1470 if ($row['CType'] == 'text' || $row['CType'] == 'textpic') {
1471 if ($row['bodytext']) {
1472 $out .= $this->linkEditContent($this->renderText($row['bodytext']), $row) . '<br />';
1473 }
1474 }
1475 if ($row['CType'] == 'textpic' || $row['CType'] == 'image') {
1476 if ($row['image']) {
1477 $out .= $this->thumbCode($row, 'tt_content', 'image') . '<br />';
1478 if ($row['imagecaption']) {
1479 $out .= $this->linkEditContent($this->renderText($row['imagecaption']), $row) . '<br />';
1480 }
1481 }
1482 }
1483 break;
1484 case 'bullets':
1485
1486 case 'table':
1487
1488 case 'mailform':
1489 if ($row['bodytext']) {
1490 $out .= $this->linkEditContent($this->renderText($row['bodytext']), $row) . '<br />';
1491 }
1492 break;
1493 case 'uploads':
1494 if ($row['media']) {
1495 $out .= $this->thumbCode($row, 'tt_content', 'media') . '<br />';
1496 }
1497 break;
1498 case 'multimedia':
1499 if ($row['multimedia']) {
1500 $out .= $this->renderText($row['multimedia']) . '<br />';
1501 $out .= $this->renderText($row['parameters']) . '<br />';
1502 }
1503 break;
1504 case 'menu':
1505 if ($row['pages']) {
1506 $out .= $this->linkEditContent($row['pages'], $row) . '<br />';
1507 }
1508 break;
1509 case 'shortcut':
1510 if (!empty($row['records'])) {
1511 $shortcutContent = array();
1512 $recordList = explode(',', $row['records']);
1513 foreach ($recordList as $recordIdentifier) {
1514 $split = BackendUtility::splitTable_Uid($recordIdentifier);
1515 $tableName = empty($split[0]) ? 'tt_content' : $split[0];
1516 $shortcutRecord = BackendUtility::getRecord($tableName, $split[1]);
1517 if (is_array($shortcutRecord)) {
1518 $icon = IconUtility::getSpriteIconForRecord($tableName, $shortcutRecord);
1519 $icon = $this->getPageLayoutController()->doc->wrapClickMenuOnIcon($icon, $tableName,
1520 $shortcutRecord['uid'], 1, '', '+copy,info,edit,view');
1521 $shortcutContent[] = $icon
1522 . htmlspecialchars(BackendUtility::getRecordTitle($tableName, $shortcutRecord));
1523 }
1524 }
1525 $out .= implode('<br />', $shortcutContent) . '<br />';
1526 }
1527 break;
1528 case 'list':
1529 $hookArr = array();
1530 $hookOut = '';
1531 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['list_type_Info'][$row['list_type']])) {
1532 $hookArr = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['list_type_Info'][$row['list_type']];
1533 } elseif (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['list_type_Info']['_DEFAULT'])) {
1534 $hookArr = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['list_type_Info']['_DEFAULT'];
1535 }
1536 if (count($hookArr) > 0) {
1537 $_params = array('pObj' => &$this, 'row' => $row, 'infoArr' => $infoArr);
1538 foreach ($hookArr as $_funcRef) {
1539 $hookOut .= GeneralUtility::callUserFunction($_funcRef, $_params, $this);
1540 }
1541 }
1542 if ((string)$hookOut !== '') {
1543 $out .= $hookOut;
1544 } elseif (!empty($row['list_type'])) {
1545 $label = BackendUtility::getLabelFromItemlist('tt_content', 'list_type', $row['list_type']);
1546 if (!empty($label)) {
1547 $out .= '<strong>' . $this->getLanguageService()->sL($label, TRUE) . '</strong><br />';
1548 } else {
1549 $message = sprintf($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.noMatchingValue'), $row['list_type']);
1550 $out .= GeneralUtility::makeInstance(
1551 FlashMessage::class,
1552 htmlspecialchars($message),
1553 '',
1554 FlashMessage::WARNING
1555 )->render();
1556 }
1557 } elseif (!empty($row['select_key'])) {
1558 $out .= $this->getLanguageService()->sL(BackendUtility::getItemLabel('tt_content', 'select_key'), TRUE)
1559 . ' ' . $row['select_key'] . '<br />';
1560 } else {
1561 $out .= '<strong>' . $this->getLanguageService()->getLL('noPluginSelected') . '</strong>';
1562 }
1563 $out .= $this->getLanguageService()->sL(
1564 BackendUtility::getLabelFromItemlist('tt_content', 'pages', $row['pages']),
1565 TRUE
1566 ) . '<br />';
1567 break;
1568 case 'script':
1569 $out .= $this->getLanguageService()->sL(BackendUtility::getItemLabel('tt_content', 'select_key'), TRUE)
1570 . ' ' . $row['select_key'] . '<br />';
1571 $out .= '<br />' . $this->linkEditContent($this->renderText($row['bodytext']), $row) . '<br />';
1572 $out .= '<br />' . $this->linkEditContent($this->renderText($row['imagecaption']), $row) . '<br />';
1573 break;
1574 default:
1575 $contentType = $this->CType_labels[$row['CType']];
1576
1577 if (isset($contentType)) {
1578 $out .= '<strong>' . htmlspecialchars($contentType) . '</strong><br />';
1579 if ($row['bodytext']) {
1580 $out .= $this->linkEditContent($this->renderText($row['bodytext']), $row) . '<br />';
1581 }
1582 if ($row['image']) {
1583 $out .= $this->thumbCode($row, 'tt_content', 'image') . '<br />';
1584 }
1585 } else {
1586 $message = sprintf(
1587 $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.noMatchingValue'),
1588 $row['CType']
1589 );
1590 $out .= GeneralUtility::makeInstance(
1591 FlashMessage::class,
1592 htmlspecialchars($message),
1593 '',
1594 FlashMessage::WARNING
1595 )->render();
1596 }
1597 }
1598 }
1599 // Wrap span-tags:
1600 $out = '
1601 <span class="exampleContent">' . $out . '</span>';
1602 // Add header:
1603 $out = $outHeader . $out;
1604 // Add RTE button:
1605 if ($isRTE) {
1606 $out .= $this->linkRTEbutton($row);
1607 }
1608 // Return values:
1609 if ($this->isDisabled('tt_content', $row)) {
1610 return '<span class="text-muted">' . $out . '</span>';
1611 } else {
1612 return $out;
1613 }
1614 }
1615
1616 /**
1617 * Filters out all tt_content uids which are already translated so only non-translated uids is left.
1618 * Selects across columns, but within in the same PID. Columns are expect to be the same
1619 * for translations and original but this may be a conceptual error (?)
1620 *
1621 * @param array $defLanguageCount Numeric array with uids of tt_content elements in the default language
1622 * @param int $id Page pid
1623 * @param int $lP Sys language UID
1624 * @return array Modified $defLanguageCount
1625 */
1626 public function getNonTranslatedTTcontentUids($defLanguageCount, $id, $lP) {
1627 if ($lP && count($defLanguageCount)) {
1628 // Select all translations here:
1629 $queryParts = $this->makeQueryArray('tt_content', $id, 'AND sys_language_uid=' . (int)$lP
1630 . ' AND l18n_parent IN (' . implode(',', $defLanguageCount) . ')');
1631 $result = $this->getDatabase()->exec_SELECT_queryArray($queryParts);
1632 // Flip uids:
1633 $defLanguageCount = array_flip($defLanguageCount);
1634 // Traverse any selected elements and unset original UID if any:
1635 $rowArr = $this->getResult($result);
1636 foreach ($rowArr as $row) {
1637 unset($defLanguageCount[$row['l18n_parent']]);
1638 }
1639 // Flip again:
1640 $defLanguageCount = array_keys($defLanguageCount);
1641 }
1642 return $defLanguageCount;
1643 }
1644
1645 /**
1646 * Creates button which is used to create copies of records..
1647 *
1648 * @param array $defLanguageCount Numeric array with uids of tt_content elements in the default language
1649 * @param int $lP Sys language UID
1650 * @return string "Copy languages" button, if available.
1651 */
1652 public function newLanguageButton($defLanguageCount, $lP) {
1653 if (!$this->doEdit || count($defLanguageCount) === 0 || !$lP) {
1654 return '';
1655 }
1656 $params = '';
1657 foreach ($defLanguageCount as $uidVal) {
1658 $params .= '&cmd[tt_content][' . $uidVal . '][localize]=' . $lP;
1659 }
1660 // Copy for language:
1661 $onClick = 'window.location.href=\'' . $this->getPageLayoutController()->doc->issueCommand($params) . '\'; return false;';
1662 $theNewButton = '<div class="t3-page-lang-copyce">' .
1663 $this->getPageLayoutController()->doc->t3Button(
1664 $onClick,
1665 $this->getLanguageService()->getLL('newPageContent_copyForLang') . ' [' . count($defLanguageCount) . ']'
1666 ) . '</div>';
1667 return $theNewButton;
1668 }
1669
1670 /**
1671 * Creates onclick-attribute content for a new content element
1672 *
1673 * @param int $id Page id where to create the element.
1674 * @param int $colPos Preset: Column position value
1675 * @param int $sys_language Preset: Sys langauge value
1676 * @return string String for onclick attribute.
1677 * @see getTable_tt_content()
1678 */
1679 public function newContentElementOnClick($id, $colPos, $sys_language) {
1680 if ($this->option_newWizard) {
1681 $onClick = 'window.location.href=\'db_new_content_el.php?id=' . $id . '&colPos=' . $colPos
1682 . '&sys_language_uid=' . $sys_language . '&uid_pid=' . $id
1683 . '&returnUrl=' . rawurlencode(GeneralUtility::getIndpEnv('REQUEST_URI')) . '\';';
1684 } else {
1685 $onClick = BackendUtility::editOnClick('&edit[tt_content][' . $id . ']=new&defVals[tt_content][colPos]='
1686 . $colPos . '&defVals[tt_content][sys_language_uid]=' . $sys_language, $this->backPath);
1687 }
1688 return $onClick;
1689 }
1690
1691 /**
1692 * Will create a link on the input string and possibly a big button after the string which links to editing in the RTE.
1693 * Used for content element content displayed so the user can click the content / "Edit in Rich Text Editor" button
1694 *
1695 * @param string $str String to link. Must be prepared for HTML output.
1696 * @param array $row The row.
1697 * @return string If the whole thing was editable ($this->doEdit) $str is return with link around. Otherwise just $str.
1698 * @see getTable_tt_content()
1699 */
1700 public function linkEditContent($str, $row) {
1701 $addButton = '';
1702 $onClick = '';
1703 if ($this->doEdit && $this->getBackendUser()->recordEditAccessInternals('tt_content', $row)) {
1704 // Setting onclick action for content link:
1705 $onClick = BackendUtility::editOnClick('&edit[tt_content][' . $row['uid'] . ']=edit', $this->backPath);
1706 }
1707 // Return link
1708 return $onClick ? '<a href="#" onclick="' . htmlspecialchars($onClick)
1709 . '" title="' . $this->getLanguageService()->getLL('edit', TRUE) . '">' . $str . '</a>' . $addButton : $str;
1710 }
1711
1712 /**
1713 * Adds a button to edit the row in RTE wizard
1714 *
1715 * @param array $row The row of tt_content element
1716 * @return string Button to click if you want to edit in RTE wizard.
1717 */
1718 public function linkRTEbutton($row) {
1719 $params = array();
1720 $params['table'] = 'tt_content';
1721 $params['uid'] = $row['uid'];
1722 $params['pid'] = $row['pid'];
1723 $params['field'] = 'bodytext';
1724 $params['returnUrl'] = GeneralUtility::linkThisScript();
1725 $RTEonClick = 'window.location.href=' . GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('wizard_rte', array('P' => $params))) . ';return false;';
1726 $addButton = $this->option_showBigButtons && $this->doEdit
1727 ? $this->getPageLayoutController()->doc->t3Button($RTEonClick, $this->getLanguageService()->getLL('editInRTE'))
1728 : '';
1729 return $addButton;
1730 }
1731
1732 /**
1733 * Make selector box for creating new translation in a language
1734 * Displays only languages which are not yet present for the current page and
1735 * that are not disabled with page TS.
1736 *
1737 * @param int $id Page id for which to create a new language (pages_language_overlay record)
1738 * @return string <select> HTML element (if there were items for the box anyways...)
1739 * @see getTable_tt_content()
1740 */
1741 public function languageSelector($id) {
1742 if ($this->getBackendUser()->check('tables_modify', 'pages_language_overlay')) {
1743 // First, select all
1744 $res = $this->getPageLayoutController()->exec_languageQuery(0);
1745 $langSelItems = array();
1746 $langSelItems[0] = '
1747 <option value="0"></option>';
1748 while ($row = $this->getDatabase()->sql_fetch_assoc($res)) {
1749 if ($this->getBackendUser()->checkLanguageAccess($row['uid'])) {
1750 $langSelItems[$row['uid']] = '
1751 <option value="' . $row['uid'] . '">' . htmlspecialchars($row['title']) . '</option>';
1752 }
1753 }
1754 // Then, subtract the languages which are already on the page:
1755 $res = $this->getPageLayoutController()->exec_languageQuery($id);
1756 while ($row = $this->getDatabase()->sql_fetch_assoc($res)) {
1757 unset($langSelItems[$row['uid']]);
1758 }
1759 // Remove disallowed languages
1760 if (count($langSelItems) > 1
1761 && !$this->getBackendUser()->user['admin']
1762 && strlen($this->getBackendUser()->groupData['allowed_languages'])
1763 ) {
1764 $allowed_languages = array_flip(explode(',', $this->getBackendUser()->groupData['allowed_languages']));
1765 if (count($allowed_languages)) {
1766 foreach ($langSelItems as $key => $value) {
1767 if (!isset($allowed_languages[$key]) && $key != 0) {
1768 unset($langSelItems[$key]);
1769 }
1770 }
1771 }
1772 }
1773 // Remove disabled languages
1774 $modSharedTSconfig = BackendUtility::getModTSconfig($id, 'mod.SHARED');
1775 $disableLanguages = isset($modSharedTSconfig['properties']['disableLanguages'])
1776 ? GeneralUtility::trimExplode(',', $modSharedTSconfig['properties']['disableLanguages'], TRUE)
1777 : array();
1778 if (count($langSelItems) && count($disableLanguages)) {
1779 foreach ($disableLanguages as $language) {
1780 if ($language != 0 && isset($langSelItems[$language])) {
1781 unset($langSelItems[$language]);
1782 }
1783 }
1784 }
1785 // If any languages are left, make selector:
1786 if (count($langSelItems) > 1) {
1787 $onChangeContent = 'window.location.href=\'' . $this->backPath . 'alt_doc.php?&edit[pages_language_overlay]['
1788 . $id . ']=new&overrideVals[pages_language_overlay][doktype]=' . (int)$this->pageRecord['doktype']
1789 . '&overrideVals[pages_language_overlay][sys_language_uid]=\'+this.options[this.selectedIndex].value+\'&returnUrl='
1790 . rawurlencode(GeneralUtility::getIndpEnv('REQUEST_URI')) . '\'';
1791 return $this->getLanguageService()->getLL('new_language', TRUE)
1792 . ': <select name="createNewLanguage" onchange="' . htmlspecialchars($onChangeContent) . '">
1793 ' . implode('', $langSelItems) . '
1794 </select><br /><br />';
1795 }
1796 }
1797 return '';
1798 }
1799
1800 /**
1801 * Traverse the result pointer given, adding each record to array and setting some internal values at the same time.
1802 *
1803 * @param bool|\mysqli_result|object $result MySQLi result object / DBAL object
1804 * @param string $table Table name defaulting to tt_content
1805 * @return array The selected rows returned in this array.
1806 */
1807 public function getResult($result, $table = 'tt_content') {
1808 $output = array();
1809 // Traverse the result:
1810 while ($row = $this->getDatabase()->sql_fetch_assoc($result)) {
1811 BackendUtility::workspaceOL($table, $row, -99, TRUE);
1812 if ($row) {
1813 // Add the row to the array:
1814 $output[] = $row;
1815 }
1816 }
1817 $this->generateTtContentDataArray($output);
1818 // Return selected records
1819 return $output;
1820 }
1821
1822 /********************************
1823 *
1824 * Various helper functions
1825 *
1826 ********************************/
1827
1828 /**
1829 * Initializes the clipboard for generating paste links
1830 *
1831 * @return void
1832 *
1833 * @see \TYPO3\CMS\Recordlist\RecordList::main()
1834 * @see \TYPO3\CMS\Backend\Controller\ClickMenuController::main()
1835 * @see \TYPO3\CMS\Filelist\Controller\FileListController::main()
1836 */
1837 protected function initializeClipboard() {
1838 // Start clipboard
1839 $this->clipboard = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Clipboard\Clipboard::class);
1840
1841 // Initialize - reads the clipboard content from the user session
1842 $this->clipboard->initializeClipboard();
1843
1844 // This locks the clipboard to the Normal for this request.
1845 $this->clipboard->lockToNormal();
1846
1847 // Clean up pad
1848 $this->clipboard->cleanCurrent();
1849
1850 // Save the clipboard content
1851 $this->clipboard->endClipboard();
1852 }
1853
1854 /**
1855 * Generates the data for previous and next elements which is needed for movements.
1856 *
1857 * @param array $rowArray
1858 * @return void
1859 */
1860 protected function generateTtContentDataArray(array $rowArray) {
1861 if (empty($this->tt_contentData)) {
1862 $this->tt_contentData = array(
1863 'nextThree' => array(),
1864 'next' => array(),
1865 'prev' => array(),
1866 );
1867 }
1868 foreach ($rowArray as $key => $value) {
1869 // Create the list of the next three ids (for editing links...)
1870 for ($i = 0; $i < $this->nextThree; $i++) {
1871 if (isset($rowArray[$key - $i])
1872 && !GeneralUtility::inList($this->tt_contentData['nextThree'][$rowArray[$key - $i]['uid']], $value['uid'])
1873 ) {
1874 $this->tt_contentData['nextThree'][$rowArray[$key - $i]['uid']] .= $value['uid'] . ',';
1875 }
1876 }
1877
1878 // Create information for next and previous content elements
1879 if (isset($rowArray[$key - 1])) {
1880 if (isset($rowArray[$key - 2])) {
1881 $this->tt_contentData['prev'][$value['uid']] = -$rowArray[$key - 2]['uid'];
1882 } else {
1883 $this->tt_contentData['prev'][$value['uid']] = $value['pid'];
1884 }
1885 $this->tt_contentData['next'][$rowArray[$key - 1]['uid']] = -$value['uid'];
1886 }
1887 }
1888 }
1889
1890 /**
1891 * Counts and returns the number of records on the page with $pid
1892 *
1893 * @param string $table Table name
1894 * @param int $pid Page id
1895 * @return int Number of records.
1896 */
1897 public function numberOfRecords($table, $pid) {
1898 $count = 0;
1899 if ($GLOBALS['TCA'][$table]) {
1900 $where = 'pid=' . (int)$pid . BackendUtility::deleteClause($table) . BackendUtility::versioningPlaceholderClause($table);
1901 $count = $this->getDatabase()->exec_SELECTcountRows('uid', $table, $where);
1902 }
1903 return (int)$count;
1904 }
1905
1906 /**
1907 * Processing of larger amounts of text (usually from RTE/bodytext fields) with word wrapping etc.
1908 *
1909 * @param string $input Input string
1910 * @return string Output string
1911 */
1912 public function renderText($input) {
1913 $input = strip_tags($input);
1914 $input = GeneralUtility::fixed_lgd_cs($input, 1500);
1915 return nl2br(htmlspecialchars(trim($input), ENT_QUOTES, 'UTF-8', FALSE));
1916 }
1917
1918 /**
1919 * Creates the icon image tag for record from table and wraps it in a link which will trigger the click menu.
1920 *
1921 * @param string $table Table name
1922 * @param array $row Record array
1923 * @return string HTML for the icon
1924 */
1925 public function getIcon($table, $row) {
1926 // Initialization
1927 $altText = BackendUtility::getRecordIconAltText($row, $table);
1928 $icon = IconUtility::getSpriteIconForRecord($table, $row, array('title' => $altText));
1929 $this->counter++;
1930 // The icon with link
1931 if ($this->getBackendUser()->recordEditAccessInternals($table, $row)) {
1932 $icon = $this->getPageLayoutController()->doc->wrapClickMenuOnIcon($icon, $table, $row['uid']);
1933 }
1934 return $icon;
1935 }
1936
1937 /**
1938 * Creates processed values for all field names in $fieldList based on values from $row array.
1939 * The result is 'returned' through $info which is passed as a reference
1940 *
1941 * @param string $table Table name
1942 * @param string $fieldList Comma separated list of fields.
1943 * @param array $row Record from which to take values for processing.
1944 * @param array $info Array to which the processed values are added.
1945 * @return void
1946 */
1947 public function getProcessedValue($table, $fieldList, array $row, array &$info) {
1948 // Splitting values from $fieldList
1949 $fieldArr = explode(',', $fieldList);
1950 // Traverse fields from $fieldList
1951 foreach ($fieldArr as $field) {
1952 if ($row[$field]) {
1953 $info[] = '<strong>' . htmlspecialchars($this->itemLabels[$field]) . '</strong> '
1954 . htmlspecialchars(BackendUtility::getProcessedValue($table, $field, $row[$field]));
1955 }
1956 }
1957 }
1958
1959 /**
1960 * Returns TRUE, if the record given as parameters is NOT visible based on hidden/starttime/endtime (if available)
1961 *
1962 * @param string $table Tablename of table to test
1963 * @param array $row Record row.
1964 * @return bool Returns TRUE, if disabled.
1965 */
1966 public function isDisabled($table, $row) {
1967 $enableCols = $GLOBALS['TCA'][$table]['ctrl']['enablecolumns'];
1968 return $enableCols['disabled'] && $row[$enableCols['disabled']]
1969 || $enableCols['starttime'] && $row[$enableCols['starttime']] > $GLOBALS['EXEC_TIME']
1970 || $enableCols['endtime'] && $row[$enableCols['endtime']] && $row[$enableCols['endtime']] < $GLOBALS['EXEC_TIME'];
1971 }
1972
1973 /**
1974 * Will perform "word-wrapping" on the input string. What it does is to split by space or line break,
1975 * then find any word longer than $max and if found, a hyphen is inserted.
1976 * Works well on normal texts, little less well when HTML is involved (since much HTML will have
1977 * long strings that will be broken).
1978 *
1979 * @param string $content Content to word-wrap.
1980 * @param int $max Max number of chars in a word before it will be wrapped.
1981 * @param string $char Character to insert when wrapping.
1982 * @return string Processed output.
1983 * @deprecated since 6.2 - will be removed two versions later; use CSS instead (word-break: break-all;)
1984 */
1985 public function wordWrapper($content, $max = 50, $char = ' -') {
1986 GeneralUtility::logDeprecatedFunction();
1987 $array = preg_split('/[ ' . LF . ']/', $content);
1988 foreach ($array as $val) {
1989 if (strlen($val) > $max) {
1990 $content = str_replace($val, substr(chunk_split($val, $max, $char), 0, -1), $content);
1991 }
1992 }
1993 return $content;
1994 }
1995
1996 /**
1997 * Returns icon for "no-edit" of a record.
1998 * Basically, the point is to signal that this record could have had an edit link if
1999 * the circumstances were right. A placeholder for the regular edit icon...
2000 *
2001 * @param string $label Label key from LOCAL_LANG
2002 * @return string IMG tag for icon.
2003 */
2004 public function noEditIcon($label = 'noEditItems') {
2005 return IconUtility::getSpriteIcon(
2006 'status-edit-read-only',
2007 array('title' => $this->getLanguageService()->getLL($label, TRUE))
2008 );
2009 }
2010
2011 /**
2012 * Function, which fills in the internal array, $this->allowedTableNames with all tables to
2013 * which the user has access. Also a set of standard tables (pages, static_template, sys_filemounts, etc...)
2014 * are filtered out. So what is left is basically all tables which makes sense to list content from.
2015 *
2016 * @return array
2017 */
2018 protected function cleanTableNames() {
2019 // Get all table names:
2020 $tableNames = array_flip(array_keys($GLOBALS['TCA']));
2021 // Unset common names:
2022 unset($tableNames['pages']);
2023 unset($tableNames['static_template']);
2024 unset($tableNames['sys_filemounts']);
2025 unset($tableNames['sys_action']);
2026 unset($tableNames['sys_workflows']);
2027 unset($tableNames['be_users']);
2028 unset($tableNames['be_groups']);
2029 $allowedTableNames = array();
2030 // Traverse table names and set them in allowedTableNames array IF they can be read-accessed by the user.
2031 if (is_array($tableNames)) {
2032 foreach ($tableNames as $k => $v) {
2033 if ($this->getBackendUser()->check('tables_select', $k)) {
2034 $allowedTableNames['table_' . $k] = $k;
2035 }
2036 }
2037 }
2038 return $allowedTableNames;
2039 }
2040
2041 /**
2042 * Checking if the RTE is available/enabled for a certain table/field and if so, it returns TRUE.
2043 * Used to determine if the RTE button should be displayed.
2044 *
2045 * @param string $table Table name
2046 * @param array $row Record row (needed, if there are RTE dependencies based on other fields in the record)
2047 * @param string $field Field name
2048 * @return bool Returns TRUE if the rich text editor would be enabled/available for the field name specified.
2049 */
2050 public function isRTEforField($table, $row, $field) {
2051 $specConf = $this->getSpecConfForField($table, $row, $field);
2052 if (!count($specConf)) {
2053 return FALSE;
2054 }
2055 $p = BackendUtility::getSpecConfParametersFromArray($specConf['rte_transform']['parameters']);
2056 if (isset($specConf['richtext']) && (!$p['flag'] || !$row[$p['flag']])) {
2057 BackendUtility::fixVersioningPid($table, $row);
2058 list($tscPID, $thePidValue) = BackendUtility::getTSCpid($table, $row['uid'], $row['pid']);
2059 // If the pid-value is not negative (that is, a pid could NOT be fetched)
2060 if ($thePidValue >= 0) {
2061 if (!isset($this->rteSetup[$tscPID])) {
2062 $this->rteSetup[$tscPID] = $this->getBackendUser()->getTSConfig('RTE', BackendUtility::getPagesTSconfig($tscPID));
2063 }
2064 $RTEtypeVal = BackendUtility::getTCAtypeValue($table, $row);
2065 $thisConfig = BackendUtility::RTEsetup($this->rteSetup[$tscPID]['properties'], $table, $field, $RTEtypeVal);
2066 if (!$thisConfig['disabled']) {
2067 return TRUE;
2068 }
2069 }
2070 }
2071 return FALSE;
2072 }
2073
2074 /**
2075 * Returns "special" configuration from the "types" configuration in TCA for the record given by tablename/fieldname.
2076 * Used by isRTEforField() in the process of finding whether a field has RTE enabled or not.
2077 *
2078 * @param string $table Table name
2079 * @param array $row Record array
2080 * @param string $field Field name
2081 * @return array Spec. conf (if available)
2082 * @access private
2083 * @see isRTEforField()
2084 */
2085 public function getSpecConfForField($table, $row, $field) {
2086 // Get types-configuration for the record:
2087 $types_fieldConfig = BackendUtility::getTCAtypes($table, $row);
2088 // Find the given field and return the spec key value if found:
2089 if (is_array($types_fieldConfig)) {
2090 foreach ($types_fieldConfig as $vConf) {
2091 if ($vConf['field'] == $field) {
2092 return $vConf['spec'];
2093 }
2094 }
2095 }
2096 return array();
2097 }
2098
2099 /*****************************************
2100 *
2101 * External renderings
2102 *
2103 *****************************************/
2104
2105 /**
2106 * Creates a menu of the tables that can be listed by this function
2107 * Only tables which has records on the page will be included.
2108 * Notice: The function also fills in the internal variable $this->activeTables with icon/titles.
2109 *
2110 * @param int $id Page id from which we are listing records (the function will look up if there are records on the page)
2111 * @return string HTML output.
2112 */
2113 public function getTableMenu($id) {
2114 // Initialize:
2115 $this->activeTables = array();
2116 $theTables = array('tt_content');
2117 // External tables:
2118 if (is_array($this->externalTables)) {
2119 $theTables = array_unique(array_merge($theTables, array_keys($this->externalTables)));
2120 }
2121 $out = '';
2122 // Traverse tables to check:
2123 foreach ($theTables as $tName) {
2124 // Check access and whether the proper extensions are loaded:
2125 if ($this->getBackendUser()->check('tables_select', $tName)
2126 && (isset($this->externalTables[$tName])
2127 || GeneralUtility::inList('fe_users,tt_content', $tName)
2128 || \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded($tName)
2129 )
2130 ) {
2131 // Make query to count records from page:
2132 $c = $this->getDatabase()->exec_SELECTcountRows('uid', $tName, 'pid=' . (int)$id
2133 . BackendUtility::deleteClause($tName) . BackendUtility::versioningPlaceholderClause($tName));
2134 // If records were found (or if "tt_content" is the table...):
2135 if ($c || GeneralUtility::inList('tt_content', $tName)) {
2136 // Add row to menu:
2137 $out .= '
2138 <td><a href="#' . $tName . '"></a>' . IconUtility::getSpriteIconForRecord(
2139 $tName,
2140 array(),
2141 array('title' => $this->getLanguageService()->sL($GLOBALS['TCA'][$tName]['ctrl']['title'], TRUE))
2142 ) . '</td>';
2143 // ... and to the internal array, activeTables we also add table icon and title (for use elsewhere)
2144 $this->activeTables[$tName] = IconUtility::getSpriteIconForRecord(
2145 $tName,
2146 array(),
2147 array('title' => $this->getLanguageService()->sL($GLOBALS['TCA'][$tName]['ctrl']['title'], TRUE)
2148 . ': ' . $c . ' ' . $this->getLanguageService()->getLL('records', TRUE))
2149 ) . '&nbsp;' . $this->getLanguageService()->sL($GLOBALS['TCA'][$tName]['ctrl']['title'], TRUE);
2150 }
2151 }
2152 }
2153 // Wrap cells in table tags:
2154 $out = '
2155 <!--
2156 Menu of tables on the page (table menu)
2157 -->
2158 <table border="0" cellpadding="0" cellspacing="0" id="typo3-page-tblMenu">
2159 <tr>' . $out . '
2160 </tr>
2161 </table>';
2162 // Return the content:
2163 return $out;
2164 }
2165
2166 /**
2167 * @return BackendLayoutView
2168 */
2169 protected function getBackendLayoutView() {
2170 return GeneralUtility::makeInstance(BackendLayoutView::class);
2171 }
2172
2173 /**
2174 * @return BackendUserAuthentication
2175 */
2176 protected function getBackendUser() {
2177 return $GLOBALS['BE_USER'];
2178 }
2179
2180 /**
2181 * @return DatabaseConnection
2182 */
2183 protected function getDatabase() {
2184 return $GLOBALS['TYPO3_DB'];
2185 }
2186
2187 /**
2188 * @return LanguageService
2189 */
2190 protected function getLanguageService() {
2191 return $GLOBALS['LANG'];
2192 }
2193
2194 /**
2195 * @return PageLayoutController
2196 */
2197 protected function getPageLayoutController() {
2198 return $GLOBALS['SOBE'];
2199 }
2200
2201 /**
2202 * @return DocumentTemplate
2203 */
2204 protected function getDocumentTemplate() {
2205 return $GLOBALS['TBE_TEMPLATE'];
2206 }
2207
2208 }