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 .= ''.T('Original').' | '.''.T('Translation').' |
';
// 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 .= ''.$Line[2].' | ';
if ($Line[3] <> '') $Output .= ''.$Line[3].' |
';
else $Output .= ''.T('Translate').' | ';
}
} else
{
$Output .= ''.$Line[2].' | ';
if ($Line[3] <> '') $Output .= ''.$Line[3].' |
';
else $Output .= ''.T('Translate').' | ';
}
}
$Output .= '
';
return $Output;
}
function DictionaryInsert()
{
$User = ModuleUser::Cast($this->System->GetModule('User'))->User;
$Output = '';
if ($User->Licence(LICENCE_USER))
{
$Output .= '';
} 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 = '';
} 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 = '';
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;
}
}