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