Compare commits
71 Commits
image_edit
...
debug_rout
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d0bfe90715 | ||
|
|
e14acfb739 | ||
|
|
76f2e8ba00 | ||
|
|
ecc072e25b | ||
|
|
2f4a5bb9ef | ||
|
|
12de8ee12f | ||
|
|
10ca070d81 | ||
|
|
f6e092f67d | ||
|
|
38f9b0ba72 | ||
|
|
591add448f | ||
|
|
046b31579c | ||
|
|
4f4bfd1c88 | ||
|
|
c1944dbc39 | ||
|
|
1021d9bf71 | ||
|
|
9ee35b23bc | ||
|
|
b457ed119e | ||
|
|
faefa98114 | ||
|
|
f3a9be5a89 | ||
|
|
fc3a205359 | ||
|
|
789a361871 | ||
|
|
022468c096 | ||
|
|
909a34cd37 | ||
|
|
9b5e44dfd3 | ||
|
|
be79310404 | ||
|
|
f870f77a2c | ||
|
|
5e28bf3059 | ||
|
|
afd34e5296 | ||
|
|
4916defcaa | ||
|
|
31c3ed55f4 | ||
|
|
d65af4cd43 | ||
|
|
b244b59deb | ||
|
|
60f46265c2 | ||
|
|
b8fbd84d53 | ||
|
|
2fb1ec35aa | ||
|
|
1661f16aff | ||
|
|
917d51a097 | ||
|
|
620aa9329b | ||
|
|
39c9f492dc | ||
|
|
63cc1f28c0 | ||
|
|
44e122d415 | ||
|
|
cf9a020162 | ||
|
|
483c02a4c6 | ||
|
|
cae80d7d24 | ||
|
|
8862bab1bd | ||
|
|
7738ad1863 | ||
|
|
8aeef1dca8 | ||
|
|
bd30c97194 | ||
|
|
6e88bba879 | ||
|
|
2ce603e644 | ||
|
|
7a8c0750c5 | ||
|
|
81f3f8a7e7 | ||
|
|
0177531924 | ||
|
|
5794e4cafe | ||
|
|
b839bf7f66 | ||
|
|
ec18dc60b4 | ||
|
|
4e094889c7 | ||
|
|
3d9b9bac9e | ||
|
|
01187a8450 | ||
|
|
1464562379 | ||
|
|
61b3f9f2f5 | ||
|
|
745f5ebf91 | ||
|
|
38260912cd | ||
|
|
0f15b67e8b | ||
|
|
bebb346ff9 | ||
|
|
b7685cbbc1 | ||
|
|
7cfa2e6351 | ||
|
|
fea195638b | ||
|
|
45532c497d | ||
|
|
1046390f59 | ||
|
|
1262aeb706 | ||
|
|
6158f738a2 |
@@ -1,4 +1,4 @@
|
|||||||
# fipf 2024
|
# cipf 2024
|
||||||
|
|
||||||
- this project uses submodules recursively, so after cloning you need to do :
|
- this project uses submodules recursively, so after cloning you need to do :
|
||||||
`git submodule update --init --recursive`
|
`git submodule update --init --recursive`
|
||||||
|
|||||||
6
plugins/cipf_plugin/css/menu/menu.css
Normal file
6
plugins/cipf_plugin/css/menu/menu.css
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#mytext {
|
||||||
|
border: 1px solid blue;
|
||||||
|
}
|
||||||
|
#mytext_2 {
|
||||||
|
border: 1px solid green;
|
||||||
|
}
|
||||||
65
plugins/cipf_plugin/fipfcard_plugin.php
Normal file
65
plugins/cipf_plugin/fipfcard_plugin.php
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
Plugin Name: cipf_plugin
|
||||||
|
Plugin URI:
|
||||||
|
Description:
|
||||||
|
Author: hugogogo
|
||||||
|
Version: 1.1.0
|
||||||
|
Author URI:
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* it means someone outside wp is accessing the file, in this case kill it.
|
||||||
|
*/
|
||||||
|
if (!defined('ABSPATH')) {
|
||||||
|
die('You can not access this file!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* plugin dir root
|
||||||
|
PLGNTLS_class::set_root_dir( plugin_dir_path(__FILE__), plugin_dir_url(__FILE__) );
|
||||||
|
*/
|
||||||
|
include_once( plugin_dir_path(__FILE__) . '/utils/plgntls_class.php');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* general inclusions
|
||||||
|
*/
|
||||||
|
// utils :
|
||||||
|
include_once(PLGNTLS_class::root_path() . 'php/utils/globals.php');
|
||||||
|
include_once(PLGNTLS_class::root_path() . 'utils/console_log.php');
|
||||||
|
|
||||||
|
include_once(PLGNTLS_class::root_path() . 'php/admin_menu/example_menu.php');
|
||||||
|
|
||||||
|
include_once(PLGNTLS_class::root_path() . 'php/paypal/paypal.php');
|
||||||
|
|
||||||
|
include_once(PLGNTLS_class::root_path() . '/php/user_infos.php');
|
||||||
|
//include_once(PLGNTLS_class::root_path() . '/php/hide_admin.php');
|
||||||
|
//include_once(PLGNTLS_class::root_path() . '/php/menus.php');
|
||||||
|
include_once(PLGNTLS_class::root_path() . 'php/register_partenaires.php');
|
||||||
|
include_once(PLGNTLS_class::root_path() . 'php/redirections.php');
|
||||||
|
include_once(PLGNTLS_class::root_path() . 'php/author_restriction.php');
|
||||||
|
include_once(PLGNTLS_class::root_path() . 'php/filter_mail.php');
|
||||||
|
include_once(PLGNTLS_class::root_path() . 'php/prof_check_page.php');
|
||||||
|
include_once(PLGNTLS_class::root_path() . 'php/renew_card.php');
|
||||||
|
//include_once(PLGNTLS_class::root_path() . 'php/reset_card_form.php');
|
||||||
|
include_once(PLGNTLS_class::root_path() . 'php/partner_check_page.php');
|
||||||
|
include_once(PLGNTLS_class::root_path() . 'php/format_user_infos.php');
|
||||||
|
include_once(PLGNTLS_class::root_path() . 'php/admin_modif_prof.php');
|
||||||
|
|
||||||
|
|
||||||
|
// form builder patch :
|
||||||
|
/*
|
||||||
|
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');
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
5
plugins/cipf_plugin/html/menu/example_menu.html
Normal file
5
plugins/cipf_plugin/html/menu/example_menu.html
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<input type='text' id='mytext'>
|
||||||
|
<button id='mybutton'>send</button>
|
||||||
|
|
||||||
|
<input type='text' id='mytext_2'>
|
||||||
|
<button id='mybutton_2'>send</button>
|
||||||
2
plugins/cipf_plugin/html/paypal/paypal.html
Normal file
2
plugins/cipf_plugin/html/paypal/paypal.html
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
<div id="paypal-button-container"></div>
|
||||||
|
<p id="result-message"></p>
|
||||||
24
plugins/cipf_plugin/js/admin_prevent_submit.js
Normal file
24
plugins/cipf_plugin/js/admin_prevent_submit.js
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
cipf_admin_activate_prof_form
|
||||||
|
*/
|
||||||
|
|
||||||
|
function admin_activate_form_submit_prevent_CIPF() {
|
||||||
|
let form_activate_prof = document.querySelector('#cipf_admin_activate_prof_form form');
|
||||||
|
console.log("form:");
|
||||||
|
console.log(form_activate_prof);
|
||||||
|
if (form_activate_prof === null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
function handle_form(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
let form_data = new FormData(event.target);
|
||||||
|
for (var pair of form_data.entries()) {
|
||||||
|
console.log(pair[0]+ ': ' + pair[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
form_activate_prof.addEventListener('submit', handle_form);
|
||||||
|
}
|
||||||
|
admin_activate_form_submit_prevent_CIPF();
|
||||||
|
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
|
||||||
|
function patch_form_calculation_CIPF() {
|
||||||
|
let form_calculation = document.querySelector('form.fb_form.multistep');
|
||||||
|
if (form_calculation === null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* finds the input:checked in the element .calculate_field
|
||||||
|
* and trigger the event 'change' on it
|
||||||
|
* - this event 'change' is added by form builder in divi-form-calc-min.js :
|
||||||
|
* $(document).on(
|
||||||
|
* 'change',
|
||||||
|
* '.calculate_field input:not([type="hidden"]), .calculate_field select',
|
||||||
|
* function () {
|
||||||
|
* ...
|
||||||
|
* }
|
||||||
|
* );
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function trigger_change(element) {
|
||||||
|
/*
|
||||||
|
* jquery version
|
||||||
|
*
|
||||||
|
let inputs = $(element).find('input:checked');
|
||||||
|
inputs.trigger('change');
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* js version
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
let inputs = element.querySelectorAll('input:checked');
|
||||||
|
// loop through inputs and trigger 'change' event on each
|
||||||
|
inputs.forEach(function(input) {
|
||||||
|
// Triggering 'change' event
|
||||||
|
let change_event = new Event('change', {
|
||||||
|
bubbles: true,
|
||||||
|
cancelable: true,
|
||||||
|
});
|
||||||
|
input.dispatchEvent(change_event);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// create an observer on form to check if child nodes are modified
|
||||||
|
const observer_form = new MutationObserver(wait_for_calculation_class);
|
||||||
|
observer_form.observe(form_calculation, {
|
||||||
|
subtree: true,
|
||||||
|
attributes: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
// observe mutations to see if they include the addition of class .calculate_field
|
||||||
|
// if the class is added, call the function that might trigger the change event on it
|
||||||
|
function wait_for_calculation_class(mutationsList) {
|
||||||
|
mutationsList.forEach((mutation) => {
|
||||||
|
// check if class where added
|
||||||
|
if (mutation.type !== 'attributes')
|
||||||
|
return;
|
||||||
|
if (mutation.attributeName !== 'class')
|
||||||
|
return;
|
||||||
|
// check if added class is .calculate_field
|
||||||
|
let target = mutation.target;
|
||||||
|
if (target.classList.contains('calculate_field')) {
|
||||||
|
// If the class is added, trigger the 'change' event
|
||||||
|
trigger_change(target);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
patch_form_calculation_CIPF();
|
||||||
|
|
||||||
30
plugins/cipf_plugin/js/form_builder_patch/multiple_modals.js
Normal file
30
plugins/cipf_plugin/js/form_builder_patch/multiple_modals.js
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
|
||||||
|
let modal_wrapper_CIPF = document.querySelector('#de-fb-modal-wrapper-');
|
||||||
|
|
||||||
|
// create an observer on first #de-fb-modal-wrapper- to check if child nodes are added
|
||||||
|
const observer_CIPF = new MutationObserver(wait_for_close_button_CIPF);
|
||||||
|
observer_CIPF.observe(modal_wrapper_CIPF, {
|
||||||
|
subtree: true,
|
||||||
|
childList: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
// observe mutations to see if they include the creation of the button .modal-close
|
||||||
|
// if the button is created, add an eventListener to it
|
||||||
|
function wait_for_close_button_CIPF(mutationsList) {
|
||||||
|
mutationsList.forEach((mutation) => {
|
||||||
|
// check if nodes were added
|
||||||
|
if (mutation.type !== 'childList')
|
||||||
|
return;
|
||||||
|
// check if added nodes includes the button .modal-close
|
||||||
|
let modal_close = document.querySelector('#de-fb-modal-wrapper- .modal-close');
|
||||||
|
if (modal_close !== null) {
|
||||||
|
modal_close.addEventListener("click", delete_modal_CIPF);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// when triggered, the .modal-close button will remove all childs from #de-fb-modal-wrapper-
|
||||||
|
function delete_modal_CIPF() {
|
||||||
|
modal_wrapper_CIPF.innerHTML = '';
|
||||||
|
}
|
||||||
|
|
||||||
4
plugins/cipf_plugin/js/menu/example_menu.js
Normal file
4
plugins/cipf_plugin/js/menu/example_menu.js
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
import { test_fetch } from './example_submenu.js';
|
||||||
|
|
||||||
|
test_fetch();
|
||||||
29
plugins/cipf_plugin/js/menu/example_menu_2.js
Normal file
29
plugins/cipf_plugin/js/menu/example_menu_2.js
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
|
||||||
|
const inputElement2 = document.getElementById('mytext_2');
|
||||||
|
const sendButton2 = document.getElementById('mybutton_2');
|
||||||
|
|
||||||
|
sendButton2.addEventListener('click', () => {
|
||||||
|
let inputValue = inputElement2.value;
|
||||||
|
inputValue = {
|
||||||
|
key1: 'value1',
|
||||||
|
key2: 'value2'
|
||||||
|
};
|
||||||
|
inputValue = JSON.stringify(inputValue);
|
||||||
|
console.log("inputValue:");
|
||||||
|
console.log(inputValue);
|
||||||
|
PLGNTLS_fetch('/plgntls/get_data', {
|
||||||
|
method: "POST",
|
||||||
|
})
|
||||||
|
//PLGNTLS_fetch('get_data', {body: {inputValue}})
|
||||||
|
.then((response) => response.json())
|
||||||
|
.then((data) => {
|
||||||
|
console.log("dataaa: ");
|
||||||
|
console.log(data);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.log("error: ");
|
||||||
|
console.log(error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
33
plugins/cipf_plugin/js/menu/example_submenu.js
Normal file
33
plugins/cipf_plugin/js/menu/example_submenu.js
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
|
||||||
|
import { PLGNTLS_fetch } from '../../utils/plgntls_fetch.js';
|
||||||
|
|
||||||
|
export function test_fetch() {
|
||||||
|
const inputElement = document.getElementById('mytext');
|
||||||
|
const sendButton = document.getElementById('mybutton');
|
||||||
|
|
||||||
|
sendButton.addEventListener('click', () => {
|
||||||
|
let inputValue = inputElement.value;
|
||||||
|
inputValue = {
|
||||||
|
key1: 'value1',
|
||||||
|
key2: 'value2'
|
||||||
|
};
|
||||||
|
inputValue = JSON.stringify(inputValue);
|
||||||
|
console.log("inputValue:");
|
||||||
|
console.log(inputValue);
|
||||||
|
PLGNTLS_fetch('/plgntls/get_data', {
|
||||||
|
method: "POST",
|
||||||
|
})
|
||||||
|
//PLGNTLS_fetch('get_data', {body: {inputValue}})
|
||||||
|
.then((response) => response.json())
|
||||||
|
.then((data) => {
|
||||||
|
console.log("dataaa: ");
|
||||||
|
console.log(data);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.log("error: ");
|
||||||
|
console.log(error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
62
plugins/cipf_plugin/js/paypal/create_order.js
Normal file
62
plugins/cipf_plugin/js/paypal/create_order.js
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
import { resultMessage } from './result_message.js';
|
||||||
|
import { PLGNTLS_fetch } from '../../utils/plgntls_fetch.js';
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see https://developer.paypal.com/docs/checkout/standard/integrate/#link-integratebackend
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
export async function createOrder() {
|
||||||
|
try {
|
||||||
|
const response = await PLGNTLS_fetch('/cipf_plugin/api/v1/orders', {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const orderData = await response.json();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* is it necessary since the error is catched according to the presence of id ?
|
||||||
|
* -> i think yes, because we want to know the type of http error, right ?
|
||||||
|
* -> actually the http error code will be shown in the console anyway, so...
|
||||||
|
*
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error('Network response was not ok : ' + orderData.data.status + ' message : ' + orderData.message);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (orderData.id) {
|
||||||
|
return orderData.id;
|
||||||
|
}
|
||||||
|
else { // throw an error
|
||||||
|
const errorDetail = orderData?.details?.[0];
|
||||||
|
const errorMessage = errorDetail
|
||||||
|
? `${errorDetail.issue} ${errorDetail.description} (${orderData.debug_id})`
|
||||||
|
: JSON.stringify(orderData);
|
||||||
|
throw new Error(errorMessage);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
resultMessage(`Could not initiate PayPal Checkout...<br><br>${error}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see https://developer.paypal.com/demo/checkout/#/pattern/server
|
||||||
|
*
|
||||||
|
// Call your server to set up the transaction
|
||||||
|
function createOrder(data, actions) {
|
||||||
|
const fetch_create_url = PLGNTLS_data.fetch_url + "/cipf_plugin/api/v1/orders";
|
||||||
|
console.log("fetch_create_url:", fetch_create_url);
|
||||||
|
return fetch(fetch_create_url, {
|
||||||
|
method: 'post'
|
||||||
|
}).then(function(res) {
|
||||||
|
return res.json();
|
||||||
|
}).then(function(orderData) {
|
||||||
|
return orderData.id;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
*/
|
||||||
|
|
||||||
58
plugins/cipf_plugin/js/paypal/on_approve.js
Normal file
58
plugins/cipf_plugin/js/paypal/on_approve.js
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
|
||||||
|
import { resultMessage } from './result_message.js';
|
||||||
|
import { PLGNTLS_fetch } from '../../utils/plgntls_fetch.js';
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see https://developer.paypal.com/docs/checkout/standard/integrate/#link-integratebackend
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
export async function onApprove(data, actions) {
|
||||||
|
try {
|
||||||
|
const fetch_approve_url = PLGNTLS_data.fetch_url + "/cipf_plugin/api/v1/orders/" + data.orderID + "/capture";
|
||||||
|
const response = await PLGNTLS_fetch('/cipf_plugin/api/v1/orders/' + data.orderID + '/capture', {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const orderData = await response.json();
|
||||||
|
|
||||||
|
// Three cases to handle:
|
||||||
|
// (1) Recoverable INSTRUMENT_DECLINED -> call actions.restart()
|
||||||
|
// (2) Other non-recoverable errors -> Show a failure message
|
||||||
|
// (3) Successful transaction -> Show confirmation or thank you message
|
||||||
|
|
||||||
|
const errorDetail = orderData?.details?.[0];
|
||||||
|
|
||||||
|
if (errorDetail?.issue === "INSTRUMENT_DECLINED") {
|
||||||
|
// (1) Recoverable INSTRUMENT_DECLINED -> call actions.restart()
|
||||||
|
// recoverable state, per https://developer.paypal.com/docs/checkout/standard/customize/handle-funding-failures/
|
||||||
|
return actions.restart();
|
||||||
|
}
|
||||||
|
else if (errorDetail) {
|
||||||
|
// (2) Other non-recoverable errors -> Show a failure message
|
||||||
|
throw new Error(`${errorDetail.description} (${orderData.debug_id})`);
|
||||||
|
}
|
||||||
|
else if (!orderData.purchase_units) {
|
||||||
|
throw new Error(JSON.stringify(orderData));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// (3) Successful transaction -> Show confirmation or thank you message
|
||||||
|
// Or go to another URL: actions.redirect('thank_you.html');
|
||||||
|
const transaction =
|
||||||
|
orderData?.purchase_units?.[0]?.payments?.captures?.[0] ||
|
||||||
|
orderData?.purchase_units?.[0]?.payments?.authorizations?.[0];
|
||||||
|
// to show a message on page
|
||||||
|
//resultMessage(`Transaction ${transaction.status}: ${transaction.id}<br><br>See console for all available details`);
|
||||||
|
resultMessage(eval(PLGNTLS_data.paypal_message_success));
|
||||||
|
actions.redirect(PLGNTLS_data.paypal_redirection_success);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
//resultMessage(`Sorry, your transaction could not be processed...<br><br>${error}`);
|
||||||
|
resultMessage(eval(PLGNTLS_data.paypal_message_failure));
|
||||||
|
actions.redirect(PLGNTLS_data.paypal_redirection_failure);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
56
plugins/cipf_plugin/js/paypal/paypal.js
Normal file
56
plugins/cipf_plugin/js/paypal/paypal.js
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
import { createOrder } from './create_order.js';
|
||||||
|
import { onApprove } from './on_approve.js';
|
||||||
|
|
||||||
|
|
||||||
|
window.paypal.Buttons({
|
||||||
|
/*
|
||||||
|
style: {
|
||||||
|
layout: 'vertical',
|
||||||
|
color: 'blue',
|
||||||
|
shape: 'rect',
|
||||||
|
label: 'paypal',
|
||||||
|
},
|
||||||
|
*/
|
||||||
|
createOrder: createOrder,
|
||||||
|
onApprove: onApprove,
|
||||||
|
})
|
||||||
|
.render("#paypal-button-container");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* customize card fields
|
||||||
|
* from : https://developer.paypal.com/docs/checkout/advanced/integrate#link-addpaypalbuttonsandcardfields
|
||||||
|
*
|
||||||
|
// Create the Card Fields Component and define callbacks
|
||||||
|
const cardField = paypal.CardFields({
|
||||||
|
createOrder: createOrder,
|
||||||
|
onApprove: onApprove,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Render each field after checking for eligibility
|
||||||
|
if (cardField.isEligible()) {
|
||||||
|
const nameField = cardField.NameField();
|
||||||
|
nameField.render("#card-name-field-container");
|
||||||
|
|
||||||
|
const numberField = cardField.NumberField();
|
||||||
|
numberField.render("#card-number-field-container");
|
||||||
|
|
||||||
|
const cvvField = cardField.CVVField();
|
||||||
|
cvvField.render("#card-cvv-field-container");
|
||||||
|
|
||||||
|
const expiryField = cardField.ExpiryField();
|
||||||
|
expiryField.render("#card-expiry-field-container");
|
||||||
|
|
||||||
|
// Add click listener to submit button and call the submit function on the CardField component
|
||||||
|
document
|
||||||
|
.getElementById("card-field-submit-button")
|
||||||
|
.addEventListener("click", () => {
|
||||||
|
cardField.submit().then(() => {
|
||||||
|
// submit successful
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
13
plugins/cipf_plugin/js/paypal/plgntls_fetch.js
Normal file
13
plugins/cipf_plugin/js/paypal/plgntls_fetch.js
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
|
||||||
|
//function PLGNTLS_fetch(url, options = {}) {
|
||||||
|
export function PLGNTLS_fetch(url, options = {}) {
|
||||||
|
console.log("inside PLGNTLS_fetch");
|
||||||
|
url = PLGNTLS_data.fetch_url + url;
|
||||||
|
|
||||||
|
options.headers = options.headers || {};
|
||||||
|
options.headers['X-WP-Nonce'] = PLGNTLS_data.fetch_nonce,
|
||||||
|
console.log("options:", options);
|
||||||
|
|
||||||
|
return fetch(url, options);
|
||||||
|
}
|
||||||
|
|
||||||
9
plugins/cipf_plugin/js/paypal/result_message.js
Normal file
9
plugins/cipf_plugin/js/paypal/result_message.js
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
|
||||||
|
// Example function to show a result to the user. Your site's UI library can be used instead.
|
||||||
|
//function resultMessage(message) {
|
||||||
|
export function resultMessage(message) {
|
||||||
|
const buttons = document.querySelector("#paypal-button-container");
|
||||||
|
const container = document.querySelector("#result-message");
|
||||||
|
buttons.style.display = 'none';
|
||||||
|
container.innerHTML = message;
|
||||||
|
}
|
||||||
77
plugins/cipf_plugin/php/admin_menu/example_menu.php
Normal file
77
plugins/cipf_plugin/php/admin_menu/example_menu.php
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* it means someone outside wp is accessing the file, in this case kill it.
|
||||||
|
*/
|
||||||
|
if (!defined('ABSPATH')) {
|
||||||
|
die('You can not access this file!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* menu plugin
|
||||||
|
*/
|
||||||
|
function cipfcard_plugin_menu() {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
add_menu_page
|
||||||
|
(
|
||||||
|
'cipf_card', // webpage title
|
||||||
|
'cipf_card', // menu title
|
||||||
|
'manage_options', // capability
|
||||||
|
'cipfcard-plugin', // menu_slug
|
||||||
|
'cipfcard_plugin_content' // callback function to display page content
|
||||||
|
);
|
||||||
|
}
|
||||||
|
add_action('admin_menu', 'cipfcard_plugin_menu');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function cipfcard_plugin_content() {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
$cipfcard = new PLGNTLS_class();
|
||||||
|
|
||||||
|
$my_css = '
|
||||||
|
#mytext {
|
||||||
|
background-color: lightblue;
|
||||||
|
}
|
||||||
|
#mytext_2 {
|
||||||
|
background-color: lightgreen;
|
||||||
|
}
|
||||||
|
';
|
||||||
|
echo $cipfcard->add_to_front( array(
|
||||||
|
array("js/menu/example_menu.js", 'type'=>'module'),
|
||||||
|
"css/menu/menu.css",
|
||||||
|
"PLGNTLS_menu_css" => array('css'=>$my_css),
|
||||||
|
"js/menu/example_menu_2.js",
|
||||||
|
"html/menu/example_menu.html",
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
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 cipfcard_menu_fetch_handler() {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
return new WP_REST_Response('hello', 200);
|
||||||
|
}
|
||||||
|
function cipfcard_menu_endpoint() {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
register_rest_route('plgntls', '/get_data', array(
|
||||||
|
'methods' => 'POST',
|
||||||
|
'callback' => 'cipfcard_menu_fetch_handler',
|
||||||
|
));
|
||||||
|
};
|
||||||
|
add_action('rest_api_init', 'cipfcard_menu_endpoint');
|
||||||
|
|
||||||
|
?>
|
||||||
207
plugins/cipf_plugin/php/admin_modif_prof.php
Normal file
207
plugins/cipf_plugin/php/admin_modif_prof.php
Normal file
@@ -0,0 +1,207 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* it means someone outside wp is accessing the file, in this case kill it.
|
||||||
|
*/
|
||||||
|
if (!defined('ABSPATH')) {
|
||||||
|
die('You can not access this file!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* custom action in php on custom form submission
|
||||||
|
* custom forms are not processed by divi form builder
|
||||||
|
* so they don't change between hooks before and after process
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function admin_validate_prof_CIPF() {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* calling the action to validate from the FormBuilder hook
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function custom_form_admin_validate_prof_CIPF($form_id, $post_array, $form_type) {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
$admin_validate_prof_field = PLGNTLS_class::ADMIN_VALIDATE_PROF_FIELD;
|
||||||
|
|
||||||
|
if ($form_type !== 'custom')
|
||||||
|
return;
|
||||||
|
error_log("---");
|
||||||
|
error_log("in test_form_CIPF");
|
||||||
|
// error_log("form_id");
|
||||||
|
// error_log(json_encode($form_id));
|
||||||
|
// error_log("post_array");
|
||||||
|
// error_log(json_encode($post_array));
|
||||||
|
// error_log("form_type");
|
||||||
|
// error_log(json_encode($form_type));
|
||||||
|
|
||||||
|
$field_id = $post_array['field_id'];
|
||||||
|
$contains_id = in_array($admin_validate_prof_field, $field_id);
|
||||||
|
if ($contains_id === false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
admin_validate_prof_CIPF();
|
||||||
|
}
|
||||||
|
add_action('df_before_process', 'custom_form_admin_validate_prof_CIPF', 10, 3);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* calling the action to validate from the
|
||||||
|
*
|
||||||
|
function custom_link_intercept() {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
$query_page_redirection = PLGNTLS_class::QUERY_REDIRECTION_PROFIL;
|
||||||
|
|
||||||
|
// Check if the request contains ?QUERY_REDIRECTION_PROFIL
|
||||||
|
if(isset($_GET[$query_page_redirection])) {
|
||||||
|
admin_validate_prof_CIPF();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
add_action('init', 'custom_link_intercept');
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
before :
|
||||||
|
|
||||||
|
|
||||||
|
in test_form_CIPF
|
||||||
|
form_id
|
||||||
|
""
|
||||||
|
post_array
|
||||||
|
{"field_title":["\u00c9tat du compte"],"field_name":["de_fb_compte-actif"],"field_id":["de_fb_field_1"],"form_type_confirm":""}
|
||||||
|
form_type
|
||||||
|
"custom"
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
after :
|
||||||
|
|
||||||
|
|
||||||
|
in test_form_CIPF
|
||||||
|
form_id
|
||||||
|
""
|
||||||
|
post_array
|
||||||
|
{"field_title":["\u00c9tat du compte"],"field_name":["de_fb_compte-actif"],"field_id":["de_fb_field_1"],"form_type_confirm":""}
|
||||||
|
form_type
|
||||||
|
"custom"
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
exploded view :
|
||||||
|
|
||||||
|
{
|
||||||
|
"field_title":["\u00c9tat du compte"],
|
||||||
|
"field_name":["de_fb_compte-actif"],
|
||||||
|
"field_id":["de_fb_field_1"],
|
||||||
|
"form_type_confirm":""
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
"field_title":["\u00c9tat du compte"],
|
||||||
|
"field_name":["de_fb_compte-actif"],
|
||||||
|
"field_id":["de_fb_field_1"],
|
||||||
|
"compte-actif":"Actif",
|
||||||
|
"form_type_confirm":""
|
||||||
|
}
|
||||||
|
CIPF_admin_activation_prof
|
||||||
|
{
|
||||||
|
"field_title":["\u00c9tat du compte"],
|
||||||
|
"field_name":["compte-actif"],
|
||||||
|
"field_id":["cipf_admin_activation_prof"],
|
||||||
|
"compte-actif":"Inactif",
|
||||||
|
"form_type_confirm":""
|
||||||
|
}
|
||||||
|
|
||||||
|
--- with field test :
|
||||||
|
|
||||||
|
{
|
||||||
|
"field_title":["\u00c9tat du compte","test"],
|
||||||
|
"field_name":["compte-actif","de_fb_field_3"],
|
||||||
|
"field_id":["cipf_admin_activation_prof","de_fb_field_3"],
|
||||||
|
"field_3":"",
|
||||||
|
"form_type_confirm":""
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ABORTED
|
||||||
|
* tried to receive the form in ajax from front with wp REST API
|
||||||
|
* but I cannot verify if the user is logged in
|
||||||
|
* so it does not work
|
||||||
|
*
|
||||||
|
function admin_validate_prof_form_CIPF($request) {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
$slug_page_redirection = PLGNTLS_class::SLUG_PAGE_REDIRECTION;
|
||||||
|
|
||||||
|
error_log("-----");
|
||||||
|
error_log("inside admin_validate_prof_form_CIPF");
|
||||||
|
error_log("request");
|
||||||
|
error_log(json_encode($request));
|
||||||
|
error_log("_POST");
|
||||||
|
error_log(json_encode($_POST));
|
||||||
|
// _POST : {"field_title":["\u00c9tat du compte"],"field_name":["compte-actif"],"field_id":["cipf_admin_activate_prof"],"form_key":"40781-1","unique_id":"91eed9aa-2b92-4da7-a0b4-e94f24515223","form_type":"custom","divi-form-submit":"yes","form_id":"","form_type_confirm":""}
|
||||||
|
|
||||||
|
// Set up nocache headers before redirecting : https://developer.wordpress.org/reference/functions/wp_safe_redirect/#user-contributed-notes
|
||||||
|
nocache_headers();
|
||||||
|
$redirect_url = home_url() . '/' . $slug_page_redirection;
|
||||||
|
wp_redirect($redirect_url, 301);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
function endpoint_form_admin_activate_prof_CIPF() {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
$base_rest_route = PLGNTLS_class::URL_BASE_REST_ROUTE;
|
||||||
|
|
||||||
|
register_rest_route($base_rest_route, '/admin_prof_activate_form', array(
|
||||||
|
'methods' => 'POST',
|
||||||
|
'callback' => 'admin_validate_prof_form_CIPF',
|
||||||
|
));
|
||||||
|
};
|
||||||
|
add_action('rest_api_init', 'endpoint_form_admin_activate_prof_CIPF');
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ABORTED
|
||||||
|
* enqueue script that should prevent the form to submit, but does not work
|
||||||
|
*
|
||||||
|
function admin_validate_prof_prevent_CIPF() {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
$handle = 'admin_prevent_submit';
|
||||||
|
$url = PLGNTLS_class::root_url() . 'js/admin_prevent_submit.js';
|
||||||
|
$dependencies = array();
|
||||||
|
$version = null;
|
||||||
|
$defer = true;
|
||||||
|
wp_enqueue_script($handle, $url, $dependencies, $version, $defer);
|
||||||
|
}
|
||||||
|
add_action('wp_enqueue_scripts', 'admin_validate_prof_prevent_CIPF');
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
54
plugins/cipf_plugin/php/author_restriction.php
Normal file
54
plugins/cipf_plugin/php/author_restriction.php
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* it means someone outside wp is accessing the file, in this case kill it.
|
||||||
|
*/
|
||||||
|
if (!defined('ABSPATH')) {
|
||||||
|
die('You can not access this file!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function restrict_author_page_CIPF() {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
$role_fipf = PLGNTLS_class::ROLE_FIPF;
|
||||||
|
$role_admin = PLGNTLS_class::ROLE_ADMIN;
|
||||||
|
|
||||||
|
if (!is_author())
|
||||||
|
return;
|
||||||
|
|
||||||
|
$current_user = wp_get_current_user();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* check multiple user roles
|
||||||
|
* https://developer.wordpress.org/reference/functions/current_user_can/#div-comment-4083
|
||||||
|
* if user->role is found in array of allowed role, no redirection needed
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$allowed_roles = array($role_admin, $role_fipf);
|
||||||
|
if (array_intersect($allowed_roles, $current_user->roles))
|
||||||
|
return;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* get_queried_object_id() would work too
|
||||||
|
* here get_the_author_meta works and is more explicit
|
||||||
|
*
|
||||||
|
$author_id = get_queried_object_id();
|
||||||
|
*/
|
||||||
|
$author_id = get_the_author_meta( 'ID' );
|
||||||
|
|
||||||
|
$current_user_id = get_current_user_id();
|
||||||
|
|
||||||
|
if ($current_user_id != $author_id) {
|
||||||
|
// Set up nocache headers before redirecting : https://developer.wordpress.org/reference/functions/wp_safe_redirect/#user-contributed-notes
|
||||||
|
nocache_headers();
|
||||||
|
wp_redirect(home_url(), 301);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
add_action('template_redirect', 'restrict_author_page_CIPF', 10);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
140
plugins/cipf_plugin/php/filter_mail.php
Normal file
140
plugins/cipf_plugin/php/filter_mail.php
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* it means someone outside wp is accessing the file, in this case kill it.
|
||||||
|
*/
|
||||||
|
if (!defined('ABSPATH')) {
|
||||||
|
die('You can not access this file!');
|
||||||
|
}
|
||||||
|
|
||||||
|
include_once(PLGNTLS_class::root_path() . 'php/format_user_infos.php');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* callback to provide the user info corresponding to the $$key_word$$
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function replace_words_CIPF($matches, $user_id = null) {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
if ($user_id !== null) {
|
||||||
|
$current_user = get_user_by('id', $user_id);
|
||||||
|
}
|
||||||
|
else if (is_user_logged_in()) {
|
||||||
|
$current_user = wp_get_current_user();
|
||||||
|
$user_id = get_current_user_id();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($current_user === false)
|
||||||
|
return "";
|
||||||
|
|
||||||
|
$query = $matches[1];
|
||||||
|
$result = format_user_info_CIPF($query, $current_user, $user_id);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* if result is array, take the first element (not ideal)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if (is_array($result))
|
||||||
|
$result = reset($result);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* if is special query __author_page__
|
||||||
|
* return author page url
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if ($query === '__author_page__') {
|
||||||
|
$current_user_id = get_current_user_id();
|
||||||
|
$result = get_author_posts_url($current_user_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* if no match, return $$<query>$$
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if (empty($result))
|
||||||
|
return $matches[0];
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* filter emails in the form-builder hook, before the wp_mail hook
|
||||||
|
* it receives the id of the user, no need to have the user still logged-in
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function filter_email_fb_CIPF($reply_body, $post_array) {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
$id = $post_array['ID'];
|
||||||
|
// pattern : anything surrounded by '$$', ex : $$value$$
|
||||||
|
$pattern = '/\$\$(.*?)\$\$/';
|
||||||
|
|
||||||
|
// inline callback, with 'use' to get the id
|
||||||
|
$new_body = preg_replace_callback($pattern, function($matches) use ($id) {
|
||||||
|
return replace_words_CIPF($matches, $id);
|
||||||
|
}, $reply_body);
|
||||||
|
|
||||||
|
return $new_body;
|
||||||
|
}
|
||||||
|
add_filter('df_confirmation_body', 'filter_email_fb_CIPF', 10, 2); // the receive an email
|
||||||
|
add_filter('df_notification_body', 'filter_email_fb_CIPF', 10, 2); // the admin receive a notification
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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_CIPF($args) {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
// pattern : anything surrounded by '$$', ex : $$value$$
|
||||||
|
$pattern = '/\$\$(.*?)\$\$/';
|
||||||
|
|
||||||
|
$old_body = $args['message'];
|
||||||
|
$new_body = preg_replace_callback($pattern, 'replace_words_CIPF', $old_body);
|
||||||
|
$args['message'] = $new_body;
|
||||||
|
|
||||||
|
return $args;
|
||||||
|
}
|
||||||
|
add_filter('wp_mail', 'filter_email_wp_CIPF', 10, 1);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
all filters in form_builder :
|
||||||
|
|
||||||
|
1 $body = apply_filters( 'df_notification_body', $body, $post_array );
|
||||||
|
2 $email = apply_filters( 'df_notifcation_recipient', $email, $form_id, $post_array );
|
||||||
|
3 $title = apply_filters( 'wpml_translate_single_string', $title_get, 'divi-form-builder', 'Edit Post Button Title Text' );
|
||||||
|
|
||||||
|
4 $body = apply_filters( 'df_contact_body', $body, $post_array );
|
||||||
|
5 $body = apply_filters( 'df_contact_body', $body, $post_array );
|
||||||
|
|
||||||
|
6 $email = apply_filters( 'df_contact_recipient', $email, $form_id, $post_array );
|
||||||
|
7 $email = apply_filters( 'df_contact_recipient', $email, $form_id, $processed_post_array );
|
||||||
|
|
||||||
|
8 $reply_body = apply_filters( 'df_confirmation_body', $reply_body, $post_array );
|
||||||
|
9 $reply_body = apply_filters( 'df_confirmation_body', $reply_body, $post_array );
|
||||||
|
10 $reply_body = apply_filters( 'df_confirmation_body', $reply_body, $post_array );
|
||||||
|
11 $reply_body = apply_filters( 'df_confirmation_body', $reply_body, $post_array );
|
||||||
|
|
||||||
|
12 $message_content = apply_filters( 'the_content', get_post_field( 'post_content', $message_array['layout'] ) );
|
||||||
|
13 $content = apply_filters( 'the_content', get_post_field( 'post_content', $message_array['layout'] ) );
|
||||||
|
14 $content = apply_filters( 'the_content', get_post_field( 'post_content', $html_content_divi_layout) );
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* it means someone outside wp is accessing the file, in this case kill it.
|
||||||
|
*/
|
||||||
|
if (!defined('ABSPATH')) {
|
||||||
|
die('You can not access this file!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
*/
|
||||||
|
function add_form_calculation_patch_CIPF() {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
$handle = 'form_calculation_patch';
|
||||||
|
$url = PLGNTLS_class::root_url() . 'js/form_builder_patch/form_calculation.js';
|
||||||
|
$dependencies = array('de_fb_calc');
|
||||||
|
$version = null;
|
||||||
|
$defer = true;
|
||||||
|
wp_enqueue_script( $handle, $url, $dependencies, $version, $defer);
|
||||||
|
}
|
||||||
|
add_action('wp_enqueue_scripts', 'add_form_calculation_patch_CIPF', 999);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* it means someone outside wp is accessing the file, in this case kill it.
|
||||||
|
*/
|
||||||
|
if (!defined('ABSPATH')) {
|
||||||
|
die('You can not access this file!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function test_modal_PLGNTLS() {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
$cipf_modal = new PLGNTLS_class();
|
||||||
|
$cipf_modal->add_to_front(
|
||||||
|
array(
|
||||||
|
'js/form_builder_patch/multiple_modals.js',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
add_shortcode('test_modal', 'test_modal_PLGNTLS');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -1,12 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
/*
|
|
||||||
Plugin Name: formbuilder url patch
|
/**
|
||||||
Plugin URI:
|
* it means someone outside wp is accessing the file, in this case kill it.
|
||||||
Description:
|
|
||||||
Author: hugogogo
|
|
||||||
Version: 1.1.0
|
|
||||||
Author URI:
|
|
||||||
*/
|
*/
|
||||||
|
if (!defined('ABSPATH')) {
|
||||||
|
die('You can not access this file!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* in `wp-content/plugins/divi-form-builder/includes/DiviFormBuilder.php`
|
* in `wp-content/plugins/divi-form-builder/includes/DiviFormBuilder.php`
|
||||||
@@ -14,15 +15,17 @@ Author URI:
|
|||||||
* - Undefined variable: min_length in /var/www/html/wp-content/plugins/divi-form-builder/includes/modules/FormField/FormField.php on line 5933
|
* - Undefined variable: min_length in /var/www/html/wp-content/plugins/divi-form-builder/includes/modules/FormField/FormField.php on line 5933
|
||||||
* - Undefined variable: use_icon in /var/www/html/wp-content/plugins/divi-form-builder/includes/modules/FormField/FormField.php on line 5984
|
* - Undefined variable: use_icon in /var/www/html/wp-content/plugins/divi-form-builder/includes/modules/FormField/FormField.php on line 5984
|
||||||
*/
|
*/
|
||||||
function add_my_jquery_patch()
|
function add_my_jquery_patch() {
|
||||||
{
|
PLGNTLS_class::debug_infos();
|
||||||
$handle = 'jquery_validator_url_patch';
|
$handle = 'jquery_validator_url_patch';
|
||||||
$url = plugin_dir_url(__FILE__) . 'jquery_validator_url_patch.js';
|
$url = PLGNTLS_class::root_url() . 'js/form_builder_patch/url_validation.js';
|
||||||
$dependencies = array('de_fb_validate');
|
$dependencies = array('de_fb_validate');
|
||||||
$version = '';
|
$version = null;
|
||||||
$defer = true;
|
$defer = true;
|
||||||
wp_enqueue_script( $handle, $url, $dependencies, $version, $defer);
|
wp_enqueue_script( $handle, $url, $dependencies, $version, $defer);
|
||||||
}
|
}
|
||||||
add_action('wp_enqueue_scripts', 'add_my_jquery_patch');
|
add_action('wp_enqueue_scripts', 'add_my_jquery_patch');
|
||||||
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
92
plugins/cipf_plugin/php/format_user_infos.php
Normal file
92
plugins/cipf_plugin/php/format_user_infos.php
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* it means someone outside wp is accessing the file, in this case kill it.
|
||||||
|
*/
|
||||||
|
if (!defined('ABSPATH')) {
|
||||||
|
die('You can not access this file!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function format_user_info_CIPF($query, &$current_user, $user_id) {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
$output_date_format = PLGNTLS_class::USER_INFO_DATE_FORMAT;
|
||||||
|
|
||||||
|
$is_acf = false;
|
||||||
|
$is_date = false;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* check if it's an acf field
|
||||||
|
* first method : check if _field exist
|
||||||
|
*
|
||||||
|
$_acf_field = '_'.$query;
|
||||||
|
$acf_field = $current_user->$_acf_field;
|
||||||
|
if (!empty($acf_field))
|
||||||
|
$is_acf = true;
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* check if it's an acf field, and a date
|
||||||
|
* second method : check what get_field_object() returns
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$acf_id = 'user_'.$user_id;
|
||||||
|
$acf_object = get_field_object($query, $acf_id);
|
||||||
|
if ($acf_object !== false)
|
||||||
|
$is_acf = true;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* if is acf, use the acf return format
|
||||||
|
* otherwise, use the default wordpress value
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if ($is_acf)
|
||||||
|
$output = get_field($query, $acf_id);
|
||||||
|
else
|
||||||
|
$output = $current_user->$query;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* check if is date
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if ($is_acf) {
|
||||||
|
$acf_type = $acf_object['type'];
|
||||||
|
if ($acf_type && $acf_type === "date_picker")
|
||||||
|
$is_date = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* if is date, transform format
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if ($is_date) {
|
||||||
|
$acf_date_string = $acf_object['value'];
|
||||||
|
$acf_date_format = $acf_object['return_format'];
|
||||||
|
$date = date_create_from_format($acf_date_format, $acf_date_string);
|
||||||
|
$output = $date->format($output_date_format);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* return the result
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
while (is_array($output) && count($output) === 1)
|
||||||
|
$output = reset($output);
|
||||||
|
if (is_array($output) && count($output) === 0)
|
||||||
|
$output = '';
|
||||||
|
if (!is_string($output))
|
||||||
|
$output = json_encode($output, JSON_UNESCAPED_SLASHES);
|
||||||
|
return esc_html($output);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
28
plugins/cipf_plugin/php/hide_admin.php
Normal file
28
plugins/cipf_plugin/php/hide_admin.php
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* it means someone outside wp is accessing the file, in this case kill it.
|
||||||
|
*/
|
||||||
|
if (!defined('ABSPATH')) {
|
||||||
|
die('You can not access this file!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* hide admin bar if access a front page and is not an admin
|
||||||
|
*/
|
||||||
|
function hide_admin_bar_CIPF() {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
$role_admin = PLGNTLS_class::ROLE_ADMIN;
|
||||||
|
|
||||||
|
if (!current_user_can($role_admin) && !is_admin()) {
|
||||||
|
show_admin_bar(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
add_action('after_setup_theme', 'hide_admin_bar_CIPF');
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
44
plugins/cipf_plugin/php/menus.php
Normal file
44
plugins/cipf_plugin/php/menus.php
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* it means someone outside wp is accessing the file, in this case kill it.
|
||||||
|
*/
|
||||||
|
if (!defined('ABSPATH')) {
|
||||||
|
die('You can not access this file!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* menu deconnexion
|
||||||
|
* 1. il faut creer un menu personalisé dans Apparence > Menus
|
||||||
|
* 2. dans le code ci-dessous, changer la valeur de $menu_title pour correspondre au titre du menu
|
||||||
|
* 3. et si besoin changer la valeur de $menu_redirect pour choisir la page de redirection :
|
||||||
|
* - si laissée vide, la redirection se fera sur la page de connexion de wordpress
|
||||||
|
* - avec $current_url la redirection se fera sur la page actuelle
|
||||||
|
* - avec $base_url on redirige vers la page d'accueil du site (l'url sans chemin supplementaire)
|
||||||
|
* cette variable $base_url peut etre utilisee pour construire une autre url :
|
||||||
|
* - $menu_redirect = $base_url -> https://le_site_actuel.com/
|
||||||
|
* - $menu_redirect = $base_url . 'contact' -> https://le_site_actuel.com/contact
|
||||||
|
* - $menu_redirect = $current_url -> https://le_site_actuel.com/la_meme_page
|
||||||
|
* - $menu_redirect = 'www.un_autre_site.net/contact' -> https://www.un_autre_site.net/contact
|
||||||
|
*/
|
||||||
|
function change_menu_logout($items){
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
$menu_title = 'special logout';
|
||||||
|
|
||||||
|
// quelques urls utiles :
|
||||||
|
$base_url = home_url();
|
||||||
|
$current_url = home_url( $_SERVER['REQUEST_URI'] );
|
||||||
|
|
||||||
|
$menu_redirect = '';
|
||||||
|
foreach($items as $item){
|
||||||
|
if( $item->title === $menu_title){
|
||||||
|
$item->url = wp_nonce_url( wp_logout_url( $menu_redirect ), 'log-out' );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $items;
|
||||||
|
}
|
||||||
|
add_filter('wp_nav_menu_objects', 'change_menu_logout');
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
125
plugins/cipf_plugin/php/partner_check_page.php
Normal file
125
plugins/cipf_plugin/php/partner_check_page.php
Normal file
@@ -0,0 +1,125 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* it means someone outside wp is accessing the file, in this case kill it.
|
||||||
|
*/
|
||||||
|
if (!defined('ABSPATH')) {
|
||||||
|
die('You can not access this file!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* series of actions to do before printing a partner author page
|
||||||
|
*
|
||||||
|
function check_partner_page_CIPF() {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
|
||||||
|
// the way to find the id of the author of an author_page
|
||||||
|
$author_id = get_queried_object_id();
|
||||||
|
|
||||||
|
}
|
||||||
|
add_action('template_redirect', 'check_partner_page_CIPF', 11);
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
in test_partner_CIPF
|
||||||
|
|
||||||
|
form_id
|
||||||
|
"crea_partenaire"
|
||||||
|
|
||||||
|
post_array
|
||||||
|
{
|
||||||
|
"post_status":"publish",
|
||||||
|
"field_title":[
|
||||||
|
"Nom commercial",
|
||||||
|
"Votre site Internet",
|
||||||
|
"Dans quelle rubrique devez-vous para\u00eetre ? ",
|
||||||
|
"L\\'accroche en t\u00eate de page",
|
||||||
|
"Pr\u00e9sentez-vous",
|
||||||
|
"Votre logo ",
|
||||||
|
"Image principale",
|
||||||
|
"Voulez-vous afficher cette offre ?",
|
||||||
|
"Titre",
|
||||||
|
"Texte de l\\'offre",
|
||||||
|
"Image (facultatif)",
|
||||||
|
"Voulez-vous ajouter une offre ?",
|
||||||
|
"Voulez-vous afficher cette offre ?",
|
||||||
|
"Titre",
|
||||||
|
"Texte de l\\'offre",
|
||||||
|
"Image (facultatif)",
|
||||||
|
"Voulez-vous ajouter une offre ?",
|
||||||
|
"Voulez-vous afficher l\\'offre ?",
|
||||||
|
"Titre",
|
||||||
|
"Texte de l\\'offre",
|
||||||
|
"Image (facultatif)",
|
||||||
|
"slug"
|
||||||
|
],
|
||||||
|
"post_title":"test page partner",
|
||||||
|
"meta_input":[
|
||||||
|
"de_fb_url_partenaire",
|
||||||
|
"de_fb_logo_partenaire",
|
||||||
|
"de_fb_afficher_offre_1",
|
||||||
|
"de_fb_offre_1_titre",
|
||||||
|
"de_fb_offre_1_txt",
|
||||||
|
"de_fb_offre_1_image",
|
||||||
|
"de_fb_ajouter_offre_2",
|
||||||
|
"de_fb_afficher_offre_2",
|
||||||
|
"de_fb_offre_2_titre",
|
||||||
|
"de_fb_offre_2_txt",
|
||||||
|
"de_fb_offre_2_image",
|
||||||
|
"de_fb_ajouter_offre_3",
|
||||||
|
"de_fb_afficher_offre_3",
|
||||||
|
"de_fb_offre_3_titre",
|
||||||
|
"de_fb_offre_3_txt",
|
||||||
|
"de_fb_offre_3_image"
|
||||||
|
],
|
||||||
|
"url_partenaire":"",
|
||||||
|
"tax_input":["de_fb_category"],
|
||||||
|
"category":"autres",
|
||||||
|
"post_excerpt":"accroche test page partner",
|
||||||
|
"post_content":"presentation test page partner",
|
||||||
|
"_ajax_linking_nonce":"2088c0ea4f",
|
||||||
|
"logo_partenaire":"40763",
|
||||||
|
"post_thumbnail":"40764",
|
||||||
|
"afficher_offre_1":"Afficher",
|
||||||
|
"offre_1_titre":"titre offre 1",
|
||||||
|
"offre_1_txt":"text offre 1",
|
||||||
|
"offre_1_image":"",
|
||||||
|
"ajouter_offre_2":"Oui",
|
||||||
|
"afficher_offre_2":"Masquer",
|
||||||
|
"offre_2_titre":"titre offre 2",
|
||||||
|
"offre_2_txt":"text offre 2",
|
||||||
|
"offre_2_image":"",
|
||||||
|
"ajouter_offre_3":"Oui",
|
||||||
|
"afficher_offre_3":"Afficher",
|
||||||
|
"offre_3_titre":"titre offre 3",
|
||||||
|
"offre_3_txt":"text offre 3",
|
||||||
|
"offre_3_image":"",
|
||||||
|
"post_name":"test-page-partner",
|
||||||
|
"ID":"40765",
|
||||||
|
"form_type_confirm":""
|
||||||
|
}
|
||||||
|
|
||||||
|
form_type
|
||||||
|
"post"
|
||||||
|
|
||||||
|
|
||||||
|
function test_partner_CIPF($form_id, $post_array) {
|
||||||
|
error_log("---");
|
||||||
|
error_log("in test_partner_CIPF");
|
||||||
|
error_log("form_id");
|
||||||
|
error_log(json_encode($form_id));
|
||||||
|
error_log("post_array");
|
||||||
|
error_log(json_encode($post_array));
|
||||||
|
}
|
||||||
|
add_action( 'df_before_process', 'test_partner_CIPF', 10, 2);
|
||||||
|
add_action( 'df_after_process', 'test_partner_CIPF', 10, 2);
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
26
plugins/cipf_plugin/php/paypal/paypal.php
Normal file
26
plugins/cipf_plugin/php/paypal/paypal.php
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* it means someone outside wp is accessing the file, in this case kill it.
|
||||||
|
*/
|
||||||
|
if (!defined('ABSPATH')) {
|
||||||
|
die('You can not access this file!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
include_once(PLGNTLS_class::root_path() . '/php/utils/http_errors.php');
|
||||||
|
include_once(PLGNTLS_class::root_path() . '/php/paypal/route_api_utils.php');
|
||||||
|
include_once(PLGNTLS_class::root_path() . '/php/paypal/user_can_pay.php');
|
||||||
|
include_once(PLGNTLS_class::root_path() . '/php/paypal/update_user_payment.php');
|
||||||
|
include_once(PLGNTLS_class::root_path() . '/php/paypal/shortcode.php');
|
||||||
|
include_once(PLGNTLS_class::root_path() . '/php/paypal/route_api_orders.php');
|
||||||
|
include_once(PLGNTLS_class::root_path() . '/php/paypal/route_api_orders_capture.php');
|
||||||
|
include_once(PLGNTLS_class::root_path() . '/php/paypal/routes.php');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
147
plugins/cipf_plugin/php/paypal/route_api_orders.php
Normal file
147
plugins/cipf_plugin/php/paypal/route_api_orders.php
Normal file
@@ -0,0 +1,147 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* it means someone outside wp is accessing the file, in this case kill it.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if (!defined('ABSPATH')) {
|
||||||
|
die('You can not access this file!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* this function runs before the paiement, it initiate the order
|
||||||
|
* @see https://developer.paypal.com/docs/checkout/standard/integrate/#link-integratebackend
|
||||||
|
*
|
||||||
|
* in this function and the insides functions,
|
||||||
|
* explicit errors are thrown with HttpException,
|
||||||
|
* otherwise it's an unexpected error to catch with Exception
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function handle_orders_request_CIPF($request_data) {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
|
||||||
|
// declaring outside the try..catch scope
|
||||||
|
$order_response = array();
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* - check if user can pay, according to conditions
|
||||||
|
* - process the order and get the response
|
||||||
|
* if it fails here : the order was not created
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
try {
|
||||||
|
$can_pay = check_can_pay_CIPF();
|
||||||
|
if (is_wp_error($can_pay))
|
||||||
|
throw new HttpException('not allowed to pay : ' . $can_pay->get_error_message(), 403);
|
||||||
|
|
||||||
|
$order_response = create_order_CIPF();
|
||||||
|
$json_response = $order_response['json_response'];
|
||||||
|
$http_status_code = $order_response['http_status_code'];
|
||||||
|
}
|
||||||
|
catch (HttpException $error) {
|
||||||
|
$status_code = $error->getStatusCode();
|
||||||
|
$message = 'Failed to create order in server :' . $error->getMessage();
|
||||||
|
return new WP_REST_Response($message, $status_code);
|
||||||
|
}
|
||||||
|
catch (Exception $error) {
|
||||||
|
$message = 'Failed to create order in server :' . $error->getMessage();
|
||||||
|
return new WP_REST_Response($message, 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* - add infos of the initiated order into user profil
|
||||||
|
* - return the created order to the front
|
||||||
|
* if it fails here : the order was created in paypal
|
||||||
|
* but a pbm occured in treating it with the user
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
try {
|
||||||
|
update_user_pre_order_CIPF($json_response, 'start');
|
||||||
|
|
||||||
|
/*
|
||||||
|
* https://developer.wordpress.org/reference/classes/wp_rest_response/
|
||||||
|
* extends from https://developer.wordpress.org/reference/classes/wp_http_response/
|
||||||
|
* __construct( $data = null, $status = 200, $headers = array() )
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
return new WP_REST_Response($json_response, $http_status_code);
|
||||||
|
}
|
||||||
|
catch (HttpException $error) {
|
||||||
|
$status_code = $error->getStatusCode();
|
||||||
|
$message = 'Order created, but failed in treatment :' . $error->getMessage();
|
||||||
|
return new WP_REST_Response($message, $status_code);
|
||||||
|
}
|
||||||
|
catch (Exception $error) {
|
||||||
|
$message = 'Order created, but failed in treatment :' . $error->getMessage();
|
||||||
|
return new WP_REST_Response($message, 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Create an order to start the transaction.
|
||||||
|
* @see https://developer.paypal.com/docs/api/orders/v2/#orders_create
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function create_order_CIPF() {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
$paypal_api_base_url = PLGNTLS_class::PAYPAL_API_BASE_URL;
|
||||||
|
|
||||||
|
$access_token = generate_access_token_CIPF();
|
||||||
|
|
||||||
|
$user_id = get_current_user_id();
|
||||||
|
$acf_id = 'user_' . $user_id;
|
||||||
|
$price = get_field('somme_a_regler', $acf_id);
|
||||||
|
|
||||||
|
$url = $paypal_api_base_url . '/v2/checkout/orders';
|
||||||
|
$payload = array(
|
||||||
|
'intent' => "CAPTURE",
|
||||||
|
'purchase_units' => array(
|
||||||
|
array(
|
||||||
|
'amount' => array(
|
||||||
|
'currency_code' => "EUR",
|
||||||
|
'value' => $price,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
$headers = array(
|
||||||
|
"Content-Type: application/json",
|
||||||
|
"Authorization: Bearer " . $access_token
|
||||||
|
// Uncomment one of these to force an error for negative testing (in sandbox mode only). Documentation:
|
||||||
|
// https://developer.paypal.com/tools/sandbox/negative-testing/request-headers/
|
||||||
|
// "PayPal-Mock-Response": '{"mock_application_codes": "MISSING_REQUIRED_PARAMETER"}'
|
||||||
|
// "PayPal-Mock-Response": '{"mock_application_codes": "PERMISSION_DENIED"}'
|
||||||
|
// "PayPal-Mock-Response": '{"mock_application_codes": "INTERNAL_SERVER_ERROR"}'
|
||||||
|
);
|
||||||
|
// Initialize cURL session
|
||||||
|
$ch = curl_init();
|
||||||
|
// Set cURL options
|
||||||
|
curl_setopt($ch, CURLOPT_URL, $url);
|
||||||
|
curl_setopt($ch, CURLOPT_POST, true);
|
||||||
|
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||||
|
|
||||||
|
// Execute cURL session and get the response
|
||||||
|
$response_json = curl_exec($ch);
|
||||||
|
|
||||||
|
// in utils
|
||||||
|
$response = handle_json_response_CIPF($response_json, $ch);
|
||||||
|
|
||||||
|
// Close cURL session
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
return $response;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
114
plugins/cipf_plugin/php/paypal/route_api_orders_capture.php
Normal file
114
plugins/cipf_plugin/php/paypal/route_api_orders_capture.php
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* it means someone outside wp is accessing the file, in this case kill it.
|
||||||
|
*/
|
||||||
|
if (!defined('ABSPATH')) {
|
||||||
|
die('You can not access this file!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function handle_orders_capture_request_CIPF($request) {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
$order_id = $request['orderID'];
|
||||||
|
// declaring outside the try..catch scope
|
||||||
|
$response_json = array();
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ask paypal about the finished order
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
try {
|
||||||
|
$response_json = capture_order_cipf($order_id);
|
||||||
|
$http_status_code = $response_json['http_status_code'];
|
||||||
|
$json_response = $response_json['json_response'];
|
||||||
|
}
|
||||||
|
catch (HttpException $error) {
|
||||||
|
$status_code = $error->getStatusCode();
|
||||||
|
$message = 'Failed to capture order in server :' . $error->getMessage();
|
||||||
|
return new WP_REST_Response($message, $status_code);
|
||||||
|
}
|
||||||
|
catch (Exception $error) {
|
||||||
|
$message = 'Failed to capture order in server : ' . $error->getMessage();
|
||||||
|
return new WP_REST_Response($message, 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* update the client situation
|
||||||
|
* and return the response of paypal
|
||||||
|
*
|
||||||
|
* capture status : https://developer.paypal.com/docs/api/orders/v2/#definition-order_status
|
||||||
|
* - COMPLETED
|
||||||
|
* - DECLINED
|
||||||
|
* - PARTIALLY_REFUNDED
|
||||||
|
* - PENDING
|
||||||
|
* - REFUNDED
|
||||||
|
* - FAILED
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
try {
|
||||||
|
update_user_post_capture_CIPF($json_response, 'end');
|
||||||
|
|
||||||
|
return new WP_REST_Response($json_response, $http_status_code);
|
||||||
|
}
|
||||||
|
catch (HttpException $error) {
|
||||||
|
$status_code = $error->getStatusCode();
|
||||||
|
$message = 'Failed to handle order after capture in server :' . $error->getMessage();
|
||||||
|
return new WP_REST_Response($message, $status_code);
|
||||||
|
}
|
||||||
|
catch (Exception $error) {
|
||||||
|
$message = 'Failed to handle order after capture in server :' . $error->getMessage();
|
||||||
|
return new WP_REST_Response($message, 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Capture payment for the created order to complete the transaction.
|
||||||
|
* @see https://developer.paypal.com/docs/api/orders/v2/#orders_capture
|
||||||
|
*/
|
||||||
|
function capture_order_CIPF($order_id) {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
$paypal_api_base_url = PLGNTLS_class::PAYPAL_API_BASE_URL;
|
||||||
|
$access_token = generate_access_token_CIPF();
|
||||||
|
$url = $paypal_api_base_url . '/v2/checkout/orders/' . $order_id . '/capture';
|
||||||
|
|
||||||
|
$headers = array(
|
||||||
|
"Content-Type: application/json",
|
||||||
|
"Authorization: Bearer " . $access_token
|
||||||
|
// Uncomment one of these to force an error for negative testing (in sandbox mode only). Documentation:
|
||||||
|
// https://developer.paypal.com/tools/sandbox/negative-testing/request-headers/
|
||||||
|
// 'PayPal-Mock-Response: {"mock_application_codes": "INSTRUMENT_DECLINED"}',
|
||||||
|
// 'PayPal-Mock-Response: {"mock_application_codes": "TRANSACTION_REFUSED"}',
|
||||||
|
// 'PayPal-Mock-Response: {"mock_application_codes": "INTERNAL_SERVER_ERROR"}'
|
||||||
|
);
|
||||||
|
// Initialize cURL session
|
||||||
|
$ch = curl_init();
|
||||||
|
// Set cURL options
|
||||||
|
curl_setopt($ch, CURLOPT_URL, $url);
|
||||||
|
curl_setopt($ch, CURLOPT_POST, true);
|
||||||
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
|
||||||
|
// Execute cURL session and get the response
|
||||||
|
$response_json = curl_exec($ch);
|
||||||
|
|
||||||
|
// in utils
|
||||||
|
$response = handle_json_response_CIPF($response_json, $ch);
|
||||||
|
|
||||||
|
// Close cURL session
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
return $response;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
129
plugins/cipf_plugin/php/paypal/route_api_utils.php
Normal file
129
plugins/cipf_plugin/php/paypal/route_api_utils.php
Normal file
@@ -0,0 +1,129 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* it means someone outside wp is accessing the file, in this case kill it.
|
||||||
|
*/
|
||||||
|
if (!defined('ABSPATH')) {
|
||||||
|
die('You can not access this file!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see https://developer.paypal.com/docs/checkout/standard/integrate/#link-integratebackend
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function handle_json_response_CIPF($response, $ch) {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
if ($response === false)
|
||||||
|
throw new HttpException('cURL error: ' . curl_error($ch), 502);
|
||||||
|
|
||||||
|
// Decode JSON response
|
||||||
|
$json_response = json_decode($response);
|
||||||
|
|
||||||
|
// https://stackoverflow.com/questions/2348152/detect-bad-json-data-in-php-json-decode
|
||||||
|
if ($json_response === null && json_last_error() !== JSON_ERROR_NONE) {
|
||||||
|
throw new HttpException('JSON decoding error: ' . json_last_error_msg(), 502);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return response data along with HTTP status code
|
||||||
|
return array(
|
||||||
|
'json_response' => $json_response,
|
||||||
|
'http_status_code' => curl_getinfo($ch, CURLINFO_HTTP_CODE),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
function handle_response_CIPF($response) {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Decode JSON response
|
||||||
|
$json_response = json_decode($response);
|
||||||
|
return array(
|
||||||
|
'json_response' => $json_response,
|
||||||
|
'http_status_code' => http_response_code()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (Exception $err)
|
||||||
|
{
|
||||||
|
// Get error message from response
|
||||||
|
$error_message = $response->text();
|
||||||
|
throw new Exception($error_message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate an OAuth 2.0 access token for authenticating with PayPal REST APIs.
|
||||||
|
* @see https://developer.paypal.com/docs/checkout/standard/integrate/#link-integratebackend
|
||||||
|
* @see https://developer.paypal.com/api/rest/authentication/
|
||||||
|
*/
|
||||||
|
function generate_access_token_CIPF() {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
$paypal_client_id = PLGNTLS_class::PAYPAL_CLIENT_ID;
|
||||||
|
$paypal_client_secret = PLGNTLS_class::PAYPAL_CLIENT_SECRET;
|
||||||
|
$paypal_api_base_url = PLGNTLS_class::PAYPAL_API_BASE_URL;
|
||||||
|
|
||||||
|
/*
|
||||||
|
try
|
||||||
|
{
|
||||||
|
*/
|
||||||
|
if ( !$paypal_client_id || !$paypal_client_secret ) {
|
||||||
|
throw new HttpException("MISSING_API_CREDENTIALS", 403);
|
||||||
|
}
|
||||||
|
$credentials = $paypal_client_id . ":" . $paypal_client_secret;
|
||||||
|
$auth = base64_encode($credentials);
|
||||||
|
|
||||||
|
$url = $paypal_api_base_url . '/v1/oauth2/token';
|
||||||
|
$body = http_build_query(array('grant_type' => 'client_credentials'));
|
||||||
|
// Initialize curl
|
||||||
|
$ch = curl_init();
|
||||||
|
// Set curl options
|
||||||
|
curl_setopt($ch, CURLOPT_URL, $url);
|
||||||
|
curl_setopt($ch, CURLOPT_POST, true);
|
||||||
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
||||||
|
'Authorization: Basic ' . $auth,
|
||||||
|
));
|
||||||
|
|
||||||
|
/********************/
|
||||||
|
|
||||||
|
// Execute cURL session and get the response
|
||||||
|
$data_json = curl_exec($ch);
|
||||||
|
|
||||||
|
// in utils
|
||||||
|
$data = handle_json_response_CIPF($data_json, $ch);
|
||||||
|
|
||||||
|
// Close cURL session
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
return $data['json_response']->access_token;
|
||||||
|
|
||||||
|
/********************/
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
// Execute curl and get the response
|
||||||
|
$data_json = curl_exec($ch);
|
||||||
|
|
||||||
|
if ( $data_json === false)
|
||||||
|
throw new Exception('cURL error: ' . curl_error($ch));
|
||||||
|
|
||||||
|
// Close curl
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
$data = json_decode($data_json);
|
||||||
|
|
||||||
|
return $data->access_token;
|
||||||
|
}
|
||||||
|
catch (Exception $error)
|
||||||
|
{
|
||||||
|
error_log("Failed to generate Access Token:");
|
||||||
|
error_log($error->getMessage());
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
};
|
||||||
|
|
||||||
|
?>
|
||||||
31
plugins/cipf_plugin/php/paypal/routes.php
Normal file
31
plugins/cipf_plugin/php/paypal/routes.php
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* it means someone outside wp is accessing the file, in this case kill it.
|
||||||
|
*/
|
||||||
|
if (!defined('ABSPATH')) {
|
||||||
|
die('You can not access this file!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// handling routes and endpoints
|
||||||
|
// diff routes and endpoints : https://stackoverflow.com/q/56075017/9497573
|
||||||
|
function routes_endpoints_CIPF() {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
$base_rest_route = PLGNTLS_class::URL_BASE_REST_ROUTE;
|
||||||
|
register_rest_route($base_rest_route, '/orders', array(
|
||||||
|
'methods' => 'POST',
|
||||||
|
'callback' => 'handle_orders_request_CIPF',
|
||||||
|
));
|
||||||
|
register_rest_route($base_rest_route, '/orders/(?P<orderID>[a-zA-Z0-9]+)/capture', array(
|
||||||
|
'methods' => 'POST',
|
||||||
|
'callback' => 'handle_orders_capture_request_CIPF',
|
||||||
|
));
|
||||||
|
};
|
||||||
|
add_action('rest_api_init', 'routes_endpoints_CIPF');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
64
plugins/cipf_plugin/php/paypal/shortcode.php
Normal file
64
plugins/cipf_plugin/php/paypal/shortcode.php
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* it means someone outside wp is accessing the file, in this case kill it.
|
||||||
|
*/
|
||||||
|
if (!defined('ABSPATH')) {
|
||||||
|
die('You can not access this file!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* call to paypal_shortcode_content()
|
||||||
|
*/
|
||||||
|
function paypal_shortcode_content_CIPF() {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
$slug_paypal_redirection_success = PLGNTLS_class::SLUG_PAYPAL_REDIRECTION_SUCCESS;
|
||||||
|
$slug_paypal_redirection_failure = PLGNTLS_class::SLUG_PAYPAL_REDIRECTION_FAILURE;
|
||||||
|
$paypal_client_id = PLGNTLS_class::PAYPAL_CLIENT_ID;
|
||||||
|
$paypal_message_success = PLGNTLS_class::PAYPAL_MESSAGE_SUCCESS;
|
||||||
|
$paypal_message_failure = PLGNTLS_class::PAYPAL_MESSAGE_FAILURE;
|
||||||
|
|
||||||
|
// if (!can_pay_now_CIPF())
|
||||||
|
// return no_payment_CIPF();
|
||||||
|
$cipfcard_paypal = new PLGNTLS_class();
|
||||||
|
|
||||||
|
$pp_client_id = $paypal_client_id;
|
||||||
|
$pp_sdk_currency = "EUR";
|
||||||
|
$pp_sdk_base_url = "https://www.paypal.com";
|
||||||
|
$pp_sdk_url = "{$pp_sdk_base_url}/sdk/js?client-id={$pp_client_id}¤cy={$pp_sdk_currency}";
|
||||||
|
|
||||||
|
$paypal_redirection_success = home_url() . '/' . $slug_paypal_redirection_success;
|
||||||
|
$paypal_redirection_failure = home_url() . '/' . $slug_paypal_redirection_failure;
|
||||||
|
|
||||||
|
$added_to_front = $cipfcard_paypal->add_to_front(
|
||||||
|
array(
|
||||||
|
$pp_sdk_url,
|
||||||
|
array("js/paypal/paypal.js", 'type'=>'module'),
|
||||||
|
"html/paypal/paypal.html",
|
||||||
|
),
|
||||||
|
compact (
|
||||||
|
'paypal_redirection_success',
|
||||||
|
'paypal_redirection_failure',
|
||||||
|
'paypal_message_success',
|
||||||
|
'paypal_message_failure',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
return $added_to_front;
|
||||||
|
}
|
||||||
|
add_shortcode('cipf_paypal_shortcode', 'paypal_shortcode_content_CIPF');
|
||||||
|
|
||||||
|
|
||||||
|
function no_payment_CIPF() {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
383
plugins/cipf_plugin/php/paypal/update_user_payment.php
Normal file
383
plugins/cipf_plugin/php/paypal/update_user_payment.php
Normal file
@@ -0,0 +1,383 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* it means someone outside wp is accessing the file, in this case kill it.
|
||||||
|
*/
|
||||||
|
if (!defined('ABSPATH')) {
|
||||||
|
die('You can not access this file!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* see documentation in private 'paypal.md'
|
||||||
|
* basically it check if the user who initiate the transaction
|
||||||
|
* is the same that finish it
|
||||||
|
*
|
||||||
|
* add_user_meta('user_id', 'cipf_order_id', 'aaaaaa');
|
||||||
|
* ['aaaaaa']
|
||||||
|
* add_user_meta('user_id', 'cipf_order_id', 'bbbbbb');
|
||||||
|
* ['aaaaaa', 'bbbbbb']
|
||||||
|
* add_user_meta('user_id', 'cipf_order_id', 'bbbbbb');
|
||||||
|
* ['aaaaaa', 'bbbbbb', 'bbbbbb']
|
||||||
|
* get_user_meta('user_id', 'cipf_order_id');
|
||||||
|
* ['aaaaaa', 'bbbbbb', 'bbbbbb']
|
||||||
|
* $del_ret = delete_user_meta('user_id', 'cipf_order_id', 'bbbbbb');
|
||||||
|
* ['aaaaaa'] - $del_ret === true
|
||||||
|
* $del_ret = delete_user_meta('user_id', 'cipf_order_id', 'bbbbbb');
|
||||||
|
* ['aaaaaa'] - $del_ret === false
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function update_user_pre_order_CIPF($message) {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
$acf_payment_status = PLGNTLS_class::ACF_CARD_PAYMENT_STATE;
|
||||||
|
$meta_order_id = PLGNTLS_class::META_ORDER_ID;
|
||||||
|
|
||||||
|
$order_id = $message->id;
|
||||||
|
$user_id = get_current_user_id();
|
||||||
|
$acf_id = 'user_'.$user_id;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* - delete previous order ids
|
||||||
|
* ->if we are here it's because a new order will try to be created
|
||||||
|
* - addind order_id to cipf_order_id meta field
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
delete_user_meta($user_id, $meta_order_id);
|
||||||
|
add_user_meta($user_id, $meta_order_id, $order_id);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* create a meta field to check states of payements on prof author page :
|
||||||
|
* - 'started' -> at order creation
|
||||||
|
* - 'success' -> at capture success (on author page, it means success, then make it empty)
|
||||||
|
* - 'failure' -> at capture failure (on author page, it means failure, then make it empty)
|
||||||
|
* - 'nothing' -> output nothing on author page
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
update_field($acf_payment_status['_name'], $acf_payment_status['started'], $acf_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function update_user_post_capture_CIPF($message) {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
|
||||||
|
$order_id = $message->id;
|
||||||
|
$user_id = get_current_user_id();
|
||||||
|
$status = null;
|
||||||
|
if (is_object($message) && isset($message->status))
|
||||||
|
$status = $message->status;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* capture status : https://developer.paypal.com/docs/api/orders/v2/#definition-order_status
|
||||||
|
* - COMPLETED
|
||||||
|
* - DECLINED
|
||||||
|
* - PARTIALLY_REFUNDED
|
||||||
|
* - PENDING
|
||||||
|
* - REFUNDED
|
||||||
|
* - FAILED
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* delete order_id and update user
|
||||||
|
* -> is it necessary to delete order_id since we delete it when creating a new order ?
|
||||||
|
* -> it is at least necessary to find the user who did the purchase
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
// find the user containing the order_id and delete this order_id
|
||||||
|
$user_id_to_update = find_user_with_order_id_CIPF($user_id, $order_id);
|
||||||
|
if ($user_id_to_update === false)
|
||||||
|
throw new HttpException('cannot find user with this order_id', 502);
|
||||||
|
if ($status === 'COMPLETED') {
|
||||||
|
// proceed to validate payment for user
|
||||||
|
validate_payment_for_user_CIPF($user_id_to_update, $order_id);
|
||||||
|
}
|
||||||
|
else if ($status === 'PENDING') {
|
||||||
|
// i don't know what to do yet, maybe make more checks and output a message to contact diego ?
|
||||||
|
// https://developer.paypal.com/docs/api/orders/v2/#definition-capture_status_details
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
failure_payment_for_user_CIPF($user_id_to_update, $order_id, $status);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* things to do when a payment has failed
|
||||||
|
* failed payement means order status is not COMPLETED or PENDING
|
||||||
|
* it can be :
|
||||||
|
* - DECLINED
|
||||||
|
* - PARTIALLY_REFUNDED
|
||||||
|
* - REFUNDED
|
||||||
|
* - FAILED
|
||||||
|
* -> capture status : https://developer.paypal.com/docs/api/orders/v2/#definition-order_status
|
||||||
|
* in any cases, the price was not paid
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function failure_payment_for_user_CIPF($user_id, $order_id, $status) {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
|
||||||
|
$acf_card_state = PLGNTLS_class::ACF_CARD_STATE;
|
||||||
|
$acf_card_expiration = PLGNTLS_class::ACF_CARD_EXPIRATION;
|
||||||
|
$card_duration = PLGNTLS_class::CARD_VALIDITY_TIME;
|
||||||
|
$prof_is_activ = PLGNTLS_class::ACF_PROF_IS_ACTIV;
|
||||||
|
$acf_payment_status = PLGNTLS_class::ACF_CARD_PAYMENT_STATE;
|
||||||
|
$meta_order_id = PLGNTLS_class::META_ORDER_ID;
|
||||||
|
|
||||||
|
$acf_id = 'user_'.$user_id;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* remove the order_id from user meta
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
delete_user_meta($user_id, $meta_order_id, $order_id);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* change payement status to failed
|
||||||
|
* - 'started' -> at order creation
|
||||||
|
* - 'success' -> at capture success (on author page, it means success, then mark it 'nothing')
|
||||||
|
* - 'failure' -> at capture failure (on author page, it means failure, then mark it 'nothing')
|
||||||
|
* - 'nothing' -> output nothing on author page
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
update_field($acf_payment_status['_name'], $acf_payment_status['failure'], $acf_id);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* other changes on user :
|
||||||
|
* - pofil is inactive
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
update_field($prof_is_activ['_name'], $prof_is_activ['inactiv'], $acf_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* things to do when a payment is a success
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function validate_payment_for_user_CIPF($user_id, $order_id) {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
|
||||||
|
$acf_card_state = PLGNTLS_class::ACF_CARD_STATE;
|
||||||
|
$acf_card_expiration = PLGNTLS_class::ACF_CARD_EXPIRATION;
|
||||||
|
$acf_card_number = PLGNTLS_class::ACF_CARD_NUMBER;
|
||||||
|
$card_duration = PLGNTLS_class::CARD_VALIDITY_TIME;
|
||||||
|
$prof_is_activ = PLGNTLS_class::ACF_PROF_IS_ACTIV;
|
||||||
|
$acf_payment_status = PLGNTLS_class::ACF_CARD_PAYMENT_STATE;
|
||||||
|
$meta_order_id = PLGNTLS_class::META_ORDER_ID;
|
||||||
|
/*
|
||||||
|
$acf_cgv = PLGNTLS_class::ACF_PROF_CGV;
|
||||||
|
$acf_payement = PLGNTLS_class::ACF_CARD_PAYMENT_METHOD;
|
||||||
|
$acf_delivery = PLGNTLS_class::ACF_CARD_PRICE_DELIVERY;
|
||||||
|
$acf_price = PLGNTLS_class::ACF_CARD_PRICE_CHOICE;
|
||||||
|
*/
|
||||||
|
|
||||||
|
$acf_id = 'user_'.$user_id;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* remove the order_id from user meta
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
delete_user_meta($user_id, $meta_order_id, $order_id);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* acf uses 'Y-m-d H:i:s' format : https://www.advancedcustomfields.com/resources/date-time-picker/
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$acf_date_format = 'Y-m-d H:i:s';
|
||||||
|
$acf_id = 'user_'.$user_id;
|
||||||
|
|
||||||
|
$date_now = date_create('today');
|
||||||
|
|
||||||
|
/*
|
||||||
|
* get current date limit
|
||||||
|
* if no date, use now
|
||||||
|
* if paste date, use now
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$current_date_limit_object = get_field_object($acf_card_expiration['_name'], $acf_id);
|
||||||
|
|
||||||
|
if ($current_date_limit_object === false) {
|
||||||
|
$current_date_limit = $date_now;
|
||||||
|
}
|
||||||
|
else if (empty($current_date_limit_object['value'])) {
|
||||||
|
$current_date_limit = $date_now;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$current_date_limit_string = $current_date_limit_object['value'];
|
||||||
|
$current_format_field = $current_date_limit_object['return_format'];
|
||||||
|
// compare 2 dates : https://stackoverflow.com/q/8722806/9497573
|
||||||
|
// also I dont use strtotime to compare 2 ints,
|
||||||
|
// because i don't know if it will fail one day (2000 bug alike)
|
||||||
|
$current_date_limit = date_create_from_format($current_format_field, $current_date_limit_string);
|
||||||
|
$date_diff = date_diff($date_now, $current_date_limit);
|
||||||
|
$date_is_in_past = $date_diff->format('%R%a') < 0;
|
||||||
|
|
||||||
|
if ($date_is_in_past)
|
||||||
|
$current_date_limit = $date_now;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* update date limit validity to add 1 year
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$date_plus_one_year = $current_date_limit->add(date_interval_create_from_date_string('+'.$card_duration));
|
||||||
|
update_field($acf_card_expiration['_name'], $date_plus_one_year->format($acf_date_format), $acf_id);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* - if card status is command, create card id
|
||||||
|
* - make card status to renewal
|
||||||
|
*/
|
||||||
|
$card_status = get_field($acf_card_state['_name'], $acf_id);
|
||||||
|
if ($card_status === $acf_card_state['new']) {
|
||||||
|
$card_id = $date_now->format('Ymd') . $user_id;
|
||||||
|
error_log("-------");
|
||||||
|
error_log("card_id");
|
||||||
|
error_log($card_id);
|
||||||
|
update_field($acf_card_number['_name'], $card_id, $acf_id);
|
||||||
|
}
|
||||||
|
update_field($acf_card_state['_name'], $acf_card_state['renew'], $acf_id);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* change user :
|
||||||
|
* - profile is active
|
||||||
|
* - card state is renewal
|
||||||
|
* - payement status is success
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
update_field($prof_is_activ['_name'], $prof_is_activ['activ'], $acf_id);
|
||||||
|
update_field($acf_payment_status['_name'], $acf_payment_status['success'], $acf_id);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* reset some fields for the form to buy the card
|
||||||
|
* - cgv
|
||||||
|
* - paiement
|
||||||
|
* - livraison
|
||||||
|
* - tarif
|
||||||
|
*
|
||||||
|
* could make sense to put it here,
|
||||||
|
* but actually it needs to be put at begining of form
|
||||||
|
*
|
||||||
|
update_field($acf_cgv['_name'] , array(""), 'user_'.$user_id);
|
||||||
|
update_field($acf_payement['_name'], array(""), 'user_'.$user_id);
|
||||||
|
update_field($acf_delivery['_name'], array(""), 'user_'.$user_id);
|
||||||
|
update_field($acf_price['_name'] , array(""), 'user_'.$user_id);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* add a schedule event to delete this order_id
|
||||||
|
* after 3 days ?
|
||||||
|
* time() + 60 = one minute from now
|
||||||
|
* time() + MINUTE_IN_SECONDS = one minute from now
|
||||||
|
* -> https://codex.wordpress.org/Easier_Expression_of_Time_Constants
|
||||||
|
* -> also strtotime : https://www.php.net/manual/en/function.strtotime.php
|
||||||
|
*
|
||||||
|
function schedule_delete_orderid_CIPF($user_id, $order_id)
|
||||||
|
{
|
||||||
|
$delay = time() + MINUTE_IN_SECONDS;
|
||||||
|
wp_schedule_single_event($delay, 'orderid_deletion_event_CIPF', array($user_id, $order_id));
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* action hook for the scheduled event
|
||||||
|
* TODO: ne marche pas je ne sais pas pourquoi, pas urgent a resoudre
|
||||||
|
*
|
||||||
|
function delete_order_id_later_CIPF($user_id, $order_id)
|
||||||
|
{
|
||||||
|
delete_user_meta($user_id, 'cipf_order_id', $order_id);
|
||||||
|
}
|
||||||
|
add_action('orderid_deletion_event_CIPF', 'delete_order_id_later_CIPF', 5, 2);
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @return mixed num - user_id
|
||||||
|
* bool false - if no match found
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function find_user_with_order_id_CIPF($current_user_id, $order_id) {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
$meta_order_id = PLGNTLS_class::META_ORDER_ID;
|
||||||
|
$role_prof = PLGNTLS_class::ROLE_PROF;
|
||||||
|
|
||||||
|
$user_metas = get_user_meta($current_user_id, $meta_order_id, false);
|
||||||
|
if (in_array($order_id, $user_metas)) {
|
||||||
|
return $current_user_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* it means the current user didn't have this order_id
|
||||||
|
* so we look for another user
|
||||||
|
* https://developer.wordpress.org/reference/classes/WP_User_Query/prepare_query/
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$users = get_users(array(
|
||||||
|
'role' => $role_prof,
|
||||||
|
'meta_key' => $meta_order_id,
|
||||||
|
'meta_value' => $order_id,
|
||||||
|
'fields' => 'ID',
|
||||||
|
));
|
||||||
|
if (count($users) > 1)
|
||||||
|
throw new HttpException('multiple users with same order_id', 502);
|
||||||
|
else if (count($users) === 1)
|
||||||
|
return reset($users);
|
||||||
|
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @return mixed num - user_id
|
||||||
|
* bool false - if no match found
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function delete_order_id_on_success_CIPF($current_user_id, $order_id) {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
$meta_order_id = PLGNTLS_class::META_ORDER_ID;
|
||||||
|
|
||||||
|
$del_ret = delete_user_meta($current_user_id, $meta_order_id, $order_id);
|
||||||
|
if ($del_ret === true)
|
||||||
|
return $current_user_id;
|
||||||
|
|
||||||
|
// it means the current user didn't have this order_id
|
||||||
|
// so we look for another user
|
||||||
|
$users = get_users();
|
||||||
|
foreach ($users as $user) {
|
||||||
|
$user_id = $user->ID;
|
||||||
|
$del_ret = delete_user_meta($user_id, $meta_order_id, $order_id);
|
||||||
|
if ($del_ret === true)
|
||||||
|
return $user_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
105
plugins/cipf_plugin/php/paypal/user_can_pay.php
Normal file
105
plugins/cipf_plugin/php/paypal/user_can_pay.php
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* it means someone outside wp is accessing the file, in this case kill it.
|
||||||
|
*/
|
||||||
|
if (!defined('ABSPATH')) {
|
||||||
|
die('You can not access this file!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* can pay in certain conditions
|
||||||
|
* @return true / wp_error
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function check_can_pay_CIPF() {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
$acf_card_payment_method = PLGNTLS_class::ACF_CARD_PAYMENT_METHOD;
|
||||||
|
$acf_card_price_choice = PLGNTLS_class::ACF_CARD_PRICE_CHOICE;
|
||||||
|
$acf_card_price_delivery = PLGNTLS_class::ACF_CARD_PRICE_DELIVERY;
|
||||||
|
$acf_card_price_total = PLGNTLS_class::ACF_CARD_PRICE_TOTAL;
|
||||||
|
$acf_card_expiration = PLGNTLS_class::ACF_CARD_EXPIRATION;
|
||||||
|
$card_renew_period = PLGNTLS_class::CARD_RENEW_PERIOD;
|
||||||
|
|
||||||
|
$current_user = wp_get_current_user();
|
||||||
|
$user_id = get_current_user_id();
|
||||||
|
$acf_id = 'user_' . $user_id;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* check if payment is virement or immediat
|
||||||
|
*
|
||||||
|
$payement = get_field($acf_card_payment_method['_name'], $acf_id);
|
||||||
|
if (strtolower($payement) === 'virement') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* calculate price
|
||||||
|
* update the price even if form builder already did it
|
||||||
|
* 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;
|
||||||
|
update_field($acf_card_price_total['_name'], $price, $acf_id);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* price is not empty or 0
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$price = get_field($acf_card_price_total['_name'], $acf_id);
|
||||||
|
if (empty($price)) {
|
||||||
|
return new WP_Error('cannot_purchase', "no price selected");
|
||||||
|
}
|
||||||
|
if ($price === 0) {
|
||||||
|
return new WP_Error('cannot_purchase', "price is 0, nothing to purchase");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* date validity is empty
|
||||||
|
* or is paste
|
||||||
|
* or is less than 1 month
|
||||||
|
*
|
||||||
|
$validity_field = get_field_object($acf_card_expiration, $acf_id);
|
||||||
|
|
||||||
|
if ($validity_field === false)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
$validity = $validity_field['value'];
|
||||||
|
$format_field = $validity_field['return_format'];
|
||||||
|
|
||||||
|
if (empty($validity))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
$date_validity = date_create_from_format($format_field, $validity);
|
||||||
|
|
||||||
|
$date_now = date_create('today');
|
||||||
|
$diff = date_diff($date_now, $date_validity)->format('%R%a');
|
||||||
|
if ((int)$diff <= 0) {
|
||||||
|
// date end of validity in the past
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if ((int)$diff <= $card_renew_period) {
|
||||||
|
// date expiration is in less that renew period time (ex: 30 days)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// date end of validity is in more than renew perdio (ex: 3 month)
|
||||||
|
return new WP_Error('cannot_purchase', "it's too soon to renew your card");
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
134
plugins/cipf_plugin/php/prof_check_page.php
Normal file
134
plugins/cipf_plugin/php/prof_check_page.php
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* it means someone outside wp is accessing the file, in this case kill it.
|
||||||
|
*/
|
||||||
|
if (!defined('ABSPATH')) {
|
||||||
|
die('You can not access this file!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function handle_prof_is_activ_CIPF($author_id) {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
$acf_prof_is_activ = PLGNTLS_class::ACF_PROF_IS_ACTIV;
|
||||||
|
$slug_wait_activation = PLGNTLS_class::SLUG_PROF_INACTIV;
|
||||||
|
|
||||||
|
$acf_id = 'user_' . $author_id;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* if prof is activ, do nothing more
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$is_activ = get_field($acf_prof_is_activ['_name'], $acf_id);
|
||||||
|
if ($is_activ === $acf_prof_is_activ['activ'])
|
||||||
|
return;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* else if prof inactiv
|
||||||
|
* if is admin or other allowed roles, see the page anyway
|
||||||
|
* no need to handle allowed roles, it's already
|
||||||
|
* taken care by author_restriction.php
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$user_id = get_current_user_id();
|
||||||
|
if ($user_id !== $author_id)
|
||||||
|
return;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* if prof is activ
|
||||||
|
* redirect to waiting page
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$redirection_prof_inactiv = home_url() . '/' . $slug_wait_activation;
|
||||||
|
|
||||||
|
// Set up nocache headers before redirecting : https://developer.wordpress.org/reference/functions/wp_safe_redirect/#user-contributed-notes
|
||||||
|
nocache_headers();
|
||||||
|
wp_redirect($redirection_prof_inactiv, 301);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* check acf field payment_status
|
||||||
|
* if field value is 'success'
|
||||||
|
* - show block 'failure'
|
||||||
|
* - and update field to 'nothing', so it will not show next time
|
||||||
|
* if field value is 'failure'
|
||||||
|
* - show bloc success
|
||||||
|
* - and update field to 'nothing', so it will not show next time
|
||||||
|
* if field value is 'nothing'
|
||||||
|
* - do nothing (keep blocs hidden)
|
||||||
|
* if field value is 'started'
|
||||||
|
* - do nothing (keep blocs hidden)
|
||||||
|
*
|
||||||
|
* .cipf_prof_paiement_message -> on row, added display none in page css
|
||||||
|
* #cipf_prof_paiement_reussi -> on row
|
||||||
|
* #cipf_prof_paiement_echoue -> on row
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function show_prof_paiement_messages_CIPF($user_id) {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
$acf_prof_is_activ = PLGNTLS_class::ACF_PROF_IS_ACTIV;
|
||||||
|
$acf_payment_status = PLGNTLS_class::ACF_CARD_PAYMENT_STATE;
|
||||||
|
|
||||||
|
$acf_id = 'user_' . $user_id;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* if prof is inactive, do nothing more
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$is_activ = get_field($acf_prof_is_activ['_name'], $acf_id);
|
||||||
|
if (is_null($is_activ))
|
||||||
|
return;
|
||||||
|
if (empty($is_activ))
|
||||||
|
return;
|
||||||
|
if ($is_activ === $acf_prof_is_activ['activ'])
|
||||||
|
return;
|
||||||
|
|
||||||
|
$cipf_prof_payement = new PLGNTLS_class();
|
||||||
|
|
||||||
|
$payement_status = get_field($acf_payment_status['_name'], $acf_id);
|
||||||
|
if ($payement_status === $acf_payment_status['success']) {
|
||||||
|
$cipf_prof_payement->add_to_front(array(
|
||||||
|
array( 'css' => '.cipf_prof_paiement_message#cipf_prof_paiement_reussi {display: block;}' )
|
||||||
|
));
|
||||||
|
}
|
||||||
|
else if ($payement_status === $acf_payment_status['failure']) {
|
||||||
|
$cipf_prof_payement->add_to_front(array(
|
||||||
|
array( 'css' => '.cipf_prof_paiement_message#cipf_prof_paiement_echoue {display: block;}' )
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
update_field($acf_payment_status['_name'], $acf_payment_status['nothing'], $acf_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* series of check to do before printing a prof author page
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function check_prof_page_CIPF() {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
|
||||||
|
// is an author page
|
||||||
|
if (!is_author())
|
||||||
|
return;
|
||||||
|
|
||||||
|
// the way to find the id of the author of an author_page
|
||||||
|
$author_id = get_queried_object_id();
|
||||||
|
|
||||||
|
handle_prof_is_activ_CIPF($author_id);
|
||||||
|
|
||||||
|
show_prof_paiement_messages_CIPF($author_id);
|
||||||
|
|
||||||
|
}
|
||||||
|
add_action('template_redirect', 'check_prof_page_CIPF', 11);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
127
plugins/cipf_plugin/php/redirections.php
Normal file
127
plugins/cipf_plugin/php/redirections.php
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* it means someone outside wp is accessing the file, in this case kill it.
|
||||||
|
*/
|
||||||
|
if (!defined('ABSPATH')) {
|
||||||
|
die('You can not access this file!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* redirect users to profil
|
||||||
|
* if prof -> author page
|
||||||
|
* if partenaire -> post page || home page
|
||||||
|
*/
|
||||||
|
function redirection_profil_page_CIPF(){
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
$role_prof = PLGNTLS_class::ROLE_PROF;
|
||||||
|
$role_partner = PLGNTLS_class::ROLE_PARTNER;
|
||||||
|
|
||||||
|
$base_url = home_url();
|
||||||
|
$current_user_id = get_current_user_id();
|
||||||
|
|
||||||
|
// Set up nocache headers before redirecting : https://developer.wordpress.org/reference/functions/wp_safe_redirect/#user-contributed-notes
|
||||||
|
nocache_headers();
|
||||||
|
|
||||||
|
if (!is_user_logged_in()) {
|
||||||
|
wp_redirect($base_url, 301);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (current_user_can($role_prof)) {
|
||||||
|
$user_page = get_author_posts_url($current_user_id);
|
||||||
|
wp_redirect($user_page, 301);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
else if (current_user_can($role_partner)) {
|
||||||
|
$args = array(
|
||||||
|
'post_type' => 'post',
|
||||||
|
'author' => $current_user_id,
|
||||||
|
'posts_per_page' => 1,
|
||||||
|
);
|
||||||
|
$posts = get_posts($args);
|
||||||
|
if (empty($posts))
|
||||||
|
$redirect_url = $base_url;
|
||||||
|
else {
|
||||||
|
$query = reset($posts);
|
||||||
|
$post_id = $query->ID;
|
||||||
|
$redirect_url = get_permalink($query->ID);
|
||||||
|
}
|
||||||
|
wp_redirect($redirect_url, 301);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
wp_redirect($base_url, 301);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* redirects when someone reaches 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_page_CIPF();
|
||||||
|
}
|
||||||
|
add_action('template_redirect', 'redirection_page_CIPF');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* redirects when someone reaches the page with query ?QUERY_REDIRECTION_PROFIL
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function redirection_query_CIPF() {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
$query_redirection = PLGNTLS_class::QUERY_REDIRECTION_PROFIL;
|
||||||
|
|
||||||
|
// Check if the request contains ?QUERY_REDIRECTION_PROFIL
|
||||||
|
if(isset($_GET[$query_redirection])) {
|
||||||
|
redirection_profil_page_CIPF();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
add_action('init', 'redirection_query_CIPF');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* DOES NOT WORK so far
|
||||||
|
* because to use is_user_logged_in() in redirection_profil_page_CIPF
|
||||||
|
* the request should include the X-WP-Nonce header, but it does not
|
||||||
|
* redirects when someone enter the url or redirection
|
||||||
|
* /wp-json/cipf_plugin/api/v1/redirection_cipf
|
||||||
|
*
|
||||||
|
function endpoint_for_redirection_CIPF() {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
$slug_page_redirection = PLGNTLS_class::SLUG_PAGE_REDIRECTION;
|
||||||
|
$base_rest_route = PLGNTLS_class::URL_BASE_REST_ROUTE;
|
||||||
|
|
||||||
|
register_rest_route($base_rest_route, '/' . $slug_page_redirection, array(
|
||||||
|
'methods' => 'GET',
|
||||||
|
'callback' => 'redirection_profil_page_CIPF',
|
||||||
|
));
|
||||||
|
};
|
||||||
|
add_action('rest_api_init', 'endpoint_for_redirection_CIPF');
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
98
plugins/cipf_plugin/php/register_partenaires.php
Normal file
98
plugins/cipf_plugin/php/register_partenaires.php
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* it means someone outside wp is accessing the file, in this case kill it.
|
||||||
|
*/
|
||||||
|
if (!defined('ABSPATH')) {
|
||||||
|
die('You can not access this file!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* at registration, add role 'partenaire' when page url has path 'creation-du-compte-partenaire'
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function add_partenaires_CIPF($customer_data){
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
$role_partner = PLGNTLS_class::ROLE_PARTNER;
|
||||||
|
error_log("----");
|
||||||
|
error_log("in add_partenaires");
|
||||||
|
error_log("_POST");
|
||||||
|
error_log(json_encode($_POST));
|
||||||
|
error_log("_SERVER");
|
||||||
|
error_log(json_encode($_SERVER));
|
||||||
|
|
||||||
|
$current_url = $_SERVER['HTTP_REFERER']; // not reliable to use referer, TODO: find another solution
|
||||||
|
$path_brut = parse_url($current_url, PHP_URL_PATH);
|
||||||
|
$path = trim($path_brut, '/');
|
||||||
|
if ($path === 'creation-du-compte-partenaire')
|
||||||
|
$customer_data['role'] = $role_partner;
|
||||||
|
return $customer_data;
|
||||||
|
}
|
||||||
|
add_filter( 'xoo_el_register_new_customer_data', 'add_partenaires_CIPF', 10, 1 );
|
||||||
|
/*
|
||||||
|
|
||||||
|
in add_partenaires
|
||||||
|
_POST
|
||||||
|
{
|
||||||
|
"xoo_el_reg_username":"tistilarde",
|
||||||
|
"xoo_el_reg_email":"tistilarde@gufum.com",
|
||||||
|
"xoo_el_reg_pass":"pouetpouet",
|
||||||
|
"_xoo_el_form":"register",
|
||||||
|
"xoo_el_redirect":"\/creation-du-compte-partenaire\/",
|
||||||
|
"action":"xoo_el_form_action",
|
||||||
|
"display":"popup"
|
||||||
|
}
|
||||||
|
|
||||||
|
_SERVER
|
||||||
|
{
|
||||||
|
"SERVER_SOFTWARE":"nginx\/1.20.2",
|
||||||
|
"REQUEST_URI":"\/wp-admin\/admin-ajax.php",
|
||||||
|
"USER":"www-data",
|
||||||
|
"HOME":"\/home\/www-data",
|
||||||
|
"HTTP_SEC_FETCH_SITE":"same-origin",
|
||||||
|
"HTTP_SEC_FETCH_MODE":"cors",
|
||||||
|
"HTTP_SEC_FETCH_DEST":"empty",
|
||||||
|
"HTTP_COOKIE":"wordpress_test_cookie=WP%20Cookie%20check; wp-postpass_351da2be51e3820c1ef099eec9d2e669=%24P%24BjEiJgHo.cgrpONdnfmxwpIYzraFCP.; mjx.menu=renderer%3ANativeMML%26%3Bsemantics%3Atrue%26%3Bcontext%3ABrowser%26%3Bzoom%3ANone",
|
||||||
|
"HTTP_REFERER":"https:\/\/local-cipf-plugin.com\/creation-du-compte-partenaire\/",
|
||||||
|
"HTTP_CONNECTION":"keep-alive",
|
||||||
|
"HTTP_SEC_GPC":"1",
|
||||||
|
"HTTP_DNT":"1",
|
||||||
|
"HTTP_ORIGIN":"https:\/\/local-cipf-plugin.com",
|
||||||
|
"HTTP_CONTENT_LENGTH":"211",
|
||||||
|
"HTTP_X_REQUESTED_WITH":"XMLHttpRequest",
|
||||||
|
"HTTP_CONTENT_TYPE":"application\/x-www-form-urlencoded; charset=UTF-8",
|
||||||
|
"HTTP_ACCEPT_ENCODING":"gzip, deflate, br",
|
||||||
|
"HTTP_ACCEPT_LANGUAGE":"en-US,en;q=0.5",
|
||||||
|
"HTTP_ACCEPT":"*\/*",
|
||||||
|
"HTTP_USER_AGENT":"Mozilla\/5.0 (X11; Ubuntu; Linux x86_64; rv:123.0) Gecko\/20100101 Firefox\/123.0",
|
||||||
|
"HTTP_HOST":"local-cipf-plugin.com",
|
||||||
|
"REDIRECT_STATUS":"200",
|
||||||
|
"SERVER_NAME":"local-cipf-plugin.com",
|
||||||
|
"SERVER_PORT":"443",
|
||||||
|
"SERVER_ADDR":"172.20.0.4",
|
||||||
|
"REMOTE_PORT":"58976",
|
||||||
|
"REMOTE_ADDR":"172.20.0.1",
|
||||||
|
"GATEWAY_INTERFACE":"CGI\/1.1",
|
||||||
|
"HTTPS":"on",
|
||||||
|
"REQUEST_SCHEME":"https",
|
||||||
|
"SERVER_PROTOCOL":"HTTP\/1.1",
|
||||||
|
"DOCUMENT_ROOT":"\/var\/www\/html",
|
||||||
|
"DOCUMENT_URI":"\/wp-admin\/admin-ajax.php",
|
||||||
|
"SCRIPT_NAME":"\/wp-admin\/admin-ajax.php",
|
||||||
|
"CONTENT_LENGTH":"211",
|
||||||
|
"CONTENT_TYPE":"application\/x-www-form-urlencoded; charset=UTF-8",
|
||||||
|
"REQUEST_METHOD":"POST",
|
||||||
|
"QUERY_STRING":"",
|
||||||
|
"SCRIPT_FILENAME":"\/var\/www\/html\/wp-admin\/admin-ajax.php",
|
||||||
|
"FCGI_ROLE":"RESPONDER",
|
||||||
|
"PHP_SELF":"\/wp-admin\/admin-ajax.php",
|
||||||
|
"REQUEST_TIME_FLOAT":1710328883.257681,
|
||||||
|
"REQUEST_TIME":1710328883
|
||||||
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
125
plugins/cipf_plugin/php/renew_card.php
Normal file
125
plugins/cipf_plugin/php/renew_card.php
Normal file
@@ -0,0 +1,125 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* it means someone outside wp is accessing the file, in this case kill it.
|
||||||
|
*/
|
||||||
|
if (!defined('ABSPATH')) {
|
||||||
|
die('You can not access this file!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* on renew page :
|
||||||
|
* - check restrictions
|
||||||
|
* - change some acf fields (if access granted)
|
||||||
|
*
|
||||||
|
* prevent users to fill the renew form if :
|
||||||
|
* - they are not prof and logged in,
|
||||||
|
* - and if their card is not in renewable state
|
||||||
|
* - except admins and editor
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function renew_page_restrictions_CIPF(){
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
$slug_renew_card = PLGNTLS_class::SLUG_RENEW_CARD;
|
||||||
|
$slug_page_redirection = PLGNTLS_class::SLUG_PAGE_REDIRECTION;
|
||||||
|
$role_prof = PLGNTLS_class::ROLE_PROF;
|
||||||
|
$role_fipf = PLGNTLS_class::ROLE_FIPF;
|
||||||
|
$role_admin = PLGNTLS_class::ROLE_ADMIN;
|
||||||
|
|
||||||
|
$base_url = home_url();
|
||||||
|
|
||||||
|
wp_reset_query();
|
||||||
|
|
||||||
|
if (!is_page('commande'))
|
||||||
|
return;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* is it good ?
|
||||||
|
* -> dont' redirect if user not logged in, because new users need to acces this page
|
||||||
|
*
|
||||||
|
if (!is_user_logged_in()) {
|
||||||
|
// Set up nocache headers before redirecting : https://developer.wordpress.org/reference/functions/wp_safe_redirect/#user-contributed-notes
|
||||||
|
nocache_headers();
|
||||||
|
wp_redirect($base_url, 301);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
$current_user_id = get_current_user_id();
|
||||||
|
$current_user = wp_get_current_user();
|
||||||
|
$acf_id = 'user_'.$current_user_id;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* check multiple user roles
|
||||||
|
* https://developer.wordpress.org/reference/functions/current_user_can/#div-comment-4083
|
||||||
|
*
|
||||||
|
$allowed_roles = array($role_admin, $role_fipf, $role_prof);
|
||||||
|
if (!array_intersect($allowed_roles, $current_user->roles))
|
||||||
|
return;
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* if prof, check card state
|
||||||
|
* if cannot renew, redirect
|
||||||
|
*
|
||||||
|
if (current_user_can($role_prof)) {
|
||||||
|
$can_renew = get_field($acf_prof_can_renew['_name'], $acf_id);
|
||||||
|
if ($can_renew === false) {
|
||||||
|
// Set up nocache headers before redirecting : https://developer.wordpress.org/reference/functions/wp_safe_redirect/#user-contributed-notes
|
||||||
|
nocache_headers();
|
||||||
|
$redirect_url = home_url() . '/' . $slug_page_redirection;
|
||||||
|
wp_redirect($redirect_url, 301);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
add_action('template_redirect', 'renew_page_restrictions_CIPF');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* on the renew card page for prof
|
||||||
|
* output the right message, depending of the status of the card
|
||||||
|
* 'renouveler' or 'commander'
|
||||||
|
*
|
||||||
|
* #cipf_prof_carte_commande -> default display: block;
|
||||||
|
* #cipf_prof_carte_renouvellement -> default display: none;
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function renew_page_filter_message_CIPF(){
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
$slug_renew_card = PLGNTLS_class::SLUG_RENEW_CARD;
|
||||||
|
$acf_card_state = PLGNTLS_class::ACF_CARD_STATE;
|
||||||
|
|
||||||
|
if (!is_page($slug_renew_card))
|
||||||
|
return;
|
||||||
|
|
||||||
|
$user_id = get_current_user_id();
|
||||||
|
$acf_id = 'user_'.$user_id;
|
||||||
|
|
||||||
|
$cipf_renew = new PLGNTLS_class();
|
||||||
|
|
||||||
|
$card_state = get_field($acf_card_state['_name'], $acf_id);
|
||||||
|
|
||||||
|
if ($card_state === 'Renouvellement') {
|
||||||
|
$cipf_renew->add_to_front(array(
|
||||||
|
array( 'css' => 'div#cipf_prof_carte_renouvellement {display: block;}' ),
|
||||||
|
array( 'css' => 'div#cipf_prof_carte_commande {display: none;}' ),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
add_action('wp_enqueue_scripts', 'renew_page_filter_message_CIPF');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
49
plugins/cipf_plugin/php/reset_card_form.php
Normal file
49
plugins/cipf_plugin/php/reset_card_form.php
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* it means someone outside wp is accessing the file, in this case kill it.
|
||||||
|
*/
|
||||||
|
if (!defined('ABSPATH')) {
|
||||||
|
die('You can not access this file!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* NOT USEFUL ANYMORE :
|
||||||
|
* it was to fix pbms in formbuilder with calculation field
|
||||||
|
* but I made 2 better fixes (css and js)
|
||||||
|
*
|
||||||
|
* reset some fields for the form to buy the card
|
||||||
|
* - cgv
|
||||||
|
* - paiement
|
||||||
|
* - livraison
|
||||||
|
* - tarif
|
||||||
|
* this action is called after redirection hook
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function reset_some_fields_CIPF() {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
$slug_renew_card = PLGNTLS_class::SLUG_RENEW_CARD;
|
||||||
|
$acf_cgv = PLGNTLS_class::ACF_PROF_CGV;
|
||||||
|
$acf_payement = PLGNTLS_class::ACF_CARD_PAYMENT_METHOD;
|
||||||
|
$acf_delivery = PLGNTLS_class::ACF_CARD_PRICE_DELIVERY;
|
||||||
|
$acf_price = PLGNTLS_class::ACF_CARD_PRICE_CHOICE;
|
||||||
|
|
||||||
|
if (!is_page($slug_renew_card))
|
||||||
|
return;
|
||||||
|
|
||||||
|
$user_id = get_current_user_id();
|
||||||
|
update_field($acf_cgv['_name'] , array(""), 'user_'.$user_id);
|
||||||
|
update_field($acf_payement['_name'], array(""), 'user_'.$user_id);
|
||||||
|
update_field($acf_delivery['_name'], array(""), 'user_'.$user_id);
|
||||||
|
update_field($acf_price['_name'] , array(""), 'user_'.$user_id);
|
||||||
|
}
|
||||||
|
add_action('wp', 'reset_some_fields_CIPF');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
170
plugins/cipf_plugin/php/user_infos.php
Normal file
170
plugins/cipf_plugin/php/user_infos.php
Normal file
@@ -0,0 +1,170 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* it means someone outside wp is accessing the file, in this case kill it.
|
||||||
|
*/
|
||||||
|
if (!defined('ABSPATH')) {
|
||||||
|
die('You can not access this file!');
|
||||||
|
}
|
||||||
|
|
||||||
|
include_once(PLGNTLS_class::root_path() . 'php/format_user_infos.php');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function extract_if_array_size_one_CIPF($value) {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
if (is_array($value) && count($value) === 1)
|
||||||
|
return reset($value);
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
function merge_two_arrays_CIPF($array1, $array2) {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
$new_array = $array1;
|
||||||
|
foreach ($array2 as $key2 => $value2) {
|
||||||
|
$value = extract_if_array_size_one_CIPF($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_CIPF($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_CIPF($array, $current_user, $user_id) {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
$output = '<ul>';
|
||||||
|
foreach ($array as $key => $value) {
|
||||||
|
if (str_starts_with($key, '_'))
|
||||||
|
continue ;
|
||||||
|
$value = format_user_info_CIPF($key, $current_user, $user_id);
|
||||||
|
$output .= '<li>';
|
||||||
|
$output .= '<span>';
|
||||||
|
$output .= $key;
|
||||||
|
$output .= ' : ';
|
||||||
|
$output .= $value;
|
||||||
|
$output .= '</span>';
|
||||||
|
$output .= '</li>';
|
||||||
|
}
|
||||||
|
$output .= '</ul>';
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* shortcode to write user info of post author
|
||||||
|
* 0 or 1 argument, usage :
|
||||||
|
* - [cipf_user_info] -> list of all availables infos
|
||||||
|
* - [cipf_user_info user_email] -> display the email
|
||||||
|
* - [cipf_user_info user_email user_login] -> display the email
|
||||||
|
* - [cipf_user_info user_email author='logged_in'] -> display the email of the connected user
|
||||||
|
* - [cipf_user_info user_email author='post_creator'] -> display the email of the creator of the page/post
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function current_user_infos_CIPF($atts) {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
if (!is_user_logged_in())
|
||||||
|
return ;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* choose the default id target : logged in user, or post creator ?
|
||||||
|
*
|
||||||
|
$author_is = 'logged_in'; // logged in user
|
||||||
|
*/
|
||||||
|
$author_is = 'post_creator'; // creator of post (also for author pages)
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* has parameter 'author' ?
|
||||||
|
* if yes, removes it from $atts
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if (is_array($atts)) {
|
||||||
|
if (isset($atts['author'])) {
|
||||||
|
$author_is = $atts['author'];
|
||||||
|
unset($atts['author']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* should output all or a specific parameter ?
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
$output_all = false;
|
||||||
|
if (empty($atts))
|
||||||
|
$output_all = true;
|
||||||
|
else if (count($atts) === 0)
|
||||||
|
$output_all = true;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* get author id outside loop and outside singular page : https://wordpress.stackexchange.com/q/65548
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if ($author_is === 'logged_in') {
|
||||||
|
$current_user = wp_get_current_user();
|
||||||
|
$user_id = get_current_user_id();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (is_author()) {
|
||||||
|
$user_id = get_queried_object_id();
|
||||||
|
}
|
||||||
|
else if (in_the_loop()) {
|
||||||
|
$user_id = get_the_author_meta('ID');
|
||||||
|
}
|
||||||
|
else if (is_singular()) {
|
||||||
|
$user_id = get_queried_object()->post_author;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
global $wp_query;
|
||||||
|
if (!empty($wp_query->posts))
|
||||||
|
$user_id = $wp_query->posts[0]->post_author;
|
||||||
|
}
|
||||||
|
//$current_user = new WP_User($user_id);
|
||||||
|
$current_user = get_user_by('id', $user_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* output all the available parameters (for help)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if ($output_all) {
|
||||||
|
$user_properties = (array) get_userdata($user_id)->data;
|
||||||
|
$user_metas = get_user_meta($user_id);
|
||||||
|
$user_infos = merge_two_arrays_CIPF($user_metas, $user_properties);
|
||||||
|
return output_list_front_CIPF($user_infos, $current_user, $user_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* real purpose of this shortcode :
|
||||||
|
* only return the first argument (that is not 'author')
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if (is_array($atts))
|
||||||
|
$query = $atts[0];
|
||||||
|
else if (is_string($atts))
|
||||||
|
$query = $atts;
|
||||||
|
else
|
||||||
|
return '';
|
||||||
|
// $output = $current_user->$query;
|
||||||
|
return format_user_info_CIPF($query, $current_user, $user_id);
|
||||||
|
}
|
||||||
|
add_shortcode('cipf_user_info', 'current_user_infos_CIPF');
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
68
plugins/cipf_plugin/php/utils/globals.php
Normal file
68
plugins/cipf_plugin/php/utils/globals.php
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* it means someone outside wp is accessing the file, in this case kill it.
|
||||||
|
*/
|
||||||
|
if (!defined('ABSPATH')) {
|
||||||
|
die('You can not access this file!');
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* globals variables
|
||||||
|
* const vs define : https://stackoverflow.com/questions/2447791/php-define-vs-const
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* switch console_log
|
||||||
|
const CONSOLE_OFF = true;
|
||||||
|
*/
|
||||||
|
const CIPF_CONSOLE_OFF = false;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* paypal credentials
|
||||||
|
*
|
||||||
|
* LIVE :
|
||||||
|
*
|
||||||
|
* const PAYPAL_CLIENT_ID = "Aedn5e8z__hPBvKirqw5bwlhI9ChG8_N6c1xbgybYyBr4B4oP8uVzmVdH1QVKdPQKf6bWg7orPV4PDrO";
|
||||||
|
* const PAYPAL_CLIENT_SECRET = "EGeGwfHGxHxsjnC-tH8W0IL4nN3_xlc3sXFRPCQOw5uUoWae3eOgghuDKMnZc5DVGTbP6yIjVJ1BaAra";
|
||||||
|
*
|
||||||
|
* SANBOX :
|
||||||
|
*
|
||||||
|
* const PAYPAL_CLIENT_ID = "AfcmwxIXlG2ZxaMdjazX57I70BXz__aEqNWaTnqfSCI34a0V7nMbytswx7EViUjlpHs7opyrRwaH9YLl";
|
||||||
|
* const PAYPAL_CLIENT_SECRET = "EGunIhGRjPvn0Z8wXO0JsdhET30OStTAH_IyRsmhimEN23_qiRSFD-ql4tvnulKJw6TitZ-vU-ytc4A-";
|
||||||
|
*
|
||||||
|
const PAYPAL_CLIENT_ID = "AfcmwxIXlG2ZxaMdjazX57I70BXz__aEqNWaTnqfSCI34a0V7nMbytswx7EViUjlpHs7opyrRwaH9YLl";
|
||||||
|
const PAYPAL_CLIENT_SECRET = "EGunIhGRjPvn0Z8wXO0JsdhET30OStTAH_IyRsmhimEN23_qiRSFD-ql4tvnulKJw6TitZ-vU-ytc4A-";
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* paypal api base url
|
||||||
|
const PAYPAL_API_BASE_URL = "https://api-m.sandbox.paypal.com";
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* paypal messages
|
||||||
|
* put the message betweeen backticks `message` and then between single quotes '`message`'
|
||||||
|
* because it will be evaluated in front by js, so it need something to evaluate, in ``
|
||||||
|
* you can then use variables available in the context of execution : '`Transaction ${transaction.status}`'
|
||||||
|
* is it good strategy ? idk
|
||||||
|
|
||||||
|
const PAYPAL_MESSAGE_SUCCESS = '`Transaction ${transaction.status}: ${transaction.id}<br><br>See console for all available details`';
|
||||||
|
const PAYPAL_MESSAGE_FAILURE = '`Sorry, your transaction could not be processed...<br><br>${error}`';
|
||||||
|
|
||||||
|
const PAYPAL_MESSAGE_SUCCESS = '`paiement reussi`';
|
||||||
|
const PAYPAL_MESSAGE_FAILURE = '`paiement raté`';
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* acf fields for card :
|
||||||
|
* - card_is_valid : has valid card
|
||||||
|
* - card_date_purchase : date of purchase
|
||||||
|
* - card_date_validity : date end of validity
|
||||||
|
const CARD_IS_VALID = 'carte_est_valide';
|
||||||
|
const CARD_DATE_PURCHASE = 'date_d_achat';
|
||||||
|
const CARD_DATE_VALIDITY = 'date_fin_validite';
|
||||||
|
*/
|
||||||
|
|
||||||
|
?>
|
||||||
30
plugins/cipf_plugin/php/utils/http_errors.php
Normal file
30
plugins/cipf_plugin/php/utils/http_errors.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* it means someone outside wp is accessing the file, in this case kill it.
|
||||||
|
*/
|
||||||
|
if (!defined('ABSPATH')) {
|
||||||
|
die('You can not access this file!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Define a custom exception class for HTTP errors
|
||||||
|
class HttpException extends Exception {
|
||||||
|
// HTTP status code
|
||||||
|
private $statusCode;
|
||||||
|
|
||||||
|
public function __construct($message, $statusCode) {
|
||||||
|
parent::__construct($message);
|
||||||
|
$this->statusCode = $statusCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getStatusCode() {
|
||||||
|
return $this->statusCode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
27
plugins/cipf_plugin/utils/console_log.php
Normal file
27
plugins/cipf_plugin/utils/console_log.php
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* it means someone outside wp is accessing the file, in this case kill it.
|
||||||
|
*/
|
||||||
|
if (!defined('ABSPATH')) {
|
||||||
|
die('You can not access this file!');
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
https://stackify.com/how-to-log-to-console-in-php/
|
||||||
|
*/
|
||||||
|
function console_log(...$outputs) {
|
||||||
|
PLGNTLS_class::debug_infos();
|
||||||
|
if (CIPF_CONSOLE_OFF)
|
||||||
|
return;
|
||||||
|
foreach($outputs as $output)
|
||||||
|
{
|
||||||
|
$json_output = json_encode($output, JSON_HEX_TAG);
|
||||||
|
$js_code = '<script>console.log(' . $json_output . ');</script>';
|
||||||
|
echo $js_code;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
573
plugins/cipf_plugin/utils/plgntls_class.php
Normal file
573
plugins/cipf_plugin/utils/plgntls_class.php
Normal file
@@ -0,0 +1,573 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* it means someone outside wp is accessing the file, in this case kill it.
|
||||||
|
*/
|
||||||
|
if (!defined('ABSPATH')) {
|
||||||
|
die('You can not access this file!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* include those two lines at the top of the main plugin file
|
||||||
|
*
|
||||||
|
* include_once( plugin_dir_path(__FILE__) . '/php/utils/plugin_tools.php');
|
||||||
|
* PLGNTLS_class::set_root_dir( plugin_dir_path(__FILE__), plugin_dir_url(__FILE__) );
|
||||||
|
*
|
||||||
|
* PLGNTLS means PLUGIN TOOLS
|
||||||
|
*
|
||||||
|
* .add_to_front() : this method is made to add files and codes all at once
|
||||||
|
* otherwise use the wp functions (wp_enqueue_*, wp_add_inline_*, etc)
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* ex:
|
||||||
|
*
|
||||||
|
* $my_plugin_class = new PLGNTLS_class();
|
||||||
|
* $var_1 = 'value_1';
|
||||||
|
* $var_2 = 'value_2';
|
||||||
|
* $var_3 = 'value_3';
|
||||||
|
* return $my_plugin_class->add_to_front(
|
||||||
|
* array( // files added in order by types
|
||||||
|
* 'path/to/style1.css', //
|
||||||
|
* 'path/to/script1.js', //
|
||||||
|
* 'style1_css' => 'path/to/style2.css', // -> depends on style1.css
|
||||||
|
* 'http://my_url1.com', //
|
||||||
|
* 'script1_js' => 'path/to/script2.js', // -> depends on script1.js
|
||||||
|
* 'path/to/file1.html', // | will be returned
|
||||||
|
* 'path/to/file2.html', // -> | as expanded html
|
||||||
|
* 'path/to/file3.html', // | in the order included
|
||||||
|
* 'handle_name' => 'path/to/script3.js', // -> depends on the script with handle 'handle_name'
|
||||||
|
* array( //
|
||||||
|
* 'path/to/script4.js', // | add a script with attributes
|
||||||
|
* 'attribute_1' => 'value_1', // -> | first element of array must be
|
||||||
|
* 'attribute_2' => 'value_2', // | the script, without explicit key
|
||||||
|
* ), //
|
||||||
|
* array( 'js' => 'var_js' ), // -> add inline js, only first element will be used
|
||||||
|
* array( 'css' => 'var_css' ), // -> add inline css, only first element will be used
|
||||||
|
* ),
|
||||||
|
* compact( // these variables are added to html and js files
|
||||||
|
* 'var_1', // - in html files you can access them directly
|
||||||
|
* 'var_2', // - in js files they are properties of object PLGNTLS_data
|
||||||
|
* 'var_3', // like PLGNTLS_data.var_1;
|
||||||
|
* )
|
||||||
|
* );
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
class PLGNTLS_class
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* const declarations
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
// ACF
|
||||||
|
const ACF_CARD_STATE = ['_name'=>'etat_carte', 'new'=>'Commande', 'renew'=>'Renouvellement']; // radio button
|
||||||
|
const ACF_CARD_PAYMENT_METHOD = ['_name'=>'paiement', 'paypal'=>'Paypal', 'transfert'=>'Virement']; // radio button
|
||||||
|
const ACF_CARD_PRICE_CHOICE = ['_name'=>'tarif', 'low'=>'10', 'high'=>'15']; // radio button
|
||||||
|
const ACF_CARD_PRICE_DELIVERY = ['_name'=>'livraison', 'pdf'=>'PDF', 'post'=>'Fabrication']; // radio button
|
||||||
|
const ACF_PROF_IS_ACTIV = ['_name'=>'compte-actif', 'activ'=>'Actif', 'inactiv'=>'Inactif']; // radio button
|
||||||
|
const ACF_PROF_CGV = ['_name'=>'cgv', 'cgv'=>'cgv']; // checkbox
|
||||||
|
const ACF_CARD_PRICE_TOTAL = ['_name'=>'somme_a_regler']; // number
|
||||||
|
const ACF_CARD_NUMBER = ['_name'=>'numero_de_la_carte']; // number
|
||||||
|
const ACF_CARD_EXPIRATION = ['_name'=>'fin_de_validite']; // date picker
|
||||||
|
const ACF_CARD_PAYMENT_STATE = ['_name'=>'etat_paiement', 'started'=>'en_cours', 'success'=>'reussi', 'failure'=>'echec', 'nothing'=>'aucun']; // radio button
|
||||||
|
|
||||||
|
// META
|
||||||
|
const META_PAYEMENT_STATUS = 'cipf_payement_status';
|
||||||
|
const META_ORDER_ID = 'cipf_order_id';
|
||||||
|
|
||||||
|
// SLUG & URL & QUERY
|
||||||
|
const SLUG_PROF_INACTIV = 'validation-en-cours';
|
||||||
|
const SLUG_RENEW_CARD = 'commande';
|
||||||
|
const SLUG_PAGE_REDIRECTION = 'redirection_cipf';
|
||||||
|
// const SLUG_PAYPAL_REDIRECTION_SUCCESS = self::SLUG_PAGE_REDIRECTION;
|
||||||
|
// const SLUG_PAYPAL_REDIRECTION_FAILURE = self::SLUG_PAGE_REDIRECTION;
|
||||||
|
const SLUG_PAYPAL_REDIRECTION_SUCCESS = '?'.self::QUERY_REDIRECTION_PROFIL;
|
||||||
|
const SLUG_PAYPAL_REDIRECTION_FAILURE = '?'.self::QUERY_REDIRECTION_PROFIL;
|
||||||
|
const URL_BASE_REST_ROUTE = 'cipf_plugin/api/v1'; // for routes, in php/paypal/routes.php && php/admin_modif_prof.php
|
||||||
|
const QUERY_REDIRECTION_PROFIL = 'redirection_cipf';
|
||||||
|
const QUERY_ADMIN_VALIDATE_PROF = 'admin_activate_prof_cipf'; // for admin_modif_prof.php
|
||||||
|
|
||||||
|
// PAYPAL
|
||||||
|
const PAYPAL_CLIENT_ID = "AfcmwxIXlG2ZxaMdjazX57I70BXz__aEqNWaTnqfSCI34a0V7nMbytswx7EViUjlpHs7opyrRwaH9YLl";
|
||||||
|
const PAYPAL_CLIENT_SECRET = "EGunIhGRjPvn0Z8wXO0JsdhET30OStTAH_IyRsmhimEN23_qiRSFD-ql4tvnulKJw6TitZ-vU-ytc4A-";
|
||||||
|
const PAYPAL_API_BASE_URL = "https://api-m.sandbox.paypal.com";
|
||||||
|
const PAYPAL_MESSAGE_SUCCESS = '`paiement reussi`';
|
||||||
|
const PAYPAL_MESSAGE_FAILURE = '`paiement raté`';
|
||||||
|
|
||||||
|
// ROLES
|
||||||
|
const ROLE_PROF = 'professeur__professeure';
|
||||||
|
const ROLE_PARTNER = 'partenaire';
|
||||||
|
const ROLE_FIPF = 'fipf';
|
||||||
|
const ROLE_ADMIN = 'administrator';
|
||||||
|
|
||||||
|
// OTHER
|
||||||
|
const CARD_RENEW_PERIOD = 31; // int : number of days before expiration when renew card start to be possible
|
||||||
|
const CARD_VALIDITY_TIME = '1 year'; // string : time of validity of the card (ex: '1 month' or '1 year' or '60 days')
|
||||||
|
const USER_INFO_DATE_FORMAT = 'd/m/Y'; // for user_infos.php (date format : https://www.php.net/manual/fr/datetime.format.php)
|
||||||
|
const ADMIN_VALIDATE_PROF_FIELD = 'admin_activate_prof_cipf'; // for admin_modif_prof.php
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private static $_DEBUG_INFOS = true;
|
||||||
|
private static $_plugin_dir_path;
|
||||||
|
private static $_plugin_name;
|
||||||
|
private static $_file_dir_path;
|
||||||
|
private static $_file_name;
|
||||||
|
private static $_root_path;
|
||||||
|
private static $_root_url;
|
||||||
|
|
||||||
|
private $_first_script;
|
||||||
|
private $_first_style;
|
||||||
|
private $_prefix;
|
||||||
|
private $_js_dependencies;
|
||||||
|
private $_css_dependencies;
|
||||||
|
private $_scripts_attributes;
|
||||||
|
|
||||||
|
/*
|
||||||
|
*/
|
||||||
|
public function __construct() {
|
||||||
|
if (!isset(self::$_plugin_name, self::$_file_name, self::$_file_dir_path, self::$_plugin_dir_path))
|
||||||
|
self::set_root_dir();
|
||||||
|
$this->_prefix = "PLGNTLS";
|
||||||
|
$this->_first_script = null;
|
||||||
|
$this->_first_style = null;
|
||||||
|
$this->_js_dependencies = array();
|
||||||
|
$this->_css_dependencies = array();
|
||||||
|
$this->_scripts_attributes = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ex:
|
||||||
|
* /home/www-data/cipf_plugin/php/test/test2/test3/test.php
|
||||||
|
* _plugin_dir_path /home/www-data
|
||||||
|
* _plugin_name cipf_plugin
|
||||||
|
* _file_dir_path php/test/test2/test3
|
||||||
|
* _file_name test.php
|
||||||
|
* _root_path /home/www-data/cipf_plugin/
|
||||||
|
*
|
||||||
|
* /home/www-data/cipf_plugin/test.php
|
||||||
|
* _plugin_dir_path /home/www-data
|
||||||
|
* _plugin_name cipf_plugin
|
||||||
|
* _file_dir_path ''
|
||||||
|
* _file_name test.php
|
||||||
|
* _root_path /home/www-data/cipf_plugin/
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static function set_root_dir() {
|
||||||
|
if (isset(self::$_plugin_name, self::$_file_name, self::$_file_dir_path, self::$_plugin_dir_path))
|
||||||
|
return ;
|
||||||
|
/*
|
||||||
|
* it uses exploded_path_path by removing data from the array
|
||||||
|
* so order is important !
|
||||||
|
* plugin_name / path / to / file.php
|
||||||
|
* exploded [plugin_name, path, to, file.php]
|
||||||
|
* plugin_name plugin_name [path, to, file.php]
|
||||||
|
* file_name [path, to] file.php
|
||||||
|
* file_dir_name path / to
|
||||||
|
*/
|
||||||
|
$exploded_plugin_path = explode('/', plugin_basename( __FILE__ ));
|
||||||
|
|
||||||
|
self::$_plugin_name = array_shift($exploded_plugin_path);
|
||||||
|
self::$_file_name = array_pop($exploded_plugin_path);
|
||||||
|
self::$_file_dir_path = implode('/', $exploded_plugin_path);
|
||||||
|
|
||||||
|
self::$_plugin_dir_path = str_replace('/'.plugin_basename(__DIR__).'/', '', plugin_dir_path(__FILE__));
|
||||||
|
self::$_root_path = self::$_plugin_dir_path.'/'.self::$_plugin_name.'/';
|
||||||
|
self::$_root_url = plugins_url(self::$_plugin_name.'/');
|
||||||
|
}
|
||||||
|
public static function root_path() {
|
||||||
|
if (!isset(self::$_plugin_name, self::$_file_name, self::$_file_dir_path, self::$_plugin_dir_path))
|
||||||
|
self::set_root_dir();
|
||||||
|
return(self::$_root_path);
|
||||||
|
}
|
||||||
|
public static function root_url() {
|
||||||
|
if (!isset(self::$_plugin_name, self::$_file_name, self::$_file_dir_path, self::$_plugin_dir_path))
|
||||||
|
self::set_root_dir();
|
||||||
|
return(self::$_root_url);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* for debug purposes
|
||||||
|
*/
|
||||||
|
public static function debug_infos() {
|
||||||
|
if (self::$_DEBUG_INFOS === false)
|
||||||
|
return;
|
||||||
|
$trace = debug_backtrace();
|
||||||
|
$function = $trace[1]['function'];
|
||||||
|
$file = $trace[0]['file'];
|
||||||
|
$line = $trace[0]['line'];
|
||||||
|
error_log("-debug: function '".$function."' (in ".$file.", line ".$line .')');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function add_to_front($srcs_arr = array(), $vars = array()) {
|
||||||
|
/*
|
||||||
|
* event if the function is called with no srcs
|
||||||
|
* add fetch, because it can be used just for that
|
||||||
|
*/
|
||||||
|
$this->add_fetch($srcs_arr, $vars);
|
||||||
|
$this->add_default_css($srcs_arr, $vars);
|
||||||
|
|
||||||
|
$srcs = array();
|
||||||
|
foreach($srcs_arr as $src_key => $src_value) {
|
||||||
|
$init = $this->init_src($src_key, $src_value);
|
||||||
|
if ($init !== null)
|
||||||
|
$srcs[] = $init;
|
||||||
|
}
|
||||||
|
if (!is_null($srcs_arr))
|
||||||
|
$this->add_srcs_to_front($srcs);
|
||||||
|
|
||||||
|
if (!is_null($vars))
|
||||||
|
$this->add_vars_to_front($vars);
|
||||||
|
return $this->create_html($srcs, $vars);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* PRIVATES FUNCTIONS
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* for fetch, we add the file script that contains the fetch function
|
||||||
|
* it is an es6 module with the export keyword
|
||||||
|
* that way, it can also be used by modules scripts
|
||||||
|
* to achieve that, we wouldn't need to include it here though
|
||||||
|
* but we need that the fetch function is also available for inline scripts
|
||||||
|
* so we could attach a copy of the script file without the export keyword
|
||||||
|
* but instead, inside the file, we add the fetch function to the global scope
|
||||||
|
*/
|
||||||
|
private function add_fetch(&$srcs_arr, &$vars) {
|
||||||
|
// add fetch script at beginning of scripts list
|
||||||
|
array_unshift($srcs_arr, array(self::$_file_dir_path."/plgntls_fetch.js", 'type'=>'module'));
|
||||||
|
// for the custom endpoints in rest api to work
|
||||||
|
// they need to have a nonce named 'wp_rest'
|
||||||
|
// see : https://developer.wordpress.org/rest-api/using-the-rest-api/authentication/
|
||||||
|
$fetch_nonce = array("fetch_nonce" => wp_create_nonce('wp_rest'));
|
||||||
|
$fetch_url = array("fetch_url" => get_site_url() . "/wp-json");
|
||||||
|
$vars = array_merge($vars, $fetch_nonce);
|
||||||
|
$vars = array_merge($vars, $fetch_url);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function add_default_css(&$srcs_arr, &$vars) {
|
||||||
|
// add default css file at beginning of style list
|
||||||
|
array_unshift($srcs_arr, self::$_file_dir_path."/plgntls_default.css");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @param two arguments :
|
||||||
|
* 1. html files to include in front
|
||||||
|
* - can be a string of 1 filename
|
||||||
|
* - or an array of strings of filenames
|
||||||
|
* ( https://stackoverflow.com/q/4747876/9497573 )
|
||||||
|
* - it's probably better to only add 1 file, and let it include other files
|
||||||
|
* 2. list of variables to make available to this files
|
||||||
|
* - in the form of key => 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
|
||||||
|
*/
|
||||||
|
private function create_html($files = null, $vars = null) {
|
||||||
|
if (is_null($files))
|
||||||
|
return null;
|
||||||
|
$plgn_dir = $this->root_path();
|
||||||
|
if (!is_null($vars))
|
||||||
|
extract($vars);
|
||||||
|
|
||||||
|
ob_start();
|
||||||
|
foreach($files as $file) {
|
||||||
|
if ($file->ext === 'html')
|
||||||
|
include($file->path);
|
||||||
|
}
|
||||||
|
$html = ob_get_clean();
|
||||||
|
|
||||||
|
return $html;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
private function add_vars_to_front($vars_arr)
|
||||||
|
{
|
||||||
|
if (is_null($this->_first_script))
|
||||||
|
return ;
|
||||||
|
if (is_null($vars_arr))
|
||||||
|
return ;
|
||||||
|
$handle = $this->_first_script;
|
||||||
|
$object_name = $this->_prefix . "_data";
|
||||||
|
|
||||||
|
$vars_json = json_encode($vars_arr);
|
||||||
|
$front = "let $object_name = $vars_json;";
|
||||||
|
wp_add_inline_script($handle, $front, 'before');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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
|
||||||
|
*/
|
||||||
|
private function add_srcs_to_front($srcs_arr) {
|
||||||
|
//wp_enqueue_script(<give_it_a_name>, /url/to/script, [depends on], version, defer? );
|
||||||
|
//wp_enqueue_style( <give_it_a_name>, /url/to/script, [depends on], version, media );
|
||||||
|
|
||||||
|
$previous_css_basename = '';
|
||||||
|
$previous_js_basename = '';
|
||||||
|
foreach ($srcs_arr as $src) {
|
||||||
|
if ($src->inline !== null) {
|
||||||
|
if ($src->inline === "js")
|
||||||
|
$this->add_inline_script($src);
|
||||||
|
else if ($src->inline === "css")
|
||||||
|
$this->add_inline_style($src);
|
||||||
|
}
|
||||||
|
else if (in_array($src->ext, array("js", "url"))) {
|
||||||
|
$this->add_script($src, $previous_js_basename);
|
||||||
|
$previous_js_basename = $src->handle;
|
||||||
|
}
|
||||||
|
else if ($src->ext === "css") {
|
||||||
|
$this->add_style($src, $previous_css_basename);
|
||||||
|
$previous_css_basename = $src->handle;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://developer.wordpress.org/reference/hooks/wp_script_attributes/
|
||||||
|
// https://wordpress.stackexchange.com/questions/66843/attach-a-private-function-at-a-hook
|
||||||
|
add_filter( 'wp_script_attributes', fn($attr)=>$this->add_attributes_to_script($attr), 10, 1 );
|
||||||
|
|
||||||
|
/*
|
||||||
|
* uncomment to print all enqueued files, can be usefull
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
global $wp_scripts;
|
||||||
|
error_log("wp_scripts->queue:");
|
||||||
|
error_log(json_encode($wp_scripts->queue));
|
||||||
|
global $wp_styles;
|
||||||
|
error_log("wp_styles->queue:");
|
||||||
|
error_log(json_encode($wp_styles->queue));
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
private function add_script($script, $previous_js_basename) {
|
||||||
|
if (is_null($this->_first_script))
|
||||||
|
$this->_first_script = $script->handle;
|
||||||
|
$depends_on = $this->check_dependencies($script, $previous_js_basename);
|
||||||
|
if ($depends_on !== null)
|
||||||
|
wp_enqueue_script( $script->handle, $script->url, $depends_on, $script->version, true);
|
||||||
|
}
|
||||||
|
private function add_style($style, $previous_css_basename) {
|
||||||
|
if (is_null($this->_first_style))
|
||||||
|
$this->_first_style = $style->handle;
|
||||||
|
$depends_on = $this->check_dependencies($style, $previous_css_basename);
|
||||||
|
if ($depends_on !== null)
|
||||||
|
wp_enqueue_style( $style->handle, $style->url, $depends_on, $style->version, '');
|
||||||
|
}
|
||||||
|
private function add_inline_script($src) {
|
||||||
|
$handle = $src->depends;
|
||||||
|
if ($handle === null || empty($handle))
|
||||||
|
$handle = $this->_first_script;
|
||||||
|
wp_add_inline_script($handle, $src->src, 'before');
|
||||||
|
}
|
||||||
|
private function add_inline_style($src) {
|
||||||
|
$handle = $src->depends;
|
||||||
|
if ($handle === null || empty($handle))
|
||||||
|
$handle = $this->_first_style;
|
||||||
|
wp_add_inline_style($handle, $src->src);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private function add_attributes_to_script($attr) {
|
||||||
|
if (empty($attr['id']))
|
||||||
|
return $attr;
|
||||||
|
$handle = $attr['id'];
|
||||||
|
if (isset($this->_scripts_attributes[$handle]))
|
||||||
|
$script = $this->_scripts_attributes[$handle];
|
||||||
|
else
|
||||||
|
return $attr;
|
||||||
|
|
||||||
|
foreach($script as $key => $value){
|
||||||
|
$attr[$key] = $value;
|
||||||
|
}
|
||||||
|
unset($this->_scripts_attributes[$handle]);
|
||||||
|
|
||||||
|
return $attr;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function check_dependencies(&$src, $previous_basename)
|
||||||
|
{
|
||||||
|
if (in_array($src->ext, array("js", "url")))
|
||||||
|
{
|
||||||
|
global $wp_scripts;
|
||||||
|
$already_enqueued = array_search($src->handle, $wp_scripts->queue);
|
||||||
|
if ($already_enqueued !== false)
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
else if ($src->ext === "css")
|
||||||
|
{
|
||||||
|
global $wp_styles;
|
||||||
|
$already_enqueued = array_search($src->handle, $wp_styles->queue);
|
||||||
|
if ($already_enqueued !== false)
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$depends_on = array();
|
||||||
|
if (isset($src->depends) && $src->depends !== '')
|
||||||
|
$depends_on[] = $src->depends;
|
||||||
|
if (isset($previous_basename) && $previous_basename !== '')
|
||||||
|
$depends_on[] = $previous_basename;
|
||||||
|
|
||||||
|
return $depends_on;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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 valid
|
||||||
|
* - or an object with all the necessary infos :
|
||||||
|
* 0. src : array("name.js", ...) -> "name.js"
|
||||||
|
* "name.js" -> "name.js"
|
||||||
|
* 1. ext : name.js -> "js"
|
||||||
|
* 2. basename : name.js -> "name"
|
||||||
|
* 3. handle : name.js -> "name_js"
|
||||||
|
* 4. url : url to file in wordpress
|
||||||
|
* 5. path : path to file in server
|
||||||
|
* 6. version : used to avoid browser caching
|
||||||
|
* 7. depends : string if depends on a handle, or ''
|
||||||
|
* 8. attr : associative array of html attribute like 'type'=>'module'
|
||||||
|
* 9. inline : array("js" => "name.js") -> js
|
||||||
|
* array("css" => "name.css") -> css
|
||||||
|
*/
|
||||||
|
private function init_src($key, $value) {
|
||||||
|
if (empty($value))
|
||||||
|
return null;
|
||||||
|
$src = (object)[
|
||||||
|
'src' => null,
|
||||||
|
'ext' => null,
|
||||||
|
'basename' => null,
|
||||||
|
'handle' => null,
|
||||||
|
'url' => null,
|
||||||
|
'path' => null,
|
||||||
|
'version' => null,
|
||||||
|
'depends' => null,
|
||||||
|
'attr' => null,
|
||||||
|
'inline' => null,
|
||||||
|
];
|
||||||
|
|
||||||
|
// 7. depends
|
||||||
|
if (is_string($key))
|
||||||
|
$src->depends = $key;
|
||||||
|
|
||||||
|
// 0. src
|
||||||
|
// 8. attr
|
||||||
|
// 9. inline
|
||||||
|
// first element of array is used, so must not be empty
|
||||||
|
// value => ['path/to/file', 'key1'=>'value1', 'key2'=>'value2']
|
||||||
|
// src => 'path/to/file'
|
||||||
|
// attr => ['key1'=>'value1', 'key2'=>'value2']
|
||||||
|
if (is_array($value)){
|
||||||
|
$first_key = array_keys($value)[0];
|
||||||
|
if (empty($value[$first_key]))
|
||||||
|
return null;
|
||||||
|
if ($first_key === 0) { // is a script file or url with attributes
|
||||||
|
$src->src = array_shift($value);
|
||||||
|
$src->attr = $value;
|
||||||
|
}
|
||||||
|
else if ($first_key === "js" || $first_key === "css") { // is an inline code
|
||||||
|
$src->src = $value[$first_key];
|
||||||
|
$src->inline = $first_key;
|
||||||
|
return $src; // inline only needs 'depends', 'src' and 'inline'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$src->src = $value;
|
||||||
|
$src->attr = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1. ext
|
||||||
|
if(filter_var($src->src, FILTER_VALIDATE_URL))
|
||||||
|
$src->ext = "url";
|
||||||
|
else
|
||||||
|
$src->ext = pathinfo($src->src, PATHINFO_EXTENSION);
|
||||||
|
if (! in_array($src->ext, array("js", "css", "html", "url")))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
// 2. basename
|
||||||
|
// 3. handle
|
||||||
|
// basename handle
|
||||||
|
// https://www.url.com/route -> www.url.com/route -> www_url_com_route
|
||||||
|
// path/to/script.js -> script.js -> script_js
|
||||||
|
if ($src->ext === "url") {
|
||||||
|
$url = parse_url($src->src);
|
||||||
|
$src->basename = $url['host'] . $url['path'];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
$src->basename = pathinfo($src->src, PATHINFO_BASENAME);
|
||||||
|
$src->handle = "PLGNTLS_" . str_replace(array('.', '/'), "_", $src->basename);
|
||||||
|
|
||||||
|
// 4. url
|
||||||
|
// 5. path
|
||||||
|
// 6. version
|
||||||
|
if ($src->ext === "url") {
|
||||||
|
$src->url = $src->src;
|
||||||
|
$src->path = null;
|
||||||
|
$src->version = null;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$src->url = $this->root_url().$src->src;
|
||||||
|
$src->path = $this->root_path().$src->src;
|
||||||
|
$src->version = date("ymd-Gis", filemtime($src->path));
|
||||||
|
}
|
||||||
|
|
||||||
|
// if ext is 'js' or 'url' and attr is not empty
|
||||||
|
// also add to global variable to access in 'wp_script_attributes' filter
|
||||||
|
if ($src->ext === 'js' || $src->ext === 'url') {
|
||||||
|
if ($src->attr !== null) {
|
||||||
|
$this->_scripts_attributes[$src->handle.'-js'] = $src->attr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $src;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
4
plugins/cipf_plugin/utils/plgntls_default.css
Normal file
4
plugins/cipf_plugin/utils/plgntls_default.css
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
/*
|
||||||
|
* this css file will be automatically added to front by PLGNTLS_class
|
||||||
|
* no need to write any style here, but you can if you want
|
||||||
|
*/
|
||||||
24
plugins/cipf_plugin/utils/plgntls_fetch.js
Normal file
24
plugins/cipf_plugin/utils/plgntls_fetch.js
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
|
||||||
|
/*
|
||||||
|
* this file is there for scripts that uses modules import
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
export function PLGNTLS_fetch(url, options = {}) {
|
||||||
|
console.log("inside PLGNTLS_fetch");
|
||||||
|
url = PLGNTLS_data.fetch_url + url;
|
||||||
|
|
||||||
|
options.headers = options.headers || {};
|
||||||
|
options.headers['X-WP-Nonce'] = PLGNTLS_data.fetch_nonce,
|
||||||
|
console.log("options:", options);
|
||||||
|
|
||||||
|
return fetch(url, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* For non-module scripts, attach to the global scope
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if (typeof window !== 'undefined') {
|
||||||
|
window.PLGNTLS_fetch = PLGNTLS_fetch;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
.first_el_to_change {
|
|
||||||
border: 1px solid red;
|
|
||||||
}
|
|
||||||
#model_plugin_shortcode {
|
|
||||||
border: 1px solid blue;
|
|
||||||
padding: 10px;
|
|
||||||
}
|
|
||||||
@@ -1,391 +0,0 @@
|
|||||||
<?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/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');
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
||||||
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();
|
|
||||||
|
|
||||||
|
|
||||||
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",
|
|
||||||
"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');
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
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' );
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
<div id="model_plugin_shortcode">
|
|
||||||
<ol>
|
|
||||||
<p>list get_metadata('post') :</p>
|
|
||||||
<?php
|
|
||||||
foreach($post_metadata as $meta_key => $meta_value) {
|
|
||||||
include($plgn_dir."html/templates/print_meta.html");
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
</ol>
|
|
||||||
<ol>
|
|
||||||
<p>list get_post_meta() :</p>
|
|
||||||
<?php
|
|
||||||
foreach($post_meta as $meta_key => $meta_value) {
|
|
||||||
include($plgn_dir."html/templates/print_meta.html");
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
</ol>
|
|
||||||
<ol>
|
|
||||||
<p>list get_metadata('user') :</p>
|
|
||||||
<?php
|
|
||||||
foreach($user_metadata as $meta_key => $meta_value) {
|
|
||||||
include($plgn_dir."html/templates/print_meta.html");
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
</ol>
|
|
||||||
<ol>
|
|
||||||
<p>list get_user_meta() :</p>
|
|
||||||
<?php
|
|
||||||
foreach($user_meta as $meta_key => $meta_value) {
|
|
||||||
include($plgn_dir."html/templates/print_meta.html");
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
</ol>
|
|
||||||
<ol>
|
|
||||||
<p>list get_userdata() :</p>
|
|
||||||
<?php
|
|
||||||
foreach($user_data as $meta_key => $meta_value) {
|
|
||||||
include($plgn_dir."html/templates/print_meta.html");
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
</ol>
|
|
||||||
<ol>
|
|
||||||
<p>list wp_get_current_user() :</p>
|
|
||||||
<?php
|
|
||||||
foreach($current_user as $meta_key => $meta_value) {
|
|
||||||
include($plgn_dir."html/templates/print_meta.html");
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
</ol>
|
|
||||||
<ol>
|
|
||||||
<p>list wp_get_current_user()->data :</p>
|
|
||||||
<?php
|
|
||||||
foreach($current_user->data as $meta_key => $meta_value) {
|
|
||||||
include($plgn_dir."html/templates/print_meta.html");
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
</ol>
|
|
||||||
|
|
||||||
<p>i am a new p</p>
|
|
||||||
<p class="first_el_to_change">to change</p>
|
|
||||||
<button id='test_ajax_1' name="ajax_button_1" value="2024">2024</button>
|
|
||||||
<?php
|
|
||||||
foreach($names as $name) {
|
|
||||||
include($plgn_dir."html/templates/example_presentation.html");
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
<?php
|
|
||||||
foreach($ages as $age) {
|
|
||||||
?>
|
|
||||||
<p>age <?php echo esc_html($age); ?></p>
|
|
||||||
<?php
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
<p class="third_el_to_change">to change</p>
|
|
||||||
<p>aaaaaand this is the end</p>
|
|
||||||
<form method="post" action="<?php echo esc_url( wp_registration_url() ); ?>">
|
|
||||||
<input type="text" name="user_login" placeholder="username">
|
|
||||||
<input type="email" name="user_email" placeholder="email">
|
|
||||||
<input type="password" name="user_pass" placeholder="password">
|
|
||||||
<button type="submit">register</button>
|
|
||||||
</form>
|
|
||||||
<form method="post" action="<?php echo esc_url( wp_lostpassword_url() ); ?>">
|
|
||||||
<input type="hidden" id="user_login" value="rexe">
|
|
||||||
<input type="text" name="pass1" data-reveal="1" data-pw="i0#chBo*S1Br5iDY" placeholder="new password">
|
|
||||||
<input type="hidden" name="rp_key" value="WO8qGALMbbKKsEEhXsOQ">
|
|
||||||
<button type="submit">generate</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
<input type='text' id='image_id' placeholder="image_id" value="33555">
|
|
||||||
<button id='edit_image'>edit image</button>
|
|
||||||
<div id="media_editor"></div>
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
<input type='text' id='mytext'>
|
|
||||||
<button id='mybutton'>send</button>
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
<p>hello <?php echo esc_html($name); ?></p>
|
|
||||||
<p class="second_el_to_change">to change</p>
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
<li>
|
|
||||||
"<?php echo esc_html($meta_key); ?>" :
|
|
||||||
<?php echo esc_html(json_encode($meta_value)); ?>
|
|
||||||
</li>
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
console.log("PLGNTLS_data:");
|
|
||||||
console.log(PLGNTLS_data);
|
|
||||||
|
|
||||||
const title = document.querySelector(".first_el_to_change");
|
|
||||||
title.innerHTML = "--- coucou ;) " + PLGNTLS_data.myvar_1;
|
|
||||||
|
|
||||||
const ajax_button_1 = document.querySelector("#test_ajax_1");
|
|
||||||
ajax_button_1.addEventListener('click', () => {
|
|
||||||
PLGNTLS_data.ajax(ajax_button_1, 'get_data')
|
|
||||||
.then((response) => response.json())
|
|
||||||
.then((data) => {
|
|
||||||
console.log("datou: ");
|
|
||||||
console.log(data);
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
console.log("error: ");
|
|
||||||
console.log(error);
|
|
||||||
})
|
|
||||||
;
|
|
||||||
});
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
|
|
||||||
const title2 = document.querySelector(".second_el_to_change");
|
|
||||||
title2.innerHTML = "--- ho boy !";
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
|
|
||||||
const title3 = document.querySelector(".third_el_to_change");
|
|
||||||
title3.innerHTML = "--- bye bye, " + PLGNTLS_data.myvar_2;
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,381 +0,0 @@
|
|||||||
|
|
||||||
console.log("---------------inside image_editor.js--------------");
|
|
||||||
const edit_image_button = document.getElementById('edit_image');
|
|
||||||
const image_id_field = document.getElementById('image_id');
|
|
||||||
const media_editor = document.getElementById('media_editor');
|
|
||||||
|
|
||||||
edit_image_button.addEventListener('click', () => {
|
|
||||||
const image_id = image_id_field.value;
|
|
||||||
|
|
||||||
//PLGNTLS_ajax("postid", image_id, 'image-editor')
|
|
||||||
const data_obj = {
|
|
||||||
'postid': image_id,
|
|
||||||
};
|
|
||||||
PLGNTLS_ajax(data_obj, 'image_editor_PLGNTLS')
|
|
||||||
.then((response) => response.json())
|
|
||||||
.then((data) => {
|
|
||||||
console.log("data: ");
|
|
||||||
console.log(data);
|
|
||||||
media_editor.innerHTML = data.data.html;
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
console.log("error: ");
|
|
||||||
console.log(error);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
/*
|
|
||||||
open: function (e, t, i) { // t: nonce
|
|
||||||
this._view = i; // div: #media-editor-114
|
|
||||||
var a = c('#image-editor-' + e), // e: image id
|
|
||||||
o = c('#media-head-' + e),
|
|
||||||
r = c('#imgedit-open-btn-' + e),
|
|
||||||
s = r.siblings('.spinner');
|
|
||||||
if (!r.hasClass('button-activated')) return s.addClass('is-active'),
|
|
||||||
c.ajax({
|
|
||||||
url: ajaxurl,
|
|
||||||
type: 'post',
|
|
||||||
data: {
|
|
||||||
action: 'image-editor',
|
|
||||||
_ajax_nonce: t,
|
|
||||||
postid: e,
|
|
||||||
do : 'open'},
|
|
||||||
beforeSend: function () {
|
|
||||||
r.addClass('button-activated')
|
|
||||||
}
|
|
||||||
}).done(
|
|
||||||
function (t) {
|
|
||||||
var i;
|
|
||||||
'-1' === t &&
|
|
||||||
(
|
|
||||||
i = n('Could not load the preview image.'),
|
|
||||||
a.html(
|
|
||||||
'<div class="notice notice-error" tabindex="-1" role="alert"><p>' + i + '</p></div>'
|
|
||||||
)
|
|
||||||
),
|
|
||||||
t.data &&
|
|
||||||
t.data.html &&
|
|
||||||
a.html(t.data.html),
|
|
||||||
o.fadeOut(
|
|
||||||
'fast',
|
|
||||||
function () {
|
|
||||||
a.fadeIn(
|
|
||||||
'fast',
|
|
||||||
function () {
|
|
||||||
i &&
|
|
||||||
c(document).trigger('image-editor-ui-ready')
|
|
||||||
}
|
|
||||||
),
|
|
||||||
r.removeClass('button-activated'),
|
|
||||||
s.removeClass('is-active')
|
|
||||||
}
|
|
||||||
),
|
|
||||||
l.init(e)
|
|
||||||
}
|
|
||||||
) },
|
|
||||||
imgLoaded: function (t) {
|
|
||||||
var i = c('#image-preview-' + t),
|
|
||||||
e = c('#imgedit-crop-' + t);
|
|
||||||
void 0 === this.hold.sizer &&
|
|
||||||
this.init(t),
|
|
||||||
this.initCrop(t, i, e),
|
|
||||||
this.setCropSelection(
|
|
||||||
t,
|
|
||||||
{
|
|
||||||
x1: 0,
|
|
||||||
y1: 0,
|
|
||||||
x2: 0,
|
|
||||||
y2: 0,
|
|
||||||
width: i.innerWidth(),
|
|
||||||
height: i.innerHeight()
|
|
||||||
}
|
|
||||||
),
|
|
||||||
this.toggleEditor(t, 0, !0)
|
|
||||||
},
|
|
||||||
focusManager: function () {
|
|
||||||
setTimeout(
|
|
||||||
function () {
|
|
||||||
var t = c('.notice[role="alert"]');
|
|
||||||
(t = t.length ? t : c('.imgedit-wrap').find(':tabbable:first')).attr('tabindex', '-1').trigger('focus')
|
|
||||||
},
|
|
||||||
100
|
|
||||||
)
|
|
||||||
},
|
|
||||||
initCrop: function (a, t, i) {
|
|
||||||
var o = this,
|
|
||||||
r = c('#imgedit-sel-width-' + a),
|
|
||||||
s = c('#imgedit-sel-height-' + a),
|
|
||||||
n = c('#imgedit-start-x-' + a),
|
|
||||||
d = c('#imgedit-start-y-' + a),
|
|
||||||
t = c(t);
|
|
||||||
t.data('imgAreaSelect') ||
|
|
||||||
(
|
|
||||||
o.iasapi = t.imgAreaSelect({
|
|
||||||
parent: i,
|
|
||||||
instance: !0,
|
|
||||||
handles: !0,
|
|
||||||
keys: !0,
|
|
||||||
minWidth: 3,
|
|
||||||
minHeight: 3,
|
|
||||||
onInit: function (t) {
|
|
||||||
c(t).next().css('position', 'absolute').nextAll('.imgareaselect-outer').css('position', 'absolute'),
|
|
||||||
i.children().on(
|
|
||||||
'mousedown, touchstart',
|
|
||||||
function (t) {
|
|
||||||
var i,
|
|
||||||
e = !1;
|
|
||||||
t.shiftKey &&
|
|
||||||
(
|
|
||||||
t = o.iasapi.getSelection(),
|
|
||||||
i = o.getSelRatio(a),
|
|
||||||
e = t &&
|
|
||||||
t.width &&
|
|
||||||
t.height ? t.width + ':' + t.height : i
|
|
||||||
),
|
|
||||||
o.iasapi.setOptions({
|
|
||||||
aspectRatio: e
|
|
||||||
})
|
|
||||||
}
|
|
||||||
)
|
|
||||||
},
|
|
||||||
onSelectStart: function () {
|
|
||||||
l.setDisabled(c('#imgedit-crop-sel-' + a), 1),
|
|
||||||
l.setDisabled(c('.imgedit-crop-clear'), 1),
|
|
||||||
l.setDisabled(c('.imgedit-crop-apply'), 1)
|
|
||||||
},
|
|
||||||
onSelectEnd: function (t, i) {
|
|
||||||
l.setCropSelection(a, i),
|
|
||||||
c('#imgedit-crop > *').is(':visible') ||
|
|
||||||
l.toggleControls(c('.imgedit-crop.button'))
|
|
||||||
},
|
|
||||||
onSelectChange: function (t, i) {
|
|
||||||
var e = l.hold.sizer;
|
|
||||||
r.val(l.round(i.width / e)),
|
|
||||||
s.val(l.round(i.height / e)),
|
|
||||||
n.val(l.round(i.x1 / e)),
|
|
||||||
d.val(l.round(i.y1 / e))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
)
|
|
||||||
},
|
|
||||||
setCropSelection: function (t, i) {
|
|
||||||
if (!(i = i || 0) || i.width < 3 && i.height < 3) return this.setDisabled(c('.imgedit-crop', '#imgedit-panel-' + t), 1),
|
|
||||||
this.setDisabled(c('#imgedit-crop-sel-' + t), 1),
|
|
||||||
c('#imgedit-sel-width-' + t).val(''),
|
|
||||||
c('#imgedit-sel-height-' + t).val(''),
|
|
||||||
c('#imgedit-start-x-' + t).val('0'),
|
|
||||||
c('#imgedit-start-y-' + t).val('0'),
|
|
||||||
c('#imgedit-selection-' + t).val(''),
|
|
||||||
!1;
|
|
||||||
i = {
|
|
||||||
x: i.x1,
|
|
||||||
y: i.y1,
|
|
||||||
w: i.width,
|
|
||||||
h: i.height
|
|
||||||
},
|
|
||||||
this.setDisabled(c('.imgedit-crop', '#imgedit-panel-' + t), 1),
|
|
||||||
c('#imgedit-selection-' + t).val(JSON.stringify(i))
|
|
||||||
},
|
|
||||||
close: function (t, i) {
|
|
||||||
if ((i = i || !1) && this.notsaved(t)) return !1;
|
|
||||||
this.iasapi = {},
|
|
||||||
this.hold = {},
|
|
||||||
this._view ? this._view.back() : c('#image-editor-' + t).fadeOut(
|
|
||||||
'fast',
|
|
||||||
function () {
|
|
||||||
c('#media-head-' + t).fadeIn(
|
|
||||||
'fast',
|
|
||||||
function () {
|
|
||||||
c('#imgedit-open-btn-' + t).trigger('focus')
|
|
||||||
}
|
|
||||||
),
|
|
||||||
c(this).empty()
|
|
||||||
}
|
|
||||||
)
|
|
||||||
},
|
|
||||||
notsaved: function (t) {
|
|
||||||
var i = c('#imgedit-history-' + t).val(),
|
|
||||||
i = '' !== i ? JSON.parse(i) : [];
|
|
||||||
return this.intval(c('#imgedit-undone-' + t).val()) < i.length &&
|
|
||||||
!confirm(c('#imgedit-leaving-' + t).text())
|
|
||||||
},
|
|
||||||
addStep: function (t, i, e) {
|
|
||||||
for (
|
|
||||||
var a = this,
|
|
||||||
o = c('#imgedit-history-' + i),
|
|
||||||
r = '' !== o.val() ? JSON.parse(o.val()) : [],
|
|
||||||
s = c('#imgedit-undone-' + i),
|
|
||||||
n = a.intval(s.val());
|
|
||||||
0 < n;
|
|
||||||
) r.pop(),
|
|
||||||
n--;
|
|
||||||
s.val(0),
|
|
||||||
r.push(t),
|
|
||||||
o.val(JSON.stringify(r)),
|
|
||||||
a.refreshEditor(
|
|
||||||
i,
|
|
||||||
e,
|
|
||||||
function () {
|
|
||||||
a.setDisabled(c('#image-undo-' + i), !0),
|
|
||||||
a.setDisabled(c('#image-redo-' + i), !1)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
},
|
|
||||||
rotate: function (t, i, e, a) {
|
|
||||||
if (c(a).hasClass('disabled')) return !1;
|
|
||||||
this.closePopup(a),
|
|
||||||
this.addStep({
|
|
||||||
r: {
|
|
||||||
r: t,
|
|
||||||
fw: this.hold.h,
|
|
||||||
fh: this.hold.w
|
|
||||||
}
|
|
||||||
}, i, e)
|
|
||||||
},
|
|
||||||
flip: function (t, i, e, a) {
|
|
||||||
if (c(a).hasClass('disabled')) return !1;
|
|
||||||
this.closePopup(a),
|
|
||||||
this.addStep({
|
|
||||||
f: {
|
|
||||||
f: t,
|
|
||||||
fw: this.hold.w,
|
|
||||||
fh: this.hold.h
|
|
||||||
}
|
|
||||||
}, i, e)
|
|
||||||
},
|
|
||||||
crop: function (t, i, e) {
|
|
||||||
var a = c('#imgedit-selection-' + t).val(),
|
|
||||||
o = this.intval(c('#imgedit-sel-width-' + t).val()),
|
|
||||||
r = this.intval(c('#imgedit-sel-height-' + t).val());
|
|
||||||
if (c(e).hasClass('disabled') || '' === a) return !1;
|
|
||||||
0 < (a = JSON.parse(a)).w &&
|
|
||||||
0 < a.h &&
|
|
||||||
0 < o &&
|
|
||||||
0 < r &&
|
|
||||||
(a.fw = o, a.fh = r, this.addStep({
|
|
||||||
c: a
|
|
||||||
}, t, i)),
|
|
||||||
c('#imgedit-sel-width-' + t).val(''),
|
|
||||||
c('#imgedit-sel-height-' + t).val(''),
|
|
||||||
c('#imgedit-start-x-' + t).val('0'),
|
|
||||||
c('#imgedit-start-y-' + t).val('0')
|
|
||||||
},
|
|
||||||
undo: function (i, t) {
|
|
||||||
var e = this,
|
|
||||||
a = c('#image-undo-' + i),
|
|
||||||
o = c('#imgedit-undone-' + i),
|
|
||||||
r = e.intval(o.val()) + 1;
|
|
||||||
a.hasClass('disabled') ||
|
|
||||||
(
|
|
||||||
o.val(r),
|
|
||||||
e.refreshEditor(
|
|
||||||
i,
|
|
||||||
t,
|
|
||||||
function () {
|
|
||||||
var t = c('#imgedit-history-' + i),
|
|
||||||
t = '' !== t.val() ? JSON.parse(t.val()) : [];
|
|
||||||
e.setDisabled(c('#image-redo-' + i), !0),
|
|
||||||
e.setDisabled(a, r < t.length),
|
|
||||||
t.length === r &&
|
|
||||||
c('#image-redo-' + i).trigger('focus')
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
},
|
|
||||||
redo: function (t, i) {
|
|
||||||
var e = this,
|
|
||||||
a = c('#image-redo-' + t),
|
|
||||||
o = c('#imgedit-undone-' + t),
|
|
||||||
r = e.intval(o.val()) - 1;
|
|
||||||
a.hasClass('disabled') ||
|
|
||||||
(
|
|
||||||
o.val(r),
|
|
||||||
e.refreshEditor(
|
|
||||||
t,
|
|
||||||
i,
|
|
||||||
function () {
|
|
||||||
e.setDisabled(c('#image-undo-' + t), !0),
|
|
||||||
e.setDisabled(a, 0 < r),
|
|
||||||
0 == r &&
|
|
||||||
c('#image-undo-' + t).trigger('focus')
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
},
|
|
||||||
setNumSelection: function (t, i) {
|
|
||||||
var e = c('#imgedit-sel-width-' + t),
|
|
||||||
a = c('#imgedit-sel-height-' + t),
|
|
||||||
o = c('#imgedit-start-x-' + t),
|
|
||||||
r = c('#imgedit-start-y-' + t),
|
|
||||||
o = this.intval(o.val()),
|
|
||||||
r = this.intval(r.val()),
|
|
||||||
s = this.intval(e.val()),
|
|
||||||
n = this.intval(a.val()),
|
|
||||||
d = c('#image-preview-' + t),
|
|
||||||
l = d.height(),
|
|
||||||
d = d.width(),
|
|
||||||
h = this.hold.sizer,
|
|
||||||
g = this.iasapi;
|
|
||||||
if (!1 !== this.validateNumeric(i)) return s < 1 ? (e.val(''), !1) : n < 1 ? (a.val(''), !1) : void (
|
|
||||||
(s && n || o && r) &&
|
|
||||||
(i = g.getSelection()) &&
|
|
||||||
(
|
|
||||||
s = i.x1 + Math.round(s * h),
|
|
||||||
n = i.y1 + Math.round(n * h),
|
|
||||||
o = o === i.x1 ? i.x1 : Math.round(o * h),
|
|
||||||
i = r === i.y1 ? i.y1 : Math.round(r * h),
|
|
||||||
d < s &&
|
|
||||||
(o = 0, s = d, e.val(Math.round(s / h))),
|
|
||||||
l < n &&
|
|
||||||
(i = 0, n = l, a.val(Math.round(n / h))),
|
|
||||||
g.setSelection(o, i, s, n),
|
|
||||||
g.update(),
|
|
||||||
this.setCropSelection(t, g.getSelection())
|
|
||||||
)
|
|
||||||
)
|
|
||||||
},
|
|
||||||
round: function (t) {
|
|
||||||
var i;
|
|
||||||
return t = Math.round(t),
|
|
||||||
0.6 < this.hold.sizer ? t : '1' === (i = t.toString().slice( - 1)) ? t - 1 : '9' === i ? t + 1 : t
|
|
||||||
},
|
|
||||||
setRatioSelection: function (t, i, e) {
|
|
||||||
var a = this.intval(c('#imgedit-crop-width-' + t).val()),
|
|
||||||
o = this.intval(c('#imgedit-crop-height-' + t).val()),
|
|
||||||
r = c('#image-preview-' + t).height();
|
|
||||||
!1 === this.validateNumeric(e) ? this.iasapi.setOptions({
|
|
||||||
aspectRatio: null
|
|
||||||
}) : a &&
|
|
||||||
o &&
|
|
||||||
(
|
|
||||||
this.iasapi.setOptions({
|
|
||||||
aspectRatio: a + ':' + o
|
|
||||||
}),
|
|
||||||
e = this.iasapi.getSelection(!0)
|
|
||||||
) &&
|
|
||||||
(
|
|
||||||
r < (a = Math.ceil(e.y1 + (e.x2 - e.x1) / (a / o))) ? (
|
|
||||||
a = r,
|
|
||||||
o = n(
|
|
||||||
'Selected crop ratio exceeds the boundaries of the image. Try a different ratio.'
|
|
||||||
),
|
|
||||||
c('#imgedit-crop-' + t).prepend(
|
|
||||||
'<div class="notice notice-error" tabindex="-1" role="alert"><p>' + o + '</p></div>'
|
|
||||||
),
|
|
||||||
wp.a11y.speak(o, 'assertive'),
|
|
||||||
c(i ? '#imgedit-crop-height-' + t : '#imgedit-crop-width-' + t).val('')
|
|
||||||
) : void 0 !== (r = c('#imgedit-crop-' + t).find('.notice-error')) &&
|
|
||||||
r.remove(),
|
|
||||||
this.iasapi.setSelection(e.x1, e.y1, e.x2, a),
|
|
||||||
this.iasapi.update()
|
|
||||||
)
|
|
||||||
},
|
|
||||||
validateNumeric: function (t) {
|
|
||||||
if (!1 === this.intval(c(t).val())) return c(t).val(''),
|
|
||||||
!1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}(jQuery);
|
|
||||||
|
|
||||||
|
|
||||||
*/
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
const inputElement = document.getElementById('mytext');
|
|
||||||
const sendButton = document.getElementById('mybutton');
|
|
||||||
|
|
||||||
sendButton.addEventListener('click', () => {
|
|
||||||
const inputValue = inputElement.value;
|
|
||||||
console.log("inputValue:");
|
|
||||||
console.log(inputValue);
|
|
||||||
PLGNTLS_ajax(inputValue, 'get_data')
|
|
||||||
.then((response) => response.json())
|
|
||||||
.then((data) => {
|
|
||||||
console.log("dataaa: ");
|
|
||||||
console.log(data);
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
console.log("error: ");
|
|
||||||
console.log(error);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
<?php acf_form_head(); ?>
|
|
||||||
<?php get_header(); ?>
|
|
||||||
|
|
||||||
<div id="primary">
|
|
||||||
<div id="content" role="main">
|
|
||||||
|
|
||||||
<?php /* The loop */ ?>
|
|
||||||
<?php while ( have_posts() ) : the_post(); ?>
|
|
||||||
|
|
||||||
<h1><?php the_title(); ?></h1>
|
|
||||||
|
|
||||||
<?php the_content(); ?>
|
|
||||||
|
|
||||||
<p>My custom field: <?php the_field('my_custom_field'); ?></p>
|
|
||||||
|
|
||||||
<?php acf_form(); ?>
|
|
||||||
|
|
||||||
<?php endwhile; ?>
|
|
||||||
|
|
||||||
</div><!-- #content -->
|
|
||||||
</div><!-- #primary -->
|
|
||||||
|
|
||||||
<?php get_footer(); ?>
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,82 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
function fipfcard_image_editor()
|
|
||||||
{
|
|
||||||
// ob_start();
|
|
||||||
// wp_image_editor('33545');
|
|
||||||
// return ob_get_clean();
|
|
||||||
$fipfcard_image_editor = new PLGNTLS_class();
|
|
||||||
return $fipfcard_image_editor->add_to_front(
|
|
||||||
array(
|
|
||||||
"js/image_editor.js",
|
|
||||||
"html/image_editor.html",
|
|
||||||
)
|
|
||||||
);
|
|
||||||
// if ( ! has_action( "wp_ajax_{$action}" ) ) {
|
|
||||||
// it returns error 400
|
|
||||||
|
|
||||||
}
|
|
||||||
add_shortcode('fipfcard_image_editor', 'fipfcard_image_editor');
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles image editing via AJAX.
|
|
||||||
* from wp-admin/includes/ajax-action.php
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
function wp_ajax_image_editor() {
|
|
||||||
$attachment_id = (int) $_POST['postid'];
|
|
||||||
// $attachment_id = 33555;
|
|
||||||
|
|
||||||
// if ( empty( $attachment_id ) || ! current_user_can( 'edit_post', $attachment_id ) ) {
|
|
||||||
// wp_die( -1 );
|
|
||||||
// }
|
|
||||||
|
|
||||||
// check_ajax_referer( "image_editor-$attachment_id" );
|
|
||||||
// require_once ABSPATH . 'wp-admin/includes/image-edit.php';
|
|
||||||
|
|
||||||
$msg = false;
|
|
||||||
|
|
||||||
switch ( $_POST['do'] ) {
|
|
||||||
case 'save':
|
|
||||||
$msg = wp_save_image( $attachment_id );
|
|
||||||
if ( ! empty( $msg->error ) ) {
|
|
||||||
wp_send_json_error( $msg );
|
|
||||||
}
|
|
||||||
|
|
||||||
wp_send_json_success( $msg );
|
|
||||||
break;
|
|
||||||
case 'scale':
|
|
||||||
$msg = wp_save_image( $attachment_id );
|
|
||||||
break;
|
|
||||||
case 'restore':
|
|
||||||
$msg = wp_restore_image( $attachment_id );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
ob_start();
|
|
||||||
wp_image_editor( $attachment_id, $msg );
|
|
||||||
$html = ob_get_clean();
|
|
||||||
|
|
||||||
if ( ! empty( $msg->error ) ) {
|
|
||||||
wp_send_json_error(
|
|
||||||
array(
|
|
||||||
'message' => $msg,
|
|
||||||
'html' => $html,
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
wp_send_json_success(
|
|
||||||
array(
|
|
||||||
'message' => $msg,
|
|
||||||
'html' => $html,
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
add_action( 'wp_ajax_image_editor', 'wp_ajax_image_editor' );
|
|
||||||
*/
|
|
||||||
|
|
||||||
?>
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
function fipfcard_plugin_content() {
|
|
||||||
$fipfcard = new PLGNTLS_class();
|
|
||||||
|
|
||||||
echo $fipfcard->add_to_front( array(
|
|
||||||
"js/menu/example_menu.js",
|
|
||||||
"html/menu/example_menu.html",
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
||||||
@@ -1,156 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
||||||
function that add the ajax script to front
|
|
||||||
no real needs to check if already included :
|
|
||||||
- $handle is uniq so it will not be re-enqueued
|
|
||||||
the first enqueued version would be kept
|
|
||||||
- if we used add_var_to_front() (which use wp_add_inline_script())
|
|
||||||
the vars would be added twice
|
|
||||||
leading to js syntaxe error (redeclaraiton of 'let' or 'const')
|
|
||||||
- but we use wp_localize_script() so the object will be overwritten
|
|
||||||
it's not a real pbm
|
|
||||||
(what is more efficient, check for double or overwritte object ?)
|
|
||||||
*/
|
|
||||||
function fipfcard_add_ajax_post() {
|
|
||||||
global $fipfcard_first_script;
|
|
||||||
global $fipfcard_ajax_file;
|
|
||||||
|
|
||||||
$file = fipfcard_init_file($fipfcard_ajax_file);
|
|
||||||
|
|
||||||
// // check if ajax script was already enqueued
|
|
||||||
// global $wp_scripts;
|
|
||||||
// $already_enqueued = array_search($file->handle, $wp_scripts->queue);
|
|
||||||
// if ($already_enqueued !== false)
|
|
||||||
// return ;
|
|
||||||
|
|
||||||
$fipfcard_first_script = $file->handle;
|
|
||||||
wp_enqueue_script( $file->handle, $file->url, '', $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 = "fipfcard_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 fipfcard_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 fipfcard_add_files_to_front($files_arr, $add_ajax = true) {
|
|
||||||
//wp_enqueue_script(<give_it_a_name>, /url/to/file, [depends on], version, defer? );
|
|
||||||
//wp_enqueue_style( <give_it_a_name>, /url/to/file, [depends on], version, media );
|
|
||||||
global $fipfcard_first_script;
|
|
||||||
|
|
||||||
if ($add_ajax === true)
|
|
||||||
fipfcard_add_ajax_post();
|
|
||||||
|
|
||||||
$previous_css_basename = '';
|
|
||||||
$previous_js_basename = '';
|
|
||||||
foreach ($files_arr as $file_name) {
|
|
||||||
$file = fipfcard_init_file($file_name);
|
|
||||||
if ($file->ext === "js") {
|
|
||||||
if (is_null($fipfcard_first_script))
|
|
||||||
$fipfcard_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 fipfcard_add_var_to_front($vars, $handle = null) {
|
|
||||||
if (is_null($handle)) {
|
|
||||||
global $fipfcard_first_script;
|
|
||||||
$handle = $fipfcard_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);
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
||||||
https://stackify.com/how-to-log-to-console-in-php/
|
|
||||||
*/
|
|
||||||
function console_log($output) {
|
|
||||||
if (CONSOLE_OFF)
|
|
||||||
return;
|
|
||||||
$json_output = json_encode($output, JSON_HEX_TAG);
|
|
||||||
$js_code = '<script>console.log(' . $json_output . ');</script>';
|
|
||||||
echo $js_code;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
||||||
@param two arguments :
|
|
||||||
1. html files to include in front
|
|
||||||
- can be a string of 1 filename
|
|
||||||
- or an array of strings of filenames
|
|
||||||
( https://stackoverflow.com/q/4747876/9497573 )
|
|
||||||
- it's probably better to only add 1 file, and let it include other files
|
|
||||||
2. list of variables to make available to this files
|
|
||||||
- in the form of key => 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 fipfcard_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;
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
||||||
globals variables
|
|
||||||
const vs define : https://stackoverflow.com/questions/2447791/php-define-vs-const
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* switch console_log
|
|
||||||
const CONSOLE_OFF = true;
|
|
||||||
*/
|
|
||||||
const FIPFCARD_CONSOLE_OFF = false;
|
|
||||||
|
|
||||||
/* a variable that will contain the name of the first script enqueued
|
|
||||||
*/
|
|
||||||
$fipfcard_first_script = null;
|
|
||||||
|
|
||||||
/* path to ajax.js file, from root of js dir
|
|
||||||
*/
|
|
||||||
$fipfcard_ajax_file = "utils/ajax.js";
|
|
||||||
|
|
||||||
?>
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
/**
|
|
||||||
* function that create an ajax post action
|
|
||||||
* - PLGNTLS_data.ajax_nonce and PLGNTLS_data.ajax_url
|
|
||||||
* are passed from the class PLGNTLS_class
|
|
||||||
*/
|
|
||||||
console.log("PLGNTLS_data");
|
|
||||||
console.log(PLGNTLS_data);
|
|
||||||
function PLGNTLS_ajax(data_obj, action) {
|
|
||||||
const data = new FormData();
|
|
||||||
data.append("action", action);
|
|
||||||
data.append("_ajax_nonce", PLGNTLS_data.ajax_nonce);
|
|
||||||
for (const key in data_obj)
|
|
||||||
data.append(key, data_obj[key]);
|
|
||||||
|
|
||||||
return fetch(PLGNTLS_data.ajax_url, {
|
|
||||||
method: "POST",
|
|
||||||
credentials: "same-origin",
|
|
||||||
body: data
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@@ -1,261 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* include those two lines at the top of the main plugin file
|
|
||||||
*
|
|
||||||
* include_once( plugin_dir_path(__FILE__) . '/php/utils/plugin_tools.php');
|
|
||||||
* PLGNTLS_class::set_root_dir( plugin_dir_path(__FILE__), plugin_dir_url(__FILE__) );
|
|
||||||
*
|
|
||||||
* PLGNTLS means PLUGIN TOOLS
|
|
||||||
*/
|
|
||||||
|
|
||||||
class PLGNTLS_class
|
|
||||||
{
|
|
||||||
private static $_root_path;
|
|
||||||
private static $_root_url;
|
|
||||||
|
|
||||||
private static $_ajax_already_there;
|
|
||||||
private $_first_script;
|
|
||||||
private $_prefix;
|
|
||||||
private $_js_dependencies;
|
|
||||||
private $_css_dependencies;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
public function __construct() {
|
|
||||||
if (! isset( self::$_ajax_already_there ))
|
|
||||||
self::$_ajax_already_there = false;
|
|
||||||
$this->_prefix = "PLGNTLS";
|
|
||||||
$this->_first_script = null;
|
|
||||||
$this->_js_dependencies = array();
|
|
||||||
$this->_css_dependencies = array();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* can be used before class is instanciated :
|
|
||||||
* PLGNTLS_class::set_root_dir( plugin_dir_path(__FILE__), plugin_dir_url(__FILE__) );
|
|
||||||
*/
|
|
||||||
public static function set_root_dir($path, $url) {
|
|
||||||
if (isset( self::$_root_path ))
|
|
||||||
return ;
|
|
||||||
if (isset( self::$_root_url ))
|
|
||||||
return ;
|
|
||||||
self::$_root_path = $path;
|
|
||||||
self::$_root_url = $url;
|
|
||||||
}
|
|
||||||
public static function get_path() {
|
|
||||||
return(self::$_root_path);
|
|
||||||
}
|
|
||||||
public static function get_url() {
|
|
||||||
return(self::$_root_url);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function add_to_front($files_arr = null, $vars = null) {
|
|
||||||
if (!is_null($files_arr))
|
|
||||||
{
|
|
||||||
// add ajax file at beginning of files list
|
|
||||||
array_unshift($files_arr, "utils/plugin_ajax.js");
|
|
||||||
$nonce = array("ajax_nonce" => wp_create_nonce('wp-pageviews-nonce'));
|
|
||||||
$url = array("ajax_url" => admin_url('admin-ajax.php'));
|
|
||||||
$vars = array_merge($vars, $nonce);
|
|
||||||
$vars = array_merge($vars, $url);
|
|
||||||
}
|
|
||||||
|
|
||||||
$files = array();
|
|
||||||
foreach($files_arr as $key => $file_name) {
|
|
||||||
$files[] = $this->init_file($key, $file_name);
|
|
||||||
}
|
|
||||||
if (!is_null($files_arr))
|
|
||||||
$this->add_files_to_front($files);
|
|
||||||
if (!is_null($vars))
|
|
||||||
$this->add_vars_to_front($vars);
|
|
||||||
return $this->create_html($files, $vars);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
||||||
* PRIVATES FUNCTIONS
|
|
||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param two arguments :
|
|
||||||
* 1. html files to include in front
|
|
||||||
* - can be a string of 1 filename
|
|
||||||
* - or an array of strings of filenames
|
|
||||||
* ( https://stackoverflow.com/q/4747876/9497573 )
|
|
||||||
* - it's probably better to only add 1 file, and let it include other files
|
|
||||||
* 2. list of variables to make available to this files
|
|
||||||
* - in the form of key => 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
|
|
||||||
*/
|
|
||||||
private function create_html($files = null, $vars = null) {
|
|
||||||
if (is_null($files))
|
|
||||||
return null;
|
|
||||||
$plgn_dir = $this->get_path();
|
|
||||||
if (!is_null($vars))
|
|
||||||
extract($vars);
|
|
||||||
|
|
||||||
ob_start();
|
|
||||||
foreach($files as $file) {
|
|
||||||
if ($file->ext === 'html')
|
|
||||||
include($file->path);
|
|
||||||
}
|
|
||||||
$html = ob_get_clean();
|
|
||||||
|
|
||||||
return $html;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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
|
|
||||||
*/
|
|
||||||
private function add_vars_to_front($vars_arr)
|
|
||||||
{
|
|
||||||
if (is_null($this->_first_script))
|
|
||||||
return ;
|
|
||||||
if (is_null($vars_arr))
|
|
||||||
return ;
|
|
||||||
$handle = $this->_first_script;
|
|
||||||
$object_name = $this->_prefix . "_data";
|
|
||||||
|
|
||||||
$vars_json = json_encode($vars_arr);
|
|
||||||
$front = "let $object_name = $vars_json;";
|
|
||||||
wp_add_inline_script($handle, $front, 'before');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @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
|
|
||||||
*/
|
|
||||||
private function add_files_to_front($files_arr) {
|
|
||||||
//wp_enqueue_script(<give_it_a_name>, /url/to/file, [depends on], version, defer? );
|
|
||||||
//wp_enqueue_style( <give_it_a_name>, /url/to/file, [depends on], version, media );
|
|
||||||
|
|
||||||
$previous_css_basename = '';
|
|
||||||
$previous_js_basename = '';
|
|
||||||
foreach ($files_arr as $file) {
|
|
||||||
if ($file->ext === "js") {
|
|
||||||
if (is_null($this->_first_script))
|
|
||||||
$this->_first_script = $file->handle;
|
|
||||||
$depends_on = $this->check_dependencies($file, $previous_js_basename);
|
|
||||||
if ($depends_on !== null)
|
|
||||||
wp_enqueue_script( $file->handle, $file->url, $depends_on, $file->version, true);
|
|
||||||
$previous_js_basename = $file->handle;
|
|
||||||
}
|
|
||||||
else if ($file->ext === "css") {
|
|
||||||
$depends_on = $this->check_dependencies($file, $previous_css_basename);
|
|
||||||
if ($depends_on !== null)
|
|
||||||
wp_enqueue_style( $file->handle, $file->url, $depends_on, $file->version, '');
|
|
||||||
$previous_css_basename = $file->handle;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private function check_dependencies(&$file, $previous_basename)
|
|
||||||
{
|
|
||||||
if ($file->ext === "js")
|
|
||||||
{
|
|
||||||
global $wp_scripts;
|
|
||||||
$already_enqueued = array_search($file->handle, $wp_scripts->queue);
|
|
||||||
if ($already_enqueued !== false)
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
else if ($file->ext === "css")
|
|
||||||
{
|
|
||||||
global $wp_styles;
|
|
||||||
$already_enqueued = array_search($file->handle, $wp_styles->queue);
|
|
||||||
if ($already_enqueued !== false)
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$depends_on = array();
|
|
||||||
if (isset($file->depends) && $file->depends !== '')
|
|
||||||
$depends_on[] = $file->depends;
|
|
||||||
if (isset($previous_basename) && $previous_basename !== '')
|
|
||||||
$depends_on[] = $previous_basename;
|
|
||||||
|
|
||||||
return $depends_on;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @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
|
|
||||||
* - depends : string if depends on a handle, or ''
|
|
||||||
*/
|
|
||||||
private function init_file($key, $file_name) {
|
|
||||||
$file = (object)[];
|
|
||||||
|
|
||||||
$file->ext = pathinfo($file_name, PATHINFO_EXTENSION);
|
|
||||||
if (! in_array($file->ext, array("js", "css", "html")))
|
|
||||||
return null;
|
|
||||||
|
|
||||||
$file->basename = pathinfo($file_name, PATHINFO_BASENAME);
|
|
||||||
$file->handle = "PLGNTLS_" . str_replace(".", "_", $file->basename);
|
|
||||||
|
|
||||||
$file->url = $this->get_url().$file_name;
|
|
||||||
$file->path = $this->get_path().$file_name;
|
|
||||||
$file->version = date("ymd-Gis", filemtime($file->path));
|
|
||||||
|
|
||||||
$file->depends = '';
|
|
||||||
if (is_string($key))
|
|
||||||
$file->depends = $key;
|
|
||||||
|
|
||||||
return $file;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
|
||||||
2
private
2
private
Submodule private updated: 64c9462106...a86a33b46e
Submodule wordpress_docker updated: 689543ad74...3c0a32e6ac
Reference in New Issue
Block a user