program WoWHeadLoader; {$mode objfpc}{$H+} uses {$IFDEF UNIX}{$IFDEF UseCThreads} cthreads, {$ENDIF}{$ENDIF} Classes, SysUtils, CustApp { you can add units after this } , IdHTTP, USqlDatabase ; //poznámka mazání pro testování { DELETE FROM `wowpreklad`.`TextQuest` WHERE `VersionStart` = 17359; DELETE FROM `wowpreklad`.`TextAchievement` WHERE `VersionStart` = 17359; DELETE FROM `wowpreklad`.`TextGameObject` WHERE `VersionStart` = 17359; DELETE FROM `wowpreklad`.`TextItem` WHERE `VersionStart` = 17359; DELETE FROM `wowpreklad`.`TextCreature` WHERE `VersionStart` = 17359; DELETE FROM `wowpreklad`.`TextArea` WHERE `VersionStart` = 17359; UPDATE `wowpreklad`.`TextItem` SET `VersionEnd` = 12340 WHERE `VersionEnd` = 17359; UPDATE `wowpreklad`.`TextGameObject` SET `VersionEnd` = 12340 WHERE `VersionEnd` = 17359; UPDATE `wowpreklad`.`TextQuest` SET `VersionEnd` = 12340 WHERE `VersionEnd` = 17359; UPDATE `wowpreklad`.`TextAchievement` SET `VersionEnd` = 12340 WHERE `VersionEnd` = 17359; UPDATE `wowpreklad`.`TextCreature` SET `VersionEnd` = 12340 WHERE `VersionEnd` = 17359; UPDATE `wowpreklad`.`TextArea` SET `VersionEnd` = 12340 WHERE `VersionEnd` = 17359; } type { TWoWHeadLoader } TWoWHeadLoader = class(TCustomApplication) protected procedure DoRun; override; public IdHTTP1: TIdHTTP; Database: TSqlDatabase; constructor Create(TheOwner: TComponent); override; destructor Destroy; override; procedure WriteHelp; virtual; procedure Main; function skipto(part: string; text: string): string; function TextStringReplace(text:string):string; function CompareStrings(textdb: string; textimport: string): boolean; function DelHtmlTags(text:string):string; function SqlPre(text: string):string; procedure UpdateTranslated(table:string); function GetLastVersion: integer; function GetPartText(textname: string; text: string): string; function GetEndtextData(data:string): string; procedure GetTextQuest(Id: Integer); function GetMaxID(TextType: string): integer; procedure GetText(Id: Integer;TextType : integer); end; var ImportedVersion: integer; Group: array [1..6] of string = ('achievement','item','npc','object','zone','quest'); GroupDB: array [1..6] of string = ('TextAchievement','TextItem','TextCreature','TextGameObject','TextArea','TextQuest'); Column2DB: array [1..6] of string = ('Description','Description','SubName','','',''); ImportTable: integer = 6; From: integer = 1; { TWoWHeadLoader } // IdHTTP1.Request.UserAgent:= 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)'; // IdHTTP1.ReadTimeout:= 1000; // IdHTTP1.RedirectCount := 15; // IdHTTP1.HandleRedirects:=true; procedure TWoWHeadLoader.DoRun; var ErrorMsg: String; begin // quick check parameters ErrorMsg:=CheckOptions('hsuptaif','helpschemauserpasswordhostCharsetimporttablefrom'); if ErrorMsg<>'' then begin ShowException(Exception.Create(ErrorMsg)); Terminate; Exit; end; // parse parameters if HasOption('h','help') then begin WriteHelp; Terminate; Exit; end; //inicialization Database := TSqlDatabase.Create; IdHTTP1:= TIdHTTP.Create(nil); if HasOption('s', 'schema') then begin Database.Database := GetOptionValue('s', 'schema'); end else Database.Database := 'wowpreklad'; if HasOption('u', 'user') then begin Database.UserName := GetOptionValue('u', 'user'); end else Database.UserName := 'import'; if HasOption('p', 'password') then begin Database.Password := GetOptionValue('p', 'password'); end else Database.Password := 'test'; if HasOption('t', 'host') then begin Database.Hostname := GetOptionValue('t', 'host'); end else Database.Hostname := 'localhost'; if HasOption('a', 'Charset') then begin Database.Encoding := GetOptionValue('a', 'Charset'); end else Database.Encoding := 'utf8'; if HasOption('i', 'importtable') then begin ImportTable := StrToInt(GetOptionValue('i', 'importtable')); end else ImportTable := 6; if HasOption('f', 'from') then begin From := StrToInt(GetOptionValue('f', 'from')); end else From := 1; Database.Connect; WriteLn('Nez zacnete, aktualizujte udaje v tabulce ClientVersion. Texty se budou importovat jako nejpozdejsi pojmenovana verze!'); // ReadLn; ImportedVersion:=GetLastVersion; Main; { add your program here } Database.Disconnect; Database.Free; IdHTTP1.Free; // stop program loop Terminate; end; constructor TWoWHeadLoader.Create(TheOwner: TComponent); begin inherited Create(TheOwner); StopOnException:=True; end; destructor TWoWHeadLoader.Destroy; begin inherited Destroy; end; procedure TWoWHeadLoader.WriteHelp; begin { add your help code here } WriteLn('Usage: ', ExtractFileName(ExeName), ' [options]'); WriteLn(' -h --help Show this help'); WriteLn(' -u --user Database user name, default root'); WriteLn(' -p --password Database password name'); WriteLn(' -s --schema Database schema name, default wowpreklad'); WriteLn(' -t --host Database host name, default localhost'); WriteLn(' -a --Charset Database Charset, default utf8'); WriteLn(' -i --importtable Table import: TextAchievement=1,TextItem=2,TextCreature=3,TextGameObject=4,TextArea=5,TextQuest=6, default 6'); WriteLn(' -f --from ID text begin importing'); end; procedure TWoWHeadLoader.Main; var i,t: integer; begin // UpdateQuest; { GetText(1132,2); GetText(1132,2); GetText(1284,2); GetText(1180,2); GetText(1327,2); GetText(1361,2); GetText(1384,2); GetText(1111,1); GetText(29,3); GetText(55,4); GetText(15,5); GetText(4,6); } // GetText(3977,3); // GetText(29265,3); // for t :=1 to Length(Group) do for i := From to GetMaxID(Group[ImportTable]) do begin //GetMaxID('quest') GetText(i,ImportTable); // write('.'); end; write('Done!!!'); //čekej před uzavřením // ReadLn; end; procedure TWoWHeadLoader.GetTextQuest(Id: Integer); var part,data, textname,textobject,textdescription, textcomplection,textprogress,textend, textobjective1,textobjective2,textobjective3,textobjective4: string; foundtext: boolean= true; itemfound: boolean = false; DBRows : TDbRows; i: integer; begin try //načtení data := IdHTTP1.Get('http://www.wowhead.com/quest='+IntToStr(Id)); // WriteLn(data); if (pos('This quest was marked obsolete',data) > 0) or (pos('This quest is no longer available',data) > 0) then begin foundtext:=false; WriteLn('obsolete'); Exit; end; textdescription := TextStringReplace(GetPartText('Description',data)); textcomplection := TextStringReplace(GetPartText('completion',data)); //OfferRewardText textprogress := TextStringReplace(GetPartText('progress',data)); //RequestItemsText if (textprogress = '') then textprogress := TextStringReplace(GetPartText('Progress',data)); //RequestItemsText //skok na text data := skipto('
',data); //name data := skipto('

