191 lines
6.7 KiB
PHP
191 lines
6.7 KiB
PHP
<?php
|
|
/**
|
|
* Hello World
|
|
*
|
|
* @package HelloWorld
|
|
* @author Florian Llimos
|
|
* @copyright 2024 Florian Llimos
|
|
* @license GPL-2.0-or-later
|
|
*
|
|
* @wordpress-plugin
|
|
* Plugin Name: Hello World
|
|
* Plugin URI: https://mehdinazari.com/how-to-create-hello-world-plugin-for-wordpress
|
|
* Description: This plugin prints "Hello World" inside an admin page.
|
|
* Version: 1.0.0
|
|
* Author: Florian Llimos
|
|
* Author URI: https://florianllimos.fr
|
|
* Text Domain: hello-world
|
|
* License: GPL v2 or later
|
|
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
|
|
*/
|
|
|
|
add_shortcode('hello_world_map', 'display_hello_world_page');
|
|
|
|
function display_hello_world_page() {
|
|
ob_start();
|
|
?>
|
|
<div id="container-filter">
|
|
|
|
<div id="container-filter-avancement">
|
|
<div class="container-title-filter">
|
|
<h5 id="avancement-button">Status</h5>
|
|
</div>
|
|
<div id="container-filter-avancement-1">
|
|
<div id="projets-finis" class="box-filter wait-button">
|
|
<p>Terminé</p>
|
|
</div>
|
|
<div id="en-cours" class="box-filter wait-button">
|
|
<p>En cours</p>
|
|
</div>
|
|
<div id="prevu" class="box-filter wait-button">
|
|
<p>Prévu</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<hr class="separator">
|
|
<div id="container-filter-associe">
|
|
<div class="container-title-filter">
|
|
<h5 id="associe-button" class="h2-low">Associé-e BBE</h5>
|
|
</div>
|
|
<div class="container-toggle" id="toggle-associe">
|
|
<div></div>
|
|
</div>
|
|
</div>
|
|
<div id="container-filter-label">
|
|
<div class="container-title-filter">
|
|
<h5 id="title-label">Label</h5>
|
|
</div>
|
|
<div id="container-filter-label-1">
|
|
<div id="label-haie" class="box-filter wait-button">
|
|
<p>Label haie</p>
|
|
</div>
|
|
<div id="label-vegetal" class="box-filter wait-button">
|
|
<p>Label végétal local</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div id="container-filter-domaine">
|
|
<h5 id="domaine-button">Type de projet</h5>
|
|
<div id="lieux-de-plantation">
|
|
<img src="https://sbw1.dgtn.dev/wp-content/uploads/2024/11/lieux_de_plantation.svg">
|
|
<p>Lieux de plantation</p>
|
|
</div>
|
|
<div id="exploitations-productrices-de-bois-pour-BBE">
|
|
<img src="https://sbw1.dgtn.dev/wp-content/uploads/2024/11/producteur_de_bois.svg">
|
|
<p>Producteur de bois</p>
|
|
</div>
|
|
<div id="chaufferies-bois-clients">
|
|
<img src="https://sbw1.dgtn.dev/wp-content/uploads/2024/11/chaufferie_bois_clients.svg">
|
|
<p>Acheteur de bois</p>
|
|
</div>
|
|
<div id="chaufferies-vente-de-chaleur">
|
|
<img src="https://sbw1.dgtn.dev/wp-content/uploads/2024/11/chaufferie_vente_chaleur.svg">
|
|
<p>Acheteur de chaleur</p>
|
|
</div>
|
|
<div id="plateformes-logistiques">
|
|
<img src="https://sbw1.dgtn.dev/wp-content/uploads/2024/11/plateformes_logistiques.svg">
|
|
<p>Plateforme logistique</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div id='map'></div>
|
|
<?php
|
|
return ob_get_clean();
|
|
}
|
|
|
|
add_action('wp_enqueue_scripts', 'hello_world_enqueue_assets');
|
|
function hello_world_enqueue_assets() {
|
|
if (has_shortcode(get_post()->post_content, 'hello_world_map')) {
|
|
wp_enqueue_style(
|
|
'leaflet-css',
|
|
'https://unpkg.com/leaflet@1.9.3/dist/leaflet.css',
|
|
array(),
|
|
'1.9.3'
|
|
);
|
|
|
|
wp_enqueue_script(
|
|
'leaflet-js',
|
|
'https://unpkg.com/leaflet@1.9.3/dist/leaflet.js',
|
|
array(),
|
|
'1.9.3',
|
|
true
|
|
);
|
|
|
|
wp_enqueue_style(
|
|
'leaflet-markercluster-css',
|
|
'https://unpkg.com/leaflet.markercluster@1.5.3/dist/MarkerCluster.Default.css'
|
|
);
|
|
|
|
wp_enqueue_script(
|
|
'leaflet-markercluster-js',
|
|
'https://unpkg.com/leaflet.markercluster@1.5.3/dist/leaflet.markercluster.js',
|
|
array('leaflet-js', 'jquery'),
|
|
null,
|
|
true
|
|
);
|
|
|
|
wp_enqueue_script(
|
|
'hello-world-script',
|
|
plugin_dir_url(__FILE__) . 'js/main.js',
|
|
array('leaflet-js', 'leaflet-markercluster-js'),
|
|
'1.0',
|
|
true
|
|
);
|
|
|
|
wp_enqueue_style(
|
|
'hello-world-style',
|
|
plugin_dir_url(__FILE__) . 'css/style.css',
|
|
array(),
|
|
'1.0'
|
|
);
|
|
}
|
|
}
|
|
|
|
add_action('rest_api_init', function() {
|
|
register_rest_route('custom/v1', '/markers', array(
|
|
'methods' => 'GET',
|
|
'callback' => 'get_cartographie_markers',
|
|
));
|
|
});
|
|
|
|
function get_cartographie_markers() {
|
|
global $wpdb;
|
|
$table_name = $wpdb->prefix . 'posts';
|
|
|
|
// Effectuer la requête pour obtenir les résultats
|
|
$results = $wpdb->get_results("
|
|
SELECT u3yd_posts.ID, u3yd_posts.post_name, u3yd_term_taxonomy.taxonomy,
|
|
GROUP_CONCAT(u3yd_terms.term_id ORDER BY u3yd_terms.term_id) AS term_ids,
|
|
GROUP_CONCAT(u3yd_terms.name ORDER BY u3yd_terms.term_id) AS term_names
|
|
FROM u3yd_posts
|
|
INNER JOIN u3yd_term_relationships ON u3yd_posts.ID = u3yd_term_relationships.object_id
|
|
INNER JOIN u3yd_term_taxonomy ON u3yd_term_relationships.term_taxonomy_id = u3yd_term_taxonomy.term_taxonomy_id
|
|
INNER JOIN u3yd_terms ON u3yd_term_taxonomy.term_id = u3yd_terms.term_id
|
|
WHERE u3yd_posts.post_status = 'publish'
|
|
AND u3yd_posts.post_type = 'seriestv'
|
|
GROUP BY u3yd_posts.ID, u3yd_term_taxonomy.taxonomy;
|
|
");
|
|
|
|
// Structurer les données en regroupant les taxonomies par ID
|
|
$structured_data = [];
|
|
|
|
foreach ($results as $row) {
|
|
// Si le post n'existe pas encore dans le tableau, l'ajouter avec les données de base
|
|
if(!isset($structured_data[$row->ID])){
|
|
$structured_data[$row->ID] = [
|
|
'name' => $row->post_name,
|
|
];
|
|
}
|
|
if ($row->taxonomy == "categorielabel") {
|
|
$structured_data[$row->ID][$row->taxonomy] = explode(",", $row->term_names);
|
|
} else {
|
|
$structured_data[$row->ID][$row->taxonomy] = $row->term_names;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
// Envoyer le JSON avec les en-têtes appropriés
|
|
return $structured_data;
|
|
|
|
}
|