Permalink
Browse files

Add daily wallpaper functionality

  • Loading branch information...
NEMS Linux
NEMS Linux committed Dec 28, 2018
1 parent f7fc76a commit f5945689ee534f40b4165994dc8202352a80457b
Showing with 135 additions and 13 deletions.
  1. +0 −1 changelog.txt
  2. +58 −0 config/index.php
  3. +4 −8 inc/footer.php
  4. +68 −0 inc/wallpaper.php
  5. +5 −4 tv/index.php

This file was deleted.

Oops, something went wrong.
@@ -111,6 +111,7 @@
$nemsconf['webhook'] = sanitize($_POST['webhook']);
$nemsconf['alias'] = preg_replace("/&#?[a-z0-9]{2,8};/i","",sanitize($_POST['alias']));
$nemsconf['allowupdate'] = intval($_POST['allowupdate']) ?: 5;
$nemsconf['background'] = intval($_POST['background']) ?: 5;
$nemsconf['checkin.enabled'] = intval($_POST['checkin_enabled']) ?: 0;
$nemsconf['checkin.email'] = filter_var(trim($_POST['checkin_email']), FILTER_VALIDATE_EMAIL) ?: '';
$nemsconf['checkin.interval'] = intval($_POST['checkin_interval']) ?: 8; // how many 15 minute cycles before notifying. Default 8 (2 hours).
@@ -233,6 +234,20 @@ function sanitize($string) {
</label>
</section>
<?php } ?>
<?php if (ver('nems') >= 1.5) { ?>
<section>
<label class="label">Background Image</label>
<label class="select">
<select name="background">
<option value="5"<?php if (!isset($nemsconf['background']) || $nemsconf['background'] == 5) echo ' SELECTED'; ?>>Default</option>
<option value="6"<?php if (isset($nemsconf['background']) && $nemsconf['background'] == 6) echo ' SELECTED'; ?>>Daily Image</option>
<option value="7"<?php if (isset($nemsconf['background']) && $nemsconf['background'] == 7) echo ' SELECTED'; ?>>Color Picker</option>
<option value="8"<?php if (isset($nemsconf['background']) && $nemsconf['background'] == 8) echo ' SELECTED'; ?>>Upload Image</option>
</select>
<i></i>
</label>
</section>
<?php } ?>
<?php
if (ver('nems') >= 1.4 && $disabled == 1) {
$wifi = json_decode(trim(shell_exec('/usr/local/bin/nems-info wifi')));
@@ -627,4 +642,47 @@ function sanitize($string) {
</div>
<?php
include('/var/www/html/inc/footer.php');
// https://stackoverflow.com/questions/1773698/rgb-to-hsv-in-php
function RGB_TO_HSV ($R, $G, $B) // RGB Values:Number 0-255
{ // HSV Results:Number 0-1
$HSL = array();
$var_R = ($R / 255);
$var_G = ($G / 255);
$var_B = ($B / 255);
$var_Min = min($var_R, $var_G, $var_B);
$var_Max = max($var_R, $var_G, $var_B);
$del_Max = $var_Max - $var_Min;
$V = $var_Max;
if ($del_Max == 0)
{
$H = 0;
$S = 0;
}
else
{
$S = $del_Max / $var_Max;
$del_R = ( ( ( $var_Max - $var_R ) / 6 ) + ( $del_Max / 2 ) ) / $del_Max;
$del_G = ( ( ( $var_Max - $var_G ) / 6 ) + ( $del_Max / 2 ) ) / $del_Max;
$del_B = ( ( ( $var_Max - $var_B ) / 6 ) + ( $del_Max / 2 ) ) / $del_Max;
if ($var_R == $var_Max) $H = $del_B - $del_G;
else if ($var_G == $var_Max) $H = ( 1 / 3 ) + $del_R - $del_B;
else if ($var_B == $var_Max) $H = ( 2 / 3 ) + $del_G - $del_R;
if ($H<0) $H++;
if ($H>1) $H--;
}
$HSL['H'] = $H;
$HSL['S'] = $S;
$HSL['V'] = $V;
return $HSL;
}
?>
@@ -88,16 +88,12 @@
LoginForm.initLoginForm();
ContactForm.initContactForm();
OwlCarousel.initOwlCarousel();
$(".fullscreen-static-image").backstretch([
"/img/wallpaper/server_room_dark.jpg",
"/monitorix/img/system1z.1day.png",
"/monitorix/img/net01z.1day.png",
"/monitorix/img/apache01z.1day.png"
], {duration: 10000,transition: 'fade',speed: '1000'});
});
</script>
<?php
$backgroundElem = '.fullscreen-static-image';
require_once('/var/www/html/inc/wallpaper.php');
?>
<!--[if lt IE 9]>
<script src="https://cdn.zecheriah.com/site-assets/1.9.6/One-Pages/Classic/assets/plugins/respond.js"></script>
<script src="https://cdn.zecheriah.com/site-assets/1.9.6/One-Pages/Classic/assets/plugins/html5shiv.js"></script>
@@ -0,0 +1,68 @@
<?php
/*
5 = default, server room
6 = cloud daily image
7 = color picker
8 = user uploaded
*/
$conftmp = file('/usr/local/share/nems/nems.conf');
if (is_array($conftmp) && count($conftmp) > 0) {
foreach ($conftmp as $line) {
$tmp = explode('=',$line);
if (trim($tmp[0]) == 'background') {
$background=trim($tmp[1]);
break;
} else {
$background=5;
}
}
}
// default image within nems-www
$defaultimg = '/img/wallpaper/server_room_dark.jpg';
// Set the default background element to replace
if (!isset($backgroundElem)) $backgroundElem = 'body';
switch ($background) {
case 6:
$key = strtotime('today');
// caches the response each day
if (file_exists('/tmp/wallpaper-' . $key)) {
$result = trim(file_get_contents('/tmp/wallpaper-' . $key));
} else {
$json_url = 'https://cloud.nemslinux.com/wallpaper/' . $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('/tmp/wallpaper-' . $key,$result);
}
$resultobj = json_decode($result);
if (isset($resultobj->$key)) {
$img = $resultobj->$key;
} else {
$img = $defaultimg;
}
$output = "<script>jQuery(document).ready(function() {
$('" . $backgroundElem . "').backstretch([
'" . $img . "',
], {duration: 10000,transition: 'fade',speed: '1000'});
});</script>";
break;
case 5:
default:
$output = "<script>jQuery(document).ready(function() {
$('" . $backgroundElem . "').backstretch([
'" . $defaultimg . "',
], {duration: 10000,transition: 'fade',speed: '1000'});
});</script>";
}
echo $output;
?>
@@ -97,13 +97,14 @@ function updateCountDown(){

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-backstretch/2.0.4/jquery.backstretch.min.js"></script>

<?php
$backgroundElem = 'body';
require_once('/var/www/html/inc/wallpaper.php');
?>

<script>
jQuery(document).ready(function() {
$("body").backstretch([
"/img/wallpaper/server_room_dark.jpg",
], {duration: 10000,transition: 'fade',speed: '1000'});
$(function() {
var timer;
var fadeInBuffer = false;

0 comments on commit f594568

Please sign in to comment.