array(
'name' => __( 'Adverts' ),
'singular_name' => __( 'Advert' ),
'all_items'=>'All Adverts',
'edit_item'=>'Edit Advert',
'update_item'=>'Update Advert',
'add_new_item'=>'Add New Advert',
'new_item_name'=>'New Advert',
),
'public' => true,
'exclude_from_search' => true,
'menu_position' => 5,
'supports' => array( 'title', 'thumbnail' )
)
);
}
add_action( 'init', 'akp_create_post_type' );
function akp_widget_registration() {
register_widget( 'AdKingPro_Widget' );
}
add_action( 'widgets_init', 'akp_widget_registration');
// Add scripts to page
function akp_my_scripts_method() {
wp_deregister_script( 'jquery' );
wp_register_script( 'jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js');
wp_enqueue_script( 'jquery' );
wp_enqueue_script(
'adkingpro-js',
plugins_url('js/adkingpro-functions.js', dirname(__FILE__)),
array('jquery')
);
wp_localize_script( 'adkingpro-js', 'AkpAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'ajaxnonce' => wp_create_nonce( 'akpN0nc3' ), ) );
}
add_action('wp_enqueue_scripts', 'akp_my_scripts_method');
// Update title field to become URL field
function akp_title_text_input( $title ){
global $post;
if($post->post_type == 'adverts_posts')
return $title = 'Advert URL ie http://durham.net.au/wp-plugins/adkingpro';
return $title;
}
add_filter( 'enter_title_here', 'akp_title_text_input' );
// Update Feature Image to become Advert Image
function akp_change_meta_boxes()
{
add_meta_box('akpmediatype', __('Media Type'), 'akp_media_type', 'adverts_posts', 'normal', 'high');
remove_meta_box( 'postimagediv', 'adverts_posts', 'side' );
add_meta_box('postimagediv', __('Advert Image'), 'post_thumbnail_meta_box', 'adverts_posts', 'normal', 'high');
add_meta_box('akpflashbox', __('Advert Flash File'), 'akp_flash_box', 'adverts_posts', 'normal', 'high');
add_meta_box('akpadsensebox', __('Advert AdSense Code'), 'akp_adsense_box', 'adverts_posts', 'normal', 'high');
add_meta_box('postremoveurllink', __('Remove Link from Advert?'), 'akp_remove_url_link', 'adverts_posts', 'advanced', 'high');
add_meta_box('postclickstatsdiv', __('Advert Stats'), 'akp_post_click_stats', 'adverts_posts', 'advanced', 'low');
add_meta_box('revenuevaluesdiv', __('Advert Revenue'), 'akp_revenue_values', 'adverts_posts', 'side', 'low');
}
add_action('do_meta_boxes', 'akp_change_meta_boxes');
add_action( 'post_submitbox_misc_actions', 'expiry_in_publish' );
function expiry_in_publish($post)
{
global $post;
$expiry = (get_post_meta($post->ID, 'akp_expiry_date', true)) ? get_post_meta($post->ID, 'akp_expiry_date', true) : 'never';
if ($expiry !== 'never') {
$expiry_m = date('m', $expiry);
$expiry_d = date('d', $expiry);
$expiry_y = date('Y', $expiry);
$expiry_h = date('H', $expiry);
$expiry_i = date('i', $expiry);
$expiry_output = date('M j, Y @ G:i', $expiry);
$expiry_value = date('Y-m-d G:i:s', $expiry);
} else {
$expiry_output = 'Never';
$expiry_value = $expiry;
$expiry_m = date('m', current_time('timestamp'));
$expiry_d = date('d', current_time('timestamp'));
$expiry_y = date('Y', current_time('timestamp'));
$expiry_h = date('H', current_time('timestamp'));
$expiry_i = date('i', current_time('timestamp'));
}
echo '
Expire on: '.$expiry_output.'
Edit
';
}
// Selection of media type
function akp_media_type($object, $box) {
global $wpdb, $post;
$media_type = (get_post_meta( $post->ID, 'akp_media_type', true )) ? get_post_meta( $post->ID, 'akp_media_type', true ) : 'image';
$flash = ($media_type == 'flash') ? ' selected' : '';
$adsense = ($media_type == 'adsense') ? ' selected' : '';
echo "";
echo "Image ";
echo "Flash ";
echo "AdSense ";
echo " ";
}
function akp_flash_box($object, $box) {
global $post;
$flash_url = (get_post_meta( $post->ID, 'akp_flash_url', true )) ? get_post_meta( $post->ID, 'akp_flash_url', true ) : '';
$flash_width = (get_post_meta( $post->ID, 'akp_flash_width', true )) ? get_post_meta( $post->ID, 'akp_flash_width', true ) : '';
$flash_height = (get_post_meta( $post->ID, 'akp_flash_height', true )) ? get_post_meta( $post->ID, 'akp_flash_height', true ) : '';
echo '';
echo ' ';
echo ' ';
echo ' Enter a URL or upload a SWF file';
echo ' ';
echo 'SWF Width ';
echo 'SWF Height ';
}
function akp_adsense_box($object, $box) {
global $post;
$adsense_code = (get_post_meta( $post->ID, 'akp_adsense_code', true )) ? get_post_meta( $post->ID, 'akp_adsense_code', true ) : '';
echo 'Enter the Ad Unit Code given from your Google AdSense account ';
echo ' ';
echo 'Please note that only impressions are tracked for these ads as the clicks are registers via AdSense ';
}
// Output stats for post
function akp_post_click_stats($object, $box) {
global $wpdb;
$clicks = $wpdb->get_results("SELECT COUNT(*) as clicks FROM ".$wpdb->prefix."akp_click_log WHERE post_id = '$object->ID'");
echo "This banner has had ".$clicks[0]->clicks." since being published. View Detailed Report ";
}
// Add checkbox to remove URL Link off advert
function akp_remove_url_link($object, $box) {
global $post;
$remove_url = get_post_meta( $post->ID, 'akp_remove_url', true );
// Use nonce for verification
echo ' ';
echo ' ';
}
// Add checkbox to remove URL Link off advert
function akp_revenue_values($object, $box) {
global $post;
$revenue_impression = get_post_meta( $post->ID, 'akp_revenue_per_impression', true );
$revenue_click = get_post_meta( $post->ID, 'akp_revenue_per_click', true );
echo 'Revenue Per Impression: ';
echo ' ';
echo '
';
echo 'Revenue Per Click: ';
echo ' ';
echo '
';
}
// Process the custom metabox fields
function akp_save_custom_fields( ) {
global $post;
// verify nonce
if (!isset($_POST['akp_meta_box_nonce']) || !wp_verify_nonce($_POST['akp_meta_box_nonce'], basename(__FILE__))) {
return;
}
if( $_POST ) {
if (isset($_POST['akp_remove_url']))
update_post_meta( $post->ID, 'akp_remove_url', $_POST['akp_remove_url'] );
else
update_post_meta( $post->ID, 'akp_remove_url', 0 );
if ($_POST['akp_expiry_date'] == 'never') update_post_meta( $post->ID, 'akp_expiry_date', $_POST['akp_expiry_date'] );
else {
update_post_meta( $post->ID, 'akp_expiry_date', strtotime($_POST['akp_expiry_date']) );
}
update_post_meta( $post->ID, 'akp_revenue_per_impression', $_POST['akp_revenue_per_impression'] );
update_post_meta( $post->ID, 'akp_revenue_per_click', $_POST['akp_revenue_per_click'] );
update_post_meta( $post->ID, 'akp_media_type', $_POST['akp_media_type'] );
update_post_meta( $post->ID, 'akp_flash_url', $_POST['akp_flash_url'] );
update_post_meta( $post->ID, 'akp_flash_width', $_POST['akp_flash_width'] );
update_post_meta( $post->ID, 'akp_flash_height', $_POST['akp_flash_height'] );
update_post_meta( $post->ID, 'akp_adsense_code', $_POST['akp_adsense_code'] );
}
}
add_action( 'save_post', 'akp_save_custom_fields' );
// Process the custom metabox fields
function akp_return_fields( $id = NULL ) {
global $post;
if (is_null($id)) $id = $post->ID;
$output = array();
$output['akp_remove_url'] = (get_post_meta( $id, 'akp_remove_url' ) ? get_post_meta( $id, 'akp_remove_url' ) : array(''));
$output['akp_expiry_date'] = (get_post_meta( $id, 'akp_expiry_date' ) ? get_post_meta( $id, 'akp_expiry_date' ) : 'never');
$output['akp_revenue_per_impression'] = (get_post_meta( $id, 'akp_revenue_per_impression' ) ? get_post_meta( $id, 'akp_revenue_per_impression' ) : array(''));
$output['akp_revenue_per_click'] = (get_post_meta( $id, 'akp_revenue_per_click' ) ? get_post_meta( $id, 'akp_revenue_per_click' ) : array(''));
$output['akp_media_type'] = (get_post_meta( $id, 'akp_media_type' ) ? get_post_meta( $id, 'akp_media_type' ) : array(''));
$output['akp_flash_url'] = (get_post_meta( $id, 'akp_flash_url' ) ? get_post_meta( $id, 'akp_flash_url' ) : array(''));
$output['akp_flash_width'] = (get_post_meta( $id, 'akp_flash_width' ) ? get_post_meta( $id, 'akp_flash_width' ) : array(''));
$output['akp_flash_height'] = (get_post_meta( $id, 'akp_flash_height' ) ? get_post_meta( $id, 'akp_flash_height' ) : array(''));
$output['akp_adsense_code'] = (get_post_meta( $id, 'akp_adsense_code' ) ? get_post_meta( $id, 'akp_adsense_code' ) : array(''));
return $output;
}
// Remove the Permalinks
function akp_perm($return, $id, $new_title, $new_slug){
global $post;
if(isset($post->post_type) && $post->post_type == 'adverts_posts') return '';
return $return;
}
add_filter('get_sample_permalink_html', 'akp_perm', '', 4);
// Change text labels
function akp_swap_featured_image_metabox($translation, $text, $domain) {
global $post;
$translations = get_translations_for_domain( $domain);
if (isset($post->post_type)) {
switch( $post->post_type ){
case 'adverts_posts':
if ( $text == 'Set featured image')
return $translations->translate( 'Set Advert Image' );
if ( $text == 'Remove featured image')
return $translations->translate( 'Remove Advert Image' );
break;
}
}
return $translation;
}
add_filter('gettext', 'akp_swap_featured_image_metabox', 10, 4);
// Register Advert types taxonomy
function akp_taxonomies() {
register_taxonomy(
'advert_types',
'adverts_posts',
array(
'hierarchical' => true,
'labels' => array(
'name'=>'Advert Types',
'singular_name'=>'Advert Type',
'all_items'=>'All Advert Types',
'edit_item'=>'Edit Advert Type',
'update_item'=>'Update Advert Type',
'add_new_item'=>'Add New Advert Type',
'new_item_name'=>'New Advert Type',
'search_items'=>'Search Advert Types',
),
'query_var' => true,
'rewrite' => array('slug' => 'adverts_slug')
)
);
}
add_action( 'init', 'akp_taxonomies' );
// Columns in custom post types
function akp_edit_adverts_columns( $columns ) {
$columns = array(
'cb' => ' ',
'banner_id' => __( 'Banner ID' ),
'impressions' => __( 'Impressions' ),
'clicks' => __( 'Clicks' ),
'title' => __( 'URL' ),
'advert_type' => __( 'Advert Type'),
'advert_image' => __( 'Advert Image'),
'date' => __( 'Date' ),
);
return $columns;
}
add_filter( 'manage_edit-adverts_posts_columns', 'akp_edit_adverts_columns' ) ;
// Update column data with custom data
function akp_columns($column_name, $ID) {
switch ($column_name) {
case 'advert_type' :
$terms = get_the_terms( $ID, 'advert_types' );
if ( !empty( $terms ) ) {
$out = array();
foreach ( $terms as $term ) {
$out[] = sprintf( '%s ',
esc_url( add_query_arg( array( 'post_type' => 'adverts_posts', 'advert_type' => $term->slug ), 'edit.php' ) ),
esc_html( sanitize_term_field( 'name', $term->name, $term->term_id, 'genre', 'display' ) )
);
}
echo join( ', ', $out );
} else {
echo 'No Advert Types Assigned';
}
break;
case 'advert_image' :
$post_featured_image = akp_get_featured_image($ID);
if ($post_featured_image) {
echo ' ';
}
break;
case 'banner_id' :
echo $ID;
break;
case 'impressions' :
global $wpdb;
$revenue = get_post_meta($ID, 'akp_revenue_per_impression');
if (!isset($revenue[0]) || $revenue[0] == '') $revenue[0] = '0.00';
$sign = get_option('revenue_currency');
$impressions = $wpdb->get_results("SELECT COUNT(*) as impressions FROM ".$wpdb->prefix."akp_impressions_log WHERE post_id = '$ID'");
echo $sign.$revenue[0]." x ".$impressions[0]->impressions;
break;
case 'clicks' :
global $wpdb;
$revenue = get_post_meta($ID, 'akp_revenue_per_click');
if (!isset($revenue[0]) || $revenue[0] == '') $revenue[0] = '0.00';
$sign = get_option('revenue_currency');
$clicks = $wpdb->get_results("SELECT COUNT(*) as clicks FROM ".$wpdb->prefix."akp_click_log WHERE post_id = '$ID'");
echo $sign.$revenue[0]." x ".$clicks[0]->clicks;
break;
}
}
add_action('manage_adverts_posts_posts_custom_column', 'akp_columns', 10, 2);
// GET FEATURED IMAGE
function akp_get_featured_image($post_ID) {
$post_thumbnail_id = get_post_thumbnail_id($post_ID);
if ($post_thumbnail_id) {
$post_thumbnail_img = wp_get_attachment_image_src($post_thumbnail_id, 'custom_thumbnail');
return $post_thumbnail_img[0];
}
}
function akp_log_impression($post_id) {
$timestamp = current_time('timestamp');
$expire = strtotime(get_option('impression_expiry_time'), $timestamp);
$ip_address = $_SERVER['REMOTE_ADDR'];
global $wpdb;
$ip = $wpdb->get_row("SELECT * FROM ".$wpdb->prefix."akp_impressions_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_impressions_expire
WHERE post_id = %d
AND ip_address = %s
",
$post_id, $ip_address
)
);
$wpdb->query( $wpdb->prepare(
"INSERT INTO ".$wpdb->prefix."akp_impressions_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_impressions_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_impressions_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_impressions_expire
( post_id, ip_address, expire )
VALUES ( %d, %s, %d )",
array(
$post_id,
$ip_address,
$expire
)
) );
}
}
// Dashboard Widget
function akp_enqueue($hook) {
wp_register_style( 'akp_jquery_ui', plugins_url('css/jquery-ui.css', dirname(__FILE__)), false, '1.9.2' );
wp_register_style( 'akp_css', plugins_url('css/adkingpro-styles.css', dirname(__FILE__)), false, '1.0.0' );
wp_enqueue_style('akp_jquery_ui');
wp_enqueue_style( 'akp_css' );
wp_enqueue_script( 'jquery-ui-datepicker');
wp_register_script('akp_admin_js', plugins_url( '/js/adkingpro-admin-functions.js', dirname(__FILE__) ), array('jquery', 'jquery-ui-datepicker'), '1.0.0');
wp_enqueue_script( 'akp_admin_js');
// in javascript, object properties are accessed as ajax_object.ajax_url, ajax_object.we_value
wp_localize_script( 'akp_admin_js', 'akp_ajax_object',
array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'akp_ajaxnonce' => wp_create_nonce( 'akpN0nc3' ) ) );
}
add_action( 'admin_enqueue_scripts', 'akp_enqueue' );
function akp_dashboard() {
global $wpdb;
$advert_types = get_terms('advert_types');
$count = count($advert_types);
if ($count > 0) {
foreach ($advert_types as $type) {
echo "$type->name ";
query_posts(array(
'post_type'=>'adverts_posts',
'advert_types'=>$type->slug
));
echo "";
while (have_posts()) : the_post();
$post_id = get_the_ID();
$image = akp_get_featured_image($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'");
// 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'");
// 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'");
// 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'");
?>
All Time = $all_clicks[0]->clicks ?>
This Month = $month_clicks[0]->clicks ?>
This Week = $week_clicks[0]->clicks ?>
Today = $today_clicks[0]->clicks ?>
";
wp_reset_query();
}
} else {
// No advert types set
}
}
function akp_add_dashboard_widgets() {
wp_add_dashboard_widget('akp_dashboard_widget', 'Ad King Pro - Banner Stats Summary', 'akp_dashboard');
}
add_action('wp_dashboard_setup', 'akp_add_dashboard_widgets' );
// Add settings area
function adkingpro_settings() {
add_options_page('Ad King Pro', 'Ad King Pro', 'manage_options', 'adkingpro', 'akp_settings_output');
add_dashboard_page('Ad King Pro Detailed Stats', 'Ad King Pro Stats', 'read', 'akp-detailed-stats', 'akp_detailed_output');
}
add_action('admin_menu', 'adkingpro_settings');
function register_akp_options() {
register_setting( 'akp-options', 'expiry_time' );
register_setting( 'akp-options', 'impression_expiry_time' );
register_setting( 'akp-options', 'week_start' );
register_setting( 'akp-options', 'revenue_currency' );
register_setting( 'akp-options', 'pdf_theme' );
}
add_action( 'admin_init', 'register_akp_options' );
function akp_settings_output() {
?>
Ad King Pro
How To
Use Shortcodes
Shortcodes can be used in any page or post on your site. By default:
[adkingpro]
is defaulting to the advert type 'Sidebar' and randomly chosing from that. You can define your own advert type and display the adverts attached to that type by:
[adkingpro type="your-advert-type-slug"]
Alternatively, you can display a single advert by entering its "Banner ID" which can be found in the table under the Adverts section:
[adkingpro banner="{banner_id}"]
To add this into a template, just use the "do_shortcode" function:
<?= do_shortcode("[adkingpro]"); ?>
Install PDF Themes
Download themes from my plugin page . Locate the themes folder in the adkingpro plugin folder, generally located:
/wp-content/plugins/adkingpro/themes/
Unzip the downloaded zip file and upload the entire folder into the themes folder mentioned above.
Once uploaded, return to this page and your theme will be present in the PDF Theme dropdown to the left. Choose the theme and save the options. Next time you generate a report, the theme you have chosen will be used.
The ability to upload the zip file straight from here will be added soon
FAQ
Q. After activating this plugin, my site has broken! Why?
Nine times out of ten it will be due to your own scripts being added above the standard area where all the plugins are included.
If you move your javascript files below the function, "wp_head()" in the "header.php" file of your theme, it should fix your problem.
Q. I want to track clicks on a banner that scrolls to or opens a flyout div on my site. Is it possible?
Yes. Enter a '#' in as the URL for the banner when setting it up. At output, the banner is given a number of classes to allow for styling, one being "banner{banner_id}",
where you would replace the "{banner_id}" for the number in the required adverts class.
Use this in a jquery click event and prevent the default action of the click to make it do the action you require:
$(".adkingprobanner.banner{banner_id}").click(
function(e) {
e.preventDefault();
// Your action here
});
Found an issue? Please email your concern to contact@durham.net.au
Ad King Pro Detailed Stats
'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 = $dets['akp_revenue_per_impression'][0];
$all_click_cost = $dets['akp_revenue_per_click'][0];
$all_per_impression = $currency_sign.number_format((int) $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((int) $all_click_cost, 2);
$all_click_total = $all_click_cost * $all_clicks[0]->clicks;
$all_click_total_output = $currency_sign.number_format((int) $all_click_total, 2);
$all_total_made = $all_impression_total + $all_click_total;
$all_total_made_output = $currency_sign.number_format((int) $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 = $dets['akp_revenue_per_impression'][0];
$month_click_cost = $dets['akp_revenue_per_click'][0];
$month_per_impression = $currency_sign.number_format((int) $month_impression_cost, 2);
$month_impression_total = $month_impression_cost * $month_impressions[0]->impressions;
$month_impression_total_output = $currency_sign.number_format((int) $month_impression_total, 2);
$month_per_click = $currency_sign.number_format((int) $month_click_cost, 2);
$month_click_total = $month_click_cost * $month_clicks[0]->clicks;
$month_click_total_output = $currency_sign.number_format((int) $month_click_total, 2);
$month_total_made = $month_impression_total + $month_click_total;
$month_total_made_output = $currency_sign.number_format((int) $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 = $dets['akp_revenue_per_impression'][0];
$week_click_cost = $dets['akp_revenue_per_click'][0];
$week_per_impression = $currency_sign.number_format((int) $week_impression_cost, 2);
$week_impression_total = $week_impression_cost * $week_impressions[0]->impressions;
$week_impression_total_output = $currency_sign.number_format((int) $week_impression_total, 2);
$week_per_click = $currency_sign.number_format((int) $week_click_cost, 2);
$week_click_total = $week_click_cost * $week_clicks[0]->clicks;
$week_click_total_output = $currency_sign.number_format((int) $week_click_total, 2);
$week_total_made = $week_impression_total + $week_click_total;
$week_total_made_output = $currency_sign.number_format((int) $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 = $dets['akp_revenue_per_impression'][0];
$today_click_cost = $dets['akp_revenue_per_click'][0];
$today_per_impression = $currency_sign.number_format((int) $today_impression_cost, 2);
$today_impression_total = $today_impression_cost * $today_impressions[0]->impressions;
$today_impression_total_output = $currency_sign.number_format((int) $today_impression_total, 2);
$today_per_click = $currency_sign.number_format((int) $today_click_cost, 2);
$today_click_total = $today_click_cost * $today_clicks[0]->clicks;
$today_click_total_output = $currency_sign.number_format((int) $today_click_total, 2);
$today_total_made = $today_impression_total + $today_click_total;
$today_total_made_output = $currency_sign.number_format((int) $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");
?>
Summary
All Time = $all_clicks[0]->clicks ?>
This Month = $month_clicks[0]->clicks ?>
This Week = $week_clicks[0]->clicks ?>
Today = $today_clicks[0]->clicks ?>
Detailed
Count
Cost Per
Total
Impressions
= $all_impressions[0]->impressions ?>
= $all_per_impression ?>
= $all_impression_total_output ?>
Clicks
= $all_clicks[0]->clicks ?>
= $all_per_click ?>
= $all_click_total_output ?>
TOTAL
= $all_total_made_output ?>
Date/Time
IP Address
= date('d/m/Y h:i:sa', $acd->timestamp) ?>
= $acd->ip_address ?>
Date/Time
IP Address
Count
Cost Per
Total
Impressions
= $month_impressions[0]->impressions ?>
= $month_per_impression ?>
= $month_impression_total_output ?>
Clicks
= $month_clicks[0]->clicks ?>
= $month_per_click ?>
= $month_click_total_output ?>
TOTAL
= $month_total_made_output ?>
Date/Time
IP Address
= date('d/m/Y h:i:sa', $acd->timestamp) ?>
= $acd->ip_address ?>
Date/Time
IP Address
Count
Cost Per
Total
Impressions
= $week_impressions[0]->impressions ?>
= $week_per_impression ?>
= $week_impression_total_output ?>
Clicks
= $week_clicks[0]->clicks ?>
= $week_per_click ?>
= $week_click_total_output ?>
TOTAL
= $week_total_made_output ?>
Date/Time
IP Address
= date('d/m/Y h:i:sa', $acd->timestamp) ?>
= $acd->ip_address ?>
Date/Time
IP Address
Count
Cost Per
Total
Impressions
= $today_impressions[0]->impressions ?>
= $today_per_impression ?>
= $today_impression_total_output ?>
Clicks
= $today_clicks[0]->clicks ?>
= $today_per_click ?>
= $today_click_total_output ?>
TOTAL
= $today_total_made_output ?>
Date/Time
IP Address
= date('d/m/Y h:i:sa', $acd->timestamp) ?>
= $acd->ip_address ?>
Date/Time
IP Address