Skip to content
Permalink
Browse files

Add daily color

  • Loading branch information...
NEMS Linux
NEMS Linux committed Feb 25, 2019
1 parent 90abc0a commit d088aae036eefbc7c596b4bc1bab72416b114614
Showing with 39 additions and 0 deletions.
  1. +1 −0 config/index.php
  2. +38 −0 inc/wallpaper.php
@@ -307,6 +307,7 @@ function sanitize($string) {
<label class="select">
<select name="background" id="background">
<option value="6"<?php if (!isset($nemsconf['background']) || $nemsconf['background'] == 6) echo ' SELECTED'; ?>>Daily Image (Default)</option>
<option value="9"<?php if (isset($nemsconf['background']) && $nemsconf['background'] == 9) echo ' SELECTED'; ?>>Daily Color</option>
<option value="5"<?php if (isset($nemsconf['background']) && $nemsconf['background'] == 5) echo ' SELECTED'; ?>>NEMS Legacy</option>
<option value="7"<?php if (isset($nemsconf['background']) && $nemsconf['background'] == 7) echo ' SELECTED'; ?>>Custom Color</option>
<option value="8"<?php if (isset($nemsconf['background']) && $nemsconf['background'] == 8) echo ' SELECTED'; ?>>Upload Image</option>
@@ -33,6 +33,10 @@
// default image within nems-www
$defaultimg = '/img/wallpaper/server_room_dark.jpg';
// default background color
$defaultbgcolor = '040111';
// Set the default background element to replace
if (!isset($backgroundElem)) $backgroundElem = 'body';
@@ -61,6 +65,40 @@
";
break;
case 9:
$key = strtotime('today');
// caches the response each day
$cachefile = '/tmp/bgcolor-' . $key;
if (file_exists($cachefile)) {
$result = trim(file_get_contents($cachefile));
} else {
$json_url = 'https://cloud.nemslinux.com/bgcolor/' . $key . '.json';
$ch = curl_init( $json_url );
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array('Content-type: application/json') ,
);
curl_setopt_array( $ch, $options );
$result = curl_exec($ch);
file_put_contents($cachefile,$result);
}
$resultobj = json_decode($result);
if (isset($resultobj->$key)) {
$bgcolor = $resultobj->$key;
} else {
$bgcolor = $defaultbgcolor;
}
list($rgb[0], $rgb[1], $rgb[2]) = sscanf($bgcolor, "%02x%02x%02x");
$rgb['html'] = sprintf('#%02X%02X%02X', $rgb[0], $rgb[1], $rgb[2]);
$vDark = ($v-40);
if ($vDark < 1) $vDark = 1;
$rgbDark=hsv2rgb($h,$s,$vDark);
$output = "
<style>$backgroundElem { background-image: radial-gradient(" . $rgb['html'] . "," . $rgbDark['html'] . "); }</style>
";
break;
case 6:
$key = strtotime('today');
// caches the response each day

0 comments on commit d088aae

Please sign in to comment.
You can’t perform that action at this time.