| 1 |
<?php |
| 2 |
//"top-10-addcount.js.php" Add count to database |
| 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 |
// Ajax Increment Counter |
| 15 |
tptn_inc_count(); |
| 16 |
function tptn_inc_count() { |
| 17 |
global $wpdb; |
| 18 |
$table_name = $wpdb->prefix . "top_ten"; |
| 19 |
$top_ten_daily = $wpdb->prefix . "top_ten_daily"; |
| 20 |
|
| 21 |
$id = intval($_GET['top_ten_id']); |
| 22 |
if($id > 0) { |
| 23 |
$results = $wpdb->get_results("SELECT postnumber, cntaccess FROM $table_name WHERE postnumber = '$id'"); |
| 24 |
$test = 0; |
| 25 |
if ($results) { |
| 26 |
foreach ($results as $result) { |
| 27 |
$wpdb->query("UPDATE $table_name SET cntaccess = cntaccess + 1 WHERE postnumber = $result->postnumber"); |
| 28 |
$test = 1; |
| 29 |
} |
| 30 |
} |
| 31 |
if ($test == 0) { |
| 32 |
$wpdb->query("INSERT INTO $table_name (postnumber, cntaccess) VALUES('$id', '1')"); |
| 33 |
} |
| 34 |
// Now update daily count |
| 35 |
$current_date = $wpdb->get_var("SELECT CURDATE() "); |
| 36 |
|
| 37 |
$results = $wpdb->get_results("SELECT postnumber, cntaccess, dp_date FROM $top_ten_daily WHERE postnumber = '$id' AND dp_date = '$current_date' "); |
| 38 |
$test = 0; |
| 39 |
if ($results) { |
| 40 |
foreach ($results as $result) { |
| 41 |
$wpdb->query("UPDATE $top_ten_daily SET cntaccess = cntaccess + 1 WHERE postnumber = $result->postnumber AND dp_date = '$current_date' "); |
| 42 |
$test = 1; |
| 43 |
} |
| 44 |
} |
| 45 |
if ($test == 0) { |
| 46 |
$wpdb->query("INSERT INTO $top_ten_daily (postnumber, cntaccess, dp_date) VALUES('$id', '1', '$current_date' )"); |
| 47 |
} |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
?> |
| 52 |
|