WP-PostViews - Version 1.67

Version Description

N/A

Download this release

Release Info

Developer GamerZ
Plugin Icon WP-PostViews
Version 1.67
Comparing to
See all releases

Code changes from version 1.66 to 1.67

Files changed (3) hide show
  1. postviews-options.php +94 -74
  2. readme.txt +7 -13
  3. wp-postviews.php +56 -41
postviews-options.php CHANGED
@@ -1,43 +1,50 @@
1
  <?php
2
  ### Variables Variables Variables
3
- $base_name = plugin_basename('wp-postviews/postviews-options.php');
4
  $base_page = 'admin.php?page='.$base_name;
5
- $id = (isset($_GET['id']) ? intval($_GET['id']) : 0);
6
- $mode = (isset($_GET['mode']) ? trim($_GET['mode']) : '');
7
  $text = '';
8
 
9
  ### Form Processing
10
- if(!empty($_POST['Submit'])) {
11
- check_admin_referer('wp-postviews_options');
12
- $views_options = array();
13
- $views_options['count'] = intval($_POST['views_count']);
14
- $views_options['exclude_bots'] = intval($_POST['views_exclude_bots']);
15
- $views_options['display_home'] = intval($_POST['views_display_home']);
16
- $views_options['display_single'] = intval($_POST['views_display_single']);
17
- $views_options['display_page'] = intval($_POST['views_display_page']);
18
- $views_options['display_archive'] = intval($_POST['views_display_archive']);
19
- $views_options['display_search'] = intval($_POST['views_display_search']);
20
- $views_options['display_other'] = intval($_POST['views_display_other']);
21
- $views_options['template'] = trim($_POST['views_template_template']);
22
- $views_options['most_viewed_template'] = trim($_POST['views_template_most_viewed']);
 
 
23
  $update_views_queries = array();
24
  $update_views_text = array();
25
- $update_views_queries[] = update_option('views_options', $views_options);
26
- $update_views_text[] = __('Post Views Options', 'wp-postviews');
27
  $i = 0;
28
 
29
- foreach($update_views_queries as $update_views_query) {
30
- if($update_views_query) {
31
- $text .= '<font color="green">'.$update_views_text[$i].' '.__('Updated', 'wp-postviews').'</font><br />';
32
  }
33
  $i++;
34
  }
35
- if(empty($text)) {
36
- $text = '<font color="red">'.__('No Post Views Option Updated', 'wp-postviews').'</font>';
37
  }
38
  }
39
 
40
- $views_options = get_option('views_options');
 
 
 
 
 
41
  ?>
42
  <script type="text/javascript">
43
  /* <![CDATA[*/
@@ -45,57 +52,70 @@ $views_options = get_option('views_options');
45
  var default_template;
46
  switch(template) {
47
  case 'template':
48
- default_template = "<?php _e('%VIEW_COUNT% views', 'wp-postviews'); ?>";
49
  break;
50
  case 'most_viewed':
51
- default_template = "<li><a href=\"%POST_URL%\" title=\"%POST_TITLE%\">%POST_TITLE%</a> - %VIEW_COUNT% <?php _e('views', 'wp-postviews'); ?></li>";
52
  break;
53
  }
54
  jQuery("#views_template_" + template).val(default_template);
55
  }
56
  /* ]]> */
57
  </script>
58
- <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?>
59
- <form method="post" action="<?php echo admin_url('admin.php?page='.plugin_basename(__FILE__)); ?>">
60
- <?php wp_nonce_field('wp-postviews_options'); ?>
61
  <div class="wrap">
62
- <?php screen_icon(); ?>
63
- <h2><?php _e('Post Views Options', 'wp-postviews'); ?></h2>
64
  <table class="form-table">
65
  <tr>
66
- <td valign="top" width="30%"><strong><?php _e('Count Views From:', 'wp-postviews'); ?></strong></td>
67
  <td valign="top">
68
  <select name="views_count" size="1">
69
- <option value="0"<?php selected('0', $views_options['count']); ?>><?php _e('Everyone', 'wp-postviews'); ?></option>
70
- <option value="1"<?php selected('1', $views_options['count']); ?>><?php _e('Guests Only', 'wp-postviews'); ?></option>
71
- <option value="2"<?php selected('2', $views_options['count']); ?>><?php _e('Registered Users Only', 'wp-postviews'); ?></option>
72
  </select>
73
  </td>
74
  </tr>
75
- <tr>
76
- <td valign="top" width="30%"><strong><?php _e('Exclude Bot Views:', 'wp-postviews'); ?></strong></td>
77
  <td valign="top">
78
  <select name="views_exclude_bots" size="1">
79
- <option value="0"<?php selected('0', $views_options['exclude_bots']); ?>><?php _e('No', 'wp-postviews'); ?></option>
80
- <option value="1"<?php selected('1', $views_options['exclude_bots']); ?>><?php _e('Yes', 'wp-postviews'); ?></option>
81
  </select>
82
  </td>
83
  </tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  <tr>
85
  <td valign="top">
