summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2017-05-04 15:00:21 +0300
committerAndrew Dolgov <[email protected]>2017-05-04 15:00:21 +0300
commita230bf88a9ce4589eeaf2d00226eafb78b4de01c (patch)
tree0f3656d2249c1de79162ed7e38a539292932f7c4 /include
parent86a8351ca2abbacda557819cefb66379a450103c (diff)
move to Article:
+ 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) {
Diffstat (limited to 'include')
-rw-r--r--include/functions.php118
-rw-r--r--include/functions2.php4
-rw-r--r--include/rssfuncs.php54
3 files changed, 59 insertions, 117 deletions
diff --git a/include/functions.php b/include/functions.php
index 17c3d8c4b..d5a75843f 100644
--- a/include/functions.php
+++ b/include/functions.php
@@ -305,19 +305,7 @@
}
}
- 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'");
@@ -334,7 +322,7 @@
} 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,
@@ -578,57 +566,6 @@
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);
@@ -1105,26 +1042,6 @@
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();
@@ -1147,7 +1064,7 @@
$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;
}
@@ -1172,38 +1089,11 @@
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",
diff --git a/include/functions2.php b/include/functions2.php
index 7ebf4a0cf..a47e9c463 100644
--- a/include/functions2.php
+++ b/include/functions2.php
@@ -506,7 +506,7 @@
$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 ";
@@ -670,7 +670,7 @@
$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
diff --git a/include/rssfuncs.php b/include/rssfuncs.php
index 4fdd2843f..bb8127547 100644
--- a/include/rssfuncs.php
+++ b/include/rssfuncs.php
@@ -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 = "";
@@ -1513,7 +1515,7 @@
$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);
@@ -1522,3 +1524,53 @@
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;
+ }
+ }