Skip to content

Commit

Permalink
Merge pull request #4 from LinkNacional/dev
Browse files Browse the repository at this point in the history
2.0.0 refatoração completa do plugin
GuilhermeFriedrichS authored Jul 5, 2024

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
2 parents 68772de + ffa801b commit 352b510
Showing 40 changed files with 4,101 additions and 680 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/main.yml
100644 → 100755
Original file line number Diff line number Diff line change
@@ -17,19 +17,19 @@ jobs:
steps:
- uses: actions/checkout@v3

# Run composer install
- name: Run composer install
uses: php-actions/composer@v6
with:
php_version: ${{ env.PHP_VERSION }}
working_dir: "."
args: "--no-dev --optimize-autoloader"
command: install
# Run composer install // TODO Only run composer after autoload config
#- name: Run composer install
# uses: php-actions/composer@v6
# with:
# php_version: ${{ env.PHP_VERSION }}
# working_dir: "."
# dev: no
# command: install

- name: Make plugin root directory
run: |
mkdir ${{env.PLUGIN_NAME}} &&
cp -r ./admin ./includes ./languages ./public ./vendor *.php *.txt composer.json composer.lock ./${{env.PLUGIN_NAME}}/ &&
cp -r ./admin ./includes ./languages ./public *.php *.txt composer.json composer.lock ./${{env.PLUGIN_NAME}}/ &&
find ./${{env.PLUGIN_NAME}} -type f -exec chmod 0644 {} + &&
find ./${{env.PLUGIN_NAME}} -type d -exec chmod 0755 {} + &&
ls -lah
252 changes: 252 additions & 0 deletions Admin/PGPFGForGivewpAdmin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,252 @@
<?php

namespace Lkn\PGPFGForGivewp\Admin;

use Lkn\PGPFGForGivewp\Includes\PGPFGHelperClass;
use WP_Error;

/**
* The admin-specific functionality of the plugin.
*
* @link https://www.linknacional.com.br
* @since 1.0.0
*
* @package PGPFGForGivewp
* @subpackage PGPFGForGivewp/admin
*/

/**
* The admin-specific functionality of the plugin.
*
* Defines the plugin name, version, and two examples hooks for how to
* enqueue the admin-specific stylesheet and JavaScript.
*
* @package PGPFGForGivewp
* @subpackage PGPFGForGivewp/admin
* @author Link Nacional <[email protected]>
*/
final class PGPFGForGivewpAdmin
{
/**
* The ID of this plugin.
*
* @since 1.0.0
* @access private
* @var string $plugin_name The ID of this plugin.
*/
private $plugin_name;

/**
* The version of this plugin.
*
* @since 1.0.0
* @access private
* @var string $version The current version of this plugin.
*/
private $version;

/**
* Initialize the class and set its properties.
*
* @since 1.0.0
* @param string $plugin_name The name of this plugin.
* @param string $version The version of this plugin.
*/
public function __construct($plugin_name, $version)
{
$this->plugin_name = $plugin_name . '-admin';
$this->version = $version;
}

/**
* Add setting to new section 'Custom Settings' of 'General' Tab.
*
* @param mixed $settings
*
* @return array
*/
public function add_setting_into_new_section($settings)
{
switch (give_get_current_setting_section()) {
case 'lkn-payment-pix':
// Verifique se a configuração específica já está no array
$exists = false;
foreach ($settings as $setting) {
if (isset($setting['id']) && $setting['id'] === 'lkn-payment-pix-type-setting') {
$exists = true;
break;
}
}

// Adicione as configurações apenas se ainda não existirem
if (!$exists) {
$settings[] = array(
'type' => 'title',
'id' => 'lkn-payment-pix'
);

$settings[] = array(
'name' => __('Type of Key', 'payment-gateway-pix-for-givewp'),
'desc' => __('Insert the type of the pix key.', 'payment-gateway-pix-for-givewp'),
'id' => 'lkn-payment-pix-type-setting',
'type' => 'select',
'default' => 'tel',
'options' => array(
'tel' => __('Phone', 'payment-gateway-pix-for-givewp'),
'cpf' => __('CPF', 'payment-gateway-pix-for-givewp'),
'cnpj' => __('CNPJ', 'payment-gateway-pix-for-givewp'),
'email' => __('Email', 'payment-gateway-pix-for-givewp')
),
);

$settings[] = array(
'name' => __('Pix Key', 'payment-gateway-pix-for-givewp'),
'id' => 'lkn-payment-pix-key',
'desc' => __('Insert the pix key that will be used on the donations.', 'payment-gateway-pix-for-givewp'),
'type' => 'text'
);

$settings[] = array(
'name' => __('Recipient Name', 'payment-gateway-pix-for-givewp'),
'id' => 'lkn-payment-pix-name-setting',
'desc' => __('Insert the name of the key\'s recipient.', 'payment-gateway-pix-for-givewp'),
'type' => 'text'
);

$settings[] = array(
'name' => __('Recipient City', 'payment-gateway-pix-for-givewp'),
'id' => 'lkn-payment-pix-city-setting',
'desc' => __('Insert the key recipient\'s city.', 'payment-gateway-pix-for-givewp'),
'type' => 'text'
);

$settings[] = array(
'name' => __('Payment Identificator (optional)', 'payment-gateway-pix-for-givewp'),
'id' => 'lkn-payment-pix-paymentid-setting',
'desc' => __('Insert the payment identificator, not required.', 'payment-gateway-pix-for-givewp'),
'type' => 'text'
);

$settings[] = array(
'name' => __('Enable Debug Mode', 'payment-gateway-pix-for-givewp'),
'desc' => __('Select if logs should be created for debug purposes.', 'payment-gateway-pix-for-givewp') . ((give_get_option('lkn-payment-pix-log-setting') === 'enabled' && file_exists(give_get_option('pgpfg_for_givewp_last_log')) && filesize(give_get_option('pgpfg_for_givewp_last_log'))) ? (' (<a href="#" id="check-logs">' . __('Check Last Log', 'payment-gateway-pix-for-givewp') . '</a>)') : ''),
'id' => 'lkn-payment-pix-log-setting',
'type' => 'radio_inline',
'default' => 'disabled',
'options' => array(
'enabled' => __('Enable', 'payment-gateway-pix-for-givewp'),
'disabled' => __('Disable', 'payment-gateway-pix-for-givewp')
)
);

$settings[] = array(
'name' => __('Collect Billing Details', 'payment-gateway-pix-for-givewp'),
'desc' => __('Select if billing details should be added do the donation forms (classic and legacy forms).', 'payment-gateway-pix-for-givewp'),
'id' => 'lkn-payment-pix-details-setting',
'type' => 'radio_inline',
'default' => 'disabled',
'options' => array(
'enabled' => __('Enable', 'payment-gateway-pix-for-givewp'),
'disabled' => __('Disable', 'payment-gateway-pix-for-givewp')
)
);

$settings[] = array(
'id' => 'lkn-payment-pix',
'type' => 'sectionend'
);
}

break;
}

return $settings;
}

/**
* Add new section to "General" setting tab.
*
* @param mixed $sections
*
* @return array
*/
public function add_new_setting_section($sections)
{
// Separar palavras com travessão no atributo $sections
$sections['lkn-payment-pix'] = __('Pix QR Code', 'payment-gateway-pix-for-givewp');

return $sections;
}

/**
* Register the stylesheets for the admin area.
*
* @since 1.0.0
*/
public function enqueue_styles(): void
{
/**
* This function is provided for demonstration purposes only.
*
* An instance of this class should be passed to the run() function
* defined in PGPFGForGivewp_Loader as all of the hooks are defined
* in that particular class.
*
* The PGPFGForGivewp_Loader will then create the relationship
* between the defined hooks and the functions defined in this
* class.
*/
wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__) . 'css/pgpfg-admin.css', array(), $this->version, 'all');
}

