]> git.wh0rd.org Git - tt-rss.git/commitdiff
sharepopup: implement assigning labels while sharing
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Wed, 31 Oct 2012 08:55:24 +0000 (12:55 +0400)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Wed, 31 Oct 2012 08:55:24 +0000 (12:55 +0400)
classes/api.php
classes/handler/public.php
classes/pref/feeds.php
classes/rpc.php
include/functions.php
utility.css

index 6e5ed4aa8f628486b655cd2420ff7ad3ab9bd3d1..15576c7c0dbf0d443732eeaa450f0528bed5e754 100644 (file)
@@ -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'));
index d3c3fc094cba5d6bd38dbf7a64643c4fb23ea031..f2a7730c895f9a9e961d486b623aed1a0b96daa6 100644 (file)
@@ -383,6 +383,7 @@ class Handler_Public extends Handler {
                                        <title>Tiny Tiny RSS</title>
                                        <link rel=\"stylesheet\" type=\"text/css\" href=\"utility.css\">
                                        <script type=\"text/javascript\" src=\"lib/prototype.js\"></script>
+                                       <script type=\"text/javascript\" src=\"lib/scriptaculous/scriptaculous.js?load=effects,dragdrop,controls\"></script>
                                        <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
                                </head>
                                <body id='sharepopup'>";
@@ -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 "<script type='text/javascript'>";
                                print "window.close();";
@@ -424,9 +427,23 @@ class Handler_Public extends Handler {
                                <td><input name='url' value="<?php echo $url ?>"></td></tr>
                                <tr><td align='right'><?php echo __("Content:") ?></td>
                                <td><input name='content' value=""></td></tr>
+                               <tr><td align='right'><?php echo __("Labels:") ?></td>
+                               <td><input name='labels' id="labels_value"
+                                       placeholder='Alpha, Beta, Gamma' value="">
+                               </td></tr>
+
+                               <tr><td>
+                                       <div class="autocomplete" id="labels_choices"
+                                               style="display : block"></div></td></tr>
 
                                <script type='text/javascript'>document.forms[0].title.focus();</script>
 
+                               <script type='text/javascript'>
+                                       new Ajax.Autocompleter('labels_value', 'labels_choices',
+                                  "backend.php?op=rpc&method=completeLabels",
+                                  { tokens: ',', paramName: "search" });
+                               </script>
+
                                <tr><td colspan='2'>
                                        <div style='float : right' class='insensitive-small'>
                                        <?php echo __("Shared article will appear in the Published feed.") ?>
index 91c504ce4e080c3b1ecaaac1d8c9ebd0376849ef..8cfa5336a5c2f786f2b34de1e9187016b41c1381 100644 (file)
@@ -1479,7 +1479,7 @@ class Pref_Feeds extends Handler_Protected {
 
                print "<p>" . __("Use this bookmarklet to publish arbitrary pages using Tiny Tiny RSS") . "</p>";
 
-               $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 "<a href=\"$bm_url\" class='bookmarklet'>" . __('Share with Tiny Tiny RSS'). "</a>";
 
index cb3eeda98ff73a6e891e5a335a909eac96d91404..35de3362a26fa8349b98058d48ac68a653b71027 100644 (file)
@@ -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 "<ul>";
+               while ($line = db_fetch_assoc($result)) {
+                       print "<li>" . $line["caption"] . "</li>";
+               }
+               print "</ul>";
+       }
+
+
        function completeTags() {
                $search = db_escape_string($_REQUEST["search"]);
 
index 2695b1cb94fd74e19b2722f2da5d1c5d86519bb8..a81a2c0cd65e52e0ccbdb9cbdd393914d7423d99 100644 (file)
 
        }
 
-       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;
                                        ('$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 {
                                        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;
                        }
                }
index 41541c707297e1170f712d1f5a1f922167d4a146..de0042a774c354c4a7759849f9ff00c7439c91cf 100644 (file)
@@ -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;
+}
+