blob: 4e0a68779062d5097b219c0e3b5a5dea4fb78220 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
<?php
class OERDownloadcounter extends SimpleORMap
{
protected static function configure($config = [])
{
$config['db_table'] = 'oer_downloadcounter';
parent::configure($config);
}
public static function addCounter($material_id)
{
$counter = new self();
$counter['material_id'] = $material_id;
if (Config::get()->oer_GEOLOCATOR_API) {
list($url, $lon, $lat) = explode(" ", Config::get()->oer_GEOLOCATOR_API);
$url = sprintf($url, $_SERVER['REMOTE_ADDR']);
$output = @file_get_contents($url, false, get_default_http_stream_context($url));
$output = json_decode($output, true);
if (isset($output[$lon])) {
$counter['longitude'] = $output[$lon];
}
if (isset($output[$lat])) {
$counter['latitude'] = $output[$lat];
}
}
$counter->store();
return $counter;
}
}
|