Advertwhirl Follow Mobile Sentience'; private $DonateImage = '
'; private $DonateText = 'Donate'; private $TwitterFollow = 'Follow Mobile Sentience'; private $FacebookFollow = ''; 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' => 'Handbook', '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-', '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-' ) ) ); private $RuleTypes = array ( 'author' => 'Match an author', 'posttype' => 'Match the post type', 'getargument' => 'Match link arguments' ); 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' ); // Protected constructor for singleton private function __construct(){ /** Uncomment for testing, forces loading of plugin stylesheets and javascripts */ global $pluginversion; global $pluginname; $this->version = $pluginversion; $this->name = $pluginname; $this->adserv = 'http://www.mobilesentience.com/ads/WordpressPlugins&plugin=' . $this->name . '&pluginversion=' . $this->version; $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(get_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')); } public function DeactivatePlugin() { /* Remove the shortcodes */ $this->RemoveShortcodes(); /** Register Admin Style Sheet*/ wp_deregister_style('advertwhirl-plugin-admin-css'); /** Register Admin Javascript*/ wp_deregister_script('advertwhirl-plugin-admin-scripts'); } // Protected cloner for singleton private function __clone(){} public function InitializePlugin(){ /* Get plugin data */ global $wp_version; if ($wp_version=="2.6"){ // 2.6 fix, this version unserializes data for some odd reason. $this->options = get_option($this->name . "_options"); }else{ $this->options = unserialize(get_option($this->name . "_options")); } /* Hook the actions */ $this->HookActions(); /* Add the shortcodes */ $this->AddShortcodes(); if (gettype($this->options)!="array"){ $this->options = array(); } if(!isset($this->options['settings'])) $this->options['settings'] = $this->DefaultSettings(); $this->adsense->SetUsername($this->options['settings']['adsense']['username']); $this->adsense->SetPassword($this->options['settings']['adsense']['password']); } private function DefaultSettings(){ $settings = array(); $settings['externalAdsEnabled'] = false; $settings['adUrlPrefix'] = 'advertwhirl'; /* 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 */ add_action('generate_rewrite_rules', array(&$this, 'RewriteExternalAds')); add_action('admin_init', array(&$this, 'FlushRewrites')); } public function AddShortcodes(){ add_shortcode('advertwhirl', array(&$this, 'HandleShortcode_advertwhirl')); } public function RemoveShortcodes(){ remove_shortcode('advertwhirl', array(&$this, 'HandleShortcode_advertwhirl')); } public function FlushRewrites(){ if($this->options['settings']['externalRulesUpdated']){ $this->options['settings']['externalRulesUpdated'] = false; global $wp_rewrite; $wp_rewrite->flush_rules(); } } public function RewriteExternalAds() { global $wp_rewrite; $prefix = $this->options['settings']['adUrlPrefix']; if($this->options['settings']['externalAdsEnabled']){ $newRules = array( $prefix . '/(.*)' => $this->externalAdsPath . '$1' ); $wp_rewrite->non_wp_rules = $newRules + $wp_rewrite->non_wp_rules; } } // Get the sole instance of the singleton static public function GetInstance(){ if(self::$instance === null){ self::$instance = new AdvertwhirlPlugin(); } return self::$instance; } private function GetTechnicalSpecs(){ global $wp_version; $specs .= "Plugin Specs\n"; $specs = "========================================\n"; $specs .= "Plugin: $this->name\n"; $specs .= "Plugin Version: $this->version\n"; $specs .= "Plugin Directory: $this->pluginDir\n\n"; $specs .= "Server Specs\n"; $specs = "========================================\n"; $specs .= "Server Address: " . $_SERVER['SERVER_ADDR'] . "\n"; $specs .= "Server Name: " . $_SERVER['SERVER_NAME'] . "\n"; $specs .= "Server Software: " . $_SERVER['SERVER_SOFTWARE'] . "\n\n"; $specs .= "Wordpress Specs\n"; $specs = "========================================\n"; $specs .= "Blog Name: " . get_option('blogname') . "\n"; $specs .= "Wordpress Version: $wp_version\n"; $specs .= "Wordpress Siteurl: " . get_option("siteurl") . "\n"; $specs .= "Wordpress Home: " . get_option("home") . "\n"; $specs .= "\tActive Plugins\n"; $specs .= "\t========================================\n"; foreach(get_option('active_plugins') as $index => $plugin){ if(strlen($plugin)>0) $specs .= "\t$plugin\n"; } /** PHP Info - @TODO: outputs html and needs to be parsed */ //ob_start(); //phpinfo(INFO_GENERAL or INFO_CONFIGURATION or INFO_MODULES); //$specs .= ob_get_contents(); //ob_get_clean(); return $specs; } function HandleShortcode_advertwhirl($atts, $content = null) { extract(shortcode_atts(array('campaign' => null), $atts)); $output = 'No Campaign selected'; if(isset($campaign)){ $output = 'advertisement for campaign ' . $campaign; } return $output; } // Add the stats widget to the dashboard public function AddDashboardWidgets() { // Add statistics widget to dashboard if(isset($this->options['settings']['displayDashboard']) && $this->options['settings']['displayDashboard']) wp_add_dashboard_widget("AdvertwhirlStatsWidget", "Advertwhirl", array(&$this, "DisplayAdvertwhirlStatsWidget")); } public function DisplayAdsenseStats(){ $periods = array(); foreach($this->adsense->GetReportPeriods() as $key => $value){ if(isset($this->options['settings']['adsense']['period'][$key])){ $periods[$key] = $this->options['settings']['adsense']['period'][$key]; }else{ $periods[$key] = false; } } $types = array(); foreach($this->adsense->GetReportTypes() as $key => $value){ if(isset($this->options['settings']['adsense']['type'][$key])){ $types[$key] = $this->options['settings']['adsense']['type'][$key]; }else{ $types[$key] = false; } } $categories = array(); foreach($this->adsense->GetAdCategories() as $key => $value){ if(isset($this->options['settings']['adsense']['category'][$key])){ $categories[$key] = $this->options['settings']['adsense']['category'][$key]; }else{ $categories[$key] = false; } } $this->adsense->LoadStats(); $this->adsense->GetStatTables($periods, $types, $categories); } public function DisplayAdvertwhirlStatsWidget(){ echo '
'; if($this->options['settings']['adsense']['dashboard']) $this->DisplayAdsenseStats(); echo '
'; } public function DisplayAdminMenu(){ $this->pluginPage = add_options_page('Advertwhirl Options', 'Advertwhirl', 'manage_options', __FILE__, array(&$this, 'CreateAdminPanel')); add_action('admin_print_styles-' . $this->pluginPage, array(&$this, 'LinkAdminStylesheet')); add_action('admin_print_scripts-' . $this->pluginPage, array(&$this, 'LinkAdminScripts')); } function LinkAdminStylesheet() { /** Register plugin admin stylesheet*/ wp_register_style('advertwhirl-plugin-admin-css', plugins_url('css/styles.css', __FILE__), false, $this->version); /** Enqueue plugin admin stylesheet*/ wp_enqueue_style('advertwhirl-plugin-admin-css'); } function LinkAdminScripts() { /** Register plugin admin javascript*/ wp_register_script('advertwhirl-plugin-admin-scripts', plugins_url('advertwhirl.js', __FILE__), false, $this->version); /** Enqueue plugin admin stylesheet*/ wp_enqueue_script('advertwhirl-plugin-admin-scripts'); } function DisplayMobileSentienceAd(){ echo ''; } public function DisplayAdminBanner($activeTab){ echo '

