Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 62... Línea 62...
62
        $info['latitude'] = $record->location->latitude;
62
        $info['latitude'] = $record->location->latitude;
63
        $info['note'] = get_string('iplookupmaxmindnote', 'admin');
63
        $info['note'] = get_string('iplookupmaxmindnote', 'admin');
Línea 64... Línea 64...
64
 
64
 
Línea 65... Línea 65...
65
        return $info;
65
        return $info;
66
 
66
 
Línea 67... Línea 67...
67
    } else {
67
    } else if (!empty($CFG->geopluginapikey)) {
68
        require_once($CFG->libdir.'/filelib.php');
68
        require_once($CFG->libdir.'/filelib.php');
69
 
69
 
70
        if (strpos($ip, ':') !== false) {
70
        if (strpos($ip, ':') !== false) {
71
            // IPv6 is not supported by geoplugin.net.
71
            // IPv6 is not supported by geoplugin.net.
Línea -... Línea 72...
-
 
72
            $info['error'] = get_string('invalidipformat', 'error');
72
            $info['error'] = get_string('invalidipformat', 'error');
73
            return $info;
73
            return $info;
74
        }
74
        }
75
 
75
 
76
        $requesturl = new moodle_url('https://api.geoplugin.com', ['ip' => $ip, 'auth' => $CFG->geopluginapikey]);
76
        $ipdata = download_file_content('http://www.geoplugin.net/json.gp?ip='.$ip);
77
        $response = download_file_content($requesturl->out(false), null, null, true);
-
 
78
        if ($response->response_code != 200) {
77
        if ($ipdata) {
79
            $info['error'] = get_string('cannotgeoplugin', 'error');
78
            $ipdata = preg_replace('/^geoPlugin\((.*)\)\s*$/s', '$1', $ipdata);
80
            return $info;
79
            $ipdata = json_decode($ipdata, true);
81
        }
80
        }
82
        $ipdata = json_decode($response->results, true);
81
        if (!is_array($ipdata)) {
83
        if (!is_array($ipdata)) {
Línea 102... Línea 104...
102
        $info['title'][] = $info['country'];
104
        $info['title'][] = $info['country'];
Línea 103... Línea 105...
103
 
105
 
104
        return $info;
106
        return $info;
Línea -... Línea 107...
-
 
107
    }
-
 
108
 
-
 
109
    $info['error'] = get_string('iplookupfailed', 'error', $ip);
105
    }
110
    return $info;