/**
  * media->getType()
  */
 public function test_getType()
 {
     $fixture = $this->getFixtureMedia();
     $filename = $fixture['filename'];
     $meta = $fixture['meta'];
     $media = $fixture['media'];
     $typeFile = tx_dam::file_getType($filename);
     $type = $media->getType();
     self::assertEquals($type, $typeFile['file_type'], 'Wrong file type: ' . $type . ' (' . $typeFile['file_type'] . ')');
 }
 /**
  * Returns an array with file/dir items + an array with the sorted items
  *
  * @param	string		Path (absolute) to read
  * @param	mixed		$allowTypes List or array of allow directory entry types: file, dir, link. Empty is all kinds of stuff.
  * @return	void
  */
 function read($path, $allowTypes = 'file')
 {
     $allowTypes = is_array($allowTypes) ? $allowTypes : t3lib_div::trimExplode(',', $allowTypes, true);
     if ($path) {
         $tempArray = array();
         $path = tx_dam::path_makeAbsolute($path);
         if (is_object($d = @dir($path))) {
             while ($entry = $d->read()) {
                 $filepath = $path . $entry;
                 // check for allow file types: eg. file, dir, link
                 if (@file_exists($filepath) && (!$allowTypes || in_array($type = filetype($filepath), $allowTypes))) {
                     // if filename matches exclude list this file is skipped
                     foreach ($this->excludeRegex as $expr) {
                         if (preg_match($expr, $entry)) {
                             continue 2;
                         }
                     }
                     // if filename don't matches allow list this file is skipped
                     foreach ($this->allowRegex as $expr) {
                         if (!preg_match($expr, $entry)) {
                             continue 2;
                         }
                     }
                     if ($type === 'file') {
                         $fileInfo = tx_dam::file_compileInfo($filepath);
                         if (is_array($meta = tx_dam::meta_getDataForFile($fileInfo))) {
                             // the newer stat data will be merged over the stored meta data
                             $fileInfo = array_merge($meta, $fileInfo);
                         } else {
                             $mimeType = tx_dam::file_getType($filepath);
                             $fileInfo = array_merge($fileInfo, $mimeType);
                         }
                         if (count($this->excludeFileTypes) and in_array($fileInfo['file_type'], $this->excludeFileTypes)) {
                             continue;
                         }
                         if (count($this->allowFileTypes) and !in_array($fileInfo['file_type'], $this->allowFileTypes)) {
                             continue;
                         }
                         if ($this->enableAutoIndexing) {
                             $this->autoIndex($fileInfo);
                         }
                     } elseif ($type === 'dir' or $type === 'link') {
                         $fileInfo = tx_dam::path_compileInfo($filepath);
                     }
                     // the file is valid so we add it to the list
                     $this->entries[] = $fileInfo;
                     $this->countBytes += $fileInfo['file_size'];
                 }
             }
             $d->close();
             $this->sort();
             $this->rewind();
         }
     }
 }
 /**
  * Main function, rendering the content of the rename form
  *
  * @return	void
  */
 function main()
 {
     global $LANG;
     $content = '';
     // Cleaning and checking target
     if ($this->pObj->file[0]) {
         $this->file = tx_dam::file_compileInfo($this->pObj->file[0]);
         $this->meta = tx_dam::meta_getDataForFile($this->file);
     } elseif ($id = intval($this->pObj->record['tx_dam'][0])) {
         $this->meta = tx_dam::meta_getDataByUid($id);
         $this->file = tx_dam::file_compileInfo($this->meta);
     }
     if (!is_array($this->meta)) {
         $fileType = tx_dam::file_getType($this->file);
         $this->meta = array_merge($this->file, $fileType);
         $this->meta['uid'] = 0;
     }
     if ($this->file['file_accessable']) {
         if (is_array($this->pObj->data) and $this->pObj->data['upload']) {
             $error = tx_dam::process_replaceFile($this->meta, $this->pObj->data);
             if ($error) {
                 $content .= $GLOBALS['SOBE']->getMessageBox($LANG->getLL('error'), htmlspecialchars($error), $this->pObj->buttonBack(0), 2);
             } else {
                 $this->pObj->redirect();
             }
         } else {
             $content .= $this->renderForm();
         }
     } else {
         // this should have happen in index.php already
         $content .= $this->pObj->accessDeniedMessageBox($this->file['file_name']);
     }
     return $content;
 }
 /**
  * tx_dam::file_getType()
  */
 public function test_file_getType_indexed()
 {
     $fixture = $this->getFixtureRandomIndexedFilename();
     $filename = $fixture['filename'];
     $meta = $fixture['meta'];
     $type = tx_dam::file_getType($filename);
     self::assertEquals($type['file_type'], $meta['file_type'], 'Wrong file type: ' . $type['file_type'] . ' (' . $meta['file_type'] . ')');
     self::assertEquals($type['file_mime_type'], $meta['file_mime_type'], 'Wrong mime type: ' . $type['file_mime_type'] . ' (' . $meta['file_mime_type'] . ')');
     self::assertEquals($type['file_mime_subtype'], $meta['file_mime_subtype'], 'Wrong mime sub type: ' . $type['file_mime_subtype'] . ' (' . $meta['file_mime_subtype'] . ')');
 }
 /**
  * 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);
 }
Exemplo n.º 6
0
 /**
  * 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;
 }
 /**
  * Returns an array which describes the type of a file.
  *
  * example:
  * $mimeType = array();
  * $mimeType['file_mime_type'] = 'audio';
  * $mimeType['file_mime_subtype'] = 'x-mpeg';
  * $mimeType['file_type'] = 'mp3';
  *
  * @return	array		Describes the type of a file
  */
 function getTypeAll()
 {
     $mimeType = false;
     if ($this->meta) {
         $mimeType = array();
         $mimeType['file_mime_type'] = $this->meta['file_mime_type'];
         $mimeType['file_mime_subtype'] = $this->meta['file_mime_subtype'];
         $mimeType['file_type'] = $this->meta['file_type'];
     } elseif ($this->fileInfo) {
         $mimeType = tx_dam::file_getType($this->fileInfo);
     }
     return $mimeType;
 }
 /**
  * Returns a image-tag for thumbnail(s)
  * A file icon will be returned if no thumbnail is possible
  * If 'href' and/or 'onlick' is set as attributes a A tag will be wrapped around with these.
  *
  * @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	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.
  */
 function image_thumbnailIconImgTag($fileInfo, $size = '', $imgAttributes = '', $iconAttributes = '', $makeFileIcon = TRUE)
 {
     $thumbnail = '';
     if (!is_array($imgAttributes)) {
         $imgAttributes = tx_dam_guifunc::tools_explodeAttributes($imgAttributes);
     }
     $href = $imgAttributes['href'];
     $onclick = $imgAttributes['onclick'];
     unset($imgAttributes['href']);
     unset($imgAttributes['onclick']);
     $thumbnail = tx_dam_image::previewImgTag($fileInfo, $size, $imgAttributes);
     if (!$thumbnail and $makeFileIcon) {
         if (!is_array($iconAttributes)) {
             $iconAttributes = tx_dam_guifunc::tools_explodeAttributes($iconAttributes);
         }
         $href = $iconAttributes['href'];
         $onclick = $iconAttributes['onclick'];
         unset($iconAttributes['href']);
         unset($iconAttributes['onclick']);
         $fileType = tx_dam::file_getType($fileInfo);
         $thumbnail = tx_dam_guiFunc::icon_getFileTypeImgTag($fileType, $iconAttributes);
     }
     if ($thumbnail and ($onclick or $href)) {
         $href = $href ? $href : '#';
         $thumbnail = '<a href="' . htmlspecialchars($href) . '" onclick="' . htmlspecialchars($onclick) . '">' . $thumbnail . '</a>';
     }
     return $thumbnail;
 }