Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 551d061
Showing
15 changed files
with
1,427 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
lib_emplacify | ||
-- | ||
|
||
HEY LOOK! THIS ISN'T QUITE DONE YET!! REALLY. THERE ARE STILL BUGS. | ||
|
||
Start here: [http://www.aaronland.info/weblog/2010/12/06/urmum/#enplacify](http://www.aaronland.info/weblog/2010/12/06/urmum/#enplacify) | ||
|
||
lib_emplacify is *designed* to be used in conjuction with [flamework](https://github.com/straup/flamework) (as of this writing, specifically my fork). Although it probably doesn't need to be part of core flamework I've already found uses for it in two other projects that [hold hands](https://github.com/Citytracking/dotspotting/blob/master/README.FLAMEWORK.md) with flamework so now it's a little bundle of libraries and functions and can check out and slot in where necessary. | ||
|
||
If you don't want to bother using flamework though I've included just enough real and mock flamework code so that this code will run on its own. Take a look at the `test.php` file for details. | ||
|
||
See also: | ||
-- | ||
|
||
* [https://github.com/mncaudill/flickr-machinetag-geo](https://github.com/mncaudill/flickr-machinetag-geo) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
<?php | ||
|
||
# | ||
# $Id$ | ||
# | ||
|
||
$GLOBALS['cache_local'] = array(); | ||
$GLOBALS['cache_remote_conns'] = array(); | ||
|
||
################################################################# | ||
|
||
function cache_get($cache_key){ | ||
|
||
if ($GLOBALS['cfg']['cache_force_refresh']){ | ||
|
||
return array( | ||
'ok' => 0, | ||
'error' => 'force refresh' | ||
); | ||
} | ||
|
||
$cache_key = _cache_prepare_cache_key($cache_key); | ||
log_notice("cache", "fetch cache key {$cache_key}"); | ||
|
||
if (isset($GLOBALS['cache_local'][$cache_key])){ | ||
|
||
return array( | ||
'ok' => 1, | ||
'cache' => 'local', | ||
'cache_key' => $cache_key, | ||
'data' => $GLOBALS['cache_local'][$cache_key], | ||
); | ||
} | ||
|
||
$remote_rsp = _cache_do_remote('get', $cache_key); | ||
|
||
return $remote_rsp; | ||
} | ||
|
||
################################################################# | ||
|
||
function cache_set($cache_key, $data, $store_locally=0){ | ||
|
||
$cache_key = _cache_prepare_cache_key($cache_key); | ||
log_notice("cache", "set cache key {$cache_key}"); | ||
|
||
if ($store_locally){ | ||
$GLOBALS['cache_local'][$cache_key] = $data; | ||
} | ||
|
||
$remote_rsp = _cache_do_remote('set', $cache_key, $data); | ||
|
||
return array( | ||
'ok' => 1 | ||
); | ||
} | ||
|
||
################################################################# | ||
|
||
function cache_unset($cache_key){ | ||
|
||
$cache_key = _cache_prepare_cache_key($cache_key); | ||
log_notice("cache", "unset cache key {$cache_key}"); | ||
|
||
if (isset($GLOBALS['cache_local'][$cache_key])){ | ||
unset($GLOBALS['cache_local'][$cache_key]); | ||
} | ||
|
||
$remote_rsp = _cache_do_remote('unset', $cache_key); | ||
|
||
return array( | ||
'ok' => 1 | ||
); | ||
} | ||
|
||
################################################################# | ||
|
||
function _cache_prepare_cache_key($key){ | ||
|
||
if (! $GLOBALS['cfg']['cache_prefix']){ | ||
return $key; | ||
} | ||
|
||
return "{$GLOBALS['cfg']['cache_prefix']}_{$key}"; | ||
} | ||
|
||
################################################################# | ||
|
||
function _cache_do_remote($method, $key, $data=null){ | ||
|
||
$engine = trim($GLOBALS['cfg']['cache_remote_engine']); | ||
|
||
if (! $engine){ | ||
return array( 'ok' => 0, 'error' => 'Remote caching is not enabled' ); | ||
} | ||
|
||
$remote_lib = "cache_{$engine}"; | ||
$remote_func = "cache_{$engine}_{$method}"; | ||
|
||
$args = ($data) ? array($key, $data) : array($key); | ||
|
||
loadlib($remote_lib); | ||
$rsp = call_user_func_array($remote_func, $args); | ||
|
||
$rsp['cache_key'] = $key; | ||
$rsp['cache'] = $engine; | ||
|
||
return $rsp; | ||
} | ||
|
||
################################################################# | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?php | ||
|
||
# | ||
# $Id$ | ||
# | ||
|
||
################################################################# | ||
|
||
loadlib("http"); | ||
|
||
################################################################# | ||
|
||
function geo_geocode_service_map($string_keys=0){ | ||
|
||
# 0 means 'not geocoded' | ||
|
||
$map = array( | ||
1 => 'yahoo', | ||
); | ||
|
||
if ($string_keys){ | ||
$map = array_flip($map); | ||
} | ||
|
||
return $map; | ||
} | ||
|
||
################################################################# | ||
|
||
function geo_geocode_string($string){ | ||
|
||
$service = $GLOBALS['cfg']['geo_geocoding_service']; | ||
$func = "geo_geocode_{$service}"; | ||
|
||
if ((! $service) || (! is_callable($func))){ | ||
|
||
return array( | ||
'ok' => 0, | ||
'error' => 'Unknown or undefined service', | ||
); | ||
} | ||
|
||
$rsp = call_user_func($func, $string); | ||
|
||
$map = geo_geocode_service_map('string keys'); | ||
$rsp['service_id'] = $map[ $service ]; | ||
|
||
return $rsp; | ||
} | ||
|
||
################################################################# | ||
|
||
function geo_geocode_yahoo($string){ | ||
|
||
$api_key = $GLOBALS['cfg']['geo_geocoding_yahoo_apikey']; | ||
|
||
$url = 'http://where.yahooapis.com/geocode?q='.urlencode($string).'&flags=j&appid='.urlencode($api_key); | ||
|
||
$http_rsp = http_get($url); | ||
|
||
$rsp = array( | ||
'ok' => 0, | ||
'error' => 'unknown error' | ||
); | ||
|
||
if ($http_rsp['ok']){ | ||
|
||
# pass in a 1 to disable 'shit-mode' | ||
$geocode_response = json_decode($http_rsp['body'], 1); | ||
|
||
if ($geocode_response['ResultSet']['Found'] == 1){ | ||
|
||
$results = $geocode_response['ResultSet']['Results'][0]; | ||
|
||
$rsp['ok'] = 1; | ||
$rsp['error'] = null; | ||
$rsp['latitude'] = (float)$results['latitude']; | ||
$rsp['longitude'] = (float)$results['longitude']; | ||
$rsp['extras']['woeid'] = (float)$results['woeid']; | ||
} else { | ||
$rsp['error'] = 'could not geocode'; | ||
} | ||
|
||
} | ||
|
||
return $rsp; | ||
} | ||
|
||
?> |
Oops, something went wrong.