Ignore:
Timestamp:
Mar 6, 2023, 12:16:38 PM (22 months ago)
Author:
chronos
Message:
  • Fixed: Export error due to PHP 8.1 deprecated code.
  • Modified: Code cleanup.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/Export/Export.php

    r893 r894  
    99  public int $Id;
    1010  public array $AnoNe = array('Ne', 'Ano');
    11   var $WhereLang;
    12   var $WhereUsers;
    13   var $SelectedUsers;
    14   var $UserNames;
    15   var $ClientVersion;
    16   var $OrderByUserList;
     11  public string $WhereLang;
     12  public string $WhereUsers;
     13  public string $UserNames;
     14  public array $ClientVersion;
     15  public string $OrderByUserList;
    1716  public string $TempDir;
    1817  public string $TempDirRelative;
     
    2322  function Init()
    2423  {
    25     $this->TempDir = dirname(__FILE__).'/../../'.Core::Cast($this->System)->Config['Web']['TempFolder'].'Export/'.$this->Id.'/';
     24    $this->TempDir = NormalizePath(dirname(__FILE__).'/../../'.Core::Cast($this->System)->Config['Web']['TempFolder'].'Export/'.$this->Id.'/');
    2625    if (!file_exists($this->TempDir)) mkdir($this->TempDir, 0777, true);
    2726    $this->TempDirRelative = Core::Cast($this->System)->Config['Web']['TempFolder'].'Export/'.$this->Id.'/';
    28     $this->SourceDir = dirname(__FILE__).'/../../'.Core::Cast($this->System)->Config['Web']['SourceFolder'];
     27    $this->SourceDir = NormalizePath(dirname(__FILE__).'/../../'.Core::Cast($this->System)->Config['Web']['SourceFolder']);
    2928    $this->SourceDirRelative = Core::Cast($this->System)->Config['Web']['SourceFolder'];
    3029    if (!file_exists($this->SourceDir)) mkdir($this->SourceDir, 0777, true);
     
    131130  }
    132131
    133   function NeedGeneration()
     132  function NeedGeneration(): bool
    134133  {
    135134    $this->LoadFilters();
    136     $file = '';
    137     if ($this->Export['OutputType'] == 10) $file = $this->TempDir.'Instalace_CzechWoW_'.$this->ClientVersion['Version'].'.exe';
    138     if ($this->Export['OutputType'] == 9) $file = $this->TempDir.'CzWoW_DBC.zip';
    139 
    140     if (file_exists($file))
    141       $date = date('Y-m-d H:i',(filemtime($file)));
     135    $FileName = '';
     136    if ($this->Export['OutputType'] == 10) $FileName = $this->TempDir.'Instalace_CzechWoW_'.$this->ClientVersion['Version'].'.exe';
     137    if ($this->Export['OutputType'] == 9) $FileName = $this->TempDir.'CzWoW_DBC.zip';
     138
     139    if (file_exists($FileName))
     140    {
     141      $Date = date('Y-m-d H:i',(filemtime($FileName)));
     142    }
    142143    else return true;
    143144
    144145    $DbResult = $this->Database->query('SELECT `Group`.* FROM `ExportGroup` '.
    145146      'JOIN `Group` ON `Group`.`Id` = `ExportGroup`.`Group` WHERE `ExportGroup`.`Export`='.$this->Id);
    146     $result = false;
     147    $Result = false;
    147148    while ($Group = $DbResult->fetch_assoc())
    148149    {
     
    151152      ' JOIN `User` ON `User`.`ID`=`T`.`User`'.
    152153      ' JOIN `ExportLanguage` ON (`ExportLanguage`.`Export`='.$this->Id.')'.
    153       ' WHERE ( \''.$date.'\' < `T`.`ModifyTime`) AND (`Complete` = 1) AND (`VersionStart` <= '.$this->ClientVersion['BuildNumber'].') AND (`VersionEnd` >= '.$this->ClientVersion['BuildNumber'].')'.
     154      ' WHERE ( \''.$Date.'\' < `T`.`ModifyTime`) AND (`Complete` = 1) AND (`VersionStart` <= '.$this->ClientVersion['BuildNumber'].') AND (`VersionEnd` >= '.$this->ClientVersion['BuildNumber'].')'.
    154155      ' ';
    155156
     
    157158      if ($DbResult2->num_rows > 0)
    158159      {
    159         $result = true;
    160       }
    161     }
    162     return $result;
     160        $Result = true;
     161      }
     162    }
     163    return $Result;
    163164  }
    164165
     
    206207          {
    207208            if ($GroupItem['MangosColumn'] == '') $GroupItem['MangosColumn'] = $GroupItem['Column'];
    208             $Values .= ', `'.$GroupItem['MangosColumn'].'`="'.addslashes($Line[$GroupItem['Column']]).'"';
     209            $Text = $Line[$GroupItem['Column']];
     210            if ($Text == null) $Text = '';
     211            $Values .= ', `'.$GroupItem['MangosColumn'].'`="'.addslashes($Text).'"';
    209212          }
    210213          $Values = substr($Values, 2);
     
    328331  }
    329332
    330   function ExportToDBC()
     333  function ExportToDBC(): string
    331334  {
    332335    $TranslationTree = $this->System->ModuleManager->Modules['Translation']->GetTranslationTree();
    333 
    334336    $this->LoadFilters();
    335 
    336337    $DbResult = $this->Database->query('SELECT `Group`.* FROM `ExportGroup` '.
    337338      'JOIN `Group` ON `Group`.`Id` = `ExportGroup`.`Group` '.
     
    342343      $this->AddProgress(2);
    343344      $Output .= $Group['Name'].', ';
    344       if (file_exists($this->SourceDir.$this->ClientVersion['Version'].'/dbc/'.$Group['DBCFileName'].'.dbc'))
     345
     346      $SourceDbcFileName = $this->SourceDir.$this->ClientVersion['Version'].'/dbc/'.$Group['DBCFileName'].'.dbc';
     347      if (file_exists($SourceDbcFileName))
    345348      {
    346349        // Load string column index list
     
    364367          foreach ($TranslationTree[$Group['Id']]['Items'] as $Column)
    365368          {
    366             $DbRow[$Column['Column']] = str_replace ('$ ', '$', $DbRow[$Column['Column']]);
    367             if (!$this->HaveVariable($DbRow['En'.$Column['Column']], $DbRow[$Column['Column']]))
     369            if ($DbRow[$Column['Column']] != null)
     370            {
     371              $DbRow[$Column['Column']] = str_replace('$ ', '$', $DbRow[$Column['Column']]);
     372            }
     373            $EnText = $DbRow['En'.$Column['Column']];
     374            if ($EnText == null) $EnText = '';
     375            $TargetText = $DbRow[$Column['Column']];
     376            if ($TargetText == null) $TargetText = '';
     377            if (!$this->HaveVariable($EnText, $TargetText))
    368378            {
    369379              $CanExport = false;
    370380              $Output .= ', NE='.$DbRow['ID'];
    371381            }
    372             if (!$this->HaveVariable($DbRow[$Column['Column']], $DbRow['En'.$Column['Column']]))
     382            if (!$this->HaveVariable($TargetText, $EnText))
    373383            {
    374384              $CanExport = false;
     
    383393        // Open original DBC file
    384394        $SourceDBCFile = new DBCFile();
    385         $SourceDBCFile->OpenFile($this->SourceDir.$this->ClientVersion['Version'].'/dbc/'.$Group['DBCFileName'].'.dbc', $ColumnFormat);
     395        $SourceDBCFile->OpenFile($SourceDbcFileName, $ColumnFormat);
    386396
    387397        // Create new DBC file
    388         if (!file_exists($this->TempDir.'dbc/')) mkdir($this->TempDir.'dbc/', 0777, true);
     398        $DbcDir = $this->TempDir.'dbc/';
     399        if (!file_exists($DbcDir)) mkdir($DbcDir, 0777, true);
    389400        $NewDBCFile = new DBCFile();
    390         $NewDBCFile->CreateFile($this->TempDir.'dbc/'.$Group['DBCFileName'].'.dbc', $ColumnFormat);
     401        $NewDBCFile->CreateFile($DbcDir.$Group['DBCFileName'].'.dbc', $ColumnFormat);
    391402        $NewDBCFile->SetRecordCount($SourceDBCFile->GetRecordCount());
    392403        $NewDBCFile->SetFieldCount($SourceDBCFile->GetFieldCount());
     
    436447        }
    437448        $NewDBCFile->Commit();
    438       } else $Output .= ShowMessage('Zdrojový soubor '.$this->SourceDirRelative.$this->ClientVersion['Version'].'/dbc/'.$Group['DBCFileName'].'.dbc'.' nenalezen.'."\n", MESSAGE_CRITICAL);
     449      } else $Output .= ShowMessage('Zdrojový soubor '.$SourceDbcFileName.' nenalezen.'."\n", MESSAGE_CRITICAL);
    439450    }
    440451    $Output .= 'Hotovo <br />';
     
    442453  }
    443454
    444   function ExportToLua()
     455  function ExportToLua(): string
    445456  {
    446457    $TranslationTree = $this->System->ModuleManager->Modules['Translation']->GetTranslationTree();
     
    449460
    450461    $Output = '';
    451     if (!file_exists($this->TempDir.'lua/')) mkdir($this->TempDir.'lua/', 0777, true);
     462    $LuaDir = $this->TempDir.'lua/';
     463    if (!file_exists($LuaDir)) mkdir($LuaDir, 0777, true);
    452464    $DbResult = $this->Database->query('SELECT `Group`.* FROM `ExportGroup` JOIN `Group` ON `Group`.`Id` = `ExportGroup`.`Group` WHERE `ExportGroup`.`Export`='.$this->Id.' AND `Group`.`LuaFileName` != ""');
    453465    while ($Group = $DbResult->fetch_assoc())
    454466    {
    455467      $this->AddProgress(1);
    456     //  $this->AddProgress();
    457468      $Output .= $Group['Name'].'... ';
    458469      $File = new FileStream();
    459       if (!file_exists($this->SourceDir.$this->ClientVersion['Version'].'/lua/'.$Group['LuaFileName'].'.lua'))
     470      $SourceLuaFileName = $this->SourceDir.$this->ClientVersion['Version'].'/lua/'.$Group['LuaFileName'].'.lua';
     471      if (!file_exists($SourceLuaFileName))
     472      {
    460473        continue;
    461       $File->OpenFile($this->SourceDir.$this->ClientVersion['Version'].'/lua/'.$Group['LuaFileName'].'.lua');
     474      }
     475      $File->OpenFile($SourceLuaFileName);
    462476      $File2 = new FileStream();
    463       $File2->CreateFile($this->TempDir.'lua/'.$Group['LuaFileName'].'.lua');
     477      $File2->CreateFile($LuaDir.$Group['LuaFileName'].'.lua');
    464478
    465479      $LookupTable = array();
     
    722736    if ($this->Export['WithDiacritic'] != 1) $Buffer = utf2ascii($Buffer);
    723737    $Buffer .= "  </translation>\n".
    724   "</document>";
     738      '</document>';
    725739    return $Buffer;
    726740  }
Note: See TracChangeset for help on using the changeset viewer.