PluginProbe
WebberZone Top 10 — Popular Posts / 1.5.2
WebberZone Top 10 — Popular Posts v1.5.2
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.5.2, at admin.inc.php

520 lines 22.2 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] = ($_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
41 update_option('ald_tptn_settings', $tptn_settings);
42
43 $str = '<div id="message" class="updated fade"><p>'. __('Options saved successfully.',TPTN_LOCAL_NAME) .'</p></div>';
44 echo $str;
45 }
46
47 if ($_POST['tptn_default']){
48 delete_option('ald_tptn_settings');
49 $tptn_settings = tptn_default_options();
50 update_option('ald_tptn_settings', $tptn_settings);
51
52 $str = '<div id="message" class="updated fade"><p>'. __('Options set to Default.',TPTN_LOCAL_NAME) .'</p></div>';
53 echo $str;
54 }
55
56 if ($_POST['tptn_trunc_all']){
57 tptn_trunc_count(false);
58 $str = '<div id="message" class="updated fade"><p>'. __('Top 10 popular posts reset',TPTN_LOCAL_NAME) .'</p></div>';
59 echo $str;
60 }
61
62 if ($_POST['tptn_trunc_daily']){
63 tptn_trunc_count(true);
64 $str = '<div id="message" class="updated fade"><p>'. __('Top 10 daily popular posts reset',TPTN_LOCAL_NAME) .'</p></div>';
65 echo $str;
66 }
67 ?>
68
69 <div class="wrap">
70 <h2>Top 10 </h2>
71 <div style="border: #ccc 1px solid; padding: 10px">
72 <fieldset class="options">
73 <legend>
74 <h3>
75 <?php _e('Support the Development',TPTN_LOCAL_NAME); ?>
76 </h3>
77 </legend>
78 <p>
79 <?php _e('If you find ',TPTN_LOCAL_NAME); ?>
80 <a href="http://ajaydsouza.com/wordpress/plugins/top-10/">Top 10</a>
81 <?php _e('useful, please do',TPTN_LOCAL_NAME); ?>
82 <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&amp;[email protected]&amp;item_name=Top%10%20(From%20WP-Admin)&amp;no_shipping=1&amp;return=http://ajaydsouza.com/wordpress/plugins/top-10/&amp;cancel_return=http://ajaydsouza.com/wordpress/plugins/top-10/&amp;cn=Note%20to%20Author&amp;tax=0&amp;currency_code=USD&amp;bn=PP-DonationsBF&amp;charset=UTF-8" title="Donate via PayPal"><?php _e('drop in your contribution',TPTN_LOCAL_NAME); ?></a>.
83 (<a href="http://ajaydsouza.com/donate/"><?php _e('Some reasons why you should.',TPTN_LOCAL_NAME); ?></a>)</p>
84 </fieldset>
85 </div>
86 <form method="post" id="tptn_options" name="tptn_options" style="border: #ccc 1px solid; padding: 10px">
87 <fieldset class="options">
88 <legend>
89 <h3>
90 <?php _e('Options:',TPTN_LOCAL_NAME); ?>
91 </h3>
92 </legend>
93 <p>
94 <label>
95 <?php _e('Format to display the count in: ',TPTN_LOCAL_NAME); ?><br />
96 <textarea name="count_disp_form" id="count_disp_form" cols="50" rows="5"><?php echo htmlspecialchars(stripslashes($tptn_settings[count_disp_form])); ?></textarea>
97 </label>
98 </p>
99 <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>
100 <p>
101 <label>
102 <?php _e('Number of popular posts to display: ',TPTN_LOCAL_NAME); ?>
103 <input type="textbox" name="limit" id="limit" value="<?php echo stripslashes($tptn_settings[limit]); ?>">
104 </label>
105 </p>
106 <p>
107 <label>
108 <?php _e('Daily Popular should contain views of how many days? ',TPTN_LOCAL_NAME); ?>
109 <input type="textbox" name="daily_range" id="daily_range" size="3" value="<?php echo stripslashes($tptn_settings[daily_range]); ?>">
110 </label>
111 </p>
112 <p>
113 <label>
114 <input type="checkbox" name="exclude_pages" id="exclude_pages" <?php if ($tptn_settings[exclude_pages]) echo 'checked="checked"' ?> />
115 <?php _e('Exclude Pages in display of Popular Posts? Number of views on Pages will continue to be counted.',TPTN_LOCAL_NAME); ?>
116 </label>
117 </p>
118 <p>
119 <label>
120 <input type="checkbox" name="add_to_content" id="add_to_content" <?php if ($tptn_settings[add_to_content]) echo 'checked="checked"' ?> />
121 <?php _e('Display number of views on posts?',TPTN_LOCAL_NAME); ?>
122 </label>
123 </p>
124 <p>
125 <label>
126 <input type="checkbox" name="count_on_pages" id="count_on_pages" <?php if ($tptn_settings[count_on_pages]) echo 'checked="checked"' ?> />
127 <?php _e('Display number of views on pages?',TPTN_LOCAL_NAME); ?>
128 </label>
129 </p>
130 <p>
131 <label>
132 <input type="checkbox" name="track_authors" id="track_authors" <?php if ($tptn_settings[track_authors]) echo 'checked="checked"' ?> />
133 <?php _e('Track visits of authors on their own posts?',TPTN_LOCAL_NAME); ?>
134 </label>
135 </p>
136 <p>
137 <label>
138 <input type="checkbox" name="disp_list_count" id="disp_list_count" <?php if ($tptn_settings[disp_list_count]) echo 'checked="checked"' ?> />
139 <?php _e('Display number of page views in popular lists?',TPTN_LOCAL_NAME); ?>
140 </label>
141 </p>
142 <p>
143 <label>
144 <input type="checkbox" name="d_use_js" id="d_use_js" <?php if ($tptn_settings[d_use_js]) echo 'checked="checked"' ?> />
145 <?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); ?>
146 </label>
147 </p>
148 <p>
149 <label>
150 <input type="checkbox" name="pv_in_admin" id="pv_in_admin" <?php if ($tptn_settings[pv_in_admin]) echo 'checked="checked"' ?> />
151 <?php _e('Display page views on Edit posts/pages in WP-Admin? An extra column is added with the count',TPTN_LOCAL_NAME); ?>
152 </label>
153 </p>
154 <p>
155 <label>
156 <input type="checkbox" name="show_credit" id="show_credit" <?php if ($tptn_settings[show_credit]) echo 'checked="checked"' ?> />
157 <?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); ?>
158 </label>
159 </p>
160 <h4>
161 <?php _e('Output Options:',TPTN_LOCAL_NAME); ?>
162 </h4>
163 <p>
164 <label>
165 <?php _e('Title of popular posts: ',TPTN_LOCAL_NAME); ?>
166 <input type="textbox" name="title" id="title" value="<?php echo stripslashes($tptn_settings[title]); ?>">
167 </label>
168 </p>
169 <p>
170 <label>
171 <?php _e('Title of daily popular posts: ',TPTN_LOCAL_NAME); ?>
172 <input type="textbox" name="title_daily" id="title_daily" value="<?php echo stripslashes($tptn_settings[title_daily]); ?>">
173 </label>
174 </p>
175 <h4><?php _e('Customize the output:',TPTN_LOCAL_NAME); ?></h4>
176 <p>
177 <label>
178 <?php _e('HTML to display before the list of posts: ',TPTN_LOCAL_NAME); ?>
179 <input type="textbox" name="before_list" id="before_list" value="<?php echo attribute_escape(stripslashes($tptn_settings[before_list])); ?>">
180 </label>
181 </p>
182 <p>
183 <label>
184 <?php _e('HTML to display before each list item: ',TPTN_LOCAL_NAME); ?>
185 <input type="textbox" name="before_list_item" id="before_list_item" value="<?php echo attribute_escape(stripslashes($tptn_settings[before_list_item])); ?>">
186 </label>
187 </p>
188 <p>
189 <label>
190 <?php _e('HTML to display after each list item: ',TPTN_LOCAL_NAME); ?>
191 <input type="textbox" name="after_list_item" id="after_list_item" value="<?php echo attribute_escape(stripslashes($tptn_settings[after_list_item])); ?>">
192 </label>
193 </p>
194 <p>
195 <label>
196 <?php _e('HTML to display after the list of posts: ',TPTN_LOCAL_NAME); ?>
197 <input type="textbox" name="after_list" id="after_list" value="<?php echo attribute_escape(stripslashes($tptn_settings[after_list])); ?>">
198 </label>
199 </p>
200 <h4><?php _e('Post thumbnail options:',TPTN_LOCAL_NAME); ?></h4>
201 <p>
202 <label>
203 <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"' ?> />
204 <?php _e('Display thumbnails inline with posts',TPTN_LOCAL_NAME); ?></label>
205 <br />
206 <label>
207 <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"' ?> />
208 <?php _e('Display only thumbnails, no text',TPTN_LOCAL_NAME); ?></label>
209 <br />
210 <label>
211 <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"' ?> />
212 <?php _e('Do not display thumbnails, only text.',TPTN_LOCAL_NAME); ?></label>
213 <br />
214 </p>
215 <p>
216 <label>
217 <?php _e('Post thumbnail meta field (the meta should point contain the image source): ',TPTN_LOCAL_NAME); ?>
218 <input type="textbox" name="thumb_meta" id="thumb_meta" value="<?php echo attribute_escape(stripslashes($tptn_settings[thumb_meta])); ?>">
219 </label>
220 </p>
221 <p><strong><?php _e('Thumbnail dimensions:',TPTN_LOCAL_NAME); ?></strong><br />
222 <label>
223 <?php _e('Max width: ',TPTN_LOCAL_NAME); ?>
224 <input type="textbox" name="thumb_width" id="thumb_width" value="<?php echo attribute_escape(stripslashes($tptn_settings[thumb_width])); ?>" style="width:30px">px
225 </label>
226 <br />
227 <label>
228 <?php _e('Max height: ',TPTN_LOCAL_NAME); ?>
229 <input type="textbox" name="thumb_height" id="thumb_height" value="<?php echo attribute_escape(stripslashes($tptn_settings[thumb_height])); ?>" style="width:30px">px
230 </label>
231 </p>
232 <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); ?>
233 <input type="textbox" name="thumb_default" id="thumb_default" value="<?php echo attribute_escape(stripslashes($tptn_settings[thumb_default])); ?>" style="width:500px">
234 </p>
235 <p>
236 <input type="submit" name="tptn_save" id="tptn_save" value="Save Options" style="border:#0c0 1px solid" />
237 <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;" />
238 </p>
239 <h4>
240 <?php _e('Reset count',TPTN_LOCAL_NAME); ?>
241 </h4>
242 <p>
243 <?php _e('This cannot be reversed. Make sure that your database has been backed up before proceeding',TPTN_LOCAL_NAME); ?>
244 </p>
245 <p>
246 <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;" />
247 <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;" />
248 </p>
249 </fieldset>
250 </form>
251 </div>
252 <?php
253
254 }
255
256 function tptn_manage() {
257 $paged = intval($_GET['paged']);
258 $limit = intval($_GET['limit']);
259 $daily = $_GET['daily'];
260
261 echo '<div class="wrap">';
262 echo '<h2>';
263 if (!$daily) _e('Popular Posts',TPTN_LOCAL_NAME); else _e('Daily Popular Posts',TPTN_LOCAL_NAME);
264 echo '</h2>';
265 echo '<div style="border: #ccc 1px solid; padding: 10px">';
266 echo tptn_pop_display($daily,$paged,$limit);
267 echo '</div></div>';
268 }
269
270 /* Add menu item in WP-Admin */
271 function tptn_adminmenu() {
272 if (function_exists('current_user_can')) {
273 // In WordPress 2.x
274 if (current_user_can('manage_options')) {
275 $tptn_is_admin = true;
276 }
277 } else {
278 // In WordPress 1.x
279 global $user_ID;
280 if (user_can_edit_user($user_ID, 0)) {
281 $tptn_is_admin = true;
282 }
283 }
284
285 if ((function_exists('add_options_page'))&&($tptn_is_admin)) {
286 add_options_page(__("Top 10", TPTN_LOCAL_NAME), __("Top 10", TPTN_LOCAL_NAME), 9, 'tptn_options', 'tptn_options');
287 add_posts_page(__("Popular Posts", TPTN_LOCAL_NAME), __("Top 10", TPTN_LOCAL_NAME), 9, 'tptn_manage', 'tptn_manage');
288 }
289 }
290 add_action('admin_menu', 'tptn_adminmenu');
291
292
293 /* Create a Dashboard Widget */
294 function tptn_pop_display($daily = false, $page = 0, $limit = 10) {
295 global $wpdb, $siteurl, $tableposts, $id;
296
297 $table_name = $wpdb->prefix . "top_ten";
298 if ($daily) $table_name .= "_daily"; // If we're viewing daily posts, set this to true
299
300 $tptn_settings = tptn_read_options();
301 if (!($limit)) $limit = $tptn_settings['limit'];
302 if (!($page)) $page = 0; // Default page value.
303
304 if(!$daily) {
305 $sql = "SELECT postnumber, cntaccess , ID, post_type ";
306 $sql .= "FROM $table_name INNER JOIN ". $wpdb->posts ." ON postnumber=ID " ;
307 if ($tptn_settings['exclude_pages']) $sql .= "AND post_type = 'post' ";
308 $sql .= "AND post_status = 'publish' ";
309 $sql .= "ORDER BY cntaccess DESC";
310 } else {
311 $daily_range = $tptn_settings[daily_range]. ' DAY';
312 $current_date = $wpdb->get_var("SELECT DATE_ADD(DATE_SUB(CURDATE(), INTERVAL ".$daily_range."), INTERVAL 1 DAY) ");
313
314 $sql = "SELECT postnumber, SUM(cntaccess) as sumCount, dp_date, ID, post_type, post_status ";
315 $sql .= "FROM $table_name INNER JOIN ". $wpdb->posts ." ON postnumber=ID " ;
316 if ($tptn_settings['exclude_pages']) $sql .= "AND post_type = 'post' ";
317 $sql .= "AND post_status = 'publish' AND dp_date >= '$current_date' ";
318 $sql .= "GROUP BY postnumber ";
319 $sql .= "ORDER BY sumCount DESC";
320 }
321
322 $results = $wpdb->get_results($sql);
323 $numrows = 0;
324 if ($results) {
325 foreach ($results as $result) {
326 $numrows++;
327 }
328 }
329
330 $pages = intval($numrows/$limit); // Number of results pages.
331
332 // $pages now contains int of pages, unless there is a remainder from division.
333
334 if ($numrows % $limit) {$pages++;} // has remainder so add one page
335
336 $current = ($page/$limit) + 1; // Current page number.
337
338 if (($pages < 1) || ($pages == 0)) {$total = 1;} // If $pages is less than one or equal to 0, total pages is 1.
339 else { $total = $pages;} // Else total pages is $pages value.
340
341 $first = $page + 1; // The first result.
342
343 if (!((($page + $limit) / $limit) >= $pages) && $pages != 1) {$last = $page + $limit;} //If not last results page, last result equals $page plus $limit.
344 else{$last = $numrows;} // If last results page, last result equals total number of results.
345
346 if(!$daily) {
347 $sql = "SELECT postnumber, cntaccess , ID, post_type ";
348 $sql .= "FROM $table_name INNER JOIN ". $wpdb->posts ." ON postnumber=ID " ;
349 if ($tptn_settings['exclude_pages']) $sql .= "AND post_type = 'post' ";
350 $sql .= "AND post_status = 'publish' ";
351 $sql .= "ORDER BY cntaccess DESC LIMIT $page, $limit";
352 } else {
353 $sql = "SELECT postnumber, SUM(cntaccess) as sumCount, dp_date, ID, post_type, post_status ";
354 $sql .= "FROM $table_name INNER JOIN ". $wpdb->posts ." ON postnumber=ID " ;
355 if ($tptn_settings['exclude_pages']) $sql .= "AND post_type = 'post' ";
356 $sql .= "AND post_status = 'publish' AND dp_date >= '$current_date' ";
357 $sql .= "GROUP BY postnumber ";
358 $sql .= "ORDER BY sumCount DESC LIMIT $page, $limit";
359 }
360
361 $results = $wpdb->get_results($sql);
362
363 $output = '<div id="tptn_popular_posts">';
364 $output .= '<table width="100%" border="0">
365 <tr>
366 <td width="50%" align="left">';
367 $output .= __('Results',TPTN_LOCAL_NAME);
368 $output .= ' <strong>'.$first.'</strong> - <strong>'.$last.'</strong> ';
369 $output .= __('of',TPTN_LOCAL_NAME);
370 $output .= ' <strong>'.$numrows.'</strong>
371 </td>
372 <td width="50%" align="right">';
373 $output .= __('Page',TPTN_LOCAL_NAME);
374 $output .= ' <strong>'.$current.'</strong> ';
375 $output .= __('of',TPTN_LOCAL_NAME);
376 $output .= ' <strong>'.$total.'</strong>
377 </td>
378 </tr>
379 <tr>
380 <td colspan="2" align="right">&nbsp;</td>
381 </tr>
382 <tr>
383 <td align="left">';
384
385 if(!$daily) {
386 $output .= '<a href="./edit.php?page=tptn_manage&daily=1">';
387 $output .= __('View Daily Popular Posts',TPTN_LOCAL_NAME);
388 $output .= '</a></td>';
389 } else {
390 $output .= '<a href="./edit.php?page=tptn_manage&daily=0">';
391 $output .= __('View Overall Popular Posts',TPTN_LOCAL_NAME);
392 $output .= '</a></td>';
393 }
394 $output .= '<td align="right">';
395 $output .= __('Results per-page:',TPTN_LOCAL_NAME);
396 $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>
397 </td>
398 </tr>
399 <tr>
400 <td colspan="2" align="right"><hr /></td>
401 </tr>
402 </table>';
403
404
405 $output .= '<ul>';
406 if ($results) {
407 foreach ($results as $result) {
408 $output .= '<li><a href="'.get_permalink($result->postnumber).'">'.get_the_title($result->postnumber).'</a>';
409 if ($daily) $output .= ' ('.$result->sumCount.')'; else $output .= ' ('.$result->cntaccess.')';
410 $output .= '</li>';
411 }
412 }
413 $output .= '</ul>';
414
415 $output .= '<p align="center">';
416 if ($page != 0) { // Don't show back link if current page is first page.
417 $back_page = $page - $limit;
418 $output .= "<a href=\"./edit.php?page=tptn_manage&paged=$back_page&daily=$daily&limit=$limit\">&laquo; ";
419 $output .= __('Previous',TPTN_LOCAL_NAME);
420 $output .= "</a>\n";
421 }
422
423 for ($i=1; $i <= $pages; $i++) // loop through each page and give link to it.
424 {
425 $ppage = $limit*($i - 1);
426 if ($ppage == $page){
427 $output .= "<b>$i</b>\n";
428 } // If current page don't give link, just text.
429 else{
430 $output .= "<a href=\"./edit.php?page=tptn_manage&paged=$ppage&daily=$daily&limit=$limit\">$i</a> \n";
431 }
432 }
433
434 if (!((($page+$limit) / $limit) >= $pages) && $pages != 1) { // If last page don't give next link.
435 $next_page = $page + $limit;
436 $output .= "<a href=\"./edit.php?page=tptn_manage&paged=$next_page&daily=$daily&limit=$limit\">";
437 $output .= __('Next',TPTN_LOCAL_NAME);
438 $output .= " &raquo;</a>";
439 }
440 $output .= '</p>';
441 $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>';
442 $output .= '</div>';
443
444 return $output;
445
446 }
447
448 // Dashboard for Popular Posts
449 function tptn_pop_dashboard() {
450 echo tptn_pop_display(false,0,10);
451 }
452 // Dashboard for Daily Popular Posts
453 function tptn_pop_daily_dashboard() {
454 echo tptn_pop_display(true,0,10);
455 }
456
457 function tptn_pop_dashboard_setup() {
458 if (function_exists('wp_add_dashboard_widget')) {
459 wp_add_dashboard_widget( 'tptn_pop_dashboard', __( 'Popular Posts',TPTN_LOCAL_NAME ), 'tptn_pop_dashboard' );
460 wp_add_dashboard_widget( 'tptn_pop_daily_dashboard', __( 'Daily Popular',TPTN_LOCAL_NAME ), 'tptn_pop_daily_dashboard' );
461 }
462 }
463 add_action('wp_dashboard_setup', 'tptn_pop_dashboard_setup');
464
465
466 /* Display page views on the Edit Posts / Pages screen */
467 // Add an extra column
468 function tptn_column($cols) {
469 $tptn_settings = tptn_read_options();
470
471 if ($tptn_settings[pv_in_admin]) $cols['tptn'] = __('Total / Today\'s Views',TPTN_LOCAL_NAME);
472 return $cols;
473 }
474
475 // Display page views for each column
476 function tptn_value($column_name, $id) {
477 $tptn_settings = tptn_read_options();
478 if (($column_name == 'tptn')&&($tptn_settings[pv_in_admin])) {
479 global $wpdb;
480
481 $table_name = $wpdb->prefix . "top_ten";
482
483 $resultscount = $wpdb->get_row("select postnumber, cntaccess from $table_name WHERE postnumber = $id");
484 $cntaccess = number_format((($resultscount) ? $resultscount->cntaccess : 0));
485
486 $cntaccess .= ' / ';
487
488 // Now process daily count
489 $table_name = $wpdb->prefix . "top_ten_daily";
490
491 $daily_range = $tptn_settings[daily_range]. ' DAY';
492 $current_date = $wpdb->get_var("SELECT DATE_ADD(DATE_SUB(CURDATE(), INTERVAL ".$daily_range."), INTERVAL 1 DAY) ");
493 $resultscount = $wpdb->get_row("SELECT postnumber, SUM(cntaccess) as sumCount FROM $table_name WHERE postnumber = $id AND dp_date >= '$current_date' GROUP BY postnumber ");
494 $cntaccess .= number_format((($resultscount) ? $resultscount->sumCount : 0));
495
496 echo $cntaccess;
497 }
498 }
499
500 // Output CSS for width of new column
501 function tptn_css() {
502 ?>
503 <style type="text/css">
504 #tptn { width: 50px; }
505 </style>
506 <?php
507 }
508
509 // Actions/Filters for various tables and the css output
510 add_filter('manage_posts_columns', 'tptn_column');
511 add_action('manage_posts_custom_column', 'tptn_value', 10, 2);
512 add_filter('manage_pages_columns', 'tptn_column');
513 add_action('manage_pages_custom_column', 'tptn_value', 10, 2);
514 add_filter('manage_media_columns', 'tptn_column');
515 add_action('manage_media_custom_column', 'tptn_value', 10, 2);
516 add_filter('manage_link-manager_columns', 'tptn_column');
517 add_action('manage_link_custom_column', 'tptn_value', 10, 2);
518 add_action('admin_head', 'tptn_css');
519
520 ?>