Import any XML or CSV File to WordPress - Version 3.4.1

Version Description

  • improvement: Stop parsing data which is not going to be updated
  • improvement: added new filter wp_all_import_phpexcel_object to modify excel data before import
  • bug fix: search for images ending with underscores in media
  • bug fix: import hierarchical posts/pages
  • bug fix: import cpt page templates
Download this release

Release Info

Developer soflyy
Plugin Icon 128x128 Import any XML or CSV File to WordPress
Version 3.4.1
Comparing to
See all releases

Code changes from version 3.4.0 to 3.4.1

actions/pmxi_after_xml_import.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ function pmxi_pmxi_after_xml_import( $import_id, $import )
3
+ {
4
+ if ( ! in_array($import->options['custom_type'], array('taxonomies', 'import_users')) ) {
5
+ $custom_type = get_post_type_object( $import->options['custom_type'] );
6
+ if ( ! empty($custom_type) && $custom_type->hierarchical ){
7
+ $parent_posts = get_option('wp_all_import_posts_hierarchy_' . $import_id);
8
+ if (!empty($parent_posts)){
9
+ foreach ($parent_posts as $pid => $identity){
10
+ $parent_post = wp_all_import_get_parent_post($identity, $import->options['custom_type'], $import->options['type']);
11
+ if (!empty($parent_post) && !is_wp_error($parent_post)){
12
+ wp_update_post(array(
13
+ 'ID' => $pid,
14
+ 'parent' => $parent_post->ID
15
+ ));
16
+ }
17
+ }
18
+ }
19
+ delete_option('wp_all_import_posts_hierarchy_' . $import_id);
20
+ }
21
+ }
22
+ }
classes/PHPExcel.php CHANGED
@@ -1,8 +1,15 @@
1
  <?php
 
 
 
 
 
 
 
2
  /**
3
  * PHPExcel
4
  *
5
- * Copyright (c) 2006 - 2014 PHPExcel
6
  *
7
  * This library is free software; you can redistribute it and/or
8
  * modify it under the terms of the GNU Lesser General Public
@@ -20,26 +27,10 @@
20
  *
21
  * @category PHPExcel
22
  * @package PHPExcel
23
- * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
24
  * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25
  * @version ##VERSION##, ##DATE##
26
  */
27
-
28
-
29
- /** PHPExcel root directory */
30
- if (!defined('PHPEXCEL_ROOT')) {
31
- define('PHPEXCEL_ROOT', dirname(__FILE__) . '/');
32
- require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
33
- }
34
-
35
-
36
- /**
37
- * PHPExcel
38
- *
39
- * @category PHPExcel
40
- * @package PHPExcel
41
- * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
42
- */
43
  class PHPExcel
