406 lines
9.2 KiB
PHP
406 lines
9.2 KiB
PHP
<?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_bad_categories($posts_list) {
|
|
|
|
$posts_bad_categories = [];
|
|
foreach ($posts_list as $post) {
|
|
$value = get_field("categorie", $post->ID);
|
|
if (! is_string($value)) {
|
|
array_push($posts_bad_categories, $post);
|
|
//mp_console_log("categorie:");
|
|
//mp_console_log($value);
|
|
}
|
|
if (str_starts_with($value, '["')) {
|
|
array_push($posts_bad_categories, $post);
|
|
}
|
|
}
|
|
return $posts_bad_categories;
|
|
}
|
|
|
|
|
|
|
|
|
|
function count_publish($arr_posts) {
|
|
return($arr_posts->post_status === "publish");
|
|
}
|
|
|
|
|
|
|
|
|
|
function mp_show_list_posts_no_address($posts) {
|
|
|
|
$all_posts = count($posts);
|
|
$published_posts = count(array_filter($posts, "count_publish"));
|
|
|
|
echo <<<HTML
|
|
<div style="border: 1px solid red; margin: 20px 20px 20px auto; padding: 0px 20px;">
|
|
<p style="color: red;">
|
|
<b>ATTENTION !</b>
|
|
</p>
|
|
<input type="checkbox" class="hide_not_published" id="posts_no_address_published">
|
|
<label for="posts_no_address_published">afficher uniquement les articles publiés</label>
|
|
<p>
|
|
<b>
|
|
HTML;
|
|
echo "<span class='count_all_posts'>$all_posts</span>";
|
|
echo "<span class='count_published_posts'>$published_posts</span>";
|
|
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) {
|
|
if ($post->post_status === "publish") {
|
|
echo <<<HTML
|
|
<li class="jipf_post_publish"><b>
|
|
HTML;
|
|
}
|
|
else {
|
|
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_bad_categories($posts) {
|
|
|
|
$all_posts = count($posts);
|
|
$published_posts = count(array_filter($posts, "count_publish"));
|
|
|
|
echo <<<HTML
|
|
<div style="border: 1px solid red; margin: 20px 20px 20px auto; padding: 0px 20px;">
|
|
<p style="color: red;">
|
|
<b>ATTENTION !</b>
|
|
</p>
|
|
<input type="checkbox" class="hide_not_published" id="posts_bad_categories_published">
|
|
<label for="posts_bad_categories_published">afficher uniquement les articles publiés</label>
|
|
<p>
|
|
<b>
|
|
HTML;
|
|
echo "<span class='count_all_posts'>$all_posts</span>";
|
|
echo "<span class='count_published_posts'>$published_posts</span>";
|
|
echo '</b>';
|
|
if (count($posts) == 1)
|
|
echo " article à sa catégorie mal formatée :";
|
|
else
|
|
echo " articles ont leur catégorie mal formatée :";
|
|
echo <<<HTML
|
|
</p>
|
|
<ul style="list-style: square inside;">
|
|
HTML;
|
|
foreach ($posts as $post) {
|
|
if ($post->post_status === "publish") {
|
|
echo <<<HTML
|
|
<li class="jipf_post_publish"><b>
|
|
HTML;
|
|
}
|
|
else {
|
|
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
|
|
<p style="margin:0px;">
|
|
<span style="color:blue;">catégorie: </span>
|
|
HTML;
|
|
$categorie = get_field("categorie", $post->ID);
|
|
echo '<span>';
|
|
var_dump($categorie);
|
|
echo '</span>';
|
|
echo <<<HTML
|
|
</p>
|
|
</li>
|
|
HTML;
|
|
}
|
|
echo <<<HTML
|
|
</ul>
|
|
</div>
|
|
HTML;
|
|
}
|
|
|
|
|
|
|
|
|
|
function mp_show_list_posts_no_coordinates($posts) {
|
|
|
|
$all_posts = count($posts);
|
|
$published_posts = count(array_filter($posts, "count_publish"));
|
|
|
|
echo <<<HTML
|
|
<div style="border: 1px solid blue; margin: 20px 20px 20px auto; padding: 0px 20px;">
|
|
<p style="color: blue;">
|
|
<b>INFORMATION :</b>
|
|
</p>
|
|
<input type="checkbox" class="hide_not_published" id="posts_no_coordinates_published">
|
|
<label for="posts_no_coordinates_published">afficher uniquement les articles publiés</label>
|
|
<p>
|
|
<b>
|
|
HTML;
|
|
echo "<span class='count_all_posts'>$all_posts</span>";
|
|
echo "<span class='count_published_posts'>$published_posts</span>";
|
|
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) {
|
|
if ($post->post_status === "publish") {
|
|
echo <<<HTML
|
|
<li class="jipf_post_publish"><b>
|
|
HTML;
|
|
}
|
|
else {
|
|
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);
|
|
|
|
$posts_bad_categories = mp_bad_categories($posts_list);
|
|
//mp_console_log("posts_bad_categories: ");
|
|
//mp_console_log($posts_bad_categories);
|
|
|
|
|
|
echo <<<HTML
|
|
<style>
|
|
li {
|
|
list-style-position: outside;
|
|
margin-left: 10px;
|
|
}
|
|
input.hide_not_published:checked ~ ul li:not(.jipf_post_publish) {
|
|
display: none;
|
|
}
|
|
.count_published_posts {
|
|
display: none;
|
|
}
|
|
input.hide_not_published:checked ~ p .count_all_posts {
|
|
display: none;
|
|
}
|
|
input.hide_not_published:checked ~ p .count_published_posts {
|
|
display: inline;
|
|
}
|
|
</style>
|
|
<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_bad_categories) > 0)
|
|
mp_show_list_posts_bad_categories($posts_bad_categories);
|
|
|
|
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;
|
|
}
|
|
|
|
?>
|