| 1 |
<?php |
| 2 |
//"top-10-daily.js.php" Display Daily Popular Lists. |
| 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_daily_lists() { |
| 16 |
global $wpdb, $siteurl, $tableposts, $id; |
| 17 |
$table_name = $wpdb->prefix . "top_ten_daily"; |
| 18 |
|
| 19 |
$is_widget = intval($_GET['widget']); |
| 20 |
|
| 21 |
$tptn_settings = tptn_read_options(); |
| 22 |
$limit = $tptn_settings['limit']; |
| 23 |
$daily_range = $tptn_settings[daily_range]. ' DAY'; |
| 24 |
$current_date = $wpdb->get_var("SELECT DATE_ADD(DATE_SUB(CURDATE(), INTERVAL $daily_range), INTERVAL 1 DAY) "); |
| 25 |
|
| 26 |
$sql = "SELECT postnumber, SUM(cntaccess) as sumCount, dp_date, ID, post_type, post_status "; |
| 27 |
$sql .= "FROM $table_name INNER JOIN ". $wpdb->posts ." ON postnumber=ID " ; |
| 28 |
if ($tptn_settings['exclude_pages']) $sql .= "AND post_type = 'post' "; |
| 29 |
$sql .= "AND post_status = 'publish' AND dp_date >= '$current_date' "; |
| 30 |
$sql .= "GROUP BY postnumber "; |
| 31 |
$sql .= "ORDER BY sumCount DESC LIMIT $limit"; |
| 32 |
|
| 33 |
$results = $wpdb->get_results($sql); |
| 34 |
|
| 35 |
$output = '<div id="crp_related">'; |
| 36 |
if(!$is_widget) $output .= $tptn_settings['title_daily']; |
| 37 |
$output .= '<ul>'; |
| 38 |
if ($results) { |
| 39 |
foreach ($results as $result) { |
| 40 |
$output .= '<li><a href="'.get_permalink($result->postnumber).'">'.get_the_title($result->postnumber).'</a>'; |
| 41 |
if ($tptn_settings['disp_list_count']) $output .= ' ('.$result->sumCount.')'; |
| 42 |
$output .= '</li>'; |
| 43 |
} |
| 44 |
} |
| 45 |
if ($tptn_settings['show_credit']) $output .= '<li>Popular posts by <a href="http://ajaydsouza.com/wordpress/plugins/top-10/">Top 10 plugin</a></li>'; |
| 46 |
$output .= '</ul>'; |
| 47 |
$output .= '</div>'; |
| 48 |
|
| 49 |
echo "document.write('".$output."')"; |
| 50 |
} |
| 51 |
tptn_daily_lists(); |
| 52 |
?> |
| 53 |
|