/**
  * Front-end display of widget.
  *
  * @see WP_Widget::widget()
  *
  * @param array $args
  * @param array $instance
  */
 public function widget($args, $instance)
 {
     $type = !empty($instance['type']) ? $instance['type'] : '';
     $from = !empty($instance['from']) ? $instance['from'] : '';
     $to = !empty($instance['to']) ? $instance['to'] : '';
     $more_news = !empty($instance['more_news']) ? $instance['more_news'] : '';
     // prepare data for mustache template
     $instance['more_news_on'] = !empty($instance['more_news']) ? true : false;
     $instance['link_to_more_news'] = get_permalink(get_option('page_for_posts'));
     $instance['read_more_text'] = empty($instance['read_more_text']) ? esc_html__('More news', 'proteuswidgets') : esc_html($instance['read_more_text']);
     // Get/set cache data just once for multiple widgets
     $recent_posts_data = PW_Functions::get_cached_data('pw_recent_posts', $this->max_post_number);
     // Array with posts to display
     $recent_posts = array();
     switch ($type) {
         case 'block':
             $instance['block'] = true;
             if ($from <= count($recent_posts_data)) {
                 $recent_posts[] = $recent_posts_data[$from - 1];
             }
             break;
         case 'inline':
             $instance['block'] = false;
             $recent_posts = array_intersect_key($recent_posts_data, array_flip(range($from - 1, $to - 1)));
             break;
     }
     $text = array('by' => esc_html__('By', 'proteuswidgets'), 'more_news' => $instance['read_more_text']);
     // Mustache widget-latest-news template rendering
     echo $this->mustache->render(apply_filters('pw/widget_latest_news_view', 'widget-latest-news'), array('args' => $args, 'instance' => $instance, 'posts' => array_values((array) $recent_posts), 'text' => $text));
 }