From 8361e724785767d57cd28be7ceaea7ad81fae0a2 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 9 Sep 2012 16:05:59 +0400 Subject: implement sharing of arbitrary stuff using bookmarklet and API call, bump API version --- classes/api.php | 13 ++++++++- classes/handler/public.php | 70 ++++++++++++++++++++++++++++++++++++++++++++++ classes/pref/feeds.php | 8 +++++- classes/rpc.php | 2 +- 4 files changed, 90 insertions(+), 3 deletions(-) (limited to 'classes') diff --git a/classes/api.php b/classes/api.php index 2e9c1b902..cce1d2a78 100644 --- a/classes/api.php +++ b/classes/api.php @@ -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')); + } + } } ?> diff --git a/classes/handler/public.php b/classes/handler/public.php index 983f0aaa9..cd46fa033 100644 --- a/classes/handler/public.php +++ b/classes/handler/public.php @@ -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 " + + Tiny Tiny RSS + + + + + "; + + $action = $_REQUEST["action"]; + + if ($_SESSION["uid"]) { + + if (!$action) { + + print ""; + + print ""; + + print ""; + print ""; + + $title = htmlspecialchars($_REQUEST["title"]); + $url = htmlspecialchars($_REQUEST["url"]); + + print ""; + print ""; + print ""; + + print ""; + + print "
"; + print "

Publish with Tiny Tiny RSS

"; + print "
".__("Title:")."
".__("URL:")."
".__("Content:")."
+ + + "; + + print ""; + print "
"; + + print ""; + + } 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 ""; + } + + } else { + + print "
" . __("Not logged in.") . "
"; + + } + } + } ?> diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php index ef308ee1c..d6bb94ebe 100644 --- a/classes/pref/feeds.php +++ b/classes/pref/feeds.php @@ -1557,7 +1557,7 @@ class Pref_Feeds extends Handler_Protected { print ""; # pane } - print "
"; + print "
"; print "

" . __("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.") . "

"; @@ -1569,6 +1569,12 @@ class Pref_Feeds extends Handler_Protected { print "" . __('Subscribe in Tiny Tiny RSS'). ""; + 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();})()"); + + print "" . __('Share with Tiny Tiny RSS'). ""; + print "
"; #pane print "
"; diff --git a/classes/rpc.php b/classes/rpc.php index db34a6c9d..733649139 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"); + $csrf_ignored = array("sanitycheck", "buttonplugin", "exportget", "sharepopup"); return array_search($method, $csrf_ignored) !== false; } -- cgit v1.2.3-54-g00ecf