' . $this->PromoteText . '

'; } function ShiftArrayElement(&$a, $index, $delta){ if(isset($a) && is_array($a)){ $nindex = $index + $delta; if($nindex < 0){ $nindex = 0; }else if($nindex >= sizeof($a)){ $nindex = sizeof($a) - 1; } $tmp = $a[$index]; for($i = $index; $i != $nindex; $i += $delta){ $a[$i] = $a[$i + $delta]; } $a[$nindex] = $tmp; } } function ExtractPostArray($map, $postfix = ""){ $sets = null; $i = 0; $found = true; while($found){ $set = null; $found = false; foreach($map as $dkey => $pkey){ if(is_array($pkey)){ $post = $postfix . $i . '-'; $sub = $this->ExtractPostArray($pkey, $post); if(isset($sub)){ if(!isset($set)){ $set = array(); } $set[$dkey] = $sub; $found = true; } }else if(isset($_POST[$pkey . $postfix . $i])){ if(!isset($set)){ $set = array(); } $set[$dkey] = $_POST[$pkey . $postfix . $i]; $found = true; } } if(isset($set)){ if(!isset($sets)){ $sets = array(); } $sets[] = $set; } $i++; } return $sets; } function CalculateWeights($campaign, $index, &$allocation){ // Setup weight stats $success = true; $totalWeights = 0; $totalPercents = 0; $percents = array(); foreach($allocation['ads'] as $i => $ad){ $weight = strlen($ad['weight']) > 0?$ad['weight']:0; $weight = str_replace(' ', '', $weight); if(is_numeric($weight)){ /* Weight */ $w = intVal($weight); $totalWeights += $w; if($w < 0){ $_POST['aladweighterror-' . $index . '-' . $i] = "*Allocations can't have a negative weight"; $success = false; }else if(isset($ad['percent-weight'])){ unset($ad['percent-weight']); } //error_log("CalulateWeights: weight => $weight"); }else if (strpos($weight, '%') !== false){ /* Percent */ $weight = str_replace('%', '', $weight); $percents["$i"] = floatVal($weight)/100; if($percents["$i"] < 0){ $_POST['aladweighterror-' . $index . '-' . $i] = "*Allocations can't have a negative weight"; $success = false; } $totalPercents += $percents["$i"]; //error_log("CalculateWeights percent => " . $percents["$i"]); }else{ // set error code $_POST['aladweighterror-' . $index . '-' . $i] = "*Invalid weight value"; //error_log("CalculateWeights => error"); $success = false; } } if($totalPercents > 1 || ($totalPercents == 1 && $totalWeights > 0)){ $_POST['aladweighterror-' . $index] = "*Ad slots over-allocated"; $success = false; }else if($totalPercents < 1 && $totalWeights == 0){ $_POST['aladweighterror-' . $index] = "*Ad slots under-allocated, percentage only allocations must total 100%"; $success = false; } if(!$success) return $success; // Calculate percent weights $weightWithPercents = $totalWeights == 0 && $totalPercents > 0?1000:$totalWeights/(1 - $totalPercents); $percentWeightsOnly = $totalWeights == 0 && $totalPercents > 0?true:false; //error_log("Calculate Weights: weightWithPercents = $totalWeights / (1 - $totalPercents)"); //error_log("Calculate Weights: total weights => $totalWeights"); //error_log("Calculate Weights: total percents => $totalPercents"); //error_log("Calculate Weights: weight with percents => $weightWithPercents"); if($percentWeightsOnly){ require_once('libs/Math.php'); if(count($percents) == 1){ $allocation['ads'][$i]['percent-weight'] = intval($w); }else{ $values = array(); foreach($percents as $i => $percent){ $w = $weightWithPercents * $percent; $values[] = intval($w); } $gcf = get_gcf($values); foreach($values as $i => $value){ $allocation['ads'][$i]['percent-weight'] = $gcf !== false?$value / $gcf:$value; } } } else{ foreach($percents as $i => $percent){ $w = $weightWithPercents * $percent; $allocation['ads'][$i]['percent-weight'] = ceil($w); //error_log("Calculate Weights: percent weight => " . $ad['percent-weight']); } } unset($this->options['stats']['adcampaigns'][$campaign]['allocations'][$index]['sourceweights']); $this->options['stats']['adcampaigns'][$campaign]['allocations'][$index]['sourceweights'] = array(); foreach($allocation['ads'] as $i => $ad){ $this->options['stats']['adcampaigns'][$campaign]['allocations'][$index]['sourceweights'][] = 0; } //unset($this->options['stats']['allocations'][$aname]['sponsorweight']); //$this->options['stats']['allocations'][$aname]['sponsorweight'] = 0; return $success; } function CampaignListTab_update($tab, $action){ // Check for allocation buttons $postAllocations = $this->ExtractPostArray($this->AllocationMap); if(isset($postAllocations) && sizeof($postAllocations) > 0){ $edit = false; $count = sizeof($postAllocations); for($i = 0; $i < $count; $i++){ if(isset($_POST['aldown-' . $i])){ $this->ShiftArrayElement($postAllocations, $i, 1); $edit = true; }else if(isset($_POST['alup-' . $i])){ $this->ShiftArrayElement($postAllocations, $i, -1); $edit = true; }else if(isset($_POST['alremove-' . $i])){ unset($postAllocations[$i]); $edit = true; }else if(isset($_POST['add-allocation-source-' . $i])){ $_POST['adsupdated-' . $i] = true; $postAllocations[$i]['ads'][] = $this->GetDefaultAllocationAd(); $edit = true; }else if(isset($_POST['add-allocation-ruleset-' . $i])){ $postAllocations[$i]['rulesets'][] = array(); $postAllocations[$i]['rulesets'][0]['id'] = $i . '-' . sizeof($postAllocations[$i]['rulesets']); $edit = true; } $adcount = sizeof($postAllocations[$i]['ads']); for($j = 0; $j < $adcount; $j++){ if(isset($_POST['aladremove-' . $i . '-' . $j])){ $_POST['adsupdated-' . $i] = true; unset($postAllocations[$i]['ads'][$j]); $edit = true; } } for($j = 0; $j < sizeof($postAllocations[$i]['rulesets']); $j++){ if(isset($_POST['add-allocation-rule-' . $i . '-' . $j])){ $postAllocations[$i]['rulesets'][$j]['rules'][] = $this->GetDefaultAllocationRule($_POST['new-rule-type-' . $i . '-' . $j]); $edit = true; } $rulecount = sizeof($postAllocations[$i]['rulesets'][$j]['rules']); for($k = 0; $k < $rulecount; $k++){ if(isset($_POST['alruleremove-' . $i . '-' . $j . '-' . $k])){ unset($postAllocations[$i]['rulesets'][$j]['rules'][$k]); $edit = true; } } } } if($edit){ if(isset($_POST['current-action'])){ $action = $_POST['current-action']; } if(isset($_POST['add-set']) && $_POST['add-set']){ $_POST['add'] = true;; } if(isset($_POST['edit-set']) && $_POST['edit-set']){ $_POST['edit'] = true;; } return $this->CampaignListTab_edit($tab, $action, $postAllocations); } } if(isset($_POST['current-action'])){ $action = $_POST['current-action']; } if(isset($_POST['add-set']) && $_POST['add-set']){ $_POST['add'] = true;; } if(isset($_POST['edit-set']) && $_POST['edit-set']){ $_POST['edit'] = true;; } if(isset($_POST['add-allocation'])){ $postAllocations[] = $this->GetDefaultAllocation(); return $this->CampaignListTab_edit($tab, $action, $postAllocations); } else if(isset($_POST['add'])){ if(!isset($_POST['name']) || $_POST['name'] == ""){ $_POST['name_error'] = "*Name is a required field"; return $this->CampaignListTab_edit($tab, $action); } $name = $_POST['name']; $error = false; foreach($postAllocations as $i => $allocation){ $error = $this->CalculateWeights($name, $i, $allocation)?$error:true; } if($error){ return $this->CampaignListTab_edit($tab, $action); } $this->options['adcampaigns'][$name]['allocations'] = $postAllocations; $this->options['adcampaigns'][$name]['description'] = $_POST['description']; update_option($this->name . "_options", serialize($this->options)); return $this->CampaignListTab_view($tab, $action); } else if(isset($_POST['update'])){ if(!isset($_POST['name']) || $_POST['name'] == ""){ $_POST['name_error'] = "*Name is a required field"; return $this->CampaignListTab_edit($tab, $action); } $name = $_POST['name']; if(isset($this->options['adcampaigns'][$name]) && $_POST['origname'] != $name){ $_POST['name_error'] = "*Name must be unique"; return $this->CampaignListTab_edit($tab, $action); } $error = false; foreach($postAllocations as $i => &$allocation){ if(!$_POST['adsupdated-' . $i]){ foreach($allocation['ads'] as $j => $ad){ if($_POST['aladoriginalweight-' . $i . '-' . $j] != $ad['weight']){ $error = $this->CalculateWeights($name, $i, $allocation)?$error:true; break; } } }else{ $error = $this->CalculateWeights($name, $i, $allocation)?$error:true; } } if($error){ return $this->CampaignListTab_edit($tab, $action); } if($_POST['origname'] != $name){ $oname = $_POST['origname']; unset($this->options['adcampaigns'][$oname]); unset($this->options['stats']['adcampaigns'][$oname]); } $this->options['adcampaigns'][$name]['allocations'] = $postAllocations; $this->options['adcampaigns'][$name]['description'] = $_POST['description']; update_option($this->name . "_options", serialize($this->options)); return $this->CampaignListTab_view($tab, $action); } else if(isset($_POST['delete'])){ if(!isset($_POST['name']) || $_POST['name'] == ""){ return $this->CampaignListTab_view($tab, $action); } $name = $_POST['name']; unset($this->options['adcampaigns'][$name]); update_option($this->name . "_options", serialize($this->options)); return $this->CampaignListTab_view($tab, $action); } else if(isset($_POST['cancel'])){ return $this->CampaignListTab_view($tab, $action); } } function GetAllocationRuleForm_author($i, $j, $k, $rule){ $authors = $this->db->GetAuthorsList(); $content .= ' '; return $content; } function GetAllocationRuleForm_posttype($i, $j, $k, $rule){ $content .= ' '; return $content; } function GetAllocationRuleForm_getargument($i, $j, $k, $rule){ $argumentOperators = array ( '=' => 'is equal to', '!=' => 'is not equal to', '>' => 'is greater than', '<' => 'is less than', '>=' => 'is greater than or equal to', '<=' => 'is less than or equal to', '~' => 'matches regular expression', '!~' => 'does not match regular expression', ); $content .= ' '; $content .= ' '; return $content; } function GetAllocationRuleForm($i, $j, $k, $rule){ $func = "GetAllocationRuleForm_" . $rule['type']; if(method_exists($this, $func)){ $content = ' ' . $this->RuleTypes[$rule['type']] . ' '; $content .= call_user_func(array(&$this, $func), $i, $j, $k, $rule); $content .= ' '; } return $content; } function GetAllocationAdForm($i, $index, $ad, $displayRemove){ if($displayRemove){ $labelWidth = "10%"; $adWidth = "40%"; $weightWidth = "20%"; }else{ $labelWidth = "10%"; $adWidth = "50%"; $weightWidth = "30%"; } $content .= ' '; if($displayRemove){ $content .= ' '; } $content .= '
Ad Source Weight ' . $_POST['aladweighterror-' . $i . '-' . $index] . ''; if(isset($ad['percent-weight'])){ $content .= ' '; } $content .= '
'; return $content; } function GetAllocationForm($i, $allocation, $totalAllocations){ // Calculate what buttons if any to display $displayButtonRow = $totalAllocations > 1; $displayMoveUp = $i > 0; $displayMoveDown = $i < $totalAllocations - 1; $adsupdated = isset($_POST['adsupdated-' . $i])?$_POST['adsupdated-' . $i]:false; $id = $i + 1; $content = '
' . $id . '
'; if(isset($_POST['aladweighterror-' . $i])){ $content .= ' '; } if(isset($allocation['ads'])){ foreach($allocation['ads'] as $index => $ad){ $content .= $this->GetAllocationAdForm($i, $index, $ad, sizeof($allocation['ads']) > 1); } } $content .= ' '; if(isset($allocation['rulesets'])){ $content .= ' '; } $content .= ' '; if($displayButtonRow){ $content .= ' '; } $content .= '
Description
Ads
' . $_POST['aladweighterror-' . $i] . '
Rules
'; foreach($allocation['rulesets'] as $id => $set){ $content .= ' '; } $content .= '
' . ($id + 1) . '
'; if(isset($set['rules'])){ foreach($set['rules'] as $j => $rule){ $content .= $this->GetAllocationRuleForm($i, $id, $j, $rule); } } $content .= '
'; if($displayMoveDown){ $content .= ' '; } if($displayMoveUp){ $content .= ' '; } $content .= '
'; return $content; } function GetDefaultAllocationRule($type = null){ $rule = array(); $rule['type'] = $type; $rule['author'] = ""; $rule['posttype'] = ""; $rule['tag'] = ""; $rule['category'] = ""; $rule['post'] = ""; $rule['page'] = ""; return $rule; } function GetDefaultAllocationAd(){ $ad = array(); $ad['advertisement'] = ""; $ad['weight'] = "1"; return $ad; } function GetDefaultAllocation(){ $allocation = array(); $allocation['name'] = ""; $allocation['description'] = ""; $allocation['ads'][] = $this->GetDefaultAllocationAd(); return $allocation; } function CampaignListTab_edit($tab, $action, $postAllocations = null){ $baseurl = $this->pageURL . '&tab=' . $tab . '&action='; $cancelurl = $this->pageURL . '&tab=' . $tab . '&action=view'; //verify data $add = isset($_POST['add']); $addAllocation = isset($_POST['add-allocation']); $edit = isset($_POST['edit']); $delete = isset($_POST['delete']); if ($add){ $title = "Create new ad campaign"; $submitName = "add"; $submitValue = "Save Campaign"; $origname = ""; if(isset($_POST['name'])){ $name = $_POST['name']; } if(isset($_POST['description'])){ $description = $_POST['description']; } }else if($edit){ $title = "Edit ad campaign"; $name = $_POST['name']; $submitName = "update"; $submitValue = "Save Campaign"; if(isset($_POST['origname'])){ $origname = $_POST['origname']; }else{ $origname = $name; } if(isset($_POST['description'])){ $description = $_POST['description']; }else{ if(isset($_POST['origname'])){ $description = $this->options['adcampaigns'][$origname]['description']; }else{ $description = $this->options['adcampaigns'][$name]['description']; } } } else if($delete){ return $this->CampaignListTab_update($tab, $action); } echo '

