| @@ -1,55 +1,99 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -/** | |
| 4 | - * Welcart_category Class | |
| 5 | - */ | |
| 6 | -class Welcart_category extends WP_Widget { | |
| 7 | - /** constructor */ | |
| 8 | - function Welcart_category() { | |
| 9 | - parent::WP_Widget(false, $name = 'Welcart '.__('Categories', 'usces')); | |
| 10 | - } | |
| 11 | - | |
| 12 | - /** @see WP_Widget::widget */ | |
| 13 | - function widget($args, $instance) { | |
| 14 | - extract( $args ); | |
| 15 | - $title = ( !isset($instance['title']) || WCUtils::is_blank($instance['title'])) ? 'Welcart '.__('Categories', 'usces') : $instance['title']; | |
| 16 | - $cat_slug = ( !isset($instance['cat_slug']) || WCUtils::is_blank($instance['cat_slug'])) ? 'itemgenre' : $instance['cat_slug']; | |
| 17 | - $icon = ( !isset($instance['icon']) || WCUtils::is_blank($instance['icon'])) ? 1 : (int)$instance['icon']; | |
| 18 | - //if($icon == 1) $before_title = '<div class="widget_title"><img src="' . USCES_PLUGIN_URL . '/images/category2.png" alt="' . $title . '" width="24" height="24" />'; | |
| 19 | - $img_path = file_exists(get_stylesheet_directory().'/images/category.png') ? get_stylesheet_directory_uri().'/images/category.png' : USCES_FRONT_PLUGIN_URL . '/images/category.png'; | |
| 20 | - if($icon == 1) $before_title .= '<img src="' . $img_path . '" alt="' . $title . '" />'; | |
| 21 | - ?> | |
| 22 | - <?php echo $before_widget; ?> | |
| 23 | - <?php echo $before_title | |
| 24 | - . esc_html($title) | |
| 25 | - . $after_title; ?> | |
| 26 | - | |
| 27 | - <ul class="ucart_widget_body"> | |
| 28 | - <?php $cats = get_category_by_slug($cat_slug); ?> | |
| 29 | - <?php $cquery = 'use_desc_for_title=1&child_of='.$cats->term_id.'&title_li='; ?> | |
| 30 | - <?php wp_list_categories(apply_filters('usces_filter_welcart_category', $cquery, $cats->term_id)); ?> | |
| 31 | - </ul> | |
| 32 | - | |
| 33 | - <?php echo $after_widget; ?> | |
| 34 | - <?php | |
| 35 | - } | |
| 36 | - | |
| 37 | - /** @see WP_Widget::update */ | |
| 38 | - function update($new_instance, $old_instance) { | |
| 39 | - return $new_instance; | |
| 40 | - } | |
| 41 | - | |
| 42 | - /** @see WP_Widget::form */ | |
| 43 | - function form($instance) { | |
| 44 | - $title = ( !isset($instance['title']) || WCUtils::is_blank($instance['title'])) ? 'Welcart '.__('Categories', 'usces') : esc_attr($instance['title']); | |
| 45 | - $cat_slug = ( !isset($instance['cat_slug']) || WCUtils::is_blank($instance['cat_slug'])) ? 'itemgenre' : esc_attr($instance['cat_slug']); | |
| 46 | - $icon = ( !isset($instance['icon']) || WCUtils::is_blank($instance['icon'])) ? 1 : (int)$instance['icon']; | |
| 47 | - ?> | |
| 48 | - <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></label></p> | |
| 49 | - <p><label for="<?php echo $this->get_field_id('icon'); ?>"><?php _e('display of icon', 'usces'); ?>: <select class="widefat" id="<?php echo $this->get_field_id('icon'); ?>" name="<?php echo $this->get_field_name('icon'); ?>"><option value="1"<?php if($icon == 1){echo ' selected="selected"';} ?>><?php _e('Indication', 'usces'); ?></option><option value="2"<?php if($icon == 2){echo ' selected="selected"';} ?>><?php _e('Non-indication', 'usces'); ?></option></select></label></p> | |
| 50 | - <p><label for="<?php echo $this->get_field_id('cat_slug'); ?>"><?php _e('parent category(slug)', 'usces'); ?> <input class="widefat" id="<?php echo $this->get_field_id('cat_slug'); ?>" name="<?php echo $this->get_field_name('cat_slug'); ?>" type="text" value="<?php echo $cat_slug; ?>" /></label></p> | |
| 51 | - <?php | |
| 52 | - } | |
| 53 | - | |
| 54 | -} | |
| 55 | -?> | |
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Welcart Category Widget | |
| 4 | + * | |
| 5 | + * @package Welcart | |
| 6 | + */ | |
| 7 | + | |
| 8 | +/** | |
| 9 | + * Welcart_category Class | |
| 10 | + * | |
| 11 | + * @see WP_Widget | |
| 12 | + */ | |
| 13 | +class Welcart_category extends WP_Widget { | |
| 14 | + | |
| 15 | + /** | |
| 16 | + * Constructor. | |
| 17 | + */ | |
| 18 | + public function __construct() { | |
| 19 | + $widget_ops = array( | |
| 20 | + 'classname' => 'widget_welcart_category', | |
| 21 | + 'description' => __( 'Display item categories.', 'usces' ), | |
| 22 | + ); | |
| 23 | + parent::__construct( 'welcart_category', 'Welcart ' . __( 'Categories', 'usces' ), $widget_ops ); | |
| 24 | + } | |
| 25 | + | |
| 26 | + /** | |
| 27 | + * Echoes the widget content. | |
| 28 | + * | |
| 29 | + * @see WP_Widget::widget | |
| 30 | + * @param array $args Display arguments including 'before_title', 'after_title', | |
| 31 | + * 'before_widget', and 'after_widget'. | |
| 32 | + * @param array $instance The settings for the particular instance of the widget. | |
| 33 | + */ | |
| 34 | + public function widget( $args, $instance ) { | |
| 35 | + extract( $args ); | |
| 36 | + $title = $instance['title']; | |
| 37 | + $cat_slug = ( ! isset( $instance['cat_slug'] ) || WCUtils::is_blank( $instance['cat_slug'] ) ) ? 'itemgenre' : $instance['cat_slug']; | |
| 38 | + $icon = ( ! isset( $instance['icon'] ) || WCUtils::is_blank( $instance['icon'] ) ) ? 1 : (int) $instance['icon']; | |
| 39 | + $img_path = file_exists( get_stylesheet_directory() . '/images/category.png' ) ? get_stylesheet_directory_uri() . '/images/category.png' : USCES_FRONT_PLUGIN_URL . '/images/category.png'; | |
| 40 | + if ( 1 === $icon ) { | |
| 41 | + $before_title .= '<img src="' . $img_path . '" alt="' . $title . '" />'; | |
| 42 | + } | |
| 43 | + | |
| 44 | + wel_esc_script_e( $before_widget ); | |
| 45 | + if ( ! empty( $title ) ) { | |
| 46 | + wel_esc_script_e( $before_title . esc_html( $title ) . $after_title ); | |
| 47 | + } | |
| 48 | + ?> | |
| 49 | + | |
| 50 | + <ul class="ucart_widget_body"> | |
| 51 | + <?php | |
| 52 | + $cats = get_category_by_slug( $cat_slug ); | |
| 53 | + if ( ! empty( $cats ) ) { | |
| 54 | + $cquery = '&use_desc_for_title=1&child_of=' . $cats->term_id . '&title_li='; | |
| 55 | + $categories = get_categories( $cquery ); | |
| 56 | + if ( ! empty( $categories ) ) { | |
| 57 | + wp_list_categories( apply_filters( 'usces_filter_welcart_category', $cquery, $cats->term_id ) ); | |
| 58 | + } | |
| 59 | + } | |
| 60 | + ?> | |
| 61 | + </ul> | |
| 62 | + | |
| 63 | + <?php | |
| 64 | + wel_esc_script_e( $after_widget ); | |
| 65 | + } | |
| 66 | + | |
| 67 | + /** | |
| 68 | + * Updates a particular instance of a widget. | |
| 69 | + * | |
| 70 | + * @see WP_Widget::update | |
| 71 | + * @param array $new_instance New settings for this instance as input by the user via | |
| 72 | + * WP_Widget::form(). | |
| 73 | + * @param array $old_instance Old settings for this instance. | |
| 74 | + * @return array Settings to save or bool false to cancel saving. | |
| 75 | + */ | |
| 76 | + public function update( $new_instance, $old_instance ) { | |
| 77 | + return $new_instance; | |
| 78 | + } | |
| 79 | + | |
| 80 | + /** | |
| 81 | + * Outputs the settings update form. | |
| 82 | + * | |
| 83 | + * @see WP_Widget::form | |
| 84 | + * @param array $instance Current settings. | |
| 85 | + */ | |
| 86 | + public function form( $instance ) { | |
| 87 | + $title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; | |
| 88 | + $cat_slug = ( ! isset( $instance['cat_slug'] ) || WCUtils::is_blank( $instance['cat_slug'] ) ) ? 'itemgenre' : esc_attr( $instance['cat_slug'] ); | |
| 89 | + $icon = ( ! isset( $instance['icon'] ) || WCUtils::is_blank( $instance['icon'] ) ) ? 1 : (int) $instance['icon']; | |
| 90 | + ?> | |
| 91 | + <p><label for="<?php wel_esc_script_e( $this->get_field_id( 'title' ) ); ?>"><?php esc_html_e( 'Title:', 'usces' ); ?> <input class="widefat" id="<?php wel_esc_script_e( $this->get_field_id( 'title' ) ); ?>" name="<?php wel_esc_script_e( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php wel_esc_script_e( $title ); ?>" /></label></p> | |
| 92 | + <p><label for="<?php wel_esc_script_e( $this->get_field_id( 'icon' ) ); ?>"><?php esc_html_e( 'display of icon', 'usces' ); ?>: <select class="widefat" id="<?php wel_esc_script_e( $this->get_field_id( 'icon' ) ); ?>" name="<?php wel_esc_script_e( $this->get_field_name( 'icon' ) ); ?>"> | |
| 93 | + <option value="1"<?php selected( $icon, 1 ); ?>><?php esc_html_e( 'Indication', 'usces' ); ?></option> | |
| 94 | + <option value="2"<?php selected( $icon, 2 ); ?>><?php esc_html_e( 'Non-indication', 'usces' ); ?></option></select></label> | |
| 95 | + </p> | |
| 96 | + <p><label for="<?php wel_esc_script_e( $this->get_field_id( 'cat_slug' ) ); ?>"><?php esc_html_e( 'parent category(slug)', 'usces' ); ?> <input class="widefat" id="<?php wel_esc_script_e( $this->get_field_id( 'cat_slug' ) ); ?>" name="<?php wel_esc_script_e( $this->get_field_name( 'cat_slug' ) ); ?>" type="text" value="<?php wel_esc_script_e( $cat_slug ); ?>" /></label></p> | |
| 97 | + <?php | |
| 98 | + } | |
| 99 | +} | |