WP-PostViews - Version 1.02

Version Description

Download this release

Release Info

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

Version 1.02

Files changed (2) hide show
  1. postviews.php +141 -0
  2. readme.html +318 -0
postviews.php ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: WP-PostViews
4
+ Plugin URI: http://www.lesterchan.net/portfolio/programming.php
5
+ Description: Enables You To Display How Many Time A Post Had Been Viewed.
6
+ Version: 1.02
7
+ Author: GaMerZ
8
+ Author URI: http://www.lesterchan.net
9
+ */
10
+
11
+
12
+ /* Copyright 2006 Lester Chan (email : gamerz84@hotmail.com)
13
+
14
+ This program is free software; you can redistribute it and/or modify
15
+ it under the terms of the GNU General Public License as published by
16
+ the Free Software Foundation; either version 2 of the License, or
17
+ (at your option) any later version.
18
+
19
+ This program is distributed in the hope that it will be useful,
20
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
21
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
+ GNU General Public License for more details.
23
+
24
+ You should have received a copy of the GNU General Public License
25
+ along with this program; if not, write to the Free Software
26
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27
+ */
28
+
29
+
30
+ ### Function: Calculate Post Views
31
+ add_action('loop_start', 'process_postviews');
32
+ function process_postviews() {
33
+ global $id;
34
+ $post_views = intval(post_custom('views'));
35
+ if(empty($_COOKIE[USER_COOKIE])) {
36
+ if(is_single() || is_page()) {
37
+ if($post_views > 0) {
38
+ update_post_meta($id, 'views', ($post_views+1));
39
+ } else {
40
+ add_post_meta($id, 'views', 1);
41
+ }
42
+ }
43
+ }
44
+ }
45
+
46
+
47
+ ### Function: Display The Post Views
48
+ function the_views($text_views = 'Views', $display = true) {
49
+ $post_views = intval(post_custom('views'));
50
+ if($display) {
51
+ echo number_format($post_views).' '.$text_views;
52
+ } else {
53
+ return $post_views;
54
+ }
55
+ }
56
+
57
+
58
+ ### Function: Display Most Viewed Page/Post
59
+ if(!function_exists('get_most_viewed')) {
60
+ function get_most_viewed($mode = '', $limit = 10, $chars = 0, $display = true) {
61
+ global $wpdb, $post;
62
+ $where = '';
63
+ $temp = '';
64
+ if($mode == 'post') {
65
+ $where = 'post_status = \'publish\'';
66
+ } elseif($mode == 'page') {
67
+ $where = 'post_status = \'static\'';
68
+ } else {
69
+ $where = '(post_status = \'publish\' OR post_status = \'static\')';
70
+ }
71
+ $most_viewed = $wpdb->get_results("SELECT $wpdb->posts.ID, post_title, post_name, post_status, post_date, CAST(meta_value AS UNSIGNED) AS views FROM $wpdb->posts LEFT JOIN $wpdb->postmeta ON $wpdb->postmeta.post_id = $wpdb->posts.ID WHERE post_date < '".current_time('mysql')."' AND $where AND meta_key = 'views' AND post_password = '' ORDER BY views DESC LIMIT $limit");
72
+ if($most_viewed) {
73
+ if($chars > 0) {
74
+ foreach ($most_viewed as $post) {
75
+ $post_title = htmlspecialchars(stripslashes($post->post_title));
76
+ $post_views = intval($post->views);
77
+ $post_views = number_format($post_views);
78
+ $temp .= "<li><a href=\"".get_permalink()."\">".snippet_chars($post_title, $chars)."</a> - $post_views ".__('Views')."</li>\n";
79
+ }
80
+ } else {
81
+ foreach ($most_viewed as $post) {
82
+ $post_title = htmlspecialchars(stripslashes($post->post_title));
83
+ $post_views = intval($post->views);
84
+ $post_views = number_format($post_views);
85
+ $temp .= "<li><a href=\"".get_permalink()."\">$post_title</a> - $post_views ".__('Views')."</li>\n";
86
+ }
87
+ }
88
+ } else {
89
+ $temp = '<li>'.__('N/A').'</li>'."\n";
90
+ }
91
+ if($display) {
92
+ echo $temp;
93
+ } else {
94
+ return $temp;
95
+ }
96
+ }
97
+ }
98
+
99
+
100
+ ### Added by Paolo Tagliaferri (http://www.vortexmind.net - webmaster@vortexmind.net)
101
+ function get_timespan_most_viewed($mode = '', $limit = 10, $days = 7) {
102
+ global $wpdb, $post;
103
+ $limit_date = current_time('timestamp') - ($days*86400);
104
+ $limit_date = date("Y-m-d H:i:s",$limit_date);
105
+ $where = '';
106
+ if($mode == 'post') {
107
+ $where = 'post_status = \'publish\'';
108
+ } elseif($mode == 'page') {
109
+ $where = 'post_status = \'static\'';
110
+ } else {
111
+ $where = '(post_status = \'publish\' OR post_status = \'static\')';
112
+ }
113
+ $most_viewed = $wpdb->get_results("SELECT $wpdb->posts.ID, post_title, post_name, post_status, post_date, CAST(meta_value AS UNSIGNED) AS views FROM $wpdb->posts LEFT JOIN $wpdb->postmeta ON $wpdb->postmeta.post_id = $wpdb->posts.ID WHERE post_date < '".current_time('mysql')."' AND post_date > '".$limit_date."' AND $where AND meta_key = 'views' AND post_password = '' ORDER BY views DESC LIMIT $limit");
114
+ if($most_viewed) {
115
+ echo "<ul>";
116
+ foreach ($most_viewed as $post) {
117
+ $post_title = htmlspecialchars(stripslashes($post->post_title));
118
+ $post_views = intval($post->views);
119
+ $post_views = number_format($post_views);
120
+ echo "<li><a href=\"".get_permalink()."\">$post_title</a> - $post_views ".__('Views')."</li>";
121
+ }
122
+ echo "</ul>";
123
+ } else {
124
+ _e('N/A');
125
+ }
126
+ }
127
+
128
+
129
+ ### Function: Display Total Views
130
+ if(!function_exists('get_totalviews')) {
131
+ function get_totalviews($display = true) {
132
+ global $wpdb;
133
+ $total_views = $wpdb->get_var("SELECT SUM(CAST(meta_value AS UNSIGNED)) FROM $wpdb->postmeta WHERE meta_key = 'views'");
134
+ if($display) {
135
+ echo number_format($total_views);
136
+ } else {
137
+ return number_format($total_views);
138
+ }
139
+ }
140
+ }
141
+ ?>
readme.html ADDED
@@ -0,0 +1,318 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
5
+ <title>WP-PostViews 1.02 Readme</title>
6
+ <style type="text/css" media="screen">
7
+ /* Default Style */
8
+ BODY {
9
+ font-family: Verdana, Arial;
10
+ font-size: 12px;
11
+ color: #000000;
12
+ background: #FFFFFF;
13
+ }
14
+ P {
15
+ padding-left: 10px;
16
+ }
17
+ BLOCKQUOTE {
18
+ margin: 10px 20px 0px 20px;
19
+ padding: 10px;
20
+ border: 1px solid #8d8d8d;
21
+ background-color: #f5f5f5;
22
+ }
23
+ LI {
24
+ margin-top: 20px;
25
+ }
26
+ UL LI UL LI {
27
+ margin-top: 10px;
28
+ }
29
+ A, A:active, A:link, A:visited {
30
+ color: #2d3a4c;
31
+ text-decoration: none;
32
+ }
33
+ A:hover {
34
+ color: #5577a5;
35
+ text-decoration: underline;
36
+ }
37
+ /* Place Holder Style */
38
+ #Container {
39
+ width: 780px;
40
+ margin-left: auto;
41
+ margin-right: auto;
42
+ }
43
+ #Content {
44
+ background-color: #fafafa;
45
+ border: 1px solid #a2b6cb;
46
+ padding: 10px;
47
+ margin-top: -13px;
48
+ }
49
+ /* Title Style */
50
+ #Title {
51
+ font-family: Verdana, Arial;
52
+ font-size: 22px;
53
+ font-weight: bold;
54
+ color: #389aff;
55
+ border-bottom: 1px solid #389aff;
56
+ margin-bottom: 10px;
57
+ }
58
+ .SubTitle {
59
+ font-family: Verdana, Arial;
60
+ font-size: 18px;
61
+ font-weight: bold;
62
+ color: #5b87b4;
63
+ }
64
+ .SubSubTitle {
65
+ font-family: Verdana, Arial;
66
+ font-size: 14px;
67
+ font-weight: bold;
68
+ color: #73a4d6;
69
+ }
70
+ /* Tabs */
71
+ UL#Tabs {
72
+ font-family: Verdana, Arial;
73
+ font-size: 12px;
74
+ font-weight: bold;
75
+ list-style-type: none;
76
+ padding-bottom: 28px;
77
+ border-bottom: 1px solid #a2b6cb;
78
+ margin-bottom: 12px;
79
+ z-index: 1;
80
+ }
81
+ #Tabs LI.Tab {
82
+ float: right;
83
+ height: 25px;
84
+ background-color: #deedfb;
85
+ margin: 2px 0px 0px 5px;
86
+ border: 1px solid #a2b6cb;
87
+ }
88
+ #Tabs LI.Tab A {
89
+ float: left;
90
+ display: block;
91
+ color: #666666;
92
+ text-decoration: none;
93
+ padding: 5px;
94
+ }
95
+ #Tabs LI.Tab A:hover {
96
+ background-color: #bfe0fe;
97
+ border-bottom: 1px solid #bfe0fe;
98
+ }
99
+ /* Selected Tab */
100
+ #Tabs LI.SelectedTab {
101
+ float: right;
102
+ height: 25px;
103
+ background-color: #fafafa;
104
+ margin: 2px 0px 0px 5px;
105
+ border-top: 1px solid #a2b6cb;
106
+ border-right: 1px solid #a2b6cb;
107
+ border-bottom: 1px solid #fafafa;
108
+ border-left: 1px solid #a2b6cb;
109
+ }
110
+ #Tabs LI.SelectedTab A {
111
+ float: left;
112
+ display: block;
113
+ color: #666666;
114
+ text-decoration: none;
115
+ padding: 5px;
116
+ cursor: default;
117
+ }
118
+ /* Copyright */
119
+ #Copyright {
120
+ text-align: center;
121
+ }
122
+ </style>
123
+ <script type="text/javascript">
124
+ // Index Page
125
+ function index() {
126
+ // Tab
127
+ document.getElementById('IndexTab').className = 'SelectedTab';
128
+ document.getElementById('InstallTab').className = 'Tab';
129
+ document.getElementById('UpgradeTab').className = 'Tab';
130
+ document.getElementById('UsageTab').className = 'Tab';
131
+ // Page
132
+ document.getElementById('Index').style.display= 'block';
133
+ document.getElementById('IndexTab').className = 'SelectedTab';
134
+ document.getElementById('Install').style.display = 'none';
135
+ document.getElementById('Upgrade').style.display = 'none';
136
+ document.getElementById('Usage').style.display = 'none';
137
+ }
138
+ // Installation Page
139
+ function install() {
140
+ // Tab
141
+ document.getElementById('IndexTab').className = 'Tab';
142
+ document.getElementById('InstallTab').className = 'SelectedTab';
143
+ document.getElementById('UpgradeTab').className = 'Tab';
144
+ document.getElementById('UsageTab').className = 'Tab';
145
+ // Page
146
+ document.getElementById('Index').style.display= 'none';
147
+ document.getElementById('Install').style.display = 'block';
148
+ document.getElementById('Upgrade').style.display = 'none';
149
+ document.getElementById('Usage').style.display = 'none';
150
+ }
151
+ // Upgrade Page
152
+ function upgrade() {
153
+ // Tab
154
+ document.getElementById('IndexTab').className = 'Tab';
155
+ document.getElementById('InstallTab').className = 'Tab';
156
+ document.getElementById('UpgradeTab').className = 'SelectedTab';
157
+ document.getElementById('UpgradeTab').href = 'Tab';
158
+ document.getElementById('UsageTab').className = 'Tab';
159
+ // Page
160
+ document.getElementById('Index').style.display= 'none';
161
+ document.getElementById('Install').style.display = 'none';
162
+ document.getElementById('Upgrade').style.display = 'block';
163
+ document.getElementById('Usage').style.display = 'none';
164
+ }
165
+ // Usage Page
166
+ function usage() {
167
+ // Tab
168
+ document.getElementById('IndexTab').className = 'Tab';
169
+ document.getElementById('InstallTab').className = 'Tab';
170
+ document.getElementById('UpgradeTab').className = 'Tab';
171
+ document.getElementById('UsageTab').className = 'SelectedTab';
172
+ // Page
173
+ document.getElementById('Index').style.display= 'none';
174
+ document.getElementById('Install').style.display = 'none';
175
+ document.getElementById('Upgrade').style.display = 'none';
176
+ document.getElementById('Usage').style.display = 'block';
177
+ }
178
+ </script>
179
+ </head>
180
+ <body>
181
+ <div id="Container">
182
+ <!-- Title -->
183
+ <div id="Title">WP-PostViews 1.02&nbsp;&nbsp;&nbsp;<span style="color: #aaaaaa;">Readme</span></div>
184
+
185
+ <!-- Tabs -->
186
+ <ul id="Tabs">
187
+ <li id="UsageTab" class="Tab"><a href="#Usage" onclick="usage(); return false;" title="Usage Instructions">Usage</a></li>
188
+ <li id="UpgradeTab" class="Tab"><a href="#Upgrade" onclick="upgrade(); return false;" title="Upgrade Instructions">Upgrade</a></li>
189
+ <li id="InstallTab" class="Tab"><a href="#Installation" onclick="install(); return false;" title="Installation Instructions">Installation</a></li>
190
+ <li id="IndexTab" class="SelectedTab"><a href="#Index" onclick="index(); return false;" title="Index Instructions">Index</a></li>
191
+ </ul>
192
+
193
+ <!-- Content -->
194
+ <div id="Content">
195
+ <!-- Index -->
196
+ <div id="Index">
197
+ <div class="SubTitle">&raquo; Index</div>
198
+ <div class="SubSubTitle">Plugin Information</div>
199
+ <p><b>Author</b><br /><b>&raquo;</b> Lester 'GaMerZ' Chan</p>
200
+ <p>
201
+ <b>EMail:</b><br /><b>&raquo;</b>
202
+ <script type="text/javascript">
203
+ /* <![CDATA[*/
204
+ document.write(' <a href="mailto:gamerz84@hotmail.com?Subject=WP-PostViews%201.02%20Support" title="EMail To gamerz84@hotmail.com">gamerz84@hotmail.com</a>');
205
+ /* ]]> */
206
+ </script>
207
+ </p>
208
+ <p><b>Website:</b><br /><b>&raquo;</b> <a href="http://www.lesterchan.net/" title="http://www.lesterchan.net/">http://www.lesterchan.net/</a></p>
209
+ <p><b>Demo:</b><br /><b>&raquo;</b> <a href="http://www.lesterchan.net/blogs" title="http://www.lesterchan.net/blogs">http://www.lesterchan.net/blogs</a></p>
210
+ <p><b>Documentation:</b><br /><b>&raquo;</b> <a href="http://dev.wp-plugins.org/wiki/wp-postviews" title="http://dev.wp-plugins.org/wiki/wp-postviews">http://dev.wp-plugins.org/wiki/wp-postviews</a></p>
211
+ <p><b>Development:</b><br /><b>&raquo;</b> <a href="http://dev.wp-plugins.org/browser/wp-postviews/" title="http://dev.wp-plugins.org/browser/wp-postviews/">http://dev.wp-plugins.org/browser/wp-postviews/</a></p>
212
+ <p><b>Support Forums:</b><br /><b>&raquo;</b> <a href="http://forums.lesterchan.net/viewforum.php?f=23" title="http://forums.lesterchan.net/viewforum.php?f=23">http://forums.lesterchan.net/viewforum.php?f=23</a></p>
213
+ <p><b>Updated:</b><br /><b>&raquo;</b> 1st October 2006</p>
214
+ <div class="SubSubTitle">Changelog</div>
215
+ <ul>
216
+ <li>
217
+ <b>Version 1.02 (01-10-2006)</b>
218
+ <ul>
219
+ <li>NEW: Change In get_most_viewed() To Accommodate Latest Version Of WP-Stats</li>
220
+ </ul>
221
+ </li>
222
+ <li>
223
+ <b>Version 1.01 (01-07-2006)</b>
224
+ <ul>
225
+ <li>NEW: Added Get Total Views Function</li>
226
+ <li>FIXED: Modified Get Most Viewed Post Function</li>
227
+ </ul>
228
+ </li>
229
+ <li>
230
+ <b>Version 1.00 (01-03-2006)</b>
231
+ <ul>
232
+ <li>NEW: Initial Release</li>
233
+ </ul>
234
+ </li>
235
+ </ul>
236
+ </div>
237
+
238
+ <!-- Installation Instructions -->
239
+ <div id="Install" style="display: none;">
240
+ <div class="SubTitle">&raquo; Installation Instructions</div>
241
+ <ol>
242
+ <li>
243
+ Open <b>wp-content/plugins</b> Folder
244
+ </li>
245
+ <li>
246
+ Put:
247
+ <blockquote>File: postviews.php</blockquote>
248
+ </li>
249
+ <li>
250
+ <b>Activate</b> WP-PostViews Plugin
251
+ </li>
252
+ <li>
253
+ Refer To <b>Usage</b> For Further Instructions
254
+ </li>
255
+ </ol>
256
+ </div>
257
+
258
+ <!-- Upgrade Instructions -->
259
+ <div id="Upgrade" style="display: none;">
260
+ <div class="SubTitle">&raquo; Upgrade Instructions</div>
261
+ <div class="SubSubTitle">From v1.0x To v1.02</div>
262
+ <ol>
263
+ <li>
264
+ Open <b>wp-content/plugins</b> Folder
265
+ </li>
266
+ <li>
267
+ Overwrite:
268
+ <blockquote>File: postviews.php</blockquote>
269
+ </li>
270
+ </ol>
271
+ </div>
272
+
273
+ <!-- Usage Instructions -->
274
+ <div id="Usage" style="display: none;">
275
+ <div class="SubTitle">&raquo; Usage Instructions</div>
276
+ <div class="SubSubTitle">General Usage</div>
277
+ <ol>
278
+ <li>
279
+ Open <b>wp-content/themes/&lt;YOUR THEME NAME&gt;/index.php</b>
280
+ <p>You may place it in <b>single.php</b>, <b>post.php</b> or <b>page.php</b> also.</p>
281
+ </li>
282
+ <li>
283
+ Find:
284
+ <blockquote>
285
+ &lt;?php while (have_posts()) : the_post(); ?&gt;
286
+ </blockquote>
287
+ </li>
288
+ <li>
289
+ Add Anywhere Below It:
290
+ <blockquote>
291
+ &lt;?php if(function_exists('the_views')) { the_views(); } ?&gt;
292
+ </blockquote>
293
+ <p>The <b>first value</b> you pass in is the text for views.</p>
294
+ <p>Default: the_views('Views');</p>
295
+ </li>
296
+ </ol>
297
+ <div class="SubSubTitle">View Stats (Outside WP Loop)</div>
298
+ <ul>
299
+ <li>
300
+ To Display <b>Most Viewed Post</b>
301
+ </li>
302
+ <li>
303
+ Use:
304
+ <blockquote>
305
+ &lt;?php if (function_exists('get_most_viewed')): ?&gt;<br />
306
+ &nbsp;&nbsp;&nbsp;&lt;?php get_most_viewed(); ?&gt;<br />
307
+ &lt;?php endif; ?&gt;
308
+ </blockquote>
309
+ <p>The <b>first value</b> you pass in is what you want to get, 'post', 'page' or 'both'. The <b>second value</b> you pass in is the number of post you want to get.</p>
310
+ <p>Default: get_most_viewed('both', 10);</p>
311
+ </li>
312
+ </ul>
313
+ </div>
314
+ </div>
315
+ </div>
316
+ <p id="Copyright">WP-PostViews 1.02<br />Copyright &copy; 2006 Lester 'GaMerZ' Chan. All Rights Reserved.</p>
317
+ </body>
318
+ </html>