Google Adsense Widget. Select ad type easily on your site. Define slot & channel ids for statistics. Hide ads for admins & users. Customizable colors. Easy to use shortcode [adsense]! Powered by Shailan.com. Visit: Plugin page | Documentation | Shortcode Usage.
Version: 1.6.1
Author: Matt Say
Author URI: http://shailan.com/
*/
if(!class_exists('stf_adsense')){
class stf_adsense extends WP_Widget {
function stf_adsense() {
$widget_ops = array('classname' => 'stf-adsense', 'description' => __( 'Google adsense widget' ) );
$this->WP_Widget('stf-adsense', __('Adsense'), $widget_ops);
$this->alt_option_name = 'stf_adsense';
$this->version = "1.6.1";
$this->settings_key = "stf_adsense";
$this->options_page = "adsense-widget";
// Default widget options
$this->widget_defaults = array(
'title' => '',
'slot' => '',
'channel' => '',
'type' => 'banner',
'content' => 'text_image',
'adsense_id' => ''
);
// Ad content types
$this->content_types = array( 'text', 'image', 'text_image' );
// Include ad type array
require_once("stf-ad-types.php");
$this->ad_types = $ad_types;
// Include options array
require_once("stf-adsense-options.php");
$this->options = $options;
$this->settings = $this->get_plugin_settings();
if(!is_admin()){
wp_enqueue_style( "stf-adsense", WP_PLUGIN_URL . "/adsense-widget/adsense-widget.css", false, "1.0", "all");
}
add_action('admin_menu', array( &$this, 'stf_adsense_admin') );
}
function get_plugin_settings(){
$settings = get_option( $this->settings_key );
if(FALSE === $settings){ // Options doesn't exist, install standard settings
// Create settings array
$settings = array();
// Set default values
foreach($this->options as $option){
if( array_key_exists( 'id', $option ) )
$settings[ $option['id'] ] = $option['std'];
}
// Move adsense id option to new settings
$adsid = get_option('shailan_adsense_id');
if(!empty($adsid)){ $settings['adsense_id'] = $adsid; }
$settings['version'] = $this->version;
// Save the settings
update_option( $this->settings_key, $settings );
} else { // Options exist, update if necessary
if( !empty( $settings['version'] ) ){ $ver = $settings['version']; }
else { $ver = ''; }
if($ver != $this->version){ // Update needed
// Move adsense id option to new settings
$adsid = get_option('shailan_adsense_id');
if(!empty($adsid)){ $settings['adsense_id'] = $adsid; }
// Add missing keys
foreach($this->options as $option){
if( array_key_exists ( 'id' , $option ) && !array_key_exists ( $option['id'] ,$settings ) ){
$settings[ $option['id'] ] = $option['std'];
}
}
update_option( $this->settings_key, $settings );
return $settings;
} else {
// Move adsense id option to new settings
$adsid = get_option('shailan_adsense_id');
if( !empty($adsid) ){
$settings['adsense_id'] = $adsid;
update_option( $this->settings_key, $settings );
delete_option('shailan_adsense_id');
}
// Everythings gonna be alright. Return.
return $settings;
}
}
}
function update_plugin_setting( $key, $value ){
$settings = $this->get_plugin_settings();
$settings[$key] = $value;
update_option( $this->settings_key, $settings );
}
function get_plugin_setting( $key, $default = '' ) {
$settings = $this->get_plugin_settings();
if( array_key_exists($key, $settings) ){
return $settings[$key];
} else {
return $default;
}
return FALSE;
}
function stf_adsense_admin(){
if ( @$_GET['page'] == $this->options_page ) {
if ( @$_REQUEST['action'] && 'save' == $_REQUEST['action'] ) {
// Save settings
// Get settings array
$settings = $this->get_settings();
// Set updated values
foreach($this->options as $option){
if( $option['type'] == 'checkbox' && empty( $_REQUEST[ $option['id'] ] ) ) {
$settings[ $option['id'] ] = 'off';
} else {
$settings[ $option['id'] ] = $_REQUEST[ $option['id'] ];
}
}
// Save the settings
update_option( $this->settings_key, $settings );
header("Location: admin.php?page=" . $this->options_page . "&saved=true&message=1");
die;
} else if( @$_REQUEST['action'] && 'reset' == $_REQUEST['action'] ) {
// Start a new settings array
$settings = array();
delete_option( $this->settings_key );
// Set standart values
// foreach($this->options as $option){ $settings[$option['id']] = $option['std']; }
// Save the settings
// update_option( $this->settings_key, $settings );
header("Location: admin.php?page=" . $this->options_page . "&reset=true&message=2");
die;
}
// Enqueue scripts & styles
wp_enqueue_script( "jquery" );
wp_enqueue_script( "tweetable", WP_PLUGIN_URL . '/adsense-widget/js/jquery.tweetable.js', 'jquery' );
wp_enqueue_style( "tweetable", WP_PLUGIN_URL . '/adsense-widget/css/tweetable.css' );
wp_enqueue_style( "stf-adsense", WP_PLUGIN_URL . "/adsense-widget/adsense-widget-admin.css", false, "1.0", "all");
wp_enqueue_style( "google-droid-sans", "http://fonts.googleapis.com/css?family=Droid+Sans:regular,bold&v1", false, "1.0", "all");
}
$page = add_options_page( __('Adsense Widget Options', 'adsense-widget') , __('Adsense Widget', 'adsense-widget'), 'edit_themes', $this->options_page, array( &$this, 'options_page') );
}
function options_page(){
global $options, $current;
$title = "Adsense Widget Options";
$options = $this->options;
$current = $this->get_plugin_settings();
$messages = array(
"1" => __("Adsense Widget settings saved.", "adsense-widget"),
"2" => __("Adsense Widget settings reset.", "adsense-widget")
);
$navigation = '
| " . __("Adsense Unit") . " " . $ad['name'] . " |
Slot id for the ad you created.( Eg. 1234567890 )
Your channel id.( Eg. 1234567890 )