From: danix Date: Thu, 5 Nov 2020 12:33:07 +0000 (+0100) Subject: Added php linting with phpcs. Linted files. Removed pre 2.6 locale X-Git-Tag: release_05112020-1334 X-Git-Url: https://git.danix.xyz/?p=danixland-covid-italy.git;a=commitdiff_plain;h=82cad5d9c192c1abd4c1a5d88a3228e39c10cb48 Added php linting with phpcs. Linted files. Removed pre 2.6 locale compatibility. modificato: danixland-covid-italy.php modificato: index.php nuovo file: phpcs.xml modificato: uninstall.php --- diff --git a/danixland-covid-italy.php b/danixland-covid-italy.php index a4e2bac..f335ac9 100644 --- a/danixland-covid-italy.php +++ b/danixland-covid-italy.php @@ -1,12 +1,12 @@ $daily_data) { - # $item is the entry number and $daily_data is the array that we want to filter - $processed[$item] = dnxcovita_walker($daily_data); + $all_data_link = 'https://raw.githubusercontent.com/pcm-dpc/COVID-19/master/dati-json/dpc-covid19-ita-andamento-nazionale.json'; + if ( false === ( $dnxcovita_data = get_transient( 'dnxcovita_data' ) ) ) { + $json_data = file_get_contents( $all_data_link ); + $raw_data = json_decode( $json_data, true ); + $processed = array(); + foreach ( $raw_data as $item => $daily_data ) { + // $item is the entry number and $daily_data is the array that we want to filter + $processed[ $item ] = dnxcovita_walker( $daily_data ); } - set_transient('dnxcovita_data', $processed, DAY_IN_SECONDS); - } + set_transient( 'dnxcovita_data', $processed, DAY_IN_SECONDS ); + } } /** * Remove all unwanted fields from the data stored in the transient * - * @link https://danix.xyz - * @since 0.0.1 - * @package Dnxcovita + * @link https://danix.xyz + * @since 0.0.1 + * @package Dnxcovita */ -function dnxcovita_walker($value) { +function dnxcovita_walker( $value ) { // array that filters all keys we are not interested in $not_interested = array( 'stato', 'casi_da_sospetto_diagnostico', 'casi_da_screening', 'casi_testati', - 'note' + 'note', ); - $result = array_diff_key($value, array_flip($not_interested)); + $result = array_diff_key( $value, array_flip( $not_interested ) ); return $result; } /** * Return all data * - * @link https://danix.xyz - * @since 0.0.1 - * @package Dnxcovita + * @link https://danix.xyz + * @since 0.0.1 + * @package Dnxcovita */ function dnxcovita_get_all_data() { - $data = ( false === get_transient('dnxcovita_data') ) ? dnxcovita_retrieve_data() : get_transient('dnxcovita_data'); + $data = ( false === get_transient( 'dnxcovita_data' ) ) ? dnxcovita_retrieve_data() : get_transient( 'dnxcovita_data' ); return $data; } @@ -97,13 +90,13 @@ function dnxcovita_get_all_data() { /** * Return the latest data * - * @link https://danix.xyz - * @since 0.0.1 - * @package Dnxcovita + * @link https://danix.xyz + * @since 0.0.1 + * @package Dnxcovita */ function dnxcovita_get_latest_data() { - $data = ( false === get_transient('dnxcovita_data') ) ? dnxcovita_retrieve_data() : get_transient('dnxcovita_data'); - $rev = array_reverse($data); + $data = ( false === get_transient( 'dnxcovita_data' ) ) ? dnxcovita_retrieve_data() : get_transient( 'dnxcovita_data' ); + $rev = array_reverse( $data ); $output = $rev[0]; return $output; @@ -112,13 +105,13 @@ function dnxcovita_get_latest_data() { /** * Return the data from yesterday * - * @link https://danix.xyz - * @since 0.0.1 - * @package Dnxcovita + * @link https://danix.xyz + * @since 0.0.1 + * @package Dnxcovita */ function dnxcovita_get_previous_data() { - $data = ( false === get_transient('dnxcovita_data') ) ? dnxcovita_retrieve_data() : get_transient('dnxcovita_data'); - $last = array_slice($data, -2, 1, false); + $data = ( false === get_transient( 'dnxcovita_data' ) ) ? dnxcovita_retrieve_data() : get_transient( 'dnxcovita_data' ); + $last = array_slice( $data, -2, 1, false ); return $last; } @@ -126,9 +119,9 @@ function dnxcovita_get_previous_data() { /** * Add function to widgets_init that'll load our widget. * - * @link https://danix.xyz - * @since 0.0.1 - * @package Dnxcovita + * @link https://danix.xyz + * @since 0.0.1 + * @package Dnxcovita */ add_action( 'widgets_init', 'dnxcovita_register' ); @@ -136,12 +129,12 @@ add_action( 'widgets_init', 'dnxcovita_register' ); * Register our widget. * 'dnxcovita_Widget' is the widget class used below. * - * @link https://danix.xyz - * @since 0.0.1 - * @package Dnxcovita + * @link https://danix.xyz + * @since 0.0.1 + * @package Dnxcovita */ function dnxcovita_register() { - register_widget( 'dnxcovita_Widget' ); + register_widget( 'dnxcovita_Widget' ); } /** @@ -149,118 +142,131 @@ function dnxcovita_register() { * This class handles everything that needs to be handled with the widget: * the settings, form, display, and update. Nice! * - * @link https://danix.xyz - * @since 0.0.1 - * @package Dnxcovita + * @link https://danix.xyz + * @since 0.0.1 + * @package Dnxcovita */ class dnxcovita_Widget extends WP_Widget { - /** - * Widget setup. - */ - public function __construct() { - $control_ops = array('width' => 400, 'height' => 350); - parent::__construct( - 'dnx-covid-italy', // id_base - __('Italian Covid19 Situation', 'dnxcovita' ), // Name - array( 'description' => __('Display the current Covid19 situation in Italy.', 'dnxcovita') ), - $control_ops - ); - } - /** - * How to display the widget on the public side of the site. - */ - public function widget( $args, $instance ) { - extract( $args ); + /** + * Widget setup. + */ + public function __construct() { + $control_ops = array( + 'width' => 400, + 'height' => 350, + ); + parent::__construct( + 'dnx-covid-italy', // id_base + __( 'Italian Covid19 Situation', 'dnxcovita' ), // Name + array( 'description' => __( 'Display the current Covid19 situation in Italy.', 'dnxcovita' ) ), + $control_ops + ); + } - $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base ); + /** + * How to display the widget on the public side of the site. + */ + public function widget( $args, $instance ) { + extract( $args ); - echo $args['before_widget']; - if ( ! empty( $title ) ) { - echo $args['before_title'] . $title . $args['after_title']; - } ?> + $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base ); + + echo $args['before_widget']; + if ( ! empty( $title ) ) { + echo $args['before_title'] . $title . $args['after_title']; + } ?>
- + -

