From 2a759d1d86a0e5910cfb8e0f3498f9f88d7e0237 Mon Sep 17 00:00:00 2001
From: lenovo
Date: Wed, 9 Nov 2022 14:45:09 +0100
Subject: [PATCH] clean up files to put get_events in main file instead of
add_to_scripts
---
srcs/plugins/map_prof/map_prof_hooks.php | 68 ++++++++++++++-----
srcs/plugins/map_prof/mp_add_to_scripts.php | 13 ++--
srcs/plugins/map_prof/mp_get_events.php | 6 +-
srcs/plugins/map_prof/mp_get_filters.php | 12 ++++
.../map_prof/scripts/mp_create_markers.js | 2 +-
srcs/plugins/map_prof/styles/mp__style.css | 19 ++++++
srcs/plugins/map_prof/styles/mp_filters.css | 14 ++++
srcs/plugins/map_prof/styles/mp_style.css | 24 -------
8 files changed, 106 insertions(+), 52 deletions(-)
create mode 100644 srcs/plugins/map_prof/mp_get_filters.php
create mode 100644 srcs/plugins/map_prof/styles/mp__style.css
create mode 100644 srcs/plugins/map_prof/styles/mp_filters.css
delete mode 100644 srcs/plugins/map_prof/styles/mp_style.css
diff --git a/srcs/plugins/map_prof/map_prof_hooks.php b/srcs/plugins/map_prof/map_prof_hooks.php
index 53281a3..b9017d0 100644
--- a/srcs/plugins/map_prof/map_prof_hooks.php
+++ b/srcs/plugins/map_prof/map_prof_hooks.php
@@ -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 = '
-
';
- foreach ($pays as $loc) {
- $mp_api_script .= '
';
- $mp_api_script .= $loc;
- $mp_api_script .= '
';
- }
+// foreach ($pays as $loc) {
+// $mp_api_script .= '
';
+// $mp_api_script .= $loc;
+// $mp_api_script .= '
';
+// }
$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(
'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 .= '"
';
}
}
- $errors = "nombre d'erreurs : " . $count . "
" . $errors;
+ $errors = "nombre d'erreurs : " . strval($count) . "
" . $errors;
return $errors;
}
add_shortcode('ljdp_errors_map', 'mp_errors_map');
diff --git a/srcs/plugins/map_prof/mp_add_to_scripts.php b/srcs/plugins/map_prof/mp_add_to_scripts.php
index ae454ee..a56770b 100644
--- a/srcs/plugins/map_prof/mp_add_to_scripts.php
+++ b/srcs/plugins/map_prof/mp_add_to_scripts.php
@@ -1,8 +1,5 @@
$var) {
+ wp_add_inline_script('mp_init_map', mp_php_to_js($var, $key), 'before');
+ }
}
?>
diff --git a/srcs/plugins/map_prof/mp_get_events.php b/srcs/plugins/map_prof/mp_get_events.php
index 74f8a3e..32a2c9f 100644
--- a/srcs/plugins/map_prof/mp_get_events.php
+++ b/srcs/plugins/map_prof/mp_get_events.php
@@ -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);
diff --git a/srcs/plugins/map_prof/mp_get_filters.php b/srcs/plugins/map_prof/mp_get_filters.php
new file mode 100644
index 0000000..912bd20
--- /dev/null
+++ b/srcs/plugins/map_prof/mp_get_filters.php
@@ -0,0 +1,12 @@
+$field = [];
+ }
+ mp_console_log("filters:");
+ mp_console_log($filters);
+}
+
+?>
diff --git a/srcs/plugins/map_prof/scripts/mp_create_markers.js b/srcs/plugins/map_prof/scripts/mp_create_markers.js
index b747979..5b80856 100644
--- a/srcs/plugins/map_prof/scripts/mp_create_markers.js
+++ b/srcs/plugins/map_prof/scripts/mp_create_markers.js
@@ -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;
}
diff --git a/srcs/plugins/map_prof/styles/mp__style.css b/srcs/plugins/map_prof/styles/mp__style.css
new file mode 100644
index 0000000..e894a4d
--- /dev/null
+++ b/srcs/plugins/map_prof/styles/mp__style.css
@@ -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;
+}
+
+
diff --git a/srcs/plugins/map_prof/styles/mp_filters.css b/srcs/plugins/map_prof/styles/mp_filters.css
new file mode 100644
index 0000000..7777ea6
--- /dev/null
+++ b/srcs/plugins/map_prof/styles/mp_filters.css
@@ -0,0 +1,14 @@
+
+/*
+ * FILTERS
+ */
+
+
+
+#ljdp_map_filters {
+ border: 1px solid red;
+ width: 100%;
+ height: 30px;
+}
+
+
diff --git a/srcs/plugins/map_prof/styles/mp_style.css b/srcs/plugins/map_prof/styles/mp_style.css
deleted file mode 100644
index 3c92463..0000000
--- a/srcs/plugins/map_prof/styles/mp_style.css
+++ /dev/null
@@ -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;
-}
-
-