From c35adaa73267bf518dac8df22c46d9bb552fbef3 Mon Sep 17 00:00:00 2001 From: lenovo Date: Sun, 30 Oct 2022 18:58:08 +0100 Subject: [PATCH] map is showing and files are enqueued and included the right way --- :w | 132 +++++++++++++ srcs/plugins/google_map/index.php | 23 ++- srcs/plugins/map_prof/map_prof.php | 180 ++++++++---------- srcs/plugins/map_prof/mp_console_log.php | 11 ++ srcs/plugins/map_prof/mp_init_map.js | 11 ++ .../map_prof/{style.css => mp_style.css} | 3 + srcs/plugins/map_prof/mp_url_api.php | 25 +++ srcs/requirements/nginx/Dockerfile | 2 + .../nginx/conf/inception_nginx.conf | 38 +++- 9 files changed, 307 insertions(+), 118 deletions(-) create mode 100644 :w create mode 100644 srcs/plugins/map_prof/mp_console_log.php create mode 100644 srcs/plugins/map_prof/mp_init_map.js rename srcs/plugins/map_prof/{style.css => mp_style.css} (61%) create mode 100644 srcs/plugins/map_prof/mp_url_api.php diff --git a/:w b/:w new file mode 100644 index 0000000..500be48 --- /dev/null +++ b/:w @@ -0,0 +1,132 @@ +'; + return $mp_api_script; +} +function mp_add_api() { + $mp_create_url = array( + 'src' => 'https://maps.googleapis.com/maps/api/js', + 'key' => 'AIzaSyCvdGV2ssD4ov4a9CuIlQhoJyz5gWWiSvE', + 'callback' => 'mp_init_map', + ); + $mp_src = ""; + foreach ($mp_create_url as $url_key => $url_value) { + if ($url_key === 'src') { + $mp_src .= $url_value; + if (count($mp_create_url > 1)) + $mp_src .= "?"; + } + else + $mp_src .= "&" . $url_key . "=" . $url_value; + }; + + $mp_api_script = ''; + return $mp_api_script; +} +function show_map() { + $mp_api_script = mp_add_div(); + $mp_api_script .= mp_add_api(); + return $mp_api_script; +} +add_shortcode('lejourduprof_map', 'show_map'); +//add_shortcode('lejourduprof_map', 'mp_add_div'); + + +//function print_content($content){ +// +// // print only on the page 'map', and other conditions +// // https://developer.wordpress.org/reference/hooks/the_content/ +// if (!( is_page('map_prof') && in_the_loop() && is_main_query() )) +// return $content; +// +// // https://developer.wordpress.org/reference/functions/get_posts/ +// $get_posts_args = array( +// 'numberposts' => -1, +// 'post_status' => 'publish', +// ); +// +// $posts_list = get_posts($get_posts_args); +// $content .= "

"; +// $content .= "nb posts published : "; +// $content .= count($posts_list); +// $content .= "

"; +// foreach ($posts_list as $post_value) { +// $content .= "
"; +// $content .= "- post title: ["; +// $content .= $post_value->post_title; +// $content .= "] - content: ["; +// $content .= $post_value->post_content; +// $content .= "]"; +// $content .= "
"; +// } +// +// // TESTS : print posts full content +// // +// //$posts_list = get_posts($args); +// //$content .= "

"; +// //$content .= "nb posts published : "; +// //$content .= count($posts_list); +// //$content .= "

"; +// //foreach ($posts_list as $post_key => $post_value) { +// // $content .= "

"; +// // $content .= "post content : "; +// // $content .= $post_key; +// // $content .= " : "; +// // $content .= "
"; +// // foreach ($post_value as $key => $value) { +// // $content .= "- ["; +// // $content .= $key; +// // $content .= "]: ["; +// // $content .= $value; +// // $content .= "]
"; +// // } +// // $content .= "

"; +// //} +// +// $content .= '
'; +// $content .= ''; +// $content .= ''; +// +// return $content; +//}; +//add_action('the_content', 'print_content', 1); + +?> diff --git a/srcs/plugins/google_map/index.php b/srcs/plugins/google_map/index.php index e5065fa..fbf7ae4 100644 --- a/srcs/plugins/google_map/index.php +++ b/srcs/plugins/google_map/index.php @@ -21,7 +21,7 @@ function ink_menu_page() { } function ink_gm_setting(){ ?> -

Google Map

+

Google Map

