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