diff --git a/srcs/plugins/google_map/google_map b/srcs/plugins/google_map/google_map new file mode 120000 index 0000000..d4d132a --- /dev/null +++ b/srcs/plugins/google_map/google_map @@ -0,0 +1 @@ +/home/www-data/google_map \ No newline at end of file diff --git a/srcs/plugins/map_prof/map_prof_hooks.php b/srcs/plugins/map_prof/map_prof_hooks.php index 7dcd655..edfe1c0 100644 --- a/srcs/plugins/map_prof/map_prof_hooks.php +++ b/srcs/plugins/map_prof/map_prof_hooks.php @@ -9,11 +9,26 @@ Author URI: */ + +/** + * global variables : + */ + +$mp_api_key = 'AIzaSyCvdGV2ssD4ov4a9CuIlQhoJyz5gWWiSvE'; +$mp_marker_icon = '/wp-content/plugins/map_prof/marker.png'; + + + +/** + * inclusions : + */ + include_once(dirname(__FILE__) . '/mp_console_log.php'); require_once(dirname(__FILE__) . '/mp_url_api.php'); require_once(dirname(__FILE__) . '/mp_add_to_scripts.php'); + /** * add scripts and styles to the header or the footer */ diff --git a/srcs/plugins/map_prof/mp_add_to_scripts.php b/srcs/plugins/map_prof/mp_add_to_scripts.php index 3434c0a..939ad67 100644 --- a/srcs/plugins/map_prof/mp_add_to_scripts.php +++ b/srcs/plugins/map_prof/mp_add_to_scripts.php @@ -1,64 +1,27 @@ "; -// //$content .= "nb posts published : "; -// //$content .= count($posts_list); -// //$content .= "
"; -// //foreach ($posts_list as $post_key => $post_value) { -// // $content .= "";
-// // $content .= "post content : ";
-// // $content .= $post_key;
-// // $content .= " : ";
-// // $content .= "
";
-// // foreach ($post_value as $key => $value) {
-// // $content .= "- [";
-// // $content .= $key;
-// // $content .= "]: [";
-// // $content .= $value;
-// // $content .= "]
";
-// // }
-// // $content .= "
adresse: "; + $end = "
"; + $len = strlen($begin); + $address = substr($content, strpos($content, $begin)+$len); + $address = substr($content, 0, strpos($content, $end)); + return $address; +} + +function mp_convert_coordinates(&$address) { + global $mp_api_key; + $geolocation = 'https://maps.googleapis.com/maps/api/geocode/json' + . '?address=' . urlencode($address) + . '&key=' . $mp_api_key; + + $jsoncontent = file_get_contents($geolocation); + $content = json_decode($jsoncontent); + $coordinates = $content->results[0]->geometry->location; + return $coordinates; +} + +function mp_retrieve_address(&$posts_list) { + $locs = array(); + foreach ($posts_list as $post_value) { + $content = $post_value->post_content; + $address = mp_extract_address($content); + $lat_lng = mp_convert_coordinates($address); + array_push($locs, $lat_lng); + }; + return $locs; +} + +?> diff --git a/srcs/plugins/map_prof/mp_url_api.php b/srcs/plugins/map_prof/mp_url_api.php index f77eec1..bfb5e9d 100644 --- a/srcs/plugins/map_prof/mp_url_api.php +++ b/srcs/plugins/map_prof/mp_url_api.php @@ -1,8 +1,10 @@ 'https://maps.googleapis.com/maps/api/js', - 'key' => 'AIzaSyCvdGV2ssD4ov4a9CuIlQhoJyz5gWWiSvE', + 'key' => $mp_api_key, 'callback' => 'mp_init_map', ); $mp_src = "";