File: class.t3lib_recordlist.php

package info (click to toggle)
typo3-src 4.0.2%2Bdebian-3
  • links: PTS
  • area: main
  • in suites: etch-m68k
  • size: 29,856 kB
  • ctags: 33,382
  • sloc: php: 134,523; xml: 6,976; sql: 1,084; sh: 168; makefile: 45
file content (421 lines) | stat: -rw-r--r-- 13,792 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
<?php
/***************************************************************
*  Copyright notice
*
*  (c) 1999-2006 Kasper Skaarhoj (kasperYYYY@typo3.com)
*  All rights reserved
*
*  This script is part of the TYPO3 project. The TYPO3 project is
*  free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version.
*
*  The GNU General Public License can be found at
*  http://www.gnu.org/copyleft/gpl.html.
*  A copy is found in the textfile GPL.txt and important notices to the license
*  from the author is found in LICENSE.txt distributed with these scripts.
*
*
*  This script is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
 * Library with a single function addElement that returns tablerows based on some input.
 *
 * $Id: class.t3lib_recordlist.php 1421 2006-04-10 09:27:15Z mundaun $
 * Revised for TYPO3 3.6 July/2003 by Kasper Skaarhoj
 * XHTML compliant
 *
 * @author	Kasper Skaarhoj <kasperYYYY@typo3.com>
 */
/**
 * [CLASS/FUNCTION INDEX of SCRIPT]
 *
 *
 *
 *   80: class t3lib_recordList
 *  123:     function addElement($h,$icon,$data,$tdParams='',$lMargin='',$altLine='')
 *  198:     function writeTop()
 *  206:     function writeBottom()
 *  225:     function fwd_rwd_nav($table='')
 *  258:     function fwd_rwd_HTML($type,$pointer,$table='')
 *  284:     function listURL($altId='')
 *  294:     function CBfunctions()
 *  344:     function initializeLanguages()
 *  411:     function languageFlag($sys_language_uid)
 *
 * TOTAL FUNCTIONS: 9
 * (This index is automatically created/updated by the extension "extdeveval")
 *
 */
















/**
 * This class is the base for listing of database records and files in the modules Web>List and File>Filelist
 *
 * @author	Kasper Skaarhoj <kasperYYYY@typo3.com>
 * @package TYPO3
 * @subpackage t3lib
 * @see typo3/db_list.php, typo3/file_list.php
 */
class t3lib_recordList {

		// Used in this class:
	var $iLimit = 10;						// default Max items shown
	var $leftMargin = 0;					// OBSOLETE - NOT USED ANYMORE. leftMargin
	var $showIcon = 1;
	var $no_noWrap = 0;
	var $oddColumnsTDParams ='';			// If set this is <td>-params for odd columns in addElement. Used with db_layout / pages section
	var $backPath='';
	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.
	var $addElement_tdParams = array();		// Keys are fieldnames and values are td-parameters to add in addElement();

		// Not used in this class - but maybe extension classes...
	var $fixedL = 50;						// Max length of strings
	var $script = '';
	var $thumbScript = 'thumbs.php';
	var $setLMargin=1;						// Set to zero, if you don't want a left-margin with addElement function

	var $counter=0;							// Counter increased for each element. Used to index elements for the JavaScript-code that transfers to the clipboard
	var $totalItems = '';					// This could be set to the total number of items. Used by the fwd_rew_navigation...

		// Internal (used in this class.)
	var $firstElementNumber=0;
	var $eCounter=0;
	var $HTMLcode='';			// String with accumulated HTML content

	var $pageOverlays = array();			// Contains page translation languages
	var $languageIconTitles = array();		// Contains sys language icons and titles



