Ticket #5599: 5599.diff

File 5599.diff, 3.5 KB (added by ryan, 4 years ago)
  • streams.php

     
    2626 
    2727 */ 
    2828 
     29 //------------------------------------ BUGFIX related to WordPress 2.5.x upto 2.6.0 ----------------------------------------------------------- 
     30 // all contained patches have been marked with BUGFIX-HR handling the the issues of "mbstring.func_overload = x"  
     31 // where x & 2 != 0 (str* function overloads) 
     32 // this bug at WordPress forces any translation file to fail with gettext / unpack errors and maximum runtime exceeded fatal stop 
     33 // Autor: Heiko Rabe  info@code-styling.de 
     34 //------------------------------------------------------------------------------------------------------------------------------------------------------------- 
    2935 
    3036// Simple class to wrap file streams, string streams, etc. 
    3137// seek is essential, and it should be byte stream 
     
    5864  function StringReader($str='') { 
    5965    $this->_str = $str; 
    6066    $this->_pos = 0; 
     67        //BUGFIX-HR: 2008-07-21 we have to detect, if we need mb_str* functions instead of normal functions ! 
     68        $this->is_overloaded = ((ini_get("mbstring.func_overload") & 2) != 0) && function_exists('mb_substr'); 
    6169  } 
    6270 
    6371  function read($bytes) { 
     72        //BUGFIX-HR: 2008-07-21 if we are overloaded, use the mb_str* functions 
     73        if ($this->is_overloaded) return $this->mb_read($bytes); 
    6474    $data = substr($this->_str, $this->_pos, $bytes); 
    6575    $this->_pos += $bytes; 
    6676    if (strlen($this->_str)<$this->_pos) 
     
    6878 
    6979    return $data; 
    7080  } 
     81   
     82  //BUGFIX-HR: 2008-07-21 corresponding multi byte method 
     83  function mb_read($bytes) { 
     84    $data = mb_substr($this->_str, $this->_pos, $bytes, 'ascii'); 
     85    $this->_pos += $bytes; 
     86    if (mb_strlen($this->_str, 'ascii')<$this->_pos) 
     87      $this->_pos = mb_strlen($this->_str, 'ascii'); 
    7188 
     89    return $data; 
     90  } 
     91 
    7292  function seekto($pos) { 
     93        //BUGFIX-HR: 2008-07-21 if we are overloaded, use the mb_str* functions 
     94        if ($this->is_overloaded) return $this->mb_seekto($pos); 
    7395    $this->_pos = $pos; 
    7496    if (strlen($this->_str)<$this->_pos) 
    7597      $this->_pos = strlen($this->_str); 
    7698    return $this->_pos; 
    7799  } 
     100   
     101  //BUGFIX-HR: 2008-07-21 corresponding multi byte method 
     102  function mb_seekto($pos) { 
     103    $this->_pos = $pos; 
     104    if (mb_strlen($this->_str, 'ascii')<$this->_pos) 
     105      $this->_pos = mb_strlen($this->_str, 'ascii'); 
     106    return $this->_pos; 
     107  } 
    78108 
    79109  function currentpos() { 
    80110    return $this->_pos; 
    81111  } 
    82  
     112   
    83113  function length() { 
     114        //BUGFIX-HR: 2008-07-21 if we are overloaded, use the mb_str* functions 
     115        if ($this->is_overloaded) return $this->mb_length(); 
    84116    return strlen($this->_str); 
    85117  } 
    86118 
     119  //BUGFIX-HR: 2008-07-21 corresponding multi byte method 
     120  function mb_length() { 
     121        return mb_strlen($this->str, 'ascii'); 
     122  } 
     123   
    87124} 
    88125 
    89126 
     
    149186// over it (it assumes knowledge of StringReader internals) 
    150187class CachedFileReader extends StringReader { 
    151188  function CachedFileReader($filename) { 
     189        parent::StringReader(); //BUGFIX-HR: 2008-07-21 missing parent constructor call 
    152190    if (file_exists($filename)) { 
    153191 
    154192      $length=filesize($filename); 
    155193      $fd = fopen($filename,'rb'); 
    156194 
    157195      if (!$fd) { 
    158         $this->error = 3; // Cannot read file, probably permissions 
    159         return false; 
     196                $this->error = 3; // Cannot read file, probably permissions 
     197                return false; 
    160198      } 
    161199      $this->_str = fread($fd, $length); 
    162           $this->_pos = 0; 
     200//BUGFIX-HR: 2008-07-21 not longer nessessary, cause parent contructor properly called now 
     201//        $this->_pos = 0; 
    163202          fclose($fd); 
    164203 
    165204    } else {