1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Anax\Controller; |
4
|
|
|
|
5
|
|
|
namespace artes\IP; |
6
|
|
|
|
7
|
|
|
// use Anax\Commons\AppInjectableInterface; |
8
|
|
|
// use Anax\Commons\AppInjectableTrait; |
9
|
|
|
use Anax\Commons\ContainerInjectableInterface; |
10
|
|
|
use Anax\Commons\ContainerInjectableTrait; |
11
|
|
|
use Anax\Route\Exception\NotFoundException; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* A sample controller to show how a controller class can be implemented. |
15
|
|
|
* The controller will be injected with $app if implementing the interface |
16
|
|
|
* AppInjectableInterface, 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) |
21
|
|
|
*/ |
22
|
|
|
class IPController implements ContainerInjectableInterface |
23
|
|
|
{ |
24
|
|
|
use ContainerInjectableTrait; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* This is the index method action, it handles: |
28
|
|
|
* ANY METHOD mountpoint |
29
|
|
|
* ANY METHOD mountpoint/ |
30
|
|
|
* ANY METHOD mountpoint/index |
31
|
|
|
* |
32
|
|
|
* @return object |
33
|
|
|
*/ |
34
|
1 |
|
public function initAction() : object |
35
|
|
|
{ |
36
|
1 |
|
$response = $this->di->get("response"); |
37
|
1 |
|
$session = $this->di->get("session"); |
38
|
1 |
|
$session->set("userip", null); |
39
|
1 |
|
return $response->redirect("ip"); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* This is the index method action, it handles: |
44
|
|
|
* ANY METHOD mountpoint |
45
|
|
|
* ANY METHOD mountpoint/ |
46
|
|
|
* ANY METHOD mountpoint/index |
47
|
|
|
* |
48
|
|
|
* @return object |
49
|
|
|
*/ |
50
|
1 |
|
public function indexActionGet() : object |
51
|
|
|
{ |
52
|
1 |
|
$ipkey = ""; |
53
|
|
|
// this loads $ipkey and $weatherkey |
54
|
1 |
|
include(ANAX_INSTALL_PATH . '/config/api/apikeys.php'); |
55
|
1 |
|
$page = $this->di->get("page"); |
56
|
1 |
|
$session = $this->di->get("session"); |
57
|
1 |
|
$realip = new RealIP(); |
58
|
1 |
|
$ipaddress = $realip->getRealIpAddr(); |
59
|
1 |
|
$input = $session->get("userip") ? $session->get("userip") : ""; |
60
|
|
|
|
61
|
1 |
|
$userip = new IPCheck($input); |
62
|
1 |
|
$ipmsg = $userip->printAllMessages(); |
63
|
1 |
|
$inputgeotag = new IPGeotag($ipkey); |
64
|
1 |
|
$inputgeoinfo = $inputgeotag->checkinputip($input); |
65
|
1 |
|
$iptotest = $input ? $input : $ipaddress; |
66
|
1 |
|
$usergeoinfo = $inputgeotag->checkdefaultip($iptotest); |
67
|
|
|
|
68
|
|
|
$data = [ |
69
|
1 |
|
"usergeoinfo" => $usergeoinfo, |
70
|
1 |
|
"inputgeoinfo" => $inputgeoinfo, |
71
|
1 |
|
"ipmsg" => $ipmsg |
72
|
|
|
]; |
73
|
|
|
|
74
|
1 |
|
$page->add( |
75
|
1 |
|
"ip/index", |
76
|
|
|
$data |
77
|
|
|
); |
78
|
|
|
|
79
|
1 |
|
return $page->render([ |
80
|
1 |
|
"title" => "My IP", |
81
|
|
|
]); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* This is the index method action, it handles: |
86
|
|
|
* ANY METHOD mountpoint |
87
|
|
|
* ANY METHOD mountpoint/ |
88
|
|
|
* ANY METHOD mountpoint/index |
89
|
|
|
* |
90
|
|
|
* @return object |
91
|
|
|
*/ |
92
|
1 |
|
public function indexActionPost() : object |
93
|
|
|
{ |
94
|
1 |
|
$request = $this->di->get("request"); |
95
|
1 |
|
$response = $this->di->get("response"); |
96
|
1 |
|
$session = $this->di->get("session"); |
97
|
|
|
|
98
|
1 |
|
$userip = $request->getPost("userip"); |
99
|
1 |
|
$session->set("userip", $userip); |
100
|
|
|
|
101
|
1 |
|
return $response->redirect("ip"); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|