]> git.wh0rd.org - tt-rss.git/blobdiff - classes/pref/feeds.php
edit feed: smaller buttons for icon upload; allow uploading larger favicons
[tt-rss.git] / classes / pref / feeds.php
index 2f5a0e499d7a51bb631995009f9ebe22515ecedc..d70c1a26add83d7d2e88751c58b4d24946a4e8cc 100644 (file)
@@ -36,8 +36,7 @@ class Pref_Feeds extends Handler_Protected {
 
                // first one is set by API
                $show_empty_cats = $_REQUEST['force_show_empty'] ||
-                       ($_REQUEST['mode'] != 2 && !$search &&
-                               get_pref('_PREFS_SHOW_EMPTY_CATS'));
+                       ($_REQUEST['mode'] != 2 && !$search);
 
                $items = array();
 
@@ -55,12 +54,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);
 
                }
@@ -75,6 +77,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;
@@ -133,6 +136,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'] = '';
@@ -185,8 +189,7 @@ class Pref_Feeds extends Handler_Protected {
 
                if ($enable_cats) {
                        $show_empty_cats = $_REQUEST['force_show_empty'] ||
-                               ($_REQUEST['mode'] != 2 && !$search &&
-                               get_pref('_PREFS_SHOW_EMPTY_CATS'));
+                               ($_REQUEST['mode'] != 2 && !$search);
 
                        $result = $this->dbh->query("SELECT id, title FROM ttrss_feed_categories
                                WHERE owner_uid = " . $_SESSION["uid"] . " AND parent_cat IS NULL ORDER BY order_id, title");
@@ -195,6 +198,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;
@@ -204,9 +208,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']);
@@ -217,6 +222,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';
@@ -234,6 +240,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'];
@@ -251,8 +258,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,
@@ -265,6 +272,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'];
@@ -305,11 +313,6 @@ class Pref_Feeds extends Handler_Protected {
                return;
        }
 
-       function togglehiddenfeedcats() {
-               set_pref('_PREFS_SHOW_EMPTY_CATS',
-                       (get_pref('_PREFS_SHOW_EMPTY_CATS') ? 'false' : 'true'));
-       }
-
        private function process_category_order(&$data_map, $item_id, $parent_id = false, $nest_level = 0) {
                $debug = isset($_REQUEST["debug"]);
 
@@ -393,7 +396,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;
@@ -492,7 +495,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"]);
@@ -500,14 +503,8 @@ class Pref_Feeds extends Handler_Protected {
                                if ($this->dbh->num_rows($result) != 0) {
                                        @unlink(ICONS_DIR . "/$feed_id.ico");
                                        if (rename($icon_file, ICONS_DIR . "/$feed_id.ico")) {
-
-                                               require_once "colors.php";
-
-                                               $favicon_color = $this->dbh->escape_string(
-                                                       calculate_avg_color(ICONS_DIR . "/$feed_id.ico"));
-
                                                $this->dbh->query("UPDATE ttrss_feeds SET
-                                                       favicon_avg_color = '$favicon_color'
+                                                       favicon_avg_color = ''
                                                        WHERE id = '$feed_id'");
 
                                                $rc = 0;
@@ -576,8 +573,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)."\">";
 
                }
 
@@ -740,14 +738,17 @@ class Pref_Feeds extends Handler_Protected {
                        <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();\"
+                       <button class=\"small\" dojoType=\"dijit.form.Button\" onclick=\"return uploadFeedIcon();\"
                                type=\"submit\">".__('Replace')."</button>
-                       <button dojoType=\"dijit.form.Button\" onclick=\"return removeFeedIcon($feed_id);\"
+                       <button class=\"small\" dojoType=\"dijit.form.Button\" onclick=\"return removeFeedIcon($feed_id);\"
                                type=\"submit\">".__('Remove')."</button>
                        </form>";
 
                print "</div>";
 
+               PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_EDIT_FEED,
+                       "hook_prefs_edit_feed", $feed_id);
+
                $title = htmlspecialchars($title, ENT_QUOTES);
 
                print "<div class='dlgButtons'>
@@ -793,34 +794,13 @@ 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=\"$title\">";
-
-               $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=\"$feed_url\">";
-
-               $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", $cat_id,
+                       print_feed_cat_select("cat_id", false,
                                'disabled="1" dojoType="dijit.form.Select"');
 
                        $this->batch_edit_cbox("cat_id");
@@ -834,7 +814,7 @@ class Pref_Feeds extends Handler_Protected {
 
                /* Update Interval */
 
-               print_select_hash("update_interval", $update_interval, $update_intervals,
+               print_select_hash("update_interval", "", $update_intervals,
                        'disabled="1" dojoType="dijit.form.Select"');
 
                $this->batch_edit_cbox("update_interval");
@@ -847,7 +827,7 @@ class Pref_Feeds extends Handler_Protected {
 
                        print __('Article purging:') . " ";
 
-                       print_select_hash("purge_interval", $purge_interval, $purge_intervals,
+                       print_select_hash("purge_interval", "", $purge_intervals,
                                'disabled="1" dojoType="dijit.form.Select"');
 
                        $this->batch_edit_cbox("purge_interval");
@@ -859,13 +839,13 @@ class Pref_Feeds extends Handler_Protected {
 
                print "<input dojoType=\"dijit.form.TextBox\"
                        placeHolder=\"".__("Login")."\" disabled=\"1\"
-                       name=\"auth_login\" value=\"$auth_login\">";
+                       name=\"auth_login\" value=\"\">";
 
                $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=\"$auth_pass\">";
+                       value=\"\">";
 
                $this->batch_edit_cbox("auth_pass");
 
@@ -983,7 +963,7 @@ class Pref_Feeds extends Handler_Protected {
 
                if (!$batch) {
 
-                       $result = $this->dbh->query("UPDATE ttrss_feeds SET
+                       $this->dbh->query("UPDATE ttrss_feeds SET
                                $category_qpart
                                title = '$feed_title', feed_url = '$feed_link',
                                update_interval = '$upd_intl',
@@ -999,6 +979,9 @@ class Pref_Feeds extends Handler_Protected {
                                mark_unread_on_update = $mark_unread_on_update
                        WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
 
+                       PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_SAVE_FEED,
+                               "hook_prefs_save_feed", $feed_id);
+
                } else {
                        $feed_data = array();
 
@@ -1277,13 +1260,18 @@ class Pref_Feeds extends Handler_Protected {
                        $interval_qpart = "DATE_SUB(NOW(), INTERVAL 3 MONTH)";
                }
 
-               $result = $this->dbh->query("SELECT COUNT(*) AS num_inactive FROM ttrss_feeds WHERE
+               // could be performance-intensive and prevent feeds pref-panel from showing
+               if (!defined('_DISABLE_INACTIVE_FEEDS') || !_DISABLE_INACTIVE_FEEDS) {
+                       $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");
+                       $num_inactive = $this->dbh->fetch_result($result, 0, "num_inactive");
+               } else {
+                       $num_inactive = 0;
+               }
 
                if ($num_inactive > 0) {
                        $inactive_button = "<button dojoType=\"dijit.form.Button\"
@@ -1351,9 +1339,6 @@ class Pref_Feeds extends Handler_Protected {
                print $error_button;
                print $inactive_button;
 
-               print "<button onclick=\"toggleHiddenFeedCats()\"
-                       dojoType=\"dijit.form.Button\">".__('(Un)hide empty categories')."</button>";
-
                if (defined('_ENABLE_FEED_DEBUGGING')) {
 
                        print "<select id=\"feedActionChooser\" onchange=\"feedActionChange()\">
@@ -1418,9 +1403,7 @@ class Pref_Feeds extends Handler_Protected {
 
                print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('OPML')."\">";
 
-               print "<p>" . __("Using OPML you can export and import your feeds, filters, labels and Tiny Tiny RSS settings.") . " ";
-
-               print __("Only main settings profile can be migrated using OPML.") . "</p>";
+               print_notice(__("Using OPML you can export and import your feeds, filters, labels and Tiny Tiny RSS settings.") . __("Only main settings profile can be migrated using OPML."));
 
                print "<iframe id=\"upload_iframe\"
                        name=\"upload_iframe\" onload=\"opmlImportComplete(this)\"
@@ -1463,7 +1446,7 @@ class Pref_Feeds extends Handler_Protected {
 
                        print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Firefox integration')."\">";
 
-                       print "<p>" . __('This Tiny Tiny RSS site can be used as a Firefox Feed Reader by clicking the link below.') . "</p>";
+                       print_notice(__('This Tiny Tiny RSS site can be used as a Firefox Feed Reader by clicking the link below.'));
 
                        print "<p>";
 
@@ -1480,25 +1463,20 @@ class Pref_Feeds extends Handler_Protected {
 
                print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Published & shared articles / 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_notice(__('Published articles are exported as a public RSS feed and can be subscribed by anyone who knows the URL specified below.'));
 
                $rss_url = '-2::' . htmlspecialchars(get_self_url_prefix() .
                                "/public.php?op=rss&id=-2&view-mode=all_articles");;
 
+               print "<p>";
+
                print "<button dojoType=\"dijit.form.Button\" onclick=\"return displayDlg('".__("View as RSS")."','generatedFeed', '$rss_url')\">".
                        __('Display URL')."</button> ";
 
                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 "</p>";
 
                PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION,
                        "hook_prefs_tab_section", "prefFeedsPublishedGenerated");
@@ -1549,6 +1527,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;
        }
@@ -1573,7 +1552,7 @@ class Pref_Feeds extends Handler_Protected {
                        GROUP BY ttrss_feeds.title, ttrss_feeds.id, ttrss_feeds.site_url, ttrss_feeds.feed_url
                        ORDER BY last_article");
 
-               print "<h2" .__("These feeds have not been updated with new content for 3 months (oldest first):") . "</h2>";
+               print "<p" .__("These feeds have not been updated with new content for 3 months (oldest first):") . "</p>";
 
                print "<div dojoType=\"dijit.Toolbar\">";
                print "<div dojoType=\"dijit.form.DropDownButton\">".
@@ -1594,15 +1573,12 @@ class Pref_Feeds extends Handler_Protected {
 
                while ($line = $this->dbh->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\"
@@ -1639,9 +1615,6 @@ class Pref_Feeds extends Handler_Protected {
        }
 
        function feedsWithErrors() {
-               print "<h2>" . __("These feeds have not been updated because of errors:") .
-                       "</h2>";
-
                $result = $this->dbh->query("SELECT id,title,feed_url,last_error,site_url
                FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
 
@@ -1664,15 +1637,12 @@ class Pref_Feeds extends Handler_Protected {
 
                while ($line = $this->dbh->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\"
@@ -1923,7 +1893,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(base_convert(rand(), 10, 36)));
 
                        $this->dbh->query("UPDATE ttrss_access_keys SET access_key = '$key'
                                WHERE feed_id = '$feed_id' AND is_cat = $sql_is_cat
@@ -1942,6 +1912,19 @@ 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;
+       }
 
 }
 ?>