Merge branch 'MDL-63759-master' of https://github.com/srobotta/moodle
This commit is contained in:
+69
-28
@@ -33,16 +33,38 @@ if (isguestuser()) {
|
||||
throw new require_login_exception('Guests are not allowed here.');
|
||||
}
|
||||
|
||||
$ip = optional_param('ip', getremoteaddr(), PARAM_RAW);
|
||||
$ip = optional_param('ip', getremoteaddr(), PARAM_RAW);
|
||||
$user = optional_param('user', 0, PARAM_INT);
|
||||
$width = optional_param('width', 0, PARAM_INT);
|
||||
$height = optional_param('height', 0, PARAM_INT);
|
||||
$ispopup = optional_param('popup', 0, PARAM_INT);
|
||||
|
||||
if (isset($CFG->iplookup)) {
|
||||
// Clean up of old settings.
|
||||
set_config('iplookup', NULL);
|
||||
}
|
||||
|
||||
$PAGE->set_url('/iplookup/index.php', array('id'=>$ip, 'user'=>$user));
|
||||
$PAGE->set_pagelayout('popup');
|
||||
$urlparams = [
|
||||
'id' => $ip,
|
||||
'user' => $user,
|
||||
];
|
||||
|
||||
// Params width and height are set, we assume to have a popup.
|
||||
if ($width > 0 && $height > 0) {
|
||||
$urlparams['width'] = $width;
|
||||
$urlparams['height'] = $height;
|
||||
$ispopup = 1;
|
||||
} else if ($ispopup === 1) { // Param popup was set, then we know that we want a popup.
|
||||
$urlparams['ispopup'] = 1;
|
||||
}
|
||||
// Set the page layout accordingly.
|
||||
if ($ispopup) {
|
||||
$PAGE->set_pagelayout('popup');
|
||||
} else {
|
||||
$PAGE->set_pagelayout('standard');
|
||||
}
|
||||
|
||||
$PAGE->set_url('/iplookup/index.php', $urlparams);
|
||||
$PAGE->set_context(context_system::instance());
|
||||
|
||||
$info = array($ip);
|
||||
@@ -71,38 +93,57 @@ if ($user) {
|
||||
}
|
||||
}
|
||||
}
|
||||
array_unshift($info['title'], $ip);
|
||||
|
||||
$title = implode(' - ', $info['title']);
|
||||
$title = $ip;
|
||||
foreach ($info['title'] as $component) {
|
||||
if (!empty(trim($component))) {
|
||||
$title .= ' - ' . $component;
|
||||
}
|
||||
}
|
||||
$PAGE->set_title(get_string('iplookup', 'admin').': '.$title);
|
||||
$PAGE->set_heading($title);
|
||||
echo $OUTPUT->header();
|
||||
|
||||
if (empty($CFG->googlemapkey3)) {
|
||||
$imgwidth = 620;
|
||||
$imgheight = 310;
|
||||
$dotwidth = 18;
|
||||
$dotheight = 30;
|
||||
|
||||
$dx = round((($info['longitude'] + 180) * ($imgwidth / 360)) - $imgwidth - $dotwidth/2);
|
||||
$dy = round((($info['latitude'] + 90) * ($imgheight / 180)));
|
||||
|
||||
echo '<div id="map" style="width:'.($imgwidth+$dotwidth).'px; height:'.$imgheight.'px;">';
|
||||
echo '<img src="earth.jpeg" style="width:'.$imgwidth.'px; height:'.$imgheight.'px" alt="" />';
|
||||
echo '<img src="marker.gif" style="width:'.$dotwidth.'px; height:'.$dotheight.'px; margin-left:'.$dx.'px; margin-bottom:'.$dy.'px;" alt="" />';
|
||||
echo '</div>';
|
||||
echo '<div id="note">'.$info['note'].'</div>';
|
||||
|
||||
// The map dimension is here as big as the popup/page is, so max with and at least 360px height.
|
||||
if ($ispopup) {
|
||||
echo '<h1 class="iplookup h2">' . htmlspecialchars($title) . '</h1>';
|
||||
$mapdim = 'width: '
|
||||
. (($width > 0) ? $width . 'px' : '100%')
|
||||
. '; height: '
|
||||
. (($height > 0) ? $height . 'px;' : '100%; min-height:360px;');
|
||||
} else {
|
||||
if (is_https()) {
|
||||
$PAGE->requires->js(new moodle_url('https://maps.googleapis.com/maps/api/js', array('key'=>$CFG->googlemapkey3, 'sensor'=>'false')));
|
||||
} else {
|
||||
$PAGE->requires->js(new moodle_url('http://maps.googleapis.com/maps/api/js', array('key'=>$CFG->googlemapkey3, 'sensor'=>'false')));
|
||||
}
|
||||
$module = array('name'=>'core_iplookup', 'fullpath'=>'/iplookup/module.js');
|
||||
$PAGE->requires->js_init_call('M.core_iplookup.init3', array($info['latitude'], $info['longitude'], $ip), true, $module);
|
||||
$mapdim = 'width:100%; height:100%;min-height:360px';
|
||||
}
|
||||
|
||||
echo '<div id="map" style="width: 650px; height: 360px"></div>';
|
||||
if (empty($CFG->googlemapkey3)) { // No Google API key is set, we use OSM.
|
||||
|
||||
// Have a fixed zoom factor to calculate corners of the map.
|
||||
$fkt = 4;
|
||||
$bboxleft = $info['longitude'] - $fkt;
|
||||
$bboxbottom = $info['latitude'] - $fkt;
|
||||
$bboxright = $info['longitude'] + $fkt;
|
||||
$bboxtop = $info['latitude'] + $fkt;
|
||||
|
||||
echo '<div id="map" style="' . $mapdim . '">'
|
||||
. '<object data="https://www.openstreetmap.org/export/embed.html?bbox='
|
||||
. $bboxleft . '%2C' . $bboxbottom . '%2C' . $bboxright . '%2C' . $bboxtop
|
||||
. '&layer=mapnik&marker=' . $info['latitude'] . '%2C' . $info['longitude'] . '" style="' . $mapdim . '"></object>'
|
||||
. '</div>'
|
||||
. '<div id="note">' . $info['note'] . '</div>';
|
||||
|
||||
|
||||
} else { // Google API key is set, then use Google Maps.
|
||||
$PAGE->requires->js(new moodle_url(
|
||||
'https://maps.googleapis.com/maps/api/js',
|
||||
[
|
||||
'key' => $CFG->googlemapkey3,
|
||||
'sensor' => 'false'
|
||||
]
|
||||
));
|
||||
$module = array('name'=>'core_iplookup', 'fullpath'=>'/iplookup/module.js');
|
||||
$PAGE->requires->js_init_call('M.core_iplookup.init3', [$info['latitude'], $info['longitude'], $ip], true, $module);
|
||||
|
||||
echo '<div id="map" style="' . $mapdim . '"></div>';
|
||||
echo '<div id="note">'.$info['note'].'</div>';
|
||||
}
|
||||
|
||||
|
||||
+4
-3
@@ -59,7 +59,7 @@ function iplookup_find_location($ip) {
|
||||
$info['title'][] = $info['country'];
|
||||
|
||||
$info['longitude'] = $record->location->longitude;
|
||||
$info['latitude'] = $record->location->latitude;
|
||||
$info['latitude'] = $record->location->latitude;
|
||||
$info['note'] = get_string('iplookupmaxmindnote', 'admin');
|
||||
|
||||
return $info;
|
||||
@@ -82,9 +82,10 @@ function iplookup_find_location($ip) {
|
||||
$info['error'] = get_string('cannotgeoplugin', 'error');
|
||||
return $info;
|
||||
}
|
||||
$info['latitude'] = (float)$ipdata['geoplugin_latitude'];
|
||||
$info['latitude'] = (float)$ipdata['geoplugin_latitude'];
|
||||
$info['longitude'] = (float)$ipdata['geoplugin_longitude'];
|
||||
$info['city'] = s($ipdata['geoplugin_city']);
|
||||
$info['city'] = s($ipdata['geoplugin_city']);
|
||||
$info['accuracyRadius'] = (int)$ipdata['geoplugin_locationAccuracyRadius']; // Unit is in Miles.
|
||||
|
||||
$countrycode = $ipdata['geoplugin_countryCode'];
|
||||
$countries = get_string_manager()->get_list_of_countries(true);
|
||||
|
||||
@@ -319,7 +319,7 @@ class report_log_table_log extends table_sql {
|
||||
$ip = $logextra['ip'];
|
||||
|
||||
if (empty($this->download)) {
|
||||
$url = new moodle_url("/iplookup/index.php?ip={$ip}&user={$event->userid}");
|
||||
$url = new moodle_url("/iplookup/index.php?popup=1&ip={$ip}&user={$event->userid}");
|
||||
$ip = $this->action_link($url, $ip, 'ip');
|
||||
}
|
||||
return $ip;
|
||||
|
||||
@@ -272,7 +272,7 @@ class report_loglive_table_log extends table_sql {
|
||||
// Get extra event data for origin and realuserid.
|
||||
$logextra = $event->get_logextra();
|
||||
|
||||
$url = new moodle_url("/iplookup/index.php?ip={$logextra['ip']}&user=$event->userid");
|
||||
$url = new moodle_url("/iplookup/index.php?popup=1&ip={$logextra['ip']}&user=$event->userid");
|
||||
return $this->action_link($url, $logextra['ip'], 'ip');
|
||||
}
|
||||
|
||||
@@ -287,7 +287,7 @@ class report_loglive_table_log extends table_sql {
|
||||
*/
|
||||
protected function action_link(moodle_url $url, $text, $name = 'popup') {
|
||||
global $OUTPUT;
|
||||
$link = new action_link($url, $text, new popup_action('click', $url, $name, array('height' => 440, 'width' => 700)));
|
||||
$link = new action_link($url, $text, new popup_action('click', $url, $name, array('height' => 550, 'width' => 700)));
|
||||
return $OUTPUT->render($link);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user