-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimport.php
executable file
·277 lines (199 loc) · 8.06 KB
/
import.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
<?php
ini_set("display_errors","2");
if(!($link = mysqli_connect ( "localhost" , "root" , "", "drupal" ))) {
die("Keine Verbindung zur Datenbank.");
} else {
print "verbindung klappt...";
}
function dateToTimestamp( $string ){
$format = 'Y-m-d H:i:s';
$dt = DateTime::createFromFormat($format, $string);
#echo "Format: $format; " . $dt->date . "\n";
return $dt->getTimestamp();
}
function getTIDbyString( $string, $link ){
$res = mysqli_query($link, "SELECT tid FROM term_data WHERE name = '" . $string . "'");
$vid_row = mysqli_fetch_row($res);
return $vid_row[0];
}
function replaceMarkup( $string ){
$string = preg_replace( "/\[b\]/","<strong>", $string);
$string = preg_replace( "/\[\/b\]/","</strong>", $string);
$string = preg_replace( "/\[url\](.*)\[\/url\]/","<a href=$1>$1</a>", $string);
$string = preg_replace( "/\[url=(.*)\](.*)\[\/url\]/","<a href=$1>$1</a>", $string);
return $string;
}
function importPhengUser( $link )
{
mysqli_query($link, "delete from users where uid > 5");
$ergebnis = mysqli_query($link, "SELECT name,pass, email FROM pheng_users");
while($daten = mysqli_fetch_assoc($ergebnis)) {
$name = $daten["name"];
$mail = $daten["email"];
$pass = md5( $daten["pass"] );
print "<br>$name";
//echo "<br />Website: ".$daten["website"];
$sql = "INSERT INTO users VALUES('','" . $name . "','" . $pass . " ','" . $mail . "','0','0','0','','','0','1271511383','0','0','1','NULL','" . $mail . "','','','')";
# print $sql;
#TODO: add user roles
print "ROLE NOT SET!!";
if( mysqli_query($link,$sql)) {
echo "Erfolgreiches UPDATE.";
} else {
echo "UPDATE gescheitert.";
echo $link->error;
#exit();
}
}
}
function importPhengComments( $link )
{
mysqli_query($link, "delete from comments where cid > 5");
$ergebnis = mysqli_query($link, "SELECT * FROM pheng_posts ORDER BY id ASC");
while($daten = mysqli_fetch_assoc($ergebnis)) {
$d = $daten["post_date"];
$timestamp = dateToTimestamp ( $d );
$res = mysqli_query($link, "SELECT subject,minid FROM pheng_threads WHERE id='" . $daten["thread"] ."' LIMIT 1");
$vid_row = mysqli_fetch_row($res);
$subject = mysqli_real_escape_string($link, $vid_row[0] );
$minid = $vid_row[1];
if( $minid == $daten["id"])
{
#print "breaking here, same id!";
continue;
}
$comment = replaceMarkup( $daten["message"] );
$comment = mysqli_real_escape_string($link, $comment );
$poster = $daten["poster"];
$name = $poster;
$sql = "SELECT nid FROM node_revisions WHERE title = '" . $subject . "'";
$res = mysqli_query($link,$sql);
if( $res ){
#echo "Erfolgreiches SELECT.";
} else {
echo "SELECT gescheitert.";
echo $link->error;
exit();
}
$vid_row = mysqli_fetch_row($res);
$nid = $vid_row[0];
if( $nid == 0){
print $sql;
}
$sql = "SELECT nid FROM comments WHERE nid='" . $nid . "'";
$res = mysqli_query($link, $sql);
$i=1;
while( $rows = mysqli_fetch_array($res)){
$i++;
}
$thread = str_pad($i, 2, "0", STR_PAD_LEFT). "/";
$res = mysqli_query($link, "SELECT uid FROM users WHERE name='" . $daten["poster"] ."'");
$vid_row = mysqli_fetch_row($res);
$uid = $vid_row[0];
#print "<br>$name";
#//echo "<br />Website: ".$daten["website"];
$sql = "INSERT INTO comments VALUES('','0','" . $nid . "','" . $uid . " ','" . $subject . "','". $comment ."','127.0.0.1','" . $timestamp . "','0','1','". $thread . "','" . $name . "','mail','homepage')";
#print $sql;
if( mysqli_query($link,$sql)) {
#echo "Erfolgreiches UPDATE.";
} else {
echo "UPDATE gescheitert.";
echo $link->error;
exit();
}
}
}
function importPhengPosts( $link )
{
print "deleting tables <br />";
mysqli_query($link, "delete from node where nid > 5");
mysqli_query($link, "delete from term_node where nid > 5");
mysqli_query($link, "delete from node_revisions where nid > 5");
mysqli_query($link, "delete from forum where nid > 5");
mysqli_query($link, "delete from node_comment_statistics where nid > 5");
#INSERT INTO `drupal`.`node_comment_statistics` (`nid`, `last_comment_timestamp`, `last_comment_name`, `last_comment_uid`, `comment_count`) VALUES ('6', '1271535921', 'NULL', '1', '0');
print "importing posts <br />";
////exit();
$ergebnis = mysqli_query($link, "SELECT * FROM pheng_threads");
while($daten = mysqli_fetch_assoc($ergebnis)) {
$res = mysqli_query($link, "SELECT MAX(vid) FROM node");
$vid_row = mysqli_fetch_row($res);
$vid = $vid_row[0]+1;
$res = mysqli_query($link, "SELECT MAX(nid) FROM node");
$vid_row = mysqli_fetch_row($res);
$nid = $vid_row[0]+1;
$res = mysqli_query($link, "SELECT uid FROM users WHERE name='" . $daten["starter"] ."'");
$vid_row = mysqli_fetch_row($res);
$uid = $vid_row[0];
$res = mysqli_query($link, "SELECT uid FROM users WHERE name='" . $daten["lastposter"] ."'");
$vid_row = mysqli_fetch_row($res);
$lastposter_uid = $vid_row[0];
#print $uid;
$minID = $daten["minid"];
$replies = $daten["replies"];
$res = mysqli_query($link, "SELECT message FROM pheng_posts WHERE id='" . $minID ."'");
$vid_row = mysqli_fetch_row($res);
$body = replaceMarkup( $vid_row[0] );
$body = mysqli_real_escape_string( $link, $body);
$lastChanged = dateToTimestamp( $daten["lastpost"] );
$created = dateToTimestamp( $daten["started"] );
$title = mysqli_real_escape_string($link, $daten["subject"] );
#$uid=32;
#print $title;
$sql = "INSERT INTO node VALUES('". $nid . "','". $vid ."' , 'forum', '', '" . $title . "','" . $uid . "','1','" . $created . "','" . $lastChanged . "','2','0','0','0','0','0')";
#print $sql;
if( mysqli_query($link,$sql)) {
#echo "Erfolgreiches UPDATE.<br />";
#$res = mysqli_query($link, "SELECT nid FROM node WHERE vid='" . $vid . "'");
#$vid_row = mysqli_fetch_row($res);
#$nid = $vid_row[0];
$fid = $daten["fid"];
if( $fid == 0 ) { $tid = getTIDbyString("Using hydrogen", $link); }
if( $fid == 1 ) { $tid = getTIDbyString("Using sound libraries", $link); }
if( $fid == 2 ) { $tid = getTIDbyString("Development questions",$link); }
if( $fid == 3 ) { $tid = getTIDbyString("Free zone",$link); }
if( $fid == 4 ) { $tid = getTIDbyString("Problems with hydrogen",$link); }
if( $fid == 5 ) { $tid = getTIDbyString("Hydrogen on Linux",$link); }
if( $fid == 6 ) { $tid = getTIDbyString("Hydrogen on Windows",$link); }
if( $fid == 7 ) { $tid = getTIDbyString("Hydrogen on OS X",$link); }
if( $fid == 8 ) { $tid = getTIDbyString("Share your songs",$link); }
if( $fid == 9 ) { $tid = getTIDbyString("Announcements",$link); }
if( $fid == 10 ) { $tid = getTIDbyString("Show your music",$link); }
#print "tid=". $tid . " vid= " . $vid ."nid=" . $nid;
mysqli_query($link, "INSERT INTO forum VALUES('" . $nid . "','" . $vid . "','" . $tid ."')" );
if( mysqli_query($link, "INSERT INTO term_node VALUES('" . $nid . "','" . $vid . "','" . $tid ."')" ) ) {
#
} else {
echo $link->error;
}
$teaser = $title ;
$sql="INSERT INTO node_revisions VALUES('". $nid . "','". $vid . "','" . $uid . "','" . $title . "','" . $body . "','" . $teaser . "','','" . $created . "','1')";
#print $sql;
#mysqli_query( $link, $sql);
if( mysqli_query($link, $sql ) ){
#
} else {
echo $link->error;
}
$last_comment_timestamp = $lastChanged;
$last_comment_name = "NULL";
$last_comment_uid = $lastposter_uid;
$comment_count = $replies;
$sql ="INSERT INTO node_comment_statistics VALUES('" . $nid. "','" . $last_comment_timestamp . "','" . $last_comment_name . "','" . $last_comment_uid . "','" . $comment_count . "')";
#print $sql;
if( mysqli_query($link, $sql ) ){
#
} else {
echo $link->error;
}
} else {
echo "UPDATE gescheitert.<br />";
echo $link->error;
exit();
}
}
}
#importPhengUser( $link );
importPhengPosts( $link );
importPhengComments( $link );
?>