WP-PostViews - Version 1.01

Version Description

Download this release

Release Info

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

Version 1.01

Files changed (2) hide show
  1. postviews.php +131 -0
  2. readme.html +312 -0
postviews.php ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.01
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) {
61
+ global $wpdb, $post;
62
+ $where = '';
63
+ if($mode == 'post') {
64
+ $where = 'post_status = \'publish\'';
65
+ } elseif($mode == 'page') {
66
+ $where = 'post_status = \'static\'';
67
+ } else {
68
+ $where = '(post_status = \'publish\' OR post_status = \'static\')';
69
+ }
70
+ $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");
71
+ if($most_viewed) {
72
+ if($chars > 0) {
73
+ foreach ($most_viewed as $post) {
74
+ $post_title = htmlspecialchars(stripslashes($post->post_title));
75
+ $post_views = intval($post->views);
76
+ $post_views = number_format($post_views);
77
+ echo "<li><a href=\"".get_permalink()."\">".snippet_chars($post_title, $chars)."</a> - $post_views ".__('Views')."</li>";
78
+ }
79
+ } else {
80
+ foreach ($most_viewed as $post) {
81
+ $post_title = htmlspecialchars(stripslashes($post->post_title));
82
+ $post_views = intval($post->views);
83
+ $post_views = number_format($post_views);
84
+ echo "<li><a href=\"".get_permalink()."\">$post_title</a> - $post_views ".__('Views')."</li>";
85
+ }
86
+ }
87
+ } else {
88
+ echo '<li>'.__('N/A').'</li>';
89
+ }
90
+ }
91
+ }
92
+
93
+
94
+ ### Added by Paolo Tagliaferri (http://www.vortexmind.net - webmaster@vortexmind.net)
95
+ function get_timespan_most_viewed($mode = '', $limit = 10,$days = 7) {
96
+ global $wpdb, $post;
97
+ $limit_date = current_time('timestamp') - ($days*86400);
98
+ $limit_date = date("Y-m-d H:i:s",$limit_date);
99
+ $where = '';
100
+ if($mode == 'post') {
101
+ $where = 'post_status = \'publish\'';
102
+ } elseif($mode == 'page') {
103
+ $where = 'post_status = \'static\'';
104
+ } else {
105
+ $where = '(post_status = \'publish\' OR post_status = \'static\')';
106
+ }
107
+ $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");
108
+ if($most_viewed) {
109
+ echo "<ul>";
110
+ foreach ($most_viewed as $post) {
111
+ $post_title = htmlspecialchars(stripslashes($post->post_title));
112
+ $post_views = intval($post->views);
113
+ $post_views = number_format($post_views);
114
+ echo "<li><a href=\"".get_permalink()."\">$post_title</a> - $post_views ".__('Views')."</li>";
115
+ }
116
+ echo "</ul>";
117
+ } else {
118
+ _e('N/A');
119
+ }
120
+ }
121
+
122
+
123
+ ### Function: Display Total Views
124
+ if(!function_exists('get_totalviews')) {
125
+ function get_totalviews() {
126
+ global $wpdb;
127
+ $total_views = $wpdb->get_var("SELECT SUM(CAST(meta_value AS UNSIGNED)) FROM $wpdb->postmeta WHERE meta_key = 'views'");
128
+ echo number_format($total_views);
129
+ }
130
+ }
131
+ ?>
readme.html ADDED
@@ -0,0 +1,312 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.01 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.01&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.01%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 July 2006</p>
214
+ <div class="SubSubTitle">Changelog</div>
215
+ <ul>
216
+ <li>
217
+ <b>Version 1.01 (01-07-2006)</b>
218
+ <ul>
219
+ <li>NEW: Added Get Total Views Function</li>
220
+ <li>FIXED: Modified Get Most Viewed Post Function</li>
221
+ </ul>
222
+ </li>
223
+ <li>
224
+ <b>Version 1.00 (01-03-2006)</b>
225
+ <ul>
226
+ <li>NEW: Initial Release</li>
227
+ </ul>
228
+ </li>
229
+ </ul>
230
+ </div>
231
+
232
+ <!-- Installation Instructions -->
233
+ <div id="Install" style="display: none;">
234
+ <div class="SubTitle">&raquo; Installation Instructions</div>
235
+ <ol>
236
+ <li>
237
+ Open <b>wp-content/plugins</b> Folder
238
+ </li>
239
+ <li>
240
+ Put:
241
+ <blockquote>File: postviews.php</blockquote>
242
+ </li>
243
+ <li>
244
+ <b>Activate</b> WP-PostViews Plugin
245
+ </li>
246
+ <li>
247
+ Refer To <b>Usage</b> For Further Instructions
248
+ </li>
249
+ </ol>
250
+ </div>
251
+
252
+ <!-- Upgrade Instructions -->
253
+ <div id="Upgrade" style="display: none;">
254
+ <div class="SubTitle">&raquo; Upgrade Instructions</div>
255
+ <div class="SubSubTitle">From v1.0x To v1.01</div>
256
+ <ol>
257
+ <li>
258
+ Open <b>wp-content/plugins</b> Folder
259
+ </li>
260
+ <li>
261
+ Overwrite:
262
+ <blockquote>File: postviews.php</blockquote>
263
+ </li>
264
+ </ol>
265
+ </div>
266
+
267
+ <!-- Usage Instructions -->
268
+ <div id="Usage" style="display: none;">
269
+ <div class="SubTitle">&raquo; Usage Instructions</div>
270
+ <div class="SubSubTitle">General Usage</div>
271
+ <ol>
272
+ <li>
273
+ Open <b>wp-content/themes/&lt;YOUR THEME NAME&gt;/index.php</b>
274
+ <p>You may place it in <b>single.php</b>, <b>post.php</b> or <b>page.php</b> also.</p>
275
+ </li>
276
+ <li>
277
+ Find:
278
+ <blockquote>
279
+ &lt;?php while (have_posts()) : the_post(); ?&gt;
280
+ </blockquote>
281
+ </li>
282
+ <li>
283
+ Add Anywhere Below It:
284
+ <blockquote>
285
+ &lt;?php if(function_exists('the_views')) { the_views(); } ?&gt;
286
+ </blockquote>
287
+ <p>The <b>first value</b> you pass in is the text for views.</p>
288
+ <p>Default: the_views('Views');</p>
289
+ </li>
290
+ </ol>
291
+ <div class="SubSubTitle">View Stats (Outside WP Loop)</div>
292
+ <ul>
293
+ <li>
294
+ To Display <b>Most Viewed Post</b>
295
+ </li>
296
+ <li>
297
+ Use:
298
+ <blockquote>
299
+ &lt;?php if (function_exists('get_most_viewed')): ?&gt;<br />
300
+ &nbsp;&nbsp;&nbsp;&lt;?php get_most_viewed(); ?&gt;<br />
301
+ &lt;?php endif; ?&gt;
302
+ </blockquote>
303
+ <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>
304
+ <p>Default: get_most_viewed('both', 10);</p>
305
+ </li>
306
+ </ul>
307
+ </div>
308
+ </div>
309
+ </div>
310
+ <p id="Copyright">WP-PostViews 1.01<br />Copyright &copy; 2006 Lester 'GaMerZ' Chan. All Rights Reserved.</p>
311
+ </body>
312
+ </html>