'; echo ' '; if(!isset($postAllocations)){ $postAllocations = $this->ExtractPostArray($this->AllocationMap); } if(!isset($postAllocations)){ $list = $this->options['adcampaigns'][$name]['allocations']; }else{ $list = $postAllocations; } if(sizeof($list) == 0){ $list[0] = $this->GetDefaultAllocation(); } foreach($list as $index => $allocation){ echo $this->GetAllocationForm($index, $allocation, sizeof($list)); } echo '
' . $title . '
Name ' . $_POST['name_error'] . '
Description
Advertisement Allocation Schedules
'; } function CampaignListTab_view($tab, $action){ // Create the Custom variable list $baseurl = $this->pageURL . '&tab=' . $tab . '&action='; echo '

'; if(isset($this->options['adcampaigns'])){ $i=0; foreach($this->options['adcampaigns'] as $key => $value){ echo ''; echo''; }else{ echo '>'; } echo ' '; $i++; } } echo''; }else{ echo '>'; } echo '
Name Description Action
' . $key . ' ' . $this->options['adcampaigns'][$key]['description'] . '
'; } function SourceListTab_update($tab, $action){ //verify data if($_POST['cancel']){ return $this->SourceListTab_view($tab, $action); } $add = isset($_POST['add']); $delete = isset($_POST['delete']) && isset($_POST['name']) && isset($this->options['adsources'][$_POST['name']]); $update = isset($_POST['edit']) && isset($_POST['name']) && isset($this->options['adsources'][$_POST['name']]); if ($add){ if(!isset($_POST['name']) || strlen($_POST['name']) < 1 ){ $_POST['name_error'] = '*Name required'; return $this->SourceListTab_edit($tab, $action); } if(isset($this->options['adsources'][$_POST['name']])){ $_POST['name_error'] = '*Name must be unique'; return $this->SourceListTab_edit($tab, $action); } } if($delete){ $name = $_POST['name']; unset($this->options['adsources'][$name]); update_option($this->name . "_options", serialize($this->options)); echo '

