function validate() { // check that all the folders are in place if (!GalleryResourceStorage::checkBaseStorageFolder()) { $this->_view = new AdminErrorView($this->_blogInfo); $this->_view->setMessage($this->_locale->tr("error_gallery_folder_missing")); $this->setCommonData(); return false; } return true; }
function checkFolders() { $baseFolder = GalleryResourceStorage::getResourcesStorageFolder(); $userFolder = GalleryResourceStorage::getUserFolder($this->_blogInfo->getId()); $previewsFolder = GalleryResourceStorage::getPreviewsFolder($this->_blogInfo->getId()); $folders = "{$baseFolder}<br/>{$userFolder}<br/>{$previewsFolder}"; $message = ""; // check if the storage folder exists and it is readable if (!GalleryResourceStorage::checkBaseStorageFolder() || !GalleryResourceStorage::checkUserStorageFolder($this->_blogInfo->getId()) || !GalleryResourceStorage::checkPreviewsStorageFolder($this->_blogInfo->getId()) || !GalleryResourceStorage::checkMediumSizePreviewsStorageFolder($this->_blogInfo->getId())) { $message = $this->_locale->pr("error_base_storage_folder_missing_or_unreadable", $folders); } return $message; }
function perform() { // first of all, fetch the resource $this->_resourceId = $this->_request->getValue("resourceId"); $resources = new GalleryResources(); $resource = $resources->getResource($this->_resourceId, $this->_blogInfo->getId()); // check if it was loaded ok if (!$resource) { $this->_view = new AdminResourcesListView($this->_blogInfo); $this->_view->setErrorMessage($this->_locale->tr("error_loading_resource")); $this->setCommonData(); return false; } // if so, continue... first by checking if the resource is an image or not // because if not, then there is no point in generating a thumbnail of it! if (!$resource->isImage()) { $this->_view = new AdminResourcesListView($this->_blogInfo); $this->_view->setErrorMessage($this->_locale->tr("error_resource_is_not_an_image")); } $previewHeight = $this->_config->getValue("thumbnail_height"); $previewWidth = $this->_config->getValue("thumbnail_width"); $previewKeepAspectRatio = $this->_config->getValue("thumbnails_keep_aspect_ratio"); // build the filename $fileNameParts = explode(".", $resource->getFileName()); $fileExt = strtolower($fileNameParts[count($fileNameParts) - 1]); $fileName = $resource->getOwnerId() . "-" . $resource->getId() . "." . $fileExt; // and start the resizing process $resourceStorage = new GalleryResourceStorage(); $resizer = new GalleryResizer($resourceStorage->getResourcePath($resource)); $resourceStorage->checkPreviewsStorageFolder($resource->getOwnerId()); $outFile = $resourceStorage->getPreviewsFolder($resource->getOwnerId()) . $fileName; // and finally, we can generate the preview! $result = $resizer->generate($outFile, $previewHeight, $previewWidth, $previewKeepAspectRatio); $previewFormat = $resizer->getThumbnailFormat(); $resource->setThumbnailFormat($previewFormat); $resources->updateResource($resource); if (!$result) { $this->_view = new AdminResourcesListView($this->_blogInfo); $this->_view->setErrorMessage($this->_locale->tr("error_generating_resource_preview")); } else { $previewHeight = $this->_config->getValue("medium_size_thumbnail_height"); $previewWidth = $this->_config->getValue("medium_size_thumbnail_width"); // and start the resizing process $resourceStorage = new GalleryResourceStorage(); $resizer = new GalleryResizer($resourceStorage->getResourcePath($resource)); $resourceStorage->checkMediumSizePreviewsStorageFolder($resource->getOwnerId()); $outFile = $resourceStorage->getMediumSizePreviewsFolder($resource->getOwnerId()) . $fileName; // and finally, we can generate the preview! $result = $resizer->generate($outFile, $previewHeight, $previewWidth, $previewKeepAspectRatio); $previewFormat = $resizer->getThumbnailFormat(); $resource->setThumbnailFormat($previewFormat); $resources->updateResource($resource); if (!$result) { $this->_view = new AdminResourcesListView($this->_blogInfo); $this->_view->setErrorMessage($this->_locale->tr("error_generating_resource_medium")); } else { $this->_view = new AdminEditResourceView($this->_blogInfo); $this->_view->setSuccessMessage($message = $this->_locale->tr("resource_preview_generated_ok")); $this->_view->setValue("resourceDescription", $resource->getDescription()); $this->_view->setValue("albumId", $resource->getAlbumId()); $this->_view->setValue("resource", $resource); } } $this->setCommonData(); return true; }
/** * @public */ function checkMediumSizePreviewsStorageFolder($ownerId) { $previewsFolder = GalleryResourceStorage::getMediumSizePreviewsFolder($ownerId); if ($previewsFolder[strlen($previewsFolder) - 1] == "/") { $previewsFolder = substr($previewsFolder, 0, strlen($previewsFolder) - 1); } if (!File::isDir($previewsFolder)) { // folder does not exist, so we should try to create it if (!File::createDir($previewsFolder, 0755)) { throw new Exception("Could not create user storage folder for medium size previews: " . $previewsFolder); //die(); return false; } } if (!File::isReadable($previewsFolder)) { throw new Exception($previewsFolder . " user previews storage folder exists but it is not readable!"); //die(); return false; } return true; }
/** * returns the full path to the file with the medium-sized preview * * @return full path to the medium-sized preview */ function getMediumSizePreviewFileName() { if ($this->getThumbnailFormat() == THUMBNAIL_OUTPUT_FORMAT_SAME_AS_IMAGE) { $fileParts = explode(".", $this->getFileName()); $fileExt = $fileParts[count($fileParts) - 1]; $fileName = $this->getOwnerId() . "-" . $this->getId() . "." . strtolower($fileExt); $previewFile = GalleryResourceStorage::getMediumSizePreviewsFolder($this->getOwnerId()) . $fileName; } else { $previewType = $this->getThumbnailFormat(); $fileName = $this->getOwnerId() . "-" . $this->getId() . "." . strtolower($previewType); $previewFile = GalleryResourceStorage::getMediumSizePreviewsFolder($this->getOwnerId()) . $fileName; } return $previewFile; }
/** * removes a resource from the database and disk * * @param resourceId The identifier of the resource we'd like to remove * @param ownerId Identifier of the owner of the resource. Optional. * @return Returns true if resource deleted ok or false otherwise. */ function deleteResource($resourceId, $ownerId = -1) { // first, get informaiton abotu the resource $resource = $this->getResource($resourceId, $ownerId); // now, remove it from the db $query = "DELETE FROM " . $this->getPrefix() . "gallery_resources\n WHERE id = {$resourceId}"; if ($ownerId > 0) { $query .= " AND owner_id = {$ownerId}"; } $result = $this->Execute($query); // if there was an error, we quit here if (!$result) { return false; } // otherwise, proceed and remove the file from disk $storage = new GalleryResourceStorage(); return $storage->remove($resource); }