]> git.wh0rd.org - tt-rss.git/commitdiff
Merge branch 'digest-experimental'
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Fri, 15 Oct 2010 14:58:15 +0000 (18:58 +0400)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Fri, 15 Oct 2010 14:58:15 +0000 (18:58 +0400)
1  2 
functions.php

diff --combined functions.php
index 527e78f8542804b3045ef5d70544e2499f7c106e,02f8bf78af1f0e41ffba5814872df3379e8f1ec6..d628ec743e7a575fdc36512222b41457af8d20f0
        } // function purge_feed
  
        /**
 -       * Purge old posts from old feeds.
 +       * Purge old posts from old feeds. Not used anymore, purging is done after feed update.
         * 
         * @param mixed $link A database connection
         * @param boolean $do_output Set to true to enable printed output, false by default.
         * @access public
         * @return void
         */
 -      function global_purge_old_posts($link, $do_output = false, $limit = false) {
 +      /* function global_purge_old_posts($link, $do_output = false, $limit = false) {
  
                $random_qpart = sql_random_function();
  
                        }
                }       
  
 -              // purge orphaned posts in main content table
 -              $result = db_query($link, "DELETE FROM ttrss_entries WHERE 
 -                      (SELECT COUNT(int_id) FROM ttrss_user_entries WHERE ref_id = id) = 0");
 -
 -              if ($do_output) {
 -                      $rows = db_affected_rows($link, $result);
 -                      _debug("Purged $rows orphaned posts.");
 -              }
 +              purge_orphans($link, $do_output);
  
 -      } // function global_purge_old_posts
 +      } // function global_purge_old_posts */
  
        function feed_purge_interval($link, $feed_id) {
  
                purge_orphans($link);
        }
  
 -      function purge_orphans($link) {
 +      function purge_orphans($link, $do_output = false) {
 +
                // purge orphaned posts in main content table
 -              db_query($link, "DELETE FROM ttrss_entries WHERE 
 +              $result = db_query($link, "DELETE FROM ttrss_entries WHERE 
                        (SELECT COUNT(int_id) FROM ttrss_user_entries WHERE ref_id = id) = 0");
 +
 +              if ($do_output) {
 +                      $rows = db_affected_rows($link, $result);
 +                      _debug("Purged $rows orphaned posts.");
 +              }
        }
  
        function get_feed_update_interval($link, $feed_id) {
                print "<param key=\"cdm_auto_catchup\" value=\"" . 
                        (int) get_pref($link, "CDM_AUTO_CATCHUP") . "\"/>";
  
+               print "<param key=\"fresh_article_max_age\" value=\"" . 
+                       (int) get_pref($link, "FRESH_ARTICLE_MAX_AGE") . "\"/>";
                print "<param key=\"icons_url\" value=\"" . ICONS_URL . "\"/>";
  
                print "<param key=\"cookie_lifetime\" value=\"" . SESSION_COOKIE_LIFETIME . "\"/>";
                                }
  
                                $tmp_result = db_query($link, "SELECT always_display_enclosures FROM
 -                                      ttrss_feeds WHERE id = ".$line['feed_id']." AND owner_uid = ".$_SESSION["uid"]);
 +                                      ttrss_feeds WHERE id = ".
 +                                              (($line['feed_id'] == null) ? $line['orig_feed_id'] : 
 +                                                              $line['feed_id'])." AND owner_uid = ".$_SESSION["uid"]);
  
                                $always_display_enclosures = db_fetch_result($tmp_result, 0, "always_display_enclosures");
  
                return $rv;
        }
  
+       function api_get_feeds($link, $cat_id, $unread_only, $limit, $offset) {
+                       $feeds = array();
+                       /* Labels */
+                       if (!$cat_id || $cat_id == -2) {
+                               $counters = getLabelCounters($link, true);
+                               foreach (array_keys($counters) as $id) {
+                                       $unread = $counters[$id]["counter"];
+       
+                                       if ($unread || !$unread_only) {
+       
+                                               $row = array(
+                                                               "id" => $id,
+                                                               "title" => $counters[$id]["description"],
+                                                               "unread" => $counters[$id]["counter"],
+                                                               "cat_id" => -2,
+                                                       );
+       
+                                               array_push($feeds, $row);
+                                       }
+                               }
+                       }
+                       /* Virtual feeds */
+                       if (!$cat_id || $cat_id == -1) {
+                               foreach (array(-1, -2, -3, -4, 0) as $i) {
+                                       $unread = getFeedUnread($link, $i);
+                                       if ($unread || !$unread_only) {
+                                               $title = getFeedTitle($link, $i);
+                                               $row = array(
+                                                               "id" => $i,
+                                                               "title" => $title,
+                                                               "unread" => $unread,
+                                                               "cat_id" => -1,
+                                                       );
+                                               array_push($feeds, $row);
+                                       }
+                               }                       
+                       }
+                       /* Real feeds */
+                       if ($limit) {
+                               $limit_qpart = "LIMIT $limit OFFSET $offset";
+                       } else {
+                               $limit_qpart = "";
+                       }
+                       if (!$cat_id) {
+                               $result = db_query($link, "SELECT 
+                                       id, feed_url, cat_id, title, ".
+                                               SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated
+                                               FROM ttrss_feeds WHERE owner_uid = " . $_SESSION["uid"] . 
+                                               " ORDER BY cat_id, title " . $limit_qpart);
+                       } else {
+                               $result = db_query($link, "SELECT 
+                                       id, feed_url, cat_id, title, ".
+                                               SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated
+                                               FROM ttrss_feeds WHERE 
+                                               cat_id = '$cat_id' AND owner_uid = " . $_SESSION["uid"] . 
+                                               " ORDER BY cat_id, title " . $limit_qpart);
+                       }
+                       while ($line = db_fetch_assoc($result)) {
+                               $unread = getFeedUnread($link, $line["id"]);
+                               $has_icon = feed_has_icon($line['id']);
+                               if ($unread || !$unread_only) {
+                                       $row = array(
+                                                       "feed_url" => $line["feed_url"],
+                                                       "title" => $line["title"],
+                                                       "id" => (int)$line["id"],
+                                                       "unread" => (int)$unread,
+                                                       "has_icon" => $has_icon,
+                                                       "cat_id" => (int)$line["cat_id"],
+                                                       "last_updated" => strtotime($line["last_updated"])
+                                               );
+       
+                                       array_push($feeds, $row);
+                               }
+                       }
+               return $feeds;
+       }
+       function api_get_headlines($link, $feed_id, $limit, $offset,
+                                       $filter, $is_cat, $show_excerpt, $show_content, $view_mode, $order) {
+                       /* do not rely on params below */
+                       $search = db_escape_string($_REQUEST["search"]);
+                       $search_mode = db_escape_string($_REQUEST["search_mode"]);
+                       $match_on = db_escape_string($_REQUEST["match_on"]);
+                       
+                       $qfh_ret = queryFeedHeadlines($link, $feed_id, $limit, 
+                               $view_mode, $is_cat, $search, $search_mode, $match_on,
+                               $order, $offset);
+                       $result = $qfh_ret[0];
+                       $feed_title = $qfh_ret[1];
+                       $headlines = array();
+                       while ($line = db_fetch_assoc($result)) {
+                               $is_updated = ($line["last_read"] == "" && 
+                                       ($line["unread"] != "t" && $line["unread"] != "1"));
+                               $headline_row = array(
+                                               "id" => (int)$line["id"],
+                                               "unread" => sql_bool_to_bool($line["unread"]),
+                                               "marked" => sql_bool_to_bool($line["marked"]),
+                                               "published" => sql_bool_to_bool($line["published"]),
+                                               "updated" => strtotime($line["updated"]),
+                                               "is_updated" => $is_updated,
+                                               "title" => $line["title"],
+                                               "link" => $line["link"],
+                                               "feed_id" => $line["feed_id"],
+                                               "tags" => get_article_tags($link, $line["id"]),
+                                       );
+                               if ($show_excerpt) {
+                                       $excerpt = truncate_string(strip_tags($line["content_preview"]), 100);
+                                       $headline_row["excerpt"] = $excerpt;
+                               }
+                               if ($show_content) {
+                                       $headline_row["content"] = $line["content_preview"];
+                               }
+                               array_push($headlines, $headline_row);
+                       }
+                       return $headlines;
+       }
  ?>