Deleted Source ' . $name . '

'; }else{ $name = $_POST['name']; $this->options['adsources'][$name]['adtype'] = $_POST['adtype']; if($this->options['adsources'][$name]['adtype'] == "url"){ $this->options['adsources'][$name]['url'] = $_POST['url']; $this->options['adsources'][$name]['wrap_url'] = isset($_POST['wrap_url']); $this->options['adsources'][$name]['code'] = ""; } else { $this->options['adsources'][$name]['url'] = ""; $this->options['adsources'][$name]['wrap_url'] = false; $this->options['adsources'][$name]['code'] = stripslashes($_POST['code']); } $this->options['adsources'][$name]['description'] = $_POST['description']; update_option($this->name . "_options", serialize($this->options)); if($add){ echo '

Added Source ' . $name . '

'; }else{ echo '

Updated Source ' . $name . '

'; } } $_POST['name'] = ''; $_POST['adtype'] = ''; $_POST['url'] = ''; $_POST['wrap_url'] = ''; $_POST['code'] = ''; $_POST['description'] = ''; //add to options return $this->SourceListTab_view($tab, $action); } function SourceListTab_edit($tab, $action){ $baseurl = $this->pageURL . '&tab=' . $tab . '&action='; $cancelurl = $this->pageURL . '&tab=' . $tab . '&action=view'; //verify data $add = isset($_POST['add']); $edit = isset($_POST['edit']); $delete = isset($_POST['delete']); if ($add){ $title = "Create new ad source"; $urlChecked = "checked"; $codeChecked = ""; $displayURL = ""; $displayCode = "none"; $submitName = "add"; $submitValue = "Add Source"; }else if($edit){ $title = "Edit ad source"; $name = $_POST['name']; $urlChecked = $this->options['adsources'][$name]['adtype'] == "url"?"checked":""; $codeChecked = $this->options['adsources'][$name]['adtype'] == "inline"?"checked":""; $displayURL = $this->options['adsources'][$name]['adtype'] == "url"?"":"none"; $displayCode = $this->options['adsources'][$name]['adtype'] == "inline"?"":"none"; $submitName = "edit"; $submitValue = "Edit Source"; $description = $this->options['adsources'][$name]['description']; $url = $this->options['adsources'][$name]['url']; $wrapURL = isset($this->options['adsources'][$name]['wrap_url'])?"checked":""; $code = $this->options['adsources'][$name]['code']; } else if($delete){ return $this->SourceListTab_update($tab, $action); } echo '

