';
private $DonateText = 'Donate';
private $TwitterFollow = 'Follow Mobile Sentience';
private $FacebookFollow = '';
private $eturi = 'http://www.mobilesentience.com/et/wptracker.php';
private $AdminTabs = array(
'campaigns-tab' => array('name' => 'Campaigns', 'method_base' => 'CampaignListTab'),
'sources-tab' => array('name' => 'Local Ads', 'method_base' => 'SourceListTab'),
'settings-tab' => array('name' => 'Settings', 'method_base' => 'SettingsTab'),
'handbook-tab' => array('name' => 'Tutorials', 'method_base' => 'HandbookTab'),
'support-tab' => array('name' => 'Support', 'method_base' => 'SupportTab'),
'about-tab' => array('name' => 'About', 'method_base' => 'AboutTab')
);
private $AllocationMap = array(
'name' => 'alname-',
'description' => 'aldescription-',
'displayed' => 'alpaneldisplayed-',
'ads' => array(
'advertisement' => 'alad-',
'weight' => 'aladweight-',
'percent-weight' => 'aladpercentweight-'
),
'rulesets' => array(
'id' => 'alrulesetid-',
'rules' => array(
'type' => 'alruletype-',
'author' => 'alruleauthor-',
'posttype' => 'alruleposttype-',
'tag' => 'alruletag-',
'category' => 'alrulecategory-',
'post' => 'alrulepost-',
'page' => 'alrulepage-',
'argname' => 'alruleargumentname-',
'argvalue' => 'alruleargumentvalue-',
'argop' => 'alruleargumentoperator-',
'catid' => 'alrulecategoryid-',
'catop' => 'alrulecategoryoperator-',
'tagid' => 'alruletagid-',
'tagop' => 'alruletagoperator-',
'vpath' => 'alrulevpath-',
'vpathop' => 'alrulevpathoperator-',
'cvarname' => 'alrulecvarname-',
'cvarop' => 'alrulecvaroperator-',
'cvarvalue' => 'alrulecvarvalue-',
'geolocation' => 'alrulegeolocation-',
'geoop' => 'alrulegeoop-',
'geovalue' => 'alrulegeovalue-',
'cookiename' => 'alrulecookiename-',
'cookievalue' => 'alrulecookievalue-',
'cookieop' => 'alrulecookieoperator-',
'customfieldname' => 'alrulecustomfieldname-',
'customfieldvalue' => 'alrulecustomfieldvalue-',
'customfieldop' => 'alrulecustomfieldoperator-',
'remoteipvalue' => 'alruleremoteipvalue-',
'remoteipop' => 'alruleremoteipoperator-',
'remotehostnamevalue' => 'alruleremotehostnamevalue-',
'remotehostnameop' => 'alruleremotehostnameoperator-',
'referrervalue' => 'alrulereferrervalue-',
'referrerop' => 'alrulereferreroperator-',
'adsizevalue' => 'alruleadsizevalue-',
'adsizeop' => 'alruleadsizeoperator-'
)
)
);
private $RuleTypes = array (
'author' => 'Match an author',
'posttype' => 'Match the post type',
'category' => 'Match a category',
'tag' => 'Match a tag ',
'geoip' => 'Match a location',
'getargument' => 'Match link arguments',
'cookie' => 'Match a cooke value',
'customfield' => 'Match a posts custom fields',
'remoteip' => 'Match the visitors ip address',
'remotehostname' => 'Match the visitors hostname',
'referrer' => 'Match the referring site',
'adsize' => 'Match the Ad Unit size'
);
private $VirtualThemeRules = array (
'vpath' => 'Match a Virtual Path',
'cvar' => 'Match a Virtual Theme Custom Variable'
);
private $CacheTimes = array(
'0' => 'Never Cache',
'1' => 'Save loaded data for 1 hour',
'24' => 'Save loaded data for 1 day',
'168' => 'Save loaded data for 1 week'
);
private $PostTypes = array(
'homepage' => 'Place Campaign Ads on Home Page',
'page' => 'Place Campaign Ads in Pages',
'post' => 'Place Campaign Ads in Posts',
);
private $AdPlacementAlignment = array(
'0' => 'On the left',
'1' => 'On the right',
'2' => 'Alternating on the left then on the right',
'3' => 'Alternating on the right then on the left'
);
private $AdUnitSizes = array(
'Medium Rectangle - (300x250)' => '300x250',
'Large Rectangle - (336x280)' => '336x280',
'Leaderboard - (728x90)' => '728x90',
'Wide Skyscraper - (160x600)' => '160x600',
'Banner - (468x60)' => '468x60',
'Half Banner - (234x60)' => '234x60',
'Skyscraper - (120x600)' => '120x600',
'Vertical Banner - (120x240)' => '120x240',
'Square - (250x250)' => '250x250',
'Small Square - (200x200)' => '200x200',
'Small Rectangle - (180x150)' => '180x150',
'Button - (125x125)' => '125x125',
'(728x15)' => '728x15',
'(468x15)' => '468x15',
'(200x90)' => '200x90',
'(180x90)' => '180x90',
'(160x90)' => '160x90',
'(120x90)' => '120x90'
);
// Protected constructor for singleton
//private function __construct(){
public function __construct(){
/** Uncomment for testing, forces loading of plugin stylesheets and javascripts */
global $wp_version;
global $advertwhirl_plugin_version;
global $advertwhirl_plugin_name;
global $advertwhirl_stats_name;
global $advertwhirl_options_name;
$this->version = $advertwhirl_plugin_version;
$this->name = $advertwhirl_plugin_name;
$this->options_name = $advertwhirl_options_name;
$this->stats_name = $advertwhirl_stats_name;
$this->adserv = 'http://www.mobilesentience.com/ads/WordpressPlugins&plugin=' . $this->name . '&pluginversion=' . $this->version . '&where=admin';
$this->pluginFile = __FILE__;
$this->pageURL = '?page=' . $this->getRightMost(__FILE__, 'plugins/');
$this->imagePath = WP_PLUGIN_URL . '/' . str_replace(basename( __FILE__), "", plugin_basename(__FILE__)) . '/images/';
$this->externalAdsPath = str_replace(site_url(), '', WP_PLUGIN_URL . '/' . str_replace(basename( __FILE__), "", plugin_basename(__FILE__))) . '/ServeAd.php?campaign=';
if(empty($this->pluginDir)) $this->pluginDir = dirname($this->pluginFile);
$this->libraryPath = $this->pluginDir . '/libs/';
$this->handbookPath = $this->pluginDir . '/handbook.txt';
$this->adsense = new AdsenseStats();
$this->db = new SiteDB();
//Language Setup
$locale = get_locale();
$mo = dirname(__FILE__) . "/languages/" . $this->name . "-".$locale.".mo";
load_textdomain($this->name, $mo);
//add_action('init', array(&$this, 'InitializePlugin'));
/* Get plugin data */
$this->options = maybe_unserialize(get_option($this->options_name));
if(!isset($this->options['settings'])){
$this->options['settings'] = $this->DefaultSettings();
update_option($this->options_name, $this->options);
}
/** This can be removed once everyone is using 1.0.5+ */
if(!isset($this->options['settings']['defaulttab']))
$this->options['settings']['defaulttab'] = 'handbook-tab';
/* Hook the actions */
$this->HookActions();
/* Add the shortcodes */
$this->AddShortcodes();
if(gettype($this->options)!="array"){
$this->options = array();
}
$this->adsense->SetUsername($this->options['settings']['adsense']['username']);
$this->adsense->SetPassword($this->options['settings']['adsense']['password']);
}
public function PingBack($version, $previousVersion, $state){
if(function_exists('curl_init')){
global $wp_version;
global $advertwhirl_options_name;
global $advertwhirl_plugin_version;
global $advertwhirl_plugin_name;
$options = maybe_unserialize(get_option($advertwhirl_options_name));
//private function curl_post($url, $post) {
$post['plugin'] = $advertwhirl_plugin_name;
$post['version'] = $advertwhirl_plugin_version;
$post['preversion'] = $previousVersion;
$post['state'] = $state;
$post['phpversion'] = PHP_VERSION;
$post['wpversion'] = get_bloginfo('version');
$post['site'] = get_site_url();
$post['server'] = $_SERVER['SERVER_SOFTWARE'];
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $this->eturi);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_exec($curl);
curl_close($curl);
}
}
/** Called as a static from ActivatePlugin hook */
public function ActivatePlugin() {
global $advertwhirl_options_name;
global $advertwhirl_plugin_name;
global $advertwhirl_plugin_version;
$options = maybe_unserialize(get_option($advertwhirl_options_name));
$options['flags']['deactivating'] = false;
update_option($advertwhirl_options_name, $options);
// Ad the rules for exteranl adds back to .htaccess
$inst = new AdvertwhirlPlugin();
$inst->FlushRewrites();
/* Check the version info */
$state = "active";
if(!isset($this->options['settings']['installed_version'])){
// This is a new install
$options['settings']['installed_version'] = $advertwhirl_plugin_version;
update_option($advertwhirl_options_name, $options);
}else{
// There is a current install
switch(version_compare($advertwhirl_plugin_version, $options['settings']['installed_version'])){
case -1:
// Version downgrade
$options['settings']['previous_version'] = $options['settings']['installed_version'];
$options['settings']['installed_version'] = $advertwhirl_plugin_version;
update_option($advertwhirl_options_name, $options);
break;
case 0:
// No version change, just a simple re-activation
break;
case 1:
// Version upgrade
$options['settings']['previous_version'] = $options['settings']['installed_version'];
$options['settings']['installed_version'] = $advertwhirl_plugin_version;
update_option($advertwhirl_options_name, $options);
break;
}
}
$cversion = $options['settings']['installed_version'];
$pversion = isset($options['settings']['previous_version'])?$options['settings']['previous_version']:'na';
$inst->PingBack($cversion, $pversion, $state);
}
public function DeactivatePlugin() {
global $wp_version;
global $advertwhirl_options_name;
$options = maybe_unserialize(get_option($advertwhirl_options_name));
$inst = new AdvertwhirlPlugin();
/* Remove the shortcodes */
$inst->RemoveShortcodes();
/** Register Admin Style Sheet*/
wp_deregister_style('advertwhirl-plugin-admin-css');
/** Register Admin Javascript*/
wp_deregister_script('advertwhirl-plugin-admin-scripts');
// If external ads are set flush the rules to remove the external ad rules
$options['flags']['deactivating'] = true;
update_option($advertwhirl_options_name, $options);
$inst->FlushRewrites();
$state = "inactive";
$cversion = $options['settings']['installed_version'];
$pversion = isset($options['settings']['previous_version'])?$options['settings']['previous_version']:'na';
$inst->PingBack($cversion, $pversion, $state);
}
// Protected cloner for singleton
//private function __clone(){}
public function InitializePlugin(){
if(!$this->initialized){
/* Get plugin data */
global $wp_version;
$this->options = maybe_unserialize(get_option($this->options_name));
if(!isset($this->options['settings'])){
$this->options['settings'] = $this->DefaultSettings();
update_option($this->options_name, $this->options);
}
/** This can be removed once everyone is using 1.0.5+ */
if(!isset($this->options['settings']['defaulttab']))
$this->options['settings']['defaulttab'] = 'handbook-tab';
/* Hook the actions */
$this->HookActions();
/* Add the shortcodes */
$this->AddShortcodes();
if(gettype($this->options)!="array"){
$this->options = array();
}
$this->adsense->SetUsername($this->options['settings']['adsense']['username']);
$this->adsense->SetPassword($this->options['settings']['adsense']['password']);
$this->initialized = true;
}
}
private function DefaultSettings(){
$settings = array();
$settings['externalAdsEnabled'] = false;
$settings['adUrlPrefix'] = 'advertwhirl';
$settings['defaulttab'] = 'handbook-tab';
/* Default Settings for Adsense */
$adsenseSettings = array();
$adsenseSettings['username'] = "";
$adsenseSettings['password'] = "";
$adsenseSettings['ads-cache'] = 8640;
$adsenseSettings['stats-cache'] = 8640;
$settings['adsense'] = $adsenseSettings;
$analyticsSettings = array();
$analyticsSettings['enabled'] = false;
$analyticsSettings['username'] = "";
$analyticsSettings['password'] = "";
$analyticsSettings['VariablesEnabled'] = true;
$settings['analytics'] = $analyticsSettings;
return $settings;
}
public function HookActions() {
add_action('admin_menu', array(&$this, 'DisplayAdminMenu')); /* Add the admin menu */
add_action('wp_dashboard_setup', array(&$this, 'AddDashboardWidgets')); /* Add the stats widget to the dashboard */
if(!isset($this->rewriteHooked) || !$this->rewriteHooked){
add_action('generate_rewrite_rules', array(&$this, 'RewriteExternalAds'));
$this->rewriteHooked = true;
}
add_action('admin_init', array(&$this, 'AdminInit'));
// Hooks and filters for auto insertion of ads
if($this->options['settings']['display']['hook_content'])
add_filter("the_content", array(&$this, "FilterContent"), 1000);
if($this->options['settings']['display']['hook_header'])
add_action('wp_head', array(&$this, 'InsertHeaderAds'));
if($this->options['settings']['display']['hook_footer'])
add_action('wp_footer', array(&$this, 'InsertFooterAds'));
}
public function FilterContent($content){
$type = get_post_type();
if($type == 'page' && is_front_page()){
$type = 'homepage';
}
$precontent = "";
$postcontent = "";
$midcontent = "";
$useMidContent = false;
foreach($this->options['adcampaigns'] as $name => $campaign){
// Get the display settings for this campaign
if($campaign['display']['enabled']){
// Insert an add before the content if required
if($campaign['display'][$type]['before-content']){
$precontent .= advertwhirl_get_ad($name);
}
if($campaign['display'][$type]['in-content']){
$useMidContent = true;
$maxAds = $campaign['display'][$type]['maxads'];
$adsEvery = $campaign['display'][$type]['every'];
$offset = $campaign['display'][$type]['offset'] - 1;
$align = $campaign['display'][$type]['align'];
$adon = 0; //this is a variable so you don't show ads more than once.
$midcontent .= '
';
$tcount = 0; //this is count for number of
blocks
/** This switch is broke up weird for improved performance. the modules
* doesn't need to be calculated for the content of every post/page if
* ads are aligned on the left or right
*/
switch($align){
case '0':
// 'On the left'
$float = "float:left;";
break;
case '1':
// 'On the right'
$float = "float:right;";
break;
case '2':
// 'Alternating on the left then on the right'
$even = "float:left;";
$odd = "float:right;";
break;
case '3':
// 'Alternating on the right then on the left'
$even = "float:right;";
$odd = "float:left;";
break;
}
$dimensions = explode('x', $campaign['adsize']);
if(is_array($dimensions) && count($dimensions) == 2){
$size = 'width:' . $dimensions[0] . 'px;height:' . $dimensions[1] . 'px;';
}else{
$size = '';
}
$paragraphs = explode("
", $content); //Separate the content into
blocks
foreach($paragraphs as $paragraph) {
if(preg_match('/
/',$paragraph) == 0 && $tcount >= $offset && ($tcount - $offset) % $adsEvery == 0 && $adon < $maxAds){
if($align > 1){
/** This switch is broke up weird for improved performance. the modules
* doesn't need to be calculated for the content of every post/page if
* ads are aligned on the left or right
*/
$float = $adon % 2 == 0?$even:$odd;
}
$midcontent .= '
';
}else{
echo '>';
}
if( !isset($this->options['adsources']) && (!isset($this->options['settings']['adsense']['username']) || !isset($this->options['settings']['adsense']['password']))){
$onClick = 'onClick="alert(\'You need to configure an ad source before you can setup a campaign. You can configure your own local ad sources under Ad Sources or import your Adsense Ad Units as ad sources by configuring Adsense in Settings.\'); return false;"';
}
echo '
' . "\n";
}
function GetAdsenseAdminForm(){
$content =
'
Adsense Login
Username
Password
Caching
How long should Advertwhirl save data it loads from Adsense. Loading data such as reports and ad lists can be slow, turning on caching will make the Advertwhirl control panels more responsive but new settings made at the Adsense website will not be seen immediatly by Advertwhirl. Ad code from is always cached to insure ads are served as quickly as possible. If you make a change to an Adsense Ad Slot that you are using as an ad source you will need to manually update the adsense cache.
Ad campaigns can be accessed from external sites with a permalink style url if external ads are enabled. As these ads are being loaded outside of your wordpress site any of the rules which rely on wordpress variables, posts, pages etc... will be marked false. Even if the external site is also running wordpress, all wordpress rules will be marked false.
Enable External Ads
External URL
' . get_site_url() . '//your_campaign/
If Google Analytics is enabled extra path information after the name of an ad campaign can be added to your analytics code as custom variables.
Add Google Anayltic Variables
To use location rules you need a free api key from the IP Info Database. You can request your key here it is a simple form and they will email the key in a few minutes time.
' . "\n";
echo 'Advertwhirl(pronounced Adver-twhirl) is a wordpress plugin that lets you set up advertising campaigns for your site. Each campaign has 1 or more allocation strategies which can be made active manually or by schedule. Each allocation strategy defines what ad-servers the campaign uses and how ads are rotated between them. Campaigns can be accessed through a shortcode.
Mobile Sentience LLC actively supports Advertwhirl if you have any questions or problems you can fill out the form below. The message is pre-filled with some technical specs which will help us troubleshoot any issues. Mobile Sentience provides all support through a public forum, this helps us manage our support costs as well as providing a searchable reference of past problems and questions that other users of encountered. A great place to start if you have a simple question is to see if it has already been asked and answered on the Advertwhirl Support Forum
Report a problem
' . "\n";
}
function getRightMost($sSrc, $sSrch) {
for ($i = strlen($sSrc); $i >= 0; $i = $i - 1) {
$f = strpos($sSrc, $sSrch, $i);
if ($f !== FALSE) {
return substr($sSrc,$f + strlen($sSrch), strlen($sSrc));
}
}
return $sSrc;
}
public function DisplayAdminTabs($activeTab){
echo '