Changeset 290 for trunk/export/export.php
- Timestamp:
- Dec 27, 2009, 1:08:48 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/export/export.php
r264 r290 1 1 <?php 2 2 3 function ExportToMangosSQL($Setting) 3 include_once('../includes/system.php'); 4 5 class Export extends Module 4 6 { 5 global $Database, $Config, $TranslationTree, $LanguageList; 6 7 $AnoNe = array('Ne', 'Ano'); 8 if($_SESSION['UserID'] != '') 9 { 10 $DbResult = $Database->SQLCommand('SELECT user FROM `user` WHERE ID='.$_SESSION['UserID']); 11 $User = mysql_fetch_assoc($DbResult); 12 } else $User = array('user' => 'Neznámý'); 13 14 $WhereLang = ''; 15 foreach($LanguageList as $Language) 16 if($Language['Enabled'] == 1) 17 if(isset($Setting['language'.$Language['Id']])) $WhereLang .= ' OR (Language = '.$Language['Id'].')'; 18 if($WhereLang == '') $WhereLang = 1; 19 else $WhereLang = '('.substr($WhereLang, 4).')'; 20 21 $SelectedUsers = ''; 22 foreach($Setting['users-selection'] as $Item) 23 $SelectedUsers .= ','.$Item; 24 $SelectedUsers = substr($SelectedUsers, 1); 25 26 if($SelectedUsers == '') $Where = 0; 27 else $Where = 'ID IN ('.$SelectedUsers.')'; 28 29 $UserNames = ''; 30 $DbResult = $Database->SQLCommand('SELECT user FROM `user` WHERE '.$Where); 31 while($DbRow = mysql_fetch_assoc($DbResult)) 32 $UserNames .= ','.$DbRow['user']; 33 $UserNames = substr($UserNames, 1); 7 var $Id; 8 var $AnoNe = array('Ne', 'Ano'); 9 var $WhereLang; 10 var $WhereUsers; 11 var $SelectedUsers; 12 var $UserNames; 13 var $User; 14 var $ClientVersion; 15 16 function LoadFilters() 17 { 18 $DbResult = $this->Database->query('SELECT * FROM `Export` WHERE Id='.$this->Id); 19 $this->Export = $DbResult->fetch_assoc(); 20 21 // Filter selected languages 22 $this->WhereLang = ''; 23 $DbResult = $this->Database->query('SELECT * FROM `ExportLanguage` WHERE Export='.$this->Id.' ORDER BY Sequence'); 24 while($Language = $DbResult->fetch_assoc()) 25 $this->WhereLang .= ' OR (Language = '.$Language['Language'].')'; 26 if($this->WhereLang == '') $WhereLang = 1; 27 else $this->WhereLang = '('.substr($this->WhereLang, 4).')'; 28 29 // Filter selected users 30 $this->SelectedUsers = ''; 31 $DbResult = $this->Database->query('SELECT * FROM `ExportUser` WHERE Export='.$this->Id.' ORDER BY Sequence'); 32 while($User = $DbResult->fetch_assoc()) 33 $this->SelectedUsers .= ','.$User['User']; 34 $this->SelectedUsers = substr($this->SelectedUsers, 1); 35 36 if($this->SelectedUsers == '') $Where = 0; 37 else $Where = 'ID IN ('.$this->SelectedUsers.')'; 38 39 $this->UserNames = ''; 40 $DbResult = $this->Database->query('SELECT user FROM `user` WHERE '.$Where); 41 while($DbRow = $DbResult->fetch_assoc()) 42 $this->UserNames .= ','.$DbRow['user']; 43 $this->UserNames = substr($this->UserNames, 1); 34 44 35 if($SelectedUsers == '') $WhereUsers = 1; 36 else $WhereUsers = '(User IN ('.$SelectedUsers.'))'; 37 38 $Buffer = 39 "-- Generováno projektem wowpreklad.zdechov.net\n". 40 "-- ===========================================\n". 41 "--\n". 42 "-- Web projektu: ".$Config['Web']['BaseURL']."\n". 43 "-- Datum exportu: ".date("j.n.Y H:i:s")."\n". 44 "-- Znaková sada: ".$Config['Database']['Charset']." / ".$Config['Web']['Charset']."\n". 45 "-- Diakritika: ".$AnoNe[$Setting['Diacritics']]."\n". 46 "-- Vygeneroval uživatel: ".$User['user']."\n". 47 "-- Vzato od uživatelů: ".$UserNames."\n". 48 "-- Generované tabulky: "; 49 foreach($TranslationTree as $Group) 50 if($Group['MangosTable'] != '') 51 if(in_array($Group['Id'], $Setting['groups'])) 52 $Buffer .= $Group['MangosTable'].', '; 53 $Buffer .= "\n\n"; 54 55 foreach($TranslationTree as $Group) 56 if(in_array($Group['Id'], $Setting['groups'])) 57 { 58 if($Group['MangosTable'] != '') 59 { 60 $Query = 'SELECT * FROM (SELECT * FROM '.$Group['TablePrefix'].' WHERE (Complete = 1) AND VersionStart <= '.GetBuildNumber($Setting['Version']).' AND VersionEnd >= '.GetBuildNumber($Setting['Version']).' AND '.$WhereLang.' AND '.$WhereUsers.' ORDER BY FIELD(User, '.$SelectedUsers.')) AS T GROUP BY T.entry'; 45 if($this->SelectedUsers == '') $WhereUsers = 1; 46 else $this->WhereUsers = '(User IN ('.$this->SelectedUsers.'))'; 47 48 if($_SESSION['UserID'] != '') 49 { 50 $DbResult = $this->Database->query('SELECT user FROM `user` WHERE ID='.$_SESSION['UserID']); 51 $this->User = $DbResult->fetch_assoc(); 52 } else $this->User = array('user' => 'Neznámý'); 53 54 $DbResult = $this->Database->query('SELECT `BuildNumber` FROM `wow_client_version` WHERE `Id`='.$this->Export['ClientVersion']); 55 $DbRow = $DbResult->fetch_assoc(); 56 $this->ClientVersion = $DbRow['BuildNumber']; 57 } 58 59 function ExportToMangosSQL() 60 { 61 global $TranslationTree, $LanguageList; 62 63 $this->LoadFilters(); 64 65 $Buffer = 66 "-- Generováno projektem wowpreklad.zdechov.net\n". 67 "-- ===========================================\n". 68 "--\n". 69 "-- Web projektu: ".$this->Config['Web']['BaseURL']."\n". 70 "-- Datum exportu: ".date("j.n.Y H:i:s")."\n". 71 "-- Znaková sada: ".$this->Config['Database']['Charset']." / ".$this->Config['Web']['Charset']."\n". 72 "-- Diakritika: ".$this->AnoNe[$this->Export['WithDiacritic']]."\n". 73 "-- Vygeneroval uživatel: ".$this->User['user']."\n". 74 "-- Vzato od uživatelů: ".$this->UserNames."\n". 75 "-- Generované tabulky: "; 76 77 $DbResult = $this->Database->query('SELECT `group`.* FROM `ExportGroup` JOIN `group` ON `group`.`Id` = `ExportGroup`.`Group` WHERE `ExportGroup`.`Export`='.$this->Id); 78 while($Group = $DbResult->fetch_assoc()) 79 { 80 $Buffer .= $Group['MangosTable'].', '; 81 } 82 $Buffer .= "\n\n"; 83 84 $DbResult = $this->Database->query('SELECT `group`.* FROM `ExportGroup` JOIN `group` ON `group`.`Id` = `ExportGroup`.`Group` WHERE `ExportGroup`.`Export`='.$this->Id); 85 while($Group = $DbResult->fetch_assoc()) 86 { 87 if($Group['MangosTable'] != '') 88 { 89 $Query = 'SELECT * FROM (SELECT * FROM '.$Group['TablePrefix'].' WHERE (Complete = 1) AND VersionStart <= '.$this->ClientVersion.' AND VersionEnd >= '.$this->ClientVersion.' AND '.$this->WhereLang.' AND '.$this->WhereUsers.' ORDER BY FIELD(User, '.$this->SelectedUsers.')) AS T GROUP BY T.entry'; 90 //echo($Query); 91 $Buffer .= "\n\n-- ".$Group['Name']."\n\n"; 92 $DbResult2 = $this->Database->query($Query); 93 while($Line = $DbResult2->fetch_array()) 94 { 95 $Values = ''; 96 foreach($TranslationTree[$Group['Id']]['Items'] as $GroupItem) 97 { 98 if($GroupItem['MangosColumn'] == '') $GroupItem['MangosColumn'] = $GroupItem['Column']; 99 $Values .= ', `'.$GroupItem['MangosColumn'].'`="'.addslashes($Line[$GroupItem['Column']]).'"'; 100 } 101 $Values = substr($Values, 2); 102 $Buffer .= 'UPDATE `'.$Group['MangosTable'].'` SET '.$Values.' WHERE `'.$Group['MangosTableIndex'].'` = '.$Line['entry'].';'."\n"; 103 } 104 } 105 } 106 if($this->Export['WithDiacritic'] != 1) $Buffer = utf2ascii($Buffer); 107 return($Buffer); 108 } 109 110 function ExportToAoWoWSQL() 111 { 112 global $Config, $TranslationTree, $AoWoWconf, $LanguageList; 113 114 require_once('../aowow/configs/config.php'); 115 116 $Buffer = $this->ExportToMangosSQL(); 117 118 $this->LoadFilters(); 119 120 // Data to aowow 121 122 $Database2 = new mysqli($this->Config['Database']['Host'], $this->Config['Database']['User'], $this->Config['Database']['Password'], $this->Config['Database']['Database']); 123 $Database2->query('SET NAMES '.$this->Config['Database']['Charset']); 124 $Database2->select_db($AoWoWconf['mangos']['db']); 125 $AoWoWTables = array('aowow_resistances' => 'Id', 'aowow_spelldispeltype' => 'Id', 'aowow_skill' => 'skillID'); 126 foreach($AoWoWTables as $AoWoWTable => $IndexColum) 127 { 128 $Buffer .= '--'.$AoWoWTable.', '; 129 $Buffer .= "\n\n"; 130 $Query = 'SELECT name,'.$IndexColum.' FROM '.$AoWoWTable; 131 $DbResult = $Database2->query($Query); 132 while($Line = $DbResult->fetch_assoc()) 133 { 134 $Ori_text = $Line['name']; 135 $DbResult2 = $Datbase2->query('SELECT text as en, 136 (SELECT text FROM '.$Config['Database']['Database'].'.global_strings as tabletran 137 WHERE tableen.entry = tabletran.entry AND (Complete = 1) AND '.$WhereLang.' 138 AND '.$WhereUsers.' ORDER BY FIELD(User, '.$SelectedUsers.') LIMIT 1) as tran 139 FROM '.$Config['Database']['Database'].'.global_strings as tableen WHERE 140 text = "'.addslashes($Ori_text).'" LIMIT 1'); 141 $Tran = $DbResult2->fetch_assoc(); 142 //echo ($Line['name'].'='.$Tran['tran']); 143 if($Tran['tran'] == '') 144 { 145 $DbResult2 = $Database2->query('SELECT OptionText as en, 146 (SELECT OptionText FROM '.$this->Config['Database']['Database'].'.npc_option as tabletran 147 WHERE tableen.entry = tabletran.entry AND (Complete = 1) AND '.$this->WhereLang.' 148 AND '.$this->WhereUsers.' ORDER BY FIELD(User, '.$this->SelectedUsers.') LIMIT 1) as tran 149 FROM '.$this->Config['Database']['Database'].'.npc_option as tableen WHERE 150 OptionText = "'.addslashes($Ori_text).'" LIMIT 1'); 151 $Tran = $DbResult2->fetch_assoc(); 152 } 153 154 if($Tran['tran'] <> '') 155 $Buffer .= 'UPDATE `'.$AoWoWTable.'` SET name = "'.addslashes($Tran['tran']).'" WHERE '.$IndexColum.' = '.$Line[$IndexColum].' ;'."\n"; 156 } 157 $Buffer .= "\n\n"; 158 } 159 if($this->Export['WithDiacritic'] != 1) $Buffer = utf2ascii($Buffer); 160 return($Buffer); 161 } 162 163 164 function ExportToXML() 165 { 166 global $TranslationTree, $LanguageList; 167 168 $this->LoadFilters($this->Id); 169 170 $Buffer = '<?xml version="1.0" encoding="utf-8"?>'."\n". 171 "<document>\n". 172 " <meta>\n". 173 " <projecturl>".$this->Config['Web']['BaseURL']."</projecturl>\n". 174 " <time>".date('r')."</time>\n". 175 " <diacritics mode=".'"'.$this->Export['WithDiacritic'].'"'." />\n". 176 " <author>".$this->User['user']."</author>\n". 177 " <contributors>\n"; 178 foreach(explode(',', $this->UserNames) as $UserName) 179 $Buffer .= " <user>".$UserName."</user>\n"; 180 $Buffer .= 181 " </contributors>\n". 182 " </meta>\n". 183 " <translation>\n"; 184 185 $DbResult = $this->Database->query('SELECT `group`.* FROM `ExportGroup` JOIN `group` ON `group`.`Id` = `ExportGroup`.`Group` WHERE `ExportGroup`.`Export`='.$this->Id); 186 while($Group = $DbResult->fetch_assoc()) 187 { 188 if($Group['MangosTable'] == '') 189 { 190 $Group['MangosTable'] = $Group['TablePrefix']; 191 $Group['MangosTableIndex'] = 'entry'; 192 } 193 $Query = 'SELECT *,(SELECT user FROM user WHERE user.ID=T.User) as UserName FROM (SELECT * FROM '.$Group['TablePrefix'].' WHERE (Complete = 1) AND VersionStart <= '.$this->ClientVersion.' AND VersionEnd >= '.$this->ClientVersion.' AND '.$this->WhereLang.' AND '.$this->WhereUsers.' ORDER BY FIELD(User, '.$this->SelectedUsers.')) AS T GROUP BY T.entry'; 61 194 //echo($Query); 62 $Buffer .= "\n\n-- ".$Group['Name']."\n\n"; 63 $ID = $Database->SQLCommand($Query); 64 while($Line = mysql_fetch_array($ID)) 65 { 66 $Values = ''; 67 foreach($Group['Items'] as $GroupItem) 68 { 69 if($GroupItem['MangosColumn'] == '') $GroupItem['MangosColumn'] = $GroupItem['Column']; 70 $Values .= ', `'.$GroupItem['MangosColumn'].'`="'.addslashes($Line[$GroupItem['Column']]).'"'; 71 } 72 $Values = substr($Values, 2); 73 $Buffer .= 'UPDATE `'.$Group['MangosTable'].'` SET '.$Values.' WHERE `'.$Group['MangosTableIndex'].'` = '.$Line['entry'].';'."\n"; 74 } 75 } 195 $Buffer .= ' <group id="'.$Group['Id'].'" name="'.$Group['TablePrefix'].'">'."\n"; 196 $DbResult2 = $this->Database->query($Query); 197 while($Line = $DbResult2->fetch_assoc()) 198 { 199 $Buffer .= ' <item id="'.$Line['entry'].'" user="'.$Line['UserName'].'">'."\n"; 200 $Values = ''; 201 foreach($TranslationTree[$Group['Id']]['Items'] as $GroupItem) 202 { 203 if($GroupItem['MangosColumn'] == '') $GroupItem['MangosColumn'] = $GroupItem['Column']; 204 if($Line[$GroupItem['Column']] != '') 205 $Buffer .= ' <text index="'.$GroupItem['Id'].'" name="'.$GroupItem['Column'].'">'.addslashes($Line[$GroupItem['Column']]).'</text>'."\n"; 206 } 207 $Buffer .= " </item>\n"; 208 } 209 $Buffer .= " </group>\n"; 210 } 211 if($this->Export['WithDiacritic'] != 1) $Buffer = utf2ascii($Buffer); 212 $Buffer .= " </translation>\n". 213 "</document>"; 214 return($Buffer); 215 } 216 217 function ExportToDBC() 218 { 219 global $TranslationTree, $LanguageList; 220 221 $this->LoadFilters(); 222 223 $TempDir = $this->Config['Web']['TempFolder'].$_SESSION['User'].'/dbc/'; 224 if(!file_exists($TempDir)) mkdir($TempDir, 0777, true); 225 226 227 foreach($TranslationTree as $Group) 228 if(in_array($Group['Id'], $Setting['groups']) and ($Group['DBCFileName'] != '')) 229 { 230 echo($Group['Name'].'... '); 231 $DBCFile = new DBCFile(); 232 $DBCFile->OpenFile('../source/'.$Setting['Version'].'/dbc/'.$Group['DBCFileName'].'.dbc', GetDBCColumns($Setting['Version'],$Group['DBCFileName'])); 233 $DBCFile2 = new DBCFile(); 234 $DBCFile2->CreateFile($TempDir.$Group['DBCFileName'].'.dbc', GetDBCColumns($Setting['Version'],$Group['DBCFileName'])); 235 $Count = $DBCFile->GetRecordCount(); 236 //if($Group['DBCFileName'] == 'Spell') $Count = 1000; 237 $Line = $DBCFile->GetLine(0); 238 $DBCFile2->SetRecordCount($Count); 239 for($I = 0; $I < $Count; $I++) 240 { 241 $Line = $DBCFile->GetLine($I); 242 $Query = 'SELECT * FROM (SELECT * FROM '.$Group['TablePrefix'].' WHERE (Complete = 1) AND '.$WhereLang.' AND '.$WhereUsers.' AND (entry='.$Line[0].') AND VersionStart <= '.GetBuildNumber($Setting['Version']).' AND VersionEnd >= '.GetBuildNumber($Setting['Version']).' ORDER BY FIELD(User, '.$SelectedUsers.')) AS T GROUP BY T.entry'; 243 $DbResult = $this->Database->query($Query); 244 if($DbResult->num_rows > 0) 245 { 246 $DbRow = $DbResult->fetch_assoc(); 247 // if($Setting['Diacritics'] != 1) $Buffer = utf2ascii($Buffer); 248 249 foreach($Group['Items'] as $GroupItem) 250 if(GetDBCColumnIndex($Setting['Version'],$Group['DBCFileName'],$GroupItem['Column']) != '') 251 $Line[GetDBCColumnIndex($this->Export['ClientVersion'],$Group['DBCFileName'],$GroupItem['Column'])] = $DbRow[$GroupItem['Column']]; 252 //print_r($Line); 253 } 254 $DBCFile2->SetLine($I, $Line); 255 echo('.'); 256 } 257 $DBCFile2->Commit(); 258 echo('Hotovo <br />'); 259 } 76 260 } 77 if($Setting['Diacritics'] != 1) $Buffer = utf2ascii($Buffer); 78 return($Buffer); 79 } 80 81 function ExportToAoWoWSQL($Setting) 82 { 83 global $Database, $Config, $TranslationTree, $AoWoWconf, $LanguageList; 84 85 require_once('../aowow/configs/config.php'); 86 87 $Buffer = ExportToMangosSQL($Setting); 261 262 function ExportToLua() 263 { 264 global $TranslationTree, $LanguageList; 265 266 $this->LoadFilters(); 267 268 $TempDir = $this->Config['Web']['TempFolder'].$_SESSION['User'].'/lua/'; 269 if(!file_exists($TempDir)) mkdir($TempDir, 0777, true); 270 271 $DbResult = $this->Database->query('SELECT `group`.* FROM `ExportGroup` JOIN `group` ON `group`.`Id` = `ExportGroup`.`Group` WHERE `ExportGroup`.`Export`='.$this->Id.' AND `group`.`LuaFileName` != ""'); 272 while($Group = $DbResult->fetch_assoc()) 273 { 274 echo($Group['Name'].'... '); 275 $File = new FileStream(); 276 $File->OpenFile('../source/'.$this->ClientVersion.'/lua/'.$Group['LuaFileName'].'.lua'); 277 $File2 = new FileStream(); 278 $File2->CreateFile($TempDir.''.$Group['LuaFileName'].'.lua'); 88 279 89 $AnoNe = array('Ne', 'Ano'); 90 if($_SESSION['UserID'] != '') 91 { 92 $DbResult = $Database->SQLCommand('SELECT user FROM `user` WHERE ID='.$_SESSION['UserID']); 93 $User = mysql_fetch_assoc($DbResult); 94 } else $User = array('user' => 'Neznámý'); 95 96 $WhereLang = ''; 97 foreach($LanguageList as $Language) 98 if($Language['Enabled'] == 1) 99 if(isset($Setting['language'.$Language['Id']])) $WhereLang .= ' OR (Language = '.$Language['Id'].')'; 100 if($WhereLang == '') $WhereLang = 1; 101 else $WhereLang = '('.substr($WhereLang, 4).')'; 102 103 $SelectedUsers = ''; 104 foreach($Setting['users-selection'] as $Item) 105 $SelectedUsers .= ','.$Item; 106 $SelectedUsers = substr($SelectedUsers, 1); 107 108 if($SelectedUsers == '') $Where = 0; 109 else $Where = 'ID IN ('.$SelectedUsers.')'; 110 111 $UserNames = ''; 112 $DbResult = $Database->SQLCommand('SELECT user FROM `user` WHERE '.$Where); 113 while($DbRow = mysql_fetch_assoc($DbResult)) 114 $UserNames .= ','.$DbRow['user']; 115 $UserNames = substr($UserNames, 1); 116 117 if($SelectedUsers == '') $WhereUsers = 1; 118 else $WhereUsers = '(User IN ('.$SelectedUsers.'))'; 119 120 // Data to aowow 121 122 $Database->SelectDatabase($AoWoWconf['mangos']['db']); 123 $Database->SQLCommand('SET NAMES '.$Config['Database']['Charset']); 124 $AoWoWTables = array('aowow_resistances' => 'Id', 'aowow_spelldispeltype' => 'Id', 'aowow_skill' => 'skillID'); 125 foreach($AoWoWTables as $AoWoWTable => $IndexColum) 126 { 127 $Buffer .= '--'.$AoWoWTable.', '; 128 $Buffer .= "\n\n"; 129 $Query = 'SELECT name,'.$IndexColum.' FROM '.$AoWoWTable; 130 $ID = $Database->SQLCommand($Query); 131 while($Line = mysql_fetch_assoc($ID)) 132 { 133 $Ori_text = $Line['name']; 134 $Tran = mysql_fetch_assoc($Database->SQLCommand('SELECT text as en, 135 (SELECT text FROM '.$Config['Database']['Database'].'.global_strings as tabletran 136 WHERE tableen.entry = tabletran.entry AND (Complete = 1) AND '.$WhereLang.' 137 AND '.$WhereUsers.' ORDER BY FIELD(User, '.$SelectedUsers.') LIMIT 1) as tran 138 FROM '.$Config['Database']['Database'].'.global_strings as tableen WHERE 139 text = "'.addslashes($Ori_text).'" LIMIT 1')); 140 //echo ($Line['name'].'='.$Tran['tran']); 141 if ($Tran['tran'] == '') 142 { 143 $Tran = mysql_fetch_assoc($Database->SQLCommand('SELECT OptionText as en, 144 (SELECT OptionText FROM '.$Config['Database']['Database'].'.npc_option as tabletran 145 WHERE tableen.entry = tabletran.entry AND (Complete = 1) AND '.$WhereLang.' 146 AND '.$WhereUsers.' ORDER BY FIELD(User, '.$SelectedUsers.') LIMIT 1) as tran 147 FROM '.$Config['Database']['Database'].'.npc_option as tableen WHERE 148 OptionText = "'.addslashes($Ori_text).'" LIMIT 1')); 149 } 150 if ($Tran['tran'] <> '') 151 $Buffer .= 'UPDATE `'.$AoWoWTable.'` SET name = "'.addslashes($Tran['tran']).'" WHERE '.$IndexColum.' = '.$Line[$IndexColum].' ;'."\n"; 152 } 153 $Buffer .= "\n\n"; 154 } 155 if($Setting['Diacritics'] != 1) $Buffer = utf2ascii($Buffer); 156 return($Buffer); 157 } 158 159 160 function ExportToXML($Setting) 161 { 162 global $Database, $Config, $TranslationTree, $LanguageList; 163 164 $AnoNe = array('Ne', 'Ano'); 165 if($_SESSION['UserID'] != '') 166 { 167 $DbResult = $Database->SQLCommand('SELECT user FROM `user` WHERE ID='.$_SESSION['UserID']); 168 $User = mysql_fetch_assoc($DbResult); 169 } else $User = array('user' => 'Neznámý'); 170 171 $WhereLang = ''; 172 foreach($LanguageList as $Language) 173 if($Language['Enabled'] == 1) 174 if(isset($Setting['language'.$Language['Id']])) $WhereLang .= ' OR (Language = '.$Language['Id'].')'; 175 if($WhereLang == '') $WhereLang = 1; 176 else $WhereLang = '('.substr($WhereLang, 4).')'; 177 178 $SelectedUsers = ''; 179 foreach($Setting['users-selection'] as $Item) 180 $SelectedUsers .= ','.$Item; 181 $SelectedUsers = substr($SelectedUsers, 1); 182 183 if($SelectedUsers == '') $Where = 0; 184 else $Where = 'ID IN ('.$SelectedUsers.')'; 185 186 $UserNames = ''; 187 $DbResult = $Database->SQLCommand('SELECT user FROM `user` WHERE '.$Where); 188 while($DbRow = mysql_fetch_assoc($DbResult)) 189 $UserNames .= ','.$DbRow['user']; 190 $UserNames = substr($UserNames, 1); 191 192 if($SelectedUsers == '') $WhereUsers = 1; 193 else $WhereUsers = '(User IN ('.$SelectedUsers.'))'; 194 195 $Buffer = '<?xml version="1.0" encoding="utf-8"?>'."\n". 196 "<document>\n". 197 " <meta>\n". 198 " <projecturl>".$Config['Web']['BaseURL']."</projecturl>\n". 199 " <time>".date('r')."</time>\n". 200 " <diacritics mode=".'"'.$Setting['Diacritics'].'"'." />\n". 201 " <author>".$User['user']."</author>\n". 202 " <contributors>\n"; 203 foreach(explode(',', $UserNames) as $UserName) 204 $Buffer .= " <user>".$UserName."</user>\n"; 205 $Buffer .= 206 " </contributors>\n". 207 " </meta>\n". 208 " <translation>\n"; 209 210 foreach($TranslationTree as $Group) 211 if(in_array($Group['Id'], $Setting['groups'])) 212 { 213 if($Group['MangosTable'] == '') 214 { 215 $Group['MangosTable'] = $Group['TablePrefix']; 216 $Group['MangosTableIndex'] = 'entry'; 217 } 218 $Query = 'SELECT *,(SELECT user FROM user WHERE user.ID=T.User) as UserName FROM (SELECT * FROM '.$Group['TablePrefix'].' WHERE (Complete = 1) AND VersionStart <= '.GetBuildNumber($Setting['Version']).' AND VersionEnd >= '.GetBuildNumber($Setting['Version']).' AND '.$WhereLang.' AND '.$WhereUsers.' ORDER BY FIELD(User, '.$SelectedUsers.')) AS T GROUP BY T.entry'; 219 //echo($Query); 220 $Buffer .= ' <group id="'.$Group['Id'].'" name="'.$Group['TablePrefix'].'">'."\n"; 221 $ID = $Database->SQLCommand($Query); 222 while($Line = mysql_fetch_array($ID)) 223 { 224 $Buffer .= ' <item id="'.$Line['entry'].'" user="'.$Line['UserName'].'">'."\n"; 225 $Values = ''; 226 foreach($Group['Items'] as $GroupItem) 227 { 228 if($GroupItem['MangosColumn'] == '') $GroupItem['MangosColumn'] = $GroupItem['Column']; 229 if($Line[$GroupItem['Column']] != '') 230 $Buffer .= ' <text index="'.$GroupItem['Id'].'" name="'.$GroupItem['Column'].'">'.addslashes($Line[$GroupItem['Column']]).'</text>'."\n"; 231 } 232 $Buffer .= " </item>\n"; 233 } 234 $Buffer .= " </group>\n"; 235 } 236 if($Setting['Diacritics'] != 1) $Buffer = utf2ascii($Buffer); 237 $Buffer .= " </translation>\n". 238 "</document>"; 239 return($Buffer); 240 } 241 242 function ExportToDBC($Setting) 243 { 244 global $Database, $Config, $TranslationTree, $LanguageList; 245 246 $TempDir = $Config['Web']['TempFolder'].$_SESSION['User'].'/dbc/'; 247 if(!file_exists($TempDir)) mkdir($TempDir, 0777, true); 248 249 if($_SESSION['UserID'] != '') 250 { 251 $DbResult = $Database->SQLCommand('SELECT user FROM `user` WHERE ID='.$_SESSION['UserID']); 252 $User = mysql_fetch_assoc($DbResult); 253 } else $User = array('user' => 'Neznámý'); 254 255 $WhereLang = ''; 256 foreach($LanguageList as $Language) 257 if($Language['Enabled'] == 1) 258 if(isset($Setting['language'.$Language['Id']])) $WhereLang .= ' OR (Language = '.$Language['Id'].')'; 259 if($WhereLang == '') $WhereLang = 1; 260 else $WhereLang = '('.substr($WhereLang, 4).')'; 261 262 $SelectedUsers = ''; 263 foreach($Setting['users-selection'] as $Item) 264 $SelectedUsers .= ','.$Item; 265 $SelectedUsers = substr($SelectedUsers, 1); 266 267 if($SelectedUsers == '') $Where = 0; 268 else $Where = 'ID IN ('.$SelectedUsers.')'; 269 270 $UserNames = ''; 271 $DbResult = $Database->SQLCommand('SELECT user FROM `user` WHERE '.$Where); 272 while($DbRow = mysql_fetch_assoc($DbResult)) 273 $UserNames .= ','.$DbRow['user']; 274 $UserNames = substr($UserNames, 1); 275 276 if($SelectedUsers == '') $WhereUsers = 1; 277 else $WhereUsers = '(User IN ('.$SelectedUsers.'))'; 278 279 foreach($TranslationTree as $Group) 280 if(in_array($Group['Id'], $Setting['groups']) and ($Group['DBCFileName'] != '')) 281 { 282 echo($Group['Name'].'... '); 283 $DBCFile = new DBCFile(); 284 $DBCFile->OpenFile('../source/'.$Setting['Version'].'/dbc/'.$Group['DBCFileName'].'.dbc', GetDBCColumns($Setting['Version'],$Group['DBCFileName'])); 285 $DBCFile2 = new DBCFile(); 286 $DBCFile2->CreateFile($TempDir.$Group['DBCFileName'].'.dbc', GetDBCColumns($Setting['Version'],$Group['DBCFileName'])); 287 $Count = $DBCFile->GetRecordCount(); 288 //if($Group['DBCFileName'] == 'Spell') $Count = 1000; 289 $Line = $DBCFile->GetLine(0); 290 $DBCFile2->SetRecordCount($Count); 291 for($I = 0; $I < $Count; $I++) 292 { 293 $Line = $DBCFile->GetLine($I); 294 $Query = 'SELECT * FROM (SELECT * FROM '.$Group['TablePrefix'].' WHERE (Complete = 1) AND '.$WhereLang.' AND '.$WhereUsers.' AND (entry='.$Line[0].') AND VersionStart <= '.GetBuildNumber($Setting['Version']).' AND VersionEnd >= '.GetBuildNumber($Setting['Version']).' ORDER BY FIELD(User, '.$SelectedUsers.')) AS T GROUP BY T.entry'; 295 $DbResult = $Database->SQLCommand($Query); 296 if(mysql_num_rows($DbResult) > 0) 297 { 298 $DbRow = mysql_fetch_assoc($DbResult); 299 // if($Setting['Diacritics'] != 1) $Buffer = utf2ascii($Buffer); 300 301 foreach($Group['Items'] as $GroupItem) 302 if(GetDBCColumnIndex($Setting['Version'],$Group['DBCFileName'],$GroupItem['Column']) != '') 303 $Line[GetDBCColumnIndex($Setting['Version'],$Group['DBCFileName'],$GroupItem['Column'])] = $DbRow[$GroupItem['Column']]; 304 //print_r($Line); 305 } 306 $DBCFile2->SetLine($I, $Line); 307 echo('.'); 308 } 309 $DBCFile2->Commit(); 310 echo('Hotovo <br />'); 280 while(!$File->EOF()) 281 { 282 $Line = $File->ReadLine(); 283 if(strpos($Line, '=') !== false) 284 { 285 $LineParts = explode(';', $Line); 286 $LineParts2 = explode('=', $LineParts[0]); 287 $Value['ShortCut'] = trim($LineParts2[0]); 288 $Value['Text'] = substr(trim($LineParts2[1]), 1, -1); 289 $Value['Comment'] = addslashes(substr(trim($LineParts[1]), 3)); 290 291 $Query = 'SELECT * FROM (SELECT * FROM '.$Group['TablePrefix'].' WHERE (Complete = 1) AND '.$this->WhereLang.' AND '.$this->WhereUsers.' AND (ShortCut="'.$Value['ShortCut'].'") AND VersionStart <= '.$this->ClientVersion.' AND VersionEnd >= '.$this->ClientVersion.' ORDER BY FIELD(User, '.$this->SelectedUsers.')) AS T GROUP BY T.entry'; 292 //echo($Query); 293 $DbResult2 = $this->Database->query($Query); 294 if($DbResult2->num_rows > 0) 295 { 296 $DbRow = $DbResult2->fetch_assoc(); 297 $Value['Text'] = $DbRow['Text']; 298 $Value['Comment'] = $DbRow['Comment']; 299 //echo('.'); 300 } 301 $NewLine = $Value['ShortCut'].' = "'.$Value['Text'].'";'; 302 if($Value['Comment'] != '') $NewLine .= ' -- '.$Value['Comment']; 303 $NewLine .= "\n"; 304 $File2->WriteLine($NewLine); 305 } else $File2->WriteLine($Line."\n"); 306 } 307 echo('Hotovo <br />'); 308 } 311 309 } 312 310 } 313 311 314 function ExportToLua($Setting)315 {316 global $Database, $Config, $TranslationTree, $LanguageList;317 318 $TempDir = $Config['Web']['TempFolder'].$_SESSION['User'].'/lua/';319 if(!file_exists($TempDir)) mkdir($TempDir, 0777, true);320 321 if($_SESSION['UserID'] != '')322 {323 $DbResult = $Database->SQLCommand('SELECT user FROM `user` WHERE ID='.$_SESSION['UserID']);324 $User = mysql_fetch_assoc($DbResult);325 } else $User = array('user' => 'Neznámý');326 327 $WhereLang = '';328 foreach($LanguageList as $Language)329 if($Language['Enabled'] == 1)330 if(isset($Setting['language'.$Language['Id']])) $WhereLang .= ' OR (Language = '.$Language['Id'].')';331 if($WhereLang == '') $WhereLang = 1;332 else $WhereLang = '('.substr($WhereLang, 4).')';333 334 $SelectedUsers = '';335 foreach($Setting['users-selection'] as $Item)336 $SelectedUsers .= ','.$Item;337 $SelectedUsers = substr($SelectedUsers, 1);338 339 if($SelectedUsers == '') $Where = 0;340 else $Where = 'ID IN ('.$SelectedUsers.')';341 342 $UserNames = '';343 $DbResult = $Database->SQLCommand('SELECT user FROM `user` WHERE '.$Where);344 while($DbRow = mysql_fetch_assoc($DbResult))345 $UserNames .= ','.$DbRow['user'];346 $UserNames = substr($UserNames, 1);347 348 if($SelectedUsers == '') $WhereUsers = 1;349 else $WhereUsers = '(User IN ('.$SelectedUsers.'))';350 351 foreach($TranslationTree as $Group)352 if(in_array($Group['Id'], $Setting['groups']) and ($Group['LuaFileName'] != ''))353 {354 echo($Group['Name'].'... ');355 $File = new FileStream();356 $File->OpenFile('../source/'.$Setting['Version'].'/lua/'.$Group['LuaFileName'].'.lua');357 $File2 = new FileStream();358 $File2->CreateFile($TempDir.''.$Group['LuaFileName'].'.lua');359 360 while(!$File->EOF())361 {362 $Line = $File->ReadLine();363 if(strpos($Line, '=') !== false)364 {365 $LineParts = explode(';', $Line);366 $LineParts2 = explode('=', $LineParts[0]);367 $Value['ShortCut'] = trim($LineParts2[0]);368 $Value['Text'] = substr(trim($LineParts2[1]), 1, -1);369 $Value['Comment'] = addslashes(substr(trim($LineParts[1]), 3));370 371 $Query = 'SELECT * FROM (SELECT * FROM '.$Group['TablePrefix'].' WHERE (Complete = 1) AND '.$WhereLang.' AND '.$WhereUsers.' AND (ShortCut="'.$Value['ShortCut'].'") AND VersionStart <= '.GetBuildNumber($Setting['Version']).' AND VersionEnd >= '.GetBuildNumber($Setting['Version']).' ORDER BY FIELD(User, '.$SelectedUsers.')) AS T GROUP BY T.entry';372 //echo($Query);373 $DbResult = $Database->SQLCommand($Query);374 if(mysql_num_rows($DbResult) > 0)375 {376 $DbRow = mysql_fetch_assoc($DbResult);377 $Value['Text'] = $DbRow['Text'];378 $Value['Comment'] = $DbRow['Comment'];379 //echo('.');380 }381 $NewLine = $Value['ShortCut'].' = "'.$Value['Text'].'";';382 if($Value['Comment'] != '') $NewLine .= ' -- '.$Value['Comment'];383 $NewLine .= "\n";384 $File2->WriteLine($NewLine);385 } else $File2->WriteLine($Line."\n");386 }387 echo('Hotovo <br />');388 }389 }390 391 312 ?>
Note:
See TracChangeset
for help on using the changeset viewer.