Function Reference: geodir_get_map_cache
Summary
Get the map cache if it exists.
Parameters
- $cache
- (string) (required) The JSON string cache if exists.
- Default: None
Return Values
- (string)
Change Log
Since: 1.6.22
Source File
geodir_get_map_cache() is located in geodirectory-functions/map-functions/get_markers.php [Line: 24]
Source Code
function geodir_get_map_cache($cache){ // if a search is going on then dont even try to check for cache. if(isset($_REQUEST['search']) && !empty($_REQUEST['search'])){ return $cache; } $url_params = array(); $url_params[] = isset($_REQUEST['cat_id']) ? $_REQUEST['cat_id'] : ''; $url_params[] = isset($_REQUEST['zl']) ? $_REQUEST['zl'] : ''; $url_params[] = isset($_REQUEST['gd_map_h']) ? $_REQUEST['gd_map_h'] : ''; $url_params[] = isset($_REQUEST['gd_map_w']) ? $_REQUEST['gd_map_w'] : ''; $url_params[] = isset($_REQUEST['gd_posttype']) ? $_REQUEST['gd_posttype'] : ''; $url_params[] = isset($_REQUEST['lat_ne']) ? $_REQUEST['lat_ne'] : ''; $url_params[] = isset($_REQUEST['lon_ne']) ? $_REQUEST['lon_ne'] : ''; $url_params[] = isset($_REQUEST['lat_sw']) ? $_REQUEST['lat_sw'] : ''; $url_params[] = isset($_REQUEST['lon_sw']) ? $_REQUEST['lon_sw'] : ''; $url_params[] = isset($_REQUEST['gd_country']) ? $_REQUEST['gd_country'] : ''; $url_params[] = isset($_REQUEST['gd_region']) ? $_REQUEST['gd_region'] : ''; $url_params[] = isset($_REQUEST['gd_city']) ? $_REQUEST['gd_city'] : ''; $url_params[] = isset($_REQUEST['gd_neighbourhood']) ? $_REQUEST['gd_neighbourhood'] : ''; $file_name = sanitize_file_name( md5( implode("-",$url_params) ) ); $blog_id = get_current_blog_id(); if($blog_id>1){ $file_name = $blog_id."_".$file_name; } $file_path = realpath(dirname(__FILE__))."/map-cache/"; if(file_exists($file_path.$file_name.".json")){ ob_start(); readfile($file_path.$file_name.".json"); // readfile is quicker then file get contents $content = ob_get_clean(); // do the cache delete stuff $cache_time = get_option('geodir_map_cache'); if(!$cache_time){ $cache_time = time(); update_option('geodir_map_cache', $cache_time); } if((time() - $cache_time) > 86400){ // delete the cache every 24 hours geodir_delete_map_cache(); } return $content; } return $cache; }