From bc7a144dd589302025c3b024d6da71f2e53d6496 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 15 Apr 2013 18:22:48 +0400 Subject: [PATCH] properly remove and replace favicon color when favicon gets manually removed/uploaded --- classes/pref/feeds.php | 18 ++++++++++++++++-- include/colors.php | 2 +- include/rssfuncs.php | 13 ++++++------- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php index c57cccc44..c5d6245fe 100644 --- a/classes/pref/feeds.php +++ b/classes/pref/feeds.php @@ -464,6 +464,9 @@ class Pref_Feeds extends Handler_Protected { if (db_num_rows($result) != 0) { @unlink(ICONS_DIR . "/$feed_id.ico"); + + db_query($this->link, "UPDATE ttrss_feeds SET favicon_avg_color = NULL + where id = '$feed_id'"); } return; @@ -498,8 +501,19 @@ class Pref_Feeds extends Handler_Protected { if (db_num_rows($result) != 0) { @unlink(ICONS_DIR . "/$feed_id.ico"); - rename($icon_file, ICONS_DIR . "/$feed_id.ico"); - $rc = 0; + if (rename($icon_file, ICONS_DIR . "/$feed_id.ico")) { + + require_once "colors.php"; + + $favicon_color = db_escape_string($this->link, + calculate_avg_color(ICONS_DIR . "/$feed_id.ico")); + + db_query($this->link, "UPDATE ttrss_feeds SET + favicon_avg_color = '$favicon_color' + WHERE id = '$feed_id'"); + + $rc = 0; + } } else { $rc = 2; } diff --git a/include/colors.php b/include/colors.php index 19c891517..1359b9e2d 100644 --- a/include/colors.php +++ b/include/colors.php @@ -336,6 +336,6 @@ function hsl2rgb($arr) { } } } - return false; + return ''; } ?> diff --git a/include/rssfuncs.php b/include/rssfuncs.php index 250534bd7..283e48532 100644 --- a/include/rssfuncs.php +++ b/include/rssfuncs.php @@ -412,17 +412,16 @@ $favicon_file = ICONS_DIR . "/$feed.ico"; if (file_exists($favicon_file)) { - require_once "colors.php"; + require_once "colors.php"; - $favicon_color = db_escape_string($link, - calculate_avg_color($favicon_file)); + $favicon_color = db_escape_string($link, + calculate_avg_color($favicon_file)); - if ($debug_enabled) _debug("color: $favicon_color"); - - $favicon_colorstring = ",favicon_avg_color = '".$favicon_color."'"; + $favicon_colorstring = ",favicon_avg_color = '".$favicon_color."'"; } - db_query($link, "UPDATE ttrss_feeds SET favicon_last_checked = NOW() $favicon_colorstring + db_query($link, "UPDATE ttrss_feeds SET favicon_last_checked = NOW() + $favicon_colorstring WHERE id = '$feed'"); }