[BUGFIX] Prevent compression of scripts that use ajax.php
[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 *
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 * Library with a single function addElement that returns tablerows based on some input.
29 *
30 * Revised for TYPO3 3.6 July/2003 by Kasper Skårhøj
31 * XHTML compliant
32 *
33 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
34 */
35
36
37 /**
38 * This class is the base for listing of database records and files in the modules Web>List and File>Filelist
39 *
40 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
41 * @package TYPO3
42 * @subpackage t3lib
43 * @see typo3/db_list.php, typo3/file_list.php
44 */
45 class t3lib_recordList {
46
47 // Used in this class:
48 var $iLimit = 10; // default Max items shown
49 var $leftMargin = 0; // OBSOLETE - NOT USED ANYMORE. leftMargin
50 var $showIcon = 1;
51 var $no_noWrap = 0;
52 var $oddColumnsCssClass = ''; // If set this is <td> CSS-classname for odd columns in addElement. Used with db_layout / pages section
53 var $backPath = '';
54 var $fieldArray = Array(); // Decides the columns shown. Filled with values that refers to the keys of the data-array. $this->fieldArray[0] is the title column.
55 var $addElement_tdParams = array(); // Keys are fieldnames and values are td-parameters to add in addElement(), please use $addElement_tdCSSClass for CSS-classes;
56 var $addElement_tdCssClass = array(); // Keys are fieldnames and values are td-css-classes to add in addElement();
57
58 // Not used in this class - but maybe extension classes...
59 var $fixedL = 30; // Max length of strings
60 var $script = '';
61 var $thumbScript = 'thumbs.php';
62 var $setLMargin = 1; // Set to zero, if you don't want a left-margin with addElement function
63
64 var $counter = 0; // Counter increased for each element. Used to index elements for the JavaScript-code that transfers to the clipboard
65 var $totalItems = ''; // This could be set to the total number of items. Used by the fwd_rew_navigation...
66
67 // Internal (used in this class.)
68 var $firstElementNumber = 0;
69 var $eCounter = 0;
70 var $HTMLcode = ''; // String with accumulated HTML content
71
72 var $pageOverlays = array(); // Contains page translation languages
73 var $languageIconTitles = array(); // Contains sys language icons and titles
74 var $translateTools; // translateTools object
75
76 /**
77 * constructor for t3lib_recordList
78 *
79 * @author Ingo Renner <ingo@typo3.org>
80 */
81 public function __construct() {
82 if (isset($GLOBALS['BE_USER']->uc['titleLen']) && $GLOBALS['BE_USER']->uc['titleLen'] > 0) {
83 $this->fixedL = $GLOBALS['BE_USER']->uc['titleLen'];
84 }
85 $this->getTranslateTools();
86 }
87
88
89 /**
90 * Returns a table-row with the content from the fields in the input data array.
91 * OBS: $this->fieldArray MUST be set! (represents the list of fields to display)
92 *
93 * @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'
94 * @param string $icon is the <img>+<a> of the record. If not supplied the first 'join'-icon will be a 'line' instead
95 * @param array $data is the dataarray, record with the fields. Notice: These fields are (currently) NOT htmlspecialchar'ed before being wrapped in <td>-tags
96 * @param string $tdParams is insert in the <td>-tags. Must carry a ' ' as first character
97 * @param integer OBSOLETE - NOT USED ANYMORE. $lMargin is the leftMargin (integer)
98 * @param string $altLine is the HTML <img>-tag for an alternative 'gfx/ol/line.gif'-icon (used in the top)
99 * @return string HTML content for the table row
100 */
101 function addElement($h, $icon, $data, $trParams = '', $lMargin = '', $altLine = '') {
102 $noWrap = ($this->no_noWrap) ? '' : ' nowrap="nowrap"';
103
104 // Start up:
105 $out = '
106 <!-- Element, begin: -->
107 <tr ' . $trParams . '>';
108 // Show icon and lines
109 if ($this->showIcon) {
110 $out .= '
111 <td nowrap="nowrap" class="col-icon">';
112
113 if (!$h) {
114 $out .= '<img src="clear.gif" width="1" height="8" alt="" />';
115 } else {
116 for ($a = 0; $a < $h; $a++) {
117 if (!$a) {
118 if ($icon) {
119 $out .= $icon;
120 }
121 } else {
122 }
123 }
124 }
125 $out .= '</td>
126 ';
127 }
128
129 // Init rendering.
130 $colsp = '';
131 $lastKey = '';
132 $c = 0;
133 $ccount = 0;
134
135 // Traverse field array which contains the data to present:
136 foreach ($this->fieldArray as $vKey) {
137 if (isset($data[$vKey])) {
138 if ($lastKey) {
139 $cssClass = $this->addElement_tdCssClass[$lastKey];
140 if ($this->oddColumnsCssClass && $ccount % 2 == 0) {
141 $cssClass = implode(' ', array($this->addElement_tdCssClass[$lastKey], $this->oddColumnsCssClass));
142 }
143
144 $out .= '
145 <td' .
146 $noWrap .
147 ' class="' . $cssClass . '"' .
148 $colsp .
149 $this->addElement_tdParams[$lastKey] .
150 '>' . $data[$lastKey] . '</td>';
151 }
152 $lastKey = $vKey;
153 $c = 1;
154 $ccount++;
155 } else {
156 if (!$lastKey) {
157 $lastKey = $vKey;
158 }
159 $c++;
160 }
161 if ($c > 1) {
162 $colsp = ' colspan="' . $c . '"';
163 } else {
164 $colsp = '';
165 }
166 }
167 if ($lastKey) {
168 $cssClass = $this->addElement_tdCssClass[$lastKey];
169 if ($this->oddColumnsCssClass) {
170 $cssClass = implode(' ', array($this->addElement_tdCssClass[$lastKey], $this->oddColumnsCssClass));
171 }
172
173 $out .= '
174 <td' . $noWrap . ' class="' . $cssClass . '"' . $colsp . $this->addElement_tdParams[$lastKey] . '>' . $data[$lastKey] . '</td>';
175 }
176
177 // End row
178 $out .= '
179 </tr>';
180
181 // Return row.
182 return $out;
183 }
184
185 /**
186 * Dummy function, used to write the top of a table listing.
187 *
188 * @return void
189 */
190 function writeTop() {
191 }
192
193 /**
194 * Finishes the list with the "stopper"-gif, adding the HTML code for that item to the internal ->HTMLcode string
195 *
196 * @return void
197 */
198 function writeBottom() {
199 $this->HTMLcode .= '
200
201 <!--
202 End of list table:
203 -->
204 <table border="0" cellpadding="0" cellspacing="0">';
205 $theIcon = '<img' . t3lib_iconWorks::skinImg($this->backPath, 'gfx/ol/stopper.gif', 'width="18" height="16"') . ' alt="" />';
206 $this->HTMLcode .= $this->addElement(1, '', '', '', $this->leftMargin, $theIcon);
207 $this->HTMLcode .= '
208 </table>';
209 }
210
211 /**
212 * Creates a forward/reverse button based on the status of ->eCounter, ->firstElementNumber, ->iLimit
213 *
214 * @param string Table name
215 * @return array array([boolean], [HTML]) where [boolean] is 1 for reverse element, [HTML] is the table-row code for the element
216 */
217 function fwd_rwd_nav($table = '') {
218 $code = '';
219 if ($this->eCounter >= $this->firstElementNumber && $this->eCounter < $this->firstElementNumber + $this->iLimit) {
220 if ($this->firstElementNumber && $this->eCounter == $this->firstElementNumber) {
221 // reverse
222 $theData = Array();
223 $titleCol = $this->fieldArray[0];
224 $theData[$titleCol] = $this->fwd_rwd_HTML('fwd', $this->eCounter, $table);
225 $code = $this->addElement(1, '', $theData, 'class="fwd_rwd_nav"');
226 }
227 return array(1, $code);
228 } else {
229 if ($this->eCounter == $this->firstElementNumber + $this->iLimit) {
230 // forward
231 $theData = Array();
232 $titleCol = $this->fieldArray[0];
233 $theData[$titleCol] = $this->fwd_rwd_HTML('rwd', $this->eCounter, $table);
234 $code = $this->addElement(1, '', $theData, 'class="fwd_rwd_nav"');
235 }
236 return array(0, $code);
237 }
238
239 }
240
241 /**
242 * Creates the button with link to either forward or reverse
243 *
244 * @param string Type: "fwd" or "rwd"
245 * @param integer Pointer
246 * @param string Table name
247 * @return string
248 * @access private
249 */
250 function fwd_rwd_HTML($type, $pointer, $table = '') {
251 $content = '';
252 $tParam = $table ? '&table=' . rawurlencode($table) : '';
253 switch ($type) {
254 case 'fwd':
255 $href = $this->listURL() . '&pointer=' . ($pointer - $this->iLimit) . $tParam;
256 $content = '<a href="' . htmlspecialchars($href) . '">' .
257 t3lib_iconWorks::getSpriteIcon('actions-move-up') .
258 '</a> <i>[1 - ' . $pointer . ']</i>';
259 break;
260 case 'rwd':
261 $href = $this->listURL() . '&pointer=' . $pointer . $tParam;
262 $content = '<a href="' . htmlspecialchars($href) . '">' .
263 t3lib_iconWorks::getSpriteIcon('actions-move-down') .
264 '</a> <i>[' . ($pointer + 1) . ' - ' . $this->totalItems . ']</i>';
265 break;
266 }
267 return $content;
268 }
269
270 /**
271 * Creates the URL to this script, including all relevant GPvars
272 *
273 * @param string Alternative id value. Enter blank string for the current id ($this->id)
274 * @return string URL
275 */
276 function listURL($altId = '') {
277 return $this->script .
278 '?id=' . (strcmp($altId, '') ? $altId : $this->id);
279 }
280
281 /**
282 * Returning JavaScript for ClipBoard functionality.
283 *
284 * @return string
285 */
286 function CBfunctions() {
287 return '
288 // checkOffCB()
289 function checkOffCB(listOfCBnames, link) { //
290 var checkBoxes, flag, i;
291 var checkBoxes = listOfCBnames.split(",");
292 if (link.rel === "") {
293 link.rel = "allChecked";
294 flag = true;
295 } else {
296 link.rel = "";
297 flag = false;
298 }
299 for (i = 0; i < checkBoxes.length; i++) {
300 setcbValue(checkBoxes[i], flag);
301 }
302 }
303 // cbValue()
304 function cbValue(CBname) { //
305 var CBfullName = "CBC["+CBname+"]";
306 return (document.dblistForm[CBfullName] && document.dblistForm[CBfullName].checked ? 1 : 0);
307 }
308 // setcbValue()
309 function setcbValue(CBname,flag) { //
310 CBfullName = "CBC["+CBname+"]";
311 if(document.dblistForm[CBfullName]) {
312 document.dblistForm[CBfullName].checked = flag ? "on" : 0;
313 }
314 }
315
316 ';
317 }
318
319 /**
320 * Initializes page languages and icons
321 *
322 * @return void
323 */
324 function initializeLanguages() {
325
326 // Look up page overlays:
327 $this->pageOverlays = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
328 '*',
329 'pages_language_overlay',
330 'pid=' . intval($this->id) .
331 t3lib_BEfunc::deleteClause('pages_language_overlay') .
332 t3lib_BEfunc::versioningPlaceholderClause('pages_language_overlay'),
333 '',
334 '',
335 '',
336 'sys_language_uid'
337 );
338
339 $this->languageIconTitles = $this->getTranslateTools()->getSystemLanguages($this->id, $this->backPath);
340 }
341
342 /**
343 * Return the icon for the language
344 *
345 * @param integer Sys language uid
346 * @return string Language icon
347 */
348 function languageFlag($sys_language_uid) {
349 $out = '';
350 if ($this->languageIconTitles[$sys_language_uid]['flagIcon']) {
351 $out .= t3lib_iconWorks::getSpriteIcon($this->languageIconTitles[$sys_language_uid]['flagIcon']);
352 $out .= '&nbsp;';
353 }
354 $out .= htmlspecialchars($this->languageIconTitles[$sys_language_uid]['title']);
355 return $out;
356 }
357
358 /**
359 * Gets an instance of t3lib_transl8tools.
360 *
361 * @return t3lib_transl8tools
362 */
363 protected function getTranslateTools() {
364 if (!isset($this->translateTools)) {
365 $this->translateTools = t3lib_div::makeInstance('t3lib_transl8tools');
366 }
367 return $this->translateTools;
368 }
369 }
370
371
372 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_recordlist.php'])) {
373 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_recordlist.php']);
374 }
375
376 ?>