[TASK] Use (int) instead of intval() or (integer)
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / RecordList / AbstractRecordList.php
1 <?php
2 namespace TYPO3\CMS\Backend\RecordList;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 1999-2013 Kasper Skårhøj (kasperYYYY@typo3.com)
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the text file GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 * This script is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * This copyright notice MUST APPEAR in all copies of the script!
27 ***************************************************************/
28
29 use TYPO3\CMS\Backend\Utility\BackendUtility;
30 use TYPO3\CMS\Backend\Utility\IconUtility;
31 use TYPO3\CMS\Core\Utility\GeneralUtility;
32
33 /**
34 * Library with a single function addElement that returns table
35 * rows based on some input.
36 *
37 * Base for class listing of database records and files in the
38 * modules Web>List and File>Filelist
39 *
40 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
41 * @see typo3/db_list.php
42 * @see typo3/sysext/filelist/mod1/index.php
43 */
44 abstract class AbstractRecordList {
45
46 // Used in this class:
47 // default Max items shown
48 /**
49 * @todo Define visibility
50 */
51 public $iLimit = 10;
52
53 // OBSOLETE - NOT USED ANYMORE. leftMargin
54 /**
55 * @todo Define visibility
56 */
57 public $leftMargin = 0;
58
59 /**
60 * @todo Define visibility
61 */
62 public $showIcon = 1;
63
64 /**
65 * @todo Define visibility
66 */
67 public $no_noWrap = 0;
68
69 // If set this is <td> CSS-classname for odd columns in addElement. Used with db_layout / pages section
70 /**
71 * @todo Define visibility
72 */
73 public $oddColumnsCssClass = '';
74
75 /**
76 * @todo Define visibility
77 */
78 public $backPath = '';
79
80 // Decides the columns shown. Filled with values that refers to the keys of the data-array. $this->fieldArray[0] is the title column.
81 /**
82 * @todo Define visibility
83 */
84 public $fieldArray = array();
85
86 // Keys are fieldnames and values are td-parameters to add in addElement(), please use $addElement_tdCSSClass for CSS-classes;
87 /**
88 * @todo Define visibility
89 */
90 public $addElement_tdParams = array();
91
92 // Keys are fieldnames and values are td-css-classes to add in addElement();
93 /**
94 * @todo Define visibility
95 */
96 public $addElement_tdCssClass = array();
97
98 // Not used in this class - but maybe extension classes...
99 // Max length of strings
100 /**
101 * @todo Define visibility
102 */
103 public $fixedL = 30;
104
105 /**
106 * @todo Define visibility
107 */
108 public $script = '';
109
110 // Set to zero, if you don't want a left-margin with addElement function
111 /**
112 * @todo Define visibility
113 */
114 public $setLMargin = 1;
115
116 // Counter increased for each element. Used to index elements for the JavaScript-code that transfers to the clipboard
117 /**
118 * @todo Define visibility
119 */
120 public $counter = 0;
121
122 // This could be set to the total number of items. Used by the fwd_rew_navigation...
123 /**
124 * @todo Define visibility
125 */
126 public $totalItems = '';
127
128 // Internal (used in this class.)
129 /**
130 * @todo Define visibility
131 */
132 public $firstElementNumber = 0;
133
134 /**
135 * @todo Define visibility
136 */
137 public $eCounter = 0;
138
139 // String with accumulated HTML content
140 /**
141 * @todo Define visibility
142 */
143 public $HTMLcode = '';
144
145 // Contains page translation languages
146 /**
147 * @todo Define visibility
148 */
149 public $pageOverlays = array();
150
151 // Contains sys language icons and titles
152 /**
153 * @todo Define visibility
154 */
155 public $languageIconTitles = array();
156
157 /**
158 * @var \TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider
159 * @todo Define visibility
160 */
161 public $translateTools;
162
163 /**
164 * Constructor
165 */
166 public function __construct() {
167 if (isset($GLOBALS['BE_USER']->uc['titleLen']) && $GLOBALS['BE_USER']->uc['titleLen'] > 0) {
168 $this->fixedL = $GLOBALS['BE_USER']->uc['titleLen'];
169 }
170 $this->getTranslateTools();
171 }
172
173 /**
174 * Returns a table-row with the content from the fields in the input data array.
175 * OBS: $this->fieldArray MUST be set! (represents the list of fields to display)
176 *
177 * @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'
178 * @param string $icon Is the <img>+<a> of the record. If not supplied the first 'join'-icon will be a 'line' instead
179 * @param array $data Is the dataarray, record with the fields. Notice: These fields are (currently) NOT htmlspecialchar'ed before being wrapped in <td>-tags
180 * @param string $tdParams Is insert in the <td>-tags. Must carry a ' ' as first character
181 * @param integer OBSOLETE - NOT USED ANYMORE. $lMargin is the leftMargin (integer)
182 * @param string $altLine Is the HTML <img>-tag for an alternative 'gfx/ol/line.gif'-icon (used in the top)
183 * @return string HTML content for the table row
184 * @todo Define visibility
185 */
186 public function addElement($h, $icon, $data, $trParams = '', $lMargin = '', $altLine = '') {
187 $noWrap = $this->no_noWrap ? '' : ' nowrap="nowrap"';
188 // Start up:
189 $out = '
190 <!-- Element, begin: -->
191 <tr ' . $trParams . '>';
192 // Show icon and lines
193 if ($this->showIcon) {
194 $out .= '
195 <td nowrap="nowrap" class="col-icon">';
196 if (!$h) {
197 $out .= '<img src="clear.gif" width="1" height="8" alt="" />';
198 } else {
199 for ($a = 0; $a < $h; $a++) {
200 if (!$a) {
201 if ($icon) {
202 $out .= $icon;
203 }
204 } else {
205
206 }
207 }
208 }
209 $out .= '</td>
210 ';
211 }
212 // Init rendering.
213 $colsp = '';
214 $lastKey = '';
215 $c = 0;
216 $ccount = 0;
217 // Traverse field array which contains the data to present:
218 foreach ($this->fieldArray as $vKey) {
219 if (isset($data[$vKey])) {
220 if ($lastKey) {
221 $cssClass = $this->addElement_tdCssClass[$lastKey];
222 if ($this->oddColumnsCssClass && $ccount % 2 == 0) {
223 $cssClass = implode(' ', array($this->addElement_tdCssClass[$lastKey], $this->oddColumnsCssClass));
224 }
225 $out .= '
226 <td' . $noWrap . ' class="' . $cssClass . '"' . $colsp . $this->addElement_tdParams[$lastKey] . '>' . $data[$lastKey] . '</td>';
227 }
228 $lastKey = $vKey;
229 $c = 1;
230 $ccount++;
231 } else {
232 if (!$lastKey) {
233 $lastKey = $vKey;
234 }
235 $c++;
236 }
237 if ($c > 1) {
238 $colsp = ' colspan="' . $c . '"';
239 } else {
240 $colsp = '';
241 }
242 }
243 if ($lastKey) {
244 $cssClass = $this->addElement_tdCssClass[$lastKey];
245 if ($this->oddColumnsCssClass) {
246 $cssClass = implode(' ', array($this->addElement_tdCssClass[$lastKey], $this->oddColumnsCssClass));
247 }
248 $out .= '
249 <td' . $noWrap . ' class="' . $cssClass . '"' . $colsp . $this->addElement_tdParams[$lastKey] . '>' . $data[$lastKey] . '</td>';
250 }
251 // End row
252 $out .= '
253 </tr>';
254 // Return row.
255 return $out;
256 }
257
258 /**
259 * Dummy function, used to write the top of a table listing.
260 *
261 * @return void
262 * @todo Define visibility
263 */
264 public function writeTop() {
265
266 }
267
268 /**
269 * Finishes the list with the "stopper"-gif, adding the HTML code for that item to the internal ->HTMLcode string
270 *
271 * @return void
272 * @todo Define visibility
273 * @deprecated since 6.2, will be removed 2 versions later - Function not needed anymore
274 */
275 public function writeBottom() {
276 GeneralUtility::logDeprecatedFunction();
277 }
278
279 /**
280 * Creates a forward/reverse button based on the status of ->eCounter, ->firstElementNumber, ->iLimit
281 *
282 * @param string $table Table name
283 * @return array array([boolean], [HTML]) where [boolean] is 1 for reverse element, [HTML] is the table-row code for the element
284 * @todo Define visibility
285 */
286 public function fwd_rwd_nav($table = '') {
287 $code = '';
288 if ($this->eCounter >= $this->firstElementNumber && $this->eCounter < $this->firstElementNumber + $this->iLimit) {
289 if ($this->firstElementNumber && $this->eCounter == $this->firstElementNumber) {
290 // Reverse
291 $theData = array();
292 $titleCol = $this->fieldArray[0];
293 $theData[$titleCol] = $this->fwd_rwd_HTML('fwd', $this->eCounter, $table);
294 $code = $this->addElement(1, '', $theData, 'class="fwd_rwd_nav"');
295 }
296 return array(1, $code);
297 } else {
298 if ($this->eCounter == $this->firstElementNumber + $this->iLimit) {
299 // Forward
300 $theData = array();
301 $titleCol = $this->fieldArray[0];
302 $theData[$titleCol] = $this->fwd_rwd_HTML('rwd', $this->eCounter, $table);
303 $code = $this->addElement(1, '', $theData, 'class="fwd_rwd_nav"');
304 }
305 return array(0, $code);
306 }
307 }
308
309 /**
310 * Creates the button with link to either forward or reverse
311 *
312 * @param string $type Type: "fwd" or "rwd
313 * @param integer $pointer Pointer
314 * @param string $table Table name
315 * @return string
316 * @access private
317 * @todo Define visibility
318 */
319 public function fwd_rwd_HTML($type, $pointer, $table = '') {
320 $content = '';
321 $tParam = $table ? '&table=' . rawurlencode($table) : '';
322 switch ($type) {
323 case 'fwd':
324 $href = $this->listURL() . '&pointer=' . ($pointer - $this->iLimit) . $tParam;
325 $content = '<a href="' . htmlspecialchars($href) . '">' . IconUtility::getSpriteIcon('actions-move-up') . '</a> <i>[1 - ' . $pointer . ']</i>';
326 break;
327 case 'rwd':
328 $href = $this->listURL() . '&pointer=' . $pointer . $tParam;
329 $content = '<a href="' . htmlspecialchars($href) . '">' . IconUtility::getSpriteIcon('actions-move-down') . '</a> <i>[' . ($pointer + 1) . ' - ' . $this->totalItems . ']</i>';
330 break;
331 }
332 return $content;
333 }
334
335 /**
336 * Creates the URL to this script, including all relevant GPvars
337 *
338 * @param string $altId Alternative id value. Enter blank string for the current id ($this->id)
339 * @return string URL
340 * @todo Define visibility
341 */
342 public function listURL($altId = '') {
343 return $this->script . '?id=' . ($altId !== '' ? $altId : $this->id);
344 }
345
346 /**
347 * Returning JavaScript for ClipBoard functionality.
348 *
349 * @return string
350 * @todo Define visibility
351 */
352 public function CBfunctions() {
353 return '
354 // checkOffCB()
355 function checkOffCB(listOfCBnames, link) { //
356 var checkBoxes, flag, i;
357 var checkBoxes = listOfCBnames.split(",");
358 if (link.rel === "") {
359 link.rel = "allChecked";
360 flag = true;
361 } else {
362 link.rel = "";
363 flag = false;
364 }
365 for (i = 0; i < checkBoxes.length; i++) {
366 setcbValue(checkBoxes[i], flag);
367 }
368 }
369 // cbValue()
370 function cbValue(CBname) { //
371 var CBfullName = "CBC["+CBname+"]";
372 return (document.dblistForm[CBfullName] && document.dblistForm[CBfullName].checked ? 1 : 0);
373 }
374 // setcbValue()
375 function setcbValue(CBname,flag) { //
376 CBfullName = "CBC["+CBname+"]";
377 if(document.dblistForm[CBfullName]) {
378 document.dblistForm[CBfullName].checked = flag ? "on" : 0;
379 }
380 }
381
382 ';
383 }
384
385 /**
386 * Initializes page languages and icons
387 *
388 * @return void
389 * @todo Define visibility
390 */
391 public function initializeLanguages() {
392 // Look up page overlays:
393 $this->pageOverlays = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'pages_language_overlay', 'pid=' . (int)$this->id . BackendUtility::deleteClause('pages_language_overlay') . BackendUtility::versioningPlaceholderClause('pages_language_overlay'), '', '', '', 'sys_language_uid');
394 $this->languageIconTitles = $this->getTranslateTools()->getSystemLanguages($this->id, $this->backPath);
395 }
396
397 /**
398 * Return the icon for the language
399 *
400 * @param integer $sys_language_uid Sys language uid
401 * @param boolean $addAsAdditionalText If set to true, only the flag is returned
402 * @return string Language icon
403 * @todo Define visibility
404 */
405 public function languageFlag($sys_language_uid, $addAsAdditionalText = TRUE) {
406 $out = '';
407 $title = htmlspecialchars($this->languageIconTitles[$sys_language_uid]['title']);
408 if ($this->languageIconTitles[$sys_language_uid]['flagIcon']) {
409 $out .= IconUtility::getSpriteIcon($this->languageIconTitles[$sys_language_uid]['flagIcon'], array('title' => $title));
410 if (!$addAsAdditionalText) {
411 return $out;
412 }
413 $out .= '&nbsp;';
414 }
415 $out .= $title;
416 return $out;
417 }
418
419 /**
420 * Gets an instance of TranslationConfigurationProvider
421 *
422 * @return \TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider
423 */
424 protected function getTranslateTools() {
425 if (!isset($this->translateTools)) {
426 $this->translateTools = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Configuration\\TranslationConfigurationProvider');
427 }
428 return $this->translateTools;
429 }
430
431 /**
432 * Generates HTML code for a Reference tooltip out of
433 * sys_refindex records you hand over
434 *
435 * @param array $references array of records from sys_refindex table
436 * @param string $launchViewParameter JavaScript String, which will be passed as parameters to top.launchView
437 * @return string
438 */
439 protected function generateReferenceToolTip(array $references, $launchViewParameter = '') {
440 $result = array();
441 foreach ($references as $reference) {
442 $result[] = $reference['tablename'] . ':' . $reference['recuid'] . ':' . $reference['field'];
443 if (strlen(implode(' / ', $result)) >= 100) {
444 break;
445 }
446 }
447 if (empty($result)) {
448 $htmlCode = '-';
449 } else {
450 $htmlCode = '<a href="#"';
451 if ($launchViewParameter !== '') {
452 $htmlCode .= ' onclick="' . htmlspecialchars(('top.launchView(' . $launchViewParameter . '); return false;')) . '"';
453 }
454 $htmlCode .= ' title="' . htmlspecialchars(GeneralUtility::fixed_lgd_cs(implode(' / ', $result), 100)) . '">';
455 $htmlCode .= count($references);
456 $htmlCode .= '</a>';
457 }
458 return $htmlCode;
459 }
460
461 }