1 | <?php
|
---|
2 |
|
---|
3 | class Export extends Model
|
---|
4 | {
|
---|
5 | var $Id;
|
---|
6 | var $AnoNe = array('Ne', 'Ano');
|
---|
7 | var $WhereLang;
|
---|
8 | var $WhereUsers;
|
---|
9 | var $SelectedUsers;
|
---|
10 | var $UserNames;
|
---|
11 | var $ClientVersion;
|
---|
12 | var $OrderByUserList;
|
---|
13 | var $TempDir;
|
---|
14 | var $SourceDir;
|
---|
15 |
|
---|
16 | function Init()
|
---|
17 | {
|
---|
18 | $this->TempDir = dirname(__FILE__).'/../../'.$this->Config['Web']['TempFolder'].'Export/'.$this->Id.'/';
|
---|
19 | if(!file_exists($this->TempDir)) mkdir($this->TempDir, 0777, true);
|
---|
20 | $this->TempDirRelative = $this->Config['Web']['TempFolder'].'Export/'.$this->Id.'/';
|
---|
21 | $this->SourceDir = dirname(__FILE__).'/../../'.$this->Config['Web']['SourceFolder'];
|
---|
22 | $this->SourceDirRelative = $this->Config['Web']['SourceFolder'];
|
---|
23 | if(!file_exists($this->SourceDir)) mkdir($this->SourceDir, 0777, true);
|
---|
24 | }
|
---|
25 |
|
---|
26 | function SaveAllUsers() {
|
---|
27 | $DbResult = $this->System->Database->query('SELECT * FROM `Export` WHERE `Id`='.$this->Id);
|
---|
28 | $Export = $DbResult->fetch_assoc();
|
---|
29 | if ($Export['AllUsers']) {
|
---|
30 | $DbResult2 = $this->System->Database->query('SELECT ID FROM `User` WHERE `ID` NOT IN(SELECT `User` FROM `ExportUser` WHERE `Export`='.$this->Id.')');
|
---|
31 | while($UserLine = $DbResult2->fetch_assoc())
|
---|
32 | {
|
---|
33 | $Condition = ' WHERE `Export`='.$this->Id.' AND `User`='.$UserLine['ID'];
|
---|
34 | $DbResult = $this->System->Database->query('SELECT * FROM `ExportUser` '.$Condition); //,MAX(`Sequence`) as MaxSequence
|
---|
35 | if($DbResult->num_rows > 0)
|
---|
36 | {
|
---|
37 | // $this->System->Database->query('UPDATE `ExportUser` SET `Sequence`='.$Value.$Condition);
|
---|
38 | } else
|
---|
39 | {
|
---|
40 | $this->System->Database->query('INSERT INTO `ExportUser` (`Export`, `User`, `Sequence`) VALUES ('.$this->Id.', '.$UserLine['ID'].', 0)');
|
---|
41 | }
|
---|
42 | }
|
---|
43 |
|
---|
44 | $this->System->Database->query('SET @I = 0');
|
---|
45 | $this->System->Database->query('UPDATE `ExportUser` SET `Sequence` = (@I := @I + 1) WHERE `Export`='.$this->Id.' ORDER BY `Sequence`;');
|
---|
46 | }
|
---|
47 | }
|
---|
48 |
|
---|
49 | function LoadFilters()
|
---|
50 | {
|
---|
51 | $DbResult = $this->Database->query('SELECT * FROM `Export` WHERE `Id`='.$this->Id);
|
---|
52 | if($DbResult->num_rows == 0) throw new Exception('Export '.$this->Id.' neexistuje');
|
---|
53 | $this->Export = $DbResult->fetch_assoc();
|
---|
54 |
|
---|
55 | // Filter selected users
|
---|
56 | $this->UserNames = '';
|
---|
57 | $DbResult = $this->Database->query('SELECT `ExportUser`.*, `User`.`Name`, `User`.`ID` FROM `ExportUser` '.
|
---|
58 | 'LEFT JOIN `User` ON `User`.`ID`=`ExportUser`.`User` '.
|
---|
59 | 'WHERE `ExportUser`.`Export`='.$this->Id.' ORDER BY `ExportUser`.`Sequence`');
|
---|
60 | while($UserLine = $DbResult->fetch_assoc())
|
---|
61 | {
|
---|
62 | $this->UserNames .= ', '.$UserLine['Name'];
|
---|
63 | }
|
---|
64 | $this->UserNames = substr($this->UserNames, 2);
|
---|
65 |
|
---|
66 | if($this->Export['ClientVersion'] != '')
|
---|
67 | {
|
---|
68 | $DbResult = $this->Database->query('SELECT * FROM `ClientVersion` WHERE `Id`='.$this->Export['ClientVersion']);
|
---|
69 | $this->ClientVersion = $DbResult->fetch_assoc();
|
---|
70 | } else $this->ClientVersion = '';
|
---|
71 | }
|
---|
72 |
|
---|
73 | function BuildQuery($Group, $Version = '')
|
---|
74 | {
|
---|
75 | global $TranslationTree;
|
---|
76 | $this->SaveAllUsers();
|
---|
77 |
|
---|
78 | if ($Version <> '')
|
---|
79 | $ExportVersion = $Version;
|
---|
80 | else
|
---|
81 | $ExportVersion = $this->ClientVersion['BuildNumber'];
|
---|
82 |
|
---|
83 | $DbResultItem = $this->System->Database->query('SELECT * FROM `ExportGroupItem` WHERE `Export`='.$this->Id);
|
---|
84 | while($GroupItem = $DbResultItem->fetch_assoc())
|
---|
85 | {
|
---|
86 | $GroupItems[$GroupItem['GroupItem']] = 1;
|
---|
87 | }
|
---|
88 | // Build selected columns
|
---|
89 | $Columns = '';
|
---|
90 | foreach($TranslationTree[$Group['Id']]['Items'] as $Column) {
|
---|
91 | if (!isset($GroupItems[$Column['Id']])) $Columns .= ' `T`.`'.$Column['Column'].'` AS `'.$Column['Column'].'`, ';
|
---|
92 | }
|
---|
93 | // $Columns = substr($Columns, 0, -2);
|
---|
94 |
|
---|
95 |
|
---|
96 | $Query = 'SELECT * FROM (SELECT '.$Columns.' T.`ID`,T.`Language`,T.`User`,T.`Entry`,T.`VersionEnd`,T.`VersionStart`, `User`.`Name` AS `UserName` FROM `'.$Group['TablePrefix'].'` AS `T`'.
|
---|
97 | ' JOIN `ExportUser` ON (`ExportUser`.`User`=`T`.`User`) AND (`ExportUser`.`Export`='.$this->Id.') '.
|
---|
98 | ' JOIN `User` ON `User`.`ID`=`T`.`User`'.
|
---|
99 | ' JOIN `ExportLanguage` ON (`ExportLanguage`.`Export`='.$this->Id.')'.
|
---|
100 | ' WHERE (`Complete` = 1) AND (`VersionStart` <= '.$ExportVersion.') AND (`VersionEnd` >= '.$ExportVersion.')'.
|
---|
101 | ' ORDER BY `ExportLanguage`.`Sequence`, `ExportUser`.`Sequence`) AS `TT` GROUP BY `TT`.`Entry`';
|
---|
102 |
|
---|
103 | // Build columns for english texts
|
---|
104 | $OriginalColumns = '';
|
---|
105 | foreach($TranslationTree[$Group['Id']]['Items'] as $Column) {
|
---|
106 | $OriginalColumns .= ' `T3`.`'.$Column['Column'].'` AS `En'.$Column['Column'].'`, ';
|
---|
107 | if (isset($GroupItems[$Column['Id']]))
|
---|
108 | $OriginalColumns .= ' `T3`.`'.$Column['Column'].'` AS `'.$Column['Column'].'`, ';
|
---|
109 | }
|
---|
110 | $OriginalColumns = substr($OriginalColumns, 0, -2);
|
---|
111 |
|
---|
112 | // Expand query for loading english texts
|
---|
113 | $Query = 'SELECT `T4`.*, '.$OriginalColumns.' FROM ('.$Query.') AS `T4` '.
|
---|
114 | ' LEFT JOIN `'.$Group['TablePrefix'].'` AS `T3` ON (`T3`.`Entry` = `T4`.`Entry`) '.
|
---|
115 | 'AND (`T3`.`Language` = '.$this->System->Config['OriginalLanguage'].') AND '.
|
---|
116 | '(`T3`.`VersionStart` = `T4`.`VersionStart`) AND (`T3`.`VersionEnd` = `T4`.`VersionEnd`)';
|
---|
117 |
|
---|
118 | return($Query);
|
---|
119 | }
|
---|
120 |
|
---|
121 | function NeedGeneration()
|
---|
122 | {
|
---|
123 | $this->LoadFilters();
|
---|
124 | $file = '';
|
---|
125 | if ($this->Export['OutputType'] == 10) $file = $this->TempDir.'Instalace_CzechWoW_'.$this->ClientVersion['Version'].'.exe';
|
---|
126 | if ($this->Export['OutputType'] == 9) $file = $this->TempDir.'CzWoW_DBC.zip';
|
---|
127 |
|
---|
128 | if (file_exists($file))
|
---|
129 | $date = date('Y-m-d H:i',(filemtime($file)));
|
---|
130 | else return(true);
|
---|
131 | // echo $file;
|
---|
132 |
|
---|
133 | $DbResult = $this->Database->query('SELECT `Group`.* FROM `ExportGroup` '.
|
---|
134 | 'JOIN `Group` ON `Group`.`Id` = `ExportGroup`.`Group` WHERE `ExportGroup`.`Export`='.$this->Id);
|
---|
135 | $result = false;
|
---|
136 | while($Group = $DbResult->fetch_assoc())
|
---|
137 | {
|
---|
138 | $Query = 'SELECT * FROM `'.$Group['TablePrefix'].'` AS `T`'.
|
---|
139 | ' JOIN `ExportUser` ON (`ExportUser`.`User`=`T`.`User`) AND (`ExportUser`.`Export`='.$this->Id.') '.
|
---|
140 | ' JOIN `User` ON `User`.`ID`=`T`.`User`'.
|
---|
141 | ' JOIN `ExportLanguage` ON (`ExportLanguage`.`Export`='.$this->Id.')'.
|
---|
142 | ' WHERE ( \''.$date.'\' < `T`.`ModifyTime`) AND (`Complete` = 1) AND (`VersionStart` <= '.$this->ClientVersion['BuildNumber'].') AND (`VersionEnd` >= '.$this->ClientVersion['BuildNumber'].')'.
|
---|
143 | ' ';
|
---|
144 |
|
---|
145 | $DbResult2 = $this->Database->query($Query);
|
---|
146 | if ($DbResult2->num_rows > 0) {
|
---|
147 | $result = true;
|
---|
148 | }
|
---|
149 | }
|
---|
150 | return($result);
|
---|
151 | }
|
---|
152 |
|
---|
153 | function ExportToMangosSQL()
|
---|
154 | {
|
---|
155 | global $TranslationTree;
|
---|
156 |
|
---|
157 | $this->LoadFilters();
|
---|
158 |
|
---|
159 | $Buffer =
|
---|
160 | "-- Generováno projektem wowpreklad.zdechov.net\n".
|
---|
161 | "-- ===========================================\n".
|
---|
162 | "--\n".
|
---|
163 | "-- Web projektu: ".$this->Config['Web']['Host'].$this->System->Link('/')."\n".
|
---|
164 | "-- Datum exportu: ".date("j.n.Y H:i:s")."\n".
|
---|
165 | "-- Znaková sada: ".$this->Config['Database']['Charset']." / ".$this->Config['Web']['Charset']."\n".
|
---|
166 | "-- Diakritika: ".$this->AnoNe[$this->Export['WithDiacritic']]."\n".
|
---|
167 | "-- Vygeneroval uživatel: ".$this->System->User->Name."\n".
|
---|
168 | "-- Vzato od uživatelů: ".$this->UserNames."\n".
|
---|
169 | "-- Generované tabulky: ";
|
---|
170 |
|
---|
171 | $DbResult = $this->Database->query('SELECT `Group`.* FROM `ExportGroup` '.
|
---|
172 | 'JOIN `Group` ON `Group`.`Id` = `ExportGroup`.`Group` WHERE `ExportGroup`.`Export`='.$this->Id);
|
---|
173 | while($Group = $DbResult->fetch_assoc())
|
---|
174 | {
|
---|
175 | $Buffer .= $Group['TablePrefix'].', ';
|
---|
176 | }
|
---|
177 | $Buffer .= "\n\n";
|
---|
178 |
|
---|
179 | $DbResult = $this->Database->query('SELECT `Group`.* FROM `ExportGroup` '.
|
---|
180 | 'JOIN `Group` ON `Group`.`Id` = `ExportGroup`.`Group` WHERE `ExportGroup`.`Export`='.$this->Id);
|
---|
181 | while($Group = $DbResult->fetch_assoc())
|
---|
182 | {
|
---|
183 | if($Group['MangosTable'] != '')
|
---|
184 | {
|
---|
185 | $Buffer .= "\n\n-- ".$Group['Name']."\n\n";
|
---|
186 | $DbResult2 = $this->Database->query($this->BuildQuery($Group));
|
---|
187 | if($DbResult2->num_rows > 0)
|
---|
188 | while($Line = $DbResult2->fetch_array())
|
---|
189 | {
|
---|
190 | $Values = '';
|
---|
191 | foreach($TranslationTree[$Group['Id']]['Items'] as $GroupItem)
|
---|
192 | if($GroupItem['Column'] != $Group['PrimaryKeyItem']) // Do not update primary key
|
---|
193 | {
|
---|
194 | if($GroupItem['MangosColumn'] == '') $GroupItem['MangosColumn'] = $GroupItem['Column'];
|
---|
195 | $Values .= ', `'.$GroupItem['MangosColumn'].'`="'.addslashes($Line[$GroupItem['Column']]).'"';
|
---|
196 | }
|
---|
197 | $Values = substr($Values, 2);
|
---|
198 |
|
---|
199 | // Get multicolumn index
|
---|
200 | $ColumnItems = explode(',', $Group['MangosTableIndex']);
|
---|
201 | if(count($ColumnItems) > 1)
|
---|
202 | {
|
---|
203 | $Where = 'CONCAT(';
|
---|
204 | foreach($ColumnItems as $ColumnItem)
|
---|
205 | $Where .= '`'.$ColumnItem.'`, "_", ';
|
---|
206 | $Where = substr($Where, 0, -7).')';
|
---|
207 | } else $Where = '`'.$Group['MangosTableIndex'].'`';
|
---|
208 | $Where .= ' = "'.$Line[$Group['PrimaryKeyItem']].'";';
|
---|
209 |
|
---|
210 | $Line = 'UPDATE `'.$Group['MangosTable'].'` SET '.$Values.' WHERE '.$Where;
|
---|
211 | $Line = str_replace("\n", '\n', $Line);
|
---|
212 | $Line = str_replace("\r", '', $Line);
|
---|
213 | $Buffer .= $Line."\n";
|
---|
214 | }
|
---|
215 | }
|
---|
216 | }
|
---|
217 | if($this->Export['WithDiacritic'] != 1) $Buffer = utf2ascii($Buffer);
|
---|
218 | return($Buffer);
|
---|
219 | }
|
---|
220 |
|
---|
221 | function ExportToAoWoWSQL()
|
---|
222 | {
|
---|
223 | global $TranslationTree, $AoWoWconf;
|
---|
224 |
|
---|
225 | //require_once('../aowow/configs/config.php');
|
---|
226 |
|
---|
227 | $Buffer = $this->ExportToMangosSQL();
|
---|
228 |
|
---|
229 | /*
|
---|
230 | // Data to aowow
|
---|
231 | $Database2 = new mysqli($this->Config['Database']['Host'], $this->Config['Database']['User'], $this->Config['Database']['Password'], $this->Config['Database']['Database']);
|
---|
232 | $Database2->query('SET NAMES '.$this->Config['Database']['Charset']);
|
---|
233 | $Database2->select_db($AoWoWconf['mangos']['db']);
|
---|
234 | $AoWoWTables = array(
|
---|
235 | 'aowow_resistances' => 'Id',
|
---|
236 | 'aowow_spelldispeltype' => 'Id',
|
---|
237 | 'aowow_skill' => 'skillID',
|
---|
238 | );
|
---|
239 | foreach($AoWoWTables as $AoWoWTable => $IndexColum)
|
---|
240 | {
|
---|
241 | $Buffer .= '--'.$AoWoWTable.', ';
|
---|
242 | $Buffer .= "\n\n";
|
---|
243 | $Query = 'SELECT `name`,`'.$IndexColum.'` FROM `'.$AoWoWTable.'`';
|
---|
244 | $DbResult = $Database2->query($Query);
|
---|
245 | while($Line = $DbResult->fetch_assoc())
|
---|
246 | {
|
---|
247 | $Ori_text = $Line['name'];
|
---|
248 | $DbResult2 = $Database2->query('SELECT `Text` AS `En`,
|
---|
249 | (SELECT `Text` FROM `'.$this->System->Config['Database']['Database'].'`.`TextGlobalString` AS `TableTran`
|
---|
250 | WHERE `TableEn`.`Entry` = `TableTran`.`Entry` AND (`Complete` = 1) AND '.$this->WhereLang.' AND '.$this->WhereUsers.$this->OrderByUserList.' LIMIT 1) AS `Tran`
|
---|
251 | FROM `'.$this->System->Config['Database']['Database'].'`.`TextGlobalString` AS `TableEn` WHERE
|
---|
252 | `Text` = "'.addslashes($Ori_text).'" LIMIT 1');
|
---|
253 | $Tran = $DbResult2->fetch_assoc();
|
---|
254 | //echo ($Line['name'].'='.$Tran['tran']);
|
---|
255 | if($Tran['Tran'] == '')
|
---|
256 | {
|
---|
257 | $DbResult2 = $Database2->query('SELECT `OptionText` AS `En`,
|
---|
258 | (SELECT `OptionText` FROM `'.$this->Config['Database']['Database'].'`.`TextNPCOption` AS `TableTran`
|
---|
259 | WHERE `TableEn`.`Entry` = `TableTran`.`Entry` AND (`Complete` = 1) AND '.$this->WhereLang.'
|
---|
260 | AND '.$this->WhereUsers.$this->OrderByUserList.' LIMIT 1) AS `Tran`
|
---|
261 | FROM `'.$this->Config['Database']['Database'].'`.`TextNPCOption` AS `TableEn` WHERE
|
---|
262 | `OptionText` = "'.addslashes($Ori_text).'" LIMIT 1');
|
---|
263 | $Tran = $DbResult2->fetch_assoc();
|
---|
264 | }
|
---|
265 |
|
---|
266 | if($Tran['Tran'] <> '')
|
---|
267 | $Buffer .= 'UPDATE `'.$AoWoWTable.'` SET `name` = "'.addslashes($Tran['Tran']).'" WHERE '.$IndexColum.' = '.$Line[$IndexColum].' ;'."\n";
|
---|
268 | }
|
---|
269 | $Buffer .= "\n\n";
|
---|
270 | }
|
---|
271 | */
|
---|
272 | if($this->Export['WithDiacritic'] != 1) $Buffer = utf2ascii($Buffer);
|
---|
273 | return($Buffer);
|
---|
274 | }
|
---|
275 |
|
---|
276 | function HaveVarible($String1, $String2, $StartChar = '$')
|
---|
277 | {
|
---|
278 | //Export only if translate have same varible %
|
---|
279 |
|
---|
280 | if (strpos($String1,$StartChar) !== false) {
|
---|
281 |
|
---|
282 | while ( strpos($String1,$StartChar) !== false) {
|
---|
283 | $pos = strpos($String1,$StartChar);
|
---|
284 | $String1 = substr($String1,$pos+1);
|
---|
285 | $varible = $String1;
|
---|
286 | if (strpos($varible,' ')) $varible = substr($varible,0,strpos($varible,' '));
|
---|
287 | if (strpos($varible,'.')) $varible = substr($varible,0,strpos($varible,'.'));
|
---|
288 | if (strpos($varible,',')) $varible = substr($varible,0,strpos($varible,','));
|
---|
289 | if (strpos($varible,'%')) $varible = substr($varible,0,strpos($varible,'%'));
|
---|
290 | if (strpos($varible,chr(10))) $varible = substr($varible,0,strpos($varible,chr(10)));
|
---|
291 | // echo $pos.'-'.$varible.'-'.$String1.'-' .$String2.'
|
---|
292 | // ';
|
---|
293 |
|
---|
294 | if (false === strpos($String2,$varible)) {
|
---|
295 | // echo $varible;
|
---|
296 | return(false);
|
---|
297 | }
|
---|
298 | }
|
---|
299 | }
|
---|
300 | return (true);
|
---|
301 | }
|
---|
302 |
|
---|
303 | function AddProgress($add = 2) {
|
---|
304 | if (file_exists($this->TempDir.'progress')) {
|
---|
305 | $File = new FileStream();
|
---|
306 | $File->OpenFile($this->TempDir.'progress');
|
---|
307 | $Line = $File->ReadLine();
|
---|
308 |
|
---|
309 | $File = new FileStream();
|
---|
310 | $File->CreateFile($this->TempDir.'progress');
|
---|
311 | $Line+=$add;
|
---|
312 | $File->WriteLine($Line);
|
---|
313 | }
|
---|
314 | }
|
---|
315 |
|
---|
316 | function ExportToDBC()
|
---|
317 | {
|
---|
318 | global $TranslationTree;
|
---|
319 |
|
---|
320 | $this->LoadFilters();
|
---|
321 |
|
---|
322 | $DbResult = $this->Database->query('SELECT `Group`.* FROM `ExportGroup` '.
|
---|
323 | 'JOIN `Group` ON `Group`.`Id` = `ExportGroup`.`Group` '.
|
---|
324 | 'WHERE `ExportGroup`.`Export`='.$this->Id.' AND `Group`.`DBCFileName` != ""');
|
---|
325 | $Output = 'Počet generovaných skupin: '.$DbResult->num_rows."\n";
|
---|
326 | while($Group = $DbResult->fetch_assoc())
|
---|
327 | {
|
---|
328 | $this->AddProgress();
|
---|
329 | $Output .= $Group['Name'].', ';
|
---|
330 | if(file_exists($this->SourceDir.$this->ClientVersion['Version'].'/dbc/'.$Group['DBCFileName'].'.dbc'))
|
---|
331 | {
|
---|
332 | // Load string column index list
|
---|
333 | $DbResult2 = $this->Database->query('SELECT * FROM `GroupItem` '.
|
---|
334 | 'JOIN `GroupItemDBC` ON `GroupItem`.`Id` = `GroupItemDBC`.`GroupItem` AND `GroupItemDBC`.`ClientVersion` = '.$this->ClientVersion['Id'].' WHERE `GroupItem`.`Group` = '.$Group['Id']);
|
---|
335 | $ColumnIndexes = array();
|
---|
336 | $ColumnFormat = array();
|
---|
337 | while($DbRow = $DbResult2->fetch_assoc())
|
---|
338 | {
|
---|
339 | $ColumnFormat[$DbRow['ColumnIndex']] = FORMAT_STRING;
|
---|
340 | $ColumnIndexes[$DbRow['GroupItem']] = $DbRow['ColumnIndex'];
|
---|
341 | }
|
---|
342 |
|
---|
343 | // Load all data into lookup table
|
---|
344 | $LookupTable = array();
|
---|
345 | $DbResult2 = $this->Database->query($this->BuildQuery($Group));
|
---|
346 | while($DbRow = $DbResult2->fetch_assoc()) {
|
---|
347 | //Export only if translate have same varible %
|
---|
348 | $CanExport = true;
|
---|
349 | foreach($TranslationTree[$Group['Id']]['Items'] as $Column) {
|
---|
350 | $DbRow[$Column['Column']] = str_replace ( '$ ','$',$DbRow[$Column['Column']]);
|
---|
351 | if (!$this->HaveVarible($DbRow['En'.$Column['Column']],$DbRow[$Column['Column']])) {
|
---|
352 | $CanExport = false;
|
---|
353 | $Output .= ', NE='.$DbRow['ID'];
|
---|
354 | }
|
---|
355 | if (!$this->HaveVarible($DbRow[$Column['Column']],$DbRow['En'.$Column['Column']])) {
|
---|
356 | $CanExport = false;
|
---|
357 | $Output .= ', NE='.$DbRow['ID'];
|
---|
358 | }
|
---|
359 | }
|
---|
360 |
|
---|
361 | if ($CanExport)
|
---|
362 | $LookupTable[$DbRow[$Group['PrimaryKeyItem']]] = $DbRow;
|
---|
363 |
|
---|
364 | }
|
---|
365 |
|
---|
366 | // Open original DBC file
|
---|
367 | $SourceDBCFile = new DBCFile();
|
---|
368 | $SourceDBCFile->OpenFile($this->SourceDir.$this->ClientVersion['Version'].'/dbc/'.$Group['DBCFileName'].'.dbc', $ColumnFormat);
|
---|
369 |
|
---|
370 | // Create new DBC file
|
---|
371 | if(!file_exists($this->TempDir.'dbc/')) mkdir ($this->TempDir.'dbc/', 0777, true);
|
---|
372 | $NewDBCFile = new DBCFile();
|
---|
373 | $NewDBCFile->CreateFile($this->TempDir.'dbc/'.$Group['DBCFileName'].'.dbc', $ColumnFormat);
|
---|
374 | $NewDBCFile->SetRecordCount($SourceDBCFile->GetRecordCount());
|
---|
375 | $NewDBCFile->SetFieldCount($SourceDBCFile->GetFieldCount());
|
---|
376 | $NewDBCFile->Commit();
|
---|
377 |
|
---|
378 | // Replace translated strings
|
---|
379 | $OldProgress = -1;
|
---|
380 | $Output .= "\n\r";
|
---|
381 | $RowCount = $SourceDBCFile->GetRecordCount();
|
---|
382 | $FieldCount = $SourceDBCFile->GetFieldCount();
|
---|
383 | for($Row = 0; $Row < $RowCount; $Row++)
|
---|
384 | {
|
---|
385 | $Line = $SourceDBCFile->GetLine($Row);
|
---|
386 |
|
---|
387 | // Get multicolumn index value
|
---|
388 | $PrimaryKeyItem = '';
|
---|
389 | $ColumnItems = explode(',', $Group['DBCIndex']);
|
---|
390 | if(count($ColumnItems) > 1)
|
---|
391 | {
|
---|
392 | foreach($ColumnItems as $ColumnItem)
|
---|
393 | $PrimaryKeyItem .= $Line[$ColumnItem].'_';
|
---|
394 | $PrimaryKeyItem = substr($PrimaryKeyItem, 0, -1);
|
---|
395 | } else $PrimaryKeyItem = $Line[$Group['DBCIndex']];
|
---|
396 |
|
---|
397 | if(array_key_exists($PrimaryKeyItem, $LookupTable))
|
---|
398 | {
|
---|
399 | // Replace text columns
|
---|
400 | $LookupTableItem = $LookupTable[$PrimaryKeyItem];
|
---|
401 | foreach($TranslationTree[$Group['Id']]['Items'] as $GroupItem)
|
---|
402 | {
|
---|
403 | if(array_key_exists($GroupItem['Id'], $ColumnIndexes))
|
---|
404 | $Line[$ColumnIndexes[$GroupItem['Id']]] = $LookupTableItem[$GroupItem['Column']];
|
---|
405 | }
|
---|
406 | }
|
---|
407 | $NewDBCFile->SetLine($Row, $Line);
|
---|
408 |
|
---|
409 | // Show completion progress
|
---|
410 | $Progress = round($Row / $RowCount * 100);
|
---|
411 | if($Progress != $OldProgress)
|
---|
412 | {
|
---|
413 | if ($Group['Id'] == 13) $this->AddProgress(0.01);
|
---|
414 | $Output .= $Progress."%\r";
|
---|
415 | echo($Output);
|
---|
416 | $Output = '';
|
---|
417 | $OldProgress = $Progress;
|
---|
418 | }
|
---|
419 | }
|
---|
420 | $NewDBCFile->Commit();
|
---|
421 | } else $Output .= ShowMessage('Zdrojový soubor '.$this->SourceDirRelative.$this->ClientVersion['Version'].'/dbc/'.$Group['DBCFileName'].'.dbc'.' nenalezen.'."\n", MESSAGE_CRITICAL);
|
---|
422 | }
|
---|
423 | $Output .= 'Hotovo <br />';
|
---|
424 | return($Output);
|
---|
425 | }
|
---|
426 |
|
---|
427 | function ExportToLua()
|
---|
428 | {
|
---|
429 | global $TranslationTree;
|
---|
430 |
|
---|
431 | $this->LoadFilters();
|
---|
432 |
|
---|
433 | $Output = '';
|
---|
434 | if(!file_exists($this->TempDir.'lua/')) mkdir($this->TempDir.'lua/', 0777, true);
|
---|
435 | $DbResult = $this->Database->query('SELECT `Group`.* FROM `ExportGroup` JOIN `Group` ON `Group`.`Id` = `ExportGroup`.`Group` WHERE `ExportGroup`.`Export`='.$this->Id.' AND `Group`.`LuaFileName` != ""');
|
---|
436 | while($Group = $DbResult->fetch_assoc())
|
---|
437 | {
|
---|
438 | // $this->AddProgress();
|
---|
439 | $Output .= $Group['Name'].'... ';
|
---|
440 | $File = new FileStream();
|
---|
441 | if (!file_exists($this->SourceDir.$this->ClientVersion['Version'].'/lua/'.$Group['LuaFileName'].'.lua'))
|
---|
442 | continue;
|
---|
443 | $File->OpenFile($this->SourceDir.$this->ClientVersion['Version'].'/lua/'.$Group['LuaFileName'].'.lua');
|
---|
444 | $File2 = new FileStream();
|
---|
445 | $File2->CreateFile($this->TempDir.'lua/'.$Group['LuaFileName'].'.lua');
|
---|
446 |
|
---|
447 | $LookupTable = array();
|
---|
448 | $DbResult2 = $this->Database->query($this->BuildQuery($Group));
|
---|
449 | while($DbRow = $DbResult2->fetch_assoc()) {
|
---|
450 | $CanExport = true;
|
---|
451 | foreach($TranslationTree[$Group['Id']]['Items'] as $Column) {
|
---|
452 | // if (strpos($DbRow[$Column['Column']],'\\'))
|
---|
453 | // $CanExport = false;
|
---|
454 | // $DbRow[$Column['Column']] = str_replace ( '$ ','$',$DbRow[$Column['Column']]);
|
---|
455 | // $DbRow[$Column['Column']] = $DbRow['En'.$Column['Column']];
|
---|
456 |
|
---|
457 | if (!$this->HaveVarible($DbRow['En'.$Column['Column']],$DbRow[$Column['Column']])) {
|
---|
458 | if ($CanExport) $Output .= ', NE='.$DbRow['ID'];
|
---|
459 | $CanExport = false;
|
---|
460 | }
|
---|
461 | if (!$this->HaveVarible($DbRow[$Column['Column']],$DbRow['En'.$Column['Column']])) {
|
---|
462 | if ($CanExport) $Output .= ', NE='.$DbRow['ID'];
|
---|
463 | $CanExport = false;
|
---|
464 | }
|
---|
465 | if (!$this->HaveVarible($DbRow['En'.$Column['Column']],$DbRow[$Column['Column']],'%')) {
|
---|
466 | if ($CanExport) $Output .= ', NE='.$DbRow['ID'];
|
---|
467 | $CanExport = false;
|
---|
468 | }
|
---|
469 | if (!$this->HaveVarible($DbRow[$Column['Column']],$DbRow['En'.$Column['Column']],'%')) {
|
---|
470 | if ($CanExport) $Output .= ', NE='.$DbRow['ID'];
|
---|
471 | $CanExport = false;
|
---|
472 | }
|
---|
473 | if (!$this->HaveVarible($DbRow[$Column['Column']],$DbRow['En'.$Column['Column']],'\\')) {
|
---|
474 | if ($CanExport) $Output .= ', NE='.$DbRow['ID'];
|
---|
475 | $CanExport = false;
|
---|
476 | }
|
---|
477 | if (!$this->HaveVarible($DbRow['En'.$Column['Column']],$DbRow[$Column['Column']],'\\')) {
|
---|
478 | if ($CanExport) $Output .= ', NE='.$DbRow['ID'];
|
---|
479 | $CanExport = false;
|
---|
480 | }
|
---|
481 | if (!$this->HaveVarible($DbRow[$Column['Column']],$DbRow['En'.$Column['Column']],'|')) {
|
---|
482 | if ($CanExport) $Output .= ', NE='.$DbRow['ID'];
|
---|
483 | $CanExport = false;
|
---|
484 | }
|
---|
485 | if (!$this->HaveVarible($DbRow['En'.$Column['Column']],$DbRow[$Column['Column']],'|')) {
|
---|
486 | if ($CanExport) $Output .= ', NE='.$DbRow['ID'];
|
---|
487 | $CanExport = false;
|
---|
488 | }
|
---|
489 | if (!$this->HaveVarible($DbRow[$Column['Column']],$DbRow['En'.$Column['Column']],chr(10))) {
|
---|
490 | if ($CanExport) $Output .= ', NE='.$DbRow['ID'];
|
---|
491 | $CanExport = false;
|
---|
492 | }
|
---|
493 | if (!$this->HaveVarible($DbRow['En'.$Column['Column']],$DbRow[$Column['Column']],chr(10))) {
|
---|
494 | if ($CanExport) $Output .= ', NE='.$DbRow['ID'];
|
---|
495 | $CanExport = false;
|
---|
496 | }
|
---|
497 | }
|
---|
498 |
|
---|
499 | if ($CanExport)
|
---|
500 | $LookupTable[$DbRow['ShortCut']] = $DbRow;
|
---|
501 | }
|
---|
502 |
|
---|
503 | while(!$File->EOF())
|
---|
504 | {
|
---|
505 | $Line = $File->ReadLine();
|
---|
506 | if(strpos($Line, '=') !== false)
|
---|
507 | {
|
---|
508 | $LineParts = explode('=', $Line, 2);
|
---|
509 | $Value['ShortCut'] = trim($LineParts[0]);
|
---|
510 | $Line = trim($LineParts[1]);
|
---|
511 |
|
---|
512 | if($Line[0] == '"')
|
---|
513 | {
|
---|
514 | // Quoted string value
|
---|
515 | $Line = substr($Line, 1); // Skip start qoute
|
---|
516 | $TempLine = str_replace('\"', ' ', $Line); // Temporary remove slashed quotes
|
---|
517 | if (strpos($TempLine, '"')) {
|
---|
518 | $Value['Text'] = substr($Line, 0, strpos($TempLine, '"'));
|
---|
519 | } else {
|
---|
520 | $Value['Text'] = substr($Line, 0, strpos($Line, '"'));
|
---|
521 | }
|
---|
522 | // $Value['Text'] = str_replace('\n', "\n", $Value['Text']);
|
---|
523 | // $Value['Text'] = addslashes(stripslashes($Value['Text']));
|
---|
524 | $Line = trim(substr($Line, strpos($TempLine, '"') + 1)); // Skip closing quote and semicolon {
|
---|
525 | } else
|
---|
526 | {
|
---|
527 | // Nonstring value
|
---|
528 | $Value['Text'] = substr($Line, 0, strpos($Line, ';'));
|
---|
529 | }
|
---|
530 | $Line = substr($Line, strpos($Line, ';') + 1);
|
---|
531 | $Value['Comment'] = addslashes(stripslashes(substr($Line, 3))); // Skip " --"
|
---|
532 |
|
---|
533 | if(array_key_exists($Value['ShortCut'], $LookupTable))
|
---|
534 | {
|
---|
535 | $DbRow = $LookupTable[$Value['ShortCut']];
|
---|
536 | $Value['Text'] = $DbRow['Text'];
|
---|
537 | //addslashes
|
---|
538 | $Value['Text'] = str_replace('"', '\"', $Value['Text']);
|
---|
539 | // Escape new line control characters
|
---|
540 | $Value['Text'] = str_replace("\n", '\n', $Value['Text']);
|
---|
541 | $Value['Text'] = str_replace("\r", '', $Value['Text']);
|
---|
542 | $Value['Comment'] = $DbRow['Comment'];
|
---|
543 | // Only one line comments allowed
|
---|
544 | $Value['Comment'] = str_replace("\n", ' ', $Value['Comment']);
|
---|
545 | $Value['Comment'] = str_replace("\r", '', $Value['Comment']);
|
---|
546 | //echo('.');
|
---|
547 | }
|
---|
548 | $NewLine = $Value['ShortCut'].' = "'.$Value['Text'].'";';
|
---|
549 | //if($Value['Comment'] != '') $NewLine .= ' -- '.$Value['Comment'];
|
---|
550 | $NewLine .= "\r\n";
|
---|
551 | $File2->WriteLine($NewLine);
|
---|
552 | } else $File2->WriteLine($Line);
|
---|
553 | }
|
---|
554 | $Output .= 'Hotovo <br/>';
|
---|
555 | }
|
---|
556 | return($Output);
|
---|
557 | }
|
---|
558 |
|
---|
559 | function GetReadme() {
|
---|
560 | $_GET['ExportId'] = $this->Id;
|
---|
561 | $PageExport = new PageExport($this->System);
|
---|
562 | $this->LoadFilters();
|
---|
563 | $Output = '';
|
---|
564 | //generation readme
|
---|
565 | $Output .= '<?xml version="1.0" encoding="utf-8"?\>'.
|
---|
566 | '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'.
|
---|
567 | '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cs">'.
|
---|
568 | '<head>'.
|
---|
569 | '<STYLE type="text/css">'.
|
---|
570 | '.BaseTable {margin: 2px auto 2px auto;border-width: 1px;border-color: black;border-style: solid;border-collapse: collapse;}'.
|
---|
571 |
|
---|
572 | '.BaseTable tr td{ border-width: 1px; border-color: black; border-style: solid; padding: 2px; text-align: center;}'.
|
---|
573 |
|
---|
574 | '.BaseTable tr th{ border-width: 1px; border-color: black; border-style: solid; padding: 2px; background-color: #F0F0F0; text-align: center;}'.
|
---|
575 | '</STYLE>'.
|
---|
576 | '<meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8" />'.
|
---|
577 | '<title>Čeština pro WoW</title>'.
|
---|
578 | '</head><body>'.
|
---|
579 | '<h1>České WoW - čestina pro klienta hry World of Warcraft</h1>'.
|
---|
580 |
|
---|
581 | '<table cellspacing="10"><tr><td valign="top">'.
|
---|
582 |
|
---|
583 | '<p>Texty přebírány z projektu <a href="http://wowpreklad.zdechov.net/">wowpreklad.zdechov.net</a><br>'.
|
---|
584 | '<a href="http://wowpreklad.zdechov.net/export/?Action=View&ExportId='.$this->Id.'&Tab=0">Export '.$this->Id.'</a></p><br>'.
|
---|
585 |
|
---|
586 |
|
---|
587 | '<p><strong>Vlastnosti</strong>'.
|
---|
588 | '<ul>'.
|
---|
589 | '<li>Požadovaná verze klienta: '.$this->ClientVersion['Version'].'</li>'.
|
---|
590 | '<li>Datum uvolnění: '.date('d.m.Y h:m',time()).'</li>'.
|
---|
591 | '<li>Sestaveno automaticky překladovým systémem <a href="http://wowpreklad.zdechov.net/">WoW překlad</a></li>'.
|
---|
592 | //'<li>Tento soubor se generuje každý den. Pokud se zapojíte do překladu, zítra můžete stáhnout tento soubor znovu včetně svých překladů</li>'.
|
---|
593 | //'<li>Sestavil: Maron</li>'.
|
---|
594 | '</ul>'.
|
---|
595 | '</p>'.
|
---|
596 | '<br>'.
|
---|
597 |
|
---|
598 | '<h2>Nejčastější otázky</h2>'.
|
---|
599 | '<p><strong>Jak mám hru spustit?</strong><br>'.
|
---|
600 | 'Hru musíte spustit přes soubor WowLua.exe v kořenovém adresáři hry.</p>'.
|
---|
601 |
|
---|
602 | '<p><strong>Mohu použít tuto češtinu na oficiálních serverech?</strong><br>'.
|
---|
603 | 'Ne úplně, protože se vystavujete riziku zablokování vašeho účtu z důvodu použití upravené hry. Na oficiálním serveru lze využít pouze Addon s češtinou CzWoW.</p>'.
|
---|
604 |
|
---|
605 | '<p><strong>Mám nainstalovánu češtinu a nejde mi spustit Wow.exe.</strong><br>'.
|
---|
606 | 'Pokud chcete opět spouštět hru přes původní Wow.exe v angličtině, musíte češtinu nejprve odinstalovat ze systému. Především se jedná o soubor Data/enGB/patch-enGB-5.MPQ či Data/enUS/patch-enUS-5.MPQ, který je nutno smazat.</p>'.
|
---|
607 |
|
---|
608 | '<p><strong>Nedaří se mi provést aktualizaci klienta s nainstalovanou češtinou.</strong><br>'.
|
---|
609 | 'Před aktualizací na novější verzi klienta musíte nejprve češtinu odinstalovat. Čeština totiž mění v rámci patch MPQ souboru některé soubory hry, což oficiální instalátory vyhodnotí jako poškození hry.</p>'.
|
---|
610 |
|
---|
611 | '</td><td>';
|
---|
612 |
|
---|
613 | $Output .= $PageExport->ExportViewStat(' WHERE `DBCFileName` !=\'\' OR `LuaFileName` !=\'\' OR `Group`.`Id` = 1 OR `Group`.`Id` = 2 OR `Group`.`Id` = 3 OR `Group`.`Id` = 16');
|
---|
614 |
|
---|
615 | $Output .= '</td></tr></table>'.
|
---|
616 |
|
---|
617 |
|
---|
618 | '</body></html>';
|
---|
619 | return $Output;
|
---|
620 | }
|
---|
621 |
|
---|
622 | function ExportToXML()
|
---|
623 | {
|
---|
624 | global $TranslationTree;
|
---|
625 |
|
---|
626 | $this->LoadFilters();
|
---|
627 |
|
---|
628 | $Buffer = '<?xml version="1.0" encoding="utf-8"?>'."\n".
|
---|
629 | "<document>\n".
|
---|
630 | " <meta>\n".
|
---|
631 | " <projecturl>".$this->Config['Web']['Host'].$this->System->Link('/')."</projecturl>\n".
|
---|
632 | " <time>".date('r')."</time>\n".
|
---|
633 | " <diacritics mode=".'"'.$this->Export['WithDiacritic'].'"'." />\n".
|
---|
634 | " <author>".$this->System->User->Name."</author>\n".
|
---|
635 | " <contributors>\n";
|
---|
636 | foreach(explode(',', $this->UserNames) as $UserName)
|
---|
637 | $Buffer .= " <user>".$UserName."</user>\n";
|
---|
638 | $Buffer .=
|
---|
639 | " </contributors>\n".
|
---|
640 | " </meta>\n".
|
---|
641 | " <translation>\n";
|
---|
642 |
|
---|
643 | $DbResult = $this->Database->query('SELECT `Group`.* FROM `ExportGroup` '.
|
---|
644 | 'JOIN `Group` ON `Group`.`Id` = `ExportGroup`.`Group` WHERE `ExportGroup`.`Export`='.$this->Id);
|
---|
645 | while($Group = $DbResult->fetch_assoc())
|
---|
646 | {
|
---|
647 | if($Group['MangosTable'] == '')
|
---|
648 | {
|
---|
649 | $Group['MangosTable'] = $Group['TablePrefix'];
|
---|
650 | $Group['MangosTableIndex'] = 'entry';
|
---|
651 | }
|
---|
652 | $Buffer .= ' <group id="'.$Group['Id'].'" name="'.$Group['TablePrefix'].'">'."\n";
|
---|
653 | $DbResult2 = $this->Database->query($this->BuildQuery($Group));
|
---|
654 | while($Line = $DbResult2->fetch_assoc())
|
---|
655 | {
|
---|
656 | $Buffer .= ' <item id="'.$Line['Entry'].'" user="'.$Line['UserName'].'">'."\n";
|
---|
657 | $Values = '';
|
---|
658 | foreach($TranslationTree[$Group['Id']]['Items'] as $GroupItem)
|
---|
659 | {
|
---|
660 | if($GroupItem['MangosColumn'] == '') $GroupItem['MangosColumn'] = $GroupItem['Column'];
|
---|
661 | if($Line[$GroupItem['Column']] != '')
|
---|
662 | $Buffer .= ' <text index="'.$GroupItem['Id'].'" name="'.
|
---|
663 | $GroupItem['Column'].'">'.addslashes($Line[$GroupItem['Column']]).'</text>'."\n";
|
---|
664 | }
|
---|
665 | $Buffer .= " </item>\n";
|
---|
666 | }
|
---|
667 | $Buffer .= " </group>\n";
|
---|
668 | }
|
---|
669 | if($this->Export['WithDiacritic'] != 1) $Buffer = utf2ascii($Buffer);
|
---|
670 | $Buffer .= " </translation>\n".
|
---|
671 | "</document>";
|
---|
672 | return($Buffer);
|
---|
673 | }
|
---|
674 | }
|
---|
675 |
|
---|
676 | include_once(dirname(__FILE__).'/Page.php');
|
---|
677 | include_once(dirname(__FILE__).'/ExportOutput.php');
|
---|
678 |
|
---|
679 | class ModuleExport extends AppModule
|
---|
680 | {
|
---|
681 | function __construct($System)
|
---|
682 | {
|
---|
683 | parent::__construct($System);
|
---|
684 | $this->Name = 'Export';
|
---|
685 | $this->Version = '1.0';
|
---|
686 | $this->Creator = 'Chronos';
|
---|
687 | $this->License = 'GNU/GPL';
|
---|
688 | $this->Description = 'Allow parametric export of translated texts to various supported output formats';
|
---|
689 | $this->Dependencies = array();
|
---|
690 | }
|
---|
691 |
|
---|
692 | function Start()
|
---|
693 | {
|
---|
694 | $this->System->RegisterPage('export', 'PageExport');
|
---|
695 | $this->System->RegisterMenuItem(array(
|
---|
696 | 'Title' => 'Exporty',
|
---|
697 | 'Hint' => 'Zde si můžete stáhnout přeložené texty',
|
---|
698 | 'Link' => $this->System->Link('/export/'),
|
---|
699 | 'Permission' => LICENCE_ANONYMOUS,
|
---|
700 | 'Icon' => '',
|
---|
701 | ), 2);
|
---|
702 | }
|
---|
703 | }
|
---|
704 |
|
---|