| @@ -1,70 +1,110 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -/** | |
| 4 | - * Welcart_featured Class | |
| 5 | - */ | |
| 6 | -class Welcart_featured extends WP_Widget { | |
| 7 | - /** constructor */ | |
| 8 | - function Welcart_featured() { | |
| 9 | - parent::WP_Widget(false, $name = 'Welcart '.__('Items recommended', 'usces')); | |
| 10 | - } | |
| 11 | - | |
| 12 | - /** @see WP_Widget::widget */ | |
| 13 | - function widget($args, $instance) { | |
| 14 | - global $usces; | |
| 15 | - extract( $args ); | |
| 16 | - $title = ( !isset($instance['title']) || WCUtils::is_blank($instance['title'])) ? 'Welcart '.__('Items recommended', 'usces') : $instance['title']; | |
| 17 | - $icon = ( !isset($instance['icon']) || WCUtils::is_blank($instance['icon'])) ? 1 : (int)$instance['icon']; | |
| 18 | - $num = ( !isset($instance['num']) || WCUtils::is_blank($instance['num'])) ? 1 : (int)$instance['num']; | |
| 19 | - //if($icon == 1) $before_title = '<div class="widget_title"><img src="' . USCES_PLUGIN_URL . '/images/osusume.png" alt="' . $title . '" width="24" height="24" />'; | |
| 20 | - $img_path = file_exists(get_stylesheet_directory().'/images/osusume.png') ? get_stylesheet_directory_uri().'/images/osusume.png' : USCES_FRONT_PLUGIN_URL . '/images/osusume.png'; | |
| 21 | - if($icon == 1) $before_title .= '<img src="' . $img_path . '" alt="' . $title . '" />'; | |
| 22 | - ?> | |
| 23 | - <?php echo $before_widget; ?> | |
| 24 | - <?php echo $before_title | |
| 25 | - . esc_html($title) | |
| 26 | - . $after_title; ?> | |
| 27 | - | |
| 28 | - <ul class="ucart_featured_body ucart_widget_body"> | |
| 29 | - <?php | |
| 30 | -// $offset = usces_posts_random_offset(get_posts('category='.usces_get_cat_id( 'itemreco' ))); | |
| 31 | -// $myposts = get_posts('numberposts=' . $num . '&offset='.$offset.'&category='.usces_get_cat_id( 'itemreco' )); | |
| 32 | - $myposts = get_posts('numberposts=' . $num . '&category='.usces_get_cat_id( 'itemreco' ) . '&orderby=rand'); | |
| 33 | - $list_index = 0; | |
| 34 | - foreach($myposts as $post) : | |
| 35 | - $post_id = $post->ID; | |
| 36 | - ?> | |
| 37 | - <li class="featured_list<?php echo ((1 === (int)$num) ? ' featured_single' : ''); ?><?php echo apply_filters('usces_filter_featured_list_class', NULL, $list_index, $num); ?>"> | |
| 38 | - <?php | |
| 39 | - $list = '<div class="thumimg"><a href="' . get_permalink($post_id) . '">' . usces_the_itemImage(0, 150, 150, $post, 'return' ) . "</a></div>\n"; | |
| 40 | - $list .= '<div class="thumtitle"><a href="' . get_permalink($post_id) . '" rel="bookmark">' . $usces->getItemName($post_id) . ' (' . $usces->getItemCode($post_id) . ")</a></div>\n"; | |
| 41 | - echo apply_filters( 'usces_filter_featured_widget', $list, $post, $list_index, $instance ); | |
| 42 | - ?> | |
| 43 | - </li> | |
| 44 | - <?php $list_index++; endforeach; ?> | |
| 45 | - </ul> | |
| 46 | - | |
| 47 | - <?php echo $after_widget; ?> | |
| 48 | - <?php | |
| 49 | - wp_reset_postdata(); | |
| 50 | - } | |
| 51 | - | |
| 52 | - /** @see WP_Widget::update */ | |
| 53 | - function update($new_instance, $old_instance) { | |
| 54 | - return $new_instance; | |
| 55 | - } | |
| 56 | - | |
| 57 | - /** @see WP_Widget::form */ | |
| 58 | - function form($instance) { | |
| 59 | - $title = ( !isset($instance['title']) || WCUtils::is_blank($instance['title'])) ? 'Welcart '.__('Items recommended', 'usces') : esc_attr($instance['title']); | |
| 60 | - $icon = ( !isset($instance['icon']) || WCUtils::is_blank($instance['icon'])) ? 1 : (int)$instance['icon']; | |
| 61 | - $num = ( !isset($instance['num']) || WCUtils::is_blank($instance['num'])) ? 1 : (int)$instance['num']; | |
| 62 | - ?> | |
| 63 | - <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> | |
| 64 | - <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> | |
| 65 | - <p><label for="<?php echo $this->get_field_id('num'); ?>"><?php _e('number of indication', 'usces'); ?> <input class="widefat" id="<?php echo $this->get_field_id('num'); ?>" name="<?php echo $this->get_field_name('num'); ?>" type="text" value="<?php echo $num; ?>" /></label></p> | |
| 66 | - <?php | |
| 67 | - } | |
| 68 | - | |
| 69 | -} | |
| 70 | -?> | |
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Welcart Featured Widget | |
| 4 | + * | |
| 5 | + * @package Welcart | |
| 6 | + */ | |
| 7 | + | |
| 8 | +/** | |
| 9 | + * Welcart_featured Class | |
| 10 | + * | |
| 11 | + * @see WP_Widget | |
| 12 | + */ | |
| 13 | +class Welcart_featured extends WP_Widget { | |
| 14 | + | |
| 15 | + /** | |
| 16 | + * Constructor. | |
| 17 | + */ | |
| 18 | + public function __construct() { | |
| 19 | + $widget_ops = array( | |
| 20 | + 'classname' => 'widget_welcart_featured', | |
| 21 | + 'description' => __( 'Display recommended items.', 'usces' ), | |
| 22 | + ); | |
| 23 | + parent::__construct( 'welcart_featured', 'Welcart ' . __( 'Items recommended', '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 | + global $usces; | |
| 36 | + extract( $args ); | |
| 37 | + $title = $instance['title']; | |
| 38 | + $icon = ( ! isset( $instance['icon'] ) || WCUtils::is_blank( $instance['icon'] ) ) ? 1 : (int) $instance['icon']; | |
| 39 | + $num = ( ! isset( $instance['num'] ) || WCUtils::is_blank( $instance['num'] ) ) ? 1 : (int) $instance['num']; | |
| 40 | + $img_path = file_exists( get_stylesheet_directory() . '/images/osusume.png' ) ? get_stylesheet_directory_uri() . '/images/osusume.png' : USCES_FRONT_PLUGIN_URL . '/images/osusume.png'; | |
| 41 | + if ( 1 === $icon ) { | |
| 42 | + $before_title .= '<img src="' . $img_path . '" alt="' . $title . '" />'; | |
| 43 | + } | |
| 44 | + | |
| 45 | + wel_esc_script_e( $before_widget ); | |
| 46 | + if ( ! empty( $title ) ) { | |
| 47 | + wel_esc_script_e( $before_title . esc_html( $title ) . $after_title ); | |
| 48 | + } | |
| 49 | + ?> | |
| 50 | + | |
| 51 | + <ul class="ucart_featured_body ucart_widget_body"> | |
| 52 | + <?php | |
| 53 | + $myposts = get_posts( 'numberposts=' . $num . '&category=' . usces_get_cat_id( 'itemreco' ) . '&orderby=rand' ); | |
| 54 | + $class = ( 1 === (int) $num ) ? ' featured_single' : ''; | |
| 55 | + $list_index = 0; | |
| 56 | + foreach ( $myposts as $post ) : | |
| 57 | + $post_id = $post->ID; | |
| 58 | + ?> | |
| 59 | + <li class="featured_list<?php echo esc_attr( $class ); ?><?php echo apply_filters( 'usces_filter_featured_list_class', null, $list_index, $num ); ?>"> | |
| 60 | + <?php | |
| 61 | + $list = '<div class="thumimg"><a href="' . get_permalink( $post_id ) . '">' . usces_the_itemImage( 0, 150, 150, $post, 'return' ) . '</a></div>'; | |
| 62 | + $list .= '<div class="thumtitle"><a href="' . get_permalink( $post_id ) . '" rel="bookmark">' . esc_html( $usces->getItemName( $post_id ) ) . ' (' . esc_html( $usces->getItemCode( $post_id ) ) . ')</a></div>'; | |
| 63 | + echo apply_filters( 'usces_filter_featured_widget', $list, $post, $list_index, $instance ); | |
| 64 | + ?> | |
| 65 | + </li> | |
| 66 | + <?php | |
| 67 | + $list_index++; | |
| 68 | + endforeach; | |
| 69 | + ?> | |
| 70 | + </ul> | |
| 71 | + | |
| 72 | + <?php | |
| 73 | + wel_esc_script_e( $after_widget ); | |
| 74 | + | |
| 75 | + wp_reset_postdata(); | |
| 76 | + } | |
| 77 | + | |
| 78 | + /** | |
| 79 | + * Updates a particular instance of a widget. | |
| 80 | + * | |
| 81 | + * @see WP_Widget::update | |
| 82 | + * @param array $new_instance New settings for this instance as input by the user via | |
| 83 | + * WP_Widget::form(). | |
| 84 | + * @param array $old_instance Old settings for this instance. | |
| 85 | + * @return array Settings to save or bool false to cancel saving. | |
| 86 | + */ | |
| 87 | + public function update( $new_instance, $old_instance ) { | |
| 88 | + return $new_instance; | |
| 89 | + } | |
| 90 | + | |
| 91 | + /** | |
| 92 | + * Outputs the settings update form. | |
| 93 | + * | |
| 94 | + * @see WP_Widget::form | |
| 95 | + * @param array $instance Current settings. | |
| 96 | + */ | |
| 97 | + public function form( $instance ) { | |
| 98 | + $title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; | |
| 99 | + $icon = ( ! isset( $instance['icon'] ) || WCUtils::is_blank( $instance['icon'] ) ) ? 1 : (int) $instance['icon']; | |
| 100 | + $num = ( ! isset( $instance['num'] ) || WCUtils::is_blank( $instance['num'] ) ) ? 1 : (int) $instance['num']; | |
| 101 | + ?> | |
| 102 | + <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> | |
| 103 | + <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' ) ); ?>"> | |
| 104 | + <option value="1"<?php selected( $icon, 1 ); ?>><?php esc_html_e( 'Indication', 'usces' ); ?></option> | |
| 105 | + <option value="2"<?php selected( $icon, 2 ); ?>><?php esc_html_e( 'Non-indication', 'usces' ); ?></option></select></label> | |
| 106 | + </p> | |
| 107 | + <p><label for="<?php wel_esc_script_e( $this->get_field_id( 'num' ) ); ?>"><?php esc_html_e( 'number of indication', 'usces' ); ?> <input class="widefat" id="<?php wel_esc_script_e( $this->get_field_id( 'num' ) ); ?>" name="<?php wel_esc_script_e( $this->get_field_name( 'num' ) ); ?>" type="text" value="<?php wel_esc_script_e( $num ); ?>" /></label></p> | |
| 108 | + <?php | |
| 109 | + } | |
| 110 | +} | |