@@ -56,25 +56,24 @@ function my_init_script() { wp_enqueue_script('my_script', $script_path, array('jquery')); $style_path = plugins_url('style.css', __FILE__); wp_enqueue_style('my_style', $style_path); - console_log("urlencode : " . urlencode("128 rue de la croix nivert, paris")); } +add_shortcode('googlemap', 'show_google_map'); function show_google_map() { global $wpdb; $GoogleMap_Latitude = get_option('googleMap_latitude_position'); $GoogleMap_Longitude = get_option('googleMap_longitude_position'); $GoogleMap_zoom = get_option('map_zoom_value'); //src="https://maps.googleapis.com/maps/api/geocode/json?address=paris&key=AIzaSyCvdGV2ssD4ov4a9CuIlQhoJyz5gWWiSvE -?> - -
-
-
-
- + +
+
+
+
+ '; } -add_shortcode('googlemap', 'show_google_map'); ?> diff --git a/srcs/plugins/map_prof/map_prof.php b/srcs/plugins/map_prof/map_prof.php index 80979d4..df6cbac 100644 --- a/srcs/plugins/map_prof/map_prof.php +++ b/srcs/plugins/map_prof/map_prof.php @@ -8,108 +8,92 @@ Version: 1.0.0 Author URI: */ -add_action( 'init', 'my_init_script' ); -function my_init_script() { - $style_path = plugins_url('style.css', __FILE__); - wp_enqueue_style('my_style', $style_path); +include_once(dirname(__FILE__) . '/mp_console_log.php'); +require_once(dirname(__FILE__) . '/mp_url_api.php'); + +add_action( 'wp_enqueue_scripts', 'wpa_enqueue_scripts' ); +function wpa_enqueue_scripts() { + wp_enqueue_style( 'mp_style', plugins_url('mp_style.css', __FILE__), '', '', false); + wp_enqueue_script('mp_init_map', plugins_url('mp_init_map.js', __FILE__), '', '', true); + wp_enqueue_script('mp_google_api', mp_url_api(), ['mp_init_map'], '', true); } -// if block theme : https://wordpress.org/support/topic/twenty-twenty-two-cpt-template-error-theme-without-header-is-deprecated/ -function add_map_api(){ - ?> - - - map here
'; + return $mp_api_script; } -//add_action('wp_head', 'add_map_api'); -function print_content($content){ - // print only on the page 'map', and other conditions - // https://developer.wordpress.org/reference/hooks/the_content/ - if (!( is_page('map_prof') && in_the_loop() && is_main_query() )) - return $content; - - // https://developer.wordpress.org/reference/functions/get_posts/ - $get_posts_args = array( - 'numberposts' => -1, - 'post_status' => 'publish', - ); - - $posts_list = get_posts($get_posts_args); - $content .= "

"; - $content .= "nb posts published : "; - $content .= count($posts_list); - $content .= "

"; - foreach ($posts_list as $post_value) { - $content .= "
"; - $content .= "- post title: ["; - $content .= $post_value->post_title; - $content .= "] - content: ["; - $content .= $post_value->post_content; - $content .= "]"; - $content .= "
"; - } - - // TESTS : print posts full content - // - //$posts_list = get_posts($args); - //$content .= "

"; - //$content .= "nb posts published : "; - //$content .= count($posts_list); - //$content .= "

"; - //foreach ($posts_list as $post_key => $post_value) { - // $content .= "

"; - // $content .= "post content : "; - // $content .= $post_key; - // $content .= " : "; - // $content .= "
"; - // foreach ($post_value as $key => $value) { - // $content .= "- ["; - // $content .= $key; - // $content .= "]: ["; - // $content .= $value; - // $content .= "]
"; - // } - // $content .= "

"; - //} - - $content .= '
'; - $content .= ''; - $content .= ''; - - return $content; -}; -add_action('the_content', 'print_content', 1); +//function print_content($content){ +// +// // print only on the page 'map', and other conditions +// // https://developer.wordpress.org/reference/hooks/the_content/ +// if (!( is_page('map_prof') && in_the_loop() && is_main_query() )) +// return $content; +// +// // https://developer.wordpress.org/reference/functions/get_posts/ +// $get_posts_args = array( +// 'numberposts' => -1, +// 'post_status' => 'publish', +// ); +// +// $posts_list = get_posts($get_posts_args); +// $content .= "

"; +// $content .= "nb posts published : "; +// $content .= count($posts_list); +// $content .= "

"; +// foreach ($posts_list as $post_value) { +// $content .= "
"; +// $content .= "- post title: ["; +// $content .= $post_value->post_title; +// $content .= "] - content: ["; +// $content .= $post_value->post_content; +// $content .= "]"; +// $content .= "
"; +// } +// +// // TESTS : print posts full content +// // +// //$posts_list = get_posts($args); +// //$content .= "

"; +// //$content .= "nb posts published : "; +// //$content .= count($posts_list); +// //$content .= "

"; +// //foreach ($posts_list as $post_key => $post_value) { +// // $content .= "

"; +// // $content .= "post content : "; +// // $content .= $post_key; +// // $content .= " : "; +// // $content .= "
"; +// // foreach ($post_value as $key => $value) { +// // $content .= "- ["; +// // $content .= $key; +// // $content .= "]: ["; +// // $content .= $value; +// // $content .= "]
"; +// // } +// // $content .= "

"; +// //} +// +// $content .= '
'; +// $content .= ''; +// $content .= ''; +// +// return $content; +//}; +//add_action('the_content', 'print_content', 1); ?> diff --git a/srcs/plugins/map_prof/mp_console_log.php b/srcs/plugins/map_prof/mp_console_log.php new file mode 100644 index 0000000..ef67172 --- /dev/null +++ b/srcs/plugins/map_prof/mp_console_log.php @@ -0,0 +1,11 @@ +' . $js_code . ''; + } + echo $js_code; +} +?> diff --git a/srcs/plugins/map_prof/mp_init_map.js b/srcs/plugins/map_prof/mp_init_map.js new file mode 100644 index 0000000..3240744 --- /dev/null +++ b/srcs/plugins/map_prof/mp_init_map.js @@ -0,0 +1,11 @@ +function mp_init_map() { + var location = {lat: 38.8833, lng: -77.0167}; + var map = new google.maps.Map(document.getElementById("map"), { + zoom: 12, + center: location + }); + var marker = new google.maps.Marker({ + position: location, + map: map + }); +} diff --git a/srcs/plugins/map_prof/style.css b/srcs/plugins/map_prof/mp_style.css similarity index 61% rename from srcs/plugins/map_prof/style.css rename to srcs/plugins/map_prof/mp_style.css index 9c0458b..86c7504 100644 --- a/srcs/plugins/map_prof/style.css +++ b/srcs/plugins/map_prof/mp_style.css @@ -2,3 +2,6 @@ height: 500px; width: 100%; } +#temoin { + color: blue; +} diff --git a/srcs/plugins/map_prof/mp_url_api.php b/srcs/plugins/map_prof/mp_url_api.php new file mode 100644 index 0000000..a871bde --- /dev/null +++ b/srcs/plugins/map_prof/mp_url_api.php @@ -0,0 +1,25 @@ + 'https://maps.googleapis.com/maps/api/js', + 'sensor' => 'false', + 'key' => 'AIzaSyCvdGV2ssD4ov4a9CuIlQhoJyz5gWWiSvE', + 'callback' => 'mp_init_map', + ); + $mp_src = ""; + foreach ($mp_url as $url_key => $url_value) { + if ($url_key === 'src') { + $mp_src .= $url_value; + if (count($mp_url > 1)) + $mp_src .= "?"; + } + else + $mp_src .= "&" . $url_key . "=" . $url_value; + }; + + //$mp_api_script = ''; + //return $mp_api_script; + return $mp_src; +} +?> diff --git a/srcs/requirements/nginx/Dockerfile b/srcs/requirements/nginx/Dockerfile index 549d028..19c82f6 100644 --- a/srcs/requirements/nginx/Dockerfile +++ b/srcs/requirements/nginx/Dockerfile @@ -11,6 +11,8 @@ RUN apk update && apk add \ # nginx conf COPY ./conf/nginx.conf.alpine /etc/nginx/nginx.conf COPY ./conf/inception_nginx.conf /etc/nginx/http.d/ +# dir for logs +RUN mkdir -p /var/log/nginx/ # create user www-data and assign it to group www-data RUN adduser -S www-data && \ diff --git a/srcs/requirements/nginx/conf/inception_nginx.conf b/srcs/requirements/nginx/conf/inception_nginx.conf index b4df861..b03cccb 100644 --- a/srcs/requirements/nginx/conf/inception_nginx.conf +++ b/srcs/requirements/nginx/conf/inception_nginx.conf @@ -9,18 +9,40 @@ server { root /var/www/html/; # contains default nginx index.nginx-debian.html index index.html index.php; # defines files that will be used as index (https://nginx.org/en/docs/http/ngx_http_index_module.html) + + access_log /var/log/nginx/${WP_URL}.access.log; + error_log /var/log/nginx/${WP_URL}.error.log; - location / { - try_files $uri $uri/ =404; # from /etc/nginx/sites-enabled/default : First attempt to serve request as file, then as directory, then fall back to displaying a 404 - } - - # pass PHP scripts to FastCGI (PHP-FPM) server + # use fastcgi for all php files location ~ \.php$ { - try_files $uri =404; - - include fastcgi_params; fastcgi_pass wordpress:9000; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + include fastcgi_params; } + +# followings are from : +# https://www.farinspace.com/wordpress-nginx-rewrite-rules/ + + # unless the request is for a valid file, send to bootstrap + # without this, permalinks changes don't work + if (!-e $request_filename) { + rewrite ^(.+)$ /index.php?q=$1 last; + } + + ## enforce NO www + #if ($host ~* ^www\.(.*)) { + # set $host_without_www $1; + # rewrite ^/(.*)$ $scheme://$host_without_www/$1 permanent; + #} + + ## catch all + #error_page 404 /index.php; + + ## deny access to apache .htaccess files + #location ~ /\.ht { + # deny all; + #} + } +