1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Hab\MeModule; |
4
|
|
|
|
5
|
|
|
use Anax\Commons\ContainerInjectableInterface; |
6
|
|
|
use Anax\Commons\ContainerInjectableTrait; |
7
|
|
|
use Hab\Model; |
|
|
|
|
8
|
|
|
|
9
|
|
|
// use Anax\Route\Exception\ForbiddenException; |
10
|
|
|
// use Anax\Route\Exception\NotFoundException; |
11
|
|
|
// use Anax\Route\Exception\InternalErrorException; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* A sample controller to show how a controller class can be implemented. |
15
|
|
|
* The controller will be injected with $di if implementing the interface |
16
|
|
|
* ContainerInjectableInterface, like this sample class does. |
17
|
|
|
* The controller is mounted on a particular route and can then handle all |
18
|
|
|
* requests for that mount point. |
19
|
|
|
* |
20
|
|
|
* @SuppressWarnings(PHPMD.TooManyPublicMethods) |
21
|
|
|
*/ |
22
|
|
|
class LocationController implements ContainerInjectableInterface |
23
|
|
|
{ |
24
|
|
|
use ContainerInjectableTrait; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @return page |
|
|
|
|
28
|
|
|
*/ |
29
|
1 |
|
public function indexAction() |
30
|
|
|
{ |
31
|
1 |
|
$page = $this->di->get("page"); |
32
|
1 |
|
$session = $this->di->get("session"); |
33
|
|
|
$data = [ |
34
|
1 |
|
"coords" => $session->get("coords"), |
35
|
|
|
// "ress" => $session->get("ress"), |
36
|
|
|
]; |
37
|
1 |
|
$page->add("MeModule/location", $data); |
38
|
|
|
|
39
|
1 |
|
return $page->render(["title" => "Location"]); |
40
|
|
|
} |
41
|
|
|
|
42
|
3 |
|
public function indexActionPost() |
43
|
|
|
{ |
44
|
3 |
|
$session = $this->di->get("session"); |
45
|
3 |
|
$request = $this->di->get("request"); |
46
|
3 |
|
$response = $this->di->get("response"); |
47
|
3 |
|
$validator = $this->di->get("ip"); |
48
|
3 |
|
$fetch = $this->di->get("fetch"); |
49
|
|
|
|
50
|
3 |
|
$keys = require(ANAX_INSTALL_PATH . "/config.php"); |
51
|
3 |
|
$darkKey = $keys["darkSky"]; |
52
|
3 |
|
$boxKey = $keys["mapbox"]; |
53
|
3 |
|
$ipKey = $keys["key"]; |
54
|
|
|
|
55
|
3 |
|
$locations = explode(",", $request->getPost("location")); |
56
|
|
|
// $resArray = $validator->multiValidate($locations); |
57
|
3 |
|
$temp = []; |
58
|
3 |
|
foreach ($locations as $loc) { |
59
|
3 |
|
$validator->setIP(ltrim($loc)); |
60
|
3 |
|
array_push($temp, $validator->sendRes()); |
61
|
|
|
} |
62
|
3 |
|
$ress = []; |
63
|
3 |
|
foreach ($temp as $tmp) { |
64
|
3 |
|
$error = ""; |
65
|
3 |
|
if ($tmp["isValid"]) { |
66
|
2 |
|
$ip = $tmp["ip"]; |
67
|
2 |
|
$res = json_decode($fetch->fetch("GET", "http://api.ipstack.com/$ip?access_key=$ipKey")); |
68
|
2 |
|
if (!$res->city) { |
69
|
1 |
|
$error = "IP: $ip did not provide a location"; |
70
|
|
|
} else { |
71
|
2 |
|
$res = [$res->latitude, $res->longitude]; |
72
|
|
|
} |
73
|
|
|
} else { |
74
|
2 |
|
$ip = $tmp["ip"]; |
75
|
2 |
|
$res = json_decode($fetch->fetch("GET", "https://api.mapbox.com/geocoding/v5/mapbox.places/$ip.json?access_token=$boxKey")); |
76
|
2 |
|
if (count($res->features) == 0) { |
77
|
1 |
|
$error = "Term: $ip didnt give a result"; |
78
|
|
|
} else { |
79
|
1 |
|
$res = [$res->features[0]->geometry->coordinates[1], $res->features[0]->geometry->coordinates[0]]; |
80
|
|
|
} |
81
|
|
|
} |
82
|
3 |
|
array_push($ress, [$res, $error, $tmp["ip"]]); |
83
|
|
|
} |
84
|
3 |
|
$data = []; |
85
|
3 |
|
foreach ($ress as $locc) { |
86
|
3 |
|
if ($locc[1] == "") { |
87
|
2 |
|
$lat = $locc[0][0]; |
88
|
2 |
|
$lng = $locc[0][1]; |
89
|
2 |
|
$res = json_decode($fetch->fetch("GET", "https://api.darksky.net/forecast/$darkKey/$lat,$lng")); |
90
|
2 |
|
array_push($data, [$res, $locc]); |
91
|
|
|
} else { |
92
|
|
|
// var_dump($locc); |
93
|
1 |
|
array_push($data, [null, $locc]); |
94
|
|
|
} |
95
|
|
|
} |
96
|
3 |
|
$session->set("coords", $data); |
97
|
|
|
|
98
|
3 |
|
return $response->redirect("location"); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
} |
102
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths