root/carte/trunk/parse.inc

Revision 11, 4.6 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
20 # traitement du fichier XML
21 function parse_xml ($xml) {
22   $nodes = $xml->children();
23   $nodes = $nodes[0]->children();
24   $nodes = $nodes[5]->children();
25   $i = 0;
26   while($node = array_shift($nodes)) {
27     if ($node->type == 1) {
28       $hotspots = $node->children();
29       while($hotspot = array_shift($hotspots)) {
30         if ($hotspot->type == "1") {
31           # récupération du status de la node
32           if ($hotspot->tagname() == "nodes") {
33             $hotspot_nodes = $hotspot->children();
34             while($hotspot_node = array_shift($hotspot_nodes)) {
35               if ($hotspot_node->type == 1) {
36                 $hotspot_node_1 = $hotspot_node->children();
37                 while($hotspot_node_2 = array_shift($hotspot_node_1)) {
38                   if ($hotspot_node_2->type == 1) {
39                     if ($hotspot_node_2->tagname == "status") {
40                       $result[$i]->status=$hotspot_node_2->get_content();
41                     }
42                   }
43                 }
44               }
45             }
46           }
47           # récupération du nom de la node
48           if ($hotspot->tagname() == "name") {
49             $result[$i]->name = $hotspot->get_content();
50           }
51           # récupération du nom de la ville
52           if ($hotspot->tagname() == "city") {
53             $result[$i]->city = $hotspot->get_content();
54           }
55           # récupération du n° de l'adresse
56           if ($hotspot->tagname() == "civicNumber") {
57             $result[$i]->civicnumber = $hotspot->get_content();
58           }
59           # récupération du nom de la rue
60           if ($hotspot->tagname() == "streetAddress") {
61             $result[$i]->adresse = $hotspot->get_content();
62           }
63           # récupération du code postal
64           if ($hotspot->tagname() == "postalCode") {
65             $result[$i]->postal = $hotspot->get_content();
66           }
67           # récupération de l'adresse du site internet
68           if ($hotspot->tagname() == "webSiteUrl") {
69             $result[$i]->url = $hotspot->get_content();
70           }
71           # récupération de la description
72           if ($hotspot->tagname() == "description") {
73             $result[$i]->description = trim($hotspot->get_content());
74             #$result[$i]->description = check_plain($result[$i]->description);
75             $result[$i]->description = nl2br($result[$i]->description);
76             $result[$i]->description = str_replace(CHR(10),"",$result[$i]->description);
77             $result[$i]->description = str_replace(CHR(13),"",$result[$i]->description);
78             $result[$i]->description = str_replace("&lt;", "<", $result[$i]->description);
79             $result[$i]->description = str_replace("&gt;", ">", $result[$i]->description);
80             $result[$i]->description = str_replace("'", "\'", $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   return $result;
97 }
98
99
100
101 function markers($xml) {
102   $result = parse_xml($xml);
103   # on prépare les données pour les transmettre au module gmap de drupal
104   $i = 0;
105   while($node = array_shift($result)) {
106     if ( ($node->lat != 0) && (isset($node->long) != 0) ) {
107       # test à décommenter pour n'afficher que les nodes du villes.
108       #if ( $node->city == "Le Mans" ) {
109         if ($node->status == "up" ) {
110           $marker = 'up';
111         }
112         else if ($node->status == "down" ) {
113           $marker = 'down';
114         }
115         else {
116           $marker = 'unknown';
117         }
118
119         $label = "";
120         if (isset($node->name)) $label = "$label <b>$node->name</b> <br/>";
121         if (isset($node->description)) $label = "$label $node->description<br/><br/>";
122         $address = adresse($node);
123         $label = "$label $address";
124         if (isset($node->url)) $label = "$label <p><a href=\"$node->url\">Site internet</a></p>";
125         # le tableau mymarkers est utilisé par le module gmap de drupal
126         # mymarkers est donc spécifique à drupal
127         $mymarkers[$i]=array('status' => $marker,
128                              'label' => $label,
129                              'point' => "$node->lat,$node->long");
130       #}
131     }
132     $i = $i+1;
133   }
134   return $mymarkers;
135 }
136
137
138 ?>
Note: See TracBrowser for help on using the browser.