Changeset 663 for trunk/Modules/Export/Export.php
- Timestamp:
- Dec 22, 2013, 12:09:24 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/Export/Export.php
r662 r663 227 227 228 228 229 230 function HaveVarible($String1, $String2, $StartChar = '$') 231 { 232 //Export only if translate have same varible % 233 234 if (strpos($String1,$StartChar)) { 235 while (strpos($String1,$StartChar)) { 236 $String1 = substr($String1,strpos($String1,$StartChar)); 237 $varible = $String1; 238 if (strpos($varible,' ')) $varible = substr($varible,0,strpos($varible,' ')); 239 if (strpos($varible,'.')) $varible = substr($varible,0,strpos($varible,'.')); 240 if (strpos($varible,',')) $varible = substr($varible,0,strpos($varible,',')); 241 if (strpos($varible,'%')) $varible = substr($varible,0,strpos($varible,'%')); 242 if (strpos($varible,chr(10))) $varible = substr($varible,0,strpos($varible,chr(10))); 243 244 if (false == strpos($String2,$varible)) { 245 // echo $varible; 246 return(false); 247 } 248 } 249 } 250 return (true); 251 } 252 253 function ExportToDBC() 254 { 255 global $TranslationTree; 256 257 $this->LoadFilters(); 258 259 $DbResult = $this->Database->query('SELECT `Group`.* FROM `ExportGroup` '. 260 'JOIN `Group` ON `Group`.`Id` = `ExportGroup`.`Group` '. 261 'WHERE `ExportGroup`.`Export`='.$this->Id.' AND `Group`.`DBCFileName` != ""'); 262 $Output = 'Počet generovaných skupin: '.$DbResult->num_rows."\n"; 263 while($Group = $DbResult->fetch_assoc()) 264 { 265 $Output .= $Group['Name'].', '; 266 if(file_exists($this->SourceDir.$this->ClientVersion['Version'].'/dbc/'.$Group['DBCFileName'].'.dbc')) 267 { 268 // Load string column index list 269 $DbResult2 = $this->Database->query('SELECT * FROM `GroupItem` '. 270 'JOIN `GroupItemDBC` ON `GroupItem`.`Id` = `GroupItemDBC`.`GroupItem` AND `GroupItemDBC`.`ClientVersion` = '.$this->ClientVersion['Id'].' WHERE `GroupItem`.`Group` = '.$Group['Id']); 271 $ColumnIndexes = array(); 272 $ColumnFormat = array(); 273 while($DbRow = $DbResult2->fetch_assoc()) 274 { 275 $ColumnFormat[$DbRow['ColumnIndex']] = FORMAT_STRING; 276 $ColumnIndexes[$DbRow['GroupItem']] = $DbRow['ColumnIndex']; 277 } 278 279 // Load all data into lookup table 280 $LookupTable = array(); 281 $DbResult2 = $this->Database->query($this->BuildQuery($Group)); 282 while($DbRow = $DbResult2->fetch_assoc()) { 283 //Export only if translate have same varible % 284 $CanExport = true; 285 foreach($TranslationTree[$Group['Id']]['Items'] as $Column) { 286 $DbRow[$Column['Column']] = str_replace ( '$ ','$',$DbRow[$Column['Column']]); 287 if (!$this->HaveVarible($DbRow['En'.$Column['Column']],$DbRow[$Column['Column']])) { 288 $CanExport = false; 289 $Output .= ', NE='.$DbRow['ID']; 290 } 291 if (!$this->HaveVarible($DbRow[$Column['Column']],$DbRow['En'.$Column['Column']])) { 292 $CanExport = false; 293 $Output .= ', NE='.$DbRow['ID']; 294 } 295 } 296 297 if ($CanExport) 298 $LookupTable[$DbRow[$Group['PrimaryKeyItem']]] = $DbRow; 299 300 } 301 302 // Open original DBC file 303 $SourceDBCFile = new DBCFile(); 304 $SourceDBCFile->OpenFile($this->SourceDir.$this->ClientVersion['Version'].'/dbc/'.$Group['DBCFileName'].'.dbc', $ColumnFormat); 305 306 // Create new DBC file 307 if(!file_exists($this->TempDir.'dbc/')) mkdir ($this->TempDir.'dbc/', 0777, true); 308 $NewDBCFile = new DBCFile(); 309 $NewDBCFile->CreateFile($this->TempDir.'dbc/'.$Group['DBCFileName'].'.dbc', $ColumnFormat); 310 $NewDBCFile->SetRecordCount($SourceDBCFile->GetRecordCount()); 311 $NewDBCFile->SetFieldCount($SourceDBCFile->GetFieldCount()); 312 $NewDBCFile->Commit(); 313 314 // Replace translated strings 315 $OldProgress = -1; 316 $Output .= "\n\r"; 317 $RowCount = $SourceDBCFile->GetRecordCount(); 318 $FieldCount = $SourceDBCFile->GetFieldCount(); 319 for($Row = 0; $Row < $RowCount; $Row++) 320 { 321 $Line = $SourceDBCFile->GetLine($Row); 322 323 // Get multicolumn index value 324 $PrimaryKeyItem = ''; 325 $ColumnItems = explode(',', $Group['DBCIndex']); 326 if(count($ColumnItems) > 1) 327 { 328 foreach($ColumnItems as $ColumnItem) 329 $PrimaryKeyItem .= $Line[$ColumnItem].'_'; 330 $PrimaryKeyItem = substr($PrimaryKeyItem, 0, -1); 331 } else $PrimaryKeyItem = $Line[$Group['DBCIndex']]; 332 333 if(array_key_exists($PrimaryKeyItem, $LookupTable)) 334 { 335 // Replace text columns 336 $LookupTableItem = $LookupTable[$PrimaryKeyItem]; 337 foreach($TranslationTree[$Group['Id']]['Items'] as $GroupItem) 338 { 339 if(array_key_exists($GroupItem['Id'], $ColumnIndexes)) 340 $Line[$ColumnIndexes[$GroupItem['Id']]] = $LookupTableItem[$GroupItem['Column']]; 341 } 342 } 343 $NewDBCFile->SetLine($Row, $Line); 344 345 // Show completion progress 346 $Progress = round($Row / $RowCount * 100); 347 if($Progress != $OldProgress) 348 { 349 $Output .= $Progress."%\r"; 350 echo($Output); 351 $Output = ''; 352 $OldProgress = $Progress; 353 } 354 } 355 $NewDBCFile->Commit(); 356 } else $Output .= ShowMessage('Zdrojový soubor '.$this->SourceDirRelative.$this->ClientVersion['Version'].'/dbc/'.$Group['DBCFileName'].'.dbc'.' nenalezen.'."\n", MESSAGE_CRITICAL); 357 } 358 $Output .= 'Hotovo <br />'; 359 return($Output); 360 } 361 362 function ExportToLua() 363 { 364 global $TranslationTree; 365 366 $this->LoadFilters(); 367 368 $Output = ''; 369 if(!file_exists($this->TempDir.'lua/')) mkdir($this->TempDir.'lua/', 0777, true); 370 $DbResult = $this->Database->query('SELECT `Group`.* FROM `ExportGroup` JOIN `Group` ON `Group`.`Id` = `ExportGroup`.`Group` WHERE `ExportGroup`.`Export`='.$this->Id.' AND `Group`.`LuaFileName` != ""'); 371 while($Group = $DbResult->fetch_assoc()) 372 { 373 $Output .= $Group['Name'].'... '; 374 $File = new FileStream(); 375 $File->OpenFile($this->SourceDir.$this->ClientVersion['Version'].'/lua/'.$Group['LuaFileName'].'.lua'); 376 $File2 = new FileStream(); 377 $File2->CreateFile($this->TempDir.'lua/'.$Group['LuaFileName'].'.lua'); 378 379 $LookupTable = array(); 380 $DbResult2 = $this->Database->query($this->BuildQuery($Group)); 381 while($DbRow = $DbResult2->fetch_assoc()) { 382 $CanExport = true; 383 foreach($TranslationTree[$Group['Id']]['Items'] as $Column) { 384 $DbRow[$Column['Column']] = str_replace ( '$ ','$',$DbRow[$Column['Column']]); 385 // echo $DbRow[$Column['Column']].' - '.$DbRow['En'.$Column['Column']].' 386 //'; 387 if (!$this->HaveVarible($DbRow['En'.$Column['Column']],$DbRow[$Column['Column']])) { 388 $CanExport = false; 389 $Output .= ', NE='.$DbRow['ID']; 390 } 391 if (!$this->HaveVarible($DbRow[$Column['Column']],$DbRow['En'.$Column['Column']])) { 392 $CanExport = false; 393 $Output .= ', NE='.$DbRow['ID']; 394 } 395 if (!$this->HaveVarible($DbRow['En'.$Column['Column']],$DbRow[$Column['Column']],'%')) { 396 $CanExport = false; 397 $Output .= ', NE='.$DbRow['ID']; 398 } 399 if (!$this->HaveVarible($DbRow[$Column['Column']],$DbRow['En'.$Column['Column']],'%')) { 400 $CanExport = false; 401 $Output .= ', NE='.$DbRow['ID']; 402 } 403 if (!$this->HaveVarible($DbRow[$Column['Column']],$DbRow['En'.$Column['Column']],'\\')) { 404 $CanExport = false; 405 $Output .= ', NE='.$DbRow['ID']; 406 } 407 if (!$this->HaveVarible($DbRow[$Column['Column']],$DbRow['En'.$Column['Column']],'\\')) { 408 $CanExport = false; 409 $Output .= ', NE='.$DbRow['ID']; 410 } 411 } 412 413 414 if ($CanExport) 415 $LookupTable[$DbRow['ShortCut']] = $DbRow; 416 } 417 418 while(!$File->EOF()) 419 { 420 $Line = $File->ReadLine(); 421 if(strpos($Line, '=') !== false) 422 { 423 $LineParts = explode('=', $Line, 2); 424 $Value['ShortCut'] = trim($LineParts[0]); 425 $Line = trim($LineParts[1]); 426 427 if($Line[0] == '"') 428 { 429 // Quoted string value 430 $Line = substr($Line, 1); // Skip start qoute 431 $TempLine = str_replace('\"', ' ', $Line); // Temporary remove slashed quotes 432 if (strpos($TempLine, '"')) { 433 $Value['Text'] = substr($Line, 0, strpos($TempLine, '"')); 434 } else { 435 $Value['Text'] = substr($Line, 0, strpos($Line, '"')); 436 } 437 // $Value['Text'] = str_replace('\n', "\n", $Value['Text']); 438 // $Value['Text'] = addslashes(stripslashes($Value['Text'])); 439 $Line = trim(substr($Line, strpos($TempLine, '"') + 1)); // Skip closing quote and semicolon { 440 } else 441 { 442 // Nonstring value 443 $Value['Text'] = substr($Line, 0, strpos($Line, ';')); 444 } 445 $Line = substr($Line, strpos($Line, ';') + 1); 446 $Value['Comment'] = addslashes(stripslashes(substr($Line, 3))); // Skip " --" 447 448 if(array_key_exists($Value['ShortCut'], $LookupTable)) 449 { 450 $DbRow = $LookupTable[$Value['ShortCut']]; 451 $Value['Text'] = $DbRow['Text']; 452 //addslashes 453 $Value['Text'] = str_replace('"', '\"', $Value['Text']); 454 // Escape new line control characters 455 $Value['Text'] = str_replace("\n", '\n', $Value['Text']); 456 $Value['Text'] = str_replace("\r", '', $Value['Text']); 457 $Value['Comment'] = $DbRow['Comment']; 458 // Only one line comments allowed 459 $Value['Comment'] = str_replace("\n", ' ', $Value['Comment']); 460 $Value['Comment'] = str_replace("\r", '', $Value['Comment']); 461 //echo('.'); 462 } 463 $NewLine = $Value['ShortCut'].' = "'.$Value['Text'].'";'; 464 //if($Value['Comment'] != '') $NewLine .= ' -- '.$Value['Comment']; 465 $NewLine .= "\r\n"; 466 $File2->WriteLine($NewLine); 467 } else $File2->WriteLine($Line); 468 } 469 $Output .= 'Hotovo <br/>'; 470 } 471 return($Output); 472 } 473 229 474 function ExportToXML() 230 475 { … … 279 524 return($Buffer); 280 525 } 281 282 function HaveVarible($String1, $String2, $StartChar = '$')283 {284 //Export only if translate have same varible %285 if (strpos($String1,$StartChar)) {286 while (strpos($String1,$StartChar)) {287 $String1 = substr($String1,strpos($String1,$StartChar));288 $varible = $String1;289 if (strpos($varible,' ')) $varible = substr($varible,0,strpos($varible,' '));290 if (strpos($varible,'.')) $varible = substr($varible,0,strpos($varible,'.'));291 if (strpos($varible,',')) $varible = substr($varible,0,strpos($varible,','));292 if (strpos($varible,'%')) $varible = substr($varible,0,strpos($varible,'%'));293 if (strpos($varible,chr(10))) $varible = substr($varible,0,strpos($varible,chr(10)));294 if (false == strpos($String2,$varible)) {295 // echo $varible;296 297 return(false);298 }299 }300 }301 return (true);302 }303 304 function ExportToDBC()305 {306 global $TranslationTree;307 308 $this->LoadFilters();309 310 $DbResult = $this->Database->query('SELECT `Group`.* FROM `ExportGroup` '.311 'JOIN `Group` ON `Group`.`Id` = `ExportGroup`.`Group` '.312 'WHERE `ExportGroup`.`Export`='.$this->Id.' AND `Group`.`DBCFileName` != ""');313 $Output = 'Počet generovaných skupin: '.$DbResult->num_rows."\n";314 while($Group = $DbResult->fetch_assoc())315 {316 $Output .= $Group['Name'].', ';317 if(file_exists($this->SourceDir.$this->ClientVersion['Version'].'/dbc/'.$Group['DBCFileName'].'.dbc'))318 {319 // Load string column index list320 $DbResult2 = $this->Database->query('SELECT * FROM `GroupItem` '.321 'JOIN `GroupItemDBC` ON `GroupItem`.`Id` = `GroupItemDBC`.`GroupItem` AND `GroupItemDBC`.`ClientVersion` = '.$this->ClientVersion['Id'].' WHERE `GroupItem`.`Group` = '.$Group['Id']);322 $ColumnIndexes = array();323 $ColumnFormat = array();324 while($DbRow = $DbResult2->fetch_assoc())325 {326 $ColumnFormat[$DbRow['ColumnIndex']] = FORMAT_STRING;327 $ColumnIndexes[$DbRow['GroupItem']] = $DbRow['ColumnIndex'];328 }329 330 // Load all data into lookup table331 $LookupTable = array();332 $DbResult2 = $this->Database->query($this->BuildQuery($Group));333 while($DbRow = $DbResult2->fetch_assoc()) {334 //Export only if translate have same varible %335 $CanExport = true;336 foreach($TranslationTree[$Group['Id']]['Items'] as $Column) {337 $DbRow[$Column['Column']] = str_replace ( '$ ','$',$DbRow[$Column['Column']]);338 if (!$this->HaveVarible($DbRow['En'.$Column['Column']],$DbRow[$Column['Column']])) {339 $CanExport = false;340 $Output .= ', NE='.$DbRow['ID'];341 }342 if (!$this->HaveVarible($DbRow[$Column['Column']],$DbRow['En'.$Column['Column']])) {343 $CanExport = false;344 $Output .= ', NE='.$DbRow['ID'];345 }346 }347 348 if ($CanExport)349 $LookupTable[$DbRow[$Group['PrimaryKeyItem']]] = $DbRow;350 351 }352 353 // Open original DBC file354 $SourceDBCFile = new DBCFile();355 $SourceDBCFile->OpenFile($this->SourceDir.$this->ClientVersion['Version'].'/dbc/'.$Group['DBCFileName'].'.dbc', $ColumnFormat);356 357 // Create new DBC file358 if(!file_exists($this->TempDir.'dbc/')) mkdir ($this->TempDir.'dbc/', 0777, true);359 $NewDBCFile = new DBCFile();360 $NewDBCFile->CreateFile($this->TempDir.'dbc/'.$Group['DBCFileName'].'.dbc', $ColumnFormat);361 $NewDBCFile->SetRecordCount($SourceDBCFile->GetRecordCount());362 $NewDBCFile->SetFieldCount($SourceDBCFile->GetFieldCount());363 $NewDBCFile->Commit();364 365 // Replace translated strings366 $OldProgress = -1;367 $Output .= "\n\r";368 $RowCount = $SourceDBCFile->GetRecordCount();369 $FieldCount = $SourceDBCFile->GetFieldCount();370 for($Row = 0; $Row < $RowCount; $Row++)371 {372 $Line = $SourceDBCFile->GetLine($Row);373 374 // Get multicolumn index value375 $PrimaryKeyItem = '';376 $ColumnItems = explode(',', $Group['DBCIndex']);377 if(count($ColumnItems) > 1)378 {379 foreach($ColumnItems as $ColumnItem)380 $PrimaryKeyItem .= $Line[$ColumnItem].'_';381 $PrimaryKeyItem = substr($PrimaryKeyItem, 0, -1);382 } else $PrimaryKeyItem = $Line[$Group['DBCIndex']];383 384 if(array_key_exists($PrimaryKeyItem, $LookupTable))385 {386 // Replace text columns387 $LookupTableItem = $LookupTable[$PrimaryKeyItem];388 foreach($TranslationTree[$Group['Id']]['Items'] as $GroupItem)389 {390 if(array_key_exists($GroupItem['Id'], $ColumnIndexes))391 $Line[$ColumnIndexes[$GroupItem['Id']]] = $LookupTableItem[$GroupItem['Column']];392 }393 }394 $NewDBCFile->SetLine($Row, $Line);395 396 // Show completion progress397 $Progress = round($Row / $RowCount * 100);398 if($Progress != $OldProgress)399 {400 $Output .= $Progress."%\r";401 echo($Output);402 $Output = '';403 $OldProgress = $Progress;404 }405 }406 $NewDBCFile->Commit();407 } else $Output .= ShowMessage('Zdrojový soubor '.$this->SourceDirRelative.$this->ClientVersion['Version'].'/dbc/'.$Group['DBCFileName'].'.dbc'.' nenalezen.'."\n", MESSAGE_CRITICAL);408 }409 $Output .= 'Hotovo <br />';410 return($Output);411 }412 413 function ExportToLua()414 {415 global $TranslationTree;416 417 $this->LoadFilters();418 419 $Output = '';420 if(!file_exists($this->TempDir.'lua/')) mkdir($this->TempDir.'lua/', 0777, true);421 $DbResult = $this->Database->query('SELECT `Group`.* FROM `ExportGroup` JOIN `Group` ON `Group`.`Id` = `ExportGroup`.`Group` WHERE `ExportGroup`.`Export`='.$this->Id.' AND `Group`.`LuaFileName` != ""');422 while($Group = $DbResult->fetch_assoc())423 {424 $Output .= $Group['Name'].'... ';425 $File = new FileStream();426 $File->OpenFile($this->SourceDir.$this->ClientVersion['Version'].'/lua/'.$Group['LuaFileName'].'.lua');427 $File2 = new FileStream();428 $File2->CreateFile($this->TempDir.'lua/'.$Group['LuaFileName'].'.lua');429 430 $LookupTable = array();431 $DbResult2 = $this->Database->query($this->BuildQuery($Group));432 while($DbRow = $DbResult2->fetch_assoc()) {433 $CanExport = true;434 foreach($TranslationTree[$Group['Id']]['Items'] as $Column) {435 $DbRow[$Column['Column']] = str_replace ( '$ ','$',$DbRow[$Column['Column']]);436 if (!$this->HaveVarible($DbRow['En'.$Column['Column']],$DbRow[$Column['Column']])) {437 $CanExport = false;438 $Output .= ', NE='.$DbRow['ID'];439 }440 if (!$this->HaveVarible($DbRow[$Column['Column']],$DbRow['En'.$Column['Column']])) {441 $CanExport = false;442 $Output .= ', NE='.$DbRow['ID'];443 }444 if (!$this->HaveVarible($DbRow['En'.$Column['Column']],$DbRow[$Column['Column']],'%')) {445 $CanExport = false;446 $Output .= ', NE='.$DbRow['ID'];447 }448 if (!$this->HaveVarible($DbRow[$Column['Column']],$DbRow['En'.$Column['Column']],'%')) {449 $CanExport = false;450 $Output .= ', NE='.$DbRow['ID'];451 }452 }453 454 if ($CanExport)455 $LookupTable[$DbRow['ShortCut']] = $DbRow;456 }457 458 while(!$File->EOF())459 {460 $Line = $File->ReadLine();461 if(strpos($Line, '=') !== false)462 {463 $LineParts = explode('=', $Line, 2);464 $Value['ShortCut'] = trim($LineParts[0]);465 $Line = trim($LineParts[1]);466 if($Line[0] == '"')467 {468 // Quoted string value469 $Line = substr($Line, 1); // Skip start qoute470 $TempLine = str_replace('\"', ' ', $Line); // Temporary remove slashed quotes471 $Value['Text'] = substr($Line, 0, strpos($TempLine, '"'));472 // $Value['Text'] = str_replace('\n', "\n", $Value['Text']);473 // $Value['Text'] = addslashes(stripslashes($Value['Text']));474 $Line = trim(substr($Line, strpos($TempLine, '"') + 1)); // Skip closing quote and semicolon {475 } else476 {477 // Nonstring value478 $Value['Text'] = substr($Line, 0, strpos($Line, ';'));479 }480 $Line = substr($Line, strpos($Line, ';') + 1);481 $Value['Comment'] = addslashes(stripslashes(substr($Line, 3))); // Skip " --"482 483 if(array_key_exists($Value['ShortCut'], $LookupTable))484 {485 $DbRow = $LookupTable[$Value['ShortCut']];486 $Value['Text'] = addslashes($DbRow['Text']);487 // Escape new line control characters488 $Value['Text'] = str_replace("\n", '\n', $Value['Text']);489 $Value['Text'] = str_replace("\r", '', $Value['Text']);490 $Value['Comment'] = $DbRow['Comment'];491 // Only one line comments allowed492 $Value['Comment'] = str_replace("\n", ' ', $Value['Comment']);493 $Value['Comment'] = str_replace("\r", '', $Value['Comment']);494 //echo('.');495 }496 $NewLine = $Value['ShortCut'].' = "'.$Value['Text'].'";';497 //if($Value['Comment'] != '') $NewLine .= ' -- '.$Value['Comment'];498 $NewLine .= "\r\n";499 $File2->WriteLine($NewLine);500 } else $File2->WriteLine($Line);501 }502 $Output .= 'Hotovo <br/>';503 }504 return($Output);505 }506 526 } 507 527
Note:
See TracChangeset
for help on using the changeset viewer.