Changeset 545


Ignore:
Timestamp:
Jun 18, 2013, 6:07:52 PM (11 years ago)
Author:
chronos
Message:
  • Přidáno: Prvotní podpora pro modulární systém.
  • Přidáno: Podpora pro používání pěkných URL.
  • Upraveno: Vstupní stránka se generuje z modulu FrontPage.
  • Upraveno: Stránka banners převedena na modul Referrer.
Location:
trunk
Files:
9 added
1 deleted
7 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore
      •  

        old new  
        55.project
        66.buildpath
         7Query.log
  • trunk/TranslationList.php

    r544 r545  
    109109  }
    110110  $Output .= '</select></td>';
    111   if($Filter['Language'] != 0) $LanguageFilter = ' AND (`Language` = '.$Filter['Language'].')';
     111  if($Filter['Language'] != 0) $LanguageFilter = ' AND (`T`.`Language` = '.$Filter['Language'].')';
    112112    else $LanguageFilter = '';
    113113
     
    153153  {
    154154    if($Filter['State'] == 0) $Filter['SQL'] .= $UserFilter.$VersionFilter.'';
    155     else if($Filter['State'] == 1) $Filter['SQL'] .= $VersionFilter.' AND (`Language` = '.$Config['OriginalLanguage'].') '.
     155    else if($Filter['State'] == 1) $Filter['SQL'] .= $VersionFilter.' AND (`T`.`Language` = '.$Config['OriginalLanguage'].') '.
    156156      'AND NOT EXISTS(SELECT 1 FROM `'.$Table.'` AS `Sub` WHERE '.
    157157      '(`Sub`.`Language` <> '.$Config['OriginalLanguage'].')'.$LanguageFilter.$UserFilter.
  • trunk/includes/Page.php

    r542 r545  
    11<?php
    2 
    3 function ShowShoutbox()
    4 {
    5   global $System, $Config, $User, $System;
    6  
    7   $Output = '<strong><a href="'.$System->Link('/action.php?action=ShoutBoxView').'">Kecátko:</a></strong>';
    8   if($User->Licence(LICENCE_USER))
    9     $Output .= ' <a href="'.$System->Link('/action.php?action=shoutbox').'">Vložit</a>';
    10   $Output .= '<div class="box"><table>';
    11   $DbResult = $System->Database->query('SELECT * FROM `ShoutBox` ORDER BY `ID` DESC LIMIT 30');
    12   while($Line = $DbResult->fetch_assoc())
    13     $Output .= '<tr><td><strong>'.$Line['UserName'].'</strong>: '.MakeActiveLinks($Line['Text']).'</td></tr>';
    14   $Output .= '</table></div>';
    15   return($Output);
    16 }
    172
    183function ShowTopBar()
     
    340325}
    341326
     327class Page
     328{
     329  var $System;
     330  var $Database;
     331 
     332  function __construct($System)
     333  {
     334    $this->System = &$System;
     335    $this->Database = &$System->Database;   
     336  }
     337       
     338        function Show()
     339        {
     340                return('');
     341  }
     342 
     343  function GetOutput()
     344  {
     345        $Output = $this->Show();
     346        $Output = ShowPage($Output);     
     347        return($Output);
     348  }
     349}
     350
    342351?>
  • trunk/includes/Version.php

    r543 r545  
    11<?php
    22
    3 $Revision = 543; // Subversion revision
     3$Revision = 545; // Subversion revision
    44$DatabaseRevision = 543; // Database structure revision
    5 $ReleaseTime = '2013-06-17';
     5$ReleaseTime = '2013-06-18';
    66
    77?>
  • trunk/includes/global.php

    r538 r545  
    1111  include_once(dirname(__FILE__).'/config.php');
    1212include_once(dirname(__FILE__).'/Version.php');
     13include_once(dirname(__FILE__).'/AppModule.php');
     14
     15// Include application modules
     16// TODO: Make modules configurable
     17include_once(dirname(__FILE__).'/../Modules/AoWoW/AoWoW.php');
     18include_once(dirname(__FILE__).'/../Modules/Referrer/Referrer.php');
     19include_once(dirname(__FILE__).'/../Modules/FrontPage/FrontPage.php');
    1320
    1421GlobalInit();
     
    5259  // TODO: Global initialized variable should be removed
    5360  $TranslationTree = GetTranslationTree();
    54 
    55   LogReferrer();
     61 
     62  // Initialize application modules
     63  $System->ModuleManager->RegisterModule(new AoWoW($System));
     64  $System->ModuleManager->RegisterModule(new Referrer($System));
     65  $System->ModuleManager->Modules['Referrer']->Excluded[] = $System->Config['Web']['Host'];
     66  $System->ModuleManager->RegisterModule(new FrontPage($System));
     67  $System->ModuleManager->StartAll();
    5668}
    5769
     
    633645  if($Session) $_SESSION[$Name] = $Result;
    634646  return($Result);
    635 }
    636 
    637 function LogReferrer()
    638 {
    639   global $System;
    640 
    641   if(array_key_exists('HTTP_REFERER', $_SERVER))
    642   {
    643     $Referrer = addslashes($_SERVER['HTTP_REFERER']);
    644     $HostName = substr($Referrer, strpos($Referrer, '/') + 2);
    645     $HostName = substr($HostName, 0, strpos($HostName, '/'));
    646     if($HostName != $System->Config['Web']['Host'])
    647     {
    648       $DbResult = $System->Database->query('SELECT `Id` FROM `Referrer` WHERE `Web` = "'.$HostName.'"');
    649       if($DbResult->num_rows > 0)
    650       {
    651         $DbRow = $DbResult->fetch_assoc();
    652         $System->Database->query('UPDATE `Referrer` SET `Hits` = `Hits` + 1, `DateLast` = NOW(), `LastURL` = "'.addslashes($Referrer).'" WHERE `Id` = '.$DbRow['Id']);
    653       } else $System->Database->query('INSERT INTO `Referrer` (`Web`, `DateFirst`, `DateLast`, `LastURL`, `Hits`) VALUES ("'.$HostName.'", NOW(), NOW( ), "'.addslashes($Referrer).'", 1)');
    654     }
    655   }
    656647}
    657648
     
    744735}
    745736
     737function ProcessURL()
     738{
     739        if(array_key_exists('REDIRECT_QUERY_STRING', $_SERVER))
     740                $PathString = $_SERVER['REDIRECT_QUERY_STRING'];
     741        else $PathString = '';
     742        if(substr($PathString, -1, 1) == '/') $PathString = substr($PathString, 0, -1);
     743        $PathItems = explode('/', $PathString);
     744        if(strpos($_SERVER['REQUEST_URI'], '?') !== false)
     745                $_SERVER['QUERY_STRING'] = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], '?') + 1);
     746        else $_SERVER['QUERY_STRING'] = '';
     747        parse_str($_SERVER['QUERY_STRING'], $_GET);
     748        return($PathItems);
     749}
     750
    746751?>
  • trunk/includes/system.php

    r542 r545  
    2121  var $Database;
    2222  var $Config;
     23  var $ModuleManager;
     24  var $PathItems;
    2325 
    2426  function __construct()
     
    4042    $this->Database->ShowSQLError = $this->Config['Web']['ShowSQLError'];
    4143    $this->Database->LogSQLQuery = $this->Config['Web']['LogSQLQuery'];
     44    $this->ModuleManager = new AppModuleManager();
    4245  }
    4346 
     
    5053  function Link($Target)
    5154  {
    52     global $Config;
    53    
    54     return($Config['Web']['BaseURL'].$Target);
     55    return($this->Config['Web']['BaseURL'].$Target);
    5556  }
     57 
     58  function RegisterPage($Path, $Handler)
     59  {
     60    if(is_array($Path))
     61    {
     62      $Page = &$this->Pages;
     63      $LastKey = array_pop($Path);
     64      foreach($Path as $PathItem)
     65      {
     66        $Page = &$Page[$PathItem];       
     67      }
     68      if(!is_array($Page)) $Page = array('' => $Page);
     69      $Page[$LastKey] = $Handler;
     70    } else $this->Pages[$Path] = $Handler;
     71  }
     72 
     73  function SearchPage($PathItems, $Pages)
     74  {
     75    if(count($PathItems) > 0) $PathItem = $PathItems[0];
     76      else $PathItem = '';
     77    if(array_key_exists($PathItem, $Pages))
     78    {
     79      if(is_array($Pages[$PathItem]))
     80      {
     81        array_shift($PathItems);
     82        return($this->SearchPage($PathItems, $Pages[$PathItem]));
     83      } else return($Pages[$PathItem]);
     84    } else return('');
     85  }
     86 
     87  function PageNotFound()
     88  {
     89    return('Page '.implode('/', $this->PathItems).' not found.');
     90  }
     91 
     92  function ShowPage()
     93  {
     94    /* @var $Page Page */
     95    $ClassName = $this->SearchPage($this->PathItems, $this->Pages);     
     96    if($ClassName != '')
     97    {
     98      $Page = new $ClassName($this);
     99      $Page->GetOutput();
     100    } else echo($this->PageNotFound());
     101  }
    56102}
    57 
    58 ?>
  • trunk/index.php

    r536 r545  
    22
    33include_once('includes/global.php');
    4  
    5 function ShowNews()
    6 {
    7   global $System;
    84
    9   $Output = '<strong>Změny systému:</strong><div class="NewsBox">';
    10   $DbResult = $System->Database->query('SELECT `News`.`Time`, `User`.`Name`, `News`.`Text`,`News`.`Title`'.
    11     ' FROM `News` JOIN `User` ON `User`.`ID` = `News`.`User` ORDER BY `Time` DESC LIMIT 10');
    12   while($DbRow = $DbResult->fetch_assoc())
    13     $Output .= '<div><strong>'.$DbRow['Title'].' ('.HumanDate($DbRow['Time']).')</strong> <br />'.$DbRow['Text'].' ('.$DbRow['Name'].')</div>'; 
    14   $Output .= '<a href="action.php?action=news">Všechny zprávy</a>';
    15   $Output .= '</div>';
    16   return($Output);
    17 }
    18 
    19 function ShowLastTranslated()
    20 {
    21   global $System, $Config;
    22 
    23   $Count = 40;
    24   $Output = '<strong>Poslední překlady:</strong>';
    25   //'<div class="NewsBox">';
    26  
    27   $GroupListQuery = 'SELECT `Group`.* FROM `Group`';
    28   $Query = '';
    29   $UnionItems = array();
    30   $DbResult = $System->Database->query($GroupListQuery);
    31   if($DbResult->num_rows > 0)
    32   {
    33   while($DbRow = $DbResult->fetch_assoc())
    34   {
    35     $UnionItems[] = 'SELECT `T`.`ID`, `T`.`Take`, `T`.`User`, `T`.`ModifyTime`, `T`.`Group`, `T`.`GroupName` '.
    36     'FROM (SELECT `T`.`User`, `T`.`ID`, `T`.`ModifyTime`, '.
    37     $DbRow['Id'].' AS `Group`, "'.addslashes($DbRow['Name']).'" AS `GroupName`, `T`.`Take` FROM `'.
    38     $DbRow['TablePrefix'].'` AS `T`'.
    39     ' WHERE (`T`.`Complete` = 1) AND (`T`.`Language` != '.$Config['OriginalLanguage'].') ORDER BY `T`.`ModifyTime` DESC LIMIT '.
    40     $Count.') AS `T`';
    41   }
    42   $Query = 'SELECT `TT`.*, `User`.`Name` AS `UserName`, `User`.`Id` AS `UserId` '.
    43   ' FROM ('.implode(' UNION ', $UnionItems).') AS `TT`'.
    44   ' JOIN `User` ON `User`.`Id` = `TT`.`User`'.
    45   ' ORDER BY `ModifyTime` DESC LIMIT '.$Count;
    46   $DbResult = $System->Database->query($Query);
    47   $Output .= '<table class="MiniTable"><tr><th>Datum</th><th>Kdo</th><th>Nový</th><th>Zdroj</th><th>Skupina</th></tr>';
    48   while($DbRow = $DbResult->fetch_assoc())
    49   {
    50     $Output .= '<tr><td>'.HumanDate($DbRow['ModifyTime']).'</td>'.
    51     '<td><a href="user.php?user='.$DbRow['UserId'].'">'.$DbRow['UserName'].'</a></td>'.
    52     '<td><a href="form.php?group='.$DbRow['Group'].'&amp;ID='.$DbRow['ID'].'">'.$DbRow['ID'].'</a></td>'.
    53     '<td><a href="form.php?group='.$DbRow['Group'].'&amp;ID='.$DbRow['Take'].'">'.$DbRow['Take'].'</a></td>'.
    54     '<td><a href="TranslationList.php?group='.$DbRow['Group'].'&amp;action=filter">'.$DbRow['GroupName'].'</a></td></tr>'; 
    55   }
    56   $Output .= '</table>';
    57   }
    58   return($Output);
    59 }
    60 
    61 function ShowWelcome()
    62 {
    63   global $Config;
    64  
    65   // Cookies have to be used before any text is sent to output
    66   if(!array_key_exists('HideWelcome', $_COOKIE)) $_COOKIE['HideWelcome'] = 0;
    67   if(isset($_GET['Action']))
    68   {
    69     if($_GET['Action'] == 'HideWelcome') $_COOKIE['HideWelcome'] = 1;
    70     if($_GET['Action'] == 'UnHideWelcome') $_COOKIE['HideWelcome'] = 0;
    71   }
    72   setcookie('HideWelcome', $_COOKIE['HideWelcome'], time() + 3600 * 24 * 365);
    73  
    74   if(isset($_COOKIE['HideWelcome']) and ($_COOKIE['HideWelcome'] == 1))
    75   {
    76     $Action = '<a href="?Action=UnHideWelcome">Odkrýt úvod</a>';
    77     $HideWelcome = 'display: none';
    78   } else
    79   {
    80     $Action = '<a href="?Action=HideWelcome">Skrýt úvod</a>';
    81     $HideWelcome = '';
    82   }
    83 
    84   // Echo text even if it is hidden because of caching by external searching engines
    85   return('<div style="'.$HideWelcome.'">'.
    86   '<div id="bannertitle">'.$Config['Web']['Title'].'</div>'.
    87   'Otevřený webový systém pro překládání textů ze hry World of Warcraft (WoW).<br />'.
    88   '<ul>'.
    89   '<li>Projekt je provozován jako otevřený vyznává principy volnosti a otevřenosti. Proto jsou texty volně ke stažení.</li>'.
    90   '<li>Projekt slouží k týmovému překladu. Kdokoliv může přispět přeložením textů a uveřejněním odkazu popř. banneru na svých stránkách.</li>'.
    91   '<li>Projekt není zaměřen pouze na jeden server a umožňuje společné překládání lidem z různých serverů. Překladatelé mohou překládat v týmech podle jména svého serveru a exportovat texty pouze od vybraných překladatelů.</li>'.
    92   '<li>Přeložené texty lze volně stahovat v různých tvarech jako XML, SQL, Addon a Lua. Přeložené texty lze tedy snadno importovat do svého free serveru nebo použít v jiných projektech.</li>'.
    93   '<li>Cílem projektu je přeložit všechny texty ze hry. Nikoliv pouze texty výprav (questů).</li>'.
    94   '<li>Texty lze překládat do dvou jazyků, češtiny a slovenštiny.</li>'.
    95   '</ul></div>'.$Action);
    96 }
    975
    986HandleLoginForm();
     
    1008$Output = '';
    1019if(isset($Message)) $Output .= ShowMessage($Message, $MessageType);
    102 $Output .= '<br />'. 
    103 '<table class="Home"><tr><td colspan="3">'.ShowWelcome().
    104 '</td></tr>'.
    105 '<tr><td>'.ShowLastTranslated().'</td>'.
    106 '<td class="news-box">'.ShowNews().'</td>'.
    107 '<td>'.ShowShoutBox().'</td>'.
    108 '</tr></table>';
    109          
    110 ShowPage($Output);
     10
     11$System->PathItems = ProcessURL();
     12$System->ShowPage();       
    11113
    11214?>
Note: See TracChangeset for help on using the changeset viewer.