Completed
Push — master ( 518a3f...773ce1 )
by Greg
11:58
created

Log::goal()   B

Complexity

Conditions 4
Paths 5

Size

Total Lines 24
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 8.6845
c 0
b 0
f 0
cc 4
eloc 20
nc 5
nop 3
1
<?php
2
/**
3
 * /classes/DomainMOD/Log.php
4
 *
5
 * This file is part of DomainMOD, an open source domain and internet asset manager.
6
 * Copyright (c) 2010-2017 Greg Chetcuti <[email protected]>
7
 *
8
 * Project: http://domainmod.org   Author: http://chetcuti.com
9
 *
10
 * DomainMOD is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
11
 * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
12
 * version.
13
 *
14
 * DomainMOD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
15
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License along with DomainMOD. If not, see
18
 * http://www.gnu.org/licenses/.
19
 *
20
 */
21
//@formatter:off
22
namespace DomainMOD;
23
24
class Log
25
{
26
27
    public function goal($goal, $old_version, $new_version)
28
    {
29
        if ($goal == 'install') {
30
            $base_url = 'https://domainmod.org/installed/index.php?v=' . urlencode($new_version);
31
        } elseif ($goal == 'upgrade') {
32
            $base_url = 'https://domainmod.org/upgraded/index.php?ov=' . urlencode($old_version) . '&nv=' . urlencode($new_version);
33
        } else {
34
            return;
35
        }
36
        $ip_address = urlencode($_SERVER['SERVER_ADDR']);
37
        $user_agent = urlencode($_SERVER['HTTP_USER_AGENT']);
38
        $language = urlencode($_SERVER['HTTP_ACCEPT_LANGUAGE']);
39
        $log_url = $base_url . '&ip=' . $ip_address . '&a=' . $user_agent . '&l=' . $language;
40
        $context = stream_context_create(array('https' => array('header' => 'Connection: close\r\n')));
41
        $result = file_get_contents($log_url, false, $context);
42
        if (!$result) {
43
            $handle = curl_init();
44
            curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
45
            curl_setopt($handle, CURLOPT_URL, $log_url);
46
            curl_exec($handle);
47
            curl_close($handle);
48
        }
49
        return;
50
    }
51
52
} //@formatter:on
53