Ejemplo n.º 1
0
 function test_csv()
 {
     $desired_outputs = array(6, 5);
     $log = array();
     $options = array("opt_min_backlinks" => 1);
     $csvParser = new CSVParser($log, $options);
     foreach ($this->test_files as $key => $file) {
         $_FILES['ebn_import']['tmp_name'] = $file;
         $posts = $csvParser->parseUploadedMajesticFile();
         $this->assertEquals($desired_outputs[$key], count($posts));
     }
 }
Ejemplo n.º 2
0
 /**
  *
  * Handle POST submission
  *
  * @param array $options
  *
  * @return void
  *
  */
 private function handleUploadedData($options)
 {
     // Check if we have the correct nonce value for the form, else ignore the whole request
     if (!wp_verify_nonce($_POST['ebn_nonce'], 'majestic_importer_nonce')) {
         $this->log['error'][] = 'Authentication failed. Please refresh the page and try again.';
         $this->showLog();
         return;
     }
     if (empty($_FILES['ebn_import']['tmp_name'])) {
         $this->log['error'][] = 'No file uploaded, aborting.';
         $this->showLog();
         return;
     }
     if (!current_user_can('publish_pages')) {
         $this->log['error'][] = 'You don\'t have the permissions to publish pages. Please contact the blog\'s administrator.';
         $this->showLog();
         return;
     }
     $time_start = microtime(true);
     $csvParser = new CSVParser($this->log, $options);
     $imported_posts = $csvParser->parseUploadedMajesticFile();
     $imported = 0;
     foreach ($imported_posts as $post) {
         $id = $this->create_post($post, $options, get_home_url());
         if ($id) {
             $imported++;
         }
     }
     $exec_time = microtime(true) - $time_start;
     $this->log['notice'][] = sprintf("<b>Imported {$imported} pages in %.2f seconds.</b>", $exec_time);
     $this->showLog();
 }