adsns_options = get_site_option( 'adsns_settings' ); else $this->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() { 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['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' => '', 'clientid_prefix' => 'pub', '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', 'pallete' => 'Default Google pallete', 'position' => 'homepostend', 'widget_title' => '', 'code' => ' ' ); 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 ( 'ad_unit' == $this->adsns_options['adtype'] ) { if ( 'default_image' == $this->adsns_options['adtypeselect'] ) $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 check if plugin is compatible with current WP version */ function adsns_version_check() { global $wp_version, $bws_plugin_info; if ( function_exists( 'get_plugin_data' ) && ( ! isset( $bws_plugin_info ) || empty( $bws_plugin_info ) ) ) { $plugin_info = get_plugin_data(plugin_dir_path(__FILE__) . "adsense-plugin.php" ); $bws_plugin_info = array( 'id' => '80', 'version' => $plugin_info["Version"] ); }; $plugin_data = get_plugin_data( plugin_dir_path( __FILE__ ) . "adsense-plugin.php", false ); $require_wp = "3.0"; /* Wordpress at least requires version */ $plugin = plugin_basename( __FILE__ ); if ( version_compare( $wp_version, $require_wp, "<" ) ) { if ( is_plugin_active( $plugin ) ) { deactivate_plugins( $plugin ); wp_die( "" . $plugin_data['Name'] . " " . __( 'requires', 'adsense' ) . " WordPress " . $require_wp . " " . __( 'or higher, that is why it has been deactivated! Please upgrade WordPress and try again.', 'adsense') . "

" . __( 'Back to the WordPress', 'adsense') . " " . __( 'Plugins page', 'adsense') . "." ); } } } /* 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 "

".__( "Settings saved", 'adsense' )."

"; if ( 3 <= strlen( trim( $_REQUEST['clientid_prefix'] ) ) && 'pub' == substr( trim( $_REQUEST['clientid_prefix'] ) , -3, 3 ) ) { $this->adsns_options['clientid_prefix'] = $_REQUEST['clientid_prefix']; if ( isset( $_REQUEST['client_id'] ) ) { /* client */ $this->adsns_options['clientid'] = $_REQUEST['client_id']; } if ( isset( $_REQUEST['mycode'] ) ) { /* ad code */ $id = stripslashes( $_REQUEST['mycode'] ); if ( 0 < strlen( $id ) ) { //$this->adsns_options['code'] = $id; } } if ( isset( $_REQUEST['homeAds'] ) ) { /* select */ $this->adsns_options['max_homepostads'] = $_REQUEST['homeAds']; } if ( isset( $_REQUEST['adtypeselect'] ) ) { /* adtypeselect */ $this->adsns_options['adtypeselect'] = $_REQUEST['adtypeselect']; } else { $this->adsns_options['adtypeselect'] = ''; } if ( isset( $_REQUEST['default'] ) ) { /* format */ $this->adsns_options['default'] = $_REQUEST['default']; } else { $this->adsns_options['default'] = ''; } if ( isset( $_REQUEST['image_only'] ) ) { /* format */ $this->adsns_options['image_only'] = $_REQUEST['image_only']; } else { $this->adsns_options['image_only'] = ''; } if ( isset( $_REQUEST['link_unit'] ) ) { /* format */ $this->adsns_options['link_unit'] = $_REQUEST['link_unit']; } else { $this->adsns_options['link_unit'] = ''; } if ( isset( $_REQUEST['adtype'] ) ) { /* adtype */ $this->adsns_options['adtype'] = $_REQUEST['adtype']; } if ( isset( $_REQUEST['corner_style'] ) ) { /* corner_style */ $this->adsns_options['corner_style'] = $_REQUEST['corner_style']; } if ( isset( $_REQUEST['pallete'] ) ) { /* pallete */ $this->adsns_options['pallete'] = $_REQUEST['pallete']; } if ( isset( $_REQUEST['border'] ) ) { /* border */ $this->adsns_options['border'] = $_REQUEST['border']; } if ( isset( $_REQUEST['title'] ) ) { /* title */ $this->adsns_options['title'] = $_REQUEST['title']; } if ( isset( $_REQUEST['background'] ) ) { /* background */ $this->adsns_options['background'] = $_REQUEST['background']; } if ( isset( $_REQUEST['text'] ) ) { /* text */ $this->adsns_options['text'] = $_REQUEST['text']; } if ( isset( $_REQUEST['url'] ) ) { /* url */ $this->adsns_options['url'] = $_REQUEST['url']; } if ( isset( $_REQUEST['position'] ) ) { /* position */ $this->adsns_options['position'] = $_REQUEST['position']; } if ( isset( $_REQUEST['donate'] ) ) { /* donate */ $this->adsns_options['donate'] = $_REQUEST['donate']; } if ( 'ad_unit' == $this->adsns_options['adtype'] ) { if ( 'default_image' == $this->adsns_options['adtypeselect'] ) $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 = ''; } $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 echo "

" . __( "Please enter valid Publisher ID.", 'adsense' ) . "

"; } else echo "

" . __( "Please enter your Publisher ID.", 'adsense' ) . "

"; } /* Click on Save Changes button end */ $this->adsns_view_options_page(); echo '
'; } /* Admin interface of plugin */ function adsns_view_options_page() { global $wpmu; static $sp_nonce_flag = false; if ( 1 == $wpmu ) $this->adsns_options = get_site_option( 'adsns_settings' ); else $this->adsns_options = get_option( 'adsns_settings' ); ?>
-
adsns_options['adtype'] || 'adunit' == $this->adsns_options['adtype'] ) echo 'checked="checked"'; ?> />
adsns_options['adtype'] ) echo 'checked="checked"'; ?> />
adsns_options['adtype'] && ( 'default' == $this->adsns_options['adtypeselect'] || 'default_image' == $this->adsns_options['adtypeselect'] ) || 'text' == $this->adsns_options['adtypeselect'] || 'text_image' == $this->adsns_options['adtypeselect'] ) echo 'style="visibility: visible;"'; else echo 'style="visibility: hidden;"'; ?>>
adsns_options['adtype'] && ( 'image_only' == $this->adsns_options['adtypeselect'] || 'image' == $this->adsns_options['adtypeselect'] ) ) echo 'style="visibility: visible;"'; else echo 'style="visibility: hidden;"'; ?> class="right_img">
adsns_options['adtype'] ) echo 'style="visibility: visible;margin-top: -24px"'; else echo 'style="visibility: hidden;margin-top: -32px"'; ?> class="right">



%


:
: http://support.bestwebsoft.com
.ads { position: relative; text-align: center; clear: both; } EOF; } /* *displays AdSense in widget *@return array() */ function adsns_widget_display() { global $wpmu, $adsns_count; if ( 1 == $wpmu ) $this->adsns_options = get_site_option( 'adsns_settings' ); else $this->adsns_options = get_option( 'adsns_settings' ); $title = $this->adsns_options['widget_title']; echo '
  • ' . $title . '

    '; if ( $adsns_count < $this->adsns_options['max_ads'] ) { $this->adsns_donate(); echo '
    ' . $this->adsns_options['code'] . '
    '; $this->adsns_options['num_show']++; update_option( 'adsns_settings', $this->adsns_options ); $adsns_count = $this->adsns_options['num_show']; } echo "
  • "; } /* *Register widget for use in sidebars. *Registers widget control callback for customizing options */ function adsns_register_widget() { wp_register_sidebar_widget( 'adsns_widget', /* Unique widget id */ 'AdSense', /* Widget name */ array( $this, 'adsns_widget_display' ), /* Callback function */ array( 'description' => 'Widget displays AdSense' ) /* Options */ ); wp_register_widget_control( 'adsns_widget', /* Unique widget id */ 'AdSense', /* Widget name */ array( $this, 'adsns_widget_control' ) /* Callback function */ ); } /* *Registers widget control callback for customizing options *@return array */ function adsns_widget_control() { if( isset( $_POST["adsns-widget-submit"] ) ) { $this->adsns_options['widget_title'] = strip_tags( stripslashes( $_POST["adsns-widget-title"] ) ); update_option( 'adsns_settings', $this->adsns_options ); } $title = $this->adsns_options['widget_title']; echo '

    '; echo ''; } } /* Class */ ?>