	/**
	 * Returns a table-row with the content from the fields in the input data array.
	 * OBS: $this->fieldArray MUST be set! (represents the list of fields to display)
	 *
	 * @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'
	 * @param	string		$icon is the <img>+<a> of the record. If not supplied the first 'join'-icon will be a 'line' instead
	 * @param	array		$data is the dataarray, record with the fields. Notice: These fields are (currently) NOT htmlspecialchar'ed before being wrapped in <td>-tags
	 * @param	string		$tdParams is insert in the <td>-tags. Must carry a ' ' as first character
	 * @param	integer		OBSOLETE - NOT USED ANYMORE. $lMargin is the leftMargin (integer)
	 * @param	string		$altLine is the HTML <img>-tag for an alternative 'gfx/ol/line.gif'-icon (used in the top)
	 * @return	string		HTML content for the table row
	 */
	function addElement($h,$icon,$data,$tdParams='',$lMargin='',$altLine='')	{
		$noWrap = ($this->no_noWrap) ? '' : ' nowrap="nowrap"';

			// Start up:
		$out='
		<!-- Element, begin: -->
		<tr>';
			// Show icon and lines
		if ($this->showIcon)	{
			$out.='
			<td nowrap="nowrap"'.$tdParams.'>';

			if (!$h)	{
#				$out.='<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/halfline.gif','width="18" height="8"').' alt="" />';
				$out.='<img src="clear.gif" width="1" height="8" alt="" />';
			} else {
				for ($a=0;$a<$h;$a++)	{
					if (!$a)	{
#						$out.= $altLine ? $altLine : '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/line.gif','width="18" height="16"').' alt="" />';
						if ($icon)	$out.= $icon;
					} else {
#						$out.= $altLine ? $altLine :'<br /><img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/line.gif','width="18" height="16"').' alt="" />';
					}
				}
			}
			$out.='</td>
			';
		}

			// Init rendering.
		$colsp='';
		$lastKey='';
		$c=0;
		$ccount=0;
		$tdP[0] = $this->oddColumnsTDParams ? $this->oddColumnsTDParams : $tdParams;
		$tdP[1] = $tdParams;

			// Traverse field array which contains the data to present:
		reset($this->fieldArray);
		while(list(,$vKey)=each($this->fieldArray))	{
			if (isset($data[$vKey]))	{
				if ($lastKey)	{
					$out.='
						<td'.
						$noWrap.
						$tdP[($ccount%2)].
						$colsp.
						$this->addElement_tdParams[$lastKey].
						'>'.$data[$lastKey].'</td>';
				}
				$lastKey=$vKey;
				$c=1;
				$ccount++;
			} else {
				if (!$lastKey) {$lastKey=$vKey;}
				$c++;
			}
			if ($c>1)	{$colsp=' colspan="'.$c.'"';} else {$colsp='';}
		}
		if ($lastKey)	{	$out.='
						<td'.$noWrap.$tdP[($ccount%2)].$colsp.$this->addElement_tdParams[$lastKey].'>'.$data[$lastKey].'</td>';	}

			// End row
		$out.='
		</tr>';

			// Return row.
		return $out;
	}

	/**
	 * Dummy function, used to write the top of a table listing.
	 *
	 * @return	void
	 */
	function writeTop()	{
	}

	/**
	 * Finishes the list with the "stopper"-gif, adding the HTML code for that item to the internal ->HTMLcode string
	 *
	 * @return	void
	 */
	function writeBottom()	{
		$this->HTMLcode.='

		<!--
			End of list table:
		-->
		<table border="0" cellpadding="0" cellspacing="0">';
		$theIcon='<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/stopper.gif','width="18" height="16"').' alt="" />';
		$this->HTMLcode.=$this->addElement(1,'','','',$this->leftMargin,$theIcon);
		$this->HTMLcode.='
		</table>';
	}

	/**
	 * Creates a forward/reverse button based on the status of ->eCounter, ->firstElementNumber, ->iLimit
	 *
	 * @param	string		Table name
	 * @return	array		array([boolean], [HTML]) where [boolean] is 1 for reverse element, [HTML] is the table-row code for the element
	 */
	function fwd_rwd_nav($table='')	{
		$code='';
		if ($this->eCounter >= $this->firstElementNumber   &&   $this->eCounter < $this->firstElementNumber+$this->iLimit)	{
			if ($this->firstElementNumber && $this->eCounter==$this->firstElementNumber)	{
					// 	reverse
				$theData = Array();
				$titleCol=$this->fieldArray[0];
				$theData[$titleCol] = $this->fwd_rwd_HTML('fwd',$this->eCounter,$table);
				$code=$this->addElement(1,'',$theData);
			}
			return Array(1,$code);
		} else {
			if ($this->eCounter==$this->firstElementNumber+$this->iLimit)	{
					// 	forward
				$theData = Array();
				$titleCol=$this->fieldArray[0];
				$theData[$titleCol] = $this->fwd_rwd_HTML('rwd',$this->eCounter,$table);
				$code=$this->addElement(1,'',$theData);
			}
			return Array(0,$code);
		}

	}