',data); textname := TextStringReplace(Copy(data,0,Pos('

',data)-1)); //objektiv data := skipto('',data); for i:= 0 to 4 do begin data := StringReplace(data,'
','$B',[rfIgnoreCase]); data := StringReplace(data,'
','$B',[rfIgnoreCase]); end; textobject := TextStringReplace(Copy(data,0,Pos('<',data)-1)); //endtext+objects data:=GetEndtextData(data); // WriteLn(data); repeat data := skipto('',data); part := Copy(data,0,Pos('',data)-1); if (Copy(part,0,Length(part)-1) = 'Suggested players: ') then Continue; if ((Pos('item',part) > 0)) then begin itemfound:=true; textend:=''; end; if ((Pos('<',part) = 0) and (Pos('#',part) = 0) and (Pos(' ',part) = 0)) then begin // part := Copy(part,0,Pos(' ',part)-1); textend:=TextStringReplace(DelHtmlTags(part)); end; if ((Pos('object=',part) > 0) or (Pos('javascript',part) > 0) or ((itemfound = false) and (Pos('#',part) = 0) and (Pos('<',part) = 0))) then begin part := Copy(part,0,Pos(' ',part)-1); part := TextStringReplace(DelHtmlTags(part)); //todo if (textobjective1 = '') then textobjective1:=part else if (textobjective2 = '') then textobjective2:=part else if (textobjective3 = '') then textobjective3:=part else if (textobjective4 = '') then textobjective4:=part; end; data := skipto('',data); until (Pos('',data) = 0); if ((itemfound = false) and (textend <> '')) then begin if (textobjective4 <> '') then textobjective4:='' else if (textobjective3 <> '') then textobjective3:='' else if (textobjective2 <> '') then textobjective2:='' else if (textobjective1 <> '') then textobjective1:=''; end; If foundtext then begin DBRows := Database.Query('SELECT * FROM `TextQuest` WHERE `Entry` ='+IntToStr(Id)+' AND `Language` =0 ORDER BY `TextQuest`.`VersionEnd` DESC '); if (DBRows.Count > 0) then begin if (DBRows.Data[0].Values['VersionEnd'] = IntToStr(ImportedVersion)) then begin WriteLn('Allready importet'); Exit; //konec pokud už tam text je end; if ( CompareStrings(DBRows.Data[0].Values['Title'],textname) and CompareStrings(DBRows.Data[0].Values['Objectives'],textobject) and CompareStrings(DBRows.Data[0].Values['Details'],textdescription) and CompareStrings(DBRows.Data[0].Values['OfferRewardText'],textcomplection) and CompareStrings(DBRows.Data[0].Values['RequestItemsText'],textprogress) and CompareStrings(DBRows.Data[0].Values['ObjectiveText2'],textobjective2) and CompareStrings(DBRows.Data[0].Values['ObjectiveText3'],textobjective3) and CompareStrings(DBRows.Data[0].Values['ObjectiveText4'],textobjective4) and ( ( CompareStrings(DBRows.Data[0].Values['EndText'],textend) and CompareStrings(DBRows.Data[0].Values['ObjectiveText1'],textobjective1) ) or ( CompareStrings(DBRows.Data[0].Values['EndText'],textobjective1) and CompareStrings(DBRows.Data[0].Values['ObjectiveText1'],textend) ) ) ) then begin //text je stejný Database.Query('UPDATE `TextQuest` SET `VersionEnd` = '+IntToStr(ImportedVersion)+' WHERE `Id` = '+DBRows.Data[0].Values['Id']+' AND `Entry` ='+IntToStr(Id)+';'); Database.Query('UPDATE `TextQuest` SET `VersionEnd` = '+IntToStr(ImportedVersion)+' WHERE `Take` = '+DBRows.Data[0].Values['Id']+' AND `Entry` ='+IntToStr(Id)+';'); UpdateTranslated('textquest'); WriteLn('update'); Exit; //konec: text je stejný upravili se jenom výsledné verze end; // if not ( // CompareStrings(DBRows.Data[0].Values['EndText'],textend) and // CompareStrings(DBRows.Data[0].Values['ObjectiveText1'],textobjective1) and // CompareStrings(DBRows.Data[0].Values['ObjectiveText2'],textobjective2) and // CompareStrings(DBRows.Data[0].Values['ObjectiveText3'],textobjective3) and // CompareStrings(DBRows.Data[0].Values['ObjectiveText4'],textobjective4) // ) then Readln; end; begin { WriteLn('INSERT INTO `TextQuest` (' +'`ID` ,`Entry` ,`Title` ,`Details` ,`Objectives` ,`OfferRewardText` ,`RequestItemsText` ,`EndText` ,' +'`ObjectiveText1` ,`ObjectiveText2` ,`ObjectiveText3` ,`ObjectiveText4` ' +',`Language` , `User` , `Complete` ,`CompleteParts` ,`Take` ,`VersionStart` ,`VersionEnd` ,`ModifyTime`)' +'VALUES (NULL,'+IntToStr(Id)+',' +SqlPre(textname)+', ' +SqlPre(textdescription)+', ' +SqlPre(textobject)+', ' +SqlPre(textcomplection)+', ' +SqlPre(textprogress)+', ' +SqlPre(textend)+', ' +SqlPre(textobjective1)+', ' +SqlPre(textobjective2)+', ' +SqlPre(textobjective3)+', ' +SqlPre(textobjective4)+', ' +'0, NULL, 1,0,NULL,'+IntToStr(ImportedVersion)+','+IntToStr(ImportedVersion)+',NOW())'); } Database.Query('INSERT INTO `TextQuest` (' +'`ID` ,`Entry` ,`Title` ,`Details` ,`Objectives` ,`OfferRewardText` ,`RequestItemsText` ,`EndText` ,' +'`ObjectiveText1` ,`ObjectiveText2` ,`ObjectiveText3` ,`ObjectiveText4` ' +',`Language` , `User` , `Complete` ,`CompleteParts` ,`Take` ,`VersionStart` ,`VersionEnd` ,`ModifyTime`)' +'VALUES (NULL,'+IntToStr(Id)+',' +SqlPre(textname)+', ' +SqlPre(textdescription)+', ' +SqlPre(textobject)+', ' +SqlPre(textcomplection)+', ' +SqlPre(textprogress)+', ' +SqlPre(textend)+', ' +SqlPre(textobjective1)+', ' +SqlPre(textobjective2)+', ' +SqlPre(textobjective3)+', ' +SqlPre(textobjective4)+', ' +'0, NULL, 1,0,NULL,'+IntToStr(ImportedVersion)+','+IntToStr(ImportedVersion)+',NOW())'); WriteLn('insert'); //TODO: zkopírovat přeložený text pokud je celý anglický přeložený end; { if (DBRows.Count = 0) then Exit; WriteLn('guest='+IntToStr(Id)+' DB "' +DBRows.Data[0].Values['Title']+ '" '+chr(10)+ 'Objektiv:"'+DBRows.Data[0].Values['Objectives']+ '" '+chr(10) +'Description: "'+DBRows.Data[0].Values['Details']+'"'+chr(10) +'Complection: "'+DBRows.Data[0].Values['OfferRewardText']+'"'+chr(10) +'Progress: "'+DBRows.Data[0].Values['RequestItemsText']+'"'+chr(10) +'textend: "'+DBRows.Data[0].Values['EndText']+'"'+chr(10) +'textobjective1: "'+DBRows.Data[0].Values['ObjectiveText1']+'"'+chr(10) +'textobjective2: "'+DBRows.Data[0].Values['ObjectiveText2']+'"'+chr(10) +'textobjective3: "'+DBRows.Data[0].Values['ObjectiveText3']+'"'+chr(10) +'textobjective4: "'+DBRows.Data[0].Values['ObjectiveText4']+'"'+chr(10) ); WriteLn('guest='+IntToStr(Id)+' "'+textname+ '" '+chr(10)+ 'Objektiv:"'+textobject+ '" '+chr(10) +'Description: "'+textdescription+'"'+chr(10) +'Complection: "'+textcomplection+'"'+chr(10) +'Progress: "'+textprogress+'"'+chr(10) +'textend: "'+textend+'"'+chr(10) +'textobjective1: "'+textobjective1+'"'+chr(10) +'textobjective2: "'+textobjective2+'"'+chr(10) +'textobjective3: "'+textobjective3+'"'+chr(10) +'textobjective4: "'+textobjective4+'"'+chr(10) ); } end; except on E: EIdHTTPProtocolException do begin if E.ErrorCode = 404 then begin foundtext := false; WriteLn('notfound'); end; end; on E:Exception do GetTextQuest(Id); end; end; procedure TWoWHeadLoader.GetText(Id: Integer; TextType: Integer); var part,data, sql, textname,textdescription: string; foundtext: boolean = true; DBRows : TDbRows; i: integer; begin WriteLn(); WriteLn(Group[TextType]+'='+IntToStr(Id)); if (TextType = 6) then begin GetTextQuest(Id); Exit; end; try //načtení data := IdHTTP1.Get('http://www.wowhead.com/'+Group[TextType]+'='+IntToStr(Id)); if (pos('',data) > 0) then begin WriteLn('color:red'); // ReadLn; foundtext:=false; Exit; end; if ((pos('is no longer available within the game.',data) > 0)) then begin foundtext:=false; Exit; end; if ('item' = Group[TextType]) then begin if (Pos('Use:',data) >0) then begin data := skipto('Use:',data); data := skipto('>',data); // textdescription := TextStringReplace(Copy(data,0,Pos('',data); //name data := skipto('',data); textname := TextStringReplace(Copy(data,0,Pos('',data)-1)); //description data := skipto('',data); if ('' <> Column2DB[TextType]) then if ('item' <> Group[TextType]) then begin data := skipto('',data); textdescription := TextStringReplace(Copy(data,0,Pos('<',data)-1)); end; if ('npc' = Group[TextType]) then begin if not (Pos('src="',textname) >0) then begin if (Pos('>',textname) > 0) then textdescription := skipto('<',textname); textdescription := TextStringReplace(Copy(textdescription,0,Length(textdescription)-1)); end; if (Pos('<',textname) >0) then textname := TextStringReplace(Copy(textname,0,Pos('<',textname)-1)); end; textname:=DelHtmlTags(textname); If foundtext then begin DBRows := Database.Query('SELECT * FROM `'+GroupDB[TextType]+'` WHERE `Entry` ='+IntToStr(Id)+' AND `Language` =0 ORDER BY `VersionEnd` DESC '); if (DBRows.Count > 0) then begin WriteLn('"'+DBRows.Data[0].Values['Name']+'"-"'+DBRows.Data[0].Values[Column2DB[TextType]]+'"'); WriteLn('"'+textname+'"-"'+textdescription+'"'); if (DBRows.Data[0].Values['VersionEnd'] = IntToStr(ImportedVersion)) then Exit; //konec pokud už tam text je if ( CompareStrings(DBRows.Data[0].Values['Name'],textname) and CompareStrings(DBRows.Data[0].Values[Column2DB[TextType]],textdescription) ) then begin //text je stejný Database.Query('UPDATE `'+GroupDB[TextType]+'` SET `VersionEnd` = '+IntToStr(ImportedVersion)+' WHERE `Id` = '+DBRows.Data[0].Values['Id']+' AND `Entry` ='+IntToStr(Id)+';'); Database.Query('UPDATE `'+GroupDB[TextType]+'` SET `VersionEnd` = '+IntToStr(ImportedVersion)+' WHERE `Take` = '+DBRows.Data[0].Values['Id']+' AND `Entry` ='+IntToStr(Id)+';'); WriteLn('update'); UpdateTranslated(GroupDB[TextType]); Exit; //konec: text je stejný upravili se jenom výsledné verze end; end; sql := 'INSERT INTO `'+GroupDB[TextType]+'` (`ID` ,`Entry` ,`Name`,'; if (Column2DB[TextType] <> '') then sql += '`'+Column2DB[TextType]+'` ,'; sql +='`Language` , `User` , `Complete` ,`CompleteParts` ,`Take` ,`VersionStart` ,`VersionEnd` ,`ModifyTime`)' +'VALUES (NULL,'+IntToStr(Id)+',' +SqlPre(textname)+', '; if (Column2DB[TextType] <> '') then sql += SqlPre(textdescription)+', '; sql +='0, NULL, 1,0,NULL,'+IntToStr(ImportedVersion)+','+IntToStr(ImportedVersion)+',NOW())'; WriteLn('insert'); Database.Query(sql); end; except on E: EIdHTTPProtocolException do begin if E.ErrorCode = 404 then begin foundtext := false; WriteLn('notfound'); end; end; on E:Exception do // GetText(Id,TextType); end; end; function TWoWHeadLoader.GetMaxID(TextType: string): integer; var data,cr:string; maxid:integer=1000; //34000 pro questy begin // http://www.wowhead.com/quests?filter=cr=30;crs=1;crv=34000 if (TextType = 'quest') then begin maxid := 34000; cr := '30'; end; if (TextType = 'npc') then begin //http://www.wowhead.com/npcs?filter=cr=37;crs=1;crv=10000 maxid := 74000; cr := '37'; end; if (TextType = 'achievement') then begin //http://www.wowhead.com/achievements?filter=cr=9;crs=1;crv=8000 maxid := 8000; cr := '9'; end; if (TextType = 'object') then begin //http://www.wowhead.com/objects?filter=cr=15;crs=1;crv=230000 maxid := 230000; cr := '15'; end; if (TextType = 'item') then begin //http://www.wowhead.com/items?filter=cr=151;crs=1;crv=106000 maxid := 106000; cr := '151'; end; if (TextType = 'zone') then begin maxid := 10000; result := maxid; Exit; cr := '30'; end; result := maxid; try repeat data := IdHTTP1.Get('http://www.wowhead.com/'+TextType+'s?filter=cr='+cr+';crs=1;crv='+IntToStr(maxid)); result := maxid; WriteLn(TextType+'s MaxID='+IntToStr(maxid)); maxid := maxid+400; until (Pos('Your criteria did not match',data) > 0); except on E: EIdHTTPProtocolException do begin if E.ErrorCode = 404 then begin end; end; on E:Exception do end; end; function TWoWHeadLoader.GetLastVersion: integer; var DBRows: TDbRows; begin //TODO: automaticky zjišťovat verze http://www.wowwiki.com/Patch_5.4.0 DBRows := Database.Query('SELECT * FROM ClientVersion WHERE `Title` != "" ORDER BY `ClientVersion`.`BuildNumber` DESC LIMIT 0 , 30'); Result := StrToInt(DBRows.Data[0].Values['BuildNumber']); Database.Query('UPDATE `ClientVersion` SET `Imported` = 1 WHERE `clientversion`.`BuildNumber` ='+DBRows.Data[0].Values['BuildNumber']+';'); end; function TWoWHeadLoader.skipto(part: string; text: string): string; begin if (Pos(part,text) > 0) then Result := Copy(text,Pos(part,text)+Length(part),Length(text)) else Result := Copy(text,Pos(part,text),Length(text)) end; function TWoWHeadLoader.GetPartText(textname: string; text: string): string; begin text := skipto('>'+textname+'<',text); text := skipto('-'+textname+'"',text); text := skipto('>',text); text := StringReplace(text,'
','$B',[rfReplaceAll, rfIgnoreCase]); text := StringReplace(text,'
','$B',[rfReplaceAll, rfIgnoreCase]); Result := Copy(text,0,Pos('<',text)-1); // if ((Copy(Result,0,1) = chr(10)) or (Copy(Result,0,1) = chr(13)) or (Copy(Result,0,1) = ' ') )then // Result := Copy(Result,1,Length(Result)); // if ((Copy(Result,0,1) = chr(10)) or (Copy(Result,0,1) = chr(13)) or (Copy(Result,0,1) = ' ')) then // Result := Copy(Result,1,Length(Result)); end; function TWoWHeadLoader.TextStringReplace(text: string): string; var part,part2: string; begin text := StringReplace(text,'
','$B',[rfReplaceAll, rfIgnoreCase]); text := StringReplace(text,'
','$B',[rfReplaceAll, rfIgnoreCase]); text := StringReplace(text,' ',' ',[rfReplaceAll, rfIgnoreCase]); text := StringReplace(text,'&','&',[rfReplaceAll, rfIgnoreCase]); text := StringReplace(text,''',chr(39),[rfReplaceAll, rfIgnoreCase]); text := StringReplace(text,'<name>','$N',[rfReplaceAll, rfIgnoreCase]); text := StringReplace(text,'<class>','$C',[rfReplaceAll, rfIgnoreCase]); text := StringReplace(text,'<race>','$R',[rfReplaceAll, rfIgnoreCase]); // text := StringReplace(text,'<name>','$G',[rfReplaceAll, rfIgnoreCase]); //<good sir/my lady> repeat part := Copy(text,Pos('<',text),Pos('>',text)-Pos('<',text)); if (part <> '') then begin if (Pos('/',part) > 0) then begin part2 := '$G'+Copy(part,5,Pos('/',part)-5)+':'+Copy(part,Pos('/',part)+1,Length(part))+';'; text := StringReplace(text,part+'>',part2,[rfReplaceAll, rfIgnoreCase]); end; text := StringReplace(text,'<','<',[rfIgnoreCase]); text := StringReplace(text,'>','>',[rfIgnoreCase]); end; until not (Pos('<',text) > 0); text := StringReplace(text,'<','<',[rfReplaceAll, rfIgnoreCase]); text := StringReplace(text,'>','>',[rfReplaceAll, rfIgnoreCase]); text := StringReplace(text,'"','"',[rfReplaceAll, rfIgnoreCase]); Result := text; while ((Copy(Result,0,1) = chr(10)) or (Copy(Result,0,1) = chr(13)) or (Copy(Result,0,1) = ' ')) do begin Result := Copy(Result,2,Length(Result)); end; while ((Copy(Result,Length(Result),Length(Result)-1) = chr(10)) or (Copy(Result,Length(Result),Length(Result)-1) = chr(13)) or (Copy(Result,Length(Result),Length(Result)-1) = ' ')) do begin Result := Copy(Result,0,Length(Result)-1); end; end; function TWoWHeadLoader.CompareStrings(textdb: string; textimport: string): boolean; var part,data :string; begin textdb:=DelHtmlTags(LowerCase(textdb)); textdb := StringReplace(textdb,'s'+chr(39)+'s','',[rfReplaceAll, rfIgnoreCase]); textdb := StringReplace(textdb,'s'+chr(39),'',[rfReplaceAll, rfIgnoreCase]); textdb := StringReplace(textdb,chr(39)+'s','',[rfReplaceAll, rfIgnoreCase]); textdb := StringReplace(textdb,chr(39),'',[rfReplaceAll, rfIgnoreCase]); textdb := StringReplace(textdb,' ','',[rfReplaceAll, rfIgnoreCase]); textdb := StringReplace(textdb,',','',[rfReplaceAll, rfIgnoreCase]); textdb := StringReplace(textdb,'.','',[rfReplaceAll, rfIgnoreCase]); textdb := StringReplace(textdb,chr(10),'',[rfReplaceAll, rfIgnoreCase]); textdb := StringReplace(textdb,chr(13),'',[rfReplaceAll, rfIgnoreCase]); textdb := StringReplace(textdb,'$b','',[rfReplaceAll, rfIgnoreCase]); textimport:=DelHtmlTags(LowerCase(textimport)); textimport := StringReplace(textimport,'s'+chr(39)+'s','',[rfReplaceAll, rfIgnoreCase]); textimport := StringReplace(textimport,'s'+chr(39),'',[rfReplaceAll, rfIgnoreCase]); textimport := StringReplace(textimport,chr(39)+'s','',[rfReplaceAll, rfIgnoreCase]); textimport := StringReplace(textimport,chr(39),'',[rfReplaceAll, rfIgnoreCase]); textimport := StringReplace(textimport,' ','',[rfReplaceAll, rfIgnoreCase]); textimport := StringReplace(textimport,',','',[rfReplaceAll, rfIgnoreCase]); textimport := StringReplace(textimport,'.','',[rfReplaceAll, rfIgnoreCase]); textimport := StringReplace(textimport,chr(10),'',[rfReplaceAll, rfIgnoreCase]); textimport := StringReplace(textimport,chr(13),'',[rfReplaceAll, rfIgnoreCase]); textimport := StringReplace(textimport,'$b','',[rfReplaceAll, rfIgnoreCase]); if ((textdb = textimport) or ( (textdb <> '') and (textimport = '') )) then Result := true else begin //zkusím rozgenerovat $g nejdřív podle prvního data:=textdb; while (Pos('$g',data)> 0) do begin part := skipto('$g',data); part := '$g'+Copy(part,0,Pos(';',part)); data := StringReplace(data,part,Copy(part,3,Pos(':',part)-3),[rfReplaceAll, rfIgnoreCase]); end; if (data = textimport) then Result := true else begin data:=textdb; while (Pos('$g',data)> 0) do begin part := skipto('$g',data); part := '$g'+Copy(part,0,Pos(';',part)); data := StringReplace(data,part,Copy(part,Pos(':',part)+1,Length(part)-1-Pos(':',part)),[rfReplaceAll, rfIgnoreCase]); end; if (data = textimport) then Result := true else begin Result:=false; WriteLn('db: '+textdb); WriteLn('in: '+textimport); end; end; end; end; function TWoWHeadLoader.DelHtmlTags(text: string): string; begin while ((Result = '') and (text <> '')) do begin if (Pos('<',text) <> 0) then begin text := StringReplace(text,Copy(text,Pos('<',text),Pos('>',text)-Pos('<',text)+1),'',[rfReplaceAll, rfIgnoreCase]); Result := Copy(text,0,Pos('<',text)-1); end else Result := text; end; // Result := text; end; function TWoWHeadLoader.SqlPre(text: string): string; begin text := StringReplace(text,'"','\"',[rfReplaceAll, rfIgnoreCase]); text := StringReplace(text,chr(39),'\'+chr(39),[rfReplaceAll, rfIgnoreCase]); Result := chr(39)+text+chr(39); end; procedure TWoWHeadLoader.UpdateTranslated(table: string); var i:integer; DBRows : TDbRows; begin { global $TranslationTree, $PatchVersion, $Config; $Output = '

