Changeset 858 for trunk


Ignore:
Timestamp:
Jan 21, 2016, 9:54:58 AM (9 years ago)
Author:
chronos
Message:
  • Modified: Custom install script replaced by more sophisticated Setup class which also allows to configure system parameters and application modules.
Location:
trunk
Files:
3 added
2 deleted
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Application/DefaultConfig.php

    r837 r858  
    11<?php
    22
    3 $IsDeveloper = in_array($_SERVER['REMOTE_ADDR'], array('127.0.0.1'));
    4 
    5 $DefaultConfig = array(
    6   'Database' => array(
    7     'Host' => 'localhost',
    8     'User' => 'root',
    9     'Password' => '',
    10     'Database' => 'wowpreklad',
    11     'DatabaseAoWoW' => 'wowpreklad_mangos',
    12     'Prefix' => '',
    13     'Charset' => 'utf8',
    14     'MangosPrefix' => '',
    15   ),
    16   'Style' => 'maron',
    17   'Web' => array(
    18     'Title' => 'Projekt překládání textů hry WoW',
    19     'Description' => '',
    20     'Keywords' => 'world of warcraft, wow, translation',
    21     'Charset' => 'utf-8',
    22     'Host' => 'localhost',
    23     'BaseURL' => '',
    24     'AdminEmail' => 'admin@localhost',
    25     'Authors' => 'autor',
    26     'ShowSQLQuery' => false,
    27     'ShowSQLError' => $IsDeveloper,
    28     'LogSQLQuery' => $IsDeveloper,
    29     'ShowPHPError' => $IsDeveloper,
    30     'ShowRuntimeInfo' => $IsDeveloper,
    31     'FormatOutput' => $IsDeveloper,
    32     'ItemsPerPage' => 40,
    33     'TempFolder' => 'tmp/',
    34     'SourceFolder' => 'source/',
    35     'GameVersion' => '3.3.5a',
    36     'VisiblePagingItems' => 20,
    37     'Timezone' => 'Europe/Prague',
    38     'WebCounter' => '',
    39     'Advertisement' => '',
    40     'Locale' => 'cs',
    41   ),
    42   'ForbiddedUserNames' => array('addon', 'admin', 'administrator'),
    43   'ExportTaskProcessPeriod' => 10,
    44   'MaxExportPerUser' => 10,
    45   'AoWoWExportId' => 1,
    46   'OriginalLanguage' => 1,
    47   'SystemPassword' => '',
    48 );
     3class DefaultConfig
     4{
     5  function Get()
     6  {
     7    $IsDeveloper = in_array($_SERVER['REMOTE_ADDR'], array('127.0.0.1'));
     8    return(array(
     9      array('Name' => 'SystemPassword', 'Type' => 'PasswordEncoded', 'Default' => '', 'Title' => 'System password'),
     10      array('Name' => 'Database/Host', 'Type' => 'String', 'Default' => 'localhost', 'Title' => 'Server'),
     11      array('Name' => 'Database/User', 'Type' => 'String', 'Default' => 'root', 'Title' => 'User'),
     12      array('Name' => 'Database/Password', 'Type' => 'Password', 'Default' => '', 'Title' => 'Password'),
     13      array('Name' => 'Database/Database', 'Type' => 'String', 'Default' => 'wowpreklad', 'Title' => 'Database'),
     14      array('Name' => 'Database/Prefix', 'Type' => 'String', 'Default' => '', 'Title' => 'Prefix'),
     15      array('Name' => 'Database/Charset', 'Type' => 'String', 'Default' => 'utf8', 'Title' => 'Charset'),
     16      array('Name' => 'Database/DatabaseAoWoW', 'Type' => 'String', 'Default' => 'wowpreklad_mangos', 'Title' => 'Database AoWoW'),
     17      array('Name' => 'Database/MangosPrefix', 'Type' => 'String', 'Default' => '', 'Title' => 'Mangos prefix'),
     18      array('Name' => 'Web/Style', 'Type' => 'String', 'Default' => 'maron', 'Title' => 'Style'),
     19      array('Name' => 'Web/Title', 'Type' => 'String', 'Default' => 'Project of translation of WoW game', 'Title' => 'Title'),
     20      array('Name' => 'Web/Description', 'Type' => 'String', 'Default' => '', 'Title' => 'Description'),
     21      array('Name' => 'Web/Keywords', 'Type' => 'String', 'Default' => 'world of warcraft, wow, translation', 'Title' => 'Keywords'),
     22      array('Name' => 'Web/Charset', 'Type' => 'String', 'Default' => 'utf-8', 'Title' => 'Charset'),
     23      array('Name' => 'Web/Host', 'Type' => 'String', 'Default' => 'localhost', 'Title' => 'Host domain name'),
     24      array('Name' => 'Web/BaseURL', 'Type' => 'String', 'Default' => '', 'Title' => 'Root URL'),
     25      array('Name' => 'Web/AdminEmail', 'Type' => 'String', 'Default' => 'admin@localhost', 'Title' => 'Admin e-mail'),
     26      array('Name' => 'Web/Authors', 'Type' => 'String', 'Default' => '', 'Title' => 'Authors'),
     27      array('Name' => 'Web/ShowSQLError', 'Type' => 'Boolean', 'Default' => '0', 'Title' => 'Show SQL errors'),
     28      array('Name' => 'Web/ShowSQLQuery', 'Type' => 'Boolean', 'Default' => '0', 'Title' => 'Show SQL queries'),
     29      array('Name' => 'Web/ShowPHPError', 'Type' => 'Boolean', 'Default' => '0', 'Title' => 'Show PHP errors'),
     30      array('Name' => 'Web/ShowRuntimeInfo', 'Type' => 'Boolean', 'Default' => '0', 'Title' => 'Show runtime information'),
     31      array('Name' => 'Web/LogSQLQuery', 'Type' => 'Boolean', 'Default' => '0', 'Title' => 'Log SQL queries'),
     32      array('Name' => 'Web/FormatOutput', 'Type' => 'Boolean', 'Default' => '0', 'Title' => 'Format produced HTML code'),
     33      array('Name' => 'Web/ItemsPerPage', 'Type' => 'Integer', 'Default' => '50', 'Title' => 'Items per page'),
     34      array('Name' => 'Web/TempFolder', 'Type' => 'String', 'Default' => 'tmp/', 'Title' => 'Temporary directory'),
     35      array('Name' => 'Web/SourceFolder', 'Type' => 'String', 'Default' => 'source/', 'Title' => 'Source directory'),
     36      array('Name' => 'Web/GameVersion', 'Type' => 'String', 'Default' => '3.3.5a', 'Title' => 'Game version'),
     37      array('Name' => 'Web/VisiblePagingItems', 'Type' => 'Integer', 'Default' => 20, 'Title' => 'Visible paging items'),
     38      array('Name' => 'Web/Timezone', 'Type' => 'String', 'Default' => 'Europe/Prague', 'Title' => 'Time zone'),
     39      array('Name' => 'Web/WebCounter', 'Type' => 'String', 'Default' => '', 'Title' => 'Web counter HTML code'),
     40      array('Name' => 'Web/Advertisement', 'Type' => 'String', 'Default' => '', 'Title' => 'Advertisement HTML code'),
     41      array('Name' => 'Web/Locale', 'Type' => 'String', 'Default' => 'cs', 'Title' => 'Default locale code'),
     42      array('Name' => 'ForbiddedUserNames', 'Type' => 'Array', 'Default' => array('addon', 'admin', 'administrator'), 'Title' => 'Forbidded user names'),
     43      array('Name' => 'ExportTaskProcessPeriod', 'Type' => 'Integer', 'Default' => 10, 'Title' => 'Export task process period'),
     44      array('Name' => 'MaxExportPerUser', 'Type' => 'Integer', 'Default' => 10, 'Title' => 'Max export count per user'),
     45      array('Name' => 'AoWoWExportId', 'Type' => 'Integer', 'Default' => 1, 'Title' => 'ID of AoWoW export'),
     46      array('Name' => 'OriginalLanguage', 'Type' => 'Integer', 'Default' => 1, 'Title' => 'Original language'),
     47      array('Name' => 'EnableGoogleTranslate', 'Type' => 'Boolean', 'Default' => false, 'Title' => 'Enable Google translate'),
     48    ));
     49  }
     50}
  • trunk/Application/Version.php

    r857 r858  
    77
    88$Version = '1.0-alfa';
    9 $Revision = 857; // Subversion revision
     9$Revision = 858; // Subversion revision
    1010$DatabaseRevision = 857; // Database structure revision
    11 $ReleaseTime = '2016-01-19';
     11$ReleaseTime = '2016-01-20';
  • trunk/Modules/Redirection/Redirection.php

    r857 r858  
    3939      if($this->System->PathItems[0] == 'statistic.php') $Output = $this->Redirect($this->System->Link('/progress/'));
    4040      if($this->System->PathItems[0] == 'register.php') $Output = $this->Redirect($this->System->Link('/registration/'));
     41      if($this->System->PathItems[0] == 'registrace.php') $Output = $this->Redirect($this->System->Link('/registration/'));
    4142      if($this->System->PathItems[0] == 'dictionary.php') $Output = $this->Redirect($this->System->Link('/dictionary/'));
    4243      if($this->System->PathItems[0] == 'download-addon.php') $Output = $this->Redirect($this->System->Link('/download/'));
     
    6061        if(($this->System->PathItems[0] == 'phpBB3') and ($this->System->PathItems[1] == 'index.php'))
    6162          $Output = $this->Redirect($this->System->Link('/forum/'));
     63        if(($this->System->PathItems[0] == 'download') and ($this->System->PathItems[1] == 'ceske_fonty_do_wow.zip'))
     64          $Output = $this->Redirect($this->System->Link('/files/ceske_fonty_do_wow.zip'));
    6265      }
    6366    }
  • trunk/Packages/Common/AppModule.php

    r838 r858  
    232232    {
    233233      if(!array_key_exists($Dependency, $this->Modules))
    234         throw new Exception('Module "'.$Module->Name.'" dependency "'.$Dependency.'" not found');
     234        throw new Exception(sprintf(T('Module "%s" dependency "%s" not found'), $Module->Name, $Dependency));
    235235      $DepModule = $this->Modules[$Dependency];
    236236      if(in_array(ModuleCondition::All, $Conditions) or
  • trunk/Packages/Common/Common.php

    r856 r858  
    1616include_once(dirname(__FILE__).'/Page.php');
    1717include_once(dirname(__FILE__).'/Locale.php');
     18include_once(dirname(__FILE__).'/Update.php');
     19include_once(dirname(__FILE__).'/Setup.php');
     20include_once(dirname(__FILE__).'/Table.php');
    1821
    1922class PackageCommon
     
    3437  }
    3538}
     39
     40class Paging
     41{
     42  var $TotalCount;
     43  var $ItemPerPage;
     44  var $Around;
     45  var $SQLLimit;
     46  var $Page;
     47
     48  function __construct()
     49  {
     50    global $System;
     51
     52    $this->ItemPerPage = $System->Config['Web']['ItemsPerPage'];
     53    $this->Around = $System->Config['Web']['VisiblePagingItems'];
     54  }
     55
     56  function Show()
     57  {
     58    $QueryItems = GetQueryStringArray($_SERVER['QUERY_STRING']);
     59
     60    $Result = '';
     61    if(array_key_exists('all', $QueryItems))
     62    {
     63      $PageCount = 1;
     64      $ItemPerPage = $this->TotalCount;
     65    } else
     66    {
     67      $ItemPerPage = $this->ItemPerPage;
     68      $Around = round($this->Around / 2);
     69      $PageCount = floor($this->TotalCount / $ItemPerPage) + 1;
     70    }
     71
     72    if(!array_key_exists('Page', $_SESSION)) $_SESSION['Page'] = 0;
     73    if(array_key_exists('page', $_GET)) $_SESSION['Page'] = $_GET['page'] * 1;
     74    if($_SESSION['Page'] < 0) $_SESSION['Page'] = 0;
     75    if($_SESSION['Page'] >= $PageCount) $_SESSION['Page'] = $PageCount - 1;
     76    $CurrentPage = $_SESSION['Page'];
     77
     78    $Result .= 'Počet položek: <strong>'.$this->TotalCount.'</strong> &nbsp; Stránky: ';
     79
     80    $Result = '';
     81    if($PageCount > 1)
     82    {
     83      if($CurrentPage > 0)
     84      {
     85        $QueryItems['page'] = 0;
     86        $Result.= '<a href="?'.SetQueryStringArray($QueryItems).'">&lt;&lt;</a> ';
     87        $QueryItems['page'] = ($CurrentPage - 1);
     88        $Result.= '<a href="?'.SetQueryStringArray($QueryItems).'">&lt;</a> ';
     89      }
     90      $PagesMax = $PageCount - 1;
     91      $PagesMin = 0;
     92      if($PagesMax > ($CurrentPage + $Around)) $PagesMax = $CurrentPage + $Around;
     93      if($PagesMin < ($CurrentPage - $Around))
     94      {
     95        $Result.= ' ... ';
     96        $PagesMin = $CurrentPage - $Around;
     97      }
     98      for($i = $PagesMin; $i <= $PagesMax; $i++)
     99      {
     100        if($i == $CurrentPage) $Result.= '<strong>'.($i + 1).'</strong> ';
     101        else {
     102         $QueryItems['page'] = $i;
     103         $Result .= '<a href="?'.SetQueryStringArray($QueryItems).'">'.($i + 1).'</a> ';
     104        }
     105      }
     106      if($PagesMax < ($PageCount - 1)) $Result .= ' ... ';
     107      if($CurrentPage < ($PageCount - 1))
     108      {
     109        $QueryItems['page'] = ($CurrentPage + 1);
     110        $Result.= '<a href="?'.SetQueryStringArray($QueryItems).'">&gt;</a> ';
     111        $QueryItems['page'] = ($PageCount - 1);
     112        $Result.= '<a href="?'.SetQueryStringArray($QueryItems).'">&gt;&gt;</a>';
     113      }
     114    }
     115    $QueryItems['all'] = '1';
     116    if($PageCount > 1) $Result.= ' <a href="?'.SetQueryStringArray($QueryItems).'">Vše</a>';
     117
     118    $Result = '<div style="text-align: center">'.$Result.'</div>';
     119    $this->SQLLimit = ' LIMIT '.$CurrentPage * $ItemPerPage.', '.$ItemPerPage;
     120    $this->Page = $CurrentPage;
     121    return($Result);
     122  }
     123}
  • trunk/Packages/Common/Database.php

    r838 r858  
    8484  function query($Query)
    8585  {
    86     if(!$this->Connected()) throw new Exception('Not connected to database');
     86    if(!$this->Connected()) throw new Exception(T('Not connected to database'));
    8787    if(($this->ShowSQLQuery == true) or ($this->LogSQLQuery == true)) $QueryStartTime = microtime();
    8888    $this->LastQuery = $Query;
  • trunk/Packages/Common/Locale.php

    r856 r858  
    5151      $ClassName = 'LocaleText'.$Language;
    5252      $this->Texts = new $ClassName();
    53     } else throw new Exception('Language file '.$FileName.' not found');
     53    } else throw new Exception(sprintf(T('Language file %s not found'), $FileName));
    5454    $this->Texts->Load();
    5555  }
     
    236236      $this->CurrentLocale->Dir = $this->Dir;
    237237      $this->CurrentLocale->Load($Code);
    238     } else throw new Exception('Unsupported locale code '.$Code);
     238    } else throw new Exception(sprintf(T('Unsupported locale code %s'), $Code));
    239239  }
    240240}
  • trunk/Packages/Common/Mail.php

    r838 r858  
    9696  function Send()
    9797  {
    98     if(count($this->Bodies) == 0) throw new Exception('Mail: Need at least one text body');
     98    if(count($this->Bodies) == 0) throw new Exception(T('Mail message need at least one text body'));
    9999
    100100    $Body = $this->BuildAttachment($this->BuildBody());
     
    126126      }
    127127    }
    128     if($To == '') throw new Exception('Mail: Need at least one recipient address');
     128    if($To == '') throw new Exception(T('Mail message need at least one recipient address'));
    129129
    130130    $this->Headers['Mime-Version'] = '1.0';
     
    142142    $this->Subject = strtr($this->Subject, "\r\n", '  ');
    143143
    144     if($this->Subject == '') throw new Exception('Mail: Missing Subject');
     144    if($this->Subject == '') throw new Exception(T('Mail message missing Subject'));
    145145
    146146
     
    162162    {
    163163      if(!$this->ValidEmail($Address))
    164   throw new Exception('Mail: Invalid address '.$Address);
     164  throw new Exception(sprintf(T('Mail message invalid address %s'), $Address));
    165165    }
    166166  }
     
    190190        {
    191191          if(!file_exists($FileName))
    192             throw new Exception('Mail: Attached file '.$FileName.' can\'t be found');
     192            throw new Exception(sprintf(T('Mail message attached file %s can\'t be found'), $FileName));
    193193          $Data = file_get_contents($FileName);
    194194        } else
  • trunk/includes/Global.php

    r856 r858  
    22
    33include_once(dirname(__FILE__).'/../Packages/Common/Common.php');
    4 include_once(dirname(__FILE__).'/System.php');
    5 include_once(dirname(__FILE__).'/Update.php');
    6 include_once(dirname(__FILE__).'/PageEdit.php');
    74if(file_exists(dirname(__FILE__).'/../Config/Config.php'))
    85  include_once(dirname(__FILE__).'/../Config/Config.php');
    9   else die('Config file Config/Config.php not found');
     6include_once(dirname(__FILE__).'/System.php');
     7include_once(dirname(__FILE__).'/../Application/DefaultConfig.php');
     8include_once(dirname(__FILE__).'/PageEdit.php');
    109include_once(dirname(__FILE__).'/../Application/Version.php');
    1110require_once(dirname(__FILE__).'/../HTML/BBCodeParser2.php');
  • trunk/includes/System.php

    r855 r858  
    2929    $this->Config = $Config;
    3030    date_default_timezone_set($this->Config['Web']['Timezone']);
    31 
     31    mb_internal_encoding("UTF-8");
     32
     33    if(isset($this->Config['Database']))
     34    {
    3235    $this->Database->Connect($this->Config['Database']['Host'],
    3336      $this->Config['Database']['User'], $this->Config['Database']['Password'],
     
    3740    $this->Database->ShowSQLError = $this->Config['Web']['ShowSQLError'];
    3841    $this->Database->LogSQLQuery = $this->Config['Web']['LogSQLQuery'];
     42    }
    3943
    4044    $this->LocaleManager = new LocaleManager($this);
     
    8892  {
    8993    global $ScriptStartTime, $TranslationTree, $StopAfterUpdateManager,
    90       $UpdateManager, $DatabaseRevision;
     94      $UpdateManager;
    9195
    9296    $ScriptStartTime = GetMicrotime();
    9397    if(GetRemoteAddress() != '') session_start();
    94 
    95     if(!isset($this->Config)) die('Systém není nainstalován. Pokračujte v instalaci <a href="admin/install.php">zde</a>.');
    96 
    97     $this->Init();
    98 
    99     // Check database persistence structure
    100     $UpdateManager = new UpdateManager();
    101     $UpdateManager->Database = $this->Database;
    102     $UpdateManager->Revision = $DatabaseRevision;
    103     if(!$UpdateManager->IsInstalled()) die('Systém vyžaduje instalaci databáze. Pokračujte <a href="'.$this->Link('/Application/install.php').'">zde</a>');
    104     if(!$UpdateManager->IsUpToDate()) die('Systém vyžaduje aktualizaci databáze. Pokračujte <a href="'.$this->Link('/Application/install.php').'">zde</a>');
    10598
    10699    // SQL injection hack protection
     
    112105    }
    113106    foreach($_GET as $Index => $Item) $_GET[$Index] = addslashes($_GET[$Index]);
     107
     108    $this->Init();
     109
     110    // Register and start existing modules
     111    $this->Setup = new Setup($this);
     112    $this->Setup->Start();
     113    $this->Setup->UpdateManager->VersionTable = 'DbVersion';
     114    if($this->Setup->CheckState())
     115    {
     116      $this->ModuleManager->Start();
     117    }
    114118
    115119    // TODO: Global initialized variable should be removed
Note: See TracChangeset for help on using the changeset viewer.