1 | <?php
|
---|
2 |
|
---|
3 | // Settings
|
---|
4 | $xp_from_word = 1;
|
---|
5 | $index_level = 100;
|
---|
6 | $from_diakrit = 3; // higher xp for word with diacritics
|
---|
7 |
|
---|
8 | function CheckDiakrit($Word)
|
---|
9 | {
|
---|
10 | $Result = false;
|
---|
11 | $Diakrit = array("á","č","ď","é","ě","í","ľ","ň","ó","ř","š","ť","ú",
|
---|
12 | "ů","ý","ž","Á","Č","Ď","É","Ě","Í","Ľ","Ň","Ó","Ř","Š","Ť","Ú","Ů","Ý","Ž");
|
---|
13 | for ($i = 0; $i < count($Diakrit); $i = $i + 1)
|
---|
14 | {
|
---|
15 | if (strpos($Word, $Diakrit[$i]) <> false)
|
---|
16 | $Result = true;
|
---|
17 | }
|
---|
18 | return $Result;
|
---|
19 | }
|
---|
20 |
|
---|
21 | function GetXPFromTranslation($UserId)
|
---|
22 | {
|
---|
23 | global $System, $xp_from_word, $from_diakrit, $Config;
|
---|
24 |
|
---|
25 | $TranslationTree = $System->ModuleManager->Modules['Translation']->GetTranslationTree();
|
---|
26 |
|
---|
27 | $xp = 0;
|
---|
28 | foreach ($TranslationTree as $Group)
|
---|
29 | {
|
---|
30 | if ($Group['TablePrefix'] != '')
|
---|
31 | {
|
---|
32 | $GroupBy = 'GROUP BY ';
|
---|
33 | $TakeColumns = '';
|
---|
34 | foreach ($TranslationTree[$Group['Id']]['Items'] as $Index => $TextItem)
|
---|
35 | {
|
---|
36 | $GroupBy .= '`T`.`'.$TextItem['Column'].'`, ';
|
---|
37 | $TakeColumns .= ', `T2`.`'.$TextItem['Column'].'` AS `'.$TextItem['Column'].'_Take`';
|
---|
38 | }
|
---|
39 | $GroupBy = substr($GroupBy, 0, -2);
|
---|
40 |
|
---|
41 | $IDtran = $System->Database->query('SELECT *, `T2`.`Language` AS `Language_Take`'.$TakeColumns.' FROM `'.$Group['TablePrefix'].'` AS `T` '.
|
---|
42 | 'LEFT JOIN `'.$Group['TablePrefix'].'` AS `T2` ON `T2`.`ID` = `T`.`Take` '.
|
---|
43 | 'WHERE (`T`.`User` = '.$UserId.') AND (`T`.`Complete` = 1) AND (`T`.`Take` IS NOT NULL) '.$GroupBy);
|
---|
44 | while ($Line = $IDtran->fetch_array())
|
---|
45 | {
|
---|
46 | $xp_translation = 0;
|
---|
47 | $translated = true;
|
---|
48 | foreach ($TranslationTree[$Group['Id']]['Items'] as $Index => $TextItem)
|
---|
49 | {
|
---|
50 | if (($Line[$TextItem['Column']] <> $Line[$TextItem['Column'].'_Take']) and
|
---|
51 | (strlen($Line[$TextItem['Column']]) > (strlen($Line[$TextItem['Column'].'_Take']) * 0.5)))
|
---|
52 | {
|
---|
53 | $TextArr = explode(' ', $Line[$TextItem['Column']]);
|
---|
54 | foreach ($TextArr as $Word)
|
---|
55 | {
|
---|
56 | if (CheckDiakrit($Word)) $indikator = $from_diakrit;
|
---|
57 | else $indikator = 1;
|
---|
58 | $xp_translation = $xp_translation + ($indikator * $xp_from_word);
|
---|
59 | }
|
---|
60 | } else
|
---|
61 | {
|
---|
62 | if (($Line[$TextItem['Column']] == $Line[$TextItem['Column'].'_Take']) and
|
---|
63 | ($Config['OriginalLanguage'] == $Line['Language_Take']) and ($Line[$TextItem['Column'].'_Take'] <> '') and
|
---|
64 | ($TextItem['Column'] <> 'ShortCut')) $translated = false;
|
---|
65 | }
|
---|
66 | }
|
---|
67 | if ($translated) $xp = $xp + $xp_translation; // XP addition for entire translation if complete translated
|
---|
68 | }
|
---|
69 | }
|
---|
70 | }
|
---|
71 | return $xp;
|
---|
72 | }
|
---|
73 |
|
---|
74 | function UserLevelUpdate($UserId)
|
---|
75 | {
|
---|
76 | global $System, $Config;
|
---|
77 |
|
---|
78 | $TranslationTree = $System->ModuleManager->Modules['Translation']->GetTranslationTree();
|
---|
79 | // Main code for users
|
---|
80 | $DbResult = $System->Database->query('SELECT `ID`, `Name` FROM `User` WHERE `Id` = '.$UserId);
|
---|
81 | if ($DbResult->num_rows > 0)
|
---|
82 | {
|
---|
83 | while ($LineUser = $DbResult->fetch_array())
|
---|
84 | {
|
---|
85 | // Build TranslatedCount query
|
---|
86 | $TranslatedCount = '(';
|
---|
87 | if (count($TranslationTree) > 0)
|
---|
88 | {
|
---|
89 | foreach ($TranslationTree as $Group)
|
---|
90 | if ($Group['TablePrefix'] != '')
|
---|
91 | {
|
---|
92 | $Count = '(SELECT COUNT(*) FROM `'.$Group['TablePrefix'].'` WHERE (`Complete` = 1) AND (`Language` <> '.
|
---|
93 | $Config['OriginalLanguage'].') AND (`User`='.$LineUser['ID'].'))';
|
---|
94 | $TranslatedCount .= 'COALESCE('.$Count.', 0) + ';
|
---|
95 | }
|
---|
96 | $TranslatedCount = substr($TranslatedCount, 0, -3).')';
|
---|
97 | } else $TranslatedCount = 0;
|
---|
98 |
|
---|
99 | $xp = GetXPFromTranslation($LineUser['ID']);
|
---|
100 | $System->Database->query('UPDATE `User` SET `XP` = '.$xp.', `TranslatedCount` = '.$TranslatedCount.' WHERE `User`.`ID` = '.$LineUser['ID']);
|
---|
101 | }
|
---|
102 | }
|
---|
103 | }
|
---|