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