]> git.openstreetmap.org Git - nominatim.git/blob - lib/output.php
Merge branch 'separate-compilation' of https://github.com/eyusupov/Nominatim into...
[nominatim.git] / lib / output.php
1 <?php
2
3
4 function formatOSMType($sType, $bIncludeExternal = true)
5 {
6     if ($sType == 'N') return 'node';
7     if ($sType == 'W') return 'way';
8     if ($sType == 'R') return 'relation';
9
10     if (!$bIncludeExternal) return '';
11
12     if ($sType == 'T') return 'way';
13     if ($sType == 'I') return 'way';
14
15     // not handled: P, L
16
17     return '';
18 }
19
20 function osmLink($aFeature, $sRefText = false)
21 {
22     $sOSMType = formatOSMType($aFeature['osm_type'], false);
23     if ($sOSMType) {
24         return '<a href="//www.openstreetmap.org/'.$sOSMType.'/'.$aFeature['osm_id'].'">'.$sOSMType.' '.($sRefText?$sRefText:$aFeature['osm_id']).'</a>';
25     }
26     return '';
27 }
28
29 function wikipediaLink($aFeature)
30 {
31     if ($aFeature['wikipedia']) {
32         list($sLanguage, $sArticle) = explode(':', $aFeature['wikipedia']);
33         return '<a href="https://'.$sLanguage.'.wikipedia.org/wiki/'.urlencode($sArticle).'" target="_blank">'.$aFeature['wikipedia'].'</a>';
34     }
35     return '';
36 }
37
38 function detailsLink($aFeature, $sTitle = false, $sExtraProperties = false)
39 {
40     if (!$aFeature['place_id']) return '';
41
42     $sHtml = '<a ';
43     if ($sExtraProperties) {
44         $sHtml .= $sExtraProperties.' ';
45     }
46
47     $sHtml .= 'href="details.php?place_id='.$aFeature['place_id'].'">'.($sTitle?$sTitle:$aFeature['place_id']).'</a>';
48
49     return $sHtml;
50 }
51
52 function detailsPermaLink($aFeature, $sRefText = false, $sExtraProperties = false)
53 {
54     $sOSMType = formatOSMType($aFeature['osm_type'], false);
55
56     if ($sOSMType) {
57         $sHtml = '<a ';
58         if ($sExtraProperties) {
59             $sHtml .= $sExtraProperties.' ';
60         }
61         $sHtml .= 'href="details.php?osmtype='.$aFeature['osm_type']
62                   .'&osmid='.$aFeature['osm_id'].'&class='.$aFeature['class'].'">';
63
64         if ($sRefText) {
65             $sHtml .= $sRefText.'</a>';
66         } else {
67             $sHtml .= $sOSMType.' '.$aFeature['osm_id'].'</a>';
68         }
69
70         return $sHtml;
71     }
72     return detailsLink($aFeature, $sRefText, $sExtraProperties);
73 }