/
wallpaper.php
76 lines (68 loc) · 2.38 KB
/
wallpaper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
/*
5 = default, server room
6 = cloud daily image
7 = color picker
8 = user uploaded
*/
// defaults
$background=5;
$backgroundBlur=2; // 2 = disabled, 1 = enabled
$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]);
} elseif (trim($tmp[0]) == 'backgroundBlur') {
$backgroundBlur=trim($tmp[1]);
}
}
}
// 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;
if ($backgroundBlur == 1) {
$bluramt = 15;
echo "<style>div.backstretch { -webkit-filter: blur(" . $bluramt . "px); -moz-filter: blur(" . $bluramt . "px); -o-filter: blur(" . $bluramt . "px); -ms-filter: blur(" . $bluramt . "px); filter: blur(" . $bluramt . "px); margin: -" . ($bluramt*2) . "px; }</style>";
}
?>