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 render()
 {
     // get the page from the request
     $this->_page = $this->getCurrentPageFromRequest();
     // and the current album
     $galleryAlbums = new GalleryAlbums();
     $galleryResources = new GalleryResources();
     if ($this->_albumId > ROOT_ALBUM_ID && $this->_page > 0) {
         $album = $galleryAlbums->getAlbum($this->_albumId, $this->_blogInfo->getId());
         if (!$album || $album == "") {
             $this->_albumId = ROOT_ALBUM_ID;
         } else {
             //$resources = $album->getResources();
             $resources = $galleryResources->getUserResources($this->_blogInfo->getId(), $this->_albumId, $this->_resourceType, $this->_page, DEFAULT_ITEMS_PER_PAGE);
             $numResources = $galleryResources->getNumUserResources($this->_blogInfo->getId(), $this->_albumId, $this->_resourceType);
         }
     } else {
         $albums = $galleryAlbums->getChildAlbums($this->_albumId, $this->_blogInfo->getId());
         $resources = array();
     }
     // get a list with the nested albums
     $userAlbums = $galleryAlbums->getNestedAlbumList($this->_blogInfo->getId());
     // event about the albums we just loaded
     $this->notifyEvent(EVENT_ALBUMS_LOADED, array("albums" => &$userAlbums));
     $this->setValue("albumsList", $userAlbums);
     // fetch some statistics and continue
     $quotaUsage = GalleryResourceQuotas::getBlogResourceQuotaUsage($this->_blogInfo->getId());
     $totalResources = $galleryResources->getNumResources($this->_blogInfo->getId());
     $currentQuota = GalleryResourceQuotas::getBlogResourceQuota($this->_blogInfo->getId());
     $this->setValue("quotausage", $quotaUsage);
     $this->setValue("totalresources", $totalResources);
     $this->setValue("quota", $currentQuota);
     // and now export info about the albums and so on but only
     // if we're browsing the first page only (albums do not appear anymore after the first page)
     $this->setValue("album", $album);
     if ($this->_albumId > ROOT_ALBUM_ID && $this->_page < 2) {
         $this->setValue("albums", $album->getChildren());
     } else {
         $this->setValue("albums", $albums);
     }
     // event about the resources
     $this->notifyEvent(EVENT_RESOURCES_LOADED, array("resources" => &$resources));
     $this->setValue("resources", $resources);
     // finally, create and export the pager
     $pager = new Pager($this->_pagerUrl, $this->_page, $numResources, DEFAULT_ITEMS_PER_PAGE);
     $this->setValue("pager", $pager);
     parent::render();
 }
 function render()
 {
     // fetch the child albums of the current top level album
     $galleryAlbums = new GalleryAlbums();
     $albums = $galleryAlbums->getChildAlbums($this->_albumId, $this->_blogInfo->getId());
     // get some info about the parent album if it's different from the
     // top level album
     if ($this->_albumId > 0) {
         $album = $galleryAlbums->getAlbum($this->_albumId, $this->_blogInfo->getId());
     }
     // fetch the albums for this blog
     $this->setValue("albums", $albums);
     $this->setValue("albumid", $this->_albumId);
     $this->setValue("album", $album);
     parent::render();
 }
 /**
  * Carries out the specified action
  */
 function perform()
 {
     $this->_albumId = $this->_request->getValue("albumId");
     $this->_parentId = $this->_request->getValue("parentId");
     $this->_albumName = Textfilter::filterAllHTML($this->_request->getValue("albumName"));
     $this->_albumDescription = Textfilter::filterAllHTML($this->_request->getValue("albumDescription"));
     $this->_showAlbum = $this->_request->getValue("showAlbum");
     if ($this->_showAlbum == "") {
         $this->_showAlbum = 0;
     }
     // fetch the albums for this blog
     $albums = new GalleryAlbums();
     $album = $albums->getAlbum($this->_albumId, $this->_blogInfo->getId());
     if (!$album) {
         $this->_view = new AdminResourcesListView($this->_blogInfo);
         $this->_blogInfo;
         $this->_view->setErrorMessage($this->_locale->tr("error_updating_album"));
         $this->setCommonData();
         return false;
     }
     // update the fields in the object
     $album->setName($this->_albumName);
     $album->setDescription($this->_albumDescription);
     $album->setParentId($this->_parentId);
     $album->setShowAlbum($this->_showAlbum);
     $this->notifyEvent(EVENT_PRE_ALBUM_UPDATE, array("album" => &$album));
     // and update the data in the database
     if (!$albums->updateAlbum($album)) {
         $this->_view = new AdminResourcesListView($this->_blogInfo);
         $this->_blogInfo;
         $this->_view->setErrorMessage($this->_locale->tr("error_updating_album"));
         $this->setCommonData();
         return false;
     }
     $this->_view = new AdminResourcesListView($this->_blogInfo);
     $this->_view->setSuccessMessage($this->_locale->pr("album_updated_ok", $album->getName()));
     $this->notifyEvent(EVENT_POST_ALBUM_UPDATE, array("album" => &$album));
     $this->setCommonData();
     // clear the cache
     CacheControl::resetBlogCache($this->_blogInfo->getId(), false);
     // better to return true if everything fine
     return true;
 }
 /**
  * carries out the specified album
  */
 function perform()
 {
     // get the album id
     $albumId = $this->_request->getValue("albumId");
     // load the resource
     $albums = new GalleryAlbums();
     // create the view
     $this->_view = new AdminResourcesListView($this->_blogInfo);
     // fetch the resource albumm first, to get some info about it
     $album = $albums->getAlbum($albumId, $this->_blogInfo->getId(), false);
     if (!$album) {
         $this->_view->setErrorMessage($this->_locale->tr("error_fetching_album"));
         $this->setCommonData();
         return false;
     }
     // notify of the "pre" delete event
     $this->notifyEvent(EVENT_PRE_ALBUM_DELETE, array("album" => &$album));
     //
     // this album cannot be deleted if either:
     //   1) we have resources under it
     //   2) we have child albums under it
     //
     if ($album->getNumChildren() > 0 || $album->getNumResources() > 0) {
         $this->_view->setErrorMessage($this->_locale->pr("error_album_has_children", $album->getName()));
     } else {
         // otherwise, we can go ahead and remove it
         if ($albums->deleteAlbum($albumId, $this->_blogInfo->getId())) {
             $this->_view->setSuccessMessage($this->_locale->pr("album_deleted_ok", $album->getName()));
             $this->notifyEvent(EVENT_PRE_ALBUM_DELETE, array("album" => &$album));
             // clear the cache
             CacheControl::resetBlogCache($this->_blogInfo->getId(), false);
         } else {
             $this->_view->setErrorMessage($this->_locale->pr("error_deleting_album", $album->getName()));
         }
     }
     // return the view
     $this->setCommonData();
     // better to return true if everything fine
     return true;
 }
 /**
  * Carries out the specified action
  */
 function perform()
 {
     // fetch the albums for this blog
     $this->_albumId = $this->_request->getValue("albumId");
     $albums = new GalleryAlbums();
     $album = $albums->getAlbum($this->_albumId, $this->_blogInfo->getId());
     if (!$album) {
         $this->_view = new AdminResourcesListView($this->_blogInfo);
         $this->_view->setErrorMessage($this->_locale->tr("error_fetching_album"));
     } else {
         // and put everything into the template
         $this->_view = new AdminEditResourceAlbumView($this->_blogInfo);
         $this->_view->setValue("albumName", $album->getName());
         $this->_view->setValue("albumDescription", $album->getDescription());
         $this->_view->setValue("showAlbum", $album->getShowAlbum());
         $this->_view->setValue("parentId", $album->getParentId());
         $this->_view->setValue("albumId", $album->getId());
     }
     $this->setCommonData();
     // better to return true if everything fine
     return true;
 }
 /**
  * Given an album, generates a link to its parent. Must be implemented by child classes to generate
  * a valid URL.
  *
  * @param album The album
  */
 function parentAlbumLink($album)
 {
     if ($album->getParentId() == 0) {
         // if the parent album is the root album, let's make it easy...
         $albumLink = $this->albumLink(null);
     } else {
         // i don't really like this bit because suddenly, a request generator class
         // starts loading objects from the db...
         $albums = new GalleryAlbums();
         $parentAlbum = $albums->getAlbum($album->getParentId());
         $albumLink = $this->albumLink($parentAlbum);
     }
     return $albumLink;
 }
