コード例 #1
0
 /**
  * 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;
 }
コード例 #2
0
$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!!!! :)
//
// before adding the article, we need to add some additional markup
// with links to the attachments that were sent
$rg = $blogInfo->getBlogRequestGenerator();