From: Sarah Hoffmann Date: Sun, 9 Feb 2020 15:05:22 +0000 (+0100) Subject: use detailsPermaLink function on main website as well X-Git-Tag: v3.5.0~86^2~2 X-Git-Url: https://git.openstreetmap.org./nominatim.git/commitdiff_plain/c36fd72f99ce6489b29fa846ec9af650747ab959 use detailsPermaLink function on main website as well --- diff --git a/lib/output.php b/lib/output.php index 8715efbc..4a15ecde 100644 --- a/lib/output.php +++ b/lib/output.php @@ -33,20 +33,39 @@ function wikipediaLink($aFeature) return ''; } -function detailsLink($aFeature, $sTitle = false) +function detailsLink($aFeature, $sTitle = false, $sExtraProperties = false) { if (!$aFeature['place_id']) return ''; - return ''.($sTitle?$sTitle:$aFeature['place_id']).''; + $sHtml = ''.($sTitle?$sTitle:$aFeature['place_id']).''; + + return $sHtml; } -function detailsPermaLink($aFeature, $sRefText = false) +function detailsPermaLink($aFeature, $sRefText = false, $sExtraProperties = false) { $sOSMType = formatOSMType($aFeature['osm_type'], false); if ($sOSMType) { - $sLabel = $sRefText ? $sRefText : $sOSMType.' '.$aFeature['osm_id']; - return ''.$sLabel.''; + $sHtml = ''; + + if ($sRefText) { + $sHtml .= $sRefText.''; + } else { + $sHtml .= $sOSMType.' '.$aFeature['osm_id'].''; + } + + return $sHtml; } - return detailsLink($aFeature, $sRefText); + return detailsLink($aFeature, $sRefText, $sExtraProperties); } diff --git a/lib/template/address-html.php b/lib/template/address-html.php index 9b098428..5be714d3 100644 --- a/lib/template/address-html.php +++ b/lib/template/address-html.php @@ -85,7 +85,7 @@ else echo ' ('.ucwords(str_replace('_',' ',$aResult['type'])).')'; echo '

'.$aResult['lat'].','.$aResult['lon'].'

'; - echo ' details'; + echo detailsPermaLink($aResult, 'details', 'class="btn btn-default btn-xs details"'); echo ''; ?> diff --git a/lib/template/search-html.php b/lib/template/search-html.php index c42476bf..2b8c1495 100644 --- a/lib/template/search-html.php +++ b/lib/template/search-html.php @@ -53,7 +53,7 @@ echo ' ('.ucwords(str_replace('_',' ',$aResult['class'])).')'; else echo ' ('.ucwords(str_replace('_',' ',$aResult['type'])).')'; - echo ' details'; + echo detailsPermaLink($aResult, 'details', 'class="btn btn-default btn-xs details"'); echo ''; $i = $i+1; } diff --git a/test/php/Nominatim/OutputTest.php b/test/php/Nominatim/OutputTest.php index ce9bfa35..48644845 100644 --- a/test/php/Nominatim/OutputTest.php +++ b/test/php/Nominatim/OutputTest.php @@ -51,6 +51,25 @@ class OutputTest extends \PHPUnit\Framework\TestCase ); } + public function testDetailsPermaLinkWithExtraPropertiesNode() + { + $aFeature = array('osm_type' => 'N', 'osm_id'=> 2, 'class' => 'amenity'); + $this->assertSame( + detailsPermaLink($aFeature, 'something', 'class="xtype"'), + 'something' + ); + } + + public function testDetailsPermaLinkWithExtraPropertiesTiger() + { + $aFeature = array('osm_type' => 'T', 'osm_id'=> 5, 'place_id' => 46); + $this->assertSame( + detailsPermaLink($aFeature, 'something', 'class="xtype"'), + 'something' + ); + } + +