]> git.wh0rd.org Git - tt-rss.git/commitdiff
implement sharing of arbitrary stuff using bookmarklet and API call, bump API version
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Sun, 9 Sep 2012 12:05:59 +0000 (16:05 +0400)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Sun, 9 Sep 2012 12:05:59 +0000 (16:05 +0400)
classes/api.php
classes/handler/public.php
classes/pref/feeds.php
classes/rpc.php
include/functions.php
utility.css

index 2e9c1b9026500fc4ded8f8966d2f60025d34c675..cce1d2a78d6837f2ce3adab5b5a744c48695abf1 100644 (file)
@@ -2,7 +2,7 @@
 
 class API extends Handler {
 
-       const API_LEVEL  = 3;
+       const API_LEVEL  = 4;
 
        const STATUS_OK  = 0;
        const STATUS_ERR = 1;
@@ -419,6 +419,17 @@ class API extends Handler {
                print $this->wrap(self::STATUS_ERR, array("error" => 'UNKNOWN_METHOD'));
        }
 
+       function shareToPublished() {
+               $title = db_escape_string(strip_tags($_REQUEST["title"]));
+               $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"])) {
+                       print $this->wrap(self::STATUS_OK, array("status" => 'OK'));
+               } else {
+                       print $this->wrap(self::STATUS_ERR, array("error" => 'Publishing failed'));
+               }
+       }
 }
 
 ?>
index 983f0aaa9fcab92cc8c8b1b62dc6e1df0b6b4b85..cd46fa033df0f7fef269c6379770a193cce7009d 100644 (file)
@@ -306,5 +306,75 @@ class Handler_Public extends Handler {
                // Update all feeds needing a update.
                update_daemon_common($this->link, 0, true, false);
        }
+
+       function sharepopup() {
+               header('Content-Type: text/html; charset=utf-8');
+               print "<html>
+                               <head>
+                                       <title>Tiny Tiny RSS</title>
+                                       <link rel=\"stylesheet\" type=\"text/css\" href=\"utility.css\">
+                                       <script type=\"text/javascript\" src=\"lib/prototype.js\"></script>
+                                       <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
+                               </head>
+                               <body id='sharepopup'>";
+
+               $action = $_REQUEST["action"];
+
+               if ($_SESSION["uid"]) {
+
+                       if (!$action) {
+
+                               print "<table height='100%' width='100%'><tr><td colspan='2'>";
+                               print "<h1>Publish with Tiny Tiny RSS</h1>";
+                               print "</td></tr>";
+
+                               print "<form id='share_form' name='share_form'>";
+
+                               print "<input type=\"hidden\" name=\"op\" value=\"sharepopup\">";
+                               print "<input type=\"hidden\" name=\"action\" value=\"share\">";
+
+                               $title = htmlspecialchars($_REQUEST["title"]);
+                               $url = htmlspecialchars($_REQUEST["url"]);
+
+                               print "<tr><td>".__("Title:")."</td><td width='80%'><input name='title' value=\"$title\"></td></tr>";
+                               print "<tr><td>".__("URL:")."</td><td><input name='url' value=\"$url\"></td></tr>";
+                               print "<tr><td>".__("Content:")."</td><td><input name='content' value=\"\"></td></tr>";
+
+                               print "<script type='text/javascript'>";
+                               print "document.forms[0].title.focus();";
+                               print "</script>";
+
+                               print "<tr><td colspan='2'>
+                                       <button type=\"submit\">".
+                                               __('Publish')."</button>
+                                       <button onclick=\"return window.close()\">".
+                                               __('Cancel')."</button>
+                                       </div>";
+
+                               print "</form>";
+                               print "</td></tr></table>";
+
+                               print "</body></html>";
+
+                       } else {
+
+                               $title = db_escape_string(strip_tags($_REQUEST["title"]));
+                               $url = db_escape_string(strip_tags($_REQUEST["url"]));
+                               $content = db_escape_string(strip_tags($_REQUEST["content"]));
+
+                               create_published_article($this->link, $title, $url, $content, $_SESSION["uid"]);
+
+                               print "<script type='text/javascript'>";
+                               print "window.close();";
+                               print "</script>";
+                       }
+
+               } else {
+
+                       print "<table><tr><td>" . __("Not logged in.") . "</td></tr></table>";
+
+               }
+       }
+
 }
 ?>
index ef308ee1c9751f95e66d7f2c421050a4bc3f7b1b..d6bb94ebe2158e38e14ba35ba4e4ccb8777b5929 100644 (file)
@@ -1557,7 +1557,7 @@ class Pref_Feeds extends Handler_Protected {
                        print "</div>"; # pane
                }
 
