diff --git a/.gitignore b/.gitignore index d99fbf9..dd4c15e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ *~ .vagrant +www/include/config_dev.php www/include/config_local*.php www/include/secrets*.php www/test*.php diff --git a/www/.htaccess b/www/.htaccess index 07e9f03..8a9c694 100644 --- a/www/.htaccess +++ b/www/.htaccess @@ -75,9 +75,15 @@ RewriteRule ^contact/?$ contact.php [L,QSA] RewriteRule ^id/?$ id.php [L] # mostly so we can get cfg.abs_root_url RewriteRule ^id/([0-9]+)/?$ id.php?id=$1&%{QUERY_STRING} [L] +RewriteRule ^id/([0-9]+)/nearby/?$ id.php?id=$1&nearby=1&%{QUERY_STRING} [L] RewriteRule ^id/([0-9]+)/info(.json)?$ info.php?id=$1&%{QUERY_STRING} [L] +RewriteRule ^nearby/?$ nearby.php?%{QUERY_STRING} [L] +RewriteRule ^nearby/([0-9]+)/?$ nearby.php?id=$1&%{QUERY_STRING} [L] + +RewriteRule ^placetypes/([a-z]+)/?$ placetype.php?placetype=$1&%{QUERY_STRING} [L] + RewriteRule ^tags/([a-z]+)/?$ tag.php?tag=$1&%{QUERY_STRING} [L] # See all this stuff that's been commented out? It's a lot of hoop-jumping diff --git a/www/id.php b/www/id.php index acd7696..f53101f 100644 --- a/www/id.php +++ b/www/id.php @@ -16,6 +16,12 @@ error_404(); } + if (get_isset("nearby")){ + $url = whosonfirst_places_nearby_url_for_place($place); + header("location: {$url}"); + exit(); + } + $parent_id = $place["wof:parent_id"]; if ($parent_id != -1){ @@ -24,7 +30,7 @@ } $GLOBALS['smarty']->assign_by_ref("place", $place); - $GLOBALS['smarty']->display("page_id.txt", $place); + $GLOBALS['smarty']->display("page_id.txt"); exit(); ?> \ No newline at end of file diff --git a/www/include/config.php b/www/include/config.php index 9c3430a..c8286d8 100644 --- a/www/include/config.php +++ b/www/include/config.php @@ -4,7 +4,11 @@ # Things you may want to change in a hurry $GLOBALS['cfg']['site_name'] = 'Who\'s On First API'; +<<<<<<< HEAD $GLOBALS['cfg']['environment'] = 'prod'; +======= + $GLOBALS['cfg']['environment'] = 'dev'; +>>>>>>> 82c38130bb71707250efc609fa436ffadb482eb5 $GLOBALS['cfg']['site_disabled'] = 0; $GLOBALS['cfg']['site_disabled_retry_after'] = 0; # seconds; if set will return HTTP Retry-After header diff --git a/www/include/init.php b/www/include/init.php index a6189bd..fca46b7 100644 --- a/www/include/init.php +++ b/www/include/init.php @@ -238,6 +238,7 @@ function filter_strict_quot($str){ $local_secrets, $server_secrets, $host_secrets ); + foreach ($to_check as $path){ if (file_exists($path)){ @@ -245,6 +246,7 @@ function filter_strict_quot($str){ } } + foreach ($config_files as $path){ # echo "load {$path}
"; @@ -627,4 +629,4 @@ function handle_error_notices($errno, $errstr){ } } - # end of flamework-api stuff for API site keys \ No newline at end of file + # end of flamework-api stuff for API site keys diff --git a/www/include/lib_whosonfirst_places.php b/www/include/lib_whosonfirst_places.php index 0245791..42841d1 100644 --- a/www/include/lib_whosonfirst_places.php +++ b/www/include/lib_whosonfirst_places.php @@ -265,6 +265,14 @@ function whosonfirst_places_url_for_place($place){ ######################################################################## + function whosonfirst_places_nearby_url_for_place($place){ + + $enc_id = urlencode($place["wof:id"]); + return $GLOBALS["cfg"]["abs_root_url"] . "nearby/{$enc_id}/"; + } + + ######################################################################## + function whosonfirst_places_data_url_for_place($place){ loadlib("whosonfirst_uri"); diff --git a/www/javascript/flamework.api.js b/www/javascript/flamework.api.js index 6766b2d..2b05882 100644 --- a/www/javascript/flamework.api.js +++ b/www/javascript/flamework.api.js @@ -18,7 +18,7 @@ flamework.api = function(){ '_handlers': { 'endpoint': null_handler, - 'accesstoken': null_handler, + 'authentication': null_handler, }, 'set_handler': function(target, handler){ @@ -90,18 +90,12 @@ flamework.api = function(){ form_data.append('method', method); - if (! form_data.has('access_token')){ + var set_auth = self.get_handler('authentication'); - var get_accesstoken = self.get_handler('accesstoken'); - - if (! get_accesstoken){ - dothis_onerror(self.destruct("there is no accesstoken handler")); - return false; - } - - form_data.append('access_token', get_accesstoken()); + if (set_auth){ + form_data = set_auth(form_data); } - + var onload = function(rsp){ var target = rsp.target; diff --git a/www/javascript/mapzen.places.api.js b/www/javascript/mapzen.places.api.js new file mode 100644 index 0000000..eef62a1 --- /dev/null +++ b/www/javascript/mapzen.places.api.js @@ -0,0 +1,47 @@ +var mapzen = mapzen || {}; +mapzen.places = mapzen.places || {}; + +mapzen.places.api = (function(){ + + var _api = undefined; + + var self = { + + 'init': function(){ + + _api = new flamework.api(); + _api.set_handler('endpoint', mapzen.places.api.endpoint); + _api.set_handler('authentication', mapzen.places.api.authentication); + }, + + 'execute_method': function(method, data, on_success, on_error){ + _api.call(method, data, on_success, on_error); + }, + + 'call': function(method, data, on_success, on_error){ + _api.call(method, data, on_success, on_error); + }, + + 'endpoint': function(){ + return document.body.getAttribute("data-mapzen-api-endpoint"); + }, + + 'authentication': function(form_data){ + + var key = document.body.getAttribute("data-mapzen-api-key"); + + if (! form_data.has("api_key")){ + form_data.append("api_key", key); + } + + return form_data; + } + } + + return self; + +})(); + +window.addEventListener('load', function(e){ + mapzen.places.api.init(); +}); diff --git a/www/javascript/mapzen.places.map.js b/www/javascript/mapzen.places.map.js index 807f563..978bb36 100644 --- a/www/javascript/mapzen.places.map.js +++ b/www/javascript/mapzen.places.map.js @@ -32,6 +32,22 @@ mapzen.places.map = (function(){ return maps[map_id]; }, + + 'draw_nearby_map': function(map_id, cb){ + + var map_el = document.getElementById(map_id); + var map = self.get_map(map_id); + + if (map_el.getAttribute("data-wof-id")){ + return self.draw_place_map(map_id, cb); + } + + console.log(location.href); + + map.setView([37.7749, -122.4194], 12); + + cb(map); + }, 'draw_place_map': function(map_id, cb){ @@ -108,13 +124,52 @@ mapzen.places.map = (function(){ 'add_geojson_to_map': function(map, geojson, more){ + console.log("GEOJSON", geojson); + if (! more){ more = {}; } - + + var point_style = { + "color": "#000", + "weight": 2, + "opacity": 1, + "radius": 6, + "fillColor": "#0BBDFF", + "fillOpacity": 1 + }; + + var point_handler = function(feature, latlon){ + + var props = feature['properties']; + var label = props['wof:name']; + + var m = L.circleMarker(latlon, point_style); + m.bindTooltip(label); + + return m; + }; + + var feature_handler = function(feature, layer) { + + var props = feature['properties']; + var wofid = props["wof:id"]; + + layer.on('click', function (e){ + + var enc_id = encodeURIComponent(wofid); + + var abs_root_url = document.body.getAttribute("data-abs-root-url"); + var url = abs_root_url + "id/" + enc_id + "/"; + + location.href = url; + }); + + }; + var args = { - // "style": style, - // "pointToLayer": handler + "pointToLayer": point_handler, + "onEachFeature": feature_handler, } // console.log("[map][geojson] ADD", geojson, args); diff --git a/www/javascript/mapzen.places.nearby.init.js b/www/javascript/mapzen.places.nearby.init.js new file mode 100644 index 0000000..e35d2e8 --- /dev/null +++ b/www/javascript/mapzen.places.nearby.init.js @@ -0,0 +1,85 @@ +window.addEventListener("load", function load(event){ + + var cb = function(map){ + + L.Mapzen.hash({ + map: map + }); + + var nearby_layer; + + var nearby = function(){ + + var center = map.getCenter(); + + var lat = center.lat; + var lon = center.lng; + + var method = "whosonfirst.places.getNearby"; + + var args = { + "latitude": lat, + "longitude": lon, + "per_page": 200, + "extras": "geom:", + }; + + var on_success = function(rsp){ + + var features = []; + + var places = rsp["places"]; + var count_places = places.length; + + for (var i=0; i < count_places; i++){ + + var place = places[i]; + + var name = place["wof:name"]; + + var lat = place["geom:latitude"]; + var lon = place["geom:longitude"]; + + var coords = [ lon, lat ]; + + var geom = { + "type": "Point", + "coordinates": coords, + }; + + var props = place; + + var feature = { + "type": "Feature", + "geometry": geom, + "properties": props, + }; + + features.push(feature); + } + + var feature_collection = { + "type": "FeatureCollection", + "features": features, + }; + + nearby_layer = mapzen.places.map.add_geojson_to_map(map, feature_collection); + }; + + mapzen.places.api.execute_method(method, args, function(rsp){ + on_success(rsp); + }); + + if (nearby_layer){ + nearby_layer.remove(map); + } + }; + + map.on("dragend", nearby); + map.on("zoomend", nearby); + + nearby(); + }; + + mapzen.places.map.draw_nearby_map("map", cb); +}); diff --git a/www/javascript/mapzen.whosonfirst.api.js b/www/javascript/mapzen.whosonfirst.api.js index 85e745c..2bce447 100644 --- a/www/javascript/mapzen.whosonfirst.api.js +++ b/www/javascript/mapzen.whosonfirst.api.js @@ -11,7 +11,7 @@ mapzen.whosonfirst.api = (function(){ _api = new flamework.api(); _api.set_handler('endpoint', mapzen.whosonfirst.api.endpoint); - _api.set_handler('accesstoken', mapzen.whosonfirst.api.accesstoken); + _api.set_handler('authentication', mapzen.whosonfirst.api.authentication); }, 'call': function(method, data, on_success, on_error){ @@ -22,8 +22,15 @@ mapzen.whosonfirst.api = (function(){ return document.body.getAttribute("data-api-endpoint"); }, - 'accesstoken': function(){ - return document.body.getAttribute("data-api-access-token"); + 'authentication': function(form_data){ + + var access_token = document.body.getAttribute("data-api-access-token"); + + if (! form_data.has("access_token")){ + form_data.append("access_token", access_token); + } + + return form_data; } } diff --git a/www/nearby.php b/www/nearby.php new file mode 100644 index 0000000..11217fa --- /dev/null +++ b/www/nearby.php @@ -0,0 +1,26 @@ +assign_by_ref("place", $place); + } + + $GLOBALS['smarty']->display("page_nearby.txt", $place); + exit(); +?> \ No newline at end of file diff --git a/www/placetype.php b/www/placetype.php new file mode 100644 index 0000000..e4390ea --- /dev/null +++ b/www/placetype.php @@ -0,0 +1,20 @@ +assign_by_ref("placetype", $pt); + $GLOBALS['smarty']->display("page_placetype.txt"); + + exit(); +?> \ No newline at end of file diff --git a/www/templates/inc_head.txt b/www/templates/inc_head.txt index 8d0d808..2b3756d 100644 --- a/www/templates/inc_head.txt +++ b/www/templates/inc_head.txt @@ -37,6 +37,6 @@ - + {include file="inc_head_navi.txt"} diff --git a/www/templates/page_id.txt b/www/templates/page_id.txt index 2389aa9..31a98c2 100644 --- a/www/templates/page_id.txt +++ b/www/templates/page_id.txt @@ -51,7 +51,7 @@ {capture assign="addr_full"}{$place|@whosonfirst_places_property:"addr:full"}{/capture} {capture assign="addr_phone"}{$place|@whosonfirst_places_property:"addr:phone"}{/capture} {assign var="wof_tags" value=$place|@whosonfirst_places_property:"wof:tags"} - {if $addr_full != ""}
  • Its address is {$addr_full|@escape} and its exact latitude and longitude is {$place|@whosonfirst_places_property:"geom:latitude"|@escape}, {$place|@whosonfirst_places_property:"geom:longitude"|@escape}.
  • {/if} + {if $addr_full != ""}
  • Its address is {$addr_full|@escape} and its exact latitude and longitude is {$place|@whosonfirst_places_property:"geom:latitude"|@escape}, {$place|@whosonfirst_places_property:"geom:longitude"|@escape}.
  • {/if} {if $addr_phone != ""}
  • Its phone number is {$addr_phone|@escape}.
  • {/if} {if $wof_tags|@count}
  • It is tagged {foreach from=$wof_tags item="tag" name="tags"}{$tag|@escape}{if $smarty.foreach.tags.last}.{else} and {/if}{/foreach}{/if}
  • diff --git a/www/templates/page_nearby.txt b/www/templates/page_nearby.txt new file mode 100644 index 0000000..06e9e4f --- /dev/null +++ b/www/templates/page_nearby.txt @@ -0,0 +1,22 @@ +{capture assign="page_title"}Nearby{/capture} +{include file="inc_head.txt"} + +
    +
    + +{if $place} +{capture assign="wof_id"}{$place|@whosonfirst_places_property:"wof:id"}{/capture} +{capture assign="wof_name"}{$place|@whosonfirst_places_property:"wof:name"}{/capture} + +
    +{else} +
    +{/if} + +
    +
    + + + + +{include file="inc_foot.txt"} diff --git a/www/templates/page_placetype.txt b/www/templates/page_placetype.txt new file mode 100644 index 0000000..f310cc6 --- /dev/null +++ b/www/templates/page_placetype.txt @@ -0,0 +1,11 @@ +{include file="inc_head.txt"} + +
    +
    + +
    + +
    +
    + +{include file="inc_foot.txt"}