/**
* Register the JavaScript for the admin area.
*
* @since 1.0.0
*/
public function enqueue_scripts(): void
{
/**
* This function is provided for demonstration purposes only.
*
* An instance of this class should be passed to the run() function
* defined in PGPFGForGivewp_Loader as all of the hooks are defined
* in that particular class.
*
* The PGPFGForGivewp_Loader will then create the relationship
* between the defined hooks and the functions defined in this
* class.
*/
wp_enqueue_script($this->plugin_name, plugin_dir_url(__FILE__) . 'js/pgpfg-admin.js', array('jquery', 'wp-i18n'), $this->version, false);
wp_set_script_translations($this->plugin_name, 'payment-gateway-pix-for-givewp', PGPFG_PIX_LANGUAGE_DIR);

$logPath = give_get_option('pgpfg_for_givewp_last_log_url');
$wp_error = false;
$remote = null;
if ($logPath !== false) {
$remote = wp_remote_get($logPath);

if(gettype($remote) === gettype(new WP_Error())) {
PGPFGHelperClass::log(wp_json_encode(array(
'Remote Response' => $remote,
'log url' => $logPath,
'log path' => give_get_option('pgpfg_for_givewp_last_log')
), JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));

$wp_error = $remote;
}

}
$logContents = wp_remote_retrieve_body($remote);

wp_localize_script(
$this->plugin_name,
'lknAttr',
[
'logContents' => ($wp_error ? wp_json_encode(array(
'Error' => 'Error retrieving log'
), JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT) : $logContents)
]
);
}
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ const { __ } = wp.i18n;
const adminPage = lknFindGetParameter('section')

