From 1b4d1a6b449de081f2d45983df11950ac4c453bc Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 31 Oct 2012 12:55:24 +0400 Subject: [PATCH] sharepopup: implement assigning labels while sharing --- classes/api.php | 2 +- classes/handler/public.php | 19 ++++++++++++++++++- classes/pref/feeds.php | 2 +- classes/rpc.php | 19 ++++++++++++++++++- include/functions.php | 24 ++++++++++++++++++++++-- utility.css | 31 +++++++++++++++++++++++++++++++ 6 files changed, 91 insertions(+), 6 deletions(-) diff --git a/classes/api.php b/classes/api.php index 6e5ed4aa..15576c7c 100644 --- a/classes/api.php +++ b/classes/api.php @@ -439,7 +439,7 @@ class API extends Handler { $url = db_escape_string(strip_tags($_REQUEST["url"])); $content = db_escape_string(strip_tags($_REQUEST["content"])); - if (create_published_article($this->link, $title, $url, $content, $_SESSION["uid"])) { + if (create_published_article($this->link, $title, $url, $content, "", $_SESSION["uid"])) { print $this->wrap(self::STATUS_OK, array("status" => 'OK')); } else { print $this->wrap(self::STATUS_ERR, array("error" => 'Publishing failed')); diff --git a/classes/handler/public.php b/classes/handler/public.php index d3c3fc09..f2a7730c 100644 --- a/classes/handler/public.php +++ b/classes/handler/public.php @@ -383,6 +383,7 @@ class Handler_Public extends Handler { Tiny Tiny RSS + "; @@ -396,8 +397,10 @@ class Handler_Public extends Handler { $title = db_escape_string(strip_tags($_REQUEST["title"])); $url = db_escape_string(strip_tags($_REQUEST["url"])); $content = db_escape_string(strip_tags($_REQUEST["content"])); + $labels = db_escape_string(strip_tags($_REQUEST["labels"])); - create_published_article($this->link, $title, $url, $content, $_SESSION["uid"]); + create_published_article($this->link, $title, $url, $content, $labels, + $_SESSION["uid"]); print " + +
diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php index 91c504ce..8cfa5336 100644 --- a/classes/pref/feeds.php +++ b/classes/pref/feeds.php @@ -1479,7 +1479,7 @@ class Pref_Feeds extends Handler_Protected { print "

" . __("Use this bookmarklet to publish arbitrary pages using Tiny Tiny RSS") . "

"; - $bm_url = htmlspecialchars("javascript:(function(){var d=document,w=window,e=w.getSelection,k=d.getSelection,x=d.selection,s=(e?e():(k)?k():(x?x.createRange().text:0)),f='".SELF_URL_PATH."/public.php?op=sharepopup',l=d.location,e=encodeURIComponent,g=f+'&title='+((e(s))?e(s):e(document.title))+'&url='+e(l.href);function a(){if(!w.open(g,'t','toolbar=0,resizable=0,scrollbars=1,status=1,width=500,height=200')){l.href=g;}}a();})()"); + $bm_url = htmlspecialchars("javascript:(function(){var d=document,w=window,e=w.getSelection,k=d.getSelection,x=d.selection,s=(e?e():(k)?k():(x?x.createRange().text:0)),f='".SELF_URL_PATH."/public.php?op=sharepopup',l=d.location,e=encodeURIComponent,g=f+'&title='+((e(s))?e(s):e(document.title))+'&url='+e(l.href);function a(){if(!w.open(g,'t','toolbar=0,resizable=0,scrollbars=1,status=1,width=500,height=250')){l.href=g;}}a();})()"); print "" . __('Share with Tiny Tiny RSS'). ""; diff --git a/classes/rpc.php b/classes/rpc.php index cb3eeda9..35de3362 100644 --- a/classes/rpc.php +++ b/classes/rpc.php @@ -2,7 +2,7 @@ class RPC extends Handler_Protected { function csrf_ignore($method) { - $csrf_ignored = array("sanitycheck", "buttonplugin", "exportget", "sharepopup"); + $csrf_ignored = array("sanitycheck", "buttonplugin", "exportget", "completelabels"); return array_search($method, $csrf_ignored) !== false; } @@ -426,6 +426,23 @@ class RPC extends Handler_Protected { print json_encode(array("link" => $new_link)); } + function completeLabels() { + $search = db_escape_string($_REQUEST["search"]); + + $result = db_query($this->link, "SELECT DISTINCT caption FROM + ttrss_labels2 + WHERE owner_uid = '".$_SESSION["uid"]."' AND + LOWER(caption) LIKE LOWER('$search%') ORDER BY caption + LIMIT 5"); + + print ""; + } + + function completeTags() { $search = db_escape_string($_REQUEST["search"]); diff --git a/include/functions.php b/include/functions.php index 2695b1cb..a81a2c0c 100644 --- a/include/functions.php +++ b/include/functions.php @@ -5545,10 +5545,18 @@ } - function create_published_article($link, $title, $url, $content, $owner_uid) { - $guid = sha1($url); + function create_published_article($link, $title, $url, $content, $labels_str, + $owner_uid) { + + $guid = sha1($url . $owner_uid); // include owner_uid to prevent global GUID clash $content_hash = sha1($content); + if ($labels_str != "") { + $labels = explode(",", $labels_str); + } else { + $labels = array(); + } + $rc = false; if (!$title) $title = $url; @@ -5584,6 +5592,12 @@ ('$ref_id', '', NULL, NULL, $owner_uid, true, '', '', NOW(), '', false)"); } + if (count($labels) != 0) { + foreach ($labels as $label) { + label_add_article($link, $ref_id, trim($label), $owner_uid); + } + } + $rc = true; } else { @@ -5602,6 +5616,12 @@ VALUES ('$ref_id', '', NULL, NULL, $owner_uid, true, '', '', NOW(), '', false)"); + if (count($labels) != 0) { + foreach ($labels as $label) { + label_add_article($link, $ref_id, trim($label), $owner_uid); + } + } + $rc = true; } } diff --git a/utility.css b/utility.css index 41541c70..de0042a7 100644 --- a/utility.css +++ b/utility.css @@ -151,3 +151,34 @@ body#sharepopup form { body#sharepopup input { width : 100%; } + +div.autocomplete { + position : absolute; + width : 250px; + background-color : white; + border :1px solid #778899; + margin : 0px; + padding : 0px; + z-index : 4; +} + +div.autocomplete ul { + list-style-type : none; + margin : 0px; + padding : 0px; + font-size : 10px; +} + +div.autocomplete ul li.selected { + background-color : #fff7d5; +} + +div.autocomplete ul li { + list-style-type : none; + display : block; + margin : 0; + padding : 2px; + height : 32px; + cursor : pointer; +} + -- 2.39.2