Edit File by line
/home/barbar84/www/wp-inclu.../pomo
File: streams.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Classes, which help reading streams of data from files.
[2] Fix | Delete
* Based on the classes from Danilo Segan <danilo@kvota.net>
[3] Fix | Delete
*
[4] Fix | Delete
* @version $Id: streams.php 1157 2015-11-20 04:30:11Z dd32 $
[5] Fix | Delete
* @package pomo
[6] Fix | Delete
* @subpackage streams
[7] Fix | Delete
*/
[8] Fix | Delete
[9] Fix | Delete
if ( ! class_exists( 'POMO_Reader', false ) ) :
[10] Fix | Delete
class POMO_Reader {
[11] Fix | Delete
[12] Fix | Delete
public $endian = 'little';
[13] Fix | Delete
public $_post = '';
[14] Fix | Delete
[15] Fix | Delete
/**
[16] Fix | Delete
* PHP5 constructor.
[17] Fix | Delete
*/
[18] Fix | Delete
function __construct() {
[19] Fix | Delete
$this->is_overloaded = ( ( ini_get( 'mbstring.func_overload' ) & 2 ) != 0 ) && function_exists( 'mb_substr' ); // phpcs:ignore PHPCompatibility.IniDirectives.RemovedIniDirectives.mbstring_func_overloadDeprecated
[20] Fix | Delete
$this->_pos = 0;
[21] Fix | Delete
}
[22] Fix | Delete
[23] Fix | Delete
/**
[24] Fix | Delete
* PHP4 constructor.
[25] Fix | Delete
*
[26] Fix | Delete
* @deprecated 5.4.0 Use __construct() instead.
[27] Fix | Delete
*
[28] Fix | Delete
* @see POMO_Reader::__construct()
[29] Fix | Delete
*/
[30] Fix | Delete
public function POMO_Reader() {
[31] Fix | Delete
_deprecated_constructor( self::class, '5.4.0', static::class );
[32] Fix | Delete
self::__construct();
[33] Fix | Delete
}
[34] Fix | Delete
[35] Fix | Delete
/**
[36] Fix | Delete
* Sets the endianness of the file.
[37] Fix | Delete
*
[38] Fix | Delete
* @param string $endian Set the endianness of the file. Accepts 'big', or 'little'.
[39] Fix | Delete
*/
[40] Fix | Delete
function setEndian( $endian ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid
[41] Fix | Delete
$this->endian = $endian;
[42] Fix | Delete
}
[43] Fix | Delete
[44] Fix | Delete
/**
[45] Fix | Delete
* Reads a 32bit Integer from the Stream
[46] Fix | Delete
*
[47] Fix | Delete
* @return mixed The integer, corresponding to the next 32 bits from
[48] Fix | Delete
* the stream of false if there are not enough bytes or on error
[49] Fix | Delete
*/
[50] Fix | Delete
function readint32() {
[51] Fix | Delete
$bytes = $this->read( 4 );
[52] Fix | Delete
if ( 4 != $this->strlen( $bytes ) ) {
[53] Fix | Delete
return false;
[54] Fix | Delete
}
[55] Fix | Delete
$endian_letter = ( 'big' === $this->endian ) ? 'N' : 'V';
[56] Fix | Delete
$int = unpack( $endian_letter, $bytes );
[57] Fix | Delete
return reset( $int );
[58] Fix | Delete
}
[59] Fix | Delete
[60] Fix | Delete
/**
[61] Fix | Delete
* Reads an array of 32-bit Integers from the Stream
[62] Fix | Delete
*
[63] Fix | Delete
* @param int $count How many elements should be read
[64] Fix | Delete
* @return mixed Array of integers or false if there isn't
[65] Fix | Delete
* enough data or on error
[66] Fix | Delete
*/
[67] Fix | Delete
function readint32array( $count ) {
[68] Fix | Delete
$bytes = $this->read( 4 * $count );
[69] Fix | Delete
if ( 4 * $count != $this->strlen( $bytes ) ) {
[70] Fix | Delete
return false;
[71] Fix | Delete
}
[72] Fix | Delete
$endian_letter = ( 'big' === $this->endian ) ? 'N' : 'V';
[73] Fix | Delete
return unpack( $endian_letter . $count, $bytes );
[74] Fix | Delete
}
[75] Fix | Delete
[76] Fix | Delete
/**
[77] Fix | Delete
* @param string $string
[78] Fix | Delete
* @param int $start
[79] Fix | Delete
* @param int $length
[80] Fix | Delete
* @return string
[81] Fix | Delete
*/
[82] Fix | Delete
function substr( $string, $start, $length ) {
[83] Fix | Delete
if ( $this->is_overloaded ) {
[84] Fix | Delete
return mb_substr( $string, $start, $length, 'ascii' );
[85] Fix | Delete
} else {
[86] Fix | Delete
return substr( $string, $start, $length );
[87] Fix | Delete
}
[88] Fix | Delete
}
[89] Fix | Delete
[90] Fix | Delete
/**
[91] Fix | Delete
* @param string $string
[92] Fix | Delete
* @return int
[93] Fix | Delete
*/
[94] Fix | Delete
function strlen( $string ) {
[95] Fix | Delete
if ( $this->is_overloaded ) {
[96] Fix | Delete
return mb_strlen( $string, 'ascii' );
[97] Fix | Delete
} else {
[98] Fix | Delete
return strlen( $string );
[99] Fix | Delete
}
[100] Fix | Delete
}
[101] Fix | Delete
[102] Fix | Delete
/**
[103] Fix | Delete
* @param string $string
[104] Fix | Delete
* @param int $chunk_size
[105] Fix | Delete
* @return array
[106] Fix | Delete
*/
[107] Fix | Delete
function str_split( $string, $chunk_size ) {
[108] Fix | Delete
if ( ! function_exists( 'str_split' ) ) {
[109] Fix | Delete
$length = $this->strlen( $string );
[110] Fix | Delete
$out = array();
[111] Fix | Delete
for ( $i = 0; $i < $length; $i += $chunk_size ) {
[112] Fix | Delete
$out[] = $this->substr( $string, $i, $chunk_size );
[113] Fix | Delete
}
[114] Fix | Delete
return $out;
[115] Fix | Delete
} else {
[116] Fix | Delete
return str_split( $string, $chunk_size );
[117] Fix | Delete
}
[118] Fix | Delete
}
[119] Fix | Delete
[120] Fix | Delete
/**
[121] Fix | Delete
* @return int
[122] Fix | Delete
*/
[123] Fix | Delete
function pos() {
[124] Fix | Delete
return $this->_pos;
[125] Fix | Delete
}
[126] Fix | Delete
[127] Fix | Delete
/**
[128] Fix | Delete
* @return true
[129] Fix | Delete
*/
[130] Fix | Delete
function is_resource() {
[131] Fix | Delete
return true;
[132] Fix | Delete
}
[133] Fix | Delete
[134] Fix | Delete
/**
[135] Fix | Delete
* @return true
[136] Fix | Delete
*/
[137] Fix | Delete
function close() {
[138] Fix | Delete
return true;
[139] Fix | Delete
}
[140] Fix | Delete
}
[141] Fix | Delete
endif;
[142] Fix | Delete
[143] Fix | Delete
if ( ! class_exists( 'POMO_FileReader', false ) ) :
[144] Fix | Delete
class POMO_FileReader extends POMO_Reader {
[145] Fix | Delete
[146] Fix | Delete
/**
[147] Fix | Delete
* @param string $filename
[148] Fix | Delete
*/
[149] Fix | Delete
function __construct( $filename ) {
[150] Fix | Delete
parent::__construct();
[151] Fix | Delete
$this->_f = fopen( $filename, 'rb' );
[152] Fix | Delete
}
[153] Fix | Delete
[154] Fix | Delete
/**
[155] Fix | Delete
* PHP4 constructor.
[156] Fix | Delete
*
[157] Fix | Delete
* @deprecated 5.4.0 Use __construct() instead.
[158] Fix | Delete
*
[159] Fix | Delete
* @see POMO_FileReader::__construct()
[160] Fix | Delete
*/
[161] Fix | Delete
public function POMO_FileReader( $filename ) {
[162] Fix | Delete
_deprecated_constructor( self::class, '5.4.0', static::class );
[163] Fix | Delete
self::__construct( $filename );
[164] Fix | Delete
}
[165] Fix | Delete
[166] Fix | Delete
/**
[167] Fix | Delete
* @param int $bytes
[168] Fix | Delete
* @return string|false Returns read string, otherwise false.
[169] Fix | Delete
*/
[170] Fix | Delete
function read( $bytes ) {
[171] Fix | Delete
return fread( $this->_f, $bytes );
[172] Fix | Delete
}
[173] Fix | Delete
[174] Fix | Delete
/**
[175] Fix | Delete
* @param int $pos
[176] Fix | Delete
* @return bool
[177] Fix | Delete
*/
[178] Fix | Delete
function seekto( $pos ) {
[179] Fix | Delete
if ( -1 == fseek( $this->_f, $pos, SEEK_SET ) ) {
[180] Fix | Delete
return false;
[181] Fix | Delete
}
[182] Fix | Delete
$this->_pos = $pos;
[183] Fix | Delete
return true;
[184] Fix | Delete
}
[185] Fix | Delete
[186] Fix | Delete
/**
[187] Fix | Delete
* @return bool
[188] Fix | Delete
*/
[189] Fix | Delete
function is_resource() {
[190] Fix | Delete
return is_resource( $this->_f );
[191] Fix | Delete
}
[192] Fix | Delete
[193] Fix | Delete
/**
[194] Fix | Delete
* @return bool
[195] Fix | Delete
*/
[196] Fix | Delete
function feof() {
[197] Fix | Delete
return feof( $this->_f );
[198] Fix | Delete
}
[199] Fix | Delete
[200] Fix | Delete
/**
[201] Fix | Delete
* @return bool
[202] Fix | Delete
*/
[203] Fix | Delete
function close() {
[204] Fix | Delete
return fclose( $this->_f );
[205] Fix | Delete
}
[206] Fix | Delete
[207] Fix | Delete
/**
[208] Fix | Delete
* @return string
[209] Fix | Delete
*/
[210] Fix | Delete
function read_all() {
[211] Fix | Delete
$all = '';
[212] Fix | Delete
while ( ! $this->feof() ) {
[213] Fix | Delete
$all .= $this->read( 4096 );
[214] Fix | Delete
}
[215] Fix | Delete
return $all;
[216] Fix | Delete
}
[217] Fix | Delete
}
[218] Fix | Delete
endif;
[219] Fix | Delete
[220] Fix | Delete
if ( ! class_exists( 'POMO_StringReader', false ) ) :
[221] Fix | Delete
/**
[222] Fix | Delete
* Provides file-like methods for manipulating a string instead
[223] Fix | Delete
* of a physical file.
[224] Fix | Delete
*/
[225] Fix | Delete
class POMO_StringReader extends POMO_Reader {
[226] Fix | Delete
[227] Fix | Delete
public $_str = '';
[228] Fix | Delete
[229] Fix | Delete
/**
[230] Fix | Delete
* PHP5 constructor.
[231] Fix | Delete
*/
[232] Fix | Delete
function __construct( $str = '' ) {
[233] Fix | Delete
parent::__construct();
[234] Fix | Delete
$this->_str = $str;
[235] Fix | Delete
$this->_pos = 0;
[236] Fix | Delete
}
[237] Fix | Delete
[238] Fix | Delete
/**
[239] Fix | Delete
* PHP4 constructor.
[240] Fix | Delete
*
[241] Fix | Delete
* @deprecated 5.4.0 Use __construct() instead.
[242] Fix | Delete
*
[243] Fix | Delete
* @see POMO_StringReader::__construct()
[244] Fix | Delete
*/
[245] Fix | Delete
public function POMO_StringReader( $str = '' ) {
[246] Fix | Delete
_deprecated_constructor( self::class, '5.4.0', static::class );
[247] Fix | Delete
self::__construct( $str );
[248] Fix | Delete
}
[249] Fix | Delete
[250] Fix | Delete
/**
[251] Fix | Delete
* @param string $bytes
[252] Fix | Delete
* @return string
[253] Fix | Delete
*/
[254] Fix | Delete
function read( $bytes ) {
[255] Fix | Delete
$data = $this->substr( $this->_str, $this->_pos, $bytes );
[256] Fix | Delete
$this->_pos += $bytes;
[257] Fix | Delete
if ( $this->strlen( $this->_str ) < $this->_pos ) {
[258] Fix | Delete
$this->_pos = $this->strlen( $this->_str );
[259] Fix | Delete
}
[260] Fix | Delete
return $data;
[261] Fix | Delete
}
[262] Fix | Delete
[263] Fix | Delete
/**
[264] Fix | Delete
* @param int $pos
[265] Fix | Delete
* @return int
[266] Fix | Delete
*/
[267] Fix | Delete
function seekto( $pos ) {
[268] Fix | Delete
$this->_pos = $pos;
[269] Fix | Delete
if ( $this->strlen( $this->_str ) < $this->_pos ) {
[270] Fix | Delete
$this->_pos = $this->strlen( $this->_str );
[271] Fix | Delete
}
[272] Fix | Delete
return $this->_pos;
[273] Fix | Delete
}
[274] Fix | Delete
[275] Fix | Delete
/**
[276] Fix | Delete
* @return int
[277] Fix | Delete
*/
[278] Fix | Delete
function length() {
[279] Fix | Delete
return $this->strlen( $this->_str );
[280] Fix | Delete
}
[281] Fix | Delete
[282] Fix | Delete
/**
[283] Fix | Delete
* @return string
[284] Fix | Delete
*/
[285] Fix | Delete
function read_all() {
[286] Fix | Delete
return $this->substr( $this->_str, $this->_pos, $this->strlen( $this->_str ) );
[287] Fix | Delete
}
[288] Fix | Delete
[289] Fix | Delete
}
[290] Fix | Delete
endif;
[291] Fix | Delete
[292] Fix | Delete
if ( ! class_exists( 'POMO_CachedFileReader', false ) ) :
[293] Fix | Delete
/**
[294] Fix | Delete
* Reads the contents of the file in the beginning.
[295] Fix | Delete
*/
[296] Fix | Delete
class POMO_CachedFileReader extends POMO_StringReader {
[297] Fix | Delete
/**
[298] Fix | Delete
* PHP5 constructor.
[299] Fix | Delete
*/
[300] Fix | Delete
function __construct( $filename ) {
[301] Fix | Delete
parent::__construct();
[302] Fix | Delete
$this->_str = file_get_contents( $filename );
[303] Fix | Delete
if ( false === $this->_str ) {
[304] Fix | Delete
return false;
[305] Fix | Delete
}
[306] Fix | Delete
$this->_pos = 0;
[307] Fix | Delete
}
[308] Fix | Delete
[309] Fix | Delete
/**
[310] Fix | Delete
* PHP4 constructor.
[311] Fix | Delete
*
[312] Fix | Delete
* @deprecated 5.4.0 Use __construct() instead.
[313] Fix | Delete
*
[314] Fix | Delete
* @see POMO_CachedFileReader::__construct()
[315] Fix | Delete
*/
[316] Fix | Delete
public function POMO_CachedFileReader( $filename ) {
[317] Fix | Delete
_deprecated_constructor( self::class, '5.4.0', static::class );
[318] Fix | Delete
self::__construct( $filename );
[319] Fix | Delete
}
[320] Fix | Delete
}
[321] Fix | Delete
endif;
[322] Fix | Delete
[323] Fix | Delete
if ( ! class_exists( 'POMO_CachedIntFileReader', false ) ) :
[324] Fix | Delete
/**
[325] Fix | Delete
* Reads the contents of the file in the beginning.
[326] Fix | Delete
*/
[327] Fix | Delete
class POMO_CachedIntFileReader extends POMO_CachedFileReader {
[328] Fix | Delete
/**
[329] Fix | Delete
* PHP5 constructor.
[330] Fix | Delete
*/
[331] Fix | Delete
public function __construct( $filename ) {
[332] Fix | Delete
parent::__construct( $filename );
[333] Fix | Delete
}
[334] Fix | Delete
[335] Fix | Delete
/**
[336] Fix | Delete
* PHP4 constructor.
[337] Fix | Delete
*
[338] Fix | Delete
* @deprecated 5.4.0 Use __construct() instead.
[339] Fix | Delete
*
[340] Fix | Delete
* @see POMO_CachedIntFileReader::__construct()
[341] Fix | Delete
*/
[342] Fix | Delete
function POMO_CachedIntFileReader( $filename ) {
[343] Fix | Delete
_deprecated_constructor( self::class, '5.4.0', static::class );
[344] Fix | Delete
self::__construct( $filename );
[345] Fix | Delete
}
[346] Fix | Delete
}
[347] Fix | Delete
endif;
[348] Fix | Delete
[349] Fix | Delete
[350] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function