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

Last change on this file since 695 was 695, checked in by maron, 11 years ago
  • Added: selection groupitems in export
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 if(!file_exists($this->TempDir.'CzWoW/')) mkdir($this->TempDir.'CzWoW/', 0777, true);
108
109 $DbResult = $this->Database->query('SELECT `Group`.* FROM `ExportGroup` JOIN `Group` ON `Group`.`Id` = `ExportGroup`.`Group` WHERE `ExportGroup`.`Export`='.$this->Id.' AND `Group`.`TablePrefix` != ""');
110 while($Group = $DbResult->fetch_assoc())
111 {
112 //získání čísla verze pro export
113 $ID = $this->Database->query('SELECT LastVersion FROM `Group` WHERE Id = '.$Group['Id']);
114 $LastVersion = $ID->fetch_assoc();
115
116 if ($LastVersion['LastVersion'] < $this->ClientVersion['BuildNumber'])
117 $ExportVersion = $LastVersion['LastVersion'];
118 else $ExportVersion = '';
119
120 foreach($TranslationTree[$Group['Id']]['Items'] as $Column)
121 if($Column['AddonFileName'] != '')
122 {
123 if(!isset($CreatedFileListCount[$Column['AddonFileName']]))
124 $CreatedFileListCount[$Column['AddonFileName']] = 0;
125 $CreatedFileListCount[$Column['AddonFileName']]++;
126 $FileIndex = $CreatedFileListCount[$Column['AddonFileName']];
127
128 $CreatedFileList[] = $Column['AddonFileName'].'_'.$FileIndex;
129 $FileName = $this->TempDir.'CzWoW/'.$Column['AddonFileName'].'_'.$FileIndex.'.lua';
130 $Output .= $Column['AddonFileName'].': ';
131 $i = 0;
132
133 $Buffer = 'CZWOW_'.$Column['AddonFileName'].'_count='.$FileIndex.';CZWOW_'.$Column['AddonFileName'].'_'.$FileIndex.'={';
134
135 $DbResult2 = $this->Database->query($this->BuildQuery($Group,$ExportVersion));
136
137 while($Line = $DbResult2->fetch_assoc())
138 {
139 $en = trim($this->ReplaceEnText($Line['En'.$Column['Column']]));
140 $cz = $this->ReplaceCzText($Line[$Column['Column']]);
141 if(($en <> '') and ($cz <> '') and ($this->NotCancel($en)))
142 {
143 $Buffer .= "\n".'["'.$en.'"]="'.$cz.'",';
144 $i++;
145 }
146 }
147
148 $Buffer = $Buffer."\n};if not CZWOW_".$Column['AddonFileName']." then CZWOW_".$Column['AddonFileName']."=0; end; CZWOW_".$Column['AddonFileName']."=CZWOW_".$Column['AddonFileName']."+".$i.";\n";
149
150 file_put_contents($FileName, $Buffer);
151 $Output .= '<b>Hotovo</b><br />';
152 }
153 }
154
155
156 // Generete list file of translated
157 $CountFiles = 'CountFiles.lua';
158 $Buffer = '';
159 foreach($CreatedFileList as $CreatedFile)
160 $Buffer .= 'CZWOW_'.str_replace('_','_count=',$CreatedFile).';'."\n";
161 foreach($TranslationTree as $Group)
162 foreach($TranslationTree[$Group['Id']]['Items'] as $Column)
163 if (($Column['AddonFileName'] != '') and (!in_array($Column['AddonFileName'].'_1', $CreatedFileList)))
164 {
165 $Buffer .= 'CZWOW_'.$Column['AddonFileName'].'_count=0;'."\n";
166 }
167
168 file_put_contents($this->TempDir.'CzWoW/'.$CountFiles, $Buffer);
169
170
171 // Generate file Translates.xml
172 $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";
173 $Buffer .= '<script file="'.$CountFiles.'"/>'."\n";
174 foreach($CreatedFileList as $CreatedFile)
175 $Buffer .= '<script file="'.$CreatedFile.'.lua"/>'."\n";
176 $Buffer .= '</Ui>';
177 file_put_contents($this->TempDir.'CzWoW/Translates.xml', $Buffer);
178 return($Output);
179 }
180
181
182 function MakeClientStrings()
183 {
184 global $TranslationTree;
185
186 $this->LoadFilters();
187
188 $Buffer = "local f=function(name, en, cz) CzWoW_interface[name]=cz;CzWoW_interface_entoname[en]=name; end; CzWoW_interface={};CzWoW_interface_entoname={ };\n";
189 $Group = $TranslationTree[14]; // client table
190 $Column['Column'] = 'Text';
191
192 $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');
193 //$Group = $DbResult->fetch_assoc();
194 if ($DbResult->num_rows == 0)
195 $CanGenerated = '-1';
196 else
197 $CanGenerated = '';
198
199 $DbResult = $this->Database->query($this->BuildQuery($Group,$CanGenerated));
200 while($Line = $DbResult->fetch_array())
201 {
202 $Original = $this->my_trim($Line['En'.$Column['Column']]);
203 $Translated = $this->my_trim($Line[$Column['Column']]);
204 if($this->ClientVersion['Version'] == '2.4.3')
205 {
206 $Original = str_replace("|Hchannel:%d|h[%s]|h", '[%s]', $Original);
207 $Translated = str_replace("|Hchannel:%d|h[%s]|h", '[%s]', $Translated);
208 }
209 $Buffer .= 'f("'.addslashes($Line['ShortCut']).'", "'.$Original.'","'.$Translated.'");'."\n";
210 }
211
212 if(!file_exists($this->TempDir.'CzWoW/')) mkdir($this->TempDir.'CzWoW/',0777, true);
213 file_put_contents($this->TempDir.'CzWoW/LocalizationStrings.lua', $Buffer);
214 }
215
216 function MakeAddon()
217 {
218 if(!file_exists($this->TempDir)) mkdir($this->TempDir, 0777, true);
219 $Output = $this->MakeLanguageFiles();
220 $Output .= $this->MakeClientStrings();
221 // $Output .= MakeMainScript($Setting);
222 return($Output);
223 }
224
225 function MakeReadme()
226 {
227 $DbResult = $this->Database->query('SELECT * FROM `CzWoWPackageVersion` ORDER BY `Date` DESC');
228 $Line = $DbResult->fetch_assoc();
229
230 $Buffer = '
231 Čeština pro klienty:
232 Vytvořeno v projektu http://wowpreklad.zdechov.net/
233 Obsahuje Fonty pro správné zobrazování českých znaků, WoW addon překládající
234texty
235
236 Instalace:
237 Soubory rozbalte/zkopírujte do kořenové složky s hrou. Obvikle bývá
238"C:/Program Files/World of Warcraft/".
239
240 Verze:
241 Verze Addonu: '.$Line['Version'].'
242 Tato verze je pro verzi hry '.$this->ClientVersion['Version'].'
243
244 Změny ve verzích:
245
246 ';
247 $DbResult = $System->Database->query('SELECT * FROM `CzWoWPackageVersion` ORDER BY `Date` DESC');
248 while($Line = $DbResult->fetch_assoc())
249 {
250 $Buffer .='
251 Verze: '.$Line['Version'].'
252 =============
253 '.$Line['text'].'
254
255 ';
256 }
257 file_put_contents($this->TempDir.'CZWOW-Readme.txt', $Buffer);
258 }
259}
Note: See TracBrowser for help on using the repository browser.