/** * Returns rendered previewer * used player: * http://aktuell.de.selfhtml.org/artikel/grafik/flashmusik/ * http://loudblog.de/index.php?s=download * * @param array $row Meta data array * @param integer $size The maximum size of the previewer * @param string $type The wanted previewer type * @param array $conf Additional configuration values. Might be empty. * @return array True if this is the right previewer for the file */ function render($row, $size, $type, $conf = array()) { $outArr = array('htmlCode' => '', 'headerCode' => ''); $absFile = tx_dam::file_absolutePath($row['file_path'] . $row['file_name']); $siteUrl = t3lib_div::getIndpEnv('TYPO3_SITE_URL'); $fileRelPath = tx_dam::file_relativeSitePath($row['file_path'] . $row['file_name']); $playerRelPath = str_replace(PATH_site, '', PATH_txdam); #$size = 'width="200" height="55"'; #$playerRelPath .= 'res/emff_lila.swf'; $size = 'width="120" height="37"'; $playerRelPath .= 'res/emff_inx.swf'; $outArr['htmlCode'] = '<div class="previewMP3"> <object type="application/x-shockwave-flash" data="' . htmlspecialchars($siteUrl . $playerRelPath) . '?streaming=yes&src=' . htmlspecialchars($siteUrl . t3lib_div::rawUrlEncodeFP($fileRelPath)) . '" ' . $size . '> <param name="movie" value="' . htmlspecialchars($siteUrl . $playerRelPath) . '?streaming=yes&src=' . htmlspecialchars($siteUrl . t3lib_div::rawUrlEncodeFP($fileRelPath)) . '" /> <param name="quality" value="high" /> </object> </div>'; return $outArr; }
/** * delete file when record is deleted */ function processCmdmap_preProcess($command, $table, $id, $value, $tce) { global $FILEMOUNTS, $BE_USER, $TYPO3_CONF_VARS; if ($table === 'tx_dam') { if ($rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'tx_dam', 'uid=' . $id, '', '', 1, 'uid')) { $row = $rows[$id]; switch ($command) { // delete the file when the record is deleted case 'delete': require_once PATH_t3lib . 'class.t3lib_basicfilefunc.php'; require_once PATH_t3lib . 'class.t3lib_extfilefunc.php'; $filepath = tx_dam::file_absolutePath($row); if (@is_file($filepath)) { $cmd = array(); $cmd['delete'][0]['data'] = $filepath; // Initializing: $tce->fileProcessor = t3lib_div::makeInstance('t3lib_extFileFunctions'); $tce->fileProcessor->init($FILEMOUNTS, $TYPO3_CONF_VARS['BE']['fileExtensions']); $tce->fileProcessor->init_actionPerms(tx_dam::getFileoperationPermissions()); $tce->fileProcessor->dontCheckForUnique = $tce->overwriteExistingFiles ? 1 : 0; // Checking referer / executing: $refInfo = parse_url(t3lib_div::getIndpEnv('HTTP_REFERER')); $httpHost = t3lib_div::getIndpEnv('TYPO3_HOST_ONLY'); if ($httpHost != $refInfo['host'] && $tce->vC != $BE_USER->veriCode() && !$TYPO3_CONF_VARS['SYS']['doNotCheckReferer']) { $tce->fileProcessor->writeLog(0, 2, 1, 'Referer host "%s" and server host "%s" did not match!', array($refInfo['host'], $httpHost)); } else { $tce->fileProcessor->start($cmd); $tce->fileProcessor->processData(); } } break; default: break; } } } }
/** * Writing/update the content of textfiles (action=9) * * @param array $cmds['data'] is the new content. $cmds['target'] is the target (file or dir) * @param string $id: ID of the item * @return boolean Returns true on success */ function func_edit($cmds, $id) { if (!$this->isInit) { return FALSE; } $theTarget = tx_dam::file_absolutePath($cmds['target']); $content = $cmds['content'] ? $cmds['content'] : $cmds['data']; $extList = $GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext']; $type = filetype($theTarget); if (!($type == 'file')) { // $type MUST BE file $this->writelog(9, 2, 123, 'Target "%s" was not a file!', array($theTarget), 'edit', $id); return; } $fileInfo = t3lib_div::split_fileref($theTarget); // Fetches info about path, name, extention of $theTarget if (!$this->checkPathAgainstMounts($fileInfo['path'])) { $this->writelog(9, 1, 121, 'Destination path "%s" was not within your mountpoints!', array($fileInfo['path']), 'edit', $id); return; } if (!$this->actionPerms['editFile']) { $this->writelog(9, 1, 104, 'You are not allowed to edit files!', '', 'edit', $id); return; } if (!$this->checkIfAllowed($fileInfo['fileext'], $fileInfo['path'], $fileInfo['file'])) { $this->writelog(9, 1, 103, 'Fileextension "%s" was not allowed!', array($fileInfo['fileext']), 'edit', $id); return; } if (!t3lib_div::inList($extList, $fileInfo['fileext'])) { $this->writelog(9, 1, 102, 'Fileextension "%s" is not a textfile format! (%s)', array($fileInfo['fileext'], $extList), 'edit', $id); return; } if (!t3lib_div::writeFile($theTarget, $content)) { $this->writelog(9, 1, 100, 'File "%s" was not saved! Write-permission problem in "%s"?', array($theTarget, $fileInfo['path']), 'edit', $id); return; } clearstatcache(); $this->writelog(9, 0, 1, 'File saved to "%s", bytes: %s, MD5: %s ', array($fileInfo['file'], @filesize($theTarget), md5($content)), 'edit', $id); return true; }
/** * media->filepath */ public function test_getPathAbsolute() { $fixture = $this->getFixtureMedia(); $filename = $fixture['filename']; $meta = $fixture['meta']; $media = $fixture['media']; $filepath = tx_dam::file_absolutePath($filename); $path = $media->filepath; self::assertEquals($path, $filepath, 'File path differs: ' . $path . ' (' . $filepath . ')'); }
/** * Button: file info popup * * @param mixed $fileInfo Is a file path or an array containing a file info from tx_dam::file_compileInfo(). * @return string Button HTML code * @todo still in use? */ function btn_infoFile($fileInfo) { global $LANG, $BACK_PATH; $filepath = tx_dam::file_absolutePath($fileInfo); $onClick = 'top.launchView(\'' . $filepath . '\',\'\',\'' . $BACK_PATH . '\');return false;'; $aTagAttribute = ' onclick="' . htmlspecialchars($onClick) . '"'; $label = $LANG->sL('LLL:EXT:lang/locallang_core.xml:cm.info', 1); $iconImgTag = '<img' . t3lib_iconWorks::skinImg($BACK_PATH, 'gfx/zoom2.gif', 'width="12" height="12"') . ' alt="" />'; $hoverText = $LANG->sL('LLL:EXT:lang/locallang_mod_web_list.xml:showInfo', 1); $content = tx_dam_SCbase::button($iconImgTag, $label, $hoverText, $url = '#', $aTagAttribute); return $content; }
/** * Returns a command array for the current type * * @return array Command array * @access private */ function _getCommand() { $filepath = tx_dam::file_absolutePath($this->itemInfo); $script = $this->env['defaultCmdScript']; $script .= '?CMD=' . $this->cmd; $script .= '&vC=' . $GLOBALS['BE_USER']->veriCode(); $script .= '&file[]=' . rawurlencode($filepath); if ($this->type === 'context') { $commands['url'] = $script; } else { $script .= '&returnUrl=' . rawurlencode($this->env['returnUrl']); $commands['href'] = $script; } return $commands; }
/** * Returns a command array for the current type * * @return array Command array * @access private */ function _getCommand() { // what we want is to have info about the file // and while DAM registered an info viewer for file we use that instead of the record info view // $commands['onclick'] = 'top.launchView(\''.$this->itemInfo['__table'].'\', \''.$this->itemInfo['uid'].'\'); return false;'; $filename = tx_dam::file_absolutePath($this->itemInfo); $onClick = 'top.launchView(\'' . $filename . '\', \'\');'; if ($this->type === 'context') { $commands['onclick'] = $onClick . ' return hideCM();'; } else { $commands['onclick'] = $onClick . ' return false;'; } return $commands; }
/** * Compiles meta/fielInfo data for file and record items * * @return array Item array. Key is uid or md5 of filepath */ function compileFilesAndRecordsData() { $items = array(); if (count($this->file)) { foreach ($this->file as $filepath) { $fileInfo = tx_dam::file_compileInfo($filepath, true); $meta = tx_dam::meta_getDataForFile($fileInfo, '*'); if (!is_array($meta)) { $fileType = tx_dam::file_getType($filepath); $meta = array_merge($fileInfo, $fileType); $meta['uid'] = 0; } $id = $meta['uid'] ? $meta['uid'] : md5(tx_dam::file_absolutePath($fileInfo)); $items[$id] = array_merge($meta, $fileInfo); } } elseif (count($this->record['tx_dam'])) { foreach ($this->record['tx_dam'] as $uid) { if ($meta = tx_dam::meta_getDataByUid($uid, '*')) { $fileInfo = tx_dam::file_compileInfo($meta, true); $items[$meta['uid']] = array_merge($meta, $fileInfo); } } } return $items; }
/** * Renders the item icon * * @param array $item item array * @return string */ function getItemIcon($item) { static $titleNotIndexed; static $iconNotIndexed; if (!$iconNotIndexed) { $titleNotIndexed = 'title="' . $GLOBALS['LANG']->getLL('fileNotIndexed') . '"'; $iconNotIndexed = '<img' . t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'], 'gfx/required_h.gif', 'width="10" height="10"') . ' ' . $titleNotIndexed . ' alt="" />'; } $type = $item['__type']; if ($type == 'file') { $titleAttr = ''; $attachToIcon = ''; if (!$item['__isIndexed'] and !($uid = tx_dam::file_isIndexed($item))) { $attachToIcon = $iconNotIndexed; $titleAttr = $titleNotIndexed; } $iconTag = tx_dam::icon_getFileTypeImgTag($item, $titleAttr); if ($this->enableContextMenus) { $iconTag = $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($iconTag, tx_dam::file_absolutePath($item)); } $iconTag .= $attachToIcon; } else { $titleAttr = 'title="' . htmlspecialchars($item[$type . '_title']) . '"'; $iconTag = tx_dam::icon_getFileTypeImgTag($item, $titleAttr); if ($this->enableContextMenus) { $iconTag = $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($iconTag, tx_dam::path_makeAbsolute($item)); } } return $iconTag; }
/** * Renders the item icon * * @param array $item item array * @return string */ function getItemIcon(&$item) { static $iconNotExists; if (!$iconNotExists) { $titleNotExists = 'title="' . $GLOBALS['LANG']->getLL('fileNotExists', true) . '"'; $iconNotExists = '<img' . t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'], PATH_txdam_rel . 'i/error_h.gif', 'width="10" height="10"') . ' ' . $titleNotExists . ' alt="" />'; } $titletext = t3lib_BEfunc::getRecordIconAltText($item, $this->table); $itemIcon = tx_dam::icon_getFileTypeImgTag($item, 'title="' . $titletext . '"'); if ($this->enableContextMenus) { $itemIcon = $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($itemIcon, $this->table, $item['uid']); } if (!is_file(tx_dam::file_absolutePath($item))) { $item['file_status'] = TXDAM_status_file_missing; $itemIcon .= $iconNotExists; } return $itemIcon; }
/** * "Finding" the files belonging to tx_dam records. * * @param string The uid of the record from $table * @param string The filename (usually found in field "file_name") * @param array Parameters set for the softref parser key in TCA/columns (currently unused) * @return array Result array on positive matches, containing one or null results */ function findRef_dam_file($uid, $fileName, $spParams) { $resultArray = array(); $fileInfo = tx_dam::meta_getDataByUid($uid, tx_dam_db::getMetaInfoFieldList() . ', description'); if ($fileInfo) { $file = $fileInfo['file_path'] . $fileInfo['file_name']; $tokenID = $this->makeTokenID(0); $resultArray = array('content' => '{softref:' . $tokenID . '}', 'elements' => array(0 => array('matchString' => $fileName, 'subst' => array('type' => 'file', 'tokenID' => $tokenID, 'tokenValue' => $fileName, 'relFileName' => $file, 'title' => $fileInfo['title'], 'description' => $fileInfo['description'])))); if (!@is_file(tx_dam::file_absolutePath($fileInfo))) { // Finally, notice if the file does not exist. $resultArray['elements'][0]['error'] = 'File does not exist!'; } } return $resultArray; }
/** * Returns an array with the names of files in a specific path * * @param string Path to start to collect files. If it is a file itself it will be added to the list too * @param boolean Go recursive into subfolder? * @param array Array of file paths * @return array Array of file paths */ function collectFiles($path, $recursive = false, $filearray = array()) { if ($path) { $pathname = $this->getFilePath($path); $pathname = tx_dam::file_absolutePath($path); if (@is_file($pathname)) { if ($metaFile = $this->getMetaFilePath($path)) { $filearray[md5($pathname)] = array('processFile' => $pathname, 'metaFile' => $metaFile); } else { $filearray[md5($pathname)] = $pathname; } } else { $filearray = $this->getFilesInDir($path, $recursive, $filearray); } } if ($this->writeDevLog) { t3lib_div::devLog('collectFiles(): ' . $path, 'tx_dam_indexing', 0, $filearray); } return $filearray; }
/** * Returns an fixture which is a random already indexed file. * @return mixed Is false when no indexed file available or: array('meta' => $row, 'filename' => $filename) */ protected function getFixtureRandomIndexedFilename() { $select_fields = '*'; #uid,file_name,file_path,file_hash'; $where = array(); $where['deleted'] = 'deleted=0'; $where['pidList'] = 'pid IN (' . tx_dam_db::getPidList() . ')'; $where['file_hash'] = 'file_hash'; $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($select_fields, 'tx_dam', implode(' AND ', $where), '', 'RAND()', 50); while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { if (is_file($filename = tx_dam::file_absolutePath($row))) { return array('meta' => $row, 'filename' => $filename); } } return false; }
/** * Returns a image-tag, URL and attributes for a image preview * * @param mixed $fileInfo Is a file path or an array containing a file info from tx_dam::file_compileInfo(). * @param string $size Optional: $size is [w]x[h] of the image preview. 56 is default. * @param mixed $imgAttributes additional attributes for the image tag * @return array Thumbnail image tag, url and attributes with width/height * @todo calc width/height from cm size or similar when hpixels not available * @todo return false when file is missing? */ function preview($fileInfo, $size = '', $imgAttributes = '') { // get some file information if (!is_array($fileInfo)) { $fileInfo = tx_dam::file_compileInfo($fileInfo); } $filepath = tx_dam::file_absolutePath($fileInfo); if ($filepath and @file_exists($filepath) and @is_file($filepath)) { $fileType = tx_dam::file_getType($fileInfo); if (!tx_dam_image::isPreviewPossible($fileType)) { return array(); } if (!is_array($imgAttributes)) { $imgAttributes = tx_dam_image::tools_explodeAttributes($imgAttributes); } $imgAttributes['alt'] = isset($imgAttributes['alt']) ? $imgAttributes['alt'] : ($fileInfo['alt_text'] ? $fileInfo['alt_text'] : $fileInfo['title']); $imgAttributes['title'] = isset($imgAttributes['title']) ? $imgAttributes['title'] : $imgAttributes['alt']; // Check and parse the size parameter $size = trim($size); list($sizeX, $sizeY) = tx_dam_image::parseSize($size); $sizeMax = $max = max($sizeX, $sizeY); // get maximum image pixel size $maxImageSize = 0; if ($fileInfo['hpixels']) { $maxImageSize = max($fileInfo['hpixels'], $fileInfo['vpixels']); } elseif (t3lib_div::inList('gif,jpg,png', $fileType['file_type'])) { if (is_array($imgInfo = @getimagesize($filepath))) { $fileInfo['hpixels'] = $imgInfo[0]; $fileInfo['vpixels'] = $imgInfo[1]; $maxImageSize = max($fileInfo['hpixels'], $fileInfo['vpixels']); } } // calculate the image preview size $useOriginalImage = false; if ($maxImageSize and $maxImageSize <= $sizeMax) { $useOriginalImage = true; $thumbSizeX = $fileInfo['hpixels']; $thumbSizeY = $fileInfo['vpixels']; $imgAttributes['width'] = $thumbSizeX; $imgAttributes['height'] = $thumbSizeY; } elseif ($maxImageSize) { list($thumbSizeX, $thumbSizeY) = tx_dam_image::calcSize($fileInfo['hpixels'], $fileInfo['vpixels'], $sizeX, $sizeY); $imgAttributes['width'] = $thumbSizeX; $imgAttributes['height'] = $thumbSizeY; $size = $thumbSizeX . 'x' . $thumbSizeY; } elseif (tx_dam_image::isPreviewPossible($fileType)) { $thumbSizeX = $sizeX; $thumbSizeY = $sizeY; $size = $thumbSizeX . 'x' . $thumbSizeY; } else { $thumbSizeX = 0; $thumbSizeY = 0; } $url = ''; $thumbnail = ''; if ($thumbSizeX) { // use the original image if it's size fits to the image preview size if ($useOriginalImage) { if (TYPO3_MODE === 'FE') { $url = preg_replace('#^' . preg_quote(PATH_site) . '#', '', $filepath); } else { $url = $GLOBALS['BACK_PATH'] . '../' . preg_replace('#^' . preg_quote(PATH_site) . '#', '', $filepath); } // use thumbs.php script } else { $check = basename($filepath) . ':' . filemtime($filepath) . ':' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey']; $url = 'thumbs.php?'; $url .= '&file=' . rawurlencode($filepath); $url .= $size ? '&size=' . $size : ''; $url .= '&md5sum=' . t3lib_div::shortMD5($check); $url .= '&dummy=' . $GLOBALS['EXEC_TIME']; if (TYPO3_MODE === 'FE') { $url = TYPO3_mainDir . $url; } else { $url = $GLOBALS['BACK_PATH'] . $url; } } } $imgAttributes = tx_dam_image::tools_implodeAttributes($imgAttributes); $thumbnail = '<img src="' . htmlspecialchars($url) . '"' . $imgAttributes . ' />'; } return array('img' => $thumbnail, 'url' => $url, 'attributes' => $imgAttributes, 'sizeX' => $thumbSizeX, 'sizeY' => $thumbSizeY); }
/** * Returns rendered previewer * * @param array $row Meta data array * @param integer $size The maximum size of the previewer * @param string $type The wanted previewer type * @param array $conf Additional configuration values. Might be empty. * @return array True if this is the right previewer for the file */ function render($row, $size, $type, $conf = array()) { $outArr = array('htmlCode' => '', 'headerCode' => ''); $absFile = tx_dam::file_absolutePath($row['file_path'] . $row['file_name']); if ($row['hpixels'] > 160 or $row['vpixels'] > 160) { $width = $row['hpixels'] > 160 ? 160 : $row['hpixels']; $height = intval($row['vpixels'] * $width / $row['hpixels']); if ($height > 160) { $height = 160; $width = intval($row['hpixels'] * $height / $row['vpixels']); } $widthZoom = $width * 2; $widthZoom = $row['hpixels'] > $widthZoom ? $widthZoom : $row['hpixels']; $margin = 4; $diaPadding = 9; $outArr['headerCode'] = ' <style type="text/css"> /* Photo-Zoom */ /* MSIE z-index work-a-round */ /* reversing natural z-index */ .txdamPZWrapper { position:relative; z-index:900; } /* Mozilla z-index bliss */ .txdamPZWrapper a { z-index:0; } .txdamPZWrapper a:hover { position:absolute; z-index:900; } .txdamPZWrapper .txdamPZ { position:relative; } .txdamPZWrapper .txdamPZ a:hover { border:0; background:none; text-decoration:none; } .txdamPZ a { position:absolute; cursor:default; } .txdamPZ img { align: left; width:' . $width . 'px; height:' . $height . 'px; } /* ZoomOpen Positions */ .txdamPZ a:hover,.txdamPZ a:hover img { width:' . $widthZoom . 'px; height:auto;} .txdamPZWrapper .txdamPZ a:hover { left:-' . ($widthZoom - $width) . 'px; } /*MSIE-specific*/ .txdamPZWrapper>.txdamPZ a:hover { left:-' . ($widthZoom - $width) . 'px; } /*Mozilla-specific*/ /* End Photo-Zoom */ .txdamPZ img { padding:8px; background-color:#fff; border:solid #888 1px; } </style> '; $outArr['htmlCode'] = ' <!-- start Photo-Zoom code --> <div class="txdamPZDummy" style="height:' . ($height + $diaPadding + $diaPadding + $margin + $margin) . 'px; width:' . ($width + $diaPadding + $diaPadding + $margin + $margin) . 'px; "></div> <div class="txdamPZWrapper" style="text-align:left;top:-' . ($height + $diaPadding) . 'px; margin-left:' . $margin . 'px; margin-top:-1em; "> <p class="txdamPZ" > <a href="javascript:void(0)">' . t3lib_BEfunc::getThumbNail('thumbs.php', $absFile, '', $widthZoom) . '</a> </p> </div> <br /> <!-- end Photo-Zoom code --> '; } else { $outArr['htmlCode'] = '<div class="previewThumb">' . t3lib_BEfunc::getThumbNail('thumbs.php', $absFile, ' align="middle" style="border:solid 1px #ccc;"', 160) . '</div>'; } return $outArr; }
/** * tx_dam::file_absolutePath() */ public function test_file_absolutePath() { $GLOBALS['T3_VAR']['ext']['dam']['pathInfoCache'] = array(); $filepath = $this->getFixtureFilename(); $filename = tx_dam::file_basename($filepath); $testpath = tx_dam::file_dirname($filepath); $path = tx_dam::path_makeClean($testpath); $path = tx_dam::path_makeRelative($path); $path = tx_dam::file_absolutePath($path . $filename); self::assertEquals($path, $filepath, 'File path differs: ' . $path . ' (' . $filepath . ')'); $filepath = $this->getFixtureFilename(); $fileinfo = tx_dam::file_compileInfo($filepath, $ignoreExistence = false); $path = tx_dam::file_absolutePath($fileinfo); self::assertEquals($path, $filepath, 'File path differs: ' . $path . ' (' . $filepath . ')'); }
/** * Rendering the copy file form for a multiple items * * @return string HTML content */ function renderFormMulti($items, $targetFolder) { global $BACK_PATH, $LANG, $TCA; $content = ''; $references = 0; // FOLDER_INFO is missing due to missing param in current function - so we set it to nothing $this->pObj->markers['FOLDER_INFO'] = ''; $titleNotExists = 'title="' . $GLOBALS['LANG']->getLL('fileNotExists', true) . '"'; $iconNotExists = '<img' . t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'], PATH_txdam_rel . 'i/error_h.gif', 'width="10" height="10"') . ' ' . $titleNotExists . ' valign="top" alt="" />'; $referencedIcon = '<img' . t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'], PATH_txdam_rel . 'i/is_referenced.gif', 'width="15" height="12"') . ' title="' . $LANG->getLL($this->langPrefix . 'messageReferencesUsed', 1) . '" alt="" />'; // init table layout $tableLayout = array('table' => array('<table cellpadding="2" cellspacing="1" border="0" width="100%">', '</table>'), '0' => array('defCol' => array('<th nowrap="nowrap" class="bgColor5">', '</th>'), '0' => array('<th width="1%" class="bgColor5">', '</th>'), '1' => array('<th width="1%" class="bgColor5">', '</th>'), '3' => array('<th width="1%" class="bgColor5">', '</th>'), '4' => array('<th width="1%" class="bgColor5">', '</th>'), '5' => array('<th width="1%" class="bgColor5">', '</th>')), 'defRow' => array('defCol' => array('<td nowrap="nowrap" class="bgColor4">', '</td>'), '2' => array('<td class="bgColor4">', '</td>'), '3' => array('<td style="text-align:center" class="bgColor4">', '</td>'), '4' => array('<td style="padding:0 5px 0 5px" class="bgColor4">', '</td>'), '5' => array('<td style="text-align:center" class="bgColor4">', '</td>'))); $cTable = array(); $tr = 0; $td = 0; $cTable[$tr][$td++] = ' '; $cTable[$tr][$td++] = ' '; $cTable[$tr][$td++] = $LANG->sL($TCA['tx_dam']['columns']['title']['label'], 1); $cTable[$tr][$td++] = ' '; $cTable[$tr][$td++] = ' '; $cTable[$tr][$td++] = $LANG->sL($TCA['tx_dam']['columns']['file_path']['label'], 1); $tr++; foreach ($items as $id => $meta) { $filepath = tx_dam::file_absolutePath($meta); if ($meta['file_accessable']) { $checkbox = '<input type="checkbox" name="data[' . $this->copyOrMove . '][' . $id . '][data]" value="' . htmlspecialchars($filepath) . '" checked="checked" />'; } else { $checkbox = '<img' . t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'], PATH_txdam_rel . 'i/error_h.gif', 'width="10" height="10"') . ' title="' . $LANG->getLL('accessDenied', true) . '" alt="" />'; } $title = $meta['title'] ? $meta['title'] : $meta['file_name']; $title = t3lib_div::fixed_lgd_cs($title, 50); $icon = tx_dam_guiFunc::icon_getFileTypeImgTag($meta, 'class="c-recicon"', false); if (!@file_exists($filepath)) { $icon .= $iconNotExists; $info = ''; } else { $info = $GLOBALS['SOBE']->btn_infoFile($meta); } // Add row to table $td = 0; $cTable[$tr][$td++] = $checkbox; $cTable[$tr][$td++] = $icon; $cTable[$tr][$td++] = htmlspecialchars($title); $cTable[$tr][$td++] = htmlspecialchars(strtoupper($meta['file_type'])); $cTable[$tr][$td++] = $info; $cTable[$tr][$td++] = htmlspecialchars(t3lib_div::fixed_lgd_cs($meta['file_path'], -15)); $tr++; } $itemTable = $this->pObj->doc->table($cTable, $tableLayout); $targetFolderRel = tx_dam::path_makeRelative($targetFolder); $msg = array(); $msg[] = ' '; $msg[] = $LANG->getLL('labelTargetFolder', 1) . ' <strong>' . htmlspecialchars($targetFolderRel) . '</strong>'; $msg[] = ' '; $msg[] = htmlspecialchars(sprintf($LANG->getLL($this->langPrefix . 'message'), $targetFolderRel)); $msg[] = ' '; $msg[] = $itemTable; $buttons = ' <input type="hidden" name="data[' . $this->copyOrMove . '][' . $id . '][data]" value="' . htmlspecialchars($filepath) . '" /> <input type="hidden" name="data[' . $this->copyOrMove . '][' . $id . '][target]" value="' . htmlspecialchars($targetFolder) . '" />'; if (tx_dam::config_checkValueEnabled('mod.txdamM1_SHARED.displayExtraButtons', 1)) { if ($this->copyOrMove == 'copy') { $buttons .= ' <input type="submit" value="' . $LANG->getLL('tx_dam_cmd_filecopy.submit', 1) . '" /> <input type="submit" value="' . $LANG->sL('LLL:EXT:lang/locallang_core.xml:labels.cancel', 1) . '" onclick="jumpBack(); return false;" />'; } else { $buttons .= ' <input type="submit" value="' . $LANG->getLL('tx_dam_cmd_filemove.submit', 1) . '" /> <input type="submit" value="' . $LANG->sL('LLL:EXT:lang/locallang_core.xml:labels.cancel', 1) . '" onclick="jumpBack(); return false;" />'; } } $this->pObj->docHeaderButtons['SAVE'] = '<input class="c-inputButton" name="_savedok"' . t3lib_iconWorks::skinImg($this->pObj->doc->backPath, 'gfx/clip_copy.gif') . ' title="' . $LANG->getLL($this->langPrefix . 'submit', 1) . '" height="16" type="image" width="16">'; $this->pObj->docHeaderButtons['CLOSE'] = '<a href="#" onclick="jumpBack(); return false;"><img' . t3lib_iconWorks::skinImg($this->pObj->doc->backPath, 'gfx/closedok.gif') . ' class="c-inputButton" title="' . $LANG->sL('LLL:EXT:lang/locallang_core.xml:labels.cancel', 1) . '" alt="" height="16" width="16"></a>'; $content .= $GLOBALS['SOBE']->getMessageBox($GLOBALS['SOBE']->pageTitle, $msg, $buttons, 1); return $content; }
/** * Replace a file with an uploaded file and process indexing and DB update * Important: $meta['uid'] have to be used in the upload data like this $upload_data['upload'][$meta['uid']] * * @param array $meta Meta data array * @param array $upload_data Form upload data for $TCEfile->setCmdmap($upload_data) * @return mixed error message or error array * @see tx_dam_tce_file::getLastError() */ function process_replaceFile($meta, $upload_data, $getFullErrorLogEntry = FALSE) { global $TYPO3_CONF_VARS; $error = false; require_once PATH_txdam . 'lib/class.tx_dam_tce_file.php'; $TCEfile = t3lib_div::makeInstance('tx_dam_tce_file'); $TCEfile->init(); // allow overwrite $TCEfile->fileProcessor->dontCheckForUnique = true; // FIXME overwrite only original file not others // dontCheckForUnique=true allow overwriting any file // dontCheckForUnique have to be false and the file have to be replaced afterwards? if ($id = $meta['uid'] and is_array($upload_data['upload'][$id])) { // Processing uploads $TCEfile->setCmdmap($upload_data); $log = $TCEfile->process(); if ($TCEfile->errors()) { $error = $TCEfile->getLastError(); } else { $newFile = $log['cmd']['upload'][$id]['target_file']; $newFile = tx_dam::file_absolutePath($newFile); $new_filename = tx_dam::file_basename($newFile); // new file name - so we need to update some stuff if ($new_filename !== $meta['file_name']) { // rename meta data fields $fields_values = array(); $fields_values['file_name'] = $new_filename; $fields_values['file_dl_name'] = $new_filename; $fields_values['uid'] = $meta['uid']; tx_dam_db::insertUpdateData($fields_values); // delete the old file $oldFile = tx_dam::file_absolutePath($meta); @unlink($oldFile); if (@is_file($oldFile)) { $error = 'File ' . $meta['file_name'] . ' could not be deleted.'; if ($getFullErrorLogEntry) { $error = array('msg' => $error); } } } // reindex the file $setup = array('recursive' => false, 'doReindexing' => tx_dam::config_checkValueEnabled('setup.indexing.replaceFile.reindexingMode', 2)); tx_dam::index_process($newFile, $setup); } } else { $error = true; } if (!$error) { $info = array('uid' => $meta['uid'], 'new_file' => $newFile, 'old_file' => $oldFile); tx_dam::_callProcessPostTrigger('replaceFile', $info); } return $error; }
/** * Render list of files. * * @param array $filesArray List of files. See tx_dam_db::getReferencedFiles * @param boolean $displayThumbs * @param boolean $disabled * @return string HTML output */ function renderFileList($filesArray, $displayThumbs = true, $disabled = false) { global $LANG; $out = ''; // Listing the files: if (is_array($filesArray) && count($filesArray)) { $lines = array(); foreach ($filesArray['rows'] as $row) { $absFilePath = tx_dam::file_absolutePath($row); $fileExists = @file_exists($absFilePath); $addAttrib = 'class="absmiddle"'; $addAttrib .= tx_dam_guiFunc::icon_getTitleAttribute($row); $iconTag = tx_dam::icon_getFileTypeImgTag($row, $addAttrib); // add clickmenu if ($fileExists && !$disabled) { # $fileIcon = $this->tceforms->getClickMenu($fileIcon, $absFilePath); $iconTag = $this->tceforms->getClickMenu($iconTag, 'tx_dam', $row['uid']); } $title = $row['title'] ? t3lib_div::fixed_lgd_cs($row['title'], $this->tceforms->titleLen) : t3lib_BEfunc::getNoRecordTitle(); // Create link to showing details about the file in a window: if ($fileExists) { #$Ahref = $GLOBALS['BACK_PATH'].'show_item.php?table='.rawurlencode($absFilePath).'&returnUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI')); $onClick = 'top.launchView(\'tx_dam\', \'' . $row['uid'] . '\');'; $onClick = 'top.launchView(\'' . $absFilePath . '\');'; $ATag_info = '<a href="#" onclick="' . htmlspecialchars($onClick) . '">'; $info = $ATag_info . '<img' . t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'], 'gfx/zoom2.gif', 'width="12" height="12"') . ' title="' . $LANG->getLL('info', 1) . '" alt="" /> ' . $LANG->getLL('info', 1) . '</a>'; } else { $info = ' '; } // Thumbnail/size generation: $clickThumb = ''; if ($displayThumbs && $fileExists && tx_dam_image::isPreviewPossible($row)) { $clickThumb = tx_dam_image::previewImgTag($row); $clickThumb = '<div class="clickThumb">' . $clickThumb . '</div>'; } elseif ($displayThumbs) { $clickThumb = '<div style="width:68px"></div>'; } // Show element: $lines[] = ' <tr class="bgColor4"> <td valign="top" nowrap="nowrap" style="min-width:20em">' . $iconTag . htmlspecialchars($title) . ' </td> <td valign="top" nowrap="nowrap" width="1%">' . $info . '</td> </tr>'; $infoText = tx_dam_guiFunc::meta_compileInfoData($row, 'file_name, file_size:filesize, _dimensions, caption:truncate:50', 'table'); $infoText = str_replace('<table>', '<table border="0" cellpadding="0" cellspacing="1">', $infoText); $infoText = str_replace('<strong>', '<strong style="font-weight:normal;">', $infoText); $infoText = str_replace('</td><td>', '</td><td class="bgColor-10">', $infoText); if ($displayThumbs) { $lines[] = ' <tr class="bgColor"> <td valign="top" colspan="2"> <table border="0" cellpadding="0" cellspacing="0"><tr> <td valign="top">' . $clickThumb . '</td> <td valign="top" style="padding-left:1em">' . $infoText . '</td></tr> </table> <div style="height:0.5em;"></div> </td> </tr>'; } else { $lines[] = ' <tr class="bgColor"> <td valign="top" colspan="2" style="padding-left:22px"> ' . $infoText . ' <div style="height:0.5em;"></div> </td> </tr>'; } $lines[] = ' <tr> <td colspan="2"><div style="height:0.5em;"></div></td> </tr>'; } // Wrap all the rows in table tags: $out .= ' <!-- File listing --> <table border="0" cellpadding="1" cellspacing="1"> ' . implode('', $lines) . ' </table>'; } // Return accumulated content for filelisting: return $out; }
/** * Returns a linked image-tag for thumbnail(s) * * @param mixed $fileInfo Is a file path or an array containing a file info from tx_dam::file_compileInfo(). * @param string $size Optional: $size is [w]x[h] of the thumbnail. 56 is default. * @param string $titleContent Optional: Used as a title= attribute content * @param mixed $imgAttributes Optional: is additional attributes for the image tags * @param mixed $iconAttributes Optional: additional attributes for the image tags for file icons * @param string $onClick Optional: If falso no A tag with onclick will be wrapped. If NULL top.launchView() will be used. If string it's value will be used as onclick value. * @param boolean $makeFileIcon If true a file icon will be returned if no thumbnail is possible * @return string Thumbnail image tag. * @deprecated - really? */ function thumbnail($fileInfo, $size = '', $titleContent = '', $imgAttributes = '', $iconAttributes = '', $onClick = NULL, $makeFileIcon = TRUE) { // get some file information if (!is_array($fileInfo)) { $fileInfo = tx_dam::file_compileInfo($fileInfo); } if (!is_array($imgAttributes)) { $imgAttributes = tx_dam_guifunc::tools_explodeAttributes($imgAttributes); } $titleContent = $titleContent ? $titleContent : ($imgAttributes['title'] ? $imgAttributes['title'] : tx_dam_guiFunc::meta_compileHoverText($fileInfo, '', ' - ')); $imgAttributes['title'] = $titleContent; if (!($onClick === false)) { $filepath = tx_dam::file_absolutePath($fileInfo); $imgAttributes['onclick'] = !is_null($onClick) ? $onClick : (TYPO3_MODE === 'BE' ? 'top.launchView(\'' . $filepath . '\',\'\',\'' . $GLOBALS['BACK_PATH'] . '\');return false;' : false); } if ($makeFileIcon) { if (!is_array($iconAttributes)) { $iconAttributes = tx_dam_guifunc::tools_explodeAttributes($iconAttributes); } $iconAttributes['title'] = isset($iconAttributes['title']) ? $iconAttributes['title'] : $titleContent; } $thumbnail = tx_dam_guiFunc::image_thumbnailIconImgTag($fileInfo, $size, $imgAttributes, $iconAttributes, $makeFileIcon); return $thumbnail; }