]> git.openstreetmap.org Git - nominatim.git/blob - lib/template/search-xml.php
Merge remote-tracking branch 'upstream/master'
[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':'')));
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 $aResult['aBoundingBox'][0];
40                         echo ','.$aResult['aBoundingBox'][1];
41                         echo ','.$aResult['aBoundingBox'][2];
42                         echo ','.$aResult['aBoundingBox'][3];
43                         echo '"';
44
45                         if ($bShowPolygons && isset($aResult['aPolyPoints']))
46                         {
47                                 echo ' polygonpoints=\'';
48                                 echo json_encode($aResult['aPolyPoints']);
49                                 echo '\'';
50                         }
51                 }
52
53                 if (isset($aResult['asgeojson']))
54                 {
55                         echo ' geojson=\'';
56                         echo $aResult['asgeojson'];
57                         echo '\'';
58                 }
59
60                 if (isset($aResult['assvg']))
61                 {
62                         echo ' geosvg=\'';
63                         echo $aResult['assvg'];
64                         echo '\'';
65                 }
66
67                 if (isset($aResult['astext']))
68                 {
69                         echo ' geotext=\'';
70                         echo $aResult['astext'];
71                         echo '\'';
72                 }
73
74                 if (isset($aResult['zoom']))
75                 {
76                         echo " zoom='".$aResult['zoom']."'";
77                 }
78
79                 echo " lat='".$aResult['lat']."'";
80                 echo " lon='".$aResult['lon']."'";
81                 echo " display_name='".htmlspecialchars($aResult['name'], ENT_QUOTES)."'";
82
83                 echo " class='".htmlspecialchars($aResult['class'])."'";
84                 echo " type='".htmlspecialchars($aResult['type'], ENT_QUOTES)."'";
85                 echo " importance='".htmlspecialchars($aResult['importance'])."'";
86                 if (isset($aResult['icon']) && $aResult['icon'])
87                 {
88                         echo " icon='".htmlspecialchars($aResult['icon'], ENT_QUOTES)."'";
89                 }
90
91                 $bHasDelim = false;
92
93                 if (isset($aResult['askml']))
94                 {
95                         if (!$bHasDelim)
96                         {
97                                 $bHasDelim = true;
98                                 echo ">";
99                         }
100                         echo "\n<geokml>";
101                         echo $aResult['askml'];
102                         echo "</geokml>";
103                 }
104
105                 if (isset($aResult['sExtraTags']))
106                 {
107                         if (!$bHasDelim)
108                         {
109                                 $bHasDelim = true;
110                                 echo ">";
111                         }
112                         echo "\n<extratags>";
113                         foreach ($aResult['sExtraTags'] as $sKey => $sValue)
114                         {
115                                 echo '<tag key="'.htmlspecialchars($sKey).'" value="'.htmlspecialchars($sValue).'"/>';
116                         }
117                         echo "</extratags>";
118                 }
119
120                 if (isset($aResult['sNameDetails']))
121                 {
122                         if (!$bHasDelim)
123                         {
124                                 $bHasDelim = true;
125                                 echo ">";
126                         }
127                         echo "\n<namedetails>";
128                         foreach ($aResult['sNameDetails'] as $sKey => $sValue)
129                         {
130                                 echo '<name desc="'.htmlspecialchars($sKey).'">';
131                                 echo htmlspecialchars($sValue);
132                                 echo "</name>";
133                         }
134                         echo "</namedetails>";
135                 }
136
137                 if (isset($aResult['address']))
138                 {
139                         if (!$bHasDelim)
140                         {
141                                 $bHasDelim = true;
142                                 echo ">";
143                         }
144                         echo "\n";
145                         foreach($aResult['address'] as $sKey => $sValue)
146                         {
147                                 $sKey = str_replace(' ','_',$sKey);
148                                 echo "<$sKey>";
149                                 echo htmlspecialchars($sValue);
150                                 echo "</$sKey>";
151                         }
152                 }
153
154                 if ($bHasDelim)
155                 {
156                         echo "</place>";
157                 }
158                 else
159                 {
160                         echo "/>";
161                 }
162         }
163         
164         echo "</" . (isset($sXmlRootTag)?$sXmlRootTag:'searchresults') . ">";