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