Changeset 455 for trunk/includes


Ignore:
Timestamp:
Apr 13, 2010, 10:03:12 AM (15 years ago)
Author:
george
Message:
  • Upraveno: Přístup k databázi převeden na objektový pomocí rozšířené PHP třídy mysqli. Při práci s databází použít globální objekt $System a jeho prvek $Database ($System->Database->query("SELECT ...");.
  • Upraveno: Při vkládání nové zprávy do Kecátka neprovádět přesměrování, ale rovnou zobrazit výpis. U některých překladatelů toto způsobovalo opakované vložení zprávy.
Location:
trunk/includes
Files:
1 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/Database.php

    r420 r455  
    1717  function open()
    1818  {
    19     parent::__construct($this->HostName, $this->UserName, $this->Password, $this->Schema);
     19    parent::real_connect($this->HostName, $this->UserName, $this->Password, $this->Schema);
    2020    $this->charset($this->Charset);
    2121  }
  • trunk/includes/global.php

    r454 r455  
    1515
    1616include_once(dirname(__FILE__).'/config.php');
    17 include_once(dirname(__FILE__).'/error.php');
    18 include_once(dirname(__FILE__).'/databaseconection.php');
     17include_once(dirname(__FILE__).'/Database.php');
    1918include_once(dirname(__FILE__).'/global_function.php');
    2019include_once(dirname(__FILE__).'/rss.php');
     
    2221include_once(dirname(__FILE__).'/user.php');
    2322
    24 $Database = new Database($Config['Database']['Host'], $Config['Database']['User'], $Config['Database']['Password']);
    25 $Database->SQLCommand('SET NAMES '.$Config['Database']['Charset']);
    26 $Database->SelectDatabase($Config['Database']['Database']);   
    27 
    28 $TranslationTree = GetTranslationTree();
    29 $LanguageList = GetLanguageList();
    30 
    3123$System = new System();
    3224$System->Init();
    3325$User = new User($System);
    3426
     27include_once(dirname(__FILE__).'/error.php');
     28
     29$TranslationTree = GetTranslationTree();
     30$LanguageList = GetLanguageList();
     31
    3532function GetMicrotime()
    3633{
     
    4138function ShowShoutbox()
    4239{
    43   global $Database, $Config, $User, $System;
     40  global $System, $Config, $User, $System;
    4441 
    4542  echo('<strong><a href="'.$System->Link('/action.php?action=ShoutBoxView').'">Kecátko:</a></strong>');
     
    4744    echo(' <a href="'.$System->Link('/action.php?action=shoutbox').'">Vložit</a>');
    4845  echo('<div class="box"><table>');
    49   $ID = $Database->SQLCommand('SELECT * FROM `ShoutBox` ORDER BY `ID` DESC LIMIT 30');
    50   while($Line = mysql_fetch_assoc($ID))
     46  $DbResult = $System->Database->query('SELECT * FROM `ShoutBox` ORDER BY `ID` DESC LIMIT 30');
     47  while($Line = $DbResult->fetch_assoc())
    5148    echo('<tr><td><strong>'.$Line['User'].'</strong>: '.htmlspecialchars($Line['Text']).'</td></tr>');
    5249  echo('</table></div>');
     
    5552function ShowTopBar()
    5653{
    57   global $Config, $Database, $User, $System;
     54  global $Config, $System, $User, $System;
    5855 
    5956  echo('<div class="Menu">');
     
    6158  if($User->Licence(LICENCE_USER))
    6259  {
    63     $DbResult = $Database->SQLCommand('SELECT `Id`, `Name` FROM `Team` WHERE `Id`='.$User->Team);
    64     $Team = mysql_fetch_assoc($DbResult);
     60    $DbResult = $System->Database->query('SELECT `Id`, `Name` FROM `Team` WHERE `Id`='.$User->Team);
     61    $Team = $DbResult->fetch_assoc();
    6562
    6663    //echo('<span class="MenuItem">Moje překlady: <a href="">Dokončené</a> <a href="">Rozpracované</a> <a href="">Exporty</a> Tým: <a href="">'.$Team['name'].'</a></span>');
     
    159156function ShowTranslatedMenu()
    160157{
    161   global $TranslationTree, $Config, $Database, $User, $System;
     158  global $TranslationTree, $User, $System;
    162159
    163160  echo('<strong>Překladové skupiny:</strong><br /><div id="TranslationMenu">');
     
    182179function ShowOnlineUserList()
    183180{
    184   global $Database, $Moderators, $User;
     181  global $System, $Moderators, $User;
    185182 
    186183  echo('Online překladatelé:<br />');
    187   $ID = $Database->SQLCommand('SELECT `Name`, `GM`, `ID` FROM `User` WHERE `LastLogin` >= NOW() - 300 AND ((`LastLogout` < `LastLogin`) OR (ISNULL(`LastLogout`)))');
    188   while($DbUser = mysql_fetch_assoc($ID))
     184  $DbResult = $System->Database->query('SELECT `Name`, `GM`, `ID` FROM `User` WHERE `LastLogin` >= NOW() - 300 AND ((`LastLogout` < `LastLogin`) OR (ISNULL(`LastLogout`)))');
     185  while($DbUser = $DbResult->fetch_assoc())
    189186  {
    190187    if($User->Licence(LICENCE_MODERATOR)) $Name = '<a href="user.php?user='.$DbUser['ID'].'">'.$DbUser['Name'].'</a>';
     
    197194function ShowPage()
    198195{
    199   global $User, $Config, $Database, $RSSChannels, $PageFooterRequested, $System; 
    200  
    201   echo('<?xml version="1.0" encoding="'.$Config['Web']['Charset'].'"?>
     196  global $User, $RSSChannels, $PageFooterRequested, $System; 
     197 
     198  echo('<?xml version="1.0" encoding="'.$System->Config['Web']['Charset'].'"?>
    202199  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    203200<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cz">'.
    204201'<head>'.
    205 '<meta http-equiv="content-type" content="application/xhtml+xml; charset='.$Config['Web']['Charset'].'" />'.
     202'<meta http-equiv="content-type" content="application/xhtml+xml; charset='.$System->Config['Web']['Charset'].'" />'.
    206203'<meta name="keywords" content="wow, quest, questy, questů, preklad, mangos, překlad, překládání, přeložený, přeložení, čeština, world of warcraft, open source, free, addon" />'.
    207 '<meta name="description" content="'.$Config['Web']['Title'].'" />'.
     204'<meta name="description" content="'.$System->Config['Web']['Title'].'" />'.
    208205'<meta name="robots" content="all" />'.
    209206'<link rel="stylesheet" href="'.$System->Link('/style/style.css').'" type="text/css" media="all" />'.
     
    213210  foreach($RSSChannels as $Channel)
    214211    echo(' <link rel="alternate" title="'.$Channel['Title'].'" href="'.$Channel['URL'].'" type="application/rss+xml" />');
    215   echo('<title>'.$Config['Web']['Title'].'</title>
     212  echo('<title>'.$System->Config['Web']['Title'].'</title>
    216213</head>
    217214<body>');
     
    268265function ShowFooter()
    269266{
    270   global $Database, $Config, $ScriptStartTime, $PageFooterRequested, $User;
     267  global $System, $ScriptStartTime, $PageFooterRequested, $User;
    271268
    272269  if(isset($PageFooterRequested))
     
    291288
    292289    echo('</td></tr>');
    293     if($Config['Web']['ShowRuntimeInfo'] == true) echo('<tr><td colspan="3" style="text-align: center;">Doba generování: '.$ScriptGenerateDuration.' s / '.ini_get('max_execution_time').' s &nbsp;&nbsp; Použitá paměť: '.HumanSize(memory_get_peak_usage(FALSE)).' / '.ini_get('memory_limit').'B &nbsp;&nbsp; <a href="http://validator.w3.org/check?uri='.htmlentities('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'].'?'.$_SERVER['QUERY_STRING']).'">HTML validator</a></td></tr>');
     290    if($System->Config['Web']['ShowRuntimeInfo'] == true) echo('<tr><td colspan="3" style="text-align: center;">Doba generování: '.$ScriptGenerateDuration.' s / '.ini_get('max_execution_time').' s &nbsp;&nbsp; Použitá paměť: '.HumanSize(memory_get_peak_usage(FALSE)).' / '.ini_get('memory_limit').'B &nbsp;&nbsp; <a href="http://validator.w3.org/check?uri='.htmlentities('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'].'?'.$_SERVER['QUERY_STRING']).'">HTML validator</a></td></tr>');
    294291    echo('</table>'.
    295292      '</body>'.
    296293      '</html>');
    297     $Database->Disconnect();
    298294    $User->Store();
    299295  }
  • trunk/includes/global_function.php

    r443 r455  
    3636function GetPageList($TotalCount)
    3737{
    38   global $Database, $Config;
     38  global $System;
    3939   
    4040  $QueryItems = GetQueryStringArray($_SERVER['QUERY_STRING']);
    4141 
    42   $ItemPerPage = $Config['Web']['ItemsPerPage'];
    43   $Around = round($Config['Web']['VisiblePagingItems'] / 2);
     42  $ItemPerPage = $System->Config['Web']['ItemsPerPage'];
     43  $Around = round($System->Config['Web']['VisiblePagingItems'] / 2);
    4444  $Result = '';
    4545  $PageCount = floor($TotalCount / $ItemPerPage) + 1;
     
    218218function GetLanguageList()
    219219{
    220   global $Database;
     220  global $System;
    221221 
    222222  $Result = array();
    223   $DbResult = $Database->SQLCommand('SELECT * FROM `Language` WHERE `Enabled` = 1');
    224   while($DbRow = mysql_fetch_assoc($DbResult))
     223  $DbResult = $System->Database->query('SELECT * FROM `Language` WHERE `Enabled` = 1');
     224  while($DbRow = $DbResult->fetch_assoc())
    225225    $Result[$DbRow['Id']] = $DbRow;
    226226  return($Result);
     
    229229function GetTranslationTree()
    230230{
    231   global $Database;
     231  global $System;
    232232 
    233233  $Result = array();
    234   $DbResult = $Database->SQLCommand('SELECT *, UNIX_TIMESTAMP(`LastImport`) AS `LastImportTime` FROM `Group` ORDER BY `Name`');
    235   while($DbRow = mysql_fetch_assoc($DbResult))
     234  $DbResult = $System->Database->query('SELECT *, UNIX_TIMESTAMP(`LastImport`) AS `LastImportTime` FROM `Group` ORDER BY `Name`');
     235  while($DbRow = $DbResult->fetch_assoc())
    236236  {
    237237    $DbRow['Items'] = array();
    238238    $Result[$DbRow['Id']] = $DbRow;
    239239  }
    240   $DbResult = $Database->SQLCommand('SELECT * FROM `GroupItem` ORDER BY `Group`, `Sequence`');
    241   while($DbRow = mysql_fetch_assoc($DbResult))
     240  $DbResult = $System->Database->query('SELECT * FROM `GroupItem` ORDER BY `Group`, `Sequence`');
     241  while($DbRow = $DbResult->fetch_assoc())
    242242  {
    243243    $Result[$DbRow['Group']]['Items'][] = $DbRow;
     
    250250function WriteLog($Text, $Type)
    251251{
    252   global $Database, $Config, $User;
     252  global $System, $User;
    253253 
    254254  if(!isset($_SERVER['REMOTE_ADDR'])) $IP = 'Konzole';
    255255    else $IP = addslashes($_SERVER['REMOTE_ADDR']);
    256256
    257   $Database->SelectDatabase($Config['Database']['Database']);   
     257  if(isset($User->Id)) $UserId = $User->Id;
     258    else $UserId = 0;
    258259  $Query = 'INSERT INTO `Log` ( `User` , `Type` , `Text` , `Date` , `IP` )
    259    VALUES ('.$User->Id.', '.$Type.', "'.addslashes($Text).'", NOW(), "'.$IP.'")';
    260   $Database->SQLCommand($Query);
     260   VALUES ('.$UserId.', '.$Type.', "'.addslashes($Text).'", NOW(), "'.$IP.'")';
     261  $System->Database->query($Query);
    261262}
    262263
     
    273274function FollowingTran($TextID, $Table, $GroupId, $Prev = false)
    274275{
    275   global $Database;
     276  global $System;
    276277 
    277278  if($Prev)
     
    283284  }
    284285 
    285   $Next = mysql_fetch_assoc($Database->SQLCommand($sql));
     286  $DbResult = $System->Database->query($sql);
     287  $Next = $DbResult->fetch_assoc();
    286288  if($Next)
    287289  {
    288290    if($Prev) echo('<a href="form.php?group='.$GroupId.'&amp;ID='.$Next['ID'].'">Předcházející '.$Next['ID'].'</a> ');
    289291    else echo('<a href="form.php?group='.$GroupId.'&amp;ID='.$Next['ID'].'">Následující '.$Next['ID'].'</a> ');
    290       return 'form.php?group='.$GroupId.'&amp;ID='.$Next['ID'];
     292      return('form.php?group='.$GroupId.'&amp;ID='.$Next['ID']);
    291293  }
    292294}
     
    294296function GetBuildNumber($Version)
    295297{
    296   global $Database, $BuildNumbers;
     298  global $System, $BuildNumbers;
    297299 
    298300  if(isset($BuildNumbers[$Version]) == false)
    299301  {
    300302    $sql = 'SELECT `BuildNumber` FROM `ClientVersion` WHERE `Version` = "'.$Version.'"';
    301     $DbRow = mysql_fetch_assoc($Database->SQLCommand($sql));
     303    $DbResult = $System->Database->query($sql);
     304    $DbRow = $DbResult->fetch_assoc();
    302305    $BuildNumbers[$Version] = $DbRow['BuildNumber'];
    303306  }
     
    307310function GetVersionWOW($BuildNumber)
    308311{
    309   global $Database, $VersionsWOW;
     312  global $System, $VersionsWOW;
    310313 
    311314  if(isset($VersionsWOW[$BuildNumber]) == false)
    312315  {
    313316    $sql = 'SELECT `Version` FROM `ClientVersion` WHERE `BuildNumber` = "'.$BuildNumber.'"';
    314     $Version = mysql_fetch_assoc($Database->SQLCommand($sql));
     317    $DbResult = $System->Database->query($sql);
     318    $Version = $DbResult->fetch_assoc();
    315319    $VersionsWOW[$BuildNumber] = $Version['Version'];
    316320  }
     
    442446}
    443447
    444 
    445448function GetTranslatNames($Text,$mode,$TablesColumn)
    446449{
    447   global $Database;
     450  global $System;
    448451 
    449452 /* $TablesID = array('gameobject' => 5,
     
    482485      }
    483486      }
    484       $where = substr($where,0,strlen($where)-4);
     487      $where = substr($where, 0, strlen($where) - 4);
    485488      $where .= ')';
    486489      if ($SqlOK) {
    487         $ID = $Database->SQLCommand($sql.$where.$groupby);
     490        $DbResult = $System->Database->query($sql.$where.$groupby);
    488491    //  echo ($sql.'|'.$where.'|'.$groupby);
    489         while($Line = mysql_fetch_assoc($ID)) {
    490         $buff[] = array($Line['ID'],GetIDbyName($Table),$Line[$Column],$Line['Tran']);
     492        while($Line = $DbResult->fetch_assoc())
     493        {
     494          $buff[] = array($Line['ID'], GetIDbyName($Table), $Line[$Column], $Line['Tran']);
    491495        }
    492496    }
  • trunk/includes/system.php

    r426 r455  
    11<?php
    22
    3 //include_once('database.php');
     3include_once('Database.php');
    44
    55class Module
     
    2222  var $Config;
    2323 
     24  function __construct()
     25  {
     26    $this->Database = new Database();
     27    $this->Config = array();
     28  }
     29 
    2430  function Init()
    2531  {
    2632    include('config.php');
    2733    $this->Config = $Config;
    28     $this->Database = new mysqli($this->Config['Database']['Host'], $this->Config['Database']['User'], $this->Config['Database']['Password'], $this->Config['Database']['Database']);
    29     $this->Database->query('SET NAMES '.$this->Config['Database']['Charset']);
     34    $this->Database->HostName = $this->Config['Database']['Host'];
     35    $this->Database->UserName = $this->Config['Database']['User'];
     36    $this->Database->Password = $this->Config['Database']['Password'];
     37    $this->Database->Schema = $this->Config['Database']['Database'];
     38    $this->Database->Charset = $this->Config['Database']['Charset'];
     39    $this->Database->ShowSQLQuery = $this->Config['Web']['ShowSQLQuery'];
     40    $this->Database->ShowSQLError = $this->Config['Web']['ShowSQLError'];
     41    $this->Database->open();
    3042  }
    3143 
Note: See TracChangeset for help on using the changeset viewer.