|
1
|
|
|
<?php |
|
2
|
|
|
namespace Malm18\IPChecker; |
|
3
|
|
|
|
|
4
|
|
|
use Anax\Commons\ContainerInjectableInterface; |
|
5
|
|
|
use Anax\Commons\ContainerInjectableTrait; |
|
6
|
|
|
|
|
7
|
|
|
// use Anax\Route\Exception\ForbiddenException; |
|
8
|
|
|
// use Anax\Route\Exception\NotFoundException; |
|
9
|
|
|
// use Anax\Route\Exception\InternalErrorException; |
|
10
|
|
|
/** |
|
11
|
|
|
* A sample controller to show how a controller class can be implemented. |
|
12
|
|
|
* The controller will be injected with $di if implementing the interface |
|
13
|
|
|
* ContainerInjectableInterface, like this sample class does. |
|
14
|
|
|
* The controller is mounted on a particular route and can then handle all |
|
15
|
|
|
* requests for that mount point. |
|
16
|
|
|
* |
|
17
|
|
|
* @SuppressWarnings(PHPMD.TooManyPublicMethods) |
|
18
|
|
|
*/ |
|
19
|
|
|
class IPController implements ContainerInjectableInterface |
|
20
|
|
|
{ |
|
21
|
|
|
use ContainerInjectableTrait; |
|
22
|
|
|
|
|
23
|
1 |
|
public function indexActionGet() : object |
|
24
|
|
|
{ |
|
25
|
|
|
// $session = $this->di->session; |
|
26
|
1 |
|
$ipHandler = new IPHandler(); |
|
27
|
|
|
|
|
28
|
1 |
|
$ownIP = $ipHandler->checkOwnIP(); |
|
29
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
$data = [ |
|
33
|
1 |
|
"ownIP" => $ownIP |
|
34
|
|
|
]; |
|
35
|
|
|
|
|
36
|
|
|
// Add content as a view and then render the page |
|
37
|
1 |
|
$page = $this->di->get("page"); |
|
38
|
|
|
|
|
39
|
1 |
|
$page->add("ipChecker/ipChecker", $data); |
|
40
|
|
|
|
|
41
|
1 |
|
return $page->render(); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
|
|
46
|
2 |
|
public function indexActionPost() : object |
|
47
|
|
|
{ |
|
48
|
2 |
|
$session = $this->di->get("session"); |
|
49
|
|
|
// $ipHandler = new IpHandler(); |
|
50
|
2 |
|
$request = $this->di->get("request"); |
|
51
|
2 |
|
$response = $this->di->get("response"); |
|
52
|
2 |
|
$theIP = $request->getPost("ip1"); |
|
53
|
|
|
|
|
54
|
2 |
|
if (!is_null($theIP)) { |
|
55
|
|
|
// $ipInfo = $ipHandler->checkIP($theIP); |
|
56
|
|
|
// $ipInfo2 = json_decode($ipInfo, true); |
|
57
|
|
|
// $ipInfo3 = gettype($ipInfo); |
|
58
|
|
|
// echo $ipInfo3; |
|
59
|
|
|
// var_dump(json_decode($ipInfo, true)); |
|
60
|
|
|
// var_dump($ipInfo2); |
|
61
|
|
|
// var_dump($ipInfo['ip']); |
|
62
|
2 |
|
$session->set("ip1", $theIP); |
|
63
|
|
|
// $session->set("hostname", $ipInfo['hostname']); |
|
64
|
|
|
// $session->set("type", $ipInfo['type']); |
|
65
|
|
|
// $session->set("latitude", $ipInfo['latitude']); |
|
66
|
|
|
// $session->set("longitude", $ipInfo['longitude']); |
|
67
|
|
|
// $session->set("city", $ipInfo['city']); |
|
68
|
|
|
// $session->set("country_name", $ipInfo['country_name']); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
2 |
|
return $response->redirect("ip-checker/resultpage"); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
|
|
75
|
|
|
|
|
76
|
2 |
|
public function resultPageActionGet() : object |
|
77
|
|
|
{ |
|
78
|
|
|
|
|
79
|
|
|
// $session->set("latitude", $ipInfo['latitude']); |
|
80
|
|
|
// $session->set("longitude", $ipInfo['longitude']); |
|
81
|
|
|
// $session->set("city", $ipInfo['city']); |
|
82
|
|
|
// $session->set("country_name", $ipInfo['country_name']); |
|
83
|
|
|
|
|
84
|
2 |
|
$session = $this->di->get("session"); |
|
85
|
|
|
|
|
86
|
2 |
|
$theIP = $session->get("ip1"); |
|
87
|
|
|
|
|
88
|
2 |
|
$ipHandler = new IPHandler(); |
|
89
|
|
|
|
|
90
|
2 |
|
$ipInfo = $ipHandler->checkIP($theIP); |
|
91
|
|
|
|
|
92
|
2 |
|
$latitude = $ipInfo['latitude']; |
|
93
|
2 |
|
$longitude = $ipInfo['longitude']; |
|
94
|
2 |
|
$minLong = $ipHandler->minLong($ipInfo['longitude']); |
|
95
|
2 |
|
$maxLong = $ipHandler->maxLong($ipInfo['longitude']); |
|
96
|
2 |
|
$minLat = $ipHandler->minLat($ipInfo['latitude']); |
|
97
|
2 |
|
$maxLat = $ipHandler->maxLat($ipInfo['latitude']); |
|
98
|
|
|
|
|
99
|
|
|
// echo("$latitude"); |
|
100
|
|
|
// echo($latitude); |
|
101
|
|
|
|
|
102
|
2 |
|
$mapLink = $ipHandler->mapLink($latitude, $longitude, $minLat, $maxLat, $minLong, $maxLong); |
|
103
|
|
|
|
|
104
|
|
|
// $var = 5; |
|
105
|
|
|
// $var_is_greater_than_two = ($var > 2 ? true : false); |
|
106
|
|
|
|
|
107
|
|
|
// var_dump($ipInfo); |
|
108
|
|
|
// $session->set("ip1", "ip2"); |
|
109
|
|
|
|
|
110
|
|
|
// $hostname = $session->get("hostname"); |
|
111
|
|
|
// $city = $session->get("city"); |
|
112
|
|
|
// $country_name = $session->get("country_name"); |
|
113
|
|
|
// $latitude = $session->get("latitude"); |
|
114
|
|
|
// $longitude = $session->get("longitude"); |
|
115
|
|
|
// $type = $session->get("type"); |
|
116
|
|
|
|
|
117
|
|
|
// var_dump($session); |
|
118
|
|
|
$data = [ |
|
119
|
2 |
|
"ip1" => $theIP, |
|
120
|
2 |
|
"city" => $ipInfo['city'], |
|
121
|
2 |
|
"country_name" => $ipInfo['country_name'], |
|
122
|
2 |
|
"latitude" => $ipInfo['latitude'], |
|
123
|
2 |
|
"longitude" => $ipInfo['longitude'], |
|
124
|
2 |
|
"mapLink" => $mapLink, |
|
125
|
2 |
|
"continent_name" => $ipInfo['continent_name'], |
|
126
|
2 |
|
"region_name" => $ipInfo['region_name'], |
|
127
|
|
|
// "calling_code" => $ipInfo['location']['calling_code'], |
|
128
|
2 |
|
"type" => $ipInfo['type'] |
|
129
|
|
|
]; |
|
130
|
|
|
// Add content as a view and then render the page |
|
131
|
2 |
|
$page = $this->di->get("page"); |
|
132
|
|
|
// $data = [ |
|
133
|
|
|
// "content" => "HELLO!" |
|
134
|
|
|
// ]; |
|
135
|
2 |
|
$page->add("ipChecker/resultPage", $data); |
|
136
|
|
|
// $page->add("anax/v2/article/default", $data, "sidebar-left"); |
|
137
|
|
|
// $page->add("anax/v2/article/default", $data, "sidebar-right"); |
|
138
|
|
|
// $page->add("anax/v2/article/default", $data, "flash"); |
|
139
|
2 |
|
return $page->render(); |
|
140
|
|
|
} |
|
141
|
|
|
} |
|
142
|
|
|
|