Skip to content

Commit

Permalink
Merge pull request #52 from nfe/php
Browse files Browse the repository at this point in the history
Versão mínima do PHP
  • Loading branch information
gblmarquez authored May 9, 2018
2 parents fea82f6 + 9f4c588 commit a2d9a7f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 26 deletions.
4 changes: 4 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Tags: woocommerce, shop, receipt, nfe, nota fiscal, nota, receita, sefaz, nfse,
Requires at least: 4.7
Tested up to: 4.9.4
Stable tag: 1.2.5
Requires PHP: 5.5
WC tested up to: 3.3.5
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -58,5 +60,7 @@ Thanks in advance for your help on any translation efforts!
* Added option to require an address when issuing an invoice.
* Fixed a bug where zero orders could be issued.
* Added notice in the order list when a order is zeroed.
* Added php require header on the readme.txt
* Fixed a bug that gave fatal error when on before PHP 5.5 versions.
* Fix - load_textdomain first from WP_LANG_DIR before load_plugin_textdomain
* Tweak - Tweak load_plugin_textdomain to be relative - this falls back to WP_LANG_DIR automatically. Can prevent "open_basedir restriction in effect".
64 changes: 38 additions & 26 deletions includes/admin/class-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,18 @@ public function init_form_fields() {
$lists = $this->get_companies();

if ( empty( $lists ) ) {
$company_list = array_merge( array( '' => __( 'No company found in account', 'woo-nfe' ) ), $lists );
$company_list = array_merge(array(
'' => __( 'No company found', 'woo-nfe' ),
), $lists );
} else {
$company_list = array_merge( array( '' => __( 'Select a company...', 'woo-nfe' ) ), $lists );
$company_list = array_merge(array(
'' => __( 'Select a company...', 'woo-nfe' ),
), $lists );
}
} else {
$company_list = array( 'no-company' => __( 'Enter your API key to see your company(ies).', 'woo-nfe' ) );
$company_list = array(
'no-company' => __( 'Enter your API key to see your company(ies).', 'woo-nfe' ),
);
}

$this->form_fields = array(
Expand Down Expand Up @@ -187,6 +193,7 @@ public function init_form_fields() {
'description' => sprintf( __( 'Log events such as API requests, you can check this log in %s.', 'woo-nfe' ), '<a href="' . esc_url( admin_url( 'admin.php?page=wc-status&tab=logs&log_file=' . esc_attr( $this->id ) . '-' . sanitize_file_name( wp_hash( $this->id ) ) . '.log' ) ) . '">' . __( 'System Status - Logs', 'woo-nfe' ) . '</a>' ),
),
);

return apply_filters( 'woo_nfe_settings_' . $this->id, $this->form_fields );
}