86
- <strong><?php _e('Views Template:', 'wp-postviews'); ?></strong><br /><br />
87
- <?php _e('Allowed Variables:', 'wp-postviews'); ?><br />
88
  - %VIEW_COUNT%<br /><br />
89
- <input type="button" name="RestoreDefault" value="<?php _e('Restore Default Template', 'wp-postviews'); ?>" onclick="views_default_templates('template');" class="button" />
90
  </td>
91
  <td valign="top">
92
- <input type="text" id="views_template_template" name="views_template_template" size="70" value="<?php echo htmlspecialchars(stripslashes($views_options['template'])); ?>" />
93
  </td>
94
  </tr>
95
  <tr>
96
  <td valign="top">
97
- <strong><?php _e('Most Viewed Template:', 'wp-postviews'); ?></strong><br /><br />
98
- <?php _e('Allowed Variables:', 'wp-postviews'); ?><br />
99
  - %VIEW_COUNT%<br />
100
  - %POST_TITLE%<br />
101
  - %POST_DATE%<br />
@@ -103,79 +123,79 @@ $views_options = get_option('views_options');
103
  - %POST_EXCERPT%<br />
104
  - %POST_CONTENT%<br />
105
  - %POST_URL%<br /><br />
106
- <input type="button" name="RestoreDefault" value="<?php _e('Restore Default Template', 'wp-postviews'); ?>" onclick="views_default_templates('most_viewed');" class="button" />
107
  </td>
108
  <td valign="top">
109
- <textarea cols="80" rows="15" id="views_template_most_viewed" name="views_template_most_viewed"><?php echo htmlspecialchars(stripslashes($views_options['most_viewed_template'])); ?></textarea>
110
  </td>
111
  </tr>
112
  </table>
113
- <h3><?php _e('Display Options', 'wp-postviews'); ?></h3>
114
- <p><?php _e('These options specify where the view counts should be displayed and to whom. By default view counts will be displayed to all visitors. Note that the theme files must contain a call to <code>the_views()</code> in order for any view count to be displayed.', 'wp-postviews'); ?></p>
115
  <table class="form-table">
116
  <tr>
117
- <td valign="top"><strong><?php _e('Home Page:', 'wp-postviews'); ?></strong></td>
118
  <td>
119
  <select name="views_display_home" size="1">
120
- <option value="0"<?php selected('0', $views_options['display_home']); ?>><?php _e('Display to everyone', 'wp-postviews'); ?></option>
121
- <option value="1"<?php selected('1', $views_options['display_home']); ?>><?php _e('Display to registered users only', 'wp-postviews'); ?></option>
122
- <option value="2"<?php selected('2', $views_options['display_home']); ?>><?php _e('Don\'t display on home page', 'wp-postviews'); ?></option>
123
  </select>
124
  </td>
125
  </tr>
126
  <tr>
127
- <td valign="top"><strong><?php _e('Singe Posts:', 'wp-postviews'); ?></strong></td>
128
  <td>
129
  <select name="views_display_single" size="1">
130
- <option value="0"<?php selected('0', $views_options['display_single']); ?>><?php _e('Display to everyone', 'wp-postviews'); ?></option>
131
- <option value="1"<?php selected('1', $views_options['display_single']); ?>><?php _e('Display to registered users only', 'wp-postviews'); ?></option>
132
- <option value="2"<?php selected('2', $views_options['display_single']); ?>><?php _e('Don\'t display on single posts', 'wp-postviews'); ?></option>
133
  </select>
134
  </td>
135
  </tr>
136
  <tr>
137
- <td valign="top"><strong><?php _e('Pages:', 'wp-postviews'); ?></strong></td>
138
  <td>
139
  <select name="views_display_page" size="1">
140
- <option value="0"<?php selected('0', $views_options['display_page']); ?>><?php _e('Display to everyone', 'wp-postviews'); ?></option>
141
- <option value="1"<?php selected('1', $views_options['display_page']); ?>><?php _e('Display to registered users only', 'wp-postviews'); ?></option>
142
- <option value="2"<?php selected('2', $views_options['display_page']); ?>><?php _e('Don\'t display on pages', 'wp-postviews'); ?></option>
143
  </select>
144
  </td>
145
  </tr>
146
  <tr>
147
- <td valign="top"><strong><?php _e('Archive Pages:', 'wp-postviews'); ?></strong></td>
148
  <td>
149
  <select name="views_display_archive" size="1">
150
- <option value="0"<?php selected('0', $views_options['display_archive']); ?>><?php _e('Display to everyone', 'wp-postviews'); ?></option>
151
- <option value="1"<?php selected('1', $views_options['display_archive']); ?>><?php _e('Display to registered users only', 'wp-postviews'); ?></option>
152
- <option value="2"<?php selected('2', $views_options['display_archive']); ?>><?php _e('Don\'t display on archive pages', 'wp-postviews'); ?></option>
153
  </select>
154
  </td>
155
  </tr>
156
  <tr>
157
- <td valign="top"><strong><?php _e('Search Pages:', 'wp-postviews'); ?></strong></td>
158
  <td>
159
  <select name="views_display_search" size="1">