// as part of the error message the list of available categories
if (!$category) {
    $response = new MoblogResponse($request->getReplyTo(), "pLog Moblog: Error", "The category does not exist.");
    MoblogLogger::log("User '" . $request->getUser() . "' tried to use category '" . $categoryId . "' which does not exist.");
    $response->send();
    return false;
}
//
// finally, add the resources to the database
//
// first, create a new album to hold these attachments
$albums = new GalleryAlbums();
$userAlbums = $albums->getUserAlbums($blogInfo->getId());
$t = new Timestamp();
$albumId = $blogSettings->getValue("plugin_moblog_gallery_resource_album_id");
$album = $albums->getAlbum($albumId, $blogInfo->getId());
// check if the album was loaded
if (!$album) {
    $response = new MoblogResponse($request->getReplyTo(), "pLog Moblog: Error", "The album does not exist.");
    MoblogLogger::log("User '" . $request->getUser() . "' tried to use album '" . $albumId . "' which does not exist.");
    $response->send();
    return false;
}
MoblogLogger::log("Adding resources to album " . $album->getName());
$attachments = $request->getAttachments();
$res = new GalleryResources();
$resourceIds = array();
foreach ($attachments as $attachment) {
    MoblogLogger::log("-- Processing attachment " . $attachment->getFileName());
    $result = $res->addResource($blogInfo->getId(), $albumId, $attachment->getFileName(), $attachment);
    //$filePath = $attachment->getFolder()."/".$attachment->getFileName();
 /**
  * Given an album, generates a link to its parent. Must be implemented by child classes to generate
  * a valid URL.
  *
  * @param album The album
  */
 function parentAlbumLink($album)
 {
     if ($album->getParentId() > 0) {
         $galleryAlbums = new GalleryAlbums();
         $parentAlbum = $galleryAlbums->getAlbum($album->getParentId());
         $albumLink = $this->getBaseUrl() . '/' . $this->_blogInfo->getId() . '_' . StringUtils::text2url($this->_blogInfo->getBlog()) . '/albums/' . $album->getParentId() . '_' . StringUtils::text2url($parentAlbum->getName()) . '.html';
     } else {
         // this will return the default link to the albums
         $albumLink = $this->getBaseUrl() . '/' . $this->_blogInfo->getId() . '_' . StringUtils::text2url($this->_blogInfo->getBlog()) . '/albums/';
     }
     return $albumLink;
 }
 /**
  * deletes resources from the list
  */
 function _deleteAlbums()
 {
     $albums = new GalleryAlbums();
     // loop through the array of resource ids and
     // remove them all
     foreach ($this->_albumIds as $albumId => $value) {
         // fetch the resource first, to get some info about it
         $album = $albums->getAlbum($albumId, $this->_blogInfo->getId());
         if (!$album) {
             $this->_errorMessage .= $this->_locale->pr("error_deleting_album2", $albumId) . "<br/>";
         } else {
             if ($album->getNumChildren() > 0 || $album->getNumResources() > 0) {
                 $this->_errorMessage .= $this->_locale->pr("error_album_has_children", $album->getName());
             } else {
                 $this->notifyEvent(EVENT_PRE_ALBUM_DELETE, array("album" => &$album));
                 // and now remove it
                 $res = $albums->deleteAlbum($albumId, $this->_blogInfo->getId());
                 if ($res) {
                     $this->_totalOk++;
                     if ($this->_totalOk > 1) {
                         $this->_successMessage = $this->_locale->pr("items_deleted_ok", $this->_totalOk);
                     } else {
                         $this->_successMessage = $this->_locale->pr("item_deleted_ok", $album->getName());
                     }
                     $this->notifyEvent(EVENT_POST_ALBUM_DELETE, array("album" => &$album));
                 } else {
                     $this->_errorMessage .= $this->_locale->pr("error_deleting_album", $album->getName()) . "<br/>";
                 }
             }
         }
     }
     return true;
 }