source: trunk/img_level.php@ 129

Last change on this file since 129 was 129, checked in by maron, 16 years ago

filtrování XP při hromadném překladu

File size: 4.3 KB
Line 
1<?php
2
3require_once('includes/global.php');
4if (array_key_exists('nothide',$_GET))
5 $nothide = true;
6else
7 $nothide = false;
8if ($nothide) ShowPage();
9
10$FontFile = 'images/FRIZQT__.ttf';
11$TranslationTree = GetTranslationTree();
12
13//nastavení
14$xp_from_word = 1;
15$index_level = 100;
16$from_diakrit = 3; //zvýšené xp za slovo s diakritikou
17
18 function CheckDiakrit($word) {
19 $result = false;
20 $Diakrit = Array("á","č","ď","é","ě","í","ľ","ň","ó","ř","š","ť","ú",
21 "ů","ý","ž","Á","Č","Ď","É","Ě","Í","Ľ","Ň","Ó","Ř","Š","Ť","Ú","Ů","Ý","Ž");
22 for ($i=0;$i<count($Diakrit);$i=$i+1) {
23 if (strpos($word,$Diakrit[$i]) <> false) {
24 $result = true;
25 }
26 }
27 return $result;
28 }
29
30 function CreateImg($user,$xp) {
31 global $index_level,$FontFile;
32
33 if ($xp > 0) {
34 $level = sqrt ($xp / $index_level);
35 $level = substr($level,0,strpos($level,'.'));
36 } else {
37 $level = 0;
38 }
39 $xp_min = ($level) * ($level) * ($index_level);
40 $xp_max = ($level+1)*($level+1)* ($index_level);
41 $xp_max = $xp_max-$xp_min;
42 $xp = $xp-$xp_min;
43
44 if($xp_max > 0) $Percent = ( $xp / $xp_max) * 100; else $Percent = 0;
45 $Percent = substr($Percent, 0, 5);
46
47 $PercentBar = $Percent * 2.5;
48 $Image = ImageCreateTrueColor(250, 15);
49 $Color1 = imagecolorallocate($Image, 214, 214, 214);
50 $Color2 = imagecolorallocate($Image, 239, 131, 166);
51 $Color3 = imagecolorallocate($Image, 225, 0, 0);
52 imagefilledrectangle($Image, 0, 0, 250, 15, $Color1);
53 imagefilledrectangle($Image, 0, 0, $PercentBar, 59, $Color2);
54 ImageTTFText($Image, 11, 0, 10, 12, $Color3, $FontFile, $level.' Level');
55 ImageTTFText($Image, 8, 0, 80, 12, $Color3, $FontFile, $xp.'/'.$xp_max.' xp '.$user);
56
57 if (file_exists('tmp/'.$user.'/') == false) mkdir ('tmp/'.$user.'/');
58 ImagePNG($Image,'tmp/'.$user.'/level.png');
59 }
60
61 function GetXPFromTranslation($user_ID) {
62 global $Database,$TranslationTree,$xp_from_word,$from_diakrit;
63 $xp = 0;
64
65 foreach($TranslationTree as $Group) { //překladové skupiny
66 if($Group['TablePrefix'] != '') {
67 $IDtran = $Database->SQLCommand('SELECT * FROM `'.$Group['TablePrefix'].'` WHERE User = '.$user_ID.' AND Complete = 1 GROUP BY Take');
68 while ($Line = mysql_fetch_array($IDtran)) { //jednotlivé překlady
69 $LineComparison = mysql_fetch_assoc($Database->SQLCommand('SELECT * FROM `'.$Group['TablePrefix'].'` WHERE ID = '.$Line['Take']));
70 $xp_translation = 0; //mazání posledního
71 $translated = true;
72 foreach($TranslationTree[$Group['Id']]['Items'] as $Index => $TextItem) { //jednotlivé položky překladu
73 if (($Line[$TextItem['Column']] <> $LineComparison[$TextItem['Column']]) and (strlen($Line[$TextItem['Column']]) > (strlen($LineComparison[$TextItem['Column']])*0.5))) { //zda není stejný, zda je aspoň dlouhý jako polovina
74 $TextArr = explode(' ',$Line[$TextItem['Column']]);
75 for ($i=0;$i<count($TextArr);$i=$i+1) { //pro každé slovo
76 if (CheckDiakrit($TextArr[$i])) // zjišťování diakritiky
77 $indikator = $from_diakrit;
78 else
79 $indikator = 1;
80 $xp_translation = $xp_translation + ($indikator * $xp_from_word);
81 }
82 } else {
83 if (($Line[$TextItem['Column']] == $LineComparison[$TextItem['Column']]) and ($Line['Take'] == $LineComparison['ID']) and ($LineComparison[$TextItem['Column']] <> ''))
84 $translated = false;
85 }
86 }
87 if ($translated) $xp = $xp+$xp_translation; //přičítání XP za celý překlad, pokud je celý přeložený
88 }
89 }
90 }
91 return $xp;
92 }
93
94//hlavní kod
95 if ($nothide) $ID = $Database->SQLCommand('SELECT ID,user FROM user');
96 else $ID = $Database->SQLCommand('SELECT ID,user FROM user WHERE NeedUpdate = 1');
97
98while ($LineUser = mysql_fetch_array($ID)) {
99 $xp = GetXPFromTranslation($LineUser['ID']); //načítání XP
100 $Database->SQLCommand('UPDATE user SET XP = '.$xp.' WHERE ID = '.$LineUser['ID']); //ukládání XP pro řazení
101 CreateImg($LineUser['user'],$xp); //vytváření obrázku
102 if ($nothide) echo ('<img src="tmp/'.$LineUser['user'].'/level.png" /><br>');
103}
104 $Database->SQLCommand('UPDATE user SET NeedUpdate = 0');
105
106if ($nothide) ShowFooter();
107
108?>
Note: See TracBrowser for help on using the repository browser.