From afb875ccd704dec355b73eecb2ded23f047414d8 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 20 Apr 2011 12:06:30 +0400 Subject: add rpc method to export feedbrowser data; update schema --- modules/backend-rpc.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'modules') diff --git a/modules/backend-rpc.php b/modules/backend-rpc.php index f21ca5814..8b4fb04c7 100644 --- a/modules/backend-rpc.php +++ b/modules/backend-rpc.php @@ -834,6 +834,38 @@ return; } + if ($subop == "fbExport") { + + // TODO: change to _POST + $access_key = db_escape_string($_REQUEST["key"]); + + // TODO: rate limit checking using last_connected + $result = db_query($link, "SELECT id FROM ttrss_linked_instances + WHERE access_key = '$access_key'"); + + if (db_num_rows($result) == 1) { + + $instance_id = db_fetch_result($result, 0, "id"); + + $result = db_query($link, "SELECT feed_url, title, subscribers + FROM ttrss_feedbrowser_cache ORDER BY subscribers DESC LIMIT 100"); + + $feeds = array(); + + while ($line = db_fetch_assoc($result)) { + array_push($feeds, $line); + } + + db_query($link, "UPDATE ttrss_linked_instances SET last_connected = NOW() + WHERE id = '$instance_id'"); + + print json_encode(array("feeds" => $feeds)); + } else { + print json_encode(array("error" => array("code" => 6))); + } + return; + } + print json_encode(array("error" => array("code" => 7, "message" => "Unknown method: $subop"))); } -- cgit v1.2.3 From 373266eb0394cd879e74db009e1629828a47eb33 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 20 Apr 2011 12:11:24 +0400 Subject: implement instances tab --- modules/pref-instances.php | 86 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 modules/pref-instances.php (limited to 'modules') diff --git a/modules/pref-instances.php b/modules/pref-instances.php new file mode 100644 index 000000000..0671944d3 --- /dev/null +++ b/modules/pref-instances.php @@ -0,0 +1,86 @@ +"; + print "
"; + + print "
"; + + $sort = db_escape_string($_REQUEST["sort"]); + + if (!$sort || $sort == "undefined") { + $sort = "access_url"; + } + + print "
". + "" . __('Select').""; + print "
"; + print "
".__('All')."
"; + print "
".__('None')."
"; + print "
"; + + print ""; + print ""; + print ""; + + print "
"; #toolbar + + $result = db_query($link, "SELECT * FROM ttrss_linked_instances + ORDER BY $sort"); + + print "

" . __("You can connect other instances of Tiny Tiny RSS to this one to share Popular feeds. Link to this instance of Tiny Tiny RSS by using this URL:"); + + print " (display url)"; + + print "

"; + + print " + + + + "; + + $lnum = 0; + + while ($line = db_fetch_assoc($result)) { + $class = ($lnum % 2) ? "even" : "odd"; + + $id = $line['id']; + $this_row_id = "id=\"LIRR-$id\""; + + $line["last_connected"] = make_local_datetime($link, $line["last_connected"], false); + + print ""; + + print ""; + + $onclick = "onclick='editInstance($id, event)' title='".__('Click to edit')."'"; + + print ""; + print ""; + + print ""; + + ++$lnum; + } + + print "
 ".__('Instance URL')."".__('Last connected')."
" . htmlspecialchars($line['access_url']) . "" . htmlspecialchars($line['last_connected']) . "
"; + + print "

