]> git.wh0rd.org - tt-rss.git/blobdiff - classes/pref/feeds.php
Merge branch 'master' of git.tt-rss.org:fox/tt-rss
[tt-rss.git] / classes / pref / feeds.php
index ffe7410fe901295c1d35e4db639ebd09ee6f63e1..530d851d7812bb28621e0805bb9d61d0c600549c 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 class Pref_Feeds extends Handler_Protected {
+       public static $feed_languages = array("English", "Danish", "Dutch", "Finnish", "French", "German", "Hungarian", "Italian", "Norwegian",
+               "Portuguese", "Russian", "Spanish", "Swedish", "Turkish", "Simple");
 
        function csrf_ignore($method) {
                $csrf_ignored = array("index", "getfeedtree", "add", "editcats", "editfeed",
@@ -54,12 +56,15 @@ class Pref_Feeds extends Handler_Protected {
                        $cat['type'] = 'category';
                        $cat['unread'] = 0;
                        $cat['child_unread'] = 0;
+                       $cat['auxcounter'] = 0;
+                       $cat['parent_id'] = $cat_id;
 
                        $cat['items'] = $this->get_category_items($line['id']);
 
-                       $cat['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items']));
+                       $num_children = $this->calculate_children_count($cat);
+                       $cat['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', $num_children), $num_children);
 
-                       if (count($cat['items']) > 0 || $show_empty_cats)
+                       if ($num_children > 0 || $show_empty_cats)
                                array_push($items, $cat);
 
                }
