array( 'label' => __( 'Settings', 'adsense-plugin' ) ),
'settings_vi' => array( 'label' => __( 'VI Intelligence', 'adsense-plugin' ) ),
'misc' => array( 'label' => __( 'Misc', 'adsense-plugin' ) ),
'custom_code' => array( 'label' => __( 'Custom Code', 'adsense-plugin' ) ),
'license' => array( 'label' => __( 'License Key', 'adsense-plugin' ) ),
);
parent::__construct( array(
'plugin_basename' => $plugin_basename,
'plugins_info' => $adsns_plugin_info,
'prefix' => 'adsns',
'default_options' => adsns_default_options(),
'options' => $adsns_options,
'is_network_options' => is_network_admin(),
'tabs' => $tabs,
'wp_slug' => '',
'pro_page' => 'admin.php?page=adsense-pro.php',
'bws_license_plugin' => 'adsense-pro/adsense-pro.php',
'link_key' => '2887beb5e9d5e26aebe6b7de9152ad1f',
'link_pn' => '80'
) );
$this->vi_revenue = adsns_vi_get_revenue();
$this->adsns_client = adsns_client();
add_filter( get_parent_class( $this ) . '_display_custom_messages', array( $this, 'display_custom_messages' ) );
}
/**
* Display custom error\message\notice
* @access public
* @param $save_results - array with error\message\notice
* @return void
*/
public function display_custom_messages( $save_results ) {
if ( isset( $this->options['authorization_code'] ) ) {
$this->adsns_client->setAccessToken( $this->options['authorization_code'] );
}
if ( $this->adsns_client->getAccessToken() ) {
$adsns_adsense = new Google_Service_AdSense( $this->adsns_client );
$adsns_adsense_accounts = $adsns_adsense->accounts;
$adsns_adsense_adclients = $adsns_adsense->adclients;
$adsns_adsense_adunits = $adsns_adsense->adunits;
try {
$adsns_list_accounts = $adsns_adsense_accounts->listAccounts()->getItems();
} catch ( Google_Service_Exception $e ) {
$adsns_err = $e->getErrors(); ?>
%s %s %s',
__( 'Account Error:', 'adsense-plugin' ),
$adsns_err[0]['message'],
sprintf( __( 'Create account in %s', 'adsense-plugin' ), 'Google AdSense.' )
); ?>
options['authorization_code'], $this->options['publisher_id'] );
} else {
if ( ! empty( $_POST['adsns_authorization_code'] ) ) {
try {
$this->adsns_client->authenticate( sanitize_text_field( $_POST['adsns_authorization_code'] ) );
$this->options['authorization_code'] = sanitize_text_field( $this->adsns_client->getAccessToken() );
if ( isset( $this->options['authorization_code'] ) ) {
$this->adsns_client->setAccessToken( $this->options['authorization_code'] );
}
if ( $this->adsns_client->getAccessToken() ) {
$adsns_adsense = new Google_Service_AdSense( $this->adsns_client );
$adsns_adsense_accounts = $adsns_adsense->accounts;
$adsns_adsense_adclients = $adsns_adsense->adclients;
$adsns_adsense_adunits = $adsns_adsense->adunits;
try {
$adsns_list_accounts = $adsns_adsense_accounts->listAccounts()->getItems();
$this->options['publisher_id'] = $adsns_list_accounts[0]['id'];
adsns_vi_create_ads_file( 'google', adsns_vi_get_google_ads_file_content() );
} catch ( Exception $e ) {}
}
} catch ( Exception $e ) {}
}
if ( isset( $this->options['publisher_id'] ) ) {
$this->options['include_inactive_ads'] = ( isset( $_POST['adsns_include_inactive_id'] ) ) ? 1 : 0;
}
if ( isset( $_POST['adsns_authorization_code'] ) && isset( $_POST['adsns_authorize'] ) && ! $this->adsns_client->getAccessToken() ) {
$error .= __( 'Invalid authorization code. Please, try again.', 'adsense-plugin' );
}
}
update_option( 'adsns_options', $this->options );
$message = __( "Settings saved.", 'adsense-plugin' );
return compact( 'message', 'notice', 'error' );
}
public function tab_settings() { ?>
help_phrase(); ?>
bws_pro_block_links(); ?>
help_phrase(); ?>
vi_revenue ) { ?>
%s', $adsns_vi_settings_api['demoPageURL'], __( 'demo', 'adsense-plugin' ) ) ); ?>
vi_revenue['netRevenue'] ) || ! isset( $this->vi_revenue['mtdReport'] ) ) { ?>
%s', __( 'FAQs', 'adsense-plugin' ) ) ); ?>
$vi_revenue['netRevenue'] !== NULL ? $this->vi_revenue['netRevenue'] : 0 ), 2, '.', ' ' ); ?>
vi_revenue_data = $this->vi_revenue['mtdReport'] !== NULL ? $this->vi_revenue['mtdReport'] : array();
$vi_chart_data = array(
'labels' => array(),
'data' => array()
);
foreach ( $this->vi_revenue_data as $data ) {
$vi_chart_data['labels'][] = date_i18n( 'M d', strtotime( $data['date'] ) );
$vi_chart_data['data'][] = $data['revenue'];
}
$script = "(function($) {
$(document).ready( function() {
var $vi_chart_data = " . json_encode( $vi_chart_data ) . ";
$('#adsns_vi_revenue_chart_canvas').trigger( 'displayWidgetChart', $vi_chart_data );
} );
})(jQuery);";
wp_register_script( 'adsns_vi_revenue_chart_canvas', '' );
wp_enqueue_script( 'adsns_vi_revenue_chart_canvas' );
wp_add_inline_script( 'adsns_vi_revenue_chart_canvas', sprintf( $script ) ); ?>