[TASK] Fix CGL violations against InlineControlStructure
[Packages/TYPO3.CMS.git] / typo3 / class.file_list.inc
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2009 Kasper Skårhøj (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 /**
29 * Class for rendering of File>Filelist
30 *
31 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
32 * @package TYPO3
33 * @subpackage core
34 */
35 class fileList extends t3lib_recordList {
36 // default Max items shown
37 var $iLimit = 40;
38 // Boolean. Thumbnails on records containing files (pictures)
39 var $thumbs = 0;
40 var $widthGif = '<img src="clear.gif" width="1" height="1" hspace="165" alt="" />';
41 // Max length of strings
42 var $fixedL = 30;
43 var $script = '';
44 // If TRUE click menus are generated on files and folders
45 var $clickMenus = 1;
46 // The field to sort by...
47 var $sort = '';
48 // Reverse sorting flag
49 var $sortRev = 1;
50 var $firstElementNumber = 0;
51 var $clipBoard = 0;
52 var $bigControlPanel = 0;
53
54 // internal
55 var $JScode = '';
56 var $HTMLcode = '';
57 var $totalbytes = 0;
58 var $dirs = array();
59 var $files = array();
60 var $path = '';
61
62 /**
63 * @var t3lib_file_Folder
64 */
65 protected $folderObject;
66
67 // Counting the elements no matter what...
68 var $eCounter = 0;
69 var $dirCounter = 0;
70 var $totalItems = '';
71
72 var $CBnames = array();
73
74 /**
75 * Initialization of class
76 *
77 * @param t3lib_file_Folder $folderObject The folder to work on
78 * @param integer $pointer Pointer
79 * @param boolean $sort Sorting column
80 * @param boolean $sortRev Sorting direction
81 * @param boolean $bigControlPanel Show clipboard flag
82 * @return void
83 */
84 function start(t3lib_file_Folder $folderObject, $pointer, $sort, $sortRev, $clipBoard = FALSE, $bigControlPanel = FALSE) {
85
86 $this->script = t3lib_BEfunc::getModuleUrl('file_list');
87 $this->folderObject = $folderObject;
88 $this->counter = 0;
89 $this->totalbytes = 0;
90 $this->JScode = '';
91 $this->HTMLcode = '';
92 $this->path = $folderObject->getIdentifier();
93 $this->sort = $sort;
94 $this->sortRev = $sortRev;
95 $this->firstElementNumber=$pointer;
96 $this->clipBoard = $clipBoard;
97 $this->bigControlPanel = $bigControlPanel;
98 // Setting the maximum length of the filenames to the user's settings or minimum 30 (= $this->fixedL)
99 $this->fixedL = max($this->fixedL, $GLOBALS['BE_USER']->uc['titleLen']);
100
101 $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_common.xml');
102 }
103
104 /**
105 * Reading files and directories, counting elements and generating the list in ->HTMLcode
106 *
107 * @return void
108 */
109 function generateList() {
110 $this->HTMLcode .= $this->getTable('fileext,tstamp,size,rw,_REF_');
111 }
112
113 /**
114 * Return the buttons used by the file list to include in the top header
115 *
116 * @param t3lib_file_Folder $folderObject
117 * @return array
118 */
119 public function getButtonsAndOtherMarkers(t3lib_file_Folder $folderObject) {
120
121 $otherMarkers = array(
122 'PAGE_ICON' => '',
123 'TITLE' => '',
124 );
125
126 $buttons = array(
127 'level_up' => '',
128 'refresh' => '',
129 'title' => '',
130 'page_icon' => '',
131 );
132
133 // Makes the code for the foldericon in the top
134 if ($folderObject) {
135 list($title,$icon,$path) = $this->dirData($folderObject);
136 $title = htmlspecialchars($folderObject->getIdentifier());
137
138 // Start compiling the HTML
139 // @todo: how to fix this? $title = $GLOBALS['SOBE']->basicFF->blindPath($title);
140
141 // If this is some subpage under the mount root....
142 if ($folderObject->getStorage()->isWithinFileMountBoundaries($folderObject)) {
143 // The icon with link
144 $otherMarkers['PAGE_ICON'] = t3lib_iconWorks::getSpriteIcon($icon, array('title' => $title));
145
146 $buttons['level_up'] = $this->linkWrapDir(t3lib_iconWorks::getSpriteIcon('actions-view-go-up', array('title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.upOneLevel', 1))), $folderObject);
147 // No HTML specialchars here - HTML like <strong> </strong> is allowed
148 $otherMarkers['TITLE'] .= t3lib_div::removeXSS(t3lib_div::fixed_lgd_cs($title, -($this->fixedL+20)));
149
150 } else {
151 // This is the root page
152 $otherMarkers['PAGE_ICON'] = t3lib_iconWorks::getSpriteIcon('apps-filetree-root');
153 $otherMarkers['TITLE'] .= htmlspecialchars(t3lib_div::fixed_lgd_cs($title, - ($this->fixedL + 20)));
154 }
155
156 if ($this->clickMenus) {
157 $otherMarkers['PAGE_ICON'] = $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($otherMarkers['PAGE_ICON'], $folderObject->getCombinedIdentifier());
158 }
159 }
160
161 $buttons['refresh'] = '<a href="'.htmlspecialchars($this->listURL()).'" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.reload', 1) . '">'.
162 t3lib_iconWorks::getSpriteIcon('actions-system-refresh') .
163 '</a>';
164
165 return array($buttons, $otherMarkers);
166 }
167
168 /**
169 * Wrapping input string in a link with clipboard command.
170 *
171 * @param string $string String to be linked - must be htmlspecialchar'ed / prepared before.
172 * @param string $table table - NOT USED
173 * @param string $cmd "cmd" value
174 * @param string $warning Warning for JS confirm message
175 * @return string Linked string
176 */
177 function linkClipboardHeaderIcon($string, $table, $cmd, $warning = '') {
178 $onClickEvent = 'document.dblistForm.cmd.value=\''.$cmd.'\';document.dblistForm.submit();';
179 if ($warning) {
180 $onClickEvent = 'if (confirm('.$GLOBALS['LANG']->JScharCode($warning).')){'.$onClickEvent.'}';
181 }
182 return '<a href="#" onclick="'.htmlspecialchars($onClickEvent).'return false;">'.$string.'</a>';
183 }
184
185 /**
186 * Returns a table with directories and files listed.
187 *
188 * @param array $rowlist Array of files from path
189 * @return string HTML-table
190 */
191 function getTable($rowlist) {
192
193 // TODO use folder methods directly when they support filters
194 $storage = $this->folderObject->getStorage();
195 $storage->resetFileAndFolderNameFiltersToDefault();
196
197 $folders = $storage->getFolderList($this->folderObject->getIdentifier());
198 $files = $storage->getFileList($this->folderObject->getIdentifier());
199
200
201 // Only render the contents of a browsable storage
202 if ($this->folderObject->getStorage()->isBrowsable()) {
203
204 $this->sort = trim($this->sort);
205 if ($this->sort !== '') {
206 $filesToSort = array();
207 foreach ($files as $file) {
208 $fileObject = $storage->getFile($file['identifier']);
209
210 switch ($this->sort) {
211 case 'size':
212 $sortingKey = $fileObject->getSize();
213 break;
214 case 'rw':
215 $sortingKey = $fileObject->checkActionPermission('read') ? 'R' : ''
216 . $fileObject->checkActionPermission('write') ? 'W' : '';
217 break;
218 case 'fileext':
219 $sortingKey = $fileObject->getExtension();
220 break;
221 case 'tstamp':
222 $sortingKey = $fileObject->getModificationTime();
223 break;
224 default:
225 if($fileObject->hasProperty($this->sort)) {
226 $sortingKey = $fileObject->getProperty($this->sort);
227 } else {
228 $sortingKey = $fileObject->getName();
229 }
230 }
231 $i = 0;
232 while (isset($filesToSort[$sortingKey . $i])) {
233 $i++;
234 }
235 $filesToSort[$sortingKey . $i] = $fileObject;
236 }
237 if (intval($this->sortRev) === 1) {
238 krsort($filesToSort);
239 } else {
240 ksort($filesToSort);
241 }
242
243 $files = $filesToSort;
244 }
245 $this->totalItems = count($folders) + count($files);
246
247 // Adds the code of files/dirs
248 $out = '';
249 $titleCol = 'file';
250 // @todo: fix this: go up one level with FAL
251 // $upLevelDir = dirname(substr($files['files'][0]['path'], 0, -1)) . '/';
252 // $levelUp = $GLOBALS['SOBE']->basicFF->checkPathAgainstMounts($upLevelDir) ? $this->linkWrapDir(t3lib_iconWorks::getSpriteIcon('actions-view-go-up', array('title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.upOneLevel', TRUE))), $upLevelDir) : '';
253
254 // Cleaning rowlist for duplicates and place the $titleCol as the first column always!
255 $rowlist = t3lib_div::rmFromList($titleCol, $rowlist);
256 $rowlist = t3lib_div::uniqueList($rowlist);
257 $rowlist = $rowlist ? $titleCol.','.$rowlist : $titleCol;
258 if ($this->bigControlPanel || $this->clipBoard) {
259 $rowlist = str_replace('file,', 'file,_CLIPBOARD_,', $rowlist);
260 }
261 $this->fieldArray = explode(',', $rowlist);
262
263 $folderObjects = array();
264 foreach ($folders as $folder) {
265 $folderObjects[] = $storage->getFolder($folder['identifier']);
266 }
267
268 // Directories are added
269 $iOut = $this->formatDirList($folderObjects);
270
271 if ($iOut) {
272 // Half line is drawn
273 $theData = array(
274 $titleCol => ''
275 );
276 }
277
278 // Files are added
279 $iOut .= $this->formatFileList($files, $titleCol);
280
281
282 // Header line is drawn
283 $theData = array();
284
285 foreach ($this->fieldArray as $v) {
286 if ($v == '_CLIPBOARD_' && $this->clipBoard) {
287 $cells = array();
288 $table = '_FILE';
289 $elFromTable = $this->clipObj->elFromTable($table);
290 if (count($elFromTable)) {
291 $cells[] = '<a href="' . htmlspecialchars($this->clipObj->pasteUrl('_FILE', $this->folderObject->getCombinedIdentifier())) . '" onclick="return ' . htmlspecialchars($this->clipObj->confirmMsg('_FILE', $this->path, 'into', $elFromTable)) . '" title="' . $GLOBALS['LANG']->getLL('clip_paste', 1) . '">' .
292 t3lib_iconWorks::getSpriteIcon('actions-document-paste-after') .
293 '</a>';
294 }
295 if ($this->clipObj->current!='normal' && $iOut) {
296 $cells[]=$this->linkClipboardHeaderIcon(t3lib_iconWorks::getSpriteIcon('actions-edit-copy', array('title' => $GLOBALS['LANG']->getLL('clip_selectMarked', 1))), $table, 'setCB');
297 $cells[]=$this->linkClipboardHeaderIcon(t3lib_iconWorks::getSpriteIcon('actions-edit-delete', array('title' => $GLOBALS['LANG']->getLL('clip_deleteMarked'))), $table, 'delete', $GLOBALS['LANG']->getLL('clip_deleteMarkedWarning'));
298 $onClick = 'checkOffCB(\'' . implode(',', $this->CBnames) . '\', this); return false;';
299 $cells[] = '<a class="cbcCheckAll" rel="" href="#" onclick="' . htmlspecialchars($onClick) . '" title="' . $GLOBALS['LANG']->getLL('clip_markRecords', TRUE) . '">' .
300 t3lib_iconWorks::getSpriteIcon('actions-document-select').
301 '</a>';
302 }
303 $theData[$v] = implode('', $cells);
304 } else { // Normal row:
305 $theT = $this->linkWrapSort($GLOBALS['LANG']->getLL('c_' . $v, 1), $this->folderObject->getCombinedIdentifier(), $v);
306 $theData[$v] = $theT;
307 }
308 }
309 $out .= '<thead>' . $this->addelement(1, $levelUp, $theData, ' class="t3-row-header"', '') . '</thead>';
310 $out .= '<tbody>' . $iOut . '</tbody>';
311
312 // half line is drawn
313
314 // finish
315 $out = '
316
317
318 <!--
319 File list table:
320 -->
321 <table cellpadding="0" cellspacing="0" id="typo3-filelist">
322 '.$out.'
323 </table>';
324 } else {
325 /** @var $flashMessage t3lib_FlashMessage */
326 $flashMessage = t3lib_div::makeInstance(
327 't3lib_FlashMessage',
328 $GLOBALS['LANG']->getLL('storageNotBrowsableMessage'),
329 $GLOBALS['LANG']->getLL('storageNotBrowsableTitle'),
330 t3lib_FlashMessage::INFO
331 );
332 $out = $flashMessage->render();
333 }
334
335 return $out;
336 }
337
338 /**
339 * Gets the number of files and total size of a folder
340 *
341 * @return string
342 **/
343 function getFolderInfo() {
344 if($this->counter == 1) {
345 $fileLabel = $GLOBALS['LANG']->getLL('file', TRUE);
346 } else {
347 $fileLabel = $GLOBALS['LANG']->getLL('files', TRUE);
348 }
349 return $this->counter . ' ' . $fileLabel . ', ' . t3lib_div::formatSize($this->totalbytes, $GLOBALS['LANG']->getLL('byteSizeUnits', TRUE));
350 }
351
352 /**
353 * This returns tablerows for the directories in the array $items['sorting'].
354 *
355 * @param t3lib_file_Folder[] $folders Folders of t3lib_file_Folder
356 * @return string HTML table rows.
357 */
358 function formatDirList(array $folders) {
359 $out = '';
360
361 foreach ($folders as $folderObject) {
362 list($flag, $code) = $this->fwd_rwd_nav();
363 $out .= $code;
364 if ($flag) {
365 // Initialization
366 $this->counter++;
367
368 list($title, $icon, $path) = $this->dirData($folderObject);
369
370 // The icon with link
371 $theIcon = t3lib_iconWorks::getSpriteIconForFile('folder', array('title' => $title));
372 if ($this->clickMenus) {
373 $theIcon = $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($theIcon, $folderObject->getCombinedIdentifier());
374 }
375
376 // Preparing and getting the data-array
377 $theData = array();
378 foreach ($this->fieldArray as $field) {
379 switch($field) {
380 case 'size':
381 $numFiles = $folderObject->getFileCount();
382 $theData[$field] = $numFiles . ' ' . $GLOBALS['LANG']->getLL(($numFiles === 1 ? 'file' : 'files'), TRUE);
383 break;
384 case 'rw':
385 $theData[$field] = (!$folderObject->checkActionPermission('read') ? ' ' : '<span class="typo3-red"><strong>' . $GLOBALS['LANG']->getLL('read', TRUE) . '</strong></span>')
386 . (!$folderObject->checkActionPermission('write') ? '' : '<span class="typo3-red"><strong>' . $GLOBALS['LANG']->getLL('write', TRUE) . '</strong></span>');
387 break;
388 case 'fileext':
389 $theData[$field] = $GLOBALS['LANG']->getLL('folder', TRUE);
390 break;
391 case 'tstamp':
392 // @todo: FAL: how to get the mtime info -- $theData[$field] = t3lib_BEfunc::date($theFile['tstamp']);
393 $theData[$field] = '-';
394 break;
395 case 'file':
396 $theData[$field] = $this->linkWrapDir($title, $folderObject);
397 break;
398 case '_CLIPBOARD_':
399 $temp = '';
400 if ($this->bigControlPanel) {
401 $temp .= $this->makeEdit($folderObject);
402 }
403 $temp .= $this->makeClip($folderObject);
404 $theData[$field] = $temp;
405 break;
406 case '_REF_':
407 $theData[$field] = $this->makeRef($folderObject);
408 break;
409 default:
410 $theData[$field] = t3lib_div::fixed_lgd_cs($theFile[$field], $this->fixedL);
411 break;
412 }
413 }
414
415 $out .= $this->addelement(1, $theIcon, $theData, ' class="file_list_normal"');
416 }
417 $this->eCounter++;
418 $this->dirCounter = $this->eCounter;
419 }
420 return $out;
421 }
422
423 /**
424 * Wraps the directory-titles
425 *
426 * @param string $title String to be wrapped in links
427 * @param t3lib_file_Folder $folderObject Folder to work on
428 * @return string HTML
429 */
430 function linkWrapDir($title, t3lib_file_Folder $folderObject) {
431 $href = $this->backPath . $this->script . '?id=' . rawurlencode($folderObject->getCombinedIdentifier());
432 $onclick = ' onclick="'.htmlspecialchars('top.content.nav_frame.hilight_row("file","folder' . t3lib_div::md5int($folderObject->getCombinedIdentifier()) . '_"+top.fsMod.currentBank)') . '"';
433
434 // Sometimes $code contains plain HTML tags. In such a case the string should not be modified!
435 if (!strcmp($title, strip_tags($title))) {
436 return '<a href="'.htmlspecialchars($href).'"'.$onclick.' title="'.htmlspecialchars($title).'">'.t3lib_div::fixed_lgd_cs($title, $this->fixedL).'</a>';
437 } else {
438 return '<a href="'.htmlspecialchars($href).'"'.$onclick.'>' . $title . '</a>';
439 }
440 }
441
442 /**
443 * Wraps filenames in links which opens them in a window IF they are in web-path.
444 *
445 * @param string $code String to be wrapped in links
446 * @param t3lib_file_File $fileObject File to be linked
447 * @return string HTML
448 */
449 function linkWrapFile($code, t3lib_file_File $fileObject) {
450 $fileUrl = $fileObject->getPublicUrl(TRUE);
451 if ($fileUrl) {
452 $aOnClick = "return top.openUrlInWindow('" . $fileUrl . "', 'WebFile');";
453 $code = '<a href="#" title="' . htmlspecialchars($code) . '" onclick="' . htmlspecialchars($aOnClick) . '">' . t3lib_div::fixed_lgd_cs($code, $this->fixedL) . '</a>';
454 }
455 return $code;
456 }
457
458 /**
459 * Returns list URL; This is the URL of the current script with id and imagemode parameters, thats all.
460 * The URL however is not relative (with the backpath), otherwise t3lib_div::sanitizeLocalUrl() would say that
461 * the URL would be invalid
462 *
463 * @return string URL
464 */
465 function listURL() {
466 return t3lib_div::linkThisScript(array(
467 'target' => rawurlencode($this->folderObject->getCombinedIdentifier()),
468 'imagemode' => $this->thumbs
469 ));
470 }
471
472 /**
473 * Returns some data specific for the directories...
474 *
475 * @param t3lib_file_Folder $folderObject File information array
476 * @return array (title, icon, path)
477 */
478 function dirData(t3lib_file_Folder $folderObject) {
479 $title = htmlspecialchars($folderObject->getName());
480 $icon = 'apps-filetree-folder-default';
481
482 if ($title == '_temp_') {
483 $icon = 'apps-filetree-folder-temp';
484 $title = '<strong>' . $GLOBALS['LANG']->getLL('temp', TRUE) . '</strong>';
485 }
486
487 if ($title == '_recycler_') {
488 $icon = 'apps-filetree-folder-recycler';
489 $title = '<strong>' . $GLOBALS['LANG']->getLL('recycler', TRUE) . '</strong>';
490 }
491
492 // Mark the icon as read-only icon if the folder is not writable
493 if ($folderObject->checkActionPermission('write') === FALSE) {
494 $icon = 'apps-filetree-folder-locked';
495 }
496 return array($title, $icon, $folderObject->getIdentifier());
497 }
498
499 /**
500 * This returns tablerows for the files in the array $items['sorting'].
501 *
502 * @param t3lib_file_File[] $files File items
503 * @return string HTML table rows.
504 */
505 function formatFileList(array $files) {
506 $out = '';
507
508 foreach ($files as $fileObject) {
509 list($flag, $code) = $this->fwd_rwd_nav();
510 $out .= $code;
511 if ($flag) {
512 // Initialization
513 $this->counter++;
514 $fileInfo = $fileObject->getStorage()->getFileInfo($fileObject);
515
516 $this->totalbytes += $fileObject->getSize();
517 $ext = $fileObject->getExtension();
518 $fileName = trim($fileObject->getName());
519
520 // The icon with link
521 $theIcon = t3lib_iconWorks::getSpriteIconForFile($ext, array('title' => $fileName));
522
523 if ($this->clickMenus) {
524 $theIcon = $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($theIcon, $fileObject->getCombinedIdentifier());
525 }
526
527 // Preparing and getting the data-array
528 $theData = array();
529 foreach ($this->fieldArray as $field) {
530 switch ($field) {
531 case 'size':
532 $theData[$field] = t3lib_div::formatSize($fileObject->getSize(), $GLOBALS['LANG']->getLL('byteSizeUnits', TRUE));
533 break;
534 case 'rw':
535 $theData[$field] = '' .
536 (!$fileObject->checkActionPermission('read') ? ' ' : '<span class="typo3-red"><strong>' . $GLOBALS['LANG']->getLL('read', TRUE) . '</strong></span>') .
537 (!$fileObject->checkActionPermission('write') ? '' : '<span class="typo3-red"><strong>' . $GLOBALS['LANG']->getLL('write', TRUE) . '</strong></span>');
538 break;
539 case 'fileext':
540 $theData[$field] = strtoupper($ext);
541 break;
542 case 'tstamp':
543 $theData[$field] = t3lib_BEfunc::date($fileInfo['mtime']);
544 break;
545 case '_CLIPBOARD_':
546 $temp = '';
547 if ($this->bigControlPanel) {
548 $temp .= $this->makeEdit($fileObject);
549 }
550 $temp .= $this->makeClip($fileObject);
551 $theData[$field] = $temp;
552 break;
553 case '_REF_':
554 $theData[$field] = $this->makeRef($fileObject);
555 break;
556 case 'file':
557 $theData[$field] = $this->linkWrapFile(htmlspecialchars($fileName), $fileObject);
558
559 // Thumbnails?
560 if ($this->thumbs && $this->isImage($ext)) {
561 $processedFile = $fileObject->process(t3lib_file_ProcessedFile::CONTEXT_IMAGEPREVIEW, array());
562 if ($processedFile) {
563 $thumbUrl = $processedFile->getPublicUrl(TRUE);
564 $theData[$field] .= '<br /><img src="' . $thumbUrl . '" hspace="2" title="' . htmlspecialchars($fileName) . '" alt="" />';
565 }
566 }
567 break;
568 default:
569 // @todo: fix the access on the array
570 $theData[$field]= htmlspecialchars(t3lib_div::fixed_lgd_cs($theFile[$field], $this->fixedL));
571 break;
572 }
573 }
574
575 $out .= $this->addelement(1, $theIcon, $theData, ' class="file_list_normal"');
576 }
577 $this->eCounter++;
578 }
579 return $out;
580 }
581
582 /**
583 * Returns TRUE if $ext is an image-extension according to $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
584 *
585 * @param string $ext File extension
586 * @return boolean
587 */
588 function isImage($ext) {
589 return t3lib_div::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], strtolower($ext));
590 }
591
592 /**
593 * Wraps the directory-titles ($code) in a link to filelist/mod1/index.php (id=$path) and sorting commands...
594 *
595 * @param string $code String to be wrapped
596 * @param string $folderIdentifier ID (path)
597 * @param string $col Sorting column
598 * @return string HTML
599 */
600 function linkWrapSort($code, $folderIdentifier, $col) {
601 // reverse sorting
602 if ($this->sort == $col && !$this->sortRev) {
603 $params='&SET[sort]=' . $col . '&SET[reverse]=1';
604 } else {
605 $params='&SET[sort]=' . $col . '&SET[reverse]=0';
606 }
607 $href = t3lib_div::resolveBackPath($GLOBALS['BACK_PATH'] . $this->script) . '?id=' . rawurlencode($folderIdentifier) . $params;
608 return '<a href="'.htmlspecialchars($href).'">'.$code.'</a>';
609 }
610
611 /**
612 * Creates the clipboard control pad
613 *
614 * @param t3lib_file_File|t3lib_file_Folder $fileOrFolderObject Array with information about the file/directory for which to make the clipboard panel for the listing.
615 * @return string HTML-table
616 */
617 function makeClip($fileOrFolderObject) {
618 $cells = array();
619 $fullIdentifier = $fileOrFolderObject->getCombinedIdentifier();
620 $md5 = t3lib_div::shortmd5($fullIdentifier);
621
622 // For normal clipboard, add copy/cut buttons:
623 if ($this->clipObj->current == 'normal') {
624 $isSel = $this->clipObj->isSelected('_FILE', $md5);
625 $cells[]='<a href="' . htmlspecialchars($this->clipObj->selUrlFile($fullIdentifier, 1, ($isSel == 'copy'))) . '">' .
626 t3lib_iconWorks::getSpriteIcon('actions-edit-copy' . ($isSel == 'copy' ? '-release' : ''), array('title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:cm.copy', 1))) .
627 '</a>';
628 $cells[]='<a href="' . htmlspecialchars($this->clipObj->selUrlFile($fullIdentifier, 0, ($isSel == 'cut'))) . '">' .
629 t3lib_iconWorks::getSpriteIcon('actions-edit-cut' . ($isSel == 'cut' ? '-release' : ''), array('title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:cm.cut', 1))) .
630 '</a>';
631 } else { // For numeric pads, add select checkboxes:
632 $n = '_FILE|'.$md5;
633 $this->CBnames[] = $n;
634
635 $checked = ($this->clipObj->isSelected('_FILE', $md5) ? ' checked="checked"' : '');
636 $cells[] = '<input type="hidden" name="CBH['.$n.']" value="0" />'.
637 '<input type="checkbox" name="CBC[' . $n . ']" value="' . htmlspecialchars($fullIdentifier) . '" class="smallCheckboxes"' . $checked . ' />';
638 }
639
640 // Display PASTE button, if directory:
641 $elFromTable = $this->clipObj->elFromTable('_FILE');
642 if (is_a($fileOrFolderObject, 't3lib_file_Folder') && count($elFromTable)) {
643 $cells[] = '<a href="' . htmlspecialchars($this->clipObj->pasteUrl('_FILE', $fullIdentifier)) . '" onclick="return ' . htmlspecialchars($this->clipObj->confirmMsg('_FILE', $fullIdentifier, 'into', $elFromTable)) . '" title="' . $GLOBALS['LANG']->getLL('clip_pasteInto', TRUE) . '">' .
644 t3lib_iconWorks::getSpriteIcon('actions-document-paste-into') .
645 '</a>';
646 }
647
648 // Compile items into a DIV-element:
649 return ' <!-- CLIPBOARD PANEL: -->
650 <div class="typo3-clipCtrl">
651 ' . implode('
652 ', $cells) . '
653 </div>';
654 }
655
656 /**
657 * Creates the edit control section
658 *
659 * @param t3lib_file_File|t3lib_file_Folder $fileOrFolderObject Array with information about the file/directory for which to make the edit control section for the listing.
660 * @return string HTML-table
661 */
662 function makeEdit($fileOrFolderObject) {
663 $cells = array();
664 $fullIdentifier = $fileOrFolderObject->getCombinedIdentifier();
665
666 // Edit metadata of file
667 try {
668 if (is_a($fileOrFolderObject, 't3lib_file_File') && $fileOrFolderObject->isIndexed() && $fileOrFolderObject->checkActionPermission('edit')) {
669 $data = array(
670 'sys_file' => array($fileOrFolderObject->getUid() => 'edit')
671 );
672 $editOnClick = t3lib_BEfunc::editOnClick(t3lib_div::implodeArrayForUrl('edit', $data), $GLOBALS['BACK_PATH'], $this->listUrl());
673 $cells['editmetadata'] = '<a href="#" onclick="' . $editOnClick . '" title="Edit Metadata of this file">' . t3lib_iconWorks::getSpriteIcon('actions-document-open') . '</a>';
674 } else{
675 $cells['editmetadata'] = t3lib_iconWorks::getSpriteIcon('empty-empty');
676 }
677 } catch (Exception $e) {
678 $cells['editmetadata'] = t3lib_iconWorks::getSpriteIcon('empty-empty');
679 }
680
681 // Edit file content (if editable)
682 if (is_a($fileOrFolderObject, 't3lib_file_File') && $fileOrFolderObject->checkActionPermission('edit') && t3lib_div::inList($GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'], $fileOrFolderObject->getExtension())) {
683 $editOnClick = 'top.content.list_frame.location.href=top.TS.PATH_typo3+\'file_edit.php?target=' .
684 rawurlencode($fullIdentifier) .
685 '&returnUrl=\'+top.rawurlencode(top.content.list_frame.document.location.pathname+top.content.list_frame.document.location.search);return false;';
686 $cells['edit'] = '<a href="#" onclick="' . $editOnClick . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:cm.edit') . '">' . t3lib_iconWorks::getSpriteIcon('actions-page-open') . '</a>';
687 } else {
688 $cells['edit'] = t3lib_iconWorks::getSpriteIcon('empty-empty');
689 }
690
691 // rename the file
692 if ($fileOrFolderObject->checkActionPermission('rename')) {
693 $renameOnClick = 'top.content.list_frame.location.href = top.TS.PATH_typo3+\'file_rename.php?target=' .
694 rawurlencode($fullIdentifier) .
695 '&returnUrl=\'+top.rawurlencode(top.content.list_frame.document.location.pathname+top.content.list_frame.document.location.search);return false;';
696
697 $cells['rename'] = '<a href="#" onclick="' . $renameOnClick . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:cm.rename') . '">' . t3lib_iconWorks::getSpriteIcon('actions-edit-rename') . '</a>';
698 } else {
699 $cells['rename'] = t3lib_iconWorks::getSpriteIcon('empty-empty');
700 }
701
702 if (is_a($fileOrFolderObject, 't3lib_file_Folder')) {
703 $infoOnClick = 'top.launchView( \'_FOLDER\', \'' . $fullIdentifier . '\');return false;';
704 } elseif (is_a($fileOrFolderObject, 't3lib_file_File')) {
705 $infoOnClick = 'top.launchView( \'_FILE\', \'' . $fullIdentifier . '\');return false;';
706 }
707
708 $cells['info'] = '<a href="#" onclick="' . $infoOnClick . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:cm.info') . '">' . t3lib_iconWorks::getSpriteIcon('status-dialog-information') . '</a>';
709 // Hook for manipulating edit icons.
710 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['fileList']['editIconsHook'])) {
711 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['fileList']['editIconsHook'] as $classData) {
712 $hookObject = t3lib_div::getUserObj($classData);
713
714 if (!($hookObject instanceof fileList_editIconHook)) {
715 throw new UnexpectedValueException('$hookObject must implement interface fileList_editIconHook', 1235225797);
716 }
717
718 $hookObject->manipulateEditIcons($cells, $this);
719 }
720 }
721
722 // Compile items into a DIV-element:
723 return ' <!-- EDIT CONTROLS: -->
724 <div class="typo3-editCtrl">
725 ' . implode('
726 ', $cells).'
727 </div>';
728 }
729
730 /**
731 * Make reference count
732 *
733 * @param t3lib_file_File|t3lib_file_Folder $fileOrFolderObject Array with information about the file/directory for which to make the clipboard panel for the listing.
734 * @return string HTML
735 */
736 function makeRef($fileOrFolderObject) {
737 if ($fileOrFolderObject instanceof t3lib_file_FolderInterface) {
738 return '-';
739 }
740
741 // Look up the path:
742 $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
743 '*',
744 'sys_refindex',
745 'ref_table = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr('sys_file', 'sys_refindex') .
746 ' AND ref_uid = ' . $fileOrFolderObject->getUid() . ' AND deleted=0'
747 );
748
749 // Compile information for title tag:
750 $infoData = array();
751 if (is_array($rows)) {
752 foreach ($rows as $row) {
753 $infoData[] = $row['tablename'] . ':' . $row['recuid'] . ':' . $row['field'];
754 }
755 }
756
757 return count($infoData) ? '<a href="#" onclick="' . htmlspecialchars('top.launchView( \'_FILE\', \'' . $fileOrFolderObject->getCombinedIdentifier() . '\'); return false;') . '" title="' . htmlspecialchars(t3lib_div::fixed_lgd_cs(implode(' / ', $infoData), 100)) . '">' . count($infoData) . '</a>' : '-';
758 }
759 }
760 ?>