source: trunk/Modules/Export/CreateAddon.php@ 564

Last change on this file since 564 was 564, checked in by chronos, 12 years ago
  • Fixed: Export class dependency.
File size: 9.8 KB
Line 
1<?php
2
3include_once(dirname(__FILE__).'/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 $Man = str_replace(' ', '', $Man);
27 $Woman = str_replace(' ', '', $Woman);
28 $string = $Before.'"..gsub(gsub(UnitSex("player"), "^2$", "'.$Man.'"), "^3$", "'.$Woman.'").."'.$After;
29 }
30 $Gender = '$g';
31 while(strpos($string, $Gender) !== false)
32 {
33 $Before = substr($string, 0, strpos($string, $Gender));
34 $Man = substr($string, strpos($string, $Gender) + 2);
35 $Woman = substr($Man, strpos($Man, ':') + 1);
36 $After = substr($Woman, strpos($Woman, ';') + 1);
37 $Man = substr($Man, 0, strpos($Man, ':'));
38 $Woman = substr($Woman, 0, strpos($Woman, ';'));
39 $Man = str_replace(' ', '', $Man);
40 $Woman = str_replace(' ', '', $Woman);
41 $string = $Before.'"..gsub(gsub(UnitSex("player"), "^2$", "'.$Man.'"),"^3$", "'.$Woman.'").."'.$After;
42 }
43
44 $string = str_replace('$', '', $string);
45 $string = str_replace("\r", '', $string);
46 $string = str_replace("\n", '\r\n', $string);
47 return($string);
48 }
49
50 function ReplaceEnText($string)
51 {
52 // $string = mysql_escape_string($string);
53 $string = strtolower($string);
54
55 $string = str_replace('"', '\"', $string);
56 $string = str_replace('$b$b', ' ', $string);
57 $string = str_replace('$b $b', ' ', $string);
58 $string = str_replace('$b', ' ', $string);
59 $string = $this->ReplaceVarInText($string);
60 while(strpos($string, ' '))
61 $string = str_replace(' ', ' ', $string);
62 return($string);
63 }
64
65 function ReplaceCzText($string)
66 {
67 $string = $this->Database->real_escape_string($string);
68 $string = str_replace('$B', '\r\n', $string);
69 $string = str_replace('$b', '\r\n', $string);
70 $string = $this->ReplaceVarInText($string);
71 return($string);
72 }
73
74 function NotCancel($string)
75 {
76 //echo (strpos($string,'<html>'));
77 if (strpos($string,'<html>') > -1) return(false);
78 else return(true);
79 }
80
81 function my_trim($string)
82 {
83 $string = addslashes($string);
84 $string = str_replace("\n", '\r\\'."\n",$string);
85 $string = str_replace("\r", '',$string);
86 $string = str_replace("\\\\\\", '\\\\',$string);
87 $string = str_replace("\\\\\\", '\\\\',$string);
88 $string = str_replace("\\\\\\", '\\\\',$string);
89 $string = str_replace("\\\\32", '\\32',$string);
90 $string = str_replace('\\\\"', '\\"',$string);
91 $string = str_replace('\\\\n', '\\n',$string);
92 $string = str_replace('\\\\124', '\\124',$string);
93
94 return ($string);
95 }
96
97 function MakeLanguageFiles()
98 {
99 global $TranslationTree, $CreatedFileList;
100
101 $Output = '';
102 $this->LoadFilters();
103
104 $CreatedFileList = array();
105 $CreatedFileListCount = array();
106
107 $DbResult = $this->Database->query('SELECT `Group`.* FROM `ExportGroup` JOIN `Group` ON `Group`.`Id` = `ExportGroup`.`Group` WHERE `ExportGroup`.`Export`='.$this->Id.' AND `Group`.`TablePrefix` != ""');
108 while($Group = $DbResult->fetch_assoc())
109 {
110 //získání čísla verze pro export
111 $ID = $this->Database->query('SELECT LastVersion FROM `Group` WHERE Id = '.$Group['Id']);
112 $LastVersion = $ID->fetch_assoc();
113
114 if ($LastVersion['LastVersion'] < $this->ClientVersion['BuildNumber'])
115 $ExportVersion = $LastVersion['LastVersion'];
116 else $ExportVersion = '';
117
118 foreach($TranslationTree[$Group['Id']]['Items'] as $Column)
119 if($Column['AddonFileName'] != '')
120 {
121 if(!isset($CreatedFileListCount[$Column['AddonFileName']]))
122 $CreatedFileListCount[$Column['AddonFileName']] = 0;
123 $CreatedFileListCount[$Column['AddonFileName']]++;
124 $FileIndex = $CreatedFileListCount[$Column['AddonFileName']];
125
126 $CreatedFileList[] = $Column['AddonFileName'].'_'.$FileIndex;
127 $FileName = $this->TempDir.'CzWoW/'.$Column['AddonFileName'].'_'.$FileIndex.'.lua';
128 if(!file_exists($this->TempDir.'CzWoW/')) mkdir($this->TempDir.'CzWoW/', 0777, true);
129 $Output .= $Column['AddonFileName'].': ';
130 $i = 0;
131
132 $Buffer = 'CZWOW_'.$Column['AddonFileName'].'_count='.$FileIndex.';CZWOW_'.$Column['AddonFileName'].'_'.$FileIndex.'={';
133
134 $DbResult2 = $this->Database->query($this->BuildQuery($Group,'',$ExportVersion));
135
136 while($Line = $DbResult2->fetch_assoc())
137 {
138 $en = trim($this->ReplaceEnText($Line['En'.$Column['Column']]));
139 $cz = $this->ReplaceCzText($Line[$Column['Column']]);
140 if(($en <> '') and ($cz <> '') and ($this->NotCancel($en)))
141 {
142 $Buffer .= "\n".'["'.$en.'"]="'.$cz.'",';
143 $i++;
144 }
145 }
146
147 $Buffer = $Buffer."\n};if not CZWOW_".$Column['AddonFileName']." then CZWOW_".$Column['AddonFileName']."=0; end; CZWOW_".$Column['AddonFileName']."=CZWOW_".$Column['AddonFileName']."+".$i.";\n";
148
149 file_put_contents($FileName, $Buffer);
150 $Output .= '<b>Hotovo</b><br />';
151 }
152 }
153
154
155 // Generete list file of translated
156 $CountFiles = 'CountFiles.lua';
157 $Buffer = '';
158 foreach($CreatedFileList as $CreatedFile)
159 $Buffer .= 'CZWOW_'.str_replace('_','_count=',$CreatedFile).';'."\n";
160 foreach($TranslationTree as $Group)
161 foreach($TranslationTree[$Group['Id']]['Items'] as $Column)
162 if (($Column['AddonFileName'] != '') and (!in_array($Column['AddonFileName'].'_1', $CreatedFileList)))
163 {
164 $Buffer .= 'CZWOW_'.$Column['AddonFileName'].'_count=0;'."\n";
165 }
166
167 file_put_contents($this->TempDir.'CzWoW/'.$CountFiles, $Buffer);
168
169
170 // Generate file Translates.xml
171 $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">'."\n";
172 $Buffer .= '<script file="'.$CountFiles.'"/>'."\n";
173 foreach($CreatedFileList as $CreatedFile)
174 $Buffer .= '<script file="'.$CreatedFile.'.lua"/>'."\n";
175 $Buffer .= '</Ui>';
176 file_put_contents($this->TempDir.'CzWoW/Translates.xml', $Buffer);
177 return($Output);
178 }
179
180
181 function MakeClientStrings()
182 {
183 global $TranslationTree;
184
185 $this->LoadFilters();
186
187 $Buffer = "local f=function(name, en, cz) CzWoW_interface[name]=cz;CzWoW_interface_entoname[en]=name; end; CzWoW_interface={};CzWoW_interface_entoname={ };\n";
188 $Group = $TranslationTree[14]; // client table
189 $Column['Column'] = 'Text';
190
191 $DbResult = $this->Database->query('SELECT `Group`.* FROM `ExportGroup` JOIN `Group` ON `Group`.`Id` = `ExportGroup`.`Group` WHERE `ExportGroup`.`Export`='.$this->Id.' AND `Group`.`TablePrefix` != "" AND `Group`.`Id` = 14');
192 //$Group = $DbResult->fetch_assoc();
193 if ($DbResult->num_rows == 0)
194 $CanGenerated = '-1';
195 else
196 $CanGenerated = '';
197
198 $DbResult = $this->Database->query($this->BuildQuery($Group,'',$CanGenerated));
199 while($Line = $DbResult->fetch_array())
200 {
201 $Original = $this->my_trim($Line['En'.$Column['Column']]);
202 $Translated = $this->my_trim($Line[$Column['Column']]);
203 if($this->ClientVersion['Version'] == '2.4.3')
204 {
205 $Original = str_replace("|Hchannel:%d|h[%s]|h", '[%s]', $Original);
206 $Translated = str_replace("|Hchannel:%d|h[%s]|h", '[%s]', $Translated);
207 }
208 $Buffer .= 'f("'.addslashes($Line['ShortCut']).'", "'.$Original.'","'.$Translated.'");'."\n";
209 }
210
211 if(!file_exists($this->TempDir.'CzWoW/')) mkdir($this->TempDir.'CzWoW/',0777, true);
212 file_put_contents($this->TempDir.'CzWoW/LocalizationStrings.lua', $Buffer);
213 }
214
215 function MakeAddon()
216 {
217 if(!file_exists($this->TempDir)) mkdir($this->TempDir, 0777, true);
218 $Output = $this->MakeLanguageFiles();
219 $Output .= $this->MakeClientStrings();
220 // $Output .= MakeMainScript($Setting);
221 return($Output);
222 }
223
224 function MakeReadme()
225 {
226 $DbResult = $this->Database->query('SELECT * FROM `CzWoWPackageVersion` ORDER BY `Date` DESC');
227 $Line = $DbResult->fetch_assoc();
228
229 $Buffer = '
230 Čeština pro klienty:
231 Vytvořeno v projektu http://wowpreklad.zdechov.net/
232 Obsahuje Fonty pro správné zobrazování českých znaků, WoW addon překládající
233texty
234
235 Instalace:
236 Soubory rozbalte/zkopírujte do kořenové složky s hrou. Obvikle bývá
237"C:/Program Files/World of Warcraft/".
238
239 Verze:
240 Verze Addonu: '.$Line['Version'].'
241 Tato verze je pro verzi hry '.$this->ClientVersion['Version'].'
242
243 Změny ve verzích:
244
245 ';
246 $DbResult = $System->Database->query('SELECT * FROM `CzWoWPackageVersion` ORDER BY `Date` DESC');
247 while($Line = $DbResult->fetch_assoc())
248 {
249 $Buffer .='
250 Verze: '.$Line['Version'].'
251 =============
252 '.$Line['text'].'
253
254 ';
255 }
256 file_put_contents($this->TempDir.'CZWOW-Readme.txt', $Buffer);
257 }
258}
Note: See TracBrowser for help on using the repository browser.