added ip addr

This commit is contained in:
asus
2023-09-22 14:02:55 +02:00
parent f829277d55
commit 31f897056f
6 changed files with 74 additions and 32 deletions

View File

@@ -17,6 +17,7 @@ Author URI:
*/ */
include_once(dirname(__FILE__) . '/utils/mp_console_log.php'); 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'); require_once(dirname(__FILE__) . '/mp_enqueue.php');
@@ -56,22 +57,10 @@ function mp_ljdp_map() {
mp_enqueue_scripts_and_styles(); mp_enqueue_scripts_and_styles();
$events = mp_get_published_events(); // mp_get_events.php $events = mp_get_published_events(); // mp_get_events.php
mp_console_log("events :"); //mp_console_log("events :");
mp_console_log($events); //mp_console_log($events);
// foreach ($events as $event) { //foreach ($events as $event)
// mp_console_log("--------------- 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);
// }
$locations = mp_sort_events($events); // mp_get_locations.php $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) { function post_published_coordinates($id, $post) {
$location = mp_get_coordinates($id); $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 ) ) if ( ! add_post_meta( $id, 'location', $location, true ) )
update_post_meta( $id, 'location', $location ); update_post_meta( $id, 'location', $location );

View File

@@ -4,8 +4,11 @@
* les parametres suivants sont necessaires pour le fonctionnement du plugin * les parametres suivants sont necessaires pour le fonctionnement du plugin
*/ */
/* cle api de google maps */ /* cle api google maps pour "Maps Javascript API" */
$mp_api_key = 'AIzaSyCvdGV2ssD4ov4a9CuIlQhoJyz5gWWiSvE'; //$mp_api_key = 'AIzaSyCvdGV2ssD4ov4a9CuIlQhoJyz5gWWiSvE'; // fabien
//$mp_api_key = 'AIzaSyBNWx_3vuMKQr_nJbFKNBx6-x7NXwVqSwE'; $mp_api_key = 'AIzaSyDAZv8QNRQjnVY6kdzJRxWmZDaNIcgYp9E';
/* cle api google maps pour "Geocoding API" */
$mp_api_key_geo = 'AIzaSyBskxuBhowQdLjJmIj2gc66KoP1GLO3SEg';
?> ?>

View File

@@ -137,6 +137,9 @@ function mp_show_list_posts_no_coordinates($posts) {
} }
echo <<<HTML echo <<<HTML
</ul> </ul>
<p style="background-color: lightblue; padding: 5px 10px; width: fit-content;">
<b>pour actualiser les coordonnees d'un article, il suffit de le remettre en "brouillon" puis de le publier a nouveau</b>
</p>
</div> </div>
HTML; HTML;
} }
@@ -161,19 +164,48 @@ function mp_show_post_number($posts_list, $posts_published) {
function mp_show_api_key_n_ip() { function mp_show_api_key_n_ip() {
global $mp_api_key; global $mp_api_key;
global $mp_api_key_geo;
echo <<<HTML echo <<<HTML
<p>l'adresse ip du serveur est : <b> <p>l'adresse ip du serveur est : <b>
HTML; HTML;
echo $_SERVER['SERVER_ADDR'] . "</b></p>"; $external_ip = mp_get_ip();
echo $external_ip;
echo <<<HTML echo <<<HTML
<p>la cle api de google maps utilisee est : <b> </b></p>
HTML; HTML;
echo $mp_api_key . "</b></p>";
echo <<<HTML echo <<<HTML
<p style="color: blue;">&rarr; 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</p> <p>les cles api de google maps utilisees sont :</p>
<ul style="list-style: square inside; max-width: 500px;">
<li>pour la carte : <b style='float:right; margin-right: 10px;'>
HTML;
echo $mp_api_key;
echo <<<HTML
</b></li>
<li>pour les coordonnees : <b style='float:right; margin-right: 10px;'>
HTML;
echo $mp_api_key_geo;
echo <<<HTML
</b></li></ul>
<p>(elles sont inscrites dans ./settings/mp_required.php)</p>
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 <<<HTML
<p style="color: blue;">
<b>&rarr; pour la carte : </b>
cette cle api peut etre restreinte par url, et par api avec la "Maps Javascript API"
</p>
<p style="color: blue;">
<b>&rarr; pour les coordonnees : </b>
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"
</p>
<p style="color: blue;">
<b>&rarr; pour utiliser une seule cle api : </b>
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"
</p>
HTML; HTML;
} }
@@ -215,7 +247,6 @@ function ljdp_map_plugin_content() {
HTML; HTML;
} }
echo <<<HTML echo <<<HTML
</div> </div>
HTML; HTML;

View File

@@ -13,7 +13,7 @@ function mp_get_address($id) {
} }
function mp_get_coordinates($id) { function mp_get_coordinates($id) {
global $mp_api_key; global $mp_api_key_geo;
$event = (object)[]; $event = (object)[];
$location = (object)[]; $location = (object)[];
$location->coordinates = null; $location->coordinates = null;
@@ -24,15 +24,15 @@ function mp_get_coordinates($id) {
$location->approximate = false; $location->approximate = false;
$address = mp_get_address($id); $address = mp_get_address($id);
mp_console_log("adresse: " . $address); //mp_console_log("adresse: " . $address);
// get coordinates from google maps api // get coordinates from google maps api
$geolocation = 'https://maps.googleapis.com/maps/api/geocode/json' $geolocation = 'https://maps.googleapis.com/maps/api/geocode/json'
. '?language=fr' . '?language=fr'
. '&address=' . urlencode($address) . '&address=' . urlencode($address)
. '&key=' . $mp_api_key; . '&key=' . $mp_api_key_geo;
mp_console_log("geolocation:"); //mp_console_log("geolocation:");
mp_console_log($geolocation); //mp_console_log($geolocation);
$jsoncontent = file_get_contents($geolocation); $jsoncontent = file_get_contents($geolocation);
mp_console_log("jsoncontent:"); mp_console_log("jsoncontent:");
mp_console_log($jsoncontent); mp_console_log($jsoncontent);

View File

@@ -0,0 +1,18 @@
<?php
function mp_get_ip() {
$external_ip = "";
// curl with php :
// https://www.php.net/manual/en/function.curl-init.php
$ch = curl_init('https://ifconfig.me/ip');
// CURLOPT_RETURNTRANSFER is set to true, which means that cURL should return the response from the HTTP request as a string, rather than printing it to the screen
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$external_ip = curl_exec($ch);
//mp_console_log("ip:");
//mp_console_log($external_ip);
curl_close($ch);
return $external_ip;
}
?>

View File

@@ -15,6 +15,7 @@ RUN apk update && apk add \
php7-tokenizer \ php7-tokenizer \
php7-zip \ php7-zip \
php7-dom \ php7-dom \
php7-curl \
\ \
mariadb-client \ mariadb-client \
curl \ curl \