summaryrefslogtreecommitdiff
path: root/www/api
diff options
context:
space:
mode:
authorcweiske <cweiske@b3834d28-1941-0410-a4f8-b48e95affb8f>2010-09-29 20:57:30 +0000
committercweiske <cweiske@b3834d28-1941-0410-a4f8-b48e95affb8f>2010-09-29 20:57:30 +0000
commit8e2b25a095ab769146ac7fa672d7a4c4eda32ab4 (patch)
treeda7acce61ecc547ea9b4bb5c183397c8a1e0c230 /www/api
parent66af94feaf9ef817da260c0d293577bf74e53bcf (diff)
downloadsemanticscuttle-8e2b25a095ab769146ac7fa672d7a4c4eda32ab4.tar.gz
semanticscuttle-8e2b25a095ab769146ac7fa672d7a4c4eda32ab4.tar.bz2
api/posts/add respects the "replace" parameter now
git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@777 b3834d28-1941-0410-a4f8-b48e95affb8f
Diffstat (limited to 'www/api')
-rw-r--r--www/api/posts_add.php24
1 files changed, 20 insertions, 4 deletions
diff --git a/www/api/posts_add.php b/www/api/posts_add.php
index 0e06d50..7f9dc59 100644
--- a/www/api/posts_add.php
+++ b/www/api/posts_add.php
@@ -16,6 +16,8 @@
* - 0 or 'public': Everyone can see the bookmark
* @param string $shared "no" or "yes": Switches between private and
* public (optional)
+ * @param string $replace "yes" or "no" - replaces a bookmark with the
+ * same URL (optional)
*
* Notes:
* - tags cannot have spaces
@@ -23,7 +25,6 @@
* - 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.
*
@@ -78,6 +79,8 @@ if (isset($_REQUEST['dt']) && (trim($_REQUEST['dt']) != '')) {
$dt = null;
}
+$replace = isset($_REQUEST['replace']) && ($_REQUEST['replace'] == 'yes');
+
$status = 0;
if (isset($_REQUEST['status'])) {
$status_str = trim($_REQUEST['status']);
@@ -114,9 +117,22 @@ if (is_null($url)) {
$msg = 'Description missing';
} else {
// We're good with info; now insert it!
- if ($bs->bookmarkExists($url, $userservice->getCurrentUserId())) {
- $msg = 'something went wrong';
- } else {
+ $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) {
$added = $bs->addBookmark(
$url, $description, $extended, '', $status, $tags, null, $dt, true
);