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