public static function wp_pvp_count()
 {
     global $wpdb;
     $post_id = (int) $_GET['post_id'];
     WP_PVP::add_views($post_id);
     $json = array();
     $data = $wpdb->get_row('SELECT * FROM ' . $wpdb->postviews_plus . ' WHERE count_id = "' . esc_attr($_GET['count_id']) . '"');
     if ($data) {
         if (!empty($data->tv)) {
             $post_list = explode(',', $data->tv);
             if (is_array($post_list)) {
                 foreach ($post_list as $post_ID) {
                     $user_views = (int) get_post_meta($post_ID, WP_PVP::$post_meta_views, true);
                     $bot_views = (int) get_post_meta($post_ID, WP_PVP::$post_meta_botviews, true);
                     $json['wppvp_tv_' . $post_ID] = number_format_i18n($user_views + $bot_views);
                     $json['wppvp_tuv_' . $post_ID] = number_format_i18n($user_views);
                     $json['wppvp_tbv_' . $post_ID] = number_format_i18n($bot_views);
                 }
             }
         }
         if (!empty($data->gt)) {
             $gts = explode(',', $data->gt);
             foreach ($gts as $gt) {
                 $with_bot = (bool) substr($gt, 0, 1);
                 switch (substr($gt, 1, 1)) {
                     case 1:
                         $type = 'category';
                         break;
                     case 2:
                         $type = 'post_tag';
                         break;
                     default:
                         $type = '';
                         break;
                 }
                 $term_id = explode('-', substr($gt, 2));
                 if (count($term_id) == 1) {
                     $term_id = $term_id[0];
                 }
                 $json['wppvp_gt_' . $gt] = number_format_i18n(get_totalviews_term($term_id, false, $with_bot, $type));
             }
         }
     }
     wp_send_json($json);
 }
    public static function setting()
    {
        global $wpdb;
        if (isset($_POST['wp-pvp-setting']) && wp_verify_nonce($_POST['wp-pvp-setting'], 'wp-pvp-setting')) {
            if (!empty($_POST['Update'])) {
                self::update_setting();
                WP_PVP::$options = get_option('PVP_options', WP_PVP::$options);
            }
            if (!empty($_POST['Default'])) {
                self::reset_setting();
                WP_PVP::$options = get_option('PVP_options', WP_PVP::$options);
            }
        }
        ?>
		<?php 
        if (!empty($text)) {
            echo '<div id="message" class="updated fade"><p>' . $text . '</p></div>';
        }
        ?>
		<div class="wrap"><form method="post" action="">
			<h2><?php 
        _e('Post Views Plus Options', WP_PVP::$textdomain);
        ?>
</h2>
			<h3 class="title"><?php 
        _e('Basic Options', WP_PVP::$textdomain);
        ?>
</h3>
			<table class="form-table">
				<tr>
					<th scope="row"><?php 
        _e('Count Views From:', WP_PVP::$textdomain);
        ?>
</th>
					<td>
						<select name="views_count" size="1">
							<option value="0"<?php 
        selected('0', WP_PVP::$options['count']);
        ?>
><?php 
        _e('Everyone', WP_PVP::$textdomain);
        ?>
</option>
							<option value="1"<?php 
        selected('1', WP_PVP::$options['count']);
        ?>
><?php 
        _e('Guests Only', WP_PVP::$textdomain);
        ?>
</option>
							<option value="2"<?php 
        selected('2', WP_PVP::$options['count']);
        ?>
><?php 
        _e('Registered Users Only', WP_PVP::$textdomain);
        ?>
</option>
						</select>
					</td>
				</tr>
				<tr>
					<th scope="row"><?php 
        _e('Reflash check:', WP_PVP::$textdomain);
        ?>
</th>
					<td>
						<select name="views_check_reflash" size="1">
							<option value="0"<?php 
        selected('0', WP_PVP::$options['check_reflash']);
        ?>
><?php 
        _e('Close', WP_PVP::$textdomain);
        ?>
</option>
							<option value="1"<?php 
        selected('1', WP_PVP::$options['check_reflash']);
        ?>
><?php 
        _e('Open', WP_PVP::$textdomain);
        ?>
</option>
						</select>
						<?php 
        _e('Check is based on IP.', WP_PVP::$textdomain);
        ?>
<br>
						<?php 
        _e('Reflash timeout:', WP_PVP::$textdomain);
        ?>
						<input type="text" id="views_timeout" name="views_timeout" size="10" value="<?php 
        echo WP_PVP::$options['timeout'];
        ?>
" /><?php 
        _e('second.', WP_PVP::$textdomain);
        ?>
					</td>
				</tr>
				<tr>
					<th scope="row"><?php 
        _e('Views Template:', WP_PVP::$textdomain);
        ?>
</th>
					<td>
						<?php 
        _e('All views:', WP_PVP::$textdomain);
        ?>
						<input type="text" id="views_template_template" name="views_template_template" size="70" value="<?php 
        echo htmlspecialchars(stripslashes(WP_PVP::$options['template']));
        ?>
" /><br>
						<?php 
        _e('Allowed Variables:', WP_PVP::$textdomain);
        ?>
 - %VIEW_COUNT%<br><br>
						<?php 
        _e('Only user views:', WP_PVP::$textdomain);
        ?>
						<input type="text" id="views_template_user_template" name="views_template_user_template" size="70" value="<?php 
        echo htmlspecialchars(stripslashes(WP_PVP::$options['user_template']));
        ?>
" /><br>
						<?php 
        _e('Allowed Variables:', WP_PVP::$textdomain);
        ?>
 - %VIEW_COUNT%<br><br>
						<?php 
        _e('Only bot views:', WP_PVP::$textdomain);
        ?>
						<input type="text" id="views_template_bot_template" name="views_template_bot_template" size="70" value="<?php 
        echo htmlspecialchars(stripslashes(WP_PVP::$options['bot_template']));
        ?>
" /><br>
						<?php 
        _e('Allowed Variables:', WP_PVP::$textdomain);
        ?>
 - %VIEW_COUNT%
					</td>
				</tr>
				<tr>
					<th scope="row"><?php 
        _e('Most Viewed Template:', WP_PVP::$textdomain);
        ?>
</th>
					<td>
						<textarea cols="65" rows="4"  id="views_template_most_viewed" name="views_template_most_viewed"><?php 
        echo htmlspecialchars(stripslashes(WP_PVP::$options['most_viewed_template']));
        ?>
</textarea><br>
						<?php 
        _e('Allowed Variables:', WP_PVP::$textdomain);
        ?>
 - %VIEW_COUNT% - %POST_TITLE% - %POST_EXCERPT% - %POST_CONTENT% - %POST_DATE% - %POST_URL% - %POST_THUMBNAIL%<br><br>
						<?php 
        _e('Size of post thumbnail: ', WP_PVP::$textdomain);
        _e('Width: ', WP_PVP::$textdomain);
        ?>
 <input type="text" id="set_thumbnail_size_w" name="set_thumbnail_size_w" size="5" value="<?php 
        echo WP_PVP::$options['set_thumbnail_size_w'];
        ?>
" />
						<?php 
        _e('Height: ', WP_PVP::$textdomain);
        ?>
 <input type="text" id="set_thumbnail_size_h" name="set_thumbnail_size_h" size="5" value="<?php 
        echo WP_PVP::$options['set_thumbnail_size_h'];
        ?>
" />
					</td>
				</tr>
				<tr>
					<th scope="row"><?php 
        _e('BOT User_agent:', WP_PVP::$textdomain);
        ?>
</th>
					<td>
						<textarea cols="30" rows="<?php 
        echo count(WP_PVP::$options['botagent']) + 1;
        ?>
"  id="views_botagent" name="views_botagent"><?php 
        echo htmlspecialchars(stripslashes(implode("\n", WP_PVP::$options['botagent'])));
        ?>
</textarea><br>
						<?php 
        _e('For each BOT user_agent one line.', WP_PVP::$textdomain);
        ?>
					</td>
				</tr>
			</table>
			<p>&nbsp;</p>
			<h3 class="title"><?php 
        _e('Display Options', WP_PVP::$textdomain);
        ?>
</h3>
			<table class="form-table">
				<tr>
					<th scope="row"><?php 
        _e('Home Page:', WP_PVP::$textdomain);
        ?>
</th>
					<td>
						<select name="views_display_home" size="1">
							<option value="0"<?php 
        selected('0', WP_PVP::$options['display_home']);
        ?>
><?php 
        _e('Display to everyone', WP_PVP::$textdomain);
        ?>
</option>
							<option value="1"<?php 
        selected('1', WP_PVP::$options['display_home']);
        ?>
><?php 
        _e('Display to registered users only', WP_PVP::$textdomain);
        ?>
</option>
							<option value="2"<?php 
        selected('2', WP_PVP::$options['display_home']);
        ?>
><?php 
        _e('Don\'t display on home page', WP_PVP::$textdomain);
        ?>
</option>
						</select>
					</td>
				</tr>
				<tr>
					<th scope="row"><?php 
        _e('Singe Posts:', WP_PVP::$textdomain);
        ?>
</th>
					<td>
						<select name="views_display_single" size="1">
							<option value="0"<?php 
        selected('0', WP_PVP::$options['display_single']);
        ?>
><?php 
        _e('Display to everyone', WP_PVP::$textdomain);
        ?>
</option>
							<option value="1"<?php 
        selected('1', WP_PVP::$options['display_single']);
        ?>
><?php 
        _e('Display to registered users only', WP_PVP::$textdomain);
        ?>
</option>
							<option value="2"<?php 
        selected('2', WP_PVP::$options['display_single']);
        ?>
><?php 
        _e('Don\'t display on single posts', WP_PVP::$textdomain);
        ?>
</option>
						</select>
					</td>
				</tr>
				<tr>
					<th scope="row"><?php 
        _e('Pages:', WP_PVP::$textdomain);
        ?>
</th>
					<td>
						<select name="views_display_page" size="1">
							<option value="0"<?php 
        selected('0', WP_PVP::$options['display_page']);
        ?>
><?php 
        _e('Display to everyone', WP_PVP::$textdomain);
        ?>
</option>
							<option value="1"<?php 
        selected('1', WP_PVP::$options['display_page']);
        ?>
><?php 
        _e('Display to registered users only', WP_PVP::$textdomain);
        ?>
</option>
							<option value="2"<?php 
        selected('2', WP_PVP::$options['display_page']);
        ?>
><?php 
        _e('Don\'t display on pages', WP_PVP::$textdomain);
        ?>
</option>
						</select>
					</td>
				</tr>
				<tr>
					<th scope="row"><?php 
        _e('Archive Pages:', WP_PVP::$textdomain);
        ?>
</th>
					<td>
						<select name="views_display_archive" size="1">
							<option value="0"<?php 
        selected('0', WP_PVP::$options['display_archive']);
        ?>
><?php 
        _e('Display to everyone', WP_PVP::$textdomain);
        ?>
</option>
							<option value="1"<?php 
        selected('1', WP_PVP::$options['display_archive']);
        ?>
><?php 
        _e('Display to registered users only', WP_PVP::$textdomain);
        ?>
</option>
							<option value="2"<?php 
        selected('2', WP_PVP::$options['display_archive']);
        ?>
><?php 
        _e('Don\'t display on archive pages', WP_PVP::$textdomain);
        ?>
</option>
						</select>
					</td>
				</tr>
				<tr>
					<th scope="row"><?php 
        _e('Search Pages:', WP_PVP::$textdomain);
        ?>
</th>
					<td>
						<select name="views_display_search" size="1">
							<option value="0"<?php 
        selected('0', WP_PVP::$options['display_search']);
        ?>
><?php 
        _e('Display to everyone', WP_PVP::$textdomain);
        ?>
</option>
							<option value="1"<?php 
        selected('1', WP_PVP::$options['display_search']);
        ?>
><?php 
        _e('Display to registered users only', WP_PVP::$textdomain);
        ?>
</option>
							<option value="2"<?php 
        selected('2', WP_PVP::$options['display_search']);
        ?>
><?php 
        _e('Don\'t display on search pages', WP_PVP::$textdomain);
        ?>
</option>
						</select>
					</td>
				</tr>
				<tr>
					<th scope="row"><?php 
        _e('Other Pages:', WP_PVP::$textdomain);
        ?>
</th>
					<td>
						<select name="views_display_other" size="1">
							<option value="0"<?php 
        selected('0', WP_PVP::$options['display_other']);
        ?>
><?php 
        _e('Display to everyone', WP_PVP::$textdomain);
        ?>
</option>
							<option value="1"<?php 
        selected('1', WP_PVP::$options['display_other']);
        ?>
><?php 
        _e('Display to registered users only', WP_PVP::$textdomain);
        ?>
</option>
							<option value="2"<?php 
        selected('2', WP_PVP::$options['display_other']);
        ?>
><?php 
        _e('Don\'t display on other pages', WP_PVP::$textdomain);
        ?>
</option>
						</select>
					</td>
				</tr>
			</table>
			<p><?php 
        _e('These options specify where the view counts should be displayed and to whom.<br>Note that the theme files must contain a call to <code>the_views()</code> in order for any view count to be displayed.', WP_PVP::$textdomain);
        ?>
</p>
			<p class="submit">
				<input type="submit" name="Update" class="button-primary" value="<?php 
        _e('Save Changes', WP_PVP::$textdomain);
        ?>
" />
				<input type="submit" name="Default" class="button-primary" value="<?php 
        _e('Reset to Default', WP_PVP::$textdomain);
        ?>
" />
				<?php 
        wp_nonce_field('wp-pvp-setting', 'wp-pvp-setting');
        ?>
			</p>
		</form></div>


		<h2><?php 
        _e('Uninstall WP-PostViews Plus', WP_PVP::$textdomain);
        ?>
</h2>
		<p><?php 
        _e('Deactivating WP-PostViews Plus plugin does not remove any data that may have been created, such as the views data. To completely remove this plugin, you can uninstall it here.', WP_PVP::$textdomain);
        ?>
</p>
		<div style="color: red">
			<h3 class="title"><?php 
        _e('WARNING:', WP_PVP::$textdomain);
        ?>
</h3>
			<?php 
        _e('Once uninstalled, this cannot be undone. You should use a Database Backup plugin of WordPress to back up all the data first.', WP_PVP::$textdomain);
        ?>
			<p>
				<?php 
        printf(__('The database table <strong>%s</strong> will be DELETED.', WP_PVP::$textdomain), $wpdb->postviews_plus);
        ?>
<br>
				<?php 
        printf(__('The database table <strong>%s</strong> will be DELETED.', WP_PVP::$textdomain), $wpdb->postviews_plus_reflash);
        ?>
			</p>
			<?php 
        _e('The following WordPress Options/PostMetas will be DELETED:', WP_PVP::$textdomain);
        ?>
<br>
			<?php 
        _e('WordPress Options', WP_PVP::$textdomain);
        ?>
<br>
			<ol>
				<?php 
        foreach (self::$views_settings as $settings) {
            echo '<li>' . $settings . '</li>' . "\n";
        }
        ?>
			</ol>
			<?php 
        _e('WordPress PostMetas', WP_PVP::$textdomain);
        ?>
<br>
			<ol>
				<?php 
        foreach (self::$views_postmetas as $postmeta) {
            echo '<li>' . $postmeta . '</li>' . "\n";
        }
        ?>
			</ol>
		</div>
		<form method="post" action="">
			<input type="checkbox" name="uninstall_views_yes" value="yes" />&nbsp;<?php 
        _e('Yes', WP_PVP::$textdomain);
        ?>
			<input type="submit" name="do" value="<?php 
        _e('UNINSTALL WP-PostViews Plus', WP_PVP::$textdomain);
        ?>
" class="button" onclick="return confirm('<?php 
        _e('You Are About To Uninstall WP-PostViews Plus From WordPress.\\nThis Action Is Not Reversible.\\n\\n Choose [Cancel] To Stop, [OK] To Uninstall.', WP_PVP::$textdomain);
        ?>
')" />
			<?php 
        wp_nonce_field('wp-pvp-uninstall', 'wp-pvp-uninstall');
        ?>
		</form>

		<h2><?php 
        _e('Thank', WP_PVP::$textdomain);
        ?>
</h2>
		<p><?php 
        _e('Translation contributors', WP_PVP::$textdomain);
        ?>
:</p>
		<p>zh_CN(简体中文) By ddbiz</p>
		<?php 
    }
Beispiel #3
0
function get_totalviews_term($term_id = 1, $display = true, $with_bot = true, $type = '')
{
    global $wpdb;
    $where = '';
    $inner_join = '';
    if ($term_id != 0) {
        if (is_array($term_id)) {
            $term_id = array_map('intval', $term_id);
            $where = 'tt.term_id IN (' . implode(',', $term_id) . ') AND ';
        } else {
            $where = 'tt.term_id=' . intval($term_id) . ' AND ';
        }
        $inner_join = 'INNER JOIN ' . $wpdb->term_relationships . ' AS tr ON pm.post_id = tr.object_id' . ' INNER JOIN ' . $wpdb->term_taxonomy . ' AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id AND tt.taxonomy = "' . $type . '"';
    }
    $add_word = get_totalviews_stats_word($term_id, $with_bot, $type);
    if ($with_bot) {
        $total_views = $wpdb->get_var('SELECT SUM(IFNULL(CAST(pm.meta_value AS UNSIGNED), 0)) FROM ' . $wpdb->postmeta . ' AS pm ' . $inner_join . ' WHERE ' . $where . ' (pm.meta_key = "' . WP_PVP::$post_meta_views . '" OR pm.meta_key = "' . WP_PVP::$post_meta_botviews . '")');
        $template = str_replace('%VIEW_COUNT%', '<span id="wppvp_gt_' . $add_word . '">%VIEW_COUNT%</span>', WP_PVP::$options['template']);
    } else {
        $total_views = $wpdb->get_var('SELECT SUM(IFNULL(CAST(pm.meta_value AS UNSIGNED), 0)) FROM ' . $wpdb->postmeta . ' AS pm ' . $inner_join . ' WHERE ' . $where . ' pm.meta_key = "' . WP_PVP::$post_meta_views . '"');
        $template = str_replace('%VIEW_COUNT%', '<span id="wppvp_gt_' . $add_word . '">%VIEW_COUNT%</span>', WP_PVP::$options['user_template']);
    }
    $total_views = intval($total_views);
    if ($display) {
        if (defined('WP_CACHE') && WP_CACHE) {
            WP_PVP::add_cache_stats('gt', $term_id, $with_bot, $type);
            $template = str_replace('%VIEW_COUNT%', '', $template);
        } else {
            $template = str_replace('%VIEW_COUNT%', number_format_i18n($total_views), $template);
        }
        echo $template;
    } else {
        return $total_views;
    }
}
Beispiel #4
0
 public static function add_views($post_ID)
 {
     if ($post_ID > 0) {
         if (!wp_is_post_revision($post)) {
             switch (self::$options['count']) {
                 case 0:
                     self::$should_count = true;
                     break;
                 case 1:
                     if (!is_user_logged_in()) {
                         self::$should_count = true;
                     }
                     break;
                 case 2:
                     if (is_user_logged_in()) {
                         self::$should_count = true;
                     }
                     break;
             }
         }
         if (self::$should_count) {
             if (self::$options['check_reflash']) {
                 global $wpdb;
                 $ip = preg_replace('/[^0-9a-fA-F:., ]/', '', $_SERVER['REMOTE_ADDR']);
                 $wpdb->query('DELETE FROM ' . $wpdb->postviews_plus_reflash . ' WHERE look_time < DATE_SUB(CURRENT_TIMESTAMP, INTERVAL ' . self::$options['timeout'] . ' SECOND)');
                 $data = $wpdb->get_var('SELECT `look_time` FROM ' . $wpdb->postviews_plus_reflash . ' WHERE `post_id` = "' . $post_id . '" AND `user_ip` = "' . $ip . '"');
                 if ($data) {
                     return;
                 }
                 $wpdb->insert($wpdb->postviews_plus_reflash, array('post_id' => $post_ID, 'user_ip' => $ip), array('%d', '$s'));
             }
             $useragent = strtolower(trim($_SERVER['HTTP_USER_AGENT']));
             $bot = false;
             if (is_array(self::$options['botagent'])) {
                 $regex = '/(' . str_replace('@@@@@@', ')|(', preg_quote(implode(self::$options['botagent'], '@@@@@@'), '/')) . ')/si';
                 $bot = preg_match($regex, $useragent);
             }
             if ($bot) {
                 $post_views = (int) get_post_meta($post_ID, self::$post_meta_botviews, true) + 1;
                 update_post_meta($post_ID, self::$post_meta_botviews, $post_views);
             } else {
                 $post_views = (int) get_post_meta($post_ID, self::$post_meta_views, true) + 1;
                 update_post_meta($post_ID, self::$post_meta_views, $post_views);
             }
         }
     }
 }