From 31f897056fb706b48b11908248edf2bebe125d3c Mon Sep 17 00:00:00 2001
From: asus
Date: Fri, 22 Sep 2023 14:02:55 +0200
Subject: [PATCH] added ip addr
---
srcs/plugins/map_prof/map_prof_hooks.php | 25 +++--------
.../plugins/map_prof/settings/mp_required.php | 9 ++--
.../map_prof/srcs/menu/mp_menu_content.php | 43 ++++++++++++++++---
.../srcs/publish/mp_get_coordinates.php | 10 ++---
srcs/plugins/map_prof/utils/mp_get_ip.php | 18 ++++++++
srcs/requirements/wordpress/Dockerfile | 1 +
6 files changed, 74 insertions(+), 32 deletions(-)
create mode 100644 srcs/plugins/map_prof/utils/mp_get_ip.php
diff --git a/srcs/plugins/map_prof/map_prof_hooks.php b/srcs/plugins/map_prof/map_prof_hooks.php
index bf7a788..6392238 100644
--- a/srcs/plugins/map_prof/map_prof_hooks.php
+++ b/srcs/plugins/map_prof/map_prof_hooks.php
@@ -17,6 +17,7 @@ Author URI:
*/
include_once(dirname(__FILE__) . '/utils/mp_console_log.php');
+include_once(dirname(__FILE__) . '/utils/mp_get_ip.php');
require_once(dirname(__FILE__) . '/mp_enqueue.php');
@@ -56,22 +57,10 @@ function mp_ljdp_map() {
mp_enqueue_scripts_and_styles();
$events = mp_get_published_events(); // mp_get_events.php
- mp_console_log("events :");
- mp_console_log($events);
-// foreach ($events as $event) {
-// mp_console_log("--------------- event :");
-// mp_console_log("id: " . $event->id);
-// mp_console_log("adresse: " . $event->adresse);
-// mp_console_log("pays: " . $event->pays);
-// mp_console_log("ville: " . $event->ville);
-// mp_console_log("irl: " . $event->irl);
-// mp_console_log($event);
-//
-// $fields = get_fields($event_id);
-// mp_console_log($fields);
-// foreach( $fields as $name => $value )
-// mp_console_log($name . " : " . $value);
-// }
+ //mp_console_log("events :");
+ //mp_console_log($events);
+ //foreach ($events as $event)
+ // mp_console_log($event);
$locations = mp_sort_events($events); // mp_get_locations.php
@@ -127,8 +116,8 @@ add_shortcode('ljdp_errors_map', 'mp_errors_map');
function post_published_coordinates($id, $post) {
$location = mp_get_coordinates($id);
- mp_console_log("location: ");
- mp_console_log($location);
+ //mp_console_log("location: ");
+ //mp_console_log($location);
if ( ! add_post_meta( $id, 'location', $location, true ) )
update_post_meta( $id, 'location', $location );
diff --git a/srcs/plugins/map_prof/settings/mp_required.php b/srcs/plugins/map_prof/settings/mp_required.php
index 8021a91..f7d159e 100644
--- a/srcs/plugins/map_prof/settings/mp_required.php
+++ b/srcs/plugins/map_prof/settings/mp_required.php
@@ -4,8 +4,11 @@
* les parametres suivants sont necessaires pour le fonctionnement du plugin
*/
-/* cle api de google maps */
-$mp_api_key = 'AIzaSyCvdGV2ssD4ov4a9CuIlQhoJyz5gWWiSvE';
-//$mp_api_key = 'AIzaSyBNWx_3vuMKQr_nJbFKNBx6-x7NXwVqSwE';
+/* cle api google maps pour "Maps Javascript API" */
+//$mp_api_key = 'AIzaSyCvdGV2ssD4ov4a9CuIlQhoJyz5gWWiSvE'; // fabien
+$mp_api_key = 'AIzaSyDAZv8QNRQjnVY6kdzJRxWmZDaNIcgYp9E';
+
+/* cle api google maps pour "Geocoding API" */
+$mp_api_key_geo = 'AIzaSyBskxuBhowQdLjJmIj2gc66KoP1GLO3SEg';
?>
diff --git a/srcs/plugins/map_prof/srcs/menu/mp_menu_content.php b/srcs/plugins/map_prof/srcs/menu/mp_menu_content.php
index 83213d9..276c23e 100644
--- a/srcs/plugins/map_prof/srcs/menu/mp_menu_content.php
+++ b/srcs/plugins/map_prof/srcs/menu/mp_menu_content.php
@@ -137,6 +137,9 @@ function mp_show_list_posts_no_coordinates($posts) {
}
echo <<
+
+ pour actualiser les coordonnees d'un article, il suffit de le remettre en "brouillon" puis de le publier a nouveau
+
HTML;
}
@@ -161,19 +164,48 @@ function mp_show_post_number($posts_list, $posts_published) {
function mp_show_api_key_n_ip() {
global $mp_api_key;
+ global $mp_api_key_geo;
echo <<l'adresse ip du serveur est :
HTML;
- echo $_SERVER['SERVER_ADDR'] . "
";
-
+ $external_ip = mp_get_ip();
+ echo $external_ip;
echo <<la cle api de google maps utilisee est :
+
HTML;
- echo $mp_api_key . "";
echo <<→ pour que la cle api fonctionne coté serveur il faut utiliser une cle qui soit unique pour ce serveur et soit restreinte avec l'adresse ip du serveur et non pas avec l'url
+ les cles api de google maps utilisees sont :
+
+ - pour la carte :
+ HTML;
+ echo $mp_api_key;
+ echo <<
+ - pour les coordonnees :
+ HTML;
+ echo $mp_api_key_geo;
+ echo <<
+ (elles sont inscrites dans ./settings/mp_required.php)
+ HTML;
+
+ // need to use an api key with special restrictions :
+ // https://stackoverflow.com/questions/42167695/api-key-browser-api-keys-cannot-have-referer-restrictions-when-used-with-this-ap
+ echo <<
+ → pour la carte :
+ cette cle api peut etre restreinte par url, et par api avec la "Maps Javascript API"
+
+
+ → pour les coordonnees :
+ cette cle api ne doit pas etre restreinte par url, elle peut etre restreinte par adresse ip du serveur, et par api avec la "Geocoding API"
+
+
+ → pour utiliser une seule cle api :
+ cette cle api ne doit pas etre restreinte ni par url ni par adresse ip, elle peut etre restreinte par api avec les deux "Maps Javascript API" et "Geocoding API"
+
HTML;
}
@@ -215,7 +247,6 @@ function ljdp_map_plugin_content() {
HTML;
}
-
echo <<
HTML;
diff --git a/srcs/plugins/map_prof/srcs/publish/mp_get_coordinates.php b/srcs/plugins/map_prof/srcs/publish/mp_get_coordinates.php
index 5741b9c..023e346 100644
--- a/srcs/plugins/map_prof/srcs/publish/mp_get_coordinates.php
+++ b/srcs/plugins/map_prof/srcs/publish/mp_get_coordinates.php
@@ -13,7 +13,7 @@ function mp_get_address($id) {
}
function mp_get_coordinates($id) {
- global $mp_api_key;
+ global $mp_api_key_geo;
$event = (object)[];
$location = (object)[];
$location->coordinates = null;
@@ -24,15 +24,15 @@ function mp_get_coordinates($id) {
$location->approximate = false;
$address = mp_get_address($id);
- mp_console_log("adresse: " . $address);
+ //mp_console_log("adresse: " . $address);
// get coordinates from google maps api
$geolocation = 'https://maps.googleapis.com/maps/api/geocode/json'
. '?language=fr'
. '&address=' . urlencode($address)
- . '&key=' . $mp_api_key;
- mp_console_log("geolocation:");
- mp_console_log($geolocation);
+ . '&key=' . $mp_api_key_geo;
+ //mp_console_log("geolocation:");
+ //mp_console_log($geolocation);
$jsoncontent = file_get_contents($geolocation);
mp_console_log("jsoncontent:");
mp_console_log($jsoncontent);
diff --git a/srcs/plugins/map_prof/utils/mp_get_ip.php b/srcs/plugins/map_prof/utils/mp_get_ip.php
new file mode 100644
index 0000000..84acfee
--- /dev/null
+++ b/srcs/plugins/map_prof/utils/mp_get_ip.php
@@ -0,0 +1,18 @@
+
diff --git a/srcs/requirements/wordpress/Dockerfile b/srcs/requirements/wordpress/Dockerfile
index 05bf066..b460fce 100644
--- a/srcs/requirements/wordpress/Dockerfile
+++ b/srcs/requirements/wordpress/Dockerfile
@@ -15,6 +15,7 @@ RUN apk update && apk add \
php7-tokenizer \
php7-zip \
php7-dom \
+ php7-curl \
\
mariadb-client \
curl \