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() ) { $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 Options', '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 $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( ! 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( $adsns_options = get_option( 'adsns_sets' ) ) { unset( $adsns_options['code2'] ); add_option( 'adsns_settings', $adsns_options ); delete_option( 'adsns_sets' ); } $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 "

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

"; if ( isset( $_REQUEST['client_id'] ) ) { ## client $this->adsns_options['clientid'] = $_REQUEST['client_id']; } if ( isset( $_REQUEST['mycode'] ) ) { ## ad code $id = stripslashes( $_REQUEST['mycode'] ); if ( strlen( $id ) > 0 ) { //$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( $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 = ''; } $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 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(){ static $sp_nonce_flag = false; $this->adsns_options = get_option( 'adsns_settings' ); ?>

adsns_options['adtype'] == 'ad_unit' || $this->adsns_options['adtype'] == 'adunit') echo 'checked="checked"'; ?>/>
adsns_options['adtype'] == 'link_unit' ) echo 'checked="checked"'; ?>/>

adsns_options['adtype'] == 'ad_unit' && ( $this->adsns_options['adtypeselect'] == 'default' || $this->adsns_options['adtypeselect'] == 'default_image' ) || $this->adsns_options['adtypeselect'] == 'text' || $this->adsns_options['adtypeselect'] == 'text_image' ) echo 'style="visibility: visible;"'; else echo 'style="visibility: hidden;"'; ?>>
adsns_options['adtype'] == 'ad_unit' && ( $this->adsns_options['adtypeselect'] == 'image_only' || $this->adsns_options['adtypeselect'] == 'image' ) ) echo 'style="visibility: visible;"'; else echo 'style="visibility: hidden;"'; ?> class="right_img">
adsns_options['adtype'] == 'link_unit' ) echo 'style="visibility: visible;margin-top: -28px"'; else echo 'style="visibility: hidden;margin-top: -28px"'; ?> class="right">



.ads { position: relative; text-align: center; clear: both; } EOF; } /* *displays AdSense in widget *@return array() */ function adsns_widget_display() { global $adsns_count; $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( // options 'description' => 'Widget displays AdSense' ) ); 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 ?>