- Timestamp:
- Sep 12, 2020, 12:04:32 AM (4 years ago)
- Location:
- trunk
- Files:
-
- 8 added
- 3 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/Config.sample.php
r3 r39 12 12 $Config['ItemsPerPage'] = 30; 13 13 $Config['VisiblePagingItems'] = 5; 14 $Config['Locale'] = 'en'; -
trunk/Global.php
r32 r39 16 16 17 17 return $Config['BaseURL'].$URL; 18 } 19 20 function GetRemoteAddress() 21 { 22 if (array_key_exists('REMOTE_ADDR', $_SERVER)) $IP = $_SERVER['REMOTE_ADDR']; 23 else $IP = ''; 24 return $IP; 18 25 } 19 26 -
trunk/index.php
r38 r39 5 5 include_once('Global.php'); 6 6 include_once('Run.php'); 7 include_once('PrefixMultiplier.php'); 7 include_once('Packages/Common/Base.php'); 8 include_once('Packages/Common/PrefixMultiplier.php'); 9 include_once('Packages/Common/Locale.php'); 8 10 9 11 session_start(); 10 12 11 class Application 13 class Application extends System 12 14 { 13 15 var $NoFullPage = false; 14 16 15 function Link($URL)16 {17 return $this->Config['BaseURL'].$URL;18 }19 20 17 function Run() 21 18 { … … 26 23 class MyApplication extends Application 27 24 { 28 var $Database;29 25 var $Config; 30 26 var $LeaderboardURL; 27 var $LocaleManager; 28 var $BaseURL; 29 var $LinkLocaleExceptions; 30 var $Title; 31 31 32 32 function __construct() 33 33 { 34 34 $this->LeaderboardURL = 'https://registrace.teribear.cz/Leaderboard'; 35 $this->BaseURL = ''; 36 $this->LinkLocaleExceptions = array(); 37 $this->Title = ''; 35 38 } 36 39 … … 49 52 function YearList($Path, $SelectedYear, $Table = 'Runner', $Where = '1') 50 53 { 51 $Output = 'Year: ';54 $Output = T('Year').': '; 52 55 $DbResult = $this->Database->query('SELECT DISTINCT(Year) AS Year FROM `'.$Table.'` WHERE '.$Where.' ORDER BY Year ASC'); 53 56 while ($DbRow = $DbResult->fetch_assoc()) … … 63 66 function ItemsYearList($Path, $SelectedId, $Table = 'Runner', $Where = '1') 64 67 { 65 $Output = 'Year: ';68 $Output = T('Year').': '; 66 69 $DbResult = $this->Database->query('SELECT T1.Id AS Id, T2.Year AS Year FROM (SELECT DISTINCT(Id) AS Id FROM `'.$Table.'` WHERE '.$Where.' ORDER BY Year ASC) AS T1 '. 67 70 'LEFT JOIN '.$Table.' AS T2 ON T1.Id=T2.Id'); … … 78 81 { 79 82 $Output = '<div>'. 80 '<a href="'.$this->Link('/').'">Summary</a> '. 81 '<a href="'.$this->Link('/runners/').'">Runners</a> '. 82 '<a href="'.$this->Link('/teams/').'">Teams</a> '. 83 '<a href="'.$this->Link('/families/').'">Families</a> '. 83 '<a href="'.$this->Link('/').'">'.T('Summary').'</a> '. 84 '<a href="'.$this->Link('/runners/').'">'.T('Runners').'</a> '. 85 '<a href="'.$this->Link('/teams/').'">'.T('Teams').'</a> '. 86 '<a href="'.$this->Link('/families/').'">'.T('Families').'</a> '. 87 $this->ShowLocaleSelector(). 84 88 '</div>'; 89 return $Output; 90 } 91 92 function ShowLocaleSelector() 93 { 94 //$Output .= ' <form action="?setlocale" method="get">'; 95 $Output = ' <select onchange="window.location=this.value">'; 96 foreach ($this->LocaleManager->Available as $Locale) 97 { 98 $Remaining = substr($_SERVER["REQUEST_URI"], strlen($this->BaseURL)); 99 if (substr($Remaining, 1, strlen($Locale['Code'].'/')) == $this->LocaleManager->LangCode.'/') 100 $Remaining = substr($Remaining, strlen('/'.$Locale['Code'])); 101 if ($Locale['Code'] == $this->LocaleManager->CurrentLocale->Texts->Code) $Selected = ' selected="selected"'; 102 else $Selected = ''; 103 $Remaining = $this->TranslateReverseURL($Remaining, $this->LocaleManager->LangCode); 104 105 $URL = $this->LinkLocale($Remaining, $Locale['Code']); 106 $Output .= '<option title="" value="'.$URL.'"'.$Selected.' onchange="this.form.submit()">'.$Locale['Title'].'</option>'; 107 } 108 $Output .= '</select><noscript><span><input type="submit" value="Submit"/></span></noscript>'; 109 85 110 return $Output; 86 111 } … … 121 146 { 122 147 $ItemsPerPage = 30; 123 $MaxCount = 450 * 30;148 $MaxCount = 350 * 30; 124 149 if ($Count > 0) $MaxCount = $Count; 125 150 $Result = array(); … … 296 321 } else 297 322 { 298 echo( 'Unsupported type"'.$Item['Type'].'".<br/>');323 echo(T('Unsupported type').' "'.$Item['Type'].'".<br/>'); 299 324 } 300 325 } … … 331 356 //file_put_contents('import/'.$Hash.'.txt', print_r($Items, true)); 332 357 } 358 $Output = T('Data synchronization from leaderboard finished.'); 359 return $Output; 333 360 } 334 361 335 362 function ShowTeams() 336 363 { 337 return $this->ShowTeamsInternal( 'Teams', 'Team', 'teams', 'team', 'Team', '(IsFamily=0)');364 return $this->ShowTeamsInternal(T('Teams'), T('Team'), 'teams', 'team', 'Team', '(IsFamily=0)'); 338 365 } 339 366 340 367 function ShowFamilies() 341 368 { 342 return $this->ShowTeamsInternal( 'Families', 'Family', 'families', 'family', 'Team', '(IsFamily=1)');369 return $this->ShowTeamsInternal(T('Families'), T('Family'), 'families', 'family', 'Team', '(IsFamily=1)'); 343 370 } 344 371 … … 346 373 { 347 374 $Output = ''; 375 $this->Title = $Title.' - '.$this->Title; 348 376 $Output .= '<div class="page-title">'.$Title.'</div>'; 349 377 $Year = $this->GetYear(); … … 354 382 $Where .= ' AND (Name LIKE "%'.addslashes($_GET['query']).'%")'; 355 383 } 356 $Output .= '<div class="section-title">'.$this->YearList('/'.$UrlDir.'/', $Year, $Table).' Name: '.$this->ShowSearch().'</div>';384 $Output .= '<div class="section-title">'.$this->YearList('/'.$UrlDir.'/', $Year, $Table).' '.T('Name').': '.$this->ShowSearch().'</div>'; 357 385 358 386 $DbResult = $this->Database->query('SELECT COUNT(*) FROM `'.$Table.'` WHERE '.$Where); … … 363 391 $Output .= $PageList['Output']; 364 392 $TableColumns = array( 365 array('Name' => 'Name', 'Title' => 'Name'),366 array('Name' => 'RunnersCount', 'Title' => 'Runners'),367 array('Name' => 'Distance', 'Title' => 'Distance'),368 array('Name' => 'Money', 'Title' => 'Money'),369 array('Name' => 'DistanceRunner', 'Title' => 'Distance per runner'),370 array('Name' => 'MoneyRunner', 'Title' => 'Money per runner'),371 array('Name' => 'Rank', 'Title' => 'Rank'),393 array('Name' => 'Name', 'Title' => T('Name')), 394 array('Name' => 'RunnersCount', 'Title' => T('Runners')), 395 array('Name' => 'Distance', 'Title' => T('Distance')), 396 array('Name' => 'Money', 'Title' => T('Money')), 397 array('Name' => 'DistanceRunner', 'Title' => T('Distance per runner')), 398 array('Name' => 'MoneyRunner', 'Title' => T('Money per runner')), 399 array('Name' => 'Rank', 'Title' => T('Rank')), 372 400 ); 373 401 $Order = GetOrderTableHeader($TableColumns, 'Distance', 1); … … 413 441 function ShowTeam() 414 442 { 415 return $this->ShowTeamInternal( 'Team', 'team');443 return $this->ShowTeamInternal(T('Team'), 'team'); 416 444 } 417 445 418 446 function ShowFamily() 419 447 { 420 return $this->ShowTeamInternal( 'Family', 'family');448 return $this->ShowTeamInternal(T('Family'), 'family'); 421 449 } 422 450 … … 428 456 if ((count($this->PathItems) > 0) and ($this->PathItems[count($this->PathItems) - 1] != '')) 429 457 $TeamId = $this->PathItems[count($this->PathItems) - 1]; 430 if (!is_numeric($TeamId)) die( 'TeamId needs to be numeric');458 if (!is_numeric($TeamId)) die(T('Team id needs to be numeric')); 431 459 432 460 $DbResult = $this->Database->query('SELECT Team.*, '. … … 437 465 'FROM Team WHERE Id='.$TeamId); 438 466 $DbRow = $DbResult->fetch_assoc(); 467 $this->Title = $Title.' '.$DbRow['Name'].' - '.$this->Title; 439 468 $Output .= '<div class="page-title">'.$Title.' '.$DbRow['Name'].'</div>'; 440 469 $Output .= '<div class="section-title">'.$this->ItemsYearList('/'.$UrlDir.'/', $TeamId, 'Team', 'Name="'.$DbRow['Name'].'"').'</div>'; 441 $Output .= '<div class="section-title">Runners: '.$DbRow['RunnerCount'].', Distance: '.$DbRow['Distance'].' km, Money: '.$DbRow['Money'].' Kč, Rank: '.$DbRow['Rank'].'</div>'; 470 $Output .= '<div class="section-title">'. 471 T('Runners').': '.$DbRow['RunnerCount'].', '. 472 T('Distance').': '.$DbRow['Distance'].' km, '. 473 T('Money').': '.$DbRow['Money'].' Kč, '. 474 T('Rank').': '.$DbRow['Rank'].'</div>'; 442 475 443 476 $Where = 'Team='.$TeamId; … … 448 481 $PageList = GetPageList($DbRow[0]); 449 482 450 $Gender = array('', 'Men', 'Woman', 'Kid');483 $Gender = array('', T('Man'), T('Woman'), T('Kid')); 451 484 $Output .= '<div id="list_content">'; 452 485 $Output .= $PageList['Output']; 453 486 $TableColumns = array( 454 array('Name' => 'Name', 'Title' => 'Name'),455 array('Name' => 'Gender', 'Title' => 'Category'),456 array('Name' => 'Distance', 'Title' => 'Distance'),457 array('Name' => 'Money', 'Title' => 'Money'),458 array('Name' => 'Rank', 'Title' => 'Rank'),459 array('Name' => 'Time', 'Title' => 'Last change'),487 array('Name' => 'Name', 'Title' => T('Name')), 488 array('Name' => 'Gender', 'Title' => T('Category')), 489 array('Name' => 'Distance', 'Title' => T('Distance')), 490 array('Name' => 'Money', 'Title' => T('Money')), 491 array('Name' => 'Rank', 'Title' => T('Rank')), 492 array('Name' => 'Time', 'Title' => T('Last change')), 460 493 ); 461 494 $Order = GetOrderTableHeader($TableColumns, 'Distance', 1); … … 493 526 $PrefixMultiplier = new PrefixMultiplier(); 494 527 495 $Output = '<div class="section-title"> Lap progress</div>';528 $Output = '<div class="section-title">'.T('Lap progress').'</div>'; 496 529 $Where = $Table.'Stat.'.$Table.'='.$Id; 497 530 $DbResult = $this->Database->query('SELECT COUNT(*) FROM `'.$Table.'Stat` WHERE '.$Where); … … 502 535 $Output .= $PageList['Output']; 503 536 $TableColumns = array( 504 array('Name' => 'Time', 'Title' => 'Time'),505 array('Name' => 'Distance', 'Title' => 'Distance[km]'),506 array('Name' => 'Money', 'Title' => 'Money[Kč]'),507 array('Name' => 'Rank', 'Title' => 'Rank'),508 array('Name' => 'Duration', 'Title' => 'Duration'),509 array('Name' => 'Length', 'Title' => 'Length[km]'),510 array('Name' => 'Speed', 'Title' => 'Speed [km/hour]'),537 array('Name' => 'Time', 'Title' => T('Time')), 538 array('Name' => 'Distance', 'Title' => T('Distance').' [km]'), 539 array('Name' => 'Money', 'Title' => T('Money').' [Kč]'), 540 array('Name' => 'Rank', 'Title' => T('Rank')), 541 array('Name' => 'Duration', 'Title' => T('Duration')), 542 array('Name' => 'Length', 'Title' => T('Length').' [km]'), 543 array('Name' => 'Speed', 'Title' => T('Speed').' [km/'.T('hour').']'), 511 544 ); 512 545 $Order = GetOrderTableHeader($TableColumns, 'Time', 1); … … 550 583 $PageList = GetPageList($DbRow[0]); 551 584 552 $Output = '<div class="section-title"> Daily progress</div>';585 $Output = '<div class="section-title">'.T('Daily progress').'</div>'; 553 586 $Output .= '<div id="list_content">'; 554 587 $Output .= $PageList['Output']; 555 588 $TableColumns = array( 556 array('Name' => 'Time', 'Title' => 'Time'),557 array('Name' => 'Distance', 'Title' => 'Distance[km]'),558 array('Name' => 'Money', 'Title' => 'Money[Kč]'),559 array('Name' => 'Rank', 'Title' => 'Rank'),560 array('Name' => 'Duration', 'Title' => 'Duration'),561 array('Name' => 'Length', 'Title' => 'Length[km]'),562 array('Name' => 'Speed', 'Title' => 'Speed [km/hour]'),589 array('Name' => 'Time', 'Title' => T('Time')), 590 array('Name' => 'Distance', 'Title' => T('Distance').' [km]'), 591 array('Name' => 'Money', 'Title' => T('Money').' [Kč]'), 592 array('Name' => 'Rank', 'Title' => T('Rank')), 593 array('Name' => 'Duration', 'Title' => T('Duration')), 594 array('Name' => 'Length', 'Title' => T('Length').' [km]'), 595 array('Name' => 'Speed', 'Title' => T('Speed').' [km/'.T('hour').']'), 563 596 ); 564 597 $Order = GetOrderTableHeader($TableColumns, 'Time', 1); … … 597 630 $Output = '<form action="?" method="get" style="display: inline;">'; 598 631 $Output .= '<input type="text" size="10" name="query" value="'.$Query.'"/> '. 599 '<input type="submit" value=" Search"/>';632 '<input type="submit" value="'.T('Search').'"/>'; 600 633 $Output .= '</form>'; 601 634 return $Output; … … 604 637 function ShowRunners() 605 638 { 606 $Output = '<div class="page-title">Runners</div>'; 639 $this->Title = T('Runners').' - '.$this->Title; 640 $Output = '<div class="page-title">'.T('Runners').'</div>'; 607 641 $Year = $this->GetYear(); 608 642 609 $Output .= '<div class="section-title">'.$this->YearList('/runners/', $Year, 'Runner').' Name: '.$this->ShowSearch().'</div>';643 $Output .= '<div class="section-title">'.$this->YearList('/runners/', $Year, 'Runner').' '.T('Name').': '.$this->ShowSearch().'</div>'; 610 644 $Where = '(Year='.$Year.')'; 611 645 if (array_key_exists('query', $_GET) and ($_GET['query'] != '')) … … 618 652 $PageList = GetPageList($DbRow[0]); 619 653 620 $Gender = array('', 'Man', 'Woman', 'Kid');654 $Gender = array('', T('Man'), T('Woman'), T('Kid')); 621 655 $Output .= '<div id="list_content">'; 622 656 $Output .= $PageList['Output']; 623 657 $TableColumns = array( 624 array('Name' => 'Name', 'Title' => 'Name'),625 array('Name' => 'Gender', 'Title' => 'Category'),626 array('Name' => 'Distance', 'Title' => 'Distance'),627 array('Name' => 'Money', 'Title' => 'Money'),628 array('Name' => 'Rank', 'Title' => 'Rank'),629 array('Name' => 'Time', 'Title' => 'Last change'),658 array('Name' => 'Name', 'Title' => T('Name')), 659 array('Name' => 'Gender', 'Title' => T('Category')), 660 array('Name' => 'Distance', 'Title' => T('Distance')), 661 array('Name' => 'Money', 'Title' => T('Money')), 662 array('Name' => 'Rank', 'Title' => T('Rank')), 663 array('Name' => 'Time', 'Title' => T('Last change')), 630 664 ); 631 665 $Order = GetOrderTableHeader($TableColumns, 'Distance', 1); … … 664 698 if ((count($this->PathItems) > 0) and ($this->PathItems[count($this->PathItems) - 1] != '')) 665 699 $RunnerId = $this->PathItems[count($this->PathItems) - 1]; 666 if (!is_numeric($RunnerId)) die( 'Runner id needs to be numeric');700 if (!is_numeric($RunnerId)) die(T('Runner id needs to be numeric')); 667 701 668 702 $DbResult = $this->Database->query('SELECT Runner.Name, Team.Name AS TeamName, Team.Id AS TeamId FROM Runner LEFT JOIN Team ON Team.Id=Runner.Team WHERE Runner.Id='.$RunnerId); 669 703 $DbRow = $DbResult->fetch_assoc(); 670 $Output .= '<div class="page-title">Runner '.$DbRow['Name'].'</div>'; 704 $this->Title = T('Runner').' '.$DbRow['Name'].' - '.$this->Title; 705 $Output .= '<div class="page-title">'.T('Runner').' '.$DbRow['Name'].'</div>'; 671 706 if ($DbRow['TeamName'] != '') 672 707 $Output .= '<div class="section-title"><a href="'.$this->Link('/team/'.$DbRow['TeamId']).'">'.$DbRow['TeamName'].'</a></div>'; … … 703 738 { 704 739 $Output = ''; 705 $Output .= '<p> This website collects data from official <a href="'.$this->LeaderboardURL.'">leaderboard</a> site and tracks and presents progress of runners and teams.</p>';706 $Output .= '<div class="page-title"> Summary</div>';740 $Output .= '<p>'.sprintf(T('This website collects data from official <a href="%s">leaderboard</a> site and tracks and presents progress of runners and teams.'), $this->LeaderboardURL).'</p>'; 741 $Output .= '<div class="page-title">'.T('Summary').'</div>'; 707 742 $Year = $this->GetYear(); 708 743 … … 717 752 718 753 $Output .= '<table class="WideTable">'; 719 $Output .= '<tr><th> Category</th><th>Count</th><th>Distance [km]</th><th>Money[Kč]</th></tr>';720 $Output .= '<tr><td> Everyone</td><td>'.$Runners['TotalCount'].'</td><td>'.$Runners['TotalDistance'].'</td><td>'.$Runners['TotalMoney'].'</td></tr>';721 $Output .= '<tr><td> Men</td><td>'.$Men['TotalCount'].'</td><td>'.$Men['TotalDistance'].'</td><td>'.$Men['TotalMoney'].'</td></tr>';722 $Output .= '<tr><td> Women</td><td>'.$Women['TotalCount'].'</td><td>'.$Women['TotalDistance'].'</td><td>'.$Women['TotalMoney'].'</td></tr>';723 $Output .= '<tr><td> Kids</td><td>'.$Kids['TotalCount'].'</td><td>'.$Kids['TotalDistance'].'</td><td>'.$Kids['TotalMoney'].'</td></tr>';724 $Output .= '<tr><td> Teams</td><td>'.$Teams['TotalCount'].'</td><td>'.$Teams['TotalDistance'].'</td><td>'.$Teams['TotalMoney'].'</td></tr>';725 $Output .= '<tr><td> Families</td><td>'.$Families['TotalCount'].'</td><td>'.$Families['TotalDistance'].'</td><td>'.$Families['TotalMoney'].'</td></tr>';754 $Output .= '<tr><th>'.T('Category').'</th><th>'.T('Count').'</th><th>'.T('Distance').' [km]</th><th>'.T('Money').' [Kč]</th></tr>'; 755 $Output .= '<tr><td>'.T('Everyone').'</td><td>'.$Runners['TotalCount'].'</td><td>'.$Runners['TotalDistance'].'</td><td>'.$Runners['TotalMoney'].'</td></tr>'; 756 $Output .= '<tr><td>'.T('Men').'</td><td>'.$Men['TotalCount'].'</td><td>'.$Men['TotalDistance'].'</td><td>'.$Men['TotalMoney'].'</td></tr>'; 757 $Output .= '<tr><td>'.T('Women').'</td><td>'.$Women['TotalCount'].'</td><td>'.$Women['TotalDistance'].'</td><td>'.$Women['TotalMoney'].'</td></tr>'; 758 $Output .= '<tr><td>'.T('Kids').'</td><td>'.$Kids['TotalCount'].'</td><td>'.$Kids['TotalDistance'].'</td><td>'.$Kids['TotalMoney'].'</td></tr>'; 759 $Output .= '<tr><td>'.T('Teams').'</td><td>'.$Teams['TotalCount'].'</td><td>'.$Teams['TotalDistance'].'</td><td>'.$Teams['TotalMoney'].'</td></tr>'; 760 $Output .= '<tr><td>'.T('Families').'</td><td>'.$Families['TotalCount'].'</td><td>'.$Families['TotalDistance'].'</td><td>'.$Families['TotalMoney'].'</td></tr>'; 726 761 $Output .= '</table>'; 727 762 … … 738 773 '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.$Lang.'" lang="'.$Lang.'">'. 739 774 '<head>'. 740 '<link rel="stylesheet" href="'.$this->Link('/style .css').'" type="text/css" media="all" />'.775 '<link rel="stylesheet" href="'.$this->Link('/style/style.css').'" type="text/css" media="all" />'. 741 776 '<meta http-equiv="content-type" content="application/xhtml+xml; charset='.$this->Config['Encoding'].'" />'. 742 '<meta name="viewport" content="width=device-width, initial-scale=1">' .743 '<script src="'.$this->Link('/jquery.js').'"></script>';744 $Output .= '<title> Teribear stats</title>'.777 '<meta name="viewport" content="width=device-width, initial-scale=1">'; 778 //'<script src="'.$this->Link('/jquery.js').'"></script>'; 779 $Output .= '<title>'.$this->Title.'</title>'. 745 780 '</head><body>'; 746 781 $Output .= $Content; 747 $Output .= '<br/><div class="footer"> Contact: <a href="mailto:'.$Config['Contact'].'">'.$Config['Contact'].'</a> '.748 '<a href="https://app.zdechov.net/teribear/"> Source code</a></div>';782 $Output .= '<br/><div class="footer">'.T('Contact').': <a href="mailto:'.$Config['Contact'].'">'.$Config['Contact'].'</a> '. 783 '<a href="https://app.zdechov.net/teribear/">'.T('Source code').'</a></div>'; 749 784 $Output .= '</body></html>'; 750 785 return $Output; 751 786 } 752 787 788 function Link($Target) 789 { 790 if (substr($Target, 0, strlen($this->BaseURL)) == $this->BaseURL) 791 $Remaining = substr($Target, strlen($this->BaseURL)); 792 else $Remaining = $Target; 793 $TargetParts = explode('/', $Remaining); 794 if ((count($TargetParts) > 0) and ($TargetParts[0] == '')) 795 array_splice($TargetParts, 0, 1); 796 if (count($TargetParts) > 0) 797 { 798 if (in_array($TargetParts[0], $this->LinkLocaleExceptions)) 799 { 800 $Result = $this->BaseURL.$Target; 801 } else $Result = $this->LinkLocale($Target); 802 } else $Result = $this->LinkLocale($Target); 803 return $Result; 804 } 805 806 function TranslateURL($URL, $Locale) 807 { 808 // Try translate URL directory parts from current locale to target locale 809 $Remaining = $URL; 810 $RemainingParts = explode('?', $Remaining); 811 $Directory = $RemainingParts[0]; 812 if (count($RemainingParts) > 1) 813 { 814 $Params = $RemainingParts[1]; 815 } else 816 { 817 $Params = ''; 818 } 819 $TargetLocaleManager = new LocaleManager($this); 820 $TargetLocaleManager->Dir = $this->LocaleManager->Dir; 821 $TargetLocaleManager->Available = $this->LocaleManager->Available; 822 $TargetLocaleManager->LoadLocale($Locale); 823 824 $DirectoryParts = explode('/', $Directory); 825 foreach ($DirectoryParts as $Index => $Item) 826 { 827 $NewText = $TargetLocaleManager->CurrentLocale->Texts->Translate($Item, 'URL'); 828 $DirectoryParts[$Index] = $NewText; 829 } 830 $Directory = implode('/', $DirectoryParts); 831 $Remaining = $Directory; 832 if ($Params != '') $Remaining .= '?'.$Params; 833 834 return $Remaining; 835 } 836 837 function TranslateReverseURL($URL, $Locale) 838 { 839 // Try translate URL directory parts from current locale to target locale 840 $Remaining = $URL; 841 $RemainingParts = explode('?', $Remaining); 842 $Directory = $RemainingParts[0]; 843 if (count($RemainingParts) > 1) 844 { 845 $Params = $RemainingParts[1]; 846 } else { 847 $Params = ''; 848 } 849 $TargetLocaleManager = new LocaleManager($this); 850 $TargetLocaleManager->Dir = $this->LocaleManager->Dir; 851 $TargetLocaleManager->Available = $this->LocaleManager->Available; 852 $TargetLocaleManager->LoadLocale($Locale); 853 854 $DirectoryParts = explode('/', $Directory); 855 foreach ($DirectoryParts as $Index => $Item) 856 { 857 $NewText = $TargetLocaleManager->CurrentLocale->Texts->TranslateReverse($Item, 'URL'); 858 $DirectoryParts[$Index] = $NewText; 859 } 860 $Directory = implode('/', $DirectoryParts); 861 $Remaining = $Directory; 862 if ($Params != '') $Remaining .= '?'.$Params; 863 864 return $Remaining; 865 } 866 867 function LinkLocale($Target, $Locale = '') 868 { 869 if ($Locale == '') $Locale = $this->LocaleManager->LangCode; 870 871 $Target = $this->TranslateURL($Target, $Locale); 872 873 if ($Locale == $this->LocaleManager->DefaultLangCode) 874 return $this->BaseURL.$Target; 875 return $this->BaseURL.'/'.$Locale.$Target; 876 } 877 753 878 function Run() 754 879 { 755 global $Config ;880 global $Config, $GlobalLocaleManager; 756 881 757 882 $this->Config = $Config; … … 763 888 //$this->Database->ShowSQLError = true; 764 889 //$this->Database->ShowSQLQuery = true; 890 891 $this->LocaleManager = new LocaleManager($this); 892 $this->LocaleManager->Dir = dirname(__FILE__).'/Locale'; 893 $this->LocaleManager->Available = array( 894 'cs' => array('Code' => 'cs', 'Title' => 'Česky'), 895 'en' => array('Code' => 'en', 'Title' => 'English'), 896 ); 897 $GlobalLocaleManager = $this->LocaleManager; 898 $this->LinkLocaleExceptions = array('style'); 899 765 900 $this->PathItems = $this->ProcessURL(); 766 901 902 // Detect interface locale 903 if (isset($this->Config['Locale'])) 904 $this->LocaleManager->DefaultLangCode = $this->Config['Locale']; 905 $this->LocaleManager->LangCode = $this->LocaleManager->DefaultLangCode; 906 if (count($this->PathItems) > 0) 907 { 908 $NewLangCode = $this->PathItems[0]; 909 if (array_key_exists($NewLangCode, $this->LocaleManager->Available)) 910 { 911 array_shift($this->PathItems); 912 $this->LocaleManager->LangCode = $NewLangCode; 913 } 914 } 915 if (array_key_exists($this->LocaleManager->LangCode, $this->LocaleManager->Available)) 916 { 917 $this->LocaleManager->LoadLocale($this->LocaleManager->LangCode); 918 } 919 920 if (GetRemoteAddress() != '') 921 { 922 $this->BaseURL = $_SERVER["CONTEXT_PREFIX"]; 923 if (substr($this->BaseURL, -1, 1) == '/') $this->BaseURL = substr($this->BaseURL, 0, -1); 924 } 925 926 $this->Title = T('Teribear stats'); 767 927 $Output = ''; 768 928 … … 771 931 { 772 932 $Item = $this->PathItems[0]; 933 $Item = $this->LocaleManager->CurrentLocale->Texts->TranslateReverse($Item, 'URL'); 773 934 if ($Item == 'sync') $Output .= $this->ShowSync(); 774 935 //else if ($this->PathItems[0] == 'empty') $Output .= $this->ShowEmpty();
Note:
See TracChangeset
for help on using the changeset viewer.