]> git.wh0rd.org - tt-rss.git/blobdiff - functions.php
purge feeds after updating
[tt-rss.git] / functions.php
index 793fa5f40a48b3a3e577bcde7acd9098e5e701ca..565c5d1032cca34d497f90db239f89f432e7494e 100644 (file)
 
                if (!$owner_uid) return;
 
-               $purge_unread = get_pref($link, "PURGE_UNREAD_ARTICLES",
-                       $owner_uid, false);
+               if (FORCE_ARTICLE_PURGE == 0) {
+                       $purge_unread = get_pref($link, "PURGE_UNREAD_ARTICLES",
+                               $owner_uid, false);
+               } else {
+                       $purge_unread = true;
+                       $purge_interval = FORCE_ARTICLE_PURGE;
+               }
 
                if (!$purge_unread) $query_limit = " unread = false AND ";
 
 //                             print "Feed $feed_id: purge interval = $purge_interval\n";
                        }
 
-                       if ($purge_interval > 0) {
+                       if ($purge_interval > 0 || FORCE_ARTICLE_PURGE) {
                                purge_feed($link, $feed_id, $purge_interval, $do_output);
                        }
                }       
                                        _debug("update_rss_feed: updating counters cache...");
                                }
 
-                               ccache_update($link, $feed, $owner_uid);
+                               // disabled, purge_feed() does that...
+                               //ccache_update($link, $feed, $owner_uid);
                        }
 