160
- <option value="0"<?php selected('0', $views_options['display_search']); ?>><?php _e('Display to everyone', 'wp-postviews'); ?></option>
161
- <option value="1"<?php selected('1', $views_options['display_search']); ?>><?php _e('Display to registered users only', 'wp-postviews'); ?></option>
162
- <option value="2"<?php selected('2', $views_options['display_search']); ?>><?php _e('Don\'t display on search pages', 'wp-postviews'); ?></option>
163
  </select>
164
  </td>
165
  </tr>
166
  <tr>
167
- <td valign="top"><strong><?php _e('Other Pages:', 'wp-postviews'); ?></strong></td>
168
  <td>
169
  <select name="views_display_other" size="1">
170
- <option value="0"<?php selected('0', $views_options['display_other']); ?>><?php _e('Display to everyone', 'wp-postviews'); ?></option>
171
- <option value="1"<?php selected('1', $views_options['display_other']); ?>><?php _e('Display to registered users only', 'wp-postviews'); ?></option>
172
- <option value="2"<?php selected('2', $views_options['display_other']); ?>><?php _e('Don\'t display on other pages', 'wp-postviews'); ?></option>
173
  </select>
174
  </td>
175
  </tr>
176
  </table>
177
  <p class="submit">
178
- <input type="submit" name="Submit" class="button-primary" value="<?php _e('Save Changes', 'wp-postviews'); ?>" />
179
  </p>
180
  </div>
181
  </form>
1
  <?php
2
  ### Variables Variables Variables
3
+ $base_name = plugin_basename( 'wp-postviews/postviews-options.php' );
4
  $base_page = 'admin.php?page='.$base_name;
5
+ $id = (isset($_GET['id'] ) ? intval($_GET['id'] ) : 0);
6
+ $mode = (isset($_GET['mode'] ) ? trim($_GET['mode'] ) : '' );
7
  $text = '';
8
 
9
  ### Form Processing
10
+ if(!empty($_POST['Submit'] )) {
11
+ check_admin_referer( 'wp-postviews_options' );
12
+ $views_options = array(
13
+ 'count' => intval( $_POST['views_count'] )
14
+ , 'exclude_bots' => intval( $_POST['views_exclude_bots'] )
15
+ , 'display_home' => intval( $_POST['views_display_home'] )
16
+ , 'display_single' => intval( $_POST['views_display_single'] )
17
+ , 'display_page' => intval( $_POST['views_display_page'] )
18
+ , 'display_archive' => intval( $_POST['views_display_archive'] )
19
+ , 'display_search' => intval( $_POST['views_display_search'] )
20
+ , 'display_other' => intval( $_POST['views_display_other'] )
21
+ , 'use_ajax' => intval( $_POST['views_use_ajax'] )
22
+ , 'template' => trim( $_POST['views_template_template'] )
23
+ , 'most_viewed_template' => trim( $_POST['views_template_most_viewed'] )
24
+ );
25
  $update_views_queries = array();
26
  $update_views_text = array();
27
+ $update_views_queries[] = update_option( 'views_options', $views_options );
28
+ $update_views_text[] = __( 'Post Views Options', 'wp-postviews' );
29
  $i = 0;
30
 
31
+ foreach( $update_views_queries as $update_views_query ) {
32
+ if( $update_views_query ) {
33
+ $text .= '<font style="color: green;">' . $update_views_text[$i] . ' ' . __( 'Updated', 'wp-postviews' ) . '</font><br />';
34
  }
35
  $i++;
36
  }
37
+ if( empty( $text ) ) {
38
+ $text = '<font style="color: red;">' . __( 'No Post Views Option Updated', 'wp-postviews' ) . '</font>';
39
  }
40
  }
41
 
42
+ $views_options = get_option( 'views_options' );
43
+
44
+ // Default
45
+ if( !isset ( $views_options['use_ajax'] ) ) {
46
+ $views_options['use_ajax'] = 1;
47
+ }
48
  ?>
49
  <script type="text/javascript">
50
  /* <![CDATA[*/
52
  var default_template;
53
  switch(template) {
54
  case 'template':
55
+ default_template = "<?php _e( '%VIEW_COUNT% views', 'wp-postviews' ); ?>";
56
  break;
57
  case 'most_viewed':
58
+ default_template = "<li><a href=\"%POST_URL%\" title=\"%POST_TITLE%\">%POST_TITLE%</a> - %VIEW_COUNT% <?php _e( 'views', 'wp-postviews' ); ?></li>";
59
  break;
60
  }
61
  jQuery("#views_template_" + template).val(default_template);
62
  }
63
  /* ]]> */
64
  </script>
65
+ <?php if( !empty( $text ) ) { echo '<div id="message" class="updated fade"><p>' . $text . '</p></div>'; } ?>
66
+ <form method="post" action="<?php echo admin_url( 'admin.php?page=' . plugin_basename( __FILE__ ) ); ?>">
67
+ <?php wp_nonce_field( 'wp-postviews_options' ); ?>
68
  <div class="wrap">
69
+ <h2><?php _e( 'Post Views Options', 'wp-postviews' ); ?></h2>
 
70
  <table class="form-table">
71
  <tr>
