| 1 |
<?php |
| 2 |
//"top-10-counter.js.php" Display number of page views |
| 3 |
Header("content-type: application/x-javascript"); |
| 4 |
|
| 5 |
if (!function_exists('add_action')) { |
| 6 |
$wp_root = '../../..'; |
| 7 |
if (file_exists($wp_root.'/wp-load.php')) { |
| 8 |
require_once($wp_root.'/wp-load.php'); |
| 9 |
} else { |
| 10 |
require_once($wp_root.'/wp-config.php'); |
| 11 |
} |
| 12 |
} |
| 13 |
|
| 14 |
// Display counter using Ajax |
| 15 |
function tptn_disp_count() { |
| 16 |
global $wpdb; |
| 17 |
|
| 18 |
$table_name = $wpdb->prefix . "top_ten"; |
| 19 |
$table_name_daily = $wpdb->prefix . "top_ten_daily"; |
| 20 |
$tptn_settings = tptn_read_options(); |
| 21 |
$count_disp_form = stripslashes($tptn_settings[count_disp_form]); |
| 22 |
|
| 23 |
$id = intval($_GET['top_ten_id']); |
| 24 |
if($id > 0) { |
| 25 |
|
| 26 |
$resultscount = $wpdb->get_row("SELECT postnumber, cntaccess FROM ".$table_name." WHERE postnumber = ".$id); |
| 27 |
$cntaccess = number_format((($resultscount) ? $resultscount->cntaccess : 0)); |
| 28 |
$count_disp_form = str_replace("%totalcount%", $cntaccess, $count_disp_form); |
| 29 |
|
| 30 |
// Now process daily count |
| 31 |
$daily_range = $tptn_settings[daily_range]; |
| 32 |
$current_time = gmdate( 'Y-m-d', ( time() + ( get_option( 'gmt_offset' ) * 3600 ) ) ); |
| 33 |
$current_date = strtotime ( '-'.$daily_range. ' DAY' , strtotime ( $current_time ) ); |
| 34 |
$current_date = date ( 'Y-m-j' , $current_date ); |
| 35 |
|
| 36 |
$resultscount = $wpdb->get_row("SELECT postnumber, SUM(cntaccess) as sumCount FROM ".$table_name_daily." WHERE postnumber = ".$id." AND dp_date >= '".$current_date."' GROUP BY postnumber "); |
| 37 |
$cntaccess = number_format((($resultscount) ? $resultscount->sumCount : 1)); |
| 38 |
$count_disp_form = str_replace("%dailycount%", $cntaccess, $count_disp_form); |
| 39 |
|
| 40 |
echo 'document.write("'.$count_disp_form.'")'; |
| 41 |
} |
| 42 |
} |
| 43 |
tptn_disp_count(); |
| 44 |
?> |