Začínám se synchronizací VersionEnd u přeložených textů
'; foreach($TranslationTree as $Group) { $Output .= '
'.$Group['Name'].' '; $DbResult = $this->System->Database->query('SELECT `gs_tran`.`ID`, '. '`gs_tran`.`VersionEnd` AS `VersionEnd_tran`, '. '`gs_orig`.`VersionEnd` AS `VersionEnd_orig` FROM `'. $Group['TablePrefix'].'` AS `gs_tran` JOIN `'.$Group['TablePrefix']. '` AS `gs_orig` ON `gs_orig`.`ID` = `gs_tran`.`Take` WHERE '. '`gs_tran`.`VersionEnd` <> `gs_orig`.`VersionEnd`'); while($DbRow = $DbResult->fetch_assoc()) { $this->System->Database->query('UPDATE `'.$Group['TablePrefix'].'` SET `VersionEnd` = '.$DbRow['VersionEnd_orig'].' WHERE `ID` = '.$DbRow['ID']); $Output .= '. '; } $Output .= 'Dokončeno.'; } return($Output); } repeat DBRows := Database.Query('SELECT `gs_tran`.`ID` , `gs_tran`.`VersionEnd` AS `VersionEnd_tran` ,' +'`gs_orig`.`VersionEnd` AS `VersionEnd_orig`' +' FROM `'+table+'` AS `gs_tran` JOIN `'+table+'` AS `gs_orig` ON `gs_orig`.`ID` = `gs_tran`.`Take`' +'WHERE `gs_tran`.`VersionEnd` <> `gs_orig`.`VersionEnd` '); for i:=0 to DBRows.Count-1 do begin Database.Query('UPDATE `'+table+'` SET `VersionEnd` = '+DBRows.Data[i].Values['VersionEnd_orig']+' WHERE `ID` = '+DBRows.Data[i].Values['ID']); end; until (DBRows.Count = 0); end; function TWoWHeadLoader.GetEndtextData(data: string): string; var i:integer; begin data := skipto('',data); //mazání podsupin u objektů questu for i:=0 to 4 do begin if (0 < Pos('
',data) <> data) then data := Copy(data,0,Pos('',data); // WriteLn(Copy(data,0,Pos('