@@ -74,6 +79,7 @@ class Pref_Feeds extends Handler_Protected {
                        $feed = array();
                        $feed['id'] = 'FEED:' . $feed_line['id'];
                        $feed['bare_id'] = (int)$feed_line['id'];
+                       $feed['auxcounter'] = 0;
                        $feed['name'] = $feed_line['title'];
                        $feed['checkbox'] = false;
                        $feed['unread'] = 0;
@@ -132,6 +138,7 @@ class Pref_Feeds extends Handler_Protected {
                                        $item = array();
                                        $item['id'] = 'FEED:' . $feed_id;
                                        $item['bare_id'] = (int)$feed_id;
+                                       $item['auxcounter'] = 0;
                                        $item['name'] = $feed['title'];
                                        $item['checkbox'] = false;
                                        $item['error'] = '';
@@ -193,6 +200,7 @@ class Pref_Feeds extends Handler_Protected {
                                $cat = array();
                                $cat['id'] = 'CAT:' . $line['id'];
                                $cat['bare_id'] = (int)$line['id'];
+                               $cat['auxcounter'] = 0;
                                $cat['name'] = $line['title'];
                                $cat['items'] = array();
                                $cat['checkbox'] = false;
@@ -202,9 +210,10 @@ class Pref_Feeds extends Handler_Protected {
 
                                $cat['items'] = $this->get_category_items($line['id']);
 
-                               $cat['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items']));
+                               $num_children = $this->calculate_children_count($cat);
+                               $cat['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', $num_children), $num_children);
 
-                               if (count($cat['items']) > 0 || $show_empty_cats)
+                               if ($num_children > 0 || $show_empty_cats)
                                        array_push($root['items'], $cat);
 
                                $root['param'] += count($cat['items']);
@@ -215,6 +224,7 @@ class Pref_Feeds extends Handler_Protected {
                        $cat = array();
                        $cat['id'] = 'CAT:0';
                        $cat['bare_id'] = 0;
+                       $cat['auxcounter'] = 0;
                        $cat['name'] = __("Uncategorized");
                        $cat['items'] = array();
                        $cat['type'] = 'category';
@@ -232,6 +242,7 @@ class Pref_Feeds extends Handler_Protected {
                                $feed = array();
                                $feed['id'] = 'FEED:' . $feed_line['id'];
                                $feed['bare_id'] = (int)$feed_line['id'];
+                               $feed['auxcounter'] = 0;
                                $feed['name'] = $feed_line['title'];
                                $feed['checkbox'] = false;
                                $feed['error'] = $feed_line['last_error'];
@@ -249,8 +260,8 @@ class Pref_Feeds extends Handler_Protected {
                        if (count($cat['items']) > 0 || $show_empty_cats)
                                array_push($root['items'], $cat);
 
-                       $root['param'] += count($cat['items']);
-                       $root['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items']));
+                       $num_children = $this->calculate_children_count($root);
+                       $root['param'] = vsprintf(_ngettext('(%d feed)', '(%d feeds)', $num_children), $num_children);
 
                } else {
                        $feed_result = $this->dbh->query("SELECT id, title, last_error,
@@ -263,6 +274,7 @@ class Pref_Feeds extends Handler_Protected {
                                $feed = array();
                                $feed['id'] = 'FEED:' . $feed_line['id'];
                                $feed['bare_id'] = (int)$feed_line['id'];
+                               $feed['auxcounter'] = 0;
                                $feed['name'] = $feed_line['title'];
                                $feed['checkbox'] = false;
                                $feed['error'] = $feed_line['last_error'];
@@ -386,7 +398,7 @@ class Pref_Feeds extends Handler_Protected {
 #              print_r($data['items']);
 
                if (is_array($data) && is_array($data['items'])) {
-                       $cat_order_id = 0;
+#                      $cat_order_id = 0;
 
                        $data_map = array();
                        $root_item = false;
@@ -485,7 +497,7 @@ class Pref_Feeds extends Handler_Protected {
                $feed_id = $this->dbh->escape_string($_REQUEST["feed_id"]);
 
                if (is_file($icon_file) && $feed_id) {
-                       if (filesize($icon_file) < 20000) {
+                       if (filesize($icon_file) < 65535) {
 
                                $result = $this->dbh->query("SELECT id FROM ttrss_feeds
                                        WHERE id = '$feed_id' AND owner_uid = ". $_SESSION["uid"]);
@@ -521,6 +533,9 @@ class Pref_Feeds extends Handler_Protected {
                global $purge_intervals;
                global $update_intervals;
 
+               print '<div dojoType="dijit.layout.TabContainer" style="height : 450px">
+                       <div dojoType="dijit.layout.ContentPane" title="'.__('General').'">';
+
                $feed_id = $this->dbh->escape_string($_REQUEST["id"]);
 
                $result = $this->dbh->query(
@@ -563,8 +578,9 @@ class Pref_Feeds extends Handler_Protected {
                $last_error = $this->dbh->fetch_result($result, 0, "last_error");
 
                if ($last_error) {
-                       print "&nbsp;<span title=\"".htmlspecialchars($last_error)."\"
-                               class=\"feed_error\">(error)</span>";
+                       print "&nbsp;<img src=\"images/error.png\" alt=\"(error)\"
+                               style=\"vertical-align : middle\"
+                               title=\"".htmlspecialchars($last_error)."\">";
 
                }
 
@@ -582,6 +598,18 @@ class Pref_Feeds extends Handler_Protected {
                                'dojoType="dijit.form.Select"');
                }
 
+               /* FTS Stemming Language */
+
+               if (DB_TYPE == "pgsql") {
+                       $feed_language = $this->dbh->fetch_result($result, 0, "feed_language");
+
+                       print "<hr/>";
+
+                       print __('Language:') . " ";
+                       print_select("feed_language", $feed_language, $this::$feed_languages,
+                               'dojoType="dijit.form.Select"');
+               }
+
                print "</div>";
 
                print "<div class=\"dlgSec\">".__("Update")."</div>";
@@ -633,8 +661,11 @@ class Pref_Feeds extends Handler_Protected {
                        </div>";
 
                print "</div>";
-               print "<div class=\"dlgSec\">".__("Options")."</div>";
-               print "<div class=\"dlgSecCont\">";
+
+               print '</div><div dojoType="dijit.layout.ContentPane" title="'.__('Options').'">';
+
+               //print "<div class=\"dlgSec\">".__("Options")."</div>";
+               print "<div class=\"dlgSecSimple\">";
 
                $private = sql_bool_to_bool($this->dbh->fetch_result($result, 0, "private"));
 
@@ -712,10 +743,11 @@ class Pref_Feeds extends Handler_Protected {
 
                print "</div>";
 
+               print '</div><div dojoType="dijit.layout.ContentPane" title="'.__('Icon').'">';
+
                /* Icon */
 
-               print "<div class=\"dlgSec\">".__("Icon")."</div>";
-               print "<div class=\"dlgSecCont\">";
+               print "<div class=\"dlgSecSimple\">";
 
                print "<iframe name=\"icon_upload_iframe\"
                        style=\"width: 400px; height: 100px; display: none;\"></iframe>";
@@ -726,18 +758,23 @@ class Pref_Feeds extends Handler_Protected {
                        <input id=\"icon_file\" size=\"10\" name=\"icon_file\" type=\"file\">
                        <input type=\"hidden\" name=\"op\" value=\"pref-feeds\">
                        <input type=\"hidden\" name=\"feed_id\" value=\"$feed_id\">
-                       <input type=\"hidden\" name=\"method\" value=\"uploadicon\">
-                       <button dojoType=\"dijit.form.Button\" onclick=\"return uploadFeedIcon();\"
+                       <input type=\"hidden\" name=\"method\" value=\"uploadicon\"><p>
+                       <button class=\"\" dojoType=\"dijit.form.Button\" onclick=\"return uploadFeedIcon();\"
                                type=\"submit\">".__('Replace')."</button>
-                       <button dojoType=\"dijit.form.Button\" onclick=\"return removeFeedIcon($feed_id);\"
+                       <button class=\"\" dojoType=\"dijit.form.Button\" onclick=\"return removeFeedIcon($feed_id);\"
                                type=\"submit\">".__('Remove')."</button>
                        </form>";
 
                print "</div>";
 
+               print '</div><div dojoType="dijit.layout.ContentPane" title="'.__('Plugins').'">';
+
                PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_EDIT_FEED,
                        "hook_prefs_edit_feed", $feed_id);
 
+
+               print "</div></div>";
+
                $title = htmlspecialchars($title, ENT_QUOTES);
 
                print "<div class='dlgButtons'>
@@ -763,6 +800,7 @@ class Pref_Feeds extends Handler_Protected {
                        <button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('feedEditDlg').hide()\">".__('Cancel')."</button>
                </div>";
 
+
                return;
        }
 
@@ -783,31 +821,10 @@ class Pref_Feeds extends Handler_Protected {
                print "<div class=\"dlgSec\">".__("Feed")."</div>";
                print "<div class=\"dlgSecCont\">";
 
-               /* Title */
-
-               print "<input dojoType=\"dijit.form.ValidationTextBox\"
-                       disabled=\"1\" style=\"font-size : 16px; width : 20em;\" required=\"1\"
-                       name=\"title\" value=\"\">";
-
-               $this->batch_edit_cbox("title");
-
-               /* Feed URL */
-
-               print "<br/>";
-
-               print __('URL:') . " ";
-               print "<input dojoType=\"dijit.form.ValidationTextBox\" disabled=\"1\"
-                       required=\"1\" regExp='^(http|https)://.*' style=\"width : 20em\"
-                       name=\"feed_url\" value=\"\">";
-
-               $this->batch_edit_cbox("feed_url");
-
                /* Category */
 
                if (get_pref('ENABLE_FEED_CATS')) {
 
-                       print "<br/>";
-
                        print __('Place in category:') . " ";
 
                        print_feed_cat_select("cat_id", false,
@@ -817,6 +834,18 @@ class Pref_Feeds extends Handler_Protected {
 
                }
 
+               /* FTS Stemming Language */
+
+               if (DB_TYPE == "pgsql") {
+                       print "<hr/>";
+
+                       print __('Language:') . " ";
+                       print_select("feed_language", "", $this::$feed_languages,
+                               'disabled="1" dojoType="dijit.form.Select"');
+
+                       $this->batch_edit_cbox("feed_language");
+               }
+
                print "</div>";
 
                print "<div class=\"dlgSec\">".__("Update")."</div>";
@@ -853,7 +882,7 @@ class Pref_Feeds extends Handler_Protected {
 
                $this->batch_edit_cbox("auth_login");
 
-               print "<br/><input dojoType=\"dijit.form.TextBox\" type=\"password\" name=\"auth_pass\"
+               print "<hr/> <input dojoType=\"dijit.form.TextBox\" type=\"password\" name=\"auth_pass\"
                        placeHolder=\"".__("Password")."\" disabled=\"1\"
                        value=\"\">";
 
@@ -948,6 +977,8 @@ class Pref_Feeds extends Handler_Protected {
                $mark_unread_on_update = checkbox_to_sql_bool(
                        $this->dbh->escape_string($_POST["mark_unread_on_update"]));
 
+               $feed_language = $this->dbh->escape_string(trim($_POST["feed_language"]));
+
                if (strlen(FEED_CRYPT_KEY) > 0) {
                        require_once "crypt.php";
                        $auth_pass = substr(encrypt_string($auth_pass), 0, 250);
@@ -973,7 +1004,12 @@ class Pref_Feeds extends Handler_Protected {
 
                if (!$batch) {
 
-                       $result = $this->dbh->query("UPDATE ttrss_feeds SET
+                       $result = db_query("SELECT feed_url FROM ttrss_feeds WHERE id = " . $feed_id);
+                       $orig_feed_url = db_fetch_result($result, 0, "feed_url");
+
+                       $reset_basic_info = $orig_feed_url != $feed_link;
+
+                       $this->dbh->query("UPDATE ttrss_feeds SET
                                $category_qpart
                                title = '$feed_title', feed_url = '$feed_link',
                                update_interval = '$upd_intl',
@@ -986,9 +1022,16 @@ class Pref_Feeds extends Handler_Protected {
                                hide_images = $hide_images,
                                include_in_digest = $include_in_digest,
                                always_display_enclosures = $always_display_enclosures,
-                               mark_unread_on_update = $mark_unread_on_update
+                               mark_unread_on_update = $mark_unread_on_update,
+                               feed_language = '$feed_language'
                        WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
 
+                       if ($reset_basic_info) {
+                               require_once "rssfuncs.php";
+
+                               set_basic_feed_info($feed_id);
+                       }
+
                        PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_SAVE_FEED,
                                "hook_prefs_save_feed", $feed_id);
 
@@ -1061,6 +1104,10 @@ class Pref_Feeds extends Handler_Protected {
                                                $qpart = $category_qpart_nocomma;
                                                break;
 
+                                       case "feed_language":
+                                               $qpart = "feed_language = '$feed_language'";
+                                               break;
+
                                }
 
                                if ($qpart) {
@@ -1264,25 +1311,11 @@ class Pref_Feeds extends Handler_Protected {
                                __("Feeds with errors") . "</button>";
                }
 
-               if (DB_TYPE == "pgsql") {
-                       $interval_qpart = "NOW() - INTERVAL '3 months'";
-               } else {
-                       $interval_qpart = "DATE_SUB(NOW(), INTERVAL 3 MONTH)";
-               }
-
-               $result = $this->dbh->query("SELECT COUNT(*) AS num_inactive FROM ttrss_feeds 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"]);
-
-               $num_inactive = $this->dbh->fetch_result($result, 0, "num_inactive");
-
-               if ($num_inactive > 0) {
-                       $inactive_button = "<button dojoType=\"dijit.form.Button\"
-                                       onclick=\"showInactiveFeeds()\">" .
-                                       __("Inactive feeds") . "</button>";
-               }
+               $inactive_button = "<button dojoType=\"dijit.form.Button\"
+                               id=\"pref_feeds_inactive_btn\"
+                               style=\"display : none\"
+                               onclick=\"showInactiveFeeds()\">" .
+                               __("Inactive feeds") . "</button>";
 
                $feed_search = $this->dbh->escape_string($_REQUEST["search"]);
 
@@ -1394,6 +1427,8 @@ class Pref_Feeds extends Handler_Protected {
                </script>
                <script type=\"dojo/method\" event=\"onLoad\" args=\"item\">
                        Element.hide(\"feedlistLoading\");
+
+                       checkInactiveFeeds();
                </script>
                </div>";
 
@@ -1483,15 +1518,6 @@ class Pref_Feeds extends Handler_Protected {
 
                print "</p>";
 
-               print_warning(__("You can disable all articles shared by unique URLs here."));
-
-               print "<p>";
-
-               print "<button dojoType=\"dijit.form.Button\" onclick=\"return clearArticleAccessKeys()\">".
-                       __('Unshare all articles')."</button> ";
-
-               print "</p>";
-
                PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION,
                        "hook_prefs_tab_section", "prefFeedsPublishedGenerated");
 
@@ -1541,6 +1567,7 @@ class Pref_Feeds extends Handler_Protected {
                $obj['updated'] = $updated;
                $obj['icon'] = getFeedIcon($feed_id);
                $obj['bare_id'] = $feed_id;
+               $obj['auxcounter'] = 0;
 
                return $obj;
        }
@@ -1592,8 +1619,6 @@ class Pref_Feeds extends Handler_Protected {
                        # 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\"
@@ -1658,8 +1683,6 @@ class Pref_Feeds extends Handler_Protected {
                        # 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\"
@@ -1800,7 +1823,7 @@ class Pref_Feeds extends Handler_Protected {
                }
                print "</td></tr><tr><td colspan='2'>";
                print "<textarea
-                       style='font-size : 12px; width : 100%; height: 200px;'
+                       style='font-size : 12px; width : 98%; height: 200px;'
                        placeHolder=\"".__("Feeds to subscribe, One per line")."\"
                        dojoType=\"dijit.form.SimpleTextarea\" required=\"1\" name=\"feeds\"></textarea>";
 
@@ -1910,7 +1933,7 @@ class Pref_Feeds extends Handler_Protected {
                        AND owner_uid = " . $owner_uid);
 
                if ($this->dbh->num_rows($result) == 1) {
-                       $key = $this->dbh->escape_string(sha1(uniqid(rand(), true)));
+                       $key = $this->dbh->escape_string(uniqid_short());
 
                        $this->dbh->query("UPDATE ttrss_access_keys SET access_key = '$key'
                                WHERE feed_id = '$feed_id' AND is_cat = $sql_is_cat
@@ -1929,6 +1952,34 @@ class Pref_Feeds extends Handler_Protected {
                        owner_uid = " . $_SESSION["uid"]);
        }
 
+       private function calculate_children_count($cat) {
+               $c = 0;
 
+               foreach ($cat['items'] as $child) {
+                       if ($child['type'] == 'category') {
+                               $c += $this->calculate_children_count($child);
+                       } else {
+                               $c += 1;
+                       }
+               }
+
+               return $c;
+       }
+
+       function getinactivefeeds() {
+               if (DB_TYPE == "pgsql") {
+                       $interval_qpart = "NOW() - INTERVAL '3 months'";
+               } else {
+                       $interval_qpart = "DATE_SUB(NOW(), INTERVAL 3 MONTH)";
+               }
+
+               $result = $this->dbh->query("SELECT COUNT(*) AS num_inactive FROM ttrss_feeds 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"]);
+
+               print (int) $this->dbh->fetch_result($result, 0, "num_inactive");
+       }
 }
 ?>