source: trunk/export/create_addon.php@ 323

Last change on this file since 323 was 323, checked in by maron, 15 years ago

Mazání přebytečných mezer u vytváření addonu

File size: 10.0 KB
Line 
1<?php
2
3include_once('export.php');
4
5class ExportAddon extends Export
6{
7
8 // Replace special codes by lua functions
9 function ReplaceVarInText($string)
10 {
11 $string = str_replace('$N', '"..strlower(UnitName("player")).."', $string);
12 $string = str_replace('$n', '"..strlower(UnitName("player")).."', $string);
13 $string = str_replace('$C', '"..strlower(UnitClass("player")).."', $string);
14 $string = str_replace('$c', '"..strlower(UnitClass("player")).."', $string);
15 $string = str_replace('$R', '"..strlower(UnitRace("player")).."', $string);
16 $string = str_replace('$r', '"..strlower(UnitRace("player")).."', $string);
17 $Gender = '$G';
18 while(strpos($string, $Gender) !== false)
19 {
20 $Before = substr($string, 0, strpos($string, $Gender));
21 $Man = substr($string, strpos($string, $Gender) + 2);
22 $Woman = substr($Man, strpos($Man, ':') + 1);
23 $After = substr($Woman, strpos($Woman, ';') + 1);
24 $Man = substr($Man, 0, strpos($Man, ':'));
25 $Woman = substr($Woman, 0, strpos($Woman, ';'));
26 str_replace(' ', '', $Man);
27 str_replace(' ', '', $Woman);
28 $string = $Before.'"..gsub(gsub(UnitSex("player"), "^2$", "'.
29 $Man.'"), "^3$", "'.$Woman.'").."'.$After;
30 }
31 $Gender = '$g';
32 while(strpos($string, $Gender) !== false)
33 {
34 $Before = substr($string, 0, strpos($string, $Gender));
35 $Man = substr($string, strpos($string, $Gender) + 2);
36 $Woman = substr($Man, strpos($Man, ':') + 1);
37 $After = substr($Woman, strpos($Woman, ';') + 1);
38 $Man = substr($Man, 0, strpos($Man, ':'));
39 $Woman = substr($Woman, 0, strpos($Woman, ';'));
40 str_replace(' ', '', $Man);
41 str_replace(' ', '', $Woman);
42 $string = $Before.'"..gsub(gsub(UnitSex("player"), "^2$", "'.$Man.'"), "^3$", "'.$Woman.'").."'.$After;
43 }
44
45 $string = str_replace('$', '', $string);
46 $string = str_replace("\r", '', $string);
47 $string = str_replace("\n", '\r\n', $string);
48 return($string);
49 }
50
51 function ReplaceEnText($string)
52 {
53 // $string = mysql_escape_string($string);
54 $string = strtolower($string);
55
56 $string = str_replace('"', '\"', $string);
57 $string = str_replace('$b$b', ' ', $string);
58 $string = str_replace('$b $b', ' ', $string);
59 $string = str_replace('$b', ' ', $string);
60 while(strpos($string, ' '))
61 $string = str_replace(' ', ' ', $string);
62 $string = $this->ReplaceVarInText($string);
63 return($string);
64 }
65
66 function ReplaceCzText($string)
67 {
68 $string = mysql_escape_string($string);
69 $string = str_replace('$B', '\r\n', $string);
70 $string = str_replace('$b', '\r\n', $string);
71 $string = $this->ReplaceVarInText($string);
72 return($string);
73 }
74
75 function NotCancel($string)
76 {
77 //echo (strpos($string,'<html>'));
78 if (strpos($string,'<html>') > -1) return(false);
79 else return(true);
80 }
81
82 function MakeLanguageFiles()
83 {
84 global $TranslationTree, $CreatedFileList, $LanguageList;
85
86 $this->LoadFilters();
87
88 $CreatedFileList = array();
89 $CreatedFileListCount = array();
90
91 $DbResult = $this->Database->query('SELECT `group`.* FROM `ExportGroup` JOIN `group` ON `group`.`Id` = `ExportGroup`.`Group` WHERE `ExportGroup`.`Export`='.$this->Id.' AND `group`.`TablePrefix` != ""');
92 while($Group = $DbResult->fetch_assoc())
93 {
94 foreach($TranslationTree[$Group['Id']]['Items'] as $Column)
95 if($Column['AddonFileName'] != '')
96 {
97 if(!isset($CreatedFileListCount[$Column['AddonFileName']]))
98 $CreatedFileListCount[$Column['AddonFileName']] = 0;
99 $CreatedFileListCount[$Column['AddonFileName']]++;
100 $FileIndex = $CreatedFileListCount[$Column['AddonFileName']];
101
102 $CreatedFileList[] = $Column['AddonFileName'].'_'.$FileIndex;
103 $FileName = $this->TempDir.'CzWoW/'.$Column['AddonFileName'].'_'.$FileIndex.'.lua';
104 if(!file_exists($this->TempDir.'CzWoW/')) mkdir($this->TempDir.'CzWoW/', 0777, true);
105 echo($Column['AddonFileName'].': ');
106 $i = 0;
107
108 $Buffer = 'CZWOW_'.$Column['AddonFileName'].
109 '_count='.$FileIndex.'; CZWOW_'.$Column['AddonFileName'].'_'.$FileIndex.'={';
110
111 $Query = 'SELECT T2.'.$Column['Column'].' AS Translation, T3.'.$Column['Column'].' as Original FROM (SELECT T1.entry, T1.'.$Column['Column'].' FROM (SELECT entry,'.$Column['Column'].' FROM '.$Group['TablePrefix'].' WHERE (Complete = 1) AND VersionStart <= '.$this->ClientVersion['BuildNumber'].' AND VersionEnd >= '.$this->ClientVersion['BuildNumber'].' AND '.$this->WhereLang.' AND '.$this->WhereUsers.$this->OrderByUserList.') AS T1 GROUP BY T1.entry) as T2 JOIN '.$Group['TablePrefix'].' AS T3 ON (T2.entry = T3.entry) AND (T3.Language = 0)';
112 $DbResult2 = $this->Database->query($Query);
113 while($Line = $DbResult2->fetch_assoc())
114 {
115 $en = trim($this->ReplaceEnText($Line['Original']));
116 $cz = $this->ReplaceCzText($Line['Translation']);
117 if(($en <> '') and ($cz <> '') and ($this->NotCancel($en)))
118 {
119 $Buffer .= "\n".'["'.$en.'"]="'.$cz.'",';
120 $i++;
121 }
122 }
123
124 $Buffer = $Buffer."\n};if not CZWOW_".$Column['AddonFileName']." then CZWOW_".$Column['AddonFileName']."=0; end; CZWOW_".$Column['AddonFileName']."=CZWOW_".$Column['AddonFileName']."+".$i.";\n";
125
126 file_put_contents($FileName, $Buffer);
127 echo('<b>Hotovo</b><br />');
128 }
129 }
130
131 // Generate file Translates.xml
132 $Buffer = '<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/.\FrameXML\UI.xsd"><script file="BookPage_1.lua"/>'."\n";
133 foreach($CreatedFileList as $CreatedFile)
134 $Buffer .= '<script file="'.$CreatedFile.'.lua"/>'."\n";
135 $Buffer .= '</Ui>';
136 file_put_contents($this->TempDir.'CzWoW/Translates.xml', $Buffer);
137 }
138
139 function MakeClientStrings()
140 {
141 global $TranslationTree, $LanguageList;
142
143 $this->LoadFilters();
144
145 $Buffer = "local f=function(name, en, cz) CzWoW_interface[name]=cz; CzWoW_interface_entoname[en]=name; end; CzWoW_interface={ };CzWoW_interface_entoname={ };\n";
146 $Group = $TranslationTree[14]; // client table
147 $Column['Column'] = 'Text';
148 $Query = 'SELECT T2.'.$Column['Column'].' AS Translation, T3.'.$Column['Column'].' as Original, T3.ShortCut FROM (SELECT T1.entry, T1.'.$Column['Column'].' FROM (SELECT entry,'.$Column['Column'].' FROM '.$Group['TablePrefix'].' WHERE (Complete = 1) AND VersionStart <= '.$this->ClientVersion['BuildNumber'].' AND VersionEnd >= '.$this->ClientVersion['BuildNumber'].' AND '.$this->WhereLang.' AND '.$this->WhereUsers.$this->OrderByUserList.') AS T1 GROUP BY T1.entry) as T2 JOIN '.$Group['TablePrefix'].' AS T3 ON (T2.entry = T3.entry) AND (T3.Language = 0)';
149 $DbResult = $this->Database->query($Query);
150 while($Line = $DbResult->fetch_array())
151 {
152 $Original = str_replace("\r", '', str_replace("\n", '\r\\'."\n", addslashes($Line['Original'])));
153 $Translated = str_replace("\r", '', str_replace("\n", '\r\\'."\n", addslashes($Line['Translation'])));
154 if ($this->ClientVersion['Version'] == '2.4.3')
155 {
156 $Original = str_replace("|Hchannel:%d|h[%s]|h", '[%s]', $Original);
157 $Translated = str_replace("|Hchannel:%d|h[%s]|h", '[%s]', $Translated);
158 }
159 $Buffer .= 'f("'.addslashes($Line['ShortCut']).'", "'.$Original.'", "'.$Translated.'");'."\n";
160 }
161 // Nepřeložené texty
162 $Query = 'SELECT '.$Column['Column'].' as Original, ShortCut FROM '.$Group['TablePrefix'].' WHERE Language = 0 AND VersionStart <= '.$this->ClientVersion['BuildNumber'].' AND VersionEnd >= '.$this->ClientVersion['BuildNumber'].' AND entry NOT IN (SELECT entry FROM '.$Group['TablePrefix'].' WHERE (Complete = 1) AND VersionStart <= '.$this->ClientVersion['BuildNumber'].' AND VersionEnd >= '.$this->ClientVersion['BuildNumber'].' AND '.$this->WhereLang.' AND '.$this->WhereUsers.')';
163 $DbResult = $this->Database->query($Query);
164 while($Line = $DbResult->fetch_array())
165 {
166 $Original = str_replace("\r", '', str_replace("\n", '\r\\'."\n", addslashes($Line['Original'])));
167 $Translated = str_replace("\r", '', str_replace("\n", '\r\\'."\n", $Line['Original']));
168 if(substr($this->ClientVersion['Version'], 0, 2) == '2.')
169 {
170 $Original = str_replace("|Hchannel:%d|h[%s]|h", '[%s]', $Original);
171 $Translated = str_replace("|Hchannel:%d|h[%s]|h", '[%s]', $Translated);
172 }
173 $Buffer .= 'f("'.addslashes($Line['ShortCut']).'", "'.$Original.'", "'.$Translated.'");'."\n";
174 }
175 if(!file_exists($this->TempDir.'CzWoW/')) mkdir($this->TempDir.'CzWoW/', 0777, true);
176 file_put_contents($this->TempDir.'CzWoW/LocalizationStrings.lua', $Buffer);
177 }
178
179 function MakeAddon()
180 {
181 if(!file_exists($this->TempDir)) mkdir($this->TempDir, 0777, true);
182 $this->MakeLanguageFiles();
183 $this->MakeClientStrings();
184 // MakeMainScript($Setting);
185 }
186
187 function MakeReadme()
188 {
189 $DbResult = $this->Database->query('SELECT * FROM verseclient ORDER BY DATE DESC');
190 $Line = $DbResult->fetch_assoc();
191
192 $Buffer = '
193 Čeština pro klienty:
194 Vytvořeno v projektu http://wowpreklad.zdechov.net/
195 Obsahuje Fonty pro správné zobrazování českých znaků, WoW addon překládající texty
196
197 Instalace:
198 Soubory rozbalte/zkopírujte do kořenové složky s hrou. Obvikle bývá "C:/Program Files/World of Warcraft/".
199
200 Verze:
201 Verze Addonu: '.$Line['verse'].'
202 Tato verze je pro verzi hry '.$this->ClientVersion['Version'].'
203
204 Změny ve verzích:
205
206 ';
207 $DbResult = $Database->query('SELECT * FROM verseclient ORDER BY DATE DESC');
208 while($Line = $DbResult->fetch_assoc())
209 {
210 $Buffer .='
211 Verze: '.$Line['verse'].'
212 =============
213 '.$Line['text'].'
214
215 ';
216 }
217 file_put_contents($this->TempDir.'CZWOW-Readme.txt', $Buffer);
218 }
219}
220
221?>
Note: See TracBrowser for help on using the repository browser.