]> git.wh0rd.org - tt-rss.git/blobdiff - classes/pref/feeds.php
move inactiveFeeds and feedsWithErrors to pref-feeds; fix element id collisions
[tt-rss.git] / classes / pref / feeds.php
index 74ad973875483e7c9a8fd80cc14c23f3dde01805..3a7da72d3c3ed858010d427d910b823af6d9c9e8 100644 (file)
@@ -3,7 +3,7 @@ class Pref_Feeds extends Handler_Protected {
 
        function csrf_ignore($method) {
                $csrf_ignored = array("index", "getfeedtree", "add", "editcats", "editfeed",
-                       "savefeedorder", "uploadicon");
+                       "savefeedorder", "uploadicon", "feedswitherrors", "inactivefeeds");
 
                return array_search($method, $csrf_ignored) !== false;
        }
@@ -24,16 +24,12 @@ class Pref_Feeds extends Handler_Protected {
                return;
        }
 
-       function remtwitterinfo() {
-
-               db_query($this->link, "UPDATE ttrss_users SET twitter_oauth = NULL
-                       WHERE id = " . $_SESSION['uid']);
+       private function get_category_items($cat_id) {
+               $search = $_SESSION["prefs_feed_search"];
 
-               return;
-       }
+               if ($search) $search_qpart = " AND LOWER(title) LIKE LOWER('%$search%')";
 
-       private function get_category_items($cat_id) {
-               $show_empty_cats = $_REQUEST['mode'] != 2 &&
+               $show_empty_cats = $_REQUEST['mode'] != 2 && !$search &&
                        get_pref($this->link, '_PREFS_SHOW_EMPTY_CATS');
 
                $items = array();
@@ -154,7 +150,7 @@ class Pref_Feeds extends Handler_Protected {
                }
 
                if ($enable_cats) {
-                       $show_empty_cats = $_REQUEST['mode'] != 2 &&
+                       $show_empty_cats = $_REQUEST['mode'] != 2 && !$search &&
                                get_pref($this->link, '_PREFS_SHOW_EMPTY_CATS');
 
                        $result = db_query($this->link, "SELECT id, title, collapsed FROM ttrss_feed_categories
@@ -1176,111 +1172,6 @@ class Pref_Feeds extends Handler_Protected {
 
        }
 
-       function add() {
-               $feed_url = db_escape_string(trim($_REQUEST["feed_url"]));
-               $cat_id = db_escape_string($_REQUEST["cat_id"]);
-               $p_from = db_escape_string($_REQUEST["from"]);
-
-               /* only read authentication information from POST */
-
-               $auth_login = db_escape_string(trim($_POST["auth_login"]));
-               $auth_pass = db_escape_string(trim($_POST["auth_pass"]));
-
-               if ($p_from != 'tt-rss') {
-                       header('Content-Type: text/html; charset=utf-8');
-                       print "<html>
-                               <head>
-                                       <title>Tiny Tiny RSS</title>
-                                       <link rel=\"stylesheet\" type=\"text/css\" href=\"utility.css\">
-                                       <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
-                               </head>
-                               <body>
-                               <img class=\"floatingLogo\" src=\"images/logo_wide.png\"
-                                       alt=\"Tiny Tiny RSS\"/>
-                               <h1>Subscribe to feed...</h1>";
-               }
-
-               $rc = subscribe_to_feed($this->link, $feed_url, $cat_id, $auth_login, $auth_pass);
-
-               switch ($rc) {
-               case 1:
-                       print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url));
-                       break;
-               case 2:
-                       print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url));
-                       break;
-               case 3:
-                       print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url));
-                       break;
-               case 0:
-                       print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
-                       break;
-               case 4:
-                       print_notice(__("Multiple feed URLs found."));
-
-                       $feed_urls = get_feeds_from_html($feed_url);
-                       break;
-               case 5:
-                       print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url));
-                       break;
-               }
-
-               if ($p_from != 'tt-rss') {
-
-                       if ($feed_urls) {
-
-                               print "<form action=\"backend.php\">";
-                               print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
-                               print "<input type=\"hidden\" name=\"quiet\" value=\"1\">";
-                               print "<input type=\"hidden\" name=\"method\" value=\"add\">";
-
-                               print "<select name=\"feed_url\">";
-
-                               foreach ($feed_urls as $url => $name) {
-                                       $url = htmlspecialchars($url);
-                                       $name = htmlspecialchars($name);
-
-                                       print "<option value=\"$url\">$name</option>";
-                               }
-
-                               print "<input type=\"submit\" value=\"".__("Subscribe to selected feed").
-                                       "\">";
-
-                               print "</form>";
-                       }
-
-                       $tp_uri = get_self_url_prefix() . "/prefs.php";
-                       $tt_uri = get_self_url_prefix();
-
-                       if ($rc <= 2){
-                               $result = db_query($this->link, "SELECT id FROM ttrss_feeds WHERE
-                                       feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
-
-                               $feed_id = db_fetch_result($result, 0, "id");
-                       } else {
-                               $feed_id = 0;
-                       }
-                       print "<p>";
-
-                       if ($feed_id) {
-                               print "<form method=\"GET\" style='display: inline'
-                                       action=\"$tp_uri\">
-                                       <input type=\"hidden\" name=\"tab\" value=\"feedConfig\">
-                                       <input type=\"hidden\" name=\"method\" value=\"editFeed\">
-                                       <input type=\"hidden\" name=\"methodparam\" value=\"$feed_id\">
-                                       <input type=\"submit\" value=\"".__("Edit subscription options")."\">
-                                       </form>";
-                       }
-
-                       print "<form style='display: inline' method=\"GET\" action=\"$tt_uri\">
-                               <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
-                               </form></p>";
-
-                       print "</body></html>";
-                       return;
-               }
-       }
-
        function categorize() {
                $ids = split(",", db_escape_string($_REQUEST["ids"]));
 
@@ -1565,7 +1456,7 @@ class Pref_Feeds extends Handler_Protected {
                        print "</div>"; # pane
                }
 
-               print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Subscribing using bookmarklet')."\">";
+               print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Bookmarklets')."\">";
 
                print "<p>" . __("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.") . "</p>";
 
@@ -1577,6 +1468,12 @@ class Pref_Feeds extends Handler_Protected {
 
                print "<a href=\"$bm_url\" class='bookmarklet'>" . __('Subscribe in Tiny Tiny RSS'). "</a>";
 
+               print "<p>" . __("Use this bookmarklet to publish arbitrary pages using Tiny Tiny RSS") . "</p>";
+
+               $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 "<a href=\"$bm_url\" class='bookmarklet'>" . __('Share with Tiny Tiny RSS'). "</a>";
+
                print "</div>"; #pane
 
                print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Published & shared articles / Generated feeds')."\">";
@@ -1603,35 +1500,6 @@ class Pref_Feeds extends Handler_Protected {
 
                print "</div>"; #pane
 
-               if (defined('CONSUMER_KEY') && CONSUMER_KEY != '') {
-
-                       print "<div id=\"pref-feeds-twitter\" dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Twitter')."\">";
-
-                       $result = db_query($this->link, "SELECT COUNT(*) AS cid FROM ttrss_users
-                               WHERE twitter_oauth IS NOT NULL AND twitter_oauth != '' AND
-                               id = " . $_SESSION['uid']);
-
-                       $is_registered = db_fetch_result($result, 0, "cid") != 0;
-
-                       if (!$is_registered) {
-                               print_notice(__('Before you can update your Twitter feeds, you must register this instance of Tiny Tiny RSS with Twitter.com.'));
-                       } else {
-                               print_notice(__('You have been successfully registered with Twitter.com and should be able to access your Twitter feeds.'));
-                       }
-
-                       print "<button dojoType=\"dijit.form.Button\" onclick=\"window.location.href = 'twitter.php?op=register'\">".
-                               __("Register with Twitter.com")."</button>";
-
-                       print " ";
-
-                       print "<button dojoType=\"dijit.form.Button\"
-                               onclick=\"return clearTwitterCredentials()\">".
-                               __("Clear stored credentials")."</button>";
-
-                       print "</div>"; # pane
-
-               }
-
                print "</div>"; #container
 
        }
@@ -1679,5 +1547,160 @@ class Pref_Feeds extends Handler_Protected {
                return $obj;
        }
 
+       function inactiveFeeds() {
+
+               if (DB_TYPE == "pgsql") {
+                       $interval_qpart = "NOW() - INTERVAL '3 months'";
+               } else {
+                       $interval_qpart = "DATE_SUB(NOW(), INTERVAL 3 MONTH)";
+               }
+
+               $result = db_query($this->link, "SELECT ttrss_feeds.title, ttrss_feeds.site_url,
+                               ttrss_feeds.feed_url, ttrss_feeds.id, MAX(updated) AS last_article
+                       FROM ttrss_feeds, ttrss_entries, ttrss_user_entries WHERE
+                               (SELECT MAX(updated) FROM ttrss_entries, ttrss_user_entries WHERE
+                                       ttrss_entries.id = ref_id AND
+                                               ttrss_user_entries.feed_id = ttrss_feeds.id) < $interval_qpart
+                       AND ttrss_feeds.owner_uid = ".$_SESSION["uid"]." AND
+                               ttrss_user_entries.feed_id = ttrss_feeds.id AND
+                               ttrss_entries.id = ref_id
+                       GROUP BY ttrss_feeds.title, ttrss_feeds.id, ttrss_feeds.site_url, ttrss_feeds.feed_url
+                       ORDER BY last_article");
+
+               print "<div class=\"dialogNotice\">" . __("These feeds have not been updated with new content for 3 months (oldest first):") . "</div>";
+
+               print "<div dojoType=\"dijit.Toolbar\">";
+               print "<div dojoType=\"dijit.form.DropDownButton\">".
+                               "<span>" . __('Select')."</span>";
+               print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
+               print "<div onclick=\"selectTableRows('prefInactiveFeedList', 'all')\"
+                       dojoType=\"dijit.MenuItem\">".__('All')."</div>";
+               print "<div onclick=\"selectTableRows('prefInactiveFeedList', 'none')\"
+                       dojoType=\"dijit.MenuItem\">".__('None')."</div>";
+               print "</div></div>";
+               print "</div>"; #toolbar
+
+               print "<div class=\"inactiveFeedHolder\">";
+
+               print "<table width=\"100%\" cellspacing=\"0\" id=\"prefInactiveFeedList\">";
+
+               $lnum = 1;
+
+               while ($line = db_fetch_assoc($result)) {
+
+                       $class = ($lnum % 2) ? "even" : "odd";
+                       $feed_id = $line["id"];
+                       $this_row_id = "id=\"FUPDD-$feed_id\"";
+
+                       # class needed for selectTableRows()
+                       print "<tr class=\"placeholder\" $this_row_id>";
+
+                       $edit_title = htmlspecialchars($line["title"]);
+
+                       # id needed for selectTableRows()
+                       print "<td width='5%' align='center'><input
+                               onclick='toggleSelectRow2(this);' dojoType=\"dijit.form.CheckBox\"
+                               type=\"checkbox\" id=\"FUPDC-$feed_id\"></td>";
+                       print "<td>";
+
+                       print "<a class=\"visibleLink\" href=\"#\" ".
+                               "title=\"".__("Click to edit feed")."\" ".
+                               "onclick=\"editFeed(".$line["id"].")\">".
+                               htmlspecialchars($line["title"])."</a>";
+
+                       print "</td><td class=\"insensitive\" align='right'>";
+                       print make_local_datetime($this->link, $line['last_article'], false);
+                       print "</td>";
+                       print "</tr>";
+
+                       ++$lnum;
+               }
+
+               print "</table>";
+               print "</div>";
+
+               print "<div class='dlgButtons'>";
+               print "<div style='float : left'>";
+               print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('inactiveFeedsDlg').removeSelected()\">"
+                       .__('Unsubscribe from selected feeds')."</button> ";
+               print "</div>";
+
+               print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('inactiveFeedsDlg').hide()\">".
+                       __('Close this window')."</button>";
+
+               print "</div>";
+
+       }
+
+       function feedsWithErrors() {
+               print "<div class=\"dialogNotice\">" . __("These feeds have not been updated because of errors:") . "</div>";
+
+               $result = db_query($this->link, "SELECT id,title,feed_url,last_error,site_url
+               FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
+
+               print "<div dojoType=\"dijit.Toolbar\">";
+               print "<div dojoType=\"dijit.form.DropDownButton\">".
+                               "<span>" . __('Select')."</span>";
+               print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
+               print "<div onclick=\"selectTableRows('prefErrorFeedList', 'all')\"
+                       dojoType=\"dijit.MenuItem\">".__('All')."</div>";
+               print "<div onclick=\"selectTableRows('prefErrorFeedList', 'none')\"
+                       dojoType=\"dijit.MenuItem\">".__('None')."</div>";
+               print "</div></div>";
+               print "</div>"; #toolbar
+
+               print "<div class=\"inactiveFeedHolder\">";
+
+               print "<table width=\"100%\" cellspacing=\"0\" id=\"prefErrorFeedList\">";
+
+               $lnum = 1;
+
+               while ($line = db_fetch_assoc($result)) {
+
+                       $class = ($lnum % 2) ? "even" : "odd";
+                       $feed_id = $line["id"];
+                       $this_row_id = "id=\"FERDD-$feed_id\"";
+
+                       # class needed for selectTableRows()
+                       print "<tr class=\"placeholder\" $this_row_id>";
+
+                       $edit_title = htmlspecialchars($line["title"]);
+
+                       # id needed for selectTableRows()
+                       print "<td width='5%' align='center'><input
+                               onclick='toggleSelectRow2(this);' dojoType=\"dijit.form.CheckBox\"
+                               type=\"checkbox\" id=\"FERDC-$feed_id\"></td>";
+                       print "<td>";
+
+                       print "<a class=\"visibleLink\" href=\"#\" ".
+                               "title=\"".__("Click to edit feed")."\" ".
+                               "onclick=\"editFeed(".$line["id"].")\">".
+                               htmlspecialchars($line["title"])."</a>: ";
+
+                       print "<span class=\"insensitive\">";
+                       print htmlspecialchars($line["last_error"]);
+                       print "</span>";
+
+                       print "</td>";
+                       print "</tr>";
+
+                       ++$lnum;
+               }
+
+               print "</table>";
+               print "</div>";
+
+               print "<div class='dlgButtons'>";
+               print "<div style='float : left'>";
+               print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('errorFeedsDlg').removeSelected()\">"
+                       .__('Unsubscribe from selected feeds')."</button> ";
+               print "</div>";
+
+               print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('errorFeedsDlg').hide()\">".
+                       __('Close this window')."</button>";
+
+               print "</div>";
+       }
+
 }
 ?>