2007-12-12 16:29:16 +00:00
|
|
|
<?php
|
2010-09-29 20:56:10 +00:00
|
|
|
/**
|
|
|
|
* API for adding a new bookmark.
|
|
|
|
*
|
|
|
|
* The following POST and GET parameters are accepted:
|
|
|
|
* @param string $url URL of the bookmark (required)
|
|
|
|
* @param string $description Bookmark title (required)
|
|
|
|
* @param string $extended Extended bookmark description (optional)
|
|
|
|
* @param string $tags Space-separated list of tags (optional)
|
|
|
|
* @param string $dt Date and time of bookmark creation (optional)
|
|
|
|
* Must be of format YYYY-MM-DDTHH:II:SSZ
|
|
|
|
* @param integer $status Visibility status (optional):
|
|
|
|
* - 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)
|
2010-09-29 20:57:30 +00:00
|
|
|
* @param string $replace "yes" or "no" - replaces a bookmark with the
|
|
|
|
* same URL (optional)
|
2010-09-29 20:56:10 +00:00
|
|
|
*
|
|
|
|
* 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 - 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
|
|
|
|
*/
|
2007-12-12 16:29:16 +00:00
|
|
|
|
|
|
|
// Force HTTP authentication
|
2010-03-17 20:11:21 +00:00
|
|
|
$httpContentType = 'text/xml';
|
|
|
|
require_once 'httpauth.inc.php';
|
2007-12-12 16:29:16 +00:00
|
|
|
|
2010-09-29 20:56:10 +00:00
|
|
|
$bs = SemanticScuttle_Service_Factory::get('Bookmark');
|
2007-12-12 16:29:16 +00:00
|
|
|
|
|
|
|
// Get all the bookmark's passed-in information
|
2010-09-29 20:56:10 +00:00
|
|
|
if (isset($_REQUEST['url']) && (trim($_REQUEST['url']) != '')) {
|
2007-12-12 16:29:16 +00:00
|
|
|
$url = trim(urldecode($_REQUEST['url']));
|
2010-09-29 20:56:10 +00:00
|
|
|
} else {
|
|
|
|
$url = null;
|
|
|
|
}
|
2007-12-12 16:29:16 +00:00
|
|
|
|
2010-09-29 20:56:10 +00:00
|
|
|
if (isset($_REQUEST['description']) && (trim($_REQUEST['description']) != '')) {
|
2007-12-12 16:29:16 +00:00
|
|
|
$description = trim($_REQUEST['description']);
|
2010-09-29 20:56:10 +00:00
|
|
|
} else {
|
|
|
|
$description = null;
|
|
|
|
}
|
2007-12-12 16:29:16 +00:00
|
|
|
|
2010-09-29 20:56:10 +00:00
|
|
|
if (isset($_REQUEST['extended']) && (trim($_REQUEST['extended']) != '')) {
|
2007-12-12 16:29:16 +00:00
|
|
|
$extended = trim($_REQUEST['extended']);
|
2010-09-29 20:56:10 +00:00
|
|
|
} else {
|
|
|
|
$extended = null;
|
|
|
|
}
|
2007-12-12 16:29:16 +00:00
|
|
|
|
2010-09-29 20:56:10 +00:00
|
|
|
if (isset($_REQUEST['tags']) && (trim($_REQUEST['tags']) != '')
|
|
|
|
&& (trim($_REQUEST['tags']) != ',')
|
|
|
|
) {
|
2007-12-12 16:29:16 +00:00
|
|
|
$tags = trim($_REQUEST['tags']);
|
2010-09-29 20:56:10 +00:00
|
|
|
} else {
|
|
|
|
$tags = null;
|
|
|
|
}
|
2007-12-12 16:29:16 +00:00
|
|
|
|
2010-09-29 20:56:10 +00:00
|
|
|
if (isset($_REQUEST['dt']) && (trim($_REQUEST['dt']) != '')) {
|
2007-12-12 16:29:16 +00:00
|
|
|
$dt = trim($_REQUEST['dt']);
|
2010-09-29 20:56:10 +00:00
|
|
|
} else {
|
|
|
|
$dt = null;
|
|
|
|
}
|
2007-12-12 16:29:16 +00:00
|
|
|
|
2010-09-29 20:57:30 +00:00
|
|
|
$replace = isset($_REQUEST['replace']) && ($_REQUEST['replace'] == 'yes');
|
|
|
|
|
2011-03-15 06:53:39 +00:00
|
|
|
$status = $GLOBALS['defaults']['privacy'];
|
2007-12-12 16:29:16 +00:00
|
|
|
if (isset($_REQUEST['status'])) {
|
|
|
|
$status_str = trim($_REQUEST['status']);
|
|
|
|
if (is_numeric($status_str)) {
|
|
|
|
$status = intval($status_str);
|
2010-09-29 20:56:10 +00:00
|
|
|
if ($status < 0 || $status > 2) {
|
2007-12-12 16:29:16 +00:00
|
|
|
$status = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch ($status_str) {
|
2010-09-29 20:56:10 +00:00
|
|
|
case 'private':
|
|
|
|
$status = 2;
|
|
|
|
break;
|
|
|
|
case 'shared':
|
|
|
|
$status = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$status = 0;
|
|
|
|
break;
|
2007-12-12 16:29:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-22 08:51:56 +00:00
|
|
|
if (isset($_REQUEST['shared']) && (trim($_REQUEST['shared']) == 'no')) {
|
|
|
|
$status = 2;
|
|
|
|
}
|
|
|
|
|
2007-12-12 16:29:16 +00:00
|
|
|
// Error out if there's no address or description
|
2010-09-29 20:55:14 +00:00
|
|
|
if (is_null($url)) {
|
|
|
|
header('HTTP/1.0 400 Bad Request');
|
|
|
|
$msg = 'URL missing';
|
|
|
|
} else if (is_null($description)) {
|
|
|
|
header('HTTP/1.0 400 Bad Request');
|
|
|
|
$msg = 'Description missing';
|
2007-12-12 16:29:16 +00:00
|
|
|
} else {
|
2010-09-29 20:55:14 +00:00
|
|
|
// We're good with info; now insert it!
|
2010-09-29 20:57:30 +00:00
|
|
|
$exists = $bs->bookmarkExists($url, $userservice->getCurrentUserId());
|
|
|
|
if ($exists) {
|
|
|
|
if (!$replace) {
|
|
|
|
header('HTTP/1.0 409 Conflict');
|
|
|
|
$msg = 'bookmark does already exist';
|
|
|
|
} else {
|
|
|
|
//delete it before we re-add it
|
|
|
|
$bookmark = $bs->getBookmarkByAddress($url, false);
|
|
|
|
$bId = $bookmark['bId'];
|
|
|
|
$bs->deleteBookmark($bId);
|
|
|
|
|
|
|
|
$exists = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$exists) {
|
2010-09-29 20:56:10 +00:00
|
|
|
$added = $bs->addBookmark(
|
2010-09-29 20:55:14 +00:00
|
|
|
$url, $description, $extended, '', $status, $tags, null, $dt, true
|
|
|
|
);
|
|
|
|
$msg = 'done';
|
|
|
|
}
|
2007-12-12 16:29:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set up the XML file and output the result.
|
2010-09-29 20:55:14 +00:00
|
|
|
echo '<?xml version="1.0" standalone="yes" ?' . ">\r\n";
|
|
|
|
echo '<result code="' . $msg .'" />';
|
2007-12-12 16:29:16 +00:00
|
|
|
?>
|