. */ class AntiAdBlock { var $name = 'anti_adblock'; var $homepage = 'http://omninoggin.com/projects/wordpress-plugins/anti-adblock-wordpress-plugin/'; var $displayed = false; function get_default_options() { return array( 'can_close' => true, 'hide_content' => false, 'image' => $this->get_plugin_url() . '/images/disable_adblock.png', 'message' => __('
Without advertisement revenue we will not be able to continue to provide quality content. Please consider disabling your AdBlock software (at least for this site). Thank you in advance for your support and understanding!
', $this->name), 'message_css' => ' background-color:#fff; border:1px solid #ccc; color:#333; height:auto; left:25%; padding:20px; position:fixed; top:100px; width:50%; z-index:10;', 'max_nag' => 1, 'show_link' => true, 'visits_till_nag' => 10 ); } function activate() { $this->upgrade_options(); $this->set_my_nonce(); } function set_my_nonce() { $aab_options = get_option($this->name); $aab_options['my_nonce'] = 'a' . substr(md5(wp_create_nonce($name)), rand(0, 15), rand(5, 16)); update_option($this->name, $aab_options); } function display() { if ( !$this->displayed ) { $aab_options = get_option($this->name); // strip end-of-line characters $style = str_replace("\n", '', $aab_options['message_css']); $style = str_replace("\r", '', $style); printf('%s
%s%s%s
', __('Click here to close', $this->name), __('You will no longer receive this message after ', $this->name), $aab_options['max_nag'], __(' visit(s) (cookies required).', $this->name) ); } else $close_html = ''; if ( $aab_options['show_link'] ) $link_html = sprintf('
', $this->homepage, __('Powered by Anti-AdBlock', $this->name), __('Powered by Anti-AdBlock', $this->name) ); else $link_html = ''; // generate JS printf(' ', $expire_days, $expire_days, ($aab_options['visits_till_nag']) ? $aab_options['visits_till_nag'] : 0, ($aab_options['visits_till_nag']) ? $aab_options['visits_till_nag'] : 0, ($aab_options['max_nag']) ? $aab_options['max_nag'] : 0, $aab_options['my_nonce'], $aab_options['my_nonce'], $image_html, $aab_options['message'], $close_html, $link_html, $aab_options['my_nonce'] ); } function update_options() { // new options $aab_new_options = stripslashes_deep($_POST['aab_options_update']); // current options $aab_current_options = get_option($this->name); // convert "on" to true and "off" to false for checkbox fields // and set defaults for fields that are left blank if ( isset($aab_new_options['can_close']) ) $aab_new_options['can_close'] = true; else $aab_new_options['can_close'] = false; if ( isset($aab_new_options['hide_content']) ) $aab_new_options['hide_content'] = true; else $aab_new_options['hide_content'] = false; if ( isset($aab_new_options['show_link']) && isset($aab_new_options['show_link']) == "on") $aab_new_options['show_link'] = true; else $aab_new_options['show_link'] = false; // set defaults if some fields that are left blank or invalid if ( !is_numeric($aab_new_options['max_nag']) ) $aab_new_options['max_nag'] = $aab_current_options['max_nag']; elseif ( !$aab_new_options['max_nag'] || (int)$aab_new_options['max_nag'] < 0 ) $aab_new_options['max_nag'] = 0; else { $aab_new_options['max_nag'] = (int)$aab_new_options['max_nag']; } if ( !is_numeric($aab_new_options['visits_till_nag']) ) $aab_new_options['visits_till_nag'] = $aab_current_options['visits_till_nag']; elseif ( !$aab_new_options['visits_till_nag'] || (int)$aab_new_options['visits_till_nag'] < 0 ) $aab_new_options['visits_till_nag'] = 0; else { $aab_new_options['visits_till_nag'] = (int)$aab_new_options['visits_till_nag']; } // Update options foreach($aab_new_options as $key => $value) { $aab_current_options[$key] = $value; } update_option($this->name, $aab_current_options); } function upgrade_options() { $aab_options = get_option($this->name); if ( !$aab_options ) { add_option($this->name, $this->get_default_options()); } else { $default_options = $this->get_default_options(); foreach($default_options as $option_name => $option_value) { if(!isset($aab_options[$option_name])) { $aab_options[$option_name] = $option_value; } } update_option($this->name, $aab_options); } } function reset_options() { if ( !get_option($this->name) ) { add_option($this->name, $this->get_default_options()); } else { update_option($this->name, $this->get_default_options()); } } function get_name() { return $this->name; } function get_plugin_dir() { // Pre-2.6 compatibility if ( !defined('WP_CONTENT_DIR') ) define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' ); return WP_CONTENT_DIR.'/plugins/'.plugin_basename(dirname(__FILE__)); } function get_plugin_url() { // Pre-2.6 compatibility if ( !defined('WP_CONTENT_URL') ) define( 'WP_CONTENT_URL', get_option('siteurl') . '/wp-content'); return WP_CONTENT_URL.'/plugins/'.plugin_basename(dirname(__FILE__)); } function get_current_page_url() { $isHTTPS = (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on"); $port = (isset($_SERVER["SERVER_PORT"]) && ((!$isHTTPS && $_SERVER["SERVER_PORT"] != "80") || ($isHTTPS && $_SERVER["SERVER_PORT"] != "443"))); $port = ($port) ? ':'.$_SERVER["SERVER_PORT"] : ''; $url = ($isHTTPS ? 'https://' : 'http://').$_SERVER["SERVER_NAME"].$port.$_SERVER["REQUEST_URI"]; return $url; } function admin_menu() { add_options_page('Anti-AdBlock', 'Anti-AdBlock', 'manage_options', 'anti-adblock', array($this, 'admin_page')); } function admin_page() { // load text domain for translations load_plugin_textdomain($this->name); if ( isset($_POST['aab_options_update_submit']) ) { // if user wants to update options check_admin_referer($this->name); $this->update_options(); printf('%s
%s
%s