summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2018-12-12 07:57:37 +0300
committerAndrew Dolgov <[email protected]>2018-12-12 07:57:37 +0300
commiteda4ac2a2bb4bd96d06d0a2255dbc3d01cf16e31 (patch)
tree4849126854e9b818a3e2249df219f7f7f6dc7591
parentb6a021461d2ea54a91ce77c58591ad2ead35abdc (diff)
add fallback colors for headline feed titles based on feed name if favicon color is not available
-rwxr-xr-xclasses/feeds.php29
-rwxr-xr-xjs/Headlines.js4
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) {
</span>
<div class="feed">
- <a href="#" style="background-color: rgba(${hl.favicon_avg_color_rgba})"
+ <a href="#" style="background-color: ${hl.feed_bg_color}"
onclick="Feeds.open({feed:${hl.feed_id}})">${hl.feed_title}</a>
</div>
@@ -501,7 +501,7 @@ define(["dojo/_base/declare"], function (declare) {
</span>
</div>
<span class="feed">
- <a style="background : rgba(${hl.favicon_avg_color_rgba})" href="#" onclick="Feeds.open({feed:${hl.feed_id}})">${hl.feed_title}</a>
+ <a style="background : ${hl.feed_bg_color}" href="#" onclick="Feeds.open({feed:${hl.feed_id}})">${hl.feed_title}</a>
</span>
<div title="${hl.imported}">
<span class="updated">${hl.updated}</span>