209 lines
7.1 KiB
PHP
209 lines
7.1 KiB
PHP
<?php
|
|
/**
|
|
*
|
|
* @package Cartographie
|
|
* @author Digitanie
|
|
* @copyright 2024 Digitanie
|
|
*
|
|
* @wordpress-plugin
|
|
* Plugin Name: Cartographie
|
|
* Description: Plugin pour la cartographie.
|
|
* Version: 1.0.0
|
|
* Author: Digitanie
|
|
* Author URI: https://digitanie.org
|
|
* Text Domain: cartographie
|
|
*/
|
|
|
|
add_shortcode('cartographie', '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">Associé-e BBE</h5>
|
|
</div>
|
|
<div class="container-toggle" id="toggle-associe" value="all">
|
|
<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="/wp-content/plugins/cartographie/media/lieux_de_plantation.svg">
|
|
<p>Lieux de plantation</p>
|
|
</div>
|
|
<div id="exploitations-productrices-de-bois-pour-BBE">
|
|
<img src="/wp-content/plugins/cartographie/media/producteur_de_bois.svg">
|
|
<p>Producteur de bois</p>
|
|
</div>
|
|
<div id="chaufferies-bois-clients">
|
|
<img src="/wp-content/plugins/cartographie/media/chaufferie_bois_clients.svg">
|
|
<p>Acheteur de bois</p>
|
|
</div>
|
|
<div id="chaufferies-vente-de-chaleur">
|
|
<img src="/wp-content/plugins/cartographie/media/chaufferie_vente_chaleur.svg">
|
|
<p>Acheteur de chaleur</p>
|
|
</div>
|
|
<div id="plateformes-logistiques">
|
|
<img src="/wp-content/plugins/cartographie/media/plateformes_logistiques.svg">
|
|
<p>Plateforme logistique</p>
|
|
</div>
|
|
</div>
|
|
<div id=""><p id="modal-title"></p></div>
|
|
</div>
|
|
<div id='map' class='map-container'>
|
|
<div id="full-screen">
|
|
<img src="https://cdn-icons-png.flaticon.com/128/3413/3413667.png">
|
|
</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, 'cartographie')) {
|
|
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';
|
|
|
|
$results = $wpdb->get_results("
|
|
SELECT wp_posts.ID, wp_posts.post_title, wp_term_taxonomy.taxonomy,
|
|
GROUP_CONCAT(wp_terms.term_id ORDER BY wp_terms.term_id) AS term_ids,
|
|
GROUP_CONCAT(wp_terms.name ORDER BY wp_terms.term_id) AS term_names
|
|
FROM wp_posts
|
|
INNER JOIN wp_term_relationships ON wp_posts.ID = wp_term_relationships.object_id
|
|
INNER JOIN wp_term_taxonomy ON wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id
|
|
INNER JOIN wp_terms ON wp_term_taxonomy.term_id = wp_terms.term_id
|
|
WHERE wp_posts.post_status = 'publish'
|
|
AND wp_posts.post_type = 'markercartographie'
|
|
GROUP BY wp_posts.ID, wp_term_taxonomy.taxonomy;
|
|
");
|
|
|
|
$structured_data = [];
|
|
|
|
$image_results = $wpdb->get_results("
|
|
SELECT wp_posts.ID, wp_postmeta.meta_value AS image_id, image_posts.guid AS image_url
|
|
FROM wp_posts
|
|
LEFT JOIN wp_postmeta ON wp_posts.ID = wp_postmeta.post_id AND wp_postmeta.meta_key = '_thumbnail_id'
|
|
LEFT JOIN wp_posts AS image_posts ON wp_postmeta.meta_value = image_posts.ID
|
|
WHERE wp_posts.post_status = 'publish'
|
|
AND wp_posts.post_type = 'markercartographie';
|
|
");
|
|
|
|
$image_data = [];
|
|
foreach ($image_results as $image_row) {
|
|
$image_data[$image_row->ID] = [
|
|
'image_id' => $image_row->image_id,
|
|
'image_url' => $image_row->image_url,
|
|
];
|
|
}
|
|
|
|
foreach ($results as $row) {
|
|
if (!isset($structured_data[$row->ID])) {
|
|
$structured_data[$row->ID] = [
|
|
'name' => $row->post_title,
|
|
];
|
|
}
|
|
|
|
// Ajouter les termes (taxonomies)
|
|
if ($row->taxonomy == "categorielabel") {
|
|
$structured_data[$row->ID][$row->taxonomy] = explode(",", $row->term_names);
|
|
} else {
|
|
$structured_data[$row->ID][$row->taxonomy] = $row->term_names;
|
|
}
|
|
|
|
// Ajouter l'image mise en avant si elle existe
|
|
if (isset($image_data[$row->ID])) {
|
|
$structured_data[$row->ID]['image'] = $image_data[$row->ID];
|
|
}
|
|
}
|
|
|
|
return $structured_data;
|
|
|
|
|
|
}
|