]> git.wh0rd.org Git - tt-rss.git/commitdiff
move to Article:
authorAndrew Dolgov <noreply@madoka.volgo-balt.ru>
Thu, 4 May 2017 12:00:21 +0000 (15:00 +0300)
committerAndrew Dolgov <noreply@madoka.volgo-balt.ru>
Thu, 4 May 2017 12:00:21 +0000 (15:00 +0300)
+       static function purge_orphans($do_output = false) {

move to Feeds

+       static function getGlobalUnread($user_id = false) {
+       static function getCategoryTitle($cat_id) {
+       static function getLabelUnread($label_id, $owner_uid = false) {

classes/api.php
classes/article.php
classes/feeds.php
classes/handler/public.php
classes/pref/feeds.php
classes/pref/filters.php
classes/rpc.php
include/functions.php
include/functions2.php
include/rssfuncs.php

index ad3ccea09d34e2ab7ee57c172f5a6660acf809e1..2dee790b3b6eba4e9fe9c75e2d5598de8925805a 100644 (file)
@@ -101,7 +101,7 @@ class API extends Handler {
                if ($feed_id) {
                        $this->wrap(self::STATUS_OK, array("unread" => getFeedUnread($feed_id, $is_cat)));
                } else {
-                       $this->wrap(self::STATUS_OK, array("unread" => getGlobalUnread()));
+                       $this->wrap(self::STATUS_OK, array("unread" => Feeds::getGlobalUnread()));
                }
        }
 
@@ -170,7 +170,7 @@ class API extends Handler {
 
                                if ($unread || !$unread_only) {
                                        array_push($cats, array("id" => $cat_id,
-                                               "title" => getCategoryTitle($cat_id),
+                                               "title" => Feeds::getCategoryTitle($cat_id),
                                                "unread" => $unread));
                                }
                        }
index e0c8d3e6d1d69afec6e734bff3ad8f6be3a8f412..64c04e140e251aca402cc95152266823b9e946ef 100644 (file)
@@ -864,4 +864,17 @@ class Article extends Handler_Protected {
                return $rv;
        }
 
+       static function purge_orphans($do_output = false) {
+
+               // purge orphaned posts in main content table
+               $result = db_query("DELETE FROM ttrss_entries WHERE
+                       NOT EXISTS (SELECT ref_id FROM ttrss_user_entries WHERE ref_id = id)");
+
+               if ($do_output) {
+                       $rows = db_affected_rows($result);
+                       _debug("Purged $rows orphaned posts.");
+               }
+       }
+
+
 }
index 2b99a2823e9597dbe1206cfce4748c0ac4c0d3b0..8f57f059ea1bac6168a627ff673d5959f0246037 100755 (executable)
@@ -1445,7 +1445,7 @@ class Feeds extends Handler_Protected {
 
                        $label_id = feed_to_label_id($feed);
 
-                       return getLabelUnread($label_id, $owner_uid);
+                       return Feeds::getLabelUnread($label_id, $owner_uid);
 
                }
 
@@ -1602,7 +1602,7 @@ class Feeds extends Handler_Protected {
 
        static function getFeedTitle($id, $cat = false) {
                if ($cat) {
-                       return getCategoryTitle($id);
+                       return Feeds::getCategoryTitle($id);
                } else if ($id == -1) {
                        return __("Starred articles");
                } else if ($id == -2) {
@@ -1707,5 +1707,51 @@ class Feeds extends Handler_Protected {
                return $unread;
        }
 
+       static function getGlobalUnread($user_id = false) {
+
+               if (!$user_id) {
+                       $user_id = $_SESSION["uid"];
+               }
+
+               $result = db_query("SELECT SUM(value) AS c_id FROM ttrss_counters_cache
+                       WHERE owner_uid = '$user_id' AND feed_id > 0");
+
+               $c_id = db_fetch_result($result, 0, "c_id");
+
+               return $c_id;
+       }
+
+       static function getCategoryTitle($cat_id) {
+
+               if ($cat_id == -1) {
+                       return __("Special");
+               } else if ($cat_id == -2) {
+                       return __("Labels");
+               } else {
+
+                       $result = db_query("SELECT title FROM ttrss_feed_categories WHERE
+                               id = '$cat_id'");
+
+                       if (db_num_rows($result) == 1) {
+                               return db_fetch_result($result, 0, "title");
+                       } else {
+                               return __("Uncategorized");
+                       }
+               }
+       }
+
+       static function getLabelUnread($label_id, $owner_uid = false) {
+               if (!$owner_uid) $owner_uid = $_SESSION["uid"];
+
+               $result = db_query("SELECT COUNT(ref_id) AS unread FROM ttrss_user_entries, ttrss_user_labels2
+                       WHERE owner_uid = '$owner_uid' AND unread = true AND label_id = '$label_id' AND article_id = ref_id");
+
+               if (db_num_rows($result) != 0) {
+                       return db_fetch_result($result, 0, "unread");
+               } else {
+                       return 0;
+               }
+       }
+
 }
 
index 89d481ec54c6357e2e64a34510f44551ef4b9b46..0f1ae21ebc4adc6e586bf417598087b177ae8319 100644 (file)
@@ -287,7 +287,7 @@ class Handler_Public extends Handler {
                if ($this->dbh->num_rows($result) == 1) {
                        $uid = $this->dbh->fetch_result($result, 0, "id");
 
-                       print getGlobalUnread($uid);
+                       print Feeds::getGlobalUnread($uid);
 
                        if ($fresh) {
                                print ";";
index 4dbc07a9fe4b3f2d638b82099571ae4971819ec8..f3df0297d41d5238dba67325f31512b1d739675c 100755 (executable)
@@ -1542,7 +1542,7 @@ class Pref_Feeds extends Handler_Protected {
 
                $obj['id'] = 'CAT:' . $cat_id;
                $obj['items'] = array();
-               $obj['name'] = getCategoryTitle($cat_id);
+               $obj['name'] = Feeds::getCategoryTitle($cat_id);
                $obj['type'] = 'category';
                $obj['unread'] = (int) $cat_unread;
                $obj['bare_id'] = $cat_id;
index 924588899b7371a3e770ba94d771535477928ee4..e4943a5a5919f61cb2892e8e0813afdd4503d9b7 100755 (executable)
@@ -224,7 +224,7 @@ class Pref_Filters extends Handler_Protected {
                while ($line = $this->dbh->fetch_assoc($result)) {
 
                        $where = sql_bool_to_bool($line["cat_filter"]) ?
-                               getCategoryTitle($line["cat_id"]) :
+                               Feeds::getCategoryTitle($line["cat_id"]) :
                                ($line["feed_id"] ?
                                        Feeds::getFeedTitle($line["feed_id"]) : __("All feeds"));
 
@@ -497,7 +497,7 @@ class Pref_Filters extends Handler_Protected {
 
                if (strpos($feed_id, "CAT:") === 0) {
                        $feed_id = (int) substr($feed_id, 4);
-                       $feed = getCategoryTitle($feed_id);
+                       $feed = Feeds::getCategoryTitle($feed_id);
                } else {
                        $feed_id = (int) $feed_id;
 
index f82f1ef32e4724fa43dadf29d85d6d378268525d..949a6177aad001f85cd6815b4861548150929ed9 100755 (executable)
@@ -151,7 +151,7 @@ class RPC extends Handler_Protected {
                $this->dbh->query("DELETE FROM ttrss_user_entries
                        WHERE ref_id IN ($ids) AND owner_uid = " . $_SESSION["uid"]);
 
-               purge_orphans();
+               Article::purge_orphans();
 
                print json_encode(array("message" => "UPDATE_COUNTERS"));
        }
@@ -556,7 +556,7 @@ class RPC extends Handler_Protected {
                }
 
                // Purge orphans and cleanup tags
-               purge_orphans();
+               Article::purge_orphans();
                //cleanup_tags(14, 50000);
 
                if ($num_updated > 0) {
index 17c3d8c4b397b9cbdaeea109d8a8bdb4b44e8ca8..d5a75843f10d86200b33f7e2676fb4ef39d31dfa 100644 (file)
                }
        }
 
-       function purge_orphans($do_output = false) {
-
-               // purge orphaned posts in main content table
-               $result = db_query("DELETE FROM ttrss_entries WHERE
-                       NOT EXISTS (SELECT ref_id FROM ttrss_user_entries WHERE ref_id = id)");
-
-               if ($do_output) {
-                       $rows = db_affected_rows($result);
-                       _debug("Purged $rows orphaned posts.");
-               }
-       }
-
-       function get_feed_update_interval($feed_id) {
+       /*function get_feed_update_interval($feed_id) {
                $result = db_query("SELECT owner_uid, update_interval FROM
                        ttrss_feeds WHERE id = '$feed_id'");
 
                } else {
                        return -1;
                }
-       }
+       }*/
 
        // TODO: multiple-argument way is deprecated, first parameter is a hash now
        function fetch_file_contents($options /* previously: 0: $url , 1: $type = false, 2: $login = false, 3: $pass = false,
                return $favicon_url;
        } // function get_favicon_url
 
-       function check_feed_favicon($site_url, $feed) {
-#              print "FAVICON [$site_url]: $favicon_url\n";
-
-               $icon_file = ICONS_DIR . "/$feed.ico";
-
-               if (!file_exists($icon_file)) {
-                       $favicon_url = get_favicon_url($site_url);
-
-                       if ($favicon_url) {
-                               // Limiting to "image" type misses those served with text/plain
-                               $contents = fetch_file_contents($favicon_url); // , "image");
-
-                               if ($contents) {
-                                       // Crude image type matching.
-                                       // Patterns gleaned from the file(1) source code.
-                                       if (preg_match('/^\x00\x00\x01\x00/', $contents)) {
-                                               // 0       string  \000\000\001\000        MS Windows icon resource
-                                               //error_log("check_feed_favicon: favicon_url=$favicon_url isa MS Windows icon resource");
-                                       }
-                                       elseif (preg_match('/^GIF8/', $contents)) {
-                                               // 0       string          GIF8            GIF image data
-                                               //error_log("check_feed_favicon: favicon_url=$favicon_url isa GIF image");
-                                       }
-                                       elseif (preg_match('/^\x89PNG\x0d\x0a\x1a\x0a/', $contents)) {
-                                               // 0       string          \x89PNG\x0d\x0a\x1a\x0a         PNG image data
-                                               //error_log("check_feed_favicon: favicon_url=$favicon_url isa PNG image");
-                                       }
-                                       elseif (preg_match('/^\xff\xd8/', $contents)) {
-                                               // 0       beshort         0xffd8          JPEG image data
-                                               //error_log("check_feed_favicon: favicon_url=$favicon_url isa JPG image");
-                                       }
-                                       else {
-                                               //error_log("check_feed_favicon: favicon_url=$favicon_url isa UNKNOWN type");
-                                               $contents = "";
-                                       }
-                               }
-
-                               if ($contents) {
-                                       $fp = @fopen($icon_file, "w");
-
-                                       if ($fp) {
-                                               fwrite($fp, $contents);
-                                               fclose($fp);
-                                               chmod($icon_file, 0644);
-                                       }
-                               }
-                       }
-            return $icon_file;
-               }
-       }
-
        function initialize_user_prefs($uid, $profile = false) {
 
                $uid = db_escape_string($uid);
                return $data;
        }
 
-       function getCategoryTitle($cat_id) {
-
-               if ($cat_id == -1) {
-                       return __("Special");
-               } else if ($cat_id == -2) {
-                       return __("Labels");
-               } else {
-
-                       $result = db_query("SELECT title FROM ttrss_feed_categories WHERE
-                               id = '$cat_id'");
-
-                       if (db_num_rows($result) == 1) {
-                               return db_fetch_result($result, 0, "title");
-                       } else {
-                               return __("Uncategorized");
-                       }
-               }
-       }
-
-
        function getCategoryCounters() {
                $ret_arr = array();
 
                        $line["cat_id"] = (int) $line["cat_id"];
 
                        if ($line["num_children"] > 0) {
-                               $child_counter = getCategoryChildrenUnread($line["cat_id"], $_SESSION["uid"]);
+                               $child_counter = Feeds::getCategoryChildrenUnread($line["cat_id"], $_SESSION["uid"]);
                        } else {
                                $child_counter = 0;
                        }
                return Feeds::getFeedArticles($feed, $is_cat, true, $_SESSION["uid"]);
        }
 
-       function getLabelUnread($label_id, $owner_uid = false) {
-               if (!$owner_uid) $owner_uid = $_SESSION["uid"];
-
-               $result = db_query("SELECT COUNT(ref_id) AS unread FROM ttrss_user_entries, ttrss_user_labels2
-                       WHERE owner_uid = '$owner_uid' AND unread = true AND label_id = '$label_id' AND article_id = ref_id");
-
-               if (db_num_rows($result) != 0) {
-                       return db_fetch_result($result, 0, "unread");
-               } else {
-                       return 0;
-               }
-       }
-
-       function getGlobalUnread($user_id = false) {
-
-               if (!$user_id) {
-                       $user_id = $_SESSION["uid"];
-               }
-
-               $result = db_query("SELECT SUM(value) AS c_id FROM ttrss_counters_cache
-                       WHERE owner_uid = '$user_id' AND feed_id > 0");
-
-               $c_id = db_fetch_result($result, 0, "c_id");
-
-               return $c_id;
-       }
-
        function getGlobalCounters($global_unread = -1) {
                $ret_arr = array();
 
                if ($global_unread == -1) {
-                       $global_unread = getGlobalUnread();
+                       $global_unread = Feeds::getGlobalUnread();
                }
 
                $cv = array("id" => "global-unread",
index 7ebf4a0cfe92a09df35e9a5078c2a44687f1380e..a47e9c46390d23029c91a1ac37716642e1df6afd 100644 (file)
                                        $unread = getFeedUnread($feed, $cat_view);
 
                                        if ($cat_view && $feed > 0 && $include_children)
-                                               $unread += getCategoryChildrenUnread($feed);
+                                               $unread += Feeds::getCategoryChildrenUnread($feed);
 
                                        if ($unread > 0) {
                                                $view_query_part = " unread = true AND ";
                                $feed_title = T_sprintf("Search results: %s", $search);
                        } else {
                                if ($cat_view) {
-                                       $feed_title = getCategoryTitle($feed);
+                                       $feed_title = Feeds::getCategoryTitle($feed);
                                } else {
                                        if (is_numeric($feed) && $feed > 0) {
                                                $result = db_query("SELECT title,site_url,last_error,last_updated
index 4fdd2843fbcda78c3c9d379299c8beb10188fae1..bb812754725c645424efc7745d74742c3d766f05 100644 (file)
@@ -4,6 +4,8 @@
        define_default('DAEMON_SLEEP_INTERVAL', 120);
        define_default('_MIN_CACHE_FILE_SIZE', 1024);
 
+       // TODO: this needs to be removed from global namespace into classes/RSS.php or something
+
        function calculate_article_hash($article, $pluginhost) {
                $tmp = "";
 
                $count = update_feedbrowser_cache();
                _debug("Feedbrowser updated, $count feeds processed.");
 
-               purge_orphans( true);
+               Article::purge_orphans( true);
                cleanup_counters_cache($debug);
 
                //$rc = cleanup_tags( 14, 50000);
                PluginHost::getInstance()->run_hooks(PluginHost::HOOK_HOUSE_KEEPING, "hook_house_keeping", "");
        }
 
+       function check_feed_favicon($site_url, $feed) {
+       #               print "FAVICON [$site_url]: $favicon_url\n";
+
+               $icon_file = ICONS_DIR . "/$feed.ico";
+
+               if (!file_exists($icon_file)) {
+                       $favicon_url = get_favicon_url($site_url);
+
+                       if ($favicon_url) {
+                               // Limiting to "image" type misses those served with text/plain
+                               $contents = fetch_file_contents($favicon_url); // , "image");
+
+                               if ($contents) {
+                                       // Crude image type matching.
+                                       // Patterns gleaned from the file(1) source code.
+                                       if (preg_match('/^\x00\x00\x01\x00/', $contents)) {
+                                               // 0       string  \000\000\001\000        MS Windows icon resource
+                                               //error_log("check_feed_favicon: favicon_url=$favicon_url isa MS Windows icon resource");
+                                       }
+                                       elseif (preg_match('/^GIF8/', $contents)) {
+                                               // 0       string          GIF8            GIF image data
+                                               //error_log("check_feed_favicon: favicon_url=$favicon_url isa GIF image");
+                                       }
+                                       elseif (preg_match('/^\x89PNG\x0d\x0a\x1a\x0a/', $contents)) {
+                                               // 0       string          \x89PNG\x0d\x0a\x1a\x0a         PNG image data
+                                               //error_log("check_feed_favicon: favicon_url=$favicon_url isa PNG image");
+                                       }
+                                       elseif (preg_match('/^\xff\xd8/', $contents)) {
+                                               // 0       beshort         0xffd8          JPEG image data
+                                               //error_log("check_feed_favicon: favicon_url=$favicon_url isa JPG image");
+                                       }
+                                       else {
+                                               //error_log("check_feed_favicon: favicon_url=$favicon_url isa UNKNOWN type");
+                                               $contents = "";
+                                       }
+                               }
+
+                               if ($contents) {
+                                       $fp = @fopen($icon_file, "w");
+
+                                       if ($fp) {
+                                               fwrite($fp, $contents);
+                                               fclose($fp);
+                                               chmod($icon_file, 0644);
+                                       }
+                               }
+                       }
+                       return $icon_file;
+               }
+       }