[FEATURE] Allow .ts file extension for static typoscript templates
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_recordlist.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 /**
28 * Library with a single function addElement that returns table
29 * rows based on some input.
30 *
31 * Base for class listing of database records and files in the
32 * modules Web>List and File>Filelist
33 *
34 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
35 * @package TYPO3
36 * @subpackage t3lib
37 * @see typo3/db_list.php
38 * @see typo3/sysext/filelist/mod1/index.php
39 */
40 abstract class t3lib_recordList {
41
42 // Used in this class:
43 // default Max items shown
44 var $iLimit = 10;
45 // OBSOLETE - NOT USED ANYMORE. leftMargin
46 var $leftMargin = 0;
47 var $showIcon = 1;
48 var $no_noWrap = 0;
49 // If set this is <td> CSS-classname for odd columns in addElement. Used with db_layout / pages section
50 var $oddColumnsCssClass = '';
51 var $backPath = '';
52 // Decides the columns shown. Filled with values that refers to the keys of the data-array. $this->fieldArray[0] is the title column.
53 var $fieldArray = array();
54 // Keys are fieldnames and values are td-parameters to add in addElement(), please use $addElement_tdCSSClass for CSS-classes;
55 var $addElement_tdParams = array();
56 // Keys are fieldnames and values are td-css-classes to add in addElement();
57 var $addElement_tdCssClass = array();
58
59 // Not used in this class - but maybe extension classes...
60 // Max length of strings
61 var $fixedL = 30;
62 var $script = '';
63 // Set to zero, if you don't want a left-margin with addElement function
64 var $setLMargin = 1;
65
66 // Counter increased for each element. Used to index elements for the JavaScript-code that transfers to the clipboard
67 var $counter = 0;
68 // This could be set to the total number of items. Used by the fwd_rew_navigation...
69 var $totalItems = '';
70
71 // Internal (used in this class.)
72 var $firstElementNumber = 0;
73 var $eCounter = 0;
74 // String with accumulated HTML content
75 var $HTMLcode = '';
76
77 // Contains page translation languages
78 var $pageOverlays = array();
79 // Contains sys language icons and titles
80 var $languageIconTitles = array();
81 // TranslateTools object
82 var $translateTools;
83
84 /**
85 * Constructor for t3lib_recordList
86 */
87 public function __construct() {
88 if (isset($GLOBALS['BE_USER']->uc['titleLen']) && $GLOBALS['BE_USER']->uc['titleLen'] > 0) {
89 $this->fixedL = $GLOBALS['BE_USER']->uc['titleLen'];
90 }
91 $this->getTranslateTools();
92 }
93
94
95 /**
96 * Returns a table-row with the content from the fields in the input data array.
97 * OBS: $this->fieldArray MUST be set! (represents the list of fields to display)
98 *
99 * @param integer $h Is an integer >=0 and denotes how tall a element is. Set to '0' makes a halv line, -1 = full line, set to 1 makes a 'join' and above makes 'line'
100 * @param string $icon Is the <img>+<a> of the record. If not supplied the first 'join'-icon will be a 'line' instead
101 * @param array $data Is the dataarray, record with the fields. Notice: These fields are (currently) NOT htmlspecialchar'ed before being wrapped in <td>-tags
102 * @param string $tdParams Is insert in the <td>-tags. Must carry a ' ' as first character
103 * @param integer OBSOLETE - NOT USED ANYMORE. $lMargin is the leftMargin (integer)
104 * @param string $altLine Is the HTML <img>-tag for an alternative 'gfx/ol/line.gif'-icon (used in the top)
105 * @return string HTML content for the table row
106 */
107 function addElement($h, $icon, $data, $trParams = '', $lMargin = '', $altLine = '') {
108 $noWrap = ($this->no_noWrap) ? '' : ' nowrap="nowrap"';
109
110 // Start up:
111 $out = '
112 <!-- Element, begin: -->
113 <tr ' . $trParams . '>';
114 // Show icon and lines
115 if ($this->showIcon) {
116 $out .= '
117 <td nowrap="nowrap" class="col-icon">';
118
119 if (!$h) {
120 $out .= '<img src="clear.gif" width="1" height="8" alt="" />';
121 } else {
122 for ($a = 0; $a < $h; $a++) {
123 if (!$a) {
124 if ($icon) {
125 $out .= $icon;
126 }
127 } else {
128 }
129 }
130 }
131 $out .= '</td>
132 ';
133 }
134
135 // Init rendering.
136 $colsp = '';
137 $lastKey = '';
138 $c = 0;
139 $ccount = 0;
140
141 // Traverse field array which contains the data to present:
142 foreach ($this->fieldArray as $vKey) {
143 if (isset($data[$vKey])) {
144 if ($lastKey) {
145 $cssClass = $this->addElement_tdCssClass[$lastKey];
146 if ($this->oddColumnsCssClass && $ccount % 2 == 0) {
147 $cssClass = implode(' ', array($this->addElement_tdCssClass[$lastKey], $this->oddColumnsCssClass));
148 }
149
150 $out .= '
151 <td' .
152 $noWrap .
153 ' class="' . $cssClass . '"' .
154 $colsp .
155 $this->addElement_tdParams[$lastKey] .
156 '>' . $data[$lastKey] . '</td>';
157 }
158 $lastKey = $vKey;
159 $c = 1;
160 $ccount++;
161 } else {
162 if (!$lastKey) {
163 $lastKey = $vKey;
164 }
165 $c++;
166 }
167 if ($c > 1) {
168 $colsp = ' colspan="' . $c . '"';
169 } else {
170 $colsp = '';
171 }
172 }
173 if ($lastKey) {
174 $cssClass = $this->addElement_tdCssClass[$lastKey];
175 if ($this->oddColumnsCssClass) {
176 $cssClass = implode(' ', array($this->addElement_tdCssClass[$lastKey], $this->oddColumnsCssClass));
177 }
178
179 $out .= '
180 <td' . $noWrap . ' class="' . $cssClass . '"' . $colsp . $this->addElement_tdParams[$lastKey] . '>' . $data[$lastKey] . '</td>';
181 }
182
183 // End row
184 $out .= '
185 </tr>';
186
187 // Return row.
188 return $out;
189 }
190
191 /**
192 * Dummy function, used to write the top of a table listing.
193 *
194 * @return void
195 */
196 function writeTop() {
197 }
198
199 /**
200 * Finishes the list with the "stopper"-gif, adding the HTML code for that item to the internal ->HTMLcode string
201 *
202 * @return void
203 */
204 function writeBottom() {
205 $this->HTMLcode .= '
206
207 <!--
208 End of list table:
209 -->
210 <table border="0" cellpadding="0" cellspacing="0">';
211 $theIcon = '<img' . t3lib_iconWorks::skinImg($this->backPath, 'gfx/ol/stopper.gif', 'width="18" height="16"') . ' alt="" />';
212 $this->HTMLcode .= $this->addElement(1, '', array(), '', $this->leftMargin, $theIcon);
213 $this->HTMLcode .= '
214 </table>';
215 }
216
217 /**
218 * Creates a forward/reverse button based on the status of ->eCounter, ->firstElementNumber, ->iLimit
219 *
220 * @param string $table Table name
221 * @return array array([boolean], [HTML]) where [boolean] is 1 for reverse element, [HTML] is the table-row code for the element
222 */
223 function fwd_rwd_nav($table = '') {
224 $code = '';
225 if ($this->eCounter >= $this->firstElementNumber && $this->eCounter < $this->firstElementNumber + $this->iLimit) {
226 if ($this->firstElementNumber && $this->eCounter == $this->firstElementNumber) {
227 // Reverse
228 $theData = Array();
229 $titleCol = $this->fieldArray[0];
230 $theData[$titleCol] = $this->fwd_rwd_HTML('fwd', $this->eCounter, $table);
231 $code = $this->addElement(1, '', $theData, 'class="fwd_rwd_nav"');
232 }
233 return array(1, $code);
234 } else {
235 if ($this->eCounter == $this->firstElementNumber + $this->iLimit) {
236 // Forward
237 $theData = Array();
238 $titleCol = $this->fieldArray[0];
239 $theData[$titleCol] = $this->fwd_rwd_HTML('rwd', $this->eCounter, $table);
240 $code = $this->addElement(1, '', $theData, 'class="fwd_rwd_nav"');
241 }
242 return array(0, $code);
243 }
244
245 }
246
247 /**
248 * Creates the button with link to either forward or reverse
249 *
250 * @param string $type Type: "fwd" or "rwd"
251 * @param integer $pointer Pointer
252 * @param string $table Table name
253 * @return string
254 * @access private
255 */
256 function fwd_rwd_HTML($type, $pointer, $table = '') {
257 $content = '';
258 $tParam = $table ? '&table=' . rawurlencode($table) : '';
259 switch ($type) {
260 case 'fwd':
261 $href = $this->listURL() . '&pointer=' . ($pointer - $this->iLimit) . $tParam;
262 $content = '<a href="' . htmlspecialchars($href) . '">' .
263 t3lib_iconWorks::getSpriteIcon('actions-move-up') .
264 '</a> <i>[1 - ' . $pointer . ']</i>';
265 break;
266 case 'rwd':
267 $href = $this->listURL() . '&pointer=' . $pointer . $tParam;
268 $content = '<a href="' . htmlspecialchars($href) . '">' .
269 t3lib_iconWorks::getSpriteIcon('actions-move-down') .
270 '</a> <i>[' . ($pointer + 1) . ' - ' . $this->totalItems . ']</i>';
271 break;
272 }
273 return $content;
274 }
275
276 /**
277 * Creates the URL to this script, including all relevant GPvars
278 *
279 * @param string $altId Alternative id value. Enter blank string for the current id ($this->id)
280 * @return string URL
281 */
282 function listURL($altId = '') {
283 return $this->script .
284 '?id=' . (strcmp($altId, '') ? $altId : $this->id);
285 }
286
287 /**
288 * Returning JavaScript for ClipBoard functionality.
289 *
290 * @return string
291 */
292 function CBfunctions() {
293 return '
294 // checkOffCB()
295 function checkOffCB(listOfCBnames, link) { //
296 var checkBoxes, flag, i;
297 var checkBoxes = listOfCBnames.split(",");
298 if (link.rel === "") {
299 link.rel = "allChecked";
300 flag = true;
301 } else {
302 link.rel = "";
303 flag = false;
304 }
305 for (i = 0; i < checkBoxes.length; i++) {
306 setcbValue(checkBoxes[i], flag);
307 }
308 }
309 // cbValue()
310 function cbValue(CBname) { //
311 var CBfullName = "CBC["+CBname+"]";
312 return (document.dblistForm[CBfullName] && document.dblistForm[CBfullName].checked ? 1 : 0);
313 }
314 // setcbValue()
315 function setcbValue(CBname,flag) { //
316 CBfullName = "CBC["+CBname+"]";
317 if(document.dblistForm[CBfullName]) {
318 document.dblistForm[CBfullName].checked = flag ? "on" : 0;
319 }
320 }
321
322 ';
323 }
324
325 /**
326 * Initializes page languages and icons
327 *
328 * @return void
329 */
330 function initializeLanguages() {
331
332 // Look up page overlays:
333 $this->pageOverlays = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
334 '*',
335 'pages_language_overlay',
336 'pid=' . intval($this->id) .
337 t3lib_BEfunc::deleteClause('pages_language_overlay') .
338 t3lib_BEfunc::versioningPlaceholderClause('pages_language_overlay'),
339 '',
340 '',
341 '',
342 'sys_language_uid'
343 );
344
345 $this->languageIconTitles = $this->getTranslateTools()->getSystemLanguages($this->id, $this->backPath);
346 }
347
348 /**
349 * Return the icon for the language
350 *
351 * @param integer $sys_language_uid Sys language uid
352 * @param boolean $addAsAdditionalText If set to true, only the flag is returned
353 *
354 * @return string Language icon
355 */
356 function languageFlag($sys_language_uid, $addAsAdditionalText = TRUE) {
357 $out = '';
358 $title = htmlspecialchars($this->languageIconTitles[$sys_language_uid]['title']);
359 if ($this->languageIconTitles[$sys_language_uid]['flagIcon']) {
360 $out .= t3lib_iconWorks::getSpriteIcon($this->languageIconTitles[$sys_language_uid]['flagIcon'], array('title' => $title));
361
362 if (!$addAsAdditionalText) {
363 return $out;
364 }
365 $out .= '&nbsp;';
366 }
367 $out .= $title;
368 return $out;
369 }
370
371 /**
372 * Gets an instance of t3lib_transl8tools.
373 *
374 * @return t3lib_transl8tools
375 */
376 protected function getTranslateTools() {
377 if (!isset($this->translateTools)) {
378 $this->translateTools = t3lib_div::makeInstance('t3lib_transl8tools');
379 }
380 return $this->translateTools;
381 }
382
383 /**
384 * Generates HTML code for a Reference tooltip out of
385 * sys_refindex records you hand over
386 *
387 * @param array $references array of records from sys_refindex table
388 * @param string $launchViewParameter JavaScript String, which will be passed as parameters to top.launchView
389 * @return string
390 */
391 protected function generateReferenceToolTip(array $references, $launchViewParameter = '') {
392 $result = array();
393
394 foreach ($references as $reference) {
395 $result[] =
396 $reference['tablename'] . ':' .
397 $reference['recuid'] . ':' .
398 $reference['field'];
399 if (strlen(implode(' / ', $result)) >= 100) {
400 break;
401 }
402 }
403
404 if (empty($result)) {
405 $htmlCode = '-';
406 } else {
407 $htmlCode = '<a href="#"';
408 if ($launchViewParameter !== '') {
409 $htmlCode .= ' onclick="' . htmlspecialchars('top.launchView(' . $launchViewParameter . '); return false;') . '"';
410 }
411 $htmlCode .= ' title="' . htmlspecialchars(t3lib_div::fixed_lgd_cs(implode(' / ', $result), 100)) . '">';
412 $htmlCode .= count($result);
413 $htmlCode .= '</a>';
414
415 }
416 return $htmlCode;
417 }
418 }
419
420 ?>