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(); }
/** * returns the current quota allocated for a blog * * @param blogId * @return * @static */ function getBlogResourceQuota($blogId) { $blogs = new Blogs(); $blogSettings = $blogs->getBlogSettings($blogId); $blogQuota = $blogSettings->getValue("resources_quota"); if ($blogQuota == "") { $blogQuota = GalleryResourceQuotas::getGlobalResourceQuota(); } return $blogQuota; }
/** * adds a resource to the gallery when the resource is already stored on disk, instead of * it coming from an upload as it usually happens. This method is better than * GalleryResources::addResource() when instead of dealing with uploaded files, the file * is already in disk and all that is left to do is to add it to the database. * * @param ownerId * @param albumId * @param description * @param fullFilePath The real path where the file is stored. This is expected to be * its final and permanent destination * @return It will return one of the following constants: * - GALLERY_ERROR_RESOURCE_TOO_BIG * - GALLERY_ERROR_RESOURCE_FORBIDDEN_EXTENSION * - GALLERY_ERROR_QUOTA_EXCEEDED * - GALLERY_ERROR_ADDING_RESOURCE * - GALLERY_ERROR_UPLOADS_NOT_ENABLED * or the identifier of the resource that was just added if the operation succeeded. */ function addResourceFromDisk($ownerId, $albumId, $description, $fullFilePath) { // check if quotas are enabled, and if this file would make us go // over the quota if (GalleryResourceQuotas::isBlogOverResourceQuota($ownerId, File::getSize($fullFilePath))) { return GALLERY_ERROR_QUOTA_EXCEEDED; } $fileName = basename($fullFilePath); $filePath = dirname($fullFilePath); // get the metadata $getId3 = new GetID3(); $metadata = $getId3->analyze($fullFilePath); // nifty helper method from the getid3 package getid3_lib::CopyTagsToComments($metadata); $resourceType = $this->_getResourceType($fullFilePath, $metadata); $info = $this->_filterMetadata($metadata, $resourceType); // set the flags $flags = 0; if ($resourceType == GALLERY_RESOURCE_IMAGE) { $flags = $flags | GALLERY_RESOURCE_PREVIEW_AVAILABLE; } // add the record to the database $resourceId = $this->addResourceToDatabase($ownerId, $albumId, $description, $flags, $resourceType, $filePath, $fileName, $metadata); if (!$resourceId) { return false; } // and finally move the file to the right place in disk // move the file to disk $storage = new GalleryResourceStorage(); $resFile = $storage->storeFile($resourceId, $ownerId, $fullFilePath, RESOURCE_STORAGE_STORE_MOVE); // if the file cannot be read, we will also remove the record from the // database so that we don't screw up $fileReadable = File::isReadable($resFile); if (!$resFile || $resFile < 0 || !$fileReadable) { // if something went wrong, we should not keep the record in the db $query = "DELETE FROM " . $this->getPrefix() . "gallery_resources\n WHERE id = {$resourceId}"; $this->Execute($query); return $resFile; } // and finally, we can generate the thumbnail only if the file is an image, of course :) if ($resourceType == GALLERY_RESOURCE_IMAGE) { $this->generateResourceThumbnail($resFile, $resourceId, $ownerId); } // return the id of the resource we just added return $resourceId; }