Ad Widget Version: 2.6.0 Author: Broadstreet Ads Author URI: http://broadstreetads.com */ require_once 'lib/Utility.php'; add_action('admin_init', array('AdWidget_Core', 'registerScripts')); add_action('widgets_init', array('AdWidget_Core', 'registerWidgets')); add_action('admin_menu', array('AdWidget_Core', 'registerAdmin')); /** * This class is the core of Ad Widget */ class AdWidget_Core { CONST KEY_INSTALL_REPORT = 'AdWidget_Installed'; CONST VERSION = '2.6.0'; CONST KEY_WELCOME = 'AdWidget_Welcome'; /** * The callback used to register the scripts */ static function registerScripts() { # Include thickbox on widgets page if($GLOBALS['pagenow'] == 'widgets.php') { wp_enqueue_script('thickbox'); wp_enqueue_style('thickbox'); wp_enqueue_script('adwidget-main', self::getBaseURL().'assets/widgets.js'); } } /** * The callback used to register the widget */ static function registerWidgets() { register_widget('AdWidget_HTMLWidget'); register_widget('AdWidget_ImageWidget'); } /** * Get the base URL of the plugin installation * @return string the base URL */ public static function getBaseURL() { return (get_bloginfo('url') . '/wp-content/plugins/ad-widget/'); } /** * Register the admin settings page */ static function registerAdmin() { add_options_page('Ad Widget', 'Ad Widget', 'edit_pages', 'adwidget.php', array(__CLASS__, 'adminMenuCallback')); } /** * The function used by WP to print the admin settings page */ static function adminMenuCallback() { self::sendInstallReportIfNew(); if(isset($_POST['cancel'])) Broadstreet_Adwidget_Mini_Utility::hasAdserving(false); if(isset($_POST['subscribe'])) Broadstreet_Adwidget_Mini_Utility::hasAdserving(true); include dirname(__FILE__) . '/views/admin.php'; } /** * Makes a call to the Broadstreet service to collect information information * on the blog in case of errors and other needs. */ public static function sendReport($message = 'General') { $report = "$message\n"; $report .= get_bloginfo('name'). "\n"; $report .= get_bloginfo('url'). "\n"; $report .= get_bloginfo('admin_email'). "\n"; $report .= 'WP Version: ' . get_bloginfo('version'). "\n"; $report .= 'Plugin Version: ' . self::VERSION . "\n"; $report .= "$message\n"; @wp_mail('plugin@broadstreetads.com', "Report: $message", $report); } /** * Send a welcome email to the user */ public static function sendWelcome() { $got_welcome = self::getOption(self::KEY_WELCOME); if($got_welcome != 'true') { $email = get_bloginfo('admin_email'); $subject = "Message from WP AdWidget"; $body = "Thank you for using WP AdWidget! If you have any questions, reach out to kenny@broadstreetads.com.\n\n" . "*One Other Thing*\n\nYou might also be interested in Selfie: http://wordpress.org/plugins/selfie :)\n\n" . "It's self serve advertising that you can implement in a couple minutes.\n\n" . "Best of luck!\n" . "- Kenny Katzgrau\n\n" . '"Our readers are perhaps our greatest untapped resource" - New York Times Innovation Report'; self::setOption(self::KEY_WELCOME, 'true'); @wp_mail($email, $subject, $body); } } /** * If this is a new installation and we've never sent a report to the * Broadstreet server, send a packet of basic info about this blog in case * issues should arise in the future. */ public static function sendInstallReportIfNew() { $install_key = self::KEY_INSTALL_REPORT; $upgrade_key = self::KEY_INSTALL_REPORT .'_'. self::VERSION; $installed = self::getOption($install_key); $upgraded = self::getOption($upgrade_key); $sent = ($installed && $upgraded); if($sent === FALSE) { if(!$installed) { self::sendWelcome(); self::sendReport("Installation"); self::setOption($install_key, 'true'); self::setOption($upgrade_key, 'true'); } else { self::sendWelcome(); self::sendReport("Upgrade"); self::setOption($upgrade_key, 'true'); } } } /** * Sets a Wordpress option * @param string $name The name of the option to set * @param string $value The value of the option to set */ public static function setOption($name, $value) { if (get_option($name) !== FALSE) { update_option($name, $value); } else { $deprecated = ' '; $autoload = 'yes'; add_option($name, $value, $deprecated, $autoload); } } /** * Gets a Wordpress option * @param string $name The name of the option * @param mixed $default The default value to return if one doesn't exist * @return string The value if the option does exist */ public static function getOption($name, $default = FALSE) { $value = get_option($name); if( $value !== FALSE ) return $value; return $default; } } /** * The HTML Widget */ class AdWidget_HTMLWidget extends WP_Widget { /** * Set the widget options */ function AdWidget_HTMLWidget() { $widget_ops = array('classname' => 'AdWidget_HTMLWidget', 'description' => 'Place an ad code like Google ads or other ad provider'); $this->WP_Widget('AdWidget_HTMLWidget', 'Ad: HTML/Javascript Ad', $widget_ops); } /** * Display the widget on the sidebar * @param array $args * @param array $instance */ function widget($args, $instance) { extract($args); echo $before_widget; echo "