summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2011-10-04 13:11:07 +0400
committerAndrew Dolgov <[email protected]>2011-10-04 13:18:41 +0400
commit83cd33fcec05473bf2bd00836c7eaa7d9b584461 (patch)
tree024ff7b024164a27e93e362763883e66cb40fa4b
parent359fc686ddfc13dc1f9ee8127fd14a13a0ede4e8 (diff)
implement sharing articles by unique url
-rw-r--r--backend.php24
-rw-r--r--functions.php9
-rw-r--r--modules/backend-rpc.php9
-rw-r--r--modules/popup-dialog.php40
-rw-r--r--modules/pref-feeds.php11
-rw-r--r--prefs.js18
-rw-r--r--sanity_check.php2
-rw-r--r--schema/ttrss_schema_mysql.sql3
-rw-r--r--schema/ttrss_schema_pgsql.sql3
-rw-r--r--tt-rss.css2
-rw-r--r--viewfeed.js23
11 files changed, 136 insertions, 8 deletions
diff --git a/backend.php b/backend.php
index e3260739f..c0050090c 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 4a28af4c1..a8e0461f0 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'] .= "<img src=\"".theme_image($link, 'images/art-share.png')."\"
+ class='tagsPic' style=\"cursor : pointer\"
+ onclick=\"shareArticle(".$line['int_id'].")\"
+ alt='Zoom' title='".__('Share by URL')."'>";
+
$rv['content'] .= "<img src=\"".theme_image($link, 'images/digest_checkbox.png')."\"
class='tagsPic' style=\"cursor : pointer\"
onclick=\"closeArticlePanel($id)\"
diff --git a/modules/backend-rpc.php b/modules/backend-rpc.php
index 6cd9cd2d9..f6b66885e 100644
--- a/modules/backend-rpc.php
+++ b/modules/backend-rpc.php
@@ -783,6 +783,15 @@
return;
}
+ // Silent
+ if ($subop == "clearArticleKeys") {
+ db_query($link, "UPDATE ttrss_user_entries SET uuid = '' WHERE
+ owner_uid = " . $_SESSION["uid"]);
+
+ return;
+ }
+
+
if ($subop == "verifyRegexp") {
$reg_exp = $_REQUEST["reg_exp"];
diff --git a/modules/popup-dialog.php b/modules/popup-dialog.php
index 4d2408d15..f65d005ff 100644
--- a/modules/popup-dialog.php
+++ b/modules/popup-dialog.php
@@ -1071,12 +1071,52 @@
__('Cancel')."</button></div>";
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 "<div class=\"tagCloudContainer\">";
+ print "<a id='pub_opml_url' href='$url_path' target='_blank'>$url_path</a>";
+ print "</div>";
+ /* if (!label_find_id($link, __('Shared'), $_SESSION["uid"]))
+ label_create($link, __('Shared'), $_SESSION["uid"]);
+ label_add_article($link, $ref_id, __('Shared'), $_SESSION['uid']); */
+ }
+
+ print "<div align='center'>";
+
+ print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('shareArticleDlg').hide()\">".
+ __('Close this window')."</button>";
+
+ print "</div>";
+
+ return;
}
print "</dlg>";
+
}
?>
diff --git a/modules/pref-feeds.php b/modules/pref-feeds.php
index 0fd3f02f1..d5f0e8b4e 100644
--- a/modules/pref-feeds.php
+++ b/modules/pref-feeds.php
@@ -1506,7 +1506,9 @@
print "</div>"; #pane
- print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Published articles and generated feeds')."\">";
+ print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Published & shared articles and generated feeds')."\">";
+
+ print "<h3>" . __("Published articles and generated feeds") . "</h3>";
print "<p>".__('Published articles are exported as a public RSS feed and can be subscribed by anyone who knows the URL specified below.')."</p>";
@@ -1519,6 +1521,13 @@
print "<button dojoType=\"dijit.form.Button\" onclick=\"return clearFeedAccessKeys()\">".
__('Clear all generated URLs')."</button> ";
+ print "<h3>" . __("Articles shared by URL") . "</h3>";
+
+ print "<p>" . __("You can disable all articles shared by unique URLs here.") . "</p>";
+
+ print "<button dojoType=\"dijit.form.Button\" onclick=\"return clearArticleAccessKeys()\">".
+ __('Unshare all articles')."</button> ";
+
print "</div>"; #pane
if (defined('CONSUMER_KEY') && CONSUMER_KEY != '') {
diff --git a/prefs.js b/prefs.js
index 1cf294329..8a2a018e1 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 9df2fb047..9009cbc24 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 "<b>Fatal Error</b>: You forgot to copy
diff --git a/schema/ttrss_schema_mysql.sql b/schema/ttrss_schema_mysql.sql
index 66f5f4b29..a8f9939da 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 687426534..b8ede02dd 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 42b0af15b..bc08dd8eb 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 c36b06a61..1d47c2add 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&param=" + 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);
+ }
+}
+
+