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