[TASK] Merge submodule version into core
[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 textfile 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 // TranslateTools object
158 /**
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 */
274 public function writeBottom() {
275 $this->HTMLcode .= '
276
277 <!--
278 End of list table:
279 -->
280 <table border="0" cellpadding="0" cellspacing="0">';
281 $theIcon = '<img' . IconUtility::skinImg($this->backPath, 'gfx/ol/stopper.gif', 'width="18" height="16"') . ' alt="" />';
282 $this->HTMLcode .= $this->addElement(1, '', array(), '', $this->leftMargin, $theIcon);
283 $this->HTMLcode .= '
284 </table>';
285 }
286
287 /**
288 * Creates a forward/reverse button based on the status of ->eCounter, ->firstElementNumber, ->iLimit
289 *
290 * @param string $table Table name
291 * @return array array([boolean], [HTML]) where [boolean] is 1 for reverse element, [HTML] is the table-row code for the element
292 * @todo Define visibility
293 */
294 public function fwd_rwd_nav($table = '') {
295 $code = '';
296 if ($this->eCounter >= $this->firstElementNumber && $this->eCounter < $this->firstElementNumber + $this->iLimit) {
297 if ($this->firstElementNumber && $this->eCounter == $this->firstElementNumber) {
298 // Reverse
299 $theData = array();
300 $titleCol = $this->fieldArray[0];
301 $theData[$titleCol] = $this->fwd_rwd_HTML('fwd', $this->eCounter, $table);
302 $code = $this->addElement(1, '', $theData, 'class="fwd_rwd_nav"');
303 }
304 return array(1, $code);
305 } else {
306 if ($this->eCounter == $this->firstElementNumber + $this->iLimit) {
307 // Forward
308 $theData = array();
309 $titleCol = $this->fieldArray[0];
310 $theData[$titleCol] = $this->fwd_rwd_HTML('rwd', $this->eCounter, $table);
311 $code = $this->addElement(1, '', $theData, 'class="fwd_rwd_nav"');
312 }
313 return array(0, $code);
314 }
315 }
316
317 /**
318 * Creates the button with link to either forward or reverse
319 *
320 * @param string $type Type: "fwd" or "rwd
321 * @param integer $pointer Pointer
322 * @param string $table Table name
323 * @return string
324 * @access private
325 * @todo Define visibility
326 */
327 public function fwd_rwd_HTML($type, $pointer, $table = '') {
328 $content = '';
329 $tParam = $table ? '&table=' . rawurlencode($table) : '';
330 switch ($type) {
331 case 'fwd':
332 $href = $this->listURL() . '&pointer=' . ($pointer - $this->iLimit) . $tParam;
333 $content = '<a href="' . htmlspecialchars($href) . '">' . IconUtility::getSpriteIcon('actions-move-up') . '</a> <i>[1 - ' . $pointer . ']</i>';
334 break;
335 case 'rwd':
336 $href = $this->listURL() . '&pointer=' . $pointer . $tParam;
337 $content = '<a href="' . htmlspecialchars($href) . '">' . IconUtility::getSpriteIcon('actions-move-down') . '</a> <i>[' . ($pointer + 1) . ' - ' . $this->totalItems . ']</i>';
338 break;
339 }
340 return $content;
341 }
342
343 /**
344 * Creates the URL to this script, including all relevant GPvars
345 *
346 * @param string $altId Alternative id value. Enter blank string for the current id ($this->id)
347 * @return string URL
348 * @todo Define visibility
349 */
350 public function listURL($altId = '') {
351 return $this->script . '?id=' . (strcmp($altId, '') ? $altId : $this->id);
352 }
353
354 /**
355 * Returning JavaScript for ClipBoard functionality.
356 *
357 * @return string
358 * @todo Define visibility
359 */
360 public function CBfunctions() {
361 return '
362 // checkOffCB()
363 function checkOffCB(listOfCBnames, link) { //
364 var checkBoxes, flag, i;
365 var checkBoxes = listOfCBnames.split(",");
366 if (link.rel === "") {
367 link.rel = "allChecked";
368 flag = true;
369 } else {
370 link.rel = "";
371 flag = false;
372 }
373 for (i = 0; i < checkBoxes.length; i++) {
374 setcbValue(checkBoxes[i], flag);
375 }
376 }
377 // cbValue()
378 function cbValue(CBname) { //
379 var CBfullName = "CBC["+CBname+"]";
380 return (document.dblistForm[CBfullName] && document.dblistForm[CBfullName].checked ? 1 : 0);
381 }
382 // setcbValue()
383 function setcbValue(CBname,flag) { //
384 CBfullName = "CBC["+CBname+"]";
385 if(document.dblistForm[CBfullName]) {
386 document.dblistForm[CBfullName].checked = flag ? "on" : 0;
387 }
388 }
389
390 ';
391 }
392
393 /**
394 * Initializes page languages and icons
395 *
396 * @return void
397 * @todo Define visibility
398 */
399 public function initializeLanguages() {
400 // Look up page overlays:
401 $this->pageOverlays = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'pages_language_overlay', 'pid=' . intval($this->id) . BackendUtility::deleteClause('pages_language_overlay') . BackendUtility::versioningPlaceholderClause('pages_language_overlay'), '', '', '', 'sys_language_uid');
402 $this->languageIconTitles = $this->getTranslateTools()->getSystemLanguages($this->id, $this->backPath);
403 }
404
405 /**
406 * Return the icon for the language
407 *
408 * @param integer $sys_language_uid Sys language uid
409 * @param boolean $addAsAdditionalText If set to true, only the flag is returned
410 * @return string Language icon
411 * @todo Define visibility
412 */
413 public function languageFlag($sys_language_uid, $addAsAdditionalText = TRUE) {
414 $out = '';
415 $title = htmlspecialchars($this->languageIconTitles[$sys_language_uid]['title']);
416 if ($this->languageIconTitles[$sys_language_uid]['flagIcon']) {
417 $out .= IconUtility::getSpriteIcon($this->languageIconTitles[$sys_language_uid]['flagIcon'], array('title' => $title));
418 if (!$addAsAdditionalText) {
419 return $out;
420 }
421 $out .= '&nbsp;';
422 }
423 $out .= $title;
424 return $out;
425 }
426
427 /**
428 * Gets an instance of TranslationConfigurationProvider
429 *
430 * @return \TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider
431 */
432 protected function getTranslateTools() {
433 if (!isset($this->translateTools)) {
434 $this->translateTools = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Configuration\\TranslationConfigurationProvider');
435 }
436 return $this->translateTools;
437 }
438
439 /**
440 * Generates HTML code for a Reference tooltip out of
441 * sys_refindex records you hand over
442 *
443 * @param array $references array of records from sys_refindex table
444 * @param string $launchViewParameter JavaScript String, which will be passed as parameters to top.launchView
445 * @return string
446 */
447 protected function generateReferenceToolTip(array $references, $launchViewParameter = '') {
448 $result = array();
449 foreach ($references as $reference) {
450 $result[] = $reference['tablename'] . ':' . $reference['recuid'] . ':' . $reference['field'];
451 if (strlen(implode(' / ', $result)) >= 100) {
452 break;
453 }
454 }
455 if (empty($result)) {
456 $htmlCode = '-';
457 } else {
458 $htmlCode = '<a href="#"';
459 if ($launchViewParameter !== '') {
460 $htmlCode .= ' onclick="' . htmlspecialchars(('top.launchView(' . $launchViewParameter . '); return false;')) . '"';
461 }
462 $htmlCode .= ' title="' . htmlspecialchars(GeneralUtility::fixed_lgd_cs(implode(' / ', $result), 100)) . '">';
463 $htmlCode .= count($references);
464 $htmlCode .= '</a>';
465 }
466 return $htmlCode;
467 }
468
469 }
470
471
472 ?>