-
Notifications
You must be signed in to change notification settings - Fork 0
/
importer-bbpress.php
155 lines (142 loc) · 4.23 KB
/
importer-bbpress.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
<?php
/*
Plugin Name: BBXF Import
Plugin URI: http://www.bbpress.org/
Description: Allows administrators to import forum data from a BBXF file.
Author: Dan Larkin
Version: 0.1 alpha
Author URI: http://www.stealyourcarbon.net/
*/
/**
* Includes necessary files.
*/
function import_init ()
{
if (!class_exists ('BBXF_Parse'))
{
require_once ('importer/bbxf-parse.php');
require_once ('importer/bbip.php');
require_once ('importer/bbip-bbpress.php');
}
if (!class_exists ('BBXP'))
{
require_once ('exporter/bbxp.php');
require_once ('exporter/bbxp-bbpress.php');
}
}
/**
* Executes all necessary functions to make the importation happen.
*/
function import_main ()
{
global $bbdb;
import_init ();
$bbip = new BBIP_bbPress;
$bbip->db = $bbdb;
$bbip->export_lib->db = $bbdb;
if ('true' == $_POST['users'])
{
$bbip->import_users = true;
}
if ('true' == $_POST['content'])
{
$bbip->import_content = true;
}
if ('true' == $_POST['preserve'])
{
$bbip->preserve_ids = true;
if ('true' == $_POST['current'])
{
$bbip->preserve_current_user = true;
}
if ('true' == $_POST['admins'])
{
$bbip->preserve_admins = true;
}
}
$bbip->read_file ($_FILES['import_file']['tmp_name']);
while ($bbip->file_contents)
{
$current = $bbip->find_element ($bbip->file_contents);
if ('!--' != $current[0] && '?xml' != $current[0] && 'forums_data' != $current[0])
{
die ('Invalid top-level element (' . $current[0] . ').');
}
$bbip->call_element ($current);
$bbip->file_contents = $bbip->remove_element ($current[1], $bbip->file_contents);
}
$bbip->check_for_duplicates ();
$bbip->import_prep ();
if ($bbip->import_users)
{
$bbip->insert_users ();
}
if ($bbip->import_content)
{
$bbip->insert_forums ();
$bbip->insert_topics ();
}
display_import_results ($bbip);
}
/**
* Displays the results of the importation process.
*
* Displays message upon successful importation. Also displays
* data that was skipped based on user import options.
* (Needs prettification.)
*/
function display_import_results ($bbip)
{
?>
<p><?php _e ('The importation process was completed successfully!'); ?></p>
<?php if ($bbip->skipped_data) : ?>
<p><?php _e ('Based on the options you chose and conflicts with existing data, some data was skipped. This data will be shown below. Sorry it\'s not very pretty yet...'); ?></p>
<pre><?php print_r ($bbip->skipped_data); ?></pre>
<?php
endif;
}
/**
* Displays the admin import page.
*
* Gives a simple explanation of how the import process works and gives
* users a form to choose their options and provide their file.
*/
function import_page ()
{
?>
<h2><?php _e ('Import'); ?></h2>
<?php if ('true' == $_POST['importing']) : import_main (); else : ?>
<p><?php _e ('bbPress can import forums data from a BBXF file you provide via the form below. Such a file can be generated by another bbPress installation or another forum software with a compatible export feature.'); ?></p>
<p><?php _e ('This file should contain data about users, forums, topics, and posts. You can select which types of data to import below.'); ?></p>
<form enctype="multipart/form-data" action="" method="post">
<fieldset>
<legend>Import File »</legend>
<input type="file" name="import_file" />
</fieldset>
<fieldset>
<legend>Options »</legend>
<input type="checkbox" name="users" value="true" checked /> Import user data.<br />
<input type="checkbox" name="content" value="true" checked /> Import forum, topic, and post data.<br />
<input type="checkbox" name="preserve" value="true" /> Preserve IDs.<br />
<input type="checkbox" name="current" value="true" checked /> Do not overwrite current user.<br />
<input type="checkbox" name="admins" value="true" checked /> Do not overwrite keymasters.
</fieldset>
<!-- Form options. -->
<p class="submit">
<input type="submit" name="submit" value="<?php _e ('Import Forums Data'); ?>" />
<input type="hidden" name="importing" value="true" />
</p>
</form>
<?php
endif;
}
/**
* Adds import link to admin menu.
*/
function import_add_admin ()
{
global $bb_submenu;
$bb_submenu['content.php'][] = array (__('Import'), 'use_keys', 'import_page', 'importer-bbpress.php');
}
add_action ('bb_admin_menu_generator', 'import_add_admin');
?>