/**
  * 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;
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
示例#8
0
    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();
$postBody = $request->getBody() . "<br/>";
$numItems = count($resourceIds);
$curItem = 0;
foreach ($resourceIds as $resId) {
    $resource = $res->getResource($resId);
    $markup = "<a id=\"res_" . $resId . "\" href=\"" . $rg->resourceLink($resource) . "\">";
    if ($resource->isImage()) {
        $previewType = $blogSettings->getValue("plugin_moblog_resource_preview_type");
        if ($previewType == MOBLOG_EMBED_MEDIUM_PREVIEW) {
            $link = $rg->resourceMediumSizePreviewLink($resource);
        } elseif ($previewType == MOBLOG_EMBED_FULL_SIZE_VIEW) {
            $link = $rg->resourceDownloadLink($resource);
        } else {
            $link = $rg->resourcePreviewLink($resource);
        }
        $markup .= "<img src=\"{$link}\" alt=\"" . $resource->getDescription() . "\" />";
    } else {
        $markup .= $resource->getDescription();
    }
    $markup .= "</a>";
 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;
 }
示例#10
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');
    }
}
 /**
  * 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;
 }