Ticket #5599: 5599.2.diff
| File 5599.2.diff, 2.3 KB (added by ryan, 4 years ago) |
|---|
-
wp-includes/streams.php
58 58 function StringReader($str='') { 59 59 $this->_str = $str; 60 60 $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'); 61 63 } 62 64 63 65 function read($bytes) { 66 if ($this->is_overloaded) return $this->mb_read($bytes); 64 67 $data = substr($this->_str, $this->_pos, $bytes); 65 68 $this->_pos += $bytes; 66 69 if (strlen($this->_str)<$this->_pos) … … 68 71 69 72 return $data; 70 73 } 74 75 function mb_read($bytes) { 76 $data = mb_substr($this->_str, $this->_pos, $bytes, 'ascii'); 77 $this->_pos += $bytes; 78 if (mb_strlen($this->_str, 'ascii')<$this->_pos) 79 $this->_pos = mb_strlen($this->_str, 'ascii'); 71 80 81 return $data; 82 } 83 72 84 function seekto($pos) { 85 if ($this->is_overloaded) return $this->mb_seekto($pos); 73 86 $this->_pos = $pos; 74 87 if (strlen($this->_str)<$this->_pos) 75 88 $this->_pos = strlen($this->_str); 76 89 return $this->_pos; 77 90 } 91 92 function mb_seekto($pos) { 93 $this->_pos = $pos; 94 if (mb_strlen($this->_str, 'ascii')<$this->_pos) 95 $this->_pos = mb_strlen($this->_str, 'ascii'); 96 return $this->_pos; 97 } 78 98 79 99 function currentpos() { 80 100 return $this->_pos; 81 101 } 82 102 83 103 function length() { 104 if ($this->is_overloaded) return $this->mb_length(); 84 105 return strlen($this->_str); 85 106 } 86 107 108 function mb_length() { 109 return mb_strlen($this->str, 'ascii'); 110 } 111 87 112 } 88 113 89 114 … … 149 174 // over it (it assumes knowledge of StringReader internals) 150 175 class CachedFileReader extends StringReader { 151 176 function CachedFileReader($filename) { 177 parent::StringReader(); 178 152 179 if (file_exists($filename)) { 153 180 154 181 $length=filesize($filename); 155 182 $fd = fopen($filename,'rb'); 156 183 157 184 if (!$fd) { 158 $this->error = 3; // Cannot read file, probably permissions159 return false;185 $this->error = 3; // Cannot read file, probably permissions 186 return false; 160 187 } 161 188 $this->_str = fread($fd, $length); 162 $this->_pos = 0;163 189 fclose($fd); 164 190 165 191 } else {