official github repository from the Ministry of Health.', 'dnxcovita'); +

+ official github repository from the Ministry of Health.', 'dnxcovita' ); $moh_site = 'https://github.com/pcm-dpc/COVID-19'; $moh_site_title = 'official github repository from the Ministry of Health report on COVID19 in Italy.'; - echo sprintf( $pull_desc, - esc_html($moh_site), - esc_html($moh_site_title) + echo sprintf( + $pull_desc, + esc_html( $moh_site ), + esc_html( $moh_site_title ) ); - ?>

-

+

+

+ %1$s'; $w3c_data = $latest_data['data']; - $ut = strtotime($w3c_data); - $ld = date('d/m/Y', $ut); - $lh = date('H:i', $ut); - $latest_check = sprintf( $timestring, - esc_html($expl), - esc_attr($w3c_data), - esc_html($ld), - esc_html($lh) + $ut = strtotime( $w3c_data ); + $ld = date( 'd/m/Y', $ut ); + $lh = date( 'H:i', $ut ); + $latest_check = sprintf( + $timestring, + esc_html( $expl ), + esc_attr( $w3c_data ), + esc_html( $ld ), + esc_html( $lh ) ); - echo $latest_check; - ?>

+ echo $latest_check; + ?> +

- $value) { - // we generate the fields first and then populate the output - if ( 'data' === $key ) { - $latest_date = date('d/m/Y', strtotime($value)); - $previous_date = date('d/m/Y', strtotime($yesterday_data[0][$key])); - } - // this check is redundant because $value is obtained straight from the json - // but still, better check than being sorry - if ( is_numeric($value) ) { - $latest_content = number_format($value, 0, ',', '˙'); - $diff = $value - $yesterday_data[0][$key]; - $diff_plusminus = (is_numeric($diff) && round($diff) > 1) ? ' +' : ' −'; - $diff_content = $diff_plusminus . number_format($diff, 0, ',', '˙'); - } - // Now we have all the values formatted so we can output the definition list - if ('data' !== $key) { - echo '
' . str_replace('_', ' ', $key) . '
'; - echo '
' . $latest_content . ' ' . $diff_content . '
'; + $value ) { + // we generate the fields first and then populate the output + if ( 'data' === $key ) { + $latest_date = date( 'd/m/Y', strtotime( $value ) ); + $previous_date = date( 'd/m/Y', strtotime( $yesterday_data[0][ $key ] ) ); + } + // this check is redundant because $value is obtained straight from the json + // but still, better check than being sorry + if ( is_numeric( $value ) ) { + $latest_content = number_format( $value, 0, ',', '˙' ); + $diff = $value - $yesterday_data[0][ $key ]; + $diff_plusminus = ( is_numeric( $diff ) && round( $diff ) > 1 ) ? ' +' : ''; + $diff_content = $diff_plusminus . number_format( $diff, 0, ',', '˙' ); + } + // Now we have all the values formatted so we can output the definition list + if ( 'data' !== $key ) { + echo '
' . str_replace( '_', ' ', $key ) . '
'; + echo '
' . $latest_content . ' ' . $diff_content . '
'; + } } - } ?> + ?>
- '' ) ); - $title = sanitize_text_field( $instance['title'] ); - ?> -

- - -

- '' ) ); + $title = sanitize_text_field( $instance['title'] ); + ?> +

+ + +

+ + + danix Wordpress Coding Standards + + + . + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/uninstall.php b/uninstall.php index db3ef81..77db867 100644 --- a/uninstall.php +++ b/uninstall.php @@ -19,10 +19,10 @@ * For more information, see the following discussion: * https://github.com/tommcfarlin/WordPress-Plugin-Boilerplate/pull/123#issuecomment-28541913 * - * @link https://danix.xyz - * @since 0.0.1 + * @link https://danix.xyz + * @since 0.0.1 * - * @package Dnxcovita + * @package Dnxcovita */ // If uninstall not called from WordPress, then exit.