Ad King Pro

'adverts_posts' )); $currency_sign = get_option('revenue_currency'); while (have_posts()) : the_post(); $post_id = get_the_ID(); $image = akp_get_featured_image($post_id); $dets = akp_return_fields($post_id); // Get All Time Click Count $all_clicks = $wpdb->get_results("SELECT COUNT(*) as clicks FROM ".$wpdb->prefix."akp_click_log WHERE post_id = '$post_id'"); $all_impressions = $wpdb->get_results("SELECT COUNT(*) as impressions FROM ".$wpdb->prefix."akp_impressions_log WHERE post_id = '$post_id'"); $all_impression_cost = (is_numeric($dets['akp_revenue_per_impression'][0])) ? $dets['akp_revenue_per_impression'][0] : '0.00'; $all_click_cost = (is_numeric($dets['akp_revenue_per_click'][0])) ? $dets['akp_revenue_per_click'][0] : '0.00'; $all_per_impression = $currency_sign.number_format($all_impression_cost, 2); $all_impression_total = $all_impression_cost * $all_impressions[0]->impressions; $all_impression_total_output = $currency_sign.number_format($all_impression_total, 2); $all_per_click = $currency_sign.number_format($all_click_cost, 2); $all_click_total = $all_click_cost * $all_clicks[0]->clicks; $all_click_total_output = $currency_sign.number_format($all_click_total, 2); $all_total_made = $all_impression_total + $all_click_total; $all_total_made_output = $currency_sign.number_format($all_total_made, 2); // Get This Month Click Count $month_start = mktime(0, 0, 0, date('n', current_time('timestamp')), 1, date('Y', current_time('timestamp'))); $month_end = mktime(23, 59, 59, date('n', current_time('timestamp')), date('t', current_time('timestamp')), date('Y', current_time('timestamp'))); $month_clicks = $wpdb->get_results("SELECT COUNT(*) as clicks FROM ".$wpdb->prefix."akp_click_log WHERE timestamp BETWEEN '$month_start' AND '$month_end' AND post_id = '$post_id'"); $month_impressions = $wpdb->get_results("SELECT COUNT(*) as impressions FROM ".$wpdb->prefix."akp_impressions_log WHERE timestamp BETWEEN '$month_start' AND '$month_end' AND post_id = '$post_id'"); $month_impression_cost = (is_numeric($dets['akp_revenue_per_impression'][0])) ? $dets['akp_revenue_per_impression'][0] : '0.00'; $month_click_cost = (is_numeric($dets['akp_revenue_per_click'][0])) ? $dets['akp_revenue_per_click'][0] : '0.00'; $month_per_impression = $currency_sign.number_format($month_impression_cost, 2); $month_impression_total = $month_impression_cost * $month_impressions[0]->impressions; $month_impression_total_output = $currency_sign.number_format($month_impression_total, 2); $month_per_click = $currency_sign.number_format($month_click_cost, 2); $month_click_total = $month_click_cost * $month_clicks[0]->clicks; $month_click_total_output = $currency_sign.number_format($month_click_total, 2); $month_total_made = $month_impression_total + $month_click_total; $month_total_made_output = $currency_sign.number_format($month_total_made, 2); // Get This Week click count $start_week = get_option('week_starts'); if (strtolower(date('l', current_time('timestamp'))) == $start_week) { $day = date('j', current_time('timestamp')); $month = date('n', current_time('timestamp')); $year = date('Y', current_time('timestamp')); } else { $day = date('j', strtotime('last '.$start_week)); $month = date('n', strtotime('last '.$start_week)); $year = date('Y', strtotime('last '.$start_week)); } $week_start = mktime(0, 0, 0, $month, $day, $year); $week_end = mktime(23, 59, 59, date('n', strtotime("+7 days", $week_start)), date('j', strtotime("+7 days", $week_start)), date('Y', strtotime("+7 days", $week_start))); $week_clicks = $wpdb->get_results("SELECT COUNT(*) as clicks FROM ".$wpdb->prefix."akp_click_log WHERE timestamp BETWEEN '$week_start' AND '$week_end' AND post_id = '$post_id'"); $week_impressions = $wpdb->get_results("SELECT COUNT(*) as impressions FROM ".$wpdb->prefix."akp_impressions_log WHERE timestamp BETWEEN '$week_start' AND '$week_end' AND post_id = '$post_id'"); $week_impression_cost = (is_numeric($dets['akp_revenue_per_impression'][0])) ? $dets['akp_revenue_per_impression'][0] : '0.00'; $week_click_cost = (is_numeric($dets['akp_revenue_per_click'][0])) ? $dets['akp_revenue_per_click'][0] : '0.00'; $week_per_impression = $currency_sign.number_format($week_impression_cost, 2); $week_impression_total = $week_impression_cost * $week_impressions[0]->impressions; $week_impression_total_output = $currency_sign.number_format($week_impression_total, 2); $week_per_click = $currency_sign.number_format($week_click_cost, 2); $week_click_total = $week_click_cost * $week_clicks[0]->clicks; $week_click_total_output = $currency_sign.number_format($week_click_total, 2); $week_total_made = $week_impression_total + $week_click_total; $week_total_made_output = $currency_sign.number_format($week_total_made, 2); // Get Today Click count $today_start = mktime(0, 0, 0, date('n', current_time('timestamp')), date('j', current_time('timestamp')), date('Y', current_time('timestamp'))); $today_end = mktime(23, 59, 59, date('n', current_time('timestamp')), date('j', current_time('timestamp')), date('Y', current_time('timestamp'))); $today_clicks = $wpdb->get_results("SELECT COUNT(*) as clicks FROM ".$wpdb->prefix."akp_click_log WHERE timestamp BETWEEN '$today_start' AND '$today_end' AND post_id = '$post_id'"); $today_impressions = $wpdb->get_results("SELECT COUNT(*) as impressions FROM ".$wpdb->prefix."akp_impressions_log WHERE timestamp BETWEEN '$today_start' AND '$today_end' AND post_id = '$post_id'"); $today_impression_cost = (is_numeric($dets['akp_revenue_per_impression'][0])) ? $dets['akp_revenue_per_impression'][0] : '0.00'; $today_click_cost = (is_numeric($dets['akp_revenue_per_click'][0])) ? $dets['akp_revenue_per_click'][0] : '0.00'; $today_per_impression = $currency_sign.number_format($today_impression_cost, 2); $today_impression_total = $today_impression_cost * $today_impressions[0]->impressions; $today_impression_total_output = $currency_sign.number_format($today_impression_total, 2); $today_per_click = $currency_sign.number_format($today_click_cost, 2); $today_click_total = $today_click_cost * $today_clicks[0]->clicks; $today_click_total_output = $currency_sign.number_format($today_click_total, 2); $today_total_made = $today_impression_total + $today_click_total; $today_total_made_output = $currency_sign.number_format($today_total_made, 2); // Initilize Detail log $all_clicks_detailed = $wpdb->get_results("SELECT * FROM ".$wpdb->prefix."akp_click_log WHERE post_id = '$post_id' ORDER BY timestamp DESC"); $month_clicks_detailed = $wpdb->get_results("SELECT * FROM ".$wpdb->prefix."akp_click_log WHERE timestamp BETWEEN '$month_start' AND '$month_end' AND post_id = '$post_id' ORDER BY timestamp DESC"); $week_clicks_detailed = $wpdb->get_results("SELECT * FROM ".$wpdb->prefix."akp_click_log WHERE timestamp BETWEEN '$week_start' AND '$week_end' AND post_id = '$post_id' ORDER BY timestamp DESC"); $day_clicks_detailed = $wpdb->get_results("SELECT * FROM ".$wpdb->prefix."akp_click_log WHERE timestamp BETWEEN '$today_start' AND '$today_end' AND post_id = '$post_id' ORDER BY timestamp DESC"); ?>