if (adminPage && (adminPage === 'lkn-payment-pix')) {
const giveForm = $('.form-table')
const giveForm = $('.give-submit-wrap')
const noticeDiv = document.createElement('div')
noticeDiv.setAttribute('style', 'padding: 10px; padding-top:15px;padding-bottom:15px;background-color: #fcf9e8;color: #646970;border: solid 1px lightgrey;border-left-color: #dba617;border-left-width: 4px;font-size: 14px;min-width: 625px;margin-top: 10px;')

@@ -51,17 +51,80 @@ const { __ } = wp.i18n;
noticeDiv.innerHTML += '</ul>'
noticeDiv.innerHTML += '<a style="margin: 18px; padding-right: 0px; margin-top: 20px;" href="https://www.linknacional.com.br/wordpress/givewp/" target="_blank">' + __('Learn more now', 'payment-gateway-pix-for-givewp') + '</a>'

giveForm.after(noticeDiv)
const lknCieloNoticeDiv = document.createElement('div')
lknCieloNoticeDiv.setAttribute('style', "background-color: #fcf9e8;color: #646970;border: solid 1px #d3d3d3;border-left: 4px #dba617 solid;font-size: 16px;margin-top: 10px;")
lknCieloNoticeDiv.setAttribute('id', 'lkn-cielo-hosting-notice')

lknCieloNoticeDiv.innerHTML = '<a href="https://www.linknacional.com.br/wordpress/" target="_blank" style="text-decoration:none; display: block;padding: 10px;">' + __('WordPress Maintenance and Support!', 'payment-gateway-pix-for-givewp') + '</a>'



if (giveForm && lknCieloNoticeDiv) {
giveForm.after(noticeDiv)
noticeDiv.after(lknCieloNoticeDiv)

const linkInNoticeDiv = noticeDiv.getElementsByTagName('a');
const linkLknCieloInNoticeDiv = lknCieloNoticeDiv.getElementsByTagName('a');

setDarkCss(linkInNoticeDiv, linkLknCieloInNoticeDiv, noticeDiv, lknCieloNoticeDiv)

WPDarkMode.onChange(() => {

if (WPDarkMode.isActive) {
setDarkCss(linkInNoticeDiv, linkLknCieloInNoticeDiv, noticeDiv, lknCieloNoticeDiv)

} else {
const linkInNoticeDiv = noticeDiv.getElementsByTagName('a');
const linkLknCieloInNoticeDiv = lknCieloNoticeDiv.getElementsByTagName('a');

if (linkInNoticeDiv && linkLknCieloInNoticeDiv) {
for (let i = 0; i < linkInNoticeDiv.length; i++) {
linkInNoticeDiv[i].style.color = '#2271b1';
}
for (let i = 0; i < linkLknCieloInNoticeDiv.length; i++) {
linkLknCieloInNoticeDiv[i].style.color = '#2271b1';
}
}

noticeDiv.style.color = '#646970'
noticeDiv.style.backgroundColor = '#fcf9e8'
lknCieloNoticeDiv.style.color = '#646970'
lknCieloNoticeDiv.style.backgroundColor = '#fcf9e8'
}
});

}
const checkLogs = $('#check-logs')
checkLogs.on('click', (ev) => {
const dataStr = 'data:text/json;charset=utf-8,' + encodeURIComponent(lknAttr.logContents)

checkLogs.attr('href', dataStr)
checkLogs.attr('download', 'pix_payment.log')
})
if (checkLogs) {
checkLogs.on('click', (ev) => {
const dataStr = 'data:text/json;charset=utf-8,' + encodeURIComponent(lknAttr.logContents)

checkLogs.attr('href', dataStr)
checkLogs.attr('download', 'pix_payment.log')
})
}
}

function setDarkCss(linkInNoticeDiv, linkLknCieloInNoticeDiv, noticeDiv, lknCieloNoticeDiv) {
if (WPDarkMode.isActive) {
noticeDiv.style.color = 'white'
noticeDiv.style.backgroundColor = '#292a2a'
lknCieloNoticeDiv.style.backgroundColor = '#292a2a'
lknCieloNoticeDiv.style.color = 'white'

if (linkInNoticeDiv && linkLknCieloInNoticeDiv) {
for (let i = 0; i < linkInNoticeDiv.length; i++) {
linkInNoticeDiv[i].style.color = 'lightblue';
}
for (let i = 0; i < linkLknCieloInNoticeDiv.length; i++) {
linkLknCieloInNoticeDiv[i].style.color = 'lightblue';
}
}
}
}

function lknFindGetParameter (parameterName) {
function lknFindGetParameter(parameterName) {
let result = null
let tmp = []
location.search
16 changes: 12 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# 2.0.0 - 24/06/2024
* Migração para programação orientada a objetos;
* Implementação de autoloader;
* Adição de compatibilidade com o template GiveWP 3.0.0;
* Adição de limpeza automática de logs usando WP-CRON;
* Otimização do código e remoção de redundâncias;
* Atualização com as novas diretrizes do WordPress.

# 1.0.0 - 05/01/2024
* Added options to set the recipient's key using provided information.
* Added option to add the recipient's key to GiveWP donation forms.
* Added option to add billing details to donation forms.
* Added debug mode for advanced users.
* Adicionadas opções para definir a chave do destinatário usando as informações fornecidas;
* Adicionada opção para incluir a chave do destinatário nos formulários de doação GiveWP;
* Adicionada opção para incluir detalhes de faturamento nos formulários de doação;
* Adicionado modo de depuração para usuários avançados.
Loading

0 comments on commit 352b510

Please sign in to comment.