72
+ <td valign="top" width="30%"><strong><?php _e( 'Count Views From:', 'wp-postviews' ); ?></strong></td>
73
  <td valign="top">
74
  <select name="views_count" size="1">
75
+ <option value="0"<?php selected( '0', $views_options['count'] ); ?>><?php _e( 'Everyone', 'wp-postviews' ); ?></option>
76
+ <option value="1"<?php selected( '1', $views_options['count'] ); ?>><?php _e( 'Guests Only', 'wp-postviews' ); ?></option>
77
+ <option value="2"<?php selected( '2', $views_options['count'] ); ?>><?php _e( 'Registered Users Only', 'wp-postviews' ); ?></option>
78
  </select>
79
  </td>
80
  </tr>
81
+ <tr>
82
+ <td valign="top" width="30%"><strong><?php _e( 'Exclude Bot Views:', 'wp-postviews' ); ?></strong></td>
83
  <td valign="top">
84
  <select name="views_exclude_bots" size="1">
85
+ <option value="0"<?php selected( '0', $views_options['exclude_bots'] ); ?>><?php _e( 'No', 'wp-postviews' ); ?></option>
86
+ <option value="1"<?php selected( '1', $views_options['exclude_bots'] ); ?>><?php _e( 'Yes', 'wp-postviews' ); ?></option>
87
  </select>
88
  </td>
89
  </tr>
90
+ <?php if( defined( 'WP_CACHE' ) && WP_CACHE ): ?>
91
+ <tr>
92
+ <td valign="top" width="30%"><strong><?php _e( 'Use AJAX To Update Views:', 'wp-postviews' ); ?></strong></td>
93
+ <td valign="top">
94
+ <select name="views_use_ajax" size="1">
95
+ <option value="0"<?php selected( '0', $views_options['use_ajax'] ); ?>><?php _e( 'No', 'wp-postviews' ); ?></option>
96
+ <option value="1"<?php selected( '1', $views_options['use_ajax'] ); ?>><?php _e( 'Yes', 'wp-postviews' ); ?></option>
97
+ </select>
98
+ <p>
99
+ <?php _e( 'You have caching enabled for your WordPress installation, by default WP-PostViews will use AJAX to update the view count. However in some cases, you might not want it.', 'wp-postviews' ); ?>
100
+ </p>
101
+ </td>
102
+ </tr>
103
+ <?php endif; ?>
104
  <tr>
105
  <td valign="top">
106
+ <strong><?php _e( 'Views Template:', 'wp-postviews' ); ?></strong><br /><br />
107
+ <?php _e( 'Allowed Variables:', 'wp-postviews' ); ?><br />
108
  - %VIEW_COUNT%<br /><br />
109
+ <input type="button" name="RestoreDefault" value="<?php _e( 'Restore Default Template', 'wp-postviews' ); ?>" onclick="views_default_templates( 'template' );" class="button" />
110
  </td>
111
  <td valign="top">
112
+ <input type="text" id="views_template_template" name="views_template_template" size="70" value="<?php echo htmlspecialchars(stripslashes($views_options['template'] )); ?>" />
113
  </td>
114
  </tr>
115
  <tr>
116
  <td valign="top">
117
+ <strong><?php _e( 'Most Viewed Template:', 'wp-postviews' ); ?></strong><br /><br />
118
+ <?php _e( 'Allowed Variables:', 'wp-postviews' ); ?><br />
119
  - %VIEW_COUNT%<br />
120
  - %POST_TITLE%<br />
121
  - %POST_DATE%<br />
123
  - %POST_EXCERPT%<br />
124
  - %POST_CONTENT%<br />
125
  - %POST_URL%<br /><br />
126
+ <input type="button" name="RestoreDefault" value="<?php _e( 'Restore Default Template', 'wp-postviews' ); ?>" onclick="views_default_templates( 'most_viewed' );" class="button" />
127
  </td>
128
  <td valign="top">
129
+ <textarea cols="80" rows="15" id="views_template_most_viewed" name="views_template_most_viewed"><?php echo htmlspecialchars(stripslashes($views_options['most_viewed_template'] )); ?></textarea>
130
  </td>
131
  </tr>
132
  </table>
133
+ <h3><?php _e( 'Display Options', 'wp-postviews' ); ?></h3>
134
+ <p><?php _e( 'These options specify where the view counts should be displayed and to whom. By default view counts will be displayed to all visitors. Note that the theme files must contain a call to <code>the_views()</code> in order for any view count to be displayed.', 'wp-postviews' ); ?></p>
135
  <table class="form-table">
136
  <tr>
137
+ <td valign="top"><strong><?php _e( 'Home Page:', 'wp-postviews' ); ?></strong></td>
138
  <td>
139
  <select name="views_display_home" size="1">
140
+ <option value="0"<?php selected( '0', $views_options['display_home'] ); ?>><?php _e( 'Display to everyone', 'wp-postviews' ); ?></option>
141
+ <option value="1"<?php selected( '1', $views_options['display_home'] ); ?>><?php _e( 'Display to registered users only', 'wp-postviews' ); ?></option>
142
+ <option value="2"<?php selected( '2', $views_options['display_home'] ); ?>><?php _e( 'Don\'t display on home page', 'wp-postviews' ); ?></option>
143
  </select>
