function widget($args, $instance)
 {
     extract($args);
     $title = apply_filters('widget_title', $instance['title']);
     $limit = (int) @$instance['limit'];
     $limit = $limit ? $limit : 5;
     $data = new Wdpv_Options();
     $voted_timeframe = @$instance['voted_timeframe'];
     if (!in_array($voted_timeframe, array_keys($data->timeframes))) {
         $voted_timeframe = false;
     }
     if (is_main_site()) {
         $model = new Wdpv_Model();
         $posts = $model->get_popular_on_network($limit, $voted_timeframe);
         echo $before_widget;
         if ($title) {
             echo $before_title . $title . $after_title;
         }
         if (is_array($posts)) {
             echo "<ul class='wdpv_popular_posts wdpv_network_popular'>";
             foreach ($posts as $post) {
                 $data = get_blog_post($post['blog_id'], $post['post_id']);
                 echo "<li>";
                 echo '<a href="' . get_blog_permalink($post['blog_id'], $post['post_id']) . '">' . $data->post_title . '</a> ';
                 printf(__('<span class="wdpv_vote_count">(%s votes)</span>', 'wdpv'), $post['total']);
                 echo "</li>";
             }
             echo "</ul>";
         }
         echo $after_widget;
     }
 }
Example #2
0
 function process_popular_code($args)
 {
     $args = extract(shortcode_atts(array('limit' => 5, 'network' => false), $args));
     $model = new Wdpv_Model();
     $posts = $network ? $model->get_popular_on_network($limit) : $model->get_popular_on_current_site($limit);
     $ret = '';
     if (is_array($posts)) {
         $ret .= '<ul class="wdpv_popular_posts ' . ($network ? 'wdpv_network_popular' : '') . '">';
         foreach ($posts as $post) {
             if ($network) {
                 $data = get_blog_post($post['blog_id'], $post['post_id']);
                 if (!$data) {
                     continue;
                 }
             }
             $title = $network ? $data->post_title : $post['post_title'];
             $permalink = $network ? get_blog_permalink($post['blog_id'], $post['post_id']) : get_permalink($post['ID']);
             $ret .= "<li>" . "<a href='{$permalink}'>{$title}</a> " . sprintf(__('<span class="wdpv_vote_count">(%s votes)</span>', 'wdpv'), $post['total']) . "</li>";
         }
         $ret .= '</ul>';
     }
     return $ret;
 }