| 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 |
$results = $wpdb->get_results("select postnumber, cntaccess from $top_ten_daily where postnumber = '$id'"); |
| 36 |
$test = 0; |
| 37 |
if ($results) { |
| 38 |
foreach ($results as $result) { |
| 39 |
$wpdb->query("update $top_ten_daily set cntaccess = cntaccess + 1 where postnumber = $result->postnumber"); |
| 40 |
$test = 1; |
| 41 |
} |
| 42 |
} |
| 43 |
if ($test == 0) { |
| 44 |
$wpdb->query("insert into $top_ten_daily (postnumber, cntaccess) values('$id', '1')"); |
| 45 |
} |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
?> |
| 50 |
|