add fallback colors for headline feed titles based on feed name if favicon color is not available

This commit is contained in:
Andrew Dolgov 2018-12-12 07:57:37 +03:00
parent b6a021461d
commit eda4ac2a2b
2 changed files with 26 additions and 7 deletions

View File

@ -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];
}
}

View File

@ -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>