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 | $this->SaveAllUsers();
|
---|
25 | }
|
---|
26 |
|
---|
27 | function SaveAllUsers() {
|
---|
28 | $DbResult = $this->System->Database->query('SELECT * FROM `Export` WHERE `Id`='.$this->Id);
|
---|
29 | $Export = $DbResult->fetch_assoc();
|
---|
30 | if ($Export['AllUsers']) {
|
---|
31 | $DbResult2 = $this->System->Database->query('SELECT ID FROM `User` WHERE `ID` NOT IN(SELECT `User` FROM `ExportUser` WHERE `Export`='.$this->Id.')');
|
---|
32 | while($UserLine = $DbResult2->fetch_assoc())
|
---|
33 | {
|
---|
34 | $Condition = ' WHERE `Export`='.$this->Id.' AND `User`='.$UserLine['ID'];
|
---|
35 | $DbResult = $this->System->Database->query('SELECT * FROM `ExportUser` '.$Condition); //,MAX(`Sequence`) as MaxSequence
|
---|
36 | if($DbResult->num_rows > 0)
|
---|
37 | {
|
---|
38 | // $this->System->Database->query('UPDATE `ExportUser` SET `Sequence`='.$Value.$Condition);
|
---|
39 | } else
|
---|
40 | {
|
---|
41 | $this->System->Database->query('INSERT INTO `ExportUser` (`Export`, `User`, `Sequence`) VALUES ('.$this->Id.', '.$UserLine['ID'].', 0)');
|
---|
42 | }
|
---|
43 | }
|
---|
44 |
|
---|
45 | $this->System->Database->query('SET @I = 0');
|
---|
46 | $this->System->Database->query('UPDATE `ExportUser` SET `Sequence` = (@I := @I + 1) WHERE `Export`='.$this->Id.' ORDER BY `Sequence`;');
|
---|
47 | }
|
---|
48 | }
|
---|
49 |
|
---|
50 | function LoadFilters()
|
---|
51 | {
|
---|
52 | $DbResult = $this->Database->query('SELECT * FROM `Export` WHERE `Id`='.$this->Id);
|
---|
53 | if($DbResult->num_rows == 0) throw new Exception('Export '.$this->Id.' neexistuje');
|
---|
54 | $this->Export = $DbResult->fetch_assoc();
|
---|
55 |
|
---|
56 | // Filter selected users
|
---|
57 | $this->UserNames = '';
|
---|
58 | $DbResult = $this->Database->query('SELECT `ExportUser`.*, `User`.`Name`, `User`.`ID` FROM `ExportUser` '.
|
---|
59 | 'LEFT JOIN `User` ON `User`.`ID`=`ExportUser`.`User` '.
|
---|
60 | 'WHERE `ExportUser`.`Export`='.$this->Id.' ORDER BY `ExportUser`.`Sequence`');
|
---|
61 | while($UserLine = $DbResult->fetch_assoc())
|
---|
62 | {
|
---|
63 | $this->UserNames .= ', '.$UserLine['Name'];
|
---|
64 | }
|
---|
65 | $this->UserNames = substr($this->UserNames, 2);
|
---|
66 |
|
---|
67 | if($this->Export['ClientVersion'] != '')
|
---|
68 | {
|
---|
69 | $DbResult = $this->Database->query('SELECT * FROM `ClientVersion` WHERE `Id`='.$this->Export['ClientVersion']);
|
---|
70 | $this->ClientVersion = $DbResult->fetch_assoc();
|
---|
71 | } else $this->ClientVersion = '';
|
---|
72 | }
|
---|
73 |
|
---|
74 | function BuildQuery($Group, $Columns = '', $Version = '')
|
---|
75 | {
|
---|
76 | global $TranslationTree;
|
---|
77 |
|
---|
78 | if ($Version <> '')
|
---|
79 | $ExportVersion = $Version;
|
---|
80 | else
|
---|
81 | $ExportVersion = $this->ClientVersion['BuildNumber'];
|
---|
82 |
|
---|
83 | $Query = 'SELECT * FROM (SELECT `T`.*, '.$Columns.'`User`.`Name` AS `UserName` FROM `'.$Group['TablePrefix'].'` AS `T`'.
|
---|
84 | ' JOIN `ExportUser` ON (`ExportUser`.`User`=`T`.`User`) AND (`ExportUser`.`Export`='.$this->Id.') '.
|
---|
85 | ' JOIN `User` ON `User`.`ID`=`T`.`User`'.
|
---|
86 | ' JOIN `ExportLanguage` ON (`ExportLanguage`.`Export`='.$this->Id.')'.
|
---|
87 | ' WHERE (`Complete` = 1) AND (`VersionStart` <= '.$ExportVersion.') AND (`VersionEnd` >= '.$ExportVersion.')'.
|
---|
88 | ' ORDER BY `ExportLanguage`.`Sequence`, `ExportUser`.`Sequence`) AS `TT` GROUP BY `TT`.`Entry`';
|
---|
89 |
|
---|
90 | // Build columns for english texts
|
---|
91 | $OriginalColumns = '';
|
---|
92 | foreach($TranslationTree[$Group['Id']]['Items'] as $Column)
|
---|
93 | $OriginalColumns .= ' `T3`.`'.$Column['Column'].'` AS `En'.$Column['Column'].'`, ';
|
---|
94 | $OriginalColumns = substr($OriginalColumns, 0, -2);
|
---|
95 |
|
---|
96 | // Expand query for loading english texts
|
---|
97 | $Query = 'SELECT `T4`.*, '.$OriginalColumns.' FROM ('.$Query.') AS `T4` '.
|
---|
98 | ' LEFT JOIN `'.$Group['TablePrefix'].'` AS `T3` ON (`T3`.`Entry` = `T4`.`Entry`) '.
|
---|
99 | 'AND (`T3`.`Language` = '.$this->System->Config['OriginalLanguage'].') AND '.
|
---|
100 | '(`T3`.`VersionStart` = `T4`.`VersionStart`) AND (`T3`.`VersionEnd` = `T4`.`VersionEnd`)';
|
---|
101 |
|
---|
102 | return($Query);
|
---|
103 | }
|
---|
104 |
|
---|
105 | function ExportToMangosSQL()
|
---|
106 | {
|
---|
107 | global $TranslationTree;
|
---|
108 |
|
---|
109 | $this->LoadFilters();
|
---|
110 |
|
---|
111 | $Buffer =
|
---|
112 | "-- Generováno projektem wowpreklad.zdechov.net\n".
|
---|
113 | "-- ===========================================\n".
|
---|
114 | "--\n".
|
---|
115 | "-- Web projektu: ".$this->Config['Web']['Host'].$this->System->Link('/')."\n".
|
---|
116 | "-- Datum exportu: ".date("j.n.Y H:i:s")."\n".
|
---|
117 | "-- Znaková sada: ".$this->Config['Database']['Charset']." / ".$this->Config['Web']['Charset']."\n".
|
---|
118 | "-- Diakritika: ".$this->AnoNe[$this->Export['WithDiacritic']]."\n".
|
---|
119 | "-- Vygeneroval uživatel: ".$this->System->User->Name."\n".
|
---|
120 | "-- Vzato od uživatelů: ".$this->UserNames."\n".
|
---|
121 | "-- Generované tabulky: ";
|
---|
122 |
|
---|
123 | $DbResult = $this->Database->query('SELECT `Group`.* FROM `ExportGroup` '.
|
---|
124 | 'JOIN `Group` ON `Group`.`Id` = `ExportGroup`.`Group` WHERE `ExportGroup`.`Export`='.$this->Id);
|
---|
125 | while($Group = $DbResult->fetch_assoc())
|
---|
126 | {
|
---|
127 | $Buffer .= $Group['TablePrefix'].', ';
|
---|
128 | }
|
---|
129 | $Buffer .= "\n\n";
|
---|
130 |
|
---|
131 | $DbResult = $this->Database->query('SELECT `Group`.* FROM `ExportGroup` '.
|
---|
132 | 'JOIN `Group` ON `Group`.`Id` = `ExportGroup`.`Group` WHERE `ExportGroup`.`Export`='.$this->Id);
|
---|
133 | while($Group = $DbResult->fetch_assoc())
|
---|
134 | {
|
---|
135 | if($Group['MangosTable'] != '')
|
---|
136 | {
|
---|
137 | $Buffer .= "\n\n-- ".$Group['Name']."\n\n";
|
---|
138 | $DbResult2 = $this->Database->query($this->BuildQuery($Group));
|
---|
139 | if($DbResult2->num_rows > 0)
|
---|
140 | while($Line = $DbResult2->fetch_array())
|
---|
141 | {
|
---|
142 | $Values = '';
|
---|
143 | foreach($TranslationTree[$Group['Id']]['Items'] as $GroupItem)
|
---|
144 | if($GroupItem['Column'] != $Group['PrimaryKeyItem']) // Do not update primary key
|
---|
145 | {
|
---|
146 | if($GroupItem['MangosColumn'] == '') $GroupItem['MangosColumn'] = $GroupItem['Column'];
|
---|
147 | $Values .= ', `'.$GroupItem['MangosColumn'].'`="'.addslashes($Line[$GroupItem['Column']]).'"';
|
---|
148 | }
|
---|
149 | $Values = substr($Values, 2);
|
---|
150 |
|
---|
151 | // Get multicolumn index
|
---|
152 | $ColumnItems = explode(',', $Group['MangosTableIndex']);
|
---|
153 | if(count($ColumnItems) > 1)
|
---|
154 | {
|
---|
155 | $Where = 'CONCAT(';
|
---|
156 | foreach($ColumnItems as $ColumnItem)
|
---|
157 | $Where .= '`'.$ColumnItem.'`, "_", ';
|
---|
158 | $Where = substr($Where, 0, -7).')';
|
---|
159 | } else $Where = '`'.$Group['MangosTableIndex'].'`';
|
---|
160 | $Where .= ' = "'.$Line[$Group['PrimaryKeyItem']].'";';
|
---|
161 |
|
---|
162 | $Line = 'UPDATE `'.$Group['MangosTable'].'` SET '.$Values.' WHERE '.$Where;
|
---|
163 | $Line = str_replace("\n", '\n', $Line);
|
---|
164 | $Line = str_replace("\r", '', $Line);
|
---|
165 | $Buffer .= $Line."\n";
|
---|
166 | }
|
---|
167 | }
|
---|
168 | }
|
---|
169 | if($this->Export['WithDiacritic'] != 1) $Buffer = utf2ascii($Buffer);
|
---|
170 | return($Buffer);
|
---|
171 | }
|
---|
172 |
|
---|
173 | function ExportToAoWoWSQL()
|
---|
174 | {
|
---|
175 | global $TranslationTree, $AoWoWconf;
|
---|
176 |
|
---|
177 | //require_once('../aowow/configs/config.php');
|
---|
178 |
|
---|
179 | $Buffer = $this->ExportToMangosSQL();
|
---|
180 |
|
---|
181 | /*
|
---|
182 | // Data to aowow
|
---|
183 | $Database2 = new mysqli($this->Config['Database']['Host'], $this->Config['Database']['User'], $this->Config['Database']['Password'], $this->Config['Database']['Database']);
|
---|
184 | $Database2->query('SET NAMES '.$this->Config['Database']['Charset']);
|
---|
185 | $Database2->select_db($AoWoWconf['mangos']['db']);
|
---|
186 | $AoWoWTables = array(
|
---|
187 | 'aowow_resistances' => 'Id',
|
---|
188 | 'aowow_spelldispeltype' => 'Id',
|
---|
189 | 'aowow_skill' => 'skillID',
|
---|
190 | );
|
---|
191 | foreach($AoWoWTables as $AoWoWTable => $IndexColum)
|
---|
192 | {
|
---|
193 | $Buffer .= '--'.$AoWoWTable.', ';
|
---|
194 | $Buffer .= "\n\n";
|
---|
195 | $Query = 'SELECT `name`,`'.$IndexColum.'` FROM `'.$AoWoWTable.'`';
|
---|
196 | $DbResult = $Database2->query($Query);
|
---|
197 | while($Line = $DbResult->fetch_assoc())
|
---|
198 | {
|
---|
199 | $Ori_text = $Line['name'];
|
---|
200 | $DbResult2 = $Database2->query('SELECT `Text` AS `En`,
|
---|
201 | (SELECT `Text` FROM `'.$this->System->Config['Database']['Database'].'`.`TextGlobalString` AS `TableTran`
|
---|
202 | WHERE `TableEn`.`Entry` = `TableTran`.`Entry` AND (`Complete` = 1) AND '.$this->WhereLang.' AND '.$this->WhereUsers.$this->OrderByUserList.' LIMIT 1) AS `Tran`
|
---|
203 | FROM `'.$this->System->Config['Database']['Database'].'`.`TextGlobalString` AS `TableEn` WHERE
|
---|
204 | `Text` = "'.addslashes($Ori_text).'" LIMIT 1');
|
---|
205 | $Tran = $DbResult2->fetch_assoc();
|
---|
206 | //echo ($Line['name'].'='.$Tran['tran']);
|
---|
207 | if($Tran['Tran'] == '')
|
---|
208 | {
|
---|
209 | $DbResult2 = $Database2->query('SELECT `OptionText` AS `En`,
|
---|
210 | (SELECT `OptionText` FROM `'.$this->Config['Database']['Database'].'`.`TextNPCOption` AS `TableTran`
|
---|
211 | WHERE `TableEn`.`Entry` = `TableTran`.`Entry` AND (`Complete` = 1) AND '.$this->WhereLang.'
|
---|
212 | AND '.$this->WhereUsers.$this->OrderByUserList.' LIMIT 1) AS `Tran`
|
---|
213 | FROM `'.$this->Config['Database']['Database'].'`.`TextNPCOption` AS `TableEn` WHERE
|
---|
214 | `OptionText` = "'.addslashes($Ori_text).'" LIMIT 1');
|
---|
215 | $Tran = $DbResult2->fetch_assoc();
|
---|
216 | }
|
---|
217 |
|
---|
218 | if($Tran['Tran'] <> '')
|
---|
219 | $Buffer .= 'UPDATE `'.$AoWoWTable.'` SET `name` = "'.addslashes($Tran['Tran']).'" WHERE '.$IndexColum.' = '.$Line[$IndexColum].' ;'."\n";
|
---|
220 | }
|
---|
221 | $Buffer .= "\n\n";
|
---|
222 | }
|
---|
223 | */
|
---|
224 | if($this->Export['WithDiacritic'] != 1) $Buffer = utf2ascii($Buffer);
|
---|
225 | return($Buffer);
|
---|
226 | }
|
---|
227 |
|
---|
228 |
|
---|
229 |
|
---|
230 | function HaveVarible($String1, $String2, $StartChar = '$')
|
---|
231 | {
|
---|
232 | //Export only if translate have same varible %
|
---|
233 |
|
---|
234 | if (strpos($String1,$StartChar) !== false) {
|
---|
235 |
|
---|
236 | while ( strpos($String1,$StartChar) !== false) {
|
---|
237 | $pos = strpos($String1,$StartChar);
|
---|
238 | $String1 = substr($String1,$pos+1);
|
---|
239 | $varible = $String1;
|
---|
240 | if (strpos($varible,' ')) $varible = substr($varible,0,strpos($varible,' '));
|
---|
241 | if (strpos($varible,'.')) $varible = substr($varible,0,strpos($varible,'.'));
|
---|
242 | if (strpos($varible,',')) $varible = substr($varible,0,strpos($varible,','));
|
---|
243 | if (strpos($varible,'%')) $varible = substr($varible,0,strpos($varible,'%'));
|
---|
244 | if (strpos($varible,chr(10))) $varible = substr($varible,0,strpos($varible,chr(10)));
|
---|
245 | // echo $pos.'-'.$varible.'-'.$String1.'-' .$String2.'
|
---|
246 | // ';
|
---|
247 |
|
---|
248 | if (false === strpos($String2,$varible)) {
|
---|
249 | // echo $varible;
|
---|
250 | return(false);
|
---|
251 | }
|
---|
252 | }
|
---|
253 | }
|
---|
254 | return (true);
|
---|
255 | }
|
---|
256 |
|
---|
257 | function AddProgress($add = 2) {
|
---|
258 | if (file_exists($this->TempDir.'progress')) {
|
---|
259 | $File = new FileStream();
|
---|
260 | $File->OpenFile($this->TempDir.'progress');
|
---|
261 | $Line = $File->ReadLine();
|
---|
262 |
|
---|
263 | $File = new FileStream();
|
---|
264 | $File->CreateFile($this->TempDir.'progress');
|
---|
265 | $Line+=$add;
|
---|
266 | $File->WriteLine($Line);
|
---|
267 | }
|
---|
268 | }
|
---|
269 |
|
---|
270 | function ExportToDBC()
|
---|
271 | {
|
---|
272 | global $TranslationTree;
|
---|
273 |
|
---|
274 | $this->LoadFilters();
|
---|
275 |
|
---|
276 | $DbResult = $this->Database->query('SELECT `Group`.* FROM `ExportGroup` '.
|
---|
277 | 'JOIN `Group` ON `Group`.`Id` = `ExportGroup`.`Group` '.
|
---|
278 | 'WHERE `ExportGroup`.`Export`='.$this->Id.' AND `Group`.`DBCFileName` != ""');
|
---|
279 | $Output = 'Počet generovaných skupin: '.$DbResult->num_rows."\n";
|
---|
280 | while($Group = $DbResult->fetch_assoc())
|
---|
281 | {
|
---|
282 | $this->AddProgress();
|
---|
283 | $Output .= $Group['Name'].', ';
|
---|
284 | if(file_exists($this->SourceDir.$this->ClientVersion['Version'].'/dbc/'.$Group['DBCFileName'].'.dbc'))
|
---|
285 | {
|
---|
286 | // Load string column index list
|
---|
287 | $DbResult2 = $this->Database->query('SELECT * FROM `GroupItem` '.
|
---|
288 | 'JOIN `GroupItemDBC` ON `GroupItem`.`Id` = `GroupItemDBC`.`GroupItem` AND `GroupItemDBC`.`ClientVersion` = '.$this->ClientVersion['Id'].' WHERE `GroupItem`.`Group` = '.$Group['Id']);
|
---|
289 | $ColumnIndexes = array();
|
---|
290 | $ColumnFormat = array();
|
---|
291 | while($DbRow = $DbResult2->fetch_assoc())
|
---|
292 | {
|
---|
293 | $ColumnFormat[$DbRow['ColumnIndex']] = FORMAT_STRING;
|
---|
294 | $ColumnIndexes[$DbRow['GroupItem']] = $DbRow['ColumnIndex'];
|
---|
295 | }
|
---|
296 |
|
---|
297 | // Load all data into lookup table
|
---|
298 | $LookupTable = array();
|
---|
299 | $DbResult2 = $this->Database->query($this->BuildQuery($Group));
|
---|
300 | while($DbRow = $DbResult2->fetch_assoc()) {
|
---|
301 | //Export only if translate have same varible %
|
---|
302 | $CanExport = true;
|
---|
303 | foreach($TranslationTree[$Group['Id']]['Items'] as $Column) {
|
---|
304 | $DbRow[$Column['Column']] = str_replace ( '$ ','$',$DbRow[$Column['Column']]);
|
---|
305 | if (!$this->HaveVarible($DbRow['En'.$Column['Column']],$DbRow[$Column['Column']])) {
|
---|
306 | $CanExport = false;
|
---|
307 | $Output .= ', NE='.$DbRow['ID'];
|
---|
308 | }
|
---|
309 | if (!$this->HaveVarible($DbRow[$Column['Column']],$DbRow['En'.$Column['Column']])) {
|
---|
310 | $CanExport = false;
|
---|
311 | $Output .= ', NE='.$DbRow['ID'];
|
---|
312 | }
|
---|
313 | }
|
---|
314 |
|
---|
315 | if ($CanExport)
|
---|
316 | $LookupTable[$DbRow[$Group['PrimaryKeyItem']]] = $DbRow;
|
---|
317 |
|
---|
318 | }
|
---|
319 |
|
---|
320 | // Open original DBC file
|
---|
321 | $SourceDBCFile = new DBCFile();
|
---|
322 | $SourceDBCFile->OpenFile($this->SourceDir.$this->ClientVersion['Version'].'/dbc/'.$Group['DBCFileName'].'.dbc', $ColumnFormat);
|
---|
323 |
|
---|
324 | // Create new DBC file
|
---|
325 | if(!file_exists($this->TempDir.'dbc/')) mkdir ($this->TempDir.'dbc/', 0777, true);
|
---|
326 | $NewDBCFile = new DBCFile();
|
---|
327 | $NewDBCFile->CreateFile($this->TempDir.'dbc/'.$Group['DBCFileName'].'.dbc', $ColumnFormat);
|
---|
328 | $NewDBCFile->SetRecordCount($SourceDBCFile->GetRecordCount());
|
---|
329 | $NewDBCFile->SetFieldCount($SourceDBCFile->GetFieldCount());
|
---|
330 | $NewDBCFile->Commit();
|
---|
331 |
|
---|
332 | // Replace translated strings
|
---|
333 | $OldProgress = -1;
|
---|
334 | $Output .= "\n\r";
|
---|
335 | $RowCount = $SourceDBCFile->GetRecordCount();
|
---|
336 | $FieldCount = $SourceDBCFile->GetFieldCount();
|
---|
337 | for($Row = 0; $Row < $RowCount; $Row++)
|
---|
338 | {
|
---|
339 | $Line = $SourceDBCFile->GetLine($Row);
|
---|
340 |
|
---|
341 | // Get multicolumn index value
|
---|
342 | $PrimaryKeyItem = '';
|
---|
343 | $ColumnItems = explode(',', $Group['DBCIndex']);
|
---|
344 | if(count($ColumnItems) > 1)
|
---|
345 | {
|
---|
346 | foreach($ColumnItems as $ColumnItem)
|
---|
347 | $PrimaryKeyItem .= $Line[$ColumnItem].'_';
|
---|
348 | $PrimaryKeyItem = substr($PrimaryKeyItem, 0, -1);
|
---|
349 | } else $PrimaryKeyItem = $Line[$Group['DBCIndex']];
|
---|
350 |
|
---|
351 | if(array_key_exists($PrimaryKeyItem, $LookupTable))
|
---|
352 | {
|
---|
353 | // Replace text columns
|
---|
354 | $LookupTableItem = $LookupTable[$PrimaryKeyItem];
|
---|
355 | foreach($TranslationTree[$Group['Id']]['Items'] as $GroupItem)
|
---|
356 | {
|
---|
357 | if(array_key_exists($GroupItem['Id'], $ColumnIndexes))
|
---|
358 | $Line[$ColumnIndexes[$GroupItem['Id']]] = $LookupTableItem[$GroupItem['Column']];
|
---|
359 | }
|
---|
360 | }
|
---|
361 | $NewDBCFile->SetLine($Row, $Line);
|
---|
362 |
|
---|
363 | // Show completion progress
|
---|
364 | $Progress = round($Row / $RowCount * 100);
|
---|
365 | if($Progress != $OldProgress)
|
---|
366 | {
|
---|
367 | if ($Group['Id'] == 13) $this->AddProgress(0.01);
|
---|
368 | $Output .= $Progress."%\r";
|
---|
369 | echo($Output);
|
---|
370 | $Output = '';
|
---|
371 | $OldProgress = $Progress;
|
---|
372 | }
|
---|
373 | }
|
---|
374 | $NewDBCFile->Commit();
|
---|
375 | } else $Output .= ShowMessage('Zdrojový soubor '.$this->SourceDirRelative.$this->ClientVersion['Version'].'/dbc/'.$Group['DBCFileName'].'.dbc'.' nenalezen.'."\n", MESSAGE_CRITICAL);
|
---|
376 | }
|
---|
377 | $Output .= 'Hotovo <br />';
|
---|
378 | return($Output);
|
---|
379 | }
|
---|
380 |
|
---|
381 | function ExportToLua()
|
---|
382 | {
|
---|
383 | global $TranslationTree;
|
---|
384 |
|
---|
385 | // $this->LoadFilters();
|
---|
386 |
|
---|
387 | $Output = '';
|
---|
388 | if(!file_exists($this->TempDir.'lua/')) mkdir($this->TempDir.'lua/', 0777, true);
|
---|
389 | $DbResult = $this->Database->query('SELECT `Group`.* FROM `ExportGroup` JOIN `Group` ON `Group`.`Id` = `ExportGroup`.`Group` WHERE `ExportGroup`.`Export`='.$this->Id.' AND `Group`.`LuaFileName` != ""');
|
---|
390 | while($Group = $DbResult->fetch_assoc())
|
---|
391 | {
|
---|
392 | $this->AddProgress();
|
---|
393 | $Output .= $Group['Name'].'... ';
|
---|
394 | $File = new FileStream();
|
---|
395 | $File->OpenFile($this->SourceDir.$this->ClientVersion['Version'].'/lua/'.$Group['LuaFileName'].'.lua');
|
---|
396 | $File2 = new FileStream();
|
---|
397 | $File2->CreateFile($this->TempDir.'lua/'.$Group['LuaFileName'].'.lua');
|
---|
398 |
|
---|
399 | $LookupTable = array();
|
---|
400 | $DbResult2 = $this->Database->query($this->BuildQuery($Group));
|
---|
401 | while($DbRow = $DbResult2->fetch_assoc()) {
|
---|
402 | $CanExport = true;
|
---|
403 | foreach($TranslationTree[$Group['Id']]['Items'] as $Column) {
|
---|
404 | // if (strpos($DbRow[$Column['Column']],'\\'))
|
---|
405 | // $CanExport = false;
|
---|
406 | // $DbRow[$Column['Column']] = str_replace ( '$ ','$',$DbRow[$Column['Column']]);
|
---|
407 | $DbRow[$Column['Column']] = $DbRow['En'.$Column['Column']];
|
---|
408 |
|
---|
409 | if (!$this->HaveVarible($DbRow['En'.$Column['Column']],$DbRow[$Column['Column']])) {
|
---|
410 | if ($CanExport) $Output .= ', NE='.$DbRow['ID'];
|
---|
411 | $CanExport = false;
|
---|
412 | }
|
---|
413 | if (!$this->HaveVarible($DbRow[$Column['Column']],$DbRow['En'.$Column['Column']])) {
|
---|
414 | if ($CanExport) $Output .= ', NE='.$DbRow['ID'];
|
---|
415 | $CanExport = false;
|
---|
416 | }
|
---|
417 | if (!$this->HaveVarible($DbRow['En'.$Column['Column']],$DbRow[$Column['Column']],'%')) {
|
---|
418 | if ($CanExport) $Output .= ', NE='.$DbRow['ID'];
|
---|
419 | $CanExport = false;
|
---|
420 | }
|
---|
421 | if (!$this->HaveVarible($DbRow[$Column['Column']],$DbRow['En'.$Column['Column']],'%')) {
|
---|
422 | if ($CanExport) $Output .= ', NE='.$DbRow['ID'];
|
---|
423 | $CanExport = false;
|
---|
424 | }
|
---|
425 | if (!$this->HaveVarible($DbRow[$Column['Column']],$DbRow['En'.$Column['Column']],'\\')) {
|
---|
426 | if ($CanExport) $Output .= ', NE='.$DbRow['ID'];
|
---|
427 | $CanExport = false;
|
---|
428 | }
|
---|
429 | if (!$this->HaveVarible($DbRow['En'.$Column['Column']],$DbRow[$Column['Column']],'\\')) {
|
---|
430 | if ($CanExport) $Output .= ', NE='.$DbRow['ID'];
|
---|
431 | $CanExport = false;
|
---|
432 | }
|
---|
433 | if (!$this->HaveVarible($DbRow[$Column['Column']],$DbRow['En'.$Column['Column']],'|')) {
|
---|
434 | if ($CanExport) $Output .= ', NE='.$DbRow['ID'];
|
---|
435 | $CanExport = false;
|
---|
436 | }
|
---|
437 | if (!$this->HaveVarible($DbRow['En'.$Column['Column']],$DbRow[$Column['Column']],'|')) {
|
---|
438 | if ($CanExport) $Output .= ', NE='.$DbRow['ID'];
|
---|
439 | $CanExport = false;
|
---|
440 | }
|
---|
441 | if (!$this->HaveVarible($DbRow[$Column['Column']],$DbRow['En'.$Column['Column']],chr(10))) {
|
---|
442 | if ($CanExport) $Output .= ', NE='.$DbRow['ID'];
|
---|
443 | $CanExport = false;
|
---|
444 | }
|
---|
445 | if (!$this->HaveVarible($DbRow['En'.$Column['Column']],$DbRow[$Column['Column']],chr(10))) {
|
---|
446 | if ($CanExport) $Output .= ', NE='.$DbRow['ID'];
|
---|
447 | $CanExport = false;
|
---|
448 | }
|
---|
449 | }
|
---|
450 |
|
---|
451 | if ($CanExport)
|
---|
452 | $LookupTable[$DbRow['ShortCut']] = $DbRow;
|
---|
453 | }
|
---|
454 |
|
---|
455 | while(!$File->EOF())
|
---|
456 | {
|
---|
457 | $Line = $File->ReadLine();
|
---|
458 | if(strpos($Line, '=') !== false)
|
---|
459 | {
|
---|
460 | $LineParts = explode('=', $Line, 2);
|
---|
461 | $Value['ShortCut'] = trim($LineParts[0]);
|
---|
462 | $Line = trim($LineParts[1]);
|
---|
463 |
|
---|
464 | if($Line[0] == '"')
|
---|
465 | {
|
---|
466 | // Quoted string value
|
---|
467 | $Line = substr($Line, 1); // Skip start qoute
|
---|
468 | $TempLine = str_replace('\"', ' ', $Line); // Temporary remove slashed quotes
|
---|
469 | if (strpos($TempLine, '"')) {
|
---|
470 | $Value['Text'] = substr($Line, 0, strpos($TempLine, '"'));
|
---|
471 | } else {
|
---|
472 | $Value['Text'] = substr($Line, 0, strpos($Line, '"'));
|
---|
473 | }
|
---|
474 | // $Value['Text'] = str_replace('\n', "\n", $Value['Text']);
|
---|
475 | // $Value['Text'] = addslashes(stripslashes($Value['Text']));
|
---|
476 | $Line = trim(substr($Line, strpos($TempLine, '"') + 1)); // Skip closing quote and semicolon {
|
---|
477 | } else
|
---|
478 | {
|
---|
479 | // Nonstring value
|
---|
480 | $Value['Text'] = substr($Line, 0, strpos($Line, ';'));
|
---|
481 | }
|
---|
482 | $Line = substr($Line, strpos($Line, ';') + 1);
|
---|
483 | $Value['Comment'] = addslashes(stripslashes(substr($Line, 3))); // Skip " --"
|
---|
484 |
|
---|
485 | if(array_key_exists($Value['ShortCut'], $LookupTable))
|
---|
486 | {
|
---|
487 | $DbRow = $LookupTable[$Value['ShortCut']];
|
---|
488 | $Value['Text'] = $DbRow['Text'];
|
---|
489 | //addslashes
|
---|
490 | $Value['Text'] = str_replace('"', '\"', $Value['Text']);
|
---|
491 | // Escape new line control characters
|
---|
492 | $Value['Text'] = str_replace("\n", '\n', $Value['Text']);
|
---|
493 | $Value['Text'] = str_replace("\r", '', $Value['Text']);
|
---|
494 | $Value['Comment'] = $DbRow['Comment'];
|
---|
495 | // Only one line comments allowed
|
---|
496 | $Value['Comment'] = str_replace("\n", ' ', $Value['Comment']);
|
---|
497 | $Value['Comment'] = str_replace("\r", '', $Value['Comment']);
|
---|
498 | //echo('.');
|
---|
499 | }
|
---|
500 | $NewLine = $Value['ShortCut'].' = "'.$Value['Text'].'";';
|
---|
501 | //if($Value['Comment'] != '') $NewLine .= ' -- '.$Value['Comment'];
|
---|
502 | $NewLine .= "\r\n";
|
---|
503 | $File2->WriteLine($NewLine);
|
---|
504 | } else $File2->WriteLine($Line);
|
---|
505 | }
|
---|
506 | $Output .= 'Hotovo <br/>';
|
---|
507 | }
|
---|
508 | return($Output);
|
---|
509 | }
|
---|
510 |
|
---|
511 | function ExportToXML()
|
---|
512 | {
|
---|
513 | global $TranslationTree;
|
---|
514 |
|
---|
515 | $this->LoadFilters();
|
---|
516 |
|
---|
517 | $Buffer = '<?xml version="1.0" encoding="utf-8"?>'."\n".
|
---|
518 | "<document>\n".
|
---|
519 | " <meta>\n".
|
---|
520 | " <projecturl>".$this->Config['Web']['Host'].$this->System->Link('/')."</projecturl>\n".
|
---|
521 | " <time>".date('r')."</time>\n".
|
---|
522 | " <diacritics mode=".'"'.$this->Export['WithDiacritic'].'"'." />\n".
|
---|
523 | " <author>".$this->System->User->Name."</author>\n".
|
---|
524 | " <contributors>\n";
|
---|
525 | foreach(explode(',', $this->UserNames) as $UserName)
|
---|
526 | $Buffer .= " <user>".$UserName."</user>\n";
|
---|
527 | $Buffer .=
|
---|
528 | " </contributors>\n".
|
---|
529 | " </meta>\n".
|
---|
530 | " <translation>\n";
|
---|
531 |
|
---|
532 | $DbResult = $this->Database->query('SELECT `Group`.* FROM `ExportGroup` '.
|
---|
533 | 'JOIN `Group` ON `Group`.`Id` = `ExportGroup`.`Group` WHERE `ExportGroup`.`Export`='.$this->Id);
|
---|
534 | while($Group = $DbResult->fetch_assoc())
|
---|
535 | {
|
---|
536 | if($Group['MangosTable'] == '')
|
---|
537 | {
|
---|
538 | $Group['MangosTable'] = $Group['TablePrefix'];
|
---|
539 | $Group['MangosTableIndex'] = 'entry';
|
---|
540 | }
|
---|
541 | $Buffer .= ' <group id="'.$Group['Id'].'" name="'.$Group['TablePrefix'].'">'."\n";
|
---|
542 | $DbResult2 = $this->Database->query($this->BuildQuery($Group));
|
---|
543 | while($Line = $DbResult2->fetch_assoc())
|
---|
544 | {
|
---|
545 | $Buffer .= ' <item id="'.$Line['Entry'].'" user="'.$Line['UserName'].'">'."\n";
|
---|
546 | $Values = '';
|
---|
547 | foreach($TranslationTree[$Group['Id']]['Items'] as $GroupItem)
|
---|
548 | {
|
---|
549 | if($GroupItem['MangosColumn'] == '') $GroupItem['MangosColumn'] = $GroupItem['Column'];
|
---|
550 | if($Line[$GroupItem['Column']] != '')
|
---|
551 | $Buffer .= ' <text index="'.$GroupItem['Id'].'" name="'.
|
---|
552 | $GroupItem['Column'].'">'.addslashes($Line[$GroupItem['Column']]).'</text>'."\n";
|
---|
553 | }
|
---|
554 | $Buffer .= " </item>\n";
|
---|
555 | }
|
---|
556 | $Buffer .= " </group>\n";
|
---|
557 | }
|
---|
558 | if($this->Export['WithDiacritic'] != 1) $Buffer = utf2ascii($Buffer);
|
---|
559 | $Buffer .= " </translation>\n".
|
---|
560 | "</document>";
|
---|
561 | return($Buffer);
|
---|
562 | }
|
---|
563 | }
|
---|
564 |
|
---|
565 | include_once(dirname(__FILE__).'/Page.php');
|
---|
566 | include_once(dirname(__FILE__).'/ExportOutput.php');
|
---|
567 |
|
---|
568 | class ModuleExport extends AppModule
|
---|
569 | {
|
---|
570 | function __construct($System)
|
---|
571 | {
|
---|
572 | parent::__construct($System);
|
---|
573 | $this->Name = 'Export';
|
---|
574 | $this->Version = '1.0';
|
---|
575 | $this->Creator = 'Chronos';
|
---|
576 | $this->License = 'GNU/GPL';
|
---|
577 | $this->Description = 'Allow parametric export of translated texts to various supported output formats';
|
---|
578 | $this->Dependencies = array();
|
---|
579 | }
|
---|
580 |
|
---|
581 | function Start()
|
---|
582 | {
|
---|
583 | $this->System->RegisterPage('export', 'PageExport');
|
---|
584 | $this->System->RegisterMenuItem(array(
|
---|
585 | 'Title' => 'Exporty',
|
---|
586 | 'Hint' => 'Zde si můžete stáhnout přeložené texty',
|
---|
587 | 'Link' => $this->System->Link('/export/'),
|
---|
588 | 'Permission' => LICENCE_ANONYMOUS,
|
---|
589 | 'Icon' => '',
|
---|
590 | ), 2);
|
---|
591 | }
|
---|
592 | }
|
---|
593 |
|
---|