forked from importwp/importwp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjc-importer.php
365 lines (301 loc) · 7.1 KB
/
jc-importer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
<?php
/**
* Plugin Name: ImportWP
* Plugin URI: https://www.importwp.com
* Description: Wordpress CSV/XML Importer Plugin, Easily import users, posts, custom post types and taxonomies from XML or CSV files
* Author: James Collings <[email protected]>
* Author URI: http://www.jamescollings.co.uk
* Version: 0.5
*
* @package ImportWP
* @author James Collings <[email protected]>
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
require_once 'app/core/exceptions.php';
require_once 'app/parse/parser.php';
// libs.
require_once 'app/libs/xmloutput.php';
require_once 'app/libs/class-importwp-premium.php';
// attachments.
require_once 'app/attachment/class-jci-attachment.php';
require_once 'app/attachment/class-jci-ftp-attachments.php';
require_once 'app/attachment/class-jci-curl-attachments.php';
require_once 'app/attachment/class-jci-upload-attachments.php';
require_once 'app/attachment/class-jci-string-attachments.php';
require_once 'app/attachment/class-jci-local-attachments.php';
// mappers.
require_once 'app/mapper/Mapper.php';
require_once 'app/mapper/PostMapper.php';
require_once 'app/mapper/TableMapper.php';
require_once 'app/mapper/UserMapper.php';
require_once 'app/mapper/VirtualMapper.php';
require_once 'app/mapper/TaxMapper.php';
// parsers.
require_once 'app/parse/data-csv.php';
require_once 'app/parse/data-xml.php';
// templates.
require_once 'app/templates/template.php';
require_once 'app/templates/template-user.php';
require_once 'app/templates/template-post.php';
require_once 'app/templates/template-page.php';
require_once 'app/templates/template-tax.php';
require_once 'app/helpers/form.php';
require_once 'app/functions.php';
/**
* Class JC_Importer
*
* Core plugin class
*/
class JC_Importer {
/**
* Current Plugin Version
*
* @var string
*/
protected $version = '0.5';
/**
* Plugin base directory
*
* @var string
*/
protected $plugin_dir;
/**
* Plugin base url
*
* @var string
*/
protected $plugin_url;
/**
* List of available template strings
*
* @var array[string]
*/
protected $templates = array();
/**
* Current plugin database schema version
*
* @var int
*/
protected $db_version = 2;
/**
* Debug flag
*
* @var bool
*/
protected $debug = false;
/**
* Loaded Importer Class
*
* @var JC_Importer_Core
*/
public $importer;
/**
* Plugin Text Strings
*
* @var IWP_Text
*/
private $text;
/**
* Single instance of class
*
* @var null
*/
protected static $_instance = null;
/**
* Return current instance of class
*
* @return JC_Importer
*/
public static function instance() {
if ( is_null( self::$_instance ) ) {
self::$_instance = new self();
}
return self::$_instance;
}
/**
* JC_Importer constructor.
*/
public function __construct() {
$this->plugin_dir = plugin_dir_path( __FILE__ );
$this->plugin_url = plugins_url( '/', __FILE__ );
require_once 'app/libs/class-iwp-text.php';
$this->text = new IWP_Text();
add_action( 'init', array( $this, 'init' ) );
add_action( 'plugins_loaded', array( $this, 'db_update_check' ) );
$this->parsers = apply_filters( 'jci/register_parser', array() );
// activation.
register_activation_hook( __FILE__, array( $this, 'activation' ) );
add_action( 'admin_init', array( $this, 'load_plugin' ) );
}
/**
* Setup plugin, loading all classes
*
* @return void
*/
public function init() {
do_action( 'jci/before_init' );
$this->register_post_types();
// register templates.
$this->templates = apply_filters( 'jci/register_template', $this->templates );
// load importer.
require_once 'app/core/importer.php';
// core models.
require_once 'app/models/importer.php';
require_once 'app/models/log.php';
if ( is_admin() ) {
// load importer.
$importer_id = isset( $_GET['import'] ) && ! empty( $_GET['import'] ) ? intval( $_GET['import'] ) : 0;
if ( $importer_id > 0 ) {
$this->importer = new JC_Importer_Core( $importer_id );
}
require_once 'app/admin.php';
new JC_Importer_Admin( $this );
require_once 'app/ajax.php';
new JC_Importer_Ajax( $this );
}
ImporterModel::init( $this );
ImportLog::init( $this );
JCI_FormHelper::init( $this );
// plugin loaded.
do_action( 'jci/init' );
}
/**
* Register jc-imports custom post types
*
* @return void
*/
function register_post_types() {
// importers.
register_post_type( 'jc-imports', array(
'public' => false,
'has_archive' => false,
'show_in_nav_menus' => false,
'label' => 'Importer',
) );
// importer csv/xml files.
register_post_type( 'jc-import-files', array(
'public' => false,
'has_archive' => false,
'show_in_nav_menus' => false,
'label' => 'Importer Files',
) );
// importer tempaltes.
register_post_type( 'jc-import-template', array(
'public' => false,
'has_archive' => false,
'show_in_nav_menus' => false,
'label' => 'Template',
) );
}
/**
* Set Plugin Activation
*
* @return void
*/
function activation() {
add_option( 'Activated_Plugin', 'jcimporter' );
}
/**
* Run Activation Functions
*
* @return void
*/
function load_plugin() {
if ( is_admin() ) {
if ( get_option( 'Activated_Plugin' ) === 'jcimporter' ) {
// scaffold log table.
require_once 'app/models/schema.php';
$schema = new JCI_DB_Schema( $this );
$schema->install();
delete_option( 'Activated_Plugin' );
}
$this->db_update_check();
}
}
/**
* Check if database requires an upgrade
*/
public function db_update_check() {
$curr_db = intval( get_site_option( 'jci_db_version' ) );
if ( is_admin() && $curr_db < $this->db_version ) {
require_once 'app/models/schema.php';
$schema = new JCI_DB_Schema( $this );
$schema->upgrade( $curr_db );
update_site_option( 'jci_db_version', $this->db_version );
}
}
/**
* Get plugin directory
*
* @return string
*/
public function get_plugin_dir() {
return $this->plugin_dir;
}
/**
* Get plugin url
*
* @return string
*/
public function get_plugin_url() {
return $this->plugin_url;
}
/**
* Is debug enabled?
*
* @return bool
*/
public function is_debug() {
return $this->debug;
}
/**
* Get importer template
*
* @param string $template Template name.
*
* @return mixed|string
*/
public function get_template( $template ) {
if ( isset( $this->templates[ $template ] ) ) {
$temp = $this->templates[ $template ];
$this->templates[ $template ] = new $temp;
return $this->templates[ $template ];
}
return false;
}
/**
* Get importer templates
*
* @return array
*/
public function get_templates() {
return $this->templates;
}
/**
* Get plugin version
*
* @return string
*/
public function get_version() {
return $this->version;
}
/**
* Get text class
*
* @return IWP_Text
*/
public function text(){
return $this->text;
}
}
/**
* Globally access JC_Importer instance.
*
* @return JC_Importer
*/
function JCI() {
return JC_Importer::instance();
}
$GLOBALS['jcimporter'] = JCI();