144
  </td>
145
  </tr>
146
  <tr>
147
+ <td valign="top"><strong><?php _e( 'Singe Posts:', 'wp-postviews' ); ?></strong></td>
148
  <td>
149
  <select name="views_display_single" size="1">
150
+ <option value="0"<?php selected( '0', $views_options['display_single'] ); ?>><?php _e( 'Display to everyone', 'wp-postviews' ); ?></option>
151
+ <option value="1"<?php selected( '1', $views_options['display_single'] ); ?>><?php _e( 'Display to registered users only', 'wp-postviews' ); ?></option>
152
+ <option value="2"<?php selected( '2', $views_options['display_single'] ); ?>><?php _e( 'Don\'t display on single posts', 'wp-postviews' ); ?></option>
153
  </select>
154
  </td>
155
  </tr>
156
  <tr>
157
+ <td valign="top"><strong><?php _e( 'Pages:', 'wp-postviews' ); ?></strong></td>
158
  <td>
159
  <select name="views_display_page" size="1">
160
+ <option value="0"<?php selected( '0', $views_options['display_page'] ); ?>><?php _e( 'Display to everyone', 'wp-postviews' ); ?></option>
161
+ <option value="1"<?php selected( '1', $views_options['display_page'] ); ?>><?php _e( 'Display to registered users only', 'wp-postviews' ); ?></option>
162
+ <option value="2"<?php selected( '2', $views_options['display_page'] ); ?>><?php _e( 'Don\'t display on pages', 'wp-postviews' ); ?></option>
163
  </select>
164
  </td>
165
  </tr>
166
  <tr>
167
+ <td valign="top"><strong><?php _e( 'Archive Pages:', 'wp-postviews' ); ?></strong></td>
168
  <td>
169
  <select name="views_display_archive" size="1">
170
+ <option value="0"<?php selected( '0', $views_options['display_archive'] ); ?>><?php _e( 'Display to everyone', 'wp-postviews' ); ?></option>
171
+ <option value="1"<?php selected( '1', $views_options['display_archive'] ); ?>><?php _e( 'Display to registered users only', 'wp-postviews' ); ?></option>
172
+ <option value="2"<?php selected( '2', $views_options['display_archive'] ); ?>><?php _e( 'Don\'t display on archive pages', 'wp-postviews' ); ?></option>
173
  </select>
174
  </td>
175
  </tr>
176
  <tr>
177
+ <td valign="top"><strong><?php _e( 'Search Pages:', 'wp-postviews' ); ?></strong></td>
178
  <td>
179
  <select name="views_display_search" size="1">
180
+ <option value="0"<?php selected( '0', $views_options['display_search'] ); ?>><?php _e( 'Display to everyone', 'wp-postviews' ); ?></option>
181
+ <option value="1"<?php selected( '1', $views_options['display_search'] ); ?>><?php _e( 'Display to registered users only', 'wp-postviews' ); ?></option>
182
+ <option value="2"<?php selected( '2', $views_options['display_search'] ); ?>><?php _e( 'Don\'t display on search pages', 'wp-postviews' ); ?></option>
183
  </select>
184
  </td>
185
  </tr>
186
  <tr>
187
+ <td valign="top"><strong><?php _e( 'Other Pages:', 'wp-postviews' ); ?></strong></td>
188
  <td>
189
  <select name="views_display_other" size="1">
190
+ <option value="0"<?php selected( '0', $views_options['display_other'] ); ?>><?php _e( 'Display to everyone', 'wp-postviews' ); ?></option>
191
+ <option value="1"<?php selected( '1', $views_options['display_other'] ); ?>><?php _e( 'Display to registered users only', 'wp-postviews' ); ?></option>
192
+ <option value="2"<?php selected( '2', $views_options['display_other'] ); ?>><?php _e( 'Don\'t display on other pages', 'wp-postviews' ); ?></option>
193
  </select>
194
  </td>
195
  </tr>
196
  </table>
197
  <p class="submit">
198
+ <input type="submit" name="Submit" class="button-primary" value="<?php _e( 'Save Changes', 'wp-postviews' ); ?>" />
199
  </p>
200
  </div>
201
  </form>
readme.txt CHANGED
@@ -2,29 +2,20 @@
2
  Contributors: GamerZ
3
  Donate link: http://lesterchan.net/site/donation/
4
  Tags: views, hits, counter, postviews
5
- Requires at least: 2.8
6
- Tested up to: 3.8
7
- Stable tag: 1.66
8
 
9
  Enables you to display how many times a post/page had been viewed.
10
 
11
  == Description ==
12
 
