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