WordPress.org

Make WordPress Core

Ticket #5599: 5599.alternate.diff

File 5599.alternate.diff, 2.2 KB (added by westi, 11 years ago)

Rejigged patch

  • wp-includes/streams.php

     
    5858  function StringReader($str='') {
    5959    $this->_str = $str;
    6060    $this->_pos = 0;
     61    // If string functions are overloaded, we need to use the mb versions
     62    $this->is_overloaded = ((ini_get("mbstring.func_overload") & 2) != 0) && function_exists('mb_substr');
    6163  }
    6264
     65  function _substr($string, $start, $length) {
     66        if ($this->is_overloaded) {
     67                return mb_substr($string,$start,$length,'ascii');
     68        } else {
     69                return substr($string,$start,$length);
     70        }
     71  }
     72
     73  function _strlen($string) {
     74        if ($this->is_overloaded) {
     75                return mb_strlen($string,'ascii');
     76        } else {
     77                return strlen($string);
     78        }
     79  }
     80
    6381  function read($bytes) {
    64     $data = substr($this->_str, $this->_pos, $bytes);
     82          $data = $this->_substr($this->_str, $this->_pos, $bytes);
    6583    $this->_pos += $bytes;
    66     if (strlen($this->_str)<$this->_pos)
    67       $this->_pos = strlen($this->_str);
     84    if ($this->_strlen($this->_str)<$this->_pos)
     85      $this->_pos = $this->_strlen($this->_str);
    6886
    6987    return $data;
    7088  }
    7189
    7290  function seekto($pos) {
    7391    $this->_pos = $pos;
    74     if (strlen($this->_str)<$this->_pos)
    75       $this->_pos = strlen($this->_str);
     92    if ($this->_strlen($this->_str)<$this->_pos)
     93      $this->_pos = $this->_strlen($this->_str);
    7694    return $this->_pos;
    7795  }
    7896
     
    8199  }
    82100
    83101  function length() {
    84     return strlen($this->_str);
     102    return $this->_strlen($this->_str);
    85103  }
    86 
    87104}
    88105
    89106
     
    149166// over it (it assumes knowledge of StringReader internals)
    150167class CachedFileReader extends StringReader {
    151168  function CachedFileReader($filename) {
     169    parent::StringReader();
     170
    152171    if (file_exists($filename)) {
    153172
    154173      $length=filesize($filename);
    155174      $fd = fopen($filename,'rb');
    156175
    157176      if (!$fd) {
    158         $this->error = 3; // Cannot read file, probably permissions
    159         return false;
     177        $this->error = 3; // Cannot read file, probably permissions
     178        return false;
    160179      }
    161180      $this->_str = fread($fd, $length);
    162           $this->_pos = 0;
    163181          fclose($fd);
    164182
    165183    } else {