adsns_options = get_option( 'adsns_settings' );
$this->adsns_options['code'] = stripslashes( $this->adsns_options['code'] );
$this->adsns_options['num_show'] = 0;
update_option( 'adsns_settings', $this->adsns_options );
}
// Show ads after post on a single page
function adsns_end_post_ad( $content ) {
global $adsns_count;
$this->adsns_donate(); // Calling a donate function
if ( ! is_feed() && is_single() && $adsns_count < $this->adsns_options[ 'max_ads' ] && $adsns_count < $this->adsns_options['max_homepostads'] ) { // Checking if we are on a single page
$content.= '
' . $this->adsns_options['code'] . '
'; // Adding an ad code on page
$this->adsns_options['num_show'] ++; // Counting views
update_option( 'adsns_settings', $this->adsns_options );
$adsns_count = $this->adsns_options['num_show'];
}
return $content;
}
// Show ads after comment form
function adsns_end_comment_ad() {
global $adsns_count;
$this->adsns_donate();
if( ! is_feed() && $adsns_count < $this->adsns_options[ 'max_ads' ] && $adsns_count < $this->adsns_options['max_homepostads'] ) {
echo '
' . $this->adsns_options['code'] . '
';
$this->adsns_options['num_show'] ++; // Counting views
update_option( 'adsns_settings', $this->adsns_options );
$adsns_count = $this->adsns_options['num_show'];
}
}
// Show ads after post on home page
function adsns_end_home_post_ad( $content ) {
global $adsns_count;
if ( $adsns_count < $this->adsns_options[ 'max_ads' ] && $adsns_count < $this->adsns_options['max_homepostads'] ) {
if( ! is_feed() && ( is_home() || is_front_page() ) ) {
// if( ! is_feed() && is_home() ) {
$this->adsns_donate(); // Calling a donate function
$content .= '
' . $this->adsns_options['code'] . '
';
$this->adsns_options['num_show'] ++; // Counting views
update_option( 'adsns_settings', $this->adsns_options );
$adsns_count = $this->adsns_options['num_show']; // restore count value
}
}
return $content;
}
// Show ads in footer
function adsns_end_footer_ad() {
$this->adsns_donate();
if( ! is_feed() && $adsns_count < $this->adsns_options[ 'max_ads' ] && $adsns_count < $this->adsns_options['max_homepostads'] ) {
echo '';
$this->adsns_options['num_show'] ++; // Counting views
update_option( 'adsns_settings', $this->adsns_options );
$adsns_count = $this->adsns_options['num_show']; // restore count value
}
}
// Add 'BWS Plugins' menu at the left side in administer panel
function adsns_add_admin_menu() {
add_menu_page( 'BWS Plugins', 'BWS Plugins', 'manage_options', 'bws_plugins', 'bws_add_menu_render', plugins_url( "images/px.png", __FILE__ ), 1001 );
add_submenu_page( 'bws_plugins', __( 'AdSense Settings', 'adsense'), __( 'AdSense', 'adsense' ), 'manage_options', "adsense-plugin.php", array( $this, 'adsns_settings_page' ) );
}
// Add a link for settings page
function adsns_plugin_action_links( $links, $file ) {
global $this_adsns_plugin;
if ( $file == $this_adsns_plugin ){
$settings_link = '' . __( 'Settings', 'adsense' ) . '';
array_unshift( $links, $settings_link );
}
return $links;
}
function adsns_register_plugin_links($links, $file) {
global $this_adsns_plugin;
if ( $file == $this_adsns_plugin ) {
$links[] = '' . __( 'Settings', 'adsense' ) . '';
$links[] = '' . __( 'FAQ', 'adsense' ) . '';
$links[] = '' . __( 'Support', 'adsense' ) . '';
}
return $links;
}
// Creating a default options for showing ads. Starts on plugin activation.
function adsns_activate() {
global $wpmu, $adsns_options, $count, $current_count, $adsns_count, $max_ads;
$new_options = array(
'num_show' => '0',
'donate' => '0',
'max_ads' => '3',
'max_homepostads' => '1',
'clientid' => '',
'donate_id' => '1662250046693311',
'adtypeselect' => 'text',
'donate_width' => '',
'donate_height' => '',
'default' => '468x60',
'image_only' => '',
'link_unit' => '',
'adtype' => 'adunit',
'corner_style' => 'none',
'border' => '#FFFFFF',
'title' => '#0000FF',
'background' => '#FFFFFF',
'text' => '#000000',
'url' => '#008000',
'palette' => 'Default Google pallete',
'position' => 'homepostend',
'code' => ' ',
'widget_title' => ''
);
if ( 1 == $wpmu ) {
if ( ! get_site_option( 'adsns_settings' ) ) {
add_site_option( 'adsns_settings', $new_options, '', 'yes' );
}
} else {
if ( ! get_option( 'adsns_settings' ) )
add_option( 'adsns_settings', $new_options, '', 'yes' );
}
$count = 0; //current number of showed ads
$current_count = 0; // tmp var for storing a number of already showed ads
$adsns_count = 0; // number of posts on home page
if ( 1 == $wpmu )
$adsns_options = get_site_option( 'adsns_settings' );
else
$adsns_options = get_option( 'adsns_settings' );
$adsns_options = array_merge( $new_options, $adsns_options );
update_option( 'adsns_settings', $adsns_options );
$max_ads = $adsns_options['max_ads']; // max number of ads
}
// Donate settings
function adsns_donate() {
if ( $this->adsns_options['donate'] > 0 ) {
$don = intval( 100/$this->adsns_options['donate'] ); // Calculating number of donate ads for showing
}
if ( $this->adsns_options['donate'] > 0 && $this->adsns_options['num_show'] % $don == 0) { // Checking if now showing ad must be a donate ad
$dimensions = explode( "x", $this->adsns_options['default'] ); // Calculating dimensions of ad block
$this->adsns_options['donate_width'] = $dimensions[0]; // Width
$this->adsns_options['donate_height'] = $dimensions[1]; // Height
$don_code = '';
$this->adsns_options['code'] = $don_code;
//update_option( 'adsns_settings', $this->adsns_options );
} else {
if( $this->adsns_options['adtype'] == 'ad_unit' ) {
if($this->adsns_options['adtypeselect'] == 'default_image')
$adtypeselect = 'default';
else
$adtypeselect = $this->adsns_options['adtypeselect'];
$dimensions = explode( "x", $this->adsns_options[ $adtypeselect ] ); // Calculating dimensions of ad block
$format = $this->adsns_options[ $adtypeselect ];
$format .= '_as';
switch($this->adsns_options['adtypeselect']) {
case 'image_only':
$type = 'google_ad_type = "image";';
break;
case 'default_image':
$type = 'google_ad_type = "text_image";';
break;
default:
$type = 'google_ad_type = "text";';
break;
}
} else {
$dimensions = explode( "x", $this->adsns_options[ $this->adsns_options['adtype'] ] ); // Calculating dimensions of ad block
$format = $this->adsns_options[ $this->adsns_options['adtype'] ];
$format .= '_0ads_al';
$type = '';
}
if ( 'none' == $this->adsns_options['corner_style'] ) {
$features = '';
} else {
$features = 'google_ui_features = "rc:'.$this->adsns_options['corner_style'].'";';
}
$this->adsns_options['donate_width'] = $dimensions[0]; // Width
$this->adsns_options['donate_height'] = $dimensions[1]; // Height
$don_code = '';
$this->adsns_options['code'] = $don_code;
//update_option( 'adsns_settings', $this->adsns_options );
}
}
// Function fo deactivation
function adsns_deactivate(){
}
// Saving settings
function adsns_settings_page(){
// Run once
if ( ! $adsns_options = get_option( 'adsns_settings' ) ){
$this->adsns_activate();
}
echo '
' . $this->page_title . '
';
if ( isset( $_REQUEST['adsns_update'] ) && check_admin_referer( plugin_basename(__FILE__), 'adsns_nonce_name' ) ) { ### if click on Save Changes button
if ( strlen( $_REQUEST['client_id'] ) > 0 ) {
echo "