-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.php
More file actions
67 lines (49 loc) 路 2.57 KB
/
Copy pathindex.php
File metadata and controls
67 lines (49 loc) 路 2.57 KB
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
64
65
66
67
<?php
$opts = array('http' => array('proxy' => 'www-cache:3128', "request_fulluri" => true));
$context = stream_context_create($opts);
function getIP() {
$ip = $_SERVER['REMOTE_ADDR'];
return ($ip == "::1") ? "" : $ip;
}
$location = simplexml_load_string(file_get_contents('http://freegeoip.net/xml/'.getIP(), false, $context)) ;
$weather_api = 'http://www.infoclimat.fr/public-api/gfs/xml?_ll='.$location->Latitude.','.$location->Longitude.'&_auth=ARsDFFIsBCZRfFtsD3lSe1Q8ADUPeVRzBHgFZgtuAH1UMQNgUTNcPlU5VClSfVZkUn8AYVxmVW0Eb1I2WylSLgFgA25SNwRuUT1bPw83UnlUeAB9DzFUcwR4BWMLYwBhVCkDb1EzXCBVOFQoUmNWZlJnAH9cfFVsBGRSPVs1UjEBZwNkUjIEYVE6WyYPIFJjVGUAZg9mVD4EbwVhCzMAMFQzA2JRMlw5VThUKFJiVmtSZQBpXGtVbwRlUjVbKVIuARsDFFIsBCZRfFtsD3lSe1QyAD4PZA%3D%3D&_c=19f3aa7d766b6ba91191c8be71dd1ab2';
$weather = simplexml_load_string(file_get_contents($weather_api, false, $context)) or die('Unable to load weather API') ;
$bikes = simplexml_load_string(file_get_contents('http://www.velostanlib.fr/service/carto', false, $context)) or die('Unable to load bikes API');
# MERGING XML FILES
$XML = new SimpleXMLElement('<application></application>');
$node = $XML->addChild('user');
$node->addAttribute('latitude',$location->Latitude);
$node->addAttribute('longitude',$location->Longitude);
$node = $XML->addChild('weather');
foreach ($weather->echeance as $echeance) {
$child = $node->addChild('day');
foreach( $echeance->attributes() as $key => $value ) {
$child->addAttribute($key, $value);
foreach ($echeance->temperature->level as $temperature) {
$greatChild = $child->addChild('temperature', $temperature[0]);
foreach ($temperature->attributes() as $key2 => $value2) {
$greatChild->addAttribute($key2, $value2);
}
}
}
}
$node = $XML->addChild('velostan');
foreach ($bikes->markers->marker as $marker) {
$child = $node->addChild('marker');
foreach( $marker->attributes() as $key => $value ) {
$child->addAttribute( $key, $value );
}
$station = simplexml_load_string(file_get_contents('http://www.velostanlib.fr/service/stationdetails/nancy/'.$marker['number'], false, $context)) or die('Unable to load bikes API');
$child = $child->addChild('station');
$child->addAttribute('available', $station->available);
$child->addAttribute('free', $station->free);
$child->addAttribute('total', $station->total);
}
# START XSLT
$xslt = new XSLTProcessor();
# IMPORT STYLESHEET
$XSL = new DOMDocument();
$XSL->load('style.xsl');
$xslt->importStylesheet( $XSL );
#PRINT
print $xslt->transformToXML( $XML );