Name = 'Dictionary'; $this->Version = '1.0'; $this->Creator = 'Chronos'; $this->License = 'GNU/GPL'; $this->Description = 'Custom dictionary for better translation coordination'; $this->Dependencies = array('Translation'); } function DoStart(): void { $this->System->RegisterPage(['dictionary'], 'PageDictionary'); Core::Cast($this->System)->RegisterMenuItem(array( 'Name' => 'Dictionary', 'Title' => T('Dictionary'), 'Hint' => T('Dictionary words from WoW'), 'Link' => $this->System->Link('/dictionary/'), 'Permission' => LICENCE_ANONYMOUS, 'Icon' => '', ), 1); if (array_key_exists('Search', $this->System->ModuleManager->Modules)) $this->System->ModuleManager->Modules['Search']->RegisterSearch('dictionary', T('Dictionary'), array('Text', 'Description'), '(SELECT * FROM `Dictionary` WHERE `Language` = '.Core::Cast($this->System)->Config['OriginalLanguage'].') AS `T`', $this->System->Link('/dictionary/?search=')); } } class PageDictionary extends Page { function WriteTranslatNames($Text, $mode) { $Output = ''; if ($mode == 0) $Output .= '..'.T('Found names of items, places and NPC'); if ($mode == 1) $Output .= '..'.T('All untranslated'); if ($mode == 2) $Output .= '..'.T('Untranslated'); $Output .= ''; $Output .= ''.''; // TODO: Remove static table names in code. They should be controlled from database $TablesColumn = array ( 'TextGameObject' => 'Name', 'TextCreature' => 'name', 'TextItem' => 'Name', 'TextTransport' => 'Name', 'TextAreaTriggerTeleport' => 'Name', 'TextAreaTriggerTavern' => 'Name', 'Dictionary' => 'Text', 'TextArea' => 'Name', 'TextAreaPOI' => 'Name', 'TextCharacterClass' => 'Name', 'TextCharacterRace' => 'Name1', 'TextItemSubClass' => 'Name', 'TextCreatureType' => 'Name', ); $buff = GetTranslatNames($Text, $mode, GetTranslatNamesArray()); // $buff[] = array($Line['ID'],GetIDbyName($Table),$Line[$Column],$Line['Tran']); foreach ($buff as $Line) { if ($mode == 0) { if (strpos(strtolower($Text), strtolower($Line[2])) > 0) { $Output .= ''; if ($Line[3] <> '') $Output .= ''; else $Output .= ''; } } else { $Output .= ''; if ($Line[3] <> '') $Output .= ''; else $Output .= ''; } } $Output .= '
'.T('Original').''.T('Translation').'
'.$Line[2].''.$Line[3].'
'.T('Translate').'
'.$Line[2].''.$Line[3].'
'.T('Translate').'
'; return $Output; } function DictionaryInsert() { $User = ModuleUser::Cast($this->System->GetModule('User'))->User; $Output = ''; if ($User->Licence(LICENCE_USER)) { $Output .= '
'. '
'.T('New word insertion').''. ''. ''. ''. ''. ''. '
'. T('Original word').':
'.T('Translated').':
'.T('Language').':'.WriteLanguages($_SESSION['language']).'
'.T('Selectable description').':
'. '
'. '
'; } else $Output .= ShowMessage(T('Access denied'), MESSAGE_CRITICAL); return $Output; } function DictionarySave() { $User = ModuleUser::Cast($this->System->GetModule('User'))->User; if ($User->Licence(LICENCE_USER)) { if (array_key_exists('Original', $_POST) and array_key_exists('Translated', $_POST) and array_key_exists('Description', $_POST)) { // Check if original text exists and determine entry id $DbResult = $this->Database->query('SELECT * FROM `Dictionary` WHERE '. '`Text` = "'.$_POST['Original'].'" AND `Language`= '.Core::Cast($this->System)->Config['OriginalLanguage']); if ($DbResult->num_rows > 0) { $DbRow = $DbResult->fetch_assoc(); $Entry = $DbRow['Entry']; } else { $DbResult = $this->Database->query('SELECT MAX(`Entry`) FROM `Dictionary`'); $DbRow = $DbResult->fetch_row(); $Entry = $DbRow[0] + 1; $this->Database->query('INSERT INTO `Dictionary` ( `Text` , `Entry` , `Description` , '. '`User`, `Language` ) VALUES ("'.$_POST['Original'].'", "'.$Entry.'", "", NULL, '.Core::Cast($this->System)->Config['OriginalLanguage'].');'); } $DbResult = $this->Database->query('SELECT `Id` FROM `Dictionary` WHERE '. '`Entry` = '.$Entry.' AND `Language`='.$_POST['Language'].' AND `User`='.$User->Id); if ($DbResult->num_rows > 0) { $DbRow = $DbResult->fetch_assoc(); $this->Database->query('UPDATE `Dictionary` SET `Text`="'.$_POST['Translated'].'", '. '`Description` = "'.$_POST['Description'].'" WHERE Id='.$DbRow['Id']); } else $this->Database->query('INSERT INTO `Dictionary` ( `Text` , `Entry` , `Description` , '. '`User`, `Language` ) VALUES ("'.$_POST['Translated'].'", "'.$Entry.'", "'. $_POST['Description'].'", '.$User->Id.', '.$_POST['Language'].')'); $Output = ShowMessage('Záznam byl uložen!'); } else $Output = ShowMessage(T('You have to fill all column of form.'), MESSAGE_CRITICAL); } else $Output = ShowMessage(T('Access denied'), MESSAGE_CRITICAL); return $Output; } function DictionaryRemove() { $User = ModuleUser::Cast($this->System->GetModule('User'))->User; if ($User->Licence(LICENCE_USER)) { $this->Database->query('DELETE FROM `Dictionary` WHERE (`User`='.$User->Id.') AND (`Id`='.($_GET['id'] * 1).')'); $Output = ShowMessage(T('Record removed')); } else $Output = ShowMessage(T('Access denied'), MESSAGE_CRITICAL); return $Output; } function DictionaryModify() { $User = ModuleUser::Cast($this->System->GetModule('User'))->User; if ($User->Licence(LICENCE_USER)) { $DbResult = $this->Database->query('SELECT * FROM `Dictionary` WHERE `Id`='.($_GET['id'] * 1)); if ($DbResult->num_rows > 0) { $DbRow = $DbResult->fetch_assoc(); $DbResult = $this->Database->query('SELECT * FROM `Dictionary` WHERE (`User` IS NULL) '. 'AND (`Entry`='.$DbRow['Entry'].') AND (`Language`= '.Core::Cast($this->System)->Config['OriginalLanguage'].')'); $DbRow2 = $DbResult->fetch_assoc(); $Output = '
'. '
Upravení slova'. ''. ''. ''. ''. ''. ''. '
'. 'Původní anglické slovo:
Přeložené:
'.T('Language').':'.WriteLanguages($DbRow['Language']).'
'.T('Description').':
'. '
'. '
'; } else $Output = ShowMessage(T('Item not found'), MESSAGE_CRITICAL); } else $Output = ShowMessage(T('Access denied'), MESSAGE_CRITICAL); return $Output; } function DictionaryGroup() { $TranslationTree = $this->System->ModuleManager->Modules['Translation']->GetTranslationTree(); $Output = ''; $GroupId = LoadGroupIdParameter(); if (array_key_exists('mode', $_GET)) $mode = $_GET['mode']; else $mode = 0; //0 = exact names, 1=all names, 2=nontranslated $Table = $TranslationTree[$GroupId]['TablePrefix']; if (array_key_exists('ID', $_GET)) { $TextID = $_GET['ID']; $Output .= T('Translated names related to translation text').': '.$TextID.'
'. ''.T('All').' '. ''.T('Exact').' '. ''.T('Untranslated').' '; $DbResult = $this->Database->query('SELECT * FROM '.$Table.' WHERE ID = '.$TextID); $Line = $DbResult->fetch_assoc(); if (!$Line) $Output .= ShowMessage(T('Translation not found'), MESSAGE_CRITICAL); else { $Text = ''; foreach ($TranslationTree[$GroupId]['Items'] as $Index => $TextItem) $Text .= ' '.$Line[$TextItem['Column']]; $Output .= $this->WriteTranslatNames($Text, $mode); } } return $Output; } function DictionaryShow() { $User = ModuleUser::Cast($this->System->GetModule('User'))->User; global $LanguageList; $Output = '
'. ''; if (array_key_exists('search', $_GET)) $Search = $_GET['search']; else $Search = ''; $Output .= ''. ''. ''. '
'; if ($User->Licence(LICENCE_USER)) $Output .= ' '.T('Add word').''; $Output .= '
'.T('Language').': '; $Lang = ''.T('All').''; if ($_SESSION['language'] == '') $Output .= ''.$Lang.' '; else $Output .= $Lang; foreach ($LanguageList as $Language) if ($Language['Enabled'] == 1) { $Lang = ' '.T($Language['Name']).''; if ($Language['Id'] == $_SESSION['language']) $Output .= ''.$Lang.' '; else $Output .= $Lang; } $Output .= '
'; if (!is_numeric($_SESSION['language'])) $LanguageFilter = ''; else $LanguageFilter = ' AND (`T1`.`Language` = '.$_SESSION['language'].')'; if ($Search <> '') { $Condition = ' AND (LOWER(`T1`.`Text`) LIKE LOWER("%'.$Search.'%")) OR '. ' (LOWER(`T2`.`Text`) LIKE LOWER("%'.$Search.'%")) OR '. '(LOWER(`T1`.`Description`) LIKE LOWER("%'.$Search.'%"))'; } else $Condition = ''; $sql = 'SELECT `User`.`Name` AS `UserName`, `User`.`Id` AS `UserId`, '. '`Language`.`Name` AS `LangName`, `T1`.`Id` AS `Id`, '. '`T1`.`Entry`, `T2`.`Text` AS `Original`, `T1`.`Text` AS `Translated`, `T1`.`Description` '. 'FROM `Dictionary` AS `T1` JOIN `Dictionary` AS `T2` '. 'ON (`T2`.`Entry` = `T1`.`Entry`) AND (`T2`.`Language` = '.Core::Cast($this->System)->Config['OriginalLanguage'].') '. 'JOIN `Language` ON `Language`.`Id` = `T1`.`Language` '. 'JOIN `User` ON `User`.`ID` = `T1`.`User` '. 'WHERE 1'. $LanguageFilter.$Condition; $DbResult = $this->Database->query('SELECT COUNT(*) FROM ('.$sql.') AS `T1`'); $DbRow = $DbResult->fetch_row(); $PageList = GetPageList($DbRow[0]); $Output .= $PageList['Output']; if (is_numeric($_SESSION['language'])) $LanguageName = $LanguageList[$_SESSION['language']]['Name']; else $LanguageName = T('Translation'); $TableColumns = array( array('Name' => 'Original', 'Title' => T('English')), array('Name' => 'Translated', 'Title' => T($LanguageName)), ); if (!is_numeric($_SESSION['language'])) $TableColumns[] = array('Name' => 'LangName', 'Title' => T('Language')); $TableColumns[] = array('Name' => 'Description', 'Title' => T('Description')); $TableColumns[] = array('Name' => 'UserName', 'Title' => T('Translator')); if ($User->Licence(LICENCE_USER)) $TableColumns[] = array('Name' => '', 'Title' => T('Action')); $Order = GetOrderTableHeader($TableColumns, 'Original'); $Output .= ''.$Order['Output']; $sql_page = $sql.$Order['SQL'].$PageList['SQLLimit']; $DbResult = $this->Database->query($sql_page); while ($Line = $DbResult->fetch_assoc()) { $Output .= ''. ''. ''; if (!is_numeric($_SESSION['language'])) $Output .= ''; $Output .= ''. ''; if ($User->Licence(LICENCE_USER)) { if ($Line['UserId'] == $User->Id) $Output .= ''; else $Output .= ''; } $Output .= ''; } $Output .= '
'.htmlspecialchars($Line['Original']).''.htmlspecialchars($Line['Translated']).''.T($Line['LangName']).''.htmlspecialchars($Line['Description']).''. $Line['UserName'].''.T('Delete').''. ' '.T('Modify').'
'. $PageList['Output']. '
'; return $Output; } function Show(): string { global $LanguageList; $User = ModuleUser::Cast($this->System->GetModule('User'))->User; $this->Title = T('Dictionary'); $LanguageList = GetLanguageList(); if (!isset($_SESSION['language'])) { if ($User->Licence(LICENCE_USER)) { $_SESSION['language'] = $User->Language; } else $_SESSION['language'] = ''; } if (array_key_exists('language', $_GET)) { if ($_GET['language'] == '') $_SESSION['language'] = ''; else $_SESSION['language'] = $_GET['language'] * 1; } $Output = '

'.T('Dictionary').'

'; $ShowList = true; if (array_key_exists('action', $_GET)) { if ($_GET['action'] == 'group') { $Output .= $this->DictionaryGroup(); $ShowList = false; } else if ($_GET['action'] == 'insert') $Output .= $this->DictionaryInsert(); else if ($_GET['action'] == 'save') $Output .= $this->DictionarySave(); else if ($_GET['action'] == 'remove') $Output .= $this->DictionaryRemove(); else if ($_GET['action'] == 'modify') $Output .= $this->DictionaryModify(); else $Output .= ShowMessage(T('Unknown action'), MESSAGE_CRITICAL); } if ($ShowList == true) $Output .= $this->DictionaryShow(); return $Output; } }