"; #pane + print ""; #container + + } +?> -- cgit v1.2.3 From 16270276cf27620d72974eb7e71f089ea8bc3bd5 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 20 Apr 2011 13:32:40 +0400 Subject: implement search in pref-feeds (closes #332) --- modules/pref-feeds.php | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'modules') diff --git a/modules/pref-feeds.php b/modules/pref-feeds.php index c95e039cd..f496c782f 100644 --- a/modules/pref-feeds.php +++ b/modules/pref-feeds.php @@ -36,6 +36,10 @@ if ($subop == "getfeedtree") { + $search = $_SESSION["prefs_feed_search"]; + + if ($search) $search_qpart = " AND LOWER(title) LIKE LOWER('%$search%')"; + $root = array(); $root['id'] = 'root'; $root['name'] = __('Feeds'); @@ -59,7 +63,7 @@ ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated FROM ttrss_feeds WHERE cat_id = '".$line['id']."' AND owner_uid = ".$_SESSION["uid"]. - " ORDER BY order_id, title"); + "$search_qpart ORDER BY order_id, title"); while ($feed_line = db_fetch_assoc($feed_result)) { $feed = array(); @@ -75,7 +79,8 @@ array_push($cat['items'], $feed); } - array_push($root['items'], $cat); + if (count($cat['items']) > 0) + array_push($root['items'], $cat); } /* Uncategorized is a special case */ @@ -91,7 +96,7 @@ ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated FROM ttrss_feeds WHERE cat_id IS NULL AND owner_uid = ".$_SESSION["uid"]. - " ORDER BY order_id, title"); + "$search_qpart ORDER BY order_id, title"); while ($feed_line = db_fetch_assoc($feed_result)) { $feed = array(); @@ -107,13 +112,15 @@ array_push($cat['items'], $feed); } - array_push($root['items'], $cat); + if (count($cat['items']) > 0) + array_push($root['items'], $cat); + } else { $feed_result = db_query($link, "SELECT id, title, last_error, ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated FROM ttrss_feeds WHERE owner_uid = ".$_SESSION["uid"]. - " ORDER BY order_id, title"); + "$search_qpart ORDER BY order_id, title"); while ($feed_line = db_fetch_assoc($feed_result)) { $feed = array(); @@ -1304,6 +1311,13 @@ print "
"; + print "
+ + +
"; + print "
". "" . __('Select').""; print "
"; -- cgit v1.2.3 From 9104a3e65afdb884dd2a6289ac62161d8176c555 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 20 Apr 2011 14:11:15 +0400 Subject: implement instance edit & save --- modules/backend-rpc.php | 7 +++++ modules/pref-instances.php | 64 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 70 insertions(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/backend-rpc.php b/modules/backend-rpc.php index 8b4fb04c7..2ff9a6312 100644 --- a/modules/backend-rpc.php +++ b/modules/backend-rpc.php @@ -866,6 +866,13 @@ return; } + if ($subop == "genHash") { + $hash = sha1(uniqid(rand(), true)); + + print json_encode(array("hash" => $hash)); + return; + } + print json_encode(array("error" => array("code" => 7, "message" => "Unknown method: $subop"))); } diff --git a/modules/pref-instances.php b/modules/pref-instances.php index 0671944d3..c57b46f35 100644 --- a/modules/pref-instances.php +++ b/modules/pref-instances.php @@ -5,8 +5,70 @@ if ($subop == "edit") { - print "TODO: function not implemented."; + $id = db_escape_string($_REQUEST["id"]); + $result = db_query($link, "SELECT * FROM ttrss_linked_instances WHERE + id = '$id'"); + + print ""; + print ""; + print ""; + + print "
".__("Instance")."
"; + + print "
"; + + /* URL */ + + $access_url = htmlspecialchars(db_fetch_result($result, 0, "access_url")); + + print __("URL:") . " "; + + print ""; + + print "
"; + + $access_key = htmlspecialchars(db_fetch_result($result, 0, "access_key")); + + /* Access key */ + + print __("Access key:") . " "; + + print ""; + + print "
"; + + print "
+
+ +
+ +
"; + + return; + } + + if ($subop == "editSave") { + $id = db_escape_string($_REQUEST["id"]); + $access_url = db_escape_string($_REQUEST["access_url"]); + $access_key = db_escape_string($_REQUEST["access_key"]); + + db_query($link, "UPDATE ttrss_linked_instances SET + access_key = '$access_key', access_url = '$access_url' + WHERE id = '$id'"); return; } -- cgit v1.2.3 From 323103323b5ca370bd64e96b77b49f0b48bc05ed Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 20 Apr 2011 14:25:02 +0400 Subject: implement instance adding and deleting --- modules/popup-dialog.php | 53 ++++++++++++++++++++++++++++++++++++++++++++++ modules/pref-instances.php | 34 ++++++++++++++++++++++++++++- 2 files changed, 86 insertions(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/popup-dialog.php b/modules/popup-dialog.php index 2eb63af9d..906e89f4f 100644 --- a/modules/popup-dialog.php +++ b/modules/popup-dialog.php @@ -990,6 +990,59 @@ type=\"submit\">". __('Close this window').""; print "
"; + } + + if ($id == "addInstance") { + + print ""; + print ""; + + print "
".__("Instance")."
"; + + print "
"; + + /* URL */ + + print __("URL:") . " "; + + print ""; + + print "
"; + + $access_key = sha1(uniqid(rand(), true)); + + /* Access key */ + + print __("Access key:") . " "; + + print ""; + + print "
"; + + print "
+
+ +
+ +
"; + + return; + + + + } print ""; diff --git a/modules/pref-instances.php b/modules/pref-instances.php index c57b46f35..ab3d78c44 100644 --- a/modules/pref-instances.php +++ b/modules/pref-instances.php @@ -3,6 +3,37 @@ $subop = $_REQUEST['subop']; + if ($subop == "remove") { + $ids = db_escape_string($_REQUEST['ids']); + + db_query($link, "DELETE FROM ttrss_linked_instances WHERE + id IN ($ids)"); + + return; + } + + if ($subop == "add") { + $id = db_escape_string($_REQUEST["id"]); + $access_url = db_escape_string($_REQUEST["access_url"]); + $access_key = db_escape_string($_REQUEST["access_key"]); + + db_query($link, "BEGIN"); + + $result = db_query($link, "SELECT id FROM ttrss_linked_instances + WHERE access_url = '$access_url'"); + + if (db_num_rows($result) == 0) { + db_query($link, "INSERT INTO ttrss_linked_instances + (access_url, access_key, last_connected) VALUES + ('$access_url', '$access_key', '1970-01-01')"); + + } + + db_query($link, "COMMIT"); + + return; + } + if ($subop == "edit") { $id = db_escape_string($_REQUEST["id"]); @@ -67,7 +98,8 @@ $access_key = db_escape_string($_REQUEST["access_key"]); db_query($link, "UPDATE ttrss_linked_instances SET - access_key = '$access_key', access_url = '$access_url' + access_key = '$access_key', access_url = '$access_url', + last_connected = '1970-01-01' WHERE id = '$id'"); return; -- cgit v1.2.3 From 258d48a04749d57fd3e91524ac9c5da51440e739 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 20 Apr 2011 14:32:30 +0400 Subject: show partial access key in main instance editor, better key input checking --- modules/popup-dialog.php | 2 +- modules/pref-instances.php | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'modules') diff --git a/modules/popup-dialog.php b/modules/popup-dialog.php index 906e89f4f..f5a30a06e 100644 --- a/modules/popup-dialog.php +++ b/modules/popup-dialog.php @@ -1019,7 +1019,7 @@ print __("Access key:") . " "; print ""; diff --git a/modules/pref-instances.php b/modules/pref-instances.php index ab3d78c44..45df2eb39 100644 --- a/modules/pref-instances.php +++ b/modules/pref-instances.php @@ -70,7 +70,7 @@ print __("Access key:") . " "; print ""; @@ -143,6 +143,7 @@ print "   ".__('Instance URL')." + ".__('Access key')." ".__('Last connected')." "; @@ -163,7 +164,11 @@ $onclick = "onclick='editInstance($id, event)' title='".__('Click to edit')."'"; + $access_key = mb_substr($line['access_key'], 0, 4) . '...' . + mb_substr($line['access_key'], -4); + print "" . htmlspecialchars($line['access_url']) . ""; + print "" . htmlspecialchars($access_key) . ""; print "" . htmlspecialchars($line['last_connected']) . ""; print ""; -- cgit v1.2.3 From ae5f7bb11a7698a84c9352436c144286f7c81630 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 20 Apr 2011 15:21:00 +0400 Subject: implement fetching and exporting of shared feeds --- modules/backend-rpc.php | 32 -------------------------------- modules/popup-dialog.php | 2 ++ modules/pref-instances.php | 16 ++++++++++++---- 3 files changed, 14 insertions(+), 36 deletions(-) (limited to 'modules') diff --git a/modules/backend-rpc.php b/modules/backend-rpc.php index 2ff9a6312..75ce6886a 100644 --- a/modules/backend-rpc.php +++ b/modules/backend-rpc.php @@ -834,38 +834,6 @@ return; } - if ($subop == "fbExport") { - - // TODO: change to _POST - $access_key = db_escape_string($_REQUEST["key"]); - - // TODO: rate limit checking using last_connected - $result = db_query($link, "SELECT id FROM ttrss_linked_instances - WHERE access_key = '$access_key'"); - - if (db_num_rows($result) == 1) { - - $instance_id = db_fetch_result($result, 0, "id"); - - $result = db_query($link, "SELECT feed_url, title, subscribers - FROM ttrss_feedbrowser_cache ORDER BY subscribers DESC LIMIT 100"); - - $feeds = array(); - - while ($line = db_fetch_assoc($result)) { - array_push($feeds, $line); - } - - db_query($link, "UPDATE ttrss_linked_instances SET last_connected = NOW() - WHERE id = '$instance_id'"); - - print json_encode(array("feeds" => $feeds)); - } else { - print json_encode(array("error" => array("code" => 6))); - } - return; - } - if ($subop == "genHash") { $hash = sha1(uniqid(rand(), true)); diff --git a/modules/popup-dialog.php b/modules/popup-dialog.php index f5a30a06e..6cb60eef4 100644 --- a/modules/popup-dialog.php +++ b/modules/popup-dialog.php @@ -1023,6 +1023,8 @@ style=\"width: 20em\" name=\"access_key\" id=\"instance_add_key\" value=\"$access_key\">"; + print "

