Plugin Directory

Changeset 2749264


Ignore:
Timestamp:
06/28/2022 07:01:32 PM (4 years ago)
Author:
soflyy
Message:

Release 3.6.8 version

Location:
wp-all-import
Files:
636 added
3 edited

Legend:

Unmodified
Added
Removed
  • wp-all-import/trunk/classes/upload.php

    r2633722 r2749264  
    99        protected $is_csv = false;
    1010
    11         protected $uploadsPath;             
     11        protected $uploadsPath;
    1212
    1313        function __construct( $file,  $errors, $targetDir = false ){
     
    4444            $this->file = wp_all_import_get_absolute_path($this->file);
    4545
    46             $templates = false;     
    47 
    48             $bundle = array(); 
     46            $templates = false;
     47
     48            $bundle = array();
    4949
    5050            $bundleFiles = array();
     
    5353
    5454            if (empty($this->file)) {
    55                 $this->errors->add('form-validation', __('Please specify a file to import.<br/><br/>If you are uploading the file from your computer, please wait for it to finish uploading (progress bar at 100%), before trying to continue.', 'wp_all_import_plugin'));             
     55                $this->errors->add('form-validation', __('Please specify a file to import.<br/><br/>If you are uploading the file from your computer, please wait for it to finish uploading (progress bar at 100%), before trying to continue.', 'wp_all_import_plugin'));
    5656            } elseif (!is_file($this->file)) {
    5757                $this->errors->add('form-validation', __('Uploaded file is empty', 'wp_all_import_plugin'));
     
    5959                $this->errors->add('form-validation', __('Uploaded file must be XML, CSV, ZIP, GZIP, GZ, JSON, SQL, TXT, DAT or PSV', 'wp_all_import_plugin'));
    6060            } elseif (preg_match('%\W(zip)$%i', trim(basename($this->file)))) {
    61                                        
     61
    6262                if (!class_exists('PclZip')) {
    6363                    require_once ABSPATH . 'wp-admin/includes/class-pclzip.php';
     
    7272                    if ( ! empty($v_result_list) ) {
    7373                        foreach ($v_result_list as $unzipped_file) {
     74                            if ($unzipped_file['status'] == 'ok' and preg_match('%\W(php)$%i', trim($unzipped_file['stored_filename']))) {
     75                                unlink($unzipped_file['filename']);
     76                                continue;
     77                            }
    7478                            if ($unzipped_file['status'] == 'ok' and preg_match('%\W(xml|csv|txt|dat|psv|json|xls|xlsx|gz)$%i', trim($unzipped_file['stored_filename'])) and strpos($unzipped_file['stored_filename'], 'readme.txt') === false ) {
    7579                                if ( strpos(basename($unzipped_file['stored_filename']), 'WP All Import Template') === 0 || strpos(basename($unzipped_file['stored_filename']), 'templates_') === 0 ) {
     
    8084                                        $options = maybe_unserialize($templateOptions[0]['options']);
    8185                                        return array(
    82                                             'filePath' => $templateOptions[0]['_import_url'],                                                                                                                                   
     86                                            'filePath' => $templateOptions[0]['_import_url'],
    8387                                            'bundle' => $bundle,
    84                                             'template' => json_encode($templateOptions),           
    85                                             'templates' => $templates,                             
     88                                            'template' => json_encode($templateOptions),
     89                                            'templates' => $templates,
    8690                                            'post_type' => (!empty($options)) ? $options['custom_type'] : false,
    8791                                            'taxonomy_type' => (!empty($options['taxonomy_type'])) ? $options['taxonomy_type'] : false,
     
    9195                                } else {
    9296                                    if ($filePath == '') {
    93                                         $filePath = $unzipped_file['filename'];                                 
     97                                        $filePath = $unzipped_file['filename'];
    9498                                    }
    9599                                    if ( ! in_array($unzipped_file['filename'], $bundleFiles) ) {
     
    109113                        }
    110114                        if ( ! empty($bundle)) $filePath = current($bundle);
    111                     }                                       
     115                    }
    112116
    113117                    if ( $this->uploadsPath === false ){
     
    117121                    if (empty($filePath)) {
    118122                        $zip = zip_open(trim($this->file));
    119                         if (is_resource($zip)) {                                                       
     123                        if (is_resource($zip)) {
    120124                            while ($zip_entry = zip_read($zip)) {
    121                                 $filePath = zip_entry_name($zip_entry);                                             
    122                                 $fp = fopen($this->uploadsPath."/".$filePath, "w");
    123                                 if (zip_entry_open($zip, $zip_entry, "r")) {
    124                                   $buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
    125                                   fwrite($fp,"$buf");
    126                                   zip_entry_close($zip_entry);
    127                                   fclose($fp);
    128                                 }
    129                                 break;
     125                                $filePath = zip_entry_name($zip_entry);
     126                                if (preg_match('%\W(xml|csv|txt|dat|psv|json|xls|xlsx|gz)$%i', trim($filePath))) {
     127                                    $fp = fopen($this->uploadsPath."/".$filePath, "w");
     128                                    if (zip_entry_open($zip, $zip_entry, "r")) {
     129                                        $buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
     130                                        fwrite($fp,"$buf");
     131                                        zip_entry_close($zip_entry);
     132                                        fclose($fp);
     133                                    }
     134                                    break;
     135                                }
    130136                            }
    131137                            zip_close($zip);
    132138                        } else {
    133                             $this->errors->add('form-validation', __('WP All Import couldn\'t find a file to import inside your ZIP.<br/><br/>Either the .ZIP file is broken, or doesn\'t contain a file with an extension of  XML, CSV, PSV, DAT, or TXT. <br/>Please attempt to unzip your .ZIP file on your computer to ensure it is a valid .ZIP file which can actually be unzipped, and that it contains a file which WP All Import can import.', 'wp_all_import_plugin'));       
    134                         }                       
    135                     }
    136                     // Detect if file is very large                 
     139                            $this->errors->add('form-validation', __('WP All Import couldn\'t find a file to import inside your ZIP.<br/><br/>Either the .ZIP file is broken, or doesn\'t contain a file with an extension of  XML, CSV, PSV, DAT, or TXT. <br/>Please attempt to unzip your .ZIP file on your computer to ensure it is a valid .ZIP file which can actually be unzipped, and that it contains a file which WP All Import can import.', 'wp_all_import_plugin'));
     140                        }
     141                    }
     142                    // Detect if file is very large
    137143                    $source = array(
    138144                        'name' => basename($this->file),
    139                         'type' => 'upload',                         
    140                         'path' => $this->file,                 
     145                        'type' => 'upload',
     146                        'path' => $this->file,
    141147                    );
    142148                    $fileFormats = $this->get_xml_file( $filePath );
     
    145151                }
    146152            } elseif ( preg_match('%\W(csv|txt|dat|psv|tsv)$%i', trim($this->file))) { // If CSV file uploaded
    147                    
     153
    148154                if ( $this->uploadsPath === false ){
    149155                     $this->errors->add('form-validation', __('WP All Import can\'t access your WordPress uploads folder.', 'wp_all_import_plugin'));
    150                 }                                   
     156                }
    151157                $filePath = $this->file;
    152158                $source = array(
     
    154160                    'type' => 'upload',
    155161                    'path' => $filePath,
    156                 );                             
    157 
    158                 include_once(PMXI_Plugin::ROOT_DIR.'/libraries/XmlImportCsvParse.php'); 
    159 
    160                 $csv = new PMXI_CsvParser( array( 'filename' => $this->file, 'targetDir' => $this->uploadsPath ) ); 
     162                );
     163
     164                include_once(PMXI_Plugin::ROOT_DIR.'/libraries/XmlImportCsvParse.php');
     165
     166                $csv = new PMXI_CsvParser( array( 'filename' => $this->file, 'targetDir' => $this->uploadsPath ) );
    161167                //@unlink($filePath);
    162168                $csv_path = $filePath;
    163                 $filePath = $csv->xml_path;                             
     169                $filePath = $csv->xml_path;
    164170                $this->is_csv = $csv->is_csv;
    165                 $this->root_element = 'node';               
    166                        
     171                $this->root_element = 'node';
     172
    167173            } elseif(preg_match('%\W(gz)$%i', trim($this->file))){ // If gz file uploaded
    168174                $fileInfo = wp_all_import_get_gz($this->file, 0, $this->uploadsPath);
    169175                if ( ! is_wp_error($fileInfo) ){
    170176                    $filePath = $fileInfo['localPath'];
    171                     // Detect if file is very large             
     177                    // Detect if file is very large
    172178                    $source = array(
    173179                        'name' => basename($this->file),
    174180                        'type' => 'upload',
    175                         'path' => $this->file,                 
     181                        'path' => $this->file,
    176182                    );
    177                     // detect CSV or XML 
    178                     if ( $fileInfo['type'] == 'csv') { // it is CSV file                                   
    179                        
    180                         include_once(PMXI_Plugin::ROOT_DIR.'/libraries/XmlImportCsvParse.php');                 
     183                    // detect CSV or XML
     184                    if ( $fileInfo['type'] == 'csv') { // it is CSV file
     185
     186                        include_once(PMXI_Plugin::ROOT_DIR.'/libraries/XmlImportCsvParse.php');
    181187                        $csv = new PMXI_CsvParser( array( 'filename' => $filePath, 'targeDir' => $this->uploadsPath ) ); // create chunks
    182188                        //@unlink($filePath);
     
    190196            } elseif (preg_match('%\W(json)$%i', trim($this->file))){
    191197
    192                 // Detect if file is very large             
     198                // Detect if file is very large
    193199                $source = array(
    194200                    'name' => basename($this->file),
    195201                    'type' => 'upload',
    196                     'path' => $this->file,                 
     202                    'path' => $this->file,
    197203                );
    198204
     
    200206                $json_str = str_replace("\xEF\xBB\xBF",'', $json_str);
    201207                $is_json = wp_all_import_is_json($json_str);
    202                
     208
    203209                if( is_wp_error($is_json)){
    204210                    $this->errors->add('form-validation', $is_json->get_error_message(), 'wp_all_import_plugin');
     
    206212                    $xml_data = wp_all_import_json_to_xml( json_decode($json_str, true) );
    207213                    if ( empty($xml_data) ){
    208                         $this->errors->add('form-validation', __('Can not import this file. JSON to XML convertation failed.', 'wp_all_import_plugin'));   
     214                        $this->errors->add('form-validation', __('Can not import this file. JSON to XML convertation failed.', 'wp_all_import_plugin'));
    209215                    } else{
    210216                        $jsontmpname = $this->uploadsPath  .'/'. wp_all_import_url_title(wp_unique_filename($this->uploadsPath, str_replace("json", "xml", basename($this->file))));
    211217                        //@unlink($this->file);
    212218                        file_put_contents($jsontmpname, $xml_data);
    213                         $filePath = $jsontmpname;       
    214                        
     219                        $filePath = $jsontmpname;
     220
    215221                    }
    216222                }
     
    219225                    'name' => basename($this->file),
    220226                    'type' => 'upload',
    221                     'path' => $this->file,                 
     227                    'path' => $this->file,
    222228                );
    223229                include_once( PMXI_Plugin::ROOT_DIR . '/libraries/XmlImportSQLParse.php' );
     
    228234                    'name' => basename($this->file),
    229235                    'type' => 'upload',
    230                     'path' => $this->file,                 
     236                    'path' => $this->file,
    231237                );
    232238
     
    241247                    'path' => $filePath,
    242248                );
    243             }           
     249            }
    244250
    245251            if ( $this->errors->get_error_codes() ) return $this->errors;
    246252
    247             $decodedTemplates = empty($templates) ? false : json_decode($templates, true);         
    248 
    249             $source['path'] = wp_all_import_get_relative_path($source['path']);         
    250            
     253            $decodedTemplates = empty($templates) ? false : json_decode($templates, true);
     254
     255            $source['path'] = wp_all_import_get_relative_path($source['path']);
     256
    251257            $templateOptions = "";
    252258
    253259            if ( is_array($decodedTemplates) ) {
    254260                $templateOptions = empty($decodedTemplates[0]) ? current($decodedTemplates) : $decodedTemplates;
    255             }           
    256 
    257             $options = (empty($templateOptions[0]['options'])) ? false : maybe_unserialize($templateOptions[0]['options']);         
     261            }
     262
     263            $options = (empty($templateOptions[0]['options'])) ? false : maybe_unserialize($templateOptions[0]['options']);
    258264
    259265            if ( ! empty($options['root_element'])) $this->root_element = $options['root_element'];
     
    279285            $templates = false;
    280286
    281             $bundle = array(); 
     287            $bundle = array();
    282288
    283289            $bundleFiles = array();
    284290
    285291            if (empty($this->file)) {
    286                 $this->errors->add('form-validation', __('Please specify a file to import.', 'wp_all_import_plugin'));             
     292                $this->errors->add('form-validation', __('Please specify a file to import.', 'wp_all_import_plugin'));
    287293            } elseif ( ! preg_match('%^https?://%i', $this->file)) {
    288                 $this->errors->add('form-validation', __('The URL to your file is not valid.<br/><br/>Please make sure the URL starts with http:// or https://. To import from https://, your server must have OpenSSL installed.'), 'wp_all_import_plugin');               
     294                $this->errors->add('form-validation', __('The URL to your file is not valid.<br/><br/>Please make sure the URL starts with http:// or https://. To import from https://, your server must have OpenSSL installed.'), 'wp_all_import_plugin');
    289295            } elseif( ! is_writeable($this->uploadsPath)){
    290296                $this->errors->add('form-validation', __('Uploads folder '.$this->uploadsPath.' is not writable.'), 'wp_all_import_plugin');
     
    299305                if( '' == $feed_type and ! preg_match('%\W(xml|csv|zip|gz|xls|xlsx)$%i', trim($this->file))) $feed_type = wp_all_import_get_remote_file_name(trim($this->file));
    300306
    301                 if ('zip' == $feed_type or empty($feed_type) and preg_match('%\W(zip)$%i', trim($this->file))) {                           
    302                    
     307                if ('zip' == $feed_type or empty($feed_type) and preg_match('%\W(zip)$%i', trim($this->file))) {
     308
    303309                    $tmpname = $this->uploadsPath . '/' . wp_unique_filename($this->uploadsPath, md5(basename($this->file)) . '.zip');
    304                    
    305                     @copy($this->file, $tmpname);               
    306                    
    307                     if (!file_exists($tmpname)) {                                       
     310
     311                    @copy($this->file, $tmpname);
     312
     313                    if (!file_exists($tmpname)) {
    308314                        $request = get_file_curl($this->file, $tmpname);
    309                         if (is_wp_error($request)) $this->errors->add('form-validation', $request->get_error_message());                       
    310                         if (!file_exists($tmpname)) $this->errors->add('form-validation', __('Failed upload ZIP archive', 'wp_all_import_plugin'));                     
     315                        if (is_wp_error($request)) $this->errors->add('form-validation', $request->get_error_message());
     316                        if (!file_exists($tmpname)) $this->errors->add('form-validation', __('Failed upload ZIP archive', 'wp_all_import_plugin'));
    311317                    }
    312318
     
    322328                        if (!empty($v_result_list)) {
    323329                            foreach ($v_result_list as $unzipped_file) {
     330                                if ($unzipped_file['status'] == 'ok' and preg_match('%\W(php)$%i', trim($unzipped_file['stored_filename']))) {
     331                                    unlink($unzipped_file['filename']);
     332                                    continue;
     333                                }
    324334                                if ($unzipped_file['status'] == 'ok' and preg_match('%\W(xml|csv|txt|dat|psv|json|xls|xlsx|gz)$%i', trim($unzipped_file['stored_filename'])) and strpos($unzipped_file['stored_filename'], 'readme.txt') === false ) {
    325335                                    if ( strpos(basename($unzipped_file['stored_filename']), 'WP All Import Template') === 0 || strpos(basename($unzipped_file['stored_filename']), 'templates_') === 0) {
    326336                                        $templates = file_get_contents($unzipped_file['filename']);
    327337                                        $decodedTemplates = json_decode($templates, true);
    328                                         $templateOptions = empty($decodedTemplates[0]) ? current($decodedTemplates) : $decodedTemplates;           
     338                                        $templateOptions = empty($decodedTemplates[0]) ? current($decodedTemplates) : $decodedTemplates;
    329339                                    }
    330340                                    else {
    331341                                        if ($filePath == '') {
    332                                             $filePath = $unzipped_file['filename'];                                 
     342                                            $filePath = $unzipped_file['filename'];
    333343                                        }
    334344                                        if ( ! in_array($unzipped_file['filename'], $bundleFiles) ) {
    335345                                            $bundleFiles[basename($unzipped_file['filename'])] = $unzipped_file['filename'];
    336                                         }                                       
     346                                        }
    337347                                    }
    338348                                }
     
    348358                            }
    349359                            if ( ! empty($bundle)) $filePath = current($bundle);
    350                         }                       
     360                        }
    351361
    352362                        if($this->uploadsPath === false){
    353363                             $this->errors->add('form-validation', __('WP All Import can\'t access your WordPress uploads folder.', 'wp_all_import_plugin'));
    354                         }                       
    355 
    356                         if(empty($filePath)){                       
     364                        }
     365
     366                        if(empty($filePath)){
    357367                            $zip = zip_open(trim($tmpname));
    358                             if (is_resource($zip)) {                                                       
     368                            if (is_resource($zip)) {
    359369                                while ($zip_entry = zip_read($zip)) {
    360                                     $filePath = zip_entry_name($zip_entry);                                             
    361                                     $fp = fopen($this->uploadsPath."/".$filePath, "w");
    362                                     if (zip_entry_open($zip, $zip_entry, "r")) {
    363                                       $buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
    364                                       fwrite($fp,"$buf");
    365                                       zip_entry_close($zip_entry);
    366                                       fclose($fp);
    367                                     }
    368                                     break;
     370                                    $filePath = zip_entry_name($zip_entry);
     371                                    if (preg_match('%\W(xml|csv|txt|dat|psv|json|xls|xlsx|gz)$%i', trim($filePath))) {
     372                                        $fp = fopen($this->uploadsPath . "/" . $filePath, "w");
     373                                        if (zip_entry_open($zip, $zip_entry, "r")) {
     374                                            $buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
     375                                            fwrite($fp, "$buf");
     376                                            zip_entry_close($zip_entry);
     377                                            fclose($fp);
     378                                        }
     379                                        break;
     380                                    }
    369381                                }
    370382                                zip_close($zip);
    371383                            } else {
    372                                 $this->errors->add('form-validation', __('WP All Import couldn\'t find a file to import inside your ZIP.<br/><br/>Either the .ZIP file is broken, or doesn\'t contain a file with an extension of  XML, CSV, PSV, DAT, or TXT. <br/>Please attempt to unzip your .ZIP file on your computer to ensure it is a valid .ZIP file which can actually be unzipped, and that it contains a file which WP All Import can import.', 'wp_all_import_plugin'));       
    373                             }                       
    374                         }
    375                         // Detect if file is very large                     
     384                                $this->errors->add('form-validation', __('WP All Import couldn\'t find a file to import inside your ZIP.<br/><br/>Either the .ZIP file is broken, or doesn\'t contain a file with an extension of  XML, CSV, PSV, DAT, or TXT. <br/>Please attempt to unzip your .ZIP file on your computer to ensure it is a valid .ZIP file which can actually be unzipped, and that it contains a file which WP All Import can import.', 'wp_all_import_plugin'));
     385                            }
     386                        }
     387                        // Detect if file is very large
    376388                        $source = array(
    377389                            'name' => basename(parse_url($this->file, PHP_URL_PATH)),
    378390                            'type' => 'url',
    379                             'path' => $feed_xpath,                         
     391                            'path' => $feed_xpath,
    380392                        );
    381393                        $fileFormats = $this->get_xml_file( $filePath );
     
    385397                    if (file_exists($tmpname)) wp_all_import_remove_source($tmpname, false);
    386398                } elseif ('csv' == $feed_type or '' == $feed_type and preg_match('%\W(csv|txt|dat|psv|tsv)$%i', trim($this->file))) {
    387                                    
     399
    388400                    $source = array(
    389401                        'name' => basename(parse_url($this->file, PHP_URL_PATH)),
    390402                        'type' => 'url',
    391                         'path' => $feed_xpath,                 
     403                        'path' => $feed_xpath,
    392404                    );
    393405                    // copy remote file in binary mode
     
    395407                    if ( ! is_wp_error($filePath) ){
    396408                        if ( ! file_exists($filePath)) {
    397                             $this->errors->add('form-validation', __('WP All Import was not able to download your file.<br/><br/>Please make sure the URL to your file is valid.<br/>You can test this by pasting it into your browser.<br/>Other reasons for this error can include some server setting on your host restricting access to this particular URL or external URLs in general, or some setting on the server hosting the file you are trying to access preventing your server from accessing it.', 'wp_all_import_plugin'));                         
    398                         }
    399                         // Detect if file is very large                                         
    400                         include_once(PMXI_Plugin::ROOT_DIR.'/libraries/XmlImportCsvParse.php');                 
     409                            $this->errors->add('form-validation', __('WP All Import was not able to download your file.<br/><br/>Please make sure the URL to your file is valid.<br/>You can test this by pasting it into your browser.<br/>Other reasons for this error can include some server setting on your host restricting access to this particular URL or external URLs in general, or some setting on the server hosting the file you are trying to access preventing your server from accessing it.', 'wp_all_import_plugin'));
     410                        }
     411                        // Detect if file is very large
     412                        include_once(PMXI_Plugin::ROOT_DIR.'/libraries/XmlImportCsvParse.php');
    401413                        $csv = new PMXI_CsvParser( array( 'filename' => $filePath, 'targetDir' => $this->uploadsPath ) ); // create chunks
    402414                        //wp_all_import_remove_source($filePath, false);
     
    413425                        'name' => basename(parse_url($this->file, PHP_URL_PATH)),
    414426                        'type' => 'url',
    415                         'path' => $feed_xpath,                 
     427                        'path' => $feed_xpath,
    416428                    );
    417429                    // copy remote file in binary mode
     
    425437                        $xml_data = wp_all_import_json_to_xml( json_decode($json_str, true) );
    426438                        if ( empty($xml_data) ){
    427                             $this->errors->add('form-validation', __('Can not import this file. JSON to XML convertation failed.', 'wp_all_import_plugin'));   
     439                            $this->errors->add('form-validation', __('Can not import this file. JSON to XML convertation failed.', 'wp_all_import_plugin'));
    428440                        } else {
    429                             $tmpname = $this->uploadsPath  .'/'. wp_all_import_url_title(wp_unique_filename($this->uploadsPath, str_replace("json", "xml", basename($filePath))));                                 
     441                            $tmpname = $this->uploadsPath  .'/'. wp_all_import_url_title(wp_unique_filename($this->uploadsPath, str_replace("json", "xml", basename($filePath))));
    430442                            file_put_contents($tmpname, $xml_data);
    431443                            wp_all_import_remove_source($filePath, false);
    432                             $filePath = $tmpname;                           
     444                            $filePath = $tmpname;
    433445                        }
    434446                    }
     
    437449                        'name' => basename($this->file),
    438450                        'type' => 'url',
    439                         'path' => $feed_xpath,                 
     451                        'path' => $feed_xpath,
    440452                    );
    441453                    // copy remote file in binary mode
    442454                    $localSQLPath = wp_all_import_get_url($this->file, $this->uploadsPath, 'sql');
    443455                    include_once( PMXI_Plugin::ROOT_DIR . '/libraries/XmlImportSQLParse.php' );
    444                     $sql = new PMXI_SQLParser( $localSQLPath, $this->uploadsPath );                 
    445                     $filePath = $sql->parse();             
     456                    $sql = new PMXI_SQLParser( $localSQLPath, $this->uploadsPath );
     457                    $filePath = $sql->parse();
    446458                    wp_all_import_remove_source($localSQLPath, false);
    447459                } elseif (preg_match('%\W(xls|xlsx)$%i', $feed_type) || preg_match('%\W(xls|xlsx)$%i', strtok(trim($this->file), "?")) || preg_match('%\W(xls|xlsx)$%i', trim($this->file))) {
     
    450462                        'name' => basename($this->file),
    451463                        'type' => 'url',
    452                         'path' => $feed_xpath,                 
     464                        'path' => $feed_xpath,
    453465                    );
    454466                    // copy remote file in binary mode
    455467                    $localXLSPath = wp_all_import_get_url($this->file, $this->uploadsPath, 'xls');
    456468                    include_once( PMXI_Plugin::ROOT_DIR . '/libraries/XmlImportXLSParse.php' );
    457                     $xls = new PMXI_XLSParser( $localXLSPath, $this->uploadsPath );                 
    458                     $filePath = $xls->parse();             
     469                    $xls = new PMXI_XLSParser( $localXLSPath, $this->uploadsPath );
     470                    $filePath = $xls->parse();
    459471                    wp_all_import_remove_source($localXLSPath, false);
    460472                } else {
    461473                    if ('gz' == $feed_type or '' == $feed_type and preg_match('%\W(gz|gzip)$%i', trim($this->file))){
    462                         $fileInfo = wp_all_import_get_gz($this->file, 0, $this->uploadsPath);                       
     474                        $fileInfo = wp_all_import_get_gz($this->file, 0, $this->uploadsPath);
    463475                    } else {
    464476                        $headers = wp_all_import_get_feed_type($this->file);
    465                         if ($headers['Content-Type'] and in_array($headers['Content-Type'], array('gz', 'gzip')) or $headers['Content-Encoding'] and in_array($headers['Content-Encoding'], array('gz', 'gzip'))){                         
     477                        if ($headers['Content-Type'] and in_array($headers['Content-Type'], array('gz', 'gzip')) or $headers['Content-Encoding'] and in_array($headers['Content-Encoding'], array('gz', 'gzip'))){
    466478                            $fileInfo = wp_all_import_get_gz($this->file, 0, $this->uploadsPath, $headers);
    467479                        } else {
    468480                            $fileInfo = wp_all_import_get_url($this->file, $this->uploadsPath, $headers['Content-Type'], $headers['Content-Encoding'], true);
    469                         }                                           
    470                     }                                       
    471                    
     481                        }
     482                    }
     483
    472484                    if ( ! is_wp_error($fileInfo) ){
    473485                        $filePath = $fileInfo['localPath'];
    474486                        if ( ! file_exists($filePath)) {
    475                             $this->errors->add('form-validation', __('WP All Import was not able to download your file.<br/><br/>Please make sure the URL to your file is valid.<br/>You can test this by pasting it into your browser.<br/>Other reasons for this error can include some server setting on your host restricting access to this particular URL or external URLs in general, or some setting on the server hosting the file you are trying to access preventing your server from accessing it.', 'wp_all_import_plugin'));                         
    476                         }
    477                         // Detect if file is very large                 
     487                            $this->errors->add('form-validation', __('WP All Import was not able to download your file.<br/><br/>Please make sure the URL to your file is valid.<br/>You can test this by pasting it into your browser.<br/>Other reasons for this error can include some server setting on your host restricting access to this particular URL or external URLs in general, or some setting on the server hosting the file you are trying to access preventing your server from accessing it.', 'wp_all_import_plugin'));
     488                        }
     489                        // Detect if file is very large
    478490                        $source = array(
    479491                            'name' => basename(parse_url($this->file, PHP_URL_PATH)),
    480492                            'type' => 'url',
    481                             'path' => $feed_xpath,                 
     493                            'path' => $feed_xpath,
    482494                        );
    483495                        $fileInfo['type'] = apply_filters('wp_all_import_feed_type', $fileInfo['type'], $this->file);
    484                         // detect CSV or XML 
     496                        // detect CSV or XML
    485497                        switch ($fileInfo['type']) {
    486498                            case 'csv':
    487                                 include_once(PMXI_Plugin::ROOT_DIR.'/libraries/XmlImportCsvParse.php');                 
     499                                include_once(PMXI_Plugin::ROOT_DIR.'/libraries/XmlImportCsvParse.php');
    488500                                $csv = new PMXI_CsvParser( array( 'filename' => $filePath, 'targetDir' => $this->uploadsPath ) ); // create chunks
    489501                                $csv_path = $filePath;
     
    491503                                $filePath = $csv->xml_path;
    492504                                $this->is_csv = $csv->is_csv;
    493                                 $this->root_element = 'node';                                                   
     505                                $this->root_element = 'node';
    494506                                break;
    495507                            case 'json':
     
    497509                                $json_str = str_replace("\xEF\xBB\xBF",'', $json_str);
    498510                                $is_json = wp_all_import_is_json($json_str);
    499                                
     511
    500512                                if( is_wp_error($is_json)){
    501513                                    $this->errors->add('form-validation', $is_json->get_error_message(), 'wp_all_import_plugin');
     
    503515                                    $xml_data = wp_all_import_json_to_xml( json_decode($json_str, true) );
    504516                                    if ( empty($xml_data) ) {
    505                                         $this->errors->add('form-validation', __('Can not import this file. JSON to XML convertation failed.', 'wp_all_import_plugin'));   
     517                                        $this->errors->add('form-validation', __('Can not import this file. JSON to XML convertation failed.', 'wp_all_import_plugin'));
    506518                                    } else {
    507                                         $tmpname = $this->uploadsPath  .'/'. wp_all_import_url_title(wp_unique_filename($this->uploadsPath, str_replace("json", "xml", basename($filePath))));                                 
     519                                        $tmpname = $this->uploadsPath  .'/'. wp_all_import_url_title(wp_unique_filename($this->uploadsPath, str_replace("json", "xml", basename($filePath))));
    508520                                        file_put_contents($tmpname, $xml_data);
    509521                                        wp_all_import_remove_source($filePath, false);
    510                                         $filePath = $tmpname;                           
     522                                        $filePath = $tmpname;
    511523                                    }
    512524                                }
     
    514526                            case 'sql':
    515527                                include_once( PMXI_Plugin::ROOT_DIR . '/libraries/XmlImportSQLParse.php' );
    516                                 $sql = new PMXI_SQLParser( $filePath, $this->uploadsPath );                 
     528                                $sql = new PMXI_SQLParser( $filePath, $this->uploadsPath );
    517529                                $filePath = $sql->parse();
    518                                 break; 
     530                                break;
    519531                            default:
    520532                                # code...
     
    528540            if ( $this->errors->get_error_codes() ) return $this->errors;
    529541
    530             $decodedTemplates = empty($templates) ? json_decode($importTemplate, true) : json_decode($templates, true);         
    531            
     542            $decodedTemplates = empty($templates) ? json_decode($importTemplate, true) : json_decode($templates, true);
     543
    532544            $templateOptions = "";
    533545
     
    536548            }
    537549
    538             $options = (empty($templateOptions[0]['options'])) ? false : maybe_unserialize($templateOptions[0]['options']);     
     550            $options = (empty($templateOptions[0]['options'])) ? false : maybe_unserialize($templateOptions[0]['options']);
    539551
    540552            if ( ! empty($options['root_element'])) $this->root_element = $options['root_element'];
     
    554566            );
    555567        }
    556                
     568
    557569        protected function get_xml_file( $filePath )
    558570        {
     
    563575                if($this->uploadsPath === false){
    564576                     $this->errors->add('form-validation', __('WP All Import can\'t access your WordPress uploads folder.', 'wp_all_import_plugin'));
    565                 }                                                                                               
    566                
     577                }
     578
    567579                include_once(PMXI_Plugin::ROOT_DIR.'/libraries/XmlImportCsvParse.php');
    568580                $csv = new PMXI_CsvParser( array( 'filename' => $filePath, 'targetDir' => $this->uploadsPath ) ); // create chunks
    569                
     581
    570582                $csv_path = $filePath;
    571583
    572584                $filePath = $csv->xml_path;
    573585                $this->is_csv = $csv->is_csv;
    574                 $this->root_element = 'node';       
    575                
     586                $this->root_element = 'node';
     587
    576588            } elseif (preg_match('%\W(json)$%i', trim($filePath))){
    577589
     
    579591                $json_str = str_replace("\xEF\xBB\xBF",'', $json_str);
    580592                $is_json = wp_all_import_is_json($json_str);
    581                
     593
    582594                if( is_wp_error($is_json)){
    583595                    $this->errors->add('form-validation', $is_json->get_error_message(), 'wp_all_import_plugin');
    584596                }
    585                 else{                   
    586                    
     597                else{
     598
    587599                    $xml_data = wp_all_import_json_to_xml( json_decode($json_str, true) );
    588600
    589601                    if ( empty($xml_data) ){
    590                         $this->errors->add('form-validation', __('Can not import this file. JSON to XML convertation failed.', 'wp_all_import_plugin'));   
     602                        $this->errors->add('form-validation', __('Can not import this file. JSON to XML convertation failed.', 'wp_all_import_plugin'));
    591603                    }
    592604                    else{
    593                         $jsontmpname = $this->uploadsPath  .'/'. wp_all_import_url_title(wp_unique_filename($this->uploadsPath, str_replace("json", "xml", basename($filePath))));                                                             
     605                        $jsontmpname = $this->uploadsPath  .'/'. wp_all_import_url_title(wp_unique_filename($this->uploadsPath, str_replace("json", "xml", basename($filePath))));
    594606                        file_put_contents($jsontmpname, $xml_data);
    595607                        wp_all_import_remove_source($filePath, false);
     
    601613            elseif (preg_match('%\W(sql)$%i', trim($filePath))){
    602614
    603                 include_once( PMXI_Plugin::ROOT_DIR . '/libraries/XmlImportSQLParse.php' ); 
     615                include_once( PMXI_Plugin::ROOT_DIR . '/libraries/XmlImportSQLParse.php' );
    604616
    605617                $localSQLPath = $filePath;
     
    607619                $filePath = $sql->parse();
    608620                wp_all_import_remove_source($localSQLPath, false);
    609             }       
     621            }
    610622            elseif (preg_match('%\W(xls|xlsx)$%i', trim($filePath))){
    611623
    612                 include_once( PMXI_Plugin::ROOT_DIR . '/libraries/XmlImportXLSParse.php' ); 
    613 
    614                 $localXLSPath = $filePath;                     
    615                 $xls = new PMXI_XLSParser( $localXLSPath, $this->uploadsPath );                         
    616                 $filePath = $xls->parse();             
     624                include_once( PMXI_Plugin::ROOT_DIR . '/libraries/XmlImportXLSParse.php' );
     625
     626                $localXLSPath = $filePath;
     627                $xls = new PMXI_XLSParser( $localXLSPath, $this->uploadsPath );
     628                $filePath = $xls->parse();
    617629                wp_all_import_remove_source($localXLSPath, false);
    618630
  • wp-all-import/trunk/plugin.php

    r2736112 r2749264  
    44Plugin URI: http://www.wpallimport.com/wordpress-xml-csv-import/?utm_source=import-plugin-free&utm_medium=wp-plugins-page&utm_campaign=upgrade-to-pro
    55Description: The most powerful solution for importing XML and CSV files to WordPress. Create Posts and Pages with content from any XML or CSV file. A paid upgrade to WP All Import Pro is available for support and additional features.
    6 Version: 3.6.7
     6Version: 3.6.8
    77Author: Soflyy
    88*/
     
    2626define('WP_ALL_IMPORT_PREFIX', 'pmxi_');
    2727
    28 define('PMXI_VERSION', '3.6.7');
     28define('PMXI_VERSION', '3.6.8');
    2929
    3030define('PMXI_EDITION', 'free');
  • wp-all-import/trunk/readme.txt

    r2737093 r2749264  
    33Requires at least: 4.1
    44Tested up to: 6.0
    5 Stable tag: 3.6.7
     5Stable tag: 3.6.8
    66Tags: wordpress csv import, wordpress xml import, xml, csv, datafeed, import, migrate, import csv to wordpress, import xml to wordpress, advanced xml import, advanced csv import, bulk csv import, bulk xml import, bulk data import, xml to custom post type, csv to custom post type, woocommerce csv import, woocommerce xml import, csv import, import csv, xml import, import xml, csv importer
    77
     
    105105
    106106== Changelog ==
     107
     108= 3.6.8 =
     109* security improvement
    107110
    108111= 3.6.7 =
Note: See TracChangeset for help on using the changeset viewer.