diff --git a/plugins/cipf_plugin/fipfcard_plugin.php b/plugins/cipf_plugin/fipfcard_plugin.php index 49b8e52..22f1021 100644 --- a/plugins/cipf_plugin/fipfcard_plugin.php +++ b/plugins/cipf_plugin/fipfcard_plugin.php @@ -2,9 +2,9 @@ /* Plugin Name: cipf_plugin Plugin URI: -Description: test avec page de redirection +Description: version avec vraie page redirection && patch formbuilder calculation Author: hugogogo -Version: 0.2.8 +Version: 0.2.8.2 Author URI: */ @@ -55,8 +55,8 @@ include_once(PLGNTLS_class::root_path() . 'php/admin_modif_prof.php'); /* include_once(PLGNTLS_class::root_path() . 'php/form_builder_patch/url_validation.php'); include_once(PLGNTLS_class::root_path() . 'php/form_builder_patch/multiple_modals.php'); -include_once(PLGNTLS_class::root_path() . 'php/form_builder_patch/form_calculation.php'); */ +include_once(PLGNTLS_class::root_path() . 'php/form_builder_patch/form_calculation.php'); diff --git a/plugins/cipf_plugin/php/admin_modif_prof.php b/plugins/cipf_plugin/php/admin_modif_prof.php index 62f8748..6100caf 100644 --- a/plugins/cipf_plugin/php/admin_modif_prof.php +++ b/plugins/cipf_plugin/php/admin_modif_prof.php @@ -18,60 +18,12 @@ if (!defined('ABSPATH')) { -/* -* version 4 : -* modifying directly the current user : very hardcore, and need to store it -*/ -function shortcode_choose_meta_id_CIPF ($options) { - PLGNTLS_class::debug_infos(); -// $role_fipf = PLGNTLS_class::ROLE_FIPF; -// $role_admin = PLGNTLS_class::ROLE_ADMIN; -// -// $current_user = wp_get_current_user(); -// -// $allowed_roles = array($role_admin, $role_fipf); -// if (!array_intersect($allowed_roles, $current_user->roles)) -// return; - - - $option = reset($options); - if (!is_string($option)) { - return; - } - - if ($option === 'logged_in') { - $id = get_current_user_id(); - error_log("logged_in id : " . $id); - PLGNTLS_class::set_current_user_backup(); - wp_set_current_user($id); - } - else if ($option === 'post_creator') { - $id = get_queried_object_id(); - error_log("post_creator id : " . $id); - PLGNTLS_class::set_current_user_backup(); - wp_set_current_user($id); - } - else if ($option === 'off') { - $id = PLGNTLS_class::reset_current_user_backup(); - error_log("reset id : " . $id); - wp_set_current_user($id); - } - else - return; - - - //add_action('set_current_user', 'force_set_user_CIPF'); -} -add_shortcode('cipf_change_meta_id', 'shortcode_choose_meta_id_CIPF'); - - - /* * version 3 : * * trying with a filter on wp_get_current_user() * used by form builder to retrieve the user before using get_metadat() -* -> somehow the filter is never called +* -> the filter is not called in most cases, if user is instance of WP_USER */ //function filter_user_id_CIPF($id) { // PLGNTLS_class::debug_infos(); @@ -83,7 +35,8 @@ add_shortcode('cipf_change_meta_id', 'shortcode_choose_meta_id_CIPF'); // error_log("-in add_filter_for_user_id_CIPF"); // this is output // add_filter('determine_current_user', 'filter_user_id_CIPF', 10, 1); //} -//add_action('wp', 'add_filter_for_user_id_CIPF'); +//add_shortcode('cipf_change_meta_id', 'add_filter_for_user_id_CIPF'); +////add_action('wp', 'add_filter_for_user_id_CIPF'); @@ -114,11 +67,11 @@ add_shortcode('cipf_change_meta_id', 'shortcode_choose_meta_id_CIPF'); // // $object_id = 117; // -///* -//* I just copied the code of wordpress : -//* i'm not sure there is a better way -//* -//*/ +// /* +// * I just copied the code of wordpress : +// * i'm not sure there is a better way +// * +// */ // $meta_cache = wp_cache_get( $object_id, $meta_type . '_meta' ); // // if ( ! $meta_cache ) { @@ -141,9 +94,9 @@ add_shortcode('cipf_change_meta_id', 'shortcode_choose_meta_id_CIPF'); // return array_map( 'maybe_unserialize', $meta_cache[ $meta_key ] ); // } // } -///* -//* FIN copy -//*/ +// /* +// * FIN copy +// */ //} //function add_filter_for_user_id_CIPF($wp) { // PLGNTLS_class::debug_infos(); diff --git a/plugins/cipf_plugin/php/paypal/user_can_pay.php b/plugins/cipf_plugin/php/paypal/user_can_pay.php index 081dd12..7e2e2bb 100644 --- a/plugins/cipf_plugin/php/paypal/user_can_pay.php +++ b/plugins/cipf_plugin/php/paypal/user_can_pay.php @@ -44,9 +44,81 @@ function check_can_pay_CIPF() { * in case it was changed from admin pannel * */ - $tarif = (int)get_field($acf_card_price_choice['_name'], $acf_id); - $livraison = (int)get_field($acf_card_price_delivery['_name'], $acf_id); - $price = $tarif + $livraison; + $tarif_object = get_field_object($acf_card_price_choice['_name'], $acf_id); + error_log("tarif_object"); + error_log(json_encode($tarif_object)); + /* +{ + "ID":34541, + "key":"field_65d24447cc89f", + "label":"Tarif", + "name":"tarif", + "aria-label":"", + "prefix":"acf", + "type":"radio", + "value":"Je suis hors r\u00e9seau FIPF et je souhaite commander la carte \u00e0 15 \u20ac", + "menu_order":3, + "instructions":"", + "required":0, + "id":"", + "class":"", + "conditional_logic":0, + "parent":34538, + "wrapper":{ + "width":"", + "class":"", + "id":"" + }, + "choices":{ + "10":"Mon association adh\u00e8re \u00e0 la FIPF, je peux commander la carte \u00e0 10 \u20ac", + "15":"Je suis hors r\u00e9seau FIPF et je souhaite commander la carte \u00e0 15 \u20ac" + }, + "default_value":"", + "return_format":"label", + "allow_null":0, + "other_choice":0, + "layout":"vertical", + "save_other_choice":0, + "_name":"tarif", + "_valid":1 +} +{ + "ID":34541, + "key":"field_65d24447cc89f", + "label":"Tarif", + "name":"tarif", + "aria-label":"", + "prefix":"acf", + "type":"radio", + "value":"15", + "menu_order":3, + "instructions":"", + "required":0,"id":"", + "class":"", + "conditional_logic":0, + "parent":34538, + "wrapper":{"width":"","class":"","id":""}, + "choices":{ + "10":"Mon association adh\u00e8re \u00e0 la FIPF, je peux commander la carte \u00e0 10 \u20ac", + "15":"Je suis hors r\u00e9seau FIPF et je souhaite commander la carte \u00e0 15 \u20ac" + }, + "default_value":"", + "return_format":"value", + "allow_null":0, + "other_choice":0, + "layout":"vertical", + "save_other_choice":0, + "_name":"tarif", + "_valid":1 +} + */ +// $tarif_value = ; +// $tarif = (int)$tarif_value; + $livraison_object = get_field_object($acf_card_price_delivery['_name'], $acf_id); +// $livraison_value = ; +// $livraison = (int)$livraison_value; +// $price = $tarif + $livraison; + $price = 3; update_field($acf_card_price_total['_name'], $price, $acf_id); /* diff --git a/plugins/cipf_plugin/php/redirections.php b/plugins/cipf_plugin/php/redirections.php index 25f99e1..1afb3db 100644 --- a/plugins/cipf_plugin/php/redirections.php +++ b/plugins/cipf_plugin/php/redirections.php @@ -69,16 +69,16 @@ function redirection_profil_CIPF(){ * redirects when on the page with slug defined in SLUG_PAGE_REDIRECTION * */ -//function redirection_page_CIPF(){ -// PLGNTLS_class::debug_infos(); -// $slug_page_redirection = PLGNTLS_class::SLUG_PAGE_REDIRECTION; -// -// if (!is_page($slug_page_redirection)) -// return; -// -// redirection_profil_CIPF(); -//} -//add_action('template_redirect', 'redirection_page_CIPF'); +function redirection_page_CIPF(){ + PLGNTLS_class::debug_infos(); + $slug_page_redirection = PLGNTLS_class::SLUG_PAGE_REDIRECTION; + + if (!is_page($slug_page_redirection)) + return; + + redirection_profil_CIPF(); +} +add_action('template_redirect', 'redirection_page_CIPF'); @@ -90,35 +90,35 @@ function redirection_profil_CIPF(){ * works even if the page actually does not exists * */ -function redirection_query_CIPF() { - PLGNTLS_class::debug_infos(); - $slug_page_redirection = PLGNTLS_class::SLUG_PAGE_REDIRECTION; - - - if (!isset($_GET['q'])) - return; - - /* - * check the request /path/ - * for url : https://url.com/path/to/file/?query=value - * -> $_GET: {"q":"/path/to/file/","query":"value"} - * - */ - $get_path = trim($_GET['q'], '/'); - if ($get_path !== $slug_page_redirection) - return; - - /* - * check the request ?query - * - if(!isset($_GET['query'])) - return; - */ - - redirection_profil_CIPF(); -} -add_action('template_redirect', 'redirection_query_CIPF'); -//add_action('init', 'redirection_query_CIPF'); +//function redirection_query_CIPF() { +// PLGNTLS_class::debug_infos(); +// $slug_page_redirection = PLGNTLS_class::SLUG_PAGE_REDIRECTION; +// +// +// if (!isset($_GET['q'])) +// return; +// +// /* +// * check the request /path/ +// * for url : https://url.com/path/to/file/?query=value +// * -> $_GET: {"q":"/path/to/file/","query":"value"} +// * +// */ +// $get_path = trim($_GET['q'], '/'); +// if ($get_path !== $slug_page_redirection) +// return; +// +// /* +// * check the request ?query +// * +// if(!isset($_GET['query'])) +// return; +// */ +// +// redirection_profil_CIPF(); +//} +//add_action('template_redirect', 'redirection_query_CIPF'); +////add_action('init', 'redirection_query_CIPF'); diff --git a/plugins/cipf_plugin/utils/plgntls_class.php b/plugins/cipf_plugin/utils/plgntls_class.php index e5b551d..e9bfe3a 100644 --- a/plugins/cipf_plugin/utils/plgntls_class.php +++ b/plugins/cipf_plugin/utils/plgntls_class.php @@ -54,8 +54,7 @@ if (!defined('ABSPATH')) { * */ -class PLGNTLS_class -{ +class PLGNTLS_class { /* * const declarations * @@ -117,7 +116,6 @@ class PLGNTLS_class private static $_file_name; private static $_root_path; private static $_root_url; - private static $_backup_current_user = null; private $_first_script; private $_first_style; @@ -192,26 +190,6 @@ class PLGNTLS_class - /* - * setter and getter for current user backup - * - */ - public static function set_current_user_backup() { - if (self::$_backup_current_user !== null) - return; - self::$_backup_current_user = get_current_user_id(); - } - public static function get_current_user_backup() { - return self::$_backup_current_user; - } - public static function reset_current_user_backup() { - $backup_user = self::$_backup_current_user; - self::$_backup_current_user = null; - return $backup_user; - } - - - /* * for debug purposes diff --git a/plugins/custer/author_id.php b/plugins/custer/author_id.php new file mode 100644 index 0000000..c1d8a39 --- /dev/null +++ b/plugins/custer/author_id.php @@ -0,0 +1,42 @@ +post_author; +// } + else { + $user_id = 0; + } + + return $user_id; +} + + + + + +?> diff --git a/plugins/custer/change_id.php b/plugins/custer/change_id.php new file mode 100644 index 0000000..e6b4a67 --- /dev/null +++ b/plugins/custer/change_id.php @@ -0,0 +1,58 @@ + there is no sens in forcing the logged_in, because it's already the default +* +* [custer_change_id] -> default (author) +* [custer_change_id author] -> author +* [custer_change_id off] -> reset to logged_in +* +*/ +function shortcode_change_id($options) { + /* + * set the default value for option + * currently it can only be author + * + */ + $option = 'author'; + if (is_array($options)) { + $option = reset($options); + } + + if (!is_string($option)) { + return; + } + + + if ($option === 'author') { + $id = get_author_id(); + Custer::set_current_user_backup(); + wp_set_current_user($id); + } + else if ($option === 'off') { + $id = Custer::reset_current_user_backup(); + wp_set_current_user($id); + } + else + return; +} +add_shortcode('custer_change_id', __NAMESPACE__.'\shortcode_change_id'); + + + + +?> diff --git a/plugins/custer/custer.php b/plugins/custer/custer.php new file mode 100644 index 0000000..ce8db9b --- /dev/null +++ b/plugins/custer/custer.php @@ -0,0 +1,31 @@ + diff --git a/plugins/custer/custer_class.php b/plugins/custer/custer_class.php new file mode 100644 index 0000000..eb77032 --- /dev/null +++ b/plugins/custer/custer_class.php @@ -0,0 +1,48 @@ + diff --git a/plugins/custer/filter_mail.php b/plugins/custer/filter_mail.php new file mode 100644 index 0000000..e9ef21b --- /dev/null +++ b/plugins/custer/filter_mail.php @@ -0,0 +1,90 @@ +$$ + * + */ + if (empty($result)) + return $matches[0]; + + return $result; +} + + + + + +/* +* filter emails at the final point : the wp_mail hook +* it uses a callback that rely on the logged-in user +* it will works well most of the time, but it's possible +* that a user logged out before the email is sent +* or event that a different user has already logged in +*/ +function filter_email_wp($args) { + // pattern : anything surrounded by '$$', ex : $$value$$ + $pattern = '/\$\$(.*?)\$\$/'; + + $old_body = $args['message']; + $new_body = preg_replace_callback($pattern, __NAMESPACE__.'\replace_words', $old_body); + $args['message'] = $new_body; + + return $args; +} +add_filter('wp_mail', __NAMESPACE__.'\filter_email_wp', 10, 1); + + + + +?> diff --git a/plugins/custer/format_user_infos.php b/plugins/custer/format_user_infos.php new file mode 100644 index 0000000..02ff4fb --- /dev/null +++ b/plugins/custer/format_user_infos.php @@ -0,0 +1,87 @@ +$query; + + + + /* + * try to extract a string + * + */ + while (is_array($output) && count($output) === 1) + $output = reset($output); + + + + /* + * if is not acf + * check if is a date + * and format it + * to create a DateTime from a time stamp : https://stackoverflow.com/a/12039058/9497573 + * + */ + if (!$is_acf) { + $timestamp = false; + if (is_string($output)) { + $timestamp = strtotime($output); + } + if ($timestamp !== false) { + $date = new DateTime('@' . $timestamp); + $output = $date->format($output_date_format); + } + } + + + + /* + * return the result + * + */ + if (is_array($output) && count($output) === 0) + $output = ''; + if (!is_string($output)) + $output = json_encode($output, JSON_UNESCAPED_SLASHES); + return esc_html($output); +} + + + + + +?> diff --git a/plugins/custer/user_infos.php b/plugins/custer/user_infos.php new file mode 100644 index 0000000..d3d1ad4 --- /dev/null +++ b/plugins/custer/user_infos.php @@ -0,0 +1,182 @@ + $value2) { + $value = extract_if_array_size_one($value2); + // if key was not in first array, add the new element to it + if (!isset($new_array[$key2])) { + $new_array[$key2] = $value2; + continue; + } + // if key was in first array, add both in an array + $value1 = extract_if_array_size_one($new_array[$key2]); + if (empty($value1)) + $new_array[$key2] = $value2; + else if (empty($value2)) + $new_array[$key2] = $value1; + else { + $new_value = array($value1, $value2); + $new_array[$key] = $new_value; + } + } + return $new_array; +} + + +function output_list_front($array, $current_user, $user_id) { + $output = '