clean up files to put get_events in main file instead of add_to_scripts
This commit is contained in:
@@ -22,6 +22,9 @@ require_once(dirname(__FILE__) . '/mp_add_to_scripts.php');
|
|||||||
require_once(dirname(__FILE__) . '/mp_get_coordinates.php');
|
require_once(dirname(__FILE__) . '/mp_get_coordinates.php');
|
||||||
require_once(dirname(__FILE__) . '/settings/mp_required.php');
|
require_once(dirname(__FILE__) . '/settings/mp_required.php');
|
||||||
require_once(dirname(__FILE__) . '/settings/mp_optionnals.php');
|
require_once(dirname(__FILE__) . '/settings/mp_optionnals.php');
|
||||||
|
require_once(dirname(__FILE__) . '/mp_get_events.php');
|
||||||
|
require_once(dirname(__FILE__) . '/mp_sort_events.php');
|
||||||
|
require_once(dirname(__FILE__) . '/mp_get_filters.php');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -90,49 +93,83 @@ add_filter('script_loader_tag', 'mp_tag_scripts', 10, 2);
|
|||||||
* run php script, and replace shortcode by return value
|
* run php script, and replace shortcode by return value
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function mp_add_div() {
|
function mp_ljdp_map() {
|
||||||
|
|
||||||
|
|
||||||
|
/* * * * * * * * * * * * * * *
|
||||||
|
* ENQUEUE SCRIPTS AND STYLES
|
||||||
|
*/
|
||||||
|
|
||||||
// https://developers.google.com/maps/documentation/javascript/marker-clustering
|
// https://developers.google.com/maps/documentation/javascript/marker-clustering
|
||||||
$marker_clusterer = "https://unpkg.com/@googlemaps/markerclusterer/dist/index.min.js";
|
$marker_clusterer = "https://unpkg.com/@googlemaps/markerclusterer/dist/index.min.js";
|
||||||
|
|
||||||
wp_enqueue_style('mp_style', plugins_url('styles/mp_style.css', __FILE__), '', '', false);
|
wp_enqueue_style('mp__style', plugins_url('styles/mp__style.css', __FILE__), '', '', false);
|
||||||
wp_enqueue_style('mp_style_info_windows', plugins_url('styles/mp_info_windows.css', __FILE__), '', '', false);
|
|
||||||
wp_enqueue_style('mp_style_zoom', plugins_url('styles/mp_zoom.css', __FILE__), '', '', false);
|
|
||||||
|
|
||||||
wp_enqueue_script('mp_info_window', plugins_url('scripts/mp_info_window.js', __FILE__), '', '', false);
|
wp_enqueue_script('mp_info_window', plugins_url('scripts/mp_info_window.js', __FILE__), '', '', false);
|
||||||
wp_enqueue_script('mp_errors', plugins_url('scripts/mp_errors.js', __FILE__), '', '', false);
|
wp_enqueue_script('mp_errors_map', plugins_url('scripts/mp_errors_map.js', __FILE__), '', '', false);
|
||||||
wp_enqueue_script('mp_create_markers', plugins_url('scripts/mp_create_markers.js', __FILE__), '', '', false);
|
wp_enqueue_script('mp_create_markers', plugins_url('scripts/mp_create_markers.js', __FILE__), '', '', false);
|
||||||
wp_enqueue_script('mp_draw_clusters', plugins_url('scripts/mp_draw_clusters.js', __FILE__), '', '', false);
|
wp_enqueue_script('mp_draw_clusters', plugins_url('scripts/mp_draw_clusters.js', __FILE__), '', '', false);
|
||||||
wp_enqueue_script('mp_marker_clusterer', $marker_clusterer, '', '', true);
|
wp_enqueue_script('mp_marker_clusterer', $marker_clusterer, '', '', true);
|
||||||
wp_enqueue_script('mp_init_map', plugins_url('scripts/mp_init_map.js', __FILE__), ['mp_marker_clusterer'],'', true);
|
wp_enqueue_script('mp_init_map', plugins_url('scripts/mp_init_map.js', __FILE__), ['mp_marker_clusterer'],'', true);
|
||||||
wp_enqueue_script('mp_google_api', mp_url_api(), ['mp_init_map'], '', true);
|
wp_enqueue_script('mp_google_api', mp_url_api(), ['mp_init_map'], '', true);
|
||||||
|
|
||||||
|
|
||||||
|
/* * * * * * * * *
|
||||||
|
* FIND LOCATIONS
|
||||||
|
*/
|
||||||
|
|
||||||
|
$events = mp_get_published_events();
|
||||||
|
$locations = mp_sort_events($events);
|
||||||
|
$to_add = array(
|
||||||
|
"locations" => $locations,
|
||||||
|
);
|
||||||
|
mp_add_to_scripts($to_add);
|
||||||
|
|
||||||
|
$filters_fields = array(
|
||||||
|
"pays",
|
||||||
|
"ville",
|
||||||
|
"categorie",
|
||||||
|
);
|
||||||
|
|
||||||
|
$filters = mp_get_filters($events, $filters_fields);
|
||||||
|
|
||||||
|
|
||||||
|
/* * * * * * * *
|
||||||
|
* ADD FILTERS
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
pays
|
pays
|
||||||
ville
|
ville
|
||||||
categorie
|
categorie
|
||||||
*/
|
*/
|
||||||
$pays = array();
|
// $filters = (object)[];
|
||||||
mp_add_to_scripts($pays);
|
// $filters->pays = [];
|
||||||
|
// $filters->ville = [];
|
||||||
|
// $filters->categorie = [];
|
||||||
|
//
|
||||||
|
// mp_console_log("filters:");
|
||||||
|
// mp_console_log($filters);
|
||||||
|
|
||||||
|
|
||||||
$mp_api_script = '
|
$mp_api_script = '
|
||||||
<div id="ljdp_map_wrapper">
|
<div id="ljdp_map_wrapper">
|
||||||
<div id="ljdp_map"></div>
|
|
||||||
<div id="ljdp_map_filters">
|
<div id="ljdp_map_filters">
|
||||||
';
|
';
|
||||||
foreach ($pays as $loc) {
|
// foreach ($pays as $loc) {
|
||||||
$mp_api_script .= '<p>';
|
// $mp_api_script .= '<p>';
|
||||||
$mp_api_script .= $loc;
|
// $mp_api_script .= $loc;
|
||||||
$mp_api_script .= '</p>';
|
// $mp_api_script .= '</p>';
|
||||||
}
|
// }
|
||||||
$mp_api_script .= '
|
$mp_api_script .= '
|
||||||
</div>
|
</div>
|
||||||
|
<div id="ljdp_map"></div>
|
||||||
</div>
|
</div>
|
||||||
';
|
';
|
||||||
|
|
||||||
return $mp_api_script;
|
return $mp_api_script;
|
||||||
}
|
}
|
||||||
add_shortcode('lejourduprof_map', 'mp_add_div');
|
add_shortcode('lejourduprof_map', 'mp_ljdp_map');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -150,7 +187,6 @@ function mp_errors_map() {
|
|||||||
$get_posts_args = array(
|
$get_posts_args = array(
|
||||||
'numberposts' => -1,
|
'numberposts' => -1,
|
||||||
'post_status' => 'publish',
|
'post_status' => 'publish',
|
||||||
//'post_status' => 'draft',
|
|
||||||
'post_type' => 'post',
|
'post_type' => 'post',
|
||||||
);
|
);
|
||||||
$posts = get_posts($get_posts_args);
|
$posts = get_posts($get_posts_args);
|
||||||
@@ -167,7 +203,7 @@ function mp_errors_map() {
|
|||||||
$errors .= '"</p>';
|
$errors .= '"</p>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$errors = "<p>nombre d'erreurs : " . $count . "</p>" . $errors;
|
$errors = "<p>nombre d'erreurs : " . strval($count) . "</p>" . $errors;
|
||||||
return $errors;
|
return $errors;
|
||||||
}
|
}
|
||||||
add_shortcode('ljdp_errors_map', 'mp_errors_map');
|
add_shortcode('ljdp_errors_map', 'mp_errors_map');
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once(dirname(__FILE__) . '/mp_get_events.php');
|
|
||||||
require_once(dirname(__FILE__) . '/mp_sort_events.php');
|
|
||||||
|
|
||||||
function mp_php_to_js($php_var, $js_var_name) {
|
function mp_php_to_js($php_var, $js_var_name) {
|
||||||
$js_var = 'let ' . $js_var_name . ' = ';
|
$js_var = 'let ' . $js_var_name . ' = ';
|
||||||
$js_var .= json_encode($php_var);
|
$js_var .= json_encode($php_var);
|
||||||
@@ -10,24 +7,24 @@ function mp_php_to_js($php_var, $js_var_name) {
|
|||||||
return $js_var;
|
return $js_var;
|
||||||
}
|
}
|
||||||
|
|
||||||
function mp_add_to_scripts(&$pays) {
|
function mp_add_to_scripts($to_add) {
|
||||||
global $mp_icon_size;
|
global $mp_icon_size;
|
||||||
global $mp_icon_color;
|
global $mp_icon_color;
|
||||||
global $mp_icon_color_back;
|
global $mp_icon_color_back;
|
||||||
global $mp_icon_size_factor;
|
global $mp_icon_size_factor;
|
||||||
global $mp_coordinates_default;
|
global $mp_coordinates_default;
|
||||||
global $mp_icon_stroke_width;
|
global $mp_icon_stroke_width;
|
||||||
$events = mp_get_published_events($pays);
|
|
||||||
$locations = mp_sort_events($events);
|
|
||||||
|
|
||||||
//wp_add_inline_script('mp_init_map', mp_php_to_js($events, 'events'), 'before');
|
|
||||||
wp_add_inline_script('mp_init_map', mp_php_to_js($locations, 'locations'), 'before');
|
|
||||||
wp_add_inline_script('mp_init_map', mp_php_to_js($mp_icon_size, 'icon_size'), 'before');
|
wp_add_inline_script('mp_init_map', mp_php_to_js($mp_icon_size, 'icon_size'), 'before');
|
||||||
wp_add_inline_script('mp_init_map', mp_php_to_js($mp_icon_color, 'icon_color'), 'before');
|
wp_add_inline_script('mp_init_map', mp_php_to_js($mp_icon_color, 'icon_color'), 'before');
|
||||||
wp_add_inline_script('mp_init_map', mp_php_to_js($mp_icon_color_back, 'icon_color_back'), 'before');
|
wp_add_inline_script('mp_init_map', mp_php_to_js($mp_icon_color_back, 'icon_color_back'), 'before');
|
||||||
wp_add_inline_script('mp_init_map', mp_php_to_js($mp_icon_size_factor, 'icon_size_factor'), 'before');
|
wp_add_inline_script('mp_init_map', mp_php_to_js($mp_icon_size_factor, 'icon_size_factor'), 'before');
|
||||||
wp_add_inline_script('mp_init_map', mp_php_to_js($mp_coordinates_default, 'coordinates_default'), 'before');
|
wp_add_inline_script('mp_init_map', mp_php_to_js($mp_coordinates_default, 'coordinates_default'), 'before');
|
||||||
wp_add_inline_script('mp_init_map', mp_php_to_js($mp_icon_stroke_width, 'icon_stroke_width'), 'before');
|
wp_add_inline_script('mp_init_map', mp_php_to_js($mp_icon_stroke_width, 'icon_stroke_width'), 'before');
|
||||||
|
|
||||||
|
foreach ($to_add as $key => $var) {
|
||||||
|
wp_add_inline_script('mp_init_map', mp_php_to_js($var, $key), 'before');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ function mp_get_published_posts() {
|
|||||||
return $posts_published;
|
return $posts_published;
|
||||||
}
|
}
|
||||||
|
|
||||||
function mp_fill_fields_value($id, &$pays) {
|
function mp_fill_fields_value($id) {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* get_field is an ACF function
|
* get_field is an ACF function
|
||||||
@@ -164,11 +164,11 @@ function mp_fill_fields_value($id, &$pays) {
|
|||||||
return $event;
|
return $event;
|
||||||
}
|
}
|
||||||
|
|
||||||
function mp_get_published_events(&$pays) {
|
function mp_get_published_events() {
|
||||||
$posts_list = mp_get_published_posts();
|
$posts_list = mp_get_published_posts();
|
||||||
$events = [];
|
$events = [];
|
||||||
foreach ($posts_list as $post) {
|
foreach ($posts_list as $post) {
|
||||||
$event = mp_fill_fields_value($post->ID, $pays);
|
$event = mp_fill_fields_value($post->ID);
|
||||||
$event->id = $post->ID;
|
$event->id = $post->ID;
|
||||||
$event->title = $post->post_title;
|
$event->title = $post->post_title;
|
||||||
array_push($events, $event);
|
array_push($events, $event);
|
||||||
|
|||||||
12
srcs/plugins/map_prof/mp_get_filters.php
Normal file
12
srcs/plugins/map_prof/mp_get_filters.php
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
function mp_get_filters($events, $filters_fields) {
|
||||||
|
$filters = (object)[];
|
||||||
|
foreach ($filters_fields as $field) {
|
||||||
|
$filters->$field = [];
|
||||||
|
}
|
||||||
|
mp_console_log("filters:");
|
||||||
|
mp_console_log($filters);
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -22,7 +22,7 @@ function create_markers(map, locations, infowindow) {
|
|||||||
for (loc of locations) {
|
for (loc of locations) {
|
||||||
|
|
||||||
if (loc.coordinates == null) {
|
if (loc.coordinates == null) {
|
||||||
console.log("coordinates == null");
|
//console.log("coordinates == null");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
19
srcs/plugins/map_prof/styles/mp__style.css
Normal file
19
srcs/plugins/map_prof/styles/mp__style.css
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
|
||||||
|
@import "mp_info_windows.css";
|
||||||
|
@import "mp_zoom.css";
|
||||||
|
@import "mp_filters.css";
|
||||||
|
|
||||||
|
#ljdp_map_wrapper {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ljdp_map {
|
||||||
|
height: 500px;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
#temoin {
|
||||||
|
color: blue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
14
srcs/plugins/map_prof/styles/mp_filters.css
Normal file
14
srcs/plugins/map_prof/styles/mp_filters.css
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
|
||||||
|
/*
|
||||||
|
* FILTERS
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ljdp_map_filters {
|
||||||
|
border: 1px solid red;
|
||||||
|
width: 100%;
|
||||||
|
height: 30px;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
|
|
||||||
#ljdp_map_wrapper {
|
|
||||||
position: relative;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ljdp_map {
|
|
||||||
height: 500px;
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
#temoin {
|
|
||||||
color: blue;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#ljdp_map_filters {
|
|
||||||
border: 1px solid blue;
|
|
||||||
position: absolute;
|
|
||||||
top: 0px;
|
|
||||||
left: 0px;
|
|
||||||
width: 100%;
|
|
||||||
height: 30px;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user