44
  {
45
  /**
@@ -47,282 +38,298 @@ class PHPExcel
47
  *
48
  * @var string
49
  */
50
- private $_uniqueID;
51
 
52
  /**
53
  * Document properties
54
  *
55
  * @var PHPExcel_DocumentProperties
56
  */
57
- private $_properties;
58
 
59
  /**
60
  * Document security
61
  *
62
  * @var PHPExcel_DocumentSecurity
63
  */
64
- private $_security;
65
 
66
  /**
67
  * Collection of Worksheet objects
68
  *
69
  * @var PHPExcel_Worksheet[]
70
  */
71
- private $_workSheetCollection = array();
72
 
73
  /**
74
- * Calculation Engine
75
- *
76
- * @var PHPExcel_Calculation
77
- */
78
- private $_calculationEngine = NULL;
79
 
80
  /**
81
  * Active sheet index
82
  *
83
- * @var int
84
  */
85
- private $_activeSheetIndex = 0;
86
 
87
  /**
88
  * Named ranges
89
  *
90
  * @var PHPExcel_NamedRange[]
91
  */
92
- private $_namedRanges = array();
93
 
94
  /**
95
  * CellXf supervisor
96
  *
97
  * @var PHPExcel_Style
98
  */
99
- private $_cellXfSupervisor;
100
 
101
  /**
102
  * CellXf collection
103
  *
104
  * @var PHPExcel_Style[]
105
  */
106
- private $_cellXfCollection = array();
107
 
108
  /**
109
  * CellStyleXf collection
110
  *
111
  * @var PHPExcel_Style[]
112
  */
113
- private $_cellStyleXfCollection = array();
114
-
115
- /**
116
- * _hasMacros : this workbook have macros ?
117
- *
118
- * @var bool
119
- */
120
- private $_hasMacros = FALSE;
121
-
122
- /**
123
- * _macrosCode : all macros code (the vbaProject.bin file, this include form, code, etc.), NULL if no macro
124
- *
125
- * @var binary
126
- */
127
- private $_macrosCode=NULL;
128
- /**
129
- * _macrosCertificate : if macros are signed, contains vbaProjectSignature.bin file, NULL if not signed
130
- *
131
- * @var binary
132
- */
133
- private $_macrosCertificate=NULL;
134
-
135
- /**
136
- * _ribbonXMLData : NULL if workbook is'nt Excel 2007 or not contain a customized UI
137
- *
138
- * @var NULL|string
139
- */
140
- private $_ribbonXMLData=NULL;
141
-
142
- /**
143
- * _ribbonBinObjects : NULL if workbook is'nt Excel 2007 or not contain embedded objects (picture(s)) for Ribbon Elements
144
- * ignored if $_ribbonXMLData is null
145
- *
146
- * @var NULL|array
147
- */
148
- private $_ribbonBinObjects=NULL;
149
-
150
- /**
151
- * The workbook has macros ?
152
- *
153
- * @return true if workbook has macros, false if not
154
- */
155
- public function hasMacros(){
156
- return $this->_hasMacros;
157
- }
158
-
159
- /**
160
- * Define if a workbook has macros
161
- *
162
- * @param true|false
163
- */
164
- public function setHasMacros($hasMacros=false){
165
- $this->_hasMacros=(bool)$hasMacros;
166
- }
167
-
168
- /**
169
- * Set the macros code
170
- *
171
- * @param binary string|null
172
- */
173
- public function setMacrosCode($MacrosCode){
174
- $this->_macrosCode=$MacrosCode;
175
- $this->setHasMacros(!is_null($MacrosCode));
176
- }
177
-
178
- /**
179
- * Return the macros code
180
- *
181
- * @return binary|null
182
- */
183
- public function getMacrosCode(){
184
- return $this->_macrosCode;
185
- }
186
-
187
- /**
188
- * Set the macros certificate
189
- *
190
- * @param binary|null
191
- */
192
- public function setMacrosCertificate($Certificate=NULL){
193
- $this->_macrosCertificate=$Certificate;
194
- }
195
-
196
- /**
197
- * Is the project signed ?
198
- *
199
- * @return true|false
200
- */
201
- public function hasMacrosCertificate(){
202
- return !is_null($this->_macrosCertificate);
203
- }
204
-
205
- /**
206
- * Return the macros certificate
207
- *
208
- * @return binary|null
209
- */
210
- public function getMacrosCertificate(){
211
- return $this->_macrosCertificate;
212
- }
213
-
214
- /**
215
- * Remove all macros, certificate from spreadsheet
216
- *
217
- * @param none
218
- * @return void
219
- */
220
- public function discardMacros(){
221
- $this->_hasMacros=false;
222
- $this->_macrosCode=NULL;
223
- $this->_macrosCertificate=NULL;
224
- }
225
-
226
- /**
227
- * set ribbon XML data
228
- *
229
- */
230
- public function setRibbonXMLData($Target=NULL, $XMLData=NULL){
231
- if(!is_null($Target) && !is_null($XMLData)){
232
- $this->_ribbonXMLData=array('target'=>$Target, 'data'=>$XMLData);
233
- }else{
234
- $this->_ribbonXMLData=NULL;
235
- }
236
- }
237
-
238
- /**
239
- * retrieve ribbon XML Data
240
- *
241
- * return string|null|array
242
- */
243
- public function getRibbonXMLData($What='all'){//we need some constants here...
244
- $ReturnData=NULL;
245
- $What=strtolower($What);
246
- switch($What){
247
- case 'all':
248
- $ReturnData=$this->_ribbonXMLData;
249
- break;
250
- case 'target':
251
- case 'data':
252
- if(is_array($this->_ribbonXMLData) && array_key_exists($What,$this->_ribbonXMLData)){
253
- $ReturnData=$this->_ribbonXMLData[$What];
254
- }//else $ReturnData stay at null
255
- break;
256
- }//default: $ReturnData at null
257
- return $ReturnData;
258
- }
259
-
260
- /**
261
- * store binaries ribbon objects (pictures)
262
- *
263
- */
264
- public function setRibbonBinObjects($BinObjectsNames=NULL, $BinObjectsData=NULL){
265
- if(!is_null($BinObjectsNames) && !is_null($BinObjectsData)){
266
- $this->_ribbonBinObjects=array('names'=>$BinObjectsNames, 'data'=>$BinObjectsData);
267
- }else{
268
- $this->_ribbonBinObjects=NULL;
269
- }
270
- }
271
- /**
272
- * return the extension of a filename. Internal use for a array_map callback (php<5.3 don't like lambda function)
273
- *
274
- */
275
- private function _getExtensionOnly($ThePath){
276
- return pathinfo($ThePath, PATHINFO_EXTENSION);
277
- }
278
-
279
- /**
280
- * retrieve Binaries Ribbon Objects
281
- *
282
- */
283
- public function getRibbonBinObjects($What='all'){
284
- $ReturnData=NULL;
285
- $What=strtolower($What);
286
- switch($What){
287
- case 'all':
288
- return $this->_ribbonBinObjects;
289
- break;
290
- case 'names':
291
- case 'data':
292
- if(is_array($this->_ribbonBinObjects) && array_key_exists($What, $this->_ribbonBinObjects)){
293
- $ReturnData=$this->_ribbonBinObjects[$What];
294
- }
295
- break;
296
- case 'types':
297
- if(is_array($this->_ribbonBinObjects) && array_key_exists('data', $this->_ribbonBinObjects) && is_array($this->_ribbonBinObjects['data'])){
298
- $tmpTypes=array_keys($this->_ribbonBinObjects['data']);
299
- $ReturnData=array_unique(array_map(array($this,'_getExtensionOnly'), $tmpTypes));
300
- }else
301
- $ReturnData=array();//the caller want an array... not null if empty
302
- break;
303
- }
304
- return $ReturnData;
305
- }
306
-
307
- /**
308
- * This workbook have a custom UI ?
309
- *
310
- * @return true|false
311
- */
312
- public function hasRibbon(){
313
- return !is_null($this->_ribbonXMLData);
314
- }
315
-
316
- /**
317
- * This workbook have additionnal object for the ribbon ?
318
- *
319
- * @return true|false
320
- */
321
- public function hasRibbonBinObjects(){
322
- return !is_null($this->_ribbonBinObjects);
323
- }
324
-
325
- /**
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
326
  * Check if a sheet with a specified code name already exists
327
  *
328
  * @param string $pSheetCodeName Name of the worksheet to check
@@ -330,52 +337,52 @@ class PHPExcel
330
  */
331
  public function sheetCodeNameExists($pSheetCodeName)
332
  {
333
- return ($this->getSheetByCodeName($pSheetCodeName) !== NULL);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
334
  }
335
 
336
- /**
337
- * Get sheet by code name. Warning : sheet don't have always a code name !
338
- *
339
- * @param string $pName Sheet name
340
- * @return PHPExcel_Worksheet
341
- */
342
- public function getSheetByCodeName($pName = '')
343
- {
344
- $worksheetCount = count($this->_workSheetCollection);
345
- for ($i = 0; $i < $worksheetCount; ++$i) {
346
- if ($this->_workSheetCollection[$i]->getCodeName() == $pName) {
347
- return $this->_workSheetCollection[$i];
348
- }
349
- }
350
-
351
- return null;
352
- }
353
-
354
- /**
355
- * Create a new PHPExcel with one Worksheet
356
- */
357
- public function __construct()
358
- {
359
- $this->_uniqueID = uniqid();
360
- $this->_calculationEngine = PHPExcel_Calculation::getInstance($this);
361
-
362
- // Initialise worksheet collection and add one worksheet
363
- $this->_workSheetCollection = array();
364
- $this->_workSheetCollection[] = new PHPExcel_Worksheet($this);
365
- $this->_activeSheetIndex = 0;
366
 
367
  // Create document properties
368
- $this->_properties = new PHPExcel_DocumentProperties();
369
 
370
  // Create document security
371
- $this->_security = new PHPExcel_DocumentSecurity();
372
 
373
  // Set named ranges
374
- $this->_namedRanges = array();
375
 
376
  // Create the cellXf supervisor
377
- $this->_cellXfSupervisor = new PHPExcel_Style(true);
378
- $this->_cellXfSupervisor->bindParent($this);
379
 
380
  // Create the default style
381
  $this->addCellXf(new PHPExcel_Style);
@@ -386,10 +393,11 @@ class PHPExcel
386
  * Code to execute when this worksheet is unset()
387
  *
388
  */
389
- public function __destruct() {
390
- PHPExcel_Calculation::unsetInstance($this);
 
391
  $this->disconnectWorksheets();
392
- } // function __destruct()
393
 
394
  /**
395
  * Disconnect all worksheets from this PHPExcel workbook object,
@@ -398,24 +406,24 @@ class PHPExcel
398
  */
399
  public function disconnectWorksheets()
400
  {
401
- $worksheet = NULL;
402
- foreach($this->_workSheetCollection as $k => &$worksheet) {
403
  $worksheet->disconnectCells();
404
- $this->_workSheetCollection[$k] = null;
405
  }
406
  unset($worksheet);
407
- $this->_workSheetCollection = array();
408
  }
409
 
410
- /**
411
- * Return the calculation engine for this worksheet
412
- *
413
- * @return PHPExcel_Calculation
414
- */
415
- public function getCalculationEngine()
416
- {
417
- return $this->_calculationEngine;
418
- } // function getCellCacheController()
419
 
420
  /**
421
  * Get properties
@@ -424,7 +432,7 @@ class PHPExcel
424
  */
425
  public function getProperties()
426
  {
427
- return $this->_properties;
428
  }
429
 
430
  /**
@@ -434,7 +442,7 @@ class PHPExcel
434
  */
435
  public function setProperties(PHPExcel_DocumentProperties $pValue)
436
  {
437
- $this->_properties = $pValue;
438
  }
439
 
440
  /**
@@ -444,7 +452,7 @@ class PHPExcel
444
  */
445
  public function getSecurity()
446
  {
447
- return $this->_security;
448
  }
449
 
450
  /**
@@ -454,7 +462,7 @@ class PHPExcel
454
  */
455
  public function setSecurity(PHPExcel_DocumentSecurity $pValue)
456
  {
457
- $this->_security = $pValue;
458
  }
459
 
460
  /**
@@ -466,7 +474,7 @@ class PHPExcel
466
  */
467
  public function getActiveSheet()
468
  {
469
- return $this->getSheet($this->_activeSheetIndex);
470
  }
471
 
472
  /**
@@ -476,7 +484,7 @@ class PHPExcel
476
  * @return PHPExcel_Worksheet
477
  * @throws PHPExcel_Exception
478
  */
479
- public function createSheet($iSheetIndex = NULL)
480
  {
481
  $newSheet = new PHPExcel_Worksheet($this);
482
  $this->addSheet($newSheet, $iSheetIndex);
@@ -491,7 +499,7 @@ class PHPExcel
491
  */
492
  public function sheetNameExists($pSheetName)
493
  {
494
- return ($this->getSheetByName($pSheetName) !== NULL);
495
  }
496
 
497
  /**
@@ -502,31 +510,31 @@ class PHPExcel
502
  * @return PHPExcel_Worksheet
503
  * @throws PHPExcel_Exception
504
  */
505
- public function addSheet(PHPExcel_Worksheet $pSheet, $iSheetIndex = NULL)
506
  {
507
  if ($this->sheetNameExists($pSheet->getTitle())) {
508
  throw new PHPExcel_Exception(
509
- "Workbook already contains a worksheet named '{$pSheet->getTitle()}'. Rename this worksheet first."
510
  );
511
  }
512
 
513
- if($iSheetIndex === NULL) {
514
- if ($this->_activeSheetIndex < 0) {
515
- $this->_activeSheetIndex = 0;
516
  }
517
- $this->_workSheetCollection[] = $pSheet;
518
  } else {
519
  // Insert the sheet at the requested index
520
  array_splice(
521
- $this->_workSheetCollection,
522
  $iSheetIndex,
523
  0,
524
  array($pSheet)
525
- );
526
 
527
  // Adjust active sheet index if necessary
528
- if ($this->_activeSheetIndex >= $iSheetIndex) {
529
- ++$this->_activeSheetIndex;
530
  }
531
  }
532
 
@@ -546,19 +554,18 @@ class PHPExcel
546
  public function removeSheetByIndex($pIndex = 0)
547
  {
548
 
549
- $numSheets = count($this->_workSheetCollection);
550
-
551
  if ($pIndex > $numSheets - 1) {
552
  throw new PHPExcel_Exception(
553
- "You tried to remove a sheet by the out of bounds index: {$pIndex}. The actual number of sheets is {$numSheets}."
554
  );
555
  } else {
556
- array_splice($this->_workSheetCollection, $pIndex, 1);
557
  }
558
  // Adjust active sheet index if necessary
559
- if (($this->_activeSheetIndex >= $pIndex) &&
560
- ($pIndex > count($this->_workSheetCollection) - 1)) {
561
- --$this->_activeSheetIndex;
562
  }
563
 
564
  }
@@ -572,14 +579,14 @@ class PHPExcel
572
  */
573
  public function getSheet($pIndex = 0)
574
  {
575
- if (!isset($this->_workSheetCollection[$pIndex])) {
576
  $numSheets = $this->getSheetCount();
577
  throw new PHPExcel_Exception(
578
  "Your requested sheet index: {$pIndex} is out of bounds. The actual number of sheets is {$numSheets}."
579
  );
580
  }
581
 
582
- return $this->_workSheetCollection[$pIndex];
583
  }
584
 
585
  /**
@@ -589,7 +596,7 @@ class PHPExcel
589
  */
590
  public function getAllSheets()
591
  {
592
- return $this->_workSheetCollection;
593
  }
594
 
595
  /**
@@ -600,26 +607,26 @@ class PHPExcel
600
  */
601
  public function getSheetByName($pName = '')
602
  {
603
- $worksheetCount = count($this->_workSheetCollection);
604
  for ($i = 0; $i < $worksheetCount; ++$i) {
605
- if ($this->_workSheetCollection[$i]->getTitle() === $pName) {
606
- return $this->_workSheetCollection[$i];
607
  }
608
  }
609
 
610
- return NULL;
611
  }
612
 
613
  /**
614
  * Get index for sheet
615
  *
616
  * @param PHPExcel_Worksheet $pSheet
617
- * @return Sheet index
618
  * @throws PHPExcel_Exception
619
  */
620
  public function getIndex(PHPExcel_Worksheet $pSheet)
621
  {
622
- foreach ($this->_workSheetCollection as $key => $value) {
623
  if ($value->getHashCode() == $pSheet->getHashCode()) {
624
  return $key;
625
  }
@@ -633,19 +640,19 @@ class PHPExcel
633
  *
634
  * @param string $sheetName Sheet name to modify index for
635
  * @param int $newIndex New index for the sheet
636
- * @return New sheet index
637
  * @throws PHPExcel_Exception
638
  */
639
  public function setIndexByName($sheetName, $newIndex)
640
  {
641
  $oldIndex = $this->getIndex($this->getSheetByName($sheetName));
642
  $pSheet = array_splice(
643
- $this->_workSheetCollection,
644
  $oldIndex,
645
  1
646
  );
647
  array_splice(
648
- $this->_workSheetCollection,
649
  $newIndex,
650
  0,
651
  $pSheet
@@ -660,7 +667,7 @@ class PHPExcel
660
  */
661
  public function getSheetCount()
662
  {
663
- return count($this->_workSheetCollection);
664
  }
665
 
666
  /**
@@ -670,7 +677,7 @@ class PHPExcel
670
  */
671
  public function getActiveSheetIndex()
672
  {
673
- return $this->_activeSheetIndex;
674
  }
675
 
676
  /**
@@ -682,14 +689,14 @@ class PHPExcel
682
  */
683
  public function setActiveSheetIndex($pIndex = 0)
684
  {
685
- $numSheets = count($this->_workSheetCollection);
686
 
687
  if ($pIndex > $numSheets - 1) {
688
  throw new PHPExcel_Exception(
689
- "You tried to set a sheet active by the out of bounds index: {$pIndex}. The actual number of sheets is {$numSheets}."
690
  );
691
  } else {
692
- $this->_activeSheetIndex = $pIndex;
693
  }
694
  return $this->getActiveSheet();
695
  }
@@ -735,13 +742,14 @@ class PHPExcel
735
  * @throws PHPExcel_Exception
736
  * @return PHPExcel_Worksheet
737
  */
738
- public function addExternalSheet(PHPExcel_Worksheet $pSheet, $iSheetIndex = null) {
 
739
  if ($this->sheetNameExists($pSheet->getTitle())) {
740
  throw new PHPExcel_Exception("Workbook already contains a worksheet named '{$pSheet->getTitle()}'. Rename the external sheet first.");
741
  }
742
 
743
  // count how many cellXfs there are in this workbook currently, we will need this below
744
- $countCellXfs = count($this->_cellXfCollection);
745
 
746
  // copy all the shared cellXfs from the external workbook and append them to the current
747
  foreach ($pSheet->getParent()->getCellXfCollection() as $cellXf) {
@@ -754,7 +762,7 @@ class PHPExcel
754
  // update the cellXfs
755
  foreach ($pSheet->getCellCollection(false) as $cellID) {
756
  $cell = $pSheet->getCell($cellID);
757
- $cell->setXfIndex( $cell->getXfIndex() + $countCellXfs );
758
  }
759
 
760
  return $this->addSheet($pSheet, $iSheetIndex);
@@ -765,23 +773,25 @@ class PHPExcel
765
  *
766
  * @return PHPExcel_NamedRange[]
767
  */
768
- public function getNamedRanges() {
769
- return $this->_namedRanges;
 
770
  }
771
 
772
  /**
773
  * Add named range
774
  *
775
  * @param PHPExcel_NamedRange $namedRange
776
- * @return PHPExcel
777
  */
778
- public function addNamedRange(PHPExcel_NamedRange $namedRange) {
 
779
  if ($namedRange->getScope() == null) {
780
  // global scope
781
- $this->_namedRanges[$namedRange->getName()] = $namedRange;
782
  } else {
783
  // local scope
784
- $this->_namedRanges[$namedRange->getScope()->getTitle().'!'.$namedRange->getName()] = $namedRange;
785
  }
786
  return true;
787
  }
@@ -793,18 +803,19 @@ class PHPExcel
793
  * @param PHPExcel_Worksheet|null $pSheet Scope. Use null for global scope
794
  * @return PHPExcel_NamedRange|null
795
  */
796
- public function getNamedRange($namedRange, PHPExcel_Worksheet $pSheet = null) {
 
797
  $returnValue = null;
798
 
799
- if ($namedRange != '' && ($namedRange !== NULL)) {
800
  // first look for global defined name
801
- if (isset($this->_namedRanges[$namedRange])) {
802
- $returnValue = $this->_namedRanges[$namedRange];
803
  }
804
 
805
  // then look for local defined name (has priority over global defined name if both names exist)
806
- if (($pSheet !== NULL) && isset($this->_namedRanges[$pSheet->getTitle() . '!' . $namedRange])) {
807
- $returnValue = $this->_namedRanges[$pSheet->getTitle() . '!' . $namedRange];
808
  }
809
  }
810
 
@@ -818,14 +829,15 @@ class PHPExcel
818
  * @param PHPExcel_Worksheet|null $pSheet Scope: use null for global scope.
819
  * @return PHPExcel
820
  */
821
- public function removeNamedRange($namedRange, PHPExcel_Worksheet $pSheet = null) {
822
- if ($pSheet === NULL) {
823
- if (isset($this->_namedRanges[$namedRange])) {
824
- unset($this->_namedRanges[$namedRange]);
 
825
  }
826
  } else {
827
- if (isset($this->_namedRanges[$pSheet->getTitle() . '!' . $namedRange])) {
828
- unset($this->_namedRanges[$pSheet->getTitle() . '!' . $namedRange]);
829
  }
830
  }
831
  return $this;
@@ -836,7 +848,8 @@ class PHPExcel
836
  *
837
  * @return PHPExcel_WorksheetIterator
838
  */
839
- public function getWorksheetIterator() {
 
840
  return new PHPExcel_WorksheetIterator($this);
841
  }
842
 
@@ -845,13 +858,14 @@ class PHPExcel
845
  *
846
  * @return PHPExcel
847
  */
848
- public function copy() {
 
849
  $copied = clone $this;
850
 
851
- $worksheetCount = count($this->_workSheetCollection);
852
  for ($i = 0; $i < $worksheetCount; ++$i) {
853
- $this->_workSheetCollection[$i] = $this->_workSheetCollection[$i]->copy();
854
- $this->_workSheetCollection[$i]->rebindParent($this);
855
  }
856
 
857
  return $copied;
@@ -860,8 +874,9 @@ class PHPExcel
860
  /**
861
  * Implement PHP __clone to create a deep clone, not just a shallow copy.
862
  */
863
- public function __clone() {
864
- foreach($this as $key => $val) {
 
865
  if (is_object($val) || (is_array($val))) {
866
  $this->{$key} = unserialize(serialize($val));
867
  }
@@ -875,7 +890,7 @@ class PHPExcel
875
  */
876
  public function getCellXfCollection()
877
  {
878
- return $this->_cellXfCollection;
879
  }
880
 
881
  /**
@@ -886,18 +901,18 @@ class PHPExcel
886
  */
887
  public function getCellXfByIndex($pIndex = 0)
888
  {
889
- return $this->_cellXfCollection[$pIndex];
890
  }
891
 
892
  /**
893
  * Get cellXf by hash code
894
  *
895
  * @param string $pValue
896
- * @return PHPExcel_Style|false
897
  */
898
  public function getCellXfByHashCode($pValue = '')
899
  {
900
- foreach ($this->_cellXfCollection as $cellXf) {
901
  if ($cellXf->getHashCode() == $pValue) {
902
  return $cellXf;
903
  }
@@ -913,7 +928,7 @@ class PHPExcel
913
  */
914
  public function cellXfExists($pCellStyle = null)
915
  {
916
- return in_array($pCellStyle, $this->_cellXfCollection, true);
917
  }
918
 
919
  /**
@@ -924,8 +939,8 @@ class PHPExcel
924
  */
925
  public function getDefaultStyle()
926
  {
927
- if (isset($this->_cellXfCollection[0])) {
928
- return $this->_cellXfCollection[0];
929
  }
930
  throw new PHPExcel_Exception('No default style found for this workbook');
931
  }
@@ -937,33 +952,33 @@ class PHPExcel
937
  */
938
  public function addCellXf(PHPExcel_Style $style)
939
  {
940
- $this->_cellXfCollection[] = $style;
941
- $style->setIndex(count($this->_cellXfCollection) - 1);
942
  }
943
 
944
  /**
945
  * Remove cellXf by index. It is ensured that all cells get their xf index updated.
946
  *
947
- * @param int $pIndex Index to cellXf
948
  * @throws PHPExcel_Exception
949
  */
950
  public function removeCellXfByIndex($pIndex = 0)
951
  {
952
- if ($pIndex > count($this->_cellXfCollection) - 1) {
953
  throw new PHPExcel_Exception("CellXf index is out of bounds.");
954
  } else {
955
  // first remove the cellXf
956
- array_splice($this->_cellXfCollection, $pIndex, 1);
957
 
958
  // then update cellXf indexes for cells
959
- foreach ($this->_workSheetCollection as $worksheet) {
960
  foreach ($worksheet->getCellCollection(false) as $cellID) {
961
  $cell = $worksheet->getCell($cellID);
962
  $xfIndex = $cell->getXfIndex();
963
- if ($xfIndex > $pIndex ) {
964
  // decrease xf index by 1
965
  $cell->setXfIndex($xfIndex - 1);
966
- } else if ($xfIndex == $pIndex) {
967
  // set to default xf index 0
968
  $cell->setXfIndex(0);
969
  }
@@ -979,7 +994,7 @@ class PHPExcel
979
  */
980
  public function getCellXfSupervisor()
981
  {
982
- return $this->_cellXfSupervisor;
983
  }
984
 
985
  /**
@@ -989,29 +1004,29 @@ class PHPExcel
989
  */
990
  public function getCellStyleXfCollection()
991
  {
992
- return $this->_cellStyleXfCollection;
993
  }
994
 
995
  /**
996
  * Get cellStyleXf by index
997
  *
998
- * @param int $pIndex
999
  * @return PHPExcel_Style
1000
  */
1001
  public function getCellStyleXfByIndex($pIndex = 0)
1002
  {
1003
- return $this->_cellStyleXfCollection[$pIndex];
1004
  }
1005
 
1006
  /**
1007
  * Get cellStyleXf by hash code
1008
  *
1009
  * @param string $pValue
1010
- * @return PHPExcel_Style|false
1011
  */
1012
  public function getCellStyleXfByHashCode($pValue = '')
1013
  {
1014
- foreach ($this->_cellStyleXfCollection as $cellStyleXf) {
1015
  if ($cellStyleXf->getHashCode() == $pValue) {
1016
  return $cellStyleXf;
1017
  }
@@ -1026,22 +1041,22 @@ class PHPExcel
1026
  */
1027
  public function addCellStyleXf(PHPExcel_Style $pStyle)
1028
  {
1029
- $this->_cellStyleXfCollection[] = $pStyle;
1030
- $pStyle->setIndex(count($this->_cellStyleXfCollection) - 1);
1031
  }
1032
 
1033
  /**
1034
  * Remove cellStyleXf by index
1035
  *
1036
- * @param int $pIndex
1037
  * @throws PHPExcel_Exception
1038
  */
1039
  public function removeCellStyleXfByIndex($pIndex = 0)
1040
  {
1041
- if ($pIndex > count($this->_cellStyleXfCollection) - 1) {
1042
  throw new PHPExcel_Exception("CellStyleXf index is out of bounds.");
1043
  } else {
1044
- array_splice($this->_cellStyleXfCollection, $pIndex, 1);
1045
  }
1046
  }
1047
 
@@ -1053,12 +1068,11 @@ class PHPExcel
1053
  {
1054
  // how many references are there to each cellXf ?
1055
  $countReferencesCellXf = array();
1056
- foreach ($this->_cellXfCollection as $index => $cellXf) {
1057
  $countReferencesCellXf[$index] = 0;
1058
  }
1059
 
1060
  foreach ($this->getWorksheetIterator() as $sheet) {
1061
-
1062
  // from cells
1063
  foreach ($sheet->getCellCollection(false) as $cellID) {
1064
  $cell = $sheet->getCell($cellID);
@@ -1081,48 +1095,48 @@ class PHPExcel
1081
  // remove cellXfs without references and create mapping so we can update xfIndex
1082
  // for all cells and columns
1083
  $countNeededCellXfs = 0;
1084
- foreach ($this->_cellXfCollection as $index => $cellXf) {
 
1085
  if ($countReferencesCellXf[$index] > 0 || $index == 0) { // we must never remove the first cellXf
1086
  ++$countNeededCellXfs;
1087
  } else {
1088
- unset($this->_cellXfCollection[$index]);
1089
  }
1090
  $map[$index] = $countNeededCellXfs - 1;
1091
  }
1092
- $this->_cellXfCollection = array_values($this->_cellXfCollection);
1093
 
1094
  // update the index for all cellXfs
1095
- foreach ($this->_cellXfCollection as $i => $cellXf) {
1096
  $cellXf->setIndex($i);
1097
  }
1098
 
1099
  // make sure there is always at least one cellXf (there should be)
1100
- if (empty($this->_cellXfCollection)) {
1101
- $this->_cellXfCollection[] = new PHPExcel_Style();
1102
  }
1103
 
1104
  // update the xfIndex for all cells, row dimensions, column dimensions
1105
  foreach ($this->getWorksheetIterator() as $sheet) {
1106
-
1107
  // for all cells
1108
  foreach ($sheet->getCellCollection(false) as $cellID) {
1109
  $cell = $sheet->getCell($cellID);
1110
- $cell->setXfIndex( $map[$cell->getXfIndex()] );
1111
  }
1112
 
1113
  // for all row dimensions
1114
  foreach ($sheet->getRowDimensions() as $rowDimension) {
1115
  if ($rowDimension->getXfIndex() !== null) {
1116
- $rowDimension->setXfIndex( $map[$rowDimension->getXfIndex()] );
1117
  }
1118
  }
1119
 
1120
  // for all column dimensions
1121
  foreach ($sheet->getColumnDimensions() as $columnDimension) {
1122
- $columnDimension->setXfIndex( $map[$columnDimension->getXfIndex()] );
1123
  }
1124
 
1125
- // also do garbage collection for all the sheets
1126
  $sheet->garbageCollect();
1127
  }
1128
  }
@@ -1132,8 +1146,8 @@ class PHPExcel
1132
  *
1133
  * @return string
1134
  */
1135
- public function getID() {
1136
- return $this->_uniqueID;
 
1137
  }
1138
-
1139
  }
1
  <?php
2
+
3
+ /** PHPExcel root directory */
4
+ if (!defined('PHPEXCEL_ROOT')) {
5
+ define('PHPEXCEL_ROOT', dirname(__FILE__) . '/');
6
+ require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
7
+ }
8
+
9
  /**
10
  * PHPExcel
11
  *
12
+ * Copyright (c) 2006 - 2015 PHPExcel
13
  *
14
  * This library is free software; you can redistribute it and/or
15
  * modify it under the terms of the GNU Lesser General Public
27
  *
28
  * @category PHPExcel
29
  * @package PHPExcel
30
+ * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
31
  * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
32
  * @version ##VERSION##, ##DATE##
33
  */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  class PHPExcel
35
  {
36
  /**
38
  *
39
  * @var string
40
  */
41
+ private $uniqueID;
42
 
43
  /**
44
  * Document properties
45
  *
46
  * @var PHPExcel_DocumentProperties
47
  */
48
+ private $properties;
49
 
50
  /**
51
  * Document security
52
  *
53
  * @var PHPExcel_DocumentSecurity
54
  */
55
+ private $security;
56
 
57
  /**
58
  * Collection of Worksheet objects
59
  *
60
  * @var PHPExcel_Worksheet[]
61
  */
62
+ private $workSheetCollection = array();
63
 
64
  /**
65
+ * Calculation Engine
66
+ *
67
+ * @var PHPExcel_Calculation
68
+ */
69
+ private $calculationEngine;
70
 
71
  /**
72
  * Active sheet index
73
  *
74
+ * @var integer
75
  */
76
+ private $activeSheetIndex = 0;
77
 
78
  /**
79
  * Named ranges
80
  *
81
  * @var PHPExcel_NamedRange[]
82
  */
83
+ private $namedRanges = array();
84
 
85
  /**
86
  * CellXf supervisor
87
  *
88
  * @var PHPExcel_Style
89
  */
90
+ private $cellXfSupervisor;
91
 
92
  /**
93
  * CellXf collection
94
  *
95
  * @var PHPExcel_Style[]
96
  */
97
+ private $cellXfCollection = array();
98
 
99
  /**
100
  * CellStyleXf collection
101
  *
102
  * @var PHPExcel_Style[]
103
  */
104
+ private $cellStyleXfCollection = array();
105
+
106
+ /**
107
+ * hasMacros : this workbook have macros ?
108
+ *
109
+ * @var bool
110
+ */
111
+ private $hasMacros = false;
112
+
113
+ /**
114
+ * macrosCode : all macros code (the vbaProject.bin file, this include form, code, etc.), null if no macro
115
+ *
116
+ * @var binary
117
+ */
118
+ private $macrosCode;
119
+ /**
120
+ * macrosCertificate : if macros are signed, contains vbaProjectSignature.bin file, null if not signed
121
+ *
122
+ * @var binary
123
+ */
124
+ private $macrosCertificate;
125
+
126
+ /**
127
+ * ribbonXMLData : null if workbook is'nt Excel 2007 or not contain a customized UI
128
+ *
129
+ * @var null|string
130
+ */
131
+ private $ribbonXMLData;
132
+
133
+ /**
134
+ * ribbonBinObjects : null if workbook is'nt Excel 2007 or not contain embedded objects (picture(s)) for Ribbon Elements
135
+ * ignored if $ribbonXMLData is null
136
+ *
137
+ * @var null|array
138
+ */
139
+ private $ribbonBinObjects;
140
+
141
+ /**
142
+ * The workbook has macros ?
143
+ *
144
+ * @return boolean true if workbook has macros, false if not
145
+ */
146
+ public function hasMacros()
147
+ {
148
+ return $this->hasMacros;
149
+ }
150
+
151
+ /**
152
+ * Define if a workbook has macros
153
+ *
154
+ * @param boolean $hasMacros true|false
155
+ */
156
+ public function setHasMacros($hasMacros = false)
157
+ {
158
+ $this->hasMacros = (bool) $hasMacros;
159
+ }
160
+
161
+ /**
162
+ * Set the macros code
163
+ *
164
+ * @param string $MacrosCode string|null
165
+ */
166
+ public function setMacrosCode($MacrosCode = null)
167
+ {
168
+ $this->macrosCode=$MacrosCode;
169
+ $this->setHasMacros(!is_null($MacrosCode));
170
+ }
171
+
172
+ /**
173
+ * Return the macros code
174
+ *
175
+ * @return string|null
176
+ */
177
+ public function getMacrosCode()
178
+ {
179
+ return $this->macrosCode;
180
+ }
181
+
182
+ /**
183
+ * Set the macros certificate
184
+ *
185
+ * @param string|null $Certificate
186
+ */
187
+ public function setMacrosCertificate($Certificate = null)
188
+ {
189
+ $this->macrosCertificate=$Certificate;
190
+ }
191
+
192
+ /**
193
+ * Is the project signed ?
194
+ *
195
+ * @return boolean true|false
196
+ */
197
+ public function hasMacrosCertificate()
198
+ {
199
+ return !is_null($this->macrosCertificate);
200
+ }
201
+
202
+ /**
203
+ * Return the macros certificate
204
+ *
205
+ * @return string|null
206
+ */
207
+ public function getMacrosCertificate()
208
+ {
209
+ return $this->macrosCertificate;
210
+ }
211
+
212
+ /**
213
+ * Remove all macros, certificate from spreadsheet
214
+ *
215
+ */
216
+ public function discardMacros()
217
+ {
218
+ $this->hasMacros=false;
219
+ $this->macrosCode=null;
220
+ $this->macrosCertificate=null;
221
+ }
222
+
223
+ /**
224
+ * set ribbon XML data
225
+ *
226
+ */
227
+ public function setRibbonXMLData($Target = null, $XMLData = null)
228
+ {
229
+ if (!is_null($Target) && !is_null($XMLData)) {
230
+ $this->ribbonXMLData = array('target' => $Target, 'data' => $XMLData);
231
+ } else {
232
+ $this->ribbonXMLData = null;
233
+ }
234
+ }
235
+
236
+ /**
237
+ * retrieve ribbon XML Data
238
+ *
239
+ * return string|null|array
240
+ */
241
+ public function getRibbonXMLData($What = 'all') //we need some constants here...
242
+ {
243
+ $ReturnData = null;
244
+ $What = strtolower($What);
245
+ switch ($What){
246
+ case 'all':
247
+ $ReturnData = $this->ribbonXMLData;
248
+ break;
249
+ case 'target':
250
+ case 'data':
251
+ if (is_array($this->ribbonXMLData) && array_key_exists($What, $this->ribbonXMLData)) {
252
+ $ReturnData = $this->ribbonXMLData[$What];
253
+ }
254
+ break;
255
+ }
256
+
257
+ return $ReturnData;
258
+ }
259
+
260
+ /**
261
+ * store binaries ribbon objects (pictures)
262
+ *
263
+ */
264
+ public function setRibbonBinObjects($BinObjectsNames = null, $BinObjectsData = null)
265
+ {
266
+ if (!is_null($BinObjectsNames) && !is_null($BinObjectsData)) {
267
+ $this->ribbonBinObjects = array('names' => $BinObjectsNames, 'data' => $BinObjectsData);
268
+ } else {
269
+ $this->ribbonBinObjects = null;
270
+ }
271
+ }
272
+ /**
273
+ * return the extension of a filename. Internal use for a array_map callback (php<5.3 don't like lambda function)
274
+ *
275
+ */
276
+ private function getExtensionOnly($ThePath)
277
+ {
278
+ return pathinfo($ThePath, PATHINFO_EXTENSION);
279
+ }
280
+
281
+ /**
282
+ * retrieve Binaries Ribbon Objects
283
+ *
284
+ */
285
+ public function getRibbonBinObjects($What = 'all')
286
+ {
287
+ $ReturnData = null;
288
+ $What = strtolower($What);
289
+ switch($What) {
290
+ case 'all':
291
+ return $this->ribbonBinObjects;
292
+ break;
293
+ case 'names':
294
+ case 'data':
295
+ if (is_array($this->ribbonBinObjects) && array_key_exists($What, $this->ribbonBinObjects)) {
296
+ $ReturnData=$this->ribbonBinObjects[$What];
297
+ }
298
+ break;
299
+ case 'types':
300
+ if (is_array($this->ribbonBinObjects) &&
301
+ array_key_exists('data', $this->ribbonBinObjects) && is_array($this->ribbonBinObjects['data'])) {
302
+ $tmpTypes=array_keys($this->ribbonBinObjects['data']);
303
+ $ReturnData = array_unique(array_map(array($this, 'getExtensionOnly'), $tmpTypes));
304
+ } else {
305
+ $ReturnData=array(); // the caller want an array... not null if empty
306
+ }
307
+ break;
308
+ }
309
+ return $ReturnData;
310
+ }
311
+
312
+ /**
313
+ * This workbook have a custom UI ?
314
+ *
315
+ * @return boolean true|false
316
+ */
317
+ public function hasRibbon()
318
+ {
319
+ return !is_null($this->ribbonXMLData);
320
+ }
321
+
322
+ /**
323
+ * This workbook have additionnal object for the ribbon ?
324
+ *
325
+ * @return boolean true|false
326
+ */
327
+ public function hasRibbonBinObjects()
328
+ {
329
+ return !is_null($this->ribbonBinObjects);
330
+ }
331
+
332
+ /**
333
  * Check if a sheet with a specified code name already exists
334
  *
335
  * @param string $pSheetCodeName Name of the worksheet to check
337
  */
338
  public function sheetCodeNameExists($pSheetCodeName)
339
  {
340
+ return ($this->getSheetByCodeName($pSheetCodeName) !== null);
341
+ }
342
+
343
+ /**
344
+ * Get sheet by code name. Warning : sheet don't have always a code name !
345
+ *
346
+ * @param string $pName Sheet name
347
+ * @return PHPExcel_Worksheet
348
+ */
349
+ public function getSheetByCodeName($pName = '')
350
+ {
351
+ $worksheetCount = count($this->workSheetCollection);
352
+ for ($i = 0; $i < $worksheetCount; ++$i) {
353
+ if ($this->workSheetCollection[$i]->getCodeName() == $pName) {
354
+ return $this->workSheetCollection[$i];
355
+ }
356
+ }
357
+
358
+ return null;
359
  }
360
 
361
+ /**
362
+ * Create a new PHPExcel with one Worksheet
363
+ */
364
+ public function __construct()
365
+ {
366
+ $this->uniqueID = uniqid();
367
+ $this->calculationEngine = new PHPExcel_Calculation($this);
368
+
369
+ // Initialise worksheet collection and add one worksheet
370
+ $this->workSheetCollection = array();
371
+ $this->workSheetCollection[] = new PHPExcel_Worksheet($this);
372
+ $this->activeSheetIndex = 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
373
 
374
  // Create document properties
375
+ $this->properties = new PHPExcel_DocumentProperties();
376
 
377
  // Create document security
378
+ $this->security = new PHPExcel_DocumentSecurity();
379
 
380
  // Set named ranges
381
+ $this->namedRanges = array();
382
 
383
  // Create the cellXf supervisor
384
+ $this->cellXfSupervisor = new PHPExcel_Style(true);
385
+ $this->cellXfSupervisor->bindParent($this);
386
 
387
  // Create the default style
388
  $this->addCellXf(new PHPExcel_Style);
393
  * Code to execute when this worksheet is unset()
394
  *
395
  */
396
+ public function __destruct()
397
+ {
398
+ $this->calculationEngine = null;
399
  $this->disconnectWorksheets();
400
+ }
401
 
402
  /**
403
  * Disconnect all worksheets from this PHPExcel workbook object,
406
  */
407
  public function disconnectWorksheets()
408
  {
409
+ $worksheet = null;
410
+ foreach ($this->workSheetCollection as $k => &$worksheet) {
411
  $worksheet->disconnectCells();
412
+ $this->workSheetCollection[$k] = null;
413
  }
414
  unset($worksheet);
415
+ $this->workSheetCollection = array();
416
  }
417
 
418
+ /**
419
+ * Return the calculation engine for this worksheet
420
+ *
421
+ * @return PHPExcel_Calculation
422
+ */
423
+ public function getCalculationEngine()
424
+ {
425
+ return $this->calculationEngine;
426
+ } // function getCellCacheController()
427
 
428
  /**
429
  * Get properties
432
  */
433
  public function getProperties()
434
  {
435
+ return $this->properties;
436
  }
437
 
438
  /**
442
  */
443
  public function setProperties(PHPExcel_DocumentProperties $pValue)
444
  {
445
+ $this->properties = $pValue;
446
  }
447
 
448
  /**
452
  */
453
  public function getSecurity()
454
  {
455
+ return $this->security;
456
  }
457
 
458
  /**
462
  */
463
  public function setSecurity(PHPExcel_DocumentSecurity $pValue)
464
  {
465
+ $this->security = $pValue;
466
  }
467
 
468
  /**
474
  */
475
  public function getActiveSheet()
476
  {
477
+ return $this->getSheet($this->activeSheetIndex);
478
  }
479
 
480
  /**
484
  * @return PHPExcel_Worksheet
485
  * @throws PHPExcel_Exception
486
  */
487
+ public function createSheet($iSheetIndex = null)
488
  {
489
  $newSheet = new PHPExcel_Worksheet($this);
490
  $this->addSheet($newSheet, $iSheetIndex);
499
  */
500
  public function sheetNameExists($pSheetName)
501
  {
502
+ return ($this->getSheetByName($pSheetName) !== null);
503
  }
504
 
505
  /**
510
  * @return PHPExcel_Worksheet
511
  * @throws PHPExcel_Exception
512
  */
513
+ public function addSheet(PHPExcel_Worksheet $pSheet, $iSheetIndex = null)
514
  {
515
  if ($this->sheetNameExists($pSheet->getTitle())) {
516
  throw new PHPExcel_Exception(
517
+ "Workbook already contains a worksheet named '{$pSheet->getTitle()}'. Rename this worksheet first."
518
  );
519
  }
520
 
521
+ if ($iSheetIndex === null) {
522
+ if ($this->activeSheetIndex < 0) {
523
+ $this->activeSheetIndex = 0;
524
  }
525
+ $this->workSheetCollection[] = $pSheet;
526
  } else {
527
  // Insert the sheet at the requested index
528
  array_splice(
529
+ $this->workSheetCollection,
530
  $iSheetIndex,
531
  0,
532
  array($pSheet)
533
+ );
534
 
535
  // Adjust active sheet index if necessary
536
+ if ($this->activeSheetIndex >= $iSheetIndex) {
537
+ ++$this->activeSheetIndex;
538
  }
539
  }
540
 
554
  public function removeSheetByIndex($pIndex = 0)
555
  {
556
 
557
+ $numSheets = count($this->workSheetCollection);
 
558
  if ($pIndex > $numSheets - 1) {
559
  throw new PHPExcel_Exception(
560
+ "You tried to remove a sheet by the out of bounds index: {$pIndex}. The actual number of sheets is {$numSheets}."
561
  );
562
  } else {
563
+ array_splice($this->workSheetCollection, $pIndex, 1);
564
  }
565
  // Adjust active sheet index if necessary
566
+ if (($this->activeSheetIndex >= $pIndex) &&
567
+ ($pIndex > count($this->workSheetCollection) - 1)) {
568
+ --$this->activeSheetIndex;
569
  }
570
 
571
  }
579
  */
580
  public function getSheet($pIndex = 0)
581
  {
582
+ if (!isset($this->workSheetCollection[$pIndex])) {
583
  $numSheets = $this->getSheetCount();
584
  throw new PHPExcel_Exception(
585
  "Your requested sheet index: {$pIndex} is out of bounds. The actual number of sheets is {$numSheets}."
586
  );
587
  }
588
 
589
+ return $this->workSheetCollection[$pIndex];
590
  }
591
 
592
  /**
596
  */
597
  public function getAllSheets()
598
  {
599
+ return $this->workSheetCollection;
600
  }
601
 
602
  /**
607
  */
608
  public function getSheetByName($pName = '')
609
  {
610
+ $worksheetCount = count($this->workSheetCollection);
611
  for ($i = 0; $i < $worksheetCount; ++$i) {
612
+ if ($this->workSheetCollection[$i]->getTitle() === $pName) {
613
+ return $this->workSheetCollection[$i];
614
  }
615
  }
616
 
617
+ return null;
618
  }
619
 
620
  /**
621
  * Get index for sheet
622
  *
623
  * @param PHPExcel_Worksheet $pSheet
624
+ * @return int Sheet index
625
  * @throws PHPExcel_Exception
626
  */
627
  public function getIndex(PHPExcel_Worksheet $pSheet)
628
  {
629
+ foreach ($this->workSheetCollection as $key => $value) {
630
  if ($value->getHashCode() == $pSheet->getHashCode()) {
631
  return $key;
632
  }
640
  *
641
  * @param string $sheetName Sheet name to modify index for
642
  * @param int $newIndex New index for the sheet
643
+ * @return int New sheet index
644
  * @throws PHPExcel_Exception
645
  */
646
  public function setIndexByName($sheetName, $newIndex)
647
  {
648
  $oldIndex = $this->getIndex($this->getSheetByName($sheetName));
649
  $pSheet = array_splice(
650
+ $this->workSheetCollection,
651
  $oldIndex,
652
  1
653
  );
654
  array_splice(
655
+ $this->workSheetCollection,
656
  $newIndex,
657
  0,
658
  $pSheet
667
  */
668
  public function getSheetCount()
669
  {
670
+ return count($this->workSheetCollection);
671
  }
672
 
673
  /**
677
  */
678
  public function getActiveSheetIndex()
679
  {
680
+ return $this->activeSheetIndex;
681
  }
682
 
683
  /**
689
  */
690
  public function setActiveSheetIndex($pIndex = 0)
691
  {
692
+ $numSheets = count($this->workSheetCollection);
693
 
694
  if ($pIndex > $numSheets - 1) {
695
  throw new PHPExcel_Exception(
696
+ "You tried to set a sheet active by the out of bounds index: {$pIndex}. The actual number of sheets is {$numSheets}."
697
  );
698
  } else {
699
+ $this->activeSheetIndex = $pIndex;
700
  }
701
  return $this->getActiveSheet();
702
  }
742
  * @throws PHPExcel_Exception
743
  * @return PHPExcel_Worksheet
744
  */
745
+ public function addExternalSheet(PHPExcel_Worksheet $pSheet, $iSheetIndex = null)
746
+ {
747
  if ($this->sheetNameExists($pSheet->getTitle())) {
748
  throw new PHPExcel_Exception("Workbook already contains a worksheet named '{$pSheet->getTitle()}'. Rename the external sheet first.");
749
  }
750
 
751
  // count how many cellXfs there are in this workbook currently, we will need this below
752
+ $countCellXfs = count($this->cellXfCollection);
753
 
754
  // copy all the shared cellXfs from the external workbook and append them to the current
755
  foreach ($pSheet->getParent()->getCellXfCollection() as $cellXf) {
762
  // update the cellXfs
763
  foreach ($pSheet->getCellCollection(false) as $cellID) {
764
  $cell = $pSheet->getCell($cellID);
765
+ $cell->setXfIndex($cell->getXfIndex() + $countCellXfs);
766
  }
767
 
768
  return $this->addSheet($pSheet, $iSheetIndex);
773
  *
774
  * @return PHPExcel_NamedRange[]
775
  */
776
+ public function getNamedRanges()
777
+ {
778
+ return $this->namedRanges;
779
  }
780
 
781
  /**
782
  * Add named range
783
  *
784
  * @param PHPExcel_NamedRange $namedRange
785
+ * @return boolean
786
  */
787
+ public function addNamedRange(PHPExcel_NamedRange $namedRange)
788
+ {
789
  if ($namedRange->getScope() == null) {
790
  // global scope
791
+ $this->namedRanges[$namedRange->getName()] = $namedRange;
792
  } else {
793
  // local scope
794
+ $this->namedRanges[$namedRange->getScope()->getTitle().'!'.$namedRange->getName()] = $namedRange;
795
  }
796
  return true;
797
  }
803
  * @param PHPExcel_Worksheet|null $pSheet Scope. Use null for global scope
804
  * @return PHPExcel_NamedRange|null
805
  */
806
+ public function getNamedRange($namedRange, PHPExcel_Worksheet $pSheet = null)
807
+ {
808
  $returnValue = null;
809
 
810
+ if ($namedRange != '' && ($namedRange !== null)) {
811
  // first look for global defined name
812
+ if (isset($this->namedRanges[$namedRange])) {
813
+ $returnValue = $this->namedRanges[$namedRange];
814
  }
815
 
816
  // then look for local defined name (has priority over global defined name if both names exist)
817
+ if (($pSheet !== null) && isset($this->namedRanges[$pSheet->getTitle() . '!' . $namedRange])) {
818
+ $returnValue = $this->namedRanges[$pSheet->getTitle() . '!' . $namedRange];
819
  }
820
  }
821
 
829
  * @param PHPExcel_Worksheet|null $pSheet Scope: use null for global scope.
830
  * @return PHPExcel
831
  */
832
+ public function removeNamedRange($namedRange, PHPExcel_Worksheet $pSheet = null)
833
+ {
834
+ if ($pSheet === null) {
835
+ if (isset($this->namedRanges[$namedRange])) {
836
+ unset($this->namedRanges[$namedRange]);
837
  }
838
  } else {
839
+ if (isset($this->namedRanges[$pSheet->getTitle() . '!' . $namedRange])) {
840
+ unset($this->namedRanges[$pSheet->getTitle() . '!' . $namedRange]);
841
  }
842
  }
843
  return $this;
848
  *
849
  * @return PHPExcel_WorksheetIterator
850
  */
851
+ public function getWorksheetIterator()
852
+ {
853
  return new PHPExcel_WorksheetIterator($this);
854
  }
855
 
858
  *
859
  * @return PHPExcel
860
  */
861
+ public function copy()
862
+ {
863
  $copied = clone $this;
864
 
865
+ $worksheetCount = count($this->workSheetCollection);
866
  for ($i = 0; $i < $worksheetCount; ++$i) {
867
+ $this->workSheetCollection[$i] = $this->workSheetCollection[$i]->copy();
868
+ $this->workSheetCollection[$i]->rebindParent($this);
869
  }
870
 
871
  return $copied;
874
  /**
875
  * Implement PHP __clone to create a deep clone, not just a shallow copy.
876
  */
877
+ public function __clone()
878
+ {
879
+ foreach ($this as $key => $val) {
880
  if (is_object($val) || (is_array($val))) {
881
  $this->{$key} = unserialize(serialize($val));
882
  }
890
  */
891
  public function getCellXfCollection()
892
  {
893
+ return $this->cellXfCollection;
894
  }
895
 
896
  /**
901
  */
902
  public function getCellXfByIndex($pIndex = 0)
903
  {
904
+ return $this->cellXfCollection[$pIndex];
905
  }
906
 
907
  /**
908
  * Get cellXf by hash code
909
  *
910
  * @param string $pValue
911
+ * @return PHPExcel_Style|boolean False if no match found
912
  */
913
  public function getCellXfByHashCode($pValue = '')
914
  {
915
+ foreach ($this->cellXfCollection as $cellXf) {
916
  if ($cellXf->getHashCode() == $pValue) {
917
  return $cellXf;
918
  }
928
  */
929
  public function cellXfExists($pCellStyle = null)
930
  {
931
+ return in_array($pCellStyle, $this->cellXfCollection, true);
932
  }
933
 
934
  /**
939
  */
940
  public function getDefaultStyle()
941
  {
942
+ if (isset($this->cellXfCollection[0])) {
943
+ return $this->cellXfCollection[0];
944
  }
945
  throw new PHPExcel_Exception('No default style found for this workbook');
946
  }
952
  */
953
  public function addCellXf(PHPExcel_Style $style)
954
  {
955
+ $this->cellXfCollection[] = $style;
956
+ $style->setIndex(count($this->cellXfCollection) - 1);
957
  }
958
 
959
  /**
960
  * Remove cellXf by index. It is ensured that all cells get their xf index updated.
961
  *
962
+ * @param integer $pIndex Index to cellXf
963
  * @throws PHPExcel_Exception
964
  */
965
  public function removeCellXfByIndex($pIndex = 0)
966
  {
967
+ if ($pIndex > count($this->cellXfCollection) - 1) {
968
  throw new PHPExcel_Exception("CellXf index is out of bounds.");
969
  } else {
970
  // first remove the cellXf
971
+ array_splice($this->cellXfCollection, $pIndex, 1);
972
 
973
  // then update cellXf indexes for cells
974
+ foreach ($this->workSheetCollection as $worksheet) {
975
  foreach ($worksheet->getCellCollection(false) as $cellID) {
976
  $cell = $worksheet->getCell($cellID);
977
  $xfIndex = $cell->getXfIndex();
978
+ if ($xfIndex > $pIndex) {
979
  // decrease xf index by 1
980
  $cell->setXfIndex($xfIndex - 1);
981
+ } elseif ($xfIndex == $pIndex) {
982
  // set to default xf index 0
983
  $cell->setXfIndex(0);
984
  }
994
  */
995
  public function getCellXfSupervisor()
996
  {
997
+ return $this->cellXfSupervisor;
998
  }
999
 
1000
  /**
1004
  */
1005
  public function getCellStyleXfCollection()
1006
  {
1007
+ return $this->cellStyleXfCollection;
1008
  }
1009
 
1010
  /**
1011
  * Get cellStyleXf by index
1012
  *
1013
+ * @param integer $pIndex Index to cellXf
1014
  * @return PHPExcel_Style
1015
  */
1016
  public function getCellStyleXfByIndex($pIndex = 0)
1017
  {
1018
+ return $this->cellStyleXfCollection[$pIndex];
1019
  }
1020
 
1021
  /**
1022
  * Get cellStyleXf by hash code
1023
  *
1024
  * @param string $pValue
1025
+ * @return PHPExcel_Style|boolean False if no match found
1026
  */
1027
  public function getCellStyleXfByHashCode($pValue = '')
1028
  {
1029
+ foreach ($this->cellStyleXfCollection as $cellStyleXf) {
1030
  if ($cellStyleXf->getHashCode() == $pValue) {
1031
  return $cellStyleXf;
1032
  }
1041
  */
1042
  public function addCellStyleXf(PHPExcel_Style $pStyle)
1043
  {
1044
+ $this->cellStyleXfCollection[] = $pStyle;
1045
+ $pStyle->setIndex(count($this->cellStyleXfCollection) - 1);
1046
  }
1047
 
1048
  /**
1049
  * Remove cellStyleXf by index
1050
  *
1051
+ * @param integer $pIndex Index to cellXf
1052
  * @throws PHPExcel_Exception
1053
  */
1054
  public function removeCellStyleXfByIndex($pIndex = 0)
1055
  {
1056
+ if ($pIndex > count($this->cellStyleXfCollection) - 1) {
1057
  throw new PHPExcel_Exception("CellStyleXf index is out of bounds.");
1058
  } else {
1059
+ array_splice($this->cellStyleXfCollection, $pIndex, 1);
1060
  }
1061
  }
1062
 
1068
  {
1069
  // how many references are there to each cellXf ?
1070
  $countReferencesCellXf = array();
1071
+ foreach ($this->cellXfCollection as $index => $cellXf) {
1072
  $countReferencesCellXf[$index] = 0;
1073
  }
1074
 
1075
  foreach ($this->getWorksheetIterator() as $sheet) {
 
1076
  // from cells
1077
  foreach ($sheet->getCellCollection(false) as $cellID) {
1078
  $cell = $sheet->getCell($cellID);
1095
  // remove cellXfs without references and create mapping so we can update xfIndex
1096
  // for all cells and columns
1097
  $countNeededCellXfs = 0;
1098
+ $map = array();
1099
+ foreach ($this->cellXfCollection as $index => $cellXf) {
1100
  if ($countReferencesCellXf[$index] > 0 || $index == 0) { // we must never remove the first cellXf
1101
  ++$countNeededCellXfs;
1102
  } else {
1103
+ unset($this->cellXfCollection[$index]);
1104
  }
1105
  $map[$index] = $countNeededCellXfs - 1;
1106
  }
1107
+ $this->cellXfCollection = array_values($this->cellXfCollection);
1108
 
1109
  // update the index for all cellXfs
1110
+ foreach ($this->cellXfCollection as $i => $cellXf) {
1111
  $cellXf->setIndex($i);
1112
  }
1113
 
1114
  // make sure there is always at least one cellXf (there should be)
1115
+ if (empty($this->cellXfCollection)) {
1116
+ $this->cellXfCollection[] = new PHPExcel_Style();
1117
  }
1118
 
1119
  // update the xfIndex for all cells, row dimensions, column dimensions
1120
  foreach ($this->getWorksheetIterator() as $sheet) {
 
1121
  // for all cells
1122
  foreach ($sheet->getCellCollection(false) as $cellID) {
1123
  $cell = $sheet->getCell($cellID);
1124
+ $cell->setXfIndex($map[$cell->getXfIndex()]);
1125
  }
1126
 
1127
  // for all row dimensions
1128
  foreach ($sheet->getRowDimensions() as $rowDimension) {
1129
  if ($rowDimension->getXfIndex() !== null) {
1130
+ $rowDimension->setXfIndex($map[$rowDimension->getXfIndex()]);
1131
  }
1132
  }
1133
 
1134
  // for all column dimensions
1135
  foreach ($sheet->getColumnDimensions() as $columnDimension) {
1136
+ $columnDimension->setXfIndex($map[$columnDimension->getXfIndex()]);
1137
  }
1138
 
1139
+ // also do garbage collection for all the sheets
1140
  $sheet->garbageCollect();
1141
  }
1142
  }
1146
  *
1147
  * @return string
1148
  */
1149
+ public function getID()
1150
+ {
1151
+ return $this->uniqueID;
1152
  }
 
1153
  }
classes/PHPExcel/Cell.php CHANGED
@@ -814,7 +814,12 @@ class PHPExcel_Cell
814
  $_indexCache[$pString] = $_columnLookup[$pString];
815
  return $_indexCache[$pString];
816
  } elseif (!isset($pString{2})) {
817
- $_indexCache[$pString] = $_columnLookup[$pString{0}] * 26 + $_columnLookup[$pString{1}];
 
 
 
 
 
818
  return $_indexCache[$pString];
819
  } elseif (!isset($pString{3})) {
820
  $_indexCache[$pString] = $_columnLookup[$pString{0}] * 676 + $_columnLookup[$pString{1}] * 26 + $_columnLookup[$pString{2}];
814
  $_indexCache[$pString] = $_columnLookup[$pString];
815
  return $_indexCache[$pString];
816
  } elseif (!isset($pString{2})) {
817
+ if (!isset($_columnLookup[$pString{0}]) || !isset($_columnLookup[$pString{1}])){
818
+ $_indexCache[$pString] = false;
819
+ }
820
+ else{
821
+ $_indexCache[$pString] = $_columnLookup[$pString{0}] * 26 + $_columnLookup[$pString{1}];
822
+ }
823
  return $_indexCache[$pString];
824
  } elseif (!isset($pString{3})) {
825
  $_indexCache[$pString] = $_columnLookup[$pString{0}] * 676 + $_columnLookup[$pString{1}] * 26 + $_columnLookup[$pString{2}];
classes/api.php CHANGED
@@ -384,6 +384,8 @@ class PMXI_API
384
  $image_filename = wp_unique_filename($targetDir, $image_name);
385
  $image_filepath = $targetDir . '/' . $image_filename;
386
 
 
 
387
  // do not download images
388
  if ( "yes" != $download_images ){
389
 
@@ -401,7 +403,6 @@ class PMXI_API
401
  if ($file_type == 'files'){
402
  if( ! $wp_filetype = wp_check_filetype(basename($image_filepath), null )) {
403
  $logger and call_user_func($logger, sprintf(__('- <b>WARNING</b>: Can\'t detect attachment file type %s', 'wp_all_import_plugin'), trim($image_filepath)));
404
- $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
405
  @unlink($image_filepath);
406
  }
407
  else {
@@ -453,7 +454,6 @@ class PMXI_API
453
  }
454
 
455
  if ( ! $result ){
456
- $url = str_replace(" ", "%20", trim(pmxi_convert_encoding($img_url)));
457
 
458
  $request = get_file_curl($url, $image_filepath);
459
 
384
  $image_filename = wp_unique_filename($targetDir, $image_name);
385
  $image_filepath = $targetDir . '/' . $image_filename;
386
 
387
+ $url = str_replace(" ", "%20", trim(pmxi_convert_encoding($img_url)));
388
+
389
  // do not download images
390
  if ( "yes" != $download_images ){
391
 
403
  if ($file_type == 'files'){
404
  if( ! $wp_filetype = wp_check_filetype(basename($image_filepath), null )) {
405
  $logger and call_user_func($logger, sprintf(__('- <b>WARNING</b>: Can\'t detect attachment file type %s', 'wp_all_import_plugin'), trim($image_filepath)));
 
406
  @unlink($image_filepath);
407
  }
408
  else {
454
  }
455
 
456
  if ( ! $result ){
 
457
 
458
  $request = get_file_curl($url, $image_filepath);
459
 
classes/chunk.php CHANGED
@@ -109,18 +109,16 @@ class PMXI_Chunk {
109
  return;
110
  }
111
 
 
 
 
 
112
  if ( PMXI_Plugin::getInstance()->getOption('force_stream_reader') )
113
  {
114
  $this->parser_type = 'xmlstreamer';
115
  }
116
  else
117
  {
118
- $input = new PMXI_Input();
119
-
120
- $import_id = $input->get('id', 0);
121
-
122
- if ( empty($import_id)) $import_id = $input->get('import_id', 0);
123
-
124
  if ( ! empty($import_id) )
125
  {
126
  $this->parser_type = empty($parser_type) ? 'xmlreader' : $parser_type;
@@ -200,6 +198,8 @@ class PMXI_Chunk {
200
  break;
201
  }
202
  }
 
 
203
  }
204
  }
205
 
109
  return;
110
  }
111
 
112
+ $input = new PMXI_Input();
113
+ $import_id = $input->get('id', 0);
114
+ if ( empty($import_id)) $import_id = $input->get('import_id', 0);
115
+
116
  if ( PMXI_Plugin::getInstance()->getOption('force_stream_reader') )
117
  {
118
  $this->parser_type = 'xmlstreamer';
119
  }
120
  else
121
  {
 
 
 
 
 
 
122
  if ( ! empty($import_id) )
123
  {
124
  $this->parser_type = empty($parser_type) ? 'xmlreader' : $parser_type;
198
  break;
199
  }
200
  }
201
+
202
+ $this->options['element'] = apply_filters('wp_all_import_root_element', $this->options['element'], $import_id, $this->cloud);
203
  }
204
  }
205
 
classes/render.php CHANGED
@@ -111,7 +111,7 @@ if ( ! class_exists('PMXI_Render')){
111
  else $path = $el->nodeName;
112
 
113
  foreach ($el->attributes as $attr) {
114
- echo '<option value="'.$path . '@' . $attr->nodeName.'">'. $path . '@' . $attr->nodeName . '</option>';
115
  }
116
  if ($el->hasChildNodes()) {
117
  foreach ($el->childNodes as $child) {
111
  else $path = $el->nodeName;
112
 
113
  foreach ($el->attributes as $attr) {
114
+ echo '<option value="'.$path . '/@' . $attr->nodeName.'">'. $path . '@' . $attr->nodeName . '</option>';
115
  }
116
  if ($el->hasChildNodes()) {
117
  foreach ($el->childNodes as $child) {
controllers/admin/import.php CHANGED
@@ -1507,17 +1507,13 @@ class PMXI_Admin_Import extends PMXI_Controller_Admin {
1507
  $post['custom_value'] = array_intersect_key($post['custom_value'], $not_empty);
1508
 
1509
  // validate
1510
- if (array_keys(array_filter($post['custom_name'], 'strlen')) != array_keys(array_filter($post['custom_value'], 'strlen')) and ! count(array_filter($post['custom_format'])) ) {
1511
- $this->errors->add('form-validation', __('Both name and value must be set for all custom parameters', 'wp_all_import_plugin'));
1512
- } else {
1513
- foreach ($post['custom_name'] as $custom_name) {
1514
- $this->_validate_template($custom_name, __('Custom Field Name', 'wp_all_import_plugin'));
1515
- }
1516
- foreach ($post['custom_value'] as $key => $custom_value) {
1517
- if ( empty($post['custom_format'][$key]) )
1518
- $this->_validate_template($custom_value, __('Custom Field Value', 'wp_all_import_plugin'));
1519
- }
1520
- }
1521
 
1522
  if ( $post['type'] == "post" and $post['custom_type'] == "product" and class_exists('PMWI_Plugin')){
1523
  // remove entires where both custom_name and custom_value are empty
@@ -1662,10 +1658,12 @@ class PMXI_Admin_Import extends PMXI_Controller_Admin {
1662
  protected function _validate_template($text, $field_title)
1663
  {
1664
  try {
1665
- $scanner = new XmlImportTemplateScanner();
1666
- $tokens = $scanner->scan(new XmlImportStringReader($text));
1667
- $parser = new XmlImportTemplateParser($tokens);
1668
- $tree = $parser->parse();
 
 
1669
  } catch (XmlImportException $e) {
1670
  $this->errors->add('form-validation', sprintf(__('%s template is invalid: %s', 'wp_all_import_plugin'), $field_title, $e->getMessage()));
1671
  }
1507
  $post['custom_value'] = array_intersect_key($post['custom_value'], $not_empty);
1508
 
1509
  // validate
1510
+ foreach ($post['custom_name'] as $custom_name) {
1511
+ $this->_validate_template($custom_name, __('Custom Field Name', 'wp_all_import_plugin'));
1512
+ }
1513
+ foreach ($post['custom_value'] as $key => $custom_value) {
1514
+ if ( empty($post['custom_format'][$key]) )
1515
+ $this->_validate_template($custom_value, __('Custom Field Value', 'wp_all_import_plugin'));
1516
+ }
 
 
 
 
1517
 
1518
  if ( $post['type'] == "post" and $post['custom_type'] == "product" and class_exists('PMWI_Plugin')){
1519
  // remove entires where both custom_name and custom_value are empty
1658
  protected function _validate_template($text, $field_title)
1659
  {
1660
  try {
1661
+ if ($text != ''){
1662
+ $scanner = new XmlImportTemplateScanner();
1663
+ $tokens = $scanner->scan(new XmlImportStringReader($text));
1664
+ $parser = new XmlImportTemplateParser($tokens);
1665
+ $tree = $parser->parse();
1666
+ }
1667
  } catch (XmlImportException $e) {
1668
  $this->errors->add('form-validation', sprintf(__('%s template is invalid: %s', 'wp_all_import_plugin'), $field_title, $e->getMessage()));
1669
  }
controllers/controller.php CHANGED
@@ -123,6 +123,7 @@ abstract class PMXI_Controller {
123
  $msgs = $this->warnings;
124
  }
125
  if (is_wp_error($msgs)) {
 
126
  $msgs = $msgs->get_error_messages();
127
  }
128
  if ( ! is_array($msgs)) {
123
  $msgs = $this->warnings;
124
  }
125
  if (is_wp_error($msgs)) {
126
+ unset($msgs->errors['root-element-validation']);
127
  $msgs = $msgs->get_error_messages();
128
  }
129
  if ( ! is_array($msgs)) {
helpers/functions.php CHANGED
@@ -35,6 +35,7 @@
35
  if (preg_match('%png%i', $content_type[1])) return 'png';
36
  if (preg_match('%gif%i', $content_type[1])) return 'gif';
37
  if (preg_match('%svg%i', $content_type[1])) return 'svg';
 
38
  return ($content_type[1] == "unknown") ? "" : $content_type[1];
39
  }
40
 
35
  if (preg_match('%png%i', $content_type[1])) return 'png';
36
  if (preg_match('%gif%i', $content_type[1])) return 'gif';
37
  if (preg_match('%svg%i', $content_type[1])) return 'svg';
38
+ if (preg_match('%pdf%i', $content_type[1])) return 'pdf';
39
  return ($content_type[1] == "unknown") ? "" : $content_type[1];
40
  }
41
 
helpers/wp_all_import_get_image_from_gallery.php CHANGED
@@ -12,28 +12,49 @@ function wp_all_import_get_image_from_gallery($image_name, $targetDir = false, $
12
 
13
  $attch = '';
14
 
15
- // search attachment by attached file
16
- $attachment_meta = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM " . $wpdb->postmeta . " WHERE meta_key = %s AND meta_value = %s OR meta_value LIKE %s;", '_wp_attached_file', $image_name, "%/" . $image_name ) );
17
 
18
- if ( ! empty($attachment_meta) )
19
- {
20
- $attch = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM " . $wpdb->posts . " WHERE ID = %d;", $attachment_meta->post_id ) );
21
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
  if ( empty($attch) )
24
- {
25
- // search attachment by file name with extension
26
- $attch = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM " . $wpdb->posts . " WHERE (post_title = %s OR post_title = %s OR post_name = %s) AND post_type = %s AND post_mime_type LIKE %s;", $image_name, preg_replace('/\\.[^.\\s]{3,4}$/', '', $image_name), sanitize_title($image_name), "attachment", "image%" ) );
27
-
28
- // search attachment by file name without extension
29
- if ( empty($attch) )
30
- {
31
- $attachment_title = explode(".", $image_name);
32
- if (is_array($attachment_title) and count($attachment_title) > 1) array_pop($attachment_title);
33
- $image_name = implode(".", $attachment_title);
34
 
35
- $attch = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM " . $wpdb->posts . " WHERE (post_title = %s OR post_title = %s OR post_name = %s) AND post_type = %s AND post_mime_type LIKE %s;", $image_name, preg_replace('/\\.[^.\\s]{3,4}$/', '', $image_name), sanitize_title($image_name), "attachment", "image%" ) );
36
- }
 
 
 
 
 
37
  }
38
 
39
  // search attachment by file headers
12
 
13
  $attch = '';
14
 
15
+ // search attachment by attached file
16
+ $attachment_metas = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM " . $wpdb->postmeta . " WHERE meta_key = %s AND (meta_value = %s OR meta_value LIKE %s);", '_wp_attached_file', $image_name, "%/" . $image_name ) );
17
 
18
+ // if (empty($attachment_metas)){
19
+ // $attachment_metas = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM " . $wpdb->postmeta . " WHERE meta_key = %s AND (meta_value = %s OR meta_value LIKE %s);", '_wp_attached_file', sanitize_file_name($image_name), "%/" . sanitize_file_name($image_name) ) );
20
+ // }
21
+
22
+ if ( ! empty($attachment_metas) )
23
+ {
24
+ foreach ($attachment_metas as $attachment_meta) {
25
+ $attch = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM " . $wpdb->posts . " WHERE ID = %d;", $attachment_meta->post_id ) );
26
+ if ( ! empty($attch) ) break;
27
+ }
28
+ }
29
+
30
+ if (empty($attch)){
31
+ $attachment_metas = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM " . $wpdb->postmeta . " WHERE meta_key = %s AND (meta_value = %s OR meta_value LIKE %s);", '_wp_attached_file', sanitize_file_name($image_name), "%/" . sanitize_file_name($image_name) ) );
32
+
33
+ if ( ! empty($attachment_metas) )
34
+ {
35
+ foreach ($attachment_metas as $attachment_meta) {
36
+ $attch = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM " . $wpdb->posts . " WHERE ID = %d;", $attachment_meta->post_id ) );
37
+ if ( ! empty($attch) ) break;
38
+ }
39
+ }
40
+ }
41
 
42
  if ( empty($attch) )
43
+ {
44
+ $wp_filetype = wp_check_filetype(basename($image_name), null );
45
+
46
+ if ( ! empty($wp_filetype['type'])){
47
+ // search attachment by file name with extension
48
+ $attch = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM " . $wpdb->posts . " WHERE (post_title = %s OR post_title = %s OR post_name = %s) AND post_type = %s AND post_mime_type = %s;", $image_name, preg_replace('/\\.[^.\\s]{3,4}$/', '', $image_name), sanitize_title($image_name), "attachment", $wp_filetype['type'] ) );
49
+ }
 
 
 
50
 
51
+ // search attachment by file name without extension
52
+ if ( empty($attch) ) {
53
+ $attachment_title = explode(".", $image_name);
54
+ if (is_array($attachment_title) and count($attachment_title) > 1) array_pop($attachment_title);
55
+ $image_name = implode(".", $attachment_title);
56
+ $attch = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM " . $wpdb->posts . " WHERE (post_title = %s OR post_title = %s OR post_name = %s) AND post_type = %s AND post_mime_type LIKE %s;", $image_name, preg_replace('/\\.[^.\\s]{3,4}$/', '', $image_name), sanitize_title($image_name), "attachment", "image%" ) );
57
+ }
58
  }
59
 
60
  // search attachment by file headers
helpers/wp_all_import_get_parent_post.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ function wp_all_import_get_parent_post($identity, $post_type, $import_type = 'post') {
3
+ $page = 0;
4
+ switch ($import_type) {
5
+ case 'post':
6
+ if ( ! empty($identity) ){
7
+ if (ctype_digit($identity)){
8
+ $page = get_post($identity);
9
+ }
10
+ else
11
+ {
12
+ $page = get_page_by_title($identity, OBJECT, $post_type);
13
+
14
+ if ( empty($page) ){
15
+ $args = array(
16
+ 'name' => $identity,
17
+ 'post_type' => $post_type,
18
+ 'post_status' => 'any',
19
+ 'numberposts' => 1
20
+ );
21
+ $my_posts = get_posts($args);
22
+ if ( $my_posts ) {
23
+ $page = $my_posts[0];
24
+ }
25
+ }
26
+ }
27
+ }
28
+ break;
29
+
30
+ case 'page':
31
+ $page = get_page_by_title($identity) or $page = get_page_by_path($identity) or ctype_digit($identity) and $page = get_post($identity);
32
+ break;
33
+
34
+ default:
35
+ # code...
36
+ break;
37
+ }
38
+ return (!empty($page)) ? (int) $page->ID : 0;
39
+ }
helpers/wp_all_import_sanitize_filename.php CHANGED
@@ -6,7 +6,10 @@ function wp_all_import_sanitize_filename($filename) {
6
  if ( ! empty($filename_parts) and count($filename_parts) > 1){
7
  $ext = end($filename_parts);
8
  // Replace all weird characters
9
- $sanitized = sanitize_file_name(substr($filename, 0, -(strlen($ext)+1)));
 
 
 
10
  // Replace dots inside filename
11
  //$sanitized = str_replace('.','-', $sanitized);
12
  return $sanitized . '.' . $ext;
6
  if ( ! empty($filename_parts) and count($filename_parts) > 1){
7
  $ext = end($filename_parts);
8
  // Replace all weird characters
9
+ $sanitized = substr($filename, 0, -(strlen($ext)+1));
10
+ $sanitized = str_replace("_", "willbetrimmed", $sanitized);
11
+ $sanitized = sanitize_file_name($sanitized);
12
+ $sanitized = str_replace("willbetrimmed", "_", $sanitized);
13
  // Replace dots inside filename
14
  //$sanitized = str_replace('.','-', $sanitized);
15
  return $sanitized . '.' . $ext;
libraries/XmlImportCsvParse.php CHANGED
@@ -975,7 +975,8 @@ class PMXI_CsvParser
975
  if ( ! empty($_GET['import_id']) ) $import_id = $_GET['import_id'];
976
 
977
  $create_new_headers = apply_filters('wp_all_import_auto_create_csv_headers', false, $import_id);
978
- $headers = array();
 
979
  while ($keys = fgetcsv($res, $l, $d, $e)) {
980
 
981
  $empty_columns = 0;
@@ -989,7 +990,15 @@ class PMXI_CsvParser
989
  $buf_keys = $keys;
990
  foreach ($keys as $key => $value) {
991
  if (!$create_new_headers and (preg_match('%\W(http:|https:|ftp:)$%i', $value) or is_numeric($value))) $create_new_headers = true;
 
992
  $value = trim(strtolower(preg_replace('/^[0-9]{1}/','el_', preg_replace('/[^a-z0-9_]/i', '', $value))));
 
 
 
 
 
 
 
993
  $value = (!empty($value)) ? $value : 'undefined' . $key;
994
  if (empty($headers[$value]))
995
  $headers[$value] = 1;
975
  if ( ! empty($_GET['import_id']) ) $import_id = $_GET['import_id'];
976
 
977
  $create_new_headers = apply_filters('wp_all_import_auto_create_csv_headers', false, $import_id);
978
+ $replace_first_number = apply_filters('wp_all_import_replace_first_number_in_headers', true, $import_id);
979
+ $headers = array();
980
  while ($keys = fgetcsv($res, $l, $d, $e)) {
981
 
982
  $empty_columns = 0;
990
  $buf_keys = $keys;
991
  foreach ($keys as $key => $value) {
992
  if (!$create_new_headers and (preg_match('%\W(http:|https:|ftp:)$%i', $value) or is_numeric($value))) $create_new_headers = true;
993
+ if ($replace_first_number){
994
  $value = trim(strtolower(preg_replace('/^[0-9]{1}/','el_', preg_replace('/[^a-z0-9_]/i', '', $value))));
995
+ }
996
+ else{
997
+ $value = preg_replace('/[^a-z0-9_]/i', '', $value);
998
+ if (preg_match('/^[0-9]{1}/', $value)){
999
+ $value = 'el_' . trim(strtolower($value));
1000
+ }
1001
+ }
1002
  $value = (!empty($value)) ? $value : 'undefined' . $key;
1003
  if (empty($headers[$value]))
1004
  $headers[$value] = 1;
libraries/XmlImportXLSParse.php CHANGED
@@ -34,6 +34,8 @@ class PMXI_XLSParser{
34
 
35
  $objPHPExcel = PHPExcel_IOFactory::load($this->_filename);
36
 
 
 
37
  $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'CSV')->setDelimiter(',')
38
  ->setEnclosure('"')
39
  ->setLineEnding("\r\n")
34
 
35
  $objPHPExcel = PHPExcel_IOFactory::load($this->_filename);
36
 
37
+ $objPHPExcel = apply_filters('wp_all_import_phpexcel_object', $objPHPExcel, $this->_filename);
38
+
39
  $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'CSV')->setDelimiter(',')
40
  ->setEnclosure('"')
41
  ->setLineEnding("\r\n")
models/import/record.php CHANGED
@@ -99,6 +99,10 @@ class PMXI_Import_Record extends PMXI_Model_Record {
99
 
100
  public $post_meta_to_insert = array();
101
 
 
 
 
 
102
  /**
103
  * Perform import operation
104
  * @param string $xml XML string to import
@@ -141,17 +145,17 @@ class PMXI_Import_Record extends PMXI_Model_Record {
141
 
142
  $chunk == 1 and $logger and call_user_func($logger, __('Composing excerpts...', 'wp_all_import_plugin'));
143
  $post_excerpt = array();
144
- if ( ! empty($this->options['post_excerpt']) ){
145
  $post_excerpt = XmlImportParser::factory($xml, $cxpath, $this->options['post_excerpt'], $file)->parse($records); $tmp_files[] = $file;
146
  }
147
  else{
148
  count($titles) and $post_excerpt = array_fill(0, count($titles), '');
149
- }
150
 
151
  if ( "xpath" == $this->options['status'] ){
152
  $chunk == 1 and $logger and call_user_func($logger, __('Composing statuses...', 'wp_all_import_plugin'));
153
  $post_status = array();
154
- if ( ! empty($this->options['status_xpath']) ){
155
  $post_status = XmlImportParser::factory($xml, $cxpath, $this->options['status_xpath'], $file)->parse($records); $tmp_files[] = $file;
156
  }
157
  else{
@@ -162,7 +166,7 @@ class PMXI_Import_Record extends PMXI_Model_Record {
162
  if ( "xpath" == $this->options['comment_status'] ){
163
  $chunk == 1 and $logger and call_user_func($logger, __('Composing comment statuses...', 'wp_all_import_plugin'));
164
  $comment_status = array();
165
- if (!empty($this->options['comment_status_xpath'])){
166
  $comment_status = XmlImportParser::factory($xml, $cxpath, $this->options['comment_status_xpath'], $file)->parse($records); $tmp_files[] = $file;
167
  }
168
  else{
@@ -231,108 +235,64 @@ class PMXI_Import_Record extends PMXI_Model_Record {
231
  if ( "no" == $this->options['is_multiple_page_parent'] ){
232
  $chunk == 1 and $logger and call_user_func($logger, __('Composing page parent...', 'wp_all_import_plugin'));
233
  $page_parent = array();
234
- if (!empty($this->options['single_page_parent'])){
235
  $page_parent = XmlImportParser::factory($xml, $cxpath, $this->options['single_page_parent'], $file)->parse($records); $tmp_files[] = $file;
236
- foreach ($page_parent as $key => $identity) {
237
-
238
- $page = 0;
239
- switch ($this->options['type']) {
240
-
241
- case 'post':
242
-
243
- if ( ! empty($identity) ){
244
-
245
- if (ctype_digit($identity)){
246
- $page = get_post($identity);
247
- }
248
- else
249
- {
250
- $page = get_page_by_title($identity, OBJECT, $post_type[$key]);
251
-
252
- if ( empty($page) ){
253
- $args = array(
254
- 'name' => $identity,
255
- 'post_type' => $post_type[$key],
256
- 'post_status' => 'any',
257
- 'numberposts' => 1
258
- );
259
- $my_posts = get_posts($args);
260
- if ( $my_posts ) {
261
- $page = $my_posts[0];
262
- }
263
- }
264
-
265
- }
266
-
267
- }
268
-
269
- break;
270
-
271
- case 'page':
272
-
273
- $page = get_page_by_title($identity) or $page = get_page_by_path($identity) or ctype_digit($identity) and $page = get_post($identity);
274
-
275
- break;
276
-
277
- default:
278
- # code...
279
- break;
280
- }
281
-
282
- $page_parent[$key] = (!empty($page)) ? $page->ID : 0;
283
-
284
-
285
- }
286
  }
287
  else{
288
  count($titles) and $page_parent = array_fill(0, count($titles), 0);
289
  }
290
  }
291
 
292
- $chunk == 1 and $logger and call_user_func($logger, __('Composing authors...', 'wp_all_import_plugin'));
293
- $post_author = array();
294
- $current_user = wp_get_current_user();
 
295
 
296
- if (!empty($this->options['author'])){
297
- $post_author = XmlImportParser::factory($xml, $cxpath, $this->options['author'], $file)->parse($records); $tmp_files[] = $file;
298
- foreach ($post_author as $key => $author) {
299
- $user = get_user_by('login', $author) or $user = get_user_by('slug', $author) or $user = get_user_by('email', $author) or ctype_digit($author) and $user = get_user_by('id', $author);
300
- if (!empty($user))
301
- {
302
- $post_author[$key] = $user->ID;
303
- }
304
- else{
305
- if ($current_user->ID){
306
- $post_author[$key] = $current_user->ID;
307
- }
308
  else{
309
- $super_admins = get_super_admins();
310
- if ( ! empty($super_admins)){
311
- $sauthor = array_shift($super_admins);
312
- $user = get_user_by('login', $sauthor) or $user = get_user_by('slug', $sauthor) or $user = get_user_by('email', $sauthor) or ctype_digit($sauthor) and $user = get_user_by('id', $sauthor);
313
- $post_author[$key] = (!empty($user)) ? $user->ID : $current_user->ID;
314
- }
 
 
 
 
 
315
  }
316
  }
317
  }
318
- }
319
- else{
320
- if ($current_user->ID){
321
- count($titles) and $post_author = array_fill(0, count($titles), $current_user->ID);
322
- }
323
- else{
324
- $super_admins = get_super_admins();
325
- if ( ! empty($super_admins)){
326
- $author = array_shift($super_admins);
327
- $user = get_user_by('login', $author) or $user = get_user_by('slug', $author) or $user = get_user_by('email', $author) or ctype_digit($author) and $user = get_user_by('id', $author);
328
- count($titles) and $post_author = array_fill(0, count($titles), (!empty($user)) ? $user->ID : $current_user->ID);
329
- }
330
- }
331
- }
 
 
 
 
332
 
333
  $chunk == 1 and $logger and call_user_func($logger, __('Composing slugs...', 'wp_all_import_plugin'));
334
  $post_slug = array();
335
- if (!empty($this->options['post_slug'])){
336
  $post_slug = XmlImportParser::factory($xml, $cxpath, $this->options['post_slug'], $file)->parse($records); $tmp_files[] = $file;
337
  }
338
  else{
@@ -341,7 +301,7 @@ class PMXI_Import_Record extends PMXI_Model_Record {
341
 
342
  $chunk == 1 and $logger and call_user_func($logger, __('Composing menu order...', 'wp_all_import_plugin'));
343
  $menu_order = array();
344
- if (!empty($this->options['order'])){
345
  $menu_order = XmlImportParser::factory($xml, $cxpath, $this->options['order'], $file)->parse($records); $tmp_files[] = $file;
346
  }
347
  else{
@@ -349,7 +309,7 @@ class PMXI_Import_Record extends PMXI_Model_Record {
349
  }
350
 
351
  $chunk == 1 and $logger and call_user_func($logger, __('Composing contents...', 'wp_all_import_plugin'));
352
- if (!empty($this->options['content'])){
353
  $contents = XmlImportParser::factory(
354
  ((!empty($this->options['is_keep_linebreaks']) and intval($this->options['is_keep_linebreaks'])) ? $xml : preg_replace('%\r\n?|\n%', ' ', $xml)),
355
  $cxpath,
@@ -362,39 +322,44 @@ class PMXI_Import_Record extends PMXI_Model_Record {
362
  }
363
 
364
  $chunk == 1 and $logger and call_user_func($logger, __('Composing dates...', 'wp_all_import_plugin'));
365
- if ('specific' == $this->options['date_type']) {
366
- $dates = XmlImportParser::factory($xml, $cxpath, $this->options['date'], $file)->parse($records); $tmp_files[] = $file;
367
- $warned = array(); // used to prevent the same notice displaying several times
368
- foreach ($dates as $i => $d) {
369
- if ($d == 'now') $d = current_time('mysql'); // Replace 'now' with the WordPress local time to account for timezone offsets (WordPress references its local time during publishing rather than the server’s time so it should use that)
370
- $time = strtotime($d);
371
- if (FALSE === $time) {
372
- in_array($d, $warned) or $logger and call_user_func($logger, sprintf(__('<b>WARNING</b>: unrecognized date format `%s`, assigning current date', 'wp_all_import_plugin'), $warned[] = $d));
373
- $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
374
- $time = time();
 
 
 
375
  }
376
- $dates[$i] = date('Y-m-d H:i:s', $time);
377
- }
378
- } else {
379
- $dates_start = XmlImportParser::factory($xml, $cxpath, $this->options['date_start'], $file)->parse($records); $tmp_files[] = $file;
380
- $dates_end = XmlImportParser::factory($xml, $cxpath, $this->options['date_end'], $file)->parse($records); $tmp_files[] = $file;
381
- $warned = array(); // used to prevent the same notice displaying several times
382
- foreach ($dates_start as $i => $d) {
383
- $time_start = strtotime($dates_start[$i]);
384
- if (FALSE === $time_start) {
385
- in_array($dates_start[$i], $warned) or $logger and call_user_func($logger, sprintf(__('<b>WARNING</b>: unrecognized date format `%s`, assigning current date', 'wp_all_import_plugin'), $warned[] = $dates_start[$i]));
386
- $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
387
- $time_start = time();
 
 
 
 
 
 
388
  }
389
- $time_end = strtotime($dates_end[$i]);
390
- if (FALSE === $time_end) {
391
- in_array($dates_end[$i], $warned) or $logger and call_user_func($logger, sprintf(__('<b>WARNING</b>: unrecognized date format `%s`, assigning current date', 'wp_all_import_plugin'), $warned[] = $dates_end[$i]));
392
- $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
393
- $time_end = time();
394
- }
395
- $dates[$i] = date('Y-m-d H:i:s', mt_rand($time_start, $time_end));
396
  }
397
- }
 
 
 
398
 
399
  // [custom taxonomies]
400
  require_once(ABSPATH . 'wp-admin/includes/taxonomy.php');
@@ -402,7 +367,7 @@ class PMXI_Import_Record extends PMXI_Model_Record {
402
  $taxonomies = array();
403
  $exclude_taxonomies = apply_filters('pmxi_exclude_taxonomies', (class_exists('PMWI_Plugin')) ? array('post_format', 'product_type', 'product_shipping_class') : array('post_format'));
404
  $post_taxonomies = array_diff_key(get_taxonomies_by_object_type(array($this->options['custom_type']), 'object'), array_flip($exclude_taxonomies));
405
- if ( ! empty($post_taxonomies) && $this->options['custom_type'] != 'import_users' ):
406
  foreach ($post_taxonomies as $ctx): if ("" == $ctx->labels->name or (class_exists('PMWI_Plugin') and strpos($ctx->name, "pa_") === 0 and $this->options['custom_type'] == "product")) continue;
407
  $chunk == 1 and $logger and call_user_func($logger, sprintf(__('Composing terms for `%s` taxonomy...', 'wp_all_import_plugin'), $ctx->labels->name));
408
  $tx_name = $ctx->name;
@@ -636,6 +601,8 @@ class PMXI_Import_Record extends PMXI_Model_Record {
636
  $image_meta_captions_bundle = array();
637
  $image_meta_alts_bundle = array();
638
  $image_meta_descriptions_bundle = array();
 
 
639
  foreach ($image_sections as $section) {
640
  $chunk == 1 and $logger and call_user_func($logger, __('Composing URLs for ' . strtolower($section['title']) . '...', 'wp_all_import_plugin'));
641
  $featured_images = array();
@@ -740,6 +707,7 @@ class PMXI_Import_Record extends PMXI_Model_Record {
740
 
741
  }
742
  }
 
743
 
744
  // Composing attachments
745
  if ( ! (($uploads = wp_upload_dir()) && false === $uploads['error'])) {
@@ -750,7 +718,7 @@ class PMXI_Import_Record extends PMXI_Model_Record {
750
  $chunk == 1 and $logger and call_user_func($logger, __('Composing URLs for attachments files...', 'wp_all_import_plugin'));
751
  $attachments = array();
752
 
753
- if ($this->options['attachments']) {
754
  // Detect if attachments is separated by comma
755
  $atchs = empty($this->options['atch_delim']) ? explode(',', $this->options['attachments']) : explode($this->options['atch_delim'], $this->options['attachments']);
756
  if (!empty($atchs)){
@@ -912,8 +880,12 @@ class PMXI_Import_Record extends PMXI_Model_Record {
912
  'post_date_gmt' => get_gmt_from_date($dates[$i]),
913
  'post_author' => $post_author[$i],
914
  'menu_order' => (int) $menu_order[$i],
915
- 'post_parent' => ("no" == $this->options['is_multiple_page_parent']) ? (int) $page_parent[$i] : (int) $this->options['parent']
 
916
  ), $this->options['custom_type'], $this->id, $i);
 
 
 
917
  $logger and call_user_func($logger, sprintf(__('Combine all data for post `%s`...', 'wp_all_import_plugin'), $articleData['post_title']));
918
 
919
  // if ( "xpath" == $this->options['status'] )
@@ -1348,7 +1320,14 @@ class PMXI_Import_Record extends PMXI_Model_Record {
1348
  $logger and call_user_func($logger, __('<b>ERROR</b>', 'wp_all_import_plugin') . ': ' . $pid->get_error_message());
1349
  $logger and !$is_cron and PMXI_Plugin::$session->errors++;
1350
  $skipped++;
1351
- } else {
 
 
 
 
 
 
 
1352
 
1353
  if ("manual" != $this->options['duplicate_matching'] or empty($articleData['ID'])){
1354
  // associate post with import
@@ -1485,7 +1464,8 @@ class PMXI_Import_Record extends PMXI_Model_Record {
1485
  // [/custom fields]
1486
 
1487
  // Page Template
1488
- if ( ! empty($articleData['post_type']) and 'page' == $articleData['post_type'] and wp_all_import_is_update_cf('_wp_page_template', $this->options) and ( !empty($this->options['page_template']) or "no" == $this->options['is_multiple_page_template']) ){
 
1489
  update_post_meta($pid, '_wp_page_template', ("no" == $this->options['is_multiple_page_template']) ? $page_template[$i] : $this->options['page_template']);
1490
  }
1491
 
@@ -1637,7 +1617,7 @@ class PMXI_Import_Record extends PMXI_Model_Record {
1637
  $logger and call_user_func($logger, sprintf(__('- Importing image `%s` for `%s` ...', 'wp_all_import_plugin'), $img_url, $articleData['post_title']));
1638
 
1639
  // generate local file name
1640
- $image_name = urldecode(($this->options[$option_slug . 'auto_rename_images'] and !empty($auto_rename_images_bundle[$slug][$i])) ? sanitize_file_name(($img_ext) ? str_replace("." . $default_extension, "", $auto_rename_images_bundle[$slug][$i]) : $auto_rename_images_bundle[$slug][$i]) : sanitize_file_name((($img_ext) ? str_replace("." . $default_extension, "", $bn) : $bn))) . (("" != $img_ext) ? '.' . $img_ext : '');
1641
  $image_name = apply_filters("wp_all_import_image_filename", $image_name, empty($img_titles[$k]) ? '' : $img_titles[$k], empty($img_captions[$k]) ? '' : $img_captions[$k], empty($img_alts[$k]) ? '' : $img_alts[$k], $articleData, $this->id);
1642
 
1643
  // if wizard store image data to custom field
@@ -1648,21 +1628,48 @@ class PMXI_Import_Record extends PMXI_Model_Record {
1648
  $is_base64_images_allowed = apply_filters("wp_all_import_is_base64_images_allowed", true, $url, $this->id);
1649
 
1650
  if ( $bundle_data['type'] == 'images' and base64_encode(base64_decode($url)) == $url and $is_base64_images_allowed ){
1651
- $img = @imagecreatefromstring(base64_decode($url));
1652
- if($img)
1653
- {
1654
- $logger and call_user_func($logger, __('- found base64_encoded image', 'wp_all_import_plugin'));
1655
-
1656
- $image_filename = md5(time()) . '.jpg';
1657
- $image_filepath = $targetDir . '/' . $image_filename;
1658
- imagejpeg($img, $image_filepath);
1659
- if( ! ($image_info = apply_filters('pmxi_getimagesize', @getimagesize($image_filepath), $image_filepath)) or ! in_array($image_info[2], array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) {
1660
- $logger and call_user_func($logger, sprintf(__('- <b>WARNING</b>: File %s is not a valid image and cannot be set as featured one', 'wp_all_import_plugin'), $image_filepath));
1661
- $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
1662
- } else {
1663
- $create_image = true;
1664
- }
1665
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1666
  }
1667
 
1668
  if ( ! $create_image ) {
@@ -2042,11 +2049,12 @@ class PMXI_Import_Record extends PMXI_Model_Record {
2042
 
2043
  if ($this->options['is_search_existing_attach']){
2044
  // search existing attachment
2045
- $attch = $this->wpdb->get_row( $this->wpdb->prepare( "SELECT * FROM " . $this->wpdb->posts . " WHERE (post_title = %s OR post_title = %s OR post_name = %s OR post_name = %s) AND post_type = %s;", $attachment_filename, preg_replace('/\\.[^.\\s]{3,4}$/', '', $attachment_filename), sanitize_title($attachment_filename), sanitize_title(preg_replace('/\\.[^.\\s]{3,4}$/', '', $attachment_filename)), "attachment" ) );
2046
 
2047
  if ( $attch != null ){
2048
  $download_file = false;
2049
  $attach_id = $attch->ID;
 
2050
  }
2051
  }
2052
 
@@ -2099,7 +2107,26 @@ class PMXI_Import_Record extends PMXI_Model_Record {
2099
  }
2100
  }
2101
  }
2102
- else{
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2103
  $logger and call_user_func($logger, __('- <b>ACTION</b>: pmxi_attachment_uploaded', 'wp_all_import_plugin'));
2104
  do_action( 'pmxi_attachment_uploaded', $pid, $attach_id, $attachment_filepath);
2105
  }
@@ -2256,8 +2283,8 @@ class PMXI_Import_Record extends PMXI_Model_Record {
2256
  $is_update = ! empty($articleData['ID']);
2257
 
2258
  // fire important hooks after custom fields are added
2259
- if ( ! $this->options['is_fast_mode'] and $this->options['custom_type'] != 'import_users'){
2260
- $post_object = get_post( $pid );
2261
  do_action( "save_post_" . $articleData['post_type'], $pid, $post_object, $is_update );
2262
  do_action( 'save_post', $pid, $post_object, $is_update );
2263
  do_action( 'wp_insert_post', $pid, $post_object, $is_update );
99
 
100
  public $post_meta_to_insert = array();
101
 
102
+ public function is_parsing_required( $option ){
103
+ return ($this->options['update_all_data'] == 'yes' || $this->options[$option] || $this->options['create_new_records']) ? true : false;
104
+ }
105
+
106
  /**
107
  * Perform import operation
108
  * @param string $xml XML string to import
145
 
146
  $chunk == 1 and $logger and call_user_func($logger, __('Composing excerpts...', 'wp_all_import_plugin'));
147
  $post_excerpt = array();
148
+ if ( ! empty($this->options['post_excerpt']) && $this->is_parsing_required('is_update_excerpt')){
149
  $post_excerpt = XmlImportParser::factory($xml, $cxpath, $this->options['post_excerpt'], $file)->parse($records); $tmp_files[] = $file;
150
  }
151
  else{
152
  count($titles) and $post_excerpt = array_fill(0, count($titles), '');
153
+ }
154
 
155
  if ( "xpath" == $this->options['status'] ){
156
  $chunk == 1 and $logger and call_user_func($logger, __('Composing statuses...', 'wp_all_import_plugin'));
157
  $post_status = array();
158
+ if ( ! empty($this->options['status_xpath']) && $this->is_parsing_required('is_update_status') ){
159
  $post_status = XmlImportParser::factory($xml, $cxpath, $this->options['status_xpath'], $file)->parse($records); $tmp_files[] = $file;
160
  }
161
  else{
166
  if ( "xpath" == $this->options['comment_status'] ){
167
  $chunk == 1 and $logger and call_user_func($logger, __('Composing comment statuses...', 'wp_all_import_plugin'));
168
  $comment_status = array();
169
+ if (!empty($this->options['comment_status_xpath']) && $this->is_parsing_required('is_update_comment_status') ){
170
  $comment_status = XmlImportParser::factory($xml, $cxpath, $this->options['comment_status_xpath'], $file)->parse($records); $tmp_files[] = $file;
171
  }
172
  else{
235
  if ( "no" == $this->options['is_multiple_page_parent'] ){
236
  $chunk == 1 and $logger and call_user_func($logger, __('Composing page parent...', 'wp_all_import_plugin'));
237
  $page_parent = array();
238
+ if ( ! empty($this->options['single_page_parent']) && $this->is_parsing_required('is_update_parent') ){
239
  $page_parent = XmlImportParser::factory($xml, $cxpath, $this->options['single_page_parent'], $file)->parse($records); $tmp_files[] = $file;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
240
  }
241
  else{
242
  count($titles) and $page_parent = array_fill(0, count($titles), 0);
243
  }
244
  }
245
 
246
+ if ( $this->is_parsing_required('is_update_author') ){
247
+ $chunk == 1 and $logger and call_user_func($logger, __('Composing authors...', 'wp_all_import_plugin'));
248
+ $post_author = array();
249
+ $current_user = wp_get_current_user();
250
 
251
+ if (!empty($this->options['author'])){
252
+ $post_author = XmlImportParser::factory($xml, $cxpath, $this->options['author'], $file)->parse($records); $tmp_files[] = $file;
253
+ foreach ($post_author as $key => $author) {
254
+ $user = get_user_by('login', $author) or $user = get_user_by('slug', $author) or $user = get_user_by('email', $author) or ctype_digit($author) and $user = get_user_by('id', $author);
255
+ if (!empty($user))
256
+ {
257
+ $post_author[$key] = $user->ID;
258
+ }
 
 
 
 
259
  else{
260
+ if ($current_user->ID){
261
+ $post_author[$key] = $current_user->ID;
262
+ }
263
+ else{
264
+ $super_admins = get_super_admins();
265
+ if ( ! empty($super_admins)){
266
+ $sauthor = array_shift($super_admins);
267
+ $user = get_user_by('login', $sauthor) or $user = get_user_by('slug', $sauthor) or $user = get_user_by('email', $sauthor) or ctype_digit($sauthor) and $user = get_user_by('id', $sauthor);
268
+ $post_author[$key] = (!empty($user)) ? $user->ID : $current_user->ID;
269
+ }
270
+ }
271
  }
272
  }
273
  }
274
+ else{
275
+ if ($current_user->ID){
276
+ count($titles) and $post_author = array_fill(0, count($titles), $current_user->ID);
277
+ }
278
+ else{
279
+ $super_admins = get_super_admins();
280
+ if ( ! empty($super_admins)){
281
+ $author = array_shift($super_admins);
282
+ $user = get_user_by('login', $author) or $user = get_user_by('slug', $author) or $user = get_user_by('email', $author) or ctype_digit($author) and $user = get_user_by('id', $author);
283
+ count($titles) and $post_author = array_fill(0, count($titles), (!empty($user)) ? $user->ID : $current_user->ID);
284
+ }
285
+ }
286
+ }
287
+ }
288
+ else{
289
+ $current_user = wp_get_current_user();
290
+ count($titles) and $post_author = array_fill(0, count($titles), $current_user->ID);
291
+ }
292
 
293
  $chunk == 1 and $logger and call_user_func($logger, __('Composing slugs...', 'wp_all_import_plugin'));
294
  $post_slug = array();
295
+ if (!empty($this->options['post_slug']) && $this->is_parsing_required('is_update_slug') ){
296
  $post_slug = XmlImportParser::factory($xml, $cxpath, $this->options['post_slug'], $file)->parse($records); $tmp_files[] = $file;
297
  }
298
  else{
301
 
302
  $chunk == 1 and $logger and call_user_func($logger, __('Composing menu order...', 'wp_all_import_plugin'));
303
  $menu_order = array();
304
+ if (!empty($this->options['order']) && $this->is_parsing_required('is_update_menu_order')){
305
  $menu_order = XmlImportParser::factory($xml, $cxpath, $this->options['order'], $file)->parse($records); $tmp_files[] = $file;
306
  }
307
  else{
309
  }
310
 
311
  $chunk == 1 and $logger and call_user_func($logger, __('Composing contents...', 'wp_all_import_plugin'));
312
+ if (!empty($this->options['content']) && $this->is_parsing_required('is_update_content') ){
313
  $contents = XmlImportParser::factory(
314
  ((!empty($this->options['is_keep_linebreaks']) and intval($this->options['is_keep_linebreaks'])) ? $xml : preg_replace('%\r\n?|\n%', ' ', $xml)),
315
  $cxpath,
322
  }
323
 
324
  $chunk == 1 and $logger and call_user_func($logger, __('Composing dates...', 'wp_all_import_plugin'));
325
+ if ( $this->is_parsing_required('is_update_dates') ){
326
+ if ('specific' == $this->options['date_type']) {
327
+ $dates = XmlImportParser::factory($xml, $cxpath, $this->options['date'], $file)->parse($records); $tmp_files[] = $file;
328
+ $warned = array(); // used to prevent the same notice displaying several times
329
+ foreach ($dates as $i => $d) {
330
+ if ($d == 'now') $d = current_time('mysql'); // Replace 'now' with the WordPress local time to account for timezone offsets (WordPress references its local time during publishing rather than the server’s time so it should use that)
331
+ $time = strtotime($d);
332
+ if (FALSE === $time) {
333
+ in_array($d, $warned) or $logger and call_user_func($logger, sprintf(__('<b>WARNING</b>: unrecognized date format `%s`, assigning current date', 'wp_all_import_plugin'), $warned[] = $d));
334
+ $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
335
+ $time = time();
336
+ }
337
+ $dates[$i] = date('Y-m-d H:i:s', $time);
338
  }
339
+ } else {
340
+ $dates_start = XmlImportParser::factory($xml, $cxpath, $this->options['date_start'], $file)->parse($records); $tmp_files[] = $file;
341
+ $dates_end = XmlImportParser::factory($xml, $cxpath, $this->options['date_end'], $file)->parse($records); $tmp_files[] = $file;
342
+ $warned = array(); // used to prevent the same notice displaying several times
343
+ foreach ($dates_start as $i => $d) {
344
+ $time_start = strtotime($dates_start[$i]);
345
+ if (FALSE === $time_start) {
346
+ in_array($dates_start[$i], $warned) or $logger and call_user_func($logger, sprintf(__('<b>WARNING</b>: unrecognized date format `%s`, assigning current date', 'wp_all_import_plugin'), $warned[] = $dates_start[$i]));
347
+ $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
348
+ $time_start = time();
349
+ }
350
+ $time_end = strtotime($dates_end[$i]);
351
+ if (FALSE === $time_end) {
352
+ in_array($dates_end[$i], $warned) or $logger and call_user_func($logger, sprintf(__('<b>WARNING</b>: unrecognized date format `%s`, assigning current date', 'wp_all_import_plugin'), $warned[] = $dates_end[$i]));
353
+ $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
354
+ $time_end = time();
355
+ }
356
+ $dates[$i] = date('Y-m-d H:i:s', mt_rand($time_start, $time_end));
357
  }
 
 
 
 
 
 
 
358
  }
359
+ }
360
+ else{
361
+ count($titles) and $dates = array_fill(0, count($titles), date('Y-m-d H:i:s', strtotime(current_time('mysql'))));
362
+ }
363
 
364
  // [custom taxonomies]
365
  require_once(ABSPATH . 'wp-admin/includes/taxonomy.php');
367
  $taxonomies = array();
368
  $exclude_taxonomies = apply_filters('pmxi_exclude_taxonomies', (class_exists('PMWI_Plugin')) ? array('post_format', 'product_type', 'product_shipping_class') : array('post_format'));
369
  $post_taxonomies = array_diff_key(get_taxonomies_by_object_type(array($this->options['custom_type']), 'object'), array_flip($exclude_taxonomies));
370
+ if ( $this->is_parsing_required('is_update_categories') && ! empty($post_taxonomies) && ! in_array($this->options['custom_type'], array('import_users', 'taxonomies')) ):
371
  foreach ($post_taxonomies as $ctx): if ("" == $ctx->labels->name or (class_exists('PMWI_Plugin') and strpos($ctx->name, "pa_") === 0 and $this->options['custom_type'] == "product")) continue;
372
  $chunk == 1 and $logger and call_user_func($logger, sprintf(__('Composing terms for `%s` taxonomy...', 'wp_all_import_plugin'), $ctx->labels->name));
373
  $tx_name = $ctx->name;
601
  $image_meta_captions_bundle = array();
602
  $image_meta_alts_bundle = array();
603
  $image_meta_descriptions_bundle = array();
604
+
605
+ if ( $this->options['update_all_data'] == 'yes' || $this->options['is_update_images'] ){
606
  foreach ($image_sections as $section) {
607
  $chunk == 1 and $logger and call_user_func($logger, __('Composing URLs for ' . strtolower($section['title']) . '...', 'wp_all_import_plugin'));
608
  $featured_images = array();
707
 
708
  }
709
  }
710
+ }
711
 
712
  // Composing attachments
713
  if ( ! (($uploads = wp_upload_dir()) && false === $uploads['error'])) {
718
  $chunk == 1 and $logger and call_user_func($logger, __('Composing URLs for attachments files...', 'wp_all_import_plugin'));
719
  $attachments = array();
720
 
721
+ if ($this->options['attachments'] && $this->is_parsing_required('is_update_attachments') ) {
722
  // Detect if attachments is separated by comma
723
  $atchs = empty($this->options['atch_delim']) ? explode(',', $this->options['attachments']) : explode($this->options['atch_delim'], $this->options['attachments']);
724
  if (!empty($atchs)){
880
  'post_date_gmt' => get_gmt_from_date($dates[$i]),
881
  'post_author' => $post_author[$i],
882
  'menu_order' => (int) $menu_order[$i],
883
+ 'post_parent' => ("no" == $this->options['is_multiple_page_parent']) ? wp_all_import_get_parent_post($page_parent[$i], $post_type[$i], $this->options['type']) : (int) $this->options['parent'],
884
+ 'page_template' => ("no" == $this->options['is_multiple_page_template']) ? $page_template[$i] : $this->options['page_template']
885
  ), $this->options['custom_type'], $this->id, $i);
886
+ if ( 'shop_coupon' == $post_type[$i] ){
887
+ $articleData['post_excerpt'] = $articleData['post_content'];
888
+ }
889
  $logger and call_user_func($logger, sprintf(__('Combine all data for post `%s`...', 'wp_all_import_plugin'), $articleData['post_title']));
890
 
891
  // if ( "xpath" == $this->options['status'] )
1320
  $logger and call_user_func($logger, __('<b>ERROR</b>', 'wp_all_import_plugin') . ': ' . $pid->get_error_message());
1321
  $logger and !$is_cron and PMXI_Plugin::$session->errors++;
1322
  $skipped++;
1323
+ } else {
1324
+
1325
+ if (empty($articleData['post_parent']) && !empty($page_parent[$i])){
1326
+ $parent_posts = get_option('wp_all_import_posts_hierarchy_' . $this->id);
1327
+ if (empty($parent_posts)) $parent_posts = array();
1328
+ $parent_posts[$pid] = $page_parent[$i];
1329
+ update_option('wp_all_import_posts_hierarchy_' . $this->id, $parent_posts);
1330
+ }
1331
 
1332
  if ("manual" != $this->options['duplicate_matching'] or empty($articleData['ID'])){
1333
  // associate post with import
1464
  // [/custom fields]
1465
 
1466
  // Page Template
1467
+ global $wp_version;
1468
+ if ( ! empty($articleData['post_type']) and ('page' == $articleData['post_type'] || version_compare($wp_version, '4.7.0', '>=')) and wp_all_import_is_update_cf('_wp_page_template', $this->options) and ( !empty($this->options['page_template']) or "no" == $this->options['is_multiple_page_template']) ){
1469
  update_post_meta($pid, '_wp_page_template', ("no" == $this->options['is_multiple_page_template']) ? $page_template[$i] : $this->options['page_template']);
1470
  }
1471
 
1617
  $logger and call_user_func($logger, sprintf(__('- Importing image `%s` for `%s` ...', 'wp_all_import_plugin'), $img_url, $articleData['post_title']));
1618
 
1619
  // generate local file name
1620
+ $image_name = urldecode(($this->options[$option_slug . 'auto_rename_images'] and !empty($auto_rename_images_bundle[$slug][$i])) ? sanitize_file_name(($img_ext) ? str_replace("." . $default_extension, "", $auto_rename_images_bundle[$slug][$i]) : $auto_rename_images_bundle[$slug][$i]) : (($img_ext) ? str_replace("." . $default_extension, "", $bn) : $bn)) . (("" != $img_ext) ? '.' . $img_ext : '');
1621
  $image_name = apply_filters("wp_all_import_image_filename", $image_name, empty($img_titles[$k]) ? '' : $img_titles[$k], empty($img_captions[$k]) ? '' : $img_captions[$k], empty($img_alts[$k]) ? '' : $img_alts[$k], $articleData, $this->id);
1622
 
1623
  // if wizard store image data to custom field
1628
  $is_base64_images_allowed = apply_filters("wp_all_import_is_base64_images_allowed", true, $url, $this->id);
1629
 
1630
  if ( $bundle_data['type'] == 'images' and base64_encode(base64_decode($url)) == $url and $is_base64_images_allowed ){
1631
+ $image_name = empty($this->options[$option_slug . 'auto_rename_images']) ? md5(time()) . '.jpg' : sanitize_file_name($auto_rename_images_bundle[$slug][$i]) . '.jpg';
1632
+ $image_name = apply_filters("wp_all_import_image_filename", $image_name, empty($img_titles[$k]) ? '' : $img_titles[$k], empty($img_captions[$k]) ? '' : $img_captions[$k], empty($img_alts[$k]) ? '' : $img_alts[$k], $articleData, $this->id);
1633
+
1634
+ // search existing attachment
1635
+ if ($this->options[$option_slug . 'search_existing_images'] or "gallery" == $this->options[$option_slug . 'download_images']){
1636
+
1637
+ $image_filename = $image_name;
1638
+
1639
+ $attch = wp_all_import_get_image_from_gallery($image_name, $targetDir, $bundle_data['type']);
1640
+
1641
+ if ("gallery" == $this->options[$option_slug . 'download_images']) $download_image = false;
1642
+
1643
+ if (empty($attch))
1644
+ {
1645
+ $logger and call_user_func($logger, sprintf(__('- <b>WARNING</b>: Image %s not found in media gallery.', 'wp_all_import_plugin'), trim($image_name)));
1646
+ }
1647
+ else
1648
+ {
1649
+ $logger and call_user_func($logger, sprintf(__('- Using existing image `%s` for post `%s` ...', 'wp_all_import_plugin'), trim($image_name), $articleData['post_title']));
1650
+ $download_image = false;
1651
+ $create_image = false;
1652
+ $attid = $attch->ID;
1653
+ }
1654
+ }
1655
+
1656
+ if ($download_image){
1657
+ $img = @imagecreatefromstring(base64_decode($url));
1658
+ if($img)
1659
+ {
1660
+ $logger and call_user_func($logger, __('- found base64_encoded image', 'wp_all_import_plugin'));
1661
+
1662
+ //$image_filename = md5(time()) . '.jpg';
1663
+ $image_filepath = $targetDir . '/' . $image_filename;
1664
+ imagejpeg($img, $image_filepath);
1665
+ if( ! ($image_info = apply_filters('pmxi_getimagesize', @getimagesize($image_filepath), $image_filepath)) or ! in_array($image_info[2], array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) {
1666
+ $logger and call_user_func($logger, sprintf(__('- <b>WARNING</b>: File %s is not a valid image and cannot be set as featured one', 'wp_all_import_plugin'), $image_filepath));
1667
+ $logger and !$is_cron and PMXI_Plugin::$session->warnings++;
1668
+ } else {
1669
+ $create_image = true;
1670
+ }
1671
+ }
1672
+ }
1673
  }
1674
 
1675
  if ( ! $create_image ) {
2049
 
2050
  if ($this->options['is_search_existing_attach']){
2051
  // search existing attachment
2052
+ $attch = wp_all_import_get_image_from_gallery($attachment_filename, $targetDir, 'files');
2053
 
2054
  if ( $attch != null ){
2055
  $download_file = false;
2056
  $attach_id = $attch->ID;
2057
+ $logger and call_user_func($logger, sprintf(__('- Using existing file `%s` for post `%s` ...', 'wp_all_import_plugin'), trim($attachment_filename), $articleData['post_title']));
2058
  }
2059
  }
2060
 
2107
  }
2108
  }
2109
  }
2110
+
2111
+ if ($attach_id && ! is_wp_error($attach_id))
2112
+ {
2113
+ if ($attch != null && empty($attch->post_parent) && ! in_array($post_type[$i], array('taxonomies'))){
2114
+ wp_update_post(
2115
+ array(
2116
+ 'ID' => $attch->ID,
2117
+ 'post_parent' => $pid
2118
+ )
2119
+ );
2120
+ }
2121
+
2122
+ if ($attch != null and empty($attch->post_parent))
2123
+ {
2124
+ $logger and call_user_func($logger, sprintf(__('- Attachment has been successfully updated for file `%s`', 'wp_all_import_plugin'), ($handle_attachment) ? $handle_attachment['url'] : $targetUrl . '/' . $attachment_filename));
2125
+ }
2126
+ elseif(empty($attch))
2127
+ {
2128
+ $logger and call_user_func($logger, sprintf(__('- Attachment has been successfully created for file `%s`', 'wp_all_import_plugin'), ($handle_attachment) ? $handle_attachment['url'] : $targetUrl . '/' . $attachment_filename));
2129
+ }
2130
  $logger and call_user_func($logger, __('- <b>ACTION</b>: pmxi_attachment_uploaded', 'wp_all_import_plugin'));
2131
  do_action( 'pmxi_attachment_uploaded', $pid, $attach_id, $attachment_filepath);
2132
  }
2283
  $is_update = ! empty($articleData['ID']);
2284
 
2285
  // fire important hooks after custom fields are added
2286
+ if ( ! $this->options['is_fast_mode'] and ! in_array($this->options['custom_type'], array('import_users', 'taxonomies'))){
2287
+ $post_object = $this->wpdb->get_row( $this->wpdb->prepare( "SELECT * FROM {$this->wpdb->posts} WHERE ID = %d", $pid) );
2288
  do_action( "save_post_" . $articleData['post_type'], $pid, $post_object, $is_update );
2289
  do_action( 'save_post', $pid, $post_object, $is_update );
2290
  do_action( 'wp_insert_post', $pid, $post_object, $is_update );
plugin.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: WP All Import
4
  Plugin URI: http://www.wpallimport.com/upgrade-to-pro?utm_source=wordpress.org&utm_medium=plugins-page&utm_campaign=free+plugin
5
  Description: 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.4.0
7
  Author: Soflyy
8
  */
9
 
@@ -25,7 +25,7 @@ define('WP_ALL_IMPORT_ROOT_URL', rtrim(plugin_dir_url(__FILE__), '/'));
25
  */
26
  define('WP_ALL_IMPORT_PREFIX', 'pmxi_');
27
 
28
- define('PMXI_VERSION', '3.4.0');
29
 
30
  define('PMXI_EDITION', 'free');
31
 
3
  Plugin Name: WP All Import
4
  Plugin URI: http://www.wpallimport.com/upgrade-to-pro?utm_source=wordpress.org&utm_medium=plugins-page&utm_campaign=free+plugin
5
  Description: 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.4.1
7
  Author: Soflyy
8
  */
9
 
25
  */
26
  define('WP_ALL_IMPORT_PREFIX', 'pmxi_');
27
 
28
+ define('PMXI_VERSION', '3.4.1');
29
 
30
  define('PMXI_EDITION', 'free');
31
 
readme.txt CHANGED
@@ -1,8 +1,8 @@
1
  === Import any XML or CSV File to WordPress ===
2
  Contributors: soflyy, wpallimport
3
  Requires at least: 4.1
4
- Tested up to: 4.7
5
- Stable tag: 3.4.0
6
  Tags: 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
7
 
8
  WP All Import is an extremely powerful importer that makes it easy to import any XML or CSV file to WordPress.
@@ -105,6 +105,13 @@ Does it work with special character encoding like Hebrew, Arabic, Chinese, etc?
105
 
106
  == Changelog ==
107
 
 
 
 
 
 
 
 
108
  = 3.4.0 =
109
  * improvement: compatibility with PHP 7.x
110
 
1
  === Import any XML or CSV File to WordPress ===
2
  Contributors: soflyy, wpallimport
3
  Requires at least: 4.1
4
+ Tested up to: 4.7.2
5
+ Stable tag: 3.4.1
6
  Tags: 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
7
 
8
  WP All Import is an extremely powerful importer that makes it easy to import any XML or CSV file to WordPress.
105
 
106
  == Changelog ==
107
 
108
+ = 3.4.1 =
109
+ * improvement: Stop parsing data which is not going to be updated
110
+ * improvement: added new filter wp_all_import_phpexcel_object to modify excel data before import
111
+ * bug fix: search for images ending with underscores in media
112
+ * bug fix: import hierarchical posts/pages
113
+ * bug fix: import cpt page templates
114
+
115
  = 3.4.0 =
116
  * improvement: compatibility with PHP 7.x
117
 
static/js/admin.js CHANGED
@@ -169,9 +169,9 @@
169
  });
170
 
171
  if ( $import_to_custom_type != 'product' &&
172
- ( $('textarea[name=download_featured_image]').val() != "" ||
173
- $('textarea[name=gallery_featured_image]').val() != "" ||
174
- $('textarea[name=featured_image]').val() != "" ))
175
  {
176
  $is_show_images_notice = true;
177
  }
169
  });
170
 
171
  if ( $import_to_custom_type != 'product' &&
172
+ ( $('textarea[name=download_featured_image]').length && $('textarea[name=download_featured_image]').val() != "" ||
173
+ $('textarea[name=gallery_featured_image]').length && $('textarea[name=gallery_featured_image]').val() != "" ||
174
+ $('textarea[name=featured_image]').length && $('textarea[name=featured_image]').val() != "" ))
175
  {
176
  $is_show_images_notice = true;
177
  }
views/admin/import/preview_images.php CHANGED
@@ -27,7 +27,7 @@
27
 
28
  <?php
29
 
30
- switch ($this->options[$option_slug . 'download_images']) {
31
  case 'no':
32
  $featured_delim = $post[$get['slug'] . 'featured_delim'];
33
  break;
@@ -104,7 +104,7 @@
104
  $img_ext = pmxi_getExtensionFromStr($img);
105
  $default_extension = pmxi_getExtension($bn);
106
 
107
- $image_name = apply_filters("wp_all_import_image_filename", urldecode(sanitize_file_name((($img_ext) ? str_replace("." . $default_extension, "", $bn) : $bn))) . (("" != $img_ext) ? '.' . $img_ext : ''));
108
 
109
  ?>
110
 
@@ -121,7 +121,7 @@
121
  $img_ext = pmxi_getExtensionFromStr($img);
122
  $default_extension = pmxi_getExtension($bn);
123
 
124
- $image_name = apply_filters("wp_all_import_image_filename", urldecode(sanitize_file_name((($img_ext) ? str_replace("." . $default_extension, "", $bn) : $bn))) . (("" != $img_ext) ? '.' . $img_ext : ''));
125
 
126
  $attch = wp_all_import_get_image_from_gallery($image_name);
127
 
27
 
28
  <?php
29
 
30
+ switch ($post[$option_slug . 'download_images']) {
31
  case 'no':
32
  $featured_delim = $post[$get['slug'] . 'featured_delim'];
33
  break;
104
  $img_ext = pmxi_getExtensionFromStr($img);
105
  $default_extension = pmxi_getExtension($bn);
106
 
107
+ $image_name = apply_filters("wp_all_import_image_filename", urldecode((($img_ext) ? str_replace("." . $default_extension, "", $bn) : $bn)) . (("" != $img_ext) ? '.' . $img_ext : ''));
108
 
109
  ?>
110
 
121
  $img_ext = pmxi_getExtensionFromStr($img);
122
  $default_extension = pmxi_getExtension($bn);
123
 
124
+ $image_name = apply_filters("wp_all_import_image_filename", urldecode((($img_ext) ? str_replace("." . $default_extension, "", $bn) : $bn)) . (("" != $img_ext) ? '.' . $img_ext : ''));
125
 
126
  $attch = wp_all_import_get_image_from_gallery($image_name);
127
 
views/admin/import/template/_other_template.php CHANGED
@@ -176,7 +176,9 @@
176
  </tr>
177
  <?php endif; ?>
178
 
179
- <?php if ( 'page' == $post_type ):?>
 
 
180
  <tr>
181
  <td>
182
  <h4><?php _e('Page Template', 'wp_all_import_plugin') ?></h4>
176
  </tr>
177
  <?php endif; ?>
178
 
179
+ <?php
180
+ global $wp_version;
181
+ if ( 'page' == $post_type || version_compare($wp_version, '4.7.0', '>=') ):?>
182
  <tr>
183
  <td>
184
  <h4><?php _e('Page Template', 'wp_all_import_plugin') ?></h4>
views/admin/manage/index.php CHANGED
@@ -306,7 +306,7 @@ $columns = apply_filters('pmxi_manage_imports_columns', $columns);
306
 
307
  <a href="<?php echo add_query_arg(array('id' => $item['id'], 'action' => 'scheduling'), $this->baseUrl)?>"><?php _e('Cron Scheduling', 'wp_all_import_plugin'); ?></a> <br>
308
 
309
- <a href="<?php echo add_query_arg(array('page' => 'pmxi-admin-history', 'id' => $item['id']), $this->baseUrl)?>"><?php _e('History Logs', 'wp_all_import_plugin'); ?></a>
310
 
311
  </td>
312
  <?php
306
 
307
  <a href="<?php echo add_query_arg(array('id' => $item['id'], 'action' => 'scheduling'), $this->baseUrl)?>"><?php _e('Cron Scheduling', 'wp_all_import_plugin'); ?></a> <br>
308
 
309
+ <a href="<?php echo add_query_arg(array('page' => 'pmxi-admin-history', 'id' => $item['id']), remove_query_arg('pagenum', $this->baseUrl))?>"><?php _e('History Logs', 'wp_all_import_plugin'); ?></a>
310
 
311
  </td>
312
  <?php