From b6ea57c8b6fac904f97f456463a52e509de51733 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Thu, 3 May 2012 17:29:08 +0200 Subject: [PATCH] Bookmarks: Move delete code to Bookmarks class, also change to use id --- apps/bookmarks/ajax/delBookmark.php | 35 +++++------------------------ apps/bookmarks/js/bookmarks.js | 10 +++++---- apps/bookmarks/lib/bookmarks.php | 32 ++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 33 deletions(-) diff --git a/apps/bookmarks/ajax/delBookmark.php b/apps/bookmarks/ajax/delBookmark.php index 2634bed0b9..0b5689811a 100755 --- a/apps/bookmarks/ajax/delBookmark.php +++ b/apps/bookmarks/ajax/delBookmark.php @@ -30,33 +30,10 @@ $RUNTIME_NOSETUPFS=true; OCP\JSON::checkLoggedIn(); OCP\JSON::checkAppEnabled('bookmarks'); -$params=array( - htmlspecialchars_decode($_GET["url"]), - OCP\USER::getUser() - ); +$id = $_GET['id']; +if (!OC_Bookmarks_Bookmarks::deleteUrl($id)){ + OC_JSON::error(); + exit(); +} -$query = OCP\DB::prepare(" - SELECT id FROM *PREFIX*bookmarks - WHERE url LIKE ? - AND user_id = ? - "); - -$id = $query->execute($params)->fetchOne(); - -$query = OCP\DB::prepare(" - DELETE FROM *PREFIX*bookmarks - WHERE id = $id - "); - -$result = $query->execute(); - - -$query = OCP\DB::prepare(" - DELETE FROM *PREFIX*bookmarks_tags - WHERE bookmark_id = $id - "); - -$result = $query->execute(); -// var_dump($params); - -OCP\JSON::success(array('data' => array())); +OCP\JSON::success(); diff --git a/apps/bookmarks/js/bookmarks.js b/apps/bookmarks/js/bookmarks.js index 38b8c43eb7..b1eebaa551 100644 --- a/apps/bookmarks/js/bookmarks.js +++ b/apps/bookmarks/js/bookmarks.js @@ -93,11 +93,13 @@ function delBookmark(event) { var record = $(this).parent().parent(); $.ajax({ url: OC.filePath('bookmarks', 'ajax', 'delBookmark.php'), - data: 'url=' + encodeURIComponent($(this).parent().parent().children('.bookmark_url:first').text()), + data: 'id=' + record.data('id'), success: function(data){ - record.remove(); - if($('.bookmarks_list').is(':empty')) { - $("#firstrun").show(); + if (data.status == 'success') { + record.remove(); + if($('.bookmarks_list').is(':empty')) { + $("#firstrun").show(); + } } } }); diff --git a/apps/bookmarks/lib/bookmarks.php b/apps/bookmarks/lib/bookmarks.php index 67b8e2f780..e0005968f3 100755 --- a/apps/bookmarks/lib/bookmarks.php +++ b/apps/bookmarks/lib/bookmarks.php @@ -113,5 +113,37 @@ class OC_Bookmarks_Bookmarks{ $bookmarks = $query->execute($params)->fetchAll(); return $bookmarks; } + + public static function deleteUrl($id) + { + $user = OCP\USER::getUser(); + + $query = OCP\DB::prepare(" + SELECT id FROM *PREFIX*bookmarks + WHERE id = ? + AND user_id = ? + "); + + $result = $query->execute(array($id, $user)); + $id = $result->fetchOne(); + if ($id === false) { + return false; + } + + $query = OCP\DB::prepare(" + DELETE FROM *PREFIX*bookmarks + WHERE id = $id + "); + + $result = $query->execute(); + + $query = OCP\DB::prepare(" + DELETE FROM *PREFIX*bookmarks_tags + WHERE bookmark_id = $id + "); + + $result = $query->execute(); + return true; + } } ?>