source: trunk/Modules/Translation/Comparison.php

Last change on this file was 900, checked in by chronos, 6 weeks ago
  • Fixed: More form input fields validation.
  • Modified: Code cleanup.
File size: 4.7 KB
Line 
1<?php
2
3class PageTranslationComparison extends Page
4{
5 function CompareString($String1, $String2)
6 {
7 $Result = '';
8 //TODO: Implement colored comparison
9 //strcasecmp($String1, $String2) == 0 je totožné
10 // echo $String1.'<br /><br />';
11 $ArrStr1 = explode(' ', $String1);
12 $ArrStr2 = explode(' ', $String2);
13
14 for ($i = 0; $i < count($ArrStr1); $i++)
15 {
16 if (isset($ArrStr2[$i]))
17 {
18 if ($ArrStr1[$i] == $ArrStr2[$i])
19 {
20 $Result .= $ArrStr1[$i].' ';
21 } else
22 {
23 $find = false;
24 for ($j = 0; $j < count($ArrStr2); $j++)
25 {
26 if (($ArrStr1[$i] == $ArrStr2[$j]) and ($find == false))
27 {
28 $Result .= $ArrStr1[$i].' ';
29 $find = true;
30 }
31 }
32 if ($find == false)
33 $Result .= '<span class="edit">'.$ArrStr1[$i].' </span>';
34 }
35 } else $Result .= '<span class="edit">'.$ArrStr1[$i].' </span>';
36 }
37 return $Result;
38 }
39
40 function Show(): string
41 {
42 $User = ModuleUser::Cast($this->System->GetModule('User'))->User;
43 $TranslationTree = $this->System->ModuleManager->Modules['Translation']->GetTranslationTree();
44
45 $Output = '';
46
47 if ($User->Licence(LICENCE_USER))
48 {
49 $Output = 'Text je porovnáván vždy ku předešlému (vlevo). Změny jsou zvýrazněny <span class="edit">barvou.</span><br /><br />';
50
51 $GroupId = LoadGroupIdParameter();
52 $Table = $TranslationTree[$GroupId]['TablePrefix'];
53
54 if (array_key_exists('entry', $_GET))
55 {
56 $Textentry = $_GET['entry'];
57 if ((array_key_exists('ID1', $_GET)) and ($_GET['ID1'] <> -1)) //porovnání pouze 2 textů
58 {
59 $TextID1 = $_GET['ID1'];
60 $TextID2 = $_GET['ID2'];
61 $WhereID = ' AND ((`'.$Table.'`.`ID` = '.$TextID1.') OR (`'.$Table.'`.`ID` = '.$TextID2.'))';
62 } else $WhereID = '';
63
64 $DataID = $this->Database->query('SELECT `'.$Table.'`.*, `User`.`Name` AS `UserName`, '.
65 '`Language`.`Name` AS `LanguageName` '.
66 'FROM '.$Table.' LEFT JOIN `User` ON `User`.`Id` = `'.$Table.'`.`User` '.
67 ' LEFT JOIN `Language` ON `Language`.`Id` = `'.$Table.'`.`Language` '.
68 'WHERE `Entry` = '.$Textentry.' '.$WhereID.' ORDER BY `Language`');
69 while ($Line[] = $DataID->fetch_assoc());
70 array_pop($Line);
71
72 $Output .= 'Počet porovnávaných textů: <strong>'.count($Line).'</strong><br /> ';
73
74 $Output .= '<strong>Číslo textu: <a href="http://www.wowhead.com/?quest='.$Textentry.'">'.$Textentry.'</a></strong>'.
75 '<table class="BaseTable">'.
76 '<tr><th>Přeložil</th>';
77 foreach ($Line as $Index => $LineItem)
78 $Output .= '<th>'.$LineItem['UserName'].'</th>';
79 $Output .= '</tr>'.
80 '<tr>'.
81 '<th>ID textu</th>';
82 foreach ($Line as $Index => $LineItem)
83 $Output .= '<td><a href="form.php?group='.$GroupId.'&amp;ID='.$LineItem['ID'].'">'.$LineItem['ID'].'</a></td>';
84 $Output .= '</tr>'.
85 '<tr><th>Převzato</th>';
86 foreach ($Line as $Index => $LineItem)
87 $Output .= '<td><a href="form.php?group='.$GroupId.'&amp;ID='.$LineItem['Take'].'">'.$LineItem['Take'].'</a></td>';
88 $Output .= '</tr>'.
89 '<tr><th>'.T('Language').'</th>';
90 foreach ($Line as $Index => $LineItem)
91 $Output .= '<td>'.T($LineItem['LanguageName']).'</td>';
92 $Output .= '</tr>'.
93 '<tr><th>'.T('Version').'</th>';
94 foreach ($Line as $Index => $LineItem)
95 $Output .= '<td>'.GetVersionWOW($LineItem['VersionStart']).' - '.GetVersionWOW($LineItem['VersionEnd']).'</td>';
96 $Output .= '</tr>';
97 foreach ($TranslationTree[$GroupId]['Items'] as $Index => $TextItem)
98 {
99 $writethis = false;
100 for ($i = 0; $i < count($Line); $i++)
101 {
102 if ($Line[$i][$TextItem['Column']] <> '') $writethis = true;
103 }
104 if ($writethis)
105 {
106 $Output .= '<tr><th>'.$TextItem['Name'].'</th>';
107 for ($i = 0; $i < count($Line); $i++)
108 {
109 if ($i > 0)
110 {
111 $Output .= '<td>';
112 $Output .= str_replace("\n", '<br/>', $this->CompareString(htmlspecialchars($Line[$i][$TextItem['Column']]),htmlspecialchars($Line[$i - 1][$TextItem['Column']])));
113 $Output .= '</td>';
114 } else $Output .= '<td>'.htmlspecialchars($Line[$i][$TextItem['Column']]).'</td>';
115 }
116 $Output .= '</tr>';
117 }
118 }
119 $Output .= '</table>';
120 } else $Output .= ShowMessage('Nebylo zadáno ID.', MESSAGE_CRITICAL);
121 } else $Output .= ShowMessage('Porovnávat můžou pouze překladatelé!', MESSAGE_CRITICAL);
122
123 return $Output;
124 }
125}
Note: See TracBrowser for help on using the repository browser.