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