From 83cd33fcec05473bf2bd00836c7eaa7d9b584461 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 4 Oct 2011 13:11:07 +0400 Subject: [PATCH] implement sharing articles by unique url --- backend.php | 24 ++++++++++++++++++++- functions.php | 9 ++++++-- modules/backend-rpc.php | 9 ++++++++ modules/popup-dialog.php | 40 +++++++++++++++++++++++++++++++++++ modules/pref-feeds.php | 11 +++++++++- prefs.js | 18 ++++++++++++++++ sanity_check.php | 2 +- schema/ttrss_schema_mysql.sql | 3 ++- schema/ttrss_schema_pgsql.sql | 3 ++- tt-rss.css | 2 +- viewfeed.js | 23 ++++++++++++++++++++ 11 files changed, 136 insertions(+), 8 deletions(-) diff --git a/backend.php b/backend.php index e3260739..c0050090 100644 --- a/backend.php +++ b/backend.php @@ -59,7 +59,7 @@ } if (!($_SESSION["uid"] && validate_session($link)) && $op != "globalUpdateFeeds" && - $op != "rss" && $op != "getUnread" && $op != "getProfiles" && + $op != "rss" && $op != "getUnread" && $op != "getProfiles" && $op != "share" && $op != "fbexport" && $op != "logout" && $op != "pubsub") { if ($op == 'pref-feeds' && $_REQUEST['subop'] == 'add') { @@ -633,6 +633,28 @@ } break; // fbexport + case "share": + $uuid = db_escape_string($_REQUEST["key"]); + + $result = db_query($link, "SELECT ref_id, owner_uid FROM ttrss_user_entries WHERE + uuid = '$uuid'"); + + if (db_num_rows($result) != 0) { + header("Content-Type: text/html"); + + $id = db_fetch_result($result, 0, "ref_id"); + $owner_uid = db_fetch_result($result, 0, "owner_uid"); + + $article = format_article($link, $id, false, true); + + print_r($article['content']); + + } else { + print "Article not found."; + } + + break; + default: header("Content-Type: text/plain"); print json_encode(array("error" => array("code" => 7))); diff --git a/functions.php b/functions.php index 4a28af4c..a8e0461f 100644 --- a/functions.php +++ b/functions.php @@ -1275,9 +1275,9 @@ $result = db_query($link, "INSERT INTO ttrss_user_entries (ref_id, owner_uid, feed_id, unread, last_read, marked, - published, score, tag_cache, label_cache) + published, score, tag_cache, label_cache, uuid) VALUES ('$ref_id', '$owner_uid', '$feed', $unread, - $last_read_qpart, $marked, $published, '$score', '', '')"); + $last_read_qpart, $marked, $published, '$score', '', '', '')"); if (PUBSUBHUBBUB_HUB && $published == 'true') { $rss_link = get_self_url_prefix() . @@ -4927,6 +4927,11 @@ alt='Zoom' title='".__('Share on Twitter')."'>"; } + $rv['content'] .= "Zoom"; + $rv['content'] .= ""; return; + } + if ($id == "shareArticle") { + $result = db_query($link, "SELECT uuid, ref_id FROM ttrss_user_entries WHERE int_id = '$param' + AND owner_uid = " . $_SESSION['uid']); + if (db_num_rows($result) == 0) { + print "Article not found."; + } else { + $uuid = db_fetch_result($result, 0, "uuid"); + $ref_id = db_fetch_result($result, 0, "ref_id"); + + if (!$uuid) { + $uuid = db_escape_string(sha1(uniqid(rand(), true))); + db_query($link, "UPDATE ttrss_user_entries SET uuid = '$uuid' WHERE int_id = '$param' + AND owner_uid = " . $_SESSION['uid']); + } + + print __("You can share this article by the following unique URL:"); + + $url_path = get_self_url_prefix(); + $url_path .= "/backend.php?op=share&key=$uuid"; + + print "
"; + print "$url_path"; + print "
"; + + /* if (!label_find_id($link, __('Shared'), $_SESSION["uid"])) + label_create($link, __('Shared'), $_SESSION["uid"]); + + label_add_article($link, $ref_id, __('Shared'), $_SESSION['uid']); */ + } + + print "
"; + + print ""; + + print "
"; + + return; } print ""; + } ?> diff --git a/modules/pref-feeds.php b/modules/pref-feeds.php index 0fd3f02f..d5f0e8b4 100644 --- a/modules/pref-feeds.php +++ b/modules/pref-feeds.php @@ -1506,7 +1506,9 @@ print ""; #pane - print "
"; + print "
"; + + print "

" . __("Published articles and generated feeds") . "

"; print "

".__('Published articles are exported as a public RSS feed and can be subscribed by anyone who knows the URL specified below.')."

"; @@ -1519,6 +1521,13 @@ print " "; + print "

" . __("Articles shared by URL") . "

"; + + print "

" . __("You can disable all articles shared by unique URLs here.") . "

"; + + print " "; + print "
"; #pane if (defined('CONSUMER_KEY') && CONSUMER_KEY != '') { diff --git a/prefs.js b/prefs.js index 1cf29432..8a2a018e 100644 --- a/prefs.js +++ b/prefs.js @@ -1590,6 +1590,24 @@ function clearFeedAccessKeys() { return false; } +function clearArticleAccessKeys() { + + var ok = confirm(__("This will invalidate all previously shared article URLs. Continue?")); + + if (ok) { + notify_progress("Clearing URLs..."); + + var query = "?op=rpc&subop=clearArticleKeys"; + + new Ajax.Request("backend.php", { + parameters: query, + onComplete: function(transport) { + notify_info("Shared URLs cleared."); + } }); + } + + return false; +} function resetFeedOrder() { try { notify_progress("Loading, please wait..."); diff --git a/sanity_check.php b/sanity_check.php index 9df2fb04..9009cbc2 100644 --- a/sanity_check.php +++ b/sanity_check.php @@ -2,7 +2,7 @@ require_once "functions.php"; define('EXPECTED_CONFIG_VERSION', 23); - define('SCHEMA_VERSION', 85); + define('SCHEMA_VERSION', 86); if (!file_exists("config.php")) { print "Fatal Error: You forgot to copy diff --git a/schema/ttrss_schema_mysql.sql b/schema/ttrss_schema_mysql.sql index 66f5f4b2..a8f9939d 100644 --- a/schema/ttrss_schema_mysql.sql +++ b/schema/ttrss_schema_mysql.sql @@ -152,6 +152,7 @@ create index ttrss_entries_updated_idx on ttrss_entries(updated); create table ttrss_user_entries ( int_id integer not null primary key auto_increment, ref_id integer not null, + uuid varchar(200) not null, feed_id int, orig_feed_id int, owner_uid integer not null, @@ -254,7 +255,7 @@ create table ttrss_tags (id integer primary key auto_increment, create table ttrss_version (schema_version int not null) ENGINE=InnoDB DEFAULT CHARSET=UTF8; -insert into ttrss_version values (85); +insert into ttrss_version values (86); create table ttrss_enclosures (id integer primary key auto_increment, content_url text not null, diff --git a/schema/ttrss_schema_pgsql.sql b/schema/ttrss_schema_pgsql.sql index 68742653..b8ede02d 100644 --- a/schema/ttrss_schema_pgsql.sql +++ b/schema/ttrss_schema_pgsql.sql @@ -137,6 +137,7 @@ create index ttrss_entries_updated_idx on ttrss_entries(updated); create table ttrss_user_entries ( int_id serial not null primary key, ref_id integer not null references ttrss_entries(id) ON DELETE CASCADE, + uuid varchar(200) not null, feed_id int references ttrss_feeds(id) ON DELETE CASCADE, orig_feed_id integer references ttrss_archived_feeds(id) ON DELETE SET NULL, owner_uid integer not null references ttrss_users(id) ON DELETE CASCADE, @@ -225,7 +226,7 @@ create index ttrss_tags_post_int_id_idx on ttrss_tags(post_int_id); create table ttrss_version (schema_version int not null); -insert into ttrss_version values (85); +insert into ttrss_version values (86); create table ttrss_enclosures (id serial not null primary key, content_url text not null, diff --git a/tt-rss.css b/tt-rss.css index 42b0af15..bc08dd8e 100644 --- a/tt-rss.css +++ b/tt-rss.css @@ -1,4 +1,4 @@ -body#ttrssMain, body#ttrssPrefs, body#ttrssLogin { +body#ttrssMain, body#ttrssPrefs, body#ttrssLogin, body { background : white; color : black; margin : 0px; diff --git a/viewfeed.js b/viewfeed.js index c36b06a6..1d47c2ad 100644 --- a/viewfeed.js +++ b/viewfeed.js @@ -2184,6 +2184,7 @@ function precache_headlines() { feed_precache_timeout_id = false; }, 3000); + x }, 1000); } @@ -2191,3 +2192,25 @@ function precache_headlines() { exception_error("precache_headlines", e); } } + +function shareArticle(id) { + try { + if (dijit.byId("shareArticleDlg")) + dijit.byId("shareArticleDlg").destroyRecursive(); + + var query = "backend.php?op=dlg&id=shareArticle¶m=" + param_escape(id); + + dialog = new dijit.Dialog({ + id: "shareArticleDlg", + title: __("Share article by URL"), + style: "width: 600px", + href: query}); + + dialog.show(); + + } catch (e) { + exception_error("emailArticle", e); + } +} + +