'0',
'akp_track_impressions' => '1',
'akp_track_clicks' => '1',
'akp_ga_intergrated' => '1',
'akp_ga_implemented' => 'universal',
'akp_ga_imp_action' => 'Impression',
'akp_ga_click_action' => 'Click',
'expiry_time' => '+6 hours',
'impression_expiry_time' => '+0 hours',
'akp_image_sizes' => '',
'akp_auth_role' => 'subscriber',
'akp_custom_css' => '/* Add any CSS you would like to modify your banner ads here */',
'akp_default_media_type' => 'image',
'akp_default_window_target' => 'blank',
'akp_default_nofollow' => '0',
'akp_default_remove_link' => '0',
'akp_default_rev_imp' => '0.00',
'akp_default_rev_click' => '0.00',
);
function __construct($static_func = NULL, $param = NULL) {
if (is_null($static_func)) {
add_action( 'admin_notices', array(&$this, 'admin_notice') );
add_action( 'admin_init', array(&$this, 'register_options') );
add_action( 'init', array(&$this, 'create_post_type') );
add_action( 'admin_head', array(&$this, 'wpt_icons') );
add_action( 'widgets_init', array(&$this, 'widget_registration') );
add_action( 'wp_enqueue_scripts', array(&$this, 'public_scripts') );
add_action( 'wp_head', array(&$this, 'public_dynamic_css') );
add_action( 'advert_types_edit_form_fields', array(&$this, 'extra_advert_types_fields'), 10, 2);
add_action( 'edited_advert_types', array(&$this, 'save_extra_advert_types_fields'), 10, 2);
add_action( 'init', array(&$this, 'image_sizes') );
add_action( 'do_meta_boxes', array(&$this, 'change_meta_boxes') );
add_action( 'post_submitbox_misc_actions', array(&$this, 'expiry_in_publish') );
add_action( 'save_post', array(&$this, 'save_custom_fields') );
add_action( 'wp_ajax_set-adverts_posts-akp_rollover_image-thumbnail', array(&$this, 'set_rollover') );
add_action( 'manage_adverts_posts_posts_custom_column', array(&$this, 'columns'), 10, 2);
add_action( 'admin_enqueue_scripts', array(&$this, 'enqueue') );
add_action( 'admin_menu', array(&$this, 'add_parent_page') );
add_filter( 'enter_title_here', array(&$this, 'title_text_input') );
add_filter( 'get_sample_permalink_html', array(&$this, 'remove_perma'), '', 4);
add_filter( 'gettext', array(&$this, 'swap_featured_image_metabox'), 10, 4);
add_filter( 'manage_edit-adverts_posts_columns',array(&$this, 'edit_adverts_columns') ) ;
} else {
return $this->$static_func($param);
}
}
function init() {
// Blank for now
}
public function check_page($hook) {
global $current_screen;
$akp_pages = array('adverts_posts_page_adkingpro');
$pages_req = array('post.php', 'post-new.php', 'edit.php');
if (in_array($hook, $akp_pages)) return true;
if (in_array($hook, $pages_req) && $current_screen->post_type == 'adverts_posts') return true;
return false;
}
public function allowed_cap() {
$role = get_option('akp_auth_role');
$cap = 'akp_edit_one';
switch ($role) {
case 'administrator':
$cap = 'akp_edit_five';
break;
case 'editor':
$cap = 'akp_edit_four';
break;
case 'author':
$cap = 'akp_edit_three';
break;
case 'contributor':
$cap = 'akp_edit_two';
break;
case 'subscriber':
$cap = 'akp_edit_one';
break;
}
return $cap;
}
// Check for capabilities and throw error if doesn't exist.
public function admin_notice() {
if (!current_user_can('akp_edit_one')) {
?>
Ad King Pro = __("capabilities haven't been added to the list which will prevent you from using Ad King Pro. Please deactivate and reactivate the plugin to add these .", 'akptext' ); ?>
adkingpro_options as $option=>$default_value) {
register_setting( 'akp-options', $option );
add_option( $option, $default_value );
}
}
public function unregister_options() {
foreach ($this->adkingpro_options as $option=>$default_value) unregister_setting( 'akp-options', $option );
}
public function delete_options() {
foreach ($this->adkingpro_options as $option=>$default_value) delete_option( $option );
}
// Register Adverts
public function create_post_type() {
$cap = $this->allowed_cap();
register_post_type( 'adverts_posts',
array(
'labels' => array(
'name' => __( 'Adverts', 'akptext' ),
'singular_name' => __( 'Advert', 'akptext' ),
'all_items' => __( 'All Adverts', 'akptext' ),
'edit_item' => __( 'Edit Advert', 'akptext' ),
'update_item' => __( 'Update Advert', 'akptext' ),
'add_new_item' => __( 'Add New Advert', 'akptext' ),
'new_item_name' => __( 'New Advert', 'akptext' ),
'menu_name' => _x( 'Adverts', 'admin menu', 'akptext' ),
'name_admin_bar' => _x( 'Advert', 'add new on admin bar', 'akptext' ),
'add_new' => _x( 'Add New', 'advert', 'akptext' ),
'new_item' => __( 'New Advert', 'akptext' ),
'view_item' => __( 'View Advert', 'akptext' ),
'search_items' => __( 'Search Adverts', 'akptext' ),
'parent_item_colon' => __( 'Parent Adverts:', 'akptext' ),
'not_found' => __( 'No adverts found.', 'akptext' ),
'not_found_in_trash' => __( 'No adverts found in Trash.', 'akptext' ),
),
'capabilities' => array(
'publish_posts' => $cap,
'edit_posts' => $cap,
'edit_others_posts' => $cap,
'delete_posts' => $cap,
'delete_others_posts' => $cap,
'read_private_posts' => $cap,
'edit_post' => $cap,
'delete_post' => $cap,
'read_post' => $cap,
),
'public' => true,
'exclude_from_search' => true,
'publicly_queryable' => false,
'show_in_nav_menus' => false,
'rewrite' => false,
'query_var' => false,
'menu_position' => 5,
'supports' => array( 'title', 'thumbnail' )
)
);
register_taxonomy(
'advert_types',
'adverts_posts',
array(
'hierarchical' => true,
'labels' => array(
'name'=>__('Advert Types', 'akptext' ),
'singular_name'=>__('Advert Type', 'akptext' ),
'all_items'=>__('All Advert Types', 'akptext' ),
'edit_item'=>__('Edit Advert Type', 'akptext' ),
'update_item'=>__('Update Advert Type', 'akptext' ),
'add_new_item'=>__('Add New Advert Type', 'akptext' ),
'new_item_name'=>__('New Advert Type', 'akptext' ),
'search_items'=>__('Search Advert Types', 'akptext' ),
),
'query_var' => false,
'rewrite' => array('slug' => 'adverts_slug')
)
);
}
public function widget_registration() {
register_widget( 'AdKingPro_Widget' );
}
// Styling for the custom post type icon
public function wpt_icons() {
?>
admin_url( 'admin-ajax.php' ), 'ajaxnonce' => wp_create_nonce( 'akpN0nc3' ), ) );
wp_enqueue_style('akp-dynamic-css', admin_url('admin-ajax.php').'?action=akp_dynamic_css');
}
public function public_dynamic_css() {
?>
term_id;
$cat_meta = get_option( "akp_advert_type_$t_id");
?>
= __("Leave the below blank to use the full size of the image you upload.", 'akptext') ?>
= __('Set width of advert', 'akptext'); ?>
= __('If variable, please leave blank', 'akptext'); ?>
= __('Set height of advert', 'akptext'); ?>
= __('If variable, please leave blank'); ?>
= __('Hard crop image?', 'akptext'); ?>
/>
'adverts_posts',
'numberposts' => -1,
'output' => 'object',
) );
foreach ( $adverts as $advert ) {
$attachments =& get_children(array('post_type'=>'attachment', 'post_mimi_type'=>'image', 'post_parent'=>$advert->ID));
foreach ($attachments as $attachment) {
$fullsizepath = get_attached_file( $attachment->ID );
if ( FALSE !== $fullsizepath && @file_exists($fullsizepath) ) {
set_time_limit( 30 );
$metadata = array();
if ( preg_match('!^image/!', get_post_mime_type( $attachment )) && file_is_displayable_image($fullsizepath) ) {
$imagesize = getimagesize( $fullsizepath );
$metadata['width'] = $imagesize[0];
$metadata['height'] = $imagesize[1];
list($uwidth, $uheight) = wp_constrain_dimensions($metadata['width'], $metadata['height'], 128, 96);
$metadata['hwstring_small'] = "height='$uheight' width='$uwidth'";
// Make the file path relative to the upload dir
$metadata['file'] = _wp_relative_upload_path($fullsizepath);
$intermediate_size = image_make_intermediate_size( $fullsizepath, $term_meta['advert_width'], $term_meta['advert_height'], $term_meta['advert_crop'] );
if ($intermediate_size)
$metadata['sizes']['akp_'.$t_id] = $intermediate_size;
// fetch additional metadata from exif/iptc
$image_meta = wp_read_image_metadata( $fullsizepath );
if ( $image_meta )
$metadata['image_meta'] = $image_meta;
}
wp_update_attachment_metadata( $attachment->ID, apply_filters( 'wp_generate_attachment_metadata', $metadata, $attachment->ID ) );
}
}
}
return;
}
}
public function image_sizes() {
if ( function_exists( 'add_image_size' ) ) {
$sizes = get_option('akp_image_sizes');
if (!empty($sizes)) :
foreach ($sizes as $image_name => $dimensions) {
if ($dimensions['crop'] == '1') $crop = true; else $crop = false;
add_image_size( $image_name, $dimensions['width'], $dimensions['width'], $crop);
}
endif;
}
}
// Update title field to become URL field
public function title_text_input( $title ){
global $post;
if($post->post_type == 'adverts_posts')
return $title = __('Advert URL ie http://kingpro.me/plugins/ad-king-pro', 'akptext');
return $title;
}
// Update Feature Image to become Advert Image
public function change_meta_boxes() {
add_meta_box('akpshortcode', __('Ad King Pro Shortcode Builder', 'akptext'), array(&$this, 'shortcode_builder'), 'adverts_posts', 'normal', 'high');
add_filter( "postbox_classes_adverts_posts_akpshortcode", array(&$this,'minify_akpshortcode') );
add_meta_box('akpmediatype', __('Media Type', 'akptext'), array(&$this, 'media_type'), 'adverts_posts', 'normal', 'high');
remove_meta_box( 'postimagediv', 'adverts_posts', 'side' );
if (current_theme_supports('post-thumbnails')) {
add_meta_box('postimagediv', __('Advert Image', 'akptext'), 'post_thumbnail_meta_box', 'adverts_posts', 'normal', 'high');
add_meta_box('postrolloverdiv', __('Advert Rollover Image', 'akptext'), array(&$this, 'rollover_image_box'), 'adverts_posts', 'normal', 'high');
add_meta_box('akpimageattrbox', __('Advert Image Attributes', 'akptext'), array(&$this, 'image_attrs_box'), 'adverts_posts', 'normal', 'high');
} else
add_meta_box('akpimagebox', __('Advert Image', 'akptext'), array(&$this, 'image_box'), 'adverts_posts', 'normal', 'high');
add_meta_box('akpflashbox', __('Advert Flash File', 'akptext'), array(&$this, 'flash_box'), 'adverts_posts', 'normal', 'high');
add_meta_box('akphtml5box', __('Advert HTML5 File', 'akptext'), array(&$this, 'html5_box'), 'adverts_posts', 'normal', 'high');
add_meta_box('akpadsensebox', __('Advert AdSense Code', 'akptext'), array(&$this, 'adsense_box'), 'adverts_posts', 'normal', 'high');
add_meta_box('akptextbox', __('Advert Text', 'akptext'), array(&$this, 'text_box'), 'adverts_posts', 'normal', 'high');
add_meta_box('akpgaintergration', __('Google Analytics Event Values', 'akptext'), array(&$this, 'ga_intergration'), 'adverts_posts', 'normal', 'high');
add_meta_box('linkoptionsdiv', __('Link Options', 'akptext'), array(&$this, 'link_options'), 'adverts_posts', 'side', 'low');
}
public function expiry_in_publish($post) {
global $post;
if (get_post_type($post) == 'adverts_posts') {
$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', 'akptext').': '.$expiry_output.'
'.__('Edit', 'akptext').'
'.__('01-Jan', 'akptext').'
'.__('02-Feb', 'akptext').'
'.__('03-Mar', 'akptext').'
'.__('04-Apr', 'akptext').'
'.__('05-May', 'akptext').'
'.__('06-Jun', 'akptext').'
'.__('07-Jul', 'akptext').'
'.__('08-Aug', 'akptext').'
'.__('09-Sep', 'akptext').'
'.__('10-Oct', 'akptext').'
'.__('11-Nov', 'akptext').'
'.__('12-Dec', 'akptext').'
, @ :
'.__('OK', 'akptext').'
'.__('Cancel', 'akptext').'
'.__('Set to Never', 'akptext').'
';
}
}
// Display example shortcode
public function shortcode_builder($object, $box) {
global $wpdb, $post;
?>
[adkingpro ]
$campaign, 'banner'=>$banner, 'implemented'=>$ga_implemented, 'imp_action'=>$ga_imp_action, 'click_action'=>$ga_click_action);
}
// GA Intergration fields
public function ga_intergration($object, $box) {
global $wpdb, $post;
$ga_data = $this->ga_data($post->ID);
echo ''.__('Campaign (GA Category)', 'akptext').' ';
echo ' ';
echo ''.__('Banner Name (GA Label)', 'akptext').' ';
echo ' ';
echo 'Below is what will be used to input data into your Google Analytics account for the events:
';
echo ''.__('Impressions Event', 'akptext').' ';
if ($ga_data['implemented'] == 'classic')
echo "_gaq.push(['_trackEvent','".$ga_data['campaign']." ','".$ga_data['imp_action']."', '".$ga_data['banner']." ']);
";
elseif ($ga_data['implemented'] == 'universal')
echo "ga('send', 'event', '".$ga_data['campaign']." ', '".$ga_data['imp_action']."', '".$ga_data['banner']." ');
";
echo ''.__('Clicks Event', 'akptext').' ';
if ($ga_data['implemented'] == 'classic')
echo "_gaq.push(['_trackEvent','".$ga_data['campaign']." ','".$ga_data['click_action']."', '".$ga_data['banner']." ']);
";
elseif ($ga_data['implemented'] == 'universal')
echo "ga('send', 'event', '".$ga_data['campaign']." ', '".$ga_data['click_action']."', '".$ga_data['banner']." ');
";
}
public function minify_akpshortcode( $classes ) {
array_push( $classes, 'closed' );
return $classes;
}
// Selection of media type
public function 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 ) : get_option('akp_default_media_type', 'image');
$html5 = ($media_type == 'html5') ? ' selected' : '';
$flash = ($media_type == 'flash') ? ' selected' : '';
$adsense = ($media_type == 'adsense') ? ' selected' : '';
$text = ($media_type == 'text') ? ' selected' : '';
echo "";
echo "".__('Image', 'akptext')." ";
echo "".__('HTML5', 'akptext')." ";
echo "".__('Flash', 'akptext')." ";
echo "".__('AdSense', 'akptext')." ";
echo "".__('Text', 'akptext')." ";
echo " ";
}
public function image_box($object, $box) {
global $post;
$image_url = (get_post_meta( $post->ID, 'akp_image_url', true )) ? get_post_meta( $post->ID, 'akp_image_url', true ) : '';
$image_rollover = (get_post_meta( $post->ID, 'akp_rollover_image', true )) ? get_post_meta( $post->ID, 'akp_rollover_image', true ) : '';
$image_alt = (get_post_meta( $post->ID, 'akp_image_alt', true )) ? get_post_meta( $post->ID, 'akp_image_alt', true ) : '';
echo '';
echo ' ';
echo ' ';
echo ' '.__('Enter a URL or upload an image (You are seeing this box as you have disabled "post-thumbnails" support.)', 'akptext');
echo ' ';
echo '';
echo ' ';
echo ' ';
echo ' '.__("Enter a URL or upload a rollover image (Leave blank if you don't want/need one)", 'akptext');
echo ' ';
echo ''.__('Banner description (this will be added to the alt tag on the image)', 'akptext').' ';
echo ' ';
echo ' ';
}
public function rollover_image_box($object, $box) {
global $post;
$thumbnail_id = get_post_meta($post->ID, "akp_rollover_image", true);
echo $this->rollover_image_box_html($thumbnail_id);
}
public function rollover_image_box_html($thumbnail_id = NULL) {
global $content_width, $_wp_additional_image_sizes, $post_ID, $wp_version;
$url_class = "";
if (version_compare($wp_version, '3.5', '<')) {
// Use the old thickbox for versions prior to 3.5
$image_library_url = get_upload_iframe_src('image');
// if TB_iframe is not moved to end of query string, thickbox will remove all query args after it.
$image_library_url = add_query_arg( array( 'context' => "akp_rollover_image", 'TB_iframe' => 1 ), remove_query_arg( 'TB_iframe', $image_library_url ) );
$url_class = "thickbox";
} else {
// Use the media modal for 3.5 and up
$image_library_url = "#";
}
$format_string = '%%s
';
$set_thumbnail_link = sprintf( $format_string, sprintf( esc_attr__( "Set %s" , 'multiple-post-thumbnails' ), "Rollover Image" ), $image_library_url, "advert_types", "akp_rollover_image", $url_class, "Rollver Image", $thumbnail_id );
$content = sprintf( $set_thumbnail_link, sprintf( esc_html__( "Set %s", 'multiple-post-thumbnails' ), "Rollover Image" ) );
if ($thumbnail_id && get_post($thumbnail_id)) {
$old_content_width = $content_width;
$content_width = 266;
if ( !isset($_wp_additional_image_sizes["adverts_posts-akp_rollover_image-thumbnail"]))
$thumbnail_html = wp_get_attachment_image($thumbnail_id, array($content_width, $content_width));
else
$thumbnail_html = wp_get_attachment_image($thumbnail_id, "adverts_posts-akp_rollover_image-thumbnail");
if (!empty($thumbnail_html)) {
$content = sprintf($set_thumbnail_link, $thumbnail_html);
$content .= 'Remove Rollover Image
';
}
$content_width = $old_content_width;
}
return $content;
}
public function image_attrs_box($object, $box) {
global $post;
$image_alt = (get_post_meta( $post->ID, 'akp_image_alt', true )) ? get_post_meta( $post->ID, 'akp_image_alt', true ) : '';
echo ''.__('Banner description (this will be added to the alt tag on the image)', 'akptext').' ';
echo ' ';
echo ' ';
}
public function html5_box($object, $box) {
global $post;
$html5_url = (get_post_meta( $post->ID, 'akp_html5_url', true )) ? get_post_meta( $post->ID, 'akp_html5_url', true ) : '';
$html5_width = (get_post_meta( $post->ID, 'akp_html5_width', true )) ? get_post_meta( $post->ID, 'akp_html5_width', true ) : '';
$html5_height = (get_post_meta( $post->ID, 'akp_html5_height', true )) ? get_post_meta( $post->ID, 'akp_html5_height', true ) : '';
echo '';
echo ' ';
echo ' ';
echo ' '.__('Enter a URL or upload a HTML5 file - PLEASE NOTE: Must contain at least one (1) anchor tag (<a />) with a "href" attribute', 'akptext');
echo ' ';
echo ''.__('Frame Width', 'akptext').' ';
echo ''.__('Frame Height', 'akptext').' ';
}
public function 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', 'akptext');
echo ' ';
echo ''.__('SWF Width', 'akptext').' ';
echo ''.__('SWF Height', 'akptext').' ';
}
public function 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', 'akptext').' ';
echo ' ';
echo ''.__('Please note that only impressions are tracked for these ads as the clicks are registers via AdSense', 'akptext').' ';
}
public function text_box($object, $box) {
global $post;
$text = (get_post_meta( $post->ID, 'akp_text', true )) ? get_post_meta( $post->ID, 'akp_text', true ) : '';
echo ''.__('Enter the text you would like on the link that will be tracked', 'akptext').' ';
echo ' ';
}
// Add checkbox to remove URL Link off advert
public function link_options($object, $box) {
global $post;
$remove_url = (get_post_meta( $post->ID, 'akp_remove_url', true )) ? get_post_meta( $post->ID, 'akp_remove_url', true ) : get_option('akp_default_remove_link', '0');
$target = (get_post_meta( $post->ID, 'akp_target', true )) ? get_post_meta( $post->ID, 'akp_target', true ) : get_option('akp_default_window_target', 'blank');
$self = ($target == 'self') ? ' selected' : '';
$parent = ($target == 'parent') ? ' selected' : '';
$top = ($target == 'top') ? ' selected' : '';
$none = ($target == 'none') ? ' selected' : '';
$nofollow = (get_post_meta( $post->ID, 'akp_nofollow', true )) ? get_post_meta( $post->ID, 'akp_nofollow', true ) : get_option('akp_default_nofollow', '0');
// Use nonce for verification
echo ' ';
echo ''.__("Remove URL from link", 'akptext').': ';
echo ' ';
echo '
';
echo "".__("Window Target", "akptext")." ";
echo "_blank ";
echo "_self ";
echo "_parent ";
echo "_top ";
echo "".__('none', 'akptext')." ";
echo "
";
echo ''.__('Add "nofollow" to link?', 'akptext').'
';
}
// Process the custom metabox fields
public function 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_media_type', $_POST['akp_media_type'] );
if (isset($_POST['akp_image_url']))
update_post_meta( $post->ID, 'akp_image_url', $_POST['akp_image_url'] );
if (isset($_POST['akp_rollover_image']))
update_post_meta( $post->ID, 'akp_rollover_image', $_POST['akp_rollover_image'] );
update_post_meta( $post->ID, 'akp_image_alt', $_POST['akp_image_alt'] );
update_post_meta( $post->ID, 'akp_html5_url', $_POST['akp_html5_url'] );
update_post_meta( $post->ID, 'akp_html5_width', $_POST['akp_html5_width'] );
update_post_meta( $post->ID, 'akp_html5_height', $_POST['akp_html5_height'] );
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'] );
update_post_meta( $post->ID, 'akp_text', $_POST['akp_text'] );
update_post_meta( $post->ID, 'akp_ga_campaign', $_POST['akp_ga_campaign']);
update_post_meta( $post->ID, 'akp_ga_banner', $_POST['akp_ga_banner']);
if (isset($_POST['akp_target']))
update_post_meta( $post->ID, 'akp_target', $_POST['akp_target'] );
if (isset($_POST['akp_nofollow']))
update_post_meta( $post->ID, 'akp_nofollow', $_POST['akp_nofollow'] );
}
}
// Ajax save for rollover uploader
public function set_rollover() {
global $post_ID;
if (wp_verify_nonce( $_POST['_ajax_nonce'], "akpN0nc3" )) {
$post_ID = intval($_POST['post_id']);
if ( !current_user_can('edit_post', $post_ID))
die('-1');
$thumbnail_id = intval($_POST['thumbnail_id']);
if ($thumbnail_id == '-1') {
delete_post_meta($post_ID, "akp_rollover_image");
die(akp_rollover_image_box_html(NULL));
}
if ($thumbnail_id && get_post($thumbnail_id)) {
$thumbnail_html = wp_get_attachment_image($thumbnail_id, 'thumbnail');
if (!empty($thumbnail_html)) {
update_post_meta($post_ID, "akp_rollover_image", $thumbnail_id);
die(rollover_image_box_html($thumbnail_id));
}
}
}
die('0');
}
// Process the custom metabox fields
public function 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_media_type'] = (get_post_meta( $id, 'akp_media_type' ) ? get_post_meta( $id, 'akp_media_type' ) : array(''));
$output['akp_image_url'] = (get_post_meta( $id, 'akp_image_url' ) ? get_post_meta( $id, 'akp_image_url' ) : array(''));
$output['akp_rollover_image'] = (get_post_meta( $id, 'akp_rollover_image' ) ? get_post_meta( $id, 'akp_rollover_image' ) : array(''));
$output['akp_image_alt'] = (get_post_meta( $id, 'akp_image_alt' ) ? get_post_meta( $id, 'akp_image_alt' ) : array(''));
$output['akp_html5_url'] = (get_post_meta( $id, 'akp_html5_url' ) ? get_post_meta( $id, 'akp_html5_url' ) : array(''));
$output['akp_html5_width'] = (get_post_meta( $id, 'akp_html5_width' ) ? get_post_meta( $id, 'akp_html5_width' ) : array(''));
$output['akp_html5_height'] = (get_post_meta( $id, 'akp_html5_height' ) ? get_post_meta( $id, 'akp_html5_height' ) : 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(''));
$output['akp_text'] = (get_post_meta( $id, 'akp_text' ) ? get_post_meta( $id, 'akp_text' ) : array(''));
$output['akp_target'] = (get_post_meta( $id, 'akp_target' ) ? get_post_meta( $id, 'akp_target' ) : array('blank'));
$output['akp_nofollow'] = (get_post_meta( $id, 'akp_nofollow' ) ? get_post_meta( $id, 'akp_nofollow' ) : array('0'));
$output['akp_ga_campaign'] = (get_post_meta( $id, 'akp_ga_campaign' ) ? get_post_meta( $id, 'akp_ga_campaign' ) : array(''));
$output['akp_ga_banner'] = (get_post_meta( $id, 'akp_ga_banner' ) ? get_post_meta( $id, 'akp_ga_banner' ) : array(''));
return $output;
}
// Remove the Permalinks
public function remove_perma($return, $id, $new_title, $new_slug){
global $post;
if(isset($post->post_type) && $post->post_type == 'adverts_posts') return '';
return $return;
}
// Change text labels
public function 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;
}
// Columns in custom post types
public function edit_adverts_columns( $columns ) {
$columns = array(
'cb' => ' ',
'banner_id' => __( 'Banner ID', 'akptext' ),
'shortcode' => __( 'Shortcode', 'akptext'),
'title' => __( 'URL', 'akptext' ),
'media_type' => __( 'Media','akptext'),
'advert_type' => __( 'Advert Type', 'akptext'),
'advert_image' => __( 'Advert Image', 'akptext'),
'date' => __( 'Date', 'akptext' ),
);
return $columns;
}
// Update column data with custom data
public function 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', 'akptext');
}
break;
case 'advert_image' :
$post_featured_image = $this->get_featured_image($ID);
if ($post_featured_image) {
echo ' ';
}
break;
case 'banner_id' :
echo $ID;
break;
case 'shortcode' :
echo "[adkingpro banner=\"$ID\"]";
break;
case 'media_type' :
global $wpdb;
$mediatype = get_post_meta($ID, 'akp_media_type');
echo strtoupper($mediatype[0]);
break;
}
}
// GET FEATURED IMAGE
public function get_featured_image($post_ID, $thumb = 'custom_thumbnail') {
$post_thumbnail_id = get_post_thumbnail_id($post_ID);
if ($post_thumbnail_id) {
$post_thumbnail_img = wp_get_attachment_image_src($post_thumbnail_id, $thumb);
return $post_thumbnail_img[0];
}
}
function log_impression($post_id) {
// GA Enabled
$ga_data = $this->ga_data($post_id);
if ($ga_data['implemented'] == 'classic')
$output = "";
elseif ($ga_data['implemented'] == 'universal')
$output = "";
return $output;
}
function enqueue($hook) {
if ($this->check_page($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_register_style( 'fontawesome', plugins_url('css/font-awesome.min.css', dirname(__FILE__)), false, '3.2.1');
wp_enqueue_style('akp_jquery_ui');
wp_enqueue_style( 'fontawesome' );
wp_enqueue_style( 'akp_css' );
wp_enqueue_style( 'thickbox' );
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');
wp_enqueue_script( 'thickbox' );
// 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' ) ) );
endif;
}
function add_parent_page() {
if (current_user_can($this->allowed_cap())) {
add_submenu_page('edit.php?post_type=adverts_posts', 'Settings', 'Settings', 'akp_edit_one', 'adkingpro', array(&$this, 'settings_output') );
}
}
function settings_output() {
include 'screens/settings.php';
}
}
}
new AKP_Admin();