' . $title . '
Name ' . $_POST['name_error'] . '
Description
Add Type URL Inline Code
URL
Inline Code
'; //add to options //$this->SourceListTab_view($tab, $action); } function SourceListTab_view($tab, $action){ // Create the Custom variable list $baseurl = $this->pageURL . '&tab=' . $tab . '&action='; echo '

'; if(isset($this->options['adsources'])){ $i=0; foreach($this->options['adsources'] as $key => $value){ echo ''; echo''; }else{ echo '>'; } echo ' '; $i++; } } echo''; }else{ echo '>'; } echo '
Name Description Action
' . $key . '
'; } function DisplaySettingsGroup($name, $content, $open){ $ps = $open?'':'style="display:none;"'; $chevron = $open?'collapse.gif':'expand.gif'; echo '
' . $name . '
Show/Hide
' . $content . '
' . "\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 Caching
Reports Caching
Adsense Reports
Get reports for '; foreach($this->adsense->GetReportPeriods() as $key => $value){ $checked = $this->options['settings']['adsense']['period'][$key]?'checked':''; $content .= ' '; } $content .= '
Statistics to report '; foreach($this->adsense->GetReportTypes() as $key => $value){ $checked = $this->options['settings']['adsense']['type'][$key]?'checked':''; $content .= ' '; } $content .= '
Get statistics for ad categories '; foreach($this->adsense->GetAdCategories() as $key => $value){ $checked = $this->options['settings']['adsense']['category'][$key]?'checked':''; $content .= ' '; } $content .= '
' . "\n"; return $content; } function GetGeneralSettingsAdminForm(){ $fillAllocation = $this->options['settings']['fillEmptyAllocations']?"checked":""; $displayDashboard = $this->options['settings']['displayDashboard']?"checked":""; $adsenseDashboard = $this->options['settings']['adsense']['dashboard']?'checked':''; $externalAdsEnabled = $this->options['settings']['externalAdsEnabled']?"checked":""; $adUrlPrefix = $this->options['settings']['adUrlPrefix']; $gaEnabled = $this->options['settings']['analytics']['enabled'] && strlen($this->options['settings']['analytics']['username']) > 0 && strlen($this->options['settings']['analytics']['password']) > 0?"":"disabled"; $gaVariablesEnabled = $this->options['settings']['analytics']['VariablesEnabled']?"checked":""; $content = '
Ad Sources
Empty Sources
External Ads
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
Dashboard
' . "\n"; return $content; } function GetCommissionJunctionAdminForm(){ $content = "Commission Junction integration still under development"; return $content; } function GetGoogleAnalyticsAdminForm(){ $content = "Google Anayltics integration still under development"; return $content; } function SettingsTab_view($tab, $action){ $baseurl = $this->pageURL . '&tab=' . $tab . '&action='; echo '
' . "\n"; /** Panel for general settings */ $groupOpen = true; $groupName = "General Settings"; $groupContent = $this->GetGeneralSettingsAdminForm(); $this->DisplaySettingsGroup($groupName, $groupContent, $groupOpen); /** Panel for Adsense settings */ $groupOpen = true; $groupName = "Adsense Settings"; $groupContent = $this->GetAdsenseAdminForm(); $this->DisplaySettingsGroup($groupName, $groupContent, $groupOpen); /** Panel for Google Analytics settings */ $groupOpen = false; $groupName = "Google Anayltics"; $groupContent = $this->GetGoogleAnalyticsAdminForm(); $this->DisplaySettingsGroup($groupName, $groupContent, $groupOpen); /** Panel for Commission Junction settings */ $groupOpen = false; $groupName = "Commission Junction"; $groupContent = $this->GetCommissionJunctionAdminForm(); $this->DisplaySettingsGroup($groupName, $groupContent, $groupOpen); echo '
' . "\n"; } function SettingsTab_update($tab, $action){ //verify data $update = isset($_POST['update']); $reloadAdsenseAdsCache = isset($_POST['reload-adsense-ads-cache']); $reloadAdsenseStatsCache = isset($_POST['reload-adsense-stats-cache']); if ($reloadAdsenseAdsCache){ if(isset($this->options['settings']['adsense']['username']) && isset($this->options['settings']['adsense']['password'])){ $this->adsense->LoadAdUnits(true); $this->adsense->Logout(); } } if ($reloadAdsenseStatsCache){ if(isset($this->options['settings']['adsense']['username']) && isset($this->options['settings']['adsense']['password'])){ $this->adsense->LoadStats(true); $this->adsense->Logout(); } } if ($update){ /** Update Adsense Settings */ $this->options['settings']['adsense']['username'] = $_POST['adsenseUsername']; $this->adsense->SetUsername($this->options['settings']['adsense']['username']); if(isset($_POST['adsensePassword']) && strlen($_POST['adsensePassword']) > 1){ $this->options['settings']['adsense']['password'] = $_POST['adsensePassword']; $this->adsense->SetPassword($this->options['settings']['adsense']['password']); } foreach($this->adsense->GetReportPeriods() as $key => $value){ $this->options['settings']['adsense']['period'][$key] = isset($_POST['adsense_report_period_' . $key]); } foreach($this->adsense->GetReportTypes() as $key => $value){ $this->options['settings']['adsense']['type'][$key] = isset($_POST['adsense_report_type_' . $key]); } foreach($this->adsense->GetAdCategories() as $key => $value){ $this->options['settings']['adsense']['category'][$key] = isset($_POST['adsense_report_category_' . $key]); } if(isset($_POST['adsense-ads-cache-time'])){ $this->options['settings']['adsense']['ads-cache'] = $_POST['adsense-ads-cache-time']; $this->adsense->SetAdsCache($_POST['adsense-ads-cache-time'] * 360); } if(isset($_POST['adsense-stats-cache-time'])){ $this->options['settings']['adsense']['stats-cache'] = $_POST['adsense-stats-cache-time']; $this->adsense->SetStatsCache($_POST['adsense-stats-cache-time'] * 360); } /** Update General Settings */ $this->options['settings']['fillEmptyAllocations'] = isset($_POST['fillEmptyAllocations']); if(isset($_POST['defaultsource'])) $this->options['settings']['defaultsource'] = $_POST['defaultsource']; $this->options['settings']['displayDashboard'] = isset($_POST['displayDashboard']); $this->options['settings']['adsense']['dashboard'] = isset($_POST['adsenseDashboard']); $this->options['settings']['externalRulesUpdated'] = true; //if($this->options['settings']['externalAdsEnabled'] != isset($_POST['externalAdsEnabled'])){ // $this->options['settings']['externalRulesUpdated'] = true; //} else if($this->options['settings']['adUrlPrefix'] != $_POST['adUrlPrefix']){ // $this->options['settings']['externalRulesUpdated'] = true; //}else{ // $this->options['settings']['externalRulesUpdated'] = false; //} $this->options['settings']['externalAdsEnabled'] = isset($_POST['externalAdsEnabled']); $this->options['settings']['adUrlPrefix'] = $_POST['adUrlPrefix']; $this->options['settings']['analytics']['VariablesEnabled'] = isset($_POST['gaVariablesEnabled']); /** Save the updated settings */ update_option($this->name . "_options", serialize($this->options)); } //add to options $this->SettingsTab_view($tab, $action); } function DisplayHandbookSection($name, $content){ //$ps = $open?'':'style="display:none;"'; //$chevron = $open?'collapse.gif':'expand.gif'; echo '
' . $name . '
Show/Hide
' . "\n"; } function MarkupHandbookSection($section){ $content = '
' . "\n"; $content .= str_replace(array("\r\n", "\n", "\r"), '
', $section); $content .= '
' . "\n"; return $content; } function GetHandbookSections($path){ $handbookText = file_get_contents($path, true); //split('= section =', $handbookText); $chunks = preg_split('/<-- ([^>]+) -->/i', $handbookText, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); $sections = array(); for($i = 0; $i < count($chunks); $i++){ $sections[$chunks[$i]] = $this->MarkupHandbookSection($chunks[$i + 1]); $i++; } return $sections; } function HandbookTab_view($tab, $action){ $sections = $this->GetHandbookSections($this->handbookPath); foreach($sections as $name => $content){ if(isset($name) && isset($content)) $this->DisplayHandbookSection($name, $content); } } function AboutTab_view($tab, $action){ echo '

