/**
  * Carries out the specified action
  */
 function perform()
 {
     // load the resource
     $resourceId = $this->_request->getValue("resourceId");
     $resources = new GalleryResources();
     // initialize the view we're going to use
     $this->_view = new AdminResourcesListView($this->_blogInfo);
     // fetch the resource first, to get some info about it
     $resource = $resources->getResource($resourceId, $this->_blogInfo->getId());
     if (!$resource) {
         $this->_view->setErrorMessage($this->_locale->tr("error_fetching_resource"));
         $this->setCommonData();
         return false;
     }
     // if the resource was loaded ok...
     $this->notifyEvent(EVENT_PRE_RESOURCE_DELETE, array("resource" => &$resource));
     // remove it
     $res = $resources->deleteResource($resourceId, $this->_blogInfo->getId());
     if ($res) {
         $this->_view->setSuccessMessage($this->_locale->pr("resource_deleted_ok", $resource->getFileName()));
         $this->notifyEvent(EVENT_PRE_RESOURCE_DELETE, array("resource" => &$resource));
         // clear the cache if everything went fine
         CacheControl::resetBlogCache($this->_blogInfo->getId(), false);
     } else {
         $this->_view->setErrorMessage($this->_locale->pr("error_deleting_resource", $resource->getFileName()));
     }
     // return the view
     $this->setCommonData();
     // better to return true if everything fine
     return true;
 }
 /**
  * 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;
 }
 /**
  * deletes resources from the list
  */
 function _deleteResources()
 {
     // load the resource
     $resources = new GalleryResources();
     // loop through the array of resource ids and
     // remove them all
     foreach ($this->_resourceIds as $resourceId => $value) {
         // fetch the resource first, to get some info about it
         $resource = $resources->getResource($resourceId, $this->_blogInfo->getId());
         if (!$resource) {
             $this->_errorMessage .= $this->_locale->pr("error_deleting_resource2", $resourceId) . "<br/>";
         } else {
             $this->notifyEvent(EVENT_PRE_RESOURCE_DELETE, array("resource" => &$resource));
             // and now remove it
             $res = $resources->deleteResource($resourceId, $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", $resource->getFileName());
                 }
                 $this->notifyEvent(EVENT_PRE_RESOURCE_DELETE, array("resource" => &$resource));
             } else {
                 $this->_errorMessage .= $this->_locale->pr("error_deleting_resource", $resource->getFileName()) . "<br/>";
             }
         }
     }
     return true;
 }
 /**
  * Carries out the specified action
  */
 function perform()
 {
     // fetch the information coming from the resource
     $this->_description = Textfilter::filterAllHTML($this->_request->getValue("resourceDescription"));
     $this->_albumId = $this->_request->getValue("albumId");
     $this->_resource = $this->_request->getValue("resourceFile");
     // check if there is any file uploaded
     $files = HttpVars::getFiles();
     // we probably need to rearrange the $files array a bit better...
     $this->_files = array();
     foreach ($files as $file) {
         if ($file["error"] == 0 && $file["size"] > 0 && $file["name"] != "") {
             $this->_files[] = $file;
         }
     }
     // let the gallery library do its work...
     $resources = new GalleryResources();
     $this->_view = new AdminResourcesListView($this->_blogInfo, array("albumId" => $this->_albumId));
     $successMessage = "";
     $errorMessage = "";
     foreach ($this->_files as $file) {
         // create a new FileUpload object based on the file
         $upload = new FileUpload($file);
         // add the resource to the db
         $this->notifyEvent(EVENT_PRE_RESOURCE_ADD, array("upload" => &$upload));
         $res = $resources->addResource($this->_blogInfo->getId(), $this->_albumId, $this->_description, $upload);
         // check if everything went fine and if not, show an error message
         if ($res > 0) {
             $successMessage .= $this->_locale->pr("resource_added_ok", $file["name"]) . "<br/>";
             // try to fetch the resource so that we can send it in the event
             $resource = $resources->getResource($res, $this->_blogInfo->getId());
             $this->notifyEvent(EVENT_POST_RESOURCE_ADD, array("resource" => &$resource));
         } else {
             if ($res == GALLERY_ERROR_RESOURCE_FORBIDDEN_EXTENSION) {
                 $errorMessage .= $this->_locale->pr("error_resource_forbidden_extension", $file["name"]) . "<br/>";
             } elseif ($res == GALLERY_ERROR_RESOURCE_TOO_BIG) {
                 $errorMessage .= $this->_locale->pr("error_resource_too_big", $file["name"]) . "<br/>";
             } elseif ($res == GALLERY_ERROR_UPLOADS_NOT_ENABLED) {
                 $errorMessage .= $this->_locale->tr("error_uploads_disabled") . "<br/>";
             } elseif ($res == GALLERY_ERROR_QUOTA_EXCEEDED) {
                 $errorMessage .= $this->_locale->tr("error_quota_exceeded") . "<br/>";
             } else {
                 $errorMessage .= $this->_locale->pr("error_adding_resource", $file["name"]) . "<br/>";
             }
         }
     }
     // clear the cache no matter what happened... we should only clear it if there was at least one
     // file uploaded but this way is not that bad after all...
     CacheControl::resetBlogCache($this->_blogInfo->getId(), false);
     if ($successMessage != "") {
         $this->_view->setSuccessMessage($successMessage);
     }
     if ($errorMessage != "") {
         $this->_view->setErrorMessage($errorMessage);
     }
     $this->setCommonData();
     return true;
 }
 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;
 }
 /**
  * Returns the quota usage of a user
  *
  * @param userId The user whose quota usage we would like to know
  * @param albumId The album identifier, optional
  * @return The number of bytes used
  * @static
  */
 function getBlogResourceQuotaUsage($userId, $albumId = -1)
 {
     // get the user resources
     $resources = new GalleryResources();
     $blogResources = $resources->getUserResources($userId, $albumId);
     if (!$blogResources) {
         return 0;
     }
     // and now go one by one calculating the sizes
     $total = 0;
     foreach ($blogResources as $resource) {
         $total += $resource->getFileSize();
     }
     return $total;
 }
 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();
 }
 /**
  * Carries out the specified action
  */
 function perform()
 {
     // load the resource
     $this->_resourceId = $this->_request->getValue("resourceId");
     $resources = new GalleryResources();
     $resource = $resources->getResource($this->_resourceId, $this->_blogInfo->getId());
     if (!$resource) {
         $this->_view = new AdminResourcesListView($this->_blogInfo);
         $this->_view->setErrorMessage($this->_locale->tr("error_fetching_resource"));
     } else {
         $this->_view = new AdminEditResourceView($this->_blogInfo);
         $this->notifyEvent(EVENT_RESOURCE_LOADED, array("resource" => &$resource));
         $this->_view->setValue("resource", $resource);
         // export some useful information
         $this->_view->setValue("resourceDescription", $resource->getDescription());
         $this->_view->setValue("albumId", $resource->getAlbumId());
         $this->_view->setValue("resourceDescription", $resource->getDescription());
         $this->_view->setValue("albumId", $resource->getAlbumId());
     }
     $this->setCommonData();
     // better to return true if everything fine
     return true;
 }
 function perform()
 {
     // initialize the plugin manager, needed to inform plugins of the EVENT_RESOURCE_LOADED
     // event, in case any of them is waiting for it! This obviously slows things down but
     // hey, what can I do? Users ask and I deliver...
     $this->_pm =& PluginManager::getPluginManager();
     $this->_pm->setBlogInfo($this->_blogInfo);
     $this->_userInfo = $this->_blogInfo->getOwnerInfo();
     $this->_pm->setUserInfo($this->_userInfo);
     // and fetch the resource
     $resources = new GalleryResources();
     if ($this->_resName) {
         $resource = $resources->getResourceFile($this->_blogInfo->getId(), $this->_resName);
     } else {
         $resource = $resources->getResource($this->_resId, $this->_blogInfo->getId());
     }
     if (!$resource) {
         // return 404 not found because the resource wasn't found
         $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: Resource {$this->_resId} not found");
         return false;
     }
     // we need to let plugins know that we have successfully loaded a resource
     $this->notifyEvent(EVENT_RESOURCE_LOADED, array("resource" => &$resource));
     // generate the correct view with the resource data...
     $this->_view = new ResourceServerView($resource, $this->_mode);
     return true;
 }