" . __("Use one access key for both linked instances."); + print "

"; print "
diff --git a/modules/pref-instances.php b/modules/pref-instances.php index 45df2eb39..d3510c287 100644 --- a/modules/pref-instances.php +++ b/modules/pref-instances.php @@ -24,8 +24,9 @@ if (db_num_rows($result) == 0) { db_query($link, "INSERT INTO ttrss_linked_instances - (access_url, access_key, last_connected) VALUES - ('$access_url', '$access_key', '1970-01-01')"); + (access_url, access_key, last_connected, last_status_in, last_status_out) + VALUES + ('$access_url', '$access_key', '1970-01-01', -1, -1)"); } @@ -74,6 +75,8 @@ style=\"width: 20em\" name=\"access_key\" id=\"instance_edit_key\" value=\"$access_key\">"; + print "

" . __("Use one access key for both linked instances."); + print "

"; print "
@@ -131,7 +134,10 @@ print "
"; #toolbar - $result = db_query($link, "SELECT * FROM ttrss_linked_instances + $result = db_query($link, "SELECT *, + (SELECT COUNT(*) FROM ttrss_linked_feeds + WHERE instance_id = ttrss_linked_instances.id) AS num_feeds + FROM ttrss_linked_instances ORDER BY $sort"); print "

" . __("You can connect other instances of Tiny Tiny RSS to this one to share Popular feeds. Link to this instance of Tiny Tiny RSS by using this URL:"); @@ -144,7 +150,8 @@   ".__('Instance URL')." ".__('Access key')." - ".__('Last connected')." + ".__('Last connected')." + ".__('Stored feeds')." "; $lnum = 0; @@ -170,6 +177,7 @@ print "" . htmlspecialchars($line['access_url']) . ""; print "" . htmlspecialchars($access_key) . ""; print "" . htmlspecialchars($line['last_connected']) . ""; + print "" . htmlspecialchars($line['num_feeds']) . ""; print ""; -- cgit v1.2.3 From 414d0d1f46d2be49e95cf668efec906fb989d1f2 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 20 Apr 2011 15:36:46 +0400 Subject: implement feedbrowser using linked feeds; set proper fetch timeout --- modules/pref-feeds.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'modules') diff --git a/modules/pref-feeds.php b/modules/pref-feeds.php index f496c782f..238ca0a85 100644 --- a/modules/pref-feeds.php +++ b/modules/pref-feeds.php @@ -1539,11 +1539,21 @@ } if ($mode == 1) { - $result = db_query($link, "SELECT feed_url, subscribers FROM + /* $result = db_query($link, "SELECT feed_url, subscribers FROM ttrss_feedbrowser_cache WHERE (SELECT COUNT(id) = 0 FROM ttrss_feeds AS tf WHERE tf.feed_url = ttrss_feedbrowser_cache.feed_url AND owner_uid = '$owner_uid') $search_qpart - ORDER BY subscribers DESC LIMIT $limit"); + ORDER BY subscribers DESC LIMIT $limit"); */ + + $result = db_query($link, "SELECT feed_url, title, SUM(subscribers) AS subscribers FROM + (SELECT feed_url, title, subscribers FROM ttrss_feedbrowser_cache UNION ALL + SELECT feed_url, title, subscribers FROM ttrss_linked_feeds) AS qqq + WHERE + (SELECT COUNT(id) = 0 FROM ttrss_feeds AS tf + WHERE tf.feed_url = qqq.feed_url + AND owner_uid = '$owner_uid') $search_qpart + GROUP BY feed_url, title ORDER BY subscribers DESC LIMIT $limit"); + } else if ($mode == 2) { $result = db_query($link, "SELECT *, (SELECT COUNT(*) FROM ttrss_user_entries WHERE -- cgit v1.2.3 From 9530efa1b506f4a0d64088ae30aec38ff27de331 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 20 Apr 2011 15:48:26 +0400 Subject: feed browser: use title from cache table --- modules/pref-feeds.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/pref-feeds.php b/modules/pref-feeds.php index 238ca0a85..4baba572a 100644 --- a/modules/pref-feeds.php +++ b/modules/pref-feeds.php @@ -1613,7 +1613,7 @@ $rv .= "

  • $check_box". - "$feed_icon $feed_url " . htmlspecialchars($details["title"]) . + "$feed_icon $feed_url " . htmlspecialchars($line["title"]) . " ($subscribers) $site_url
  • "; -- cgit v1.2.3