Advertwhirl version ' . $this->version . '


' . "\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.

' . "\n"; echo 'Example shortcode
' . "\n"; echo '[­advertwhirl campaign=CAMPAIGN]

' . "\n"; echo '© Copyright 2011 Mobile Sentience LLC
' . "\n"; echo 'Written by Max Jonathan Spaulding - Mobile Sentience LLC
' . "\n"; echo '
' . "\n"; echo 'This program is free software; you can redistribute it and/or modify
' . "\n"; echo 'it under the terms of the GNU General Public License as published by
' . "\n"; echo 'the Free Software Foundation; either version 2 of the License, or
' . "\n"; echo '(at your option) any later version.
' . "\n"; echo '
' . "\n"; echo 'This program is distributed in the hope that it will be useful,
' . "\n"; echo 'but WITHOUT ANY WARRANTY; without even the implied warranty of
' . "\n"; echo 'MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' . "\n"; echo 'GNU General Public License for more details.
' . "\n"; echo '
' . "\n"; echo 'You should have received a copy of the GNU General Public License
' . "\n"; echo 'along with this program; if not, write to the Free Software
' . "\n"; echo 'Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

' . "\n"; } function SupportTab_view($tab, $action){ $defaultSubject = 'Bug Report: ' . $this->name . ' Version ' . $this->version; $defaultMessage = "\n\n\n\n\n\n" . $this->GetTechnicalSpecs(); include_once($this->libraryPath . "/captcha/shared.php"); include_once($this->libraryPath . "/captcha/captcha_code.php"); $wpf_captcha = new CaptchaCode(); $wpf_code = wpf_str_encrypt($wpf_captcha->generateCode(6)); echo '

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
Subject
Message
Security Code
' . "\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 '
' . "\n"; echo '
' . "\n"; foreach(array_keys($this->AdminTabs) as $tab){ $url = $this->pageURL . "&tab=" . $tab; if($activeTab == $tab){ echo '' . $this->AdminTabs[$tab]['name'] . '' . "\n"; }else{ echo '' . $this->AdminTabs[$tab]['name'] . '' . "\n"; } } echo '
' . "\n"; } public function DisplayAdminContent($tab, $action){ echo '
' . "\n"; echo '
' . "\n"; if(isset($this->AdminTabs[$tab])){ $func = $this->AdminTabs[$tab]['method_base'] . "_" . $action; if(!method_exists($this, $func)){ $func = $this->AdminTabs[$tab]['method_base'] . "_view"; } if(method_exists($this, $func)){ call_user_func(array(&$this, $func), $tab, $action); } } echo '
' . "\n"; echo '
' . "\n"; echo '
' . "\n"; } // Create the administration panel public function CreateAdminPanel(){ $activeTab = "campaigns-tab"; if(isset($_GET['tab'])){ if(isset($this->AdminTabs[$_GET['tab']])){ $activeTab = $_GET['tab']; } } $action = "view"; if(isset($_GET['action'])){ $action = $_GET['action']; } $this->DisplayMobileSentienceAd(); $this->DisplayAdminBanner($activeTab); $this->DisplayAdminTabs($activeTab); $this->DisplayAdminContent($activeTab, $action); } } ?>