blob: c772eaaa6cc91f0cfb29396c4b47c737e446b6e9 (
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
30
31
32
33
34
35
36
37
38
39
|
<?php
/**
* @license GPL2 or any later version
*
* @property string $id alias column for counter_id
* @property string $counter_id database column
* @property string $material_id database column
* @property float|null $longitude database column
* @property float|null $latitude database column
* @property int|null $mkdate database column
*/
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;
}
}
|