reformat api/posts/add and document it better

git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@776 b3834d28-1941-0410-a4f8-b48e95affb8f
This commit is contained in:
cweiske 2010-09-29 20:56:10 +00:00
parent 3ff661c0e0
commit 66af94feaf

View file

@ -1,49 +1,82 @@
<?php <?php
// Implements the del.icio.us API request to add a new post. /**
// http://delicious.com/help/api#posts_add * API for adding a new bookmark.
*
// del.icio.us behavior: * The following POST and GET parameters are accepted:
// - tags can't have spaces * @param string $url URL of the bookmark (required)
// - address and description are mandatory * @param string $description Bookmark title (required)
// - description == title in semanticscuttle * @param string $extended Extended bookmark description (optional)
// - extended == description in semanticscuttle * @param string $tags Space-separated list of tags (optional)
* @param string $dt Date and time of bookmark creation (optional)
// Scuttle behavior: * Must be of format YYYY-MM-DDTHH:II:SSZ
// - Additional 'status' variable for privacy * @param integer $status Visibility status (optional):
// - No support for 'replace' variable * - 2 or 'private': Bookmark is totally private
* - 1 or 'shared': People on the user's watchlist
* can see it
* - 0 or 'public': Everyone can see the bookmark
* @param string $shared "no" or "yes": Switches between private and
* public (optional)
*
* Notes:
* - tags cannot have spaces
* - URL and description (title) are mandatory
* - delicious "description" is the "title" in SemanticScuttle
* - delicious "extended" is the "description" in SemanticScuttle
* - "status" is a SemanticScuttle addition to this API method
* - SemanticScuttle currently ignores the "replace" parameter
*
* SemanticScuttle - your social bookmark manager.
*
* PHP version 5.
*
* @category Bookmarking
* @package SemanticScuttle
* @author Benjamin Huynh-Kim-Bang <mensonge@users.sourceforge.net>
* @author Christian Weiske <cweiske@cweiske.de>
* @author Eric Dane <ericdane@users.sourceforge.net>
* @license GPL http://www.gnu.org/licenses/gpl.html
* @link http://sourceforge.net/projects/semanticscuttle
* @link http://www.delicious.com/help/api
*/
// Force HTTP authentication // Force HTTP authentication
$httpContentType = 'text/xml'; $httpContentType = 'text/xml';
require_once 'httpauth.inc.php'; require_once 'httpauth.inc.php';
/* Service creation: only useful services are created */ $bs = SemanticScuttle_Service_Factory::get('Bookmark');
$bookmarkservice =SemanticScuttle_Service_Factory::get('Bookmark');
// Get all the bookmark's passed-in information // Get all the bookmark's passed-in information
if (isset($_REQUEST['url']) && (trim($_REQUEST['url']) != '')) if (isset($_REQUEST['url']) && (trim($_REQUEST['url']) != '')) {
$url = trim(urldecode($_REQUEST['url'])); $url = trim(urldecode($_REQUEST['url']));
else } else {
$url = NULL; $url = null;
}
if (isset($_REQUEST['description']) && (trim($_REQUEST['description']) != '')) if (isset($_REQUEST['description']) && (trim($_REQUEST['description']) != '')) {
$description = trim($_REQUEST['description']); $description = trim($_REQUEST['description']);
else } else {
$description = NULL; $description = null;
}
if (isset($_REQUEST['extended']) && (trim($_REQUEST['extended']) != "")) if (isset($_REQUEST['extended']) && (trim($_REQUEST['extended']) != '')) {
$extended = trim($_REQUEST['extended']); $extended = trim($_REQUEST['extended']);
else } else {
$extended = NULL; $extended = null;
}
if (isset($_REQUEST['tags']) && (trim($_REQUEST['tags']) != '') && (trim($_REQUEST['tags']) != ',')) if (isset($_REQUEST['tags']) && (trim($_REQUEST['tags']) != '')
&& (trim($_REQUEST['tags']) != ',')
) {
$tags = trim($_REQUEST['tags']); $tags = trim($_REQUEST['tags']);
else } else {
$tags = NULL; $tags = null;
}
if (isset($_REQUEST['dt']) && (trim($_REQUEST['dt']) != '')) if (isset($_REQUEST['dt']) && (trim($_REQUEST['dt']) != '')) {
$dt = trim($_REQUEST['dt']); $dt = trim($_REQUEST['dt']);
else } else {
$dt = NULL; $dt = null;
}
$status = 0; $status = 0;
if (isset($_REQUEST['status'])) { if (isset($_REQUEST['status'])) {
@ -81,10 +114,10 @@ if (is_null($url)) {
$msg = 'Description missing'; $msg = 'Description missing';
} else { } else {
// We're good with info; now insert it! // We're good with info; now insert it!
if ($bookmarkservice->bookmarkExists($url, $userservice->getCurrentUserId())) { if ($bs->bookmarkExists($url, $userservice->getCurrentUserId())) {
$msg = 'something went wrong'; $msg = 'something went wrong';
} else { } else {
$added = $bookmarkservice->addBookmark( $added = $bs->addBookmark(
$url, $description, $extended, '', $status, $tags, null, $dt, true $url, $description, $extended, '', $status, $tags, null, $dt, true
); );
$msg = 'done'; $msg = 'done';