/**
 * Get post views from Jetpack.
 */
function jp_get_post_views($postID)
{
    if (function_exists('stats_get_csv')) {
        $post_stats = stats_get_csv('postviews', array('days' => 365, 'limit' => -1));
        foreach ($post_stats as $p) {
            if ($p['post_id'] == $postID) {
                ?>
				<span class='post-views'><?php 
                echo '<i class="fa fa-eye"></i>' . number_format_i18n($p['views']);
                ?>
</span>
			<?php 
            }
        }
    }
}
 function widget($args, $instance)
 {
     global $post;
     /* PRINT THE WIDGET */
     extract($args, EXTR_SKIP);
     $instance = wp_parse_args((array) $instance, array('title' => ''));
     $title = esc_attr($instance['title']);
     if (!is_single()) {
         return;
     }
     echo $before_widget;
     if (!empty($title)) {
         echo $before_title;
         echo apply_filters('widget_title', $title, $instance, $this->id_base);
         echo $after_title;
     }
     $name = get_the_author_meta('display_name', $post->post_author);
     echo '<div class="large-icons">';
     echo '<ul>';
     edit_post_link('<i class="icon-pencil"></i>' . __('Edit', 'myThemes'), '<li>', '</li>');
     echo '<li><a href="' . get_day_link(get_post_time('Y', false, $post->ID), get_post_time('m', false, $post->ID), get_post_time('d', false, $post->ID)) . '">';
     echo '<time datetime="' . get_post_time('Y-m-d', false, $post->ID) . '"><i class="icon-calendar"></i>' . get_post_time(get_option('date_format'), false, $post->ID) . '</time></a></li>';
     echo '<li><a href="' . get_author_posts_url($post->post_author) . '" title="' . __('Writed by ', 'myThemes') . ' ' . $name . '"><i class="icon-user-5"></i>' . $name . '</a></li>';
     if ($post->comment_status == 'open') {
         $nr = get_comments_number($post->ID);
         if ($nr == 1) {
             $comments = $nr . ' ' . __('Comment', 'myThemes');
         } else {
             $comments = $nr . ' ' . __('Comments', 'myThemes');
         }
         echo '<li><a href="' . get_comments_link($post->ID) . '"><i class="icon-comment"></i>' . $comments . '</a></li>';
     }
     if (function_exists('stats_get_csv')) {
         $args = array('days' => -1, 'post_id' => $post->ID);
         $result = stats_get_csv('postviews', $args);
         $views = $result[0]['views'];
         $nr_views = number_format_i18n($views);
         $label_views = __('views', 'myThemes');
         if ($nr_views == 1) {
             $label_views = __('view', 'myThemes');
         }
         echo '<li><i class="icon-eye-2"></i> ' . $nr_views . ' ' . $label_views . '</li>';
     }
     echo '</ul>';
     echo '</div>';
     echo $after_widget;
 }
 function widget($args, $instance)
 {
     global $post;
     /* PRINT THE WIDGET */
     extract($args, EXTR_SKIP);
     $instance = wp_parse_args((array) $instance, array('title' => ''));
     $title = $instance['title'];
     if (!is_single()) {
         return;
     }
     echo $before_widget;
     if (!empty($title)) {
         echo $before_title;
         echo apply_filters('widget_title', esc_attr($title), $instance, $this->id_base);
         echo $after_title;
     }
     $y = esc_attr(get_post_time('Y', false, $post->ID));
     $m = esc_attr(get_post_time('m', false, $post->ID));
     $d = esc_attr(get_post_time('d', false, $post->ID));
     $name = get_the_author_meta('display_name', $post->post_author);
     $dtime = get_post_time('Y-m-d', false, $post->ID);
     $ptime = get_post_time(esc_attr(get_option('date_format')), false, $post->ID, true);
     echo '<div class="large-icons">';
     echo '<ul>';
     edit_post_link('<i class="icon-pencil"></i>' . __('Edit', 'treeson'), '<li>', '</li>');
     echo '<li><a href="' . esc_url(get_day_link($y, $m, $d)) . '">';
     echo '<time datetime="' . esc_attr($dtime) . '"><i class="icon-calendar"></i>' . esc_html($ptime) . '</time></a></li>';
     echo '<li><a href="' . esc_url(get_author_posts_url($post->post_author)) . '" title="' . sprintf(__('Writed by %s', 'treeson'), esc_attr($name)) . '"><i class="icon-user-5"></i>' . esc_html($name) . '</a></li>';
     if ($post->comment_status == 'open') {
         $nr = get_comments_number($post->ID);
         echo '<li>';
         echo '<a href="' . esc_url(get_comments_link($post->ID)) . '">';
         echo '<i class="icon-comment"></i>';
         echo sprintf(_nx('%s Comment', '%s Comments', absint($nr), 'Number of comment(s) from widget "myThemes: Meta Details"', 'treeson'), number_format_i18n(absint($nr)));
         echo '</a></li>';
     }
     if (function_exists('stats_get_csv')) {
         $args = array('days' => -1, 'post_id' => $post->ID);
         $result = stats_get_csv('postviews', $args);
         $views = $result[0]['views'];
         echo '<li><i class="icon-eye-2"></i> ' . sprintf(_n('%s view', '%s views', absint($views), 'treeson'), number_format_i18n(absint($views))) . '</li>';
     }
     echo '</ul>';
     echo '</div>';
     echo $after_widget;
 }
Beispiel #4
0
    function trendy()
    {
        /* The Code ----------------- */
        if (function_exists('stats_get_csv')) {
            $top_posts = stats_get_csv('postviews', 'days=7&limit=5');
            if (count($top_posts) > 0) {
                echo '<ul>';
                foreach ($top_posts as $p) {
                    ?>
				<li><a href="<?php 
                    echo $p['post_permalink'];
                    ?>
"><?php 
                    echo $p['post_title'];
                    ?>
</a></li>
<?php 
                }
                echo '</ul>';
            }
        }
        /* End of The Code ---------- */
    }
/**
 * Get the number of pageviews for a given post ID (defaults to the current post)
 *
 * Note that it is not currently possible to retrieve the post views for
 * the homepage using this function
 *
 * @param int          $post_id   Optional. The post ID to fetch stats for. Defaults to the $post global's value.
 * @param int          $num_days  Optional. How many days to go back to include in the stats. Default is 1. Maximum 90 days.
 * @param string|bool  $end_data  Optional. The last day of the desired time frame. Format is 'Y-m-d' (e.g. 2007-05-01) and default is today's UTC date.
 * @return int|false Number of pageviews or false on error.
 */
function wpcom_vip_get_post_pageviews($post_id = null, $num_days = 1, $end_date = false)
{
    // Check Jetpack is present and active
    if (class_exists('Jetpack') && Jetpack::is_active()) {
        $args = array('post_id' => $post_id, 'num_days' => $num_days, 'end_date' => $end_date);
        // Default post_id to the current post ID, and check it's an int
        if (is_null($args['post_id'])) {
            $args['post_id'] = get_the_ID();
        }
        $args['post_id'] = absint($args['post_id']);
        if (empty($args['post_id'])) {
            return false;
        }
        // Ensure num_days is least 1, but no more than 90
        $args['num_days'] = max(1, min(90, absint($args['num_days'])));
        $posts = stats_get_csv('postviews', $args);
        $views = $posts[0];
    } else {
        // If Jetpack is not present or not active, fake the data returned
        $views = mt_rand(0, 20000);
    }
    return absint($views);
}
Beispiel #6
0
    /**
     * Print HTML with meta information for the current post-date/time and author.
     *
     * @since SG Window 1.0.0
     */
    function sgwindow_posted_on()
    {
        $is_author = is_singular() ? '1' == sgwindow_get_theme_mod('is_author') ? true : false : ('1' == sgwindow_get_theme_mod('blog_is_author') ? true : false);
        $is_date = is_singular() ? '1' == sgwindow_get_theme_mod('is_date') ? true : false : ('1' == sgwindow_get_theme_mod('blog_is_date') ? true : false);
        $is_comments = is_singular() ? '1' == sgwindow_get_theme_mod('is_comments') ? true : false : ('1' == sgwindow_get_theme_mod('blog_is_comments') ? true : false);
        $is_views = is_singular() ? '1' == sgwindow_get_theme_mod('is_views') ? true : false : ('1' == sgwindow_get_theme_mod('blog_is_views') ? true : false);
        $rez = '';
        // Set up and print post meta information.
        if ($is_date) {
            echo '<span class="entry-date">
					<a href="' . esc_url(get_permalink()) . '" title="' . esc_attr(get_the_date('')) . '" rel="bookmark">
						<span class="entry-date" datetime="' . esc_attr(get_the_date('')) . '">' . esc_html(get_the_date()) . '</span>
					</a>
			 </span>';
        }
        if ($is_author) {
            echo '<span class="byline">
				<span title="' . get_the_author() . '" class="author vcard">
					<a class="url fn n" href="' . esc_url(get_author_posts_url(get_the_author_meta('ID'))) . '" rel="author">' . get_the_author() . '</a>
				</span>
			</span>';
        }
        if ($is_views) {
            if (class_exists('Jetpack') && Jetpack::is_module_active('stats') && function_exists('stats_get_csv')) {
                $result = $result = stats_get_csv('postviews', 'post_id=' . get_the_ID() . '&days=-1&limit=-1&summarize');
                echo '<span class="post-views" title="' . number_format_i18n($result[0]['views']) . '">' . number_format_i18n($result[0]['views']) . '</span>';
            }
        }
        if ($is_comments) {
            if (!is_single() && !post_password_required() && (comments_open() || get_comments_number())) {
                echo '<span class="comments-link">';
                comments_popup_link(__('Leave a comment', 'sg-window'), __('1 Comment', 'sg-window'), __('% Comments', 'sg-window'));
                echo '</span>';
            }
        }
    }
Beispiel #7
0
 /**
  * converts a pagebuilde array to a wordpress query args array
  * creates the $args array from shortcodes - used by the pagebuilde + widgets + by the metabox_to_args
  * @param string $atts : the shortcode string
  * @param string $paged : page number  /1  or  /2
  * @return array
  */
 static function shortcode_to_args($atts = '', $paged = '')
 {
     //print_r($atts);
     extract(shortcode_atts(array('category_ids' => '', 'category_id' => '', 'tag_slug' => '', 'sort' => '', 'limit' => '', 'autors_id' => '', 'installed_post_types' => '', 'posts_per_page' => '', 'offset' => '', 'live_filter' => '', 'live_filter_cur_post_id' => '', 'live_filter_cur_post_author' => ''), $atts));
     //init the array
     $wp_query_args = array('ignore_sticky_posts' => 1, 'post_status' => 'publish');
     /*  ----------------------------------------------------------------------
             jetpack sorting - this will return here if that's the case because it dosn't work with other filters (it's site wide, no category + this or other combinations)
         */
     if ($sort == 'jetpack_popular_2') {
         if (function_exists('stats_get_csv')) {
             // the damn jetpack api cannot return only posts so it may return pages. That's why we query with a bigger + 5 limit
             // so that if the api returns also 5 pages mixed with the post we will still have the desired number of posts
             $jetpack_api_posts = stats_get_csv('postviews', array('days' => 2, 'limit' => $limit + 5));
             if (!empty($jetpack_api_posts) and is_array($jetpack_api_posts)) {
                 $wp_query_args['post__in'] = wp_list_pluck($jetpack_api_posts, 'post_id');
                 $wp_query_args['posts_per_page'] = $limit;
                 return $wp_query_args;
             }
         }
         return array();
         // empty array makes WP_Query not run
     }
     //the query goes only via $category_ids - for both options ($category_ids and $category_id) also $category_ids overwrites $category_id
     if (!empty($category_id) and empty($category_ids)) {
         $category_ids = $category_id;
     }
     if (!empty($category_ids)) {
         $wp_query_args['cat'] = $category_ids;
     }
     if (!empty($tag_slug)) {
         $wp_query_args['tag'] = str_replace(' ', '-', $tag_slug);
     }
     switch ($sort) {
         case 'featured':
             if (!empty($category_ids)) {
                 //for each category, get the object and compose the slug
                 $cat_id_array = explode(',', $category_ids);
                 foreach ($cat_id_array as &$cat_id) {
                     $cat_id = trim($cat_id);
                     //get the category object
                     $td_tmp_cat_obj = get_category($cat_id);
                     //make the $args
                     if (empty($wp_query_args['category_name'])) {
                         $wp_query_args['category_name'] = $td_tmp_cat_obj->slug;
                         //get by slug (we get the children categories too)
                     } else {
                         $wp_query_args['category_name'] .= ',' . $td_tmp_cat_obj->slug;
                         //get by slug (we get the children categories too)
                     }
                     unset($td_tmp_cat_obj);
                 }
             }
             $wp_query_args['cat'] = get_cat_ID(TD_FEATURED_CAT);
             //add the fetured cat
             break;
         case 'popular':
             $wp_query_args['meta_key'] = td_page_views::$post_view_counter_key;
             $wp_query_args['orderby'] = 'meta_value_num';
             $wp_query_args['order'] = 'DESC';
             break;
         case 'popular7':
             $wp_query_args['meta_key'] = td_page_views::$post_view_counter_7_day_total;
             $wp_query_args['orderby'] = 'meta_value_num';
             $wp_query_args['order'] = 'DESC';
             break;
         case 'review_high':
             $wp_query_args['meta_key'] = td_review::$td_review_key;
             $wp_query_args['orderby'] = 'meta_value_num';
             $wp_query_args['order'] = 'DESC';
             break;
         case 'random_posts':
             $wp_query_args['orderby'] = 'rand';
             break;
         case 'alphabetical_order':
             $wp_query_args['orderby'] = 'title';
             $wp_query_args['order'] = 'ASC';
             break;
         case 'comment_count':
             $wp_query_args['orderby'] = 'comment_count';
             $wp_query_args['order'] = 'DESC';
             break;
         case 'random_today':
             $wp_query_args['orderby'] = 'rand';
             $wp_query_args['year'] = date('Y');
             $wp_query_args['monthnum'] = date('n');
             $wp_query_args['day'] = date('j');
             break;
         case 'random_7_day':
             $wp_query_args['orderby'] = 'rand';
             $wp_query_args['date_query'] = array('column' => 'post_date_gmt', 'after' => '1 week ago');
             break;
     }
     if (!empty($autors_id)) {
         $wp_query_args['author'] = $autors_id;
     }
     //add post_type to query
     if (!empty($installed_post_types)) {
         $array_selected_post_types = array();
         $expl_installed_post_types = explode(',', $installed_post_types);
         foreach ($expl_installed_post_types as $val_this_post_type) {
             if (trim($val_this_post_type) != '') {
                 $array_selected_post_types[] = trim($val_this_post_type);
             }
         }
         $wp_query_args['post_type'] = $array_selected_post_types;
         //$installed_post_types;
     }
     /**
      * the live filters are generated in td_block.php and are added when the block is rendered on the page in the atts of the block
      * @see td_block::add_live_filter_atts
      */
     if (!empty($live_filter)) {
         switch ($live_filter) {
             case 'cur_post_same_tags':
                 $tags = wp_get_post_tags($live_filter_cur_post_id);
                 if ($tags) {
                     $taglist = array();
                     for ($i = 0; $i <= 4; $i++) {
                         if (!empty($tags[$i])) {
                             $taglist[] = $tags[$i]->term_id;
                         } else {
                             break;
                         }
                     }
                     $wp_query_args['tag__in'] = $taglist;
                     $wp_query_args['post__not_in'] = array($live_filter_cur_post_id);
                     //print_r($wp_query_args);
                     //die;
                 }
                 break;
             case 'cur_post_same_author':
                 $wp_query_args['author'] = $live_filter_cur_post_author;
                 $wp_query_args['post__not_in'] = array($live_filter_cur_post_id);
                 break;
             case 'cur_post_same_categories':
                 //print_r($atts);
                 $wp_query_args['category__in'] = wp_get_post_categories($live_filter_cur_post_id);
                 $wp_query_args['post__not_in'] = array($live_filter_cur_post_id);
                 break;
                 // ZA Custom
             // ZA Custom
             case 'cur_post_same_tags_happy':
                 $wp_query_args['tag__in'] = "44";
                 break;
             case 'cur_post_same_tags_funny':
                 $wp_query_args['tag__in'] = "45";
                 break;
             case 'cur_post_same_tags_romantic':
                 $wp_query_args['tag__in'] = "46";
                 break;
             case 'cur_post_same_tags_surprised':
                 $wp_query_args['tag__in'] = "47";
                 break;
             case 'cur_post_same_tags_sad':
                 $wp_query_args['tag__in'] = "48";
                 break;
         }
     }
     //show only unique posts if that setting is enabled on the template
     /*if (td_unique_posts::$show_only_unique == true) {
           $wp_query_args['post__not_in'] = td_unique_posts::$rendered_posts_ids;
       }*/
     if (td_unique_posts::$unique_articles_enabled == true) {
         $wp_query_args['post__not_in'] = td_unique_posts::$rendered_posts_ids;
     }
     //custom pagination limit
     if (empty($limit)) {
         $limit = get_option('posts_per_page');
     }
     $wp_query_args['posts_per_page'] = $limit;
     //custom pagination
     if (!empty($paged)) {
         $wp_query_args['paged'] = $paged;
     } else {
         $wp_query_args['paged'] = 1;
     }
     // offset + custom pagination - if we have offset, wordpress overwrites the pagination and works with offset + limit
     if (!empty($offset) and $paged > 1) {
         $wp_query_args['offset'] = $offset + ($paged - 1) * $limit;
     } else {
         $wp_query_args['offset'] = $offset;
     }
     //set this variable to pass it to the filter that fixes the pagination on the templates with fake loops. It is not used on blocks because the blocks have custom pagination
     self::$fake_loop_offset = $offset;
     //print_r($wp_query_args);
     return $wp_query_args;
 }
Beispiel #8
0
function stats_dashboard_widget_content()
{
    $blog_id = stats_get_option('blog_id');
    if (!($width = (int) ($_GET['width'] / 2)) || $width < 250) {
        $width = 370;
    }
    if (!($height = (int) $_GET['height'] - 36) || $height < 230) {
        $height = 230;
    }
    $_width = $width - 5;
    $_height = $height - ($GLOBALS['is_winIE'] ? 16 : 5);
    // hack!
    $options = stats_dashboard_widget_options();
    $http = !empty($_SERVER['HTTPS']) ? 'https' : 'http';
    $src = clean_url("{$http}://dashboard.wordpress.com/wp-admin/index.php?page=estats&blog={$blog_id}&noheader=true&chart&unit={$options['chart']}&width={$_width}&height={$_height}");
    echo "<iframe id='stats-graph' class='stats-section' frameborder='0' style='width: {$width}px; height: {$height}px; overflow: hidden' src='{$src}'></iframe>";
    $post_ids = array();
    if (version_compare('2.7-z', $GLOBALS['wp_version'], '<=')) {
        $csv_args = array('top' => '&limit=8', 'active' => '&limit=5', 'search' => '&limit=5');
        $printf = __('%s %s Views');
    } else {
        $csv_args = array('top' => '', 'active' => '', 'search' => '');
        $printf = __('%s, %s views');
    }
    foreach ($top_posts = stats_get_csv('postviews', "days={$options['top']}{$csv_args['top']}") as $post) {
        $post_ids[] = $post['post_id'];
    }
    foreach ($active_posts = stats_get_csv('postviews', "days={$options['active']}{$csv_args['active']}") as $post) {
        $post_ids[] = $post['post_id'];
    }
    // cache
    get_posts(array('include' => join(',', array_unique($post_ids))));
    $searches = array();
    foreach ($search_terms = stats_get_csv('searchterms', "days={$options['search']}{$csv_args['search']}") as $search_term) {
        $searches[] = $search_term['searchterm'];
    }
    ?>
<div id="stats-info">
	<div id="top-posts" class='stats-section'>
		<div class="stats-section-inner">
		<h4 class="heading"><?php 
    _e('Top Posts');
    ?>
</h4>
		<?php 
    foreach ($top_posts as $post) {
        if (!get_post($post['post_id'])) {
            continue;
        }
        ?>
		<p><?php 
        printf($printf, '<a href="' . get_permalink($post['post_id']) . '">' . get_the_title($post['post_id']) . '</a>', number_format_i18n($post['views']));
        ?>
</p>
		<?php 
    }
    ?>
		</div>
	</div>
	<div id="top-search" class='stats-section'>
		<div class="stats-section-inner">
		<h4 class="heading"><?php 
    _e('Top Searches');
    ?>
</h4>
		<p><?php 
    echo join(',&nbsp; ', $searches);
    ?>
</p>
		</div>
	</div>
	<div id="active" class='stats-section'>
		<div class="stats-section-inner">
		<h4 class="heading"><?php 
    _e('Most Active');
    ?>
</h4>
		<?php 
    foreach ($active_posts as $post) {
        if (!get_post($post['post_id'])) {
            continue;
        }
        ?>
		<p><?php 
        printf($printf, '<a href="' . get_permalink($post['post_id']) . '">' . get_the_title($post['post_id']) . '</a>', number_format_i18n($post['views']));
        ?>
</p>
		<?php 
    }
    ?>
		</div>
	</div>
</div>
<br class="clear" />
<p class="textright">
	<a class="button" href="index.php?page=stats"><?php 
    _e('View All');
    ?>
</a>
</p>
<?php 
    exit;
}
    <li><a href="<?php 
bloginfo('rss2_url');
?>
" title="<?php 
_e('RSS 2.0');
?>
">
    <img src="/wp-content/themes/goshen/img/feed-icon.png" alt="RSS 2.0" title="RSS 2.0" /> RSS 2.0</a></li>
</ul>
<?php 
if (function_exists('stats_get_csv')) {
    ?>
	<h2>Most-viewed</h2>
	<ul id="popularposts">
	<?php 
    $top_posts = stats_get_csv('postviews', 'days=60&limit=13');
    $i = 0;
    foreach ($top_posts as $post) {
        if (!get_post($post['post_id']) || empty($post['post_id']) || in_array($post['post_id'], array(2, 9, 85, 526))) {
            continue;
        }
        echo '<li><a href="' . get_permalink($post['post_id']) . '">' . get_the_title($post['post_id']) . '</a><div class="commentsnumber">' . get_comments_number($post['post_id']) . ' comments</div></li>';
        $i++;
        if ($i >= 5) {
            break;
        }
    }
    ?>
	</ul>
<?php 
}
 echo '<ul>';
 edit_post_link('<i class="icon-pencil"></i>' . __('Edit', 'materialize'), '<li>', '</li>');
 echo '<li><a href="' . esc_url(get_day_link($y, $m, $d)) . '">';
 echo '<time datetime="' . esc_attr($dtime) . '"><i class="icon-calendar"></i>' . esc_html($ptime) . '</time></a></li>';
 echo '<li><a href="' . esc_url(get_author_posts_url($post->post_author)) . '" title="' . sprintf(__('Writed by %s', 'materialize'), esc_attr($name)) . '"><i class="icon-user-5"></i>' . esc_html($name) . '</a></li>';
 if ($post->comment_status == 'open') {
     $nr = get_comments_number($post->ID);
     echo '<li>';
     echo '<a href="' . esc_url(get_comments_link($post->ID)) . '">';
     echo '<i class="icon-comment-5"></i>';
     echo sprintf(_nx('%s Comment', '%s Comments', absint($nr), 'Number of comment(s) from widget "myThemes: Meta Details"', 'materialize'), number_format_i18n(absint($nr)));
     echo '</a></li>';
 }
 if (function_exists('stats_get_csv')) {
     $args = array('days' => -1, 'post_id' => $post->ID);
     $result = stats_get_csv('postviews', $args);
     $views = $result[0]['views'];
     echo '<li><i class="icon-eye-2"></i> ' . sprintf(_n('%s view', '%s views', absint($views), 'materialize'), number_format_i18n(absint($views))) . '</li>';
 }
 echo '</ul>';
 echo '</div>';
 echo '</div>';
 /* ARTICLE CATEGORIES */
 if (has_category()) {
     echo '<div class="widget widget_post_categories mythemes-default-content ' . esc_attr($default_class) . '">';
     echo '<h4 class="widget-title">' . __('Article Categories', 'materialize') . '</h4>';
     echo '<div>';
     echo '<ul>';
     echo '<li>';
     the_category('</li><li>');
     echo '</li>';
Beispiel #11
0
    /**
     * Widget output
     *
     * @since SG Window 1.1.0
     *
     */
    function widget($args, $instance)
    {
        // Widget output
        extract($args);
        // Set up some default widget settings.
        $instance = wp_parse_args((array) $instance, $this->defaults($instance));
        $curr_query = null;
        $popular_posts = null;
        if (1 == $instance['content_type']) {
            global $post;
            $not_in = array();
            if (is_singular()) {
                $not_in[] = $post->ID;
            }
            $not_in = array_merge($not_in, get_option('sticky_posts'));
            $args = array();
            $tax = 'category';
            if ('0' != $instance['category']) {
                $args = array(array('taxonomy' => $tax, 'terms' => array($instance['category']), 'field' => 'term_id', 'operator' => 'IN'));
            }
            $query = new WP_Query(array('order' => 'DESC', 'orderby' => $instance['order'], 'posts_per_page' => $instance['count'], 'no_found_rows' => true, 'post_status' => 'publish', 'has_password' => false, 'post__not_in' => $not_in, 'post_type' => array('post'), 'tax_query' => $args));
            $curr_query = $query;
        } elseif (3 == $instance['content_type']) {
            //from current query
            global $wp_query;
            $curr_query = $wp_query;
        } elseif (4 == $instance['content_type']) {
            //featured posts
            global $post;
            $not_in = array();
            if (is_singular()) {
                $not_in[] = $post->ID;
            }
            $sticky = get_option('sticky_posts');
            $args = array();
            $tax = 'category';
            if ('0' != $instance['category']) {
                $args = array(array('taxonomy' => $tax, 'terms' => array($instance['category']), 'field' => 'term_id', 'operator' => 'IN'));
            }
            $query = new WP_Query(array('order' => 'DESC', 'orderby' => $instance['order'], 'posts_per_page' => $instance['count'], 'no_found_rows' => true, 'post_status' => 'publish', 'has_password' => false, 'post__in' => $sticky, 'post__not_in' => $not_in, 'post_type' => array('post'), 'tax_query' => $args));
            $curr_query = $query;
        } elseif (2 == $instance['content_type']) {
            //portfolio
            global $post;
            $not_in = array();
            if (is_singular()) {
                $not_in[] = $post->ID;
            }
            $not_in = array_merge($not_in, get_option('sticky_posts'));
            $args = array();
            $tax = 'jetpack-portfolio-type';
            if ('0' != $instance['jetpack-portfolio-type']) {
                $args = array(array('taxonomy' => $tax, 'terms' => array($instance['jetpack-portfolio-type']), 'field' => 'term_id', 'operator' => 'IN'));
            }
            $query = new WP_Query(array('order' => 'DESC', 'posts_per_page' => $instance['count'], 'no_found_rows' => true, 'post_status' => 'publish', 'has_password' => false, 'post__not_in' => $not_in, 'post_type' => 'jetpack-portfolio', 'tax_query' => $args));
            $curr_query = $query;
        } elseif (6 == $instance['content_type']) {
            //popular posts
            if (class_exists('Jetpack') && Jetpack::is_module_active('stats') && function_exists('stats_get_csv')) {
                $popular_posts = stats_get_csv('postviews', 'days=-1&limit=-1');
            }
        } elseif (5 == $instance['content_type']) {
            //related posts
            global $post;
            $not_in = array();
            if (is_singular()) {
                $not_in[] = $post->ID;
            }
            $not_in = array_merge($not_in, get_option('sticky_posts'));
            $args = array();
            $args = array('relation' => 'OR', array('taxonomy' => 'category', 'terms' => wp_get_post_categories($post->ID), 'field' => 'term_id', 'operator' => 'IN'), array('taxonomy' => 'post_tag', 'terms' => wp_get_post_tags($post->ID, array('fields' => 'ids')), 'field' => 'term_id', 'operator' => 'IN'));
            $query = new WP_Query(array('order' => 'DESC', 'orderby' => $instance['order'], 'posts_per_page' => $instance['count'], 'no_found_rows' => true, 'post_status' => 'publish', 'has_password' => false, 'post__not_in' => $not_in, 'post_type' => array('post'), 'tax_query' => $args));
            $curr_query = $query;
        }
        //print the widget for the sidebar
        if (0 == $instance['content_type'] || isset($curr_query) && $curr_query->have_posts() || isset($popular_posts)) {
            echo $before_widget;
            $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);
            if ('' !== trim($instance['title'])) {
                echo $before_title . esc_html($instance['title']) . $after_title;
            }
            if (0 == $instance['content_type']) {
                for ($i = 0; $i < $instance['count']; $i++) {
                    if (!isset($instance['is_link_' . $i]) || empty($instance['is_link_' . $i])) {
                        $instance['is_link_' . $i] = $instance['is_link'];
                    }
                    if (!isset($instance['link_' . $i]) || empty($instance['link_' . $i])) {
                        $instance['link_' . $i] = '#';
                    }
                    if (!isset($instance['img_' . $i]) || empty($instance['img_' . $i]) || '' == $instance['img_' . $i]) {
                        $instance['img_' . $i] = $instance['empty'];
                    }
                    if (!isset($instance['title_' . $i]) || empty($instance['title_' . $i])) {
                        $instance['title_' . $i] = __('Slide Title', 'sg-window') . ' ' . ($i + 1);
                    }
                    if (!isset($instance['descr_' . $i]) || empty($instance['descr_' . $i])) {
                        $instance['descr_' . $i] = __('description', 'sg-window');
                    }
                }
            } elseif (6 == $instance['content_type']) {
                //popular posts
                $i = 0;
                if (isset($popular_posts)) {
                    foreach ($popular_posts as $post) {
                        if ($i >= $instance['count']) {
                            break;
                        }
                        if (('1' == $instance['is_popular_pages'] || 'post' == get_post_type($post['post_id'])) && 'publish' == get_post_status($post['post_id']) && false == post_password_required($post['post_id']) && 0 != $post['post_id']) {
                            $instance['img_' . $i] = $instance['empty'];
                            if (has_post_thumbnail($post['post_id'])) {
                                $img = wp_get_attachment_image_src(get_post_thumbnail_id($post['post_id']), $instance['image_size']);
                                if ($img) {
                                    $instance['img_' . $i] = $img[0];
                                }
                            }
                            $instance['title_' . $i] = $post['post_title'];
                            $instance['descr_' . $i] = '';
                            $instance['link_' . $i] = $post['post_permalink'];
                            $instance['is_link_' . $i] = '1';
                            $instance['cat_' . $i] = '';
                            if ('1' == $instance['is_cat']) {
                                $categories = get_the_category($post['post_id']);
                                if (!empty($categories)) {
                                    $instance['cat_' . $i] = $categories[0]->name;
                                }
                            }
                            $i++;
                        }
                    }
                }
                $instance['count'] = $i;
            } else {
                $i = 0;
                while ($curr_query->have_posts()) {
                    $curr_query->the_post();
                    $instance['img_' . $i] = $instance['empty'];
                    if (has_post_thumbnail() && !post_password_required()) {
                        $img = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()), $instance['image_size']);
                        if ($img) {
                            $instance['img_' . $i] = $img[0];
                        }
                    }
                    $instance['title_' . $i] = get_the_title();
                    $instance['descr_' . $i] = get_the_excerpt();
                    $instance['link_' . $i] = get_permalink();
                    $instance['is_link_' . $i] = '1';
                    $instance['cat_' . $i] = '';
                    if ('1' == $instance['is_cat']) {
                        $categories = get_the_category(get_the_ID());
                        if (!empty($categories)) {
                            $instance['cat_' . $i] = $categories[0]->name;
                        }
                    }
                    $i++;
                    if (3 == $instance['content_type'] && $instance['count'] == $i) {
                        break;
                    }
                }
                $instance['count'] = $i;
            }
            ?>
			<div class="sgwindow-slider-wrapper">
			
			<div class="sgwindow-slider" style="margin: 0 <?php 
            echo esc_attr($instance['margin']);
            ?>
%;">
				<div class="<?php 
            echo esc_attr($instance['is_play']) . ' ' . absint($instance['speed']) . ' ' . absint($instance['delay']);
            ?>
 sgwindow-slider-content" style="padding-bottom:<?php 
            echo esc_attr($instance['height']);
            ?>
%;">
				
					<?php 
            for ($i = 0; $i < $instance['count']; $i++) {
                ?>
						<article class="sgwindow-slide">
						
							<?php 
                if ('1' == $instance['is_link_' . $i]) {
                    ?>
								<a class="slide-link" href="<?php 
                    echo esc_url($instance['link_' . $i]);
                    ?>
">
							<?php 
                }
                ?>
									<div class="sgwindow-slide-content" <?php 
                if ('1' == $instance['is_background']) {
                    ?>
style="background-image: url(<?php 
                    echo esc_url($instance['img_' . $i]);
                    ?>
);" <?php 
                }
                ?>
>
									
										<?php 
                if ('1' != $instance['is_background']) {
                    ?>
										
											<img class="slider-image" src="<?php 
                    echo esc_url($instance['img_' . $i]);
                    ?>
" alt="" />
									
										<?php 
                }
                ?>
										
										<div class="slider-text-wrap">
											<header>
												<h1 class="slider-title" style="color:<?php 
                echo esc_attr($instance['text_color']);
                ?>
;"><?php 
                echo esc_attr($instance['title_' . $i]);
                ?>
</h1>
											</header>
											<p class="slider-descr" style="color:<?php 
                echo esc_attr($instance['text_color']);
                ?>
;"><?php 
                echo esc_attr($instance['descr_' . $i]);
                ?>
</p>
											
											<?php 
                if ('1' == $instance['is_cat'] && isset($instance['cat_' . $i])) {
                    ?>
												<p class="slider-cat"><?php 
                    echo esc_attr($instance['cat_' . $i]);
                    ?>
</p>
											<?php 
                }
                ?>

										</div><!-- .slider-text-wrap -->
									</div><!-- .sgwindow-slide-content -->
									
							<?php 
                if ('1' == $instance['is_link_' . $i]) {
                    ?>
								</a><!-- .slide-link -->
							<?php 
                }
                ?>

						</article><!-- .sgwindow-slide -->
					<?php 
            }
            ?>
				
				</div><!-- .sgwindow-slider-content -->
				<span class="sgwindow-next-button"><span class="genericon genericon-pocket"></span></span>
				<span class="sgwindow-prev-button"><span class="genericon genericon-pocket"></span></span>
				<ul class="sgwindow-slider-buttons">
					<li class="current"></li>
					<?php 
            for ($i = 1; $i < $instance['count']; $i++) {
                ?>
						<li></li>
					<?php 
            }
            ?>
				</ul><!-- .sgwindow-slider-buttons -->
			</div><!-- .sgwindow-slider -->

			</div><!-- .sgwindow-slider-wrapper -->
			<?php 
            echo $after_widget;
            if (0 != $instance['content_type'] && 3 != $instance['content_type']) {
                wp_reset_postdata();
            }
        }
    }
Beispiel #12
0
function stats_dashboard_widget_content()
{
    $blog_id = stats_get_option('blog_id');
    if (!($width = (int) ($_GET['width'] / 2)) || $width < 250) {
        $width = 370;
    }
    if (!($height = (int) $_GET['height'] - 36) || $height < 230) {
        $height = 230;
    }
    $_width = $width - 5;
    $_height = $height - ($GLOBALS['is_winIE'] ? 16 : 5);
    // hack!
    $options = stats_dashboard_widget_options();
    $q = array('noheader' => 'true', 'proxy' => '', 'page' => 'stats', 'blog' => $blog_id, 'key' => stats_get_api_key(), 'chart' => '', 'unit' => $options['chart'], 'width' => $_width, 'height' => $_height);
    $url = 'http://dashboard.wordpress.com/wp-admin/index.php';
    $url = add_query_arg($q, $url);
    $get = wp_remote_get($url, array('timeout' => 300));
    if (is_wp_error($get) || empty($get['body'])) {
        $http = $_SERVER['HTTPS'] ? 'https' : 'http';
        $src = clean_url("{$http}://dashboard.wordpress.com/wp-admin/index.php?page=estats&blog={$blog_id}&noheader=true&chart&unit={$options['chart']}&width={$_width}&height={$_height}");
        echo "<iframe id='stats-graph' class='stats-section' frameborder='0' style='width: {$width}px; height: {$height}px; overflow: hidden' src='{$src}'></iframe>";
    } else {
        $body = stats_convert_post_titles($get['body']);
        $body = stats_convert_swf_urls($body);
        $body = stats_convert_chart_urls($body);
        $body = stats_convert_image_urls($body);
        echo $body;
    }
    $post_ids = array();
    if (version_compare('2.7-z', $GLOBALS['wp_version'], '<=')) {
        $csv_args = array('top' => '&limit=8', 'active' => '&limit=5', 'search' => '&limit=5');
        /* translators: Stats dashboard widget postviews list: "$post_title $views Views" */
        $printf = __('%1$s %2$s Views', 'stats');
    } else {
        $csv_args = array('top' => '', 'active' => '', 'search' => '');
        /* translators: Stats dashboard widget postviews list: "$post_title, $views Views" */
        $printf = __('%1$s, %2$s views', 'stats');
    }
    foreach ($top_posts = stats_get_csv('postviews', "days={$options['top']}{$csv_args['top']}") as $post) {
        $post_ids[] = $post['post_id'];
    }
    foreach ($active_posts = stats_get_csv('postviews', "days={$options['active']}{$csv_args['active']}") as $post) {
        $post_ids[] = $post['post_id'];
    }
    // cache
    get_posts(array('include' => join(',', array_unique($post_ids))));
    $searches = array();
    foreach ($search_terms = stats_get_csv('searchterms', "days={$options['search']}{$csv_args['search']}") as $search_term) {
        $searches[] = esc_html($search_term['searchterm']);
    }
    ?>
<div id="stats-info">
	<div id="top-posts" class='stats-section'>
		<div class="stats-section-inner">
		<h4 class="heading"><?php 
    _e('Top Posts', 'stats');
    ?>
</h4>
		<?php 
    foreach ($top_posts as $post) {
        if (!get_post($post['post_id'])) {
            continue;
        }
        ?>
		<p><?php 
        printf($printf, '<a href="' . get_permalink($post['post_id']) . '">' . get_the_title($post['post_id']) . '</a>', number_format_i18n($post['views']));
        ?>
</p>
		<?php 
    }
    ?>
		</div>
	</div>
	<div id="top-search" class='stats-section'>
		<div class="stats-section-inner">
		<h4 class="heading"><?php 
    _e('Top Searches', 'stats');
    ?>
</h4>
		<p><?php 
    echo join(',&nbsp; ', $searches);
    ?>
</p>
		</div>
	</div>
	<div id="active" class='stats-section'>
		<div class="stats-section-inner">
		<h4 class="heading"><?php 
    _e('Most Active', 'stats');
    ?>
</h4>
		<?php 
    foreach ($active_posts as $post) {
        if (!get_post($post['post_id'])) {
            continue;
        }
        ?>
		<p><?php 
        printf($printf, '<a href="' . get_permalink($post['post_id']) . '">' . get_the_title($post['post_id']) . '</a>', number_format_i18n($post['views']));
        ?>
</p>
		<?php 
    }
    ?>
		</div>
	</div>
</div>
<br class="clear" />
<p class="textright">
	<a class="button" href="index.php?page=stats"><?php 
    _e('View All', 'stats');
    ?>
</a>
</p>
<?php 
    exit;
}
 /**
  * Lecture des stats Jetpack afin d'y récupérer les articles/pages populaires.
  * 
  * @param int $days Période concernée.
  * 
  * @return array Tableau d'ID.
  */
 private function getPopularIDs($days)
 {
     //Lecture des articles populaires sur la période demandée.
     $post_view_posts = stats_get_csv('postviews', array('days' => $days, 'limit' => 100));
     if (!$post_view_posts) {
         return array();
     }
     //On récupère les ID.
     $post_view_ids = array_filter(wp_list_pluck($post_view_posts, 'post_id'));
     if (!$post_view_ids) {
         return array();
     }
     return $post_view_ids;
 }
    function widget($args, $instance)
    {
        extract($args);
        /* Our variables from the widget settings. */
        $number = $instance['number'];
        echo $before_widget;
        ?>

		<div class="tabbed-widget">
			<ul class="nav nav-tabs role="tablist"">
				<li role="presentation" class="active"><a href="#popular" aria-controls="popular" role="tab" data-toggle="tab"><i class="fa fa-fire"></i><?php 
        _e('Popular', 'ta-portfolio');
        ?>
</a></li>
				<li role="presentation"><a href="#recent" aria-controls="recent" role="tab" data-toggle="tab"><i class="fa fa-clock-o"></i><?php 
        _e('Recent', 'ta-portfolio');
        ?>
</a></li>
				<li role="presentation"><a href="#message" aria-controls="message" role="tab" data-toggle="tab"><i class="fa fa-comments"></i></a></li>
			</ul>

			<div class="tab-content">
				<div role="tabpanel" id="popular" class="tab-pane active">
					<?php 
        if (function_exists('stats_get_csv')) {
            // get popular posts by WordPress.com states if Jetpack plugin installed.
            $count = 0;
            $popular_posts = stats_get_csv('postviews', array('days' => 30, 'limit' => -1));
            ?>
						<div class="post-content">
							<?php 
            foreach ($popular_posts as $p) {
                if ($count >= $number) {
                    break;
                }
                if ('post' == get_post_type($p['post_id']) && 'publish' == get_post_status($p['post_id']) && false == post_password_required($p['post_id']) && 0 != $p['post_id']) {
                    ?>
									<div class="post-content">
										<div class="tab-image">
											<?php 
                    if (has_post_thumbnail($p['post_id'])) {
                        ?>
												<a href="<?php 
                        echo $p['post_permalink'];
                        ?>
" title="<?php 
                        echo $p['post_title'];
                        ?>
">
													<?php 
                        echo get_the_post_thumbnail($p['post_id'], 'tab-image');
                        ?>
												</a>
											<?php 
                    }
                    ?>
										</div>

										<div class="post-title">
											<i class="fa fa-eye"></i><i><?php 
                    echo $p['views'] . ' ' . __('Monthly Views', 'ta-portfolio');
                    ?>
</i>
											<p><a href="<?php 
                    echo $p['post_permalink'];
                    ?>
" rel="bookmark" title="<?php 
                    echo $p['post_title'];
                    ?>
"><?php 
                    echo $p['post_title'];
                    ?>
</a></p>
										</div>
									</div>
								<?php 
                    $count++;
                }
            }
            ?>
						</div>
					<?php 
        } else {
            // get popular posts by comment count.
            $popular_posts = new WP_Query(array('showposts' => $number, 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'has_password' => false, 'orderby' => 'comment_count', 'order' => 'DESC'));
            while ($popular_posts->have_posts()) {
                $popular_posts->the_post();
                ?>

							<div class="post-content">
								<div class="tab-image">
									<?php 
                if (has_post_thumbnail()) {
                    ?>
										<a href="<?php 
                    the_permalink();
                    ?>
" title="<?php 
                    the_title_attribute();
                    ?>
">
											<?php 
                    the_post_thumbnail('tab-image');
                    ?>
										</a>
									<?php 
                }
                ?>
								</div>

								<div class="post-title">
									<i class="fa fa-comments-o"></i><?php 
                comments_popup_link(__('Leave a comment', 'ta-portfolio'), __('1 Comment', 'ta-portfolio'), __('% Comments', 'ta-portfolio'));
                ?>
									<p><a href="<?php 
                echo get_permalink();
                ?>
" rel="bookmark" title="<?php 
                the_title();
                ?>
"><?php 
                the_title();
                ?>
</a></p>
								</div>
							</div>

						<?php 
            }
        }
        ?>
				</div>
				<?php 
        wp_reset_query();
        ?>

				<div role="tabpanel" id="recent" class="tab-pane">
					<?php 
        $recent_posts = new WP_Query(array('showposts' => $number, 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'has_password' => false));
        ?>
					<?php 
        while ($recent_posts->have_posts()) {
            $recent_posts->the_post();
            ?>

						<div class="post-content">
							<div class="tab-image">
								<?php 
            if (has_post_thumbnail()) {
                ?>
									<a href="<?php 
                the_permalink();
                ?>
" title="<?php 
                the_title_attribute();
                ?>
">
										<?php 
                the_post_thumbnail('tab-image');
                ?>
									</a>
								<?php 
            }
            ?>
							</div>
							<div class="post-title">
								<i class="fa fa-clock-o"></i><i><?php 
            the_time('M j, Y');
            ?>
</i>
								<p><a href="<?php 
            echo get_permalink();
            ?>
" rel="bookmark" title="<?php 
            the_title();
            ?>
"><?php 
            the_title();
            ?>
</a></p>
							</div>
						</div>

					<?php 
        }
        ?>
				</div>
				<?php 
        wp_reset_query();
        ?>

				<div role="tabpanel" id="message" class="tab-pane">
					<?php 
        $recent_comments = get_comments(array('number' => $number, 'status' => 'approve'));
        ?>
					<?php 
        foreach ($recent_comments as $comment) {
            ?>
					
						<div class="post-content">
							<i class="fa fa-comment-o"></i>
							<?php 
            if ($comment->comment_author) {
                echo $comment->comment_author;
            } else {
                _e('Anonymous', 'ta-portfolio');
            }
            ?>
 <?php 
            _e('on', 'ta-portfolio');
            ?>
								<a href="<?php 
            echo get_permalink($comment->comment_post_ID);
            ?>
" rel="bookmark" title="<?php 
            echo get_the_title($comment->comment_post_ID);
            ?>
">
									<?php 
            echo get_the_title($comment->comment_post_ID);
            ?>
								</a>
							<p>
								<i class="fa fa-quote-left"></i>
								<?php 
            echo wp_trim_words($comment->comment_content, 15);
            ?>
								<i class="fa fa-quote-right"></i>
							</p>
						</div>

					<?php 
        }
        ?>
				</div>
			</div>
		</div>

		<?php 
        echo $after_widget;
    }
function db_popular_post_aggregator()
{
    if (function_exists('stats_get_csv')) {
        global $wpdb;
        $table_name = $wpdb->base_prefix . 'db_stats';
        $blogID = get_current_blog_id();
        // get any row with blog ID for date comparison
        $result = $wpdb->get_row("SELECT * FROM {$table_name} WHERE blog_id = {$blogID} ORDER BY date_added ASC LIMIT 1", ARRAY_A);
        if (!$result || strtotime($result['date_added']) + 0 < time()) {
            // supposedly grabbing post views from past 60 months...
            $top_posts = stats_get_csv('postviews', 'period=month&days=60&limit=-1');
            if ($top_posts) {
                $wpdb->delete($table_name, array('blog_id' => $blogID), array('%d'));
                $accepted_post_types = array('post', 'premiere');
                foreach ($top_posts as $post) {
                    $postID = absint($post['post_id']);
                    $post_views = $post['views'];
                    if ($postID <= 0) {
                        continue;
                    }
                    if (!in_array(get_post_type($postID), $accepted_post_types)) {
                        continue;
                    }
                    $arr = array('blog_id' => $blogID, 'post_id' => $postID, 'views' => $post_views, 'date_added' => date('Y-m-d H:i:s', time()));
                    $wpdb->insert($table_name, $arr, array('%d', '%d', '%d', '%s'));
                    update_post_meta($postID, 'db_weekly_views', $post_views);
                }
            }
        }
    }
    die;
}
Beispiel #16
0
 function gazeta_get_post_views($post_id)
 {
     if (gazeta_is_allow_viewing() !== true) {
         return;
     }
     // update view_count from wp stats
     if (isset($post_id) && function_exists('stats_get_csv')) {
         $random = mt_rand(9999, 999999999);
         // hack to break cache bug
         $args = array('days' => $random, 'post_id' => $post_id);
         $stats = stats_get_csv('postviews', $args);
         $views = isset($stats['0']['views']) && $stats['0']['views'] > 0 ? $stats['0']['views'] : 0;
         return absint($views);
     }
     return 0;
 }
Beispiel #17
0
function getPostViews($postID)
{
    if (function_exists('the_views') && mom_option('views_by') == 'wpv') {
        the_views(false);
    } elseif (function_exists('stats_get_csv') && mom_option('views_by') == 'jetpack') {
        global $post;
        $args = array('days' => -1, 'limit' => -1, 'post_id' => $post->ID);
        $result = stats_get_csv('postviews', $args);
        $views = $result[0]['views'];
        return number_format_i18n($views) . ' ' . __('Views', 'framework');
    } else {
        $count_key = 'post_views_count';
        $count = get_post_meta($postID, $count_key, true);
        if ($count == '') {
            delete_post_meta($postID, $count_key);
            add_post_meta($postID, $count_key, '0');
            return "0 " . __('Views', 'framework');
        }
        return $count . __(' Views', 'framework');
    }
}
 /**
  * Uses data gathered by Jetpack stats and stored in WordPress.com servers
  */
 static function get_posts_by_wp_com($args)
 {
     if (!self::$_stats_enabled || !function_exists('stats_get_csv')) {
         return array();
     }
     $defaults = array('limit' => 5, 'range' => 'all', 'post_type' => 'post', 'date_format' => get_option('date_format'));
     $args = wp_parse_args((array) $args, $defaults);
     $limit = intval($args['limit']);
     /** TODO: limit $limit to 100? **/
     $days = 2;
     switch ($args['range']) {
         case 'weekly':
             $days = 7;
             break;
         case 'monthly':
             $days = 30;
             break;
         case 'daily':
             $days = 2;
             break;
             //make this 2 days to account for timezone differences
         //make this 2 days to account for timezone differences
         case 'all':
         default:
             $days = -1;
             break;
             //get all
     }
     /** we only limit to 50 posts. but change this if you want **/
     $top_posts = stats_get_csv('postviews', array('days' => $days, 'limit' => 50));
     if (!$top_posts) {
         return array();
     }
     /** Store post_id into array **/
     $post_view_ids = array_filter(wp_list_pluck($top_posts, 'post_id'));
     if (!$post_view_ids) {
         return array();
     }
     // cache
     get_posts(array('include' => join(',', array_unique($post_view_ids))));
     // return posts list
     $posts = array();
     $counter = 0;
     foreach ($top_posts as $top_post) {
         //should only trigger for homepage
         if (empty($top_post['post_id'])) {
             continue;
         }
         $post = get_post($top_post['post_id']);
         if (!$post) {
             continue;
         }
         if ($args['post_type'] != $post->post_type) {
             continue;
         }
         $permalink = get_permalink($post->ID);
         $postdate = date_i18n($args['date_format'], strtotime($post->post_date));
         $views = number_format_i18n($top_post['views']);
         if (empty($post->post_title)) {
             $title_source = $post->post_content;
             $title = wp_html_excerpt($title_source, 50);
             $title .= '&hellip;';
         } else {
             $title = $post->post_title;
         }
         $data = array('title' => $title, 'permalink' => $permalink, 'views' => $views, 'id' => $post->ID, 'postdate' => $postdate);
         $posts[] = $data;
         $counter++;
         if ($counter == $limit) {
             break;
         }
     }
     return $posts;
 }
 private function get_author_stats($args)
 {
     $args = wp_parse_args($args, array('post_status' => 'publish', 'post_type' => 'post', 'posts_per_page' => -1, 'update_post_meta_cache' => false, 'update_post_term_cache' => false, 'no_found_rows' => true));
     $authors = array();
     $posts = array();
     global $post;
     $query = new WP_Query($args);
     while ($query->have_posts()) {
         $query->the_post();
         $posts[] = $post;
     }
     wp_reset_postdata();
     foreach ($posts as $p) {
         if (!array_key_exists($p->post_author, $authors)) {
             $author = new WP_User($p->post_author);
             $authors[$p->post_author] = array('display_name' => $author->display_name, 'post_count' => 0, 'total_pageviews' => 0, 'total_wordcount' => 0);
         }
         $authors[$p->post_author]['post_count']++;
         $authors[$p->post_author]['total_wordcount'] += str_word_count(strip_tags($p->post_content));
     }
     $diff = date_diff(new DateTime($args['date_query']['after']), new DateTime($args['date_query']['before']));
     // get page views for the date range
     if (function_exists('stats_get_csv')) {
         $args = array('days' => $diff->days, 'period' => 'days', 'end' => date('Y-m-d', strtotime($args['date_query']['before'])), 'limit' => -1);
         $results = stats_get_csv('postviews', $args);
         //echo '<!--';
         //echo var_export( $args );
         //echo var_export( $results, true );
         //echo '-->';
         if (!empty($results)) {
             foreach ($results as $result) {
                 $p = get_post($result['post_id']);
                 if (!empty($p) && 'post' === $p->post_type) {
                     if (!array_key_exists($p->post_author, $authors)) {
                         $author = new WP_User($p->post_author);
                         $authors[$p->post_author] = array('display_name' => $author->display_name, 'post_count' => 0, 'total_pageviews' => 0, 'total_wordcount' => 0);
                     }
                     $authors[$p->post_author]['total_pageviews'] += absint($result['views']);
                 }
             }
         }
     }
     return $authors;
 }
Beispiel #20
0
 function cb_get_post_viewcount($cb_post_id)
 {
     $cb_stats_src = ot_get_option('cb_misc_stats_source', 'theme');
     if ($cb_stats_src != 'theme') {
         if (function_exists('stats_get_csv')) {
             if ($cb_args == NULL) {
                 $cb_args = 'period=month&days=104&post_id=' . $cb_post_id;
                 $cb_args = 'days=-1&post_id=' . $cb_post_id;
                 /* CBTEMP */
             }
             $cb_post_stats = 'cb-post-views-t-' . $cb_post_id;
             if (($cb_post_view_count = get_transient($cb_post_stats)) === false) {
                 $cb_post_view_count = stats_get_csv('postviews', $cb_args);
                 set_transient($cb_post_stats, $cb_post_view_count, 180);
             }
             if ($cb_post_view_count[0]['views'] != NULL) {
                 return $cb_post_view_count[0]['views'];
             } else {
                 return '0';
             }
         } else {
             return '0';
         }
     } else {
         $cb_visits = get_post_meta($cb_post_id, 'cb_visit_counter', true);
     }
     return $cb_visits;
 }
Beispiel #21
0
 function get_by_views($count)
 {
     $days = (int) apply_filters('jetpack_top_posts_days', 2);
     if ($days < 1) {
         $days = 2;
     }
     if ($days > 10) {
         $days = 10;
     }
     $post_view_posts = stats_get_csv('postviews', array('days' => absint($days), 'limit' => 11));
     if (!$post_view_posts) {
         return array();
     }
     $post_view_ids = array_filter(wp_list_pluck($post_view_posts, 'post_id'));
     if (!$post_view_ids) {
         return array();
     }
     return $this->get_posts($post_view_ids, $count);
 }
