PluginProbe
WebberZone Top 10 — Popular Posts / 1.6
WebberZone Top 10 — Popular Posts v1.6
4.5.1 4.5.0 4.4.3 4.4.2 4.4.1 4.4.0 4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 trunk 1.0 1.0.1 1.1 1.2 1.3 1.4 1.4.1 1.5 1.5.1 1.5.2 1.5.3 1.6 1.6.1 All 117 releases
top-10 / admin.inc.php

admin.inc.php in WebberZone Top 10 — Popular Posts 1.6, at admin.inc.php

577 lines 24.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**********************************************************************
3 * Admin Page *
4 *********************************************************************/
5 if (!defined('ABSPATH')) die("Aren't you supposed to come here via WP-Admin?");
6 define('ALD_TPTN_DIR', dirname(__FILE__));
7 if (!defined('TPTN_LOCAL_NAME')) define('TPTN_LOCAL_NAME', 'tptn');
8
9 function tptn_options() {
10
11 global $wpdb;
12 $poststable = $wpdb->posts;
13
14 $tptn_settings = tptn_read_options();
15
16 if($_POST['tptn_save']){
17 $tptn_settings[title] = ($_POST['title']);
18 $tptn_settings[title_daily] = ($_POST['title_daily']);
19 $tptn_settings[daily_range] = intval($_POST['daily_range']);
20 $tptn_settings[limit] = intval($_POST['limit']);
21 $tptn_settings[count_disp_form] = ($_POST['count_disp_form']);
22 $tptn_settings[add_to_content] = (($_POST['add_to_content']) ? true : false);
23 $tptn_settings[exclude_pages] = (($_POST['exclude_pages']) ? true : false);
24 $tptn_settings[count_on_pages] = (($_POST['count_on_pages']) ? true : false);
25 $tptn_settings[track_authors] = (($_POST['track_authors']) ? true : false);
26 $tptn_settings[pv_in_admin] = (($_POST['pv_in_admin']) ? true : false);
27 $tptn_settings[disp_list_count] = (($_POST['disp_list_count']) ? true : false);
28 $tptn_settings[d_use_js] = (($_POST['d_use_js']) ? true : false);
29 $tptn_settings[show_credit] = (($_POST['show_credit']) ? true : false);
30
31 $tptn_settings[post_thumb_op] = $_POST['post_thumb_op'];
32 $tptn_settings[before_list] = $_POST['before_list'];
33 $tptn_settings[after_list] = $_POST['after_list'];
34 $tptn_settings[before_list_item] = $_POST['before_list_item'];
35 $tptn_settings[after_list_item] = $_POST['after_list_item'];
36 $tptn_settings[thumb_meta] = $_POST['thumb_meta'];
37 $tptn_settings[thumb_default] = $_POST['thumb_default'];
38 $tptn_settings[thumb_height] = intval($_POST['thumb_height']);
39 $tptn_settings[thumb_width] = intval($_POST['thumb_width']);
40 $tptn_settings[scan_images] = (($_POST['scan_images']) ? true : false);
41 $tptn_settings[show_excerpt] = (($_POST['show_excerpt']) ? true : false);
42 $tptn_settings[excerpt_length] = intval($_POST['excerpt_length']);
43
44 update_option('ald_tptn_settings', $tptn_settings);
45
46 $str = '<div id="message" class="updated fade"><p>'. __('Options saved successfully.',TPTN_LOCAL_NAME) .'</p></div>';
47 echo $str;
48 }
49
50 if ($_POST['tptn_default']){
51 delete_option('ald_tptn_settings');
52 $tptn_settings = tptn_default_options();
53 update_option('ald_tptn_settings', $tptn_settings);
54
55 $str = '<div id="message" class="updated fade"><p>'. __('Options set to Default.',TPTN_LOCAL_NAME) .'</p></div>';
56 echo $str;
57 }
58
59 if ($_POST['tptn_trunc_all']){
60 tptn_trunc_count(false);
61 $str = '<div id="message" class="updated fade"><p>'. __('Top 10 popular posts reset',TPTN_LOCAL_NAME) .'</p></div>';
62 echo $str;
63 }
64
65 if ($_POST['tptn_trunc_daily']){
66 tptn_trunc_count(true);
67 $str = '<div id="message" class="updated fade"><p>'. __('Top 10 daily popular posts reset',TPTN_LOCAL_NAME) .'</p></div>';
68 echo $str;
69 }
70 ?>
71
72 <div class="wrap">
73 <h2>Top 10</h2>
74 <div id="options-div">
75 <form method="post" id="tptn_options" name="tptn_options" style="border: #ccc 1px solid; padding: 10px">
76 <fieldset class="options">
77 <legend>
78 <h3>
79 <?php _e('Options:',TPTN_LOCAL_NAME); ?>
80 </h3>
81 </legend>
82 <p>
83 <label>
84 <?php _e('Format to display the count in: ',TPTN_LOCAL_NAME); ?><br />
85 <textarea name="count_disp_form" id="count_disp_form" cols="50" rows="5"><?php echo htmlspecialchars(stripslashes($tptn_settings[count_disp_form])); ?></textarea>
86 </label>
87 </p>
88 <p><?php _e('Use <code>%totalcount%</code> to display the total count and <code>%dailycount%</code> to display the daily count. e.g. the default options displays <code>(Visited 123 times, 23 visits today)</code>',TPTN_LOCAL_NAME); ?></p>
89 <p>
90 <label>
91 <?php _e('Number of popular posts to display: ',TPTN_LOCAL_NAME); ?>
92 <input type="textbox" name="limit" id="limit" value="<?php echo stripslashes($tptn_settings[limit]); ?>">
93 </label>
94 </p>
95 <p>
96 <label>
97 <?php _e('Daily Popular should contain views of how many days? ',TPTN_LOCAL_NAME); ?>
98 <input type="textbox" name="daily_range" id="daily_range" size="3" value="<?php echo stripslashes($tptn_settings[daily_range]); ?>">
99 </label>
100 </p>
101 <p>
102 <label>
103 <input type="checkbox" name="exclude_pages" id="exclude_pages" <?php if ($tptn_settings[exclude_pages]) echo 'checked="checked"' ?> />
104 <?php _e('Exclude Pages in display of Popular Posts? Number of views on Pages will continue to be counted.',TPTN_LOCAL_NAME); ?>
105 </label>
106 </p>
107 <p>
108 <label>
109 <input type="checkbox" name="add_to_content" id="add_to_content" <?php if ($tptn_settings[add_to_content]) echo 'checked="checked"' ?> />
110 <?php _e('Display number of views on posts?',TPTN_LOCAL_NAME); ?>
111 </label>
112 </p>
113 <p>
114 <label>
115 <input type="checkbox" name="count_on_pages" id="count_on_pages" <?php if ($tptn_settings[count_on_pages]) echo 'checked="checked"' ?> />
116 <?php _e('Display number of views on pages?',TPTN_LOCAL_NAME); ?>
117 </label>
118 </p>
119 <p>
120 <label>
121 <input type="checkbox" name="track_authors" id="track_authors" <?php if ($tptn_settings[track_authors]) echo 'checked="checked"' ?> />
122 <?php _e('Track visits of authors on their own posts?',TPTN_LOCAL_NAME); ?>
123 </label>
124 </p>
125 <p>
126 <label>
127 <input type="checkbox" name="disp_list_count" id="disp_list_count" <?php if ($tptn_settings[disp_list_count]) echo 'checked="checked"' ?> />
128 <?php _e('Display number of page views in popular lists?',TPTN_LOCAL_NAME); ?>
129 </label>
130 </p>
131 <p>
132 <label>
133 <input type="checkbox" name="d_use_js" id="d_use_js" <?php if ($tptn_settings[d_use_js]) echo 'checked="checked"' ?> />
134 <?php _e('Force daily posts\' list to be dynamic? This options uses JavaScript to load the post and can increase your page load time',TPTN_LOCAL_NAME); ?>
135 </label>
136 </p>
137 <p>
138 <label>
139 <input type="checkbox" name="pv_in_admin" id="pv_in_admin" <?php if ($tptn_settings[pv_in_admin]) echo 'checked="checked"' ?> />
140 <?php _e('Display page views on Edit posts/pages in WP-Admin? An extra column is added with the count',TPTN_LOCAL_NAME); ?>
141 </label>
142 </p>
143 <p>
144 <label>
145 <input type="checkbox" name="show_credit" id="show_credit" <?php if ($tptn_settings[show_credit]) echo 'checked="checked"' ?> />
146 <?php _e('A link to the plugin is added as an extra list item to the list of popular posts. Not mandatory, but thanks if you do it!',TPTN_LOCAL_NAME); ?>
147 </label>
148 </p>
149 <h4>
150 <?php _e('Output Options:',TPTN_LOCAL_NAME); ?>
151 </h4>
152 <p>
153 <label>
154 <?php _e('Title of popular posts: ',TPTN_LOCAL_NAME); ?>
155 <input type="textbox" name="title" id="title" value="<?php echo stripslashes($tptn_settings[title]); ?>">
156 </label>
157 </p>
158 <p>
159 <label>
160 <?php _e('Title of daily popular posts: ',TPTN_LOCAL_NAME); ?>
161 <input type="textbox" name="title_daily" id="title_daily" value="<?php echo stripslashes($tptn_settings[title_daily]); ?>">
162 </label>
163 </p>
164 <p>
165 <label>
166 <input type="checkbox" name="show_excerpt" id="show_excerpt" <?php if ($tptn_settings[show_excerpt]) echo 'checked="checked"' ?> />
167 <strong><?php _e('Show post excerpt in list?',TPTN_LOCAL_NAME); ?></strong>
168 </label>
169 </p>
170 <p>
171 <label>
172 <?php _e('Length of excerpt (in words): ',TPTN_LOCAL_NAME); ?>
173 <input type="textbox" name="excerpt_length" id="excerpt_length" value="<?php echo stripslashes($tptn_settings[excerpt_length]); ?>">
174 </label>
175 </p>
176 <h4><?php _e('Customize the output:',TPTN_LOCAL_NAME); ?></h4>
177 <p>
178 <label>
179 <?php _e('HTML to display before the list of posts: ',TPTN_LOCAL_NAME); ?>
180 <input type="textbox" name="before_list" id="before_list" value="<?php echo attribute_escape(stripslashes($tptn_settings[before_list])); ?>">
181 </label>
182 </p>
183 <p>
184 <label>
185 <?php _e('HTML to display before each list item: ',TPTN_LOCAL_NAME); ?>
186 <input type="textbox" name="before_list_item" id="before_list_item" value="<?php echo attribute_escape(stripslashes($tptn_settings[before_list_item])); ?>">
187 </label>
188 </p>
189 <p>
190 <label>
191 <?php _e('HTML to display after each list item: ',TPTN_LOCAL_NAME); ?>
192 <input type="textbox" name="after_list_item" id="after_list_item" value="<?php echo attribute_escape(stripslashes($tptn_settings[after_list_item])); ?>">
193 </label>
194 </p>
195 <p>
196 <label>
197 <?php _e('HTML to display after the list of posts: ',TPTN_LOCAL_NAME); ?>
198 <input type="textbox" name="after_list" id="after_list" value="<?php echo attribute_escape(stripslashes($tptn_settings[after_list])); ?>">
199 </label>
200 </p>
201 <h4><?php _e('Post thumbnail options:',TPTN_LOCAL_NAME); ?></h4>
202 <p>
203 <label>
204 <input type="radio" name="post_thumb_op" value="inline" id="post_thumb_op_0" <?php if ($tptn_settings['post_thumb_op']=='inline') echo 'checked="checked"' ?> />
205 <?php _e('Display thumbnails inline with posts',TPTN_LOCAL_NAME); ?></label>
206 <br />
207 <label>
208 <input type="radio" name="post_thumb_op" value="thumbs_only" id="post_thumb_op_1" <?php if ($tptn_settings['post_thumb_op']=='thumbs_only') echo 'checked="checked"' ?> />
209 <?php _e('Display only thumbnails, no text',TPTN_LOCAL_NAME); ?></label>
210 <br />
211 <label>
212 <input type="radio" name="post_thumb_op" value="text_only" id="post_thumb_op_2" <?php if ($tptn_settings['post_thumb_op']=='text_only') echo 'checked="checked"' ?> />
213 <?php _e('Do not display thumbnails, only text.',TPTN_LOCAL_NAME); ?></label>
214 <br />
215 </p>
216 <p>
217 <label>
218 <?php _e('Post thumbnail meta field (the meta should point contain the image source): ',TPTN_LOCAL_NAME); ?>
219 <input type="textbox" name="thumb_meta" id="thumb_meta" value="<?php echo attribute_escape(stripslashes($tptn_settings[thumb_meta])); ?>">
220 </label>
221 </p>
222 <p>
223 <label>
224 <input type="checkbox" name="scan_images" id="scan_images" <?php if ($tptn_settings[scan_images]) echo 'checked="checked"' ?> />
225 <?php _e('If the postmeta is not set, then should the plugin extract the first image from the post. This can slow down the loading of your post if the first image in the related posts is large in file-size',TPTN_LOCAL_NAME); ?>
226 </label>
227 </p>
228 <p><strong><?php _e('Thumbnail dimensions:',TPTN_LOCAL_NAME); ?></strong><br />
229 <label>
230 <?php _e('Max width: ',TPTN_LOCAL_NAME); ?>
231 <input type="textbox" name="thumb_width" id="thumb_width" value="<?php echo attribute_escape(stripslashes($tptn_settings[thumb_width])); ?>" style="width:30px">px
232 </label>
233 <br />
234 <label>
235 <?php _e('Max height: ',TPTN_LOCAL_NAME); ?>
236 <input type="textbox" name="thumb_height" id="thumb_height" value="<?php echo attribute_escape(stripslashes($tptn_settings[thumb_height])); ?>" style="width:30px">px
237 </label>
238 </p>
239 <p><?php _e('The plugin will first check if the post contains a thumbnail. If it doesn\'t then it will check the meta field. If this is not available, then it will show the default image as specified below:',TPTN_LOCAL_NAME); ?>
240 <input type="textbox" name="thumb_default" id="thumb_default" value="<?php echo attribute_escape(stripslashes($tptn_settings[thumb_default])); ?>" style="width:500px">
241 </p>
242 <p>
243 <input type="submit" name="tptn_save" id="tptn_save" value="Save Options" style="border:#0c0 1px solid" />
244 <input name="tptn_default" type="submit" id="tptn_default" value="Default Options" style="border:#f00 1px solid" onclick="if (!confirm('<?php _e('Do you want to set options to Default?',TPTN_LOCAL_NAME); ?>')) return false;" />
245 </p>
246 <h4>
247 <?php _e('Reset count',TPTN_LOCAL_NAME); ?>
248 </h4>
249 <p>
250 <?php _e('This cannot be reversed. Make sure that your database has been backed up before proceeding',TPTN_LOCAL_NAME); ?>
251 </p>
252 <p>
253 <input name="tptn_trunc_all" type="submit" id="tptn_trunc_all" value="Reset Popular Posts" style="border:#900 1px solid" onclick="if (!confirm('<?php _e('Are you sure you want to reset the popular posts?',TPTN_LOCAL_NAME); ?>')) return false;" />
254 <input name="tptn_trunc_daily" type="submit" id="tptn_trunc_daily" value="Reset Daily Popular Posts" style="border:#C00 1px solid" onclick="if (!confirm('<?php _e('Are you sure you want to reset the daily popular posts?',TPTN_LOCAL_NAME); ?>')) return false;" />
255 </p>
256 </fieldset>
257 </form>
258 </div>
259 <div id="side">
260 <div class="side-widget">
261 <span class="title"><?php _e('Quick links') ?></span>
262 <ul>
263 <li><a href="http://ajaydsouza.com/wordpress/plugins/top-10/"><?php _e('Top 10 ');_e('plugin page',TPTN_LOCAL_NAME) ?></a></li>
264 <li><a href="http://ajaydsouza.com/wordpress/plugins/"><?php _e('Other plugins',TPTN_LOCAL_NAME) ?></a></li>
265 <li><a href="http://ajaydsouza.com/"><?php _e('Ajay\'s blog',TPTN_LOCAL_NAME) ?></a></li>
266 <li><a href="http://ajaydsouza.org"><?php _e('Support forum',TPTN_LOCAL_NAME) ?></a></li>
267 <li><a href="http://twitter.com/ajaydsouza"><?php _e('Follow @ajaydsouza on Twitter',TPTN_LOCAL_NAME) ?></a></li>
268 </ul>
269 </div>
270 <div class="side-widget">
271 <span class="title"><?php _e('Recent developments',TPTN_LOCAL_NAME) ?></span>
272 <?php require_once(ABSPATH . WPINC . '/rss.php'); wp_widget_rss_output('http://ajaydsouza.com/archives/category/wordpress/plugins/feed/', array('items' => 5, 'show_author' => 0, 'show_date' => 1));
273 ?>
274 </div>
275 <div class="side-widget">
276 <span class="title"><?php _e('Support the development',TPTN_LOCAL_NAME) ?></span>
277 <div id="donate-form">
278 <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
279 <input type="hidden" name="cmd" value="_xclick">
280 <input type="hidden" name="business" value="KGVN7LJLLZCMY">
281 <input type="hidden" name="lc" value="IN">
282 <input type="hidden" name="item_name" value="Donation for Top 10">
283 <input type="hidden" name="item_number" value="crp">
284 <strong><?php _e('Enter amount in USD: ',TPTN_LOCAL_NAME) ?></strong> <input name="amount" value="10.00" size="6" type="text"><br />
285 <input type="hidden" name="currency_code" value="USD">
286 <input type="hidden" name="button_subtype" value="services">
287 <input type="hidden" name="bn" value="PP-BuyNowBF:btn_donate_LG.gif:NonHosted">
288 <input type="image" src="https://www.paypal.com/en_US/i/btn/btn_donate_LG.gif" border="0" name="submit" alt="<?php _e('Send your donation to the author of',TPTN_LOCAL_NAME) ?> Top 10?">
289 <img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
290 </form>
291 </div>
292 </div>
293 </div>
294
295 </div>
296
297 <?php
298
299 }
300
301 function tptn_manage() {
302 $paged = intval($_GET['paged']);
303 $limit = intval($_GET['limit']);
304 $daily = $_GET['daily'];
305
306 echo '<div class="wrap">';
307 echo '<h2>';
308 if (!$daily) _e('Popular Posts',TPTN_LOCAL_NAME); else _e('Daily Popular Posts',TPTN_LOCAL_NAME);
309 echo '</h2>';
310 echo '<div style="border: #ccc 1px solid; padding: 10px">';
311 echo tptn_pop_display($daily,$paged,$limit);
312 echo '</div></div>';
313 }
314
315 /* Add menu item in WP-Admin */
316 function tptn_adminmenu() {
317 if (function_exists('current_user_can')) {
318 // In WordPress 2.x
319 if (current_user_can('manage_options')) {
320 $tptn_is_admin = true;
321 }
322 } else {
323 // In WordPress 1.x
324 global $user_ID;
325 if (user_can_edit_user($user_ID, 0)) {
326 $tptn_is_admin = true;
327 }
328 }
329
330 if ((function_exists('add_options_page'))&&($tptn_is_admin)) {
331 $plugin_page = add_options_page(__("Top 10", TPTN_LOCAL_NAME), __("Top 10", TPTN_LOCAL_NAME), 9, 'tptn_options', 'tptn_options');
332 add_action( 'admin_head-'. $plugin_page, 'tptn_adminhead' );
333 add_posts_page(__("Popular Posts", TPTN_LOCAL_NAME), __("Top 10", TPTN_LOCAL_NAME), 9, 'tptn_manage', 'tptn_manage');
334 }
335 }
336 add_action('admin_menu', 'tptn_adminmenu');
337
338 function tptn_adminhead() {
339 global $tptn_url;
340
341 ?>
342 <link rel="stylesheet" type="text/css" href="<?php echo $tptn_url ?>/admin-styles.css" />
343 <?php }
344
345 /* Create a Dashboard Widget */
346 function tptn_pop_display($daily = false, $page = 0, $limit = 10) {
347 global $wpdb, $siteurl, $tableposts, $id;
348
349 $table_name = $wpdb->prefix . "top_ten";
350 if ($daily) $table_name .= "_daily"; // If we're viewing daily posts, set this to true
351
352 $tptn_settings = tptn_read_options();
353 if (!($limit)) $limit = $tptn_settings['limit'];
354 if (!($page)) $page = 0; // Default page value.
355
356 if(!$daily) {
357 $sql = "SELECT postnumber, cntaccess , ID, post_type ";
358 $sql .= "FROM $table_name INNER JOIN ". $wpdb->posts ." ON postnumber=ID " ;
359 if ($tptn_settings['exclude_pages']) $sql .= "AND post_type = 'post' ";
360 $sql .= "AND post_status = 'publish' ";
361 $sql .= "ORDER BY cntaccess DESC";
362 } else {
363 $daily_range = $tptn_settings[daily_range]-1;
364 $current_time = gmdate( 'Y-m-d', ( time() + ( get_option( 'gmt_offset' ) * 3600 ) ) );
365 $current_date = strtotime ( '-'.$daily_range. ' DAY' , strtotime ( $current_time ) );
366 $current_date = date ( 'Y-m-j' , $current_date );
367
368 $sql = "SELECT postnumber, SUM(cntaccess) as sumCount, dp_date, ID, post_type, post_status ";
369 $sql .= "FROM $table_name INNER JOIN ". $wpdb->posts ." ON postnumber=ID " ;
370 if ($tptn_settings['exclude_pages']) $sql .= "AND post_type = 'post' ";
371 $sql .= "AND post_status = 'publish' AND dp_date >= '$current_date' ";
372 $sql .= "GROUP BY postnumber ";
373 $sql .= "ORDER BY sumCount DESC";
374 }
375
376 $results = $wpdb->get_results($sql);
377 $numrows = 0;
378 if ($results) {
379 foreach ($results as $result) {
380 $numrows++;
381 }
382 }
383
384 $pages = intval($numrows/$limit); // Number of results pages.
385
386 // $pages now contains int of pages, unless there is a remainder from division.
387
388 if ($numrows % $limit) {$pages++;} // has remainder so add one page
389
390 $current = ($page/$limit) + 1; // Current page number.
391
392 if (($pages < 1) || ($pages == 0)) {$total = 1;} // If $pages is less than one or equal to 0, total pages is 1.
393 else { $total = $pages;} // Else total pages is $pages value.
394
395 $first = $page + 1; // The first result.
396
397 if (!((($page + $limit) / $limit) >= $pages) && $pages != 1) {$last = $page + $limit;} //If not last results page, last result equals $page plus $limit.
398 else{$last = $numrows;} // If last results page, last result equals total number of results.
399
400 if(!$daily) {
401 $sql = "SELECT postnumber, cntaccess , ID, post_type ";
402 $sql .= "FROM $table_name INNER JOIN ". $wpdb->posts ." ON postnumber=ID " ;
403 if ($tptn_settings['exclude_pages']) $sql .= "AND post_type = 'post' ";
404 $sql .= "AND post_status = 'publish' ";
405 $sql .= "ORDER BY cntaccess DESC LIMIT $page, $limit";
406 } else {
407 $sql = "SELECT postnumber, SUM(cntaccess) as sumCount, dp_date, ID, post_type, post_status ";
408 $sql .= "FROM $table_name INNER JOIN ". $wpdb->posts ." ON postnumber=ID " ;
409 if ($tptn_settings['exclude_pages']) $sql .= "AND post_type = 'post' ";
410 $sql .= "AND post_status = 'publish' AND dp_date >= '$current_date' ";
411 $sql .= "GROUP BY postnumber ";
412 $sql .= "ORDER BY sumCount DESC LIMIT $page, $limit";
413 }
414
415 $results = $wpdb->get_results($sql);
416
417 $output = '<div id="tptn_popular_posts">';
418 $output .= '<table width="100%" border="0">
419 <tr>
420 <td width="50%" align="left">';
421 $output .= __('Results',TPTN_LOCAL_NAME);
422 $output .= ' <strong>'.$first.'</strong> - <strong>'.$last.'</strong> ';
423 $output .= __('of',TPTN_LOCAL_NAME);
424 $output .= ' <strong>'.$numrows.'</strong>
425 </td>
426 <td width="50%" align="right">';
427 $output .= __('Page',TPTN_LOCAL_NAME);
428 $output .= ' <strong>'.$current.'</strong> ';
429 $output .= __('of',TPTN_LOCAL_NAME);
430 $output .= ' <strong>'.$total.'</strong>
431 </td>
432 </tr>
433 <tr>
434 <td colspan="2" align="right">&nbsp;</td>
435 </tr>
436 <tr>
437 <td align="left">';
438
439 if(!$daily) {
440 $output .= '<a href="./edit.php?page=tptn_manage&daily=1">';
441 $output .= __('View Daily Popular Posts',TPTN_LOCAL_NAME);
442 $output .= '</a></td>';
443 } else {
444 $output .= '<a href="./edit.php?page=tptn_manage&daily=0">';
445 $output .= __('View Overall Popular Posts',TPTN_LOCAL_NAME);
446 $output .= '</a></td>';
447 }
448 $output .= '<td align="right">';
449 $output .= __('Results per-page:',TPTN_LOCAL_NAME);
450 $output .= ' <a href="./edit.php?page=tptn_manage&daily='.$daily.'&limit=10">10</a> | <a href="./edit.php?page=tptn_manage&daily='.$daily.'&limit=20">20</a> | <a href="./edit.php?page=tptn_manage&daily='.$daily.'&limit=50">50</a> | <a href="./edit.php?page=tptn_manage&daily='.$daily.'&limit=100">100</a>
451 </td>
452 </tr>
453 <tr>
454 <td colspan="2" align="right"><hr /></td>
455 </tr>
456 </table>';
457
458
459 $output .= '<ul>';
460 if ($results) {
461 foreach ($results as $result) {
462 $output .= '<li><a href="'.get_permalink($result->postnumber).'">'.get_the_title($result->postnumber).'</a>';
463 if ($daily) $output .= ' ('.$result->sumCount.')'; else $output .= ' ('.$result->cntaccess.')';
464 $output .= '</li>';
465 }
466 }
467 $output .= '</ul>';
468
469 $output .= '<p align="center">';
470 if ($page != 0) { // Don't show back link if current page is first page.
471 $back_page = $page - $limit;
472 $output .= "<a href=\"./edit.php?page=tptn_manage&paged=$back_page&daily=$daily&limit=$limit\">&laquo; ";
473 $output .= __('Previous',TPTN_LOCAL_NAME);
474 $output .= "</a>\n";
475 }
476
477 for ($i=1; $i <= $pages; $i++) // loop through each page and give link to it.
478 {
479 $ppage = $limit*($i - 1);
480 if ($ppage == $page){
481 $output .= "<b>$i</b>\n";
482 } // If current page don't give link, just text.
483 else{
484 $output .= "<a href=\"./edit.php?page=tptn_manage&paged=$ppage&daily=$daily&limit=$limit\">$i</a> \n";
485 }
486 }
487
488 if (!((($page+$limit) / $limit) >= $pages) && $pages != 1) { // If last page don't give next link.
489 $next_page = $page + $limit;
490 $output .= "<a href=\"./edit.php?page=tptn_manage&paged=$next_page&daily=$daily&limit=$limit\">";
491 $output .= __('Next',TPTN_LOCAL_NAME);
492 $output .= " &raquo;</a>";
493 }
494 $output .= '</p>';
495 $output .= '<p style="text-align:center;border-top: #000 1px solid">Popular posts by <a href="http://ajaydsouza.com/wordpress/plugins/top-10/">Top 10 plugin</a></p>';
496 $output .= '</div>';
497
498 return $output;
499
500 }
501
502 // Dashboard for Popular Posts
503 function tptn_pop_dashboard() {
504 echo tptn_pop_display(false,0,10);
505 }
506 // Dashboard for Daily Popular Posts
507 function tptn_pop_daily_dashboard() {
508 echo tptn_pop_display(true,0,10);
509 }
510
511 function tptn_pop_dashboard_setup() {
512 if (function_exists('wp_add_dashboard_widget')) {
513 wp_add_dashboard_widget( 'tptn_pop_dashboard', __( 'Popular Posts',TPTN_LOCAL_NAME ), 'tptn_pop_dashboard' );
514 wp_add_dashboard_widget( 'tptn_pop_daily_dashboard', __( 'Daily Popular',TPTN_LOCAL_NAME ), 'tptn_pop_daily_dashboard' );
515 }
516 }
517 add_action('wp_dashboard_setup', 'tptn_pop_dashboard_setup');
518
519
520 /* Display page views on the Edit Posts / Pages screen */
521 // Add an extra column
522 function tptn_column($cols) {
523 $tptn_settings = tptn_read_options();
524
525 if ($tptn_settings[pv_in_admin]) $cols['tptn'] = __('Total / Today\'s Views',TPTN_LOCAL_NAME);
526 return $cols;
527 }
528
529 // Display page views for each column
530 function tptn_value($column_name, $id) {
531 $tptn_settings = tptn_read_options();
532 if (($column_name == 'tptn')&&($tptn_settings[pv_in_admin])) {
533 global $wpdb;
534
535 $table_name = $wpdb->prefix . "top_ten";
536
537 $resultscount = $wpdb->get_row("select postnumber, cntaccess from $table_name WHERE postnumber = $id");
538 $cntaccess = number_format((($resultscount) ? $resultscount->cntaccess : 0));
539
540 $cntaccess .= ' / ';
541
542 // Now process daily count
543 $table_name = $wpdb->prefix . "top_ten_daily";
544
545 $daily_range = $tptn_settings[daily_range]-1;
546 $current_time = gmdate( 'Y-m-d', ( time() + ( get_option( 'gmt_offset' ) * 3600 ) ) );
547 $current_date = strtotime ( '-'.$daily_range. ' DAY' , strtotime ( $current_time ) );
548 $current_date = date ( 'Y-m-j' , $current_date );
549
550 $resultscount = $wpdb->get_row("SELECT postnumber, SUM(cntaccess) as sumCount FROM $table_name WHERE postnumber = $id AND dp_date >= '$current_date' GROUP BY postnumber ");
551 $cntaccess .= number_format((($resultscount) ? $resultscount->sumCount : 0));
552
553 echo $cntaccess;
554 }
555 }
556
557 // Output CSS for width of new column
558 function tptn_css() {
559 ?>
560 <style type="text/css">
561 #tptn { width: 50px; }
562 </style>
563 <?php
564 }
565
566 // Actions/Filters for various tables and the css output
567 add_filter('manage_posts_columns', 'tptn_column');
568 add_action('manage_posts_custom_column', 'tptn_value', 10, 2);
569 add_filter('manage_pages_columns', 'tptn_column');
570 add_action('manage_pages_custom_column', 'tptn_value', 10, 2);
571 add_filter('manage_media_columns', 'tptn_column');
572 add_action('manage_media_custom_column', 'tptn_value', 10, 2);
573 add_filter('manage_link-manager_columns', 'tptn_column');
574 add_action('manage_link_custom_column', 'tptn_value', 10, 2);
575 add_action('admin_head', 'tptn_css');
576
577 ?>