Expand All @@ -195,10 +202,9 @@ public function init_form_fields() {
*
* @return bool|array Bail with error message | An array of companies.
*/
private function get_companies() {
protected function get_companies() {
$key = nfe_get_field( 'api_key' );
$api_key = md5( $key );
$cache_key = 'woo_nfecompanylist_' . $api_key;
$cache_key = 'woo_nfecompanylist_' . md5( $key );
$company_list = get_transient( $cache_key );

// If there is a list from cache, load it.
Expand All @@ -223,34 +229,31 @@ private function get_companies() {
$company_list[ $company->id ] = ucwords( strtolower( $company->name ) );
}

// Save it for 30 days.
set_transient( $cache_key, $company_list, 30 * DAY_IN_SECONDS );

return $company_list;
}

/**
* URL that will receive the webhooks.
*
* @return string
*/
private function get_events_url() {
return sprintf( '%s/wc-api/%s', get_site_url(), WC_API_CALLBACK );
}

/**
* Displays notifications when the admin has something wrong with the NFe.io configuration.
*
* @return void
*/
public function display_errors() {
if ( $this->is_active() ) {
if ( empty( nfe_get_field( 'api_key' ) ) ) {
echo $this->get_message( '<strong>' . __( 'WooCommerce NFe', 'woo-nfe' ) . '</strong>: ' . sprintf( __( 'Plugin is enabled but no API key was provided. You should inform your API Key. %s', 'woo-nfe' ), '<a href="' . WOOCOMMERCE_NFE_SETTINGS_URL . '">' . __( 'Click here to configure!', 'woo-nfe' ) . '</a>' ) );
}

if ( nfe_get_field( 'issue_past_notes' ) === 'yes' && $this->issue_past_days() ) {
echo $this->get_message( '<strong>' . __( 'WooCommerce NFe', 'woo-nfe' ) . '</strong>: ' . sprintf( __( 'Enable Retroactive Issue is enabled, but no days was added. %s.', 'woo-nfe' ), '<a href="' . WOOCOMMERCE_NFE_SETTINGS_URL . '">' . __( 'Add a date to calculate or disable it.', 'woo-nfe' ) . '</a>' ) );
}
// Bail early.
if ( ! $this->is_active() ) {
return;
}

if ( ! $this->has_api_key() ) {
echo $this->get_message( '<strong>' . __( 'WooCommerce NFe', 'woo-nfe' ) . '</strong>: ' . sprintf( __( 'Plugin is enabled but no API key was provided. You should inform your API Key. %s', 'woo-nfe' ), '<a href="' . WOOCOMMERCE_NFE_SETTINGS_URL . '">' . __( 'Click here to configure!', 'woo-nfe' ) . '</a>' ) ); // WPCS: XSS ok.
}

$issue_past_notes = nfe_get_field( 'issue_past_notes' );
if ( 'yes' === $issue_past_notes && $this->issue_past_days() ) {
echo $this->get_message( '<strong>' . __( 'WooCommerce NFe', 'woo-nfe' ) . '</strong>: ' . sprintf( __( 'Enable Retroactive Issue is enabled, but no days was added. %s.', 'woo-nfe' ), '<a href="' . WOOCOMMERCE_NFE_SETTINGS_URL . '">' . __( 'Add a date to calculate or disable it.', 'woo-nfe' ) . '</a>' ) ); // WPCS: XSS ok.
}
}

Expand All @@ -260,7 +263,7 @@ public function display_errors() {
* @return void
*/
public function nfe_api_error_msg() {
echo $this->get_message( '<strong>' . __( 'WooCommerce NFe.io', 'woo-nfe' ) . '</strong>: ' . sprintf( __( 'Unable to load the companies list from NFe.io.', 'woo-nfe' ) ) );
echo $this->get_message( '<strong>' . __( 'WooCommerce NFe.io', 'woo-nfe' ) . '</strong>: ' . sprintf( __( 'Unable to load the companies list from NFe.io.', 'woo-nfe' ) ) ); // WPCS: XSS ok.
}

/**
Expand All @@ -281,12 +284,21 @@ private function get_message( $message, $type = 'error' ) {
return ob_get_clean();
}

/**
* URL that will receive the webhooks.
*
* @return string
*/
protected function get_events_url() {
return sprintf( '%s/wc-api/%s', get_site_url(), WC_API_CALLBACK );
}

/**
* Issue past date check.
*
* @return bool
*/
public function issue_past_days() {
protected function issue_past_days() {
$days = nfe_get_field( 'issue_past_days' );

if ( empty( $days ) ) {
Expand All @@ -301,7 +313,7 @@ public function issue_past_days() {
*
* @return bool
*/
public function has_api_key() {
protected function has_api_key() {
$key = nfe_get_field( 'api_key' );

if ( empty( $key ) ) {
Expand All @@ -316,7 +328,7 @@ public function has_api_key() {
*
* @return bool
*/
public function is_active() {
protected function is_active() {
$enabled = nfe_get_field( 'nfe_enable' );

if ( empty( $enabled ) ) {
Expand Down

0 comments on commit a2d9a7f

Please sign in to comment.