-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCIG_Importer.php
52 lines (42 loc) · 1.21 KB
/
CIG_Importer.php
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
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
class CIG_Importer {
protected $config;
function __construct($config = null) {
if ($config === null) {
include 'config.php';
$this->config = $config['CIG_Importer'];
}
}
function get_filename($date = null) {
if ($date !== null) {
$filename = $date . '_' . $this->config['name'] . '.xml';
} else {
$filename = $this->config['name'] . '.xml';
}
return $filename;
}
function import($date = null) {
$filename = $this->get_filename($date);
$url = $this->config['base_url'] . $filename;
$headers = array(
'Authorization: Basic ' . base64_encode($this->config['login'] . ':' . $this->config['pass']),
);
$options = array(
CURLOPT_FILE => fopen($filename, 'w'),
CURLOPT_TIMEOUT => 120,
CURLOPT_URL => $url,
CURLOPT_HTTPHEADER => $headers,
);
$ch = curl_init();
curl_setopt_array($ch, $options);
curl_exec($ch);
curl_close($ch);
}
function get_xml($date = null) {
$filename = $this->get_filename($date);
if (file_exists($filename) === false || (date("Ymd") > date("Ymd", filemtime($filename)))) {
$this->import($date);
}
return file_get_contents($filename);
}
}