chore: add .editorconfig, reformat files
This commit is contained in:
parent
3161bfee1f
commit
397bc65998
|
@ -0,0 +1,16 @@
|
|||
# Editor configuration, see https://editorconfig.org
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.{ts,js,tsx,jsx}]
|
||||
quote_type = single
|
||||
|
||||
[*.md]
|
||||
max_line_length = off
|
||||
trim_trailing_whitespace = false
|
|
@ -13,8 +13,8 @@ include_once($_SERVER['DOCUMENT_ROOT'].'/inc/config.php');
|
|||
|
||||
originHelper\origin::check($config['allowed-origins']);
|
||||
|
||||
$allowed_ip = $config['local-ip'];
|
||||
if(!($_SERVER['REMOTE_ADDR'] == $allowed_ip)) {
|
||||
$allowedIP = $config['local-ip'];
|
||||
if(!($_SERVER['REMOTE_ADDR'] == $allowedIP)) {
|
||||
header('X-CacheStatus: private');
|
||||
header('Content-Type: application/json');
|
||||
die('[]');
|
||||
|
@ -48,15 +48,15 @@ if(array_key_exists($what, $cals)) {
|
|||
die("{'err':'not found'}");
|
||||
}
|
||||
|
||||
$cache_pre = 'cache/calendar';
|
||||
$cache_post = '.cache';
|
||||
$cache_age = 10800;
|
||||
$cachePre = 'cache/calendar';
|
||||
$cachePost = '.cache';
|
||||
$cacheAge = 10800;
|
||||
|
||||
$file = $cache_pre.$what.$cache_post;
|
||||
$file = $cachePre.$what.$cachePost;
|
||||
$ret = "";
|
||||
$fileage = @filemtime($file);
|
||||
//caching
|
||||
if($fileage && !(time() - $fileage >= $cache_age) && !$debug) {
|
||||
if($fileage && !(time() - $fileage >= $cacheAge) && !$debug) {
|
||||
header('X-CacheStatus: cached');
|
||||
header('X-CacheAge: '.(time() - $fileage));
|
||||
$ret = file_get_contents($file);
|
||||
|
@ -100,9 +100,6 @@ function getEvents($url, $user, $token, $from, $to, $calendar) {
|
|||
return $ret;
|
||||
}
|
||||
|
||||
function get($key, $default_value = '') {
|
||||
return isset($_GET[$key]) ? $_GET[$key] : $default_value;
|
||||
function get($key, $defaultValue = '') {
|
||||
return isset($_GET[$key]) ? $_GET[$key] : $defaultValue;
|
||||
}
|
||||
|
||||
|
||||
?>
|
|
@ -14,8 +14,8 @@ $ret = [];
|
|||
function getPoint($baseurl, $url) {
|
||||
global $pois;
|
||||
//assumption: home location is at $pois[0]
|
||||
$home_lat = $pois[0]["lat"];
|
||||
$home_lon = $pois[0]["lon"];
|
||||
$homeLat = $pois[0]["lat"];
|
||||
$homeLon = $pois[0]["lon"];
|
||||
|
||||
$cache = "./cache/$url.cache";
|
||||
try {
|
||||
|
@ -30,19 +30,19 @@ function getPoint($baseurl, $url) {
|
|||
return ["name"=>"Error", "date"=>$now->format("c"), "error"=>$ex->getMessage()];
|
||||
}
|
||||
|
||||
$dist_poi = [];
|
||||
$distPoi = [];
|
||||
$poi = "";
|
||||
foreach ($pois as $poii) {
|
||||
$poi_dist = vincentyGreatCircleDistance($poii["lat"],$poii["lon"],$ret["lat"],$ret["lon"]);
|
||||
$dist_poi[] = ["dist"=>$poi_dist, "label"=>$poii["label"]];
|
||||
if($poi_dist < 0.3) {
|
||||
$poiDist = vincentyGreatCircleDistance($poii["lat"],$poii["lon"],$ret["lat"],$ret["lon"]);
|
||||
$distPoi[] = ["dist"=>$poiDist, "label"=>$poii["label"]];
|
||||
if($poiDist < 0.3) {
|
||||
$poi = $poii["label"];
|
||||
}
|
||||
}
|
||||
|
||||
return ["name"=>$key, "timestamp"=>$ret["timestamp"], "date"=>$dt->format("c"), "lat"=>$ret["lat"], "lon"=>$ret["lon"],
|
||||
"accuracy"=>$ret["accuracy"], "battery"=>$ret["batterylevel"],
|
||||
"distance"=>vincentyGreatCircleDistance($home_lat, $home_lon, $ret["lat"], $ret["lon"]), "poi"=>$poi /*, "debug"=>$dist_poi*/ ];
|
||||
"distance"=>vincentyGreatCircleDistance($homeLat, $homeLon, $ret["lat"], $ret["lon"]), "poi"=>$poi /*, "debug"=>$distPoi*/ ];
|
||||
}
|
||||
|
||||
foreach($points as $point) {
|
||||
|
@ -66,8 +66,5 @@ function vincentyGreatCircleDistance($latitudeFrom, $longitudeFrom, $latitudeTo,
|
|||
}
|
||||
|
||||
|
||||
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode($ret);
|
||||
|
||||
?>
|
|
@ -95,5 +95,3 @@ function endsWith($string, $endString)
|
|||
}
|
||||
return (substr($string, -$len) === $endString);
|
||||
}
|
||||
|
||||
?>
|
|
@ -83,5 +83,3 @@ $stationArray = array_slice($stationArray,0,$numReturn);
|
|||
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode($stationArray);
|
||||
|
||||
?>
|
|
@ -1,14 +1,16 @@
|
|||
<?php
|
||||
include_once($_SERVER['DOCUMENT_ROOT'].'/inc/origin.class.php');
|
||||
include_once($_SERVER['DOCUMENT_ROOT'].'/inc/config.php');
|
||||
include_once($_SERVER['DOCUMENT_ROOT'].'/inc/funcs.php');
|
||||
include_once($_SERVER['DOCUMENT_ROOT'] . '/inc/origin.class.php');
|
||||
include_once($_SERVER['DOCUMENT_ROOT'] . '/inc/config.php');
|
||||
include_once($_SERVER['DOCUMENT_ROOT'] . '/inc/funcs.php');
|
||||
|
||||
originHelper\origin::check($config['allowed-origins']);
|
||||
|
||||
setlocale(LC_TIME,"de_DE");
|
||||
setlocale(LC_TIME, "de_DE");
|
||||
|
||||
class WeatherEntry {
|
||||
class WeatherEntry
|
||||
{
|
||||
public $Date;
|
||||
public $DayName;
|
||||
public $Icon = '';
|
||||
public $Main = '';
|
||||
public $TempLow = 0.0;
|
||||
|
@ -19,28 +21,31 @@ class WeatherEntry {
|
|||
public $PercSnow;
|
||||
}
|
||||
|
||||
function parseWeather($list) {
|
||||
function parseWeather($list)
|
||||
{
|
||||
$ret = [];
|
||||
$days = [];
|
||||
$perday = [];
|
||||
$currDay = '';
|
||||
foreach($list as $entry) {
|
||||
foreach ($list as $entry) {
|
||||
$curr = new WeatherEntry();
|
||||
$curr->Date = new DateTime($entry->dt_txt);
|
||||
$curr->DayName = apiFuncs\formatAsDay($curr->Date->format('N'));
|
||||
$curr->Icon = $entry->weather[0]->id;
|
||||
$curr->Main = $entry->weather[0]->main;
|
||||
$curr->TempLow = round($entry->main->temp_min,1);
|
||||
$curr->TempHigh = round($entry->main->temp_max,1);
|
||||
$curr->TempLow = round($entry->main->temp_min, 1);
|
||||
$curr->TempHigh = round($entry->main->temp_max, 1);
|
||||
$curr->Wind = $entry->wind->speed;
|
||||
$curr->Humidity = $entry->main->humidity;
|
||||
//$curr->PercRain = $entry->rain->{'3h'};
|
||||
//$curr->PercSnow = $entry->snow->{'3h'};
|
||||
|
||||
$day = $curr->Date->format('d.n');
|
||||
if($currDay == '') { $currDay = $day; }
|
||||
if($day != $currDay) {
|
||||
if(count($perday) > 0 ) {
|
||||
if ($currDay == '') {
|
||||
$currDay = $day;
|
||||
}
|
||||
if ($day != $currDay) {
|
||||
if (count($perday) > 0) {
|
||||
$ret[] = ['key' => $currDay, 'list' => $perday];
|
||||
}
|
||||
$currDay = $day;
|
||||
|
@ -48,7 +53,7 @@ function parseWeather($list) {
|
|||
}
|
||||
$perday[] = $curr;
|
||||
}
|
||||
if($currDay != "") {
|
||||
if ($currDay != "") {
|
||||
$ret[] = ['key' => $currDay, 'list' => $perday];
|
||||
}
|
||||
|
||||
|
@ -58,13 +63,13 @@ function parseWeather($list) {
|
|||
|
||||
$weatherCache = "cache/weather.cache";
|
||||
$weatherUrl = "https://api.openweathermap.org/data/2.5/forecast";
|
||||
$weatherUrl .= "?q=".$config['weather-location']."&units=metric&APPID=".$config['weather-api']; //&cnt=16
|
||||
$weatherUrl .= "?q=" . $config['weather-location'] . "&units=metric&APPID=" . $config['weather-api']; //&cnt=16
|
||||
try {
|
||||
$weatherContent = json_decode(apiFuncs\cache_contents($weatherUrl, $weatherCache, 10800, false)); // 10800 = 3 Stunden
|
||||
} catch (Exception $ex) {
|
||||
die("<h2>error fetching weather data! <small>(".$ex->getMessage().")</small></h2>");
|
||||
die("<h2>error fetching weather data! <small>(" . $ex->getMessage() . ")</small></h2>");
|
||||
}
|
||||
$iconClass ="wi wi-owm-";
|
||||
$iconClass = "wi wi-owm-";
|
||||
|
||||
$forecast = $weatherContent->list;
|
||||
$arr = parseWeather($forecast);
|
||||
|
@ -75,19 +80,34 @@ $tmpl .= '<div class="maintemp">' . $arr[0]['list'][0]->TempLow . '\ <s
|
|||
$tmpl .= '</div></div>';
|
||||
|
||||
// rest of forecast
|
||||
for($i = 1;$i<count($arr)-1;$i++) {
|
||||
for ($i = 1; $i < count($arr) - 1; $i++) {
|
||||
$tdy = $arr[$i]['list'];
|
||||
$night = '';
|
||||
$day = '';
|
||||
$cnt = count($tdy);
|
||||
switch($cnt) {
|
||||
case 1: $night = $tdy[0]; $day = $tdy[0]; break;
|
||||
case 2: $night = $tdy[0]; $day = $tdy[1]; break;
|
||||
case 3: $night = $tdy[0]; $day = $tdy[2]; break;
|
||||
case 4: $night = $tdy[0]; $day = $tdy[3]; break;
|
||||
default: $night = $tdy[0]; $day = $tdy[4]; break;
|
||||
switch ($cnt) {
|
||||
case 1:
|
||||
$night = $tdy[0];
|
||||
$day = $tdy[0];
|
||||
break;
|
||||
case 2:
|
||||
$night = $tdy[0];
|
||||
$day = $tdy[1];
|
||||
break;
|
||||
case 3:
|
||||
$night = $tdy[0];
|
||||
$day = $tdy[2];
|
||||
break;
|
||||
case 4:
|
||||
$night = $tdy[0];
|
||||
$day = $tdy[3];
|
||||
break;
|
||||
default:
|
||||
$night = $tdy[0];
|
||||
$day = $tdy[4];
|
||||
break;
|
||||
}
|
||||
$tmpl .= '<div class="col wcol"><span class="bigger">'.$day->DayName.'</span><div class="wicon"><i class="'.$iconClass . $day->Icon . '" title="'.$day->Main .'"></i></div>';
|
||||
$tmpl .= $night->TempLow . '\ <span class="bigger">' .$day->TempHigh .'°C</span></div>';
|
||||
$tmpl .= '<div class="col wcol"><span class="bigger">' . $day->DayName . '</span><div class="wicon"><i class="' . $iconClass . $day->Icon . '" title="' . $day->Main . '"></i></div>';
|
||||
$tmpl .= $night->TempLow . '\ <span class="bigger">' . $day->TempHigh . '°C</span></div>';
|
||||
}
|
||||
echo $tmpl;
|
||||
|
|
|
@ -1,145 +1,150 @@
|
|||
<?php
|
||||
|
||||
include_once($_SERVER['DOCUMENT_ROOT'].'/inc/origin.class.php');
|
||||
include_once($_SERVER['DOCUMENT_ROOT'].'/inc/config.php');
|
||||
include_once($_SERVER['DOCUMENT_ROOT'].'/inc/funcs.php');
|
||||
include_once($_SERVER['DOCUMENT_ROOT'] . '/inc/origin.class.php');
|
||||
include_once($_SERVER['DOCUMENT_ROOT'] . '/inc/config.php');
|
||||
include_once($_SERVER['DOCUMENT_ROOT'] . '/inc/funcs.php');
|
||||
|
||||
originHelper\origin::check($config['allowed-origins']);
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
setlocale(LC_TIME,"de_DE");
|
||||
setlocale(LC_TIME, "de_DE");
|
||||
|
||||
class JsonDateTime extends \DateTime implements \JsonSerializable
|
||||
{
|
||||
public function jsonSerialize() : mixed
|
||||
{
|
||||
return $this->format("c");
|
||||
}
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return $this->format("c");
|
||||
}
|
||||
}
|
||||
|
||||
class WeatherEntry {
|
||||
public $Date;
|
||||
public $Icon = '';
|
||||
public $TempLow = 0.0;
|
||||
class WeatherEntry
|
||||
{
|
||||
public $Date;
|
||||
public $Icon = '';
|
||||
public $TempLow = 0.0;
|
||||
public $TempHigh = 0.0;
|
||||
public $RainsHigh = 0.0;
|
||||
public $Temps = [];
|
||||
public $Rains = [];
|
||||
public $Rains = [];
|
||||
}
|
||||
|
||||
function translateIconClass($class) {
|
||||
if($class === null) {
|
||||
function translateIconClass($class)
|
||||
{
|
||||
if ($class === null) {
|
||||
return null;
|
||||
}
|
||||
$class = strtolower($class);
|
||||
$postfix = null;
|
||||
if(str_ends_with($class, '_day')) {
|
||||
if (str_ends_with($class, '_day')) {
|
||||
$postfix = 'day';
|
||||
$class = substr($class, 0, strlen($class)-4);
|
||||
} elseif(str_ends_with($class, '_night')) {
|
||||
$class = substr($class, 0, strlen($class) - 4);
|
||||
} elseif (str_ends_with($class, '_night')) {
|
||||
$postfix = 'night';
|
||||
$class = substr($class, 0, strlen($class)-6);
|
||||
$class = substr($class, 0, strlen($class) - 6);
|
||||
}
|
||||
if($class === 'clearsky') {
|
||||
if($postfix === 'night') {
|
||||
if ($class === 'clearsky') {
|
||||
if ($postfix === 'night') {
|
||||
return 'wi-night-clear';
|
||||
}
|
||||
return 'wi-day-sunny';
|
||||
}
|
||||
$src = array(
|
||||
'cloudy'=>'wi-cloudy',
|
||||
'fair'=>'wi-POSTFIX-cloudy',
|
||||
'fog'=>'wi-POSTFIX-fog',
|
||||
'heavyrain'=>'wi-rain',
|
||||
'heavyrainandthunder'=>'wi-POSTFIX-storm-showers',
|
||||
'heavyrainshowers'=>'wi-POSTFIX-rain',
|
||||
'heavyrainshowersandthunder'=>'wi-thunderstorm',
|
||||
'heavysleet'=>'wi-POSTFIX-sleet',
|
||||
'heavysleetandthunder'=>'wi-POSTFIX-sleet-storm',
|
||||
'heavysleetshowers'=>'wi-POSTFIX-sleet',
|
||||
'heavysleetshowersandthunder'=>'wi-POSTFIX-sleet-storm',
|
||||
'heavysnow'=>'wi-POSTFIX-snow',
|
||||
'heavysnowandthunder'=>'wi-POSTFIX-snow-thunderstorm',
|
||||
'heavysnowshowers'=>'wi-POSTFIX-snow',
|
||||
'heavysnowshowersandthunder'=>'wi-POSTFIX-snow-thunderstorm',
|
||||
'lightrain'=>'wi-POSTFIX-rain',
|
||||
'lightrainandthunder'=>'wi-POSTFIX-thunderstorm',
|
||||
'lightrainshowers'=>'wi-POSTFIX-rain',
|
||||
'lightrainshowersandthunder'=>'wi-POSTFIX-thunderstorm',
|
||||
'lightsleet'=>'wi-POSTFIX-rain-mix',
|
||||
'lightsleetandthunder'=>'wi-POSTFIX-thunderstorm',
|
||||
'lightsleetshowers'=>'wi-POSTFIX-rain-mix',
|
||||
'lightsnow'=>'wi-POSTFIX-snow',
|
||||
'lightsnowandthunder'=>'wi-POSTFIX-snow-thunderstorm',
|
||||
'lightsnowshowers'=>'wi-POSTFIX-snow',
|
||||
'lightssleetshowersandthunder'=>'wi-POSTFIX-snow-thunderstorm',
|
||||
'lightssnowshowersandthunder'=>'wi-POSTFIX-snow-thunderstorm',
|
||||
'partlycloudy'=>'wi-POSTFIX-cloudy',
|
||||
'rain'=>'wi-POSTFIX-rain',
|
||||
'rainandthunder'=>'wi-POSTFIX-thunderstorm',
|
||||
'rainshowers'=>'wi-POSTFIX-rain',
|
||||
'rainshowersandthunder'=>'wi-POSTFIX-thunderstorm',
|
||||
'sleet'=>'wi-POSTFIX-rain-mix',
|
||||
'sleetandthunder'=>'wi-POSTFIX-thunderstorm',
|
||||
'sleetshowers'=>'wi-POSTFIX-rain-mix',
|
||||
'sleetshowersandthunder'=>'wi-POSTFIX-thunderstorm',
|
||||
'snow'=>'wi-POSTFIX-snow',
|
||||
'snowandthunder'=>'wi-POSTFIX-snow-thunderstorm',
|
||||
'snowshowers'=>'wi-POSTFIX-snow',
|
||||
'snowshowersandthunder'=>'wi-POSTFIX-snow-thunderstorm',
|
||||
'cloudy' => 'wi-cloudy',
|
||||
'fair' => 'wi-POSTFIX-cloudy',
|
||||
'fog' => 'wi-POSTFIX-fog',
|
||||
'heavyrain' => 'wi-rain',
|
||||
'heavyrainandthunder' => 'wi-POSTFIX-storm-showers',
|
||||
'heavyrainshowers' => 'wi-POSTFIX-rain',
|
||||
'heavyrainshowersandthunder' => 'wi-thunderstorm',
|
||||
'heavysleet' => 'wi-POSTFIX-sleet',
|
||||
'heavysleetandthunder' => 'wi-POSTFIX-sleet-storm',
|
||||
'heavysleetshowers' => 'wi-POSTFIX-sleet',
|
||||
'heavysleetshowersandthunder' => 'wi-POSTFIX-sleet-storm',
|
||||
'heavysnow' => 'wi-POSTFIX-snow',
|
||||
'heavysnowandthunder' => 'wi-POSTFIX-snow-thunderstorm',
|
||||
'heavysnowshowers' => 'wi-POSTFIX-snow',
|
||||
'heavysnowshowersandthunder' => 'wi-POSTFIX-snow-thunderstorm',
|
||||
'lightrain' => 'wi-POSTFIX-rain',
|
||||
'lightrainandthunder' => 'wi-POSTFIX-thunderstorm',
|
||||
'lightrainshowers' => 'wi-POSTFIX-rain',
|
||||
'lightrainshowersandthunder' => 'wi-POSTFIX-thunderstorm',
|
||||
'lightsleet' => 'wi-POSTFIX-rain-mix',
|
||||
'lightsleetandthunder' => 'wi-POSTFIX-thunderstorm',
|
||||
'lightsleetshowers' => 'wi-POSTFIX-rain-mix',
|
||||
'lightsnow' => 'wi-POSTFIX-snow',
|
||||
'lightsnowandthunder' => 'wi-POSTFIX-snow-thunderstorm',
|
||||
'lightsnowshowers' => 'wi-POSTFIX-snow',
|
||||
'lightssleetshowersandthunder' => 'wi-POSTFIX-snow-thunderstorm',
|
||||
'lightssnowshowersandthunder' => 'wi-POSTFIX-snow-thunderstorm',
|
||||
'partlycloudy' => 'wi-POSTFIX-cloudy',
|
||||
'rain' => 'wi-POSTFIX-rain',
|
||||
'rainandthunder' => 'wi-POSTFIX-thunderstorm',
|
||||
'rainshowers' => 'wi-POSTFIX-rain',
|
||||
'rainshowersandthunder' => 'wi-POSTFIX-thunderstorm',
|
||||
'sleet' => 'wi-POSTFIX-rain-mix',
|
||||
'sleetandthunder' => 'wi-POSTFIX-thunderstorm',
|
||||
'sleetshowers' => 'wi-POSTFIX-rain-mix',
|
||||
'sleetshowersandthunder' => 'wi-POSTFIX-thunderstorm',
|
||||
'snow' => 'wi-POSTFIX-snow',
|
||||
'snowandthunder' => 'wi-POSTFIX-snow-thunderstorm',
|
||||
'snowshowers' => 'wi-POSTFIX-snow',
|
||||
'snowshowersandthunder' => 'wi-POSTFIX-snow-thunderstorm',
|
||||
);
|
||||
if(isset($src[$class])) {
|
||||
if (isset($src[$class])) {
|
||||
$ret = $src[$class];
|
||||
if(str_contains($ret,'POSTFIX')) {
|
||||
$ret = str_replace('POSTFIX',($postfix ?? 'day'),$ret);
|
||||
if (str_contains($ret, 'POSTFIX')) {
|
||||
$ret = str_replace('POSTFIX', ($postfix ?? 'day'), $ret);
|
||||
}
|
||||
return $ret;
|
||||
} else {
|
||||
return 'wi-na '.$class;
|
||||
return 'wi-na ' . $class;
|
||||
}
|
||||
}
|
||||
|
||||
function parseWeather($list) {
|
||||
function parseWeather($list)
|
||||
{
|
||||
$maxDays = 5;
|
||||
$numDay = 1;
|
||||
$ret = [];
|
||||
$perday = [];
|
||||
$currDay = '';
|
||||
foreach($list as $entry) {
|
||||
$curr = new WeatherEntry();
|
||||
$curr->Date = new JsonDateTime($entry->time);
|
||||
$curr->DayName = apiFuncs\formatAsDay($curr->Date->format('N'));
|
||||
$curr->Icon = translateIconClass($entry->data->next_12_hours?->summary?->symbol_code ?? null);
|
||||
$curr->TempHigh = $entry->data->instant->details->air_temperature;
|
||||
$curr->TempLow = $entry->data->next_1_hours?->details?->precipitation_amount ?? null;
|
||||
$ret = [];
|
||||
$perday = [];
|
||||
$currDay = '';
|
||||
foreach ($list as $entry) {
|
||||
$curr = new WeatherEntry();
|
||||
$curr->Date = new JsonDateTime($entry->time);
|
||||
$curr->DayName = apiFuncs\formatAsDay($curr->Date->format('N'));
|
||||
$curr->Icon = translateIconClass($entry->data->next_12_hours?->summary?->symbol_code ?? null);
|
||||
$curr->TempHigh = $entry->data->instant->details->air_temperature;
|
||||
$curr->TempLow = $entry->data->next_1_hours?->details?->precipitation_amount ?? null;
|
||||
|
||||
$day = $curr->Date->format('d.n');
|
||||
if($currDay == '') { $currDay = $day; }
|
||||
if($day != $currDay) {
|
||||
if(count($perday) > 0 ) {
|
||||
$day = $curr->Date->format('d.n');
|
||||
if ($currDay == '') {
|
||||
$currDay = $day;
|
||||
}
|
||||
if ($day != $currDay) {
|
||||
if (count($perday) > 0) {
|
||||
$ret[] = ['day' => $currDay, 'data' => summarizeDay($perday)];
|
||||
$numDay++;
|
||||
if($numDay > $maxDays) {
|
||||
if ($numDay > $maxDays) {
|
||||
$currDay = "";
|
||||
$perday = [];
|
||||
break;
|
||||
}
|
||||
}
|
||||
$currDay = $day;
|
||||
}
|
||||
$currDay = $day;
|
||||
$perday = [];
|
||||
$days = [];
|
||||
}
|
||||
$perday[] = $curr;
|
||||
}
|
||||
if($currDay != "") {
|
||||
$ret[] = ['day' => $currDay, 'data' => summarizeDay($perday)];
|
||||
}
|
||||
}
|
||||
$perday[] = $curr;
|
||||
}
|
||||
if ($currDay != "") {
|
||||
$ret[] = ['day' => $currDay, 'data' => summarizeDay($perday)];
|
||||
}
|
||||
|
||||
return $ret;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function summarizeDay($dayArray) {
|
||||
function summarizeDay($dayArray)
|
||||
{
|
||||
// find min/max temp per day, returns one summary entry
|
||||
$ret = new WeatherEntry();
|
||||
$temps = [];
|
||||
|
@ -151,19 +156,19 @@ function summarizeDay($dayArray) {
|
|||
$ret->TempLow = $first->TempHigh; // steht alles in TempHigh.
|
||||
$ret->TempHigh = $first->TempHigh;
|
||||
$ret->RainsHigh = $first->TempLow; // rain steht in TempLow...
|
||||
foreach($dayArray as $entry) {
|
||||
if($entry->TempHigh < $ret->TempLow) {
|
||||
foreach ($dayArray as $entry) {
|
||||
if ($entry->TempHigh < $ret->TempLow) {
|
||||
$ret->TempLow = $entry->TempHigh;
|
||||
}
|
||||
if($entry->TempHigh > $ret->TempHigh) {
|
||||
if ($entry->TempHigh > $ret->TempHigh) {
|
||||
$ret->TempHigh = $entry->TempHigh;
|
||||
}
|
||||
if($entry->TempLow ?? 0.0 > $ret->RainsHigh ?? 0.0) {
|
||||
if ($entry->TempLow ?? 0.0 > $ret->RainsHigh ?? 0.0) {
|
||||
$ret->RainsHigh = $entry->TempLow;
|
||||
}
|
||||
$temps[$entry->Date->format('H:i')] = $entry->TempHigh;
|
||||
$rains[$entry->Date->format('H:i')] = $entry->TempLow;
|
||||
if($ret->Icon == null && $entry->Icon != null) {
|
||||
if ($ret->Icon == null && $entry->Icon != null) {
|
||||
$ret->Icon = translateIconClass($entry->Icon);
|
||||
}
|
||||
}
|
||||
|
@ -174,12 +179,12 @@ function summarizeDay($dayArray) {
|
|||
|
||||
$weatherCache = "cache/weather2.cache";
|
||||
$weatherUrl = "https://api.met.no/weatherapi/locationforecast/2.0/compact";
|
||||
$weatherUrl .= "?altitude=".$config['weather-alt']."&lat=".$config['weather-lat']."&lon=".$config['weather-lon'];
|
||||
$weatherUrl .= "?altitude=" . $config['weather-alt'] . "&lat=" . $config['weather-lat'] . "&lon=" . $config['weather-lon'];
|
||||
try {
|
||||
$weatherContent = json_decode(apiFuncs\cache_contents($weatherUrl, $weatherCache, 10800, true)); // 10800 = 3 Stunden
|
||||
$weatherContent = json_decode(apiFuncs\cache_contents($weatherUrl, $weatherCache, 10800, true)); // 10800 = 3 Stunden
|
||||
} catch (Exception $ex) {
|
||||
// header('Content-Type: application/json');
|
||||
die(json_encode(array('err'=>"error fetching weather data! (".$ex->getMessage().")")));
|
||||
die(json_encode(array('err' => "error fetching weather data! (" . $ex->getMessage() . ")")));
|
||||
}
|
||||
|
||||
$forecast = $weatherContent->properties->timeseries;
|
||||
|
|
|
@ -176,7 +176,7 @@ var waescheVue = new Vue({
|
|||
dow: 0,
|
||||
timer: '',
|
||||
laundrydays: {
|
||||
2 : 'Wäsche?', // Dienstag
|
||||
2: 'Wäsche?', // Dienstag
|
||||
3: 'Wäsche holen' // Mittwoch
|
||||
}
|
||||
},
|
||||
|
@ -187,7 +187,7 @@ var waescheVue = new Vue({
|
|||
updateLaundryText: function () {
|
||||
var dat = new Date();
|
||||
this.dow = dat.getDay();
|
||||
if(!!this.laundrydays[this.dow]) {
|
||||
if (!!this.laundrydays[this.dow]) {
|
||||
this.laundrytext = this.laundrydays[this.dow];
|
||||
} else {
|
||||
this.laundrytext = "";
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
<?php
|
||||
include_once($_SERVER['DOCUMENT_ROOT'].'/inc/funcs.php');
|
||||
include_once($_SERVER['DOCUMENT_ROOT'].'/inc/config.php');
|
||||
include_once($_SERVER['DOCUMENT_ROOT'].'/inc/gotify.php');
|
||||
include_once($_SERVER['DOCUMENT_ROOT'] . '/inc/funcs.php');
|
||||
include_once($_SERVER['DOCUMENT_ROOT'] . '/inc/config.php');
|
||||
include_once($_SERVER['DOCUMENT_ROOT'] . '/inc/gotify.php');
|
||||
|
||||
$debug = true;
|
||||
if(isset($_GET["c"]) && $_GET["c"] == "1") {
|
||||
if (isset($_GET["c"]) && $_GET["c"] == "1") {
|
||||
$debug = false;
|
||||
}
|
||||
$sinceDate = $config['gogs-last-date'];
|
||||
|
@ -19,8 +19,8 @@ $files = array(
|
|||
);
|
||||
|
||||
|
||||
if($debug) {
|
||||
echo '<!doctype html>
|
||||
if ($debug) {
|
||||
echo '<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>gogs changes</title>
|
||||
|
@ -45,61 +45,61 @@ $sinceParam = $sinceDate->format('c');
|
|||
$hasOutput = false;
|
||||
$pushMsg = '';
|
||||
|
||||
foreach($files as $f) {
|
||||
foreach ($files as $f) {
|
||||
$needsHeader = true;
|
||||
$pushFile = '';
|
||||
$url = $commitsUrl."?path=".$f."&since=".$sinceParam;
|
||||
$url = $commitsUrl . "?path=" . $f . "&since=" . $sinceParam;
|
||||
$commits = json_decode(apiFuncs\xsget($url));
|
||||
if(is_array($commits)) {
|
||||
foreach($commits as $e) {
|
||||
if (is_array($commits)) {
|
||||
foreach ($commits as $e) {
|
||||
$dt = new DateTime($e->commit->author->date);
|
||||
if($needsHeader && $debug) {
|
||||
if ($needsHeader && $debug) {
|
||||
echo "<div class=\"card border-info mb-3\">\n";
|
||||
echo "<div class=\"card-header\">".$f."</div>\n";
|
||||
echo "<div class=\"card-header\">" . $f . "</div>\n";
|
||||
$needsHeader = false;
|
||||
}
|
||||
if($debug) {
|
||||
if ($debug) {
|
||||
echo "<div class=\"card-body\">\n";
|
||||
echo "<p class=\"card-text\">".$e->commit->message ."\n<br></p>";
|
||||
echo "<a class=\"btn btn-lg btn-info\" role=\"button\" href=\"".$e->html_url."\" title=\"View commit\">View commit</a>";
|
||||
echo "</div><div class=\"card-footer\"><small class=\"text-muted\">".$dt->format("d.m.y H:i:s")."</small></div>";
|
||||
echo "<p class=\"card-text\">" . $e->commit->message . "\n<br></p>";
|
||||
echo "<a class=\"btn btn-lg btn-info\" role=\"button\" href=\"" . $e->html_url . "\" title=\"View commit\">View commit</a>";
|
||||
echo "</div><div class=\"card-footer\"><small class=\"text-muted\">" . $dt->format("d.m.y H:i:s") . "</small></div>";
|
||||
} else {
|
||||
$pushFile = $f;
|
||||
}
|
||||
$hasOutput = true;
|
||||
}
|
||||
if(!$debug && $pushFile !== '') {
|
||||
if($pushMsg == '') {
|
||||
if (!$debug && $pushFile !== '') {
|
||||
if ($pushMsg == '') {
|
||||
$pushMsg = "The following gogs templates have changes: \n";
|
||||
}
|
||||
$pushMsg .= "- $f ";
|
||||
}
|
||||
}
|
||||
if(!$needsHeader && $debug) {
|
||||
if (!$needsHeader && $debug) {
|
||||
echo "</div>";
|
||||
}
|
||||
}
|
||||
if($hasOutput == false && $debug) {
|
||||
if ($hasOutput == false && $debug) {
|
||||
echo "<div class=\"card border-success mb-3\">\n";
|
||||
echo "<div class=\"card-header\">Nothing changed</div>\n";
|
||||
echo "<div class=\"card-body\">\n";
|
||||
echo "nothing changed since ".$sinceDate->format("d.m.y H:i");
|
||||
echo "nothing changed since " . $sinceDate->format("d.m.y H:i");
|
||||
echo "</div></div>";
|
||||
}
|
||||
|
||||
if(($debug == false) && $pushMsg !== '') {
|
||||
if (($debug == false) && $pushMsg !== '') {
|
||||
$push = new Gotify();
|
||||
$pushMsg .= "\n\n[details](https://api.mayer.life/gogs/check_gogs_changes.php)";
|
||||
if($push->send($config["gotify-url"], $config["gotify-token"], "gogs template changed", $pushMsg)) {
|
||||
print "++OK";
|
||||
} else {
|
||||
print "--ERROR ".$gotify->getLastStatus();
|
||||
}
|
||||
if ($push->send($config["gotify-url"], $config["gotify-token"], "gogs template changed", $pushMsg)) {
|
||||
print "++OK";
|
||||
} else {
|
||||
print "--ERROR " . $gotify->getLastStatus();
|
||||
}
|
||||
}
|
||||
|
||||
if($debug) {
|
||||
if ($debug) {
|
||||
echo '</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,20 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace apiFuncs {
|
||||
|
||||
function xsget($url) {
|
||||
function xsget($url)
|
||||
{
|
||||
$fake_user_agent = "Mozilla/5.0 (Windows NT 10.2; Win64; x64) AppleWebKit/666.66 (KHTML, like Gecko) Chrome/66.6.6666.66 Safari/666.66";
|
||||
\ini_set('user_agent', $fake_user_agent);
|
||||
$ret = \file_get_contents($url);
|
||||
if($ret === false) { // error retrieving $url
|
||||
if ($ret === false) { // error retrieving $url
|
||||
throw new \Exception("Error contacting $url");
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function cache_contents($url, $file, $maxAge, $statusInHeader = false) {
|
||||
if(\file_exists($file) && (\time() - \filemtime($file) <= $maxAge)) {
|
||||
|
||||
function cache_contents($url, $file, $maxAge, $statusInHeader = false)
|
||||
{
|
||||
if (\file_exists($file) && (\time() - \filemtime($file) <= $maxAge)) {
|
||||
// cache is still fresh
|
||||
if($statusInHeader) {
|
||||
if ($statusInHeader) {
|
||||
header('X-CacheStatus: cached');
|
||||
} else {
|
||||
echo "<!--Cache status: cached-->";
|
||||
|
@ -24,7 +27,7 @@ namespace apiFuncs {
|
|||
// no cache, create one
|
||||
$cache = xsget($url, true);
|
||||
\file_put_contents($file, $cache);
|
||||
if($statusInHeader) {
|
||||
if ($statusInHeader) {
|
||||
header('X-CacheStatus: fresh');
|
||||
} else {
|
||||
echo "<!--Cache status: fresh-->";
|
||||
|
@ -32,8 +35,9 @@ namespace apiFuncs {
|
|||
return $cache;
|
||||
}
|
||||
}
|
||||
|
||||
function formatAsDay($dayNum) {
|
||||
|
||||
function formatAsDay($dayNum)
|
||||
{
|
||||
switch ($dayNum) {
|
||||
case 1:
|
||||
return 'Mo';
|
||||
|
@ -54,30 +58,36 @@ namespace apiFuncs {
|
|||
}
|
||||
}
|
||||
|
||||
function get($key, $default_value = '') {
|
||||
function get($key, $default_value = '')
|
||||
{
|
||||
return isset($_GET[$key]) ? $_GET[$key] : $default_value;
|
||||
}
|
||||
function post($key, $default_value = '') {
|
||||
return isset($_POST[$key]) ? $_POST[$key] : $default_value;
|
||||
|
||||
function post($key, $default_value = '')
|
||||
{
|
||||
return isset($_POST[$key]) ? $_POST[$key] : $default_value;
|
||||
}
|
||||
function getpost($key, $default_value = '') {
|
||||
$ret = get($key,$default_value);
|
||||
if($ret == $default_value) {
|
||||
$ret = post($key,$default_value);
|
||||
}
|
||||
return $ret;
|
||||
|
||||
function getpost($key, $default_value = '')
|
||||
{
|
||||
$ret = get($key, $default_value);
|
||||
if ($ret == $default_value) {
|
||||
$ret = post($key, $default_value);
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
function getNumParam($key, $default_value=0, $maxVal=255, $minVal=0) {
|
||||
$param = \trim(getpost($key));
|
||||
if($param != "") {
|
||||
if(\preg_match("#^([0-9]*)$#", $param, $match) && $match[0] !== '') {
|
||||
$paramInt = \intval($match[0]);
|
||||
if(($paramInt >= $minVal) && ($paramInt <= $maxVal)) {
|
||||
return $paramInt;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $default_value;
|
||||
|
||||
function getNumParam($key, $default_value = 0, $maxVal = 255, $minVal = 0)
|
||||
{
|
||||
$param = \trim(getpost($key));
|
||||
if ($param != "") {
|
||||
if (\preg_match("#^([0-9]*)$#", $param, $match) && $match[0] !== '') {
|
||||
$paramInt = \intval($match[0]);
|
||||
if (($paramInt >= $minVal) && ($paramInt <= $maxVal)) {
|
||||
return $paramInt;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $default_value;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,14 +1,16 @@
|
|||
<?php
|
||||
|
||||
class Gotify {
|
||||
|
||||
class Gotify
|
||||
{
|
||||
private $laststatus;
|
||||
|
||||
public function getLastStatus() {
|
||||
public function getLastStatus()
|
||||
{
|
||||
return $this->laststatus;
|
||||
}
|
||||
|
||||
public function send($gotifyurl, $token, $title, $message) {
|
||||
public function send($gotifyurl, $token, $title, $message)
|
||||
{
|
||||
$data = [
|
||||
"title" => $title,
|
||||
"message" => $message,
|
||||
|
@ -19,33 +21,31 @@ class Gotify {
|
|||
]
|
||||
]
|
||||
];
|
||||
$data_string = json_encode($data);
|
||||
$dataString = json_encode($data);
|
||||
|
||||
$url = $gotifyurl . "?token=$token";
|
||||
|
||||
$headers = [
|
||||
"Content-Type: application/json; charset=utf-8"
|
||||
"Content-Type: application/json; charset=utf-8"
|
||||
];
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers );
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $dataString);
|
||||
|
||||
$result = curl_exec($ch);
|
||||
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
|
||||
curl_close ($ch);
|
||||
curl_close($ch);
|
||||
$this->laststatus = $code;
|
||||
|
||||
if($code == "200") {
|
||||
|
||||
if ($code == "200") {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,14 +5,14 @@ namespace originHelper {
|
|||
{
|
||||
public static $current = '';
|
||||
|
||||
public static function check(array $allowed_origins)
|
||||
public static function check(array $allowedOrigins)
|
||||
{
|
||||
if (isset($_SERVER["HTTP_ORIGIN"])) {
|
||||
$org = $_SERVER["HTTP_ORIGIN"];
|
||||
if (str_ends_with($org, "/")) {
|
||||
$org = \rtrim($org, "/");
|
||||
}
|
||||
if (\in_array($org, $allowed_origins)) {
|
||||
if (\in_array($org, $allowedOrigins)) {
|
||||
\header("Access-Control-Allow-Origin: " . $_SERVER["HTTP_ORIGIN"]);
|
||||
\header("Access-Control-Max-Age: 86400");
|
||||
} else {
|
||||
|
|
102
test/index.htm
102
test/index.htm
|
@ -2,62 +2,66 @@
|
|||
<html lang="de">
|
||||
|
||||
<head>
|
||||
<title>Test</title>
|
||||
<meta charset="utf-8">
|
||||
<link rel="icon" href="/favicon.svg">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=3.0">
|
||||
<link rel="stylesheet" href="/style.css">
|
||||
<noscript>
|
||||
<link rel="stylesheet" href="https://gma.name/fonts/opensans.css" />
|
||||
</noscript>
|
||||
<title>Test</title>
|
||||
<meta charset="utf-8">
|
||||
<link rel="icon" href="/favicon.svg">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=3.0">
|
||||
<link rel="stylesheet" href="/style.css">
|
||||
<noscript>
|
||||
<link rel="stylesheet" href="https://gma.name/fonts/opensans.css" />
|
||||
</noscript>
|
||||
</head>
|
||||
|
||||
<body class="bg-gray-100 dark:bg-gray-900 font-opensans">
|
||||
<div class="container mx-auto sm:px-4">
|
||||
<h2 class="text-3xl px-4 my-3 text-gray-900 dark:text-gray-100 md:text-5xl">Verbindung</h2>
|
||||
<div class="flex flex-wrap">
|
||||
<div class="w-full xl:w-1/4 px-4 lg:w-1/3 mb-3">
|
||||
<div class="relative flex flex-col min-w-0 rounded break-words border border-white dark:border-black bg-green-300 dark:bg-green-700">
|
||||
<div class="flex-auto p-6">
|
||||
<div class="flex flex-wrap ">
|
||||
<div class="w-1/3 lg:w-full px-4"><a href="https://gma.name" title="Gottfried Mayer"><img
|
||||
class="max-w-full h-auto border border-gray-800 dark:border-gray-200 bg-gray-200 dark:bg-gray-800 rounded p-1 mb-3 mx-auto block"
|
||||
src="/avatar.jpg" alt="Gottfried Mayer" title="Gottfried Mayer"></a></div>
|
||||
<div class="w-2/3 lg:w-full px-4 text-gray-100 dark:text-gray-900">
|
||||
<form>
|
||||
<div class="mb-3"><label for="status" class="form-label text-black dark:text-white">Die
|
||||
Verbindung</label>
|
||||
<div class="relative flex items-stretch w-full">
|
||||
<div class="block appearance-none w-full py-1 px-2 mb-1 text-base leading-normal bg-gray-600 dark:bg-gray-400 border border-gray-300 dark:border-gray-700 border-r-0 rounded-l"
|
||||
id="status">funktioniert</div>
|
||||
<span
|
||||
class="text-green-500 border border-gray-300 dark:border-gray-700 border-l-0 rounded-r py-1 px-3 mb-1 bg-gray-200 dark:bg-gray-800">✔</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mb-3"><label for="load" class="text-black dark:text-white">Ladezeit</label>
|
||||
<div class="block appearance-none w-full py-1 px-2 mb-1 text-base leading-normal bg-gray-600 dark:bg-gray-400 border border-gray-300 dark:border-gray-700 rounded"
|
||||
id="load">…</div>
|
||||
</div>
|
||||
<div class="mb-3"><label for="ip" class="text-black dark:text-white">IP-Adresse</label>
|
||||
<div
|
||||
class="block appearance-none w-full py-1 px-2 mb-1 text-base leading-normal bg-gray-600 dark:bg-gray-400 border border-gray-300 dark:border-gray-700 rounded cursor-pointer">
|
||||
<a id="ip" class="" href="#">lade …</a>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div class="container mx-auto sm:px-4">
|
||||
<h2 class="text-3xl px-4 my-3 text-gray-900 dark:text-gray-100 md:text-5xl">Verbindung</h2>
|
||||
<div class="flex flex-wrap">
|
||||
<div class="w-full xl:w-1/4 px-4 lg:w-1/3 mb-3">
|
||||
<div
|
||||
class="relative flex flex-col min-w-0 rounded break-words border border-white dark:border-black bg-green-300 dark:bg-green-700">
|
||||
<div class="flex-auto p-6">
|
||||
<div class="flex flex-wrap ">
|
||||
<div class="w-1/3 lg:w-full px-4"><a href="https://gma.name" title="Gottfried Mayer"><img
|
||||
class="max-w-full h-auto border border-gray-800 dark:border-gray-200 bg-gray-200 dark:bg-gray-800 rounded p-1 mb-3 mx-auto block"
|
||||
src="/avatar.jpg" alt="Gottfried Mayer" title="Gottfried Mayer"></a></div>
|
||||
<div class="w-2/3 lg:w-full px-4 text-gray-100 dark:text-gray-900">
|
||||
<form>
|
||||
<div class="mb-3"><label for="status" class="form-label text-black dark:text-white">Die
|
||||
Verbindung</label>
|
||||
<div class="relative flex items-stretch w-full">
|
||||
<div
|
||||
class="block appearance-none w-full py-1 px-2 mb-1 text-base leading-normal bg-gray-600 dark:bg-gray-400 border border-gray-300 dark:border-gray-700 border-r-0 rounded-l"
|
||||
id="status">funktioniert</div>
|
||||
<span
|
||||
class="text-green-500 border border-gray-300 dark:border-gray-700 border-l-0 rounded-r py-1 px-3 mb-1 bg-gray-200 dark:bg-gray-800">✔</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="xl:w-3/4 px-4 lg:w-2/3">
|
||||
<div class="relative flex flex-col min-w-0 rounded break-words border border-1 border-white dark:border-black mb-3">
|
||||
<img src="/bg.jpg" alt="Schottland 2019" title="Schottland 2019" class="w-full rounded">
|
||||
</div>
|
||||
</div>
|
||||
<div class="mb-3"><label for="load" class="text-black dark:text-white">Ladezeit</label>
|
||||
<div
|
||||
class="block appearance-none w-full py-1 px-2 mb-1 text-base leading-normal bg-gray-600 dark:bg-gray-400 border border-gray-300 dark:border-gray-700 rounded"
|
||||
id="load">…</div>
|
||||
</div>
|
||||
<div class="mb-3"><label for="ip" class="text-black dark:text-white">IP-Adresse</label>
|
||||
<div
|
||||
class="block appearance-none w-full py-1 px-2 mb-1 text-base leading-normal bg-gray-600 dark:bg-gray-400 border border-gray-300 dark:border-gray-700 rounded cursor-pointer">
|
||||
<a id="ip" class="" href="#">lade …</a>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="xl:w-3/4 px-4 lg:w-2/3">
|
||||
<div
|
||||
class="relative flex flex-col min-w-0 rounded break-words border border-1 border-white dark:border-black mb-3">
|
||||
<img src="/bg.jpg" alt="Schottland 2019" title="Schottland 2019" class="w-full rounded">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="/script.js"></script>
|
||||
</div>
|
||||
<script src="/script.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -15,8 +15,8 @@ function truncate(ip, maxlen = 20) {
|
|||
|
||||
const openIpLink = (event) => {
|
||||
const trg = event.target;
|
||||
if(trg) {
|
||||
if(trg.id === 'ip') {
|
||||
if (trg) {
|
||||
if (trg.id === 'ip') {
|
||||
return;
|
||||
} else {
|
||||
const e = document.getElementById('ip');
|
||||
|
|
|
@ -118,6 +118,3 @@ class ChannelParser {
|
|||
return $ret;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
//include_once($_SERVER['DOCUMENT_ROOT'].'/inc/config.php');
|
||||
include_once($_SERVER['DOCUMENT_ROOT'].'/inc/funcs.php');
|
||||
include_once($_SERVER['DOCUMENT_ROOT'] . '/inc/funcs.php');
|
||||
|
||||
$debug = true;
|
||||
|
||||
|
@ -13,18 +13,21 @@ $commitDate = new DateTime($commits[0]->commit->author->date);
|
|||
$commitDiff = $commitDate->diff(new DateTime());
|
||||
$numDaysSinceCommit = $commitDiff->format("%r%a");
|
||||
|
||||
if($debug == true) { echo "<pre>"; }
|
||||
if ($debug == true) {
|
||||
echo "<pre>";
|
||||
}
|
||||
|
||||
if($numDaysSinceCommit > 5) {
|
||||
if ($numDaysSinceCommit > 5) {
|
||||
echo "it has been too long! ($numDaysSinceCommit)\n";
|
||||
//todo: send some notification...
|
||||
|
||||
} else {
|
||||
if($debug == true) { echo "it has only been $numDaysSinceCommit days, all is good."; }
|
||||
if ($debug == true) {
|
||||
echo "it has only been $numDaysSinceCommit days, all is good.";
|
||||
}
|
||||
}
|
||||
|
||||
//echo "days since last commit: $numDaysSinceCommit \n";
|
||||
|
||||
if($debug == true) { echo "</pre>"; }
|
||||
|
||||
|
||||
if ($debug == true) {
|
||||
echo "</pre>";
|
||||
}
|
||||
|
|
|
@ -74,7 +74,4 @@ function gzCompressFile($source, $dest = "", $level = 9){
|
|||
return false;
|
||||
else
|
||||
return $dest;
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
}
|
||||
|
|
|
@ -30,5 +30,3 @@ if($ret == "") {
|
|||
}
|
||||
|
||||
readgzfile($file);
|
||||
|
||||
?>
|
|
@ -42,5 +42,3 @@ if($ret == "") {
|
|||
}
|
||||
|
||||
echo $ret;
|
||||
|
||||
?>
|
|
@ -46,5 +46,3 @@ if($ret == "") {
|
|||
}
|
||||
|
||||
echo $ret;
|
||||
|
||||
?>
|
|
@ -1,13 +1,13 @@
|
|||
<?php
|
||||
|
||||
require_once('workoutdefinition.class.php');
|
||||
include_once($_SERVER['DOCUMENT_ROOT'].'/inc/config.php');
|
||||
include_once($_SERVER['DOCUMENT_ROOT'].'/inc/gotify.php');
|
||||
include_once($_SERVER['DOCUMENT_ROOT'] . '/inc/config.php');
|
||||
include_once($_SERVER['DOCUMENT_ROOT'] . '/inc/gotify.php');
|
||||
|
||||
|
||||
$debug = false;
|
||||
|
||||
if($debug) {
|
||||
if ($debug) {
|
||||
ini_set('display_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ $plans = array();
|
|||
foreach ($config['workout'] as $workout) {
|
||||
$staticRep = null;
|
||||
$dynamicRep = null;
|
||||
if(is_array($workout['reps'])) {
|
||||
if (is_array($workout['reps'])) {
|
||||
$tempReps = $workout['reps'];
|
||||
$dynamicRep = new WorkoutPlanPolynom($tempReps[0], $tempReps[1], $tempReps[2], $tempReps[3], $tempReps[4], $tempReps[5]);
|
||||
} else {
|
||||
|
@ -27,8 +27,8 @@ foreach ($config['workout'] as $workout) {
|
|||
$plans[] = new WorkoutDefinition($workout['start'], $workout['desc'], new WorkoutInterval($workout['interval'], $workout['workout']), $staticRep, $dynamicRep);
|
||||
}
|
||||
|
||||
if($debug) {
|
||||
echo "<!DOCTYPE html><html><head><title>push</title></head><body>";
|
||||
if ($debug) {
|
||||
echo "<!DOCTYPE html><html><head><title>push</title></head><body>";
|
||||
}
|
||||
|
||||
$todo = '';
|
||||
|
@ -36,25 +36,25 @@ $note = '';
|
|||
|
||||
$now = new DateTime();
|
||||
|
||||
foreach($plans as $plan) {
|
||||
foreach ($plans as $plan) {
|
||||
$curr = $plan->calculateFor($now);
|
||||
if($curr) {
|
||||
if($todo) {
|
||||
if ($curr) {
|
||||
if ($todo) {
|
||||
$todo .= $txt_and;
|
||||
}
|
||||
$todo .= $curr;
|
||||
}
|
||||
}
|
||||
|
||||
if($debug) {
|
||||
echo "<pre>".$todo."</pre>";
|
||||
if ($debug) {
|
||||
echo "<pre>" . $todo . "</pre>";
|
||||
} else {
|
||||
if($todo != '') {
|
||||
if ($todo != '') {
|
||||
$push = new Gotify();
|
||||
if($push->send($config["gotify-url"], $config["gotify-token-workout"], "Workout!", $todo)) {
|
||||
if ($push->send($config["gotify-url"], $config["gotify-token-workout"], "Workout!", $todo)) {
|
||||
print "ok";
|
||||
} else {
|
||||
print "error ".$gotify->getLastStatus();
|
||||
print "error " . $gotify->getLastStatus();
|
||||
}
|
||||
} else {
|
||||
print "ok";
|
||||
|
|
|
@ -1,22 +1,27 @@
|
|||
<?php
|
||||
require_once('workoutplanpolynom.class.php');
|
||||
|
||||
class WorkoutInterval {
|
||||
class WorkoutInterval
|
||||
{
|
||||
private int $runtime;
|
||||
private int $workout;
|
||||
public function __construct(int $runtime, int $workout) {
|
||||
public function __construct(int $runtime, int $workout)
|
||||
{
|
||||
$this->runtime = $runtime;
|
||||
$this->workout = $workout;
|
||||
}
|
||||
public function getRuntime() {
|
||||
public function getRuntime()
|
||||
{
|
||||
return $this->runtime;
|
||||
}
|
||||
public function getWorkout() {
|
||||
public function getWorkout()
|
||||
{
|
||||
return $this->workout;
|
||||
}
|
||||
}
|
||||
|
||||
class WorkoutDefinition {
|
||||
class WorkoutDefinition
|
||||
{
|
||||
private \DateTime $startDate;
|
||||
private string $description;
|
||||
private WorkoutInterval $interval;
|
||||
|
@ -37,22 +42,25 @@ class WorkoutDefinition {
|
|||
$this->workoutCalculated = $workoutCalculated;
|
||||
}
|
||||
|
||||
public function getStartDate() {
|
||||
public function getStartDate()
|
||||
{
|
||||
return $this->startDate;
|
||||
}
|
||||
public function getDescription() {
|
||||
public function getDescription()
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
public function calculateFor(\DateTime $date) {
|
||||
public function calculateFor(\DateTime $date)
|
||||
{
|
||||
$dayno = $date->diff($this->startDate)->days % $this->interval->getRuntime();
|
||||
$ret = "";
|
||||
if($dayno < $this->interval->getWorkout()) {
|
||||
if($this->workoutFixed) {
|
||||
$ret .= $this->workoutFixed." ";
|
||||
} else if($this->workoutCalculated) {
|
||||
if ($dayno < $this->interval->getWorkout()) {
|
||||
if ($this->workoutFixed) {
|
||||
$ret .= $this->workoutFixed . " ";
|
||||
} else if ($this->workoutCalculated) {
|
||||
$dayForCalculated = $date->diff($this->startDate)->days;
|
||||
$ret .= $this->workoutCalculated->calc($dayForCalculated)." ";
|
||||
if($this->workoutCalculated->isPastEndDay($dayForCalculated)) {
|
||||
$ret .= $this->workoutCalculated->calc($dayForCalculated) . " ";
|
||||
if ($this->workoutCalculated->isPastEndDay($dayForCalculated)) {
|
||||
$ret .= "(Plan beendet.) ";
|
||||
}
|
||||
} else {
|
||||
|
@ -63,4 +71,3 @@ class WorkoutDefinition {
|
|||
return $ret;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,64 +1,67 @@
|
|||
<?php
|
||||
|
||||
class WorkoutPlanPolynom {
|
||||
class WorkoutPlanPolynom
|
||||
{
|
||||
private $a;
|
||||
private $b;
|
||||
private $c;
|
||||
private $maxVal;
|
||||
private $maxAmt;
|
||||
|
||||
public function __construct(
|
||||
private $b;
|
||||
private $c;
|
||||
private $maxVal;
|
||||
private $maxAmt;
|
||||
|
||||
public function __construct(
|
||||
int $startDayNum,
|
||||
int $startAmount,
|
||||
int $midDayNum,
|
||||
int $midAmount,
|
||||
int $endDayNum,
|
||||
int $endAmount,
|
||||
) {
|
||||
$matrix = array(
|
||||
array(pow($startDayNum,2),$startDayNum,1,$startAmount),
|
||||
array(pow($midDayNum,2),$midDayNum,1,$midAmount),
|
||||
array(pow($endDayNum,2),$endDayNum,1,$endAmount)
|
||||
);
|
||||
$this->maxVal = $endDayNum;
|
||||
$this->maxAmt = $endAmount;
|
||||
$denom = ($matrix[0][0] * $matrix[1][1] * $matrix[2][2]) +
|
||||
($matrix[0][1] * $matrix[1][2] * $matrix[2][0]) +
|
||||
($matrix[0][2] * $matrix[1][0] * $matrix[2][1]) -
|
||||
($matrix[0][2] * $matrix[1][1] * $matrix[2][0]) -
|
||||
($matrix[0][0] * $matrix[1][2] * $matrix[2][1]) -
|
||||
($matrix[0][1] * $matrix[1][0] * $matrix[2][2]);
|
||||
$anum = ($matrix[0][3] * $matrix[1][1] * $matrix[2][2]) +
|
||||
($matrix[0][1] * $matrix[1][2] * $matrix[2][3]) +
|
||||
($matrix[0][2] * $matrix[1][3] * $matrix[2][1]) -
|
||||
($matrix[0][2] * $matrix[1][1] * $matrix[2][3]) -
|
||||
($matrix[0][3] * $matrix[1][2] * $matrix[2][1]) -
|
||||
($matrix[0][1] * $matrix[1][3] * $matrix[2][2]);
|
||||
$bnum = ($matrix[0][0] * $matrix[1][3] * $matrix[2][2]) +
|
||||
($matrix[0][3] * $matrix[1][2] * $matrix[2][0]) +
|
||||
($matrix[0][2] * $matrix[1][0] * $matrix[2][3]) -
|
||||
($matrix[0][2] * $matrix[1][3] * $matrix[2][0]) -
|
||||
($matrix[0][0] * $matrix[1][2] * $matrix[2][3]) -
|
||||
($matrix[0][3] * $matrix[1][0] * $matrix[2][2]);
|
||||
$cnum = ($matrix[0][0] * $matrix[1][1] * $matrix[2][3]) +
|
||||
($matrix[0][1] * $matrix[1][3] * $matrix[2][0]) +
|
||||
($matrix[0][3] * $matrix[1][0] * $matrix[2][1]) -
|
||||
($matrix[0][3] * $matrix[1][1] * $matrix[2][0]) -
|
||||
($matrix[0][0] * $matrix[1][3] * $matrix[2][1]) -
|
||||
($matrix[0][1] * $matrix[1][0] * $matrix[2][3]);
|
||||
$this->a = $anum / $denom;
|
||||
$this->b = $bnum / $denom;
|
||||
$this->c = $cnum / $denom;
|
||||
}
|
||||
) {
|
||||
$matrix = array(
|
||||
array(pow($startDayNum, 2), $startDayNum, 1, $startAmount),
|
||||
array(pow($midDayNum, 2), $midDayNum, 1, $midAmount),
|
||||
array(pow($endDayNum, 2), $endDayNum, 1, $endAmount)
|
||||
);
|
||||
$this->maxVal = $endDayNum;
|
||||
$this->maxAmt = $endAmount;
|
||||
$denom = ($matrix[0][0] * $matrix[1][1] * $matrix[2][2]) +
|
||||
($matrix[0][1] * $matrix[1][2] * $matrix[2][0]) +
|
||||
($matrix[0][2] * $matrix[1][0] * $matrix[2][1]) -
|
||||
($matrix[0][2] * $matrix[1][1] * $matrix[2][0]) -
|
||||
($matrix[0][0] * $matrix[1][2] * $matrix[2][1]) -
|
||||
($matrix[0][1] * $matrix[1][0] * $matrix[2][2]);
|
||||
$anum = ($matrix[0][3] * $matrix[1][1] * $matrix[2][2]) +
|
||||
($matrix[0][1] * $matrix[1][2] * $matrix[2][3]) +
|
||||
($matrix[0][2] * $matrix[1][3] * $matrix[2][1]) -
|
||||
($matrix[0][2] * $matrix[1][1] * $matrix[2][3]) -
|
||||
($matrix[0][3] * $matrix[1][2] * $matrix[2][1]) -
|
||||
($matrix[0][1] * $matrix[1][3] * $matrix[2][2]);
|
||||
$bnum = ($matrix[0][0] * $matrix[1][3] * $matrix[2][2]) +
|
||||
($matrix[0][3] * $matrix[1][2] * $matrix[2][0]) +
|
||||
($matrix[0][2] * $matrix[1][0] * $matrix[2][3]) -
|
||||
($matrix[0][2] * $matrix[1][3] * $matrix[2][0]) -
|
||||
($matrix[0][0] * $matrix[1][2] * $matrix[2][3]) -
|
||||
($matrix[0][3] * $matrix[1][0] * $matrix[2][2]);
|
||||
$cnum = ($matrix[0][0] * $matrix[1][1] * $matrix[2][3]) +
|
||||
($matrix[0][1] * $matrix[1][3] * $matrix[2][0]) +
|
||||
($matrix[0][3] * $matrix[1][0] * $matrix[2][1]) -
|
||||
($matrix[0][3] * $matrix[1][1] * $matrix[2][0]) -
|
||||
($matrix[0][0] * $matrix[1][3] * $matrix[2][1]) -
|
||||
($matrix[0][1] * $matrix[1][0] * $matrix[2][3]);
|
||||
$this->a = $anum / $denom;
|
||||
$this->b = $bnum / $denom;
|
||||
$this->c = $cnum / $denom;
|
||||
}
|
||||
|
||||
public function calc(int $dayNum) {
|
||||
if($this->isPastEndDay($dayNum)) {
|
||||
return $this->maxAmt;
|
||||
}
|
||||
return round(($this->a * pow($dayNum,2)) + ($this->b * $dayNum) + $this->c);
|
||||
}
|
||||
public function calc(int $dayNum)
|
||||
{
|
||||
if ($this->isPastEndDay($dayNum)) {
|
||||
return $this->maxAmt;
|
||||
}
|
||||
return round(($this->a * pow($dayNum, 2)) + ($this->b * $dayNum) + $this->c);
|
||||
}
|
||||
|
||||
public function isPastEndDay(int $dayNum) {
|
||||
public function isPastEndDay(int $dayNum)
|
||||
{
|
||||
return ($dayNum >= $this->maxVal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue