رفتن به مطلب

کمک در حذف يک قسمت از قالب


پست های پیشنهاد شده

سلام تو سايت من تو سايدبار سمت چپ يک قسمتي وجود داره که محبوبترين مطالب رو نمايش ميده.ميخواستم ببينم چطوري ميشه اون قسمتي که تعداد بازديد رو نشون ميده حذفش کنم؟

59566461130542377568.png

اينم آدرس http://2daymusic.ir/

ویرایش شده توسط majidghafoorzade
لینک به ارسال

دقیقاً ماله قالبه یا افزونه wp post views؟ یه نگاه بندازید

مال خود قالب بود ولي بازديدش رو از همون افزونه ميگيره.

خب شما کد اون قسمت رو قرار بده تا بینیم به این شکل که نمیتونیم کمکی کنیم

اينم کدش خدمت شما


<h3>برترین مطالب</h3>
<div class="tabs-b-con">
<a href="#Daily">روزانه</a>
<a href="#Weekly">هفتگی</a>
<a href="#Monthly">ماهانه</a>
</div>
<div class="tabs-b" id="Daily">
<ul>
<?php if (function_exists('wpp_get_mostpopular')) wpp_get_mostpopular("range=daily&order_by=views&limit=5"); ?>
</ul>
</div>
<div class="tabs-b" id="Weekly">
<ul>
<?php if (function_exists('wpp_get_mostpopular')) wpp_get_mostpopular("range=weekly&order_by=views&limit=5"); ?>
</ul>
</div>
<div class="tabs-b" id="Monthly">
<ul>
<?php if (function_exists('wpp_get_mostpopular')) wpp_get_mostpopular("range=Monthly&order_by=views&limit=5"); ?>
</ul>
</div>
</div>
</div>
<div class="box">
<div class="content require">

لینک به ارسال

مال خود قالب بود ولي بازديدش رو از همون افزونه ميگيره.

اينم کدش خدمت شما


<h3>برترین مطالب</h3>
<div class="tabs-b-con">
<a href="#Daily">روزانه</a>
<a href="#Weekly">هفتگی</a>
<a href="#Monthly">ماهانه</a>
</div>
<div class="tabs-b" id="Daily">
<ul>
<?php if (function_exists('wpp_get_mostpopular')) wpp_get_mostpopular("range=daily&order_by=views&limit=5"); ?>
</ul>
</div>
<div class="tabs-b" id="Weekly">
<ul>
<?php if (function_exists('wpp_get_mostpopular')) wpp_get_mostpopular("range=weekly&order_by=views&limit=5"); ?>
</ul>
</div>
<div class="tabs-b" id="Monthly">
<ul>
<?php if (function_exists('wpp_get_mostpopular')) wpp_get_mostpopular("range=Monthly&order_by=views&limit=5"); ?>
</ul>
</div>
</div>
</div>
<div class="box">
<div class="content require">

خب اگه بازدید رو از افزونه میگره تو تنظیمات افزونه کلمه view واضح دیده میشه شما بخش view template رو پاک کن..

لینک به ارسال

دوستان این کد پلاگین هست( فایل wordpress-popular-posts.php )


<?php
/*
Plugin Name: Wordpress Popular Posts
Plugin URI: http://wordpress.org/extend/plugins/wordpress-popular-posts
Description: Wordpress Popular Posts is a highly customizable widget that displays the most popular posts on your blog
Version: 3.0.3
Author: Hector Cabrera
Author URI: http://cabrerahector.com
Author Email: hcabrerab@gmail.com
Text Domain: wordpress-popular-posts
Domain Path: /lang/
Network: false
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html[/b]
[b]Copyright 2014 Hector Cabrera (hcabrerab@gmail.com)[/b]
[b]This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.[/b]
[b]This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.[/b]
[b]You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/[/b]
[b]if ( !defined('ABSPATH') )
exit('Please do not load this file directly.');[/b]
[b]/**
* Wordpress Popular Posts class.
*/
if ( !class_exists('WordpressPopularPosts') ) {[/b]
[b]/**
* Register plugin's activation / deactivation functions
* @since 1.3
*/
register_activation_hook( __FILE__, array( 'WordpressPopularPosts', 'activate' ) );
register_deactivation_hook( __FILE__, array( 'WordpressPopularPosts', 'deactivate' ) );[/b]
[b]/**
* Add function to widgets_init that'll load WPP.
* @since 2.0
*/
function load_wpp() {
register_widget( 'WordpressPopularPosts' );
}
add_action( 'widgets_init', 'load_wpp' );[/b]
[b]class WordpressPopularPosts extends WP_Widget {[/b]
[b] /**
* Plugin version, used for cache-busting of style and script file references.
*
* @since 1.3.0
* @var string
*/
private $version = '3.0.3';[/b]
[b] /**
* Plugin identifier.
*
* @since 3.0.0
* @var string
*/
private $plugin_slug = 'wordpress-popular-posts';[/b]
[b] /**
* Instance of this class.
*
* @since 3.0.0
* @var object
*/
protected static $instance = NULL;[/b]
[b] /**
* Slug of the plugin screen.
*
* @since 3.0.0
* @var string
*/
protected $plugin_screen_hook_suffix = NULL;[/b]
[b] /**
* Plugin directory.
*
* @since 1.4.6
* @var string
*/
private $plugin_dir = '';[/b]
[b] /**
* Default thumbnail.
*
* @since 2.2.0
* @var string
*/
private $default_thumbnail = '';[/b]
[b] /**
* Flag to verify if thumbnails can be created or not.
*
* @since 1.4.6
* @var bool
*/
private $thumbnailing = false;[/b]
[b] /**
* Flag to verify if qTrans is present.
*
* @since 1.4.6
* @var bool
*/
private $qTrans = false;[/b]
[b] /**
* Default charset.
*
* @since 2.1.4
* @var string
*/
private $charset = "UTF-8";[/b]
[b] /**
* Plugin defaults.
*
* @since 2.3.3
* @var array
*/
protected $defaults = array(
'title' => '',
'limit' => 10,
'range' => 'daily',
'freshness' => false,
'order_by' => 'views',
'post_type' => 'post,page',
'pid' => '',
'author' => '',
'cat' => '',
'shorten_title' => array(
'active' => false,
'length' => 25,
'words' => false
),
'post-excerpt' => array(
'active' => false,
'length' => 55,
'keep_format' => false,
'words' => false
),
'thumbnail' => array(
'active' => false,
'width' => 15,
'height' => 15
),
'rating' => false,
'stats_tag' => array(
'comment_count' => false,
'views' => true,
'author' => false,
'date' => array(
'active' => false,
'format' => 'F j, Y'
),
'category' => false
),
'markup' => array(
'custom_html' => false,
'wpp-start' => '<ul class="wpp-list">',
'wpp-end' => '</ul>',
'post-html' => '<li>{thumb} {title} {stats}</li>',
'post-start' => '<li>',
'post-end' => '</li>',
'title-start' => '<h2>',
'title-end' => '</h2>'
)
);[/b]
[b] /**
* Admin page user settings defaults.
*
* @since 2.3.3
* @var array
*/
protected $default_user_settings = array(
'stats' => array(
'order_by' => 'views',
'limit' => 10,
'post_type' => 'post,page',
'freshness' => false
),
'tools' => array(
'ajax' => false,
'css' => true,
'link' => array(
'target' => '_self'
),
'thumbnail' => array(
'source' => 'featured',
'field' => '',
'resize' => false,
'default' => ''
),
'log' => array(
'level' => 0
),
'cache' => array(
'active' => false,
'interval' => array(
'time' => 'hour',
'value' => 1
)
)
)
);[/b]
[b] /**
* Admin page user settings.
*
* @since 2.3.3
* @var array
*/
private $user_settings = array();[/b]
[b] /**
* Bots list.
*
* @since 3.0.0
* @var array
*/
protected $botlist = array( 'abcdatos', 'accoona', 'acme', 'ahoy', 'altavista', 'anthill', 'appie', 'arachnophilia', 'araneo', 'aretha', 'ariadne', 'arks', 'ask', 'aspseek', 'atn', 'atomz', 'auresys', 'awapclient', 'backrub', 'bbot', 'bigfoot', 'blackwidow', 'blinde', 'bot', 'brother', 'cactvs', 'calif', 'cienciaficcion', 'cmc', 'combine', 'computingsite', 'cosmos', 'crawl', 'curl', 'cusco', 'cyberspyder', 'desertrealm', 'deweb', 'digger', 'digimarc', 'docomo', 'duppies', 'dwcp', 'ebiness', 'emacs', 'esculapio', 'esirover', 'esther', 'estyle', 'explorersearch', 'facebookexternalhit', 'feedfetcher', 'felixide', 'fido', 'flunky', 'fouineur', 'funnelweb', 'gazz', 'gcreep', 'gestalticonoclast', 'geturl', 'golem', 'google', 'grabber', 'griffon', 'gromit', 'gulliver', 'gulper', 'havindex', 'hazel', 'htdig', 'htmlgobble', 'ia_archiver', 'iagent', 'ibm', 'incywincy', 'indy', 'informant', 'infoseek', 'ingrid', 'inktomi', 'inspectorwww', 'intelliseek', 'internetseer', 'iron33', 'israelisearch', 'java', 'jeeves', 'jobo', 'jumpstation', 'kapsi', 'katipo', 'kdd', 'labelgrab', 'larbin', 'legs', 'link', 'linkidator', 'linkscan', 'linkwalker', 'lockon', 'logo', 'lwp', 'lycos', 'magpie', 'markwatch', 'marvin', 'mediafox', 'merzscope', 'meshexplorer', 'moget', 'monster', 'motor', 'mouse', 'msn', 'muninn', 'muscatferret', 'mwdsearch', 'nederland', 'netcarta', 'netmechanic', 'netscoop', 'newscan', 'nhsewalker', 'nomad', 'northstar', 'objectssearch', 'occam', 'openfind', 'orbsearch', 'packrat', 'pageboy', 'parasite', 'patric', 'pbwf', 'peregrinator', 'perl', 'pgp', 'phpdig', 'picaloader', 'piltdownman', 'pioneer', 'plumtreewebaccessor', 'poppi', 'portaljuice', 'raven', 'resume', 'rhcs', 'road', 'robbie', 'robofox', 'robozilla', 'root', 'rules', 'safetynet', 'scooter', 'scout', 'searchprocess', 'senrigan', 'shagseeker', 'shai', 'sitetech', 'sleek', 'slurp', 'slysearch', 'snooper', 'spanner', 'spider', 'sqworm', 'ssearcher', 'straight', 'suke', 'suntek', 'tarantula', 'teleport', 'templeton', 'teoma', 'teradex', 'titan', 'titin', 'ucsd', 'udmsearch', 'urlck', 'valet', 'validator', 'valkyrie', 'victoria', 'vision', 'voyager', 'w3index', 'w3m2', 'w3mir', 'webbandit', 'webcatcher', 'webclipping', 'webcopy', 'webfetcher', 'weblayers', 'weblinker', 'webmoose', 'webquest', 'webrank', 'webreader', 'webreaper', 'webs', 'websquash', 'webvac', 'webwalk', 'webwalker', 'webwatch', 'wget', 'whatuseek', 'whizbang', 'widow', 'wlm', 'wolp', 'wwwc', 'wwwwanderer', 'xget', 'yahoo', 'yandex', 'zealbot', 'zeus', 'zippy' );[/b]
[b] /*--------------------------------------------------*/
/* Constructor
/*--------------------------------------------------*/[/b]
[b] /**
* Initialize the widget by setting localization, filters, and administration functions.
*
* @since 1.0.0
*/
public function __construct() {[/b]
[b] // Load plugin text domain
add_action( 'init', array( $this, 'widget_textdomain' ) );[/b]
[b] // Upgrade check
add_action( 'init', array( $this, 'upgrade_check' ) );[/b]
[b] // Hook fired when a new blog is activated on WP Multisite
add_action( 'wpmu_new_blog', array( $this, 'activate_new_site' ) );[/b]
[b] // Notices check
add_action( 'admin_notices', array( $this, 'check_admin_notices' ) );[/b]
[b] // Create the widget
parent::__construct(
'wpp',
'Wordpress Popular Posts',
array(
'classname' => 'popular-posts',
'description' => __( 'The most Popular Posts on your blog.', $this->plugin_slug )
)
);[/b]
[b] // Get user options
$this->user_settings = get_site_option('wpp_settings_config');
if ( !$this->user_settings ) {
add_site_option('wpp_settings_config', $this->default_user_settings);
$this->user_settings = $this->default_user_settings;
} else {
$this->user_settings = $this->__merge_array_r( $this->default_user_settings, $this->user_settings );
}[/b]
[b] // Add the options page and menu item.
add_action( 'admin_menu', array( $this, 'add_plugin_admin_menu' ) );[/b]
[b] // Register admin styles and scripts
add_action( 'admin_print_styles', array( $this, 'register_admin_styles' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'register_admin_scripts' ) );
add_action( 'admin_init', array( $this, 'thickbox_setup' ) );[/b]
[b] // Register site styles and scripts
if ( $this->user_settings['tools']['css'] )
add_action( 'wp_enqueue_scripts', array( $this, 'register_widget_styles' ) );[/b]
[b] // Add plugin settings link
add_filter( 'plugin_action_links', array( $this, 'add_plugin_settings_link' ), 10, 2 );[/b]
[b] // Set plugin directory
$this->plugin_dir = plugin_dir_url(__FILE__);[/b]
[b] // Get blog charset
$this->charset = get_bloginfo('charset');[/b]
[b] // Add ajax table truncation to wp_ajax_ hook
add_action('wp_ajax_wpp_clear_data', array( $this, 'clear_data' ));[/b]
[b] // Add ajax hook for widget
add_action('wp_ajax_wpp_get_popular', array( $this, 'get_popular') );
add_action('wp_ajax_nopriv_wpp_get_popular', array( $this, 'get_popular') );[/b]
[b] // Check if images can be created
if ( extension_loaded('ImageMagick') || (extension_loaded('GD') && function_exists('gd_info')) )
$this->thumbnailing = true;[/b]
[b] // Set default thumbnail
$this->default_thumbnail = $this->plugin_dir . "no_thumb.jpg";
$this->default_user_settings['tools']['thumbnail']['default'] = $this->default_thumbnail;[/b]
[b] if ( !empty($this->user_settings['tools']['thumbnail']['default']) )
$this->default_thumbnail = $this->user_settings['tools']['thumbnail']['default'];
else
$this->user_settings['tools']['thumbnail']['default'] = $this->default_thumbnail;[/b]
[b] // qTrans plugin support
if ( function_exists('qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage') )
$this->qTrans = true;[/b]
[b] // Remove post/page prefetching!
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head' );
// Add the update hooks only if the logging conditions are met
if ( (0 == $this->user_settings['tools']['log']['level'] && !is_user_logged_in()) || (1 == $this->user_settings['tools']['log']['level']) || (2 == $this->user_settings['tools']['log']['level'] && is_user_logged_in()) ) {
// Log views on page load via AJAX
add_action( 'wp_head', array(&$this, 'print_ajax') );[/b]
[b] // Register views from everyone and/or connected users
if ( 0 != $this->user_settings['tools']['log']['level'] )
add_action( 'wp_ajax_update_views_ajax', array($this, 'update_views_ajax') );
// Register views from everyone and/or visitors only
if ( 2 != $this->user_settings['tools']['log']['level'] )
add_action( 'wp_ajax_nopriv_update_views_ajax', array($this, 'update_views_ajax') );
}[/b]
[b] // Add shortcode
add_shortcode('wpp', array(&$this, 'shortcode'));[/b]
[b] // Enable data purging at midnight
add_action( 'wpp_cache_event', array($this, 'purge_data') );
if ( !wp_next_scheduled('wpp_cache_event') ) {
$tomorrow = time() + 86400;
$midnight = mktime(0, 0, 0,
date("m", $tomorrow),
date("d", $tomorrow),
date("Y", $tomorrow));
wp_schedule_event( $midnight, 'daily', 'wpp_cache_event' );
}[/b]
[b] } // end constructor[/b]
[b] /*--------------------------------------------------*/
/* Widget API Functions
/*--------------------------------------------------*/[/b]
[b] /**
* Outputs the content of the widget.
*
* @since 1.0.0
* @param array args The array of form elements
* @param array instance The current instance of the widget
*/
public function widget( $args, $instance ) {[/b]
[b] $this->__debug($args);[/b]
[b] /**
* @var String $name
* @var String $id
* @var String $description
* @var String $class
* @var String $before_widget
* @var String $after_widget
* @var String $before_title
* @var String $after_title
* @var String $widget_id
* @var String $widget_name
*/
extract( $args, EXTR_SKIP );[/b]
[b] $markup = ($instance['markup']['custom_html'])
? 'custom'
: 'regular';[/b]
[b] echo "\n". "<!-- Wordpress Popular Posts Plugin v{$this->version} [W] [{$instance['range']}] [{$instance['order_by']}] [{$markup}] -->" . "\n";[/b]
[b] echo $before_widget . "\n";[/b]
[b] // has user set a title?
if ( '' != $instance['title'] ) {[/b]
[b] $title = apply_filters( 'widget_title', $instance['title'] );[/b]
[b] if ($instance['markup']['custom_html'] && $instance['markup']['title-start'] != "" && $instance['markup']['title-end'] != "" ) {
echo htmlspecialchars_decode($instance['markup']['title-start'], ENT_QUOTES) . $title . htmlspecialchars_decode($instance['markup']['title-end'], ENT_QUOTES);
} else {
echo $before_title . $title . $after_title;
}
}[/b]
[b] if ( $this->user_settings['tools']['ajax'] ) {
if ( empty($before_widget) || !preg_match('/id="[^"]*"/', $before_widget) ) {
?>
<p><?php _e('Error: cannot ajaxify Wordpress Popular Posts on this theme. It\'s missing the <em>id</em> attribute on before_widget (see <a href="http://codex.wordpress.org/Function_Reference/register_sidebar" target="_blank" rel="nofollow">register_sidebar</a> for more).', $this->plugin_slug ); ?></p>
<?php
} else {
?>
<script type="text/javascript">//<![CDATA[
jQuery(document).ready(function(){
jQuery.get('<?php echo admin_url('admin-ajax.php'); ?>', {
action: 'wpp_get_popular',
id: '<?php echo $this->number; ?>'
}, function(data){
jQuery('#<?php echo $widget_id; ?>').append(data);
});
});
//]]></script>
<?php
}
} else {
echo $this->__get_popular_posts( $instance );
}[/b]
[b] echo $after_widget . "\n";
echo "<!-- End Wordpress Popular Posts Plugin v{$this->version} -->"."\n";[/b]
[b] } // end widget[/b]
[b] /**
* Processes the widget's options to be saved.
*
* @since 1.0.0
* @param array new_instance The previous instance of values before the update.
* @param array old_instance The new instance of values to be generated via the update.
* @return array instance Updated instance.
*/
public function update( $new_instance, $old_instance ) {[/b]
[b] $instance = $old_instance;[/b]
[b] $instance['title'] = htmlspecialchars( stripslashes_deep(strip_tags( $new_instance['title'] )), ENT_QUOTES );
$instance['limit'] = ( $this->__is_numeric($new_instance['limit']) && $new_instance['limit'] > 0 )
? $new_instance['limit']
: 10;
$instance['range'] = $new_instance['range'];
$instance['order_by'] = $new_instance['order_by'];[/b]
[b] // FILTERS
// user did not define the custom post type name, so we fall back to default
$instance['post_type'] = ( '' == $new_instance['post_type'] )
? 'post,page'
: $new_instance['post_type'];[/b]
[b] $instance['freshness'] = $new_instance['freshness'];[/b]
[b] $instance['pid'] = implode(",", array_filter(explode(",", preg_replace( '|[^0-9,]|', '', $new_instance['pid'] ))));
$instance['cat'] = implode(",", array_filter(explode(",", preg_replace( '|[^0-9,-]|', '', $new_instance['cat'] ))));
$instance['author'] = implode(",", array_filter(explode(",", preg_replace( '|[^0-9,]|', '', $new_instance['uid'] ))));[/b]
[b] $instance['shorten_title']['words'] = $new_instance['shorten_title-words'];
$instance['shorten_title']['active'] = $new_instance['shorten_title-active'];
$instance['shorten_title']['length'] = ( $this->__is_numeric($new_instance['shorten_title-length']) && $new_instance['shorten_title-length'] > 0 )
? $new_instance['shorten_title-length']
: 25;[/b]
[b] $instance['post-excerpt']['keep_format'] = $new_instance['post-excerpt-format'];
$instance['post-excerpt']['words'] = $new_instance['post-excerpt-words'];
$instance['post-excerpt']['active'] = $new_instance['post-excerpt-active'];
$instance['post-excerpt']['length'] = ( $this->__is_numeric($new_instance['post-excerpt-length']) && $new_instance['post-excerpt-length'] > 0 )
? $new_instance['post-excerpt-length']
: 55;[/b]
[b] $instance['thumbnail']['active'] = false;
$instance['thumbnail']['width'] = 15;
$instance['thumbnail']['height'] = 15;[/b]
[b] // can create thumbnails
if ( $this->thumbnailing ) {[/b]
[b] $instance['thumbnail']['active'] = $new_instance['thumbnail-active'];[/b]
[b] if ($this->__is_numeric($new_instance['thumbnail-width']) && $this->__is_numeric($new_instance['thumbnail-height'])) {
$instance['thumbnail']['width'] = $new_instance['thumbnail-width'];
$instance['thumbnail']['height'] = $new_instance['thumbnail-height'];
}[/b]
[b] }[/b]
[b] if ( isset($instance['thumbnail']['thumb_selection']) )
unset( $instance['thumbnail']['thumb_selection'] );[/b]
[b] $instance['rating'] = $new_instance['rating'];
$instance['stats_tag']['comment_count'] = $new_instance['comment_count'];
$instance['stats_tag']['views'] = $new_instance['views'];
$instance['stats_tag']['author'] = $new_instance['author'];
$instance['stats_tag']['date']['active'] = $new_instance['date'];
$instance['stats_tag']['date']['format'] = empty($new_instance['date_format'])
? 'F j, Y'
: $new_instance['date_format'];[/b]
[b] $instance['stats_tag']['category'] = $new_instance['category'];
$instance['markup']['custom_html'] = $new_instance['custom_html'];
$instance['markup']['wpp-start'] = empty($new_instance['wpp-start'])
? htmlspecialchars( '<ul class="wpp-list">', ENT_QUOTES )
: htmlspecialchars( $new_instance['wpp-start'], ENT_QUOTES );[/b]
[b] $instance['markup']['wpp-end'] = empty($new_instance['wpp-end'])
? htmlspecialchars( '</ul>', ENT_QUOTES )
: htmlspecialchars( $new_instance['wpp-end'], ENT_QUOTES );[/b]
[b] $instance['markup']['post-html'] = empty($new_instance['post-html'])
? htmlspecialchars( '<li>{thumb} {title} {stats}</li>', ENT_QUOTES )
: htmlspecialchars( $new_instance['post-html'], ENT_QUOTES );[/b]
[b] $instance['markup']['title-start'] = empty($new_instance['title-start'])
? ''
: htmlspecialchars( $new_instance['title-start'], ENT_QUOTES );[/b]
[b] $instance['markup']['title-end'] = empty($new_instance['title-end'])
? '' :
htmlspecialchars( $new_instance['title-end'], ENT_QUOTES );[/b]
[b] return $instance;[/b]
[b] } // end widget[/b]
[b] /**
* Generates the administration form for the widget.
*
* @since 1.0.0
* @param array instance The array of keys and values for the widget.
*/
public function form( $instance ) {[/b]
[b] // parse instance values
$instance = $this->__merge_array_r(
$this->defaults,
$instance
);[/b]
[b] // Display the admin form
include( plugin_dir_path(__FILE__) . '/views/form.php' );[/b]
[b] } // end form[/b]
[b] /*--------------------------------------------------*/
/* Public methods
/*--------------------------------------------------*/[/b]
[b] /**
* Loads the Widget's text domain for localization and translation.
*
* @since 1.0.0
*/
public function widget_textdomain() {[/b]
[b] $domain = $this->plugin_slug;
$locale = apply_filters( 'plugin_locale', get_locale(), $domain );[/b]
[b] load_textdomain( $domain, WP_LANG_DIR . '/' . $domain . '/' . $domain . '-' . $locale . '.mo' );
load_plugin_textdomain( $domain, FALSE, dirname( plugin_basename( __FILE__ ) ) . '/lang/' );[/b]
[b] } // end widget_textdomain[/b]
[b] /**
* Registers and enqueues admin-specific styles.
*
* @since 1.0.0
*/
public function register_admin_styles() {[/b]
[b] if ( ! isset( $this->plugin_screen_hook_suffix ) ) {
return;
}[/b]
[b] $screen = get_current_screen();
if ( $screen->id == $this->plugin_screen_hook_suffix ) {
wp_enqueue_style( $this->plugin_slug .'-admin-styles', plugins_url( 'style/admin.css', __FILE__ ), array(), $this->version );
}[/b]
[b] } // end register_admin_styles[/b]
[b] /**
* Registers and enqueues admin-specific Javascript.
*
* @since 2.3.4
*/
public function register_admin_scripts() {[/b]
[b] if ( ! isset( $this->plugin_screen_hook_suffix ) ) {
return;
}[/b]
[b] $screen = get_current_screen();
if ( $screen->id == $this->plugin_screen_hook_suffix ) {
wp_enqueue_script( 'thickbox' );
wp_enqueue_style( 'thickbox' );
wp_enqueue_script( 'media-upload' );
wp_enqueue_script( $this->plugin_slug .'-admin-script', plugins_url( 'js/admin.js', __FILE__ ), array('jquery'), $this->version );
}[/b]
[b] } // end register_admin_scripts[/b]
[b] /**
* Hooks into getttext to change upload button text when uploader is called by WPP.
*
* @since 2.3.4
*/
function thickbox_setup() {[/b]
[b] global $pagenow;
if ( 'media-upload.php' == $pagenow || 'async-upload.php' == $pagenow ) {
add_filter( 'gettext', array( $this, 'replace_thickbox_text' ), 1, 3 );
}[/b]
[b] } // end thickbox_setup[/b]
[b] /**
* Replaces upload button text when uploader is called by WPP.
*
* @since 2.3.4
* @param string translated_text
* @param string text
* @param string domain
* @return string
*/
function replace_thickbox_text($translated_text, $text, $domain) {[/b]
[b] if ('Insert into Post' == $text) {
$referer = strpos( wp_get_referer(), 'wpp_admin' );
if ( $referer != '' ) {
return __('Upload', $this->plugin_slug );
}
}[/b]
[b] return $translated_text;[/b]
[b] } // end replace_thickbox_text[/b]
[b] /**
* Registers and enqueues widget-specific styles.
*
* @since 1.0.0
*/
public function register_widget_styles() {[/b]
[b] $theme_file = get_stylesheet_directory() . '/wpp.css';
$plugin_file = plugin_dir_path(__FILE__) . 'style/wpp.css';[/b]
[b] if ( @file_exists($theme_file) ) { // user stored a custom wpp.css on theme's directory, so use it
wp_enqueue_style( $this->plugin_slug, get_stylesheet_directory_uri() . "/wpp.css", array(), $this->version );
} elseif ( @file_exists($plugin_file) ) { // no custom wpp.css, use plugin's instead
wp_enqueue_style( $this->plugin_slug, plugins_url( 'style/wpp.css', __FILE__ ), array(), $this->version );
}[/b]
[b] } // end register_widget_styles[/b]
[b] /**
* Register the administration menu for this plugin into the WordPress Dashboard menu.
*
* @since 1.0.0
*/
public function add_plugin_admin_menu() {[/b]
[b] $this->plugin_screen_hook_suffix = add_options_page(
'Wordpress Popular Posts',
'Wordpress Popular Posts',
'manage_options',
$this->plugin_slug,
array( $this, 'display_plugin_admin_page' )
);[/b]
[b] }[/b]
[b] /**
* Render the settings page for this plugin.
*
* @since 1.0.0
*/
public function display_plugin_admin_page() {
include_once( 'views/admin.php' );
}[/b]
[b] /**
* Registers Settings link on plugin description.
*
* @since 2.3.3
* @param array links
* @param string file
* @return array
*/
public function add_plugin_settings_link( $links, $file ){[/b]
[b] $this_plugin = plugin_basename(__FILE__);[/b]
[b] if ( is_plugin_active($this_plugin) && $file == $this_plugin ) {
$links[] = '<a href="' . admin_url( 'options-general.php?page=wordpress-popular-posts' ) . '">Settings</a>';
}[/b]
[b] return $links;[/b]
[b] } // end add_plugin_settings_link[/b]
[b] /*--------------------------------------------------*/
/* Install / activation / deactivation methods
/*--------------------------------------------------*/[/b]
[b] /**
* Return an instance of this class.
*
* @since 3.0.0
* @return object A single instance of this class.
*/
public static function get_instance() {[/b]
[b] // If the single instance hasn't been set, set it now.
if ( NULL == self::$instance ) {
self::$instance = new self;
}[/b]
[b] return self::$instance;[/b]
[b] } // end get_instance[/b]
[b] /**
* Fired when the plugin is activated.
*
* @since 1.0.0
* @global object wpdb
* @param bool network_wide True if WPMU superadmin uses "Network Activate" action, false if WPMU is disabled or plugin is activated on an individual blog.
*/
public static function activate( $network_wide ) {[/b]
[b] global $wpdb;[/b]
[b] if ( function_exists( 'is_multisite' ) && is_multisite() ) {[/b]
[b] // run activation for each blog in the network
if ( $network_wide ) {[/b]
[b] $original_blog_id = get_current_blog_id();
$blogs_ids = $wpdb->get_col( "SELECT blog_id FROM {$wpdb->blogs}" );[/b]
[b] foreach( $blogs_ids as $blog_id ) {
switch_to_blog( $blog_id );
self::__activate();
}[/b]
[b] // switch back to current blog
switch_to_blog( $original_blog_id );[/b]
[b] return;[/b]
[b] }[/b]
[b] }[/b]
[b] self::__activate();[/b]
[b] } // end activate[/b]
[b] /**
* Fired when a new blog is activated on WP Multisite.
*
* @since 3.0.0
* @param int blog_id New blog ID
*/
public function activate_new_site( $blog_id ){[/b]
[b] if ( 1 !== did_action( 'wpmu_new_blog' ) )
return;[/b]
[b] // run activation for the new blog
switch_to_blog( $blog_id );
self::__activate();[/b]
[b] // switch back to current blog
restore_current_blog();[/b]
[b] } // end activate_new_site[/b]
[b] /**
* On plugin activation, checks that the WPP database tables are present.
*
* @since 2.4.0
* @global object wpdb
*/
private static function __activate() {[/b]
[b] global $wpdb;[/b]
[b] // set table name
$prefix = $wpdb->prefix . "popularposts";[/b]
[b] // fresh setup
if ( $prefix != $wpdb->get_var("SHOW TABLES LIKE '{$prefix}data'") ) {
self::__do_db_tables( $prefix );
}[/b]
[b] } // end __activate[/b]
[b] /**
* Fired when the plugin is deactivated.
*
* @since 1.0.0
* @global object wpbd
* @param bool network_wide True if WPMU superadmin uses "Network Activate" action, false if WPMU is disabled or plugin is activated on an individual blog
*/
public static function deactivate( $network_wide ) {[/b]
[b] global $wpdb;[/b]
[b] if ( function_exists( 'is_multisite' ) && is_multisite() ) {[/b]
[b] // Run deactivation for each blog in the network
if ( $network_wide ) {[/b]
[b] $original_blog_id = get_current_blog_id();
$blogs_ids = $wpdb->get_col( "SELECT blog_id FROM {$wpdb->blogs}" );[/b]
[b] foreach( $blogs_ids as $blog_id ) {
switch_to_blog( $blog_id );
self::__deactivate();
}[/b]
[b] // Switch back to current blog
switch_to_blog( $original_blog_id );[/b]
[b] return;[/b]
[b] }[/b]
[b] }[/b]
[b] self::__deactivate();[/b]
[b] } // end deactivate[/b]
[b] /**
* On plugin deactivation, disables the shortcode and removes the scheduled task.
*
* @since 2.4.0
*/
private static function __deactivate() {[/b]
[b] remove_shortcode('wpp');
wp_clear_scheduled_hook('wpp_cache_event');[/b]
[b] } // end __deactivate[/b]
[b] /**
* Checks if an upgrade procedure is required.
*
* @since 2.4.0
*/
public function upgrade_check(){[/b]
[b] // Get WPP version
$wpp_ver = get_site_option('wpp_ver');[/b]
[b] if ( !$wpp_ver ) {
add_site_option('wpp_ver', $this->version);
} elseif ( version_compare($wpp_ver, $this->version, '<') ) {
$this->__upgrade();
}[/b]
[b] } // end upgrade_check[/b]
[b] /**
* On plugin upgrade, performs a number of actions: update WPP database tables structures (if needed),
* run the setup wizard (if needed), and some other checks.
*
* @since 2.4.0
* @global object wpdb
*/
private function __upgrade() {[/b]
[b] global $wpdb;[/b]
[b] // set table name
$prefix = $wpdb->prefix . "popularposts";[/b]
[b] // validate the structure of the tables and create missing tables
self::__do_db_tables( $prefix );[/b]
[b] // If summary is empty, import data from popularpostsdatacache
if ( !$wpdb->get_var("SELECT COUNT(*) FROM {$prefix}summary") ) {[/b]
[b] // popularpostsdatacache table is still there
if ( $wpdb->get_var("SHOW TABLES LIKE '{$prefix}datacache'") ) {[/b]
[b] $sql = "
INSERT INTO {$prefix}summary (postid, pageviews, view_date, last_viewed)
SELECT id, pageviews, day_no_time, day
FROM {$prefix}datacache
GROUP BY day_no_time, id
ORDER BY day_no_time DESC";[/b]
[b] $result = $wpdb->query( $sql );[/b]
[b] // Rename old caching table
if ( $result ) {
$result = $wpdb->query( "RENAME TABLE {$prefix}datacache TO {$prefix}datacache_backup;" );
}[/b]
[b] }[/b]
[b] }[/b]
[b] // Check indexes and fields
$dataFields = $wpdb->get_results( "SHOW FIELDS FROM {$prefix}data;" );[/b]
[b] // Update fields, if needed
foreach ( $dataFields as $column ) {
if ( "postid" == $column->Field && "bigint(20)" != $column->Type ) {
$wpdb->query("ALTER TABLE {$prefix}data CHANGE postid postid bigint(20) NOT NULL;");
}[/b]
[b] if ( "pageviews" == $column->Field && "bigint(20)" != $column->Type ) {
$wpdb->query("ALTER TABLE {$prefix}data CHANGE pageviews pageviews bigint(20) DEFAULT 1;");
}
}[/b]
[b] // Update index, if needed
$dataIndex = $wpdb->get_results("SHOW INDEX FROM {$prefix}data;", ARRAY_A);[/b]
[b] if ( "PRIMARY" != $dataIndex[0]['Key_name'] ) {
$wpdb->query("ALTER TABLE {$prefix}data DROP INDEX id, ADD PRIMARY KEY (postid);");
}[/b]
[b] // Update WPP version
update_site_option('wpp_ver', $this->version);[/b]
[b] } // end __upgrade[/b]
[b] /**
* Creates/updates the WPP database tables.
*
* @since 2.4.0
* @global object wpdb
*/
private static function __do_db_tables( $prefix ) {[/b]
[b] global $wpdb;[/b]
[b] $sql = "";
$charset_collate = "";[/b]
[b] if ( !empty($wpdb->charset) )
$charset_collate = "DEFAULT CHARACTER SET {$wpdb->charset} ";[/b]
[b] if ( !empty($wpdb->collate) )
$charset_collate .= "COLLATE {$wpdb->collate}";[/b]
[b] $sql = "
CREATE TABLE {$prefix}data (
postid bigint(20) NOT NULL,
day datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
last_viewed datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
pageviews bigint(20) DEFAULT 1,
PRIMARY KEY (postid)
) {$charset_collate};
CREATE TABLE {$prefix}summary (
ID bigint(20) NOT NULL AUTO_INCREMENT,
postid bigint(20) NOT NULL,
pageviews bigint(20) NOT NULL DEFAULT 1,
view_date date NOT NULL DEFAULT '0000-00-00',
last_viewed datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (ID),
UNIQUE KEY ID_date (postid,view_date),
KEY postid (postid),
KEY last_viewed (last_viewed)
) {$charset_collate};";[/b]
[b] require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);[/b]
[b] } // end __do_db_tables[/b]
[b] /**
* Checks if the technical requirements are met.
*
* @since 2.4.0
* @link http://wordpress.stackexchange.com/questions/25910/uninstall-activate-deactivate-a-plugin-typical-features-how-to/25979#25979
* @global string $wp_version
* @return array
*/
private function __check_requirements() {[/b]
[b] global $wp_version;[/b]
[b] $php_min_version = '5.2';
$wp_min_version = '3.8';
$php_current_version = phpversion();
$errors = array();[/b]
[b] if ( version_compare( $php_min_version, $php_current_version, '>' ) ) {
$errors[] = sprintf(
__( 'Your PHP installation is too old. Wordpress Popular Posts requires at least PHP version %1$s to function correctly. Please contact your hosting provider and ask them to upgrade PHP to %1$s or higher.', $this->plugin_slug ),
$php_min_version
);
}[/b]
[b] if ( version_compare( $wp_min_version, $wp_version, '>' ) ) {
$errors[] = sprintf(
__( 'Your Wordpress version is too old. Wordpress Popular Posts requires at least Wordpress version %1$s to function correctly. Please update your blog via Dashboard > Update.', $this->plugin_slug ),
$wp_min_version
);
}[/b]
[b] return $errors;[/b]
[b] } // end __check_requirements[/b]
[b] /**
* Outputs error messages to wp-admin.
*
* @since 2.4.0
*/
public function check_admin_notices() {[/b]
[b] $errors = $this->__check_requirements();[/b]
[b] if ( empty($errors) )
return;[/b]
[b] if ( isset($_GET['activate']) )
unset($_GET['activate']);[/b]
[b] printf(
__('<div class="error"><p>%1$s</p><p><i>%2$s</i> has been <strong>deactivated</strong>.</p></div>', $this->plugin_slug),
join( '</p><p>', $errors ),
'Wordpress Popular Posts'
);[/b]
[b] deactivate_plugins( plugin_basename( __FILE__ ) );[/b]
[b] } // end check_admin_notices[/b]

[b] /*--------------------------------------------------*/
/* Plugin methods / functions
/*--------------------------------------------------*/[/b]
[b] /**
* Purges deleted posts from data/summary tables.
*
* @since 2.0.0
* @global object $wpdb
*/
public function purge_data() {[/b]
[b] global $wpdb;[/b]
[b] if ( $missing = $wpdb->get_results( "SELECT v.postid AS id FROM {$wpdb->prefix}popularpostsdata v WHERE NOT EXISTS (SELECT p.ID FROM {$wpdb->posts} p WHERE v.postid = p.ID);" ) ) {
$to_be_deleted = '';[/b]
[b] foreach ( $missing as $deleted )
$to_be_deleted .= $deleted->id . ",";[/b]
[b] $to_be_deleted = rtrim( $to_be_deleted, "," );[/b]
[b] $wpdb->query( "DELETE FROM {$wpdb->prefix}popularpostsdata WHERE postid IN({$to_be_deleted});" );
$wpdb->query( "DELETE FROM {$wpdb->prefix}popularpostssummary WHERE postid IN({$to_be_deleted});" );
}[/b]
[b] } // end purge_data[/b]
[b] /**
* Truncates data and cache on demand.
*
* @since 2.0.0
* @global object wpdb
*/
public function clear_data() {[/b]
[b] $token = $_POST['token'];
$clear = isset($_POST['clear']) ? $_POST['clear'] : '';
$key = get_site_option("wpp_rand");[/b]
[b] if (current_user_can('manage_options') && ($token === $key) && !empty($clear)) {
global $wpdb;[/b]
[b] // set table name
$prefix = $wpdb->prefix . "popularposts";[/b]
[b] if ($clear == 'cache') {
if ( $wpdb->get_var("SHOW TABLES LIKE '{$prefix}summary'") ) {
$wpdb->query("TRUNCATE TABLE {$prefix}summary;");
$this->__flush_transients();
_e('Success! The cache table has been cleared!', $this->plugin_slug);
} else {
_e('Error: cache table does not exist.', $this->plugin_slug);
}
} else if ($clear == 'all') {
if ( $wpdb->get_var("SHOW TABLES LIKE '{$prefix}data'") && $wpdb->get_var("SHOW TABLES LIKE '{$prefix}summary'") ) {
$wpdb->query("TRUNCATE TABLE {$prefix}data;");
$wpdb->query("TRUNCATE TABLE {$prefix}summary;");
$this->__flush_transients();
_e('Success! All data have been cleared!', $this->plugin_slug);
} else {
_e('Error: one or both data tables are missing.', $this->plugin_slug);
}
} else {
_e('Invalid action.', $this->plugin_slug);
}
} else {
_e('Sorry, you do not have enough permissions to do this. Please contact the site administrator for support.', $this->plugin_slug);
}[/b]
[b] die();[/b]
[b] } // end clear_data[/b]
[b] /**
* Updates views count on page load via AJAX.
*
* @since 2.0.0
*/
public function update_views_ajax(){[/b]
[b] if ( !wp_verify_nonce($_GET['token'], 'wpp-token') || !$this->__is_numeric($_GET['id']) )
die("WPP: Oops, invalid request!");[/b]
[b] $nonce = $_GET['token'];
$post_ID = $_GET['id'];[/b]
[b] $exec_time = 0;[/b]
[b] $start = $this->__microtime_float();
$result = $this->__update_views($post_ID);
$end = $this->__microtime_float();[/b]
[b] $exec_time += round($end - $start, 6);[/b]
[b] if ( $result ) {
die( "WPP: OK. Execution time: " . $exec_time . " seconds" );
}[/b]
[b] die( "WPP: Oops, could not update the views count!" );[/b]
[b] } // end update_views_ajax[/b]
[b] /**
* Outputs script to update views via AJAX.
*
* @since 2.0.0
* @global object post
*/
public function print_ajax(){[/b]
[b] wp_print_scripts('jquery');[/b]
[b] if ( !is_singular() || is_attachment() || is_front_page() || is_preview() || is_trackback() || is_feed() || is_robots() || $this->__is_bot() )
return;[/b]
[b] global $post;
$nonce = wp_create_nonce('wpp-token');[/b]
[b] ?>
<!-- Wordpress Popular Posts v<?php echo $this->version; ?> -->
<script type="text/javascript">//<![CDATA[
jQuery(document).ready(function(){
jQuery.get('<?php echo admin_url('admin-ajax.php'); ?>', {
action: 'update_views_ajax',
token: '<?php echo $nonce; ?>',
id: <?php echo $post->ID; ?>
}, function(response){
if ( console && console.log )
console.log(response);
});
});
//]]></script>
<!-- End Wordpress Popular Posts v<?php echo $this->version; ?> -->
<?php[/b]
[b] } // end print_ajax[/b]
[b] /**
* Deletes cached (transient) data.
*
* @since 3.0.0
*/
private function __flush_transients() {[/b]
[b] $wpp_transients = get_site_option('wpp_transients');[/b]
[b] if ( $wpp_transients && is_array($wpp_transients) && !empty($wpp_transients) ) {
for ($t=0; $t < count($wpp_transients); $t++)
delete_transient( $wpp_transients[$t] );[/b]
[b] update_site_option('wpp_transients', array());
}[/b]
[b] } // end __flush_transients[/b]
[b] /**
* Updates views count.
*
* @since 1.4.0
* @global object $wpdb
* @param int Post ID
* @return bool|int FALSE if query failed, TRUE on success
*/
private function __update_views($id) {[/b]
[b] /*
TODO:
For WordPress Multisite, we must define the DIEONDBERROR constant for database errors to display like so:
<?php define( 'DIEONDBERROR', true ); ?>
*/[/b]
[b] global $wpdb;
$table = $wpdb->prefix . "popularposts";
$wpdb->show_errors();[/b]
[b] // WPML support, get original post/page ID
if ( defined('ICL_LANGUAGE_CODE') && function_exists('icl_object_id') ) {
global $sitepress;
$id = icl_object_id( $id, get_post_type( $id ), false, $sitepress->get_default_language() );
}[/b]
[b] $now = $this->__now();
$curdate = $this->__curdate();[/b]
[b] // Update all-time table
$result1 = $wpdb->query( $wpdb->prepare(
"INSERT INTO {$table}data
(postid, day, last_viewed, pageviews) VALUES (%d, %s, %s, %d)
ON DUPLICATE KEY UPDATE pageviews = pageviews + 1, last_viewed = '%3\$s';",
$id,
$now,
$now,
1
));[/b]
[b] // Update range (summary) table
$result2 = $wpdb->query( $wpdb->prepare(
"INSERT INTO {$table}summary
(postid, pageviews, view_date, last_viewed) VALUES (%d, %d, %s, %s)
ON DUPLICATE KEY UPDATE pageviews = pageviews + 1, last_viewed = '%4\$s';",
$id,
1,
$curdate,
$now
));[/b]
[b] if ( !$result1 || !$result2 )
return false;[/b]
[b] // Allow WP themers / coders perform an action
// after updating views count
if ( has_action( 'wpp_update_views' ) )
do_action( 'wpp_update_views', $id );[/b]
[b] return true;[/b]
[b] } // end __update_views[/b]
[b] /**
* Queries the database and returns the posts (if any met the criteria set by the user).
*
* @since 1.4.0
* @global object $wpdb
* @param array Widget instance
* @return null|array Array of posts, or null if nothing was found
*/
protected function _query_posts($instance) {[/b]
[b] global $wpdb;[/b]
[b] // parse instance values
$instance = $this->__merge_array_r(
$this->defaults,
$instance
);[/b]
[b] $prefix = $wpdb->prefix . "popularposts";
$fields = "p.ID AS 'id', p.post_title AS 'title', p.post_date AS 'date', p.post_author AS 'uid'";
$from = "";
$where = "WHERE 1 = 1";
$orderby = "";
$groupby = "";
$limit = "LIMIT {$instance['limit']}";[/b]
[b] $post_types = "";
$pids = "";
$cats = "";
$authors = "";
$content = "";[/b]
[b] $now = $this->__now();[/b]
[b] // post filters
// * freshness - get posts published within the selected time range only
if ( $instance['freshness'] ) {
switch( $instance['range'] ){
case "yesterday":
$where .= " AND p.post_date > DATE_SUB('{$now}', INTERVAL 1 DAY) ";
break;[/b]
[b] case "daily":
$where .= " AND p.post_date > DATE_SUB('{$now}', INTERVAL 1 DAY) ";
break;[/b]
[b] case "weekly":
$where .= " AND p.post_date > DATE_SUB('{$now}', INTERVAL 1 WEEK) ";
break;[/b]
[b] case "monthly":
$where .= " AND p.post_date > DATE_SUB('{$now}', INTERVAL 1 MONTH) ";
break;[/b]
[b] default:
$where .= "";
break;
}
}[/b]
[b] // * post types - based on code seen at https://github.com/williamsba/WordPress-Popular-Posts-with-Custom-Post-Type-Support
$types = explode(",", $instance['post_type']);
$sql_post_types = "";
$join_cats = true;[/b]
[b] // if we're getting just pages, why join the categories table?
if ( 'page' == strtolower($instance['post_type']) ) {[/b]
[b] $join_cats = false;
$where .= " AND p.post_type = '{$instance['post_type']}'";[/b]
[b] }
// we're listing other custom type(s)
else {[/b]
[b] if ( count($types) > 1 ) {[/b]
[b] foreach ( $types as $post_type ) {
$sql_post_types .= "'{$post_type}',";
}[/b]
[b] $sql_post_types = rtrim( $sql_post_types, ",");
$where .= " AND p.post_type IN({$sql_post_types})";[/b]
[b] } else {
$where .= " AND p.post_type = '{$instance['post_type']}'";
}[/b]
[b] }[/b]
[b] // * posts exclusion
if ( !empty($instance['pid']) ) {[/b]
[b] $ath = explode(",", $instance['pid']);[/b]
[b] $where .= ( count($ath) > 1 )
? " AND p.ID NOT IN({$instance['pid']})"
: " AND p.ID <> '{$instance['pid']}'";[/b]
[b] }[/b]
[b] // * categories
if ( !empty($instance['cat']) && $join_cats ) {[/b]
[b] $cat_ids = explode(",", $instance['cat']);
$in = array();
$out = array();
$not_in = "";[/b]
[b] usort($cat_ids, array(&$this, '__sorter'));[/b]
[b] for ($i=0; $i < count($cat_ids); $i++) {
if ($cat_ids[$i] >= 0) $in[] = $cat_ids[$i];
if ($cat_ids[$i] < 0) $out[] = $cat_ids[$i];
}[/b]
[b] $in_cats = implode(",", $in);
$out_cats = implode(",", $out);
$out_cats = preg_replace( '|[^0-9,]|', '', $out_cats );[/b]
[b] if ($in_cats != "" && $out_cats == "") { // get posts from from given cats only
$where .= " AND p.ID IN (
SELECT object_id
FROM {$wpdb->term_relationships} AS r
JOIN {$wpdb->term_taxonomy} AS x ON x.term_taxonomy_id = r.term_taxonomy_id
JOIN {$wpdb->terms} AS t ON t.term_id = x.term_id
WHERE x.taxonomy = 'category' AND t.term_id IN({$in_cats})
)";
} else if ($in_cats == "" && $out_cats != "") { // exclude posts from given cats only
$where .= " AND p.ID NOT IN (
SELECT object_id
FROM {$wpdb->term_relationships} AS r
JOIN {$wpdb->term_taxonomy} AS x ON x.term_taxonomy_id = r.term_taxonomy_id
JOIN {$wpdb->terms} AS t ON t.term_id = x.term_id
WHERE x.taxonomy = 'category' AND t.term_id IN({$out_cats})
)";
} else { // mixed, and possibly a heavy load on the DB
$where .= " AND p.ID IN (
SELECT object_id
FROM {$wpdb->term_relationships} AS r
JOIN {$wpdb->term_taxonomy} AS x ON x.term_taxonomy_id = r.term_taxonomy_id
JOIN {$wpdb->terms} AS t ON t.term_id = x.term_id
WHERE x.taxonomy = 'category' AND t.term_id IN({$in_cats})
) AND p.ID NOT IN (
SELECT object_id
FROM {$wpdb->term_relationships} AS r
JOIN {$wpdb->term_taxonomy} AS x ON x.term_taxonomy_id = r.term_taxonomy_id
JOIN {$wpdb->terms} AS t ON t.term_id = x.term_id
WHERE x.taxonomy = 'category' AND t.term_id IN({$out_cats})
)";
}[/b]
[b] }[/b]
[b] // * authors
if ( !empty($instance['author']) ) {[/b]
[b] $ath = explode(",", $instance['author']);[/b]
[b] $where .= ( count($ath) > 1 )
? " AND p.post_author IN({$instance['author']})"
: " AND p.post_author = '{$instance['author']}'";[/b]
[b] }[/b]
[b] // All-time range
if ( "all" == $instance['range'] ) {[/b]
[b] $fields .= ", p.comment_count AS 'comment_count'";[/b]
[b] // order by comments
if ( "comments" == $instance['order_by'] ) {[/b]
[b] $from = "{$wpdb->posts} p";
$where .= " AND p.comment_count > 0 AND p.post_password = '' AND p.post_status = 'publish'";
$orderby = " ORDER BY p.comment_count DESC";[/b]
[b] // get views, too
if ( $instance['stats_tag']['views'] ) {[/b]
[b] $fields .= ", IFNULL(v.pageviews, 0) AS 'pageviews'";
$from .= " LEFT JOIN {$prefix}data v ON p.ID = v.postid";[/b]
[b] }[/b]
[b] }
// order by (avg) views
else {[/b]
[b] $from = "{$prefix}data v LEFT JOIN {$wpdb->posts} p ON v.postid = p.ID";
$where .= " AND p.post_password = '' AND p.post_status = 'publish'";[/b]
[b] // order by views
if ( "views" == $instance['order_by'] ) {[/b]
[b] $fields .= ", v.pageviews AS 'pageviews'";
$orderby = "ORDER BY pageviews DESC";[/b]
[b] }
// order by avg views
elseif ( "avg" == $instance['order_by'] ) {[/b]
[b] $fields .= ", ( v.pageviews/(IF ( DATEDIFF('{$now}', MIN(v.day)) > 0, DATEDIFF('{$now}', MIN(v.day)), 1) ) ) AS 'avg_views'";
$orderby = "ORDER BY avg_views DESC";[/b]
[b] }[/b]
[b] }[/b]
[b] } else { // CUSTOM RANGE[/b]
[b] $interval = "";[/b]
[b] switch( $instance['range'] ){
case "yesterday":
$interval = "1 DAY";
break;[/b]
[b] case "daily":
$interval = "1 DAY";
break;[/b]
[b] case "weekly":
$interval = "1 WEEK";
break;[/b]
[b] case "monthly":
$interval = "1 MONTH";
break;[/b]
[b] default:
$interval = "1 DAY";
break;
}[/b]
[b] // order by comments
if ( "comments" == $instance['order_by'] ) {[/b]
[b] $fields .= ", c.comment_count AS 'comment_count'";
$from = "(SELECT comment_post_ID AS 'id', COUNT(comment_post_ID) AS 'comment_count' FROM {$wpdb->comments} WHERE comment_date > DATE_SUB('{$now}', INTERVAL {$interval}) AND comment_approved = 1 GROUP BY id ORDER BY comment_count DESC) c LEFT JOIN {$wpdb->posts} p ON c.id = p.ID";
$where .= " AND p.post_password = '' AND p.post_status = 'publish'";[/b]
[b] if ( $instance['stats_tag']['views'] ) { // get views, too[/b]
[b] $fields .= ", IFNULL(v.pageviews, 0) AS 'pageviews'";
$from .= " LEFT JOIN (SELECT postid, SUM(pageviews) AS pageviews FROM {$prefix}summary WHERE last_viewed > DATE_SUB('{$now}', INTERVAL {$interval}) GROUP BY postid ORDER BY pageviews DESC) v ON p.ID = v.postid";[/b]
[b] }[/b]
[b] }
// ordered by views / avg
else {[/b]
[b] $from = "(SELECT postid, IFNULL(SUM(pageviews), 0) AS pageviews FROM {$prefix}summary WHERE last_viewed > DATE_SUB('{$now}', INTERVAL {$interval}) GROUP BY postid ORDER BY pageviews DESC) v LEFT JOIN {$wpdb->posts} p ON v.postid = p.ID";
$where .= " AND p.post_password = '' AND p.post_status = 'publish'";[/b]
[b] // ordered by views
if ( "views" == $instance['order_by'] ) {
$fields .= ", v.pageviews AS 'pageviews'";
}
// ordered by avg views
elseif ( "avg" == $instance['order_by'] ) {[/b]
[b] $fields .= ", ( v.pageviews/(IF ( DATEDIFF('{$now}', DATE_SUB('{$now}', INTERVAL {$interval})) > 0, DATEDIFF('{$now}', DATE_SUB('{$now}', INTERVAL {$interval})), 1) ) ) AS 'avg_views' ";
$groupby = "GROUP BY v.postid";
$orderby = "ORDER BY avg_views DESC";[/b]
[b] }[/b]
[b] // get comments, too
if ( $instance['stats_tag']['comment_count'] ) {[/b]
[b] $fields .= ", IFNULL(c.comment_count, 0) AS 'comment_count'";
$from .= " LEFT JOIN (SELECT comment_post_ID AS 'id', COUNT(comment_post_ID) AS 'comment_count' FROM {$wpdb->comments} WHERE comment_date > DATE_SUB('{$now}', INTERVAL {$interval}) AND comment_approved = 1 GROUP BY id ORDER BY comment_count DESC) c ON p.ID = c.id";[/b]
[b] }[/b]
[b] }[/b]
[b] }[/b]
[b] $query = "SELECT {$fields} FROM {$from} {$where} {$groupby} {$orderby} {$limit};";
$this->__debug( $query );[/b]
[b] $result = $wpdb->get_results($query);[/b]
[b] return apply_filters( 'wpp_query_posts', $result, $instance );[/b]
[b] } // end query_posts[/b]
[b] /**
* Returns the formatted list of posts.
*
* @since 3.0.0
* @param array instance The current instance of the widget / shortcode parameters
* @return string HTML list of popular posts
*/
private function __get_popular_posts( $instance ) {[/b]
[b] // Parse instance values
$instance = $this->__merge_array_r(
$this->defaults,
$instance
);[/b]
[b] $content = "";[/b]
[b] // Fetch posts
if ( !defined('WPP_ADMIN') && $this->user_settings['tools']['cache']['active'] ) {
$transient_name = md5(json_encode($instance));
$mostpopular = ( function_exists( 'is_multisite' ) && is_multisite() )
? get_site_transient( $transient_name )
: get_transient( $transient_name );[/b]
[b] // It wasn't there, so regenerate the data and save the transient
if ( false === $mostpopular ) {
$mostpopular = $this->_query_posts( $instance );[/b]
[b] switch($this->user_settings['tools']['cache']['interval']['time']){
case 'hour':
$time = 60 * 60;
break;[/b]
[b] case 'day':
$time = 60 * 60 * 24;
break;[/b]
[b] case 'week':
$time = 60 * 60 * 24 * 7;
break;[/b]
[b] case 'month':
$time = 60 * 60 * 24 * 30;
break;[/b]
[b] case 'year':
$time = 60 * 60 * 24 * 365;
break;
}[/b]
[b] $expiration = $time * $this->user_settings['tools']['cache']['interval']['value'];[/b]
[b] if ( function_exists( 'is_multisite' ) && is_multisite() )
set_site_transient( $transient_name, $mostpopular, $expiration );
else
set_transient( $transient_name, $mostpopular, $expiration );[/b]
[b] $wpp_transients = get_site_option('wpp_transients');[/b]
[b] if ( !$wpp_transients ) {
$wpp_transients = array( $transient_name );
add_site_option('wpp_transients', $wpp_transients);
} else {
if ( !in_array($transient_name, $wpp_transients) ) {
$wpp_transients[] = $transient_name;
update_site_option('wpp_transients', $wpp_transients);
}
}
}
} else {
$mostpopular = $this->_query_posts( $instance );
}[/b]
[b] // No posts to show
if ( !is_array($mostpopular) || empty($mostpopular) ) {
return "<p>".__('Sorry. No data so far.', $this->plugin_slug)."</p>";
}[/b]
[b] // Allow WP themers / coders access to raw data
// so they can build their own output
if ( has_filter( 'wpp_custom_html' ) && !defined('WPP_ADMIN') ) {
return apply_filters( 'wpp_custom_html', $mostpopular, $instance );
}[/b]
[b] // HTML wrapper
if ($instance['markup']['custom_html']) {
$content .= "\n" . htmlspecialchars_decode($instance['markup']['wpp-start'], ENT_QUOTES) ."\n";
} else {
$content .= "\n" . "<ul class=\"wpp-list\">" . "\n";
}[/b]
[b] // Loop through posts
foreach($mostpopular as $p) {
$content .= $this->__render_popular_post( $p, $instance );
}[/b]
[b] // END HTML wrapper
if ($instance['markup']['custom_html']) {
$content .= "\n". htmlspecialchars_decode($instance['markup']['wpp-end'], ENT_QUOTES) ."\n";
} else {
$content .= "\n". "</ul>". "\n";
}[/b]
[b] return $content;[/b]
[b] } // end __get_popular_posts[/b]
[b] /**
* Returns the formatted post.
*
* @since 3.0.0
* @param object p
* @param array instance The current instance of the widget / shortcode parameters
* @return string
*/
private function __render_popular_post($p, $instance) {[/b]
[b] // WPML support, based on Serhat Evren's suggestion - see http://wordpress.org/support/topic/wpml-trick#post-5452607
if ( defined('ICL_LANGUAGE_CODE') && function_exists('icl_object_id') ) {
$current_id = icl_object_id( $p->id, get_post_type( $p->id ), true, ICL_LANGUAGE_CODE );
$permalink = get_permalink( $current_id );
} // Get original permalink
else {
$permalink = get_permalink($p->id);
}[/b]
[b] $title = $this->_get_title($p, $instance);
$title_sub = $this->_get_title_sub($p, $instance);[/b]
[b] $author = $this->_get_author($p, $instance);
$post_cat = $this->_get_post_cat($p, $instance);[/b]
[b] $thumb = $this->_get_thumb($p, $instance);
$excerpt = $this->_get_excerpt($p, $instance);[/b]
[b] $pageviews = $this->_get_pageviews($p, $instance);
$comments = $this->_get_comments($p, $instance);
$rating = $this->_get_rating($p, $instance);[/b]
[b] $_stats = join(' | ', $this->_get_stats($p, $instance));[/b]
[b] // PUTTING IT ALL TOGETHER
// build custom layout
if ($instance['markup']['custom_html']) {[/b]
[b] $data = array(
'title' => '<a href="'.$permalink.'" title="'. esc_attr($title) .'">'.$title_sub.'</a>',
'summary' => $excerpt,
'stats' => $_stats,
'img' => $thumb,
'id' => $p->id,
'url' => $permalink,
'text_title' => $title,
'category' => $post_cat,
'author' => '<a href="' . get_author_posts_url($p->uid) . '">' . $author . '</a>',
'views' => $pageviews,
'comments' => $comments
);[/b]
[b] $content = htmlspecialchars_decode($this->__format_content($instance['markup']['post-html'], $data, $instance['rating']), ENT_QUOTES) . "\n";[/b]
[b] }
// build regular layout
else {
$content =
'<li>'
. $thumb
. '<a href="' . $permalink . '" title="' . esc_attr($title) . '" class="wpp-post-title" target="' . $this->user_settings['tools']['link']['target'] . '">' . $title_sub . '</a> '
. $excerpt . ' <span class="post-stats">' . $_stats . '</span> '
. $rating
. "</li>\n";
}[/b]
[b] return apply_filters('wpp_post', $content, $p, $instance);[/b]
[b] } // end __render_popular_post[/b]
[b] /**
* Cache.
*
* @since 3.0.0
* @param string $func function name
* @param mixed $default
* @return mixed
*/
private function &__cache($func, $default = null) {[/b]
[b] static $cache;[/b]
[b] if ( !isset($cache) ) {
$cache = array();
}[/b]
[b] if ( !isset($cache[$func]) ) {
$cache[$func] = $default;
}[/b]
[b] return $cache[$func];[/b]
[b] } // end __cache[/b]
[b] /**
* Gets post title.
*
* @since 3.0.0
* @param object p
* @param array instance The current instance of the widget / shortcode parameters
* @return string
*/
protected function _get_title($p, $instance) {[/b]
[b] $cache = &$this->__cache(__FUNCTION__, array());[/b]
[b] if ( isset($cache[$p->id]) ) {
return $cache[$p->id];
}[/b]
[b] // WPML support, based on Serhat Evren's suggestion - see http://wordpress.org/support/topic/wpml-trick#post-5452607
if ( defined('ICL_LANGUAGE_CODE') && function_exists('icl_object_id') ) {
$current_id = icl_object_id( $p->id, get_post_type( $p->id ), true, ICL_LANGUAGE_CODE );
$title = get_the_title( $current_id );
} // Check for qTranslate
else if ( $this->qTrans && function_exists('qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage') ) {
$title = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage( $p->title );
} // Use ol' plain title
else {
$title = $p->title;
}[/b]
[b] // Strip HTML tags
$title = strip_tags($title);[/b]
[b] return $cache[$p->id] = apply_filters('the_title', $title, $p->id);[/b]
[b] } // end _get_title[/b]
[b] /**
* Gets substring of post title.
*
* @since 3.0.0
* @param object p
* @param array instance The current instance of the widget / shortcode parameters
* @return string
*/
protected function _get_title_sub($p, $instance) {[/b]
[b] $cache = &$this->__cache(__FUNCTION__, array());[/b]
[b] if ( isset($cache[$p->id]) ) {
return $cache[$p->id];
}[/b]
[b] // TITLE
$title_sub = $this->_get_title($p, $instance);[/b]
[b] // truncate title
if ($instance['shorten_title']['active']) {
// by words
if (isset($instance['shorten_title']['words']) && $instance['shorten_title']['words']) {[/b]
[b] $words = explode(" ", $title_sub, $instance['shorten_title']['length'] + 1);
if (count($words) > $instance['shorten_title']['length']) {
array_pop($words);
$title_sub = implode(" ", $words) . "...";
}[/b]
[b] }
elseif (strlen($title_sub) > $instance['shorten_title']['length']) {
$title_sub = mb_substr($title_sub, 0, $instance['shorten_title']['length'], $this->charset) . "...";
}
}[/b]
[b] return $cache[$p->id] = $title_sub;[/b]
[b] } // end _get_title_sub[/b]
[b] /**
* Gets post's excerpt.
*
* @since 3.0.0
* @param object p
* @param array instance The current instance of the widget / shortcode parameters
* @return string
*/
protected function _get_excerpt($p, $instance) {[/b]
[b] $cache = &$this->__cache(__FUNCTION__, array());[/b]
[b] if ( isset($cache[$p->id]) ) {
return $cache[$p->id];
}[/b]
[b] $excerpt = '';[/b]
[b] // EXCERPT
if ($instance['post-excerpt']['active']) {[/b]
[b] $excerpt = trim($this->_get_summary($p->id, $instance));[/b]
[b] if (!empty($excerpt) && !$instance['markup']['custom_html']) {
$excerpt = '<span class="wpp-excerpt">' . $excerpt . '</span>';
}[/b]
[b] }[/b]
[b] return $cache[$p->id] = $excerpt;[/b]
[b] } // end _get_excerpt[/b]
[b] /**
* Gets post's thumbnail.
*
* @since 3.0.0
* @param object p
* @param array instance The current instance of the widget / shortcode parameters
* @return string
*/
protected function _get_thumb($p, $instance) {[/b]
[b] if ( !$instance['thumbnail']['active'] || !$this->thumbnailing ) {
return '';
}[/b]
[b] $tbWidth = $instance['thumbnail']['width'];
$tbHeight = $instance['thumbnail']['height'];
$permalink = get_permalink($p->id);
$title = $this->_get_title($p, $instance);[/b]
[b] $thumb = '<a href="' . $permalink . '" title="' . esc_attr($title) . '" target="' . $this->user_settings['tools']['link']['target'] . '">';[/b]
[b] // get image from custom field
if ($this->user_settings['tools']['thumbnail']['source'] == "custom_field") {
$path = get_post_meta($p->id, $this->user_settings['tools']['thumbnail']['field'], true);[/b]
[b] if ($path != '') {
// user has requested to resize cf image
if ( $this->user_settings['tools']['thumbnail']['resize'] ) {
$thumb .= $this->__get_img($p, null, $path, array($tbWidth, $tbHeight), $this->user_settings['tools']['thumbnail']['source'], $title);
}
// use original size
else {
$thumb .= $this->_render_image($path, array($tbWidth, $tbHeight), 'wpp-thumbnail wpp_cf', $title);
}
}
else {
$thumb .= $this->_render_image($this->default_thumbnail, array($tbWidth, $tbHeight), 'wpp-thumbnail wpp_cf_def', $title);
}
}
// get image from post / Featured Image
else {
$thumb .= $this->__get_img($p, $p->id, null, array($tbWidth, $tbHeight), $this->user_settings['tools']['thumbnail']['source'], $title);
}[/b]
[b] $thumb .= "</a>";[/b]
[b] return $cache[$p->id] = $thumb;[/b]
[b] } // end _get_thumb[/b]
[b] /**
* Gets post's views.
*
* @since 3.0.0
* @param object p
* @param array instance The current instance of the widget / shortcode parameters
* @return int|float
*/
protected function _get_pageviews($p, $instance) {[/b]
[b] $cache = &$this->__cache(__FUNCTION__ . md5(json_encode($instance)), array());[/b]
[b] if ( isset($cache[$p->id]) ) {
return $cache[$p->id];
}[/b]
[b] $pageviews = 0;[/b]
[b] if (
$instance['order_by'] == "views"
|| $instance['order_by'] == "avg"
|| $instance['stats_tag']['views']
) {
$pageviews = ($instance['order_by'] == "views" || $instance['order_by'] == "comments")
? $p->pageviews
: $p->avg_views;
}[/b]
[b] return $cache[$p->id] = $pageviews;[/b]
[b] } // end _get_pageviews[/b]
[b] /**
* Gets post's comment count.
*
* @since 3.0.0
* @param object p
* @param array instance The current instance of the widget / shortcode parameters
* @return int
*/
protected function _get_comments($p, $instance) {[/b]
[b] $cache = &$this->__cache(__FUNCTION__ . md5(json_encode($instance)), array());[/b]
[b] if ( isset($cache[$p->id]) ) {
return $cache[$p->id];
}[/b]
[b] $comments = ($instance['order_by'] == "comments" || $instance['stats_tag']['comment_count'])
? $p->comment_count
: 0;[/b]
[b] return $cache[$p->id] = $comments;[/b]
[b] } // end _get_comments[/b]
[b] /**
* Gets post's rating.
*
* @since 3.0.0
* @param object p
* @param array instance The current instance of the widget / shortcode parameters
* @return string
*/
protected function _get_rating($p, $instance) {[/b]
[b] $cache = &$this->__cache(__FUNCTION__, array());[/b]
[b] if ( isset($cache[$p->id]) ) {
return $cache[$p->id];
}[/b]
[b] $rating = '';[/b]
[b] // RATING
if (function_exists('the_ratings') && $instance['rating']) {
$rating = '<span class="wpp-rating">' . the_ratings('span', $p->id, false) . '</span>';
}[/b]
[b] return $cache[$p->id] = $rating;
} // end _get_rating[/b]
[b] /**
* Gets post's author.
*
* @since 3.0.0
* @param object p
* @param array instance The current instance of the widget / shortcode parameters
* @return string
*/
protected function _get_author($p, $instance) {[/b]
[b] $cache = &$this->__cache(__FUNCTION__, array());[/b]
[b] if ( isset($cache[$p->id]) ) {
return $cache[$p->id];
}[/b]
[b] $author = ($instance['stats_tag']['author'])
? get_the_author_meta('display_name', $p->uid)
: "";[/b]
[b] return $cache[$p->id] = $author;[/b]
[b] } // end _get_author[/b]
[b] /**
* Gets post's date.
*
* @since 3.0.0
* @param object p
* @param array instance The current instance of the widget / shortcode parameters
* @return string
*/
protected function _get_date($p, $instance) {[/b]
[b] $cache = &$this->__cache(__FUNCTION__, array());[/b]
[b] if ( isset($cache[$p->id]) ) {
return $cache[$p->id];
}[/b]
[b] $date = date_i18n($instance['stats_tag']['date']['format'], strtotime($p->date));
return $cache[$p->id] = $date;[/b]
[b] } // end _get_date[/b]
[b] /**
* Gets post's category.
*
* @since 3.0.0
* @param object p
* @param array instance The current instance of the widget / shortcode parameters
* @return string
*/
protected function _get_post_cat($p, $instance) {[/b]
[b] $cache = &$this->__cache(__FUNCTION__, array());[/b]
[b] if ( isset($cache[$p->id]) ) {
return $cache[$p->id];
}[/b]
[b] $post_cat = '';[/b]
[b] if ($instance['stats_tag']['category']) {[/b]
[b] $post_cat = get_the_category($p->id);
$post_cat = (isset($post_cat[0]))
? '<a href="' . get_category_link($post_cat[0]->term_id) . '">' . $post_cat[0]->cat_name . '</a>'
: '';[/b]
[b] }[/b]
[b] return $cache[$p->id] = $post_cat;[/b]
[b] } // end _get_post_cat[/b]
[b] /**
* Gets statistics data.
*
* @since 3.0.0
* @param object p
* @param array instance The current instance of the widget / shortcode parameters
* @return array
*/
protected function _get_stats($p, $instance) {[/b]
[b] $cache = &$this->__cache(__FUNCTION__ . md5(json_encode($instance)), array());[/b]
[b] if ( isset($cache[$p->id]) ) {
return $cache[$p->id];
}[/b]
[b] $stats = array();[/b]
[b] // STATS
// comments
if ($instance['stats_tag']['comment_count']) {
$comments = $this->_get_comments($p, $instance);[/b]
[b] $comments_text = sprintf(
_n('1 comment', '%s comments', $comments, $this->plugin_slug),
number_format_i18n($comments));[/b]
[b] $stats[] = '<span class="wpp-comments">' . $comments_text . '</span>';
}[/b]
[b] // views
if ($instance['stats_tag']['views']) {
$pageviews = $this->_get_pageviews($p, $instance);[/b]
[b] if ($instance['order_by'] == 'avg') {
$views_text = sprintf(
_n('1 view per day', '%s views per day', intval($pageviews), $this->plugin_slug),
number_format_i18n($pageviews, 2)
);
}
else {
$views_text = sprintf(
_n('1 view', '%s views', intval($pageviews), $this->plugin_slug),
number_format_i18n($pageviews)
);
}[/b]
[b] $stats[] = '<span class="wpp-views">' . $views_text . "</span>";
}[/b]
[b] // author
if ($instance['stats_tag']['author']) {
$author = $this->_get_author($p, $instance);
$display_name = '<a href="' . get_author_posts_url($p->uid) . '">' . $author . '</a>';
$stats[] = '<span class="wpp-author">' . sprintf(__('by %s', $this->plugin_slug), $display_name).'</span>';
}[/b]
[b] // date
if ($instance['stats_tag']['date']['active']) {
$date = $this->_get_date($p, $instance);
$stats[] = '<span class="wpp-date">' . sprintf(__('posted on %s', $this->plugin_slug), $date) . '</span>';
}[/b]
[b] // category
if ($instance['stats_tag']['category']) {
$post_cat = $this->_get_post_cat($p, $instance);[/b]
[b] if ($post_cat != '') {
$stats[] = '<span class="wpp-category">' . sprintf(__('under %s', $this->plugin_slug), $post_cat) . '</span>';
}
}[/b]
[b] return $cache[$p->id] = $stats;[/b]
[b] } // end _get_stats[/b]
[b] /**
* Retrieves / creates the post thumbnail.
*
* @since 2.3.3
* @param int id Post ID
* @param string url Image URL
* @param array dim Thumbnail width & height
* @param string source Image source
* @return string
*/
private function __get_img($p, $id = null, $url = null, $dim = array(80, 80), $source = "featured", $title) {[/b]
[b] if ( (!$id || empty($id) || !$this->__is_numeric($id)) && (!$url || empty($url)) ) {
return $this->_render_image($this->default_thumbnail, $dim, 'wpp-thumbnail wpp_def_noID', $title);
}[/b]
[b] // Get image by post ID (parent)
if ( $id ) {
$file_paths = $this->__get_image_file_paths($id, $source);
$file_path = $file_paths['file_path'];
$thumbnail = isset( $file_paths['thumbnail'] )
? $file_paths['thumbnail']
: '';[/b]
[b] // No images found, return default thumbnail
if ($file_path == '') {
return $this->_render_image($this->default_thumbnail, $dim, 'wpp-thumbnail wpp_def_noPath wpp_' . $source, $title);
}
}
// Get image from URL
else {
// sanitize URL, just in case
$image_url = esc_url( $url );
// remove querystring
preg_match('/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $image_url, $matches);
$image_url = $matches[0];[/b]
[b] $attachment_id = $this->__get_attachment_id($image_url);[/b]
[b] // Image is hosted locally
if ( $attachment_id ) {
$thumbnail = $image_url;
$file_path = get_attached_file($attachment_id);
}
// Image is hosted outside Wordpress
else {
$external_image = $this->__fetch_external_image($p->id, $image_url);[/b]
[b] if ( !$external_image ) {
return $this->_render_image($this->default_thumbnail, $dim, 'wpp-thumbnail wpp_def_noPath wpp_no_external', $title);
}[/b]
[b] $thumbnail = $external_image['thumbnail'];
$file_path = $external_image['file_path'];
}
}[/b]
[b] $file_info = pathinfo($file_path);
$cropped_thumb = $file_info['dirname'] . '/' . $file_info['filename'] . '-' . $dim[0] . 'x' . $dim[1] . '.' . $file_info['extension'];[/b]
[b] // there is a thumbnail already
if (file_exists($cropped_thumb)) {
$new_img = str_replace(basename($thumbnail), basename($cropped_thumb), $thumbnail);
return $this->_render_image($new_img, $dim, 'wpp-thumbnail wpp_cached_thumb wpp_' . $source, $title);
}[/b]
[b] return $this->__image_resize($file_path, $thumbnail, $dim, $source);[/b]
[b] } // end __get_img[/b]
[b] /**
* Resizes image.
*
* @since 3.0.0
* @param string path Image path
* @param string url Original image's URL
* @param array dimension Image's width and height
* @return string
*/
private function __image_resize($path, $thumbnail, $dimension, $source) {[/b]
[b] $image = wp_get_image_editor($path);[/b]
[b] // valid image, create thumbnail
if (!is_wp_error($image)) {[/b]
[b] $image->resize($dimension[0], $dimension[1], true);
$new_img = $image->save();[/b]
[b] if (is_wp_error($new_img)) {
return $this->_render_image($this->default_thumbnail, $dimension, 'wpp-thumbnail wpp_imgeditor_error wpp_' . $source, '', $image->get_error_message());
}[/b]
[b] $new_img = str_replace(basename($thumbnail), $new_img['file'], $thumbnail);[/b]
[b] return $this->_render_image($new_img, $dimension, 'wpp-thumbnail wpp_imgeditor_thumb wpp_' . $source, '');
}[/b]
[b] // ELSE
// image file path is invalid
return $this->_render_image($this->default_thumbnail, $dimension, 'wpp-thumbnail wpp_imgeditor_error wpp_' . $source, '', $image->get_error_message());[/b]
[b] } // end __image_resize[/b]
[b] /**
* Get image absolute path / URL.
*
* @since 3.0.0
* @param int id Post ID
* @param string source Image source
* @return array
*/
private function __get_image_file_paths($id, $source) {[/b]
[b] $file_path = '';
$thumbnail = array();[/b]
[b] // get thumbnail path from the Featured Image
if ($source == "featured") {[/b]
[b] // thumb attachment ID
$thumbnail_id = get_post_thumbnail_id($id);[/b]
[b] if ($thumbnail_id) {[/b]
[b] // full size image
$thumbnail = wp_get_attachment_image_src($thumbnail_id, 'full');
$thumbnail = $thumbnail[0];
// image path
$file_path = get_attached_file($thumbnail_id);[/b]
[b] }[/b]
[b] }
// get thumbnail path from post content
elseif ($source == "first_image") {[/b]
[b] /** @var wpdb $wpdb */
global $wpdb;[/b]
[b] $content = $wpdb->get_results("SELECT post_content FROM {$wpdb->posts} WHERE ID = " . $id, ARRAY_A);
$count = substr_count($content[0]['post_content'], '<img');[/b]
[b] // images have been found
// TODO: try to merge these conditions into one IF.
if ($count > 0) {[/b]
[b] preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $content[0]['post_content'], $content_images);[/b]
[b] if (isset($content_images[1][0])) {
$attachment_id = $this->__get_attachment_id($content_images[1][0]);[/b]
[b] // image from Media Library
if ($attachment_id) {
$thumbnail = $content_images[1][0];
$file_path = get_attached_file($attachment_id);
} // external image?
else {
$external_image = $this->__fetch_external_image($id, $content_images[1][0]);
if ( $external_image ) {
return $external_image;
}
}
}
}[/b]
[b] }[/b]
[b] return array(
'file_path' => $file_path,
'thumbnail' => $thumbnail
);[/b]
[b] } // end __get_image_file_paths[/b]
[b] /**
* Render image tag.
*
* @since 3.0.0
* @param string src Image URL
* @param array dimension Image's width and height
* @param string class CSS class
* @param string title Image's title/alt attribute
* @param string error Error, if the image could not be created
* @return string
*/
protected function _render_image($src, $dimension, $class, $title = "", $error = null) {[/b]
[b] $msg = '';[/b]
[b] if ($error) {
$msg = '<!-- ' . $error . ' --> ';
}[/b]
[b] return $msg .
'<img src="' . $src . '" title="' . esc_attr($title) . '" alt="' . esc_attr($title) . '" width="' . $dimension[0] . '" height="' . $dimension[1] . '" class="' . $class . '" />';[/b]
[b] } // _render_image[/b]
[b] /**
* Get the Attachment ID for a given image URL.
*
* @since 3.0.0
* @author Frankie Jarrett
* @link http://frankiejarrett.com/get-an-attachment-id-by-url-in-wordpress/
* @param string url
* @return bool|int
*/
private function __get_attachment_id($url) {[/b]
[b] // Split the $url into two parts with the wp-content directory as the separator.
$parse_url = explode( parse_url( WP_CONTENT_URL, PHP_URL_PATH ), $url );[/b]
[b] // Get the host of the current site and the host of the $url, ignoring www.
$this_host = str_ireplace( 'www.', '', parse_url( home_url(), PHP_URL_HOST ) );
$file_host = str_ireplace( 'www.', '', parse_url( $url, PHP_URL_HOST ) );[/b]
[b] // Return nothing if there aren't any $url parts or if the current host and $url host do not match.
if ( ! isset( $parse_url[1] ) || empty( $parse_url[1] ) || ( $this_host != $file_host ) ) {
return false;
}[/b]
[b] // Now we're going to quickly search the DB for any attachment GUID with a partial path match.
// Example: /uploads/2013/05/test-image.jpg
global $wpdb;[/b]
[b] if ( !$attachment = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->prefix}posts WHERE guid RLIKE %s;", $parse_url[1] ) ) ) {
// Maybe it's a resized image, so try to get the full one
$parse_url[1] = preg_replace( '/-[0-9]{1,4}x[0-9]{1,4}\.(jpg|jpeg|png|gif|bmp)$/i', '.$1', $parse_url[1] );
$attachment = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->prefix}posts WHERE guid RLIKE %s;", $parse_url[1] ) );
}[/b]
[b] // Returns null if no attachment is found.
return $attachment[0];[/b]
[b] } // __get_attachment_id[/b]
[b] /**
* Fetchs external images.
*
* @since 2.3.3
* @param string url
* @return bool|int
*/
private function __fetch_external_image($id, $url){[/b]
[b] $image = array();[/b]
[b] $uploads = wp_upload_dir();
$image['thumbnail'] = trailingslashit( $uploads['baseurl'] ) . "{$id}_". sanitize_file_name( rawurldecode(wp_basename( $url )) );
$image['file_path'] = trailingslashit( $uploads['basedir'] ) . "{$id}_". sanitize_file_name( rawurldecode(wp_basename( $url )) );[/b]
[b] // if the file exists already, return URL and path
if ( file_exists($image['file_path']) )
return $image;[/b]
[b] $accepted_status_codes = array( 200, 301, 302 );
$response = wp_remote_head( $url, array( 'timeout' => 5, 'sslverify' => false ) );[/b]
[b] if ( !is_wp_error($response) && in_array(wp_remote_retrieve_response_code($response), $accepted_status_codes) ) {
$image_data = getimagesize( $url );[/b]
[b] if ( is_array($image_data) && !empty($image_data) ) {
require_once( ABSPATH . 'wp-admin/includes/file.php' );[/b]
[b] $url = str_replace( 'https://', 'http://', $url );
$tmp = download_url( $url );[/b]
[b] // move file to Uploads
if ( !is_wp_error( $tmp ) && rename($tmp, $image['file_path']) ) {
// borrowed from WP - set correct file permissions
$stat = stat( dirname( $image['file_path'] ));
$perms = $stat['mode'] & 0000666;
@chmod( $image['file_path'], $perms );[/b]
[b] return $image;
}
}
}[/b]
[b] return false;[/b]
[b] } // end __fetch_external_image[/b]
[b] /**
* Builds post's excerpt
*
* @since 1.4.6
* @global object wpdb
* @param int post ID
* @param array widget instance
* @return string
*/
protected function _get_summary($id, $instance){[/b]
[b] if ( !$this->__is_numeric($id) )
return false;[/b]
[b] global $wpdb;[/b]
[b] $excerpt = "";[/b]
[b] // WPML support, get excerpt for current language
if ( defined('ICL_LANGUAGE_CODE') && function_exists('icl_object_id') ) {
$current_id = icl_object_id( $id, get_post_type( $id ), true, ICL_LANGUAGE_CODE );[/b]
[b] $the_post = get_post( $current_id );
$excerpt = ( empty($the_post->post_excerpt) )
? $the_post->post_content
: $the_post->post_excerpt;
} // Use ol' plain excerpt
else {
$the_post = get_post( $id );
$excerpt = ( empty($the_post->post_excerpt) )
? $the_post->post_content
: $the_post->post_excerpt;[/b]
[b] // RRR added call to the_content filters, allows qTranslate to hook in.
if ( $this->qTrans )
$excerpt = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage( $excerpt );
}[/b]
[b] // remove caption tags
$excerpt = preg_replace( "/\[caption.*\[\/caption\]/", "", $excerpt );[/b]
[b] // remove Flash objects
$excerpt = preg_replace( "/<object[0-9 a-z_?*=\":\-\/\.#\,\\n\\r\\t]+/smi", "", $excerpt );[/b]
[b] // remove Iframes
$excerpt = preg_replace( "/<iframe.*?\/iframe>/i", "", $excerpt);[/b]
[b] // remove WP shortcodes
$excerpt = strip_shortcodes( $excerpt );[/b]
[b] // remove HTML tags if requested
if ( $instance['post-excerpt']['keep_format'] ) {
$excerpt = strip_tags($excerpt, '<a><b><i><em><strong>');
} else {
$excerpt = strip_tags($excerpt);
// remove URLs, too
$excerpt = preg_replace( '_^(??:https?|ftp)://)(?:\S+(?::\S*)?@)?(??!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(??:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)(?:\.(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)*(?:\.(?:[a-z\x{00a1}-\x{ffff}]{2,})))(?::\d{2,5})?(?:/[^\s]*)?$_iuS', '', $excerpt );
}[/b]
[b] // Fix RSS CDATA tags
$excerpt = str_replace( ']]>', ']]>', $excerpt );[/b]
[b] // do we still have something to display?
if ( !empty($excerpt) ) {[/b]
[b] // truncate excerpt
if ( isset($instance['post-excerpt']['words']) && $instance['post-excerpt']['words'] ) { // by words[/b]
[b] $words = explode(" ", $excerpt, $instance['post-excerpt']['length'] + 1);[/b]
[b] if ( count($words) > $instance['post-excerpt']['length'] ) {
array_pop($words);
$excerpt = implode(" ", $words) . "...";
}[/b]
[b] } else { // by characters[/b]
[b] if ( strlen($excerpt) > $instance['post-excerpt']['length'] ) {
$excerpt = mb_substr( $excerpt, 0, $instance['post-excerpt']['length'] ) . "...";
}[/b]
[b] }[/b]
[b] }[/b]
[b] // Balance tags, if needed
if ( $instance['post-excerpt']['keep_format'] ) {
$excerpt = force_balance_tags($excerpt);
}[/b]
[b] return $excerpt;[/b]
[b] } // _get_summary[/b]
[b] /**
* WPP shortcode handler
* Since 2.0.0
*/
public function shortcode($atts = null, $content = null) {
/**
* @var String $header
* @var Int $limit
* @var String $range
* @var Bool $freshness
* @var String $order_by
* @var String $post_type
* @var String $pid
* @var String $cat
* @var String $author
* @var Int $title_length
* @var Int $title_by_words
* @var Int $excerpt_length
* @var Int $excerpt_format
* @var Int $excerpt_by_words
* @var Int $thumbnail_width
* @var Int $thumbnail_height
* @var Bool $rating
* @var Bool $stats_comments
* @var Bool $stats_views
* @var Bool $stats_author
* @var Bool $stats_date
* @var String $stats_date_format
* @var Bool $stats_category
* @var String $wpp_start
* @var String $wpp_end
* @var String $header_start
* @var String $header_end
* @var String $post_html
*/
extract( shortcode_atts( array(
'header' => '',
'limit' => 10,
'range' => 'daily',
'freshness' => false,
'order_by' => 'views',
'post_type' => 'post,page',
'pid' => '',
'cat' => '',
'author' => '',
'title_length' => 0,
'title_by_words' => 0,
'excerpt_length' => 0,
'excerpt_format' => 0,
'excerpt_by_words' => 0,
'thumbnail_width' => 0,
'thumbnail_height' => 0,
'rating' => false,
'stats_comments' => false,
'stats_views' => true,
'stats_author' => false,
'stats_date' => false,
'stats_date_format' => 'F j, Y',
'stats_category' => false,
'wpp_start' => '<ul class="wpp-list">',
'wpp_end' => '</ul>',
'header_start' => '<h2>',
'header_end' => '</h2>',
'post_html' => ''
),$atts));[/b]
[b] // possible values for "Time Range" and "Order by"
$range_values = array("yesterday", "daily", "weekly", "monthly", "all");
$order_by_values = array("comments", "views", "avg");[/b]
[b] $shortcode_ops = array(
'title' => strip_tags($header),
'limit' => (!empty($limit) && $this->__is_numeric($limit) && $limit > 0) ? $limit : 10,
'range' => (in_array($range, $range_values)) ? $range : 'daily',
'freshness' => empty($freshness) ? false : $freshness,
'order_by' => (in_array($order_by, $order_by_values)) ? $order_by : 'views',
'post_type' => empty($post_type) ? 'post,page' : $post_type,
'pid' => preg_replace('|[^0-9,]|', '', $pid),
'cat' => preg_replace('|[^0-9,-]|', '', $cat),
'author' => preg_replace('|[^0-9,]|', '', $author),
'shorten_title' => array(
'active' => (!empty($title_length) && $this->__is_numeric($title_length) && $title_length > 0),
'length' => (!empty($title_length) && $this->__is_numeric($title_length)) ? $title_length : 0,
'words' => (!empty($title_by_words) && $this->__is_numeric($title_by_words) && $title_by_words > 0),
),
'post-excerpt' => array(
'active' => (!empty($excerpt_length) && $this->__is_numeric($excerpt_length) && ($excerpt_length > 0)),
'length' => (!empty($excerpt_length) && $this->__is_numeric($excerpt_length)) ? $excerpt_length : 0,
'keep_format' => (!empty($excerpt_format) && $this->__is_numeric($excerpt_format) && ($excerpt_format > 0)),
'words' => (!empty($excerpt_by_words) && $this->__is_numeric($excerpt_by_words) && $excerpt_by_words > 0),
),
'thumbnail' => array(
'active' => (!empty($thumbnail_width) && $this->__is_numeric($thumbnail_width) && $thumbnail_width > 0),
'width' => (!empty($thumbnail_width) && $this->__is_numeric($thumbnail_width) && $thumbnail_width > 0) ? $thumbnail_width : 0,
'height' => (!empty($thumbnail_height) && $this->__is_numeric($thumbnail_height) && $thumbnail_height > 0) ? $thumbnail_height : 0,
),
'rating' => empty($rating) || $rating = "false" ? false : true,
'stats_tag' => array(
'comment_count' => empty($stats_comments) ? false : $stats_comments,
'views' => empty($stats_views) ? false : $stats_views,
'author' => empty($stats_author) ? false : $stats_author,
'date' => array(
'active' => empty($stats_date) ? false : $stats_date,
'format' => empty($stats_date_format) ? 'F j, Y' : $stats_date_format
),
'category' => empty($stats_category) ? false : $stats_category,
),
'markup' => array(
'custom_html' => true,
'wpp-start' => empty($wpp_start) ? '<ul class="wpp-list">' : $wpp_start,
'wpp-end' => empty($wpp_end) ? '</ul>' : $wpp_end,
'title-start' => empty($header_start) ? '' : $header_start,
'title-end' => empty($header_end) ? '' : $header_end,
'post-html' => empty($post_html) ? '<li>{thumb} {title} {stats}</li>' : $post_html
)
);[/b]
[b] $shortcode_content = "\n". "<!-- Wordpress Popular Posts Plugin v". $this->version ." [SC] [".$shortcode_ops['range']."] [".$shortcode_ops['order_by']."] [custom] -->"."\n";[/b]
[b] // is there a title defined by user?
if (!empty($header) && !empty($header_start) && !empty($header_end)) {
$shortcode_content .= htmlspecialchars_decode($header_start, ENT_QUOTES) . apply_filters('widget_title', $header) . htmlspecialchars_decode($header_end, ENT_QUOTES);
}[/b]
[b] // print popular posts list
$shortcode_content .= $this->__get_popular_posts($shortcode_ops);
$shortcode_content .= "\n". "<!-- End Wordpress Popular Posts Plugin v". $this->version ." -->"."\n";[/b]
[b] return $shortcode_content;[/b]
[b] } // end shortcode[/b]
[b] /**
* Parses content tags
*
* @since 1.4.6
* @param string HTML string with content tags
* @param array Post data
* @param bool Used to display post rating (if functionality is available)
* @return string
*/
private function __format_content($string, $data = array(), $rating) {[/b]
[b] if (empty($string) || (empty($data) || !is_array($data)))
return false;[/b]
[b] $string = htmlentities( $string );[/b]
[b] $params = array();
$pattern = '/\{(excerpt|summary|stats|title|image|thumb|rating|score|url|text_title|author|category|views|comments)\}/i';
preg_match_all($pattern, $string, $matches);[/b]
[b] array_map('strtolower', $matches[0]);[/b]
[b] if ( in_array("{title}", $matches[0]) ) {
$string = str_replace( "{title}", $data['title'], $string );
}[/b]
[b] if ( in_array("{stats}", $matches[0]) ) {
$string = str_replace( "{stats}", $data['stats'], $string );
}[/b]
[b] if ( in_array("{excerpt}", $matches[0]) ) {
$string = str_replace( "{excerpt}", htmlentities($data['summary'], ENT_QUOTES), $string );
}[/b]
[b] if ( in_array("{summary}", $matches[0]) ) {
$string = str_replace( "{summary}", htmlentities($data['summary'], ENT_QUOTES), $string );
}[/b]
[b] if ( in_array("{image}", $matches[0]) ) {
$string = str_replace( "{image}", $data['img'], $string );
}[/b]
[b] if ( in_array("{thumb}", $matches[0]) ) {
$string = str_replace( "{thumb}", $data['img'], $string );
}[/b]
[b] // WP-PostRatings check
if ( $rating ) {
if ( function_exists('the_ratings_results') && in_array("{rating}", $matches[0]) ) {
$string = str_replace( "{rating}", the_ratings_results($data['id']), $string );
}[/b]
[b] if ( function_exists('expand_ratings_template') && in_array("{score}", $matches[0]) ) {
$string = str_replace( "{score}", expand_ratings_template('%RATINGS_SCORE%', $data['id']), $string);
// removing the redundant plus sign
$string = str_replace('+', '', $string);
}
}[/b]
[b] if ( in_array("{url}", $matches[0]) ) {
$string = str_replace( "{url}", $data['url'], $string );
}[/b]
[b] if ( in_array("{text_title}", $matches[0]) ) {
$string = str_replace( "{text_title}", $data['text_title'], $string );
}[/b]
[b] if ( in_array("{author}", $matches[0]) ) {
$string = str_replace( "{author}", $data['author'], $string );
}[/b]
[b] if ( in_array("{category}", $matches[0]) ) {
$string = str_replace( "{category}", $data['category'], $string );
}[/b]
[b] if ( in_array("{views}", $matches[0]) ) {
$string = str_replace( "{views}", $data['views'], $string );
}[/b]
[b] if ( in_array("{comments}", $matches[0]) ) {
$string = str_replace( "{comments}", $data['comments'], $string );
}[/b]
[b] return html_entity_decode( $string, ENT_QUOTES, $this->charset );[/b]
[b] } // end __format_content[/b]
[b] /**
* Returns HTML list via AJAX
*
* @since 2.3.3
* @return string
*/
public function get_popular( ) {[/b]
[b] if ( $this->__is_numeric($_GET['id']) && ($_GET['id'] != '') ) {
$id = $_GET['id'];
} else {
die("Invalid ID");
}[/b]
[b] $widget_instances = $this->get_settings();[/b]
[b] if ( isset($widget_instances[$id]) ) {[/b]
[b] echo $this->__get_popular_posts( $widget_instances[$id] );[/b]
[b] } else {[/b]
[b] echo "Invalid Widget ID";
}[/b]
[b] exit();[/b]
[b] } // end get_popular[/b]
[b] /*--------------------------------------------------*/
/* Helper functions
/*--------------------------------------------------*/[/b]
[b] /**
* Checks for valid number
*
* @since 2.1.6
* @param int number
* @return bool
*/
private function __is_numeric($number){
return !empty($number) && is_numeric($number) && (intval($number) == floatval($number));
}[/b]
[b] /**
* Returns server datetime
*
* @since 2.1.6
* @return string
*/
private function __curdate() {
return gmdate( 'Y-m-d', ( time() + ( get_site_option( 'gmt_offset' ) * 3600 ) ));
} // end __curdate[/b]
[b] /**
* Returns mysql datetime
*
* @since 2.1.6
* @return string
*/
private function __now() {
return current_time('mysql');
} // end __now[/b]
[b] /**
* Returns time
*
* @since 2.3.0
* @return string
*/
private function __microtime_float() {[/b]
[b] list( $msec, $sec ) = explode( ' ', microtime() );[/b]
[b] $microtime = (float) $msec + (float) $sec;
return $microtime;[/b]
[b] } // end __microtime_float[/b]
[b] /**
* Compares values
*
* @since 2.3.4
* @param int a
* @param int b
* @return int
*/
private function __sorter($a, $ {[/b]
[b] if ($a > 0 && $b > 0) {
return $a - $b;
} else {
return $b - $a;
}[/b]
[b] } // end __sorter[/b]
[b] /**
* Merges two associative arrays recursively
*
* @since 2.3.4
* @link http://www.php.net/manual/en/function.array-merge-recursive.php#92195
* @param array array1
* @param array array2
* @return array
*/
private function __merge_array_r( array &$array1, array &$array2 ) {[/b]
[b] $merged = $array1;[/b]
[b] foreach ( $array2 as $key => &$value ) {[/b]
[b] if ( is_array( $value ) && isset ( $merged[$key] ) && is_array( $merged[$key] ) ) {
$merged[$key] = $this->__merge_array_r( $merged[$key], $value );
} else {
$merged[$key] = $value;
}
}[/b]
[b] return $merged;[/b]
[b] } // end __merge_array_r[/b]
[b] /**
* Checks if visitor is human or bot.
*
* @since 3.0.0
* @return bool FALSE if human, TRUE if bot
*/
private function __is_bot() {[/b]
[b] if ( !isset($_SERVER['HTTP_USER_AGENT']) || empty($_SERVER['HTTP_USER_AGENT']) )
return true; // No UA? Bot (probably)[/b]
[b] $user_agent = strtolower($_SERVER['HTTP_USER_AGENT']);[/b]
[b] foreach ( $this->botlist as $bot ) {
if ( false !== strpos($user_agent, $bot) ) {
return true; // Bot
}
}[/b]
[b] return false; // Human, I guess...[/b]
[b] } // end __is_bot[/b]
[b] /**
* Debug function.
*
* @since 3.0.0
* @param mixed $v variable to display with var_dump()
* @param mixed $v,... unlimited optional number of variables to display with var_dump()
*/
private function __debug($v) {[/b]
[b] if ( !defined('WPP_DEBUG') || !WPP_DEBUG )
return;[/b]
[b] foreach (func_get_args() as $arg) {[/b]
[b] print "<pre>";
var_dump($arg);
print "</pre>";[/b]
[b] }[/b]
[b] } // end __debug[/b]
[b]} // end class[/b]
[b]}[/b]
[b]/**
* Wordpress Popular Posts template tags for use in themes.
*/[/b]
[b]/**
* Template tag - gets views count.
*
* @since 2.0.3
* @global object wpdb
* @param int id
* @param string range
* @param bool number_format
* @return string
*/
function wpp_get_views($id = NULL, $range = NULL, $number_format = true) {[/b]
[b]// have we got an id?
if ( empty($id) || is_null($id) || !is_numeric($id) ) {
return "-1";
} else {
global $wpdb;[/b]
[b] $table_name = $wpdb->prefix . "popularposts";[/b]
[b] if ( !$range || 'all' == $range ) {
$query = "SELECT pageviews FROM {$table_name}data WHERE postid = '{$id}'";
} else {
$interval = "";[/b]
[b] switch( $range ){
case "yesterday":
$interval = "1 DAY";
break;[/b]
[b] case "daily":
$interval = "1 DAY";
break;[/b]
[b] case "weekly":
$interval = "1 WEEK";
break;[/b]
[b] case "monthly":
$interval = "1 MONTH";
break;[/b]
[b] default:
$interval = "1 DAY";
break;
}[/b]
[b] $now = current_time('mysql');[/b]
[b] $query = "SELECT SUM(pageviews) FROM {$table_name}summary WHERE postid = '{$id}' AND last_viewed > DATE_SUB('{$now}', INTERVAL {$interval}) LIMIT 1;";
}[/b]
[b] $result = $wpdb->get_var($query);[/b]
[b] if ( !$result ) {
return "0";
}[/b]
[b] return ($number_format) ? number_format_i18n( intval($result) ) : $result;
}[/b]
[b]}[/b]
[b]/**
* Template tag - gets popular posts.
*
* @since 2.0.3
* @param mixed args
*/
function wpp_get_mostpopular($args = NULL) {[/b]
[b]$shortcode = '[wpp';[/b]
[b]if ( is_null( $args ) ) {
$shortcode .= ']';
} else {
if( is_array( $args ) ){
$atts = '';
foreach( $args as $key => $arg ){
$atts .= ' ' . $key . '="' . htmlspecialchars($arg, ENT_QUOTES) . '"';
}
} else {
$atts = trim( str_replace( "&", " ", $args ) );
}[/b]
[b] $shortcode .= ' ' . $atts . ']';
}[/b]
[b]echo do_shortcode( $shortcode );[/b]
[b]}[/b]
[b]/**
* Template tag - gets popular posts. Deprecated in 2.0.3, use wpp_get_mostpopular instead.
*
* @since 1.0
* @param mixed args
*/
function get_mostpopular($args = NULL) {
return wpp_get_mostpopular($args);
}[/b]
[b]

چیکارش کنم؟

لینک به ارسال

نه نیازی به کد پلاگین نیست..شما از پیشخوان وردپرس به بخش تنطیمات افزونه برید اونجا فیلد

view template را پاک کنید..

لینک به ارسال

دوست عزیز ، من ازتون میپرسم wp post views شما میگین بله!

اگه اون بود میتونستید از آدرس زیر عوضش کنید:

پنل وردپرستون » تنظیمات » post views » یه گزینه داره که میتونید متن رو تغییر بدید.

امّا این افزونه ای که شما استفاده میکنید یه جور دیگه است! ازش استفاده نکردم ولی فکر کنم اینجوری باشه:

آدرس زیر رو دنبال کنید:

پنل وردپرسیتون » افزونه ها » ویرایشگر » انتخاب افزونه wordpress most poplular posts » به دنبال نوشته ی زیر باشید:

   // build custom layout

(با استفاده از کلید های ctrl+f میتونید جستجو کنید)

میتونید views و... رو تغییر بدید.

اگه حل نشد بگین تا بیشتر بررسی کنم.

لطفاً از این به بعد هم بیشتر دقّت کنید توی پاسخ هاتون تا مشکلتون طولانی تر نشه.

لینک به ارسال

به گفتگو بپیوندید

هم اکنون می توانید مطلب خود را ارسال نمایید و بعداً ثبت نام کنید. اگر حساب کاربری دارید، برای ارسال با حساب کاربری خود اکنون وارد شوید .

مهمان
ارسال پاسخ به این موضوع ...

×   شما در حال چسباندن محتوایی با قالب بندی هستید.   حذف قالب بندی

  تنها استفاده از 75 اموجی مجاز می باشد.

×   لینک شما به صورت اتوماتیک جای گذاری شد.   نمایش به صورت لینک

×   محتوای قبلی شما بازگردانی شد.   پاک کردن محتوای ویرایشگر

×   شما مستقیما نمی توانید تصویر خود را قرار دهید. یا آن را اینجا بارگذاری کنید یا از یک URL قرار دهید.

×
×
  • اضافه کردن...