2011-02-22 Sancho Lerena <slerena@artica.es>
* include/streams.php: Fixed bug 3184746. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@3973 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
6704a2abaa
commit
c66ca0c5c3
|
@ -1,3 +1,7 @@
|
||||||
|
2011-02-22 Sancho Lerena <slerena@artica.es>
|
||||||
|
|
||||||
|
* include/streams.php: Fixed bug 3184746.
|
||||||
|
|
||||||
2011-02-22 Sergio Martin <sergio.martin@artica.es>
|
2011-02-22 Sergio Martin <sergio.martin@artica.es>
|
||||||
|
|
||||||
* include/languages/et.mo
|
* include/languages/et.mo
|
||||||
|
|
|
@ -1,185 +1,211 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/*l Library: StreamReader classes
|
||||||
* @package Include
|
*
|
||||||
* @subpackage External_Scripts
|
* @package External
|
||||||
*/
|
* @subpackage PHP-gettext
|
||||||
|
*
|
||||||
/*
|
* @internal
|
||||||
Copyright (c) 2003, 2005 Danilo Segan <danilo@kvota.net>.
|
Copyright (c) 2003, 2005 Danilo Segan <danilo@kvota.net>.
|
||||||
|
|
||||||
This file is part of PHP-gettext.
|
This file is part of PHP-gettext.
|
||||||
|
|
||||||
PHP-gettext is free software; you can redistribute it and/or modify
|
PHP-gettext is free software; you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
PHP-gettext is distributed in the hope that it will be useful,
|
PHP-gettext is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with PHP-gettext; if not, write to the Free Software
|
along with PHP-gettext; if not, write to the Free Software
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
//------------------------------------ BUGFIX related to WordPress 2.5.x upto 2.6.0 -----------------------------------------------------------
|
||||||
* Simple class to wrap file streams, string streams, etc.
|
// all contained patches have been marked with BUGFIX-HR handling the the issues of "mbstring.func_overload = x"
|
||||||
* seek is essential, and it should be byte stream
|
// where x & 2 != 0 (str* function overloads)
|
||||||
* @package Include
|
// this bug at WordPress forces any translation file to fail with gettext / unpack errors and maximum runtime exceeded fatal stop
|
||||||
* @subpackage Streams
|
// Autor: Heiko Rabe info@code-styling.de
|
||||||
*/
|
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
class StreamReader {
|
|
||||||
// should return a string [FIXME: perhaps return array of bytes?]
|
// Simple class to wrap file streams, string streams, etc.
|
||||||
function read($bytes) {
|
// seek is essential, and it should be byte stream
|
||||||
return false;
|
class StreamReader {
|
||||||
}
|
// should return a string [FIXME: perhaps return array of bytes?]
|
||||||
|
function read($bytes) {
|
||||||
// should return new position
|
return false;
|
||||||
function seekto($position) {
|
}
|
||||||
return false;
|
|
||||||
}
|
// should return new position
|
||||||
|
function seekto($position) {
|
||||||
// returns current position
|
return false;
|
||||||
function currentpos() {
|
}
|
||||||
return false;
|
|
||||||
}
|
// returns current position
|
||||||
|
function currentpos() {
|
||||||
// returns length of entire stream (limit for seekto()s)
|
return false;
|
||||||
function length() {
|
}
|
||||||
return false;
|
|
||||||
}
|
// returns length of entire stream (limit for seekto()s)
|
||||||
}
|
function length() {
|
||||||
|
return false;
|
||||||
/**
|
}
|
||||||
* @package Include
|
}
|
||||||
* @subpackage Streams
|
|
||||||
*/
|
class StringReader {
|
||||||
class StringReader {
|
var $_pos;
|
||||||
var $_pos;
|
var $_str;
|
||||||
var $_str;
|
|
||||||
|
function StringReader($str='') {
|
||||||
function StringReader($str='') {
|
$this->_str = $str;
|
||||||
$this->_str = $str;
|
$this->_pos = 0;
|
||||||
$this->_pos = 0;
|
//BUGFIX-HR: 2008-07-21 we have to detect, if we need mb_str* functions instead of normal functions !
|
||||||
}
|
$this->is_overloaded = ((ini_get("mbstring.func_overload") & 2) != 0) && function_exists('mb_substr');
|
||||||
|
}
|
||||||
function read($bytes) {
|
|
||||||
$data = substr($this->_str, $this->_pos, $bytes);
|
function read($bytes) {
|
||||||
$this->_pos += $bytes;
|
//BUGFIX-HR: 2008-07-21 if we are overloaded, use the mb_str* functions
|
||||||
if (strlen($this->_str)<$this->_pos)
|
if ($this->is_overloaded) return $this->mb_read($bytes);
|
||||||
$this->_pos = strlen($this->_str);
|
$data = substr($this->_str, $this->_pos, $bytes);
|
||||||
|
$this->_pos += $bytes;
|
||||||
return $data;
|
if (strlen($this->_str)<$this->_pos)
|
||||||
}
|
$this->_pos = strlen($this->_str);
|
||||||
|
|
||||||
function seekto($pos) {
|
return $data;
|
||||||
$this->_pos = $pos;
|
}
|
||||||
if (strlen($this->_str)<$this->_pos)
|
|
||||||
$this->_pos = strlen($this->_str);
|
//BUGFIX-HR: 2008-07-21 corresponding multi byte method
|
||||||
return $this->_pos;
|
function mb_read($bytes) {
|
||||||
}
|
$data = mb_substr($this->_str, $this->_pos, $bytes, 'ascii');
|
||||||
|
$this->_pos += $bytes;
|
||||||
function currentpos() {
|
if (mb_strlen($this->_str, 'ascii')<$this->_pos)
|
||||||
return $this->_pos;
|
$this->_pos = mb_strlen($this->_str, 'ascii');
|
||||||
}
|
|
||||||
|
return $data;
|
||||||
function length() {
|
}
|
||||||
return strlen($this->_str);
|
|
||||||
}
|
function seekto($pos) {
|
||||||
|
//BUGFIX-HR: 2008-07-21 if we are overloaded, use the mb_str* functions
|
||||||
}
|
if ($this->is_overloaded) return $this->mb_seekto($pos);
|
||||||
|
$this->_pos = $pos;
|
||||||
/**
|
if (strlen($this->_str)<$this->_pos)
|
||||||
* @package Include
|
$this->_pos = strlen($this->_str);
|
||||||
* @subpackage Streams
|
return $this->_pos;
|
||||||
*/
|
}
|
||||||
class FileReader {
|
|
||||||
var $_pos;
|
//BUGFIX-HR: 2008-07-21 corresponding multi byte method
|
||||||
var $_fd;
|
function mb_seekto($pos) {
|
||||||
var $_length;
|
$this->_pos = $pos;
|
||||||
|
if (mb_strlen($this->_str, 'ascii')<$this->_pos)
|
||||||
function FileReader($filename) {
|
$this->_pos = mb_strlen($this->_str, 'ascii');
|
||||||
if (file_exists($filename)) {
|
return $this->_pos;
|
||||||
|
}
|
||||||
$this->_length=filesize($filename);
|
|
||||||
$this->_pos = 0;
|
function currentpos() {
|
||||||
$this->_fd = fopen($filename,'rb');
|
return $this->_pos;
|
||||||
if (!$this->_fd) {
|
}
|
||||||
$this->error = 3; // Cannot read file, probably permissions
|
|
||||||
return false;
|
function length() {
|
||||||
}
|
//BUGFIX-HR: 2008-07-21 if we are overloaded, use the mb_str* functions
|
||||||
} else {
|
if ($this->is_overloaded) return $this->mb_length();
|
||||||
$this->error = 2; // File doesn't exist
|
return strlen($this->_str);
|
||||||
return false;
|
}
|
||||||
}
|
|
||||||
}
|
//BUGFIX-HR: 2008-07-21 corresponding multi byte method
|
||||||
|
function mb_length() {
|
||||||
function read($bytes) {
|
return mb_strlen($this->str, 'ascii');
|
||||||
if ($bytes) {
|
}
|
||||||
fseek($this->_fd, $this->_pos);
|
|
||||||
|
}
|
||||||
// PHP 5.1.1 does not read more than 8192 bytes in one fread()
|
|
||||||
// the discussions at PHP Bugs suggest it's the intended behaviour
|
|
||||||
while ($bytes > 0) {
|
class FileReader {
|
||||||
$chunk = fread($this->_fd, $bytes);
|
var $_pos;
|
||||||
$data .= $chunk;
|
var $_fd;
|
||||||
$bytes -= strlen($chunk);
|
var $_length;
|
||||||
}
|
|
||||||
$this->_pos = ftell($this->_fd);
|
function FileReader($filename) {
|
||||||
|
if (file_exists($filename)) {
|
||||||
return $data;
|
|
||||||
} else return '';
|
$this->_length=filesize($filename);
|
||||||
}
|
$this->_pos = 0;
|
||||||
|
$this->_fd = fopen($filename,'rb');
|
||||||
function seekto($pos) {
|
if (!$this->_fd) {
|
||||||
fseek($this->_fd, $pos);
|
$this->error = 3; // Cannot read file, probably permissions
|
||||||
$this->_pos = ftell($this->_fd);
|
return false;
|
||||||
return $this->_pos;
|
}
|
||||||
}
|
} else {
|
||||||
|
$this->error = 2; // File doesn't exist
|
||||||
function currentpos() {
|
return false;
|
||||||
return $this->_pos;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function length() {
|
function read($bytes) {
|
||||||
return $this->_length;
|
if ($bytes) {
|
||||||
}
|
fseek($this->_fd, $this->_pos);
|
||||||
|
|
||||||
function close() {
|
// PHP 5.1.1 does not read more than 8192 bytes in one fread()
|
||||||
fclose($this->_fd);
|
// the discussions at PHP Bugs suggest it's the intended behaviour
|
||||||
}
|
while ($bytes > 0) {
|
||||||
|
$chunk = fread($this->_fd, $bytes);
|
||||||
}
|
$data .= $chunk;
|
||||||
|
$bytes -= strlen($chunk);
|
||||||
/**
|
}
|
||||||
* Preloads entire file in memory first, then creates a StringReader
|
$this->_pos = ftell($this->_fd);
|
||||||
* over it (it assumes knowledge of StringReader internals)
|
|
||||||
* @package Include
|
return $data;
|
||||||
* @subpackage Streams
|
} else return '';
|
||||||
*/
|
}
|
||||||
class CachedFileReader extends StringReader {
|
|
||||||
function CachedFileReader($filename) {
|
function seekto($pos) {
|
||||||
if (file_exists($filename)) {
|
fseek($this->_fd, $pos);
|
||||||
|
$this->_pos = ftell($this->_fd);
|
||||||
$length=filesize($filename);
|
return $this->_pos;
|
||||||
$fd = fopen($filename,'rb');
|
}
|
||||||
|
|
||||||
if (!$fd) {
|
function currentpos() {
|
||||||
$this->error = 3; // Cannot read file, probably permissions
|
return $this->_pos;
|
||||||
return false;
|
}
|
||||||
}
|
|
||||||
$this->_str = fread($fd, $length);
|
function length() {
|
||||||
fclose($fd);
|
return $this->_length;
|
||||||
|
}
|
||||||
} else {
|
|
||||||
$this->error = 2; // File doesn't exist
|
function close() {
|
||||||
return false;
|
fclose($this->_fd);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Preloads entire file in memory first, then creates a StringReader
|
||||||
?>
|
// over it (it assumes knowledge of StringReader internals)
|
||||||
|
class CachedFileReader extends StringReader {
|
||||||
|
function CachedFileReader($filename) {
|
||||||
|
parent::StringReader(); //BUGFIX-HR: 2008-07-21 missing parent constructor call
|
||||||
|
if (file_exists($filename)) {
|
||||||
|
|
||||||
|
$length=filesize($filename);
|
||||||
|
$fd = fopen($filename,'rb');
|
||||||
|
|
||||||
|
if (!$fd) {
|
||||||
|
$this->error = 3; // Cannot read file, probably permissions
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$this->_str = fread($fd, $length);
|
||||||
|
//BUGFIX-HR: 2008-07-21 not longer nessessary, cause parent contructor properly called now
|
||||||
|
// $this->_pos = 0;
|
||||||
|
fclose($fd);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$this->error = 2; // File doesn't exist
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
Loading…
Reference in New Issue