From eda4ac2a2bb4bd96d06d0a2255dbc3d01cf16e31 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 12 Dec 2018 07:57:37 +0300 Subject: [PATCH] add fallback colors for headline feed titles based on feed name if favicon color is not available --- classes/feeds.php | 29 ++++++++++++++++++++++++----- js/Headlines.js | 4 ++-- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/classes/feeds.php b/classes/feeds.php index ed0789788..38819ec77 100755 --- a/classes/feeds.php +++ b/classes/feeds.php @@ -360,14 +360,18 @@ class Feeds extends Handler_Protected { require_once "colors.php"; - if ($fav_color && $fav_color != 'fail') { - if (!isset($rgba_cache[$feed_id])) { - $rgba_cache[$feed_id] = join(",", _color_unpack($fav_color)) . ",0.3"; + if (!isset($rgba_cache[$feed_id])) { + if ($fav_color && $fav_color != 'fail') { + $rgba_cache[$feed_id] = _color_unpack($fav_color); + } else { + $rgba_cache[$feed_id] = _color_unpack($this->color_of($line['feed_title'])); } - - $line['favicon_avg_color_rgba'] = $rgba_cache[$feed_id]; } + if (isset($rgba_cache[$feed_id])) { + $line['feed_bg_color'] = 'rgba(' . implode(",", $rgba_cache[$feed_id]) . ',0.3)'; + } + /* we don't need those */ foreach (["date_entered", "guid", "last_published", "last_marked", "tag_cache", "favicon_avg_color", @@ -1878,6 +1882,21 @@ class Feeds extends Handler_Protected { } + function color_of($name) { + $colormap = [ "#1cd7d7","#d91111","#1212d7","#8e16e5","#7b7b7b", + "#39f110","#0bbea6","#ec0e0e","#1534f2","#b9e416", + "#479af2","#f36b14","#10c7e9","#1e8fe7","#e22727" ]; + + $sum = 0; + + for ($i = 0; $i < strlen($name); $i++) { + $sum += ord($name{$i}); + } + + $sum %= count($colormap); + + return $colormap[$sum]; + } } diff --git a/js/Headlines.js b/js/Headlines.js index 364a9e748..1fd2efe25 100755 --- a/js/Headlines.js +++ b/js/Headlines.js @@ -442,7 +442,7 @@ define(["dojo/_base/declare"], function (declare) {
- ${hl.feed_title}
@@ -501,7 +501,7 @@ define(["dojo/_base/declare"], function (declare) { - ${hl.feed_title} + ${hl.feed_title}
${hl.updated}