Skip to content

Commit

Permalink
feat: adding Maps tab (merge pull request #85 from davidovski/maps)
Browse files Browse the repository at this point in the history
Add Map tab
  • Loading branch information
Ahwxorg authored Nov 12, 2023
2 parents 3f9c411 + 4375310 commit fea00da
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 1 deletion.
37 changes: 37 additions & 0 deletions engines/maps/openstreetmap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
require "engines/text/text.php";
class OSMRequest extends EngineRequest {
public function get_request_url() {

$query_encoded = str_replace("%22", "\"", urlencode($this->query));
$results = array();

// TODO allow the nominatim instance to be customised
$url = "https://nominatim.openstreetmap.org/search?q=$query_encoded&format=json";

return $url;
}


public function parse_results($response) {
$json_response = json_decode($response, true);
if (!$json_response)
return array();

$results = array();
foreach ($json_response as $item) {
array_push($results, array(
"title" => $item["name"],
"description" => $item["display_name"],
"url" => "https://www.openstreetmap.org/node/" . $item["osm_id"],
"base_url" => "www.openstreetmap.org"
));
}
return $results;
}

public static function print_results($results, $opts) {
TextSearch::print_results($results, $opts);
}
}
?>
1 change: 1 addition & 0 deletions locale/en.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"category_videos" => "Videos",
"category_torrents" => "Torrents",
"category_tor" => "Tor",
"category_maps" => "Maps",

"feature_disabled" => "The host has disabled this feature :C",

Expand Down
4 changes: 4 additions & 0 deletions misc/search_engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ function init_search($opts, $mh) {
require "engines/ahmia/hidden_service.php";
return new TorSearch($opts, $mh);

case 5:
require "engines/maps/openstreetmap.php";
return new OSMRequest($opts, $mh);

default:
require "engines/text/text.php";
return new TextSearch($opts, $mh);
Expand Down
2 changes: 1 addition & 1 deletion search.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function print_page_buttons($type, $query, $page) {
<input type="hidden" name="p" value="0">
<div class="sub-search-button-wrapper">
<?php
$categories = array("general", "images", "videos", "torrents", "tor");
$categories = array("general", "images", "videos", "torrents", "tor", "maps");

foreach ($categories as $category)
{
Expand Down
Binary file added static/images/maps_result.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit fea00da

Please sign in to comment.