Changeset 39 for trunk/index.php


Ignore:
Timestamp:
Sep 12, 2020, 12:04:32 AM (4 years ago)
Author:
chronos
Message:
  • Added: Support for locales and czech language. It can be switched on from top language selector.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/index.php

    r38 r39  
    55include_once('Global.php');
    66include_once('Run.php');
    7 include_once('PrefixMultiplier.php');
     7include_once('Packages/Common/Base.php');
     8include_once('Packages/Common/PrefixMultiplier.php');
     9include_once('Packages/Common/Locale.php');
    810
    911session_start();
    1012
    11 class Application
     13class Application extends System
    1214{
    1315  var $NoFullPage = false;
    1416
    15   function Link($URL)
    16   {
    17     return $this->Config['BaseURL'].$URL;
    18   }
    19 
    2017  function Run()
    2118  {
     
    2623class MyApplication extends Application
    2724{
    28   var $Database;
    2925  var $Config;
    3026  var $LeaderboardURL;
     27  var $LocaleManager;
     28  var $BaseURL;
     29  var $LinkLocaleExceptions;
     30  var $Title;
    3131
    3232  function __construct()
    3333  {
    3434    $this->LeaderboardURL = 'https://registrace.teribear.cz/Leaderboard';
     35    $this->BaseURL = '';
     36    $this->LinkLocaleExceptions = array();
     37    $this->Title = '';
    3538  }
    3639
     
    4952  function YearList($Path, $SelectedYear, $Table = 'Runner', $Where = '1')
    5053  {
    51     $Output = 'Year: ';
     54    $Output = T('Year').': ';
    5255    $DbResult = $this->Database->query('SELECT DISTINCT(Year) AS Year FROM `'.$Table.'` WHERE '.$Where.' ORDER BY Year ASC');
    5356    while ($DbRow = $DbResult->fetch_assoc())
     
    6366  function ItemsYearList($Path, $SelectedId, $Table = 'Runner', $Where = '1')
    6467  {
    65     $Output = 'Year: ';
     68    $Output = T('Year').': ';
    6669    $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 '.
    6770      'LEFT JOIN '.$Table.' AS T2 ON T1.Id=T2.Id');
     
    7881  {
    7982    $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().
    8488      '</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
    85110    return $Output;
    86111  }
     
    121146  {
    122147    $ItemsPerPage = 30;
    123     $MaxCount = 450 * 30;
     148    $MaxCount = 350 * 30;
    124149    if ($Count > 0) $MaxCount = $Count;
    125150    $Result = array();
     
    296321      } else
    297322      {
    298         echo('Unsupported type "'.$Item['Type'].'".<br/>');
     323        echo(T('Unsupported type').' "'.$Item['Type'].'".<br/>');
    299324      }
    300325    }
     
    331356      //file_put_contents('import/'.$Hash.'.txt', print_r($Items, true));
    332357    }
     358    $Output = T('Data synchronization from leaderboard finished.');
     359    return $Output;
    333360  }
    334361
    335362  function ShowTeams()
    336363  {
    337     return $this->ShowTeamsInternal('Teams', 'Team', 'teams', 'team', 'Team', '(IsFamily=0)');
     364    return $this->ShowTeamsInternal(T('Teams'), T('Team'), 'teams', 'team', 'Team', '(IsFamily=0)');
    338365  }
    339366
    340367  function ShowFamilies()
    341368  {
    342     return $this->ShowTeamsInternal('Families', 'Family', 'families', 'family', 'Team', '(IsFamily=1)');
     369    return $this->ShowTeamsInternal(T('Families'), T('Family'), 'families', 'family', 'Team', '(IsFamily=1)');
    343370  }
    344371
     
    346373  {
    347374    $Output = '';
     375    $this->Title = $Title.' - '.$this->Title;
    348376    $Output .= '<div class="page-title">'.$Title.'</div>';
    349377    $Year = $this->GetYear();
     
    354382      $Where .= ' AND (Name LIKE "%'.addslashes($_GET['query']).'%")';
    355383    }
    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>';
    357385
    358386    $DbResult = $this->Database->query('SELECT COUNT(*) FROM `'.$Table.'` WHERE '.$Where);
     
    363391    $Output .= $PageList['Output'];
    364392    $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')),
    372400    );
    373401    $Order = GetOrderTableHeader($TableColumns, 'Distance', 1);
     
    413441  function ShowTeam()
    414442  {
    415     return $this->ShowTeamInternal('Team', 'team');
     443    return $this->ShowTeamInternal(T('Team'), 'team');
    416444  }
    417445
    418446  function ShowFamily()
    419447  {
    420     return $this->ShowTeamInternal('Family', 'family');
     448    return $this->ShowTeamInternal(T('Family'), 'family');
    421449  }
    422450
     
    428456    if ((count($this->PathItems) > 0) and ($this->PathItems[count($this->PathItems) - 1] != ''))
    429457      $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'));
    431459
    432460    $DbResult = $this->Database->query('SELECT Team.*, '.
     
    437465      'FROM Team WHERE Id='.$TeamId);
    438466    $DbRow = $DbResult->fetch_assoc();
     467    $this->Title = $Title.' '.$DbRow['Name'].' - '.$this->Title;
    439468    $Output .= '<div class="page-title">'.$Title.' '.$DbRow['Name'].'</div>';
    440469    $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>';
    442475
    443476    $Where = 'Team='.$TeamId;
     
    448481    $PageList = GetPageList($DbRow[0]);
    449482
    450     $Gender = array('', 'Men', 'Woman', 'Kid');
     483    $Gender = array('', T('Man'), T('Woman'), T('Kid'));
    451484    $Output .= '<div id="list_content">';
    452485    $Output .= $PageList['Output'];
    453486    $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')),
    460493    );
    461494    $Order = GetOrderTableHeader($TableColumns, 'Distance', 1);
     
    493526    $PrefixMultiplier = new PrefixMultiplier();
    494527
    495     $Output = '<div class="section-title">Lap progress</div>';
     528    $Output = '<div class="section-title">'.T('Lap progress').'</div>';
    496529    $Where = $Table.'Stat.'.$Table.'='.$Id;
    497530    $DbResult = $this->Database->query('SELECT COUNT(*) FROM `'.$Table.'Stat` WHERE '.$Where);
     
    502535    $Output .= $PageList['Output'];
    503536    $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').']'),
    511544    );
    512545    $Order = GetOrderTableHeader($TableColumns, 'Time', 1);
     
    550583    $PageList = GetPageList($DbRow[0]);
    551584
    552     $Output = '<div class="section-title">Daily progress</div>';
     585    $Output = '<div class="section-title">'.T('Daily progress').'</div>';
    553586    $Output .= '<div id="list_content">';
    554587    $Output .= $PageList['Output'];
    555588    $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').']'),
    563596    );
    564597    $Order = GetOrderTableHeader($TableColumns, 'Time', 1);
     
    597630    $Output = '<form action="?" method="get" style="display: inline;">';
    598631    $Output .= '<input type="text" size="10" name="query" value="'.$Query.'"/> '.
    599       '<input type="submit" value="Search"/>';
     632      '<input type="submit" value="'.T('Search').'"/>';
    600633    $Output .= '</form>';
    601634    return $Output;
     
    604637  function ShowRunners()
    605638  {
    606     $Output = '<div class="page-title">Runners</div>';
     639    $this->Title = T('Runners').' - '.$this->Title;
     640    $Output = '<div class="page-title">'.T('Runners').'</div>';
    607641    $Year = $this->GetYear();
    608642
    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>';
    610644    $Where = '(Year='.$Year.')';
    611645    if (array_key_exists('query', $_GET) and ($_GET['query'] != ''))
     
    618652    $PageList = GetPageList($DbRow[0]);
    619653
    620     $Gender = array('', 'Man', 'Woman', 'Kid');
     654    $Gender = array('', T('Man'), T('Woman'), T('Kid'));
    621655    $Output .= '<div id="list_content">';
    622656    $Output .= $PageList['Output'];
    623657    $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')),
    630664    );
    631665    $Order = GetOrderTableHeader($TableColumns, 'Distance', 1);
     
    664698    if ((count($this->PathItems) > 0) and ($this->PathItems[count($this->PathItems) - 1] != ''))
    665699      $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'));
    667701
    668702    $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);
    669703    $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>';
    671706    if ($DbRow['TeamName'] != '')
    672707      $Output .= '<div class="section-title"><a href="'.$this->Link('/team/'.$DbRow['TeamId']).'">'.$DbRow['TeamName'].'</a></div>';
     
    703738  {
    704739    $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>';
    707742    $Year = $this->GetYear();
    708743
     
    717752
    718753    $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>';
    726761    $Output .= '</table>';
    727762
     
    738773      '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.$Lang.'" lang="'.$Lang.'">'.
    739774      '<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" />'.
    741776      '<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>'.
    745780      '</head><body>';
    746781    $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>';
    749784    $Output .= '</body></html>';
    750785    return $Output;
    751786  }
    752787
     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
    753878  function Run()
    754879  {
    755     global $Config;
     880    global $Config, $GlobalLocaleManager;
    756881
    757882    $this->Config = $Config;
     
    763888    //$this->Database->ShowSQLError = true;
    764889    //$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
    765900    $this->PathItems = $this->ProcessURL();
    766901
     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');
    767927    $Output = '';
    768928
     
    771931    {
    772932      $Item = $this->PathItems[0];
     933      $Item = $this->LocaleManager->CurrentLocale->Texts->TranslateReverse($Item, 'URL');
    773934      if ($Item == 'sync') $Output .= $this->ShowSync();
    774935      //else if ($this->PathItems[0] == 'empty') $Output .= $this->ShowEmpty();
Note: See TracChangeset for help on using the changeset viewer.