/**
  * Import process
  *
  *
  */
 function adminImportProcess()
 {
     global $wpdb;
     if (isset($_REQUEST['add'])) {
         if (!isset($_REQUEST['feed'])) {
             $add_error = __('You must select at least one feed', 'wpomatic');
         } else {
             switch ($_REQUEST['import_mode']) {
                 // Several campaigns
                 case '1':
                     $created_campaigns = array();
                     foreach ($_REQUEST['feed'] as $campaignid => $feeds) {
                         if (!in_array($campaignid, $created_campaigns)) {
                             // Create campaign
                             $title = $_REQUEST['campaign'][$campaignid];
                             if (!$title) {
                                 continue;
                             }
                             $slug = WPOTools::stripText($title);
                             $wpdb->query("INSERT INTO {$this->db['campaign']} (title, active, slug, lastactive, count) VALUES ('{$title}', 1, '{$slug}', 0, 0) ");
                             $created_campaigns[] = $wpdb->insert_id;
                             // Add feeds
                             foreach ($feeds as $feedurl => $yes) {
                                 $this->addCampaignFeed($campaignid, urldecode($feedurl));
                             }
                         }
                     }
                     $this->add_success = __('Campaigns added successfully. Feel free to edit them', 'wpomatic');
                     break;
                     // All feeds into an existing campaign
                 // All feeds into an existing campaign
                 case '2':
                     $campaignid = $_REQUEST['import_custom_campaign'];
                     foreach ($_REQUEST['feed'] as $cid => $feeds) {
                         // Add feeds
                         foreach ($feeds as $feedurl => $yes) {
                             $this->addCampaignFeed($campaignid, urldecode($feedurl));
                         }
                     }
                     $this->add_success = sprintf(__('Feeds added successfully. <a href="%s">Edit campaign</a>', 'wpomatic'), $this->adminurl . '&s=edit&id=' . $campaignid);
                     break;
                     // All feeds into new campaign
                 // All feeds into new campaign
                 case '3':
                     $title = $_REQUEST['import_new_campaign'];
                     $slug = WPOTools::stripText($title);
                     $wpdb->query("INSERT INTO {$this->db['campaign']} (title, active, slug, lastactive, count) VALUES ('{$title}', 0, '{$slug}', 0, 0) ");
                     $campaignid = $wpdb->insert_id;
                     // Add feeds
                     foreach ($_REQUEST['feed'] as $cid => $feeds) {
                         // Add feeds
                         foreach ($feeds as $feedurl => $yes) {
                             $this->addCampaignFeed($campaignid, urldecode($feedurl));
                         }
                     }
                     $this->add_success = sprintf(__('Feeds added successfully. <a href="%s">Edit campaign</a>', 'wpomatic'), $this->adminurl . '&s=edit&id=' . $campaignid);
                     break;
                     // insert into existing campaign and use this category
                 // insert into existing campaign and use this category
                 case '4':
                     foreach ($_REQUEST['feed'] as $count => $feeds) {
                         $acampid = $_REQUEST['use_this_campaign-' . $count];
                         $cid = $wpdb->get_row($wpdb->prepare('SELECT id FROM ' . $this->db['campaign'] . ' WHERE id=%d', $acampid));
                         if ($cid > 0) {
                             echo "I'll use this one: {$cid->id}<br />";
                             $campaignid = $cid->id;
                         } else {
                             echo "I'll make a new one <br />";
                             $title = $_REQUEST['campaign'][$count];
                             $slug = WPOTools::stripText($title);
                             $wpdb->query("INSERT INTO {$this->db['campaign']} (title, active, slug, lastactive, count) VALUES ('{$title}', 1, '{$slug}', 0, 0) ");
                             $campaignid = $wpdb->insert_id;
                         }
                         $cat_id = isset($_REQUEST['cat'][$count]) ? $_REQUEST['cat'][$count] : 0;
                         if ($cat_id > 1) {
                             $wpdb->insert($this->db['campaign_category'], array('category_id' => $cat_id, 'campaign_id' => $campaignid), array('%d', '%d'));
                         }
                         // Add feeds
                         foreach ($feeds as $feedurl => $yes) {
                             $this->addCampaignFeed($campaignid, urldecode($feedurl));
                         }
                     }
                     echo 'done';
                     echo '<pre>';
                     print_r($_REQUEST);
                     echo '</pre>';
                     break;
             }
         }
     }
 }
Example #2
0
 /**
  * Import process
  *
  *
  */
 function adminImportProcess()
 {
     global $wpdb;
     if (isset($_REQUEST['add'])) {
         if (!isset($_REQUEST['feed'])) {
             $add_error = __('You must select at least one feed', 'wpomatic');
         } else {
             switch ($_REQUEST['import_mode']) {
                 // Several campaigns
                 case '1':
                     $created_campaigns = array();
                     foreach ($_REQUEST['feed'] as $campaignid => $feeds) {
                         if (!in_array($campaignid, $created_campaigns)) {
                             // Create campaign
                             $title = $_REQUEST['campaign'][$campaignid];
                             if (!$title) {
                                 continue;
                             }
                             $slug = WPOTools::stripText($title);
                             $wpdb->query("INSERT INTO {$this->db['campaign']} (title, active, slug, lastactive, count) VALUES ('{$title}', 0, '{$slug}', 0, 0) ");
                             $created_campaigns[] = $wpdb->insert_id;
                             // Add feeds
                             foreach ($feeds as $feedurl => $yes) {
                                 $this->addCampaignFeed($campaignid, urldecode($feedurl));
                             }
                         }
                     }
                     $this->add_success = __('Campaigns added successfully. Feel free to edit them', 'wpomatic');
                     break;
                     // All feeds into an existing campaign
                 // All feeds into an existing campaign
                 case '2':
                     $campaignid = $_REQUEST['import_custom_campaign'];
                     foreach ($_REQUEST['feed'] as $cid => $feeds) {
                         // Add feeds
                         foreach ($feeds as $feedurl => $yes) {
                             $this->addCampaignFeed($campaignid, urldecode($feedurl));
                         }
                     }
                     $this->add_success = sprintf(__('Feeds added successfully. <a href="%s">Edit campaign</a>', 'wpomatic'), $this->adminurl . '&s=edit&id=' . $campaignid);
                     break;
                     // All feeds into new campaign
                 // All feeds into new campaign
                 case '3':
                     $title = $_REQUEST['import_new_campaign'];
                     $slug = WPOTools::stripText($title);
                     $wpdb->query("INSERT INTO {$this->db['campaign']} (title, active, slug, lastactive, count) VALUES ('{$title}', 0, '{$slug}', 0, 0) ");
                     $campaignid = $wpdb->insert_id;
                     // Add feeds
                     foreach ($_REQUEST['feed'] as $cid => $feeds) {
                         // Add feeds
                         foreach ($feeds as $feedurl => $yes) {
                             $this->addCampaignFeed($campaignid, urldecode($feedurl));
                         }
                     }
                     $this->add_success = sprintf(__('Feeds added successfully. <a href="%s">Edit campaign</a>', 'wpomatic'), $this->adminurl . '&s=edit&id=' . $campaignid);
                     break;
             }
         }
     }
 }