]> git.wh0rd.org Git - tt-rss.git/commitdiff
implement sharing articles by unique url
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Tue, 4 Oct 2011 09:11:07 +0000 (13:11 +0400)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Tue, 4 Oct 2011 09:18:41 +0000 (13:18 +0400)
backend.php
functions.php
modules/backend-rpc.php
modules/popup-dialog.php
modules/pref-feeds.php
prefs.js
sanity_check.php
schema/ttrss_schema_mysql.sql
schema/ttrss_schema_pgsql.sql
tt-rss.css
viewfeed.js

index e3260739fde70d64ac0e68f59a2bd0b9fbb8ba0f..c0050090c2633d6d92b414c5188bcbfb5e04f9df 100644 (file)
@@ -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') {
                        }
                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)));
index 4a28af4c185be6e13d095c0b15161c68d11d5846..a8e0461f0c0385fc803307a404ad1822164338e9 100644 (file)
                                                $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() .
                                                        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)\"
index 6cd9cd2d9c9b7b0f88af0abd82cfcf78f96deee3..f6b66885ea7f5a39c85352bedd619cb6a5ac33df 100644 (file)
                        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"];
 
index 4d2408d15197795718abb136f4d42b9446665d09..f65d005ffaba12c1d3b3268db1ea2b260d7869db 100644 (file)
                                        __('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>";
+
        }
 ?>
index 0fd3f02f1ecbba82d22eb1c03da4af8b0d0bfe25..d5f0e8b4e99b934f2baccc0c002acd90726dfa78 100644 (file)
 
                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>";
 
                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 != '') {
index 1cf2943293cd055ff538f05be2ce14adb6dd7215..8a2a018e14e8e5bc2d186000c12ef4f89dd73a76 100644 (file)
--- 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...");
index 9df2fb0470e20cd9e7519278dc9e33eac9db378b..9009cbc24c1ee431d4c3110552a7e55268574df4 100644 (file)
@@ -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
index 66f5f4b29ef586b29d81c49d3db3e9b20313d5cc..a8f9939da9d32b303fef34270647e7b470ec8621 100644 (file)
@@ -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,
index 687426534bb89b8506863e41936671c2de9da9c6..b8ede02dd06664e63427546ac2539de966f74f7f 100644 (file)
@@ -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,
index 42b0af15b9d958a58a123457619bae3e59ed336b..bc08dd8ebe1389846972aa10cc4d6bb4dd105431 100644 (file)
@@ -1,4 +1,4 @@
-body#ttrssMain, body#ttrssPrefs, body#ttrssLogin {
+body#ttrssMain, body#ttrssPrefs, body#ttrssLogin, body {
        background : white;
        color : black;
        margin : 0px;
index c36b06a618593d270e15becb3b25d31135a23248..1d47c2add734dedbe3aacd43a7f1546be7d9791b 100644 (file)
@@ -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);
+       }
+}
+
+