/** * Get the file's extension. * @return string */ function getExtension() { import('lib.pkp.classes.file.FileManager'); $fileManager = new FileManager(); return strtoupper($fileManager->getExtension($this->getData('fileName'))); }
/** * Truncate a filename to fit in the specified length. */ function truncateFileName($fileName, $length = 127) { if (String::strlen($fileName) <= $length) { return $fileName; } $ext = FileManager::getExtension($fileName); $truncated = String::substr($fileName, 0, $length - 1 - String::strlen($ext)) . '.' . $ext; return String::substr($truncated, 0, $length); }
static function updateUserFileList($id = 0) { global $loginManager; if (WEBSOCKET != 1 || empty($id) || !is_numeric($id)) { $id = $loginManager->getId(); } $basedir = dirname(dirname(__FILE__)) . '/data/user_' . $id . '/files'; $audio = null; $video = null; $images = null; $directory = new RecursiveDirectoryIterator($basedir); $objects = new RecursiveIteratorIterator($directory, RecursiveIteratorIterator::SELF_FIRST); foreach ($objects as $name => $object) { $extension = FileManager::getExtension($name); if (!FileManager::isVisible($object)) { continue; } if (in_array(strtoupper($extension), FileManager::EXTENSION_IMAGES)) { $images[] = str_replace($basedir, '', $name); } else { if (in_array(strtoupper($extension), FileManager::EXTENSION_VIDEO)) { $video[] = str_replace($basedir, '', $name); } else { if (in_array(strtoupper($extension), FileManager::EXTENSION_AUDIO)) { $audio[] = str_replace($basedir, '', $name); } } } } if (empty($images)) { $images = array(); } if (empty($audio)) { $audio = array(); } if (empty($video)) { $video = array(); } $datei = fopen(dirname(dirname(__FILE__)) . '/data/user_' . $id . '/.userfiles/image.json', "w+"); fwrite($datei, json_encode($images)); fclose($datei); $datei = fopen(dirname(dirname(__FILE__)) . '/data/user_' . $id . '/.userfiles/video.json', "w+"); fwrite($datei, json_encode($video)); fclose($datei); $datei = fopen(dirname(dirname(__FILE__)) . '/data/user_' . $id . '/.userfiles/audio.json', "w+"); fwrite($datei, json_encode($audio)); fclose($datei); }
/** * Resize cover thumnails for all given press objects (categories, series and published monographs). * @param $context Context * @param $objectDao CategoriesDAO, SeriesDAO or PublishedMonographsDAO * @param $coverThumbnailsMaxWidth int * @param $coverThumbnailsMaxHeight int * @param $basePath string Base path for the given object */ function _resizeCoverThumbnails($context, $objectDao, $coverThumbnailsMaxWidth, $coverThumbnailsMaxHeight, $basePath) { import('classes.file.SimpleMonographFileManager'); import('lib.pkp.classes.file.FileManager'); $fileManager = new FileManager(); $objects = $objectDao->getByPressId($context->getId()); while ($object = $objects->next()) { if (is_a($object, 'PublishedMonograph')) { $cover = $object->getCoverImage(); $simpleMonographFileManager = new SimpleMonographFileManager($context->getId(), $object->getId()); $basePath = $simpleMonographFileManager->getBasePath(); } else { $cover = $object->getImage(); } if ($cover) { // delete old cover thumbnail $fileManager->deleteFile($basePath . $cover['thumbnailName']); // get settings necessary for the new thumbnail $coverExtension = $fileManager->getExtension($cover['name']); $xRatio = min(1, $coverThumbnailsMaxWidth / $cover['width']); $yRatio = min(1, $coverThumbnailsMaxHeight / $cover['height']); $ratio = min($xRatio, $yRatio); $thumbnailWidth = round($ratio * $cover['width']); $thumbnailHeight = round($ratio * $cover['height']); // create a thumbnail image of the defined size $thumbnail = imagecreatetruecolor($thumbnailWidth, $thumbnailHeight); // generate the image of the original cover switch ($coverExtension) { case 'jpg': $coverImage = imagecreatefromjpeg($basePath . $cover['name']); break; case 'png': $coverImage = imagecreatefrompng($basePath . $cover['name']); break; case 'gif': $coverImage = imagecreatefromgif($basePath . $cover['name']); break; default: $coverImage = null; // Suppress warn } assert($coverImage); // copy the cover image to the thumbnail imagecopyresampled($thumbnail, $coverImage, 0, 0, 0, 0, $thumbnailWidth, $thumbnailHeight, $cover['width'], $cover['height']); // create the thumbnail file switch ($coverExtension) { case 'jpg': imagejpeg($thumbnail, $basePath . $cover['thumbnailName']); break; case 'png': imagepng($thumbnail, $basePath . $cover['thumbnailName']); break; case 'gif': imagegif($thumbnail, $basePath . $cover['thumbnailName']); break; } imagedestroy($thumbnail); if (is_a($object, 'PublishedMonograph')) { $object->setCoverImage(array('name' => $cover['name'], 'width' => $cover['width'], 'height' => $cover['height'], 'thumbnailName' => $cover['thumbnailName'], 'thumbnailWidth' => $thumbnailWidth, 'thumbnailHeight' => $thumbnailHeight, 'catalogName' => $cover['catalogName'], 'catalogWidth' => $cover['v'], 'catalogHeight' => $cover['catalogHeight'], 'uploadName' => $cover['uploadName'], 'dateUploaded' => $cover['dateUploaded'])); } else { $object->setImage(array('name' => $cover['name'], 'width' => $cover['width'], 'height' => $cover['height'], 'thumbnailName' => $cover['thumbnailName'], 'thumbnailWidth' => $thumbnailWidth, 'thumbnailHeight' => $thumbnailHeight, 'uploadName' => $cover['uploadName'], 'dateUploaded' => $cover['dateUploaded'])); } // Update category object to store new thumbnail information. $objectDao->updateObject($object); } unset($object); } }
/** * Get extension of the file. * @ return string */ function getFileExtension() { return FileManager::getExtension($this->getData('originalName')); }