diff --git a/Makefile b/Makefile
index 520358f..b79339b 100644
--- a/Makefile
+++ b/Makefile
@@ -30,6 +30,15 @@ erase:
new:
$(MAKE) $@ -C $(WP_DOCKER_D)
+down:
+ $(MAKE) $@ -C $(WP_DOCKER_D)
-.PHONY : all fclean re erase new
+up:
+ $(MAKE) $@ -C $(WP_DOCKER_D)
+
+build:
+ $(MAKE) $@ -C $(WP_DOCKER_D)
+
+
+.PHONY : all fclean re erase new down up build
diff --git a/plugins/fipf_wp_plugin/fipf_wp_hooks.php b/plugins/fipf_wp_plugin/fipf_wp_hooks.php
deleted file mode 100644
index 2d117eb..0000000
--- a/plugins/fipf_wp_plugin/fipf_wp_hooks.php
+++ /dev/null
@@ -1,80 +0,0 @@
- value
- # from an array of variables names as strings
- add_var_to_front( compact(
- "myvar_1",
- "myvar_2",
- ));
-
-
- $names = ["hugo", "camille"];
- $ages = ["13", "34", "56"];
- $html_front = create_html(
- array(
- "index.html",
- "index2.html",
- ),
- compact(
- "names",
- "ages",
- )
- );
-
- return $html_front;
-}
-add_shortcode('fipf_wp_plugin', 'main_shortcode');
-
-
-/* * * * * * * * * * * * * * * * * * * * * * * *
- * menu plugin
- */
-
-function plugin_menu() {
- add_menu_page(
- 'FIPF wp plugin', // webpage title
- 'FIPF', // menu title
- 'manage_options', // capability
- 'fipf-wp-plugin', // menu_slug
- 'fipf_wp_plugin_content' // callback function to display page content
- );
-}
-add_action('admin_menu', 'plugin_menu');
-
-?>
diff --git a/plugins/fipf_wp_plugin/html/index.html b/plugins/fipf_wp_plugin/html/index.html
deleted file mode 100644
index 0767c80..0000000
--- a/plugins/fipf_wp_plugin/html/index.html
+++ /dev/null
@@ -1,7 +0,0 @@
-
i am a new p
-to change
-
diff --git a/plugins/fipf_wp_plugin/html/index2.html b/plugins/fipf_wp_plugin/html/index2.html
deleted file mode 100644
index 094ffdc..0000000
--- a/plugins/fipf_wp_plugin/html/index2.html
+++ /dev/null
@@ -1,9 +0,0 @@
-
- age
-
-to change
-aaaaaand this is the end
diff --git a/plugins/fipf_wp_plugin/scripts/myscript.js b/plugins/fipf_wp_plugin/scripts/myscript.js
deleted file mode 100644
index 5bbed5f..0000000
--- a/plugins/fipf_wp_plugin/scripts/myscript.js
+++ /dev/null
@@ -1,5 +0,0 @@
-
-const title = document.querySelector(".first_el_to_change");
-title.innerHTML = "--- coucou ;)";
-
-console.log("myvar_1: " + myvar_1);
diff --git a/plugins/fipf_wp_plugin/scripts/myscript3.js b/plugins/fipf_wp_plugin/scripts/myscript3.js
deleted file mode 100644
index da21442..0000000
--- a/plugins/fipf_wp_plugin/scripts/myscript3.js
+++ /dev/null
@@ -1,5 +0,0 @@
-
-const title3 = document.querySelector(".third_el_to_change");
-title3.innerHTML = "--- bye bye";
-console.log("myvar_2: " + myvar_2);
-
diff --git a/plugins/fipf_wp_plugin/styles/mystyle.css b/plugins/fipf_wp_plugin/styles/mystyle.css
deleted file mode 100644
index 76d5017..0000000
--- a/plugins/fipf_wp_plugin/styles/mystyle.css
+++ /dev/null
@@ -1,3 +0,0 @@
-.first_el_to_change {
- border: 1px solid red;
-}
diff --git a/plugins/fipf_wp_plugin/utils/add_to_front.php b/plugins/fipf_wp_plugin/utils/add_to_front.php
deleted file mode 100644
index 9f9c34b..0000000
--- a/plugins/fipf_wp_plugin/utils/add_to_front.php
+++ /dev/null
@@ -1,52 +0,0 @@
-, /url/to/file, [depends on], version, defer? );
- //wp_enqueue_style( , /url/to/file, [depends on], version, media );
-
- $previous_css_basename = '';
- $previous_js_basename = '';
- foreach ($files_arr as $file) {
- $file_ext = pathinfo($file, PATHINFO_EXTENSION);
- $file_basename = pathinfo($file, PATHINFO_FILENAME);
- if ($file_ext === "js")
- $dir_path = 'scripts/';
- else if ($file_ext === "css")
- $dir_path = 'styles/';
- else
- continue;
-
- $file_url = plugin_dir_url(__DIR__).$dir_path.$file;
- $file_path = plugin_dir_path(__DIR__).$dir_path.$file;
- $file_version = date("ymd-Gis", filemtime($file_path));
-
- if ($file_ext === "js") {
- wp_enqueue_script( $file_basename, $file_url, $previous_js_basename, $file_version, true);
- $previous_js_basename = $file_basename;
- }
- else if ($file_ext === "css") {
- wp_enqueue_style( $file, $file_url, $previous_css_basename, $file_version, '');
- $previous_css_basename = $file_basename;
- }
- }
-}
-
-# this function expect an array of key => value
-# with the key being name of the variable, like this :
-# 'my_var' => 'value',
-# simpler way to do it is to use compact when calling the function :
-# add_var_to_front(compact("var1", "var2", "var3"));
-function add_var_to_front($var_array) {
- extract($var_array);
-
- foreach ($var_array as $key => $var)
- {
- $js_var = 'const ' . $key . ' = ';
- $js_var .= json_encode($var);
- $js_var .= ';';
- console_log("in php, js_var: " . $js_var);
- wp_add_inline_script('myscript', $js_var, 'before');
- }
-}
-
-?>
diff --git a/plugins/fipf_wp_plugin/utils/console_log.php b/plugins/fipf_wp_plugin/utils/console_log.php
deleted file mode 100644
index 3b32e03..0000000
--- a/plugins/fipf_wp_plugin/utils/console_log.php
+++ /dev/null
@@ -1,11 +0,0 @@
-' . $js_code . '';
- echo $js_code;
-}
-
-?>
-
diff --git a/plugins/fipf_wp_plugin/utils/create_html.php b/plugins/fipf_wp_plugin/utils/create_html.php
deleted file mode 100644
index 09cb99c..0000000
--- a/plugins/fipf_wp_plugin/utils/create_html.php
+++ /dev/null
@@ -1,25 +0,0 @@
-
diff --git a/plugins/fipfcard_plugin/css/example_style.css b/plugins/fipfcard_plugin/css/example_style.css
new file mode 100644
index 0000000..bf327c8
--- /dev/null
+++ b/plugins/fipfcard_plugin/css/example_style.css
@@ -0,0 +1,7 @@
+.first_el_to_change {
+ border: 1px solid red;
+}
+#model_plugin_shortcode {
+ border: 1px solid blue;
+ padding: 10px;
+}
diff --git a/plugins/fipfcard_plugin/fipfcard_plugin.php b/plugins/fipfcard_plugin/fipfcard_plugin.php
new file mode 100644
index 0000000..14b6a51
--- /dev/null
+++ b/plugins/fipfcard_plugin/fipfcard_plugin.php
@@ -0,0 +1,119 @@
+ $_POST['data'],
+ ),
+ 200
+ );
+}
+add_action( 'wp_ajax_get_data', 'my_ajax_handler' );
+
+
+?>
diff --git a/plugins/fipfcard_plugin/html/example_index.html b/plugins/fipfcard_plugin/html/example_index.html
new file mode 100644
index 0000000..73a333b
--- /dev/null
+++ b/plugins/fipfcard_plugin/html/example_index.html
@@ -0,0 +1,9 @@
+
+
i am a new p
+
to change
+
+
diff --git a/plugins/fipfcard_plugin/html/example_index2.html b/plugins/fipfcard_plugin/html/example_index2.html
new file mode 100644
index 0000000..4ad6346
--- /dev/null
+++ b/plugins/fipfcard_plugin/html/example_index2.html
@@ -0,0 +1,10 @@
+
+
age
+
+
to change
+
aaaaaand this is the end
+
diff --git a/plugins/fipfcard_plugin/html/menu/example_menu.html b/plugins/fipfcard_plugin/html/menu/example_menu.html
new file mode 100644
index 0000000..7ca76e8
--- /dev/null
+++ b/plugins/fipfcard_plugin/html/menu/example_menu.html
@@ -0,0 +1,2 @@
+
+
diff --git a/plugins/fipf_wp_plugin/html/templates/presentation.html b/plugins/fipfcard_plugin/html/templates/example_presentation.html
similarity index 100%
rename from plugins/fipf_wp_plugin/html/templates/presentation.html
rename to plugins/fipfcard_plugin/html/templates/example_presentation.html
diff --git a/plugins/fipfcard_plugin/js/example_init.js b/plugins/fipfcard_plugin/js/example_init.js
new file mode 100644
index 0000000..f12f550
--- /dev/null
+++ b/plugins/fipfcard_plugin/js/example_init.js
@@ -0,0 +1,8 @@
+
+const title = document.querySelector(".first_el_to_change");
+title.innerHTML = "--- coucou ;) " + myvar_1;
+
+const ajax_button_1 = document.querySelector("#test_ajax_1");
+ajax_button_1.addEventListener('click', () => {
+ ajax_post(ajax_button_1, 'get_data');
+});
diff --git a/plugins/fipf_wp_plugin/scripts/myscript2.js b/plugins/fipfcard_plugin/js/example_script2.js
similarity index 99%
rename from plugins/fipf_wp_plugin/scripts/myscript2.js
rename to plugins/fipfcard_plugin/js/example_script2.js
index 894f2c1..b21c8a6 100644
--- a/plugins/fipf_wp_plugin/scripts/myscript2.js
+++ b/plugins/fipfcard_plugin/js/example_script2.js
@@ -1,4 +1,3 @@
const title2 = document.querySelector(".second_el_to_change");
title2.innerHTML = "--- ho boy !";
-
diff --git a/plugins/fipfcard_plugin/js/example_script3.js b/plugins/fipfcard_plugin/js/example_script3.js
new file mode 100644
index 0000000..b1abd92
--- /dev/null
+++ b/plugins/fipfcard_plugin/js/example_script3.js
@@ -0,0 +1,3 @@
+
+const title3 = document.querySelector(".third_el_to_change");
+title3.innerHTML = "--- bye bye, " + myvar_2;
diff --git a/plugins/fipfcard_plugin/js/menu/example_menu.js b/plugins/fipfcard_plugin/js/menu/example_menu.js
new file mode 100644
index 0000000..206c5b8
--- /dev/null
+++ b/plugins/fipfcard_plugin/js/menu/example_menu.js
@@ -0,0 +1,7 @@
+const inputElement = document.getElementById('mytext');
+const sendButton = document.getElementById('mybutton');
+
+sendButton.addEventListener('click', () => {
+ const inputValue = inputElement.value;
+ ajax_post(inputValue, 'get_data');
+});
diff --git a/plugins/fipfcard_plugin/js/utils/ajax.js b/plugins/fipfcard_plugin/js/utils/ajax.js
new file mode 100644
index 0000000..c457db1
--- /dev/null
+++ b/plugins/fipfcard_plugin/js/utils/ajax.js
@@ -0,0 +1,34 @@
+/*
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+function that create an ajax post action
+it can be "overloaded" with a callback_response and _error
+*/
+function ajax_post(ajax_data, action, callback_response, callback_error) {
+ const data = new FormData();
+ data.append('action', action);
+ data.append('_ajax_nonce', wp_ajax._nonce);
+ data.append('data', ajax_data);
+
+ fetch(wp_ajax._url, {
+ method: 'POST',
+ credentials: 'same-origin',
+ body: data
+ })
+ .then((response) => response.json())
+ .then((data) => {
+ if (callback_response)
+ callback_response(data);
+ else {
+ console.log("data: ");
+ console.log(data);
+ }
+ })
+ .catch((error) => {
+ if (callback_error)
+ callback_error(error);
+ else {
+ console.log("error: ");
+ console.log(error);
+ }
+ });
+};
diff --git a/plugins/fipfcard_plugin/php/menu/example_menu.php b/plugins/fipfcard_plugin/php/menu/example_menu.php
new file mode 100644
index 0000000..c69058d
--- /dev/null
+++ b/plugins/fipfcard_plugin/php/menu/example_menu.php
@@ -0,0 +1,15 @@
+
diff --git a/plugins/fipfcard_plugin/php/utils/add_to_front.php b/plugins/fipfcard_plugin/php/utils/add_to_front.php
new file mode 100644
index 0000000..14a07db
--- /dev/null
+++ b/plugins/fipfcard_plugin/php/utils/add_to_front.php
@@ -0,0 +1,156 @@
+handle, $wp_scripts->queue);
+// if ($already_enqueued !== false)
+// return ;
+
+ $first_script = $file->handle;
+ wp_enqueue_script( $file->handle, $file->url, $previous_js_basename, $file->version, true);
+
+ $_url = admin_url( 'admin-ajax.php' );
+ $_nonce = wp_create_nonce( 'wp-pageviews-nonce' );
+ $vars = compact("_url","_nonce",);
+// add_var_to_front($vars);
+ $object_name = "wp_ajax";
+ wp_localize_script($file->handle, $object_name, $vars);
+
+}
+
+
+
+
+/*
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+@param string : name of the file, with its path from its extension directory
+ - from js/ root for .js files
+ - from css/ root for .css files
+@return object / null :
+ - null if file is not js or css
+ - or an object with all the necessary infos :
+ - ext : name.js -> "js"
+ - basename : name.js -> "name"
+ - handle : name.js -> "name_js"
+ - url : url to file in wordpress
+ - path : path to file in server
+ - version : used to avoid browser caching
+*/
+function init_file($file_name) {
+ $file = (object)[];
+
+ $file->ext = pathinfo($file_name, PATHINFO_EXTENSION);
+ if ($file->ext === "js")
+ $dir_path = 'js/';
+ else if ($file->ext === "css")
+ $dir_path = 'css/';
+ else
+ return null;
+
+ $file->basename = pathinfo($file_name, PATHINFO_FILENAME);
+ $file->handle = str_replace(".", "_", $file_name);
+
+ $file->url = FIPFCARD_PLUGIN_URL.$dir_path.$file_name;
+ $file->path = FIPFCARD_PLUGIN_DIR.$dir_path.$file_name;
+ $file->version = date("ymd-Gis", filemtime($file->path));
+
+ return $file;
+}
+
+
+
+/*
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+@param array : list of files :
+ - with their path from root of their type of file (ex: from js/ to .js files)
+ - and with their extension
+@param boolean
+ - to add ajax script and variables
+ - default to true
+*/
+function add_files_to_front($files_arr, $add_ajax = true) {
+ //wp_enqueue_script(, /url/to/file, [depends on], version, defer? );
+ //wp_enqueue_style( , /url/to/file, [depends on], version, media );
+ global $first_script;
+
+ if ($add_ajax === true)
+ add_ajax_post($file);
+
+ $previous_css_basename = '';
+ $previous_js_basename = '';
+ foreach ($files_arr as $file_name) {
+ $file = init_file($file_name);
+ if ($file->ext === "js") {
+ if (is_null($first_script))
+ $first_script = $file->handle;
+ wp_enqueue_script( $file->handle, $file->url, $previous_js_basename, $file->version, true);
+ $previous_js_basename = $file->basename;
+ }
+ else if ($file->ext === "css") {
+ wp_enqueue_style( $file->handle, $file->url, $previous_css_basename, $file->version, '');
+ $previous_css_basename = $file->basename;
+ }
+ }
+}
+
+
+
+/*
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+pass variables to js front as global variables
+@param array : list of key => value
+ with the key being name of the variable, like this :
+ 'my_var' => 'value',
+ simpler way to do it is to use compact when calling the function :
+ add_var_to_front(compact("var1", "var2", "var3"));
+@param string (optionnal) : name of first embended script that need these variables
+ (it will be available to this script and all followings)
+ this name is the filename + "_" + extension :
+ init.js -> init_js
+*/
+function add_var_to_front($vars, $handle = null) {
+ if (is_null($handle)) {
+ global $first_script;
+ $handle = $first_script;
+ }
+
+ extract($vars);
+ foreach ($vars as $key => $var)
+ {
+ $js_var = 'let '.$key.' = '.json_encode($var).';';
+ wp_add_inline_script($handle, $js_var, 'before');
+ }
+
+// the other way with localize has multiple incidences :
+// - it creates an object from wich you can access the variables
+// - so if you call it again wiht the same name, it will overwrite the previous
+// {
+// $handle = pathinfo($handle, PATHINFO_FILENAME);
+// $object_name = "php_data";
+//
+// wp_localize_script($handle, $object_name, $vars);
+// }
+}
+
+?>
diff --git a/plugins/fipfcard_plugin/php/utils/console_log.php b/plugins/fipfcard_plugin/php/utils/console_log.php
new file mode 100644
index 0000000..f45ca58
--- /dev/null
+++ b/plugins/fipfcard_plugin/php/utils/console_log.php
@@ -0,0 +1,16 @@
+console.log(' . $json_output . ');';
+ echo $js_code;
+}
+
+
+?>
diff --git a/plugins/fipfcard_plugin/php/utils/create_html.php b/plugins/fipfcard_plugin/php/utils/create_html.php
new file mode 100644
index 0000000..71f3a53
--- /dev/null
+++ b/plugins/fipfcard_plugin/php/utils/create_html.php
@@ -0,0 +1,39 @@
+ val
+ - recommanded to do it with compact()
+ex: create_html( "file.html", compact("var1","var2",) );
+ex: create_html( array("file1.html", "file2.html"), array("var1"=>"value") );
+@return a string of html code
+
+using ob_start() and ob_get_clean()
+allows to have php expansion inside the html loaded
+in opposition to the methode file_get_contents()
+
+https://stackoverflow.com/a/4402045/9497573
+*/
+function create_html($files, $vars = null) {
+ $files = (array)$files;
+ $html_dir = FIPFCARD_PLUGIN_DIR.'html/';
+ if (!is_null($vars))
+ extract($vars);
+
+ ob_start();
+ foreach($files as $file) {
+ include($html_dir.$file);
+ }
+ $html = ob_get_clean();
+
+ return $html;
+}
+
+?>
diff --git a/plugins/fipfcard_plugin/php/utils/globals.php b/plugins/fipfcard_plugin/php/utils/globals.php
new file mode 100644
index 0000000..1d38805
--- /dev/null
+++ b/plugins/fipfcard_plugin/php/utils/globals.php
@@ -0,0 +1,22 @@
+
diff --git a/private b/private
index fdb8a94..ae15730 160000
--- a/private
+++ b/private
@@ -1 +1 @@
-Subproject commit fdb8a94eb8b87f24460c9b2e3d7b1b76282d3f5c
+Subproject commit ae15730a8f0b2a794b7a8aa4fa771fa625da881c