clean up files to put get_events in main file instead of add_to_scripts

This commit is contained in:
lenovo
2022-11-09 14:45:09 +01:00
parent 80c1683904
commit 2a759d1d86
8 changed files with 106 additions and 52 deletions

View File

@@ -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__) . '/settings/mp_required.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
*/
function mp_add_div() {
function mp_ljdp_map() {
/* * * * * * * * * * * * * * *
* ENQUEUE SCRIPTS AND STYLES
*/
// https://developers.google.com/maps/documentation/javascript/marker-clustering
$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_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_style('mp__style', plugins_url('styles/mp__style.css', __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_draw_clusters', plugins_url('scripts/mp_draw_clusters.js', __FILE__), '', '', false);
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_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
ville
categorie
*/
$pays = array();
mp_add_to_scripts($pays);
// $filters = (object)[];
// $filters->pays = [];
// $filters->ville = [];
// $filters->categorie = [];
//
// mp_console_log("filters:");
// mp_console_log($filters);
$mp_api_script = '
<div id="ljdp_map_wrapper">
<div id="ljdp_map"></div>
<div id="ljdp_map_filters">
';
foreach ($pays as $loc) {
$mp_api_script .= '<p>';
$mp_api_script .= $loc;
$mp_api_script .= '</p>';
}
// foreach ($pays as $loc) {
// $mp_api_script .= '<p>';
// $mp_api_script .= $loc;
// $mp_api_script .= '</p>';
// }
$mp_api_script .= '
</div>
<div id="ljdp_map"></div>
</div>
';
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(
'numberposts' => -1,
'post_status' => 'publish',
//'post_status' => 'draft',
'post_type' => 'post',
);
$posts = get_posts($get_posts_args);
@@ -167,7 +203,7 @@ function mp_errors_map() {
$errors .= '"</p>';
}
}
$errors = "<p>nombre d'erreurs : " . $count . "</p>" . $errors;
$errors = "<p>nombre d'erreurs : " . strval($count) . "</p>" . $errors;
return $errors;
}
add_shortcode('ljdp_errors_map', 'mp_errors_map');

View File

@@ -1,8 +1,5 @@
<?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) {
$js_var = 'let ' . $js_var_name . ' = ';
$js_var .= json_encode($php_var);
@@ -10,24 +7,24 @@ function mp_php_to_js($php_var, $js_var_name) {
return $js_var;
}
function mp_add_to_scripts(&$pays) {
function mp_add_to_scripts($to_add) {
global $mp_icon_size;
global $mp_icon_color;
global $mp_icon_color_back;
global $mp_icon_size_factor;
global $mp_coordinates_default;
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_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_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_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');
}
}
?>

View File

@@ -125,7 +125,7 @@ function mp_get_published_posts() {
return $posts_published;
}
function mp_fill_fields_value($id, &$pays) {
function mp_fill_fields_value($id) {
/*
* get_field is an ACF function
@@ -164,11 +164,11 @@ function mp_fill_fields_value($id, &$pays) {
return $event;
}
function mp_get_published_events(&$pays) {
function mp_get_published_events() {
$posts_list = mp_get_published_posts();
$events = [];
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->title = $post->post_title;
array_push($events, $event);

View 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);
}
?>

View File

@@ -22,7 +22,7 @@ function create_markers(map, locations, infowindow) {
for (loc of locations) {
if (loc.coordinates == null) {
console.log("coordinates == null");
//console.log("coordinates == null");
continue;
}

View 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;
}

View File

@@ -0,0 +1,14 @@
/*
* FILTERS
*/
#ljdp_map_filters {
border: 1px solid red;
width: 100%;
height: 30px;
}

View File

@@ -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;
}