Exemplo n.º 1
0
 /**
  * Process input from the Admin UI.  Called staticly from the Wordpress form screen.
  */
 function process()
 {
     global $advman_engine;
     $filter = null;
     $mode = OX_Tools::sanitize_post_var('advman-mode');
     $action = OX_Tools::sanitize_post_var('advman-action');
     $target = OX_Tools::sanitize_post_var('advman-target');
     $targets = OX_Tools::sanitize_post_var('advman-targets');
     // For operations on a single ad
     if (is_numeric($target)) {
         $id = intval($target);
         $ad = $advman_engine->getAd($id);
     }
     // For operations on multiple ads
     if (is_array($targets)) {
         $ids = array();
         $ads = array();
         foreach ($targets as $target) {
             $i = intval($target);
             $ids[] = $i;
             $ads[] = $advman_engine->getAd($i);
         }
     }
     switch ($action) {
         case 'activate':
             if (!$ad->active) {
                 $ad->active = true;
                 $advman_engine->setAd($ad);
             }
             break;
         case 'clear':
             break;
         case 'copy':
             if (!empty($ad)) {
                 $ad = $advman_engine->copyAd($ad->id);
             }
             if (!empty($ads)) {
                 foreach ($ads as $ad) {
                     $advman_engine->copyAd($ad->id);
                 }
             }
             break;
         case 'deactivate':
             if ($ad->active) {
                 $ad->active = false;
                 $advman_engine->setAd($ad);
             }
             break;
         case 'default':
             $default = $advman_engine->getSetting('default-ad') != $ad->name ? $ad->name : '';
             $advman_engine->setSetting('default-ad', $default);
             break;
         case 'delete':
             if (!empty($ad)) {
                 $ad = $advman_engine->deleteAd($ad->id);
             }
             if (!empty($ads)) {
                 foreach ($ads as $ad) {
                     $advman_engine->deleteAd($ad->id);
                 }
             }
             $ads = $advman_engine->getAds();
             $mode = !empty($ads) ? 'list_ads' : 'create_ad';
             break;
         case 'edit':
             $mode = !empty($id) ? 'edit_ad' : 'edit_network';
             break;
         case 'filter':
             $filter_active = OX_Tools::sanitize_post_var('advman-filter-active');
             $filter_network = OX_Tools::sanitize_post_var('advman-filter-network');
             if (!empty($filter_active)) {
                 $filter['active'] = $filter_active;
             }
             if (!empty($filter_network)) {
                 $filter['network'] = $filter_network;
             }
             break;
         case 'import':
             $tag = OX_Tools::sanitize($_POST['advman-code']);
             $ad = $advman_engine->importAdTag($tag);
             $mode = 'edit_ad';
             break;
         case 'list':
             $mode = 'list_ads';
             break;
         case 'reset':
             $mode = 'edit_network';
             $ad = $advman_engine->factory($target);
             if ($ad) {
                 $ad->reset_network_properties();
                 $advman_engine->setAdNetwork($ad);
             }
             break;
         case 'apply':
         case 'save':
             if ($mode == 'edit_ad') {
                 if (Advman_Admin::save_properties($ad)) {
                     $advman_engine->setAd($ad);
                 }
             } elseif ($mode == 'edit_network') {
                 $ad = $advman_engine->factory($target);
                 if ($ad) {
                     if (Advman_Admin::save_properties($ad, true)) {
                         $advman_engine->setAdNetwork($ad);
                     }
                 }
             } elseif ($mode == 'settings') {
                 Advman_Admin::save_settings();
             }
             if ($action == 'save' && $mode != 'settings') {
                 $mode = 'list_ads';
             }
             break;
         case 'settings':
             $mode = 'settings';
             break;
         case 'cancel':
         default:
             $ads = $advman_engine->getAds();
             $mode = !empty($ads) ? 'list_ads' : 'create_ad';
             break;
     }
     $template = null;
     switch ($mode) {
         case 'create_ad':
             $template = Advman_Tools::get_template('Create');
             $template->display();
             break;
         case 'edit_ad':
             $template = Advman_Tools::get_template('Edit_Ad', $ad);
             $template->display($ad);
             break;
         case 'edit_network':
             $ad = $advman_engine->factory($target);
             if ($ad) {
                 $template = Advman_Tools::get_template('Edit_Network', $ad);
                 $template->display($ad);
             }
             break;
         case 'settings':
             $template = Advman_Tools::get_template('Settings');
             $template->display();
             break;
         case 'list_ads':
         default:
             $template = Advman_Tools::get_template('List');
             $template->display();
             break;
     }
     if (is_null($template)) {
         $template = Advman_Tools::get_template('List');
         $template->display();
     }
 }
