1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Malm18\Vader; |
4
|
|
|
|
5
|
|
|
use Anax\Commons\ContainerInjectableInterface; |
6
|
|
|
use Anax\Commons\ContainerInjectableTrait; |
7
|
|
|
|
8
|
|
|
// use Anax\Route\Exception\ForbiddenException; |
9
|
|
|
// use Anax\Route\Exception\NotFoundException; |
10
|
|
|
// use Anax\Route\Exception\InternalErrorException; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* A sample JSON controller to show how a controller class can be implemented. |
14
|
|
|
* The controller will be injected with $di if implementing the interface |
15
|
|
|
* ContainerInjectableInterface, like this sample class does. |
16
|
|
|
* The controller is mounted on a particular route and can then handle all |
17
|
|
|
* requests for that mount point. |
18
|
|
|
*/ |
19
|
|
|
class JsonVaderController implements ContainerInjectableInterface |
20
|
|
|
{ |
21
|
|
|
use ContainerInjectableTrait; |
22
|
|
|
|
23
|
|
|
// A useless comment sort of but not really |
24
|
|
|
|
25
|
|
|
// /** |
26
|
|
|
// * @var string $db a sample member variable that gets initialised |
27
|
|
|
// */ |
28
|
|
|
// private $db = "not active"; |
29
|
|
|
|
30
|
|
|
|
31
|
|
|
|
32
|
|
|
// /** |
33
|
|
|
// * The initialize method is optional and will always be called before the |
34
|
|
|
// * target method/action. This is a convienient method where you could |
35
|
|
|
// * setup internal properties that are commonly used by several methods. |
36
|
|
|
// * |
37
|
|
|
// * @return void |
38
|
|
|
// */ |
39
|
|
|
// public function initialize() : void |
40
|
|
|
// { |
41
|
|
|
// // Use to initialise member variables. |
42
|
|
|
// $this->db = "active"; |
43
|
|
|
// } |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
|
47
|
|
|
// /** |
48
|
|
|
// * This is the index method action, it handles: |
49
|
|
|
// * GET METHOD mountpoint |
50
|
|
|
// * GET METHOD mountpoint/ |
51
|
|
|
// * GET METHOD mountpoint/index |
52
|
|
|
// * |
53
|
|
|
// * @return array |
54
|
|
|
// */ |
55
|
|
|
// public function indexActionGet() : array |
56
|
|
|
// { |
57
|
|
|
// // Deal with the action and return a response. |
58
|
|
|
// $json = [ |
59
|
|
|
// "message" => __METHOD__ . ", \$db is {$this->db}", |
60
|
|
|
// ]; |
61
|
|
|
// return [$json]; |
62
|
|
|
// } |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* This is the index method action, it handles: |
66
|
|
|
* ANY METHOD mountpoint |
67
|
|
|
* ANY METHOD mountpoint/ |
68
|
|
|
* ANY METHOD mountpoint/index |
69
|
|
|
* |
70
|
|
|
*/ |
71
|
|
|
// public function indexActionGet() |
72
|
|
|
// { |
73
|
|
|
// // $request = $this->di->get("request"); |
74
|
|
|
// $request = $this->di->request; |
75
|
|
|
// $response = $this->di->response; |
76
|
|
|
// $theIP = $this->di->get("request")->getGet("ip"); |
77
|
|
|
// // var_dump($theIP); |
78
|
|
|
// |
79
|
|
|
// $ipHandler = new IpHandler(); |
80
|
|
|
// $ipInfo = $ipHandler->checkIP($theIP); |
81
|
|
|
// $session = $this->di->session; |
82
|
|
|
// |
83
|
|
|
// // var_dump($ipInfo); |
84
|
|
|
// |
85
|
|
|
// // $json = [ |
86
|
|
|
// // "ipaddress" => $ipInfo['ipaddress'], "hostname" => $ipInfo['hostname'], |
87
|
|
|
// // "type" => $ipInfo['ipaddress'] |
88
|
|
|
// // ]; |
89
|
|
|
// $json = json_encode($ipInfo, JSON_PRETTY_PRINT); |
90
|
|
|
// $session->set("json", $json); |
91
|
|
|
// $session->set("ipaddress", $ipInfo['ipaddress']); |
92
|
|
|
// return $response->redirect("ip-json-checker/jsonResultPage"); |
93
|
|
|
// // var_dump($json); |
94
|
|
|
// // Deal with the action and return a response. |
95
|
|
|
// // return $json; |
96
|
|
|
// } |
97
|
|
|
|
98
|
|
|
|
99
|
|
|
|
100
|
|
|
|
101
|
|
|
|
102
|
|
|
|
103
|
2 |
|
public function indexActionGet() |
104
|
|
|
{ |
105
|
|
|
// $request = $this->di->request; |
106
|
2 |
|
$vader = $this->di->get("vader"); |
107
|
2 |
|
$theIP = $this->di->get("request")->getGet("ip"); |
108
|
2 |
|
$pastOrFuture = $this->di->get("request")->getGet("pastOrFuture"); |
109
|
|
|
|
110
|
2 |
|
$ipHandler = new \Malm18\IPChecker\IPHandler(); |
111
|
|
|
|
112
|
2 |
|
$coordinates = $vader->checkCoordinates($theIP); |
113
|
|
|
|
114
|
2 |
|
if ($coordinates) { |
115
|
1 |
|
$latitude = $coordinates['latitude']; |
116
|
1 |
|
$longitude = $coordinates['longitude']; |
117
|
|
|
|
118
|
|
|
// $ipInfo = $ipHandler->checkIP($theIP); |
119
|
|
|
|
120
|
|
|
// $ipInfo = $ipHandler->checkIP($theIP); |
121
|
|
|
|
122
|
1 |
|
$weather = $vader->checkWeather($latitude, $longitude, $pastOrFuture); |
123
|
|
|
|
124
|
|
|
// $largeMapLink = $ipHandler->largeMapLink($ipInfo['latitude'], $ipInfo['longitude']); |
125
|
|
|
|
126
|
1 |
|
$largeMapLink = ($latitude ? $ipHandler->largeMapLink($latitude, $longitude) : ""); |
127
|
|
|
|
128
|
1 |
|
$weather2 = $vader->checkWeather2($weather); |
129
|
|
|
|
130
|
|
|
// $message = 'Hello '.($user->is_logged_in() ? $user->get('first_name') : 'Guest'); |
131
|
|
|
|
132
|
|
|
// $ipInfo2 = array("time" => $weather2[0]['time'], "summary" => $weather2['summary'], "temperatureMin" => $weather2['temperatureMin'], |
133
|
|
|
// "temperatureMax" => $weather2['temperatureMax'], "precipProbability" => $weather2['precipProbability'], "windSpeed" => $weather2['windSpeed'], |
134
|
|
|
// "windBearing" => $weather2['windBearing'], "latitude" => $latitude, "longitude" => $longitude, |
135
|
|
|
// "map_link" => $largeMapLink); |
136
|
|
|
// |
137
|
|
|
// $json = json_encode($ipInfo2); |
138
|
|
|
|
139
|
1 |
|
$weather2['mapLink'] = $largeMapLink; |
140
|
|
|
} else { |
141
|
1 |
|
$weather2 = []; |
142
|
1 |
|
$weather2['data'] = "No result for you!"; |
143
|
|
|
} |
144
|
2 |
|
return [$weather2]; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
// $var = 5; |
148
|
|
|
// $var_is_greater_than_two = ($var > 2 ? true : false); |
149
|
|
|
|
150
|
|
|
|
151
|
1 |
|
public function jsonVaderActionGet() : object |
152
|
|
|
{ |
153
|
|
|
// $session = $this->di->session; |
154
|
|
|
// // $session->set("ip1", "ip2"); |
155
|
|
|
// $ip1 = $session->get("ip1"); |
156
|
|
|
// $hostname = $session->get("hostname"); |
157
|
|
|
// $type = $session->get("type"); |
158
|
|
|
// var_dump($session); |
159
|
1 |
|
$ipHandler = new \Malm18\IPChecker\IPHandler(); |
160
|
|
|
|
161
|
1 |
|
$ownIP = $ipHandler->checkOwnIP(); |
162
|
|
|
|
163
|
|
|
$data = [ |
164
|
1 |
|
"ownIP" => $ownIP |
165
|
|
|
]; |
166
|
|
|
// Add content as a view and then render the page |
167
|
1 |
|
$page = $this->di->get("page"); |
168
|
|
|
// $data = [ |
169
|
|
|
// "content" => "HELLO!" |
170
|
|
|
// ]; |
171
|
1 |
|
$page->add("vader/jsonVader", $data); |
172
|
|
|
// $page->add("anax/v2/article/default", $data, "sidebar-left"); |
173
|
|
|
// $page->add("anax/v2/article/default", $data, "sidebar-right"); |
174
|
|
|
// $page->add("anax/v2/article/default", $data, "flash"); |
175
|
1 |
|
return $page->render(); |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
|
179
|
|
|
// public function ipJsonCheckerActionPost() : object |
180
|
|
|
// { |
181
|
|
|
// |
182
|
|
|
// |
183
|
|
|
// // $session = $this->di->session; |
184
|
|
|
// // $ipHandler = $session->get("IpHandler"); |
185
|
|
|
// $request = $this->di->request; |
186
|
|
|
// $response = $this->di->response; |
187
|
|
|
// if ($request->getPost("ipsubmit")) { |
188
|
|
|
// $theIP = $request->getPost("ip1"); |
189
|
|
|
// // $ipInfo = $ipHandler->checkIP($theIP); |
190
|
|
|
// // $session->set("ip1", $ipInfo['ipaddress']); |
191
|
|
|
// // $session->set("hostname", $ipInfo['hostname']); |
192
|
|
|
// // $session->set("type", $ipInfo['type']); |
193
|
|
|
// |
194
|
|
|
// return $response->redirect("ip-json-checker?ip=$theIP"); |
195
|
|
|
// } |
196
|
|
|
// // elseif ($_POST["newRoll"] ?? false) { |
197
|
|
|
// } |
198
|
|
|
|
199
|
|
|
|
200
|
4 |
|
public function jsonVaderActionPost() : object |
201
|
|
|
{ |
202
|
|
|
// $session = $this->di->session; |
203
|
|
|
// $ipHandler = new \Malm18\IPChecker\IpHandler(); |
204
|
4 |
|
$request = $this->di->get("request"); |
205
|
4 |
|
$response = $this->di->get("response"); |
206
|
4 |
|
$theIP = $request->getPost("ip1"); |
207
|
4 |
|
$pastOrFuture = $request->getPost("pastOrFuture"); |
208
|
|
|
|
209
|
|
|
// if (!is_null($theIP)) { |
210
|
|
|
// $ipInfo = $ipHandler->checkIP($theIP); |
211
|
|
|
// // $session->set("ip1", $ipInfo['ipaddress']); |
212
|
|
|
// // $session->set("hostname", $ipInfo['hostname']); |
213
|
|
|
// // $session->set("type", $ipInfo['type']); |
214
|
|
|
// } |
215
|
|
|
|
216
|
4 |
|
return $response->redirect("json-vader?ip=$theIP&pastOrFuture=$pastOrFuture"); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
// public function jsonResultPageActionGet() : object |
220
|
|
|
// { |
221
|
|
|
// |
222
|
|
|
// |
223
|
|
|
// $session = $this->di->session; |
224
|
|
|
// $ipaddress = $session->get("ipaddress"); |
225
|
|
|
// $json = $session->get("json"); |
226
|
|
|
// |
227
|
|
|
// $page = $this->di->get("page"); |
228
|
|
|
// |
229
|
|
|
// $data = [ |
230
|
|
|
// "ipaddress" => $ipaddress, |
231
|
|
|
// "json" => $json |
232
|
|
|
// ]; |
233
|
|
|
// |
234
|
|
|
// $page->add("ipChecker/jsonResultPage", $data); |
235
|
|
|
// |
236
|
|
|
// return $page->render(); |
237
|
|
|
// // } elseif ($_POST["newRoll"] ?? false) { |
238
|
|
|
// } |
239
|
|
|
|
240
|
|
|
// /** |
241
|
|
|
// * This sample method dumps the content of $di. |
242
|
|
|
// * GET mountpoint/dump-app |
243
|
|
|
// * |
244
|
|
|
// * @return array |
245
|
|
|
// */ |
246
|
|
|
// public function dumpDiActionGet() : array |
247
|
|
|
// { |
248
|
|
|
// // Deal with the action and return a response. |
249
|
|
|
// $services = implode(", ", $this->di->getServices()); |
250
|
|
|
// $json = [ |
251
|
|
|
// "message" => __METHOD__ . "<p>\$di contains: $services", |
252
|
|
|
// "di" => $this->di->getServices(), |
253
|
|
|
// ]; |
254
|
|
|
// return [$json]; |
255
|
|
|
// } |
256
|
|
|
|
257
|
|
|
|
258
|
|
|
|
259
|
|
|
// /** |
260
|
|
|
// * Try to access a forbidden resource. |
261
|
|
|
// * ANY mountpoint/forbidden |
262
|
|
|
// * |
263
|
|
|
// * @return array |
264
|
|
|
// */ |
265
|
|
|
// public function forbiddenAction() : array |
266
|
|
|
// { |
267
|
|
|
// // Deal with the action and return a response. |
268
|
|
|
// $json = [ |
269
|
|
|
// "message" => __METHOD__ . ", forbidden to access.", |
270
|
|
|
// ]; |
271
|
|
|
// return [$json, 403]; |
272
|
|
|
// } |
273
|
|
|
} |
274
|
|
|
|