]> git.openstreetmap.org Git - nominatim.git/blobdiff - lib/output.php
factor out link formatting function and osm type translation
[nominatim.git] / lib / output.php
diff --git a/lib/output.php b/lib/output.php
new file mode 100644 (file)
index 0000000..722d73b
--- /dev/null
@@ -0,0 +1,43 @@
+<?php
+
+       function formatOSMType($sType, $bIncludeExternal=true)
+       {
+               if ($sType == 'N') return 'node';
+               if ($sType == 'W') return 'way';
+               if ($sType == 'R') return 'relation';
+
+               if (!$bIncludeExternal) return '';
+
+               if ($sType == 'T') return 'tiger';
+               if ($sType == 'I') return 'way';
+
+               return '';
+       }
+
+       function osmLink($aFeature, $sRefText=false)
+       {
+               $sOSMType = formatOSMType($aFeature['osm_type'], false);
+               if ($sOSMType)
+               {
+                       return '<a href="//www.openstreetmap.org/'.$sOSMType.'/'.$aFeature['osm_id'].'">'.$sOSMType.' '.($sRefText?$sRefText:$aFeature['osm_id']).'</a>';
+               }
+               return '';
+       }
+
+       function wikipediaLink($aFeature)
+       {
+               if ($aFeature['wikipedia'])
+               {
+                       list($sLanguage, $sArticle) = explode(':',$aFeature['wikipedia']);
+                       return '<a href="https://'.$sLanguage.'.wikipedia.org/wiki/'.urlencode($sArticle).'" target="_blank">'.$aFeature['wikipedia'].'</a>';
+               }
+               return '';
+       }
+
+       function detailsLink($aFeature, $sTitle=false)
+       {
+               if (!$aFeature['place_id']) return '';
+
+               return '<a href="details.php?place_id='.$aFeature['place_id'].'">'.($sTitle?$sTitle:$aFeature['place_id']).'</a>';
+       }
+