Ad Widget
Version: 2.8.2
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'));
add_action('admin_footer', array('AdWidget_Core', 'footerScripts'));
/**
* This class is the core of Ad Widget
*/
class AdWidget_Core
{
CONST KEY_INSTALL_REPORT = 'AdWidget_Installed';
CONST VERSION = '2.8.2';
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 plugin_dir_url(__FILE__);
}
/**
* 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);
}
}
public static function footerScripts()
{
if(is_admin()): ?>
'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 "
{$instance['w_adcode']}
";
echo $after_widget;
}
/**
* Update the widget info from the admin panel
* @param array $new_instance
* @param array $old_instance
* @return array
*/
function update($new_instance, $old_instance)
{
$instance = $old_instance;
$instance['w_adcode'] = $new_instance['w_adcode'];
$instance['w_adv'] = $new_instance['w_adv'];
/* New ad? Upload it to Broadstreet */
if($instance['w_adcode'] && Broadstreet_Adwidget_Mini_Utility::hasAdserving()) {
$advertisement_id = false;
# New ad?
if(is_numeric(@$instance['bs_ad_id'])) $advertisement_id = $instance['bs_ad_id'];
# New advertiser?
if(!$advertisement_id) {
$api = Broadstreet_Adwidget_Mini_Utility::getClient();
$adv = $api->createAdvertiser(Broadstreet_Adwidget_Mini_Utility::getNetworkID(), $instance['w_adv']);
$instance['bs_adv_id'] = $adv->id;
}
$ad = Broadstreet_Adwidget_Mini_Utility::importHTMLAd(Broadstreet_Adwidget_Mini_Utility::getNetworkID(),
$instance['bs_adv_id'],
$instance['w_adcode'],
$advertisement_id);
if(!$advertisement_id) {
$instance['bs_ad_html'] = $ad->html;
$instance['bs_ad_id'] = $ad->id;
$instance['bs_adv_id'] = $adv->id;
}
}
return $instance;
}
/**
* Display the widget update form
* @param array $instance
*/
function form($instance)
{
$defaults = array('w_adcode' => '', 'w_adv' => 'New Advertiser');
$instance = wp_parse_args((array) $instance, $defaults);
?>
Paste your Google ad tag, or any other ad tag in this widget below.