mirror of
https://github.com/owncloud/bookmarks.git
synced 2025-02-18 15:54:28 +01:00
[Bookmark] Avoid duplicate BM, refresh old one if already exists. fix #160
This commit is contained in:
parent
be3147d21c
commit
a82bd45f26
@ -34,17 +34,17 @@ if(isset($_POST['url'])) {
|
|||||||
$pub = isset($_POST['is_public']) ? true : false;
|
$pub = isset($_POST['is_public']) ? true : false;
|
||||||
|
|
||||||
if(isset($_POST['record_id']) && is_numeric($_POST['record_id']) ) { //EDIT
|
if(isset($_POST['record_id']) && is_numeric($_POST['record_id']) ) { //EDIT
|
||||||
$bm = $_POST['record_id'];
|
$id = OC_Bookmarks_Bookmarks::editBookmark($_POST['record_id'], $_POST['url'], $_POST['title'], $tags, $_POST['description'], $pub);
|
||||||
OC_Bookmarks_Bookmarks::editBookmark($bm, $_POST['url'], $_POST['title'], $tags, $_POST['description'], $pub);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(isset($_POST['from_own'])) {
|
if(isset($_POST['from_own'])) {
|
||||||
$datas = OC_Bookmarks_Bookmarks::getURLMetadata($_POST['url']);
|
$datas = OC_Bookmarks_Bookmarks::getURLMetadata($_POST['url']);
|
||||||
if(isset($datas['title'])) $title = $datas['title'];
|
if(isset($datas['title'])) $title = $datas['title'];
|
||||||
}
|
}
|
||||||
$bm = OC_Bookmarks_Bookmarks::addBookmark($_POST['url'], $title, $tags, $_POST['description'], $pub);
|
$id = OC_Bookmarks_Bookmarks::addBookmark($_POST['url'], $title, $tags, $_POST['description'], $pub);
|
||||||
}
|
}
|
||||||
OCP\JSON::success(array('id'=>$bm,'title'=>$title));
|
$bm = OC_Bookmarks_Bookmarks::findOneBookmark($id);
|
||||||
|
OCP\JSON::success(array('item'=>$bm));
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
OC_JSON::error();
|
OC_JSON::error();
|
||||||
|
@ -43,7 +43,7 @@ else { // type == bookmark
|
|||||||
if($sort == 'bookmarks_sorting_clicks') {
|
if($sort == 'bookmarks_sorting_clicks') {
|
||||||
$sqlSortColumn = 'clickcount';
|
$sqlSortColumn = 'clickcount';
|
||||||
} else {
|
} else {
|
||||||
$sqlSortColumn = 'id';
|
$sqlSortColumn = 'lastmodified';
|
||||||
}
|
}
|
||||||
$bookmarks = OC_Bookmarks_Bookmarks::findBookmarks($offset, $sqlSortColumn, $filterTag, true);
|
$bookmarks = OC_Bookmarks_Bookmarks::findBookmarks($offset, $sqlSortColumn, $filterTag, true);
|
||||||
OCP\JSON::success(array('data' => $bookmarks));
|
OCP\JSON::success(array('data' => $bookmarks));
|
||||||
|
@ -173,16 +173,17 @@ function addBookmark(event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$('#add_url').val('');
|
$('#add_url').val('');
|
||||||
bookmark = { url: url, description:'', title:'', from_own: '1'};
|
bookmark = { url: url, description:'', title:'', from_own: '1', added_date: new Date()};
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
url: OC.filePath('bookmarks', 'ajax', 'editBookmark.php'),
|
url: OC.filePath('bookmarks', 'ajax', 'editBookmark.php'),
|
||||||
data: bookmark,
|
data: bookmark,
|
||||||
success: function(data){
|
success: function(data){
|
||||||
if (data.status == 'success') {
|
if (data.status == 'success') {
|
||||||
bookmark.id = data.id;
|
// First remove old BM if exists
|
||||||
bookmark.title = data.title
|
$('.bookmark_single').filterAttr('data-id', data.item.id).remove();
|
||||||
bookmark.added_date = new Date();
|
|
||||||
|
bookmark = $.extend({}, bookmark, data.item);
|
||||||
updateBookmarksList(bookmark, 'prepend');
|
updateBookmarksList(bookmark, 'prepend');
|
||||||
checkEmpty();
|
checkEmpty();
|
||||||
watchUrlField();
|
watchUrlField();
|
||||||
|
@ -51,7 +51,23 @@ class OC_Bookmarks_Bookmarks{
|
|||||||
$tags = $query->execute($params)->fetchAll();
|
$tags = $query->execute($params)->fetchAll();
|
||||||
return $tags;
|
return $tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function findOneBookmark($id) {
|
||||||
|
if($CONFIG_DBTYPE == 'pgsql') {
|
||||||
|
$group_fct = 'array_agg(tag)';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$group_fct = 'GROUP_CONCAT(tag)';
|
||||||
|
}
|
||||||
|
$sql = "SELECT *, (select $group_fct from *PREFIX*bookmarks_tags where bookmark_id = b.id) as tags
|
||||||
|
FROM *PREFIX*bookmarks b
|
||||||
|
WHERE user_id = ? and id = ?";
|
||||||
|
$query = OCP\DB::prepare($sql);
|
||||||
|
$result = $query->execute(array(OCP\USER::getUser(), $id))->fetchRow();
|
||||||
|
$result['tags'] = explode(',', $result['tags']);
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Finds all bookmarks, matching the filter
|
* @brief Finds all bookmarks, matching the filter
|
||||||
* @param offset result offset
|
* @param offset result offset
|
||||||
@ -295,11 +311,23 @@ class OC_Bookmarks_Bookmarks{
|
|||||||
* @return int The id of the bookmark created
|
* @return int The id of the bookmark created
|
||||||
*/
|
*/
|
||||||
public static function addBookmark($url, $title, $tags=array(), $description='', $is_public=false) {
|
public static function addBookmark($url, $title, $tags=array(), $description='', $is_public=false) {
|
||||||
|
|
||||||
$is_public = $is_public ? 1 : 0;
|
$is_public = $is_public ? 1 : 0;
|
||||||
//FIXME: Detect and do smth when user adds a known URL
|
$enc_url = htmlspecialchars_decode($url);
|
||||||
$_ut = self::getNowValue();
|
$_ut = self::getNowValue();
|
||||||
|
|
||||||
|
// Change lastmodified date if the record if already exists
|
||||||
|
$sql = "SELECT id from *PREFIX*bookmarks WHERE url = ? and user_id = ?";
|
||||||
|
$query = OCP\DB::prepare($sql, 1);
|
||||||
|
$result = $query->execute(array($enc_url, OCP\USER::getUser()));
|
||||||
|
if(count($result) != 0) {
|
||||||
|
$row = $result->fetchRow();
|
||||||
|
$sql = "UPDATE *PREFIX*bookmarks SET lastmodified = $_ut WHERE url = ? and user_id = ?";
|
||||||
|
$query = OCP\DB::prepare($sql);
|
||||||
|
$query->execute(array($enc_url, OCP\USER::getUser()));
|
||||||
|
return $row['id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$query = OCP\DB::prepare("
|
$query = OCP\DB::prepare("
|
||||||
INSERT INTO *PREFIX*bookmarks
|
INSERT INTO *PREFIX*bookmarks
|
||||||
(url, title, user_id, public, added, lastmodified, description)
|
(url, title, user_id, public, added, lastmodified, description)
|
||||||
@ -307,7 +335,7 @@ class OC_Bookmarks_Bookmarks{
|
|||||||
");
|
");
|
||||||
|
|
||||||
$params=array(
|
$params=array(
|
||||||
htmlspecialchars_decode($url),
|
$enc_url,
|
||||||
htmlspecialchars_decode($title),
|
htmlspecialchars_decode($title),
|
||||||
OCP\USER::getUser(),
|
OCP\USER::getUser(),
|
||||||
$is_public,
|
$is_public,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user