/**
  * Carries out the specified action
  */
 function perform()
 {
     // load the resource
     $this->_resourceDescription = Textfilter::filterAllHTML($this->_request->getValue("resourceDescription"));
     $this->_albumId = $this->_request->getValue("albumId");
     $this->_resourceId = $this->_request->getValue("resourceId");
     $resources = new GalleryResources();
     $resource = $resources->getResource($this->_resourceId, $this->_blogInfo->getId());
     // update the fields we'd like to update
     $resource->setAlbumId($this->_albumId);
     $resource->setDescription($this->_resourceDescription);
     // send the event
     $this->notifyEvent(EVENT_PRE_RESOURCE_UPDATE, array("resource" => &$resource));
     // and update it in the db
     $result = $resources->updateResource($resource);
     if (!$result) {
         $this->_view = new AdminResourcesListView($this->_blogInfo);
         $this->_view->setErrorMessage($this->_locale->tr("error_updating_resource"));
     } else {
         // check which submit button was pressed
         if ($this->_request->getValue("regenerate") != "") {
             return Controller::setForwardAction("regeneratePreview");
         }
         $this->_view = new AdminResourcesListView($this->_blogInfo);
         $this->_view->setSuccessMessage($this->_locale->pr("resource_updated_ok", $resource->getFileName()));
         $this->notifyEvent(EVENT_POST_RESOURCE_UPDATE, array("resource" => &$resource));
         // clear the cache
         CacheControl::resetBlogCache($this->_blogInfo->getId(), false);
     }
     $this->setCommonData();
     // better to return true if everything fine
     return true;
 }
 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;
 }