IPJsonController::ipJsonCheckerActionGet()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 25
ccs 7
cts 7
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Malm18\IPChecker;
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 IPJsonController implements ContainerInjectableInterface
20
{
21
    use ContainerInjectableTrait;
22
23
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 1
    public function indexActionGet()
104
    {
105
        // $request = $this->di->request;
106 1
        $theIP = $this->di->get("request")->getGet("ip");
107
108 1
        $ipHandler = new IPHandler();
109
        // $ipInfo = $ipHandler->checkIP($theIP);
110
111 1
        $ipInfo = $ipHandler->checkIP($theIP);
112
113
        // $largeMapLink = $ipHandler->largeMapLink($ipInfo['latitude'], $ipInfo['longitude']);
114
115 1
        $largeMapLink = ($ipInfo['latitude'] ? $ipHandler->largeMapLink($ipInfo['latitude'], $ipInfo['longitude']) : "");
116
117
        // $message = 'Hello '.($user->is_logged_in() ? $user->get('first_name') : 'Guest');
118
119 1
        $ipInfo2 = array("ip address" => $ipInfo['ip'], "type" => $ipInfo['type'], "city" => $ipInfo['city'],
120 1
        "country" => $ipInfo['country_name'], "region_name" => $ipInfo['region_name'], "continent_name" => $ipInfo['continent_name'],
121 1
        "latitude" => $ipInfo['latitude'], "longitude" => $ipInfo['longitude'],
122 1
        "map_link" => $largeMapLink);
123
        //
124
        // $json = json_encode($ipInfo2);
125
126 1
        return [$ipInfo2];
127
    }
128
129
//     $var = 5;
130
// $var_is_greater_than_two = ($var > 2 ? true : false);
131
132
133 1
    public function ipJsonCheckerActionGet() : object
134
    {
135
        // $session = $this->di->session;
136
        // // $session->set("ip1", "ip2");
137
        // $ip1 = $session->get("ip1");
138
        // $hostname = $session->get("hostname");
139
        // $type = $session->get("type");
140
        // var_dump($session);
141 1
        $ipHandler = new IPHandler();
142
143 1
        $ownIP = $ipHandler->checkOwnIP();
144
145
        $data = [
146 1
            "ownIP" => $ownIP
147
        ];
148
        // Add content as a view and then render the page
149 1
        $page = $this->di->get("page");
150
        // $data = [
151
        //     "content" => "HELLO!"
152
        // ];
153 1
        $page->add("ipChecker/ipJsonChecker", $data);
154
        // $page->add("anax/v2/article/default", $data, "sidebar-left");
155
        // $page->add("anax/v2/article/default", $data, "sidebar-right");
156
        // $page->add("anax/v2/article/default", $data, "flash");
157 1
        return $page->render();
158
    }
159
160
161
    // public function ipJsonCheckerActionPost() : object
162
    // {
163
    //
164
    //
165
    //     // $session = $this->di->session;
166
    //     // $ipHandler = $session->get("IpHandler");
167
    //     $request = $this->di->request;
168
    //     $response = $this->di->response;
169
    //     if ($request->getPost("ipsubmit")) {
170
    //     $theIP = $request->getPost("ip1");
171
    //     // $ipInfo = $ipHandler->checkIP($theIP);
172
    //     // $session->set("ip1", $ipInfo['ipaddress']);
173
    //     // $session->set("hostname", $ipInfo['hostname']);
174
    //     // $session->set("type", $ipInfo['type']);
175
    //
176
    //     return $response->redirect("ip-json-checker?ip=$theIP");
177
    // }
178
    // // elseif ($_POST["newRoll"] ?? false) {
179
    // }
180
181
182 2
    public function ipJsonCheckerActionPost() : object
183
    {
184
            // $session = $this->di->session;
185
            // $ipHandler = new IpHandler();
186 2
            $request = $this->di->get("request");
187 2
            $response = $this->di->get("response");
188 2
            $theIP = $request->getPost("ip1");
189
190
        // if (!is_null($theIP)) {
191
        //     $ipInfo = $ipHandler->checkIP($theIP);
192
        //     $ipInfo = $ipInfo . "röv";
193
        //      // $session->set("ip1", $ipInfo['ipaddress']);
194
        //      // $session->set("hostname", $ipInfo['hostname']);
195
        //      // $session->set("type", $ipInfo['type']);
196
        // }
197
198 2
            return $response->redirect("ip-json-checker?ip=$theIP");
199
    }
200
201
    // public function jsonResultPageActionGet() : object
202
    // {
203
    //
204
    //
205
    //     $session = $this->di->session;
206
    //     $ipaddress = $session->get("ipaddress");
207
    //     $json = $session->get("json");
208
    //
209
    //     $page = $this->di->get("page");
210
    //
211
    //     $data = [
212
    //         "ipaddress" => $ipaddress,
213
    //         "json" => $json
214
    //     ];
215
    //
216
    //     $page->add("ipChecker/jsonResultPage", $data);
217
    //
218
    //     return $page->render();
219
    // // } elseif ($_POST["newRoll"] ?? false) {
220
    // }
221
222
    // /**
223
    //  * This sample method dumps the content of $di.
224
    //  * GET mountpoint/dump-app
225
    //  *
226
    //  * @return array
227
    //  */
228
    // public function dumpDiActionGet() : array
229
    // {
230
    //     // Deal with the action and return a response.
231
    //     $services = implode(", ", $this->di->getServices());
232
    //     $json = [
233
    //         "message" => __METHOD__ . "<p>\$di contains: $services",
234
    //         "di" => $this->di->getServices(),
235
    //     ];
236
    //     return [$json];
237
    // }
238
239
240
241
    // /**
242
    //  * Try to access a forbidden resource.
243
    //  * ANY mountpoint/forbidden
244
    //  *
245
    //  * @return array
246
    //  */
247
    // public function forbiddenAction() : array
248
    // {
249
    //     // Deal with the action and return a response.
250
    //     $json = [
251
    //         "message" => __METHOD__ . ", forbidden to access.",
252
    //     ];
253
    //     return [$json, 403];
254
    // }
255
}
256