register_shutdown_function('shutdown');
-function runAtEnd($code)
-{
- global $endQueue;
- $endQueue[] = $code;
+function runAtEnd($code) {
+ global $endQueue;
+ $endQueue[] = $code;
}
-function shutdown()
-{
- global $endQueue;
- returnHttpResponse();
- foreach ($endQueue as $code) {
- eval($code);
- }
+function shutdown() {
+ global $endQueue;
+ returnHttpResponse();
+ foreach ($endQueue as $code) {
+ eval($code);
+ }
}
-function getCurrentConfig()
-{
- global $forceConfig;
+function getCurrentConfig() {
+ global $forceConfig;
- $ips = ['192.168.13.31' => 'cuisine', '192.168.13.30' => 'salon', '192.168.13.32' => 'sdb'];
+ $ips = ['192.168.13.31' => 'cuisine', '192.168.13.30' => 'salon', '192.168.13.32' => 'sdb'];
- if (!isset($forceConfig) && isset($_SERVER['HTTP_HOST']) && stristr($_SERVER['HTTP_HOST'], '.home.tortuga.enhydra.fr')) {
- $e = explode('.', $_SERVER['HTTP_HOST']);
- $_GET['c'] = array_shift($e);
- }
+ if (!isset($forceConfig) && isset($_SERVER['HTTP_HOST']) && stristr($_SERVER['HTTP_HOST'], '.home.tortuga.enhydra.fr')) {
+ $e = explode('.', $_SERVER['HTTP_HOST']);
+ $_GET['c'] = array_shift($e);
+ }
- if (isset($forceConfig)) {
- $_GET['c'] = $forceConfig;
- }
+ if (isset($forceConfig)) {
+ $_GET['c'] = $forceConfig;
+ }
- $expires = time() + 60 * 60 * 24 * 30;
- if (isset($_GET['c'])) {
- $_SESSION['homeconfig'] = $_GET['c'];
- }
+ $expires = time() + 60 * 60 * 24 * 30;
+ if (isset($_GET['c'])) {
+ $_SESSION['homeconfig'] = $_GET['c'];
+ }
- if (!isset($_SESSION['homeconfig'])) {
- if (isset($_SERVER['HTTP_X_REAL_IP']) && isset($ips[$_SERVER['HTTP_X_REAL_IP']])) {
- $c = $ips[$_SERVER['HTTP_X_REAL_IP']];
- } else {
- $c = 'salon';
- }
- $_SESSION['homeconfig'] = $c;
- }
- return $_SESSION['homeconfig'];
+ if (!isset($_SESSION['homeconfig'])) {
+ if (isset($_SERVER['HTTP_X_REAL_IP']) && isset($ips[$_SERVER['HTTP_X_REAL_IP']])) {
+ $c = $ips[$_SERVER['HTTP_X_REAL_IP']];
+ } else {
+ $c = 'salon';
+ }
+ $_SESSION['homeconfig'] = $c;
+ }
+ return $_SESSION['homeconfig'];
}
-function config($key = null, $value = null)
-{
- global $config;
- if (!isset($config)) {
- $config = ['SLEEPSCREEN' => 0, 'MUSICPLAYER' => 'squeezebox', 'SLEEPTYPE' => 'off', 'DEVICE' => getCurrentConfig(), 'VOLUME_DEVICE' => 'auto'];
- }
- if (null == $key) {
- return $config;
- }
- if (null == $value && isset($config[$key])) {
- return $config[$key];
- }
- $config[$key] = $value;
- return $config[$key];
+function config($key = null, $value = null) {
+ global $config;
+ if (!isset($config)) {
+ $config = ['SLEEPSCREEN' => 0, 'MUSICPLAYER' => 'squeezebox', 'SLEEPTYPE' => 'off', 'DEVICE' => getCurrentConfig(), 'VOLUME_DEVICE' => 'auto'];
+ }
+ if (null == $key) {
+ return $config;
+ }
+ if (null == $value && isset($config[$key])) {
+ return $config[$key];
+ }
+ $config[$key] = $value;
+ return $config[$key];
}
-function hasConfig($key)
-{
- global $config;
- return isset($config[$key]);
+function hasConfig($key) {
+ global $config;
+ return isset($config[$key]);
}
-function getLinkHash($s)
-{
- return sha1(json_encode($s));
+function getLinkHash($s) {
+ return sha1(json_encode($s));
}
-function accordionClosed($accordionId)
-{
- return getState($accordionId, '0') == '0';
+function accordionClosed($accordionId) {
+ return getState($accordionId, '0') == '0';
}
-function shortcutDir($allshortcuts)
-{
- $res = array();
- $hashs = array();
- if (!is_array($allshortcuts)) {
- $allshortcuts = array();
- }
-
-
- foreach ($allshortcuts as $name => $shortcuts) {
- $cols = strpos($name, 'remote') !== 0;
-
- $size = '';
- if (isset($shortcuts['size'])) {
- $size = ' data-size="' . $shortcuts['size'] . '"';
- unset($shortcuts['size']);
- }
-
- $section = '<section ' . $size . ' data-section="' . $name . '">';
- $fit = ($name == 'remote-default');
- $i = 0;
- if ($fit) {
- $section .= '<div class="fit">';
- }
- foreach ($shortcuts as $k => $s) {
- if ($s['type'] == 'clear' || $s['type'] == 'accordion' || $s['type'] == 'accordion-end') {
- if ($i % 2 == 1) {
- $section .= '</div>';
- $i = 0;
- }
-
- if ($s['type'] === 'clear') {
- $section .= '<div class="clearcol"></div>';
- } else if ($s['type'] === 'accordion') {
- $section .= '<accordion id="' . $s['id'] . '" class="accordion ' . (isset($s['closed']) && $s['closed'] ? 'closed' : '') . '"><a><span>' . $s['label'] . '</span></a>';
- } else if ($s['type'] === 'accordion-end') {
- $section .= '</accordion>';
- }
-
- continue;
- }
- $size = '';
- if (isset($s['size'])) {
- $size = ' data-size="' . $s['size'] . '"';
- }
- if ($cols && $i % 2 == 0) {
- $section .= '<div class="col" ' . $size . '>';
- }
-
- $hash = getLinkHash($s);
- $shortcut = shortcut($s, $hash);
- $section .= $shortcut;
- $hashs[$hash] = $shortcut;
-
- $i++;
- if ($cols && $i % 2 == 0) {
- $section .= '</div>';
- }
- }
- if ($cols && $i % 2 == 1) {
- $section .= '</div>';
- }
- if ($fit) {
- $section .= '</div>';
- }
- $section .= '</section>';
- $res[$name] = $section;
- }
-
- $json = json_encode($res);
-
- connectRedis()->igbset('shortcuts.' . getCurrentConfig(), $json);
- profile('save cache shortcuts', __FILE__, __LINE__);
-
- return 'SECTIONS = ' . $json . ';';
+function shortcutDir($allshortcuts) {
+ $res = array();
+ $hashs = array();
+ if (!is_array($allshortcuts)) {
+ $allshortcuts = array();
+ }
+
+
+ foreach ($allshortcuts as $name => $shortcuts) {
+ $cols = strpos($name, 'remote') !== 0;
+
+ $size = '';
+ if (isset($shortcuts['size'])) {
+ $size = ' data-size="' . $shortcuts['size'] . '"';
+ unset($shortcuts['size']);
+ }
+
+ $section = '<section ' . $size . ' data-section="' . $name . '">';
+ $fit = ($name == 'remote-default');
+ $i = 0;
+ if ($fit) {
+ $section .= '<div class="fit">';
+ }
+ foreach ($shortcuts as $k => $s) {
+ if ($s['type'] == 'clear' || $s['type'] == 'accordion' || $s['type'] == 'accordion-end') {
+ if ($i % 2 == 1) {
+ $section .= '</div>';
+ $i = 0;
+ }
+
+ if ($s['type'] === 'clear') {
+ $section .= '<div class="clearcol"></div>';
+ } else if ($s['type'] === 'accordion') {
+ $section .= '<accordion id="' . $s['id'] . '" class="accordion ' . (isset($s['closed']) && $s['closed'] ? 'closed' : '') . '"><a><span>' . $s['label'] . '</span></a>';
+ } else if ($s['type'] === 'accordion-end') {
+ $section .= '</accordion>';
+ }
+
+ continue;
+ }
+ $size = '';
+ if (isset($s['size'])) {
+ $size = ' data-size="' . $s['size'] . '"';
+ }
+ if ($cols && $i % 2 == 0) {
+ $section .= '<div class="col" ' . $size . '>';
+ }
+
+ $hash = getLinkHash($s);
+ $shortcut = shortcut($s, $hash);
+ $section .= $shortcut;
+ $hashs[$hash] = $shortcut;
+
+ $i++;
+ if ($cols && $i % 2 == 0) {
+ $section .= '</div>';
+ }
+ }
+ if ($cols && $i % 2 == 1) {
+ $section .= '</div>';
+ }
+ if ($fit) {
+ $section .= '</div>';
+ }
+ $section .= '</section>';
+ $res[$name] = $section;
+ }
+
+ $json = json_encode($res);
+
+ connectRedis()->igbset('shortcuts.' . getCurrentConfig(), $json);
+ profile('save cache shortcuts', __FILE__, __LINE__);
+
+ return 'SECTIONS = ' . $json . ';';
}
-function shortcut($s, $hash)
-{
- $attrs = array();
- $markup = 'a';
-
- if (isset($s['size'])) {
- $attrs['data-size'] = $s['size'];
- unset($s['size']);
- }
-
- if (is_string($s)) {
- return;
- }
-
- $swcorner = '';
-
- if ($s['type'] == 'ajax') {
- $attrs['class'] = 'ajax';
- $attrs['href'] = $s['url'];
- } elseif ($s['type'] == 'task') {
- $attrs['class'] = 'ajax';
- $attrs['href'] = 'scripts/tortugatask.php?task=' . $s['command'];
- } elseif ($s['type'] == 'light') {
- $attrs['class'] = 'ajax';
- $attrs['href'] = 'scripts/light.php?scene=' . $s['scene'];
- } elseif ($s['type'] == 'url') {
- $attrs['href'] = $s['href'];
- if (isset($s['iframe']) && $s['iframe']) {
- $attrs['class'] = 'iframe';
- } else if (isset($s['tab']) && $s['tab']) {
- $attrs['target'] = '_blank';
- }
- } else if ($s['type'] == 'squeeze' || $s['type'] == 'squeeze_spotify') {
- $attrs['href'] = 'scripts/squeeze.php?player=' . config('SQUEEZEBOX_PLAYER') . '&name=' . $s['label'] . '&type=' . $s['type'];
- $attrs['class'] = 'ajax music';
- } else if ($s['type'] == 'squeeze_ambiance') {
- $attrs['href'] = 'scripts/squeeze.php?player=' . config('SQUEEZEBOX_AMBIANCE_PLAYER') . '&name=' . $s['label'] . '&type=' . $s['type'];
- $attrs['class'] = 'ajax';
- $attrs['data-squeeze-volume'] = 60;
- $attrs['data-squeeze-player'] = config('SQUEEZEBOX_AMBIANCE_PLAYER');
- } else if ($s['type'] == 'vlc' || $s['type'] == 'omx') {
- $attrs['href'] = $s['url'];
- $attrs['class'] = $s['type'];
- } elseif ($s['type'] == 'time') {
- $attrs['href'] = isset($_GET['h']) && $_GET['h'] ? '//' . $_GET['h'] . '/' : '/';
- $attrs['data-init'] = "0";
- $attrs['data-init-function'] = "updateTime";
- $attrs['class'] = $s['type'] . ' info';
- if (!isset($s['label'])) {
- $s['label'] = '-';
- }
- } elseif ($s['type'] == 'time' || $s['type'] == 'separator' || $s['type'] == 'back') {
- $attrs['class'] = $s['type'] . ' info';
- if (!isset($s['label'])) {
- $s['label'] = '-';
- }
- } elseif ($s['type'] == 'volume') {
- $attrs['class'] = 'ajax';
- $attrs['href'] = 'scripts/volume.php?volume=' . $s['volume'];
- if (isset($s['increase'])) {
- $attrs['href'] .= '&increase=' . $s['increase'];
- }
- unset($s['volume']);
- } else if ($s['type'] == 'weather') {
- $attrs['class'] = $s['type'] . ' info';
- $attrs['data-init'] = "0";
- $attrs['data-init-function'] = "updateWeather";
- $s['label'] = '
+function shortcut($s, $hash) {
+ $attrs = array();
+ $markup = 'a';
+
+ if (isset($s['size'])) {
+ $attrs['data-size'] = $s['size'];
+ unset($s['size']);
+ }
+
+ if (is_string($s)) {
+ return;
+ }
+
+ $swcorner = '';
+
+ if ($s['type'] == 'ajax') {
+ $attrs['class'] = 'ajax';
+ $attrs['href'] = $s['url'];
+ } elseif ($s['type'] == 'task') {
+ $attrs['class'] = 'ajax';
+ $attrs['href'] = 'scripts/tortugatask.php?task=' . $s['command'];
+ } elseif ($s['type'] == 'light') {
+ $attrs['class'] = 'ajax';
+ $attrs['href'] = 'scripts/light.php?scene=' . $s['scene'];
+ } elseif ($s['type'] == 'url') {
+ $attrs['href'] = $s['href'];
+ if (isset($s['iframe']) && $s['iframe']) {
+ $attrs['class'] = 'iframe';
+ } else if (isset($s['tab']) && $s['tab']) {
+ $attrs['target'] = '_blank';
+ }
+ } else if ($s['type'] == 'squeeze' || $s['type'] == 'squeeze_spotify') {
+ $attrs['href'] = 'scripts/squeeze.php?player=' . config('SQUEEZEBOX_PLAYER') . '&name=' . $s['label'] . '&type=' . $s['type'];
+ $attrs['class'] = 'ajax music';
+ } else if ($s['type'] == 'squeeze_ambiance') {
+ $attrs['href'] = 'scripts/squeeze.php?player=' . config('SQUEEZEBOX_AMBIANCE_PLAYER') . '&name=' . $s['label'] . '&type=' . $s['type'];
+ $attrs['class'] = 'ajax';
+ $attrs['data-squeeze-volume'] = 60;
+ $attrs['data-squeeze-player'] = config('SQUEEZEBOX_AMBIANCE_PLAYER');
+ } else if ($s['type'] == 'vlc' || $s['type'] == 'omx') {
+ $attrs['href'] = $s['url'];
+ $attrs['class'] = $s['type'];
+ } elseif ($s['type'] == 'time') {
+ $attrs['href'] = isset($_GET['h']) && $_GET['h'] ? '//' . $_GET['h'] . '/' : '/';
+ $attrs['data-init'] = "0";
+ $attrs['data-init-function'] = "updateTime";
+ $attrs['class'] = $s['type'] . ' info';
+ if (!isset($s['label'])) {
+ $s['label'] = '-';
+ }
+ } elseif ($s['type'] == 'time' || $s['type'] == 'separator' || $s['type'] == 'back') {
+ $attrs['class'] = $s['type'] . ' info';
+ if (!isset($s['label'])) {
+ $s['label'] = '-';
+ }
+ } elseif ($s['type'] == 'volume') {
+ $attrs['class'] = 'ajax';
+ $attrs['href'] = 'scripts/volume.php?volume=' . $s['volume'];
+ if (isset($s['increase'])) {
+ $attrs['href'] .= '&increase=' . $s['increase'];
+ }
+ unset($s['volume']);
+ } else if ($s['type'] == 'weather') {
+ $attrs['class'] = $s['type'] . ' info';
+ $attrs['data-init'] = "0";
+ $attrs['data-init-function'] = "updateWeather";
+ $s['label'] = '
<div class="icons"><span class="icon-day"></span><span class="icon-night"></span></div>
<span class="temp"></span>
<div class="temperatures"><span class="temp-min"></span><span class="temp-max"></span></div>';
- } elseif ($s['type'] == 'traffic') {
- $attrs['class'] = $s['type'] . ' info';
- $attrs['data-init'] = "0";
- $attrs['data-init-function'] = "updateTraffic";
- $s['label'] = '<div class="departure">Départ à <span class="dtime"></span></div>
+ } elseif ($s['type'] == 'traffic') {
+ $attrs['class'] = $s['type'] . ' info';
+ $attrs['data-init'] = "0";
+ $attrs['data-init-function'] = "updateTraffic";
+ $s['label'] = '<div class="departure">Départ à <span class="dtime"></span></div>
<ul class="issy"><li class="car"></li><li class="subway"></li><li class="bike"></li></ul>
<div class="total_jams"><span class="jams"></span> de bouchons</div>';
- } elseif ($s['type'] == 'velib') {
- $attrs['class'] = $s['type'] . ' info';
- $attrs['data-init'] = "0";
- $attrs['data-init-function'] = "updateVelib";
- $s['label'] = '<div class="dtime"></div><ul></ul>';
- } elseif ($s['type'] == 'action') {
- $attrs['data-action'] = $s['action'];
- $attrs['data-device'] = isset($s['device']) ? $s['device'] : getCurrentConfig();
- $attrs['href'] = '#';
- } else if ($s['type'] == 'sub') {
- if (strpos($s['sub'], 'sub-') === false) {
- $s['sub'] = 'sub-' . $s['sub'];
- }
- $attrs['data-menu'] = $s['sub'];
- $attrs['href'] = '#';
- } else if ($s['type'] == 'phone') {
- $attrs['href'] = 'scripts/phonetask.php?phone=' . $s['phone'] . '&task=' . trim(base64_encode($s['task']), "=");
- $attrs['class'] = 'ajax';
- } elseif ($s['type'] == 'media') {
- $attrs['href'] = isset($s['path']) ? $s['path'] : $s['url'];
- $attrs['class'] = 'media';
- } elseif ($s['type'] == 'freebox' || $s['type'] === 'shield' || $s['type'] === 'netflix' || $s['type'] === 'amazonprime' || $s['type'] === 'nintendoswitch') {
- $attrs['href'] = $s['url'];
- $attrs['class'] = 'ajax play ' . $s['type'];
- $attrs['data-remote'] = "1";
- } else if ($s['type'] == 'map') {
- $rand = rand(1, 1000000);
- $html = '<img width="' . $s['width'] . '" height="' . $s['height'] . '" src="' . $s['image'] . '" usemap="#map_' . $rand . '" /><map class="' . $s['class'] . '" name="map_' . $rand . '">' . $s['map'] . '</map>';
- } else if ($s['type'] == 'missing') {
- $attrs['class'] = 'missing';
- } else if ($s['type'] == 'bricks') {
- $html = makeBricks($s['bricks']);
- } else if ($s['type'] == 'raspberrycast') {
- $attrs['class'] = 'raspberrycast';
- } else if ($s['type'] == 'harmonyactivity') {
- $attrs['class'] = 'harmonyactivity';
- $attrs['data-activity'] = $s['activity'];
- } else if ($s['type'] == 'ifttt') {
- $attrs['class'] = 'ifttt';
- $attrs['data-event'] = $s['event'];
- } else if ($s['type'] == 'switch' || $s['type'] === 'switchshare') {
- $attrs['href'] = '//' . $s['room'] . '.home.tortuga.enhydra.fr/';
- if ($s['type'] == 'share') {
- $h = isset($_GET['h']) && $_GET['h'] ? $_GET['h'] : $_SERVER['HTTP_HOST'];
- $attrs['href'] .= '?h=' . $h;
- } else {
- $attrs['class'] = $s['type'];
- }
- $attrs['style'] = 'background-image:url(/images/rooms/small/' . $s['room'] . '.jpg);background-size:cover;color:#fff;text-shadow:3px;';
- }
-
- if (isset($s['seen']) && $s['seen']) {
- $attrs['data-seen'] = '1';
- }
-
- if (isset($s['srt']) && count($s['srt'])) {
- $langtoemoji = ['fr' => '🇫🇷', 'en' => '🇺🇸'];
- foreach ($s['srt'] as $item) {
- $swcorner .= '<span>' . $langtoemoji[$item] . '</span>';
- }
- }
-
-
- if (isset($s['poster'])) {
- if (!isset($attrs['class'])) {
- $attrs['class'] = '';
- }
- $attrs['class'] .= ' poster';
- $attrs['style'] = 'background-image:url(' . $s['poster'] . ');';
- $s['label'] = '';
- }
-
- if ($markup == 'a' && !isset($attrs['href'])) {
- $attrs['href'] = '#';
- }
-
- if (isset($s['screenoff'])) {
- $attrs['data-screenoff'] = 1;
- }
- if (isset($s['volume'])) {
- $attrs['data-volume'] = $s['volume'];
- }
-
- if (isset($s['confirm'])) {
- $attrs['data-confirm'] = json_encode($s['confirm']['conditions']);
- $attrs['data-confirm-message'] = $s['confirm']['message'];
- }
-
-
- if (isset($html)) {
- $res = $html;
- } else {
- $res = '<' . $markup;
- foreach ($attrs as $k => $v) {
- if (is_array($v) || is_object($v)) {
- $v = json_encode($v);
- }
-
- $res .= ' ' . $k . '="' . htmlspecialchars($v) . '"';
- }
- if (!isset($s['label'])) {
- $s['label'] = '';
- }
- $res .= '><span>' . $s['label'] . '</span><div class="sw-corner">' . $swcorner . '</div></' . $markup . '>';
- }
- return $res;
+ } elseif ($s['type'] == 'velib') {
+ $attrs['class'] = $s['type'] . ' info';
+ $attrs['data-init'] = "0";
+ $attrs['data-init-function'] = "updateVelib";
+ $s['label'] = '<div class="dtime"></div><ul></ul>';
+ } elseif ($s['type'] == 'action') {
+ $attrs['data-action'] = $s['action'];
+ $attrs['data-device'] = isset($s['device']) ? $s['device'] : getCurrentConfig();
+ $attrs['href'] = '#';
+ } else if ($s['type'] == 'sub') {
+ if (strpos($s['sub'], 'sub-') === false) {
+ $s['sub'] = 'sub-' . $s['sub'];
+ }
+ $attrs['data-menu'] = $s['sub'];
+ $attrs['href'] = '#';
+ } else if ($s['type'] == 'phone') {
+ $attrs['href'] = 'scripts/phonetask.php?phone=' . $s['phone'] . '&task=' . trim($s['task']);
+ $attrs['class'] = 'ajax';
+ } elseif ($s['type'] == 'media') {
+ $attrs['href'] = isset($s['path']) ? $s['path'] : $s['url'];
+ $attrs['class'] = 'media';
+ } elseif ($s['type'] == 'freebox' || $s['type'] === 'shield' || $s['type'] === 'netflix' || $s['type'] === 'amazonprime' || $s['type'] === 'nintendoswitch') {
+ $attrs['href'] = $s['url'];
+ $attrs['class'] = 'ajax play ' . $s['type'];
+ $attrs['data-remote'] = "1";
+ } else if ($s['type'] == 'map') {
+ $rand = rand(1, 1000000);
+ $html = '<img width="' . $s['width'] . '" height="' . $s['height'] . '" src="' . $s['image'] . '" usemap="#map_' . $rand . '" /><map class="' . $s['class'] . '" name="map_' . $rand . '">' . $s['map'] . '</map>';
+ } else if ($s['type'] == 'missing') {
+ $attrs['class'] = 'missing';
+ } else if ($s['type'] == 'bricks') {
+ $html = makeBricks($s['bricks']);
+ } else if ($s['type'] == 'raspberrycast') {
+ $attrs['class'] = 'raspberrycast';
+ } else if ($s['type'] == 'harmonyactivity') {
+ $attrs['class'] = 'harmonyactivity';
+ $attrs['data-activity'] = $s['activity'];
+ } else if ($s['type'] == 'ifttt') {
+ $attrs['class'] = 'ifttt';
+ $attrs['data-event'] = $s['event'];
+ } else if ($s['type'] == 'switch' || $s['type'] === 'switchshare') {
+ $attrs['href'] = '//' . $s['room'] . '.home.tortuga.enhydra.fr/';
+ if ($s['type'] == 'share') {
+ $h = isset($_GET['h']) && $_GET['h'] ? $_GET['h'] : $_SERVER['HTTP_HOST'];
+ $attrs['href'] .= '?h=' . $h;
+ } else {
+ $attrs['class'] = $s['type'];
+ }
+ $attrs['style'] = 'background-image:url(/images/rooms/small/' . $s['room'] . '.jpg);background-size:cover;color:#fff;text-shadow:3px;';
+ }
+
+ if (isset($s['seen']) && $s['seen']) {
+ $attrs['data-seen'] = '1';
+ }
+
+ if (isset($s['srt']) && count($s['srt'])) {
+ $langtoemoji = ['fr' => '🇫🇷', 'en' => '🇺🇸'];
+ foreach ($s['srt'] as $item) {
+ $swcorner .= '<span>' . $langtoemoji[$item] . '</span>';
+ }
+ }
+
+
+ if (isset($s['poster'])) {
+ if (!isset($attrs['class'])) {
+ $attrs['class'] = '';
+ }
+ $attrs['class'] .= ' poster';
+ $attrs['style'] = 'background-image:url(' . $s['poster'] . ');';
+ $s['label'] = '';
+ }
+
+ if ($markup == 'a' && !isset($attrs['href'])) {
+ $attrs['href'] = '#';
+ }
+
+ if (isset($s['screenoff'])) {
+ $attrs['data-screenoff'] = 1;
+ }
+ if (isset($s['volume'])) {
+ $attrs['data-volume'] = $s['volume'];
+ }
+
+ if (isset($s['confirm'])) {
+ $attrs['data-confirm'] = json_encode($s['confirm']['conditions']);
+ $attrs['data-confirm-message'] = $s['confirm']['message'];
+ }
+
+
+ if (isset($html)) {
+ $res = $html;
+ } else {
+ $res = '<' . $markup;
+ foreach ($attrs as $k => $v) {
+ if (is_array($v) || is_object($v)) {
+ $v = json_encode($v);
+ }
+
+ $res .= ' ' . $k . '="' . htmlspecialchars($v) . '"';
+ }
+ if (!isset($s['label'])) {
+ $s['label'] = '';
+ }
+ $res .= '><span>' . $s['label'] . '</span><div class="sw-corner">' . $swcorner . '</div></' . $markup . '>';
+ }
+ return $res;
}
-function init()
-{
- global $volume;
- $volume = intval(CONFIG('VOLUME', '0'));
- if ($volume > 0) {
- volume($volume);
- }
- profile('Inited', __FILE__, __LINE__);
+function init() {
+ global $volume;
+ $volume = intval(CONFIG('VOLUME', '0'));
+ if ($volume > 0) {
+ volume($volume);
+ }
+ profile('Inited', __FILE__, __LINE__);
}
-function getJsonRPCClientInstance($url)
-{
- global $rpcclient;
- if (!isset($rpcclient)) {
- $rpcclient = new \Datto\JsonRpc\Http\Client($url);
- }
- return $rpcclient;
+function getJsonRPCClientInstance($url) {
+ global $rpcclient;
+ if (!isset($rpcclient)) {
+ $rpcclient = new \Datto\JsonRpc\Http\Client($url);
+ }
+ return $rpcclient;
}
-function getSynologyInstance()
-{
- global $syno;
- if (!isset($syno)) {
- $syno = new Synology_Api('192.168.13.3', 5002, 'https', 1);
- $syno->connect('Vincent', 'xxxx');
- }
- return $syno;
+function getSynologyInstance() {
+ global $syno;
+ if (!isset($syno)) {
+ $syno = new Synology_Api('192.168.13.3', 5002, 'https', 1);
+ $syno->connect('Vincent', 'xxxx');
+ }
+ return $syno;
}
-function hasNetwork()
-{
- return true;
+function hasNetwork() {
+ return true;
}
-function ping($ip, $timeout = 5, $port = 1817)
-{
- $res = @fsockopen($ip, $port, $errno, $errstr, $timeout);
- if (!$res) {
- echo $errno . ': ' . $errstr . "\n";
- }
- return $res;
+function ping($ip, $timeout = 5, $port = 1817) {
+ $res = @fsockopen($ip, $port, $errno, $errstr, $timeout);
+ if (!$res) {
+ echo $errno . ': ' . $errstr . "\n";
+ }
+ return $res;
}
-function volume($volume, $increase = '', $device = null)
-{
- $d = $device === null ? config('VOLUME_DEVICE') : $device;
- echo $d . ';' . $volume . ';' . $increase;
-
- if ($increase == ' ') {
- $increase = '+';
- }
-
- $e = explode(':', $d);
-
- $device = config('DEVICE');
- if (isset($e[1])) {
- $device = $e[1];
- $d = $e[0];
- }
- $d = mb_strtolower($d);
-
- switch ($d) {
- case 'shield':
- if ($increase == '-') {
- return shieldKey('volume-down', $device);
- } else {
- return shieldKey('volume-up', $device);
- }
- case 'raspberry':
- case 'raspberrypi':
- $cmd = 'amixer -c 0 -M -- sset PCM playback ' . round(max(0, min(100, $volume))) . '%' . $increase;
- return sshCommand($cmd, $device);
- case 'squeezeboplayer':
- case 'squeezeboxplayer':
- case 'squeezebox':
- return squeezeVolume($volume, $increase, config('SQUEEZEBOX_PLAYER'));
- case 'harmony':
- $lastHarmonyVolume = min(time(), getState('last_harmony_volume', 0));
- $limit = time() - 2;
- if ($lastHarmonyVolume > $limit) {
- return;
- }
- setState('last_harmony_volume', time());
-
- $volume = min(5, max(1, $volume));
-
- if ($increase == '-') {
- return harmonyRequest('commands/volume-down?repeat=' . $volume, 'POST');
- } else {
- return harmonyRequest('commands/volume-up?repeat=' . $volume, 'POST');
- }
- case 'vlc':
- return VLCCmd(['command' => 'volume', 'val' => $increase . '20'], $device);
- case 'denonavr':
- return denonAVRVolume($volume, $increase);
- }
+function volume($volume, $increase = '', $device = null) {
+ $d = $device === null ? config('VOLUME_DEVICE') : $device;
+ echo $d . ';' . $volume . ';' . $increase;
+
+ if ($increase == ' ') {
+ $increase = '+';
+ }
+
+ $e = explode(':', $d);
+
+ $device = config('DEVICE');
+ if (isset($e[1])) {
+ $device = $e[1];
+ $d = $e[0];
+ }
+ $d = mb_strtolower($d);
+
+ switch ($d) {
+ case 'shield':
+ if ($increase == '-') {
+ return shieldKey('volume-down', $device);
+ } else {
+ return shieldKey('volume-up', $device);
+ }
+ case 'raspberry':
+ case 'raspberrypi':
+ $cmd = 'amixer -c 0 -M -- sset PCM playback ' . round(max(0, min(100, $volume))) . '%' . $increase;
+ return sshCommand($cmd, $device);
+ case 'squeezeboplayer':
+ case 'squeezeboxplayer':
+ case 'squeezebox':
+ return squeezeVolume($volume, $increase, config('SQUEEZEBOX_PLAYER'));
+ case 'harmony':
+ $lastHarmonyVolume = min(time(), getState('last_harmony_volume', 0));
+ $limit = time() - 2;
+ if ($lastHarmonyVolume > $limit) {
+ return;
+ }
+ setState('last_harmony_volume', time());
+
+ $volume = min(5, max(1, $volume));
+
+ if ($increase == '-') {
+ return harmonyRequest('commands/volume-down?repeat=' . $volume, 'POST');
+ } else {
+ return harmonyRequest('commands/volume-up?repeat=' . $volume, 'POST');
+ }
+ case 'vlc':
+ return VLCCmd(['command' => 'volume', 'val' => $increase . '20'], $device);
+ case 'denonavr':
+ return denonAVRVolume($volume, $increase);
+ }
}
-function triggerErrorNotif($title, $message = '')
-{
- phoneTask('TortugaMessage|||' . $title . '|||' . $message, 'vincent', true);
+function triggerErrorNotif($title, $message = '') {
+ phoneTask('TortugaMessage|||' . $title . '|||' . $message, 'vincent', true);
}
-function phoneTask($task, $phone, $encode = true)
-{
- global $phones;
- $p = $phones[$phone];
-
- if ($encode) {
- $task = trim(base64_encode($task), '=');
- }
- $task = $task . "=:=task";
-
- $password = $p['password'];
-
- $url = "http://$p[ip]:1817/?message=$task&password=" . $password;
- $res = getUrlContent($url);
- //echo $url . ' : ' . $res . "\n--\n";
- if (!$res) {
- $url = "https://autoremotejoaomgcd.appspot.com/sendmessage?key=$p[key]&message=$task&target=TORTUGA&password=$password";
- $res = getUrlContent($url);
- //echo $url . ' : ' . $res . "\n--\n";
- }
- return $res;
+function phoneTask($task, $phone, $encode = true) {
+ global $phones;
+ $p = $phones[$phone];
+
+ if ($encode) {
+ $task = trim(base64_encode($task), '=');
+ }
+ $task = $task . "=:=task";
+
+ $password = $p['password'];
+
+ $url = "http://$p[ip]:1817/?message=$task&password=" . $password;
+ $res = getUrlContent($url);
+ //echo $url . ' : ' . $res . "\n--\n";
+ if (!$res) {
+ $url = "https://autoremotejoaomgcd.appspot.com/sendmessage?key=$p[key]&message=$task&target=TORTUGA&password=$password";
+ $res = getUrlContent($url);
+ //echo $url . ' : ' . $res . "\n--\n";
+ }
+ return $res;
}
-function getUrlContent($url, $timeout = 30, $user = false, $newclient = false)
-{
- $httpclient = getHttpClient($newclient);
- $options = ['timeout' => $timeout, 'read_timeout' => $timeout];
- if ($user !== false) {
- $options['auth'] = $user;
- }
- try {
- $response = $httpclient->get($url, $options);
- return $response->getBody();
- } catch (Exception $e) {
- echo $e->getMessage();
- return false;
- }
+function getUrlContent($url, $timeout = 30, $user = false, $newclient = false) {
+ $httpclient = getHttpClient($newclient);
+ $options = ['timeout' => $timeout, 'read_timeout' => $timeout];
+ if ($user !== false) {
+ $options['auth'] = $user;
+ }
+ try {
+ $response = $httpclient->get($url, $options);
+ return $response->getBody();
+ } catch (Exception $e) {
+ echo $e->getMessage();
+ return false;
+ }
}
-function waitEvent($event)
-{
- $file = ROOT . '/cache/events/' . $event;
- while (true) {
- if (file_exists($file)) {
- if (filemtime($file) < time() - 60) {
- // Expired event
- rename($file, $file . '_' . microtime(false));
- continue;
- }
- rename($file, $file . '_' . microtime(false));
- break;
- }
- usleep(0.1 * 1000000);
- }
+function waitEvent($event) {
+ $file = ROOT . '/cache/events/' . $event;
+ while (true) {
+ if (file_exists($file)) {
+ if (filemtime($file) < time() - 60) {
+ // Expired event
+ rename($file, $file . '_' . microtime(false));
+ continue;
+ }
+ rename($file, $file . '_' . microtime(false));
+ break;
+ }
+ usleep(0.1 * 1000000);
+ }
}
-function returnHttpResponse()
-{
- ignore_user_abort(true);
- if (!defined('TIMELIMIT')) {
- set_time_limit(0);
- }
- if (!headers_sent()) {
- header('Connection: close');
- header('Content-Length: ' . ob_get_length());
- }
- @ob_end_flush();
- @ob_flush();
- @flush();
- if (session_id()) session_write_close();
- if (function_exists('fastcgi_finish_request')) {
- fastcgi_finish_request();
- }
+function returnHttpResponse() {
+ ignore_user_abort(true);
+ if (!defined('TIMELIMIT')) {
+ set_time_limit(0);
+ }
+ if (!headers_sent()) {
+ header('Connection: close');
+ header('Content-Length: ' . ob_get_length());
+ }
+ @ob_end_flush();
+ @ob_flush();
+ @flush();
+ if (session_id())
+ session_write_close();
+ if (function_exists('fastcgi_finish_request')) {
+ fastcgi_finish_request();
+ }
}
-function isProcessRunning($process)
-{
- exec("ps aux | grep -i '" . $process . "' | grep -v grep", $pids);
- if (empty($pids)) {
- return false;
- }
- return true;
+function isProcessRunning($process) {
+ exec("ps aux | grep -i '" . $process . "' | grep -v grep", $pids);
+ if (empty($pids)) {
+ return false;
+ }
+ return true;
}
-function toNumber($val, $round = false)
-{
- if ($val === false) {
- return '--';
- }
- $e = explode(',', $val);
- $val = $e[0];
- $val = preg_replace('/[^0-9-.]/', '', $val);
- $val = floatval($val);
- if ($round) {
- $val = round($val, $round === true ? 0 : $round);
- }
- return $val;
+function toNumber($val, $round = false) {
+ if ($val === false) {
+ return '--';
+ }
+ $e = explode(',', $val);
+ $val = $e[0];
+ $val = preg_replace('/[^0-9-.]/', '', $val);
+ $val = floatval($val);
+ if ($round) {
+ $val = round($val, $round === true ? 0 : $round);
+ }
+ return $val;
}
-function makeNav($nav)
-{
- $map = [
- 'home' => '<div data-menu="home"><i class="fa fa-home" aria-hidden="true"></i><span>Accueil</span></div>',
- 'lights' => '<div data-menu="lights"><i class="far fa-lightbulb" aria-hidden="true"></i><span>Lumières</span></div>',
- 'music' => '<div data-menu="music"><i class="fa fa-music" aria-hidden="true"></i><span>Musique & Radio</span></div>',
- 'media' => '<div data-menu="media"><i class="fa fa-tv-retro" aria-hidden="true"></i><span>Medias & TV</span></div>',
- 'coffee' => '<div data-menu="coffee"><i class="fa fa-oven" aria-hidden="true"></i><span>Cuisine / Café</span></div>',
- 'water' => '<div data-menu="water"><i class="fa fa-faucet-drip" aria-hidden="true"></i><span>Eau chaude</span></div>',
- 'fan' => '<a href="/scripts/light.php?scene=' . config('ROOM') . '/fan/toggle" class="ajax"><i class="fa fa-fan" aria-hidden="true"></i><span>Ventilateur</span></a>',
- 'remote' => '<div data-menu="remote"><i class="fa fa-play" aria-hidden="true"></i><span>Télécommande</span></div>',
- 'switch' => '<div data-menu="switch"><i class="far fa-portal-enter" aria-hidden="true"></i><span>Changer de pièce</span></div>',
- 'clock' => '<div data-menu="clock"><i class="far fa-alarm-clock" aria-hidden="true"></i><span>Réveil</span></div>',
- 'settings' => '<div data-menu="settings"><i class="fa fa-cog" aria-hidden="true"></i><span>Paramètres</span></div>',
- 'alert' => '<div data-action="alert"><i class="fa fa-bell" aria-hidden="true"></i><span>Alerte</span></div>',
- 'off' => '<div data-action="off"><i class="fa fa-power-off" aria-hidden="true"></i><span>Éteindre</span></div>',
- ];
-
- $res = '<nav id="mainnav"><ul>';
- foreach ($nav as $item) {
- if (isset($map[$item])) {
- $res .= '<li>' . $map[$item] . '</li>';
- }
- }
- $res .= '</ul></nav>';
- return $res;
+function makeNav($nav) {
+ $map = [
+ 'home' => '<div data-menu="home"><i class="fa fa-home" aria-hidden="true"></i><span>Accueil</span></div>',
+ 'lights' => '<div data-menu="lights"><i class="far fa-lightbulb" aria-hidden="true"></i><span>Lumières</span></div>',
+ 'music' => '<div data-menu="music"><i class="fa fa-music" aria-hidden="true"></i><span>Musique & Radio</span></div>',
+ 'media' => '<div data-menu="media"><i class="fa fa-tv-retro" aria-hidden="true"></i><span>Medias & TV</span></div>',
+ 'coffee' => '<div data-menu="coffee"><i class="fa fa-oven" aria-hidden="true"></i><span>Cuisine / Café</span></div>',
+ 'water' => '<div data-menu="water"><i class="fa fa-faucet-drip" aria-hidden="true"></i><span>Eau chaude</span></div>',
+ 'fan' => '<a href="/scripts/light.php?scene=' . config('ROOM') . '/fan/toggle" class="ajax"><i class="fa fa-fan" aria-hidden="true"></i><span>Ventilateur</span></a>',
+ 'remote' => '<div data-menu="remote"><i class="fa fa-play" aria-hidden="true"></i><span>Télécommande</span></div>',
+ 'switch' => '<div data-menu="switch"><i class="far fa-portal-enter" aria-hidden="true"></i><span>Changer de pièce</span></div>',
+ 'clock' => '<div data-menu="clock"><i class="far fa-alarm-clock" aria-hidden="true"></i><span>Réveil</span></div>',
+ 'settings' => '<div data-menu="settings"><i class="fa fa-cog" aria-hidden="true"></i><span>Paramètres</span></div>',
+ 'alert' => '<div data-action="alert"><i class="fa fa-bell" aria-hidden="true"></i><span>Alerte</span></div>',
+ 'off' => '<div data-action="off"><i class="fa fa-power-off" aria-hidden="true"></i><span>Éteindre</span></div>',
+ ];
+
+ $res = '<nav id="mainnav"><ul>';
+ foreach ($nav as $item) {
+ if (isset($map[$item])) {
+ $res .= '<li>' . $map[$item] . '</li>';
+ }
+ }
+ $res .= '</ul></nav>';
+ return $res;
}
-function gloria()
-{
- $j = intval(date('N'));
- if ($j !== 1) {
- return false;
- }
- $h = intval(date('H'));
- return $h >= 12 && $h <= 17;
+function gloria() {
+ $j = intval(date('N'));
+ if ($j !== 1) {
+ return false;
+ }
+ $h = intval(date('H'));
+ return $h >= 12 && $h <= 17;
}