function init_admin() { global $_adsensem; add_action('admin_head', array('adsensem_admin', 'add_header_script')); add_action('admin_footer', array('adsensem_admin', 'admin_callback_editor')); wp_enqueue_script('prototype'); wp_enqueue_script('postbox'); add_submenu_page('edit.php', "Ad Units", "Ad Units", 10, "adsense-manager-manage-ads", array('adsensem_admin', 'admin_manage')); add_options_page("AdSense Manager Options", "AdSense Manager", 10, "adsense-manager-options", array('adsensem_admin', 'admin_options')); add_action('admin_notices', array('adsensem_admin', 'admin_notices'), 1); if (adsensem::setup_is_valid() == false) { //No startup data found, fill it out now. /* Wipe basic data */ $_adsensem['ads'] = array(); //'demo-adroll' => new Ad_ShoppingAds, $_adsensem['defaults'] = array(); $_adsensem['account-ids'] = array(); $_adsensem['default-ad'] == ''; $_adsensem['be-nice'] = ADSENSEM_BE_NICE; $_adsensem['version'] = ADSENSEM_VERSION; $deluxe = get_option('acmetech_adsensedeluxe'); if (is_array($deluxe)) { adsensem_admin::add_notice('upgrade adsense-deluxe', 'AdSense Manager has detected a previous installation of <strong>AdSense Deluxe</strong>. Import settings?', 'yn'); } $update_adsensem = true; } else { if (adsensem_admin::version_upgrade($_adsensem['version'], ADSENSEM_VERSION)) { require 'class-upgrade.php'; //Backup cycle $backup = get_option('plugin_adsensem_backup'); $backup[adsensem_admin::major_version($_adsensem['version'])] = $_adsensem; update_option('plugin_adsensem_backup', $backup); unset($backup); adsensem_upgrade::go(); $update_adsensem = true; } } if ($update_adsensem) { update_option('plugin_adsensem', $_adsensem); } }
/* REVERT TO PREVIOUS BACKUP OF AD DATABASE */ if ($_REQUEST['adsensem-revert-db']) { $backup = get_option('plugin_adsensem_backup'); $_adsensem = $backup[$_REQUEST['adsensem-revert-db']]; update_option('plugin_adsensem', $_adsensem); if ($_REQUEST['adsensem-block-upgrade']) { die; } } /* END REVERT TO PREVIOUS BACKUP OF AD DATABASE */ /* PRE-OUTPUT PROCESSING - e.g. NOTICEs (upgrade-adsense-deluxe) */ switch ($_POST['adsensem-mode'] . ':' . $_POST['adsensem-action']) { case 'notice:upgrade adsense-deluxe': if ($_POST['adsensem-notice-confirm-yes']) { require_once 'class-upgrade.php'; adsensem_upgrade::adsense_deluxe_to_3_0(); adsensem_admin::remove_notice('upgrade adsense-deluxe'); } else { adsensem_admin::remove_notice('upgrade adsense-deluxe'); } break; case 'notice:upgrade adsense-manager': adsensem_admin::remove_notice('upgrade adsense-manager'); break; case 'notice:activate adsense-manager': adsensem_admin::remove_notice('activate adsense-manager'); break; } /* END PRE-OUTPUT PROCESSING */ } /* SIDEBAR MODULES COMPATIBILITY FUNCTION */
function v2_x_to_3_0() { global $_adsensem; $old = $_adsensem; /* VERSION 3.x */ $_adsensem['ads'] = array(); $_adsensem['be-nice'] = $old['benice']; $_adsensem['default-ad'] = $old['defaults']['ad']; $_adsensem['defaults'] = array(); $_adsensem['defaults']['ad_adsense_classic'] = adsensem_upgrade::_process_v2_x_to_3_0($old['defaults']); $_adsensem['defaults']['ad_adsense'] = $_adsensem['defaults']['ad_adsense_classic']; /* Copy AdSense account-id to both class/new settings */ $_adsensem['account-ids']['ad_adsense'] = $old['adsense-account']; /* Now all that remains is to convert the ads. In 2.x ads were stored as simply arrays containing the options. To upgrade create new objects using product/slot/etc. info, or for code units run an import cycle. */ if (is_array($old['ads'])) { foreach ($old['ads'] as $oname => $oad) { if ($oad['slot'] != '') { $type = 'slot'; } else { $type = $oad['product']; } $name = adsensem_admin::validate_name($oname); switch ($type) { /* HTML Code Ads */ case 'code': $ad = adsensem_admin::import_ad($oad['code']); $_adsensem['ads'][$name] = $ad; $_adsensem['ads'][$name]->name = $name; break; /* AdSense Slot Ads */ /* AdSense Slot Ads */ case 'slot': $ad = new Ad_AdSense(); $_adsensem['ads'][$name] = $ad; $_adsensem['ads'][$name]->name = $name; $_adsensem['ads'][$name]->p = adsensem_upgrade::_process_v2_x_to_3_0($oad); break; /* AdSense Ad */ /* AdSense Ad */ case 'ad': $ad = new Ad_AdSense_Ad(); $_adsensem['ads'][$name] = $ad; $_adsensem['ads'][$name]->name = $name; $_adsensem['ads'][$name]->p = adsensem_upgrade::_process_v2_x_to_3_0($oad); break; case 'link': $ad = new Ad_AdSense_Link(); $_adsensem['ads'][$name] = $ad; $_adsensem['ads'][$name]->name = $name; $_adsensem['ads'][$name]->p = adsensem_upgrade::_process_v2_x_to_3_0($oad); break; case 'referral': case 'referral-image': case 'referral-text': $ad = new Ad_AdSense_Referral(); $_adsensem['ads'][$name] = $ad; $_adsensem['ads'][$name]->name = $name; $_adsensem['ads'][$name]->p = adsensem_upgrade::_process_v2_x_to_3_0($oad); break; } } } $_adsensem['ads'] = adsensem_admin::sort_ads_by_network($_adsensem['ads']); }