resolve some errors in php logic, like strlen with str containing space that is interpreted as array instead of string
This commit is contained in:
258
plug/map_prof/srcs/menu/mp_menu_content.php
Normal file
258
plug/map_prof/srcs/menu/mp_menu_content.php
Normal file
@@ -0,0 +1,258 @@
|
||||
<?php
|
||||
|
||||
function mp_get_all_posts() {
|
||||
|
||||
$get_posts_args = array(
|
||||
'numberposts' => -1,
|
||||
'post_status' => 'any',
|
||||
'post_type' => 'post',
|
||||
);
|
||||
$posts_list = get_posts($get_posts_args);
|
||||
|
||||
return $posts_list;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function mp_posts_published($posts_list) {
|
||||
|
||||
$posts_published = [];
|
||||
foreach ($posts_list as $post) {
|
||||
$status = $post->post_status;
|
||||
if ($status == "publish")
|
||||
array_push($posts_published, $post);
|
||||
}
|
||||
return $posts_published;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function mp_have_no_address($posts_list) {
|
||||
|
||||
$posts_no_address = [];
|
||||
foreach ($posts_list as $post) {
|
||||
$address = mp_get_address($post->ID);
|
||||
if (empty($address))
|
||||
array_push($posts_no_address, $post);
|
||||
}
|
||||
return $posts_no_address;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function mp_have_no_coordinates($posts_list) {
|
||||
|
||||
$posts_no_coordinates = [];
|
||||
foreach ($posts_list as $post) {
|
||||
$location = get_field("location", $post->ID);
|
||||
if (empty($location))
|
||||
array_push($posts_no_coordinates, $post);
|
||||
else if (empty($location->coordinates))
|
||||
array_push($posts_no_coordinates, $post);
|
||||
}
|
||||
return $posts_no_coordinates;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function mp_show_list_posts_no_address($posts) {
|
||||
|
||||
echo <<<HTML
|
||||
<div style="border: 1px solid red; margin: 20px 20px 20px auto; padding: 0px 20px;">
|
||||
<p style="color: red;">
|
||||
<b>ATTENTION !</b>
|
||||
</p>
|
||||
<p>
|
||||
<b>
|
||||
HTML;
|
||||
echo count($posts);
|
||||
echo '</b>';
|
||||
if (count($posts) == 1)
|
||||
echo " article n'a pas d'adresse :";
|
||||
else
|
||||
echo " articles n'ont pas d'adresses :";
|
||||
echo <<<HTML
|
||||
</p>
|
||||
<ul style="list-style: square inside;">
|
||||
HTML;
|
||||
foreach ($posts as $post) {
|
||||
echo <<<HTML
|
||||
<li><b>
|
||||
HTML;
|
||||
echo 'id: ';
|
||||
echo $post->ID;
|
||||
echo ' (status: ';
|
||||
echo $post->post_status;
|
||||
echo ') - ';
|
||||
if (!empty($post->mode))
|
||||
echo $post->mode[0];
|
||||
echo ' : </b>';
|
||||
echo $post->post_title;
|
||||
echo <<<HTML
|
||||
</li>
|
||||
HTML;
|
||||
}
|
||||
echo <<<HTML
|
||||
</ul>
|
||||
</div>
|
||||
HTML;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function mp_show_list_posts_no_coordinates($posts) {
|
||||
|
||||
echo <<<HTML
|
||||
<div style="border: 1px solid blue; margin: 20px 20px 20px auto; padding: 0px 20px;">
|
||||
<p style="color: blue;">
|
||||
<b>INFORMATION :</b>
|
||||
</p>
|
||||
<p>
|
||||
<b>
|
||||
HTML;
|
||||
echo count($posts);
|
||||
echo '</b>';
|
||||
if (count($posts) == 1)
|
||||
echo " article n'a pas de coordonnees :";
|
||||
else
|
||||
echo " articles n'ont pas de coordonnees :";
|
||||
echo <<<HTML
|
||||
</p>
|
||||
<ul style="list-style: square inside;">
|
||||
HTML;
|
||||
foreach ($posts as $post) {
|
||||
echo <<<HTML
|
||||
<li><b>
|
||||
HTML;
|
||||
echo 'id: ';
|
||||
echo $post->ID;
|
||||
echo ' (status: ';
|
||||
echo $post->post_status;
|
||||
echo ') - ';
|
||||
if (!empty($post->mode))
|
||||
echo $post->mode[0];
|
||||
echo ' : </b>';
|
||||
echo $post->post_title;
|
||||
echo <<<HTML
|
||||
</li>
|
||||
HTML;
|
||||
}
|
||||
echo <<<HTML
|
||||
</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>
|
||||
HTML;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function mp_show_post_number($posts_list, $posts_published) {
|
||||
|
||||
echo <<<HTML
|
||||
<p>nombre d'articles au total : <b>
|
||||
HTML;
|
||||
echo count($posts_list);
|
||||
echo "</b> (dont <b>";
|
||||
echo count($posts_published) . "</b>";
|
||||
if (count($posts_published) == 1)
|
||||
echo " publié)</p>";
|
||||
else
|
||||
echo " publiés)</p>";
|
||||
}
|
||||
|
||||
|
||||
|
||||
function mp_show_api_key_n_ip() {
|
||||
global $mp_api_key;
|
||||
global $mp_api_key_geo;
|
||||
|
||||
echo <<<HTML
|
||||
<p>l'adresse ip du serveur est : <b>
|
||||
HTML;
|
||||
$external_ip = mp_get_ip();
|
||||
echo $external_ip;
|
||||
echo <<<HTML
|
||||
</b></p>
|
||||
HTML;
|
||||
|
||||
echo <<<HTML
|
||||
<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>→ pour la carte : </b>
|
||||
cette cle api peut etre restreinte par url, et par api avec l'api <b>"Maps Javascript API"</b>
|
||||
</p>
|
||||
<p style="color: blue;">
|
||||
<b>→ 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 l'api <b>"Geocoding API"</b>
|
||||
</p>
|
||||
<p style="color: blue;">
|
||||
<b>→ 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 apis <b>"Maps Javascript API"</b> et <b>"Geocoding API"</b>
|
||||
</p>
|
||||
HTML;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function ljdp_map_plugin_content() {
|
||||
|
||||
$posts_list = mp_get_all_posts();
|
||||
//mp_console_log("posts_list: ");
|
||||
//mp_console_log($posts_list);
|
||||
|
||||
$posts_published = mp_posts_published($posts_list);
|
||||
|
||||
$posts_no_address = mp_have_no_address($posts_list);
|
||||
//mp_console_log("posts_no_address: ");
|
||||
//mp_console_log($posts_no_address);
|
||||
|
||||
$posts_no_coordinates = mp_have_no_coordinates($posts_list);
|
||||
//mp_console_log("posts_no_coordinates: ");
|
||||
//mp_console_log($posts_no_coordinates);
|
||||
|
||||
echo <<<HTML
|
||||
<div>
|
||||
<h2>JIPF map plugin</h2>
|
||||
HTML;
|
||||
|
||||
mp_show_post_number($posts_list, $posts_published);
|
||||
|
||||
mp_show_api_key_n_ip();
|
||||
|
||||
if (count($posts_no_address) > 0)
|
||||
mp_show_list_posts_no_address($posts_no_address);
|
||||
|
||||
if (count($posts_no_coordinates) > 0){
|
||||
mp_show_list_posts_no_coordinates($posts_no_coordinates);
|
||||
}
|
||||
else {
|
||||
echo <<<HTML
|
||||
<p style="color: green;">✔ tous les articles ont des coordonnees correctes :)</p>
|
||||
HTML;
|
||||
}
|
||||
|
||||
echo <<<HTML
|
||||
</div>
|
||||
HTML;
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user