	/**
	 * Creates the button with link to either forward or reverse
	 *
	 * @param	string		Type: "fwd" or "rwd"
	 * @param	integer		Pointer
	 * @param	string		Table name
	 * @return	string
	 * @access private
	 */
	function fwd_rwd_HTML($type,$pointer,$table='')	{
		$content = '';
		$tParam = $table ? '&table='.rawurlencode($table) : '';
		switch($type)	{
			case 'fwd':
				$href = $this->listURL().'&pointer='.($pointer-$this->iLimit).$tParam;
				$content = '<a href="'.htmlspecialchars($href).'">'.
						'<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/pilup.gif','width="14" height="14"').' alt="" />'.
						'</a> <i>[1 - '.$pointer.']</i>';
			break;
			case 'rwd':
				$href = $this->listURL().'&pointer='.$pointer.$tParam;
				$content = '<a href="'.htmlspecialchars($href).'">'.
						'<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/pildown.gif','width="14" height="14"').' alt="" />'.
						'</a> <i>['.($pointer+1).' - '.$this->totalItems.']</i>';
			break;
		}
		return $content;
	}

	/**
	 * Creates the URL to this script, including all relevant GPvars
	 *
	 * @param	string		Alternative id value. Enter blank string for the current id ($this->id)
	 * @return	string		URL
	 */
	function listURL($altId='')	{
		return $this->script.
			'?id='.(strcmp($altId,'')?$altId:$this->id);
	}

	/**
	 * Returning JavaScript for ClipBoard functionality.
	 *
	 * @return	string
	 */
	function CBfunctions()	{
		return '
		// checkOffCB()
	function checkOffCB(listOfCBnames)	{	//
		var notChecked=0;
		var total=0;

			// Checking how many is checked, how many is not
		var pointer=0;
		var pos = listOfCBnames.indexOf(",");
		while (pos!=-1)	{
			if (!cbValue(listOfCBnames.substr(pointer,pos-pointer))) notChecked++;
			total++;
			pointer=pos+1;
			pos = listOfCBnames.indexOf(",",pointer);
		}
		if (!cbValue(listOfCBnames.substr(pointer))) notChecked++;
		total++;

			// Setting the status...
		var flag = notChecked*2>total;
		pointer=0;
		pos = listOfCBnames.indexOf(",");
		while (pos!=-1)	{
			setcbValue(listOfCBnames.substr(pointer,pos-pointer),flag);

			pointer=pos+1;
			pos = listOfCBnames.indexOf(",",pointer);
		}
		setcbValue(listOfCBnames.substr(pointer),flag);
	}
		// cbValue()
	function cbValue(CBname)	{	//
		var CBfullName = "CBC["+CBname+"]";
		return (document.dblistForm[CBfullName] && document.dblistForm[CBfullName].checked ? 1 : 0);
	}
		// setcbValue()
	function setcbValue(CBname,flag)	{	//
		CBfullName = "CBC["+CBname+"]";
		document.dblistForm[CBfullName].checked = flag ? "on" : 0;
	}

		';
	}

	/**
	 * Initializes page languages and icons
	 *
	 * @return	void
	 */
	function initializeLanguages()	{
		global $TCA,$LANG;

			// Look up page overlays:
		$this->pageOverlays = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
			'*',
			'pages_language_overlay',
			'pid='.intval($this->id).
				t3lib_BEfunc::deleteClause('pages_language_overlay').
				t3lib_BEfunc::versioningPlaceholderClause('pages_language_overlay'),
			'',
			'',
			'',
			'sys_language_uid'
		);

			// icons and language titles:
		t3lib_div::loadTCA ('sys_language');
		$flagAbsPath = t3lib_div::getFileAbsFileName($TCA['sys_language']['columns']['flag']['config']['fileFolder']);
		$flagIconPath = $this->backPath.'../'.substr($flagAbsPath, strlen(PATH_site));

		$this->modSharedTSconfig = t3lib_BEfunc::getModTSconfig($this->id, 'mod.SHARED');
		$this->languageIconTitles = array();

			// Set default:
		$this->languageIconTitles[0]=array(
			'uid' => 0,
			'title' => strlen ($this->modSharedTSconfig['properties']['defaultLanguageLabel']) ? $this->modSharedTSconfig['properties']['defaultLanguageLabel'].' ('.$LANG->getLL('defaultLanguage').')' : $LANG->getLL('defaultLanguage'),
			'ISOcode' => 'DEF',
			'flagIcon' => strlen($this->modSharedTSconfig['properties']['defaultLanguageFlag']) && @is_file($flagAbsPath.$this->modSharedTSconfig['properties']['defaultLanguageFlag']) ? $flagIconPath.$this->modSharedTSconfig['properties']['defaultLanguageFlag'] : null,
		);

			// Set "All" language:
		$this->languageIconTitles[-1]=array(
			'uid' => -1,
			'title' => $LANG->getLL ('multipleLanguages'),
			'ISOcode' => 'DEF',
			'flagIcon' => $flagIconPath.'multi-language.gif',
		);

			// Find all system languages:
		$sys_languages = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
			'*',
			'sys_language',
			''
		);
		foreach($sys_languages as $row)		{
			$this->languageIconTitles[$row['uid']] = $row;

			if ($row['static_lang_isocode'])	{
				$staticLangRow = t3lib_BEfunc::getRecord('static_languages',$row['static_lang_isocode'],'lg_iso_2');
				if ($staticLangRow['lg_iso_2']) {
					$this->languageIconTitles[$row['uid']]['ISOcode'] = $staticLangRow['lg_iso_2'];
				}
			}
			if (strlen ($row['flag'])) {
				$this->languageIconTitles[$row['uid']]['flagIcon'] = @is_file($flagAbsPath.$row['flag']) ? $flagIconPath.$row['flag'] : '';
			}
		}
	}

	/**
	 * Return the icon for the language
	 *
	 * @param	integer		Sys language uid
	 * @return	string		Language icon
	 */
	function languageFlag($sys_language_uid)	{
		return ($this->languageIconTitles[$sys_language_uid]['flagIcon'] ? '<img src="'.$this->languageIconTitles[$sys_language_uid]['flagIcon'].'" class="absmiddle" alt="" />&nbsp;' : '').
				htmlspecialchars($this->languageIconTitles[$sys_language_uid]['title']);
	}
}


if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_recordlist.php'])	{
	include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_recordlist.php']);
}
?>