$ad) { if (is_array($ad) && $ad['name'] == $name) return $ad; if (is_object($ad) && $ad->name == $name) return $ad; } } } static function advman_3_5_2(&$data) { // Split out data into different data keys, and remove the 'general' key update_option('plugin_advman_settings', $data['settings']); update_option('plugin_advman_ads', $data['ads']); update_option('plugin_advman_networks', $data['networks']); update_option('plugin_advman_stats', $data['stats']); // Delete the 'general' data key delete_option('plugin_advman'); // Set backup to position 1 (position 0 is the current backup) $backup = get_option('plugin_advman_backup'); if (!empty($backup)) { update_option('plugin_advman_backup_1', $backup); } delete_option('plugin_advman_backup'); delete_option('plugin_adsensem_backup'); } static function advman_3_5_1(&$data) { // Check to see if we need to migrate any old ad tags to new ad tags global $advman_engine; $patterns = array( '//', '/<!--adsense-->/', '//', '/<!--adsense#(.*?)-->/', '//', '/<!--am-->/', '//', '/<!--am#(.*?)-->/', '/\[ad#(.*?)\]/', ); $found_posts = 0; $found_ads = 0; $offset = 0; $numberposts = 10; $args = array('numberposts' => $numberposts, 'offset' => $offset, 'post_type' => array('post','page'), 'suppress_filters' => false); $posts = get_posts($args); while ($posts) { foreach ($posts as $post) { $ad_found_in_post = false; if (!empty($post->post_content)) { foreach ($patterns as $pattern) { if (preg_match_all($pattern, $post->post_content, $matches)) { if (!empty($matches[1])) { for ($i=0; $i $numberposts, 'offset' => $offset, 'post_type' => array('post','page'), 'suppress_filters' => false); $posts = get_posts($args); } if ($found_ads) { $question = __('You have [num_ads] Advertising Manager ads in [num_posts] posts that need to be upgraded to a new ad shortcode format. Do you want to automatically upgrade these shortcodes?', 'advman'); $question = str_replace('[num_ads]', $found_ads, $question); $question = str_replace('[num_posts]', $found_posts, $question); Advman_Admin::add_notice('update_shortcodes', $question, 'yn'); } } static function update_shortcodes() { // Check to see if we need to migrate any old ad tags to new ad tags global $advman_engine; $data = $advman_engine->dal->data; $patterns = array( '//', '/<!--adsense-->/', '//', '/<!--adsense#(.*?)-->/', '//', '/<!--am-->/', '//', '/<!--am#(.*?)-->/', '/\[ad#(.*?)\]/', ); $offset = 0; $numberposts = 10; $args = array('numberposts' => $numberposts, 'offset' => $offset, 'post_type' => array('post','page'), 'suppress_filters' => false); $posts = get_posts($args); while ($posts) { foreach ($posts as $post) { if (!empty($post->post_content)) { $post_content = $post->post_content; foreach ($patterns as $pattern) { if (preg_match_all($pattern, $post->post_content, $matches)) { if (!empty($matches[1])) { for ($i = 0; $i < sizeof($matches[1]); $i++) { $name = $matches[1][$i]; $ad = Advman_Upgrade::_selectAd($data, $name); if (!$ad) { $name = html_entity_decode($name); $ad = Advman_Upgrade::_selectAd($data, $name); } if (!$ad) { $name = str_replace(";", "\\;", $name); $ad = Advman_Upgrade::_selectAd($data, $name); } if ($ad) { $search = $matches[0][$i]; $replace = "[ad name=\"$name\"]"; $post_content = str_replace($search, $replace, $post_content); } } } else { $search = str_replace("/", "", $pattern); $replace = "[ad]"; $post_content = str_replace($search, $replace, $post_content); } } } if ($post->post_content != $post_content) { $post->post_content = $post_content; wp_update_post($post); } } } $offset += $numberposts; $args = array('numberposts' => $numberposts, 'offset' => $offset, 'post_type' => array('post','page'), 'suppress_filters' => false); $posts = get_posts($args); } } static function advman_3_4_29(&$data) { // Convert stats to a new format $stats = $data['stats']; $new_stats = array(); foreach ($stats as $dt => $stat) { foreach ($stat as $adId => $impressions) { $new_stats['d'][$dt]['ad'][$adId]['i'] = $impressions; } } $data['stats'] = $new_stats; // Remove publisher-id (not used) if (isset($data['settings']['publisher-id'])) { unset($data['settings']['publisher-id']); } // Change the purge stats days to 100 if still at the default of 30 if (isset($data['settings']['purge-stats-days']) && $data['settings']['purge-stats-days'] == 30) { $data['settings']['purge-stats-days'] = 100; } // Re-send adjs client ID if ($data['settings']['enable-adjs']) { $clientId = $data['settings']['adjs-clientid']; if ($clientId) { $url = "http://adjs.io/beta_signups/$clientId"; $params = array( 'method' => 'PUT', 'headers' => array("Accept"=>'application/json'), 'body' => array('beta_signup' => array("email"=>get_option('admin_email'),"url"=> get_option('siteurl'))) ); wp_remote_request($url, $params); } } } static function advman_3_4_25(&$data) { // Remove OpenX Market - does not work unset($data['settings']['openx-market']); unset($data['settings']['openx-market-cpm']); // Set the category to be 'all' (by making it = '') foreach ($data['ads'] as $id => $ad) { if (!isset($data['ads'][$id]['openx-market'])) { unset($data['ads'][$id]['openx-market']); } if (!isset($data['ads'][$id]['openx-market-cpm'])) { unset($data['ads'][$id]['openx-market-cpm']); } } foreach ($data['networks'] as $id => $network) { if (!isset($data['networks'][$id]['openx-market'])) { unset($data['networks'][$id]['openx-market']); } if (!isset($data['networks'][$id]['openx-market-cpm'])) { unset($data['networks'][$id]['openx-market-cpm']); } } } static function advman_3_4_20(&$data) { // Remove synchronization settings unset($data['settings']['last-sync']); unset($data['settings']['openx-sync']); } static function advman_3_4_15(&$data) { // Set the category to be 'all' (by making it = '') foreach ($data['ads'] as $id => $ad) { if (!isset($data['ads'][$id]['show-tag'])) { $data['ads'][$id]['show-tag'] = ''; } } } static function advman_3_4_14(&$data) { // Add the 'enable php' setting if (!isset($data['settings']['enable-php'])) { $data['settings']['enable-php'] = false; } // Add the 'enable stats' setting if (!isset($data['settings']['stats'])) { $data['settings']['stats'] = true; } // Add the 'purge stats' setting if (!isset($data['settings']['enable-php'])) { $data['settings']['purge-stats-days'] = 30; } // Initialise the stats array $data['stats'] = array(); } static function advman_3_4_12(&$data) { // Set the category to be 'all' (by making it = '') foreach ($data['ads'] as $id => $ad) { if (!isset($data['ads'][$id]['show-category'])) { $data['ads'][$id]['show-category'] = ''; } } } static function advman_3_4_9(&$data) { // If all authors are selected, make the value '' (which means all), so that when new users are added, they will be included. $users = get_users_of_blog(); foreach ($data['ads'] as $id => $ad) { if (is_array($ad['show-author'])) { $all = true; foreach ($users as $user) { if (!in_array($user->user_id, $ad['show-author'])) { $all = false; break; } } if ($all) { $data['ads'][$id]['show-author'] = ''; } } } } static function advman_3_4_7(&$data) { // Account ID for adsense did not get saved correctly. See if we can grab it and save it correctly if (isset($data['networks']['ox_plugin_adsense']['account-id'])) { $accountId = $data['networks']['ox_plugin_adsense']['account-id']; if (is_numeric($accountId)) { $accountId = 'pub-' . $accountId; $data['networks']['ox_plugin_adsense']['account-id'] = $accountId; } foreach ($data['ads'] as $id => $ad) { if ($ad['class'] = 'ox_plugin_adsense' && empty($ad['account-id'])) { $data['ads'][$id]['account-id'] = $accountId; } } } } static function advman_3_4_3(&$data) { // for some reason our meta boxes were hidden - remove this from database $us = get_users_of_blog(); foreach ($us as $u) { delete_usermeta($u->user_id, 'meta-box-hidden_advman'); } } static function advman_3_4_2(&$data) { // Combine all show-* stuff into a single variable // Also remove the default values for the show-* stuff $types = array('page', 'post', 'home', 'search', 'archive'); // Authors $users = array(); $us = get_users_of_blog(); foreach ($us as $u) { $users[] = $u->user_id; } foreach ($data['ads'] as $id => $ad) { $pageTypes = array(); foreach ($types as $type) { if ($ad['show-' . $type] == 'yes') { $pageTypes[] = $type; } elseif (empty($ad['show-' . $type])) { $nw = $data['networks'][$ad['class']]; if ($nw['show-' . $type] == 'yes') { $pageTypes[] = $type; } } unset($data['ads'][$id]['show-' . $type]); } $data['ads'][$id]['show-pagetype'] = $pageTypes; if (!empty($ad['show-author'])) { if (!is_array($ad['show-author'])) { $data['ads'][$id]['show-author'] = $data['ads'][$id]['author'] == 'all' ? $users : array($data['ads'][$id]['author']); } } else { $nw = $data['networks'][$ad['class']]; if (!empty($nw['show-author'])) { if (is_array($nw['show-author'])) { $data['ads'][$id]['show-author'] = $nw['show-author']; } elseif ($nw['show-author'] == 'all') { $data['ads'][$id]['show-author'] = $users; } else { $data['ads'][$id]['show-author'] = array($nw['show-author']); } } } } foreach ($data['networks'] as $c => $nw) { foreach ($types as $type) { unset($data['networks'][$c]['show-' . $type]); } unset($data['networks'][$c]['show-author']); } } static function advman_3_4(&$data) { // Move the where last-sync is stored if (isset($data['last-sync'])) { $data['settings']['last-sync'] = $data['last-sync']; unset($data['last-sync']); } // Move the 'slot' and 'ad' adtypes to 'all' foreach ($data['ads'] as $id => $ad) { if (isset($ad['adtype'])) { $v = $ad['adtype']; if ($v == 'slot' || $v == 'ad') { $data['ads'][$id]['adtype'] = 'all'; } } } // Make sure the class name key is lower case (php4 is case insensitive) $nw = array(); foreach ($data['networks'] as $k => $v) { $nw[strtolower($k)] = $v; } $data['networks'] = $nw; } static function _get_version(&$data) { $version = $data['settings']['version']; if (empty($version)) { $version = $data['version']; if ($version == 'ADVMAN_VERSION') { $version = '3.3.4'; } unset ($data['version']); $data['settings']['version'] = $version; } return $version; } static function _backup($data, $version) { // Backup the last 4 versions of plugin_advman. // remove the oldest version delete_option('plugin_advamn_backup_3'); // move pos 2 to pos 3 $backup = get_option('plugin_advman_backup_2'); if (!empty($backup)) { update_option('plugin_advman_backup_3', $backup); } // move pos 1 to pos 2 $backup = get_option('plugin_advman_backup_1'); if (!empty($backup)) { update_option('plugin_advman_backup_2', $backup); } // move latest to pos 1 $backup = get_option('plugin_advman_backup_0'); if (!empty($backup)) { update_option('plugin_advman_backup_1', $backup); } // insert current into latest update_option('plugin_advman_backup_0', $data); } static function _get_code(&$ad) { $code = ''; switch (strtolower($ad['class'])) { case 'ox_plugin_adbrite' : $code = Advman_Upgrade::_get_code_adbrite($ad); break; case 'ox_plugin_adgridwork' : $code = Advman_Upgrade::_get_code_adgridwork($ad); break; case 'ox_plugin_adpinion' : $code = Advman_Upgrade::_get_code_adpinion($ad); break; case 'ox_plugin_adroll' : $code = Advman_Upgrade::_get_code_adroll($ad); break; case 'ox_plugin_adsense' : $code = Advman_Upgrade::_get_code_adsense($ad); break; case 'ox_plugin_cj' : $code = Advman_Upgrade::_get_code_cj($ad); break; case 'ox_plugin_crispads' : $code = Advman_Upgrade::_get_code_crispads($ad); break; case 'ox_plugin_openx' : $code = Advman_Upgrade::_get_code_openx($ad); break; case 'ox_plugin_shoppingads' : $code = Advman_Upgrade::_get_code_shoppingads($ad); break; case 'ox_plugin_widgetbucks' : $code = Advman_Upgrade::_get_code_widgetbucks($ad); break; case 'ox_plugin_ypn' : $code = Advman_Upgrade::_get_code_ypn($ad); break; } if (!empty($code)) { $oAd = new $ad['class']; $oAd->import_settings($code); foreach ($oAd->p as $property => $value) { $ad[$property] = $value; } } } static function _get_code_adsense($ad) { $code = '' . "\n"; $code.= '' . "\n"; return $code; } static function _get_code_adbrite($ad) { $code =''; $code .= '' . "\n"; $code .= ''; $code .= '
Your Ad Here
'; $code .= ''; return $code; } static function _get_code_adgridwork($ad) { $code ='Free Advertising'; $code.=''; return $code; } static function _get_code_adpinion($ad) { if($ad['width']>$ad['height']){$xwidth=18;$xheight=17;} else {$xwidth=0;$xheight=35;} $code =''; $code .= ''; return $code; } static function _get_code_adroll($ad) { $code =''; $code .= ''; $code .= ''; $code .= ''; $code .= ''; return $code; } static function _get_code_adsense_ad($ad) { $code=''; $code .= '' . "\n"; $code.= '' . "\n"; return $code; } static function _get_code_adsense_link($ad) { $code=''; $code .= '' . "\n"; $code.= '' . "\n"; return $code; } static function _get_code_adsense_referral($ad) { //if($ad===false){$ad=$_advman['ads'][$_advman['default_ad']];} //$ad=advman::merge_defaults($ad); //Apply defaults if($ad['product']=='referral-image') { $format = $ad['adformat'] . '_as_rimg'; } else if($ad['product']=='referral-text') { $format = 'ref_text'; } $code=''; $code .= '' . "\n"; $code.= '' . "\n"; return $code; } static function _get_code_cj($ad) { $cjservers=array( 'www.kqzyfj.com', 'www.tkqlhce.com', 'www.jdoqocy.com', 'www.dpbolvw.net', 'www.lduhtrp.net'); $code = ''; $code .= ''; $code .= '<\/scr"+"ipt>");' . "\n"; $code.='//]]>-->'; } else { //Iframe $code=''; $code.=''; } return $code; } static function _get_code_shoppingads($ad) { $code = ' ' . "\n"; return $code; } static function _get_code_widgetbucks($ad) { global $_advman; $code =''; $code .= '
'; $code .= ''; $code .= '
'; return $code; } static function _get_code_ypn($ad) { $code = ''; $code .= ''; return $code; } } ?>