source: trunk/Modules/Translation/Translation.php@ 888

Last change on this file since 888 was 888, checked in by chronos, 2 years ago
  • Modified: Updated Common package to latest version.
  • Modified: Fixes related to PHP 8.x.
File size: 9.1 KB
Line 
1<?php
2
3include_once(dirname(__FILE__).'/Comparison.php');
4include_once(dirname(__FILE__).'/Form.php');
5include_once(dirname(__FILE__).'/Save.php');
6include_once(dirname(__FILE__).'/TranslationList.php');
7include_once(dirname(__FILE__).'/Progress.php');
8include_once(dirname(__FILE__).'/LoadNames.php');
9include_once(dirname(__FILE__).'/UserLevel.php');
10
11class ModuleTranslation extends Module
12{
13 function __construct(System $System)
14 {
15 parent::__construct($System);
16 $this->Name = 'Translation';
17 $this->Version = '1.0';
18 $this->Creator = 'Chronos';
19 $this->License = 'GNU/GPL';
20 $this->Description = 'Translation of text items and groups from original language to other languages.';
21 $this->Dependencies = array('News', 'Search');
22 }
23
24 function DoStart(): void
25 {
26 $this->System->RegisterPage(['comparison.php'], 'PageTranslationComparison');
27 $this->System->RegisterPage(['form.php'], 'PageTranslationForm');
28 $this->System->RegisterPage(['save.php'], 'PageTranslationSave');
29 $this->System->RegisterPage(['progress'], 'PageProgress');
30 $this->System->RegisterPage(['translation-groups'], 'PageTranslationGroups');
31 $this->System->RegisterPage(['TranslationList.php'], 'PageTranslationList');
32 $this->System->RegisterPage(['LoadNames.php'], 'PageLoadNames');
33 $this->System->ModuleManager->Modules['News']->RegisterRSS(array('Title' => T('Last translations'),
34 'Channel' => 'translation', 'Callback' => array($this, 'ShowRSS'), 'Permission' => LICENCE_ANONYMOUS));
35 Core::Cast($this->System)->RegisterMenuItem(array(
36 'Title' => T('Completion status'),
37 'Hint' => 'Stav dokončení překládů',
38 'Link' => $this->System->Link('/progress/'),
39 'Permission' => LICENCE_ANONYMOUS,
40 'Icon' => '',
41 ), 1);
42 Core::Cast($this->System)->RegisterMenuItem(array(
43 'Title' => T('Data source'),
44 'Hint' => 'Informace o překladových skupinách',
45 'Link' => $this->System->Link('/translation-groups/'),
46 'Permission' => LICENCE_ANONYMOUS,
47 'Icon' => '',
48 ));
49 if (array_key_exists('Search', $this->System->ModuleManager->Modules))
50 {
51 $TranslationTree = $this->System->ModuleManager->Modules['Translation']->GetTranslationTree();
52 foreach ($TranslationTree as $Group)
53 {
54 $Table = $Group['TablePrefix'];
55
56 $Columns = array('ID', 'Entry');
57 foreach ($Group['Items'] as $Item)
58 {
59 if ($Item['Column'] != '') $Columns[] = $Item['Column'];
60 }
61
62 $this->System->ModuleManager->Modules['Search']->RegisterSearch('group'.$Group['Id'],
63 sprintf(T('Translation group "%s"'), $Group['Name']), $Columns, '`'.$Table.'`',
64 $this->System->Link('/TranslationList.php?group='.
65 $Group['Id'].'&amp;user=0&amp;state=0&amp;entry=&amp;text='));
66 }
67 }
68 Core::Cast($this->System)->RegisterPageBarItem('Right', 'TranslatedMenu', array($this, 'ShowTranslatedMenu'));
69 }
70
71 function ShowRSS()
72 {
73 $Items = array();
74 $DbResult = $this->Database->query('SELECT UNIX_TIMESTAMP(`Date`) AS `Date`, `User`.`Name` AS `UserName`, `Text` FROM `Log` '.
75 'JOIN `User` ON `User`.`ID` = `Log`.`User` WHERE `Type` = 1 ORDER BY `Date` DESC LIMIT 100');
76 while ($DbRow = $DbResult->fetch_assoc())
77 {
78 $Items[] = array
79 (
80 'Title' => strip_tags($DbRow['Text'].' ('.$DbRow['UserName'].')'),
81 'Link' => 'http://'.$this->System->Config['Web']['Host'].$this->System->Link('/'),
82 'Description' => $DbRow['Text'],
83 'Time' => $DbRow['Date'],
84 );
85 }
86 $Output = GenerateRSS(array
87 (
88 'Title' => $this->System->Config['Web']['Title'].' - '.T('Last translations'),
89 'Link' => 'http://'.$this->System->Config['Web']['Host'].$this->System->Link('/'),
90 'Description' => $this->System->Config['Web']['Description'],
91 'WebmasterEmail' => $this->System->Config['Web']['AdminEmail'],
92 'Items' => $Items,
93 ));
94 return $Output;
95 }
96
97 function ShowBox()
98 {
99 $Count = 40;
100 $Output = '<strong>'.T('Last translated').':</strong>';
101 $Output .= '<div class="box">';
102
103 $GroupListQuery = 'SELECT `Group`.* FROM `Group`';
104 $Query = '';
105 $UnionItems = array();
106 $DbResult = $this->Database->query($GroupListQuery);
107 if ($DbResult->num_rows > 0)
108 {
109 while ($DbRow = $DbResult->fetch_assoc())
110 {
111 $UnionItems[] = 'SELECT `T`.`ID`, `T`.`Take`, `T`.`User`, `T`.`ModifyTime`, `T`.`Group`, `T`.`GroupName` '.
112 'FROM (SELECT `T`.`User`, `T`.`ID`, `T`.`ModifyTime`, '.
113 $DbRow['Id'].' AS `Group`, "'.addslashes($DbRow['Name']).'" AS `GroupName`, `T`.`Take` FROM `'.
114 $DbRow['TablePrefix'].'` AS `T`'.
115 ' WHERE (`T`.`Complete` = 1) AND (`T`.`Language` != '.$this->System->Config['OriginalLanguage'].') ORDER BY `T`.`ModifyTime` DESC LIMIT '.
116 $Count.') AS `T`';
117 }
118 $Query = 'SELECT `TT`.*, `User`.`Name` AS `UserName`, `User`.`Id` AS `UserId` '.
119 ' FROM ('.implode(' UNION ', $UnionItems).') AS `TT`'.
120 ' JOIN `User` ON `User`.`Id` = `TT`.`User`'.
121 ' ORDER BY `ModifyTime` DESC LIMIT '.$Count;
122 $DbResult = $this->Database->query($Query);
123 $Output .= '<table class="MiniTable"><tr><th>'.T('Date').'</th><th>'.T('Who').'</th><th>'.T('New').'</th><th>'.T('Source').'</th><th>'.T('Group').'</th></tr>';
124 while ($DbRow = $DbResult->fetch_assoc())
125 {
126 $Output .= '<tr><td>'.HumanDate($DbRow['ModifyTime']).'</td>'.
127 '<td><a href="'.$this->System->Link('/user/?user='.$DbRow['UserId']).'">'.$DbRow['UserName'].'</a></td>'.
128 '<td><a href="'.$this->System->Link('/form.php?group='.$DbRow['Group'].'&amp;ID='.$DbRow['ID']).'">'.$DbRow['ID'].'</a></td>'.
129 '<td><a href="'.$this->System->Link('/form.php?group='.$DbRow['Group'].'&amp;ID='.$DbRow['Take']).'">'.$DbRow['Take'].'</a></td>'.
130 '<td><a href="'.$this->System->Link('/TranslationList.php?group='.$DbRow['Group'].'&amp;action=filter').'">'.T($DbRow['GroupName']).'</a></td></tr>';
131 }
132 $Output .= '</table>';
133 }
134 $Output .= '</div>';
135 return $Output;
136 }
137
138 function GetTranslationTree()
139 {
140 if (isset($this->TranslationTree)) return $this->TranslationTree;
141 else {
142 $Result = array();
143 $Groups = array();
144 $DbResult = $this->System->Database->query('SELECT *, UNIX_TIMESTAMP(`LastImport`) AS `LastImportTime` FROM `Group`');
145 while ($DbRow = $DbResult->fetch_assoc())
146 $Groups[T($DbRow['Name'])] = $DbRow;
147 ksort($Groups);
148 foreach ($Groups as $Group)
149 {
150 $Group['Items'] = array();
151 $Group['Game'] = T($Group['Name']);
152 $Result[$Group['Id']] = $Group;
153 }
154 $DbResult = $this->System->Database->query('SELECT * FROM `GroupItem` ORDER BY `Group`, `Sequence`');
155 while ($DbRow = $DbResult->fetch_assoc())
156 {
157 $Result[$DbRow['Group']]['Items'][] = $DbRow;
158 }
159 $this->TranslationTree = $Result;
160 return $Result;
161 }
162 }
163
164 function ShowTranslatedMenu()
165 {
166 $TranslationTree = $this->GetTranslationTree();
167
168 $Output = '<strong>'.T('Translate groups').':</strong><br /><div id="TranslationMenu">';
169 $DbResult = $this->System->Database->select('Group', '`Id`, `Name`', '1 ORDER BY `Name`');
170 while ($Group = $DbResult->fetch_assoc())
171 {
172 $Groups[T($Group['Name'])] = $Group;
173 }
174 ksort($Groups);
175 foreach ($Groups as $Group)
176 {
177 $Output .= '<div id="menuitem-group'.$Group['Id'].'" onmouseover="show(\'group'.$Group['Id'].'\')" onmouseout="hide(\'group'.$Group['Id'].'\')">'.
178 '<a href="'.$this->System->Link('/TranslationList.php?group='.$Group['Id'].
179 '&amp;action=filter').'">'.str_replace(' ','&nbsp;', T($Group['Name'])).'</a></div>'.
180 '<div id="group'.$Group['Id'].'" class="hidden-menu-item" onmouseover="show(\'group'.$Group['Id'].'\')" onmouseout="hide(\'group'.$Group['Id'].'\')">';
181 $Output .= '&nbsp;<a title="Zde můžete začít překládat" href="'.
182 $this->System->Link('/TranslationList.php?group='.$Group['Id'].'&amp;state=1&amp;user=0&amp;entry=&amp;text=').'">'.T('Untranslated').'</a><br />'.
183 '&nbsp;<a title="Přeložené texty, můžete zde hlasovat, nebo opravovat překlady" href="'.
184 $this->System->Link('/TranslationList.php?group='.$Group['Id'].'&amp;state=2&amp;user=0&amp;entry=&amp;text=').'">'.T('Translated').'</a><br />';
185 if (isset($this->System->User) and $this->System->User->Licence(LICENCE_USER))
186 {
187 $Output .= '&nbsp;<a title="'.T('Unfinished translations').'" href="'.$this->System->Link('/TranslationList.php?group='.$Group['Id'].'&amp;state=3').'">'.T('Unfinished').'</a><br />'.
188 '&nbsp;<a title="Všechny překlady, které jste přeložil" href="'.
189 $this->System->Link('/TranslationList.php?group='.$Group['Id'].'&amp;state=1&amp;user='.
190 $this->System->User->Id).'&amp;entry=&amp;text=">'.T('Own').'</a><br />';
191 }
192 $Output .= '&nbsp;<a title="'.T('Compose special filter').'" href="'.
193 $this->System->Link('/TranslationList.php?group='.$Group['Id'].'&amp;action=filter').
194 '">'.T('Filter').'</a><br />';
195 $Output .= '</div>';
196 }
197 $Output .= '</div>';
198 return $Output;
199 }
200}
Note: See TracBrowser for help on using the repository browser.