function perform()
 {
     $galleryResources = new GalleryResources();
     $galleryAlbums = new GalleryAlbums();
     // initialize the view
     $this->_view = new BlogView($this->_blogInfo, VIEW_RESOURCE_TEMPLATE, SMARTY_VIEW_CACHE_CHECK, array("resourceId" => $this->_resourceId, "resourceName" => $this->_resourceName, "albumName" => $this->_albumName, "albumId" => $this->_albumId));
     // if it's cached, do nothing
     if ($this->_view->isCached()) {
         return true;
     }
     // otherwise continue as normal...
     // try to find the album to which this resource belongs
     if ($this->_albumName) {
         $album = $galleryAlbums->getAlbumByName($this->_albumName, $this->_blogInfo->getId(), false, false);
         if (!$album) {
             $this->_view = new ErrorView($this->_blogInfo);
             $this->_view->setValue("message", "error_fetching_resource");
             $this->setCommonData();
             return false;
         }
         $this->_albumId = $album->getId();
     }
     // fetch the album we're trying to browse
     if ($this->_resourceName != "") {
         $resource = $galleryResources->getResourceFile($this->_blogInfo->getId(), $this->_resourceName, $this->_albumId);
     } else {
         $resource = $galleryResources->getResource($this->_resourceId, $this->_blogInfo->getId(), $this->_albumId);
     }
     // check if the album was correctly fetched
     if (!$resource) {
         $this->_view = new ErrorView($this->_blogInfo);
         $this->_view->setValue("message", "error_fetching_resource");
         $this->setCommonData();
         return false;
     }
     // if all went fine, continue loading the next and previous resources so that
     // navigation can be made easier...
     $nextResource = $galleryResources->getNextResource($resource);
     $prevResource = $galleryResources->getPreviousResource($resource);
     // generate events for all the resources we just loaded
     $this->notifyEvent(EVENT_RESOURCE_LOADED, array("resource" => &$resource));
     if ($nextResource) {
         $this->notifyEvent(EVENT_RESOURCE_LOADED, array("resource" => &$nextResource));
     }
     if ($prevResource) {
         $this->notifyEvent(EVENT_RESOURCE_LOADED, array("resource" => &$prevResource));
     }
     $this->_view->setValue("resource", $resource);
     $this->_view->setValue("prevresource", $prevResource);
     $this->_view->setValue("nextresource", $nextResource);
     $this->setCommonData();
     // and return everything normal
     return true;
 }
 function perform()
 {
     $galleryResources = new GalleryResources();
     $galleryAlbums = new GalleryAlbums();
     $browseRootAlbum = $this->_albumId == 0 && $this->_albumName == "";
     // check which template we should use
     if ($browseRootAlbum) {
         $template = VIEW_ALBUMS_TEMPLATE;
     } else {
         $template = VIEW_ALBUM_TEMPLATE;
     }
     // initialize the view and check if it was cached
     $this->_view = new BlogView($this->_blogInfo, $template, SMARTY_VIEW_CACHE_CHECK, array("albumId" => $this->_albumId, "albumName" => $this->_albumName));
     if ($this->_view->isCached()) {
         // nothing to do if it is cached!
         return true;
     }
     // fetch the album we're trying to browse
     if ($browseRootAlbum) {
         // fetch only the first level albums
         $blogAlbums = $galleryAlbums->getChildAlbums(0, $this->_blogInfo->getId(), true);
         if (count($blogAlbums) == 0) {
             $this->_view = new ErrorView($this->_blogInfo);
             $this->_view->setValue("message", "error_no_albums_defined");
         } else {
             $this->notifyEvent(EVENT_ALBUMS_LOADED, array("albums" => &$blogAlbums));
             $this->_view->setValue("albums", $blogAlbums);
         }
     } else {
         // the third parameter is telling _not_ to fetch all those albums that have
         // been disabled and are not to be shown in the page when browsing the album
         if ($this->_albumName) {
             $album = $galleryAlbums->getAlbumByName($this->_albumName, $this->_blogInfo->getId(), true, true);
         } else {
             $album = $galleryAlbums->getAlbum($this->_albumId, $this->_blogInfo->getId(), true, true);
         }
         // check if the album was correctly fetched
         if (!$album) {
             $this->_view = new ErrorView($this->_blogInfo);
             $this->_view->setValue("message", "error_fetching_album");
             $this->setCommonData();
             return false;
         }
         $this->notifyEvent(EVENT_ALBUM_LOADED, array("album" => &$blogAlbum));
         // put the album to the template
         $this->_view->setValue("album", $album);
     }
     // if all went fine, continue
     $this->setCommonData();
     // and return everything normal
     return true;
 }
 function validate()
 {
     // before we do anything, let's find out the blogId and if there isn't any, quit
     $this->_getBlogInfo();
     if ($this->_blogInfo == false) {
         // return 404 not found because the blog id is not correct!
         $this->_view = new ResourceServerView();
         $this->_view->addHeaderResponse("HTTP/1.1 404 Not Found");
         $this->_view->addHeaderResponse("Status: 404 Not Found");
         $this->_view->addHeaderResponse("X-pLog-Error: Blog {$resId} is not correct");
         return false;
     }
     //
     // security stuff
     //
     // :KLUDGE: the problem with the security Pipeline and the PluginManager in this
     // action is that we need to reimplement the whole stuff because... this action does not
     // inherit from BlogAction and therefore nobody is doing these things for us! I don't really
     // like to do it like this but while I think of a better way, let's leave like it
     //
     $pipeline = new Pipeline($this->_request, $this->_blogInfo);
     $result = $pipeline->process();
     // if the pipeline blocked the request, then we have to let the user know and quit
     // processing
     if (!$result->isValid()) {
         $this->_view = new ResourceServerView();
         $this->_view->addHeaderResponse("HTTP/1.1 403 Forbidden");
         $this->_view->addHeaderResponse("Status: 403 Forbidden");
         $this->_view->addHeaderResponse("X-pLog-Error: Access is blocked");
         return false;
     }
     // now if the blog id was correct, then we can proceed to get the rest of the parameters
     $this->_resName = $this->_request->getValue("resource");
     $this->_resId = $this->_request->getValue("resId");
     $this->_albumId = $this->_request->getValue("albumId");
     $this->_albumName = $this->_request->getValue("albumName");
     $this->_mode = $this->_request->getValue("mode");
     // check if we need to load the album to figure out the correct album id
     // because we got an album name instead of an album id
     if (!empty($this->_albumId) || !empty($this->_albumName)) {
         if ($this->_albumName) {
             $albums = new GalleryAlbums();
             $album = $albums->getAlbumByName($this->_albumName);
             if (!$album) {
                 $this->_view = new ResourceServerView();
                 $this->_view->addHeaderResponse("HTTP/1.1 404 Not Found");
                 $this->_view->addHeaderResponse("Status: 404 Not Found");
                 $this->_view->addHeaderResponse("X-pLog-Error: Album {$albumId} not found");
                 return false;
             }
             $this->_albumId = $album->getId();
         }
     }
     return true;
 }