Files
2023_WEBSITE_jipf/srcs/plugins/map_prof/map_prof_hooks.php

171 lines
3.7 KiB
PHP

<?php
/*
Plugin Name: map_prof
Plugin URI:
Description: add/remove locations on map at publication/deletion of posts
Author: hugogogo
Version: 1.2.0
Author URI:
*/
/**
* inclusions :
*/
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__) . '/settings/mp_required.php');
require_once(dirname(__FILE__) . '/settings/mp_optionnals.php');
require_once(dirname(__FILE__) . '/settings/mp_globals.php');
require_once(dirname(__FILE__) . '/settings/mp_url_api.php');
require_once(dirname(__FILE__) . '/srcs/errors/mp_address_errors.php');
require_once(dirname(__FILE__) . '/srcs/map/mp_add_to_scripts.php');
require_once(dirname(__FILE__) . '/srcs/map/mp_create_div.php');
require_once(dirname(__FILE__) . '/srcs/map/mp_get_events.php');
require_once(dirname(__FILE__) . '/srcs/map/mp_get_filters.php');
require_once(dirname(__FILE__) . '/srcs/map/mp_get_locations.php');
require_once(dirname(__FILE__) . '/srcs/map_posts/mp_post_events_pages.php');
require_once(dirname(__FILE__) . '/srcs/publish/mp_get_coordinates.php');
require_once(dirname(__FILE__) . '/srcs/publish/mp_update_publish.php');
require_once(dirname(__FILE__) . '/srcs/menu/mp_menu_content.php');
/**
* when 'shortcode' found in page, enqueue scripts and styles,
* run php script, and replace shortcode by return value
*/
function mp_ljdp_map() {
mp_enqueue_scripts_and_styles();
$events = mp_get_published_events(); // mp_get_events.php
//mp_console_log("events: ");
//mp_console_log($events);
//foreach ($events as $event) {
// if (gettype($event->categorie) === "array") {
// mp_console_log($event->categorie);
// }
// if (str_starts_with($event->categorie, '["')) {
// mp_console_log($event->categorie);
// }
//}
$locations = mp_sort_events($events); // mp_get_locations.php
//mp_console_log("locations: ");
//mp_console_log($locations);
$filters = mp_get_filters($events); // mp_get_filters.php
// if post event instead of map page, change coordinate and zoom
mp_post_event_pages_setting();
mp_add_to_scripts(array(
"locations" => $locations,
"filters" => $filters,
"jipf_events" => $events,
));
return mp_create_div($filters);
}
add_shortcode('lejourduprof_map', 'mp_ljdp_map');
/*
script in divi :
<script type="text/javascript">
console.log("events:");
console.log(events);
document.addEventListener("DOMContentLoaded", () => {
let counter = document.getElementById('jipf_activity_counter_map');
console.log(counter);
counter.dataset.numberValue = 20;
});
</script>
*/
/**
* re-publish posts
*/
// function mp_add_update_button() {
// return mp_create_republish_button();
// }
// add_shortcode('ljdp_update_publish', 'mp_add_update_button');
/**
* errors map
*/
function mp_errors_map() {
return mp_find_address_errors();
}
add_shortcode('ljdp_errors_map', 'mp_errors_map');
/**
* when a post is saved or published or updated,
* find its coordinates
*/
function post_published_coordinates($id, $post) {
$location = mp_get_coordinates($id);
//mp_console_log("location: ");
//mp_console_log($location);
if ( ! add_post_meta( $id, 'location', $location, true ) )
update_post_meta( $id, 'location', $location );
}
add_action( 'publish_post', 'post_published_coordinates', 10, 2 );
/**
* menu plugin
*/
function ljdp_map_menu() {
add_menu_page(
'JIPF map', // page_title
'JIPF map', // menu_title
'manage_options', // capability
'ljdp-map-plugin', // menu_slug
'ljdp_map_plugin_content' // callback function to display page content
);
}
add_action('admin_menu', 'ljdp_map_menu');
?>