]> git.wh0rd.org - tt-rss.git/blobdiff - include/functions.php
fix DAEMON_SLEEP_INTERVAL not being defined when used
[tt-rss.git] / include / functions.php
index 30d92d091a66e381afea854ed0f1a4892d96dec6..4801876c14a8777fd21181bdb651eb899c908d4e 100644 (file)
        // How many seconds to wait for initial response from website when
        // fetching files from remote sites
 
+       // feed updating stuff
+       define_default('DAEMON_UPDATE_LOGIN_LIMIT', 30);
+       define_default('DAEMON_FEED_LIMIT', 500);
+       define_default('DAEMON_SLEEP_INTERVAL', 120);
+       define_default('_MIN_CACHE_FILE_SIZE', 1024);
+
        if (DB_TYPE == "pgsql") {
                define('SUBSTRING_FOR_DATE', 'SUBSTRING_FOR_DATE');
        } else {
 
        require_once 'db-prefs.php';
        require_once 'version.php';
-       require_once 'labels.php';
        require_once 'controls.php';
 
        define('SELF_USER_AGENT', 'Tiny Tiny RSS/' . VERSION . ' (http://tt-rss.org/)');
                }
        }
 
-       function getAllCounters() {
-               $data = getGlobalCounters();
-
-               $data = array_merge($data, getVirtCounters());
-               $data = array_merge($data, getLabelCounters());
-               $data = array_merge($data, getFeedCounters());
-               $data = array_merge($data, getCategoryCounters());
-
-               return $data;
-       }
-
-       function getCategoryCounters() {
-               $ret_arr = array();
-
-               /* Labels category */
-
-               $cv = array("id" => -2, "kind" => "cat",
-                       "counter" => Feeds::getCategoryUnread(-2));
-
-               array_push($ret_arr, $cv);
-
-               $result = db_query("SELECT id AS cat_id, value AS unread,
-                       (SELECT COUNT(id) FROM ttrss_feed_categories AS c2
-                               WHERE c2.parent_cat = ttrss_feed_categories.id) AS num_children
-                       FROM ttrss_feed_categories, ttrss_cat_counters_cache
-                       WHERE ttrss_cat_counters_cache.feed_id = id AND
-                       ttrss_cat_counters_cache.owner_uid = ttrss_feed_categories.owner_uid AND
-                       ttrss_feed_categories.owner_uid = " . $_SESSION["uid"]);
-
-               while ($line = db_fetch_assoc($result)) {
-                       $line["cat_id"] = (int) $line["cat_id"];
-
-                       if ($line["num_children"] > 0) {
-                               $child_counter = Feeds::getCategoryChildrenUnread($line["cat_id"], $_SESSION["uid"]);
-                       } else {
-                               $child_counter = 0;
-                       }
-
-                       $cv = array("id" => $line["cat_id"], "kind" => "cat",
-                               "counter" => $line["unread"] + $child_counter);
-
-                       array_push($ret_arr, $cv);
-               }
-
-               /* Special case: NULL category doesn't actually exist in the DB */
-
-               $cv = array("id" => 0, "kind" => "cat",
-                       "counter" => (int) CCache::find(0, $_SESSION["uid"], true));
-
-               array_push($ret_arr, $cv);
-
-               return $ret_arr;
-       }
-
        function getFeedUnread($feed, $is_cat = false) {
                return Feeds::getFeedArticles($feed, $is_cat, true, $_SESSION["uid"]);
        }
 
-       function getGlobalCounters($global_unread = -1) {
-               $ret_arr = array();
-
-               if ($global_unread == -1) {
-                       $global_unread = Feeds::getGlobalUnread();
-               }
-
-               $cv = array("id" => "global-unread",
-                       "counter" => (int) $global_unread);
-
-               array_push($ret_arr, $cv);
-
-               $result = db_query("SELECT COUNT(id) AS fn FROM
-                       ttrss_feeds WHERE owner_uid = " . $_SESSION["uid"]);
-
-               $subscribed_feeds = db_fetch_result($result, 0, "fn");
-
-               $cv = array("id" => "subscribed-feeds",
-                       "counter" => (int) $subscribed_feeds);
-
-               array_push($ret_arr, $cv);
-
-               return $ret_arr;
-       }
-
-       function getVirtCounters() {
-
-               $ret_arr = array();
-
-               for ($i = 0; $i >= -4; $i--) {
-
-                       $count = getFeedUnread($i);
-
-                       if ($i == 0 || $i == -1 || $i == -2)
-                               $auxctr = Feeds::getFeedArticles($i, false);
-                       else
-                               $auxctr = 0;
-
-                       $cv = array("id" => $i,
-                               "counter" => (int) $count,
-                               "auxcounter" => (int) $auxctr);
-
-//                     if (get_pref('EXTENDED_FEEDLIST'))
-//                             $cv["xmsg"] = getFeedArticles($i)." ".__("total");
-
-                       array_push($ret_arr, $cv);
-               }
-
-               $feeds = PluginHost::getInstance()->get_feeds(-1);
-
-               if (is_array($feeds)) {
-                       foreach ($feeds as $feed) {
-                               $cv = array("id" => PluginHost::pfeed_to_feed_id($feed['id']),
-                                       "counter" => $feed['sender']->get_unread($feed['id']));
-
-                               if (method_exists($feed['sender'], 'get_total'))
-                                       $cv["auxcounter"] = $feed['sender']->get_total($feed['id']);
-
-                               array_push($ret_arr, $cv);
-                       }
-               }
-
-               return $ret_arr;
-       }
-
-       function getLabelCounters($descriptions = false) {
-
-               $ret_arr = array();
-
-               $owner_uid = $_SESSION["uid"];
-
-               $result = db_query("SELECT id,caption,SUM(CASE WHEN u1.unread = true THEN 1 ELSE 0 END) AS unread, COUNT(u1.unread) AS total
-                       FROM ttrss_labels2 LEFT JOIN ttrss_user_labels2 ON
-                               (ttrss_labels2.id = label_id)
-                               LEFT JOIN ttrss_user_entries AS u1 ON u1.ref_id = article_id
-                               WHERE ttrss_labels2.owner_uid = $owner_uid AND u1.owner_uid = $owner_uid
-                               GROUP BY ttrss_labels2.id,
-                                       ttrss_labels2.caption");
-
-               while ($line = db_fetch_assoc($result)) {
-
-                       $id = label_to_feed_id($line["id"]);
-
-                       $cv = array("id" => $id,
-                               "counter" => (int) $line["unread"],
-                               "auxcounter" => (int) $line["total"]);
-
-                       if ($descriptions)
-                               $cv["description"] = $line["caption"];
-
-                       array_push($ret_arr, $cv);
-               }
-
-               return $ret_arr;
-       }
-
-       function getFeedCounters($active_feed = false) {
-
-               $ret_arr = array();
-
-               $query = "SELECT ttrss_feeds.id,
-                               ttrss_feeds.title,
-                               ".SUBSTRING_FOR_DATE."(ttrss_feeds.last_updated,1,19) AS last_updated,
-                               last_error, value AS count
-                       FROM ttrss_feeds, ttrss_counters_cache
-                       WHERE ttrss_feeds.owner_uid = ".$_SESSION["uid"]."
-                               AND ttrss_counters_cache.owner_uid = ttrss_feeds.owner_uid
-                               AND ttrss_counters_cache.feed_id = id";
-
-               $result = db_query($query);
-
-               while ($line = db_fetch_assoc($result)) {
-
-                       $id = $line["id"];
-                       $count = $line["count"];
-                       $last_error = htmlspecialchars($line["last_error"]);
-
-                       $last_updated = make_local_datetime($line['last_updated'], false);
-
-                       $has_img = feed_has_icon($id);
-
-                       if (date('Y') - date('Y', strtotime($line['last_updated'])) > 2)
-                               $last_updated = '';
-
-                       $cv = array("id" => $id,
-                               "updated" => $last_updated,
-                               "counter" => (int) $count,
-                               "has_img" => (int) $has_img);
-
-                       if ($last_error)
-                               $cv["error"] = $last_error;
-
-//                     if (get_pref('EXTENDED_FEEDLIST'))
-//                             $cv["xmsg"] = getFeedArticles($id)." ".__("total");
-
-                       if ($active_feed && $id == $active_feed)
-                               $cv["title"] = truncate_string($line["title"], 30);
-
-                       array_push($ret_arr, $cv);
-
-               }
-
-               return $ret_arr;
-       }
 
        /*function get_pgsql_version() {
                $result = db_query("SELECT version() AS version");
        function load_filters($feed_id, $owner_uid) {
                $filters = array();
 
-               $cat_id = (int)getFeedCategory($feed_id);
+               $cat_id = (int)Feeds::getFeedCategory($feed_id);
 
                if ($cat_id == 0)
                        $null_cat_qpart = "cat_id IS NULL OR";
                return null;
        }
 
-       function getFeedCategory($feed) {
-               $result = db_query("SELECT cat_id FROM ttrss_feeds
-                               WHERE id = '$feed'");
-
-               if (db_num_rows($result) > 0) {
-                       return db_fetch_result($result, 0, "cat_id");
-               } else {
-                       return false;
-               }
-
-       }
-
        function implements_interface($class, $interface) {
                return in_array($interface, class_implements($class));
        }
                }
        }
 
-       function label_to_feed_id($label) {
-               return LABEL_BASE_INDEX - 1 - abs($label);
-       }
-
-       function feed_to_label_id($feed) {
-               return LABEL_BASE_INDEX - 1 + abs($feed);
-       }
-
        function get_theme_path($theme) {
                $check = "themes/$theme";
                if (file_exists($check)) return $check;
 
        }
 
-       function abs_to_rel_path($dir) {
+       /*function abs_to_rel_path($dir) {
                $tmp = str_replace(dirname(__DIR__), "", $dir);
 
                if (strlen($tmp) > 0 && substr($tmp, 0, 1) == "/") $tmp = substr($tmp, 1);
 
                return $tmp;
-       }
+       }*/
 
        function get_upload_error_message($code) {