1
0
mirror of https://github.com/owncloud/bookmarks.git synced 2025-01-18 14:52:10 +01:00

Merge branch 'master' into navigation

This commit is contained in:
Jan-Christoph Borchardt 2013-01-17 15:01:37 +07:00
commit ebbde7e14b
5 changed files with 66 additions and 23 deletions

View File

@ -34,17 +34,17 @@ if(isset($_POST['url'])) {
$pub = isset($_POST['is_public']) ? true : false;
if(isset($_POST['record_id']) && is_numeric($_POST['record_id']) ) { //EDIT
$bm = $_POST['record_id'];
OC_Bookmarks_Bookmarks::editBookmark($bm, $_POST['url'], $_POST['title'], $tags, $_POST['description'], $pub);
$id = OC_Bookmarks_Bookmarks::editBookmark($_POST['record_id'], $_POST['url'], $_POST['title'], $tags, $_POST['description'], $pub);
}
else {
if(isset($_POST['from_own'])) {
$datas = OC_Bookmarks_Bookmarks::getURLMetadata($_POST['url']);
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();
}
OC_JSON::error();

View File

@ -43,7 +43,7 @@ else { // type == bookmark
if($sort == 'bookmarks_sorting_clicks') {
$sqlSortColumn = 'clickcount';
} else {
$sqlSortColumn = 'id';
$sqlSortColumn = 'lastmodified';
}
$bookmarks = OC_Bookmarks_Bookmarks::findBookmarks($offset, $sqlSortColumn, $filterTag, true);
OCP\JSON::success(array('data' => $bookmarks));

View File

@ -98,6 +98,7 @@ input.disabled, input.disabled:hover, input.disabled:focus {
font-weight: bold;
display: inline-block;
margin-right: 0.8em;
margin-top:0.7em;
width: 20%;
text-overflow: ellipsis;
overflow: hidden;
@ -205,7 +206,7 @@ input.disabled, input.disabled:hover, input.disabled:focus {
font-weight: normal;
float:left;
padding: 0.3em;
position: relative;
position: relative;
}
ul.tagit li.tagit-new {
@ -249,8 +250,8 @@ li:hover em { display : none; }
#tag_filter ul.tagit li.tagit-choice .close{
margin-top: -8px;
cursor: pointer;
margin-top: -8px;
position: absolute;
margin-top: -8px;
position: absolute;
right: 0.1em;
top: 50%;
}
@ -262,12 +263,12 @@ li:hover em { display : none; }
text-overflow:ellipsis;
overflow:hidden;
display:block;
float:left;
position: absolute;
left: 25%;
width:40%;
top: 0.7em;
font-weight:500;
float:left;
position: absolute;
left: 25%;
width:40%;
top: 0.7em;
font-weight:500;
}
.bookmark_date, .bookmark_submit {
font-size:small;
@ -276,7 +277,7 @@ li:hover em { display : none; }
color:gray;
/* margin-top:2.5em; */
margin-right: 0.2em;
top:0.8em;
top:0.8em;
}
/*
@ -295,6 +296,19 @@ li:hover em { display : none; }
width: 80%;
}
.bookmark_single .bookmark_edit_btn {
display:none;
}
.bookmark_single:hover .bookmark_edit_btn {
display:block;
}
.bookmark_single:focus .bookmark_edit_btn {
display:block;
opacity:1;
}
.bookmark_single_form {
padding-top: 1em;
border-bottom: 1px solid #DDD;

View File

@ -173,16 +173,17 @@ function addBookmark(event) {
}
$('#add_url').val('');
bookmark = { url: url, description:'', title:'', from_own: '1'};
bookmark = { url: url, description:'', title:'', from_own: '1', added_date: new Date()};
$.ajax({
type: 'POST',
url: OC.filePath('bookmarks', 'ajax', 'editBookmark.php'),
data: bookmark,
success: function(data){
if (data.status == 'success') {
bookmark.id = data.id;
bookmark.title = data.title
bookmark.added_date = new Date();
// First remove old BM if exists
$('.bookmark_single').filterAttr('data-id', data.item.id).remove();
bookmark = $.extend({}, bookmark, data.item);
updateBookmarksList(bookmark, 'prepend');
checkEmpty();
watchUrlField();

View File

@ -51,7 +51,23 @@ class OC_Bookmarks_Bookmarks{
$tags = $query->execute($params)->fetchAll();
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
* @param offset result offset
@ -295,11 +311,23 @@ class OC_Bookmarks_Bookmarks{
* @return int The id of the bookmark created
*/
public static function addBookmark($url, $title, $tags=array(), $description='', $is_public=false) {
$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();
// 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("
INSERT INTO *PREFIX*bookmarks
(url, title, user_id, public, added, lastmodified, description)
@ -307,7 +335,7 @@ class OC_Bookmarks_Bookmarks{
");
$params=array(
htmlspecialchars_decode($url),
$enc_url,
htmlspecialchars_decode($title),
OCP\USER::getUser(),
$is_public,