forked from vanilla/porter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
class.bbpress.php
219 lines (195 loc) · 7.19 KB
/
class.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
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
<?php
/**
* bbPress exporter tool
*
* @copyright Vanilla Forums Inc. 2010
* @license http://opensource.org/licenses/gpl-2.0.php GNU GPL2
* @package VanillaPorter
*/
$Supported['bbPress'] = array('name'=>'bbPress 1.*', 'prefix' => 'bb_');
class BbPress extends ExportController {
/** @var array Required tables => columns */
protected $SourceTables = array(
'forums' => array(),
'posts' => array(),
'topics' => array(),
'users' => array('ID', 'user_login', 'user_pass', 'user_email', 'user_registered'),
'meta' => array()
);
/**
* Forum-specific export format.
* @param ExportModel $Ex
*/
protected function ForumExport($Ex) {
// Begin
$Ex->BeginExport('', 'bbPress 1.*', array('HashMethod' => 'Vanilla'));
// Users
$User_Map = array(
'ID'=>'UserID',
'user_login'=>'Name',
'user_pass'=>'Password',
'user_email'=>'Email',
'user_registered'=>'DateInserted'
);
$Ex->ExportTable('User', "select * from :_users", $User_Map); // ":_" will be replace by database prefix
// Roles
$Ex->ExportTable('Role',
"select 1 as RoleID, 'Guest' as Name
union select 2, 'Key Master'
union select 3, 'Administrator'
union select 4, 'Moderator'
union select 5, 'Member'
union select 6, 'Inactive'
union select 7, 'Blocked'");
// UserRoles
$UserRole_Map = array(
'user_id'=>'UserID'
);
$Ex->ExportTable('UserRole',
"select distinct
user_id,
case when locate('keymaster', meta_value) <> 0 then 2
when locate('administrator', meta_value) <> 0 then 3
when locate('moderator', meta_value) <> 0 then 4
when locate('member', meta_value) <> 0 then 5
when locate('inactive', meta_value) <> 0 then 6
when locate('blocked', meta_value) <> 0 then 7
else 1 end as RoleID
from :_usermeta
where meta_key = 'bb_capabilities'", $UserRole_Map);
// Categories
$Category_Map = array(
'forum_id'=>'CategoryID',
'forum_name'=>'Name',
'forum_desc'=>'Description',
'forum_slug'=>'UrlCode',
'left_order'=>'Sort'
);
$Ex->ExportTable('Category', "select *,
lower(forum_slug) as forum_slug,
nullif(forum_parent,0) as ParentCategoryID
from :_forums", $Category_Map);
// Discussions
$Discussion_Map = array(
'topic_id'=>'DiscussionID',
'forum_id'=>'CategoryID',
'topic_poster'=>'InsertUserID',
'topic_title'=>'Name',
'Format'=>'Format',
'topic_start_time'=>'DateInserted',
'topic_sticky'=>'Announce'
);
$Ex->ExportTable('Discussion', "select t.*,
'Html' as Format,
case t.topic_open when 0 then 1 else 0 end as Closed
from :_topics t", $Discussion_Map);
// Comments
$Comment_Map = array(
'post_id' => 'CommentID',
'topic_id' => 'DiscussionID',
'post_text' => array('Column'=>'Body', 'Filter'=>'bbPressTrim'),
'Format' => 'Format',
'poster_id' => 'InsertUserID',
'post_time' => 'DateInserted'
);
$Ex->ExportTable('Comment', "select p.*,
'Html' as Format
from :_posts p", $Comment_Map);
// Conversations.
// The export is different depending on the table layout.
$PM = $Ex->Exists('bbpm', array('ID', 'pm_title', 'pm_from', 'pm_to', 'pm_text', 'sent_on', 'pm_thread'));
$ConversationVersion = '';
if ($PM === TRUE) {
// This is from an old version of the plugin.
$ConversationVersion = 'old';
} elseif (is_array($PM) && count(array_intersect(array('ID', 'pm_from', 'pm_text', 'sent_on', 'pm_thread'), $PM)) == 0) {
// This is from a newer version of the plugin.
$ConversationVersion = 'new';
}
if ($ConversationVersion) {
// Conversation.
$Conv_Map = array(
'pm_thread' => 'ConversationID',
'pm_from' => 'InsertUserID'
);
$Ex->ExportTable('Conversation',
"select *, from_unixtime(sent_on) as DateInserted
from :_bbpm
where thread_depth = 0", $Conv_Map);
// ConversationMessage.
$ConvMessage_Map = array(
'ID' => 'MessageID',
'pm_thread' => 'ConversationID',
'pm_from' => 'InsertUserID',
'pm_text' => array('Column'=>'Body','Filter'=>'bbPressTrim')
);
$Ex->ExportTable('ConversationMessage',
'select *, from_unixtime(sent_on) as DateInserted
from :_bbpm', $ConvMessage_Map);
// UserConversation.
$Ex->Query("create temporary table bbpmto (UserID int, ConversationID int)");
if ($ConversationVersion == 'new') {
$To = $Ex->Query("select object_id, meta_value from bb_meta where object_type = 'bbpm_thread' and meta_key = 'to'", TRUE);
if (is_resource($To)) {
while (($Row = @mysql_fetch_assoc($To)) !== false) {
$Thread = $Row['object_id'];
$Tos = explode(',', trim($Row['meta_value'], ','));
$ToIns = '';
foreach ($Tos as $ToID) {
$ToIns .= "($ToID,$Thread),";
}
$ToIns = trim($ToIns, ',');
$Ex->Query("insert bbpmto (UserID, ConversationID) values $ToIns", TRUE);
}
mysql_free_result($To);
$Ex->ExportTable('UserConversation', 'select * from bbpmto');
}
} else {
$ConUser_Map = array(
'pm_thread' => 'ConversationID',
'pm_from' => 'UserID'
);
$Ex->ExportTable('UserConversation',
'select distinct
pm_thread,
pm_from,
del_sender as Deleted
from bb_bbpm
union
select distinct
pm_thread,
pm_to,
del_reciever
from bb_bbpm', $ConUser_Map);
}
}
// End
$Ex->EndExport();
}
}
function bbPressTrim($Text) {
return rtrim(bb_code_trick_reverse($Text));
}
function bb_code_trick_reverse( $text ) {
$text = preg_replace_callback("!(<pre><code>|<code>)(.*?)(</code></pre>|</code>)!s", 'bb_decodeit', $text);
$text = str_replace(array('<p>', '<br />'), '', $text);
$text = str_replace('</p>', "\n", $text);
$text = str_replace('<coded_br />', '<br />', $text);
$text = str_replace('<coded_p>', '<p>', $text);
$text = str_replace('</coded_p>', '</p>', $text);
return $text;
}
function bb_decodeit( $matches ) {
$text = $matches[2];
$trans_table = array_flip(get_html_translation_table(HTML_ENTITIES));
$text = strtr($text, $trans_table);
$text = str_replace('<br />', '<coded_br />', $text);
$text = str_replace('<p>', '<coded_p>', $text);
$text = str_replace('</p>', '</coded_p>', $text);
$text = str_replace(array('&','&'), '&', $text);
$text = str_replace(''', "'", $text);
if ( '<pre><code>' == $matches[1] )
$text = "\n$text\n";
return "`$text`";
}
?>