]> git.openstreetmap.org Git - nominatim.git/blob - lib/template/search-xml.php
54217933ef7d8962a5e3934b3186b6ae9cb8d57d
[nominatim.git] / lib / template / search-xml.php
1 <?php
2         header("content-type: text/xml; charset=UTF-8");
3
4         echo "<";
5         echo "?xml version=\"1.0\" encoding=\"UTF-8\" ?";
6         echo ">\n";
7
8         echo "<";
9         echo (isset($sXmlRootTag)?$sXmlRootTag:'searchresults');
10         echo " timestamp='".date(DATE_RFC822)."'";
11         echo " attribution='Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright'";
12         echo " querystring='".htmlspecialchars($sQuery, ENT_QUOTES)."'";
13         if ($sViewBox) echo " viewbox='".htmlspecialchars($sViewBox, ENT_QUOTES)."'";
14         echo " polygon='".($bShowPolygons?'true':'false')."'";
15         if (sizeof($aExcludePlaceIDs))
16         {
17                 echo " exclude_place_ids='".htmlspecialchars(join(',',$aExcludePlaceIDs))."'";
18         }
19         if ($sMoreURL)
20         {
21                 echo " more_url='".htmlspecialchars($sMoreURL)."'";
22         }
23         echo ">\n";
24
25         foreach($aSearchResults as $iResNum => $aResult)
26         {
27                 echo "<place place_id='".$aResult['place_id']."'";
28                 $sOSMType = ($aResult['osm_type'] == 'N'?'node':($aResult['osm_type'] == 'W'?'way':($aResult['osm_type'] == 'R'?'relation':($aResult['osm_type'] == 'T'?'tiger':''))));
29                 if ($sOSMType)
30                 {
31                         echo " osm_type='$sOSMType'";
32                         echo " osm_id='".$aResult['osm_id']."'";
33                 }
34                 echo " place_rank='".$aResult['rank_search']."'";
35
36                 if (isset($aResult['aBoundingBox']))
37                 {
38                         echo ' boundingbox="';
39                         echo join(',',$aResult['aBoundingBox']);
40                         echo '"';
41
42                         if ($bShowPolygons && isset($aResult['aPolyPoints']))
43                         {
44                                 echo ' polygonpoints=\'';
45                                 echo json_encode($aResult['aPolyPoints']);
46                                 echo '\'';
47                         }
48                 }
49
50                 if (isset($aResult['asgeojson']))
51                 {
52                         echo ' geojson=\'';
53                         echo $aResult['asgeojson'];
54                         echo '\'';
55                 }
56
57                 if (isset($aResult['assvg']))
58                 {
59                         echo ' geosvg=\'';
60                         echo $aResult['assvg'];
61                         echo '\'';
62                 }
63
64                 if (isset($aResult['astext']))
65                 {
66                         echo ' geotext=\'';
67                         echo $aResult['astext'];
68                         echo '\'';
69                 }
70
71                 if (isset($aResult['zoom']))
72                 {
73                         echo " zoom='".$aResult['zoom']."'";
74                 }
75
76                 echo " lat='".$aResult['lat']."'";
77                 echo " lon='".$aResult['lon']."'";
78                 echo " display_name='".htmlspecialchars($aResult['name'], ENT_QUOTES)."'";
79
80                 echo " class='".htmlspecialchars($aResult['class'])."'";
81                 echo " type='".htmlspecialchars($aResult['type'], ENT_QUOTES)."'";
82                 echo " importance='".htmlspecialchars($aResult['importance'])."'";
83                 if (isset($aResult['icon']) && $aResult['icon'])
84                 {
85                         echo " icon='".htmlspecialchars($aResult['icon'], ENT_QUOTES)."'";
86                 }
87
88                 $bHasDelim = false;
89
90                 if (isset($aResult['askml']))
91                 {
92                         if (!$bHasDelim)
93                         {
94                                 $bHasDelim = true;
95                                 echo ">";
96                         }
97                         echo "\n<geokml>";
98                         echo $aResult['askml'];
99                         echo "</geokml>";
100                 }
101
102                 if (isset($aResult['sExtraTags']))
103                 {
104                         if (!$bHasDelim)
105                         {
106                                 $bHasDelim = true;
107                                 echo ">";
108                         }
109                         echo "\n<extratags>";
110                         foreach ($aResult['sExtraTags'] as $sKey => $sValue)
111                         {
112                                 echo '<tag key="'.htmlspecialchars($sKey).'" value="'.htmlspecialchars($sValue).'"/>';
113                         }
114                         echo "</extratags>";
115                 }
116
117                 if (isset($aResult['sNameDetails']))
118                 {
119                         if (!$bHasDelim)
120                         {
121                                 $bHasDelim = true;
122                                 echo ">";
123                         }
124                         echo "\n<namedetails>";
125                         foreach ($aResult['sNameDetails'] as $sKey => $sValue)
126                         {
127                                 echo '<name desc="'.htmlspecialchars($sKey).'">';
128                                 echo htmlspecialchars($sValue);
129                                 echo "</name>";
130                         }
131                         echo "</namedetails>";
132                 }
133
134                 if (isset($aResult['address']))
135                 {
136                         if (!$bHasDelim)
137                         {
138                                 $bHasDelim = true;
139                                 echo ">";
140                         }
141                         echo "\n";
142                         foreach($aResult['address'] as $sKey => $sValue)
143                         {
144                                 $sKey = str_replace(' ','_',$sKey);
145                                 echo "<$sKey>";
146                                 echo htmlspecialchars($sValue);
147                                 echo "</$sKey>";
148                         }
149                 }
150
151                 if ($bHasDelim)
152                 {
153                         echo "</place>";
154                 }
155                 else
156                 {
157                         echo "/>";
158                 }
159         }
160         
161         echo "</" . (isset($sXmlRootTag)?$sXmlRootTag:'searchresults') . ">";