forked from vanilla/porter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
class.simplepress.php
226 lines (197 loc) · 6.51 KB
/
class.simplepress.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
<?php
/**
* ppPress exporter tool
*
* @copyright Vanilla Forums Inc. 2010
* @license http://opensource.org/licenses/gpl-2.0.php GNU GPL2
* @package VanillaPorter
*/
$Supported['SimplePress'] = array('name'=>'SimplePress 1.*', 'prefix' => 'wp_');
class SimplePress extends ExportController {
/** @var array Required tables => columns */
protected $SourceTables = array(
'sfforums' => array(),
'sfposts' => array(),
'sftopics' => array(),
'users' => array('ID', 'user_nicename', 'user_pass', 'user_email', 'user_registered')
//'meta' => array()
);
/**
* Forum-specific export format.
* @param ExportModel $Ex
*/
protected function ForumExport($Ex) {
$Ex->SourcePrefix = 'wp_';
// Get the characterset for the comments.
$CharacterSet = $Ex->GetCharacterSet('posts');
if ($CharacterSet)
$Ex->CharacterSet = $CharacterSet;
// Begin
$Ex->BeginExport('', 'SimplePress 1.*', array('HashMethod' => 'Vanilla'));
// Users
$User_Map = array(
'user_id' => 'UserID',
'display_name' => 'Name',
'user_pass' => 'Password',
'user_email' => 'Email',
'user_registered' => 'DateInserted',
'lastvisit' => 'DateLastActive'
);
$Ex->ExportTable('User',
"select m.*, u.user_pass, u.user_email, u.user_registered
from wp_users u
join wp_sfmembers m
on u.ID = m.user_id;", $User_Map);
// Roles
$Role_Map = array(
'usergroup_id' => 'RoleID',
'usergroup_name' => 'Name',
'usergroup_desc' => 'Description'
);
$Ex->ExportTable('Role',
"select
usergroup_id,
usergroup_name,
usergroup_desc
from wp_sfusergroups
union
select
100,
'Administrators',
''", $Role_Map);
// Permissions.
$Ex->ExportTable('Permission', "select
usergroup_id as RoleID,
case
when usergroup_name like 'Guest%' then 'View'
when usergroup_name like 'Member%' then 'View,Garden.SignIn.Allow,Garden.Profiles.Edit,Vanilla.Discussions.Add,Vanilla.Comments.Add'
when usergroup_name like 'Mod%' then 'View,Garden.SignIn.Allow,Garden.Profiles.Edit,Garden.Settings.View,Vanilla.Discussions.Add,Vanilla.Comments.Add,Garden.Moderation.Manage'
end as _Permissions
from wp_sfusergroups
union
select 100, 'All'");
// UserRoles
$UserRole_Map = array(
'user_id'=>'UserID',
'usergroup_id'=>'RoleID'
);
$Ex->ExportTable('UserRole',
"select
m.user_id,
m.usergroup_id
from wp_sfmemberships m
union
select
um.user_id,
100
from wp_usermeta um
where um.meta_key = 'wp_capabilities'
and um.meta_value like '%PF Manage Forums%'", $UserRole_Map);
// Categories
$Category_Map = array(
'forum_id' => 'CategoryID',
'forum_name' => array('Column'=>'Name','Filter'=>array($Ex, 'HTMLDecoder')),
'forum_desc' => 'Description',
'forum_seq' => 'Sort',
'form_slug' => 'UrlCode',
'parent_id' => 'ParentCategoryID'
);
$Ex->ExportTable('Category', "
select
f.forum_id,
f.forum_name,
f.forum_seq,
f.forum_desc,
lower(f.forum_slug) as forum_slug,
case when f.parent = 0 then f.group_id + 1000 else f.parent end as parent_id
from wp_sfforums f
union
select
1000 + g.group_id,
g.group_name,
g.group_seq,
g.group_desc,
null,
null
from wp_sfgroups g", $Category_Map);
// Discussions
$Discussion_Map = array(
'topic_id'=>'DiscussionID',
'forum_id'=>'CategoryID',
'user_id'=>'InsertUserID',
'topic_name'=>'Name',
'Format'=>'Format',
'topic_date'=>'DateInserted',
'topic_pinned'=>'Announce',
'topic_slug' => array('Column' => 'Slug', 'Type' => 'varchar(200)')
);
$Ex->ExportTable('Discussion', "select t.*,
'Html' as Format
from :_sftopics t", $Discussion_Map);
if ($Ex->Exists('sftags')) {
// Tags
$Tag_Map = array(
'tag_id' => 'TagID',
'tag_name' => 'Name');
$Ex->ExportTable('Tag', "select * from :_sftags", $Tag_Map);
if ($Ex->Exists('sftagmeta')) {
$TagDiscussion_Map = array(
'tag_id' => 'TagID',
'topic_id' => 'DiscussionID');
$Ex->ExportTable('TagDiscussion', "select * from :_sftagmeta", $TagDiscussion_Map);
}
}
// Comments
$Comment_Map = array(
'post_id' => 'CommentID',
'topic_id' => 'DiscussionID',
'post_content' => 'Body',
'Format' => 'Format',
'user_id' => 'InsertUserID',
'post_date' => 'DateInserted',
'poster_ip' => 'InsertIPAddress'
);
$Ex->ExportTable('Comment', "select p.*,
'Html' as Format
from :_sfposts p", $Comment_Map);
// Conversation.
$Conv_Map = array(
'message_id' => 'ConversationID',
'from_id' => 'InsertUserID',
'sent_date' => 'DateInserted'
);
$Ex->ExportTable('Conversation',
"select *
from :_sfmessages
where is_reply = 0", $Conv_Map);
// ConversationMessage.
$ConvMessage_Map = array(
'message_id' => 'MessageID',
'from_id' => 'InsertUserID',
'message' => array('Column'=>'Body')
);
$Ex->ExportTable('ConversationMessage',
'select c.message_id as ConversationID, m.*
from :_sfmessages c
join :_sfmessages m
on (m.is_reply = 0 and m.message_id = c.message_id) or (m.is_reply = 1 and c.is_reply = 0 and m.message_slug = c.message_slug and m.from_id in (c.from_id, c.to_id) and m.to_id in (c.from_id, c.to_id));',
$ConvMessage_Map);
// UserConversation
$UserConv_Map = array(
'message_id' => 'ConversationID',
'from_id' => 'UserID'
);
$Ex->ExportTable('UserConversation',
'select message_id, from_id
from :_sfmessages
where is_reply = 0
union
select message_id, to_id
from :_sfmessages
where is_reply = 0',
$UserConv_Map);
// End
$Ex->EndExport();
}
}
?>