Ticket #5599: 5599.diff
| File 5599.diff, 3.5 KB (added by ryan, 4 years ago) |
|---|
-
streams.php
26 26 27 27 */ 28 28 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 //------------------------------------------------------------------------------------------------------------------------------------------------------------- 29 35 30 36 // Simple class to wrap file streams, string streams, etc. 31 37 // seek is essential, and it should be byte stream … … 58 64 function StringReader($str='') { 59 65 $this->_str = $str; 60 66 $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'); 61 69 } 62 70 63 71 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); 64 74 $data = substr($this->_str, $this->_pos, $bytes); 65 75 $this->_pos += $bytes; 66 76 if (strlen($this->_str)<$this->_pos) … … 68 78 69 79 return $data; 70 80 } 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'); 71 88 89 return $data; 90 } 91 72 92 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); 73 95 $this->_pos = $pos; 74 96 if (strlen($this->_str)<$this->_pos) 75 97 $this->_pos = strlen($this->_str); 76 98 return $this->_pos; 77 99 } 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 } 78 108 79 109 function currentpos() { 80 110 return $this->_pos; 81 111 } 82 112 83 113 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(); 84 116 return strlen($this->_str); 85 117 } 86 118 119 //BUGFIX-HR: 2008-07-21 corresponding multi byte method 120 function mb_length() { 121 return mb_strlen($this->str, 'ascii'); 122 } 123 87 124 } 88 125 89 126 … … 149 186 // over it (it assumes knowledge of StringReader internals) 150 187 class CachedFileReader extends StringReader { 151 188 function CachedFileReader($filename) { 189 parent::StringReader(); //BUGFIX-HR: 2008-07-21 missing parent constructor call 152 190 if (file_exists($filename)) { 153 191 154 192 $length=filesize($filename); 155 193 $fd = fopen($filename,'rb'); 156 194 157 195 if (!$fd) { 158 $this->error = 3; // Cannot read file, probably permissions159 return false;196 $this->error = 3; // Cannot read file, probably permissions 197 return false; 160 198 } 161 199 $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; 163 202 fclose($fd); 164 203 165 204 } else {
