-
Notifications
You must be signed in to change notification settings - Fork 0
/
pullUpdates.php
63 lines (49 loc) · 1.63 KB
/
pullUpdates.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
53
54
55
56
57
58
59
60
61
62
63
<?php
$updater = new Updater;
$updater->updateLocalisationFile();
$updater->updateCategoriesFile();
class Updater {
private $_config;
public function __construct() {
$this->_config = parse_ini_file( 'config/config.ini', false );
}
public function updateLocalisationFile() {
print( "Updating localisation IDs..." );
$url = $this->_config['localisation.src'];
$filter = $this->_config['localisation.filter'];
$destination = $this->_config['localisation.dst'];
$response = $this->_curlRequest( $url, $filter );
if( $response ) {
file_put_contents( $destination, $response );
print( "done.\n" );
} else print( "FAILED!\n" );
}
public function updateCategoriesFile() {
print( "Updating agenda categories..." );
$url = $this->_config['categories.src'];
$filter = $this->_config['categories.filter'];
$destination = $this->_config['categories.dst'];
$response = $this->_curlRequest( $url, $filter );
if( $response ) {
file_put_contents( $destination, $response );
print( "done.\n" );
} else print( "FAILED!\n" );
}
private function _curlRequest( $url, $filter, $lang='de', $xml='get_as_xml' ) {
$ch = curl_init( $url );
$fields = array(
'filterView' => urlencode( $filter ),
'type' => urlencode( $filter ), // just because the plurio.net API sucks a tiny bit
'lang' => urlencode( $lang ),
'xml' => urlencode( $xml )
);
$query = http_build_query( $fields );
curl_setopt($ch,CURLOPT_POST, count($fields) );
curl_setopt($ch,CURLOPT_POSTFIELDS, $query );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
}
?>