*/ // @codingStandardsIgnoreStart class feedzy_wp_widget extends WP_Widget { // @codingStandardsIgnoreEnd /** * The class instance. * * @since 3.0.0 * @access public * @var feedzy_wp_widget $instance The instance of the class. */ public static $instance; /** * The feedzy_wp_widget constructor method * * @since 3.0.0 * @access public * * @param Feedzy_Rss_Feeds_Admin $plugin_admin The Feedzy_Rss_Feeds_Admin object. */ public function __construct( $plugin_admin = null ) { parent::__construct( false, $name = __( 'Feedzy RSS Feeds', 'feedzy-rss-feeds' ) ); self::$instance = $this; } /** * Returns the instance of this class as in the singleton pattern * * @since 3.0.0 * @access public * @return feedzy_wp_widget */ public static function get_instance() { if ( self::$instance === null ) { self::$instance = new self(); } return self::$instance; } /** * The register method for registering this widget class * * @since 3.0.0 * @access public */ public function registerWidget() { register_widget( 'feedzy_wp_widget' ); } /** * The widget form creation * * @since 3.0.0 * @access public * * @param string $instance The Widget instance. * * @return mixed */ public function form( $instance ) { $screen = get_current_screen(); // to prevent conflicts with plugins such as siteorigin page builder that call this function from outside of the 'widgets' screen. if ( ! empty( $screen ) && 'widgets' !== $screen->id ) { return; } $instance = wp_parse_args( $instance, $this->get_widget_defaults() ); $widget_form = '

'; foreach ( Feedzy_Rss_Feeds_Ui_Lang::get_form_elements() as $key_section => $section ) { $widget_form .= '

' . $section['title'] . '

'; if ( isset( $section['description'] ) ) { $widget_form .= '' . $section['description'] . ''; } foreach ( $section['elements'] as $id => $element ) { if ( isset( $element['disabled'] ) && $element['disabled'] ) { continue; } if ( $id == 'feed_title' ) { continue; } if ( $id == 'title' ) { $id = 'titlelength'; } $widget_form .= '

'; $widget_form .= ''; if ( $element['type'] == 'text' || $element['type'] == 'file' ) { $widget_form .= ''; } if ( $element['type'] == 'number' ) { $widget_form .= ''; } if ( $element['type'] == 'select' || $element['type'] == 'radio' ) { $widget_form .= ''; } $widget_form .= '

'; } } $widget_form .= '
'; $widget_form = apply_filters( 'feedzy_widget_form_filter', $widget_form, $instance, $this->get_widget_defaults() ); echo $widget_form; } /** * Get widget default values for params * * @return array List of defaults values */ public function get_widget_defaults() { $defaults = Feedzy_Rss_Feeds_Ui_Lang::get_form_defaults(); // rename title to title length as widget instance already have one $defaults['titlelength'] = $defaults['title']; $defaults['title'] = ''; $defaults['textarea'] = ''; return $defaults; } /** * Convert binary values to yes/no touple. * * @param mixed $value string Value to convert to yes/no. * * @return bool */ public static function bool_to_enum( $value ) { if ( in_array( $value, array( 'yes', 'no' ) ) ) { return $value; } $value = strval( $value ); if ( $value == '1' || $value == 'true' ) { return 'yes'; } if ( $value == '0' || $value == 'false' ) { return 'no'; } if ( $value == '' ) { return 'auto'; } return $value; } /** * * The update method * * @since 3.0.0 * @access public * * @param array $new_instance The new widget instance. * @param array $old_instance The old widget instance. * * @return array */ public function update( $new_instance, $old_instance ) { $instance = $old_instance; $instance['title'] = strip_tags( $new_instance['title'] ); if ( current_user_can( 'unfiltered_html' ) ) { $instance['textarea'] = $new_instance['textarea']; } else { $instance['textarea'] = stripslashes( wp_filter_post_kses( addslashes( $new_instance['textarea'] ) ) ); } $forms_ids = array_keys( $this->get_widget_defaults() ); foreach ( $forms_ids as $key ) { $instance[ $key ] = strip_tags( isset( $new_instance[ $key ] ) ? $new_instance[ $key ] : '' ); } $instance = apply_filters( 'feedzy_widget_update_filter', $instance, $new_instance ); return $instance; } /** * * The widget function * * @since 3.0.0 * @access public * * @param array $args The args to use. * @param array $instance The widget instance. */ public function widget( $args, $instance ) { $title = apply_filters( 'widget_title', $instance['title'] ); $textarea = apply_filters( 'widget_textarea', empty( $instance['textarea'] ) ? '' : $instance['textarea'], $instance ); // Display the widget body echo $args['before_widget']; // Check if title is set if ( $title ) { echo $args['before_title'] . $title . $args['after_title']; } // Check if text intro is set if ( isset( $instance['textarea'] ) && ! empty( $instance['textarea'] ) ) { echo '

' . wpautop( $textarea ) . '

'; } $feedzy_widget_shortcode_attributes = array( 'feeds' => $instance['feeds'], 'max' => $instance['max'], 'feed_title' => 'no', 'target' => $instance['target'], 'title' => $instance['titlelength'], 'meta' => self::bool_to_enum( $instance['meta'] ), 'summary' => self::bool_to_enum( $instance['summary'] ), 'summarylength' => $instance['summarylength'], 'thumb' => self::bool_to_enum( $instance['thumb'] ), 'default' => $instance['default'], 'size' => $instance['size'], 'keywords_title' => $instance['keywords_title'], 'keywords_ban' => $instance['keywords_ban'], ); $feedzy_widget_shortcode_attributes = apply_filters( 'feedzy_widget_shortcode_attributes_filter', $feedzy_widget_shortcode_attributes, $args, $instance ); echo feedzy_rss( $feedzy_widget_shortcode_attributes ); echo $args['after_widget']; } }