Files
2024_WEBSITE_fipf/plugins/fipfcard_plugin/fipfcard_plugin.php
asus 7cfa2e6351 - added capacity in plugin tool to take urls
- test front end integration ok
2024-02-23 10:52:02 +01:00

498 lines
14 KiB
PHP

<?php
/*
Plugin Name: fipfcard_plugin
Plugin URI:
Description:
Author: hugogogo
Version: 1.1.0
Author URI:
*/
/*
5.5 . 5.48
59 . 58.99
50.6 . 50.58
38.5 . 38.53
99.8 . 99.84
25.2 . 25.17
131.6 . 135
63.7 . 63.68
85 . 85.05
50.2 . 50.17
41.4 . 41.43
18.8 . 18.82
*/
/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
plugin dir root
*/
include_once( plugin_dir_path(__FILE__) . '/utils/plugin_tools.php');
PLGNTLS_class::set_root_dir( plugin_dir_path(__FILE__), plugin_dir_url(__FILE__) );
/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
inclusions
*/
include_once(PLGNTLS_class::get_path() . '/php/utils/globals.php');
include_once(PLGNTLS_class::get_path() . '/php/utils/console_log.php');
include_once(PLGNTLS_class::get_path() . '/php/menu/example_menu.php');
//include_once(PLGNTLS_class::get_path() . '/php/images/image_edit_shortcode.php');
//include_once(PLGNTLS_class::get_path() . '/php/images/image-edit.php');
//include_once(PLGNTLS_class::get_path() . '/php/test_cache.php');
/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
plugin shortcode
*/
function fipfcard_main_shortcode()
{
$fipfcard_tools = new PLGNTLS_class();
$myvar_1 = "I am one";
$myvar_2 = "I am two";
$names = ["hugo", "camille"];
$ages = ["13", "34", "56"];
$data = wp_get_current_user();
$data = $data->data;
$data = $data->user_email;
//error_log("data->data");
//error_log($data);
//delete_post_meta(get_the_ID(), "_data_user_email");
//delete_post_meta(get_the_ID(), "_data");
//add_post_meta(get_the_ID(), "data_user_email", $data);
$post_metadata = get_metadata( 'post', get_the_ID() );
$post_meta = get_post_meta( get_the_ID() );
$user_metadata = get_metadata( 'user', get_current_user_id() );
$user_meta = get_user_meta( get_current_user_id() );
$acf_get_fields = get_fields( get_the_ID() );
$user_data = get_userdata( get_current_user_id() );
$current_user = wp_get_current_user();
$user_email = get_field('user_email', 'MarieM');
return $fipfcard_tools->add_to_front
(
array
(
"css/example_style.css",
"js/example_init.js",
"js/example_script2.js",
"js/example_script3.js",
"html/example_index.html",
"html/example_index2.html",
),
compact
(
"myvar_1",
"myvar_2",
"post_metadata",
"post_meta",
"user_metadata",
"user_meta",
"acf_get_fields",
"user_data",
"current_user",
"user_email",
"names",
"ages",
)
);
}
add_shortcode('fipfcard_plugin', 'fipfcard_main_shortcode');
function custom_frontend_posting_form() {
$my_image = the_field('image_ratio');
error_log("my_image");
error_log(json_encode($my_image));
return $my_image;
}
add_shortcode('custom_frontend_posting_form', 'custom_frontend_posting_form');
// function author_shortode_test($field) {
// // global $authordata;
// // $user_id = $authordata->ID;
//
// $author_username = get_query_var('author_name');
// $author = get_user_by('slug', $author_username);
// $user_id = $author->ID;
//
// $acf_field = $field['field'];
// $acf_post_id = "user_{$user_id}";
//
// $acf_shortcode = "[acf field='" . $acf_field . "' post_id='" . $acf_post_id . "']";
//
// error_log("---");
// error_log("acf_shortcode:");
// error_log($acf_shortcode);
// // error_log("get_userdata:");
// // error_log(json_encode(get_userdata($user_id)->data->user_email));
// error_log("get_fields($acf_post_id):");
// error_log(json_encode(get_fields($acf_post_id)));
// error_log("get_field($acf_field, $acf_post_id):");
// error_log(json_encode(get_field($acf_field, $acf_post_id)));
//
// //$shortcode = "[acf field=" . $field['field'] . "]";
// wp_reset_query();
// $acf_return = do_shortcode($acf_shortcode);
// // error_log("acf_return:");
// // error_log(json_encode($acf_return));
// return $acf_return;
// // regarder option repeter de diviengine
// // peutetre plugin gratuit ?
// // plugin menu avec conditions
// }
// add_shortcode('fipf_acf', 'author_shortode_test', 10, 1);
function check_paypal_request()
{
error_log("----");
if (is_page('test_paypal_payment'))
error_log("on test_paypal_payment");
else if (is_page('test_paypal_ok'))
error_log("on test_paypal_ok");
else if (is_page('test_paypal_infos'))
error_log("on test_paypal_infos");
else
return;
error_log("_GET");
error_log(json_encode($_GET));
error_log("_POST");
error_log(json_encode($_POST));
// error_log("_COOKIE");
// error_log(json_encode($_COOKIE));
}
add_action('template_redirect', 'check_paypal_request');
function paypal_shortcode_content()
{
$fipfcard_paypal = new PLGNTLS_class();
/*
<input type="hidden" name="custom" value="5678" />
*/
$pp_live_client_id = "Aedn5e8z__hPBvKirqw5bwlhI9ChG8_N6c1xbgybYyBr4B4oP8uVzmVdH1QVKdPQKf6bWg7orPV4PDrO";
$pp_sandbox_client_id = "AfcmwxIXlG2ZxaMdjazX57I70BXz__aEqNWaTnqfSCI34a0V7nMbytswx7EViUjlpHs7opyrRwaH9YLl";
$pp_client_id = $pp_live_client_id;
$pp_client_id = $pp_sandbox_client_id;
$pp_sdk_currency = "EUR";
$pp_sdk_debug = "true";
$pp_sdk_base_url="https://sandbox.paypal.com";
$pp_sdk_base_url="https://www.paypal.com";
$pp_sdk_client_token="abc123xyz==";
$pp_sdk_src="$pp_sdk_base_url/sdk/js?client-id=$pp_client_id&currency=$pp_sdk_currency&debug=$pp_sdk_debug";
$pp_sdk_src="$pp_sdk_base_url/sdk/js?client-id=$pp_client_id";
$pp_sdk_attributes="src='$pp_sdk_src' data-client-token='$pp_sdk_client_token'";
$pp_sdk_attributes="src='$pp_sdk_src'";
$pp_sdk_html_script="<script $pp_sdk_attributes></script>";
return $fipfcard_paypal->add_to_front(
array(
$pp_sdk_src,
"js/paypal/paypal.js",
"html/paypal/paypal.html",
),
compact(
),
);
}
add_shortcode('fipf_paypal_shortcode', 'paypal_shortcode_content');
//function my_custom_url_handler($query)
//{
// if ($_SERVER['REQUEST_METHOD'] !== 'POST' )
// return ;
// if ($_SERVER['QUERY_STRING'] !== 'update_profile_acf' )
// return ;
// // ! add verification that user can do this edit !
//
// foreach($_POST['field_name'] as $field)
// {
// error_log("_POST[$field]");
// error_log($_POST[$field]);
// }
//}
/*
add_action('init', 'custom_action_handler');
function custom_action_handler() {
error_log("inside init :)");
if ( isset( $_GET['custom_action'] ) && $_GET['custom_action'] === 'do_something' ) {
error_log("GET :)");
}
if ( isset( $_POST['custom_action'] ) && $_POST['custom_action'] === 'do_something' ) {
error_log("POST :)");
}
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
error_log("REQUEST_METHOD === GET");
error_log("_GET");
error_log(json_encode($_GET));
}
if ($_SERVER['REQUEST_METHOD'] === 'GET' && isset($_GET['submit'])) {
error_log("REQUEST_METHOD === GET && GET[SUBMIT]");
}
if ($_SERVER['REQUEST_METHOD'] === 'POST' && $_SERVER['QUERY_STRING'] === 'custom_action=do_something' ) {
error_log("_POST['de_fb_ville']");
error_log(json_encode($_POST['de_fb_ville']));
}
*/
// custom-form-handler.php
/*
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['submit'])) {
error_log("REQUEST_METHOD === POST && POST[SUBMIT]");
error_log("_POST");
error_log(json_encode($_POST));
// Form submitted, handle the submission
$name = sanitize_text_field($_POST['name']);
$email = sanitize_email($_POST['email']);
// Perform validation
$errors = array();
if (empty($name)) {
$errors['name'] = 'Name is required';
}
if (!is_email($email)) {
$errors['email'] = 'Invalid email address';
}
if (empty($errors)) {
// Form data is valid, process the submission
// For example, save data to the database or send an email
// Redirect the user or display a success message
} else {
// Form data is not valid, display errors
// You might re-render the form with error messages here
}
}
}
*/
/*
[17-Feb-2024 17:54:21 UTC]
{
"SERVER_SOFTWARE":"nginx\/1.20.2",
"REQUEST_URI":"\/?custom_action=do_something",
"USER":"www-data",
"HOME":"\/home\/www-data",
"HTTP_SEC_GPC":"1",
"HTTP_SEC_FETCH_USER":"?1",
"HTTP_SEC_FETCH_SITE":"same-origin",
"HTTP_SEC_FETCH_MODE":"navigate",
"HTTP_SEC_FETCH_DEST":"document",
"HTTP_UPGRADE_INSECURE_REQUESTS":"1",
"HTTP_COOKIE":"wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_f31a945e73c53ab9af191e34eb33fa88=hugo%7C1708332197%7CbJvy7kRZ3UWJ2C0ZOaSuhpLCz11vHL8CA68sQv9U1ne%7C927c46e3b46a2716df0fcce98d7ccda0e158be0aad0593b2dc233de4ccad9e27; wp-settings-time-11=1708187741; mjx.menu=renderer%3ANativeMML%26%3Bsemantics%3Atrue%26%3Bcontext%3ABrowser%26%3Bzoom%3ANone",
"HTTP_REFERER":"https:\/\/local_fipfcard_plugin.com\/modif_profile\/",
"HTTP_CONNECTION":"keep-alive",
"HTTP_DNT":"1",
"HTTP_ORIGIN":"https:\/\/local_fipfcard_plugin.com",
"HTTP_CONTENT_LENGTH":"2310",
"HTTP_CONTENT_TYPE":"multipart\/form-data; boundary=---------------------------92033335430820533424009149678",
"HTTP_ACCEPT_ENCODING":"gzip, deflate, br",
"HTTP_ACCEPT_LANGUAGE":"en-US,en;q=0.5",
"HTTP_ACCEPT":"text\/html,application\/xhtml+xml,application\/xml;q=0.9,image\/avif,image\/webp,*\/*;q=0.8",
"HTTP_USER_AGENT":"Mozilla\/5.0 (X11; Ubuntu; Linux x86_64; rv:122.0) Gecko\/20100101 Firefox\/122.0",
"HTTP_HOST":"local_fipfcard_plugin.com",
"REDIRECT_STATUS":"200",
"SERVER_NAME":"local_fipfcard_plugin.com",
"SERVER_PORT":"443",
"SERVER_ADDR":"172.18.0.4",
"REMOTE_PORT":"47220",
"REMOTE_ADDR":"172.18.0.1",
"GATEWAY_INTERFACE":"CGI\/1.1",
"HTTPS":"on",
"REQUEST_SCHEME":"https",
"SERVER_PROTOCOL":"HTTP\/1.1",
"DOCUMENT_ROOT":"\/var\/www\/html",
"DOCUMENT_URI":"\/index.php",
"SCRIPT_NAME":"\/index.php",
"CONTENT_LENGTH":"2310",
"CONTENT_TYPE":"multipart\/form-data; boundary=---------------------------92033335430820533424009149678",
"REQUEST_METHOD":"POST",
"QUERY_STRING":"custom_action=do_something",
"SCRIPT_FILENAME":"\/var\/www\/html\/index.php",
"FCGI_ROLE":"RESPONDER",
"PHP_SELF":"\/index.php",
"REQUEST_TIME_FLOAT":1708192460.934234,
"REQUEST_TIME":1708192460
}
$_POST
{
"field_title":["ville_title","nom","pedagogie"],
"field_name":["de_fb_ville","de_fb_nom","de_fb_pedagogie"],
"field_id":["de_fb_ville_id","de_fb_nom","de_fb_pedagogie"],
"de_fb_ville":"gut",
"de_fb_nom":"gut",
"de_fb_pedagogie":"gut",
"form_key":"33420-0",
"unique_id":"d2564b14-290e-4865-b740-7932ae770d43",
"form_type":"custom",
"divi-form-submit":"yes",
"form_id":"modif_profile",
"form_type_confirm":""
}
add_action('parse_request', 'my_custom_url_handler');
function my_custom_url_handler($query)
{
if ($_SERVER['REQUEST_METHOD'] !== 'POST' )
return ;
if ($_SERVER['QUERY_STRING'] !== 'update_profile_acf' )
return ;
// ! add verification that user can do this edit !
foreach($_POST['field_name'] as $field)
{
error_log("_POST[$field]");
error_log($_POST[$field]);
}
}
*/
/**
* do_action( 'df_before_process', string $form_id, Array $post_array, String $form_type )
* Description: Fires after form is submitted and captcha checking is ok.
* Parameters:
* - $form_id: (String) Form ID from Form setting.
* - $post_array: (Array) Submitted fields from the form. Keys are mapped field names or custom field names (in case of Field Mapping Type is Custom).
* - $form_type : (String) Form Type
*
* wordpress_docker/volumes/wp_volume/wp-content/plugins/divi-form-builder/includes/DiviFormBuilder.php|298 col 18-35| do_action( 'df_before_process', $form_id, $post_array, $form_type );
* wordpress_docker/volumes/wp_volume/wp-content/plugins/divi-form-builder/includes/ajaxcalls/post_ajax.php|254 col 16-33| do_action( 'df_before_process', $form_id, $post_array, $form_type );
*
* check user rights :
* - https://developer.wordpress.org/reference/functions/is_user_logged_in/
* - https://stackoverflow.com/questions/19802492/check-if-current-user-is-administrator-in-wordpress
* - https://developer.wordpress.org/reference/functions/current_user_can/
*/
add_action ('df_before_process', 'PLGNTLS_my_custom_df_form_handler', 10, 3);
function PLGNTLS_my_custom_df_form_handler($form_id, $post_array, $form_type)
{
error_log("in my_custom_df_form_handler");
error_log("form_id");
error_log($form_id);
error_log("post_array");
error_log(json_encode($post_array));
error_log("form_type");
error_log($form_type);
}
// Hook into the 'acf/save_post' action
/*
add_action('acf/save_post', 'handle_acf_form_submission', 5); // 20 is the priority, you can adjust it as needed
function handle_acf_form_submission($post_id)
{
error_log("in acf/save_post");
if ($_SERVER['REQUEST_METHOD'] === 'POST' )
{
error_log("_SERVER['REQUEST_URI']");
error_log(json_encode($_SERVER['REQUEST_URI']));
error_log("_SERVER['QUERY_STRING']");
error_log(json_encode($_SERVER['QUERY_STRING']));
error_log("_POST['de_fb_ville']");
error_log(json_encode($_POST['de_fb_ville']));
}
// Check if the request is coming from the specific URL
if ($_SERVER['QUERY_STRING'] !== '/') {
return; // Exit if the request is not from the specific URL
}
// Check if this is an autosave
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return;
}
// Check if this is a revision
if (wp_is_post_revision($post_id)) {
return;
}
// Check if the current user has permission to edit the post
if (!current_user_can('edit_post', $post_id)) {
return;
}
// Your ACF form submission handling logic goes here
// For example, you can retrieve form data using $_POST and update ACF fields accordingly
if (isset($_POST['your_acf_field_name'])) {
$field_value = sanitize_text_field($_POST['your_acf_field_name']);
update_field('your_acf_field_name', $field_value, $post_id);
}
}
*/
/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
menu plugin
*/
function fipfcard_plugin_menu()
{
add_menu_page
(
'fipf_card', // webpage title
'fipf_card', // menu title
'manage_options', // capability
'fipfcard-plugin', // menu_slug
'fipfcard_plugin_content' // callback function to display page content
);
}
add_action('admin_menu', 'fipfcard_plugin_menu');
/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
ajax
- https://stackoverflow.com/questions/43557755/how-to-call-ajax-in-wordpress
- in `add_action( 'wp_ajax_get_data', 'my_ajax_handler' );`
the 'wp_ajax_get_data' is a hooks formated as 'wp_ajax_{$action}'
the `$action` param is passed in the data object of the ajax call
- to access the content of the data object properties of the ajax call :
use $_POST['property_name']
*/
function fipfcard_ajax_handler()
{
wp_send_json_success( array
(
'It works',
"data_received" => $_POST['postid'],
),
200
);
}
add_action( 'wp_ajax_get_data', 'fipfcard_ajax_handler' );
?>