13
- = Previous Versions =
14
- * [WP-PostViews 1.40 For WordPress 2.7.x](http://downloads.wordpress.org/plugin/wp-postviews.1.40.zip "WP-PostViews 1.40 For WordPress 2.7.x")
15
- * [WP-PostViews 1.31 For WordPress 2.3.x, 2.5.x And 2.6.x](http://downloads.wordpress.org/plugin/wp-postviews.1.31.zip "WP-PostViews 1.31 For WordPress 2.3.x, 2.5.x And 2.6.x")
16
- * [WP-PostViews 1.11 For WordPress 2.1.x And 2.2.x](http://downloads.wordpress.org/plugin/wp-postviews.1.11.zip "WP-PostViews 1.11 For WordPress 2.1.x And 2.2.x")
17
- * [WP-PostViews 1.02 For WordPress 2.0.x](http://downloads.wordpress.org/plugin/wp-postviews.1.02.zip "WP-PostViews 1.02 For WordPress 2.0.x")
18
-
19
  = Development =
20
- * [http://dev.wp-plugins.org/browser/wp-postviews/](http://dev.wp-plugins.org/browser/wp-postviews/ "http://dev.wp-plugins.org/browser/wp-postviews/")
21
 
22
  = Translations =
23
  * [http://dev.wp-plugins.org/browser/wp-postviews/i18n/](http://dev.wp-plugins.org/browser/wp-postviews/i18n/ "http://dev.wp-plugins.org/browser/wp-postviews/i18n/")
24
 
25
- = Support Forums =
26
- * [http://forums.lesterchan.net/index.php?board=16.0](http://forums.lesterchan.net/index.php?board=16.0 "http://forums.lesterchan.net/index.php?board=16.0")
27
-
28
  = Credits =
29
  * WP-Cache/WP-SuperCache Compatibility By [Thaya Kareeson](http://omninoggin.com/ "Thaya Kareeson")
30
  * __ngetext() by [Anna Ozeritskaya](http://hweia.ru/ "Anna Ozeritskaya")
@@ -35,6 +26,9 @@ Enables you to display how many times a post/page had been viewed.
35
  * I spent most of my free time creating, updating, maintaining and supporting these plugins, if you really love my plugins and could spare me a couple of bucks, I will really appericiate it. If not feel free to use it without any obligations.
36
 
37
  == Changelog ==
 
 
 
38
  = Version 1.66 =
39
  * NEW: Supports MultiSite Network Activation
40
  * NEW: Add %POST_DATE% and %POST_TIME% to template variables
2
  Contributors: GamerZ
3
  Donate link: http://lesterchan.net/site/donation/
4
  Tags: views, hits, counter, postviews
5
+ Requires at least: 3.0
6
+ Tested up to: 3.9
7
+ Stable tag: 1.67
8
 
9
  Enables you to display how many times a post/page had been viewed.
10
 
11
  == Description ==
12
 
 
 
 
 
 
 
13
  = Development =
14
+ * [https://github.com/lesterchan/wp-postviews/](https://github.com/lesterchan/wp-postviews/ "https://github.com/lesterchan/wp-postviews/")
15
 
16
  = Translations =
17
  * [http://dev.wp-plugins.org/browser/wp-postviews/i18n/](http://dev.wp-plugins.org/browser/wp-postviews/i18n/ "http://dev.wp-plugins.org/browser/wp-postviews/i18n/")
18
 
 
 
 
19
  = Credits =
20
  * WP-Cache/WP-SuperCache Compatibility By [Thaya Kareeson](http://omninoggin.com/ "Thaya Kareeson")
21
  * __ngetext() by [Anna Ozeritskaya](http://hweia.ru/ "Anna Ozeritskaya")
26
  * I spent most of my free time creating, updating, maintaining and supporting these plugins, if you really love my plugins and could spare me a couple of bucks, I will really appericiate it. If not feel free to use it without any obligations.
27
 
28
  == Changelog ==
29
+ = Version 1.67 =
30
+ * NEW: Allow user to not use AJAX to update the views even though WP_CACHE is true
31
+
32
  = Version 1.66 =
33
  * NEW: Supports MultiSite Network Activation
34
  * NEW: Add %POST_DATE% and %POST_TIME% to template variables
wp-postviews.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: WP-PostViews
4
  Plugin URI: http://lesterchan.net/portfolio/programming/php/
5
  Description: Enables you to display how many times a post/page had been viewed.
6
- Version: 1.66
7
  Author: Lester 'GaMerZ' Chan
8
  Author URI: http://lesterchan.net
9
  Text Domain: wp-postviews
@@ -46,35 +46,36 @@ function postviews_menu() {
46
 
47
 
48
  ### Function: Calculate Post Views
49
- add_action('wp_head', 'process_postviews');
50
  function process_postviews() {
51
  global $user_ID, $post;
52
- if(is_int($post)) {
53
- $post = get_post($post);
54
- }
55
- if(!wp_is_post_revision($post)) {
56
- if(is_single() || is_page()) {
57
- $id = intval($post->ID);
58
- $views_options = get_option('views_options');
59
- if ( ! $post_views = get_post_meta( $post->ID, 'views', true ) )
60
  $post_views = 0;
 
61
  $should_count = false;
62
- switch(intval($views_options['count'])) {
63
  case 0:
64
  $should_count = true;
65
  break;
66
  case 1:
67
- if(empty($_COOKIE[USER_COOKIE]) && intval($user_ID) == 0) {
68
  $should_count = true;
69
  }
70
  break;
71
  case 2:
72
- if(intval($user_ID) > 0) {
73
  $should_count = true;
74
  }
75
  break;
76
  }
77
- if(intval($views_options['exclude_bots']) == 1) {
78
  $bots = array
79
  (
80
  'Google Bot' => 'googlebot'
@@ -108,15 +109,15 @@ function process_postviews() {
108
  , 'Yandex' => 'yandex'
109
  );
110
  $useragent = $_SERVER['HTTP_USER_AGENT'];
111
- foreach ($bots as $name => $lookfor) {
112
- if (stristr($useragent, $lookfor) !== false) {
113
  $should_count = false;
114
  break;
115
  }
116
  }
117
  }
118
- if($should_count && (!defined('WP_CACHE') || !WP_CACHE)) {
119
- update_post_meta($id, 'views', ($post_views + 1));
120
  }
121
  }
122
  }
@@ -127,28 +128,35 @@ function process_postviews() {
127
  add_action('wp_enqueue_scripts', 'wp_postview_cache_count_enqueue');
128
  function wp_postview_cache_count_enqueue() {
129
  global $user_ID, $post;
130
- if (!wp_is_post_revision($post) && (is_single() || is_page())) {
131
- $views_options = get_option('views_options');
 
 
 
 
 
 
 
 
132
  $should_count = false;
133
- switch(intval($views_options['count'])) {
134
  case 0:
135
  $should_count = true;
136
  break;
137
  case 1:
138
- if (empty($_COOKIE[USER_COOKIE]) && intval($user_ID) == 0) {
139
  $should_count = true;
140
  }
141
  break;
142
  case 2:
143
- if (intval($user_ID) > 0) {
144
  $should_count = true;
145
  }
146
  break;
147
  }
148
- if ($should_count && defined('WP_CACHE') && WP_CACHE) {
149
- // Enqueue and localize script here
150
- wp_enqueue_script('wp-postviews-cache', plugins_url('postviews-cache.js', __FILE__), array('jquery'), '1.64', true);
151
- wp_localize_script('wp-postviews-cache', 'viewsCacheL10n', array('admin_ajax_url' => admin_url('admin-ajax.php', (is_ssl() ? 'https' : 'http')), 'post_id' => intval($post->ID)));
152
  }
153
  }
154
  }
@@ -723,21 +731,28 @@ function postviews_page_most_stats($content) {
723
 
724
 
725
  ### Function: Increment Post Views
726
- add_action('wp_ajax_postviews', 'increment_views');
727
- add_action('wp_ajax_nopriv_postviews', 'increment_views');
728
  function increment_views() {
729
- global $wpdb;
730
- if(!empty($_GET['postviews_id']))
731
- {
732
- $post_id = intval($_GET['postviews_id']);
733
- if($post_id > 0 && defined('WP_CACHE') && WP_CACHE) {
734
- $post_views = get_post_custom($post_id);
735
- $post_views = intval($post_views['views'][0]);
736
- update_post_meta($post_id, 'views', ($post_views + 1));
737
- echo ($post_views + 1);
738
- }
 
 
 
 
 
 
 
 
739
  }
740
- exit();
741
  }
742
 
743
  ### Function Show Post Views Column in WP-Admin
@@ -833,7 +848,6 @@ function sort_postviews($query) {
833
 
834
  // DIsplay Widget Control Form
835
  function form($instance) {
836
- global $wpdb;
837
  $instance = wp_parse_args((array) $instance, array('title' => __('Views', 'wp-postviews'), 'type' => 'most_viewed', 'mode' => 'both', 'limit' => 10, 'chars' => 200, 'cat_ids' => '0'));
838
  $title = esc_attr($instance['title']);
839
  $type = esc_attr($instance['type']);
@@ -906,6 +920,7 @@ function views_activation( $network_wide ) {
906
  , 'display_archive' => 0
907
  , 'display_search' => 0
908
  , 'display_other' => 0
 
909
  , 'template' => __('%VIEW_COUNT% views', 'wp-postviews')
910
  , 'most_viewed_template' => '<li><a href="%POST_URL%" title="%POST_TITLE%">%POST_TITLE%</a> - %VIEW_COUNT% '.__('views', 'wp-postviews').'</li>'
911
  );
3
  Plugin Name: WP-PostViews
4
  Plugin URI: http://lesterchan.net/portfolio/programming/php/
5
  Description: Enables you to display how many times a post/page had been viewed.
6
+ Version: 1.67
7
  Author: Lester 'GaMerZ' Chan
8
  Author URI: http://lesterchan.net
9
  Text Domain: wp-postviews
46
 
47
 
48
  ### Function: Calculate Post Views
49
+ add_action( 'wp_head', 'process_postviews' );
50
  function process_postviews() {
51
  global $user_ID, $post;
52
+ if( is_int( $post ) ) {
53
+ $post = get_post( $post );
54
+ }
55
+ if( !wp_is_post_revision( $post ) ) {
56
+ if( is_single() || is_page() ) {
57
+ $id = intval( $post->ID );
58
+ $views_options = get_option( 'views_options' );
59
+ if ( !$post_views = get_post_meta( $post->ID, 'views', true ) ) {
60
  $post_views = 0;
61
+ }
62
  $should_count = false;
63
+ switch( intval( $views_options['count'] ) ) {
64
  case 0:
65
  $should_count = true;
66
  break;
67
  case 1:
68
+ if(empty( $_COOKIE[USER_COOKIE] ) && intval( $user_ID ) === 0) {
69
  $should_count = true;
70
  }
71
  break;
72
  case 2:
73
+ if( intval( $user_ID ) > 0 ) {
74
  $should_count = true;
75
  }
76
  break;
77
  }
78
+ if( intval( $views_options['exclude_bots'] ) === 1 ) {
79
  $bots = array
80
  (
81
  'Google Bot' => 'googlebot'
109
  , 'Yandex' => 'yandex'
110
  );
111
  $useragent = $_SERVER['HTTP_USER_AGENT'];
112
+ foreach ( $bots as $name => $lookfor ) {
113
+ if ( stristr( $useragent, $lookfor ) !== false ) {
114
  $should_count = false;
115
  break;
116
  }
117
  }
118
  }
119
+ if( $should_count && ( ( isset( $views_options['use_ajax'] ) && intval( $views_options['use_ajax'] ) === 0 ) || ( !defined( 'WP_CACHE' ) || !WP_CACHE ) ) ) {
120
+ update_post_meta( $id, 'views', ( $post_views + 1 ) );
121
  }
122
  }
123
  }
128
  add_action('wp_enqueue_scripts', 'wp_postview_cache_count_enqueue');
129
  function wp_postview_cache_count_enqueue() {
130
  global $user_ID, $post;
131
+
132
+ if( !defined( 'WP_CACHE' ) || !WP_CACHE )
133
+ return;
134
+
135
+ $views_options = get_option( 'views_options' );
136
+
137
+ if( isset( $views_options['use_ajax'] ) && intval( $views_options['use_ajax'] ) === 0 )
138
+ return;
139
+
140
+ if ( !wp_is_post_revision( $post ) && ( is_single() || is_page() ) ) {
141
  $should_count = false;
142
+ switch( intval( $views_options['count'] ) ) {
143
  case 0:
144
  $should_count = true;
145
  break;
146
  case 1:
147
+ if ( empty( $_COOKIE[USER_COOKIE] ) && intval( $user_ID ) === 0) {
148
  $should_count = true;
149
  }
150
  break;
151
  case 2:
152
+ if ( intval( $user_ID ) > 0 ) {
153
  $should_count = true;
154
  }
155
  break;
156
  }
157
+ if ( $should_count ) {
158
+ wp_enqueue_script( 'wp-postviews-cache', plugins_url( 'postviews-cache.js', __FILE__ ), array( 'jquery' ), '1.67', true );
159
+ wp_localize_script( 'wp-postviews-cache', 'viewsCacheL10n', array( 'admin_ajax_url' => admin_url( 'admin-ajax.php', ( is_ssl() ? 'https' : 'http' ) ), 'post_id' => intval( $post->ID ) ) );
 
160
  }
161
  }
162
  }
731
 
732
 
733
  ### Function: Increment Post Views
734
+ add_action( 'wp_ajax_postviews', 'increment_views' );
735
+ add_action( 'wp_ajax_nopriv_postviews', 'increment_views' );
736
  function increment_views() {
737
+ if( empty( $_GET['postviews_id'] ) )
738
+ return;
739
+
740
+ if( !defined( 'WP_CACHE' ) || !WP_CACHE )
741
+ return;
742
+
743
+ $views_options = get_option( 'views_options' );
744
+
745
+ if( isset( $views_options['use_ajax'] ) && intval( $views_options['use_ajax'] ) === 0 )
746
+ return;
747
+
748
+ $post_id = intval( $_GET['postviews_id'] );
749
+ if( $post_id > 0 ) {
750
+ $post_views = get_post_custom( $post_id );
751
+ $post_views = intval( $post_views['views'][0] );
752
+ update_post_meta( $post_id, 'views', ( $post_views + 1 ) );
753
+ echo ( $post_views + 1 );
754
+ exit();
755
  }
 
756
  }
757
 
758
  ### Function Show Post Views Column in WP-Admin
848
 
849
  // DIsplay Widget Control Form
850
  function form($instance) {
 
851
  $instance = wp_parse_args((array) $instance, array('title' => __('Views', 'wp-postviews'), 'type' => 'most_viewed', 'mode' => 'both', 'limit' => 10, 'chars' => 200, 'cat_ids' => '0'));
852
  $title = esc_attr($instance['title']);
853
  $type = esc_attr($instance['type']);
920
  , 'display_archive' => 0
921
  , 'display_search' => 0
922
  , 'display_other' => 0
923
+ , 'use_ajax' => 1
924
  , 'template' => __('%VIEW_COUNT% views', 'wp-postviews')
925
  , 'most_viewed_template' => '<li><a href="%POST_URL%" title="%POST_TITLE%">%POST_TITLE%</a> - %VIEW_COUNT% '.__('views', 'wp-postviews').'</li>'
926
  );