-               print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Subscribing using bookmarklet')."\">";
+               print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Bookmarklets')."\">";
 
                print "<p>" . __("Drag the link below to your browser toolbar, open the feed you're interested in in your browser and click on the link to subscribe to it.") . "</p>";
 
@@ -1569,6 +1569,12 @@ class Pref_Feeds extends Handler_Protected {
 
                print "<a href=\"$bm_url\" class='bookmarklet'>" . __('Subscribe in Tiny Tiny RSS'). "</a>";
 
+               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();})()");
+
+               print "<a href=\"$bm_url\" class='bookmarklet'>" . __('Share with Tiny Tiny RSS'). "</a>";
+
                print "</div>"; #pane
 
                print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Published & shared articles / Generated feeds')."\">";
index db34a6c9d4a78bf70502a2842ee3048d473fd4fa..733649139f381d184e899ec30fc77d6ae479f1df 100644 (file)
@@ -2,7 +2,7 @@
 class RPC extends Handler_Protected {
 
        function csrf_ignore($method) {
-               $csrf_ignored = array("sanitycheck", "buttonplugin", "exportget");
+               $csrf_ignored = array("sanitycheck", "buttonplugin", "exportget", "sharepopup");
 
                return array_search($method, $csrf_ignored) !== false;
        }
index b9383790b191298a60e4e95cba20b558497d6cef..bbf7dd8da41be6421859d3721629d3ec1253c048 100644 (file)
                                $limit_query_part = "LIMIT " . $limit;
                        }
 
+                       $allow_archived = false;
+
                        $vfeed_query_part = "";
 
                        // override query strategy and enable feed display when searching globally
                                }
                        } else if ($feed == 0 && !$cat_view) { // archive virtual feed
                                $query_strategy_part = "feed_id IS NULL";
+                               $allow_archived = true;
                        } else if ($feed == 0 && $cat_view) { // uncategorized
                                $query_strategy_part = "cat_id IS NULL AND feed_id IS NOT NULL";
                                $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
                                if (!$cat_view) {
                                        $query_strategy_part = "published = true";
                                        $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
+                                       $allow_archived = true;
                                } else {
                                        $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
 
                                        }
                                }
 
-                               if ($feed != "0") {
+                               if (!$allow_archived) {
                                        $from_qpart = "ttrss_entries,ttrss_user_entries,ttrss_feeds$ext_tables_part";
                                        $feed_check_qpart = "ttrss_user_entries.feed_id = ttrss_feeds.id AND";
 
 
        }
 
+       function create_published_article($link, $title, $url, $content, $owner_uid) {
+               $guid = 'tt-rss-share:' . uniqid();
+               $content_hash = sha1($content);
+
+               $result = db_query($link, "INSERT INTO ttrss_entries
+                       (title, guid, link, updated, content, content_hash, date_entered, date_updated)
+                       VALUES
+                       ('$title', '$guid', '$url', NOW(), '$content', '$content_hash', NOW(), NOW())");
+
+               $result = db_query($link, "SELECT id FROM ttrss_entries WHERE guid = '$guid'");
+
+               if (db_num_rows($result) != 0) {
+                       $ref_id = db_fetch_result($result, 0, "id");
+
+                       db_query($link, "INSERT INTO ttrss_user_entries
+                               (ref_id, uuid, feed_id, orig_feed_id, owner_uid, published, tag_cache, label_cache, last_read, note, unread)
+                               VALUES
+                               ('$ref_id', '', NULL, NULL, $owner_uid, true, '', '', NOW(), '', false)");
+
+                       return true;
+
+               }
+
+               return false;
+       }
+
 ?>
index 14357b4da0219c50314844163c21abc12296236a..c4fd63fca4df528d144ae724234edb82b5bf05f6 100644 (file)
@@ -118,4 +118,28 @@ div.rss hr {
        border-color : #e0e0e0;
 }
 
+body#sharepopup {
+       background : #88b0f0;
+       margin : 10px;
+       padding : 0px;
+}
+
+body#sharepopup h1 {
+       font-size : 14px;
+       margin : 0px;
+       color : #88b0f0;
+}
 
+body#sharepopup table {
+       background : white;
+       border : 1px solid black;
+       padding : 5px;
+}
+
+body#sharepopup form { 
+       height : 100%;
+}
+
+body#sharepopup input { 
+       width : 100%;
+}