Follow-up to #16396: cleaned up code, fixed naming convention violations
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / layout / class.tx_cms_layout.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2010 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 * Include file extending db_list.inc for use with the web_layout module
29 *
30 * $Id$
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 * [CLASS/FUNCTION INDEX of SCRIPT]
39 *
40 *
41 *
42 * 115: class tx_cms_layout extends recordList
43 *
44 * SECTION: Renderings
45 * 180: function getTable($table,$id)
46 * 240: function getTable_pages($id)
47 * 378: function getTable_tt_content($id)
48 * 754: function getTable_fe_users($id)
49 * 780: function getTable_sys_note($id)
50 * 873: function getTable_tt_board($id)
51 * 955: function getTable_tt_address($id)
52 * 985: function getTable_tt_links($id)
53 * 1011: function getTable_tt_guest($id)
54 * 1026: function getTable_tt_news($id)
55 * 1047: function getTable_tt_calender($id)
56 * 1097: function getTable_tt_products($id)
57 *
58 * SECTION: Generic listing of items
59 * 1143: function makeOrdinaryList($table, $id, $fList, $icon=0, $addWhere='')
60 * 1224: function dataFields($fieldArr,$table,$row,$out=array())
61 * 1275: function headerFields($fieldArr,$table,$out=array())
62 *
63 * SECTION: Additional functions; Pages
64 * 1317: function pages_getTree($theRows,$pid,$qWhere,$treeIcons,$depth)
65 * 1350: function pages_drawItem($row,$fieldArr)
66 *
67 * SECTION: Additional functions; Content Elements
68 * 1461: function tt_content_drawColHeader($colName,$editParams,$newParams)
69 * 1513: function tt_content_drawHeader($row,$space=0,$disableMoveAndNewButtons=FALSE,$langMode=FALSE)
70 * 1643: function tt_content_drawItem($row, $isRTE=FALSE)
71 * 1806: function getNonTranslatedTTcontentUids($defLanguageCount,$id,$lP)
72 * 1836: function newLanguageButton($defLanguageCount,$lP)
73 * 1857: function infoGif($infoArr)
74 * 1873: function newContentElementOnClick($id,$colPos,$sys_language)
75 * 1891: function linkEditContent($str,$row)
76 * 1909: function linkRTEbutton($row)
77 * 1930: function languageSelector($id)
78 * 1967: function getResult($result)
79 *
80 * SECTION: Additional functions; Message board items (tt_board)
81 * 2036: function tt_board_getTree($theRows,$parent,$pid,$qWhere,$treeIcons)
82 * 2071: function tt_board_drawItem($table,$row,$re)
83 *
84 * SECTION: Various helper functions
85 * 2118: function numberOfRecords($table,$pid)
86 * 2137: function renderText($input)
87 * 2151: function getIcon($table,$row)
88 * 2174: function getProcessedValue($table,$fieldList,$row,&$info)
89 * 2194: function isDisabled($table,$row)
90 * 2212: function wordWrapper($content,$max=50,$char=' -')
91 * 2229: function noEditIcon($label='noEditItems')
92 * 2238: function cleanTableNames()
93 * 2274: function isRTEforField($table,$row,$field)
94 * 2304: function getSpecConfForField($table,$row,$field)
95 *
96 * SECTION: External renderings
97 * 2341: function getPageInfoBox($rec,$edit=0)
98 * 2510: function getTableMenu($id)
99 * 2575: function strip_tags($content, $fillEmptyContent=false)
100 *
101 * TOTAL FUNCTIONS: 43
102 * (This index is automatically created/updated by the extension "extdeveval")
103 *
104 */
105
106
107 /**
108 * Child class for the Web > Page module
109 *
110 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
111 * @package TYPO3
112 * @subpackage core
113 */
114 class tx_cms_layout extends recordList {
115
116 // External, static: For page statistics:
117 var $stat_select_field = 'page_id'; // fieldname from sys_stat to select on.
118 var $stat_codes = array(); // eg. "HITS_days:-1"
119
120 // External, static: Flags of various kinds:
121 var $pI_showUser = 0; // If true, users/groups are shown in the page info box.
122 var $pI_showStat = 1; // If true, hit statistics are shown in the page info box.
123 var $nextThree = 3; // The number of successive records to edit when showing content elements.
124 var $pages_noEditColumns = 0; // If true, disables the edit-column icon for tt_content elements
125 var $option_showBigButtons = 1; // If true, shows big buttons for editing page properties, moving, creating elements etc. in the columns view.
126 var $option_newWizard = 1; // If true, new-wizards are linked to rather than the regular new-element list.
127 var $ext_function = 0; // If set to "1", will link a big button to content element wizard.
128 var $doEdit = 1; // If true, elements will have edit icons (probably this is whethere the user has permission to edit the page content). Set externally.
129 var $agePrefixes = ' min| hrs| days| yrs'; // Age prefixes for displaying times. May be set externally to localized values.
130 var $externalTables = array(); // Array of tables to be listed by the Web > Page module in addition to the default tables.
131 var $descrTable; // "Pseudo" Description -table name
132 var $defLangBinding = FALSE; // If set true, the language mode of tt_content elements will be rendered with hard binding between default language content elements and their translations!
133
134 // External, static: Configuration of tt_content element display:
135 var $tt_contentConfig = Array(
136 'showInfo' => 1, // Boolean: Display info-marks or not
137 'showCommands' => 1, // Boolean: Display up/down arrows and edit icons for tt_content records
138 'single' => 1, // Boolean: If set, the content of column(s) $this->tt_contentConfig['showSingleCol'] is shown in the total width of the page
139 'showAsGrid' => 0, // Boolean: If set, the content of columns is shown in grid
140 'showSingleCol' => 0, // The column(s) to show if single mode (under each other)
141 'languageCols' => 0,
142 'languageMode' => 0,
143 'languageColsPointer' => 0,
144 'showHidden' => 1, // Displays hidden records as well
145 'sys_language_uid' => 0, // Which language
146 'cols' => '1,0,2,3' // The order of the rows: Default is left(1), Normal(0), right(2), margin(3)
147 );
148
149 // Internal, dynamic:
150 var $allowedTableNames = array(); // Will contain a list of tables which can be listed by the user.
151 var $activeTables = array(); // Contains icon/title of pages which are listed in the tables menu (see getTableMenu() function )
152 var $tt_contentData = Array(
153 'nextThree' => Array(),
154 'prev' => Array(),
155 'next' => Array()
156 );
157 var $CType_labels = array(); // Used to store labels for CTypes for tt_content elements
158 var $itemLabels = array(); // Used to store labels for the various fields in tt_content elements
159
160
161 /*****************************************
162 *
163 * Renderings
164 *
165 *****************************************/
166
167 /**
168 * Adds the code of a single table
169 *
170 * @param string Table name
171 * @param integer Current page id
172 * @return string HTML for listing.
173 */
174 function getTable($table, $id) {
175
176 // Load full table definition:
177 t3lib_div::loadTCA($table);
178
179 if (isset($this->externalTables[$table])) {
180 return $this->getExternalTables($id, $table);
181 } else {
182 // Branch out based on table name:
183 // Notice: Most of these tables belongs to other extensions than 'cms'. Each of these tables can be rendered only if the extensions they belong to is loaded.
184 switch ($table) {
185 case 'pages':
186 return $this->getTable_pages($id);
187 break;
188 case 'tt_content':
189 return $this->getTable_tt_content($id);
190 break;
191 case 'fe_users':
192 return $this->getTable_fe_users($id);
193 break;
194 case 'sys_note':
195 return $this->getTable_sys_note($id);
196 break;
197 case 'tt_board':
198 return $this->getTable_tt_board($id);
199 break;
200 case 'tt_address':
201 return $this->getTable_tt_address($id);
202 break;
203 case 'tt_links':
204 return $this->getTable_tt_links($id);
205 break;
206 case 'tt_guest':
207 return $this->getTable_tt_guest($id);
208 break;
209 case 'tt_news':
210 return $this->getTable_tt_news($id);
211 break;
212 case 'tt_calender':
213 return $this->getTable_tt_calender($id);
214 break;
215 case 'tt_products':
216 return $this->getTable_tt_products($id);
217 break;
218 }
219 }
220 }
221
222
223 /**
224 * Renders an external table from page id
225 *
226 * @param integer Page id
227 * @param string name of the table
228 * @return string HTML for the listing
229 */
230 function getExternalTables($id, $table) {
231
232 $type = $GLOBALS['SOBE']->MOD_SETTINGS[$table];
233 if (!isset($type)) {
234 $type = 0;
235 }
236
237 $fList = $this->externalTables[$table][$type]['fList']; // eg. "name;title;email;company,image"
238 // The columns are separeted by comma ','.
239 // Values separated by semicolon ';' are shown in the same column.
240 $icon = $this->externalTables[$table][$type]['icon'];
241 $addWhere = $this->externalTables[$table][$type]['addWhere'];
242
243 // Create listing
244 $out = $this->makeOrdinaryList($table, $id, $fList, $icon, $addWhere);
245 return $out;
246 }
247
248
249 /**
250 * Renders records from the pages table from page id
251 * (Used to get information about the page tree content by "Web>Info"!)
252 *
253 * @param integer Page id
254 * @return string HTML for the listing
255 */
256 function getTable_pages($id) {
257 global $TCA;
258
259 // Initializing:
260 $out = '';
261 $delClause = t3lib_BEfunc::deleteClause('pages') . ' AND ' . $GLOBALS['BE_USER']->getPagePermsClause(1); // Select clause for pages:
262
263 // Select current page:
264 if (!$id) {
265 $row = $GLOBALS['SOBE']->pageinfo; // The root has a pseudo record in pageinfo...
266 } else {
267 $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'pages', 'uid=' . intval($id) . $delClause);
268 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result);
269 t3lib_BEfunc::workspaceOL('pages', $row);
270 }
271
272 // If there was found a page:
273 if (is_array($row)) {
274
275 // Select which fields to show:
276 $pKey = $GLOBALS['SOBE']->MOD_SETTINGS['function'] == 'tx_cms_webinfo_hits' ? 'hits' : $GLOBALS['SOBE']->MOD_SETTINGS['pages'];
277 switch ($pKey) {
278 case 'hits':
279 $this->fieldArray = explode(',', 'title,' . implode(',', $this->stat_codes));
280 break;
281 case 1:
282 $this->cleanTableNames();
283 $tableNames = $this->allowedTableNames;
284 $this->fieldArray = explode(',', 'title,uid,' . implode(',', array_keys($tableNames)));
285 break;
286 case 2:
287 $this->fieldArray = explode(',', 'title,uid,lastUpdated,newUntil,no_cache,cache_timeout,php_tree_stop,TSconfig,storage_pid,is_siteroot,fe_login_mode');
288 break;
289 default:
290 $this->fieldArray = explode(',', 'title,uid,alias,starttime,endtime,fe_group,target,url,shortcut,shortcut_mode');
291 break;
292 }
293
294 // Getting select-depth:
295 $depth = intval($GLOBALS['SOBE']->MOD_SETTINGS['pages_levels']);
296
297 // Half line is drawn
298 $theData = Array();
299 $theData['subject'] = $this->widthGif;
300 $out .= $this->addelement(0, '', $theData);
301
302 // Overriding a few things:
303 $this->no_noWrap = 0;
304 $this->oddColumnsCssClass = 'bgColor3-20';
305
306 // Items
307 $this->eCounter = $this->firstElementNumber;
308
309 // Creating elements:
310 list($flag, $code) = $this->fwd_rwd_nav();
311 $out .= $code;
312 $editUids = array();
313 if ($flag) {
314
315 // Getting children:
316 $theRows = Array();
317 $theRows = $this->pages_getTree($theRows, $row['uid'], $delClause . t3lib_BEfunc::versioningPlaceholderClause('pages'), '', $depth);
318 if ($GLOBALS['BE_USER']->doesUserHaveAccess($row, 2)) {
319 $editUids[] = $row['uid'];
320 }
321 $out .= $this->pages_drawItem($row, $this->fieldArray);
322
323 // Traverse all pages selected:
324 foreach ($theRows as $n => $sRow) {
325 if ($GLOBALS['BE_USER']->doesUserHaveAccess($sRow, 2)) {
326 $editUids[] = $sRow['uid'];
327 }
328 $out .= $this->pages_drawItem($sRow, $this->fieldArray);
329 }
330 $this->eCounter++;
331 }
332
333 // Header line is drawn
334 $theData = Array();
335 $editIdList = implode(',', $editUids);
336
337 // Traverse fields (as set above) in order to create header values:
338 foreach ($this->fieldArray as $field) {
339 if ($editIdList && isset($TCA['pages']['columns'][$field]) && $field != 'uid' && !$this->pages_noEditColumns) {
340 $params = '&edit[pages][' . $editIdList . ']=edit&columnsOnly=' . $field . '&disHelp=1';
341 $iTitle = sprintf($GLOBALS['LANG']->getLL('editThisColumn'), rtrim(trim($GLOBALS['LANG']->sL(t3lib_BEfunc::getItemLabel('pages', $field))), ':'));
342 $eI = '<a href="#" onclick="' . htmlspecialchars(t3lib_BEfunc::editOnClick($params, $this->backPath, '')) . '" title="' . htmlspecialchars($iTitle) . '">' .
343 t3lib_iconWorks::getSpriteIcon('actions-document-open') .
344 '</a>';
345 } else {
346 $eI = '';
347 }
348 switch ($field) {
349 case 'title':
350 $theData[$field] = '&nbsp;<strong>' . $GLOBALS['LANG']->sL($TCA['pages']['columns'][$field]['label']) . '</strong>' . $eI;
351 break;
352 case 'uid':
353 $theData[$field] = '&nbsp;<strong>ID:</strong>';
354 break;
355 default:
356 if (substr($field, 0, 6) == 'table_') {
357 $f2 = substr($field, 6);
358 if ($TCA[$f2]) {
359 $theData[$field] = '&nbsp;' . t3lib_iconWorks::getSpriteIconForRecord($f2, array(), array('title' => $GLOBALS['LANG']->sL($TCA[$f2]['ctrl']['title'], 1)));
360 }
361 } elseif (substr($field, 0, 5) == 'HITS_') {
362 $fParts = explode(':', substr($field, 5));
363 switch ($fParts[0]) {
364 case 'days':
365 $timespan = mktime(0, 0, 0) + intval($fParts[1]) * 3600 * 24;
366 $theData[$field] = '&nbsp;' . date('d', $timespan);
367 break;
368 default:
369 $theData[$field] = '';
370 break;
371 }
372 } else {
373 $theData[$field] = '&nbsp;&nbsp;<strong>' . $GLOBALS['LANG']->sL($TCA['pages']['columns'][$field]['label'], 1) . '</strong>' . $eI;
374 }
375 break;
376 }
377 }
378
379 // Start table:
380 $this->oddColumnsCssClass = '';
381
382 // CSH:
383 $out = t3lib_BEfunc::cshItem($this->descrTable, 'func_' . $pKey, $GLOBALS['BACK_PATH']) .
384 '
385 <table border="0" cellpadding="0" cellspacing="0" class="typo3-page-pages">
386 ' . $this->addelement(1, '', $theData, ' class="t3-row-header"', 20) .
387 $out . '
388 </table>';
389 }
390 $this->oddColumnsCssClass = '';
391 return $out;
392 }
393
394 /**
395 * Returns the backend layout which should be used for this page.
396 *
397 * @param integer $id: Uid of the current
398 * @return integer The Uid of the backend layout record
399 */
400 function getSelectedBackendLayoutUid($id) {
401 $rootline = t3lib_BEfunc::BEgetRootLine($id);
402 $backendLayoutUid = null;
403 for ($i = count($rootline); $i > 0; $i--) {
404 $page = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('uid, be_layout, be_layout_next_level', 'pages', 'uid=' . intval($rootline[$i]['uid']));
405 if (intval($page['be_layout_next_level']) > 0 && $page['uid'] != $id) {
406 $backendLayoutUid = intval($page['be_layout_next_level']);
407 break;
408 } else {
409 if (intval($page['be_layout']) > 0) {
410 $backendLayoutUid = intval($page['be_layout']);
411 break;
412 }
413 }
414 }
415 return $backendLayoutUid;
416 }
417
418 /**
419 * Renders Content Elements from the tt_content table from page id
420 *
421 * @param integer Page id
422 * @return string HTML for the listing
423 */
424 function getTable_tt_content($id) {
425 global $TCA;
426
427 $this->initializeLanguages();
428
429 // Initialize:
430 $RTE = $GLOBALS['BE_USER']->isRTE();
431 $lMarg = 1;
432 $showHidden = $this->tt_contentConfig['showHidden'] ? '' : t3lib_BEfunc::BEenableFields('tt_content');
433 $pageTitleParamForAltDoc = '&recTitle=' . rawurlencode(t3lib_BEfunc::getRecordTitle('pages', t3lib_BEfunc::getRecordWSOL('pages', $id), TRUE));
434 $GLOBALS['SOBE']->doc->getPageRenderer()->loadExtJs();
435 $GLOBALS['SOBE']->doc->getPageRenderer()->addJsFile($GLOBALS['BACK_PATH'] . 'sysext/cms/layout/js/typo3pageModule.js');
436
437 // Get labels for CTypes and tt_content element fields in general:
438 $this->CType_labels = array();
439 foreach ($TCA['tt_content']['columns']['CType']['config']['items'] as $val) {
440 $this->CType_labels[$val[1]] = $GLOBALS['LANG']->sL($val[0]);
441 }
442 $this->itemLabels = array();
443 foreach ($TCA['tt_content']['columns'] as $name => $val) {
444 $this->itemLabels[$name] = $GLOBALS['LANG']->sL($val['label']);
445 }
446
447 // Select display mode:
448 if (!$this->tt_contentConfig['single']) { // MULTIPLE column display mode, side by side:
449
450 // Setting language list:
451 $langList = $this->tt_contentConfig['sys_language_uid'];
452 if ($this->tt_contentConfig['languageMode']) {
453 if ($this->tt_contentConfig['languageColsPointer']) {
454 $langList = '0,' . $this->tt_contentConfig['languageColsPointer'];
455 } else {
456 $langList = implode(',', array_keys($this->tt_contentConfig['languageCols']));
457 }
458 $languageColumn = array();
459 }
460 $langListArr = explode(',', $langList);
461 $defLanguageCount = array();
462 $defLangBinding = array();
463
464 // For EACH languages... :
465 foreach ($langListArr as $lP) { // If NOT languageMode, then we'll only be through this once.
466 $showLanguage = $this->defLangBinding && $lP == 0 ? ' AND sys_language_uid IN (0,-1)' : ' AND sys_language_uid=' . $lP;
467 $cList = explode(',', $this->tt_contentConfig['cols']);
468 $content = array();
469 $head = array();
470
471 // For EACH column, render the content into a variable:
472 foreach ($cList as $key) {
473 if (!$lP) {
474 $defLanguageCount[$key] = array();
475 }
476
477 // Select content elements from this column/language:
478 $queryParts = $this->makeQueryArray('tt_content', $id, 'AND colPos=' . intval($key) . $showHidden . $showLanguage);
479 $result = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
480
481 // 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:
482 if ($this->doEdit && $this->option_showBigButtons && !intval($key) && !$GLOBALS['TYPO3_DB']->sql_num_rows($result)) {
483 $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')) . "';";
484 $theNewButton = $GLOBALS['SOBE']->doc->t3Button($onClick, $GLOBALS['LANG']->getLL('newPageContent'));
485 $content[$key] .= '<img src="clear.gif" width="1" height="5" alt="" /><br />' . $theNewButton;
486 }
487
488 // Traverse any selected elements and render their display code:
489 $rowArr = $this->getResult($result);
490
491 foreach ($rowArr as $rKey => $row) {
492
493 if (is_array($row) && (int) $row['t3ver_state'] != 2) {
494 $singleElementHTML = '';
495 if (!$lP) {
496 $defLanguageCount[$key][] = $row['uid'];
497 }
498
499 $editUidList .= $row['uid'] . ',';
500 $singleElementHTML .= $this->tt_content_drawHeader($row, $this->tt_contentConfig['showInfo'] ? 15 : 5, $this->defLangBinding && $lP > 0, TRUE);
501
502 $isRTE = $RTE && $this->isRTEforField('tt_content', $row, 'bodytext');
503 $singleElementHTML .= '<div ' . ($row['_ORIG_uid'] ? ' class="ver-element"' : '') . '>' . $this->tt_content_drawItem($row, $isRTE) . '</div>';
504
505 // NOTE: this is the end tag for <div class="t3-page-ce-body">
506 // because of bad (historic) conception, starting tag has to be placed inside tt_content_drawHeader()
507 $singleElementHTML .= '</div>';
508
509
510 $statusHidden = ($this->isDisabled('tt_content', $row) ? ' t3-page-ce-hidden' : '');
511 $singleElementHTML = '<div class="t3-page-ce' . $statusHidden . '">' . $singleElementHTML . '</div>';
512
513 if ($this->defLangBinding && $this->tt_contentConfig['languageMode']) {
514 $defLangBinding[$key][$lP][$row[($lP ? 'l18n_parent' : 'uid')]] = $singleElementHTML;
515 } else {
516 $content[$key] .= $singleElementHTML;
517 }
518 } else {
519 unset($rowArr[$rKey]);
520 }
521 }
522
523 // Add new-icon link, header:
524 $newP = $this->newContentElementOnClick($id, $key, $lP);
525 $colTitle = t3lib_BEfunc::getProcessedValue('tt_content', 'colPos', $key);
526
527 $tcaItems = t3lib_div::callUserFunction('EXT:cms/classes/class.tx_cms_backendlayout.php:tx_cms_BackendLayout->getColPosListItemsParsed', $id, $this);
528 foreach ($tcaItems as $item) {
529 if ($item[1] == $key) {
530 $colTitle = $GLOBALS['LANG']->sL($item[0]);
531 }
532 }
533 $head[$key] .= $this->tt_content_drawColHeader($colTitle, ($this->doEdit && count($rowArr) ? '&edit[tt_content][' . $editUidList . ']=edit' . $pageTitleParamForAltDoc : ''), $newP);
534 $editUidList = '';
535 }
536
537 // For EACH column, fit the rendered content into a table cell:
538 $out = '';
539
540 if ($this->tt_contentConfig['showAsGrid']) {
541 $backendLayoutUid = $this->getSelectedBackendLayoutUid($id);
542 $backendLayoutRecord = t3lib_BEfunc::getRecord('be_layouts', intval($backendLayoutUid));
543 if (empty($backendLayoutRecord['config'])) {
544 // TODO: show a message that no layout was found
545 $this->tt_contentConfig['showAsGrid'] = 0;
546 }
547 }
548
549 if (!$this->tt_contentConfig['showAsGrid']) {
550 foreach ($cList as $k => $key) {
551
552 if (!$k) {
553 $out .= '
554 <td><img src="clear.gif" width="' . $lMarg . '" height="1" alt="" /></td>';
555 } else {
556 $out .= '
557 <td><img src="clear.gif" width="4" height="1" alt="" /></td>
558 <td bgcolor="#cfcfcf"><img src="clear.gif" width="1" height="1" alt="" /></td>
559 <td><img src="clear.gif" width="4" height="1" alt="" /></td>';
560 }
561 $out .= '
562 <td class="t3-page-column t3-page-column-' . $key . '">' . $head[$key] . $content[$key] . '</td>';
563
564 // Storing content for use if languageMode is set:
565 if ($this->tt_contentConfig['languageMode']) {
566 $languageColumn[$key][$lP] = $head[$key] . $content[$key];
567 if (!$this->defLangBinding) {
568 $languageColumn[$key][$lP] .= '<br /><br />' . $this->newLanguageButton($this->getNonTranslatedTTcontentUids($defLanguageCount[$key], $id, $lP), $lP);
569 }
570 }
571 }
572
573 // Wrap the cells into a table row:
574 $out = '
575 <table border="0" cellpadding="0" cellspacing="0" class="t3-page-columns">
576 <tr>' . $out . '
577 </tr>
578 </table>';
579
580 } else {
581 // GRID VIEW:
582
583 // initialize TS parser to parse config to array
584 $parser = t3lib_div::makeInstance('t3lib_TSparser');
585 $parser->parse($backendLayoutRecord['config']);
586
587 $grid .= '<div class="t3-gridContainer"><table border="0" cellspacing="1" cellpadding="4" width="80%" height="100%" class="t3-page-columns t3-gridTable">';
588
589 // add colgroups
590 $colCount = intval($parser->setup['be_layout.']['colCount']);
591 $rowCount = intval($parser->setup['be_layout.']['rowCount']);
592
593 $grid .= '<colgroup>';
594 for ($i = 0; $i < $colCount; $i++) {
595 $grid .= '<col style="width:' . (100 / $colCount) . '%"></col>';
596 }
597 $grid .= '</colgroup>';
598
599 // cycle through rows
600 for ($row = 1; $row <= $rowCount; $row++) {
601 $rowConfig = $parser->setup['be_layout.']['rows.'][$row . '.'];
602 if (!isset($rowConfig)) {
603 continue;
604 }
605
606 $grid .= '<tr>';
607
608 for ($col = 1; $col <= $colCount; $col++) {
609 $columnConfig = $rowConfig['columns.'][$col . '.'];
610
611 if (!isset($columnConfig)) {
612 continue;
613 }
614
615 // which tt_content colPos should be displayed inside this cell
616 $columnKey = intval($columnConfig['colPos']);
617
618 // render the grid cell
619 $grid .= '<td valign="top"' .
620 (isset($columnConfig['colspan']) ? ' colspan="' . $columnConfig['colspan'] . '"' : '') .
621 (isset($columnConfig['rowspan']) ? ' rowspan="' . $columnConfig['rowspan'] . '"' : '') .
622 ' class="t3-gridCell t3-page-column t3-page-column-' . $columnKey .
623 (!isset($columnConfig['colPos']) ? ' t3-gridCell-disabled' : '') .
624 (isset($columnConfig['colspan']) ? ' t3-gridCell-width' . $columnConfig['colspan'] : '') .
625 (isset($columnConfig['rowspan']) ? ' t3-gridCell-height' . $columnConfig['rowspan'] : '') . '">';
626
627 // Draw the pre-generated header with edit and new buttons if a colPos is assigned.
628 // If not, a new header without any buttons will be generated.
629 if (isset($columnConfig['colPos'])) {
630 $grid .= $head[$columnKey] . $content[$columnKey];
631 } else {
632 $grid .= $this->tt_content_drawColHeader($columnConfig['name'], '', '');
633 }
634
635 $grid .= '</td>';
636 }
637 $grid .= '</tr>';
638 }
639 $out .= $grid . '</table></div>';
640 }
641
642 // CSH:
643 $out .= t3lib_BEfunc::cshItem($this->descrTable, 'columns_multi', $GLOBALS['BACK_PATH']);
644 }
645
646 // If language mode, then make another presentation:
647 // 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!
648 if ($this->tt_contentConfig['languageMode']) {
649
650 // Get language selector:
651 $languageSelector = $this->languageSelector($id);
652
653 // Reset out - we will make new content here:
654 $out = '';
655 // Separator between language columns (black thin line)
656 $midSep = '
657 <td><img src="clear.gif" width="4" height="1" alt="" /></td>
658 <td bgcolor="black"><img src="clear.gif" width="1" height="1" alt="" /></td>
659 <td><img src="clear.gif" width="4" height="1" alt="" /></td>';
660
661 // Traverse languages found on the page and build up the table displaying them side by side:
662 $cCont = array();
663 $sCont = array();
664 foreach ($langListArr as $lP) {
665
666 // Header:
667 $cCont[$lP] = '
668 <td valign="top" align="center" class="bgColor6"><strong>' . htmlspecialchars($this->tt_contentConfig['languageCols'][$lP]) . '</strong></td>';
669
670 // "View page" icon is added:
671 $viewLink = '<a href="#" onclick="' . htmlspecialchars(t3lib_BEfunc::viewOnClick($this->id, $this->backPath, t3lib_BEfunc::BEgetRootLine($this->id), '', '', '&L=' . $lP)) . '">' .
672 t3lib_iconWorks::getSpriteIcon('actions-document-view') .
673 '</a>';
674
675 // Language overlay page header:
676 if ($lP) {
677
678 list($lpRecord) = t3lib_BEfunc::getRecordsByField('pages_language_overlay', 'pid', $id, 'AND sys_language_uid=' . intval($lP));
679 t3lib_BEfunc::workspaceOL('pages_language_overlay', $lpRecord);
680 $params = '&edit[pages_language_overlay][' . $lpRecord['uid'] . ']=edit&overrideVals[pages_language_overlay][sys_language_uid]=' . $lP;
681 $lPLabel = $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon(t3lib_iconWorks::getSpriteIconForRecord('pages_language_overlay', $lpRecord), $lpRecord['uid']) .
682 $viewLink .
683 ($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) . '">' .
684 t3lib_iconWorks::getSpriteIcon('actions-document-open') .
685 '</a>' : '') .
686 htmlspecialchars(t3lib_div::fixed_lgd_cs($lpRecord['title'], 20));
687 } else {
688 $lPLabel = $viewLink;
689 }
690 $sCont[$lP] = '
691 <td nowrap="nowrap">' . $lPLabel . '</td>';
692 }
693 // Add headers:
694 $out .= '
695 <tr class="bgColor5">' . implode($midSep, $cCont) . '
696 </tr>';
697 $out .= '
698 <tr class="bgColor5">' . implode($midSep, $sCont) . '
699 </tr>';
700
701 // Traverse previously built content for the columns:
702 foreach ($languageColumn as $cKey => $cCont) {
703 $out .= '
704 <tr>
705 <td valign="top">' . implode('</td>' . $midSep . '
706 <td valign="top">', $cCont) . '</td>
707 </tr>';
708
709 if ($this->defLangBinding) {
710 // "defLangBinding" mode
711 foreach ($defLanguageCount[$cKey] as $defUid) {
712 $cCont = array();
713 foreach ($langListArr as $lP) {
714 $cCont[] = $defLangBinding[$cKey][$lP][$defUid] .
715 '<br/>' . $this->newLanguageButton($this->getNonTranslatedTTcontentUids(array($defUid), $id, $lP), $lP);
716 }
717 $out .= '
718 <tr>
719 <td valign="top">' . implode('</td>' . $midSep . '
720 <td valign="top">', $cCont) . '</td>
721 </tr>';
722 }
723
724 // Create spacer:
725 $cCont = array();
726 foreach ($langListArr as $lP) {
727 $cCont[] = '&nbsp;';
728 }
729 $out .= '
730 <tr>
731 <td valign="top">' . implode('</td>' . $midSep . '
732 <td valign="top">', $cCont) . '</td>
733 </tr>';
734 }
735 }
736
737 // Finally, wrap it all in a table and add the language selector on top of it:
738 $out = $languageSelector . '
739 <table border="0" cellpadding="0" cellspacing="0" width="480" class="typo3-page-langMode">
740 ' . $out . '
741 </table>';
742
743 // CSH:
744 $out .= t3lib_BEfunc::cshItem($this->descrTable, 'language_list', $GLOBALS['BACK_PATH']);
745 }
746 } else { // SINGLE column mode (columns shown beneath each other):
747 #debug('single column');
748 if ($this->tt_contentConfig['sys_language_uid'] == 0 || !$this->defLangBinding) {
749
750 // Initialize:
751 if ($this->defLangBinding && $this->tt_contentConfig['sys_language_uid'] == 0) {
752 $showLanguage = ' AND sys_language_uid IN (0,-1)';
753 $lP = 0;
754 } else {
755 $showLanguage = ' AND sys_language_uid=' . $this->tt_contentConfig['sys_language_uid'];
756 $lP = $this->tt_contentConfig['sys_language_uid'];
757 }
758
759 $cList = explode(',', $this->tt_contentConfig['showSingleCol']);
760 $content = array();
761 $out = '';
762
763 // Expand the table to some preset dimensions:
764 $out .= '
765 <tr>
766 <td><img src="clear.gif" width="' . $lMarg . '" height="1" alt="" /></td>
767 <td valign="top"><img src="clear.gif" width="150" height="1" alt="" /></td>
768 <td><img src="clear.gif" width="10" height="1" alt="" /></td>
769 <td valign="top"><img src="clear.gif" width="300" height="1" alt="" /></td>
770 </tr>';
771
772 // Traverse columns to display top-on-top
773 foreach ($cList as $counter => $key) {
774
775 // Select content elements:
776 $queryParts = $this->makeQueryArray('tt_content', $id, 'AND colPos=' . intval($key) . $showHidden . $showLanguage);
777 $result = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
778 $c = 0;
779 $rowArr = $this->getResult($result);
780 $rowOut = '';
781
782 // 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:
783 if ($this->doEdit && $this->option_showBigButtons && !intval($key) && !$GLOBALS['TYPO3_DB']->sql_num_rows($result)) {
784 $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')) . "';";
785 $theNewButton = $GLOBALS['SOBE']->doc->t3Button($onClick, $GLOBALS['LANG']->getLL('newPageContent'));
786 $theNewButton = '<img src="clear.gif" width="1" height="5" alt="" /><br />' . $theNewButton;
787 } else {
788 $theNewButton = '';
789 }
790
791 // Traverse any selected elements:
792 foreach ($rowArr as $rKey => $row) {
793
794 if (is_array($row) && (int) $row['t3ver_state'] != 2) {
795
796 $c++;
797 $editUidList .= $row['uid'] . ',';
798 $isRTE = $RTE && $this->isRTEforField('tt_content', $row, 'bodytext');
799
800 // Create row output:
801 $rowOut .= '
802 <tr>
803 <td></td>
804 <td valign="top">' . $this->tt_content_drawHeader($row) . '</td>
805 <td>&nbsp;</td>
806 <td' . ($row['_ORIG_uid'] ? ' class="ver-element"' : '') . ' valign="top">' . $this->tt_content_drawItem($row, $isRTE) . '</td>
807 </tr>';
808
809 // If the element was not the last element, add a divider line:
810 if ($c != $GLOBALS['TYPO3_DB']->sql_num_rows($result)) {
811 $rowOut .= '
812 <tr>
813 <td></td>
814 <td colspan="3"><img' . t3lib_iconWorks::skinImg($this->backPath, 'gfx/stiblet_medium2.gif', 'width="468" height="1"') . ' class="c-divider" alt="" /></td>
815 </tr>';
816 }
817 } else {
818 unset($rowArr[$rKey]);
819 }
820 }
821
822 // Add spacer between sections in the vertical list
823 if ($counter) {
824 $out .= '
825 <tr>
826 <td></td>
827 <td colspan="3"><br /><br /><br /><br /></td>
828 </tr>';
829 }
830
831 // Add section header:
832 $newP = $this->newContentElementOnClick($id, $key, $this->tt_contentConfig['sys_language_uid']);
833 $out .= '
834
835 <!-- Column header: -->
836 <tr>
837 <td></td>
838 <td valign="top" colspan="3">' .
839 $this->tt_content_drawColHeader(t3lib_BEfunc::getProcessedValue('tt_content', 'colPos', $key), ($this->doEdit && count($rowArr) ? '&edit[tt_content][' . $editUidList . ']=edit' . $pageTitleParamForAltDoc : ''), $newP) .
840 $theNewButton .
841 '<br /></td>
842 </tr>';
843
844 // Finally, add the content from the records in this column:
845 $out .= $rowOut;
846 }
847
848 // Finally, wrap all table rows in one, big table:
849 $out = '
850 <table border="0" cellpadding="0" cellspacing="0" width="400" class="typo3-page-columnsMode">
851 ' . $out . '
852 </table>';
853
854 // CSH:
855 $out .= t3lib_BEfunc::cshItem($this->descrTable, 'columns_single', $GLOBALS['BACK_PATH']);
856 } else {
857 $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/>';
858 }
859 }
860
861
862 // Add the big buttons to page:
863 if ($this->option_showBigButtons) {
864 $bArray = array();
865
866 if (!$GLOBALS['SOBE']->current_sys_language) {
867 if ($this->ext_CALC_PERMS & 2) {
868 $bArray[0] = $GLOBALS['SOBE']->doc->t3Button(t3lib_BEfunc::editOnClick('&edit[pages][' . $id . "]=edit", $this->backPath, ''), $GLOBALS['LANG']->getLL('editPageProperties'));
869 }
870 } else {
871 if ($this->doEdit && $GLOBALS['BE_USER']->check('tables_modify', 'pages_language_overlay')) {
872 list($languageOverlayRecord) = t3lib_BEfunc::getRecordsByField('pages_language_overlay', 'pid', $id, 'AND sys_language_uid=' . intval($GLOBALS['SOBE']->current_sys_language));
873 $bArray[0] = $GLOBALS['SOBE']->doc->t3Button(t3lib_BEfunc::editOnClick('&edit[pages_language_overlay][' . $languageOverlayRecord['uid'] . "]=edit", $this->backPath, ''), $GLOBALS['LANG']->getLL('editPageProperties_curLang'));
874 }
875 }
876 if ($this->ext_CALC_PERMS & 4 || $this->ext_CALC_PERMS & 2) {
877 $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'));
878 }
879 if ($this->ext_CALC_PERMS & 8) {
880 $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'));
881 }
882 if ($this->doEdit && $this->ext_function == 1) {
883 $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'));
884 }
885 $out = '
886 <table border="0" cellpadding="4" cellspacing="0" class="typo3-page-buttons">
887 <tr>
888 <td>' . implode('</td>
889 <td>', $bArray) . '</td>
890 <td>' . t3lib_BEfunc::cshItem($this->descrTable, 'button_panel', $GLOBALS['BACK_PATH']) . '</td>
891 </tr>
892 </table>
893 <br />
894 ' . $out;
895 }
896
897 // Return content:
898 return $out;
899 }
900
901 /**
902 * Renders Frontend Users from the fe_users table from page id
903 *
904 * @param integer Page id
905 * @return string HTML for the listing
906 */
907 function getTable_fe_users($id) {
908
909 $this->addElement_tdParams = array(
910 'username' => ' nowrap="nowrap"',
911 'usergroup' => ' nowrap="nowrap"',
912 'name' => ' nowrap="nowrap"',
913 'address' => ' nowrap="nowrap"',
914 'zip' => ' nowrap="nowrap"',
915 'city' => ' nowrap="nowrap"',
916 'email' => ' nowrap="nowrap"',
917 'telephone' => ' nowrap="nowrap"'
918 );
919 $fList = 'username,usergroup,name,email,telephone,address,zip,city';
920 $out = $this->makeOrdinaryList('fe_users', $id, $fList, 1);
921 $this->addElement_tdParams = array();
922 return $out;
923 }
924
925 /**
926 * Renders records from the sys_notes table from page id
927 * NOTICE: Requires the sys_note extension to be loaded.
928 *
929 * @param integer Page id
930 * @return string HTML for the listing
931 */
932 function getTable_sys_note($id) {
933 global $TCA;
934
935 if (!t3lib_extMgm::isLoaded('sys_note')) {
936 return '';
937 }
938
939 // INIT:
940 $perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
941 $tree = $this->getTreeObject($id, intval($GLOBALS['SOBE']->MOD_SETTINGS['pages_levels']), $perms_clause);
942
943 $this->itemLabels = array();
944 foreach ($TCA['sys_note']['columns'] as $name => $val) {
945 $this->itemLabels[$name] = $GLOBALS['LANG']->sL($val['label']);
946 }
947
948 // If page ids were found, select all sys_notes from the page ids:
949 $out = '';
950 if (count($tree->ids)) {
951 $delClause = t3lib_BEfunc::deleteClause('sys_note') . t3lib_BEfunc::versioningPlaceholderClause('sys_note');
952 $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_note', 'pid IN (' . implode(',', $tree->ids) . ') AND (personal=0 OR cruser=' . intval($GLOBALS['BE_USER']->user['uid']) . ')' . $delClause);
953 $dbCount = $GLOBALS['TYPO3_DB']->sql_num_rows($result);
954
955 // If sys_notes were found, render them:
956 if ($dbCount) {
957 $this->fieldArray = explode(',', '__cmds__,info,note');
958
959 // header line is drawn
960 $theData = Array();
961 $theData['__cmds__'] = '';
962 $theData['info'] = '<strong>Info</strong><br /><img src="clear.gif" height="1" width="220" alt="" />';
963 $theData['note'] = '<strong>Note</strong>';
964 $out .= $this->addelement(1, '', $theData, ' class="t3-row-header"', 20);
965
966 // half line is drawn
967 $theData = Array();
968 $theData['info'] = $this->widthGif;
969 $out .= $this->addelement(0, '', $theData);
970
971 $this->no_noWrap = 1;
972
973 // Items
974 $this->eCounter = $this->firstElementNumber;
975 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) {
976 t3lib_BEfunc::workspaceOL('sys_note', $row);
977
978 if (is_array($row)) {
979 list($flag, $code) = $this->fwd_rwd_nav();
980 $out .= $code;
981 if ($flag) {
982 $color = Array(
983 0 => '', // No category
984 1 => ' class="bgColor4"', // Instructions
985 2 => ' class="bgColor2"', // Template
986 3 => '', // Notes
987 4 => ' class="bgColor5"' // To-do
988 );
989 $tdparams = $color[$row['category']];
990 $info = Array();
991 ;
992 $theData = Array();
993 $this->getProcessedValue('sys_note', 'subject,category,author,email,personal', $row, $info);
994 $cont = implode('<br />', $info);
995 $head = '<strong>Page:</strong> ' . t3lib_BEfunc::getRecordPath($row['pid'], $perms_clause, 10) . '<br />';
996
997 $theData['__cmds__'] = $this->getIcon('sys_note', $row);
998 $theData['info'] = $head . $cont;
999 $theData['note'] = nl2br($row['message']);
1000
1001 $out .= $this->addelement(1, '', $theData, $tdparams, 20);
1002
1003
1004 // half line is drawn
1005 $theData = Array();
1006 $theData['info'] = $this->widthGif;
1007 $out .= $this->addelement(0, '', $theData);
1008 }
1009 $this->eCounter++;
1010 }
1011 }
1012
1013 // Wrap it all in a table:
1014 $out = '
1015 <table border="0" cellpadding="1" cellspacing="2" width="480" class="typo3-page-sysnote">
1016 ' . $out . '
1017 </table>';
1018 }
1019 }
1020 return $out;
1021 }
1022
1023 /**
1024 * Renders records from the tt_board table from page id
1025 * NOTICE: Requires the tt_board extension to be loaded.
1026 *
1027 * @param integer Page id
1028 * @return string HTML for the listing
1029 */
1030 function getTable_tt_board($id) {
1031
1032 // Initialize:
1033 $delClause = t3lib_BEfunc::deleteClause('tt_board') . t3lib_BEfunc::versioningPlaceholderClause('tt_board');
1034 $queryParts = $this->makeQueryArray('tt_board', $id, 'AND parent=0');
1035 $this->setTotalItems($queryParts);
1036 $dbCount = 0;
1037
1038 // If items were selected, make query:
1039 if ($this->totalItems) {
1040 $result = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
1041 $dbCount = $GLOBALS['TYPO3_DB']->sql_num_rows($result);
1042 }
1043
1044 // If results came out of that, render the list:
1045 $out = '';
1046 if ($dbCount) {
1047
1048 // Setting fields to display first:
1049 if ($GLOBALS['SOBE']->MOD_SETTINGS['tt_board'] == 'expand') {
1050 $this->fieldArray = explode(',', 'subject,author,date,age');
1051 } else {
1052 $this->fieldArray = explode(',', 'subject,author,date,age,replys');
1053 }
1054
1055 // Header line is drawn
1056 $theData = Array();
1057 $theData['subject'] = '<strong>' . $GLOBALS['LANG']->getLL('tt_board_subject', 1) . '</strong>';
1058 $theData['author'] = '<strong>' . $GLOBALS['LANG']->getLL('tt_board_author', 1) . '</strong>';
1059 $theData['date'] = '<strong>' . $GLOBALS['LANG']->getLL('tt_board_date', 1) . '</strong>';
1060 $theData['age'] = '<strong>' . $GLOBALS['LANG']->getLL('tt_board_age', 1) . '</strong>';
1061 if ($GLOBALS['SOBE']->MOD_SETTINGS['tt_board'] != 'expand') {
1062 $theData['replys'] = '<strong>' . $GLOBALS['LANG']->getLL('tt_board_RE', 1) . '</strong>';
1063 }
1064 $out .= $this->addelement(1, '', $theData, ' class="t3-row-header"', 20);
1065
1066 // half line is drawn
1067 $theData = Array();
1068 $theData['subject'] = $this->widthGif;
1069 $out .= $this->addelement(0, '', $theData);
1070
1071 // Items
1072 $this->eCounter = $this->firstElementNumber;
1073 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) {
1074 t3lib_BEfunc::workspaceOL('tt_board', $row);
1075
1076 if (is_array($row)) {
1077 list($flag, $code) = $this->fwd_rwd_nav();
1078 $out .= $code;
1079
1080 if ($flag) {
1081
1082 $theRows = Array();
1083 $theRows = $this->tt_board_getTree($theRows, $row['uid'], $id, $delClause, '');
1084 $out .= $this->tt_board_drawItem('tt_board', $row, count($theRows));
1085
1086 if ($GLOBALS['SOBE']->MOD_SETTINGS['tt_board'] == 'expand') {
1087 foreach ($theRows as $n => $sRow) {
1088 $out .= $this->tt_board_drawItem('tt_board', $sRow, 0);
1089 }
1090 }
1091 }
1092 $this->eCounter++;
1093 }
1094 }
1095
1096 // Wrap it all in a table:
1097 $out = '
1098 <table border="0" cellpadding="0" cellspacing="0" class="typo3-page-listTTboard">
1099 ' . $out . '
1100 </table>';
1101 }
1102
1103 return $out;
1104 }
1105
1106 /**
1107 * Renders address records from the tt_address table from page id
1108 * NOTICE: Requires the tt_address extension to be loaded.
1109 *
1110 * @param integer Page id
1111 * @return string HTML for the listing
1112 */
1113 function getTable_tt_address($id) {
1114
1115 // Define fieldlist to show:
1116 switch ($GLOBALS['SOBE']->MOD_SETTINGS['tt_address']) {
1117 case 1:
1118 $icon = 0;
1119 $fList = 'name,address,zip,city,country';
1120 break;
1121 case 2:
1122 $icon = 1;
1123 $fList = 'name;title;email;company,image';
1124 break;
1125 default:
1126 $icon = 0;
1127 $fList = 'name,email,www,phone,fax,mobile';
1128 break;
1129 }
1130
1131 // Create listing
1132 $out = $this->makeOrdinaryList('tt_address', $id, $fList, $icon);
1133 return $out;
1134 }
1135
1136 /**
1137 * Renders link records from the tt_links table from page id
1138 * NOTICE: Requires the tt_links extension to be loaded.
1139 *
1140 * @param integer Page id
1141 * @return string HTML for the listing
1142 */
1143 function getTable_tt_links($id) {
1144
1145 // Define fieldlist to show:
1146 switch ($GLOBALS['SOBE']->MOD_SETTINGS['tt_links']) {
1147 case 1:
1148 $fList = 'title,hidden,url';
1149 break;
1150 case 2:
1151 $fList = 'title;url,note2';
1152 break;
1153 default:
1154 $fList = 'title;url,note';
1155 break;
1156 }
1157
1158 $out = $this->makeOrdinaryList('tt_links', $id, $fList, 1);
1159 return $out;
1160 }
1161
1162 /**
1163 * Renders link records from the tt_links table from page id
1164 * NOTICE: Requires the tt_links extension to be loaded.
1165 *
1166 * @param integer Page id
1167 * @return string HTML for the listing
1168 */
1169 function getTable_tt_guest($id) {
1170
1171 // Define fieldlist to show:
1172 $fList = 'title;cr_name;cr_email,note';
1173 $out = $this->makeOrdinaryList('tt_guest', $id, $fList, 1);
1174 return $out;
1175 }
1176
1177 /**
1178 * Renders news items from the tt_news table from page id
1179 * NOTICE: Requires the tt_news extension to be loaded.
1180 *
1181 * @param integer Page id
1182 * @return string HTML for the listing
1183 */
1184 function getTable_tt_news($id) {
1185
1186 $this->addElement_tdParams = array(
1187 'title' => ' nowrap="nowrap"',
1188 'datetime' => ' nowrap="nowrap"',
1189 'starttime' => ' nowrap="nowrap"',
1190 'author' => ' nowrap="nowrap"'
1191 );
1192 $fList = 'title,author,author_email,datetime,starttime,category,image';
1193 $out = $this->makeOrdinaryList('tt_news', $id, $fList, 1);
1194 $this->addElement_tdParams = array();
1195 return $out;
1196 }
1197
1198 /**
1199 * Renders calender elements link records from the tt_calender table from page id
1200 * NOTICE: Requires the tt_calender extension to be loaded.
1201 *
1202 * @param integer Page id
1203 * @return string HTML for the listing
1204 */
1205 function getTable_tt_calender($id) {
1206
1207 $type = $GLOBALS['SOBE']->MOD_SETTINGS['tt_calender'];
1208 switch ($type) {
1209 case 'date':
1210 // Date default
1211 $fList = 'date,title';
1212 $icon = 0;
1213 $out = $this->makeOrdinaryList('tt_calender', $id, $fList, $icon, ' AND type=0');
1214 return $out;
1215 break;
1216 case 'date_ext':
1217 // Date extended
1218 $fList = 'title;date;time;datetext;link,note';
1219 $icon = 1;
1220 $out = $this->makeOrdinaryList('tt_calender', $id, $fList, $icon, ' AND type=0');
1221 return $out;
1222 break;
1223 case 'todo':
1224 // Todo default
1225 $fList = 'title,complete,priority,date';
1226 $icon = 0;
1227 $out = $this->makeOrdinaryList('tt_calender', $id, $fList, $icon, ' AND type=1');
1228 return $out;
1229 break;
1230 case 'todo_ext':
1231 // Todo extended
1232 $fList = 'title;complete;priority;date;workgroup;responsible;category,note';
1233 $icon = 1;
1234 $out = $this->makeOrdinaryList('tt_calender', $id, $fList, $icon, ' AND type=1');
1235 return $out;
1236 break;
1237 default:
1238 // Overview, both todo and calender
1239 $fList = 'title,date,time,week';
1240 $icon = 1;
1241 $out = $this->makeOrdinaryList('tt_calender', $id, $fList, $icon, ' AND type=0');
1242 $out .= $this->makeOrdinaryList('tt_calender', $id, $fList, $icon, ' AND type=1');
1243 return $out;
1244 break;
1245 }
1246 }
1247
1248 /**
1249 * Renders shopping elements from the tt_products table from page id
1250 * NOTICE: Requires the tt_products extension to be loaded.
1251 *
1252 * @param integer Page id
1253 * @return string HTML for the listing
1254 */
1255 function getTable_tt_products($id) {
1256
1257 $type = $GLOBALS['SOBE']->MOD_SETTINGS['tt_products'];
1258 switch ($type) {
1259 case 'ext':
1260 $fList = 'title;itemnumber;price;price2;inStock;category,image,note';
1261 $icon = 1;
1262 $out = $this->makeOrdinaryList('tt_products', $id, $fList, $icon);
1263 break;
1264 default:
1265 $fList = 'title,itemnumber,price,category,image';
1266 $icon = 1;
1267 $out = $this->makeOrdinaryList('tt_products', $id, $fList, $icon);
1268 break;
1269 }
1270
1271 return $out;
1272 }
1273
1274
1275 /**********************************
1276 *
1277 * Generic listing of items
1278 *
1279 **********************************/
1280
1281 /**
1282 * Creates a standard list of elements from a table.
1283 *
1284 * @param string Table name
1285 * @param integer Page id.
1286 * @param string Comma list of fields to display
1287 * @param boolean If true, icon is shown
1288 * @param string Additional WHERE-clauses.
1289 * @return string HTML table
1290 */
1291 function makeOrdinaryList($table, $id, $fList, $icon = 0, $addWhere = '') {
1292 global $TCA;
1293
1294 // Initialize:
1295 $out = '';
1296 $queryParts = $this->makeQueryArray($table, $id, $addWhere);
1297 $this->setTotalItems($queryParts);
1298 $dbCount = 0;
1299
1300 // Make query for records if there were any records found in the count operation:
1301 if ($this->totalItems) {
1302 $result = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
1303 $dbCount = $GLOBALS['TYPO3_DB']->sql_num_rows($result);
1304 }
1305
1306 // If records were found, render the list:
1307 $out = '';
1308 if ($dbCount) {
1309
1310 // Set fields
1311 $this->fieldArray = t3lib_div::trimExplode(',', '__cmds__,' . $fList, TRUE);
1312
1313 // Header line is drawn
1314 $theData = array();
1315 $theData = $this->headerFields($this->fieldArray, $table, $theData);
1316 if ($this->doEdit) {
1317 $theData['__cmds__'] = '<a href="#" onclick="' . htmlspecialchars(t3lib_BEfunc::editOnClick('&edit[' . $table . '][' . $this->id . ']=new', $this->backPath)) . '" title="' . $GLOBALS['LANG']->getLL('new', TRUE) . '">' .
1318 t3lib_iconWorks::getSpriteIcon('actions-document-new') .
1319 '</a>';
1320 }
1321 $out .= $this->addelement(1, '', $theData, ' class="c-headLine"', 15);
1322
1323 // Render Items
1324 $this->eCounter = $this->firstElementNumber;
1325 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) {
1326 t3lib_BEfunc::workspaceOL($table, $row);
1327
1328 if (is_array($row)) {
1329 list($flag, $code) = $this->fwd_rwd_nav();
1330 $out .= $code;
1331 if ($flag) {
1332 $params = '&edit[' . $table . '][' . $row['uid'] . ']=edit';
1333 $Nrow = array();
1334
1335 // Setting icons/edit links:
1336 if ($icon) {
1337 $Nrow['__cmds__'] = $this->getIcon($table, $row);
1338 }
1339 if ($this->doEdit) {
1340 $Nrow['__cmds__'] .= '<a href="#" onclick="' . htmlspecialchars(t3lib_BEfunc::editOnClick($params, $this->backPath)) . '" title="' . $GLOBALS['LANG']->getLL('edit', TRUE) . '">' .
1341 t3lib_iconWorks::getSpriteIcon('actions-document-open') .
1342 '</a>';
1343 } else {
1344 $Nrow['__cmds__'] .= $this->noEditIcon();
1345 }
1346
1347 // Get values:
1348 $Nrow = $this->dataFields($this->fieldArray, $table, $row, $Nrow);
1349 $tdparams = $this->eCounter % 2 ? ' class="bgColor4"' : ' class="bgColor4-20"';
1350 $out .= $this->addelement(1, '', $Nrow, $tdparams);
1351 }
1352 $this->eCounter++;
1353 }
1354 }
1355
1356 // Wrap it all in a table:
1357 $out = '
1358
1359 <!--
1360 STANDARD LIST OF "' . $table . '"
1361 -->
1362 <table border="0" cellpadding="1" cellspacing="2" width="480" class="typo3-page-stdlist">
1363 ' . $out . '
1364 </table>';
1365 }
1366 return $out;
1367 }
1368
1369 /**
1370 * Adds content to all data fields in $out array
1371 *
1372 * @param array 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.
1373 * @param string Table name
1374 * @param array Record array
1375 * @param array Array to which the data is added
1376 * @return array $out array returned after processing.
1377 * @see makeOrdinaryList()
1378 */
1379 function dataFields($fieldArr, $table, $row, $out = array()) {
1380 global $TCA;
1381
1382 // Check table validity:
1383 if ($TCA[$table]) {
1384 t3lib_div::loadTCA($table);
1385 $thumbsCol = $TCA[$table]['ctrl']['thumbnail'];
1386
1387 // Traverse fields:
1388 foreach ($fieldArr as $fieldName) {
1389
1390 if ($TCA[$table]['columns'][$fieldName]) { // Each field has its own cell (if configured in TCA)
1391 if ($fieldName == $thumbsCol) { // If the column is a thumbnail column:
1392 $out[$fieldName] = $this->thumbCode($row, $table, $fieldName);
1393 } else { // ... otherwise just render the output:
1394 $out[$fieldName] = nl2br(htmlspecialchars(trim(t3lib_div::fixed_lgd_cs(t3lib_BEfunc::getProcessedValue($table, $fieldName, $row[$fieldName], 0, 0, 0, $row['uid']), 250))));
1395 }
1396 } 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)
1397 $theFields = explode(';', $fieldName);
1398
1399 // Traverse fields, separated by ";" (displayed in a single cell).
1400 foreach ($theFields as $fName2) {
1401 if ($TCA[$table]['columns'][$fName2]) {
1402 $out[$fieldName] .= '<strong>' . $GLOBALS['LANG']->sL($TCA[$table]['columns'][$fName2]['label'], 1) . '</strong>' .
1403 '&nbsp;&nbsp;' .
1404 htmlspecialchars(t3lib_div::fixed_lgd_cs(t3lib_BEfunc::getProcessedValue($table, $fName2, $row[$fName2], 0, 0, 0, $row['uid']), 25)) .
1405 '<br />';
1406 }
1407 }
1408 }
1409 // If no value, add a nbsp.
1410 if (!$out[$fieldName]) {
1411 $out[$fieldName] = '&nbsp;';
1412 }
1413
1414 // Wrap in dimmed-span tags if record is "disabled"
1415 if ($this->isDisabled($table, $row)) {
1416 $out[$fieldName] = $GLOBALS['TBE_TEMPLATE']->dfw($out[$fieldName]);
1417 }
1418 }
1419 }
1420 return $out;
1421 }
1422
1423 /**
1424 * Header fields made for the listing of records
1425 *
1426 * @param array Field names
1427 * @param string The table name
1428 * @param array Array to which the headers are added.
1429 * @return array $out returned after addition of the header fields.
1430 * @see makeOrdinaryList()
1431 */
1432 function headerFields($fieldArr, $table, $out = array()) {
1433 global $TCA;
1434
1435 t3lib_div::loadTCA($table);
1436
1437 foreach ($fieldArr as $fieldName) {
1438 $ll = $GLOBALS['LANG']->sL($TCA[$table]['columns'][$fieldName]['label'], 1);
1439 $out[$fieldName] = '<strong>' . ($ll ? $ll : '&nbsp;') . '</strong>';
1440 }
1441 return $out;
1442 }
1443
1444
1445 /**********************************
1446 *
1447 * Additional functions; Pages
1448 *
1449 **********************************/
1450
1451 /**
1452 * Adds pages-rows to an array, selecting recursively in the page tree.
1453 *
1454 * @param array Array which will accumulate page rows
1455 * @param integer Pid to select from
1456 * @param string Query-where clause
1457 * @param string Prefixed icon code.
1458 * @param integer Depth (decreasing)
1459 * @return array $theRows, but with added rows.
1460 */
1461 function pages_getTree($theRows, $pid, $qWhere, $treeIcons, $depth) {
1462 $depth--;
1463 if ($depth >= 0) {
1464 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'pages', 'pid=' . intval($pid) . $qWhere, '', 'sorting');
1465 $c = 0;
1466 $rc = $GLOBALS['TYPO3_DB']->sql_num_rows($res);
1467 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
1468 t3lib_BEfunc::workspaceOL('pages', $row);
1469 if (is_array($row)) {
1470 $c++;
1471 $row['treeIcons'] = $treeIcons . '<img' . t3lib_iconWorks::skinImg($this->backPath, 'gfx/ol/join' . ($rc == $c ? 'bottom' : '') . '.gif', 'width="18" height="16"') . ' alt="" />';
1472 $theRows[] = $row;
1473
1474 // Get the branch
1475 $spaceOutIcons = '<img' . t3lib_iconWorks::skinImg($this->backPath, 'gfx/ol/' . ($rc == $c ? 'blank.gif' : 'line.gif'), 'width="18" height="16"') . ' alt="" />';
1476 $theRows = $this->pages_getTree($theRows, $row['uid'], $qWhere, $treeIcons . $spaceOutIcons, $row['php_tree_stop'] ? 0 : $depth);
1477 }
1478 }
1479 } else {
1480 $count = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('uid', 'pages', 'pid=' . intval($pid) . $qWhere);
1481 if ($count) {
1482 $this->plusPages[$pid] = $count;
1483 }
1484 }
1485 return $theRows;
1486 }
1487
1488 /**
1489 * Adds a list item for the pages-rendering
1490 *
1491 * @param array Record array
1492 * @param array Field list
1493 * @return string HTML for the item
1494 */
1495 function pages_drawItem($row, $fieldArr) {
1496 global $TCA;
1497
1498 // Initialization
1499 $theIcon = $this->getIcon('pages', $row);
1500
1501 // Preparing and getting the data-array
1502 $theData = Array();
1503 foreach ($fieldArr as $field) {
1504 switch ($field) {
1505 case 'title':
1506 $red = $this->plusPages[$row['uid']] ? '<font color="red"><strong>+&nbsp;</strong></font>' : '';
1507 $pTitle = htmlspecialchars(t3lib_BEfunc::getProcessedValue('pages', $field, $row[$field], 20));
1508 if ($red) {
1509 $pTitle = '<a href="' . htmlspecialchars($this->script . '?id=' . $row['uid']) . '">' . $pTitle . '</a>';
1510 }
1511 $theData[$field] = $row['treeIcons'] . $theIcon . $red . $pTitle . '&nbsp;&nbsp;';
1512 break;
1513 case 'php_tree_stop':
1514 case 'TSconfig':
1515 $theData[$field] = $row[$field] ? '&nbsp;<strong>x</strong>' : '&nbsp;';
1516 break;
1517 case 'uid':
1518 if ($GLOBALS['BE_USER']->doesUserHaveAccess($row, 2)) {
1519 $params = '&edit[pages][' . $row['uid'] . ']=edit';
1520 $eI = '<a href="#" onclick="' . htmlspecialchars(t3lib_BEfunc::editOnClick($params, $this->backPath, '')) . '" title="' . $GLOBALS['LANG']->getLL('editThisPage', TRUE) . '">' .
1521 t3lib_iconWorks::getSpriteIcon('actions-document-open') .
1522 '</a>';
1523 } else {
1524 $eI = '';
1525 }
1526 $theData[$field] = '<span align="right">' . $row['uid'] . $eI . '</span>';
1527 break;
1528 default:
1529 if (substr($field, 0, 6) == 'table_') {
1530 $f2 = substr($field, 6);
1531 if ($TCA[$f2]) {
1532 $c = $this->numberOfRecords($f2, $row['uid']);
1533 $theData[$field] = '&nbsp;&nbsp;' . ($c ? $c : '');
1534 }
1535 } elseif (substr($field, 0, 5) == 'HITS_') {
1536 if (t3lib_extMgm::isLoaded('sys_stat')) {
1537 $fParts = explode(':', substr($field, 5));
1538 switch ($fParts[0]) {
1539 case 'days':
1540 $timespan = mktime(0, 0, 0) + intval($fParts[1]) * 3600 * 24;
1541 // Page hits
1542 $number = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows(
1543 '*',
1544 'sys_stat',
1545 $this->stat_select_field . '=' . intval($row['uid']) .
1546 ' AND tstamp >=' . intval($timespan) .
1547 ' AND tstamp <' . intval($timespan + 3600 * 24)
1548 );
1549 if ($number) {
1550 // Sessions
1551 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
1552 'count(*)',
1553 'sys_stat',
1554 $this->stat_select_field . '=' . intval($row['uid']) . '
1555 AND tstamp>=' . intval($timespan) . '
1556 AND tstamp<' . intval($timespan + 3600 * 24) . '
1557 AND surecookie!=""',
1558 'surecookie'
1559 );
1560 $scnumber = $GLOBALS['TYPO3_DB']->sql_num_rows($res);
1561
1562 $number .= '/' . $scnumber;
1563 } else {
1564 $number = '';
1565 }
1566 break;
1567 }
1568 $theData[$field] = '&nbsp;' . $number;
1569 } else {
1570 $theData[$field] = '&nbsp;';
1571 }
1572 } else {
1573 $theData[$field] = '&nbsp;&nbsp;' . htmlspecialchars(t3lib_BEfunc::getProcessedValue('pages', $field, $row[$field]));
1574 }
1575 break;
1576 }
1577 }
1578 $this->addElement_tdParams['title'] = ($row['_CSSCLASS'] ? ' class="' . $row['_CSSCLASS'] . '"' : '');
1579 return $this->addelement(1, '', $theData);
1580 }
1581
1582
1583 /**********************************
1584 *
1585 * Additional functions; Content Elements
1586 *
1587 **********************************/
1588
1589 /**
1590 * Draw header for a content element column:
1591 *
1592 * @param string Column name
1593 * @param string Edit params (Syntax: &edit[...] for alt_doc.php)
1594 * @param string New element params (Syntax: &edit[...] for alt_doc.php)
1595 * @return string HTML table
1596 */
1597 function tt_content_drawColHeader($colName, $editParams, $newParams) {
1598
1599 $icons = '';
1600 // Create command links:
1601 if ($this->tt_contentConfig['showCommands']) {
1602 // New record:
1603 if ($newParams) {
1604 $icons .= '<a href="#" onclick="' . htmlspecialchars($newParams) . '" title="' . $GLOBALS['LANG']->getLL('newInColumn', TRUE) . '">' .
1605 t3lib_iconWorks::getSpriteIcon('actions-document-new') .
1606 '</a>';
1607 }
1608 // Edit whole of column:
1609 if ($editParams) {
1610 $icons .= '<a href="#" onclick="' . htmlspecialchars(t3lib_BEfunc::editOnClick($editParams, $this->backPath)) . '" title="' . $GLOBALS['LANG']->getLL('editColumn', TRUE) . '">' .
1611 t3lib_iconWorks::getSpriteIcon('actions-document-open') .
1612 '</a>';
1613 }
1614 }
1615 if (strlen($icons)) {
1616 $icons = '<div class="t3-page-colHeader-icons">' . $icons . '</div>';
1617 }
1618
1619 // Create header row:
1620 $out = '<div class="t3-page-colHeader t3-row-header">
1621 ' . $icons . '
1622 <div class="t3-page-colHeader-label">' . htmlspecialchars($colName) . '</div>
1623 </div>';
1624 return $out;
1625 }
1626
1627 /**
1628 * Draw the header for a single tt_content element
1629 *
1630 * @param array Record array
1631 * @param integer Amount of pixel space above the header.
1632 * @param boolean If set the buttons for creating new elements and moving up and down are not shown.
1633 * @param boolean If set, we are in language mode and flags will be shown for languages
1634 * @return string HTML table with the record header.
1635 */
1636 function tt_content_drawHeader($row, $space = 0, $disableMoveAndNewButtons = FALSE, $langMode = FALSE) {
1637 global $TCA;
1638
1639 // Load full table description:
1640 t3lib_div::loadTCA('tt_content');
1641
1642 // Get record locking status:
1643 if ($lockInfo = t3lib_BEfunc::isRecordLocked('tt_content', $row['uid'])) {
1644 $lockIcon = '<a href="#" onclick="' . htmlspecialchars('alert(' . $GLOBALS['LANG']->JScharCode($lockInfo['msg']) . ');return false;') . '" title="' . htmlspecialchars($lockInfo['msg']) . '">' .
1645 t3lib_iconWorks::getSpriteIcon('status-warning-in-use') .
1646 '</a>';
1647 } else {
1648 $lockIcon = '';
1649 }
1650
1651 // Call stats information hook
1652 $stat = '';
1653 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['recStatInfoHooks'])) {
1654 $_params = array('tt_content', $row['uid'], &$row);
1655 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['recStatInfoHooks'] as $_funcRef) {
1656 $stat .= t3lib_div::callUserFunction($_funcRef, $_params, $this);
1657 }
1658 }
1659
1660 // Create line with type of content element and icon/lock-icon/title:
1661 $ceType = $this->getIcon('tt_content', $row) . ' ' .
1662 $lockIcon . ' ' .
1663 $stat . ' ' .
1664 ($langMode ? $this->languageFlag($row['sys_language_uid']) : '') . ' ' .
1665 '&nbsp;<strong>' . htmlspecialchars($this->CType_labels[$row['CType']]) . '</strong>';
1666
1667 // If show info is set...;
1668 if ($this->tt_contentConfig['showInfo']) {
1669
1670 // Get processed values:
1671 $info = Array();
1672 $this->getProcessedValue('tt_content', 'hidden,starttime,endtime,fe_group,spaceBefore,spaceAfter', $row, $info);
1673
1674 // Render control panel for the element:
1675 if ($this->tt_contentConfig['showCommands'] && $this->doEdit) {
1676
1677 if (!$disableMoveAndNewButtons) {
1678 // New content element:
1679 if ($this->option_newWizard) {
1680 $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')) . "';";
1681 } else {
1682 $params = '&edit[tt_content][' . (-$row['uid']) . ']=new';
1683 $onClick = t3lib_BEfunc::editOnClick($params, $this->backPath);
1684 }
1685 $out .= '<a href="#" onclick="' . htmlspecialchars($onClick) . '" title="' . $GLOBALS['LANG']->getLL('newAfter', 1) . '">' .
1686 t3lib_iconWorks::getSpriteIcon('actions-document-new') .
1687 '</a>';
1688 }
1689
1690 // Edit content element:
1691 $params = '&edit[tt_content][' . $this->tt_contentData['nextThree'][$row['uid']] . ']=edit';
1692 $out .= '<a href="#" onclick="' . htmlspecialchars(t3lib_BEfunc::editOnClick($params, $this->backPath)) . '" title="' .
1693 htmlspecialchars($this->nextThree > 1 ? sprintf($GLOBALS['LANG']->getLL('nextThree'), $this->nextThree) : $GLOBALS['LANG']->getLL('edit')) . '">' .
1694 t3lib_iconWorks::getSpriteIcon('actions-document-open') .
1695 '</a>';
1696
1697 // Hide element:
1698 $hiddenField = $TCA['tt_content']['ctrl']['enablecolumns']['disabled'];
1699 if ($hiddenField && $TCA['tt_content']['columns'][$hiddenField] && (!$TCA['tt_content']['columns'][$hiddenField]['exclude'] || $GLOBALS['BE_USER']->check('non_exclude_fields', 'tt_content:' . $hiddenField))) {
1700 if ($row[$hiddenField]) {
1701 $params = '&data[tt_content][' . ($row['_ORIG_uid'] ? $row['_ORIG_uid'] : $row['uid']) . '][' . $hiddenField . ']=0';
1702 $out .= '<a href="' . htmlspecialchars($GLOBALS['SOBE']->doc->issueCommand($params)) . '" title="' . $GLOBALS['LANG']->getLL('unHide', TRUE) . '">' .
1703 t3lib_iconWorks::getSpriteIcon('actions-edit-unhide') .
1704 '</a>';
1705 } else {
1706 $params = '&data[tt_content][' . ($row['_ORIG_uid'] ? $row['_ORIG_uid'] : $row['uid']) . '][' . $hiddenField . ']=1';
1707 $out .= '<a href="' . htmlspecialchars($GLOBALS['SOBE']->doc->issueCommand($params)) . '" title="' . $GLOBALS['LANG']->getLL('hide', TRUE) . '">' .
1708 t3lib_iconWorks::getSpriteIcon('actions-edit-hide') .
1709 '</a>';
1710 }
1711 }
1712
1713 // Delete
1714 $params = '&cmd[tt_content][' . $row['uid'] . '][delete]=1';
1715 $confirm = $GLOBALS['LANG']->JScharCode($GLOBALS['LANG']->getLL('deleteWarning') .
1716 t3lib_BEfunc::translationCount('tt_content', $row['uid'], ' ' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.translationsOfRecord')));
1717 $out .= '<a href="' . htmlspecialchars($GLOBALS['SOBE']->doc->issueCommand($params)) . '" onclick="' . htmlspecialchars('return confirm(' . $confirm . ');') . '" title="' . $GLOBALS['LANG']->getLL('deleteItem', TRUE) . '">' .
1718 t3lib_iconWorks::getSpriteIcon('actions-edit-delete') .
1719 '</a>';
1720
1721 if (!$disableMoveAndNewButtons) {
1722 $out .= '<span class="t3-page-ce-icons-move">';
1723 // Move element up:
1724 if ($this->tt_contentData['prev'][$row['uid']]) {
1725 $params = '&cmd[tt_content][' . $row['uid'] . '][move]=' . $this->tt_contentData['prev'][$row['uid']];
1726 $out .= '<a href="' . htmlspecialchars($GLOBALS['SOBE']->doc->issueCommand($params)) . '" title="' . $GLOBALS['LANG']->getLL('moveUp', TRUE) . '">' .
1727 t3lib_iconWorks::getSpriteIcon('actions-move-up') .
1728 '</a>';
1729 } else {
1730 $out .= t3lib_iconWorks::getSpriteIcon('empty-empty');
1731 }
1732 // Move element down:
1733 if ($this->tt_contentData['next'][$row['uid']]) {
1734 $params = '&cmd[tt_content][' . $row['uid'] . '][move]= ' . $this->tt_contentData['next'][$row['uid']];
1735 $out .= '<a href="' . htmlspecialchars($GLOBALS['SOBE']->doc->issueCommand($params)) . '" title="' . $GLOBALS['LANG']->getLL('moveDown', TRUE) . '">' .
1736 t3lib_iconWorks::getSpriteIcon('actions-move-down') .
1737 '</a>';
1738 } else {
1739 $out .= t3lib_iconWorks::getSpriteIcon('empty-empty');
1740 }
1741 $out .= '</span>';
1742 }
1743 }
1744
1745 // Display info from records fields:
1746 $infoOutput = '';
1747 if (count($info)) {
1748 $infoOutput = '<div class="t3-page-ce-info">
1749 ' . implode('<br />', $info) . '
1750 </div>';
1751 }
1752 }
1753 // Wrap the whole header
1754 // NOTE: end-tag for <div class="t3-page-ce-body"> is in getTable_tt_content()
1755 return '<h4 class="t3-page-ce-header">
1756 <div class="t3-row-header">
1757 ' . $out . '
1758 </div>
1759 </h4>
1760 <div class="t3-page-ce-body">
1761 <div class="t3-page-ce-type">
1762 ' . $ceType . '
1763 </div>
1764 ' . $infoOutput;
1765 }
1766
1767 /**
1768 * Draws the preview content for a content element
1769 *
1770 * @param string Content element
1771 * @param boolean Set if the RTE link can be created.
1772 * @return string HTML
1773 */
1774 function tt_content_drawItem($row, $isRTE = FALSE) {
1775 global $TCA;
1776
1777 $out = '';
1778 $outHeader = '';
1779
1780 // Make header:
1781 if ($row['header']) {
1782 $infoArr = Array();
1783 $this->getProcessedValue('tt_content', 'header_position,header_layout,header_link', $row, $infoArr);
1784
1785 // If header layout is set to 'hidden', display an accordant note:
1786 if ($row['header_layout'] == 100) {
1787 $hiddenHeaderNote = ' <em>[' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.hidden', true) . ']</em>';
1788 }
1789 $outHeader = ($row['date'] ? htmlspecialchars($this->itemLabels['date'] . ' ' . t3lib_BEfunc::date($row['date'])) . '<br />' : '') .
1790 '<strong>' . $this->linkEditContent($this->renderText($row['header']), $row) . $hiddenHeaderNote . '</strong><br />';
1791 }
1792
1793 // Make content:
1794 $infoArr = array();
1795 $drawItem = true;
1796
1797 // Hook: Render an own preview of a record
1798 $drawItemHooks =& $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['tt_content_drawItem'];
1799
1800 if (is_array($drawItemHooks)) {
1801 foreach ($drawItemHooks as $hookClass) {
1802 $hookObject = t3lib_div::getUserObj($hookClass);
1803
1804 if (!($hookObject instanceof tx_cms_layout_tt_content_drawItemHook)) {
1805 throw new UnexpectedValueException('$hookObject must implement interface tx_cms_layout_tt_content_drawItemHook', 1218547409);
1806 }
1807
1808 $hookObject->preProcess($this, $drawItem, $outHeader, $out, $row);
1809 }
1810 }
1811
1812 // Draw preview of the item depending on its CType (if not disabled by previous hook):
1813 if ($drawItem) {
1814 switch ($row['CType']) {
1815 case 'header':
1816 if ($row['subheader']) {
1817 $out .= $this->linkEditContent($this->renderText($row['subheader']), $row) . '<br />';
1818 }
1819 break;
1820 case 'text':
1821 case 'textpic':
1822 case 'image':
1823 if ($row['CType'] == 'text' || $row['CType'] == 'textpic') {
1824 if ($row['bodytext']) {
1825 $this->getProcessedValue('tt_content', 'text_align,text_face,text_size,text_color,text_properties', $row, $infoArr);
1826 $out .= $this->linkEditContent($this->renderText($row['bodytext']), $row) . '<br />';
1827 }
1828 }
1829 if ($row['CType'] == 'textpic' || $row['CType'] == 'image') {
1830 if ($row['image']) {
1831 $out .= $this->thumbCode($row, 'tt_content', 'image') . '<br />';
1832 if ($row['imagecaption']) {
1833 $out .= $this->linkEditContent($this->renderText($row['imagecaption']), $row) . '<br />';
1834 }
1835 }
1836 }
1837 break;
1838 case 'bullets':
1839 case 'table':
1840 case 'mailform':
1841 if ($row['bodytext']) {
1842 $out .= $this->linkEditContent($this->renderText($row['bodytext']), $row) . '<br />';
1843 }
1844 break;
1845 case 'uploads':
1846 if ($row['media']) {
1847 $out .= $this->linkEditContent($this->renderText($row['bodytext']), $row) . '<br />';
1848 }
1849 break;
1850 case 'multimedia':
1851 if ($row['multimedia']) {
1852 $out .= $this->renderText($row['multimedia']) . '<br />';
1853 $out .= $this->renderText($row['parameters']) . '<br />';
1854 }
1855 break;
1856 case 'splash':
1857 if ($row['bodytext']) {
1858 $out .= $this->linkEditContent($this->renderText($row['bodytext']), $row) . '<br />';
1859 }
1860 if ($row['image']) {
1861 $out .= $this->thumbCode($row, 'tt_content', 'image') . '<br />';
1862 }
1863 break;
1864 case 'menu':
1865 if ($row['pages']) {
1866 $out .= $this->linkEditContent($row['pages'], $row) . '<br />';
1867 }
1868 break;
1869 case 'shortcut':
1870 if ($row['records']) {
1871 $out .= $this->linkEditContent($row['shortcut'], $row) . '<br />';
1872 }
1873 break;
1874 case 'list':
1875 $out .= $GLOBALS['LANG']->sL(t3lib_BEfunc::getItemLabel('tt_content', 'list_type'), 1) . ' ' .
1876 $GLOBALS['LANG']->sL(t3lib_BEfunc::getLabelFromItemlist('tt_content', 'list_type', $row['list_type']), 1) . '<br />';
1877 $hookArr = array();
1878 $hookOut = '';
1879 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['list_type_Info'][$row['list_type']])) {
1880 $hookArr = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['list_type_Info'][$row['list_type']];
1881 } elseif (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['list_type_Info']['_DEFAULT'])) {
1882 $hookArr = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['list_type_Info']['_DEFAULT'];
1883 }
1884 if (count($hookArr) > 0) {
1885 $_params = array('pObj' => &$this, 'row' => $row, 'infoArr' => $infoArr);
1886 foreach ($hookArr as $_funcRef) {
1887 $hookOut .= t3lib_div::callUserFunction($_funcRef, $_params, $this);
1888 }
1889 }
1890 if (strcmp($hookOut, '')) {
1891 $out .= $hookOut;
1892 } else {
1893 $out .= $GLOBALS['LANG']->sL(t3lib_BEfunc::getItemLabel('tt_content', 'select_key'), 1) . ' ' . $row['select_key'] . '<br />';
1894 }
1895
1896 $out .= $GLOBALS['LANG']->sL(t3lib_BEfunc::getLabelFromItemlist('tt_content', 'pages', $row['pages']), 1) . '<br />';
1897 break;
1898 case 'script':
1899 $out .= $GLOBALS['LANG']->sL(t3lib_BEfunc::getItemLabel('tt_content', 'select_key'), 1) . ' ' . $row['select_key'] . '<br />';
1900 $out .= '<br />' . $this->linkEditContent($this->renderText($row['bodytext']), $row) . '<br />';
1901 $out .= '<br />' . $this->linkEditContent($this->renderText($row['imagecaption']), $row) . '<br />';
1902 break;
1903 default:
1904 if ($row['bodytext']) {
1905 $out .= $this->linkEditContent($this->renderText($row['bodytext']), $row) . '<br />';
1906 }
1907 break;
1908 }
1909 }
1910
1911 // Wrap span-tags:
1912 $out = '
1913 <span class="exampleContent">' . $out . '</span>';
1914 // Add header:
1915 $out = $outHeader . $out;
1916 // Add RTE button:
1917 if ($isRTE) {
1918 $out .= $this->linkRTEbutton($row);
1919 }
1920
1921 // Return values:
1922 if ($this->isDisabled('tt_content', $row)) {
1923 return $GLOBALS['TBE_TEMPLATE']->dfw($out);
1924 } else {
1925 return $out;
1926 }
1927 }
1928
1929 /**
1930 * Filters out all tt_content uids which are already translated so only non-translated uids is left.
1931 * 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 (?)
1932 *
1933 * @param array Numeric array with uids of tt_content elements in the default language
1934 * @param integer Page pid
1935 * @param integer Sys language UID
1936 * @return array Modified $defLanguageCount
1937 */
1938 function getNonTranslatedTTcontentUids($defLanguageCount, $id, $lP) {
1939 if ($lP && count($defLanguageCount)) {
1940
1941 // Select all translations here:
1942 $queryParts = $this->makeQueryArray('tt_content', $id, 'AND sys_language_uid=' . intval($lP) . ' AND l18n_parent IN (' . implode(',', $defLanguageCount) . ')');
1943 $result = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
1944
1945 // Flip uids:
1946 $defLanguageCount = array_flip($defLanguageCount);
1947
1948 // Traverse any selected elements and unset original UID if any:
1949 $rowArr = $this->getResult($result);
1950 foreach ($rowArr as $row) {
1951 unset($defLanguageCount[$row['l18n_parent']]);
1952 }
1953
1954 // Flip again:
1955 $defLanguageCount = array_keys($defLanguageCount);
1956 }
1957
1958 return $defLanguageCount;
1959 }
1960
1961 /**
1962 * Creates button which is used to create copies of records..
1963 *
1964 * @param array Numeric array with uids of tt_content elements in the default language
1965 * @param integer Sys language UID
1966 * @return string "Copy languages" button, if available.
1967 */
1968 function newLanguageButton($defLanguageCount, $lP) {
1969 if ($this->doEdit && count($defLanguageCount) && $lP) {
1970
1971 $params = '';
1972 foreach ($defLanguageCount as $uidVal) {
1973 $params .= '&cmd[tt_content][' . $uidVal . '][localize]=' . $lP;
1974 }
1975
1976 // Copy for language:
1977 $onClick = "window.location.href='" . $GLOBALS['SOBE']->doc->issueCommand($params) . "'; return false;";
1978 $theNewButton = $GLOBALS['SOBE']->doc->t3Button($onClick, $GLOBALS['LANG']->getLL('newPageContent_copyForLang') . ' [' . count($defLanguageCount) . ']');
1979 return $theNewButton;
1980 }
1981 }
1982
1983 /**
1984 * Returns an icon, which has its title attribute set to a massive amount of information about the element.
1985 *
1986 * @param array Array where values are human readable output of field values (not htmlspecialchars()'ed though). The values are imploded by a linebreak.
1987 * @return string HTML img tag if applicable.
1988 * @deprecated since TYPO3 4.4, this function will be removed in TYPO3 4.6
1989 */
1990 function infoGif($infoArr) {
1991 t3lib_div::logDeprecatedFunction();
1992
1993 if (count($infoArr) && $this->tt_contentConfig['showInfo']) {
1994 return t3lib_iconWorks::getSpriteIcon('actions-document-info', array('title' => htmlspecialchars(implode(LF, $infoArr))));
1995 }
1996 }
1997
1998 /**
1999 * Creates onclick-attribute content for a new content element
2000 *
2001 * @param integer Page id where to create the element.
2002 * @param integer Preset: Column position value
2003 * @param integer Preset: Sys langauge value
2004 * @return string String for onclick attribute.
2005 * @see getTable_tt_content()
2006 */
2007 function newContentElementOnClick($id, $colPos, $sys_language) {
2008 if ($this->option_newWizard) {
2009 $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')) . "';";
2010 } else {
2011 $onClick = t3lib_BEfunc::editOnClick('&edit[tt_content][' . $id . ']=new&defVals[tt_content][colPos]=' . $colPos . '&defVals[tt_content][sys_language_uid]=' . $sys_language, $this->backPath);
2012 }
2013 return $onClick;
2014 }
2015
2016 /**
2017 * Will create a link on the input string and possible a big button after the string which links to editing in the RTE
2018 * Used for content element content displayed so the user can click the content / "Edit in Rich Text Editor" button
2019 *
2020 * @param string String to link. Must be prepared for HTML output.
2021 * @param array The row.
2022 * @return string If the whole thing was editable ($this->doEdit) $str is return with link around. Otherwise just $str.
2023 * @see getTable_tt_content()
2024 */
2025 function linkEditContent($str, $row) {
2026 $addButton = '';
2027 $onClick = '';
2028
2029 if ($this->doEdit) {
2030 // Setting onclick action for content link:
2031 $onClick = t3lib_BEfunc::editOnClick('&edit[tt_content][' . $row['uid'] . ']=edit', $this->backPath);
2032 }
2033 // Return link
2034 return $onClick ? '<a href="#" onclick="' . htmlspecialchars($onClick) . '" title="' . $GLOBALS['LANG']->getLL('edit', 1) . '">' . $str . '</a>' . $addButton : $str;
2035 }
2036
2037 /**
2038 * Adds a button to edit the row in RTE wizard
2039 *
2040 * @param array The row of tt_content element
2041 * @return string Button to click if you want to edit in RTE wizard.
2042 */
2043 function linkRTEbutton($row) {
2044 $params = array();
2045 $params['table'] = 'tt_content';
2046 $params['uid'] = $row['uid'];
2047 $params['pid'] = $row['pid'];
2048 $params['field'] = 'bodytext';
2049 $params['returnUrl'] = t3lib_div::linkThisScript();
2050 $RTEonClick = "window.location.href='" . $this->backPath . "wizard_rte.php?" . t3lib_div::implodeArrayForUrl('', array('P' => $params)) . "';return false;";
2051 $addButton = $this->option_showBigButtons && $this->doEdit ? $GLOBALS['SOBE']->doc->t3Button($RTEonClick, $GLOBALS['LANG']->getLL('editInRTE')) : '';
2052
2053 return $addButton;
2054 }
2055
2056 /**
2057 * Make selector box for creating new translation in a language
2058 * Displays only languages which are not yet present for the current page and
2059 * that are not disabled with page TS.
2060 *
2061 * @param integer Page id for which to create a new language (pages_language_overlay record)
2062 * @return string <select> HTML element (if there were items for the box anyways...)
2063 * @see getTable_tt_content()
2064 */
2065 function languageSelector($id) {
2066 if ($GLOBALS['BE_USER']->check('tables_modify', 'pages_language_overlay')) {
2067
2068 // First, select all
2069 $res = $GLOBALS['SOBE']->exec_languageQuery(0);
2070 $langSelItems = array();
2071 $langSelItems[0] = '
2072 <option value="0"></option>';
2073 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
2074 if ($GLOBALS['BE_USER']->checkLanguageAccess($row['uid'])) {
2075 $langSelItems[$row['uid']] = '
2076 <option value="' . $row['uid'] . '">' . htmlspecialchars($row['title']) . '</option>';
2077 }
2078 }
2079
2080 // Then, subtract the languages which are already on the page:
2081 $res = $GLOBALS['SOBE']->exec_languageQuery($id);
2082 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
2083 unset($langSelItems[$row['uid']]);
2084 }
2085 // Remove disallowed languages
2086 if (count($langSelItems) > 1 &&
2087 !$GLOBALS['BE_USER']->user['admin'] &&
2088 strlen($GLOBALS['BE_USER']->groupData['allowed_languages'])) {
2089
2090 $allowed_languages = array_flip(explode(',', $GLOBALS['BE_USER']->groupData['allowed_languages']));
2091
2092 if (count($allowed_languages)) {
2093 foreach ($langSelItems as $key => $value) {
2094 if (!isset($allowed_languages[$key]) && $key != 0) {
2095 unset($langSelItems[$key]);
2096 }
2097 }
2098 }
2099 }
2100 // Remove disabled languages
2101 $modSharedTSconfig = t3lib_BEfunc::getModTSconfig($id, 'mod.SHARED');
2102 $disableLanguages = isset($modSharedTSconfig['properties']['disableLanguages']) ? t3lib_div::trimExplode(',', $modSharedTSconfig['properties']['disableLanguages'], 1) : array();
2103 if (count($langSelItems) && count($disableLanguages)) {
2104 foreach ($disableLanguages as $language) {
2105 if ($language != 0 && isset($langSelItems[$language])) {
2106 unset($langSelItems[$language]);
2107 }
2108 }
2109 }
2110
2111 // If any languages are left, make selector:
2112 if (count($langSelItems) > 1) {
2113 $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')) . '\'';
2114 return $GLOBALS['LANG']->getLL('new_language', 1) . ': <select name="createNewLanguage" onchange="' . htmlspecialchars($onChangeContent) . '">
2115 ' . implode('', $langSelItems) . '
2116 </select><br /><br />';
2117 }
2118 }
2119 }
2120
2121 /**
2122 * Traverse the result pointer given, adding each record to array and setting some internal values at the same time.
2123 *
2124 * @param pointer SQL result pointer for select query.
2125 * @param string Table name defaulting to tt_content
2126 * @return array The selected rows returned in this array.
2127 */
2128 function getResult($result, $table = 'tt_content') {
2129
2130 // Initialize:
2131 $editUidList = '';
2132 $recs = Array();
2133 $nextTree = $this->nextThree;
2134 $c = 0;
2135 $output = Array();
2136
2137 // Traverse the result:
2138 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) {
2139
2140 t3lib_BEfunc::workspaceOL($table, $row, -99, TRUE);
2141
2142 if ($row) {
2143 // Add the row to the array:
2144 $output[] = $row;
2145
2146 // Set an internal register:
2147 $recs[$c] = $row['uid'];
2148
2149 // Create the list of the next three ids (for editing links...)
2150 for ($a = 0; $a < $nextTree; $a++) {
2151 if (isset($recs[$c - $a])) {
2152 $this->tt_contentData['nextThree'][$recs[$c - $a]] .= $row['uid'] . ',';
2153 }
2154 }
2155
2156 // Set next/previous ids:
2157 if (isset($recs[$c - 1])) {
2158 if (isset($recs[$c - 2])) {
2159 $this->tt_contentData['prev'][$row['uid']] = -$recs[$c - 2];
2160 } else {
2161 $this->tt_contentData['prev'][$row['uid']] = $row['pid'];
2162 }
2163 $this->tt_contentData['next'][$recs[$c - 1]] = -$row['uid'];
2164 }
2165 $c++;
2166 }
2167 }
2168
2169 // Return selected records
2170 return $output;
2171 }
2172
2173
2174 /**********************************
2175 *
2176 * Additional functions; Message board items (tt_board)
2177 *
2178 **********************************/
2179
2180 /**
2181 * Traverses recursively a branch in a message board.
2182 *
2183 * @param array Array of rows (build up recursively)
2184 * @param integer tt_content parent uid
2185 * @param integer Page id
2186 * @param string Additional query part.
2187 * @param string HTML content to prefix items with (to draw the proper tree-graphics)
2188 * @return array $theRows, but with added content
2189 */
2190 function tt_board_getTree($theRows, $parent, $pid, $qWhere, $treeIcons) {
2191
2192 // Select tt_board elements:
2193 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'tt_board', 'pid=' . intval($pid) . ' AND parent=' . intval($parent) . $qWhere, '', 'crdate');
2194
2195 // Traverse the results:
2196 $c = 0;
2197 $rc = $GLOBALS['TYPO3_DB']->sql_num_rows($res);
2198 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
2199 $c++;
2200 $row['treeIcons'] = $treeIcons . '<img' . t3lib_iconWorks::skinImg($this->backPath, 'gfx/ol/' . ($rc == $c ? 'joinbottom.gif' : 'join.gif'), 'width="18" height="16"') . ' alt="" />';
2201 $theRows[] = $row;
2202
2203 // Get the branch
2204 $theRows = $this->tt_board_getTree(
2205 $theRows,
2206 $row['uid'],
2207 $row['pid'],
2208 $qWhere,
2209 $treeIcons . '<img' . t3lib_iconWorks::skinImg($this->backPath, 'gfx/ol/' . ($rc == $c ? 'blank.gif' : 'line.gif'), 'width="18" height="16"') . ' alt="" />'
2210 );
2211 }
2212
2213 // Return modified rows:
2214 return $theRows;
2215 }
2216
2217 /**
2218 * Adds an element to the tt_board listing:
2219 *
2220 * @param string Table name
2221 * @param array The record row
2222 * @param string Reply count, if applicable.
2223 * @return string Return content of element (table row)
2224 */
2225 function tt_board_drawItem($table, $row, $re) {
2226
2227 // Building data-arary with content:
2228 $theData = Array();
2229 $theData['subject'] = t3lib_div::fixed_lgd_cs(htmlspecialchars($row['subject']), 25) . '&nbsp; &nbsp;';
2230 $theData['author'] = t3lib_div::fixed_lgd_cs(htmlspecialchars($row['author']), 15) . '&nbsp; &nbsp;';
2231 $theData['date'] = t3lib_div::fixed_lgd_cs(t3lib_BEfunc::datetime($row['crdate']), 20) . '&nbsp; &nbsp;';
2232 $theData['age'] = t3lib_BEfunc::calcAge($GLOBALS['EXEC_TIME'] - $row['crdate'], $this->agePrefixes) . '&nbsp; &nbsp;';
2233 if ($re) {
2234 $theData['replys'] = $re;
2235 }
2236
2237 // Subject is built:
2238 $theData['subject'] =
2239 $row['treeIcons'] .
2240 $this->getIcon($table, $row) .
2241 $theData['subject'];
2242
2243 // Adding element:
2244 return $this->addelement(1, '', $theData);
2245 }
2246
2247
2248 /********************************
2249 *
2250 * Various helper functions
2251 *
2252 ********************************/
2253
2254 /**
2255 * Counts and returns the number of records on the page with $pid
2256 *
2257 * @param string Table name
2258 * @param integer Page id
2259 * @return integer Number of records.
2260 */
2261 function numberOfRecords($table, $pid) {
2262 if ($GLOBALS['TCA'][$table]) {
2263 $count = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows(
2264 'uid',
2265 $table,
2266 'pid=' . intval($pid) .
2267 t3lib_BEfunc::deleteClause($table) .
2268 t3lib_BEfunc::versioningPlaceholderClause($table)
2269 );
2270 }
2271 return intval($count);
2272 }
2273
2274 /**
2275 * Processing of larger amounts of text (usually from RTE/bodytext fields) with word wrapping etc.
2276 *
2277 * @param string Input string
2278 * @return string Output string
2279 */
2280 function renderText($input) {
2281 $input = $this->strip_tags($input, true);
2282 $input = t3lib_div::fixed_lgd_cs($input, 1500);
2283 return nl2br(htmlspecialchars(trim($this->wordWrapper($input))));
2284 }
2285
2286 /**
2287 * Creates the icon image tag for record from table and wraps it in a link which will trigger the click menu.
2288 *
2289 * @param string Table name
2290 * @param array Record array
2291 * @param string Record title (NOT USED)
2292 * @return string HTML for the icon
2293 */
2294 function getIcon($table, $row) {
2295
2296 // Initialization
2297 $alttext = t3lib_BEfunc::getRecordIconAltText($row, $table);
2298 $iconImg = t3lib_iconWorks::getSpriteIconForRecord($table, $row, array('title' => $alttext));
2299 $this->counter++;
2300
2301 // The icon with link
2302 $theIcon = $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($iconImg, $table, $row['uid']);
2303
2304 return $theIcon;
2305 }
2306
2307 /**
2308 * Creates processed values for all fieldnames in $fieldList based on values from $row array.
2309 * The result is 'returned' through $info which is passed as a reference
2310 *
2311 * @param string Table name
2312 * @param string Commalist of fields.
2313 * @param array Record from which to take values for processing.
2314 * @param array Array to which the processed values are added.
2315 * @return void
2316 */
2317 function getProcessedValue($table, $fieldList, $row, &$info) {
2318
2319 // Splitting values from $fieldList:
2320 $fieldArr = explode(',', $fieldList);
2321
2322 // Traverse fields from $fieldList:
2323 foreach ($fieldArr as $field) {
2324 if ($row[$field]) {
2325 $info[] = htmlspecialchars($this->itemLabels[$field]) . ' ' . htmlspecialchars(t3lib_BEfunc::getProcessedValue($table, $field, $row[$field]));
2326 }
2327 }
2328 }
2329
2330 /**
2331 * Returns true, if the record given as parameters is NOT visible based on hidden/starttime/endtime (if available)
2332 *
2333 * @param string Tablename of table to test
2334 * @param array Record row.
2335 * @return boolean Returns true, if disabled.
2336 */
2337 function isDisabled($table, $row) {
2338 global $TCA;
2339 if (
2340 ($TCA[$table]['ctrl']['enablecolumns']['disabled'] && $row[$TCA[$table]['ctrl']['enablecolumns']['disabled']]) ||
2341 ($TCA[$table]['ctrl']['enablecolumns']['starttime'] && $row[$TCA[$table]['ctrl']['enablecolumns']['starttime']] > $GLOBALS['EXEC_TIME']) ||
2342 ($TCA[$table]['ctrl']['enablecolumns']['endtime'] && $row[$TCA[$table]['ctrl']['enablecolumns']['endtime']] && $row[$TCA[$table]['ctrl']['enablecolumns']['endtime']] < $GLOBALS['EXEC_TIME'])
2343 ) {
2344 return true;
2345 }
2346 }
2347
2348 /**
2349 * 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.
2350 * Works well on normal texts, little less well when HTML is involved (since much HTML will have long strings that will be broken).
2351 *
2352 * @param string Content to word-wrap.
2353 * @param integer Max number of chars in a word before it will be wrapped.
2354 * @param string Character to insert when wrapping.
2355 * @return string Processed output.
2356 */
2357 function wordWrapper($content, $max = 50, $char = ' -') {
2358 $array = preg_split('/[ ' . LF . ']/', $content);
2359 foreach ($array as $val) {
2360 if (strlen($val) > $max) {
2361 $content = str_replace($val, substr(chunk_split($val, $max, $char), 0, -1), $content);
2362 }
2363 }
2364 return $content;
2365 }
2366
2367 /**
2368 * Returns icon for "no-edit" of a record.
2369 * 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...
2370 *
2371 * @param string Label key from LOCAL_LANG
2372 * @return string IMG tag for icon.
2373 */
2374 function noEditIcon($label = 'noEditItems') {
2375 return t3lib_iconWorks::getSpriteIcon('status-edit-read-only', array('title' => $GLOBALS['LANG']->getLL($label, TRUE)));
2376 }
2377
2378 /**
2379 * 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.
2380 *
2381 * @return void
2382 */
2383 function cleanTableNames() {
2384 global $TCA;
2385
2386 // Get all table names:
2387 $tableNames = array_flip(array_keys($TCA));
2388
2389 // Unset common names:
2390 unset($tableNames['pages']);
2391 unset($tableNames['static_template']);
2392 unset($tableNames['sys_filemounts']);
2393 unset($tableNames['sys_action']);
2394 unset($tableNames['sys_workflows']);
2395 unset($tableNames['be_users']);
2396 unset($tableNames['be_groups']);
2397
2398 $this->allowedTableNames = array();
2399
2400 // Traverse table names and set them in allowedTableNames array IF they can be read-accessed by the user.
2401 if (is_array($tableNames)) {
2402 foreach ($tableNames as $k => $v) {
2403 if ($GLOBALS['BE_USER']->check('tables_select', $k)) {
2404 $this->allowedTableNames['table_' . $k] = $k;
2405 }
2406 }
2407 }
2408 }
2409
2410 /**
2411 * Checking if the RTE is available/enabled for a certain table/field and if so, it returns true.
2412 * Used to determine if the RTE button should be displayed.
2413 *
2414 * @param string Table name
2415 * @param array Record row (needed, if there are RTE dependencies based on other fields in the record)
2416 * @param string Field name
2417 * @return boolean Returns true if the rich text editor would be enabled/available for the field name specified.
2418 */
2419 function isRTEforField($table, $row, $field) {
2420 $specConf = $this->getSpecConfForField($table, $row, $field);
2421 $p = t3lib_BEfunc::getSpecConfParametersFromArray($specConf['rte_transform']['parameters']);
2422 if (isset($specConf['richtext']) && (!$p['flag'] || !$row[$p['flag']])) {
2423 t3lib_BEfunc::fixVersioningPid($table, $row);
2424 list($tscPID, $thePidValue) = t3lib_BEfunc::getTSCpid($table, $row['uid'], $row['pid']);
2425 if ($thePidValue >= 0) { // If the pid-value is not negative (that is, a pid could NOT be fetched)
2426 $RTEsetup = $GLOBALS['BE_USER']->getTSConfig('RTE', t3lib_BEfunc::getPagesTSconfig($tscPID));
2427 $RTEtypeVal = t3lib_BEfunc::getTCAtypeValue($table, $row);
2428 $thisConfig = t3lib_BEfunc::RTEsetup($RTEsetup['properties'], $table, $field, $RTEtypeVal);
2429 if (!$thisConfig['disabled']) {
2430 return TRUE;
2431 }
2432 }
2433 }
2434
2435 return FALSE;
2436 }
2437
2438 /**
2439 * Returns "special" configuration from the "types" configuration in TCA for the record given by tablename/fieldname.
2440 * Used by isRTEforField() in the process of finding whether a field has RTE enabled or not.
2441 *
2442 * @param string Table name
2443 * @param array Record array
2444 * @param string Field name
2445 * @return array Spec. conf (if available)
2446 * @access private
2447 * @see isRTEforField()
2448 */
2449 function getSpecConfForField($table, $row, $field) {
2450
2451 // Get types-configuration for the record:
2452 $types_fieldConfig = t3lib_BEfunc::getTCAtypes($table, $row);
2453
2454 // Find the given field and return the spec key value if found:
2455 if (is_array($types_fieldConfig)) {
2456 foreach ($types_fieldConfig as $vconf) {
2457 if ($vconf['field'] == $field) {
2458 return $vconf['spec'];
2459 }
2460 }
2461 }
2462 }
2463
2464
2465 /*****************************************
2466 *
2467 * External renderings
2468 *
2469 *****************************************/
2470
2471 /**
2472 * Creates an info-box for the current page (identified by input record).
2473 *
2474 * @param array Page record
2475 * @param boolean If set, there will be shown an edit icon, linking to editing of the page properties.
2476 * @return string HTML for the box.
2477 */
2478 function getPageInfoBox($rec, $edit = 0) {
2479 global $LANG;
2480
2481 // If editing of the page properties is allowed:
2482 if ($edit) {
2483 $params = '&edit[pages][' . $rec['uid'] . ']=edit';
2484 $editIcon = '<a href="#" onclick="' . htmlspecialchars(t3lib_BEfunc::editOnClick($params, $this->backPath)) . '" title="' . $GLOBALS['LANG']->getLL('edit', TRUE) . '">' .
2485 t3lib_iconWorks::getSpriteIcon('actions-document-open') .
2486 '</a>';
2487 } else {
2488 $editIcon = $this->noEditIcon('noEditPage');
2489 }
2490
2491 // Setting page icon, link, title:
2492 $outPutContent = t3lib_iconWorks::getSpriteIconForRecord('pages', $rec, array('title' => t3lib_BEfunc::titleAttribForPages($rec))) .
2493 $editIcon .
2494 '&nbsp;' .
2495 htmlspecialchars($rec['title']);
2496
2497
2498 // Init array where infomation is accumulated as label/value pairs.
2499 $lines = array();
2500
2501 // Owner user/group:
2502 if ($this->pI_showUser) {
2503 // User:
2504 $users = t3lib_BEfunc::getUserNames('username,usergroup,usergroup_cached_list,uid,realName');
2505 $groupArray = explode(',', $GLOBALS['BE_USER']->user['usergroup_cached_list']);
2506 $users = t3lib_BEfunc::blindUserNames($users, $groupArray);
2507 $lines[] = array($LANG->getLL('pI_crUser') . ':', htmlspecialchars($users[$rec['cruser_id']]['username']) . ' (' . $users[$rec['cruser_id']]['realName'] . ')');
2508 }
2509
2510 // Created:
2511 $lines[] = array(
2512 $LANG->getLL('pI_crDate') . ':',
2513 t3lib_BEfunc::datetime($rec['crdate']) . ' (' . t3lib_BEfunc::calcAge($GLOBALS['EXEC_TIME'] - $rec['crdate'], $this->agePrefixes) . ')',
2514 );
2515
2516 // Last change:
2517 $lines[] = array(
2518 $LANG->getLL('pI_lastChange') . ':',
2519 t3lib_BEfunc::datetime($rec['tstamp']) . ' (' . t3lib_BEfunc::calcAge($GLOBALS['EXEC_TIME'] - $rec['tstamp'], $this->agePrefixes) . ')',
2520 );
2521
2522 // Last change of content:
2523 if ($rec['SYS_LASTCHANGED']) {
2524 $lines[] = array(
2525 $LANG->getLL('pI_lastChangeContent') . ':',
2526 t3lib_BEfunc::datetime($rec['SYS_LASTCHANGED']) . ' (' . t3lib_BEfunc::calcAge($GLOBALS['EXEC_TIME'] - $rec['SYS_LASTCHANGED'], $this->agePrefixes) . ')',
2527 );
2528 }
2529
2530 // Spacer:
2531 $lines[] = '';
2532
2533 // Display contents of certain page fields, if any value:
2534 $dfields = explode(',', 'alias,target,hidden,starttime,endtime,fe_group,no_cache,cache_timeout,newUntil,lastUpdated,subtitle,keywords,description,abstract,author,author_email');
2535 foreach ($dfields as $fV) {
2536 if ($rec[$fV]) {
2537 $lines[] = array($GLOBALS['LANG']->sL(t3lib_BEfunc::getItemLabel('pages', $fV)), t3lib_BEfunc::getProcessedValue('pages', $fV, $rec[$fV]));
2538 }
2539 }
2540
2541 // Page hits (depends on "sys_stat" extension)
2542 if ($this->pI_showStat && t3lib_extMgm::isLoaded('sys_stat')) {
2543
2544 // Counting total hits:
2545 $count = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'sys_stat', 'page_id=' . intval($rec['uid']));
2546 if ($count) {
2547
2548 // Get min/max
2549 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('min(tstamp) AS min,max(tstamp) AS max', 'sys_stat', 'page_id=' . intval($rec['uid']));
2550 $rrow2 = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
2551
2552 $lines[] = '';
2553 $lines[] = array($LANG->getLL('pI_hitsPeriod') . ':', t3lib_BEfunc::date($rrow2[0]) . ' - ' . t3lib_BEfunc::date($rrow2[1]) . ' (' . t3lib_BEfunc::calcAge($rrow2[1] - $rrow2[0], $this->agePrefixes) . ')');
2554 $lines[] = array($LANG->getLL('pI_hitsTotal') . ':', $rrow2[0]);
2555
2556
2557 // Last 10 days
2558 $nextMidNight = mktime(0, 0, 0) + 1 * 3600 * 24;
2559
2560 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('count(*), FLOOR((' . $nextMidNight . '-tstamp)/(24*3600)) AS day', 'sys_stat', 'page_id=' . intval($rec['uid']) . ' AND tstamp>' . ($nextMidNight - 10 * 24 * 3600), 'day');
2561 $days = array();
2562 while ($rrow = $GLOBALS['TYPO3_DB']->sql_fetch_row($res)) {
2563 $days[$rrow[1]] = $rrow[0];
2564 }
2565
2566 $headerH = array();
2567 $contentH = array();
2568 for ($a = 9; $a >= 0; $a--) {
2569 $headerH[] = '
2570 <td class="bgColor5" nowrap="nowrap">&nbsp;' . date('d', $nextMidNight - ($a + 1) * 24 * 3600) . '&nbsp;</td>';
2571 $contentH[] = '
2572 <td align="center">' . ($days[$a] ? intval($days[$a]) : '-') . '</td>';
2573 }
2574
2575 // Compile first hit-table (last 10 days)
2576 $hitTable = '
2577 <table border="0" cellpadding="0" cellspacing="1" class="typo3-page-hits">
2578 <tr>' . implode('', $headerH) . '</tr>
2579 <tr>' . implode('', $contentH) . '</tr>
2580 </table>';
2581 $lines[] = array($LANG->getLL('pI_hits10days') . ':', $hitTable, 1);
2582
2583
2584 // Last 24 hours
2585 $nextHour = mktime(date('H'), 0, 0) + 3600;
2586 $hours = 16;
2587
2588 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('count(*), FLOOR((' . $nextHour . '-tstamp)/3600) AS hours', 'sys_stat', 'page_id=' . intval($rec['uid']) . ' AND tstamp>' . ($nextHour - $hours * 3600), 'hours');
2589 $days = array();
2590 while ($rrow = $GLOBALS['TYPO3_DB']->sql_fetch_row($res)) {
2591 $days[$rrow[1]] = $rrow[0];
2592 }
2593
2594 $headerH = array();
2595 $contentH = array();
2596 for ($a = ($hours - 1); $a >= 0; $a--) {
2597 $headerH[] = '
2598 <td class="bgColor5" nowrap="nowrap">&nbsp;' . intval(date('H', $nextHour - ($a + 1) * 3600)) . '&nbsp;</td>';
2599 $contentH[] = '
2600 <td align="center">' . ($days[$a] ? intval($days[$a]) : '-') . '</td>';
2601 }
2602
2603 // Compile second hit-table (last 24 hours)
2604 $hitTable = '
2605 <table border="0" cellpadding="0" cellspacing="1" class="typo3-page-stat">
2606 <tr>' . implode('', $headerH) . '</tr>
2607 <tr>' . implode('', $contentH) . '</tr>
2608 </table>';
2609 $lines[] = array($LANG->getLL('pI_hits24hours') . ':', $hitTable, 1);
2610 }
2611 }
2612
2613
2614 // Finally, wrap the elements in the $lines array in table cells/rows
2615 foreach ($lines as $fV) {
2616 if (is_array($fV)) {
2617 if (!$fV[2]) {
2618 $fV[1] = htmlspecialchars($fV[1]);
2619 }
2620 $out .= '
2621 <tr>
2622 <td class="bgColor4" nowrap="nowrap"><strong>' . htmlspecialchars($fV[0]) . '&nbsp;&nbsp;</strong></td>
2623 <td class="bgColor4">' . $fV[1] . '</td>
2624 </tr>';
2625 } else {
2626 $out .= '
2627 <tr>
2628 <td colspan="2"><img src="clear.gif" width="1" height="3" alt="" /></td>
2629 </tr>';
2630 }
2631 }
2632
2633 // Wrap table tags around...
2634 $outPutContent .= '
2635
2636
2637
2638 <!--
2639 Page info box:
2640 -->
2641 <table border="0" cellpadding="0" cellspacing="1" id="typo3-page-info">
2642 ' . $out . '
2643 </table>';
2644
2645 // ... and return it.
2646 return $outPutContent;
2647 }
2648
2649 /**
2650 * Creates a menu of the tables that can be listed by this function
2651 * Only tables which has records on the page will be included.
2652 * Notice: The function also fills in the internal variable $this->activeTables with icon/titles.
2653 *
2654 * @param integer Page id from which we are listing records (the function will look up if there are records on the page)
2655 * @return string HTML output.
2656 */
2657 function getTableMenu($id) {
2658 global $TCA;
2659
2660 // Initialize:
2661 $this->activeTables = array();
2662 $theTables = explode(',', 'tt_content,fe_users,tt_address,tt_links,tt_board,tt_guest,tt_calender,tt_products,tt_news'); // NOTICE: This serves double function: Both being tables names (all) and for most others also being extension keys for the extensions they are related to!
2663
2664 // External tables:
2665 if (is_array($this->externalTables)) {
2666 $theTables = array_unique(array_merge($theTables, array_keys($this->externalTables)));
2667 }
2668
2669 // Traverse tables to check:
2670 foreach ($theTables as $tName) {
2671
2672 // Check access and whether the proper extensions are loaded:
2673 if ($GLOBALS['BE_USER']->check('tables_select', $tName) && (t3lib_extMgm::isLoaded($tName) || t3lib_div::inList('fe_users,tt_content', $tName) || isset($this->externalTables[$tName]))) {
2674
2675 // Make query to count records from page:
2676 $c = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows(
2677 'uid',
2678 $tName,
2679 'pid=' . intval($id) .
2680 t3lib_BEfunc::deleteClause($tName) .
2681 t3lib_BEfunc::versioningPlaceholderClause($tName)
2682 );
2683
2684 // If records were found (or if "tt_content" is the table...):
2685 if ($c || t3lib_div::inList('tt_content', $tName)) {
2686
2687 // Add row to menu:
2688 $out .= '
2689 <td><a href="#' . $tName . '"></a>' .
2690 t3lib_iconWorks::getSpriteIconForRecord($tName, Array(), array('title' => $GLOBALS['LANG']->sL($TCA[$tName]['ctrl']['title'], 1))) .
2691 '</td>';
2692
2693 // ... and to the internal array, activeTables we also add table icon and title (for use elsewhere)
2694 $this->activeTables[$tName] =
2695 t3lib_iconWorks::getSpriteIconForRecord($tName, Array(), array('title' => $GLOBALS['LANG']->sL($TCA[$tName]['ctrl']['title'], 1) . ': ' . $c . ' ' . $GLOBALS['LANG']->getLL('records',