Beispiel #22
0
function stats_dashboard_widget_content()
{
    if (!isset($_GET['width']) || !($width = (int) ($_GET['width'] / 2)) || $width < 250) {
        $width = 370;
    }
    if (!isset($_GET['height']) || !($height = (int) $_GET['height'] - 36) || $height < 230) {
        $height = 180;
    }
    $_width = $width - 5;
    $_height = $height - ($GLOBALS['is_winIE'] ? 16 : 5);
    // hack!
    $options = stats_dashboard_widget_options();
    $blog_id = Jetpack_Options::get_option('id');
    $q = array('noheader' => 'true', 'proxy' => '', 'blog' => $blog_id, 'page' => 'stats', 'chart' => '', 'unit' => $options['chart'], 'color' => get_user_option('admin_color'), 'width' => $_width, 'height' => $_height, 'ssl' => is_ssl(), 'j' => sprintf('%s:%s', JETPACK__API_VERSION, JETPACK__VERSION));
    $url = 'https://' . STATS_DASHBOARD_SERVER . "/wp-admin/index.php";
    $url = add_query_arg($q, $url);
    $method = 'GET';
    $timeout = 90;
    $user_id = JETPACK_MASTER_USER;
    $get = Jetpack_Client::remote_request(compact('url', 'method', 'timeout', 'user_id'));
    $get_code = wp_remote_retrieve_response_code($get);
    if (is_wp_error($get) || 2 != intval($get_code / 100) && 304 != $get_code || empty($get['body'])) {
        stats_print_wp_remote_error($get, $url);
    } else {
        $body = stats_convert_post_titles($get['body']);
        $body = stats_convert_chart_urls($body);
        $body = stats_convert_image_urls($body);
        echo $body;
    }
    $post_ids = array();
    $csv_end_date = date('Y-m-d', current_time('timestamp'));
    $csv_args = array('top' => "&limit=8&end={$csv_end_date}", 'search' => "&limit=5&end={$csv_end_date}");
    /* translators: Stats dashboard widget postviews list: "$post_title $views Views" */
    $printf = __('%1$s %2$s Views', 'jetpack');
    foreach ($top_posts = stats_get_csv('postviews', "days={$options['top']}{$csv_args['top']}") as $i => $post) {
        if ($post['post_id'] == 0) {
            unset($top_posts[$i]);
            continue;
        }
        $post_ids[] = $post['post_id'];
    }
    // cache
    get_posts(array('include' => join(',', array_unique($post_ids))));
    $searches = array();
    foreach ($search_terms = stats_get_csv('searchterms', "days={$options['search']}{$csv_args['search']}") as $search_term) {
        if ($search_term['searchterm'] == 'encrypted_search_terms') {
            continue;
        }
        $searches[] = esc_html($search_term['searchterm']);
    }
    ?>
<a class="button" href="admin.php?page=stats"><?php 
    _e('View All', 'jetpack');
    ?>
</a>
<div id="stats-info">
	<div id="top-posts" class='stats-section'>
		<div class="stats-section-inner">
		<h3 class="heading"><?php 
    _e('Top Posts', 'jetpack');
    ?>
</h3>
		<?php 
    if (empty($top_posts)) {
        ?>
			<p class="nothing"><?php 
        _e('Sorry, nothing to report.', 'jetpack');
        ?>
</p>
			<?php 
    } else {
        foreach ($top_posts as $post) {
            if (!get_post($post['post_id'])) {
                continue;
            }
            ?>
				<p><?php 
            printf($printf, '<a href="' . get_permalink($post['post_id']) . '">' . get_the_title($post['post_id']) . '</a>', number_format_i18n($post['views']));
            ?>
</p>
				<?php 
        }
    }
    ?>
		</div>
	</div>
	<div id="top-search" class='stats-section'>
		<div class="stats-section-inner">
		<h3 class="heading"><?php 
    _e('Top Searches', 'jetpack');
    ?>
</h3>
		<?php 
    if (empty($searches)) {
        ?>
			<p class="nothing"><?php 
        _e('Sorry, nothing to report.', 'jetpack');
        ?>
</p>
			<?php 
    } else {
        ?>
			<p><?php 
        echo join(',&nbsp; ', $searches);
        ?>
</p>
			<?php 
    }
    ?>
		</div>
	</div>
</div>
<div class="clear"></div>
<?php 
    exit;
}
Beispiel #23
0
 function get_by_views($count, $args)
 {
     if (defined('IS_WPCOM') && IS_WPCOM) {
         global $wpdb;
         $post_views = wp_cache_get("get_top_posts_{$count}", 'stats');
         if (false === $post_views) {
             $post_views = array_shift(stats_get_daily_history(false, get_current_blog_id(), 'postviews', 'post_id', false, 2, '', $count * 2 + 10, true));
             unset($post_views[0]);
             wp_cache_add("get_top_posts_{$count}", $post_views, 'stats', 1200);
         }
         return $this->get_posts(array_keys($post_views), $count);
     }
     /**
      * Filter the number of days used to calculate Top Posts for the Top Posts widget.
      * We do not recommend accessing more than 10 days of results at one.
      * When more than 10 days of results are accessed at once, results should be cached via the WordPress transients API.
      * Querying for -1 days will give results for an infinite number of days.
      *
      * @module widgets
      *
      * @since 3.9.3
      *
      * @param int 2 Number of days. Default is 2.
      * @param array $args The widget arguments.
      */
     $days = (int) apply_filters('jetpack_top_posts_days', 2, $args);
     /** Handling situations where the number of days makes no sense - allows for unlimited days where $days = -1 */
     if (0 == $days || false == $days) {
         $days = 2;
     }
     $post_view_posts = stats_get_csv('postviews', array('days' => absint($days), 'limit' => 11));
     if (!$post_view_posts) {
         return array();
     }
     $post_view_ids = array_filter(wp_list_pluck($post_view_posts, 'post_id'));
     if (!$post_view_ids) {
         return array();
     }
     return $this->get_posts($post_view_ids, $count);
 }
 function cb_get_post_viewcount($cb_post_id, $cb_args = NULL)
 {
     if (function_exists('stats_get_csv')) {
         if ($cb_args == NULL) {
             $cb_args = 'period=month&days=104&post_id=' . $cb_post_id;
             $cb_args = 'days=-1&post_id=' . $cb_post_id;
             /* CBTEMP */
         }
         $cb_post_stats = 'cb-post-views-t-' . $cb_post_id;
         if (($cb_post_view_count = get_transient($cb_post_stats)) === false) {
             $cb_post_view_count = stats_get_csv('postviews', $cb_args);
             set_transient($cb_post_stats, $cb_post_view_count, 180);
         }
         if ($cb_post_view_count[0]['views'] != NULL) {
             $cb_view_word = sprintf(_n('views', 'views', $cb_post_view_count[0]['views'], 'cubell'), $cb_post_view_count[0]['views']);
             return $cb_post_view_count[0]['views'] . ' ' . $cb_view_word;
         } else {
             $cb_view_word = sprintf(_n('views', 'views', 0, 'cubell'), 0);
             return '0 ' . $cb_view_word;
         }
     } else {
         return NULL;
     }
 }
 function get_by_views($count, $args)
 {
     if (defined('IS_WPCOM') && IS_WPCOM) {
         global $wpdb;
         $post_views = wp_cache_get("get_top_posts_{$count}", 'stats');
         if (false === $post_views) {
             $post_views = array_shift(stats_get_daily_history(false, get_current_blog_id(), 'postviews', 'post_id', false, 2, '', $count * 2 + 10, true));
             unset($post_views[0]);
             wp_cache_add("get_top_posts_{$count}", $post_views, 'stats', 1200);
         }
         return $this->get_posts(array_keys($post_views), $count);
     }
     /**
      * Filter the number of days used to calculate Top Posts for the Top Posts widget.
      *
      * @module widgets
      *
      * @since 3.9.3
      *
      * @param int 2 Number of days. Default is 2.
      * @param array $args The widget arguments.
      */
     $days = (int) apply_filters('jetpack_top_posts_days', 2, $args);
     if ($days < 1) {
         $days = 2;
     }
     if ($days > 10) {
         $days = 10;
     }
     $post_view_posts = stats_get_csv('postviews', array('days' => absint($days), 'limit' => 11));
     if (!$post_view_posts) {
         return array();
     }
     $post_view_ids = array_filter(wp_list_pluck($post_view_posts, 'post_id'));
     if (!$post_view_ids) {
         return array();
     }
     return $this->get_posts($post_view_ids, $count);
 }
 function get_post_views()
 {
     $post_stats = array();
     $postdata = array();
     // Hack to break cache suggested by Glisse.
     // Since 'limit' is capped at 500, use it to break cache for each interval.
     // http://wordpress.org/support/topic/post-views-not-updating
     $random = rand(500, 99999);
     // Get stats using the stats_get_csv function
     if (function_exists('stats_get_csv') && $this->settings['use_stats_get_csv']) {
         // Get post views for each interval: Unlimited, Day, Week, Month, Year
         foreach ($this->interval as $key => $value) {
             $args = array('days' => $value, 'limit' => $random, 'summarize' => 1);
             $post_stats[$key] = stats_get_csv('postviews', $args);
         }
         $this->updateMessages[-2] = "Stats being updated using the stats_get_csv function";
     } else {
         $args = $this->apiArgs;
         $args['api_key'] = $this->settings['api_key'];
         $args['limit'] = $random;
         // Get the stats using the blog_uri
         if ($this->settings['connect_blog_uri'] && $this->settings['use_blog_uri']) {
             $args['blog_uri'] = $this->settings['blog_uri'];
             $this->updateMessages[-2] = "Stats being updated using blog_uri";
         } else {
             if ($this->settings['connect_blog_id']) {
                 $args['blog_id'] = $this->settings['blog_id'];
                 $this->updateMessages[-2] = "Stats being updated using blog_id";
             } else {
                 return;
             }
         }
         // Get post views for each interval: Unlimited, Day, Week, Month, Year
         foreach ($this->interval as $key => $value) {
             $args['days'] = $value;
             $url = add_query_arg($args, $this->apiUrl);
             $json = wp_remote_get($url);
             $data = json_decode($json['body'], true);
             $post_stats[$key] = $data[0]['postviews'];
         }
     }
     $this->updateMessages[-1] = $post_stats;
     global $post;
     // Create an array indexed by interval and then post_id
     foreach ($post_stats as $key => $value) {
         $postdata[$key] = array();
         foreach ($value as $postinfo) {
             $postdata[$key][$postinfo['post_id']] = strip_tags($postinfo['views']);
         }
     }
     // Get all posts and update them
     $post_types = get_post_types(array('_builtin' => false), 'names');
     $post_types['post'] = 'post';
     $args = array('numberposts' => -1, 'post_type' => $post_types, 'post_status' => 'publish');
     $allposts = get_posts($args);
     foreach ($allposts as $post) {
         $message = "'" . get_the_title($post->ID) . "' updated with stats:";
         // Cannot save the interval data as an array in a meta key because WP cannot sort post queries by an array.
         // Have to store each interval data in it's own meta key.
         // http://wordpress.stackexchange.com/questions/99149/wp-query-meta-query-by-array-key
         foreach ($this->interval as $key => $value) {
             // Ensure that the $post-ID exists as a key in the array before trying to update post information.
             // This prevents the user from pulling data from another website and trying to add it to their own
             // posts.
             if (array_key_exists($post->ID, $postdata[$key])) {
                 $newViews = intval($postdata[$key][$post->ID]);
                 // Unlimited meta key different as to not break sites that used this previously
                 if ($key == 'Unlimited') {
                     $oldViews = get_post_meta($post->ID, 'jetpack-post-views', true);
                     // Only update posts with new stats. Prevents posts from being updated with '0' views when the API service is down.
                     if ($newViews < $oldViews) {
                         $newViews = $oldViews;
                     }
                     update_post_meta($post->ID, 'jetpack-post-views', $newViews);
                 } else {
                     // Always update non-unlimited intervals since they can fluctuate
                     update_post_meta($post->ID, 'jetpack-post-views-' . $key, $newViews);
                 }
                 $message .= " {$key}({$newViews})";
             } else {
                 $message .= " {$key}(not updated)";
             }
         }
         $this->updateMessages[$post->ID] = $message;
     }
 }
