root/carte/trunk/old/parse.php

Revision 11, 4.4 kB (checked in by alkahan, 2 years ago)

Ajout du projet de carte.

Line 
1 <?php
2
3 # Fonction qui met en page l'affichage de l'adresse
4 function adresse($data) {
5   $result = "";
6   if ( (isset($data->civicnumber)) || (isset($data->adresse)) || (isset($data->postal)) || (isset($data->city))  ) {
7     $result = "<b>Adresse:</b><br/>";
8     if (isset($data->civicnumber)) $result = "$result $data->civicnumber";         
9     if (isset($data->adresse)) {
10         $data->adresse = eregi_replace("^rue ", "", $data->adresse);
11         $result = "$result rue $data->adresse<br/>";
12     }
13     if (isset($data->postal)) $result = "$result $data->postal";         
14     if (isset($data->city)) $result = "$result $data->city";     
15     return $result;
16   }
17 }
18
19 # chargement du fichier XML
20 $xml = xmldocfile('http://auth.wireless-fr.org/hotspot_status.php?format=XML');
21
22 # traitement du fichier XML
23 $nodes = $xml->children();
24 $nodes = $nodes[0]->children();
25 $nodes = $nodes[5]->children();
26 $i = 0;
27 while($node = array_shift($nodes)) {
28   if ($node->type == 1) {
29     $hotspots = $node->children();
30     while($hotspot = array_shift($hotspots)) {
31       if ($hotspot->type == "1") {
32     # récupération du status de la node
33         if ($hotspot->tagname() == "nodes") {
34       $hotspot_nodes = $hotspot->children();
35       while($hotspot_node = array_shift($hotspot_nodes)) {
36         if ($hotspot_node->type == 1) {
37           $hotspot_node_1 = $hotspot_node->children();
38           while($hotspot_node_2 = array_shift($hotspot_node_1)) {
39             if ($hotspot_node_2->type == 1) {
40           if ($hotspot_node_2->tagname == "status") {
41                 $result[$i]->status=$hotspot_node_2->get_content();
42           }
43         }
44           }
45         }
46       }
47     }
48     # récupération du nom de la node
49     if ($hotspot->tagname() == "name") {
50       $result[$i]->name = $hotspot->get_content();
51     }
52     # récupération du nom de la ville
53     if ($hotspot->tagname() == "city") {
54       $result[$i]->city = $hotspot->get_content();
55     }
56     # récupération du n° de l'adresse
57     if ($hotspot->tagname() == "civicNumber") {
58       $result[$i]->civicnumber = $hotspot->get_content();
59     }
60     # récupération du nom de la rue
61     if ($hotspot->tagname() == "streetAddress") {
62       $result[$i]->adresse = $hotspot->get_content();
63     }
64     # récupération du code postal
65     if ($hotspot->tagname() == "postalCode") {
66       $result[$i]->postal = $hotspot->get_content();
67     }
68     # récupération de l'adresse du site internet
69     if ($hotspot->tagname() == "webSiteUrl") {
70       $result[$i]->url = $hotspot->get_content();
71     }
72     # récupération de la description
73     if ($hotspot->tagname() == "description") {
74       $result[$i]->description = trim($hotspot->get_content());
75       #$result[$i]->description = check_plain($result[$i]->description);
76       $result[$i]->description = nl2br($result[$i]->description);
77       $result[$i]->description = str_replace(CHR(10),"",$result[$i]->description);
78       $result[$i]->description = str_replace(CHR(13),"",$result[$i]->description);
79       $result[$i]->description = str_replace("&lt;", "<", $result[$i]->description);
80       $result[$i]->description = str_replace("&gt;", ">", $result[$i]->description);
81     }
82     # récupération des coordonnées GPS
83     if ($hotspot->tagname() == "gisCenterLatLong") {
84       $gis = $hotspot->attributes();
85       $result[$i]->lat = $gis[0]->value;
86       $result[$i]->long = $gis[1]->value;
87     }
88       }
89     }
90     if (! isset($result[$i]->city)) {
91       $result[$i]->city = "";
92     }
93     $i = $i+1;
94   }
95 }
96 print_r($result);
97
98
99 # on prépare les données pour les transmettre au module gmap de drupal
100 $i = 0;
101 while($node = array_shift($result)) {
102   if ( ($node->lat != 0) && (isset($node->long) != 0) ) {
103     # test à décommenter pour n'afficher que les nodes du villes.
104     #if ( $node->city == "Le Mans" ) {
105       if ($node->status == "up" ) {
106         $marker = 'up';
107       }
108       else if ($node->status == "down" ) {
109         $marker = 'down';
110       }
111       else {
112         $marker = 'unknown';
113       }
114
115       $label = "";
116       if (isset($node->name)) $label = "$label <b>$node->name</b> <br/>";
117       if (isset($node->description)) $label = "$label $node->description<br/><br/>";
118       $address = adresse($node);
119       $label = "$label $address";
120       if (isset($node->url)) $label = "$label <p><a href=\"$node->url\">Site internet</a></p>";
121       # le tableau mymarkers est utilisé par le module gmap de drupal
122       # mymarkers est donc spécifique à drupal
123       $mymarkers[$i]=array('markername' => $marker,
124                            'label' => $label,
125                            'point' => "$node->lat,$node->long");
126     #}
127   }
128   $i = $i+1;
129 }
130
131 //print_r($mymarkers);
132
133
134
135 ?>
136
Note: See TracBrowser for help on using the browser.