diff --git a/ajax/editBookmark.php b/ajax/editBookmark.php index bf213172..94cdd77c 100644 --- a/ajax/editBookmark.php +++ b/ajax/editBookmark.php @@ -29,23 +29,22 @@ OCP\JSON::checkAppEnabled('bookmarks'); // If we go the dialog form submit if(isset($_POST['url'])) { - $title = ''; + $title = isset($_POST['title']) ? $_POST['title'] : ''; $tags = isset($_POST['item']['tags']) ? $_POST['item']['tags'] : array(); $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); - $title = $_POST['title']; + $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(); diff --git a/ajax/updateList.php b/ajax/updateList.php index 7dadb73f..e52c2c30 100644 --- a/ajax/updateList.php +++ b/ajax/updateList.php @@ -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)); diff --git a/css/bookmarks.css b/css/bookmarks.css index 3ef77972..5bc0787b 100644 --- a/css/bookmarks.css +++ b/css/bookmarks.css @@ -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; diff --git a/js/bookmarks.js b/js/bookmarks.js index 438b72ac..96a16a47 100644 --- a/js/bookmarks.js +++ b/js/bookmarks.js @@ -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(); @@ -265,7 +266,7 @@ function updateBookmarksList(bookmark, position) { var taglist = ''; for ( var i=0, len=tags.length; i' + encodeEntities(tags[i]) + ' '; + taglist = taglist + '' + escapeHTML(tags[i]) + ' '; } if(!hasProtocol(bookmark.url)) { bookmark.url = 'http://' + bookmark.url; @@ -312,14 +313,6 @@ function recordClick(event) { }); } -function encodeEntities(s){ - try { - return $('
').text(s).html(); - } catch (ex) { - return ""; - } -} - function hasProtocol(url) { var regexp = /(ftp|http|https|sftp)/; return regexp.test(url); diff --git a/l10n/bg_BG.php b/l10n/bg_BG.php index 7f544c1a..bf8aaa99 100644 --- a/l10n/bg_BG.php +++ b/l10n/bg_BG.php @@ -1,14 +1,8 @@ "Отметки", -"Tags" => "Етикети", +"Bookmarks" => "Предпочитани", "Save" => "Запис", "Delete" => "Изтриване", -"Cancel" => "Отказ", -"Drag this to your browser bookmarks and click it, when you want to bookmark a webpage quickly:" => "Завлачете това в лентата с отметки на браузъра си и го натискайте, когато искате да отметнете бързо някоя страница:", -"Read later" => "Отмятане", -"Address" => "Адрес", +"Edit" => "Промяна", "Add" => "Добавяне", -"You have no bookmarks" => "Нямате отметки", -"Export" => "Изнасяне", -"Import" => "Внасяне" +"Settings" => "Настройки" ); diff --git a/l10n/bn_BD.php b/l10n/bn_BD.php index 746224d0..c6bd15f5 100644 --- a/l10n/bn_BD.php +++ b/l10n/bn_BD.php @@ -1,7 +1,33 @@ "আমদানি করার জন্য ফাইলের ফর্ম্যাটটি সঠিক নয়", +"Bookmarks" => "ঠিকাসমূহ", +"Tags" => "ট্যাগ", +"Filter by tag" => "ট্যাগ অনুসারে ছাঁক", +"Edit bookmark" => "ঠিকা সম্পাদনা", +"Are you sure you want to remove this tag from every entry?" => "প্রত্যেক ভুক্তি থেকে এই ট্যাগটি অপসারণ করতে আপনি কি বদ্ধপরিকর?", +"Warning" => "সতর্কবাণী", +"Import completed successfully." => "আমদানি সুসম্পন্ন হয়েছে।", +"Uploading..." => "আপলোড করা হচ্ছে..........", +"Bookm." => "ঠিকা", +"Add a bookmark" => "ঠিকা যোগ করুন", +"Close" => "বন্ধ", +"The title of the page" => "পৃষ্ঠার শিরোনাম", +"The address of the page" => "পৃষ্ঠার ঠিকানা", +"Description of the page" => "পৃষ্ঠার বিবরণ", "Save" => "সংরক্ষণ কর", "Delete" => "মুছে ফেল", +"Edit" => "সম্পাদনা", "Cancel" => "বাতিল", +"Drag this to your browser bookmarks and click it, when you want to bookmark a webpage quickly:" => "দ্রুত কোন ওয়েবপেজ ঠিকাতে সংরক্ষণ করতে চাইলে এটিকে টেনে ব্রাউজারের ঠিকাতে নিয়ে যান এবং তাতে ক্লিক করুনঃ", +"Read later" => "পরে পড়ার জন্য সংরক্ষন কর", +"Address" => "ঠিকানা", "Add" => "যোগ কর", -"Settings" => "নিয়ামকসমূহ" +"Related Tags" => "সম্পর্কযুক্ত ট্যাগ", +"Settings" => "নিয়ামকসমূহ", +"You have no bookmarks" => "আপনার কোন ঠিক নেই", +"You can also try to import a bookmark file" => "আপনি একটি ঠিকা ফাইল আমদানি করার চেষ্টা করে দেখতে পারেন", +"Bookmarklet" => "অনুঠিকা", +"Export & Import" => "আমদানি এবং রপ্তানি", +"Export" => "রপ্তানি", +"Import" => "আমদানি" ); diff --git a/l10n/hu_HU.php b/l10n/hu_HU.php index 0dd0b29c..a962b55e 100644 --- a/l10n/hu_HU.php +++ b/l10n/hu_HU.php @@ -1,8 +1,19 @@ "Az importálandó fájltípus nem támogatott", "Bookmarks" => "Könyvjelzők", "Tags" => "Címkék", +"Filter by tag" => "Rendezés címkék szerint", +"Edit bookmark" => "Könyvjelző szerkesztése", +"Are you sure you want to remove this tag from every entry?" => "Biztos vagy benne, hogy el szeretnéd távolítani ezt a címkét az összes bejegyzésből?", "Warning" => "Figyelmeztetés", +"Import completed successfully." => "Sikeres importálás.", +"Uploading..." => "Feltöltés...", +"Bookm." => "Könyvj.", +"Add a bookmark" => "Könyvjelző hozzáadása", "Close" => "Bezár", +"The title of the page" => "Az oldal neve", +"The address of the page" => "Az oldal webcíme", +"Description of the page" => "Az oldal leírása", "Save" => "Mentés", "Delete" => "Törlés", "Edit" => "Szerkesztés", @@ -11,8 +22,12 @@ "Read later" => "Később olvasom", "Address" => "Cím", "Add" => "Hozzáad", +"Related Tags" => "Kapcsolódó címkék", "Settings" => "Beállítások", "You have no bookmarks" => "Nincsenek könyvjelzőid", +"You can also try to import a bookmark file" => "Akár importálhatsz is egy könyvjelző fájlt", +"Bookmarklet" => "Könyvjelző", +"Export & Import" => "Export és import", "Export" => "Exportálás", "Import" => "Import" ); diff --git a/l10n/lv.php b/l10n/lv.php index 59a19938..f9a213a8 100644 --- a/l10n/lv.php +++ b/l10n/lv.php @@ -1,4 +1,5 @@ "Saglabāt", "Delete" => "Izdzēst", "Settings" => "Iestatījumi" ); diff --git a/lib/bookmarks.php b/lib/bookmarks.php index be868334..1040edc3 100644 --- a/lib/bookmarks.php +++ b/lib/bookmarks.php @@ -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, @@ -384,14 +412,14 @@ class OC_Bookmarks_Bookmarks{ $url = 'http://' . $url; } $metadata['url'] = $url; - - if (!function_exists('curl_init')) { - return $metadata; - } $page = OC_Util::getUrlContent($url); if($page) { if(preg_match( "/(.*)<\/title>/sUi", $page, $match ) !== false) - $metadata['title'] = htmlspecialchars_decode($match[1]); + $metadata['title'] = html_entity_decode($match[1], ENT_NOQUOTES , 'UTF-8'); + //Not the best solution but.... + $metadata['title'] = str_replace('™', chr(153), $metadata['title']); + $metadata['title'] = str_replace('‐', '‐', $metadata['title']); + $metadata['title'] = str_replace('–', '–', $metadata['title']); } return $metadata; } diff --git a/templates/js_tpl.php b/templates/js_tpl.php index 365ca467..75b39a85 100644 --- a/templates/js_tpl.php +++ b/templates/js_tpl.php @@ -7,10 +7,10 @@ </span>  </p> <p class="bookmark_title"> - <a href="<%= encodeEntities(url) %>" target="_blank" class="bookmark_link"> - <%= encodeEntities(title == '' ? url : title ) %> + <a href="<%= encodeURI(url) %>" target="_blank" class="bookmark_link"> + <%= escapeHTML(title == '' ? encodeURI(url) : title ) %> </a> - <span class="bookmark_desc"><%= encodeEntities(description)%> </span> + <span class="bookmark_desc"><%= escapeHTML(description)%> </span> <span class="bookmark_date"><%= formatDate(added_date) %></span> </p> <div class="bookmark_edit_btn"> @@ -28,11 +28,11 @@ <input type="hidden" name="record_id" value="<%= id %>" /> <p class="bookmark_form_title"> <input type="text" name="title" placeholder="<?php echo $l->t('The title of the page');?>" - value="<%= title %>"/> + value="<%= escapeHTML(title) %>"/> </p> <p class="bookmark_form_url"> <input type="text" name="url" placeholder="<?php echo $l->t('The address of the page');?>" - value="<%= encodeEntities(url)%>"/> + value="<%= encodeURI(url)%>"/> </p> <div class="bookmark_form_tags"><ul> <% for ( var i = 0; i < tags.length; i++ ) { %> @@ -41,7 +41,7 @@ </ul></div> <p class="bookmark_form_desc"> <textarea name="description" placeholder="<?php echo $l->t('Description of the page');?>" - ><%= description%></textarea> + ><%= escapeHTML(description) %></textarea> </p> <p class="bookmark_form_submit"><button class="reset" ><?php echo $l->t('Cancel');?></button> <input type="submit" value="<?php echo $l->t('Save');?>">