+                       purge_feed($link, $feed, 0, true);
+
                        db_query($link, "UPDATE ttrss_feeds 
                                SET last_updated = NOW(), last_error = '' WHERE id = '$feed'");
 
 
        function initialize_user($link, $uid) {
 
-               db_query($link, "INSERT INTO ttrss_labels2 (owner_uid, caption)
+/*             db_query($link, "INSERT INTO ttrss_labels2 (owner_uid, caption)
                        VALUES ('$uid', 'All Articles')");
 
                db_query($link, "INSERT INTO ttrss_filters 
                        (owner_uid, feed_id, filter_type, reg_exp, enabled, 
                                action_id, action_param, filter_param) 
-                       VALUES ('$uid', NULL, 1, '.', true, 7, 'All Articles', 'before')");
+                       VALUES ('$uid', NULL, 1, '.', true, 7, 'All Articles', 'before')"); */
 
                db_query($link, "insert into ttrss_feeds (owner_uid,title,feed_url)
                        values ('$uid', 'Tiny Tiny RSS: New Releases',
                                }
                        }
 
-//                     print session_id();
-//                     print_r($_SESSION);
-
                        if (!$_SESSION["uid"] || !validate_session($link)) {
                                render_login_form($link, $mobile);
                                exit;
                                                catchupArticlesById($link, $affected_ids, 0);
                                        }
 
+                                       if ($feed == -4) {
+                                               db_query($link, "UPDATE ttrss_user_entries 
+                                                       SET unread = false,last_read = NOW()
+                                                       WHERE owner_uid = ".$_SESSION["uid"]);
+                                       }
+
                                } else if ($feed < -10) { // label
 
                                        $label_id = -$feed - 11;
 
        function getAllCounters($link, $omode = "flc", $active_feed = false) {
 
-               /* getting all counters is a resource intensive operation, so we
-                * rate limit it a little bit */
-
-
-
-//             if (get_pref($link, "SYNC_COUNTERS") || 
-//                             time() - $_SESSION["get_all_counters_stamp"] > 5) {
-
-                       if (!$omode) $omode = "flc";
+               if (!$omode) $omode = "flc";
        
-                       getGlobalCounters($link);
+               getGlobalCounters($link);
        
-                       if (strchr($omode, "l")) getLabelCounters($link);
-                       if (strchr($omode, "f")) getFeedCounters($link, SMART_RPC_COUNTERS, $active_feed);
-                       if (strchr($omode, "t")) getTagCounters($link);
-                       if (strchr($omode, "c")) {                      
-                               if (get_pref($link, 'ENABLE_FEED_CATS')) {
-                                       getCategoryCounters($link);
-                               }
+               if (strchr($omode, "l")) getLabelCounters($link);
+               if (strchr($omode, "f")) getFeedCounters($link, SMART_RPC_COUNTERS, $active_feed);
+               if (strchr($omode, "t")) getTagCounters($link);
+               if (strchr($omode, "c")) {                      
+                       if (get_pref($link, 'ENABLE_FEED_CATS')) {
+                               getCategoryCounters($link);
                        }
-
-                       $_SESSION["get_all_counters_stamp"] = time();
-//             }
-
+               }
        }       
 
        function getCategoryCounters($link) {
                # two special categories are -1 and -2 (all virtuals; all labels)
 
-               $ctr = getCategoryUnread($link, -1);
+/*             $ctr = getCategoryUnread($link, -1);
 
-               print "<counter type=\"category\" id=\"-1\" counter=\"$ctr\"/>";
+               print "<counter type=\"category\" id=\"-1\" counter=\"$ctr\"/>"; */
 
-               $ctr = getCategoryUnread($link, -2);
+               $ctr = getCategoryUnread($link, -2); 
 
                print "<counter type=\"category\" id=\"-2\" counter=\"$ctr\"/>";
 
                        return getFeedUnread($link, -1) + getFeedUnread($link, -2) + getFeedUnread($link, -3);
                } else if ($cat == -2) {
 
-                       // FIXME: NEW_LABELS
+                       $result = db_query($link, "
+                               SELECT COUNT(unread) AS unread FROM 
+                                       ttrss_user_entries, ttrss_labels2, ttrss_user_labels2, ttrss_feeds 
+                               WHERE label_id = ttrss_labels2.id AND article_id = ref_id AND 
+                                       ttrss_labels2.owner_uid = '$owner_uid'
+                                       AND unread = true AND hidden = false AND feed_id = ttrss_feeds.id
+                                       AND ttrss_user_entries.owner_uid = '$owner_uid'");
 
-/*                     $rv = getLabelCounters($link, false, true);
-                       $ctr = 0;
+                       $unread = db_fetch_result($result, 0, "unread");
 
-                       foreach (array_keys($rv) as $k) {
-                               if ($k < -10) {
-                                       $ctr += $rv[$k]["counter"];
-                               }
-                       }
+                       return $unread;
 
-                       return $ctr; */
                } 
        }
 
                        } else {
                                $match_part .= " AND updated > DATE_SUB(NOW(), INTERVAL $intl HOUR) ";
                        }
-
+               } else if ($n_feed == -4) {
+                       $match_part = "true";
                } else if ($n_feed > 0) {
 
                        $result = db_query($link, "SELECT id FROM ttrss_feeds 
 
                $tctrs_modified = false;
 
-/*             $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
-                       FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE
-                       ttrss_user_entries.ref_id = ttrss_entries.id AND 
-                       ttrss_tags.owner_uid = ".$_SESSION["uid"]." AND
-                       post_int_id = ttrss_user_entries.int_id AND unread = true GROUP BY tag_name 
-               UNION
-                       select tag_name,0 as count FROM ttrss_tags
-                       WHERE ttrss_tags.owner_uid = ".$_SESSION["uid"]); */
-
                $age_qpart = getMaxAgeSubquery();
 
                $result = db_query($link, "SELECT tag_name,SUM((SELECT COUNT(int_id) 
 
                $ret_arr = array();
 
-               for ($i = -1; $i >= -3; $i--) {
+               for ($i = -1; $i >= -4; $i--) {
 
                        $count = getFeedUnread($link, $i);
        
                                        LEFT JOIN ttrss_user_labels2 ON (label_id = ttrss_labels2.id) 
                                                LEFT JOIN ttrss_user_entries ON (ref_id = article_id AND
                                                        unread = true AND
-                                                       ttrss_user_entries.owner_uid = '$owner_uid'),ttrss_feeds
-                                               WHERE ttrss_feeds.id = feed_id AND
-                                                       hidden = false AND                                              
-                                                       ttrss_labels2.owner_uid = '$owner_uid'
+                                                       ttrss_user_entries.owner_uid = '$owner_uid')
+                                               LEFT JOIN ttrss_feeds ON (ttrss_feeds.id = feed_id AND hidden = false)
+                                               WHERE ttrss_labels2.owner_uid = '$owner_uid'
                                        GROUP BY ttrss_labels2.id, caption");
                
                        while ($line = db_fetch_assoc($result)) {
 
                $old_counters = $_SESSION["fctr_last_value"];
 
-/*             $query = "SELECT ttrss_feeds.id,
-                               ttrss_feeds.title,
-                               ".SUBSTRING_FOR_DATE."(ttrss_feeds.last_updated,1,19) AS last_updated, 
-                               last_error, 
-                               COUNT(ttrss_entries.id) AS count 
-                       FROM ttrss_feeds 
-                               LEFT JOIN ttrss_user_entries ON (ttrss_user_entries.feed_id = ttrss_feeds.id 
-                                       AND ttrss_user_entries.owner_uid = ttrss_feeds.owner_uid 
-                                       AND ttrss_user_entries.unread = true) 
-                               LEFT JOIN ttrss_entries ON (ttrss_user_entries.ref_id = ttrss_entries.id AND
-                                       $age_qpart) 
-                       WHERE ttrss_feeds.owner_uid = ".$_SESSION["uid"]."  
-                               AND parent_feed IS NULL 
-                               GROUP BY ttrss_feeds.id, ttrss_feeds.title, ttrss_feeds.last_updated, last_error"; */
-
                $query = "SELECT ttrss_feeds.id,
                                ttrss_feeds.title,
                                ".SUBSTRING_FOR_DATE."(ttrss_feeds.last_updated,1,19) AS last_updated, 
 
                        $has_img = feed_has_icon($id);
 
-/*                     $tmp_result = db_query($link,
-                               "SELECT ttrss_feeds.id,COUNT(unread) AS unread
-                               FROM ttrss_feeds LEFT JOIN ttrss_user_entries 
-                                       ON (ttrss_feeds.id = ttrss_user_entries.feed_id) 
-                               LEFT JOIN ttrss_entries ON (ttrss_user_entries.ref_id = ttrss_entries.id) 
-                               WHERE parent_feed = '$id' AND $age_qpart AND unread = true GROUP BY ttrss_feeds.id"); */
-
                        $tmp_result = db_query($link,
                                "SELECT SUM(value) AS unread FROM ttrss_feeds, ttrss_counters_cache 
                                        WHERE parent_feed = '$id' AND feed_id = id");
                        return __("Published articles");
                } else if ($id == -3) {
                        return __("Fresh articles");
+               } else if ($id == -4) {
+                       return __("All articles");
                } else if ($id < -10) {
                        $label_id = -$id - 11;
                        $result = db_query($link, "SELECT caption FROM ttrss_labels2 WHERE id = '$label_id'");
                        if ($view_mode == "unread") {
                                $view_query_part = " unread = true AND ";
                        }
-       
+
+                       if ($view_mode == "updated") {
+                               $view_query_part = " (last_read is null and unread = false) AND ";
+                       }
+
                        if ($limit > 0) {
                                $limit_query_part = "LIMIT " . $limit;
                        } 
                        } else if ($feed == -1) { // starred virtual feed
                                $query_strategy_part = "marked = true";
                                $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
-                       } else if ($feed == -2) { // published virtual feed
-                               $query_strategy_part = "published = true";
-                               $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
+                       } else if ($feed == -2) { // published virtual feed OR labels category
+
+                               if (!$cat_view) {
+                                       $query_strategy_part = "published = true";
+                                       $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
+                               } else {
+                                       $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
+
+                                       $ext_tables_part = ",ttrss_labels2,ttrss_user_labels2";
+       
+                                       $query_strategy_part = "ttrss_labels2.id = ttrss_user_labels2.label_id AND
+                                               ttrss_user_labels2.article_id = ref_id";
+
+                               }
+
                        } else if ($feed == -3) { // fresh virtual feed
                                $query_strategy_part = "unread = true";
 
                                        $query_strategy_part .= " AND updated > DATE_SUB(NOW(), INTERVAL $intl HOUR) ";
                                }
 
+                               $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
+                       } else if ($feed == -4) { // all articles virtual feed
+                               $query_strategy_part = "true";
                                $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
                        } else if ($feed <= -10) { // labels
                                $label_id = -$feed - 11;
                                $feed_title = __("Starred articles");
                                if ($search) {  $feed_title = __("Searched for") . " $search ($feed_title)"; }
                        } else if ($feed == -2) {
-                               $feed_title = __("Published articles");
-                               if ($search) {  $feed_title = __("Searched for") . " $search ($feed_title)"; }
+                               if (!$cat_view) {
+                                       $feed_title = __("Published articles");
+                                       if ($search) {  $feed_title = __("Searched for") . " $search ($feed_title)"; }
+                               } else {
+                                       $feed_title = __("Labels");
+                               }
                        } else if ($feed == -3) {
                                $feed_title = __("Fresh articles");
                                if ($search) {  $feed_title = __("Searched for") . " $search ($feed_title)"; }
+                       } else if ($feed == -4) {
+                               $feed_title = __("All articles");
+                               if ($search) {  $feed_title = __("Searched for") . " $search ($feed_title)"; }
                        } else if ($feed < -10) {
                                $label_id = -$feed - 11;
                                $result = db_query($link, "SELECT caption FROM ttrss_labels2
 } */
                                }
 
-                               $query = "SELECT 
+                               $query = "SELECT DISTINCT 
                                                guid,
                                                ttrss_entries.id,ttrss_entries.title,
                                                updated,
 
                        if ($cat_id > 0) {
                                $cat_unread = ccache_find($link, $cat_id, $_SESSION["uid"], true);
-                       } else {
+                       } else if ($cat_id == 0 || $cat_id == -2) {
                                $cat_unread = getCategoryUnread($link, $cat_id);
                        }
 
                                $inner_title_class = "catTitleNL";
                        }
 
-                       if ($cat_id >= 0) {
-                               $cat_class = "feedCat";
-                       } else {
-                               $cat_class = "virtCat";
-                       }
+                       $cat_class = "feedCat";
 
                        print "<li class=\"$cat_class\" id=\"FCAT-$cat_id\">
                                <img onclick=\"toggleCollapseCat($cat_id)\" class=\"catCollapse\"
                $num_starred = getFeedUnread($link, -1);
                $num_published = getFeedUnread($link, -2);
                $num_fresh = getFeedUnread($link, -3);
+               $num_total = getFeedUnread($link, -4);
+
+               $class = "virt";
+
+               if ($num_total > 0) $class .= "Unread";
+
+               printFeedEntry(-4, $class, __("All articles"), $num_total, 
+                       "images/tag.png", $link);
 
                $class = "virt";
 
                                                        $cat_hidden = false;
                                                }
 
-                                               printCategoryHeader($link, -2, $cat_hidden, false);
+                                               printCategoryHeader($link, -2, $cat_hidden, true);
 
                                        } else {
                                                print "<li><hr></li>";
                                ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated_noms,
                                cat_id,last_error,
                                ttrss_feed_categories.title AS category,
-                               ttrss_feed_categories.collapsed 
-                               FROM ttrss_feeds LEFT JOIN ttrss_feed_categories 
-                                       ON (ttrss_feed_categories.id = cat_id)                          
+                               ttrss_feed_categories.collapsed,
+                               value AS unread 
+                               FROM ttrss_feeds LEFT JOIN ttrss_feed_categories
+                                       ON (ttrss_feed_categories.id = cat_id)                  
+                               LEFT JOIN ttrss_counters_cache 
+                                       ON
+                                               (ttrss_feeds.id = feed_id)
                                WHERE 
                                        ttrss_feeds.hidden = false AND
                                        ttrss_feeds.owner_uid = '$owner_uid' AND parent_feed IS NULL
                                if (!$feed) $feed = "[Untitled]";
 
                                $feed_id = $line["id"];   
+                               $unread = $line["unread"];
        
                                $subop = $_GET["subop"];
-                               
-                               $unread = ccache_find($link, $feed_id, $_SESSION["uid"]);
 
                                if (get_pref($link, 'HEADLINES_SMART_DATE')) {
                                        $last_updated = smart_date_time(strtotime($line["last_updated_noms"]));
                                $feed_icon = "&nbsp;";
                        }
 
-/*                     if ($line["comments"] && $line["link"] != $line["comments"]) {
-                               $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)";
-                       } else {
-                               $entry_comments = "";
-                       } */
-
                        $num_comments = $line["num_comments"];
                        $entry_comments = "";
 
                                print "<div clear='both'>" . $line["title"] . "$entry_author</div>";
                        }
 
-/*                     $tmp_result = db_query($link, "SELECT DISTINCT tag_name FROM
-                               ttrss_tags WHERE post_int_id = " . $line["int_id"] . "
-                               ORDER BY tag_name"); */
-
                        $tags = get_article_tags($link, $id);
        
                        $tags_str = "";
                        print "</div>";
 
                        print "<div class=\"postIcon\">" . $feed_icon . "</div>";
+
                        print "<div class=\"postContent\">";
-                       
+
                        #print "<div id=\"allEntryTags\">".__('Tags:')." $f_tags_str</div>";
 
                        $article_content = sanitize_rss($link, $line["content"]);
                                $id = $line["id"];
                                $feed_id = $line["feed_id"];
 
+                               $labels = get_article_labels($link, $id);
+                               $labels_str = "<span id=\"HLLCTR-$id\">";
+
+                               foreach ($labels as $l) {
+                                       $labels_str .= "<span 
+                                               class='hlLabelRef'>".
+                                               $l[1]."</span>";
+                               }
+
+                               $labels_str .= "</span>";
+
                                if (count($topmost_article_ids) < 5) {
                                        array_push($topmost_article_ids, $id);
                                }
 
                                $score_pic = get_score_pic($score);
 
-                               $score_title = __("(Click to change)");
+/*                             $score_title = __("(Click to change)");
+                               $score_pic = "<img class='hlScorePic' src=\"images/$score_pic\" 
+                                       onclick=\"adjustArticleScore($id, $score)\" title=\"$score $score_title\">"; */
 
                                $score_pic = "<img class='hlScorePic' src=\"images/$score_pic\" 
-                                       onclick=\"adjustArticleScore($id, $score)\" title=\"$score $score_title\">";
+                                       title=\"$score\">";
 
                                if ($score > 500) {
                                        $hlc_suffix = "H";
 
                                        print "</a>";
 
+                                       print $labels_str;
+
 #                                                      <a href=\"javascript:viewfeed($feed_id, '', false)\">".
 #                                                      $line["feed_title"]."</a>       
 
                                                        (".__('Show article').")</a>";
                                        } */
 
+                                       print $labels_str;
 
                                        if (!get_pref($link, 'VFEED_GROUP_BY_FEED')) {
                                                if ($line["feed_title"]) {      
                                print "</table>";
                        }
 
-//                     print_headline_subtoolbar($link, 
-//                             "javascript:catchupPage()", "Mark page as read", true, $rtl_content);
-
-
                } else {
                        $message = "";
 
                                case "unread":
                                        $message = __("No unread articles found to display.");
                                        break;
+                               case "updated":
+                                       $message = __("No updated articles found to display.");
+                                       break;
                                case "marked":
                                        $message = __("No starred articles found to display.");
                                        break;
                                default:
-                                       $message = __("No articles found to display.");
+                                       if ($feed < -10) {
+                                               $message = __("No articles found to display. You can assign articles to labels manually (see the Actions menu above) or use a filter.");
+                                       } else {
+                                               $message = __("No articles found to display.");
+                                       }
                        }
 
                        if (!$offset) print "<div class='whiteBox'>$message</div>";
 
        function printTagCloud($link) {
 
-               /* get first ref_id to count from */
-
-               /*
-
-               $query = "";
-
-               if (DB_TYPE == "pgsql") {
-                       $query = "SELECT MIN(id) AS id FROM ttrss_user_entries, ttrss_entries 
-                               WHERE int_id = id AND owner_uid = ".$_SESSION["uid"]."
-                               AND date_entered > NOW() - INTERVAL '30 days'";
-               } else {
-                       $query = "SELECT MIN(id) AS id FROM ttrss_user_entries, ttrss_entries 
-                               WHERE int_id = id AND owner_uid = ".$_SESSION["uid"]." 
-                               AND date_entered > DATE_SUB(NOW(), INTERVAL 30 DAY)";
-               }
-
-               $result = db_query($link, $query);
-               $first_id = db_fetch_result($result, 0, "id"); */
-
-               //AND post_int_id >= '$first_id'
                $query = "SELECT tag_name, COUNT(post_int_id) AS count 
                        FROM ttrss_tags WHERE owner_uid = ".$_SESSION["uid"]." 
                        GROUP BY tag_name ORDER BY count DESC LIMIT 50";
                                FROM ttrss_labels2, ttrss_user_labels2 
                        WHERE id = label_id 
                                AND article_id = '$id' 
-                               AND owner_uid = ".$_SESSION["uid"]);
+                               AND owner_uid = ".$_SESSION["uid"] . "
+                       ORDER BY caption");
 
                $rv = array();
 
                                (label_id, article_id) VALUES ('$label_id', '$id')");
                }
        }
+
+       function label_remove($link, $id, $owner_uid) {
+
+               db_query($link, "BEGIN");
+
+               $result = db_query($link, "SELECT caption FROM ttrss_labels2
+                       WHERE id = '$id'");
+
+               $caption = db_fetch_result($result, 0, "caption");
+
+               $result = db_query($link, "DELETE FROM ttrss_labels2 WHERE id = '$id'
+                       AND owner_uid = " . $_SESSION["uid"]);
+
+               if (db_affected_rows($link, $result) != 0 && $caption) {
+
+                       /* Disable filters that reference label being removed */
+       
+                       db_query($link, "UPDATE ttrss_filters SET
+                               enabled = false WHERE action_param = '$caption'
+                                       AND action_id = 7
+                                       AND owner_uid = " . $_SESSION["uid"]);
+                       }
+
+               db_query($link, "COMMIT");
+       }
 ?>