[TASK] Make browse_links.php a wizard
[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 * Script URL
107 */
108 public $thisScript = '';
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 * Sets the script url depending on being a module or script request
175 */
176 protected function determineScriptUrl() {
177 if ($moduleName = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('M')) {
178 $this->thisScript = \TYPO3\CMS\Backend\Utility\BackendUtility::getModuleUrl($moduleName);
179 } else {
180 $this->thisScript = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('SCRIPT_NAME');
181 }
182 }
183
184 /**
185 * @return string
186 */
187 protected function getThisScript() {
188 return strpos($this->thisScript, '?') === FALSE ? $this->thisScript . '?' : $this->thisScript . '&';
189 }
190
191 /**
192 * Returns a table-row with the content from the fields in the input data array.
193 * OBS: $this->fieldArray MUST be set! (represents the list of fields to display)
194 *
195 * @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'
196 * @param string $icon Is the <img>+<a> of the record. If not supplied the first 'join'-icon will be a 'line' instead
197 * @param array $data Is the dataarray, record with the fields. Notice: These fields are (currently) NOT htmlspecialchar'ed before being wrapped in <td>-tags
198 * @param string $tdParams Is insert in the <td>-tags. Must carry a ' ' as first character
199 * @param integer OBSOLETE - NOT USED ANYMORE. $lMargin is the leftMargin (integer)
200 * @param string $altLine Is the HTML <img>-tag for an alternative 'gfx/ol/line.gif'-icon (used in the top)
201 * @return string HTML content for the table row
202 * @todo Define visibility
203 */
204 public function addElement($h, $icon, $data, $trParams = '', $lMargin = '', $altLine = '') {
205 $noWrap = $this->no_noWrap ? '' : ' nowrap="nowrap"';
206 // Start up:
207 $out = '
208 <!-- Element, begin: -->
209 <tr ' . $trParams . '>';
210 // Show icon and lines
211 if ($this->showIcon) {
212 $out .= '
213 <td nowrap="nowrap" class="col-icon">';
214 if (!$h) {
215 $out .= '<img src="clear.gif" width="1" height="8" alt="" />';
216 } else {
217 for ($a = 0; $a < $h; $a++) {
218 if (!$a) {
219 if ($icon) {
220 $out .= $icon;
221 }
222 } else {
223
224 }
225 }
226 }
227 $out .= '</td>
228 ';
229 }
230 // Init rendering.
231 $colsp = '';
232 $lastKey = '';
233 $c = 0;
234 $ccount = 0;
235 // Traverse field array which contains the data to present:
236 foreach ($this->fieldArray as $vKey) {
237 if (isset($data[$vKey])) {
238 if ($lastKey) {
239 $cssClass = $this->addElement_tdCssClass[$lastKey];
240 if ($this->oddColumnsCssClass && $ccount % 2 == 0) {
241 $cssClass = implode(' ', array($this->addElement_tdCssClass[$lastKey], $this->oddColumnsCssClass));
242 }
243 $out .= '
244 <td' . $noWrap . ' class="' . $cssClass . '"' . $colsp . $this->addElement_tdParams[$lastKey] . '>' . $data[$lastKey] . '</td>';
245 }
246 $lastKey = $vKey;
247 $c = 1;
248 $ccount++;
249 } else {
250 if (!$lastKey) {
251 $lastKey = $vKey;
252 }
253 $c++;
254 }
255 if ($c > 1) {
256 $colsp = ' colspan="' . $c . '"';
257 } else {
258 $colsp = '';
259 }
260 }
261 if ($lastKey) {
262 $cssClass = $this->addElement_tdCssClass[$lastKey];
263 if ($this->oddColumnsCssClass) {
264 $cssClass = implode(' ', array($this->addElement_tdCssClass[$lastKey], $this->oddColumnsCssClass));
265 }
266 $out .= '
267 <td' . $noWrap . ' class="' . $cssClass . '"' . $colsp . $this->addElement_tdParams[$lastKey] . '>' . $data[$lastKey] . '</td>';
268 }
269 // End row
270 $out .= '
271 </tr>';
272 // Return row.
273 return $out;
274 }
275
276 /**
277 * Dummy function, used to write the top of a table listing.
278 *
279 * @return void
280 * @todo Define visibility
281 */
282 public function writeTop() {
283
284 }
285
286 /**
287 * Finishes the list with the "stopper"-gif, adding the HTML code for that item to the internal ->HTMLcode string
288 *
289 * @return void
290 * @todo Define visibility
291 * @deprecated since 6.2, will be removed 2 versions later - Function not needed anymore
292 */
293 public function writeBottom() {
294 GeneralUtility::logDeprecatedFunction();
295 }
296
297 /**
298 * Creates a forward/reverse button based on the status of ->eCounter, ->firstElementNumber, ->iLimit
299 *
300 * @param string $table Table name
301 * @return array array([boolean], [HTML]) where [boolean] is 1 for reverse element, [HTML] is the table-row code for the element
302 * @todo Define visibility
303 */
304 public function fwd_rwd_nav($table = '') {
305 $code = '';
306 if ($this->eCounter >= $this->firstElementNumber && $this->eCounter < $this->firstElementNumber + $this->iLimit) {
307 if ($this->firstElementNumber && $this->eCounter == $this->firstElementNumber) {
308 // Reverse
309 $theData = array();
310 $titleCol = $this->fieldArray[0];
311 $theData[$titleCol] = $this->fwd_rwd_HTML('fwd', $this->eCounter, $table);
312 $code = $this->addElement(1, '', $theData, 'class="fwd_rwd_nav"');
313 }
314 return array(1, $code);
315 } else {
316 if ($this->eCounter == $this->firstElementNumber + $this->iLimit) {
317 // Forward
318 $theData = array();
319 $titleCol = $this->fieldArray[0];
320 $theData[$titleCol] = $this->fwd_rwd_HTML('rwd', $this->eCounter, $table);
321 $code = $this->addElement(1, '', $theData, 'class="fwd_rwd_nav"');
322 }
323 return array(0, $code);
324 }
325 }
326
327 /**
328 * Creates the button with link to either forward or reverse
329 *
330 * @param string $type Type: "fwd" or "rwd
331 * @param integer $pointer Pointer
332 * @param string $table Table name
333 * @return string
334 * @access private
335 * @todo Define visibility
336 */
337 public function fwd_rwd_HTML($type, $pointer, $table = '') {
338 $content = '';
339 $tParam = $table ? '&table=' . rawurlencode($table) : '';
340 switch ($type) {
341 case 'fwd':
342 $href = $this->listURL() . '&pointer=' . ($pointer - $this->iLimit) . $tParam;
343 $content = '<a href="' . htmlspecialchars($href) . '">' . IconUtility::getSpriteIcon('actions-move-up') . '</a> <i>[1 - ' . $pointer . ']</i>';
344 break;
345 case 'rwd':
346 $href = $this->listURL() . '&pointer=' . $pointer . $tParam;
347 $content = '<a href="' . htmlspecialchars($href) . '">' . IconUtility::getSpriteIcon('actions-move-down') . '</a> <i>[' . ($pointer + 1) . ' - ' . $this->totalItems . ']</i>';
348 break;
349 }
350 return $content;
351 }
352
353 /**
354 * Creates the URL to this script, including all relevant GPvars
355 *
356 * @param string $altId Alternative id value. Enter blank string for the current id ($this->id)
357 * @return string URL
358 * @todo Define visibility
359 */
360 public function listURL($altId = '') {
361 return $this->getThisScript() . 'id=' . ($altId !== '' ? $altId : $this->id);
362 }
363
364 /**
365 * Returning JavaScript for ClipBoard functionality.
366 *
367 * @return string
368 * @todo Define visibility
369 */
370 public function CBfunctions() {
371 return '
372 // checkOffCB()
373 function checkOffCB(listOfCBnames, link) { //
374 var checkBoxes, flag, i;
375 var checkBoxes = listOfCBnames.split(",");
376 if (link.rel === "") {
377 link.rel = "allChecked";
378 flag = true;
379 } else {
380 link.rel = "";
381 flag = false;
382 }
383 for (i = 0; i < checkBoxes.length; i++) {
384 setcbValue(checkBoxes[i], flag);
385 }
386 }
387 // cbValue()
388 function cbValue(CBname) { //
389 var CBfullName = "CBC["+CBname+"]";
390 return (document.dblistForm[CBfullName] && document.dblistForm[CBfullName].checked ? 1 : 0);
391 }
392 // setcbValue()
393 function setcbValue(CBname,flag) { //
394 CBfullName = "CBC["+CBname+"]";
395 if(document.dblistForm[CBfullName]) {
396 document.dblistForm[CBfullName].checked = flag ? "on" : 0;
397 }
398 }
399
400 ';
401 }
402
403 /**
404 * Initializes page languages and icons
405 *
406 * @return void
407 * @todo Define visibility
408 */
409 public function initializeLanguages() {
410 // Look up page overlays:
411 $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');
412 $this->languageIconTitles = $this->getTranslateTools()->getSystemLanguages($this->id, $this->backPath);
413 }
414
415 /**
416 * Return the icon for the language
417 *
418 * @param integer $sys_language_uid Sys language uid
419 * @param boolean $addAsAdditionalText If set to true, only the flag is returned
420 * @return string Language icon
421 * @todo Define visibility
422 */
423 public function languageFlag($sys_language_uid, $addAsAdditionalText = TRUE) {
424 $out = '';
425 $title = htmlspecialchars($this->languageIconTitles[$sys_language_uid]['title']);
426 if ($this->languageIconTitles[$sys_language_uid]['flagIcon']) {
427 $out .= IconUtility::getSpriteIcon($this->languageIconTitles[$sys_language_uid]['flagIcon'], array('title' => $title));
428 if (!$addAsAdditionalText) {
429 return $out;
430 }
431 $out .= '&nbsp;';
432 }
433 $out .= $title;
434 return $out;
435 }
436
437 /**
438 * Gets an instance of TranslationConfigurationProvider
439 *
440 * @return \TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider
441 */
442 protected function getTranslateTools() {
443 if (!isset($this->translateTools)) {
444 $this->translateTools = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Configuration\\TranslationConfigurationProvider');
445 }
446 return $this->translateTools;
447 }
448
449 /**
450 * Generates HTML code for a Reference tooltip out of
451 * sys_refindex records you hand over
452 *
453 * @param array $references array of records from sys_refindex table
454 * @param string $launchViewParameter JavaScript String, which will be passed as parameters to top.launchView
455 * @return string
456 */
457 protected function generateReferenceToolTip(array $references, $launchViewParameter = '') {
458 $result = array();
459 foreach ($references as $reference) {
460 $result[] = $reference['tablename'] . ':' . $reference['recuid'] . ':' . $reference['field'];
461 if (strlen(implode(' / ', $result)) >= 100) {
462 break;
463 }
464 }
465 if (empty($result)) {
466 $htmlCode = '-';
467 } else {
468 $htmlCode = '<a href="#"';
469 if ($launchViewParameter !== '') {
470 $htmlCode .= ' onclick="' . htmlspecialchars(('top.launchView(' . $launchViewParameter . '); return false;')) . '"';
471 }
472 $htmlCode .= ' title="' . htmlspecialchars(GeneralUtility::fixed_lgd_cs(implode(' / ', $result), 100)) . '">';
473 $htmlCode .= count($references);
474 $htmlCode .= '</a>';
475 }
476 return $htmlCode;
477 }
478
479 }