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