Exemplo n.º 2
0
 static function ad_action($action, $ad = null)
 {
     global $advman_engine;
     //wp_die("action1:$action");
     if (!$ad) {
         $ad = Advman_Tools::get_current_ad();
     }
     if ($ad) {
         switch ($action) {
             case 'apply':
                 if (Advman_Admin::save_properties($ad)) {
                     $advman_engine->setAd($ad);
                     Advman_Admin::add_notice('advman-notice-once', __("Ad updated"), false);
                 }
                 break;
             case 'activate':
                 if (!$ad->active) {
                     $ad->active = true;
                     $advman_engine->setAd($ad);
                     Advman_Admin::add_notice('advman-notice-once', __("Ad activated"), false);
                 }
                 break;
             case 'cancel':
                 wp_redirect(admin_url('admin.php?page=advman-list'));
                 exit;
             case 'copy':
                 $ad_new = $advman_engine->copyAd($ad->id);
                 Advman_Admin::add_notice('advman-notice-once', __("Ad copied. <a href='admin.php?page=advman-ad&ad={$ad->id}'>View original</a>"), false);
                 wp_redirect(admin_url('admin.php?page=advman-ad&ad=' . $ad_new->id));
                 break;
             case 'deactivate':
                 if ($ad->active) {
                     $ad->active = false;
                     $advman_engine->setAd($ad);
                     Advman_Admin::add_notice('advman-notice-once', __("Ad deactivated"), false);
                 }
                 break;
             case 'default':
                 $default = $advman_engine->getSetting('default-ad') != $ad->name ? $ad->name : '';
                 $advman_engine->setSetting('default-ad', $default);
                 $msg = $default ? __('Ad is now default') : __('Ad is no longer default');
                 Advman_Admin::add_notice('advman-notice-once', $msg, false);
                 break;
             case 'delete':
                 $advman_engine->deleteAd($ad->id);
                 Advman_Admin::add_notice('advman-notice-once', __("Ad deleted"), false);
                 wp_redirect(admin_url('admin.php?page=advman-list'));
                 break;
             case 'edit-network':
                 wp_redirect(admin_url('admin.php?page=advman-network&network=' . strtolower(get_class($ad))));
                 exit;
             case 'edit':
                 wp_redirect(admin_url('admin.php?page=advman-ad&ad=' . $ad->id));
                 exit;
             case 'filter':
                 $filter_active = OX_Tools::sanitize_post_var('advman-filter-active');
                 $filter_network = OX_Tools::sanitize_post_var('advman-filter-network');
                 if (!empty($filter_active)) {
                     $filter['active'] = $filter_active;
                 }
                 if (!empty($filter_network)) {
                     $filter['network'] = $filter_network;
                 }
                 break;
             case 'save':
                 if (Advman_Admin::save_properties($ad)) {
                     $advman_engine->setAd($ad);
                     Advman_Admin::add_notice('advman-notice-once', __("Ad updated. <a href='admin.php?page=advman-ad&ad={$ad->id}'>View ad</a>"), false);
                 }
                 wp_redirect(admin_url('admin.php?page=advman-list'));
                 exit;
         }
     }
 }