Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Echo Off
- SetLocal EnableDelayedExpansion
- :: Wakaba[perl] to Vichan[php] MySQL database converter
- :: Required: perl, grep, sed
- :: Before converting database, replace in input sql file all "!" to "[zxz]"
- :: After the end of the process do the same in reverse for restore exclamation marks in posts.
- :: Also, check last line in output sql and replace last symbol from "," to ";" if needed
- :: Import sql-file and make "Rebuild cache" in vichan adminpanel
- :: Board name
- Set Board=b
- :: Limit for INSERT
- Set strLimit=25
- :: Input sql
- Set infile=wakaba.sql
- :: Output sql
- Set outfile=vichan.sql
- Echo.>%outfile%
- Set i=1
- For /F "eol= tokens=1-3,5,7-20 delims=," %%A In (%infile%) Do (
- For %%Z In (num parent timestamp ip name trip email subject password comment image size md5 width height thumbnail tn_width tn_height body body_nomarkup id thread) Do (Set "%%Z=")
- For %%Z In (f_name f_type f_size f_filename f_extension f_file_id f_file f_thumb f_width f_height f_thumbwidth f_thumbheight f_file_path f_thumb_path) Do (Set "%%Z=")
- Set num=%%A
- Set id=!num:~1!
- Set "id=!id:(=!"
- Set parent=%%B
- Set thread=!parent:~1!
- If "!thread!"=="0" Set thread=NULL
- Set timestamp=%%C
- Set timestamp=!timestamp:~1!
- Set ip=%%D
- Set ip=!ip:~2,-1!
- Call :IP ip
- If Not "%%E"==" ''" (
- Set "name=%%E"
- Set "name='!name:~2,-1!'"
- ) Else Set name=NULL
- If Not "%%F"==" ''" (
- Set "trip=%%F"
- Set "trip='!trip:~2,-1!'"
- ) Else Set trip=NULL
- If Not "%%G"==" ''" (
- Set "email=%%G"
- Set "email='!email:~2,-1!'"
- Set "email=!email:mailto:=!"
- ) Else Set email=NULL
- If Not "%%H"==" ''" (
- Set "subject=%%H"
- Set "subject='!subject:~2,-1!'"
- ) Else Set subject=NULL
- If Not "%%I"==" ''" (
- Set "password=%%I"
- Set "password='!password:~2,-1!'"
- ) Else Set password=NULL
- If Not "%%K"==" NULL" (
- Set "image=%%K"
- Set "image=!image:~2,-1!"
- )
- If Defined image (
- Set "f_name=!image:src/=!"
- Set "f_filename=!f_name!"
- Set "f_file=!f_name!"
- For /F "delims=" %%Z In ('Echo !f_name!^|grep -Eo "[0-9A-z]{3,4}$"') Do Set f_extension=%%Z
- For /F "delims=" %%Z In ('Echo !f_name!^|grep -Eo "[0-9]+?"') Do Set f_file_id=%%Z
- If /I "!f_extension!"=="jpeg" Set f_type=image\\/jpg
- If /I "!f_extension!"=="jpg" Set f_type=image\\/jpg
- If /I "!f_extension!"=="png" Set f_type=image\\/png
- If /I "!f_extension!"=="gif" Set f_type=image\\/gif
- Set "f_file_path=%Board%\\/src\\/!f_file!"
- Set "thumbnail=%%P"
- Set "f_thumb=!thumbnail:~2,-1!"
- Set "f_thumb=!f_thumb:thumb/=!"
- Set "f_thumb_path=%Board%\\/thumb\\/!f_thumb!"
- )
- If Not "%%L"==" NULL" (
- Set "size=%%L"
- Set "size=!size:~1!"
- Set /A size*=1024
- )
- If Not "%%M"==" NULL" (
- Set "md5=%%M"
- Set "md5=!md5:~2,-1!"
- )
- If Not "%%N"==" NULL" (
- Set "width=%%N"
- Set "f_width=!width:~1!"
- )
- If Not "%%O"==" NULL" (
- Set "height=%%O"
- Set "f_height=!height:~1!"
- )
- If Not "%%Q"==" NULL" (
- Set "tn_width=%%Q"
- Set "f_thumbwidth=!tn_width:~2,-1!"
- )
- If Not "%%R"==" NULL" (
- Set "tn_height=%%R"
- Set "f_thumbheight=!tn_height:~2,-1!"
- )
- If Not "%%J"==" ''" (
- Set "comment=%%J"
- Set "body=!comment:~2,-1!"
- Call :Body
- Call :Markup
- )
- If !i! GTR !strLimit! Set i=1
- If !i!==1 Call :Header
- <nul Set /P "Echo=(!id!, !thread!, !subject!, !email!, !name!, !trip!, NULL"
- <nul Set /P "Echo=, '!body!', '!body_nomarkup!'"
- <nul Set /P "Echo=, !timestamp!, !timestamp!"
- If Defined image (
- <nul Set /P "Echo=, '[{"name":"!f_name!","type":"!f_type!","tmp_name":"\\/tmp\\/!random!","error":0,"size":!size!,"filename":"!f_filename!","extension":"!f_extension!","file_id":"!f_file_id!","file":"!f_file!","thumb":"!f_thumb!","is_an_image":true,"width":!f_width!,"height":!height!,"thumbwidth":!f_thumbwidth!,"thumbheight":!f_thumbheight!,"file_path":"!f_file_path!","thumb_path":"!f_thumb_path!"}]', 1, '!md5!'"
- ) Else (
- <nul Set /P "Echo=, NULL, 0, NULL"
- )
- <nul Set /P "Echo=, !password!, '!ip!', 0, 0, 0, NULL, NULL)"
- If "!i!"=="!strLimit!" (
- Echo ;
- ) Else (
- Echo ,
- )
- Set /A i+=1
- )>>%outfile%
- pause
- :IP
- :: Вызвать перл для распаковки будет проще, чем городить костыль
- Set $ip=%~1
- Set ip=!%~1!
- For /F "delims=" %%A In ('perl -e "print join('.',unpack('C4',pack('N',!ip!)))"') Do Set "!$ip!=%%A!
- Exit /B
- :Body
- :: Убираем неиспользуемое и заменяем на родные для vichan классы
- Set "body=!body:<p>=!"
- Set "body=!body:</p>=!"
- Set "body=!body:unkfunc=quote!"
- Set "body=!body:highlight(=highlightReply(!"
- Exit /B
- :Markup
- :: Пытаемся создать версию поста с разметкой из вакабовского html-представления
- Set "body_nomarkup=!body:<br />=\r\n!"
- Set "body_nomarkup=!body_nomarkup:<strong>=[b]!"
- Set "body_nomarkup=!body_nomarkup:</strong>=[/b]!"
- Set "body_nomarkup=!body_nomarkup:<em>=[i]!"
- Set "body_nomarkup=!body_nomarkup:</em>=[/i]!"
- Set "body_nomarkup=!body_nomarkup:</em>=[/i]!"
- :: Ебаный sed под винду криво пишет в stdout, ненавижу временные файлы
- Echo "!body_nomarkup!"|sed -e :a -e "s/<[^>]*>//g;/</N;//ba">tmp.tmp
- For /F "eol= delims=" %%Z In (tmp.tmp) Do (Set "body_nomarkup=%%~Z")
- Set "body_nomarkup=!body_nomarkup:>=>!"
- Exit /B
- :Header
- Echo INSERT INTO `posts_%Board%` (`id`, `thread`, `subject`, `email`, `name`, `trip`, `capcode`, `body`, `body_nomarkup`, `time`, `bump`, `files`, `num_files`, `filehash`, `password`, `ip`, `sticky`, `locked`, `sage`, `embed`, `slug`) VALUES
- Exit /B
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement