get_row("SELECT * FROM ".$wpdb->prefix."akp_click_expire WHERE ip_address = '$ip_address' AND post_id = '$post_id'");
if ($ip != null) {
if ($ip->expire < $timestamp) {
$wpdb->query( $wpdb->prepare(
"DELETE FROM ".$wpdb->prefix."akp_click_expire
WHERE post_id = %d
AND ip_address = %s
",
$post_id, $ip_address
)
);
$wpdb->query( $wpdb->prepare(
"INSERT INTO ".$wpdb->prefix."akp_click_log
( post_id, ip_address, timestamp )
VALUES ( %d, %s, %d )",
array(
$post_id,
$ip_address,
$timestamp
)
) );
$wpdb->query( $wpdb->prepare(
"INSERT INTO ".$wpdb->prefix."akp_click_expire
( post_id, ip_address, expire )
VALUES ( %d, %s, %d )",
array(
$post_id,
$ip_address,
$expire
)
) );
}
} else {
$wpdb->query( $wpdb->prepare(
"INSERT INTO ".$wpdb->prefix."akp_click_log
( post_id, ip_address, timestamp )
VALUES ( %d, %s, %d )",
array(
$post_id,
$ip_address,
$timestamp
)
) );
$wpdb->query( $wpdb->prepare(
"INSERT INTO ".$wpdb->prefix."akp_click_expire
( post_id, ip_address, expire )
VALUES ( %d, %s, %d )",
array(
$post_id,
$ip_address,
$expire
)
) );
}
}
die();
}
add_action( 'wp_ajax_nopriv_akplogclick', 'akp_log_click_ajax' );
add_action( 'wp_ajax_akplogclick', 'akp_log_click_ajax' );
// Retreive clicks from daterange
function akp_date_range_ajax() {
if (wp_verify_nonce( $_POST['ajaxnonce'], 'akpN0nc3' )) {
$from_date = $_POST['from_date'];
$to_date = $_POST['to_date'];
$banner_id = $_POST['banner_id'];
global $wpdb;
$date_start = mktime(0, 0, 0, date('m', strtotime(str_replace('/', '-', $from_date))), date('d', strtotime(str_replace('/', '-', $from_date))), date('Y', strtotime(str_replace('/', '-', $from_date))));
$date_end = mktime(23, 59, 59, date('m', strtotime(str_replace('/', '-', $to_date))), date('d', strtotime(str_replace('/', '-', $to_date))), date('Y', strtotime(str_replace('/', '-', $to_date))));
$date_clicks = $wpdb->get_results("SELECT * FROM ".$wpdb->prefix."akp_click_log WHERE timestamp BETWEEN '$date_start' AND '$date_end' AND post_id = '$banner_id' ORDER BY timestamp DESC");
?>
| Date/Time |
IP Address |
| = date('d/m/Y h:i:sa', $dc->timestamp) ?> |
= $dc->ip_address ?> |
| Date/Time |
IP Address |
get_results("SELECT * FROM ".$wpdb->prefix."akp_click_log WHERE post_id = '$post_id' ORDER BY timestamp DESC");
break;
case 'month':
$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')));
$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");
break;
case 'week':
$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)));
$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");
break;
case 'today':
$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')));
$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");
break;
case 'daterange':
$from_date = $_POST['from_date'];
$to_date = $_POST['to_date'];
$date_start = mktime(0, 0, 0, date('m', strtotime(str_replace('/', '-', $from_date))), date('d', strtotime(str_replace('/', '-', $from_date))), date('Y', strtotime(str_replace('/', '-', $from_date))));
$date_end = mktime(23, 59, 59, date('m', strtotime(str_replace('/', '-', $to_date))), date('d', strtotime(str_replace('/', '-', $to_date))), date('Y', strtotime(str_replace('/', '-', $to_date))));
$clicks_detailed = $wpdb->get_results("SELECT * FROM ".$wpdb->prefix."akp_click_log WHERE timestamp BETWEEN '$date_start' AND '$date_end' AND post_id = '$post_id' ORDER BY timestamp DESC");
break;
}
$array = array();
$array[] = array('Date/Time', 'IP Address');
foreach ($clicks_detailed as $click) {
$array[] = array(date('d/m/Y h:i:sa', $click->timestamp), $click->ip_address);
}
outputCSV($array);
echo str_replace("js/","",plugin_dir_url(__FILE__))."outputs/output.csv";
?>
get_results("SELECT * FROM ".$wpdb->prefix."akp_click_log WHERE post_id = '$post_id' ORDER BY timestamp DESC");
$title = "Clicks made All-time";
break;
case 'month':
$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')));
$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");
$title = "Clicks made in the month of ".date('F', current_time('timestamp'))." in ".date('Y', current_time('timestamp'));
break;
case 'week':
$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)));
$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");
$title = "Clicks made in the week between ".date('jS F Y', $week_start)." to ".date('jS F Y', $week_end);
break;
case 'today':
$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')));
$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");
$title = "Clicks made on the ".date('jS F Y', $today_start);
break;
case 'daterange':
$from_date = $_POST['from_date'];
$to_date = $_POST['to_date'];
$date_start = mktime(0, 0, 0, date('m', strtotime(str_replace('/', '-', $from_date))), date('d', strtotime(str_replace('/', '-', $from_date))), date('Y', strtotime(str_replace('/', '-', $from_date))));
$date_end = mktime(23, 59, 59, date('m', strtotime(str_replace('/', '-', $to_date))), date('d', strtotime(str_replace('/', '-', $to_date))), date('Y', strtotime(str_replace('/', '-', $to_date))));
$clicks_detailed = $wpdb->get_results("SELECT * FROM ".$wpdb->prefix."akp_click_log WHERE timestamp BETWEEN '$date_start' AND '$date_end' AND post_id = '$post_id' ORDER BY timestamp DESC");
$title = "Clicks made between ".date('jS F Y', $date_start)." to ".date('jS F Y', $date_end);
break;
}
$pdf = new FPDF('P','mm','A4');
$pdf->AliasNbPages();
$pdf->AddPage();
query_posts(array(
'post_type'=>'adverts_posts',
'p'=>$post_id
));
while (have_posts()) : the_post();
$post_id = get_the_ID();
$image = akp_get_featured_image($post_id);
endwhile;
wp_reset_query();
$pdf->Image(str_replace('http://'.$_SERVER['HTTP_HOST'], $_SERVER['DOCUMENT_ROOT'], $image), 15, 6, 0, 20);
$pdf->SetX(15); $pdf->SetY($pdf->GetY()+ 25);
$pdf->SetFont('Arial','BU',10);
$pdf->Cell(95,8,$title,0,0,'L');
$pdf->Cell(95,8,"Banner ID: #".$post_id,0,0,'R');
$pdf->Ln(15);
$pdf->SetFillColor(227,227,227);
$pdf->SetTextColor(0,0,0);
$pdf->SetX(10);
$pdf->SetFont('Arial','B',9);
$pdf->Cell(95,5,'Date/Time',1,0,'C',1);
$pdf->Cell(95,5,'IP Address',1,0,'C',1);
$pdf->Ln(5);
$pdf->SetFillColor(255,255,255);
$pdf->SetX(10);
$pdf->SetFont('Arial','',9);
foreach ($clicks_detailed as $click) {
$pdf->Cell(95,5,date('d/m/Y h:i:sa', $click->timestamp),1,0,'C',1);
$pdf->Cell(95,5,$click->ip_address,1,0,'C',1);
$pdf->Ln(5);
}
$pdf_path = plugin_dir_path(__FILE__)."../outputs/output.pdf";
$pdf->Output($pdf_path, "F");
echo str_replace("js/","",plugin_dir_url(__FILE__))."outputs/output.pdf";
?>