Esempio n. 10
0
// 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();
    //MoblogLogger::log( "filename = ".$attachment->getFileName()." - patch = ".$filePath );
    //$result = $res->addResourceFromDisk( $blogInfo->getId(), $albumId, $attachment->getFileName(), $filePath );
    MoblogLogger::log("   Completed: result = {$result}");
    if ($result) {
        // keep this for later
        array_push($resourceIds, $result);
    }
}
//
// if everything went fine, we can now proceed and publish the post, finally!!!! :)
 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;
 }
Esempio n. 12
0
function metaWeblogNewMediaObject($args)
{
    global $users, $articles, $blogsG;
    /*
        "userid" =>
        "dateCreated" =>
        "content" =>
        "postid" =>
    */
    $blogid = $args[0];
    $username = $args[1];
    $password = $args[2];
    $file = $args[3];
    $erg = $users->getUserInfo($username, $password);
    if ($erg != false) {
        // Save this file to the tmp directory
        // Create a temp file
        // Get the temp directory
        /**if (!$tmp_dir = get_cfg_var('upload_tmp_dir')) {
               $tmp_dir = dirname(tempnam('/tmp', ''));
           }*/
        $config =& Config::getConfig();
        $tmp_dir = $config->getTempFolder();
        // Remove all characters that would need to be urlencoded
        // This may not be necessary, but this was causing problems when given file
        // names with spaces in it.
        $tempFile = ereg_replace("[^a-zA-Z0-9._-]", "_", basename($file['name']));
        // Make the tmp name
        $tempFile = $tmp_dir . '/' . $tempFile;
        // Open the file
        if (!($handle = fopen($tempFile, "wb"))) {
            return new IXR_Error(-1, 'Could not open file');
        }
        // It appears that the data has already been decoded, no need to call base64_decode
        $decodedBits = $file['bits'];
        // Write the data to the file
        if (fwrite($handle, $decodedBits) === false) {
            return new IXR_Error(-1, 'Could not write to file');
        }
        // Close the file
        fclose($handle);
        // let the gallery library do its work...
        $resources = new GalleryResources();
        // Get the first album for this blog
        $albums = new GalleryAlbums();
        // get the list of albums for this blog
        $albumArray = $albums->getUserAlbums($blogid);
        if ($albumArray == NULL || count($albumArray) == 0) {
            return new IXR_Error(-1, 'Could not find album');
        }
        // Add the resource to the first album
        $resId = $resources->addResourceFromDisk($blogid, $albumArray[0]->getId(), basename($file['name']), $tempFile);
        // Get the resource from the id
        $resource = $resources->getResource($resId, $blogid, $albumArray[0]->getId());
        // Now we need to get the url for the resource
        $blogInfo = $blogsG->getBlogInfo($blogid);
        $url = $blogInfo->getBlogRequestGenerator();
        $ret = $url->resourceDownloadLink($resource);
        return $ret;
    } else {
        return new IXR_Error(-1, 'You did not provide the correct password');
    }
}
 /**
  * this breaks our rule big time (remember: this little objects resulting
  * of dao/ classes should _never_ do any database access by themselves... 
  * all the information they need has already been fetched. However, 
  * this proved to be here a great performance improvement in the sense that
  * fetching a single album did not trigger fetchign the whole shebang
  * and whatnot from the database of albums and resources...
  * Sometimes, breaking the rules is a good thing :)
  */
 function getResources()
 {
     //return $this->_resources;
     if ($this->_resources == null) {
         $res = new GalleryResources();
         $this->_resources = $res->getUserResources($this->getOwnerId(), $this->getId());
     }
     return $this->_resources;
 }
 /**
  * returns all the resources which are linked in this post. It basically looks
  * at the "id" attribute of all links. When the resource has been added via the
  * "add resource" pop-up window from the "new post" and "edit post" pages
  * from the admin interface contains something like "res_XX" where "XX" is the
  * internal id of the resource.
  *
  * If this id attribute is not found this method will not work. We could not find
  * a better way to identify these resources...
  * 
  * @return An array of GalleryResource objects containing all the resources
  */
 function getArticleResources()
 {
     include_once PLOG_CLASS_PATH . "class/data/stringutils.class.php";
     include_once PLOG_CLASS_PATH . "class/gallery/dao/galleryresources.class.php";
     // extract all the "res_XX" values
     $regexp = "/<a.*id=\"res_([0-9]+)\".*>.*<\\/a>/im";
     $resources = array();
     $galleryResources = new GalleryResources();
     if (preg_match_all($regexp, $this->getText(), $out, PREG_SET_ORDER)) {
         // process the results
         foreach ($out as $match) {
             $resourceId = $match[1];
             // try to load the resource
             $resource = $galleryResources->getResource($resourceId, $this->getBlog());
             if ($resource) {
                 // add it to the array
                 $resources[] = $resource;
                 // and continue...
             }
         }
     }
     return $resources;
 }
 /**
  * @private
  * loads the user picture. Returns a GalleryObject if successful or false otherwise
  */
 function _loadPicture()
 {
     include_once PLOG_CLASS_PATH . "class/gallery/dao/galleryresources.class.php";
     $resources = new GalleryResources();
     $picture = $resources->getResource($this->_resourcePictureId);
     if (!$picture) {
         $this->_resourcePicture = null;
     } else {
         $this->_resourcePicture = $picture;
     }
     return $this->_resourcePicture;
 }