كود :
Private Sub forums_importer_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles forums_importer.DoWork
Dim vbcon As New MySqlConnection(gvbstr)
Dim vbcom As New MySqlCommand("", vbcon)
ff("=======================================================")
vbcom.CommandText = "select * from `forum` where `parentid`='-1' order by forumid"
If vbcon.State = ConnectionState.Closed Then
vbcon.Open()
End If
Using vbdr As MySqlDataReader = vbcom.ExecuteReader
Do While vbdr.Read
If forums_importer.CancellationPending = True Then Exit Do : Exit Sub
Dim cfinsertcon As New MySqlConnection(gmybbstr)
Dim cfinsertcom As New MySqlCommand("", cfinsertcon)
'insertcom.CommandText = "insert into mybb_forums(name,description,linkto,type,pid,parentlist,disporder,active,open,threads,posts,lastposter,lastposteruid,lastposttid,lastpostsubject,allowhtml,allowmycode,allowsmilies,allowimgcode,allowvideocode,allowpicons,allowtratings,usepostcounts,usethreadcounts,requireprefix,password,showinjump,style,overridestyle,rulestype,rulestitle,rules,unapprovedthreads,unapprovedposts,deletedthreads,deletedposts,defaultdatecut,defaultsortby,defaultsortorder) values(@name,@description,@linkto,@type,@pid,@parentlist,@disporder,@active,@open,@threads,@posts,@lastposter,@lastposteruid,@lastposttid,@lastpostsubject,@allowhtml,@allowmycode,@allowsmilies,@allowimgcode,@allowvideocode,@allowpicons,@allowtratings,@usepostcounts,@usethreadcounts,@requireprefix,@password,@showinjump,@style,@overridestyle,@rulestype,@rulestitle,@rules,@unapprovedthreads,@unapprovedposts,@deletedthreads,@deletedposts,@defaultdatecut,@defaultsortby,@defaultsortorder)"
cfinsertcom.CommandText = "insert into mybb_forums(name,description,linkto,type,pid,parentlist,disporder,active,open,allowhtml,allowmycode,allowsmilies,allowimgcode,allowvideocode,allowpicons,allowtratings,requireprefix,password,showinjump,style,overridestyle,rulestype,rulestitle,rules,defaultdatecut,defaultsortby,defaultsortorder) values(@name,@description,@linkto,@type,@pid,@parentlist,@disporder,@active,@open,@allowhtml,@allowmycode,@allowsmilies,@allowimgcode,@allowvideocode,@allowpicons,@allowtratings,@requireprefix,@password,@showinjump,@style,@overridestyle,@rulestype,@rulestitle,@rules,@defaultdatecut,@defaultsortby,@defaultsortorder)"
Dim cforumurl As String = "http://127.0.0.1/" & gvbfolder() & "/forumdisplay.php?f=" & vbdr.Item("forumid")
ff("الاستعلام عن الاقسام")
ff("قراءة رابط القسم: " & cforumurl)
Dim cfhtml As String = ghtmlsrc(cforumurl)
Dim cfdoc As New HtmlAgilityPack.HtmlDocument
cfdoc.LoadHtml(cfhtml)
Dim qn As String = cfdoc.DocumentNode.SelectSingleNode("//title").InnerText.Trim
cfinsertcom.Parameters.AddWithValue("@name", qn)
ff(" حفظ القسم: " & qn)
fl("قراءة القسم : " & qn)
Try
Dim qd As String = cfdoc.DocumentNode.SelectSingleNode("//p[@class='description']").InnerText.Trim
cfinsertcom.Parameters.AddWithValue("@description", qd)
ff(" وصف القسم : " & qd)
Catch ex As Exception
cfinsertcom.Parameters.AddWithValue("@description", "")
End Try
cfinsertcom.Parameters.AddWithValue("@linkto", "")
cfinsertcom.Parameters.AddWithValue("@type", "c")
cfinsertcom.Parameters.AddWithValue("@pid", "0")
cfinsertcom.Parameters.AddWithValue("@parentlist", "")
cfinsertcom.Parameters.AddWithValue("@disporder", vbdr.Item("displayorder"))
cfinsertcom.Parameters.AddWithValue("@active", "1")
cfinsertcom.Parameters.AddWithValue("@open", "1")
cfinsertcom.Parameters.AddWithValue("@allowhtml", "0")
cfinsertcom.Parameters.AddWithValue("@allowmycode", "1")
cfinsertcom.Parameters.AddWithValue("@allowsmilies", "1")
cfinsertcom.Parameters.AddWithValue("@allowimgcode", "1")
cfinsertcom.Parameters.AddWithValue("@allowvideocode", "1")
cfinsertcom.Parameters.AddWithValue("@allowpicons", "1")
cfinsertcom.Parameters.AddWithValue("@allowtratings", "1")
cfinsertcom.Parameters.AddWithValue("@requireprefix", "0")
cfinsertcom.Parameters.AddWithValue("@password", vbdr.Item("password"))
cfinsertcom.Parameters.AddWithValue("@showinjump", "1")
cfinsertcom.Parameters.AddWithValue("@style", vbdr.Item("styleid"))
cfinsertcom.Parameters.AddWithValue("@overridestyle", 0)
cfinsertcom.Parameters.AddWithValue("@rulestype", 0)
cfinsertcom.Parameters.AddWithValue("@rulestitle", "")
cfinsertcom.Parameters.AddWithValue("@rules", "")
cfinsertcom.Parameters.AddWithValue("@defaultdatecut", 0)
cfinsertcom.Parameters.AddWithValue("@defaultsortby", "")
cfinsertcom.Parameters.AddWithValue("@defaultsortorder", "")
If cfinsertcon.State = ConnectionState.Closed Then
cfinsertcon.Open()
End If
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
cfinsertcom.ExecuteNonQuery()
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
ff(" تم حفظ القسم: " & qn & " بنجاح")
ff("=======================================================")
'الان نبدا بحفظ المنتديات التابعة للاقسام
Dim fcon As New MySqlConnection(gvbstr)
Dim fcom As New MySqlCommand("", fcon)
fcom.CommandText = "select * from `forum` where `parentid`='" & vbdr.Item("forumid") & "' order by forumid"
If fcon.State = ConnectionState.Closed Then
fcon.Open()
End If
Using fdr As MySqlDataReader = fcom.ExecuteReader
If fdr.HasRows Then
ff("الاستعلام عن المنتديات التابعة للقسم")
ff("تم الحصول على منتديات تابعة للقسم: " & qn)
Do While fdr.Read
If forums_importer.CancellationPending = True Then Exit Do : Exit Do : Exit Sub
Dim mcon As New MySqlConnection(gmybbstr)
Dim minsert As New MySqlCommand("", mcon)
minsert.CommandText = "insert into mybb_forums(name,description,linkto,type,pid,parentlist,disporder,active,open,allowhtml,allowmycode,allowsmilies,allowimgcode,allowvideocode,allowpicons,allowtratings,requireprefix,password,showinjump,style,overridestyle,rulestype,rulestitle,rules,defaultdatecut,defaultsortby,defaultsortorder) values(@name,@description,@linkto,@type,@pid,@parentlist,@disporder,@active,@open,@allowhtml,@allowmycode,@allowsmilies,@allowimgcode,@allowvideocode,@allowpicons,@allowtratings,@requireprefix,@password,@showinjump,@style,@overridestyle,@rulestype,@rulestitle,@rules,@defaultdatecut,@defaultsortby,@defaultsortorder)"
Dim fforumurl As String = "http://127.0.0.1/" & gvbfolder() & "/forumdisplay.php?f=" & fdr.Item("forumid")
ff("قراءة رابط المنتدى: " & fforumurl)
Dim ffhtml As String = ghtmlsrc(fforumurl)
Dim ffdoc As New HtmlAgilityPack.HtmlDocument
ffdoc.LoadHtml(ffhtml)
Dim fnn As String = ffdoc.DocumentNode.SelectSingleNode("//title").InnerText.Trim
Dim fd As String = ffdoc.DocumentNode.SelectSingleNode("//p[@class='description']").InnerText.Trim
minsert.Parameters.AddWithValue("@name", fnn)
ff(" حفظ المنتدى: " & fnn)
fl(" نسخ المنتدى : " & fnn & " التابع للقسم : " & qn)
Try
minsert.Parameters.AddWithValue("@description", fd)
ff(" حفظ الوصف:" & fd)
Catch ex As Exception
minsert.Parameters.AddWithValue("@description", "")
End Try
minsert.Parameters.AddWithValue("@linkto", "")
minsert.Parameters.AddWithValue("@type", "f")
Dim maxcon As New MySqlConnection(gmybbstr)
Dim maxcom As New MySqlCommand("", maxcon)
If maxcon.State = ConnectionState.Closed Then
maxcon.Open()
End If
maxcom.CommandText = "select max(`fid`) from `mybb_forums` where `pid`='0'"
ff(" معرفة القسم الاب لهذا المنتدى")
minsert.Parameters.AddWithValue("@pid", maxcom.ExecuteScalar)
If maxcon.State = ConnectionState.Open Then
maxcon.Close()
End If
minsert.Parameters.AddWithValue("@parentlist", "")
minsert.Parameters.AddWithValue("@disporder", fdr.Item("displayorder"))
minsert.Parameters.AddWithValue("@active", "1")
minsert.Parameters.AddWithValue("@open", "1")
'threads,posts,lastposter,lastposteruid,lastposttid,lastpostsubject
'minsert.Parameters.AddWithValue("@threads", fdr.Item("threadcount"))
'minsert.Parameters.AddWithValue("@posts", fdr.Item("replycount"))
minsert.Parameters.AddWithValue("@allowhtml", "0")
minsert.Parameters.AddWithValue("@allowmycode", "1")
minsert.Parameters.AddWithValue("@allowsmilies", "1")
minsert.Parameters.AddWithValue("@allowimgcode", "1")
minsert.Parameters.AddWithValue("@allowvideocode", "1")
minsert.Parameters.AddWithValue("@allowpicons", "1")
minsert.Parameters.AddWithValue("@allowtratings", "1")
minsert.Parameters.AddWithValue("@requireprefix", "0")
minsert.Parameters.AddWithValue("@password", fdr.Item("password"))
minsert.Parameters.AddWithValue("@showinjump", "1")
minsert.Parameters.AddWithValue("@style", fdr.Item("styleid"))
minsert.Parameters.AddWithValue("@overridestyle", 0)
minsert.Parameters.AddWithValue("@rulestype", 0)
minsert.Parameters.AddWithValue("@rulestitle", "")
minsert.Parameters.AddWithValue("@rules", "")
minsert.Parameters.AddWithValue("@defaultdatecut", 0)
minsert.Parameters.AddWithValue("@defaultsortby", "")
minsert.Parameters.AddWithValue("@defaultsortorder", "")
If mcon.State = ConnectionState.Closed Then
mcon.Open()
End If
'@@@@@@@@@@@@@@@@@@@@@@@@@
minsert.ExecuteNonQuery()
ff(" تم حفظ المنتدى: " & fnn & " بنجاح")
ff("=======================================================")
'@@@@@@@@@@@@@@@@@@@@@@@@@@@
If mcon.State = ConnectionState.Open Then
mcon.Close()
End If
''القراءة من الثريدز
Dim threadcon As New MySqlConnection(gvbstr)
Dim threadcom As New MySqlCommand("", threadcon)
threadcom.CommandText = "select * from `thread` where `forumid`=" & fdr.Item("forumid") & " order by threadid asc"
If threadcon.State = ConnectionState.Closed Then
threadcon.Open()
End If
Using thrd As MySqlDataReader = threadcom.ExecuteReader
If thrd.HasRows Then
Do While thrd.Read
' ff(" الاستعلام عن مواضيع تابعة للمنتدى : " & fnn)
If forums_importer.CancellationPending = True Then Exit Do : Exit Do : Exit Do : Exit Sub
Dim threadinsertcon As New MySqlConnection(gmybbstr)
Dim threadinsertcom As New MySqlCommand("", threadinsertcon)
'الاضافة الى جدول الثريدز
threadinsertcom.CommandText = "insert into mybb_threads(fid,subject,uid,username,firstpost,lastpost,lastposter,lastposteruid,views,replies,closed,sticky,notes,visible,dateline) values(@fid,@subject,@uid,@username,@firstpost,@lastpost,@lastposter,@lastposteruid,@views,@replies,@closed,@sticky,@notes,@visible,@dateline)"
Dim maxfcon As New MySqlConnection(gmybbstr)
Dim maxfid As New MySqlCommand("", maxfcon)
maxfid.CommandText = "select max(`fid`) from `mybb_forums` where `type`='f'"
Dim lfid As String = ""
If maxfcon.State = ConnectionState.Closed Then
maxfcon.Open()
End If
lfid = maxfid.ExecuteScalar
threadinsertcom.Parameters.AddWithValue("@fid", maxfid.ExecuteScalar)
If maxfcon.State = ConnectionState.Open Then
maxfcon.Close()
End If
Dim thurl As String = "http://localhost/" & gvbfolder() & "/showthread.php?t=" & thrd.Item("threadid")
Dim thtml As String = ghtmlsrc(thurl)
Dim kateb As String = gusername(thtml)
Dim enwan As String = gtitle(thtml)
'ff("------------------------------------------")
ff("_____________________________________________________")
ff(thurl)
ff("العنوان: " & enwan & " الكاتب: " & kateb)
threadinsertcom.Parameters.AddWithValue("@subject", enwan)
' fl("نسخ الموضوع رقم: " & thrd.Item("threadid") & " التابع لمنتدى رقم: " & fdr.Item("forumid") & " التابع لقسم رقم: " & vbdr.Item("forumid"))
threadinsertcom.Parameters.AddWithValue("@uid", thrd.Item("postuserid"))
'Dim tunod As HtmlAgilityPack.HtmlNode = thdoc.DocumentNode.SelectSingleNode("//div[@class='userinfo']/div/div/a")
threadinsertcom.Parameters.AddWithValue("@username", kateb)
threadinsertcom.Parameters.AddWithValue("@firstpost", thrd.Item("firstpostid"))
threadinsertcom.Parameters.AddWithValue("@lastpost", thrd.Item("lastpostid"))
threadinsertcom.Parameters.AddWithValue("@lastposter", "")
'lastposteruid
threadinsertcom.Parameters.AddWithValue("@lastposteruid", thrd.Item("postuserid"))
'views,replies,closed,sticky,notes,visible,dateline
threadinsertcom.Parameters.AddWithValue("@views", thrd.Item("views"))
threadinsertcom.Parameters.AddWithValue("@replies", thrd.Item("replycount"))
If thrd.Item("open") = "0" Then
threadinsertcom.Parameters.AddWithValue("@closed", "1")
Else
threadinsertcom.Parameters.AddWithValue("@closed", "0")
End If
threadinsertcom.Parameters.AddWithValue("@sticky", thrd.Item("sticky"))
threadinsertcom.Parameters.AddWithValue("@notes", "")
threadinsertcom.Parameters.AddWithValue("@visible", thrd.Item("visible"))
threadinsertcom.Parameters.AddWithValue("@dateline", thrd.Item("dateline"))
If threadinsertcon.State = ConnectionState.Closed Then
threadinsertcon.Open()
End If
'================================
threadinsertcom.ExecuteNonQuery()
ff(" تم حفظ العنوان: " & enwan & " بنجاح")
ff("=============================")
' ff("_____________________________________________________")
'================================
'الان القراءة من البوستس
Dim postcon As New MySqlConnection(gmybbstr)
Dim maxtid As New MySqlCommand("select max(`tid`) from `mybb_threads`", postcon)
If postcon.State = ConnectionState.Closed Then
postcon.Open()
End If
Dim ltid As String = maxtid.ExecuteScalar
If postcon.State = ConnectionState.Open Then
postcon.Close()
End If
Dim vbc As New MySqlConnection(gvbstr)
Dim postcom As New MySqlCommand("", vbc)
postcom.CommandText = "select * from `post` where `threadid`=" & thrd.Item("threadid") & " order by postid asc"
If vbc.State = ConnectionState.Closed Then
vbc.Open()
End If
Dim mpostcon As New MySqlConnection(gmybbstr)
Using post As MySqlDataReader = postcom.ExecuteReader
If post.HasRows Then
Do While post.Read
If forums_importer.CancellationPending = True Then Exit Do : Exit Do : Exit Do : Exit Do : Exit Sub
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Dim postinsert As New MySqlCommand("", mpostcon)
postinsert.CommandText = "insert into mybb_posts(tid,subject,uid,fid,username,dateline,message,ipaddress,includesig,smilieoff,visible) values(@tid,@subject,@uid,@fid,@username,@dateline,@message,@ipaddress,@includesig,@smilieoff,@visible)"
'gtitle(thtml)
Dim url2 As String = "http://127.0.0.1/" & gvbfolder.Trim & "/showthread.php?t=" & thrd.Item("threadid").ToString.Trim & "&p=" & post.Item("postid").ToString.Trim
Dim phtml As String = ghtmlsrc(url2)
Dim poenwan As String = gtitle(phtml)
Dim pokateb As String = gpostusername(phtml, post.Item("postid"))
ff("الاستعلام عن المشاركات التابعة للموضوع: " & enwan)
ff(url2)
ff(" حفظ المشاركة: " & poenwan & " الكاتب: " & pokateb)
postinsert.Parameters.AddWithValue("@tid", ltid)
' fl("موضوع رقم: " & thrd.Item("threadid") & " مشاركة رقم: " & post.Item("postid"))
postinsert.Parameters.AddWithValue("@subject", poenwan)
postinsert.Parameters.AddWithValue("@uid", post.Item("userid"))
postinsert.Parameters.AddWithValue("@fid", lfid)
postinsert.Parameters.AddWithValue("@username", pokateb)
postinsert.Parameters.AddWithValue("@dateline", post.Item("dateline"))
postinsert.Parameters.AddWithValue("@message", gpostmessage(phtml, post.Item("postid")))
postinsert.Parameters.AddWithValue("@ipaddress", post.Item("ipaddress"))
'showsignature
postinsert.Parameters.AddWithValue("@includesig", post.Item("showsignature"))
'smilieoff,visible
If post.Item("allowsmilie") = "0" Then
postinsert.Parameters.AddWithValue("@smilieoff", "1")
Else
postinsert.Parameters.AddWithValue("@smilieoff", "0")
End If
postinsert.Parameters.AddWithValue("@visible", post.Item("visible"))
If mpostcon.State = ConnectionState.Closed Then
mpostcon.Open()
End If
'------------------------------
postinsert.ExecuteNonQuery()
ff(" تم حفظ المشاركة بنجاح ")
' ff("=======================================================")
'-------------------------------
'النظر الى المرفقات
'النظر الى مرفقات المشاركة
Dim atacon As New MySqlConnection(gvbstr)
Dim atacom As New MySqlCommand("", atacon)
atacom.CommandText = "select * from `attachment` where `contentid`=" & post.Item("postid") & " order by attachmentid"
If atacon.State = ConnectionState.Closed Then
atacon.Open()
End If
Using atard As MySqlDataReader = atacom.ExecuteReader
If atard.HasRows Then
ff("الاستعلام عن المرفقات")
ff("<<<<<<<<<< تم الحصول على مرفقات >>>>>>>>>>")
Do While atard.Read
If forums_importer.CancellationPending = True Then Exit Do : Exit Do : Exit Do : Exit Do : Exit Do : Exit Sub
Dim ataurl As String = "http://localhost/" & gvbfolder() & "/attachment.php?attachmentid=" & atard.Item("attachmentid")
Dim mbcon As New MySqlConnection(gmybbstr)
Dim toatt As New MySqlCommand("", mbcon)
toatt.CommandText = "insert into `mybb_attachments` (pid,uid,filename,filetype,filesize,attachname,visible) values(@pid,@uid,@filename,@filetype,@filesize,@attachname,@visible)"
Dim lpost As New MySqlConnection(gmybbstr)
Dim plastid As New MySqlCommand("", lpost)
plastid.CommandText = "select max(`pid`) from `mybb_posts`"
If lpost.State = ConnectionState.Closed Then
lpost.Open()
End If
toatt.Parameters.AddWithValue("@pid", plastid.ExecuteScalar)
toatt.Parameters.AddWithValue("@uid", atard.Item("userid"))
ff(" حفظ المرفق : " & atard.Item("filename"))
toatt.Parameters.AddWithValue("@filename", atard.Item("filename"))
toatt.Parameters.AddWithValue("@filetype", gfet(IO.Path.GetExtension(atard.Item("filename"))))
toatt.Parameters.AddWithValue("@filesize", gfs(ataurl))
If atard.Item("state") = "visible" Then
toatt.Parameters.AddWithValue("@visible", "1")
Else
toatt.Parameters.AddWithValue("@visible", "0")
End If
Dim fa As String = IO.Path.GetFileNameWithoutExtension(atard.Item("filename"))
Dim fn As String = "post_" & atard.Item("userid") & "_" & ToTimeStamp(Date.UtcNow) & "_" & random_str() & ".attach"
toatt.Parameters.AddWithValue("@attachname", "attachments\" & fn)
If mbcon.State = ConnectionState.Closed Then
mbcon.Open()
End If
Dim fold As String = "C:\inetpub\wwwroot\mybb\uploads\attachments\"
If IO.Directory.Exists(fold) = False Then
IO.Directory.CreateDirectory(fold)
End If
ff("يتم استخراج الملف الى مسار مجلد " & vbNewLine & "./uploads/attachments" & vbNewLine & "قد يتطلب الامر التشغيل كمسؤول")
Threading.Thread.Sleep(3000)
Dim wc As New WebClient
wc.Headers.Add("cookie", gco)
wc.DownloadFile(ataurl, fold & fn)
'0000000000000000000000000
toatt.ExecuteNonQuery()
' ff("تم حفظ المرفق: " & atard.Item("filename") & " بنجاح")
'xxxxxxxxxx تم حفظ المرفق xxxxxxxxxx
ff("<<<<<<<<<< تم حفظ المرفق بنجاح >>>>>>>>>>")
ff("=============================")
'00000000000000000000000000
Loop
atard.Close()
Else
' ff("لم يتم العثور على مرفقات")
ff("=============================")
End If
End Using
'انتهاء النظر الى مرفقات المشاركة
If atacon.State = ConnectionState.Open Then
atacon.Close()
End If
Loop
post.Close()
End If
End Using
Loop
thrd.Close()
End If
End Using
'حلقة القراءة من جدول المنتديات
Loop
fdr.Close()
Else
ff("لا يوجد منتدى")
End If
End Using
If fcon.State = ConnectionState.Open Then
fcon.Close()
End If
'حلقة القراءة من جدول الاقسام
Loop
End Using
If vbcon.State = ConnectionState.Open Then
vbcon.Close()
End If
End Sub