<?php

class ModuleRedirection extends Module
{
  public array $Excludes;

  function __construct(System $System)
  {
    parent::__construct($System);
    $this->Name = 'Redirection';
    $this->Version = '1.0';
    $this->Creator = 'Chronos';
    $this->License = 'GNU/GPL';
    $this->Description = 'Redirects erlier obsolete addresses to new ones.';
    $this->Dependencies = array();

    $this->Excludes = array();
  }

  function DoStart(): void
  {
    Core::Cast($this->System)->OnPageNotFound = array($this, 'ShowRedirect');
  }

  function Redirect($Location)
  {
    Header($_SERVER['SERVER_PROTOCOL'].' 301 Moved Permanently');
    Header('Location: '.$Location);
    return '<h3 align="center">'.T('').'</h3>';
  }

  function ShowRedirect()
  {
    $Output = '';
    if (count(Core::Cast($this->System)->PathItems) > 0)
    {
      if (Core::Cast($this->System)->PathItems[0] == 'user.php') $Output = $this->Redirect($this->System->Link('/user/'));
      if (Core::Cast($this->System)->PathItems[0] == 'team.php') $Output = $this->Redirect($this->System->Link('/team/'));
      if (Core::Cast($this->System)->PathItems[0] == 'version.php') $Output = $this->Redirect($this->System->Link('/client-version/'));
      if (Core::Cast($this->System)->PathItems[0] == 'phpBB3') $Output = $this->Redirect($this->System->Link('/forum/'));
      if (Core::Cast($this->System)->PathItems[0] == 'phpbb3') $Output = $this->Redirect($this->System->Link('/forum/'));
      if (Core::Cast($this->System)->PathItems[0] == 'statistic.php') $Output = $this->Redirect($this->System->Link('/progress/'));
      if (Core::Cast($this->System)->PathItems[0] == 'register.php') $Output = $this->Redirect($this->System->Link('/registration/'));
      if (Core::Cast($this->System)->PathItems[0] == 'registrace.php') $Output = $this->Redirect($this->System->Link('/registration/'));
      if (Core::Cast($this->System)->PathItems[0] == 'dictionary.php') $Output = $this->Redirect($this->System->Link('/dictionary/'));
      if (Core::Cast($this->System)->PathItems[0] == 'download-addon.php') $Output = $this->Redirect($this->System->Link('/download/'));
      if (Core::Cast($this->System)->PathItems[0] == 'banners.php') $Output = $this->Redirect($this->System->Link('/referrer/'));
      if (Core::Cast($this->System)->PathItems[0] == 'download.php') $Output = $this->Redirect($this->System->Link('/download/'));
      if (Core::Cast($this->System)->PathItems[0] == 'serverlist.php') $Output = $this->Redirect($this->System->Link('/server/'));
      if (Core::Cast($this->System)->PathItems[0] == 'info.php') $Output = $this->Redirect($this->System->Link('/info/'));
      if (Core::Cast($this->System)->PathItems[0] == 'userlist.php') $Output = $this->Redirect($this->System->Link('/users/'));
      if (Core::Cast($this->System)->PathItems[0] == 'promotion.php') $Output = $this->Redirect($this->System->Link('/promotion/'));
      if (Core::Cast($this->System)->PathItems[0] == 'log.php') $Output = $this->Redirect($this->System->Link('/log/'));
      if (count(Core::Cast($this->System)->PathItems) > 1)
      {
        if ((Core::Cast($this->System)->PathItems[0] == 'team') and (Core::Cast($this->System)->PathItems[1] == 'userlist.php'))
          $Output = $this->Redirect($this->System->Link('/userlist/'));
        if ((Core::Cast($this->System)->PathItems[0] == 'dictionary') and (Core::Cast($this->System)->PathItems[1] == 'user.php'))
          $Output = $this->Redirect($this->System->Link('/user/'));
        if ((Core::Cast($this->System)->PathItems[0] == 'forum') and (Core::Cast($this->System)->PathItems[1] == 'index.php'))
          $Output = $this->Redirect($this->System->Link('/forum/'));
        if ((Core::Cast($this->System)->PathItems[0] == 'phpbb3') and (Core::Cast($this->System)->PathItems[1] == 'index.php'))
          $Output = $this->Redirect($this->System->Link('/forum/'));
        if ((Core::Cast($this->System)->PathItems[0] == 'phpBB3') and (Core::Cast($this->System)->PathItems[1] == 'index.php'))
          $Output = $this->Redirect($this->System->Link('/forum/'));
        if ((Core::Cast($this->System)->PathItems[0] == 'download') and (Core::Cast($this->System)->PathItems[1] == 'ceske_fonty_do_wow.zip'))
          $Output = $this->Redirect($this->System->Link('/files/ceske_fonty_do_wow.zip'));
      }
    }
    return $Output;
  }
}