Beispiel #27
0
 function get_by_views($count)
 {
     global $wpdb;
     $post_view_posts = stats_get_csv('postviews', array('days' => 2, 'limit' => 10));
     if (!$post_view_posts) {
         return array();
     }
     $post_view_ids = array_filter(wp_list_pluck($post_view_posts, 'post_id'));
     if (!$post_view_ids) {
         return array();
     }
     return $this->get_posts($post_view_ids, $count);
 }
Beispiel #28
0
        function widget($args, $instance)
        {
            extract($args);
            extract($instance);
            // The function `stats_get_csv` is provided by the Jetpack plugin.
            // This widget is not enabled if this function does not exist.
            // - Note the `stats_get_csv` function caches its results for `300` seconds based on its input parameters
            // The `stats_get_csv` functions also fetches pages, so we have to accommodate for them and remove them from the results
            if ($this->jetpackInstalled()) {
                $popular = $this->filterResults(stats_get_csv('postviews', array('days' => self::DAYS, 'limit' => self::FETCH)));
            } else {
                echo '<!--';
            }
            // For development purposes, if there aren't any top posts then default to the latest posts.
            //if ( ! $popular || sizeof( $popular ) < $items  )
            //  $popular =  wp_get_recent_posts( array( 'numberposts' => $items, 'post_status' => 'publish' ) , OBJECT );
            $title = apply_filters('widget_title', $title);
            ?>

    <?php 
            echo $before_widget;
            ?>

    <h2><?php 
            echo $title;
            ?>

      <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
         width="24.02px" height="16.794px" viewBox="0 0 24.02 16.794" enable-background="new 0 0 24.02 16.794" xml:space="preserve">
      <path fill="none" d="M1076.826-836c0,0.736,0.598,1.334,1.334,1.334c0.737,0,1.335-0.598,1.335-1.334v-6.666
        c0-0.088-0.009-0.176-0.026-0.262c-0.008-0.039-0.023-0.077-0.034-0.115c-0.013-0.045-0.023-0.09-0.041-0.133
        c-0.02-0.046-0.046-0.088-0.069-0.131c-0.018-0.033-0.032-0.067-0.053-0.099c-0.099-0.146-0.225-0.272-0.371-0.37
        c-0.031-0.021-0.066-0.036-0.1-0.054c-0.043-0.023-0.084-0.05-0.13-0.069c-0.044-0.018-0.089-0.027-0.134-0.041
        c-0.038-0.011-0.075-0.025-0.115-0.034c-0.086-0.017-0.174-0.026-0.262-0.026h-6.672c-0.737,0-1.334,0.597-1.334,1.334
        c0,0.736,0.597,1.333,1.334,1.333h3.451l-8.789,8.781l-3.06-3.058c-0.521-0.521-1.366-0.521-1.888,0l-5.338,5.333
        c-0.521,0.521-0.521,1.365,0,1.885c0.261,0.261,0.603,0.391,0.944,0.391c0.341,0,0.683-0.13,0.943-0.391l4.394-4.391l3.061,3.058
        c0.521,0.521,1.365,0.521,1.887,0l9.732-9.724V-836z"/>
      <path fill="#F58433" d="M21.351,8c0,0.736,0.598,1.334,1.334,1.334c0.737,0,1.335-0.598,1.335-1.334V1.334
        c0-0.088-0.009-0.176-0.026-0.262c-0.008-0.039-0.023-0.077-0.034-0.115c-0.013-0.045-0.023-0.09-0.041-0.133
        c-0.02-0.046-0.046-0.088-0.069-0.131c-0.018-0.033-0.032-0.067-0.053-0.099c-0.099-0.146-0.225-0.272-0.371-0.37
        c-0.031-0.021-0.066-0.036-0.1-0.054c-0.043-0.023-0.084-0.05-0.13-0.069c-0.044-0.018-0.089-0.027-0.134-0.041
        c-0.038-0.011-0.075-0.025-0.115-0.034C22.861,0.009,22.773,0,22.685,0h-6.672c-0.737,0-1.334,0.597-1.334,1.334
        c0,0.736,0.597,1.333,1.334,1.333h3.451l-8.789,8.781l-3.06-3.058c-0.521-0.521-1.366-0.521-1.888,0L0.39,13.724
        c-0.521,0.521-0.521,1.365,0,1.885C0.651,15.87,0.993,16,1.334,16c0.341,0,0.683-0.13,0.943-0.391l4.394-4.391l3.061,3.058
        c0.521,0.521,1.365,0.521,1.887,0l9.732-9.724V8z"/>
      </svg>

    </h2>

    <ul  class="popular-posts">

    <?php 
            if (is_array($popular)) {
                foreach ($popular as $index => $post) {
                    if ($index >= $instance['items']) {
                        break;
                    }
                    ?>

          <?php 
                    print_r($post);
                    $post_permalink = get_permalink($post->ID);
                    ?>
          <li>
            <a class="widget-thumbnail" href="<?php 
                    echo $post_permalink;
                    ?>
" title="<?php 
                    echo esc_attr($post->post_title);
                    ?>
">

            <?php 
                    if (has_post_thumbnail($post->ID)) {
                        ?>

              <?php 
                        echo get_the_post_thumbnail($post->ID, 'thumbnail');
                        ?>

            <?php 
                    }
                    ?>

            <a class="widget-link" href="<?php 
                    echo $post_permalink;
                    ?>
" title="<?php 
                    echo esc_attr($post->post_title);
                    ?>
">
              <?php 
                    echo $post->post_title;
                    ?>
              <p><small><?php 
                    echo $this->convertViews($post->views);
                    ?>
</small></p>
            </a>



          </li>

    <?php 
                }
            }
            ?>

    </ul>

    <?php 
            echo $after_widget;
            if (!$this->jetpackInstalled()) {
                echo '-->';
            }
            ?>

  <?php 
        }
Beispiel #29
0
 function get_by_views($count)
 {
     /**
      * Filter the number of days used to calculate Top Posts for the Top Posts widget.
      *
      * @since 2.8.0
      *
      * @param int 2 Number of days. Default is 2.
      */
     $days = (int) apply_filters('jetpack_top_posts_days', 2);
     if ($days < 1) {
         $days = 2;
     }
     if ($days > 10) {
         $days = 10;
     }
     $post_view_posts = stats_get_csv('postviews', array('days' => absint($days), 'limit' => 11));
     if (!$post_view_posts) {
         return array();
     }
     $post_view_ids = array_filter(wp_list_pluck($post_view_posts, 'post_id'));
     if (!$post_view_ids) {
         return array();
     }
     return $this->get_posts($post_view_ids, $count);
 }
Beispiel #30
0
/**
 * Archive Meta.
 *
 * @since SG Diamond 1.0.0
*/
function sgwindow_posted_on()
{
    $is_author = is_singular() ? '1' == sgwindow_get_theme_mod('is_author') ? true : false : ('1' == sgwindow_get_theme_mod('blog_is_author') ? true : false);
    $is_date = is_singular() ? '1' == sgwindow_get_theme_mod('is_date') ? true : false : ('1' == sgwindow_get_theme_mod('blog_is_date') ? true : false);
    $is_views = is_singular() ? '1' == sgwindow_get_theme_mod('is_views') ? true : false : ('1' == sgwindow_get_theme_mod('blog_is_views') ? true : false);
    $views = null;
    if ($is_views) {
        if ('1' == sgwindow_get_theme_mod('is_views')) {
            if (class_exists('Jetpack') && Jetpack::is_module_active('stats') && function_exists('stats_get_csv')) {
                $result = stats_get_csv('postviews', 'post_id=' . get_the_ID() . '&limit=-1&summarize');
                $views = '<span class="post-views">' . esc_attr(number_format_i18n($result[0]['views'])) . '</span>';
            }
        }
    }
    if ('1' == sgwindow_get_theme_mod('is_cat') && (is_home() || is_archive() || is_search())) {
        $categories = get_the_category(get_the_ID());
        if (!empty($categories)) {
            echo '<a href="' . esc_url(get_category_link($categories[0]->term_id)) . '"><span class="post-cat' . ($is_date || isset($views) || $is_author ? ' post-sep' : '') . '">' . esc_attr($categories[0]->name) . '</span>';
        }
    }
    if ($is_author) {
        echo '<a href="' . esc_url(get_author_posts_url(get_the_author_meta('ID'))) . '"><span class="post-author' . ($is_date || isset($views) ? ' post-sep' : '') . '">' . esc_attr(get_the_author()) . '</span></a>';
    }
    if ($is_date) {
        echo '<a href="' . esc_url(get_permalink()) . '"><span class="post-date' . (isset($views) ? ' post-sep' : '') . '">' . esc_attr(get_the_date()) . '</span></a>';
    }
    if (isset($views)) {
        echo $views;
    }
}