| 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]-1; |
| 24 |
$current_time = gmdate( 'Y-m-d', ( time() + ( get_option( 'gmt_offset' ) * 3600 ) ) ); |
| 25 |
$current_date = strtotime ( '-'.$daily_range. ' DAY' , strtotime ( $current_time ) ); |
| 26 |
$current_date = date ( 'Y-m-j' , $current_date ); |
| 27 |
|
| 28 |
$sql = "SELECT postnumber, SUM(cntaccess) as sumCount, dp_date, ID, post_type, post_status "; |
| 29 |
$sql .= "FROM $table_name INNER JOIN ". $wpdb->posts ." ON postnumber=ID " ; |
| 30 |
if ($tptn_settings['exclude_pages']) $sql .= "AND post_type = 'post' "; |
| 31 |
$sql .= "AND post_status = 'publish' AND dp_date >= '$current_date' "; |
| 32 |
$sql .= "GROUP BY postnumber "; |
| 33 |
$sql .= "ORDER BY sumCount DESC LIMIT $limit"; |
| 34 |
|
| 35 |
$results = $wpdb->get_results($sql); |
| 36 |
|
| 37 |
$output = '<div id="tptn_related_daily">'; |
| 38 |
if(!$is_widget) $output .= $tptn_settings['title_daily']; |
| 39 |
|
| 40 |
if ($results) { |
| 41 |
$output .= $tptn_settings['before_list']; |
| 42 |
foreach ($results as $result) { |
| 43 |
$title = trim(stripslashes(get_the_title($result->postnumber))); |
| 44 |
$output .= $tptn_settings['before_list_item']; |
| 45 |
|
| 46 |
if (($tptn_settings['post_thumb_op']=='inline')||($tptn_settings['post_thumb_op']=='thumbs_only')) { |
| 47 |
$output .= '<a href="'.get_permalink($result->postnumber).'" rel="bookmark">'; |
| 48 |
if ((function_exists('has_post_thumbnail')) && (has_post_thumbnail($result->postnumber))) { |
| 49 |
$output .= get_the_post_thumbnail( $result->postnumber, array($tptn_settings[thumb_width],$tptn_settings[thumb_height]), array('title' => $title,'alt' => $title)); |
| 50 |
} else { |
| 51 |
$postimage = get_post_meta($result->postnumber, 'post-image', true); |
| 52 |
if ($postimage) { |
| 53 |
$output .= '<img src="'.$postimage.'" alt="'.$title.'" title="'.$title.'" width="'.$tptn_settings[thumb_width].'" height="'.$tptn_settings[thumb_height].'" />'; |
| 54 |
} else { |
| 55 |
$output .= '<img src="'.$tptn_settings[thumb_default].'" alt="'.$title.'" title="'.$title.'" width="'.$tptn_settings[thumb_width].'" height="'.$tptn_settings[thumb_height].'" />'; |
| 56 |
} |
| 57 |
} |
| 58 |
$output .= '</a> '; |
| 59 |
} |
| 60 |
if (($tptn_settings['post_thumb_op']=='inline')||($tptn_settings['post_thumb_op']=='text_only')) { |
| 61 |
$output .= '<a href="'.get_permalink($result->postnumber).'" rel="bookmark">'.$title.'</a>'; |
| 62 |
} |
| 63 |
if ($tptn_settings['disp_list_count']) $output .= ' ('.$result->sumCount.')'; |
| 64 |
$output .= $tptn_settings['after_list_item']; |
| 65 |
} |
| 66 |
if ($tptn_settings['show_credit']) $output .= $tptn_settings['before_list_item'].'Popular posts by <a href="http://ajaydsouza.com/wordpress/plugins/top-10/">Top 10 plugin</a>'.$tptn_settings['after_list_item']; |
| 67 |
$output .= $tptn_settings['after_list']; |
| 68 |
} |
| 69 |
|
| 70 |
$output .= '</div>'; |
| 71 |
|
| 72 |
echo "document.write('".$output."')"; |
| 73 |
} |
| 74 |
tptn_daily_lists(); |
| 75 |
?> |
| 76 |
|