$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); } } /** * Remove all unwanted fields from the data stored in the transient * * @link https://danix.xyz * @since 0.0.1 * @package Dnxcovita */ 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' ); $result = array_diff_key($value, array_flip($not_interested)); return $result; } /** * Return all data * * @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'); return $data; } /** * Return the latest data * * @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); $output = $rev[0]; return $output; } /** * Return the data from yesterday * * @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); return $last; } /** * Add function to widgets_init that'll load our widget. * * @link https://danix.xyz * @since 0.0.1 * @package Dnxcovita */ 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 */ function dnxcovita_register() { register_widget( 'dnxcovita_Widget' ); } /** * User_Panel class. * 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 */ 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 ); $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'); $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) ); ?>

%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) ); 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 . '
'; } } ?>
'' ) ); $title = sanitize_text_field( $instance['title'] ); ?>