450, 'height' => 325, ]; \wp_register_widget_control( $id, $name, [ $this,'WidgetMeteoControl' ], $options ); } /** * Setup 3B Meteo Widget Frontend */ function WidgetMeteo($vars) { global $wpdb; global $wpdb_query; global $wp_rewrite; extract($vars); $options = get_option('widget_trebimeteo'); $trebimeteotitle = $options['trebimeteotitle']; $trebiregione = urlencode($options['trebiregione']); $trebilocalita = urlencode($options['trebilocalita']); $trebicuno = urlencode($options['trebicuno']); $trebicdue = urlencode($options['trebicdue']); $trebictre = urlencode($options['trebictre']); $trebibuno = urlencode($options['trebibuno']); $trebibdue = urlencode($options['trebibdue']); $trebibtre = urlencode($options['trebibtre']); $trebilarghezza = urlencode($options['trebilarghezza']); $trebialtezza = urlencode($options['trebialtezza']); $trebitipo = urlencode($options['trebitipo']); $before_widget='
'; $output = ''; $output .= $before_widget; $output .= $before_title; $output .= $trebimeteotitle; $output .= $after_title; $query = []; $default_iframe_attr = [ 'src' => '', 'width' => $trebilarghezza ?? 150, 'height' => $trebialtezza ?? 190, 'frameborder' => 0, ]; switch ( $trebitipo ) { case 'lsneve': case 'treale': case 'lsmari': case 'xssmall': $query = [ 'loc' => $trebilocalita, 'tm' => $trebitipo, 'c1' => $trebicuno, 'b1' => $trebibuno, 'b2' => $trebibdue, ]; break; case 'lbigor': case 'lsmall': $query = [ 'loc' => $trebilocalita, 'tm' => $trebitipo, 'new' => 1, 'c1' => $trebicuno, 'c2' => $trebicdue, 'b1' => $trebibuno, 'b2' => $trebibdue, 'b3' => $trebibtre, ]; break; case 'ssmall': $query = [ 'loc' => $trebilocalita, 'p' => 1, 'tm' => $trebitipo, 'new' => 1, 'c1' => $trebicuno, 'c2' => $trebicdue, 'b1' => $trebibuno, 'b2' => $trebibdue, 'b3' => $trebibtre, ]; break; case 'lbig': $query = [ 'loc' => $trebilocalita, 'tm' => $trebitipo, 'new' => 1, 'c1' => $trebicuno, 'c2' => $trebicdue, 'c3' => $trebictre, 'b1' => $trebibuno, 'b2' => $trebibdue, ]; break; case 'oraxora': $query = [ 'loc' => $trebilocalita, 'tm' => $trebitipo, 'c1' => $trebicuno, 'c2' => $trebicdue, 'c3' => $trebictre, 'b1' => $trebibuno, 'b2' => $trebibdue, ]; break; case 'lneve': case 'lmari': $query = [ 'loc' => $trebilocalita, 'tm' => $trebitipo, 'c1' => $trebicuno, 'c3' => $trebictre, 'b1' => $trebibuno, 'b2' => $trebibdue, ]; break; case 'msmall': $query = [ 'idreg' => $trebiregione, 'tm' => $trebitipo, 'new' => 1, 'c1' => $trebicuno, 'b1' => $trebibuno, 'b2' => $trebibdue, ]; break; case 'msmacro': $query = [ 'idreg' => $trebiregione, 'tm' => $trebitipo, 'c1' => $trebicuno, 'c2' => $trebicdue, 'c3' => $trebictre, 'b1' => $trebibuno, 'b2' => $trebibdue, ]; break; case 'mmari': $query = [ 'idreg' => $trebiregione, 'tm' => $trebitipo, 'c1' => $trebicuno, 'c2' => $trebicdue, 'b1' => $trebibuno, 'b2' => $trebibdue, 'c3' => $trebictre, ]; break; } $url = new \TreBiMeteo\UrlBuilder( 'https://portali.3bmeteo.com/3bm_meteo.php' ); $iframe = new \TreBiMeteo\IFrameBuilder( \array_replace( $default_iframe_attr, [ 'src' => (string) $url->query( $query ), ] ) ); $output .= $iframe; if ( $trebitipo === 'mmari' || $trebitipo === 'msmacro' || $trebitipo === 'msmall' ) { $output .= trebi_getUrlRegione($trebiregione); } else { $output .= trebi_getUrlLoc($trebilocalita); } $output .= $after_widget; echo $output; } /** * Setup 3B Meteo Widget Backend */ function WidgetMeteoControl() { $options = get_option('widget_trebimeteo'); if ( ! is_array($options) ) { $options = [ 'trebimeteotitle' => 'Previsioni Meteo', 'trebiregione' => '1', 'trebilocalita' => '6', 'trebicuno' => 'ffffff', 'trebicdue' => 'ffffff', 'trebictre' => 'ffffff', 'trebibuno' => '93c1db', 'trebibdue' => '3a8ebd', 'trebibtre' => 'ffffff', 'trebilarghezza' => '190', 'trebialtezza' => '240', 'trebitipo' => 'xssmall' ]; } if ( isset( $_POST['trebimeteo-submit'] ) && $_POST['trebimeteo-submit'] ) { // Remember to sanitize and format use input appropriately. $options['trebimeteotitle'] = strip_tags(stripslashes($_POST['trebimeteotitle'])); $options['trebiregione'] = strip_tags(stripslashes($_POST['trebiregione'])); $options['trebilocalita'] = strip_tags(stripslashes($_POST['trebilocalita'])); $options['trebicuno'] = strip_tags(stripslashes($_POST['trebicuno'])); $options['trebicdue'] = strip_tags(stripslashes($_POST['trebicdue'])); $options['trebictre'] = strip_tags(stripslashes($_POST['trebictre'])); $options['trebibuno'] = strip_tags(stripslashes($_POST['trebibuno'])); $options['trebibdue'] = strip_tags(stripslashes($_POST['trebibdue'])); $options['trebibtre'] = strip_tags(stripslashes($_POST['trebibtre'])); $options['trebialtezza'] = strip_tags(stripslashes($_POST['trebialtezza'])); $options['trebilarghezza'] = strip_tags(stripslashes($_POST['trebilarghezza'])); $options['trebitipo'] = strip_tags(stripslashes($_POST['trebitipo'])); update_option('widget_trebimeteo', $options); } $trebimeteotitle = htmlspecialchars($options['trebimeteotitle'], ENT_QUOTES); $trebiregione = htmlspecialchars($options['trebiregione'], ENT_QUOTES); $trebilocalita = htmlspecialchars($options['trebilocalita'], ENT_QUOTES); $trebicuno = htmlspecialchars($options['trebicuno'], ENT_QUOTES); $trebicdue = htmlspecialchars($options['trebicdue'], ENT_QUOTES); $trebictre = htmlspecialchars($options['trebictre'], ENT_QUOTES); $trebibuno = htmlspecialchars($options['trebibuno'], ENT_QUOTES); $trebibdue = htmlspecialchars($options['trebibdue'], ENT_QUOTES); $trebibtre = htmlspecialchars($options['trebibtre'], ENT_QUOTES); $trebialtezza = htmlspecialchars($options['trebialtezza'], ENT_QUOTES); $trebilarghezza = htmlspecialchars($options['trebilarghezza'], ENT_QUOTES); $trebitipo = htmlspecialchars($options['trebitipo'], ENT_QUOTES); $xpath = WP_PLUGIN_URL.'/'.str_replace(basename( __FILE__),"",plugin_basename(__FILE__)); ?>'xssmall', 'trebi-a2' => 'lsmall', 'trebi-a3' => 'lbigor', 'trebi-b1' => 'treale', 'trebi-b2' => 'ssmall', 'trebi-c1' => 'lbig', 'trebi-c2' => 'oraxora', 'trebi-d1' => 'msmall', 'trebi-d2' => 'msmacro', 'trebi-e1' => 'lsmari', 'trebi-e2' => 'lmari', 'trebi-f1' => 'mmari', 'trebi-g1' => 'lsneve', 'trebi-g2' => 'lneve', ]; } private function get( $key, $default = '' ) { $config = $this->config(); return $config[ $key ] ?? $default; } /** * Handler for 3B Meteo Widget Shortcode * $atts ::= array of attributes * $content ::= text within enclosing form of shortcode element * $code ::= the shortcode found, when == callback name * examples: [my-shortcode] * [my-shortcode/] * [my-shortcode foo='bar'] * [my-shortcode foo='bar'/] * [my-shortcode]content[/my-shortcode] * [my-shortcode foo='bar']content[/my-shortcode] * * @return string */ function trebi_shortcode_handler( $atts, $content = null, $code = "" ) { $type = $this->get( $code ); $url = new \TreBiMeteo\UrlBuilder( 'https://portali.3bmeteo.com/3bm_meteo.php' ); $default_iframe_attr = [ 'src' => '', 'width' => $atts['width'] ?? 150, 'height' => $atts['height'] ?? 190, 'frameborder' => 0, ]; switch ( $type ) { case 'xssmall': $default = [ 'loc' => '6', 'tm' => 'xssmall', 'c1' => 'ffffff', 'b1' => '93c1db', 'b2' => '3a8ebd', ]; $new_atts = shortcode_atts( $default, $atts, $code ); $wloc = trebi_getUrlLoc( (int) $new_atts['loc'] ); $iframe_attr = [ 'src' => (string) $url->query( $new_atts ), ]; $iframe = new \TreBiMeteo\IFrameBuilder( \array_replace( $default_iframe_attr, $iframe_attr ) ); return $iframe . $wloc; case 'lsmall': $default = [ 'loc' => '6', 'tm' => 'lsmall', 'new' => '1', 'c1' => '999999', 'c2' => 'ffffff', 'b1' => '93c1db', 'b2' => 'f0f0f0', 'b3' => '2a7fae', ]; $new_atts = shortcode_atts( $default, $atts, $code ); $wloc = trebi_getUrlLoc( (int) $new_atts['loc'] ); $iframe_attr = [ 'src' => (string) $url->query( $new_atts ), 'width' => 185, 'height' => 330, ]; $iframe = new \TreBiMeteo\IFrameBuilder( \array_replace( $default_iframe_attr, $iframe_attr ) ); return $iframe . $wloc; case 'lbigor': $default = [ 'loc' => '6', 'tm' => 'lbigor', 'new' => '1', 'c1' => 'ffffff', 'c2' => '888888', 'b1' => '93c1db', 'b2' => '3a8ebd', 'b3' => 'f0f0f0', ]; $new_atts = shortcode_atts( $default, $atts, $code ); $wloc = trebi_getUrlLoc( (int) $new_atts['loc'] ); $iframe_attr = [ 'src' => (string) $url->query( $new_atts ), 'width' => 455, 'height' => 195, ]; $iframe = new \TreBiMeteo\IFrameBuilder( \array_replace( $default_iframe_attr, $iframe_attr ) ); return $iframe . $wloc; case 'treale': $default = [ 'loc' => '6', 'tm' => 'treale', 'c1' => 'ffffff', 'b1' => '93c1db', 'b2' => '3a8ebd', ]; $new_atts = shortcode_atts( $default, $atts, $code ); $wloc = trebi_getUrlLoc( (int) $new_atts['loc'] ); $iframe_attr = [ 'src' => (string) $url->query( $new_atts ), 'width' => 195, 'height' => 165, ]; $iframe = new \TreBiMeteo\IFrameBuilder( \array_replace( $default_iframe_attr, $iframe_attr ) ); return $iframe . $wloc; case 'ssmall': $default = [ 'loc' => '6', 'p' => '1', 'tm' => 'ssmall', 'new' => '1', 'c1' => 'ffffff', 'c2' => 'aaaaaa', 'b1' => '93c1db', 'b2' => '3a8ebd', 'b3' => 'f0f0f0', ]; $new_atts = shortcode_atts( $default, $atts, $code ); $wloc = trebi_getUrlLoc( (int) $new_atts['loc'] ); $iframe_attr = [ 'src' => (string) $url->query( $new_atts ), 'width' => 245, 'height' => 380, ]; $iframe = new \TreBiMeteo\IFrameBuilder( \array_replace( $default_iframe_attr, $iframe_attr ) ); return $iframe . $wloc; case 'lbig': $default = [ 'loc' => '6', 'tm' => 'lbig', 'new' => '1', 'c1' => '777777', 'c2' => 'ffffff', 'c3' => '93c1db', 'b1' => '93c1db', 'b2' => '3a8ebd', ]; $new_atts = shortcode_atts( $default, $atts, $code ); $wloc = trebi_getUrlLoc( (int) $new_atts['loc'] ); $iframe_attr = [ 'src' => (string) $url->query( $new_atts ), 'width' => 460, 'height' => 380, ]; $iframe = new \TreBiMeteo\IFrameBuilder( \array_replace( $default_iframe_attr, $iframe_attr ) ); return $iframe . $wloc; case 'oraxora': $default = [ 'loc' => '6', 'tm' => 'oraxora', 'c1' => 'ffffff', 'c2' => '777777', 'c3' => '93c1db', 'b1' => '93c1db', 'b2' => '3a8ebd', ]; $new_atts = shortcode_atts( $default, $atts, $code ); $wloc = trebi_getUrlLoc( (int) $new_atts['loc'] ); $iframe_attr = [ 'src' => (string) $url->query( $new_atts ), 'width' => 455, 'height' => 500, ]; $iframe = new \TreBiMeteo\IFrameBuilder( \array_replace( $default_iframe_attr, $iframe_attr ) ); return $iframe . $wloc; case 'msmall': $default = [ 'idreg' => '1', 'tm' => 'msmall', 'new' => '1', 'c1' => 'ffffff', 'b1' => '93c1db', 'b2' => '3a8ebd', ]; $new_atts = shortcode_atts( $default, $atts, $code ); $wloc = trebi_getUrlRegione( (int) $new_atts['idreg'] ); $iframe_attr = [ 'src' => (string) $url->query( $new_atts ), 'width' => 190, 'height' => 300, ]; $iframe = new \TreBiMeteo\IFrameBuilder( \array_replace( $default_iframe_attr, $iframe_attr ) ); return $iframe . $wloc; case 'msmacro': $default = [ 'idreg' => '1', 'tm' => 'msmacro', 'c1' => 'ffffff', 'c2' => '555555', 'c3' => '93c1db', 'b1' => '93c1db', 'b2' => '3a8ebd', ]; $new_atts = shortcode_atts( $default, $atts, $code ); $wloc = trebi_getUrlRegione( (int) $new_atts['idreg'] ); $iframe_attr = [ 'src' => (string) $url->query( $new_atts ), 'width' => 660, 'height' => 515, ]; $iframe = new \TreBiMeteo\IFrameBuilder( \array_replace( $default_iframe_attr, $iframe_attr ) ); return $iframe . $wloc; case 'lsmari': $default = [ 'loc' => '6', 'tm' => 'lsmari', 'c1' => 'ffffff', 'b1' => '93c1db', 'b2' => '3a8ebd', ]; $new_atts = shortcode_atts( $default, $atts, $code ); $wloc = trebi_getUrlLoc( (int) $new_atts['loc'] ); $iframe_attr = [ 'src' => (string) $url->query( $new_atts ), 'width' => 190, 'height' => 260, ]; $iframe = new \TreBiMeteo\IFrameBuilder( \array_replace( $default_iframe_attr, $iframe_attr ) ); return $iframe . $wloc; case 'lmari': $default = [ 'loc' => '6', 'tm' => 'lmari', 'c1' => 'ffffff', 'c3' => '93c1db', 'b1' => '93c1db', 'b2' => '3a8ebd', ]; $new_atts = shortcode_atts( $default, $atts, $code ); $wloc = trebi_getUrlLoc( (int) $new_atts['loc'] ); $iframe_attr = [ 'src' => (string) $url->query( $new_atts ), 'width' => 460, 'height' => 380, ]; $iframe = new \TreBiMeteo\IFrameBuilder( \array_replace( $default_iframe_attr, $iframe_attr ) ); return $iframe . $wloc; case 'mmari': $default = [ 'idreg' => '1', 'tm' => 'mmari', 'c1' => 'ffffff', 'c2' => '555555', 'b1' => '93c1db', 'b2' => '3a8ebd', 'c3' => '93c1db', ]; $new_atts = shortcode_atts( $default, $atts, $code ); $wloc = trebi_getUrlRegione( (int) $new_atts['idreg'] ); $iframe_attr = [ 'src' => (string) $url->query( $new_atts ), 'width' => 650, 'height' => 515, ]; $iframe = new \TreBiMeteo\IFrameBuilder( \array_replace( $default_iframe_attr, $iframe_attr ) ); return $iframe . $wloc; case 'lsneve': $default = [ 'loc' => '6', 'tm' => 'lsneve', 'c1' => 'ffffff', 'b1' => '93c1db', 'b2' => '3a8ebd', ]; $new_atts = shortcode_atts( $default, $atts, $code ); $wloc = trebi_getUrlLoc( (int) $new_atts['loc'] ); $iframe_attr = [ 'src' => (string) $url->query( $new_atts ), 'width' => 210, 'height' => 240, ]; $iframe = new \TreBiMeteo\IFrameBuilder( \array_replace( $default_iframe_attr, $iframe_attr ) ); return $iframe . $wloc; case 'lneve': $default = [ 'loc' => '6', 'tm' => 'lneve', 'c1' => 'ffffff', 'c3' => '93c1db', 'b1' => '93c1db', 'b2' => '3a8ebd', ]; $new_atts = shortcode_atts( $default, $atts, $code ); $wloc = trebi_getUrlLoc( (int) $new_atts['loc'] ); $iframe_attr = [ 'src' => (string) $url->query( $new_atts ), 'width' => 490, 'height' => 420, ]; $iframe = new \TreBiMeteo\IFrameBuilder( \array_replace( $default_iframe_attr, $iframe_attr ) ); return $iframe . $wloc; } return $this->trebi_shortcode_handler( $atts, $content, 'trebi-a1' ); } //Config page function DesignAdminPage() { require 'admin-view.php'; } /** * Returns the plugin version * * Uses the WP API to get the meta data from the top of this file (comment) * * @return string The version like 1.0.10 */ function GetVersion() { if(!function_exists('get_plugin_data')) { if(file_exists(ABSPATH . 'wp-admin/includes/plugin.php')) require_once(ABSPATH . 'wp-admin/includes/plugin.php'); //2.3+ else if(file_exists(ABSPATH . 'wp-admin/admin-functions.php')) require_once(ABSPATH . 'wp-admin/admin-functions.php'); //2.1 else return "0.ERROR"; } $data = get_plugin_data(__FILE__); return $data['Version']; } }