@@ -8,7 +8,7 @@ |
||
| 8 | 8 | "weather" => [ |
| 9 | 9 | "active" => false, |
| 10 | 10 | "shared" => true, |
| 11 | - "callback" => function () {
|
|
| 11 | + "callback" => function() {
|
|
| 12 | 12 | $weather = new \Anax\Model\Weather(); |
| 13 | 13 | $cfg = $this->get("configuration");
|
| 14 | 14 | $config = $cfg->load("apiKey.php");
|
@@ -72,47 +72,47 @@ |
||
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | public function getWeatherMultiCurl($when, $lat, $lon) : array |
| 75 | - { |
|
| 76 | - $dates = []; |
|
| 77 | - $now = time(); |
|
| 78 | - $url = "https://api.darksky.net/forecast/{$this->darkskyKey}/{$lon},{$lat}"; |
|
| 75 | + { |
|
| 76 | + $dates = []; |
|
| 77 | + $now = time(); |
|
| 78 | + $url = "https://api.darksky.net/forecast/{$this->darkskyKey}/{$lon},{$lat}"; |
|
| 79 | 79 | |
| 80 | - if ($when == "past") { |
|
| 81 | - for ($i = 0; $i < 30; $i++) { |
|
| 82 | - $now -= 86400; |
|
| 83 | - $dates[] = $now; |
|
| 84 | - } |
|
| 85 | - } elseif($when == "future") { |
|
| 86 | - for ($i = 0; $i < 7; $i++) { |
|
| 80 | + if ($when == "past") { |
|
| 81 | + for ($i = 0; $i < 30; $i++) { |
|
| 82 | + $now -= 86400; |
|
| 83 | + $dates[] = $now; |
|
| 84 | + } |
|
| 85 | + } elseif($when == "future") { |
|
| 86 | + for ($i = 0; $i < 7; $i++) { |
|
| 87 | 87 | $now += 86400; |
| 88 | 88 | $dates[] = $now; |
| 89 | 89 | } |
| 90 | - } else { |
|
| 90 | + } else { |
|
| 91 | 91 | return [ |
| 92 | - "error" => "select a time", |
|
| 92 | + "error" => "select a time", |
|
| 93 | 93 | ]; |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - $mh = curl_multi_init(); |
|
| 97 | - $chAll = []; |
|
| 98 | - foreach ($dates as $days) { |
|
| 99 | - $ch = curl_init("$url,{$days}?lang=sv&units=si"); |
|
| 100 | - curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER => true]); |
|
| 101 | - curl_multi_add_handle($mh, $ch); |
|
| 102 | - $chAll[] = $ch; |
|
| 103 | - } |
|
| 104 | - $running = null; |
|
| 105 | - do { |
|
| 106 | - curl_multi_exec($mh, $running); |
|
| 107 | - } while ($running); |
|
| 108 | - foreach ($chAll as $ch) { |
|
| 109 | - curl_multi_remove_handle($mh, $ch); |
|
| 110 | - } |
|
| 111 | - $response = []; |
|
| 112 | - foreach ($chAll as $ch) { |
|
| 113 | - $data = curl_multi_getcontent($ch); |
|
| 114 | - $response[] = json_decode($data, true); |
|
| 115 | - } |
|
| 116 | - return $response; |
|
| 117 | - } |
|
| 96 | + $mh = curl_multi_init(); |
|
| 97 | + $chAll = []; |
|
| 98 | + foreach ($dates as $days) { |
|
| 99 | + $ch = curl_init("$url,{$days}?lang=sv&units=si"); |
|
| 100 | + curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER => true]); |
|
| 101 | + curl_multi_add_handle($mh, $ch); |
|
| 102 | + $chAll[] = $ch; |
|
| 103 | + } |
|
| 104 | + $running = null; |
|
| 105 | + do { |
|
| 106 | + curl_multi_exec($mh, $running); |
|
| 107 | + } while ($running); |
|
| 108 | + foreach ($chAll as $ch) { |
|
| 109 | + curl_multi_remove_handle($mh, $ch); |
|
| 110 | + } |
|
| 111 | + $response = []; |
|
| 112 | + foreach ($chAll as $ch) { |
|
| 113 | + $data = curl_multi_getcontent($ch); |
|
| 114 | + $response[] = json_decode($data, true); |
|
| 115 | + } |
|
| 116 | + return $response; |
|
| 117 | + } |
|
| 118 | 118 | } |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | { |
| 22 | 22 | $url = "https://eu1.locationiq.com/v1/search.php?key={$this->locationiqKey}&q={$search}&format=json&limit=1"; |
| 23 | 23 | $response = get_headers($url); |
| 24 | - if($response[0] === 'HTTP/1.1 200 OK'){ |
|
| 24 | + if ($response[0] === 'HTTP/1.1 200 OK') { |
|
| 25 | 25 | $details = json_decode(file_get_contents($url)); |
| 26 | 26 | return [ |
| 27 | 27 | "lat" => $details[0]->lat, |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | $now -= 86400; |
| 48 | 48 | $dates[] = $now; |
| 49 | 49 | } |
| 50 | - } elseif($when == "future") { |
|
| 50 | + } elseif ($when == "future") { |
|
| 51 | 51 | for ($i = 0; $i < 7; $i++) { |
| 52 | 52 | $now += 86400; |
| 53 | 53 | $dates[] = $now; |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | $now -= 86400; |
| 83 | 83 | $dates[] = $now; |
| 84 | 84 | } |
| 85 | - } elseif($when == "future") { |
|
| 85 | + } elseif ($when == "future") { |
|
| 86 | 86 | for ($i = 0; $i < 7; $i++) { |
| 87 | 87 | $now += 86400; |
| 88 | 88 | $dates[] = $now; |
@@ -33,15 +33,15 @@ |
||
| 33 | 33 | ]; |
| 34 | 34 | } else { |
| 35 | 35 | return [ |
| 36 | - "valid" => "Not Valid IP", |
|
| 37 | - "ip" => null, |
|
| 38 | - "ipv" => null, |
|
| 39 | - "domain" => null, |
|
| 40 | - "lat" => null, |
|
| 41 | - "lon" => null, |
|
| 42 | - "country" => null, |
|
| 43 | - "city" => null |
|
| 44 | - ]; |
|
| 36 | + "valid" => "Not Valid IP", |
|
| 37 | + "ip" => null, |
|
| 38 | + "ipv" => null, |
|
| 39 | + "domain" => null, |
|
| 40 | + "lat" => null, |
|
| 41 | + "lon" => null, |
|
| 42 | + "country" => null, |
|
| 43 | + "city" => null |
|
| 44 | + ]; |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | } |
@@ -14,11 +14,11 @@ |
||
| 14 | 14 | $ipv = "Ipv4"; |
| 15 | 15 | } elseif (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { |
| 16 | 16 | $ipv = "Ipv6"; |
| 17 | - } else{ |
|
| 17 | + } else { |
|
| 18 | 18 | $ipv = null; |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | - if($ipv != null){ |
|
| 21 | + if ($ipv != null) { |
|
| 22 | 22 | $details = json_decode(file_get_contents("http://api.ipstack.com/{$ip}?access_key=9e9f05f2e74673444b90a999a579ab3f")); |
| 23 | 23 | $domain = gethostbyaddr($ip); |
| 24 | 24 | return [ |
@@ -31,29 +31,29 @@ |
||
| 31 | 31 | * |
| 32 | 32 | * @return string |
| 33 | 33 | */ |
| 34 | - public function indexAction() : object |
|
| 35 | - { |
|
| 36 | - $page = $this->di->get("page"); |
|
| 37 | - |
|
| 38 | - $ip = $this->di->request->getServer("REMOTE_ADDR"); |
|
| 39 | - if (isset($_GET['submit'])) { |
|
| 40 | - $ip = $this->di->request->getGet("ip"); |
|
| 41 | - } |
|
| 42 | - $validator = new \Anax\Model\ipValidation; |
|
| 43 | - $res = $validator->toJson($ip); |
|
| 44 | - $data = [ |
|
| 45 | - "valid" => $res["valid"], |
|
| 46 | - "ip" => $ip, |
|
| 47 | - "domain" => $res["domain"], |
|
| 48 | - "ipv" => $res["ipv"], |
|
| 49 | - "lat" => $res["lat"], |
|
| 50 | - "lon" => $res["lon"], |
|
| 51 | - "country" => $res["country"], |
|
| 52 | - "city" => $res["city"] |
|
| 53 | - ]; |
|
| 54 | - $page->add("ipVerification/ipJson", $data); |
|
| 55 | - |
|
| 56 | - return $page->render(); |
|
| 57 | - } |
|
| 34 | + public function indexAction() : object |
|
| 35 | + { |
|
| 36 | + $page = $this->di->get("page"); |
|
| 37 | + |
|
| 38 | + $ip = $this->di->request->getServer("REMOTE_ADDR"); |
|
| 39 | + if (isset($_GET['submit'])) { |
|
| 40 | + $ip = $this->di->request->getGet("ip"); |
|
| 41 | + } |
|
| 42 | + $validator = new \Anax\Model\ipValidation; |
|
| 43 | + $res = $validator->toJson($ip); |
|
| 44 | + $data = [ |
|
| 45 | + "valid" => $res["valid"], |
|
| 46 | + "ip" => $ip, |
|
| 47 | + "domain" => $res["domain"], |
|
| 48 | + "ipv" => $res["ipv"], |
|
| 49 | + "lat" => $res["lat"], |
|
| 50 | + "lon" => $res["lon"], |
|
| 51 | + "country" => $res["country"], |
|
| 52 | + "city" => $res["city"] |
|
| 53 | + ]; |
|
| 54 | + $page->add("ipVerification/ipJson", $data); |
|
| 55 | + |
|
| 56 | + return $page->render(); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | 59 | } |
@@ -31,68 +31,68 @@ |
||
| 31 | 31 | * |
| 32 | 32 | * @return string |
| 33 | 33 | */ |
| 34 | - public function indexActionGet() : object |
|
| 35 | - {
|
|
| 34 | + public function indexActionGet() : object |
|
| 35 | + {
|
|
| 36 | 36 | $page = $this->di->get("page");
|
| 37 | 37 | |
| 38 | - $data = [ |
|
| 39 | - "error" => $this->di->session->getOnce("error") ?? null,
|
|
| 40 | - "when" => $this->di->session->getOnce("when") ?? null,
|
|
| 41 | - "search" => $this->di->session->getOnce("search") ?? null,
|
|
| 42 | - "temp" => $this->di->session->getOnce("temp") ?? null,
|
|
| 43 | - "weather" => $this->di->session->getOnce("weather") ?? null,
|
|
| 44 | - "time" => $this->di->session->getOnce("time") ?? null,
|
|
| 45 | - "lon" => $this->di->session->getOnce("lon") ?? null,
|
|
| 46 | - "lat" => $this->di->session->getOnce("lat") ?? null,
|
|
| 47 | - ]; |
|
| 48 | - $page->add("weather/geoweather", $data);
|
|
| 49 | - |
|
| 50 | - return $page->render(); |
|
| 51 | - } |
|
| 52 | - public function indexActionPost() |
|
| 53 | - {
|
|
| 54 | - $response = $this->di->get("response");
|
|
| 55 | - $search = $this->di->get("request")->getPost("search");
|
|
| 56 | - $when = $this->di->get("request")->getPost("when");
|
|
| 57 | - $this->di->session->set("search", $search);
|
|
| 58 | - $weather = $this->di->get("weather");
|
|
| 59 | - |
|
| 60 | - |
|
| 61 | - $ip = $this->di->request->getGet("search");
|
|
| 62 | - $validator = new \Anax\Model\ipValidation; |
|
| 63 | - $res = $validator->toJson($ip); |
|
| 64 | - |
|
| 65 | - if ($res["valid"] == "valid IP"){
|
|
| 66 | - $locationInfo = $weather->getLocationData($res["city"]); |
|
| 67 | - } else {
|
|
| 68 | - if (!isset($search)){
|
|
| 38 | + $data = [ |
|
| 39 | + "error" => $this->di->session->getOnce("error") ?? null,
|
|
| 40 | + "when" => $this->di->session->getOnce("when") ?? null,
|
|
| 41 | + "search" => $this->di->session->getOnce("search") ?? null,
|
|
| 42 | + "temp" => $this->di->session->getOnce("temp") ?? null,
|
|
| 43 | + "weather" => $this->di->session->getOnce("weather") ?? null,
|
|
| 44 | + "time" => $this->di->session->getOnce("time") ?? null,
|
|
| 45 | + "lon" => $this->di->session->getOnce("lon") ?? null,
|
|
| 46 | + "lat" => $this->di->session->getOnce("lat") ?? null,
|
|
| 47 | + ]; |
|
| 48 | + $page->add("weather/geoweather", $data);
|
|
| 49 | + |
|
| 50 | + return $page->render(); |
|
| 51 | + } |
|
| 52 | + public function indexActionPost() |
|
| 53 | + {
|
|
| 54 | + $response = $this->di->get("response");
|
|
| 55 | + $search = $this->di->get("request")->getPost("search");
|
|
| 56 | + $when = $this->di->get("request")->getPost("when");
|
|
| 57 | + $this->di->session->set("search", $search);
|
|
| 58 | + $weather = $this->di->get("weather");
|
|
| 59 | + |
|
| 60 | + |
|
| 61 | + $ip = $this->di->request->getGet("search");
|
|
| 62 | + $validator = new \Anax\Model\ipValidation; |
|
| 63 | + $res = $validator->toJson($ip); |
|
| 64 | + |
|
| 65 | + if ($res["valid"] == "valid IP"){
|
|
| 66 | + $locationInfo = $weather->getLocationData($res["city"]); |
|
| 67 | + } else {
|
|
| 68 | + if (!isset($search)){
|
|
| 69 | 69 | $locationInfo = $weather->getLocationData("");
|
| 70 | 70 | } else{
|
| 71 | 71 | $locationInfo = $weather->getLocationData($search); |
| 72 | 72 | } |
| 73 | 73 | } |
| 74 | - $lon = $locationInfo["lon"] ?? null; |
|
| 75 | - $lat = $locationInfo["lat"] ?? null; |
|
| 76 | - $this->di->session->set("lon", $lon);
|
|
| 77 | - $this->di->session->set("lat", $lat);
|
|
| 78 | - $error = $locationInfo["error"] ?? null; |
|
| 79 | - $this->di->session->set("error", $error);
|
|
| 80 | - |
|
| 81 | - if ($locationInfo["error"] == null){
|
|
| 82 | - $weatherInfo = $weather->getWeather($when,$lon,$lat); |
|
| 83 | - $time = $weatherInfo["time"] ?? null; |
|
| 84 | - $this->di->session->set("time", $time);
|
|
| 85 | - |
|
| 86 | - $temp = $weatherInfo["temp"] ?? null; |
|
| 87 | - $this->di->session->set("temp", $temp);
|
|
| 88 | - |
|
| 89 | - $weather = $weatherInfo["weather"] ?? null; |
|
| 90 | - $this->di->session->set("weather", $weather);
|
|
| 91 | - |
|
| 92 | - $error = $weatherInfo["error"] ?? null; |
|
| 93 | - $this->di->session->set("error", $error);
|
|
| 74 | + $lon = $locationInfo["lon"] ?? null; |
|
| 75 | + $lat = $locationInfo["lat"] ?? null; |
|
| 76 | + $this->di->session->set("lon", $lon);
|
|
| 77 | + $this->di->session->set("lat", $lat);
|
|
| 78 | + $error = $locationInfo["error"] ?? null; |
|
| 79 | + $this->di->session->set("error", $error);
|
|
| 80 | + |
|
| 81 | + if ($locationInfo["error"] == null){
|
|
| 82 | + $weatherInfo = $weather->getWeather($when,$lon,$lat); |
|
| 83 | + $time = $weatherInfo["time"] ?? null; |
|
| 84 | + $this->di->session->set("time", $time);
|
|
| 85 | + |
|
| 86 | + $temp = $weatherInfo["temp"] ?? null; |
|
| 87 | + $this->di->session->set("temp", $temp);
|
|
| 88 | + |
|
| 89 | + $weather = $weatherInfo["weather"] ?? null; |
|
| 90 | + $this->di->session->set("weather", $weather);
|
|
| 91 | + |
|
| 92 | + $error = $weatherInfo["error"] ?? null; |
|
| 93 | + $this->di->session->set("error", $error);
|
|
| 94 | + } |
|
| 95 | + return $response->redirect("weather");
|
|
| 94 | 96 | } |
| 95 | - return $response->redirect("weather");
|
|
| 96 | - } |
|
| 97 | 97 | |
| 98 | 98 | } |
@@ -62,12 +62,12 @@ discard block |
||
| 62 | 62 | $validator = new \Anax\Model\ipValidation; |
| 63 | 63 | $res = $validator->toJson($ip); |
| 64 | 64 | |
| 65 | - if ($res["valid"] == "valid IP"){
|
|
| 65 | + if ($res["valid"] == "valid IP") {
|
|
| 66 | 66 | $locationInfo = $weather->getLocationData($res["city"]); |
| 67 | 67 | } else {
|
| 68 | - if (!isset($search)){
|
|
| 68 | + if (!isset($search)) {
|
|
| 69 | 69 | $locationInfo = $weather->getLocationData("");
|
| 70 | - } else{
|
|
| 70 | + } else {
|
|
| 71 | 71 | $locationInfo = $weather->getLocationData($search); |
| 72 | 72 | } |
| 73 | 73 | } |
@@ -78,8 +78,8 @@ discard block |
||
| 78 | 78 | $error = $locationInfo["error"] ?? null; |
| 79 | 79 | $this->di->session->set("error", $error);
|
| 80 | 80 | |
| 81 | - if ($locationInfo["error"] == null){
|
|
| 82 | - $weatherInfo = $weather->getWeather($when,$lon,$lat); |
|
| 81 | + if ($locationInfo["error"] == null) {
|
|
| 82 | + $weatherInfo = $weather->getWeather($when, $lon, $lat); |
|
| 83 | 83 | $time = $weatherInfo["time"] ?? null; |
| 84 | 84 | $this->di->session->set("time", $time);
|
| 85 | 85 | |
@@ -31,19 +31,19 @@ |
||
| 31 | 31 | $locationInfo = $weather->getLocationData($res["city"]); |
| 32 | 32 | } else {
|
| 33 | 33 | if (!isset($search)){
|
| 34 | - $locationInfo = $weather->getLocationData("");
|
|
| 35 | - } else{
|
|
| 36 | - $locationInfo = $weather->getLocationData($search); |
|
| 37 | - } |
|
| 38 | - } |
|
| 39 | - $lon = $locationInfo["lon"] ?? null; |
|
| 40 | - $lat = $locationInfo["lat"] ?? null; |
|
| 41 | - if (!isset($locationInfo["error"])){
|
|
| 34 | + $locationInfo = $weather->getLocationData("");
|
|
| 35 | + } else{
|
|
| 36 | + $locationInfo = $weather->getLocationData($search); |
|
| 37 | + } |
|
| 38 | + } |
|
| 39 | + $lon = $locationInfo["lon"] ?? null; |
|
| 40 | + $lat = $locationInfo["lat"] ?? null; |
|
| 41 | + if (!isset($locationInfo["error"])){
|
|
| 42 | 42 | |
| 43 | - $weatherInfo = $weather->getWeatherMultiCurl($when,$lon,$lat); |
|
| 44 | - } else {
|
|
| 45 | - $weatherInfo = ["error" => "that is not a city"]; |
|
| 46 | - } |
|
| 43 | + $weatherInfo = $weather->getWeatherMultiCurl($when,$lon,$lat); |
|
| 44 | + } else {
|
|
| 45 | + $weatherInfo = ["error" => "that is not a city"]; |
|
| 46 | + } |
|
| 47 | 47 | $data = [ |
| 48 | 48 | "location" => $search ?? null, |
| 49 | 49 | "lon" => $lon ?? null, |
@@ -27,20 +27,20 @@ |
||
| 27 | 27 | $validator = new \Anax\Model\ipValidation; |
| 28 | 28 | $res = $validator->toJson($ip); |
| 29 | 29 | |
| 30 | - if ($res["valid"] == "valid IP"){
|
|
| 30 | + if ($res["valid"] == "valid IP") {
|
|
| 31 | 31 | $locationInfo = $weather->getLocationData($res["city"]); |
| 32 | 32 | } else {
|
| 33 | - if (!isset($search)){
|
|
| 33 | + if (!isset($search)) {
|
|
| 34 | 34 | $locationInfo = $weather->getLocationData("");
|
| 35 | - } else{
|
|
| 35 | + } else {
|
|
| 36 | 36 | $locationInfo = $weather->getLocationData($search); |
| 37 | 37 | } |
| 38 | 38 | } |
| 39 | 39 | $lon = $locationInfo["lon"] ?? null; |
| 40 | 40 | $lat = $locationInfo["lat"] ?? null; |
| 41 | - if (!isset($locationInfo["error"])){
|
|
| 41 | + if (!isset($locationInfo["error"])) {
|
|
| 42 | 42 | |
| 43 | - $weatherInfo = $weather->getWeatherMultiCurl($when,$lon,$lat); |
|
| 43 | + $weatherInfo = $weather->getWeatherMultiCurl($when, $lon, $lat); |
|
| 44 | 44 | } else {
|
| 45 | 45 | $weatherInfo = ["error" => "that is not a city"]; |
| 46 | 46 | } |
@@ -35,7 +35,7 @@ |
||
| 35 | 35 | } else {
|
| 36 | 36 | ?> <p style= "color: red"> <?php echo $error; |
| 37 | 37 | } |
| 38 | - ?></p> |
|
| 38 | + ?></p> |
|
| 39 | 39 | </table> |
| 40 | 40 | <?php if(isset($lon) && isset($lat)){ ?>
|
| 41 | 41 | <iframe width="75%" |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | </tr> |
| 24 | 24 | |
| 25 | 25 | <?php |
| 26 | - if(is_array($time)){
|
|
| 26 | + if (is_array($time)) {
|
|
| 27 | 27 | for ($i = 0; $i < count($time); $i++) {
|
| 28 | 28 | ?> |
| 29 | 29 | <tr> |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | } |
| 38 | 38 | ?></p> |
| 39 | 39 | </table> |
| 40 | - <?php if(isset($lon) && isset($lat)){ ?>
|
|
| 40 | + <?php if (isset($lon) && isset($lat)) { ?>
|
|
| 41 | 41 | <iframe width="75%" |
| 42 | 42 | height="550" |
| 43 | 43 | frameborder="0" |
@@ -35,7 +35,7 @@ |
||
| 35 | 35 | } else { |
| 36 | 36 | ?> <p style= "color: red"> <?php echo $error; |
| 37 | 37 | } |
| 38 | - ?></p> |
|
| 38 | + ?></p> |
|
| 39 | 39 | </table> |
| 40 | 40 | <?php if(isset($lon) && isset($lat)){ ?> |
| 41 | 41 | <iframe width="75%" |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | </tr> |
| 24 | 24 | |
| 25 | 25 | <?php |
| 26 | - if(is_array($time)){ |
|
| 26 | + if (is_array($time)) { |
|
| 27 | 27 | for ($i = 0; $i < count($time); $i++) { |
| 28 | 28 | ?> |
| 29 | 29 | <tr> |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | } |
| 38 | 38 | ?></p> |
| 39 | 39 | </table> |
| 40 | - <?php if(isset($lon) && isset($lat)){ ?> |
|
| 40 | + <?php if (isset($lon) && isset($lat)) { ?> |
|
| 41 | 41 | <iframe width="75%" |
| 42 | 42 | height="550" |
| 43 | 43 | frameborder="0" |