-
Notifications
You must be signed in to change notification settings - Fork 0
/
indexhibit2-importer.php
636 lines (584 loc) · 22.3 KB
/
indexhibit2-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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
<?php
/**
* Plugin Name: Indexhibit 2 Importer
* Plugin URI: http://wordpress.org/plugins/indexhibit2-importer/
* Description: Import exhibits and media files from an Indexhibit 2 site.
* Version: 1.0.7
* Author: leemon
* Text Domain: indexhibit2-importer
* License: GPLv2 or later
*
* @package indexhibit2-importer
*/
if ( ! defined( 'WP_LOAD_IMPORTERS' ) ) {
return;
}
// Load Importer API.
require_once ABSPATH . 'wp-admin/includes/import.php';
if ( ! class_exists( 'WP_Importer' ) ) {
$class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
if ( file_exists( $class_wp_importer ) ) {
require_once $class_wp_importer;
}
}
/**
* Indexhibit 2 Importer
*
* @package WordPress
* @subpackage Importer
*/
if ( class_exists( 'WP_Importer' ) ) {
/**
* Core class used to implement the plugin.
*/
class Ix2_Import extends WP_Importer {
/**
* Database connection.
*
* @var object $ix2db
*/
public $ix2db;
/**
* Constructor. Intentionally left empty and public.
*/
public function __construct() {}
/**
* Display header
*/
public function header() {
?>
<div class="wrap">
<h2><?php _e( 'Import Indexhibit 2', 'indexhibit2-importer' ); ?></h2>
<?php
}
/**
* Display footer
*/
public function footer() {
?>
</div>
<?php
}
/**
* Display introductory text and Indexhibit 2 settings form
*/
public function greet() {
?>
<div class="narrow">
<p><?php _e( 'This importer allows you to import most of the contents from an Indexhibit 2 site into your WordPress site. It imports exhibits and media files but ignores links, sections, subsections and exhibit formats.', 'indexhibit2-importer' ); ?></p>
<p><?php _e( 'The process may take a few minutes depending on the size of your database. Please be patient.', 'indexhibit2-importer' ); ?></p>
<p><?php _e( 'Fill the following form with your Indexhibit 2 configuration settings. They can be found in the <code>/ndxzsite/config/config.php</code> file.', 'indexhibit2-importer' ); ?></p>
<form action="admin.php?import=indexhibit2&step=1" method="post">
<?php
wp_nonce_field( 'import-indexhibit2' );
$this->db_form();
?>
<p class="submit"><input type="submit" name="submit" class="button" value="<?php echo esc_attr__( 'Import exhibits', 'indexhibit2-importer' ); ?>" /></p>
</form>
</div>
<?php
}
/**
* Display Indexhibit 2 settings form
*/
public function db_form() {
?>
<table class="form-table">
<tr>
<th scope="row"><label for="ixurl"><?php _e( 'Indexhibit 2 Site Address', 'indexhibit2-importer' ); ?></label></th>
<td>
<input type="url" name="ixurl" id="ixurl" class="regular-text" required placeholder="http://" />
<p class="description" id="ixurl-description"><?php _e( 'The URL where your Indexhibit 2 site is installed', 'indexhibit2-importer' ); ?></p>
</td>
</tr>
<tr>
<th scope="row"><label for="dbname"><?php _e( 'Indexhibit 2 Database Name', 'indexhibit2-importer' ); ?></label></th>
<td>
<input type="text" name="dbname" id="dbname" class="regular-text" required />
<p class="description" id="dbname-description"><?php _e( "The <code>$indx['db']</code> value", 'indexhibit2-importer' ); ?></p>
</td>
</tr>
<tr>
<th scope="row"><label for="dbuser"><?php _e( 'Indexhibit 2 Database User', 'indexhibit2-importer' ); ?></label></th>
<td>
<input type="text" name="dbuser" id="dbuser" class="regular-text" required />
<p class="description" id="dbuser-description"><?php _e( "The <code>$indx['user']</code> value", 'indexhibit2-importer' ); ?></p>
</td>
</tr>
<tr>
<th scope="row"><label for="dbpass"><?php _e( 'Indexhibit 2 Database Password', 'indexhibit2-importer' ); ?></label></th>
<td>
<input type="password" name="dbpass" id="dbpass" class="regular-text" required />
<p class="description" id="dbpass-description"><?php _e( "The <code>$indx['pass']</code> value", 'indexhibit2-importer' ); ?></p>
</td>
</tr>
<tr>
<th scope="row"><label for="dbhost"><?php _e( 'Indexhibit 2 Database Host', 'indexhibit2-importer' ); ?></label></th>
<td>
<input type="text" name="dbhost" id="dbhost" class="regular-text" required placeholder="localhost" />
<p class="description" id="dbhost-description"><?php _e( "The <code>$indx['host']</code> value", 'indexhibit2-importer' ); ?></p>
</td>
</tr>
<tr>
<th scope="row"><label for="dbprefix"><?php _e( 'Indexhibit 2 Table Prefix', 'indexhibit2-importer' ); ?></label></th>
<td>
<input type="text" name="dbprefix" id="dbprefix" class="regular-text" required placeholder="ndxz_" />
<p class="description" id="dbprefix-description"><?php _e( "The <code>xxxx</code> value in <code>define('PX', 'xxxx')</code> value", 'indexhibit2-importer' ); ?></p>
</td>
</tr>
</table>
<?php
}
/**
* Setup connection to Indexhibit 2 database
*/
public function init_ix2db() {
$options = get_option( 'ix2_options' );
$this->ix2db = new wpdb( $options['ix2_user'], $options['ix2_pass'], $options['ix2_name'], $options['ix2_host'] );
$result = $this->ix2db->check_connection( false );
if ( ! $result ) {
return false;
}
return true;
}
/**
* Get exhibits from Indexhibit 2 database
*/
public function get_ix2_exhibits() {
$options = get_option( 'ix2_options' );
$dbprefix = $options['ix2_dbprefix'];
return $this->ix2db->get_results( 'SELECT * FROM ' . $dbprefix . "objects WHERE link = ''", ARRAY_A );
}
/**
* Get media files from Indexhibit 2 database
*/
public function get_ix2_media( $post_id ) {
$options = get_option( 'ix2_options' );
$dbprefix = $options['ix2_dbprefix'];
return $this->ix2db->get_results(
$this->ix2db->prepare( 'SELECT * FROM ' . $dbprefix . "media WHERE media_ref_id = %s AND media_mime NOT IN ( 'youtube', 'vimeo' ) ORDER BY media_order ASC", $post_id ),
ARRAY_A
);
}
/**
* Import exhibits
*/
public function import_exhibits() {
// Import exhibits.
$exhibits = $this->get_ix2_exhibits();
$result = $this->exhibits2wp( $exhibits );
if ( is_wp_error( $result ) ) {
return $result;
}
?>
<form action="admin.php?import=indexhibit2&step=2" method="post">
<?php wp_nonce_field( 'import-indexhibit2' ); ?>
<table class="form-table">
<tr>
<th scope="row"><label for="mdinsert"><?php _e( 'Insert imported media files into pages content?', 'indexhibit2-importer' ); ?></label></th>
<td>
<input type="checkbox" name="mdinsert" id="mdinsert" value="1" checked />
</td>
</tr>
</table>
<p class="submit"><input type="submit" name="submit" class="button" value="<?php echo esc_attr__( 'Import media files', 'indexhibit2-importer' ); ?>" /></p>
</form>
<?php
}
/**
* Import media files
*/
public function import_media() {
$options = get_option( 'ix2_options' );
$mdinsert = $options['ix2_mdinsert'];
$ixexhibits2wpposts = $options['ix2_exhibits2wpposts'];
// Import media.
foreach ( $ixexhibits2wpposts as $key => $value ) {
$media = $this->get_ix2_media( $key );
$result = $this->media2wp( $media, $value );
if ( is_wp_error( $result ) ) {
return $result;
}
if ( ! empty( $mdinsert ) ) {
$this->insert_attachments( $value );
}
}
?>
<form action="admin.php?import=indexhibit2&step=3" method="post">
<?php wp_nonce_field( 'import-indexhibit2' ); ?>
<p class="submit"><input type="submit" name="submit" class="button" value="<?php echo esc_attr__( 'Finish', 'indexhibit2-importer' ); ?>" /></p>
</form>
<?php
}
/**
* Perform import of exhibits
*/
public function exhibits2wp( $exhibits = '' ) {
$options = get_option( 'ix2_options' );
$count = 0;
$ixexhibits2wpposts = array();
if ( is_array( $exhibits ) ) {
echo '<p>' . __( 'Importing exhibits...', 'indexhibit2-importer' ) . '</p>';
foreach ( $exhibits as $exhibit ) {
$post_author = get_current_user_id();
$post_title = $exhibit['title'];
$post_content = $exhibit['content'];
$post_home = $exhibit['home'];
$post_date = $exhibit['pdate'];
$post_modified = $exhibit['udate'];
$post_format = $exhibit['format'];
// Set Indexhibit-to-WordPress status translation.
$ixstatus = array(
0 => 'draft',
1 => 'publish',
);
$post_status = $ixstatus[ $exhibit['status'] ];
$ret_id = 0;
// Check if the exhibit is already imported.
if ( $pinfo = post_exists( $post_title, '', $post_date ) ) {
$ret_id = wp_insert_post(
array(
'ID' => $pinfo,
'post_author' => $post_author,
'post_date' => $post_date,
'post_date_gmt' => $post_date,
'post_modified' => $post_modified,
'post_modified_gmt' => $post_modified,
'post_title' => $post_title,
'post_content' => $post_content,
'post_status' => $post_status,
'post_type' => 'page',
'comment_status' => 'closed',
'ping_status' => 'closed',
)
);
if ( is_wp_error( $ret_id ) ) {
return $ret_id;
}
add_post_meta( $ret_id, 'ix2_exhibit_format', $post_format );
} else {
$ret_id = wp_insert_post(
array(
'post_author' => $post_author,
'post_date' => $post_date,
'post_date_gmt' => $post_date,
'post_modified' => $post_modified,
'post_modified_gmt' => $post_modified,
'post_title' => $post_title,
'post_content' => $post_content,
'post_status' => $post_status,
'post_type' => 'page',
'comment_status' => 'closed',
'ping_status' => 'closed',
)
);
if ( is_wp_error( $ret_id ) ) {
return $ret_id;
}
add_post_meta( $ret_id, 'ix2_exhibit_format', $post_format );
}
// Set front page.
if ( ! empty( $post_home ) ) {
update_option( 'page_on_front', $ret_id );
update_option( 'show_on_front', 'page' );
}
$ixexhibits2wpposts[ $exhibit['id'] ] = $ret_id;
++$count;
}
}
// Store exhibit2post translation for later use.
$options['ix2_exhibits2wpposts'] = $ixexhibits2wpposts;
update_option( 'ix2_options', $options );
echo '<p>' . sprintf( __( 'Done! <strong>%1$s</strong> exhibits imported.', 'indexhibit2-importer' ), $count ) . '<br /><br /></p>';
return true;
}
/**
* Perform import of media files
*/
public function media2wp( $files = '', $post_id ) {
$count = 0;
if ( is_array( $files ) ) {
echo '<p>' . sprintf( __( 'Importing media files from exhibit "%1$s"...', 'indexhibit2-importer' ), get_the_title( $post_id ) ) . '</p>';
foreach ( $files as $file ) {
++$count;
$process = $this->process_attachment( $file, $post_id );
}
}
echo '<p>' . sprintf( __( 'Done! <strong>%1$s</strong> media files imported.', 'indexhibit2-importer' ), $count ) . '<br /><br /></p>';
return true;
}
/**
* Create new attachments based on import information
*/
public function process_attachment( $file, $parent_post ) {
$options = get_option( 'ix2_options' );
$ixurl = $options['ix2_url'];
$media_file = $file['media_file'];
$media_file_noext = preg_replace( '/\\.[^.\\s]{3,4}$/', '', $media_file );
$post = array(
'post_title' => ( ! empty( $file['media_title'] ) ? $file['media_title'] : $media_file_noext ),
'post_content' => $file['media_caption'],
'post_date' => $file['media_udate'],
'post_date_gmt' => $file['media_udate'],
'menu_order' => $file['media_order'],
'post_parent' => $parent_post,
);
$media_url = trailingslashit( $ixurl ) . 'files/gimgs/' . $media_file;
$pre_process = $this->pre_process_attachment( $post, $media_url );
if ( is_wp_error( $pre_process ) ) {
return array(
'fatal' => false,
'type' => 'error',
'code' => $pre_process->get_error_code(),
'message' => $pre_process->get_error_message(),
'text' => sprintf( __( '%1$s was not uploaded. (<strong>%2$s</strong>: %3$s)', 'indexhibit2-importer' ), $post['post_title'], $pre_process->get_error_code(), $pre_process->get_error_message() ),
);
}
// If the URL is absolute, but does not contain address, then upload it assuming base_site_url.
if ( preg_match( '|^/[\w\W]+$|', $media_url ) ) {
$base_url = get_home_url();
$media_url = rtrim( $base_url, '/' ) . $media_url;
}
$upload = $this->fetch_remote_file( $media_url, $post );
if ( is_wp_error( $upload ) ) {
return array(
'fatal' => ( $upload->get_error_code() === 'upload_dir_error' && $upload->get_error_message() !== 'Invalid file type' ? true : false ),
'type' => 'error',
'code' => $upload->get_error_code(),
'message' => $upload->get_error_message(),
'text' => sprintf( __( '%1$s could not be uploaded because of an error. (<strong>%2$s</strong>: %3$s)', 'indexhibit2-importer' ), $post['post_title'], $upload->get_error_code(), $upload->get_error_message() ),
);
}
if ( $info = wp_check_filetype( $upload['file'] ) ) {
$post['post_mime_type'] = $info['type'];
} else {
$upload = new WP_Error( 'attachment_processing_error', __( 'Invalid file type', 'indexhibit2-importer' ) );
return array(
'fatal' => false,
'type' => 'error',
'code' => $upload->get_error_code(),
'message' => $upload->get_error_message(),
'text' => sprintf( __( '%1$s could not be uploaded because of an error. (<strong>%2$s</strong>: %3$s)', 'indexhibit2-importer' ), $post['post_title'], $upload->get_error_code(), $upload->get_error_message() ),
);
}
$post['guid'] = $upload['url'];
$post['post_author'] = get_current_user_id();
// As per wp-admin/includes/upload.php.
$post_id = wp_insert_attachment( $post, $upload['file'] );
wp_update_attachment_metadata( $post_id, wp_generate_attachment_metadata( $post_id, $upload['file'] ) );
return array(
'fatal' => false,
'type' => 'updated',
'text' => sprintf( __( '%s was uploaded successfully', 'indexhibit2-importer' ), $post['post_title'] ),
);
}
/**
* Check if attachment already exist
*/
public function pre_process_attachment( $post, $url ) {
global $wpdb;
$imported = $wpdb->get_results(
$wpdb->prepare(
"SELECT ID, post_date_gmt, guid
FROM $wpdb->posts WHERE post_type = 'attachment' AND post_title = %s
",
$post['post_title']
)
);
if ( $imported ) {
foreach ( $imported as $attachment ) {
if ( sanitize_file_name( basename( $url ) ) === basename( $attachment->guid ) ) {
if ( $post['post_date_gmt'] === $attachment->post_date_gmt ) {
$remote_response = wp_safe_remote_get( $url );
$headers = wp_remote_retrieve_headers( $remote_response );
if ( filesize( get_attached_file( $attachment->ID ) ) === $headers['content-length'] ) {
return new WP_Error( 'duplicate_file_notice', __( 'File already exists', 'indexhibit2-importer' ) );
}
}
}
}
}
return false;
}
/**
* Attempt to download a remote file attachment
*/
public function fetch_remote_file( $url, $post ) {
// Extract the file name and extension from the url.
$file_name = basename( $url );
// Get placeholder file in the upload dir with a unique, sanitized filename.
$upload = wp_upload_bits( $file_name, null, '', $post['post_date'] );
if ( $upload['error'] ) {
return new WP_Error( 'upload_dir_error', $upload['error'] );
}
// Fetch the remote url and write it to the placeholder file.
$remote_response = wp_safe_remote_get(
$url,
array(
'timeout' => 300,
'stream' => true,
'filename' => $upload['file'],
)
);
$headers = wp_remote_retrieve_headers( $remote_response );
// Request failed.
if ( ! $headers ) {
@unlink( $upload['file'] );
return new WP_Error( 'import_file_error', __( 'Remote server did not respond', 'indexhibit2-importer' ) );
}
// Make sure the fetch was successful.
$remote_response_code = wp_remote_retrieve_response_code( $remote_response );
if ( '200' != $remote_response_code ) {
@unlink( $upload['file'] );
return new WP_Error( 'import_file_error', sprintf( __( 'Remote server returned error response %1$d %2$s', 'indexhibit2-importer' ), esc_html( $remote_response_code ), get_status_header_desc( $remote_response_code ) ) );
}
$filesize = filesize( $upload['file'] );
if ( isset( $headers['content-length'] ) && $filesize != $headers['content-length'] ) {
@unlink( $upload['file'] );
return new WP_Error( 'import_file_error', __( 'Remote file is incorrect size', 'indexhibit2-importer' ) );
}
if ( 0 === $filesize ) {
@unlink( $upload['file'] );
return new WP_Error( 'import_file_error', __( 'Zero size file downloaded', 'indexhibit2-importer' ) );
}
return $upload;
}
/**
* Insert attachments into posts content
*/
public function insert_attachments( $post_id ) {
$attachments = get_attached_media( 'image', $post_id );
if ( $attachments ) {
$post = get_post( $post_id );
$content = $post->post_content;
foreach ( $attachments as $attachment ) {
$content .= wp_get_attachment_image(
$attachment->ID,
'full',
false,
array( 'class' => 'attachment-full size-full ' . sprintf( 'wp-image-%d', $attachment->ID ) )
);
}
$updated_post = array(
'ID' => $post_id,
'post_content' => $content,
);
// Update post.
wp_update_post( $updated_post );
}
}
/**
* Perform cleanup of plugin options
*/
public function clean_options() {
delete_option( 'ix2_options' );
}
/**
* Display post-import information
*/
public function tips() {
?>
<p><?php _e( 'Welcome to WordPress. We hope that you will find this platform incredibly rewarding! As a new WordPress user coming from Indexhibit 2, there are some things that we would like to point out. Hopefully, they will help your transition go as smoothly as possible.', 'indexhibit2-importer' ); ?></p>
<p><?php _e( 'This plugin imports exhibits and media files from Indexhibit 2 sites, but ignores links, sections, subsections and exhibit formats.', 'indexhibit2-importer' ); ?></p>
<p><?php _e( 'Exhibits are imported as pages and media files are imported as attachments which are attached to their corresponding pages. If needed, you can convert the imported pages to posts or other post types with a plugin such as <a href="https://wordpress.org/plugins/post-type-switcher/">Post Type Switcher</a>.', 'indexhibit2-importer' ); ?></p>
<h3><?php _e( 'WordPress Resources', 'indexhibit2-importer' ); ?></h3>
<p><?php _e( 'Finally, there are numerous WordPress resources around the internet. Some of them are:', 'indexhibit2-importer' ); ?></p>
<ul>
<li><?php _e( '<a href="http://wordpress.org/">The official WordPress site</a>', 'indexhibit2-importer' ); ?></li>
<li><?php _e( '<a href="http://wordpress.org/support/">The WordPress support forums</a>', 'indexhibit2-importer' ); ?></li>
<li><?php _e( '<a href="http://developer.wordpress.org/">The WordPress developer docs (In other words, the WordPress Bible)</a>', 'indexhibit2-importer' ); ?></li>
</ul>
<p><?php _e( 'That’s it! What are you waiting for? Go <a href="../wp-login.php">log in</a>!', 'indexhibit2-importer' ); ?></p>
<?php
}
/**
* Registered callback function for the importer
*/
public function dispatch() {
$this->header();
$step = empty( $_GET['step'] ) ? 0 : (int) $_GET['step'];
if ( $step > 0 ) {
check_admin_referer( 'import-indexhibit2' );
$options = get_option( 'ix2_options' );
if ( isset( $_POST['ixurl'] ) ) {
$options['ix2_url'] = sanitize_text_field( esc_url( $_POST['ixurl'] ) );
}
if ( isset( $_POST['dbname'] ) ) {
$options['ix2_name'] = sanitize_text_field( $_POST['dbname'] );
}
if ( isset( $_POST['dbuser'] ) ) {
$options['ix2_user'] = sanitize_text_field( $_POST['dbuser'] );
}
if ( isset( $_POST['dbpass'] ) ) {
$options['ix2_pass'] = sanitize_text_field( $_POST['dbpass'] );
}
if ( isset( $_POST['dbhost'] ) ) {
$options['ix2_host'] = sanitize_text_field( $_POST['dbhost'] );
}
if ( isset( $_POST['dbprefix'] ) ) {
$options['ix2_dbprefix'] = sanitize_text_field( $_POST['dbprefix'] );
}
if ( isset( $_POST['mdinsert'] ) ) {
$options['ix2_mdinsert'] = '1';
} else {
$options['ix2_mdinsert'] = '0';
}
update_option( 'ix2_options', $options );
}
switch ( $step ) {
default:
case 0:
// Clean options.
$this->clean_options();
$this->greet();
break;
case 1:
// Try to remove execution time limit to avoid timeouts.
set_time_limit( 0 );
// Initialize database connection.
$conn = $this->init_ix2db();
if ( $conn ) {
// Import content.
$result = $this->import_exhibits();
if ( is_wp_error( $result ) ) {
echo $result->get_error_message();
}
} else {
echo '<p>' . __( 'Cannot connect to Indexhibit 2 database', 'indexhibit2-importer' ) . '</p>';
echo '<a class="button" href="admin.php?import=indexhibit2">' . __( 'Try Again', 'indexhibit2-importer' ) . '</a>';
}
break;
case 2:
// Try to remove execution time limit to avoid timeouts.
set_time_limit( 0 );
// Initialize database connection.
$conn = $this->init_ix2db();
if ( $conn ) {
// Import content.
$result = $this->import_media();
if ( is_wp_error( $result ) ) {
echo $result->get_error_message();
}
} else {
echo '<p>' . __( 'Cannot connect to Indexhibit 2 database', 'indexhibit2-importer' ) . '</p>';
echo '<a class="button" href="admin.php?import=indexhibit2">' . __( 'Try Again', 'indexhibit2-importer' ) . '</a>';
}
break;
case 3:
do_action( 'import_done', 'indexhibit2' );
$this->tips();
break;
}
$this->footer();
}
}
}
/**
* Register importer
*/
function ix2_importer_init() {
load_plugin_textdomain( 'indexhibit2-importer' );
$ix2_import = new Ix2_Import();
register_importer( 'indexhibit2', __( 'Indexhibit 2', 'indexhibit2-importer' ), __( 'Import exhibits and media files from an Indexhibit 2 site.', 'indexhibit2-importer' ), array( $ix2_import, 'dispatch' ) );
}
add_action( 'init', 'ix2_importer_init' );