2007-12-12 17:29:16 +01:00
|
|
|
<?php
|
|
|
|
// Implements the del.icio.us API request to add a new post.
|
2010-01-22 13:10:39 +01:00
|
|
|
// http://delicious.com/help/api#posts_add
|
2007-12-12 17:29:16 +01:00
|
|
|
|
|
|
|
// del.icio.us behavior:
|
|
|
|
// - tags can't have spaces
|
|
|
|
// - address and description are mandatory
|
2010-09-29 22:52:01 +02:00
|
|
|
// - description == title in semanticscuttle
|
|
|
|
// - extended == description in semanticscuttle
|
2007-12-12 17:29:16 +01:00
|
|
|
|
|
|
|
// Scuttle behavior:
|
|
|
|
// - Additional 'status' variable for privacy
|
|
|
|
// - No support for 'replace' variable
|
|
|
|
|
|
|
|
// Force HTTP authentication
|
2010-03-17 21:11:21 +01:00
|
|
|
$httpContentType = 'text/xml';
|
|
|
|
require_once 'httpauth.inc.php';
|
2007-12-12 17:29:16 +01:00
|
|
|
|
2008-12-05 08:25:04 +01:00
|
|
|
/* Service creation: only useful services are created */
|
2009-10-23 19:13:16 +02:00
|
|
|
$bookmarkservice =SemanticScuttle_Service_Factory::get('Bookmark');
|
2007-12-12 17:29:16 +01:00
|
|
|
|
|
|
|
// Get all the bookmark's passed-in information
|
|
|
|
if (isset($_REQUEST['url']) && (trim($_REQUEST['url']) != ''))
|
|
|
|
$url = trim(urldecode($_REQUEST['url']));
|
|
|
|
else
|
|
|
|
$url = NULL;
|
|
|
|
|
|
|
|
if (isset($_REQUEST['description']) && (trim($_REQUEST['description']) != ''))
|
|
|
|
$description = trim($_REQUEST['description']);
|
|
|
|
else
|
|
|
|
$description = NULL;
|
|
|
|
|
|
|
|
if (isset($_REQUEST['extended']) && (trim($_REQUEST['extended']) != ""))
|
|
|
|
$extended = trim($_REQUEST['extended']);
|
|
|
|
else
|
|
|
|
$extended = NULL;
|
|
|
|
|
|
|
|
if (isset($_REQUEST['tags']) && (trim($_REQUEST['tags']) != '') && (trim($_REQUEST['tags']) != ','))
|
|
|
|
$tags = trim($_REQUEST['tags']);
|
|
|
|
else
|
|
|
|
$tags = NULL;
|
|
|
|
|
|
|
|
if (isset($_REQUEST['dt']) && (trim($_REQUEST['dt']) != ''))
|
|
|
|
$dt = trim($_REQUEST['dt']);
|
|
|
|
else
|
|
|
|
$dt = NULL;
|
|
|
|
|
|
|
|
$status = 0;
|
|
|
|
if (isset($_REQUEST['status'])) {
|
|
|
|
$status_str = trim($_REQUEST['status']);
|
|
|
|
if (is_numeric($status_str)) {
|
|
|
|
$status = intval($status_str);
|
|
|
|
if($status < 0 || $status > 2) {
|
|
|
|
$status = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch ($status_str) {
|
|
|
|
case 'private':
|
|
|
|
$status = 2;
|
|
|
|
break;
|
|
|
|
case 'shared':
|
|
|
|
$status = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$status = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-22 09:51:56 +01:00
|
|
|
if (isset($_REQUEST['shared']) && (trim($_REQUEST['shared']) == 'no')) {
|
|
|
|
$status = 2;
|
|
|
|
}
|
|
|
|
|
2007-12-12 17:29:16 +01:00
|
|
|
// Error out if there's no address or description
|
2010-09-29 22:55:14 +02: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 17:29:16 +01:00
|
|
|
} else {
|
2010-09-29 22:55:14 +02:00
|
|
|
// We're good with info; now insert it!
|
|
|
|
if ($bookmarkservice->bookmarkExists($url, $userservice->getCurrentUserId())) {
|
|
|
|
$msg = 'something went wrong';
|
|
|
|
} else {
|
|
|
|
$added = $bookmarkservice->addBookmark(
|
|
|
|
$url, $description, $extended, '', $status, $tags, null, $dt, true
|
|
|
|
);
|
|
|
|
$msg = 'done';
|
|
|
|
}
|
2007-12-12 17:29:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set up the XML file and output the result.
|
2010-09-29 22:55:14 +02:00
|
|
|
echo '<?xml version="1.0" standalone="yes" ?' . ">\r\n";
|
|
|
|
echo '<result code="' . $msg .'" />';
|
2007-12-12 17:29:16 +01:00
|
|
|
?>
|