Changeset 819 for trunk/includes


Ignore:
Timestamp:
Feb 23, 2015, 12:56:12 AM (10 years ago)
Author:
chronos
Message:
  • Added: Class for UTF8 to other charset conversion.
  • Fixed: Google translate text conversion to UTF8.
  • Fixed: Correct $System variable reference in TranslateList.
Location:
trunk/includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/Version.php

    r818 r819  
    66// and system will need database update.
    77
    8 $Revision = 818; // Subversion revision
     8$Revision = 819; // Subversion revision
    99$DatabaseRevision = 811; // Database structure revision
    1010$ReleaseTime = '2015-02-22';
  • trunk/includes/global.php

    r816 r819  
    1111include_once(dirname(__FILE__).'/AppModule.php');
    1212include_once(dirname(__FILE__).'/Locale.php');
     13include_once(dirname(__FILE__).'/UTF8.php');
    1314require_once(dirname(__FILE__).'/../HTML/BBCodeParser2.php');
    1415
     
    145146}
    146147
    147 
    148 function GetTranslateGoogle($text,$withouttitle = false) {
     148function GetTranslateGoogle($text, $withouttitle = false)
     149{
    149150  global $System;
     151
    150152//  $text = 'Balthule\'s letter is dire. This Cult of the Dark Strand is a thorn in my side that must be removed. I have been dealing with some of the Dark Strand scum northeast of here at Ordil\'Aran. One of their number possesses a soul gem that I believe holds the secret to the cult\'s power.$b$bBring it to me, and I will be able to decipher the secrets held within.';
    151153 // $text = htmlspecialchars($text);
    152154
    153   $text = str_replace('$B','$B ',$text);
     155  $text = str_replace('$B','$B ', $text);
    154156  $text = urlencode($text);
    155157 // $text = strtolower($text);
    156158//  $text = str_replace('&','',$text);
    157159//  $text = str_replace(' ','%20',$text);
    158   if ($System->User->Language == 2)
    159     $lang = 'sk';
    160   else $lang = 'cs';
     160  $DbResult = $System->Database->select('Language', 'Code', 'Id='.$System->User->Language);
     161  $DbRow = $DbResult->fetch_assoc();
     162  $lang = $DbRow['Code'];
    161163  $url = 'http://translate.google.cz/?sl=en&tl='.$lang.'&text='.$text;
    162164
    163 
    164165  error_reporting(E_ALL ^ E_WARNING);
    165   if (($handle = @fopen($url, "r")) === FALSE) return false;
     166  if (($handle = @fopen($url, "r")) === FALSE) return(false);
    166167
    167168  $data = stream_get_contents($handle);
    168   $data = substr($data, strpos($data,'result_box'));
    169   $data = substr($data, strpos($data,'>')+1);
    170   $data = substr($data, 0, strpos($data,'</div>'));
     169  $data = substr($data, strpos($data, 'result_box'));
     170  $data = substr($data, strpos($data, '>') + 1);
     171  $data = substr($data, 0, strpos($data, '</div>'));
    171172
    172173  if ($withouttitle)
    173   while ((strpos($data,'>') !== false and strpos($data,'<') !== false) and (strpos($data,'>') > strpos($data,'<')))
    174   {
    175     $partbefore = substr($data, 0, strpos($data,'<'));
     174  while ((strpos($data, '>') !== false and (strpos($data, '<') !== false)) and (strpos($data, '>') > strpos($data, '<')))
     175  {
     176    $partbefore = substr($data, 0, strpos($data, '<'));
    176177    //  echo $partbefore;
    177     $partafter = substr($data, strpos($data,'>')+1);
     178    $partafter = substr($data, strpos($data, '>') + 1);
    178179    // echo $partafter;
    179180    $data = $partbefore.' '.$partafter;
    180181  }
    181182
    182   $data = utf8_encode($data);
    183 
    184   $data = str_replace('$ ','$',$data);
    185   $data = str_replace('$b $b','$b$b',$data);
    186   $data = str_replace('| ','|',$data);
    187 
    188   return $data;
     183  $Encoding = new Encoding();
     184  $data = $Encoding->ToUTF8($data);
     185  //$data = utf8_encode($data);
     186
     187  $data = str_replace('$ ', '$',$data);
     188  $data = str_replace('$b $b', '$b$b', $data);
     189  $data = str_replace('| ', '|', $data);
     190
     191  return($data);
    189192}
    190193
Note: See TracChangeset for help on using the changeset viewer.