080600
This commit is contained in:
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,30 +1,30 @@
|
||||
/////////////////////////////////////////////////////////////////
|
||||
/// getID3() by James Heinrich <info@getid3.org> //
|
||||
// available at http://getid3.sourceforge.net //
|
||||
// or https://www.getid3.org //
|
||||
// also https://github.com/JamesHeinrich/getID3 //
|
||||
/////////////////////////////////////////////////////////////////
|
||||
|
||||
*****************************************************************
|
||||
*****************************************************************
|
||||
|
||||
getID3() is released under multiple licenses. You may choose
|
||||
from the following licenses, and use getID3 according to the
|
||||
terms of the license most suitable to your project.
|
||||
|
||||
GNU GPL: https://gnu.org/licenses/gpl.html (v3)
|
||||
https://gnu.org/licenses/old-licenses/gpl-2.0.html (v2)
|
||||
https://gnu.org/licenses/old-licenses/gpl-1.0.html (v1)
|
||||
|
||||
GNU LGPL: https://gnu.org/licenses/lgpl.html (v3)
|
||||
|
||||
Mozilla MPL: https://www.mozilla.org/MPL/2.0/ (v2)
|
||||
|
||||
getID3 Commercial License: https://www.getid3.org/#gCL
|
||||
(no longer available, existing licenses remain valid)
|
||||
|
||||
*****************************************************************
|
||||
*****************************************************************
|
||||
|
||||
Copies of each of the above licenses are included in the 'licenses'
|
||||
directory of the getID3 distribution.
|
||||
/////////////////////////////////////////////////////////////////
|
||||
/// getID3() by James Heinrich <info@getid3.org> //
|
||||
// available at http://getid3.sourceforge.net //
|
||||
// or https://www.getid3.org //
|
||||
// also https://github.com/JamesHeinrich/getID3 //
|
||||
/////////////////////////////////////////////////////////////////
|
||||
|
||||
*****************************************************************
|
||||
*****************************************************************
|
||||
|
||||
getID3() is released under multiple licenses. You may choose
|
||||
from the following licenses, and use getID3 according to the
|
||||
terms of the license most suitable to your project.
|
||||
|
||||
GNU GPL: https://gnu.org/licenses/gpl.html (v3)
|
||||
https://gnu.org/licenses/old-licenses/gpl-2.0.html (v2)
|
||||
https://gnu.org/licenses/old-licenses/gpl-1.0.html (v1)
|
||||
|
||||
GNU LGPL: https://gnu.org/licenses/lgpl.html (v3)
|
||||
|
||||
Mozilla MPL: https://www.mozilla.org/MPL/2.0/ (v2)
|
||||
|
||||
getID3 Commercial License: https://www.getid3.org/#gCL
|
||||
(no longer available, existing licenses remain valid)
|
||||
|
||||
*****************************************************************
|
||||
*****************************************************************
|
||||
|
||||
Copies of each of the above licenses are included in the 'licenses'
|
||||
directory of the getID3 distribution.
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,327 +1,327 @@
|
||||
<?php
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
/// getID3() by James Heinrich <info@getid3.org> //
|
||||
// available at https://github.com/JamesHeinrich/getID3 //
|
||||
// or https://www.getid3.org //
|
||||
// or http://getid3.sourceforge.net //
|
||||
// see readme.txt for more details //
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// module.audio.dts.php //
|
||||
// module for analyzing DTS Audio files //
|
||||
// dependencies: NONE //
|
||||
// //
|
||||
/////////////////////////////////////////////////////////////////
|
||||
|
||||
if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tutorial http://wiki.multimedia.cx/index.php?title=DTS
|
||||
*/
|
||||
class getid3_dts extends getid3_handler
|
||||
{
|
||||
/**
|
||||
* Default DTS syncword used in native .cpt or .dts formats.
|
||||
*/
|
||||
const syncword = "\x7F\xFE\x80\x01";
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $readBinDataOffset = 0;
|
||||
|
||||
/**
|
||||
* Possible syncwords indicating bitstream encoding.
|
||||
*/
|
||||
public static $syncwords = array(
|
||||
0 => "\x7F\xFE\x80\x01", // raw big-endian
|
||||
1 => "\xFE\x7F\x01\x80", // raw little-endian
|
||||
2 => "\x1F\xFF\xE8\x00", // 14-bit big-endian
|
||||
3 => "\xFF\x1F\x00\xE8"); // 14-bit little-endian
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function Analyze() {
|
||||
$info = &$this->getid3->info;
|
||||
$info['fileformat'] = 'dts';
|
||||
|
||||
$this->fseek($info['avdataoffset']);
|
||||
$DTSheader = $this->fread(20); // we only need 2 words magic + 6 words frame header, but these words may be normal 16-bit words OR 14-bit words with 2 highest bits set to zero, so 8 words can be either 8*16/8 = 16 bytes OR 8*16*(16/14)/8 = 18.3 bytes
|
||||
|
||||
// check syncword
|
||||
$sync = substr($DTSheader, 0, 4);
|
||||
if (($encoding = array_search($sync, self::$syncwords)) !== false) {
|
||||
|
||||
$info['dts']['raw']['magic'] = $sync;
|
||||
$this->readBinDataOffset = 32;
|
||||
|
||||
} elseif ($this->isDependencyFor('matroska')) {
|
||||
|
||||
// Matroska contains DTS without syncword encoded as raw big-endian format
|
||||
$encoding = 0;
|
||||
$this->readBinDataOffset = 0;
|
||||
|
||||
} else {
|
||||
|
||||
unset($info['fileformat']);
|
||||
return $this->error('Expecting "'.implode('| ', array_map('getid3_lib::PrintHexBytes', self::$syncwords)).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($sync).'"');
|
||||
|
||||
}
|
||||
|
||||
// decode header
|
||||
$fhBS = '';
|
||||
for ($word_offset = 0; $word_offset <= strlen($DTSheader); $word_offset += 2) {
|
||||
switch ($encoding) {
|
||||
case 0: // raw big-endian
|
||||
$fhBS .= getid3_lib::BigEndian2Bin( substr($DTSheader, $word_offset, 2) );
|
||||
break;
|
||||
case 1: // raw little-endian
|
||||
$fhBS .= getid3_lib::BigEndian2Bin(strrev(substr($DTSheader, $word_offset, 2)));
|
||||
break;
|
||||
case 2: // 14-bit big-endian
|
||||
$fhBS .= substr(getid3_lib::BigEndian2Bin( substr($DTSheader, $word_offset, 2) ), 2, 14);
|
||||
break;
|
||||
case 3: // 14-bit little-endian
|
||||
$fhBS .= substr(getid3_lib::BigEndian2Bin(strrev(substr($DTSheader, $word_offset, 2))), 2, 14);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$info['dts']['raw']['frame_type'] = $this->readBinData($fhBS, 1);
|
||||
$info['dts']['raw']['deficit_samples'] = $this->readBinData($fhBS, 5);
|
||||
$info['dts']['flags']['crc_present'] = (bool) $this->readBinData($fhBS, 1);
|
||||
$info['dts']['raw']['pcm_sample_blocks'] = $this->readBinData($fhBS, 7);
|
||||
$info['dts']['raw']['frame_byte_size'] = $this->readBinData($fhBS, 14);
|
||||
$info['dts']['raw']['channel_arrangement'] = $this->readBinData($fhBS, 6);
|
||||
$info['dts']['raw']['sample_frequency'] = $this->readBinData($fhBS, 4);
|
||||
$info['dts']['raw']['bitrate'] = $this->readBinData($fhBS, 5);
|
||||
$info['dts']['flags']['embedded_downmix'] = (bool) $this->readBinData($fhBS, 1);
|
||||
$info['dts']['flags']['dynamicrange'] = (bool) $this->readBinData($fhBS, 1);
|
||||
$info['dts']['flags']['timestamp'] = (bool) $this->readBinData($fhBS, 1);
|
||||
$info['dts']['flags']['auxdata'] = (bool) $this->readBinData($fhBS, 1);
|
||||
$info['dts']['flags']['hdcd'] = (bool) $this->readBinData($fhBS, 1);
|
||||
$info['dts']['raw']['extension_audio'] = $this->readBinData($fhBS, 3);
|
||||
$info['dts']['flags']['extended_coding'] = (bool) $this->readBinData($fhBS, 1);
|
||||
$info['dts']['flags']['audio_sync_insertion'] = (bool) $this->readBinData($fhBS, 1);
|
||||
$info['dts']['raw']['lfe_effects'] = $this->readBinData($fhBS, 2);
|
||||
$info['dts']['flags']['predictor_history'] = (bool) $this->readBinData($fhBS, 1);
|
||||
if ($info['dts']['flags']['crc_present']) {
|
||||
$info['dts']['raw']['crc16'] = $this->readBinData($fhBS, 16);
|
||||
}
|
||||
$info['dts']['flags']['mri_perfect_reconst'] = (bool) $this->readBinData($fhBS, 1);
|
||||
$info['dts']['raw']['encoder_soft_version'] = $this->readBinData($fhBS, 4);
|
||||
$info['dts']['raw']['copy_history'] = $this->readBinData($fhBS, 2);
|
||||
$info['dts']['raw']['bits_per_sample'] = $this->readBinData($fhBS, 2);
|
||||
$info['dts']['flags']['surround_es'] = (bool) $this->readBinData($fhBS, 1);
|
||||
$info['dts']['flags']['front_sum_diff'] = (bool) $this->readBinData($fhBS, 1);
|
||||
$info['dts']['flags']['surround_sum_diff'] = (bool) $this->readBinData($fhBS, 1);
|
||||
$info['dts']['raw']['dialog_normalization'] = $this->readBinData($fhBS, 4);
|
||||
|
||||
|
||||
$info['dts']['bitrate'] = self::bitrateLookup($info['dts']['raw']['bitrate']);
|
||||
$info['dts']['bits_per_sample'] = self::bitPerSampleLookup($info['dts']['raw']['bits_per_sample']);
|
||||
$info['dts']['sample_rate'] = self::sampleRateLookup($info['dts']['raw']['sample_frequency']);
|
||||
$info['dts']['dialog_normalization'] = self::dialogNormalization($info['dts']['raw']['dialog_normalization'], $info['dts']['raw']['encoder_soft_version']);
|
||||
$info['dts']['flags']['lossless'] = (($info['dts']['raw']['bitrate'] == 31) ? true : false);
|
||||
$info['dts']['bitrate_mode'] = (($info['dts']['raw']['bitrate'] == 30) ? 'vbr' : 'cbr');
|
||||
$info['dts']['channels'] = self::numChannelsLookup($info['dts']['raw']['channel_arrangement']);
|
||||
$info['dts']['channel_arrangement'] = self::channelArrangementLookup($info['dts']['raw']['channel_arrangement']);
|
||||
|
||||
$info['audio']['dataformat'] = 'dts';
|
||||
$info['audio']['lossless'] = $info['dts']['flags']['lossless'];
|
||||
$info['audio']['bitrate_mode'] = $info['dts']['bitrate_mode'];
|
||||
$info['audio']['bits_per_sample'] = $info['dts']['bits_per_sample'];
|
||||
$info['audio']['sample_rate'] = $info['dts']['sample_rate'];
|
||||
$info['audio']['channels'] = $info['dts']['channels'];
|
||||
$info['audio']['bitrate'] = $info['dts']['bitrate'];
|
||||
if (isset($info['avdataend']) && !empty($info['dts']['bitrate']) && is_numeric($info['dts']['bitrate'])) {
|
||||
$info['playtime_seconds'] = ($info['avdataend'] - $info['avdataoffset']) / ($info['dts']['bitrate'] / 8);
|
||||
if (($encoding == 2) || ($encoding == 3)) {
|
||||
// 14-bit data packed into 16-bit words, so the playtime is wrong because only (14/16) of the bytes in the data portion of the file are used at the specified bitrate
|
||||
$info['playtime_seconds'] *= (14 / 16);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $bin
|
||||
* @param int $length
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
private function readBinData($bin, $length) {
|
||||
$data = substr($bin, $this->readBinDataOffset, $length);
|
||||
$this->readBinDataOffset += $length;
|
||||
|
||||
return bindec($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $index
|
||||
*
|
||||
* @return int|string|false
|
||||
*/
|
||||
public static function bitrateLookup($index) {
|
||||
static $lookup = array(
|
||||
0 => 32000,
|
||||
1 => 56000,
|
||||
2 => 64000,
|
||||
3 => 96000,
|
||||
4 => 112000,
|
||||
5 => 128000,
|
||||
6 => 192000,
|
||||
7 => 224000,
|
||||
8 => 256000,
|
||||
9 => 320000,
|
||||
10 => 384000,
|
||||
11 => 448000,
|
||||
12 => 512000,
|
||||
13 => 576000,
|
||||
14 => 640000,
|
||||
15 => 768000,
|
||||
16 => 960000,
|
||||
17 => 1024000,
|
||||
18 => 1152000,
|
||||
19 => 1280000,
|
||||
20 => 1344000,
|
||||
21 => 1408000,
|
||||
22 => 1411200,
|
||||
23 => 1472000,
|
||||
24 => 1536000,
|
||||
25 => 1920000,
|
||||
26 => 2048000,
|
||||
27 => 3072000,
|
||||
28 => 3840000,
|
||||
29 => 'open',
|
||||
30 => 'variable',
|
||||
31 => 'lossless',
|
||||
);
|
||||
return (isset($lookup[$index]) ? $lookup[$index] : false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $index
|
||||
*
|
||||
* @return int|string|false
|
||||
*/
|
||||
public static function sampleRateLookup($index) {
|
||||
static $lookup = array(
|
||||
0 => 'invalid',
|
||||
1 => 8000,
|
||||
2 => 16000,
|
||||
3 => 32000,
|
||||
4 => 'invalid',
|
||||
5 => 'invalid',
|
||||
6 => 11025,
|
||||
7 => 22050,
|
||||
8 => 44100,
|
||||
9 => 'invalid',
|
||||
10 => 'invalid',
|
||||
11 => 12000,
|
||||
12 => 24000,
|
||||
13 => 48000,
|
||||
14 => 'invalid',
|
||||
15 => 'invalid',
|
||||
);
|
||||
return (isset($lookup[$index]) ? $lookup[$index] : false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $index
|
||||
*
|
||||
* @return int|false
|
||||
*/
|
||||
public static function bitPerSampleLookup($index) {
|
||||
static $lookup = array(
|
||||
0 => 16,
|
||||
1 => 20,
|
||||
2 => 24,
|
||||
3 => 24,
|
||||
);
|
||||
return (isset($lookup[$index]) ? $lookup[$index] : false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $index
|
||||
*
|
||||
* @return int|false
|
||||
*/
|
||||
public static function numChannelsLookup($index) {
|
||||
switch ($index) {
|
||||
case 0:
|
||||
return 1;
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
return 2;
|
||||
case 5:
|
||||
case 6:
|
||||
return 3;
|
||||
case 7:
|
||||
case 8:
|
||||
return 4;
|
||||
case 9:
|
||||
return 5;
|
||||
case 10:
|
||||
case 11:
|
||||
case 12:
|
||||
return 6;
|
||||
case 13:
|
||||
return 7;
|
||||
case 14:
|
||||
case 15:
|
||||
return 8;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $index
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function channelArrangementLookup($index) {
|
||||
static $lookup = array(
|
||||
0 => 'A',
|
||||
1 => 'A + B (dual mono)',
|
||||
2 => 'L + R (stereo)',
|
||||
3 => '(L+R) + (L-R) (sum-difference)',
|
||||
4 => 'LT + RT (left and right total)',
|
||||
5 => 'C + L + R',
|
||||
6 => 'L + R + S',
|
||||
7 => 'C + L + R + S',
|
||||
8 => 'L + R + SL + SR',
|
||||
9 => 'C + L + R + SL + SR',
|
||||
10 => 'CL + CR + L + R + SL + SR',
|
||||
11 => 'C + L + R+ LR + RR + OV',
|
||||
12 => 'CF + CR + LF + RF + LR + RR',
|
||||
13 => 'CL + C + CR + L + R + SL + SR',
|
||||
14 => 'CL + CR + L + R + SL1 + SL2 + SR1 + SR2',
|
||||
15 => 'CL + C+ CR + L + R + SL + S + SR',
|
||||
);
|
||||
return (isset($lookup[$index]) ? $lookup[$index] : 'user-defined');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $index
|
||||
* @param int $version
|
||||
*
|
||||
* @return int|false
|
||||
*/
|
||||
public static function dialogNormalization($index, $version) {
|
||||
switch ($version) {
|
||||
case 7:
|
||||
return 0 - $index;
|
||||
case 6:
|
||||
return 0 - 16 - $index;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
<?php
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
/// getID3() by James Heinrich <info@getid3.org> //
|
||||
// available at https://github.com/JamesHeinrich/getID3 //
|
||||
// or https://www.getid3.org //
|
||||
// or http://getid3.sourceforge.net //
|
||||
// see readme.txt for more details //
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// module.audio.dts.php //
|
||||
// module for analyzing DTS Audio files //
|
||||
// dependencies: NONE //
|
||||
// //
|
||||
/////////////////////////////////////////////////////////////////
|
||||
|
||||
if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tutorial http://wiki.multimedia.cx/index.php?title=DTS
|
||||
*/
|
||||
class getid3_dts extends getid3_handler
|
||||
{
|
||||
/**
|
||||
* Default DTS syncword used in native .cpt or .dts formats.
|
||||
*/
|
||||
const syncword = "\x7F\xFE\x80\x01";
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $readBinDataOffset = 0;
|
||||
|
||||
/**
|
||||
* Possible syncwords indicating bitstream encoding.
|
||||
*/
|
||||
public static $syncwords = array(
|
||||
0 => "\x7F\xFE\x80\x01", // raw big-endian
|
||||
1 => "\xFE\x7F\x01\x80", // raw little-endian
|
||||
2 => "\x1F\xFF\xE8\x00", // 14-bit big-endian
|
||||
3 => "\xFF\x1F\x00\xE8"); // 14-bit little-endian
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function Analyze() {
|
||||
$info = &$this->getid3->info;
|
||||
$info['fileformat'] = 'dts';
|
||||
|
||||
$this->fseek($info['avdataoffset']);
|
||||
$DTSheader = $this->fread(20); // we only need 2 words magic + 6 words frame header, but these words may be normal 16-bit words OR 14-bit words with 2 highest bits set to zero, so 8 words can be either 8*16/8 = 16 bytes OR 8*16*(16/14)/8 = 18.3 bytes
|
||||
|
||||
// check syncword
|
||||
$sync = substr($DTSheader, 0, 4);
|
||||
if (($encoding = array_search($sync, self::$syncwords)) !== false) {
|
||||
|
||||
$info['dts']['raw']['magic'] = $sync;
|
||||
$this->readBinDataOffset = 32;
|
||||
|
||||
} elseif ($this->isDependencyFor('matroska')) {
|
||||
|
||||
// Matroska contains DTS without syncword encoded as raw big-endian format
|
||||
$encoding = 0;
|
||||
$this->readBinDataOffset = 0;
|
||||
|
||||
} else {
|
||||
|
||||
unset($info['fileformat']);
|
||||
return $this->error('Expecting "'.implode('| ', array_map('getid3_lib::PrintHexBytes', self::$syncwords)).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($sync).'"');
|
||||
|
||||
}
|
||||
|
||||
// decode header
|
||||
$fhBS = '';
|
||||
for ($word_offset = 0; $word_offset <= strlen($DTSheader); $word_offset += 2) {
|
||||
switch ($encoding) {
|
||||
case 0: // raw big-endian
|
||||
$fhBS .= getid3_lib::BigEndian2Bin( substr($DTSheader, $word_offset, 2) );
|
||||
break;
|
||||
case 1: // raw little-endian
|
||||
$fhBS .= getid3_lib::BigEndian2Bin(strrev(substr($DTSheader, $word_offset, 2)));
|
||||
break;
|
||||
case 2: // 14-bit big-endian
|
||||
$fhBS .= substr(getid3_lib::BigEndian2Bin( substr($DTSheader, $word_offset, 2) ), 2, 14);
|
||||
break;
|
||||
case 3: // 14-bit little-endian
|
||||
$fhBS .= substr(getid3_lib::BigEndian2Bin(strrev(substr($DTSheader, $word_offset, 2))), 2, 14);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$info['dts']['raw']['frame_type'] = $this->readBinData($fhBS, 1);
|
||||
$info['dts']['raw']['deficit_samples'] = $this->readBinData($fhBS, 5);
|
||||
$info['dts']['flags']['crc_present'] = (bool) $this->readBinData($fhBS, 1);
|
||||
$info['dts']['raw']['pcm_sample_blocks'] = $this->readBinData($fhBS, 7);
|
||||
$info['dts']['raw']['frame_byte_size'] = $this->readBinData($fhBS, 14);
|
||||
$info['dts']['raw']['channel_arrangement'] = $this->readBinData($fhBS, 6);
|
||||
$info['dts']['raw']['sample_frequency'] = $this->readBinData($fhBS, 4);
|
||||
$info['dts']['raw']['bitrate'] = $this->readBinData($fhBS, 5);
|
||||
$info['dts']['flags']['embedded_downmix'] = (bool) $this->readBinData($fhBS, 1);
|
||||
$info['dts']['flags']['dynamicrange'] = (bool) $this->readBinData($fhBS, 1);
|
||||
$info['dts']['flags']['timestamp'] = (bool) $this->readBinData($fhBS, 1);
|
||||
$info['dts']['flags']['auxdata'] = (bool) $this->readBinData($fhBS, 1);
|
||||
$info['dts']['flags']['hdcd'] = (bool) $this->readBinData($fhBS, 1);
|
||||
$info['dts']['raw']['extension_audio'] = $this->readBinData($fhBS, 3);
|
||||
$info['dts']['flags']['extended_coding'] = (bool) $this->readBinData($fhBS, 1);
|
||||
$info['dts']['flags']['audio_sync_insertion'] = (bool) $this->readBinData($fhBS, 1);
|
||||
$info['dts']['raw']['lfe_effects'] = $this->readBinData($fhBS, 2);
|
||||
$info['dts']['flags']['predictor_history'] = (bool) $this->readBinData($fhBS, 1);
|
||||
if ($info['dts']['flags']['crc_present']) {
|
||||
$info['dts']['raw']['crc16'] = $this->readBinData($fhBS, 16);
|
||||
}
|
||||
$info['dts']['flags']['mri_perfect_reconst'] = (bool) $this->readBinData($fhBS, 1);
|
||||
$info['dts']['raw']['encoder_soft_version'] = $this->readBinData($fhBS, 4);
|
||||
$info['dts']['raw']['copy_history'] = $this->readBinData($fhBS, 2);
|
||||
$info['dts']['raw']['bits_per_sample'] = $this->readBinData($fhBS, 2);
|
||||
$info['dts']['flags']['surround_es'] = (bool) $this->readBinData($fhBS, 1);
|
||||
$info['dts']['flags']['front_sum_diff'] = (bool) $this->readBinData($fhBS, 1);
|
||||
$info['dts']['flags']['surround_sum_diff'] = (bool) $this->readBinData($fhBS, 1);
|
||||
$info['dts']['raw']['dialog_normalization'] = $this->readBinData($fhBS, 4);
|
||||
|
||||
|
||||
$info['dts']['bitrate'] = self::bitrateLookup($info['dts']['raw']['bitrate']);
|
||||
$info['dts']['bits_per_sample'] = self::bitPerSampleLookup($info['dts']['raw']['bits_per_sample']);
|
||||
$info['dts']['sample_rate'] = self::sampleRateLookup($info['dts']['raw']['sample_frequency']);
|
||||
$info['dts']['dialog_normalization'] = self::dialogNormalization($info['dts']['raw']['dialog_normalization'], $info['dts']['raw']['encoder_soft_version']);
|
||||
$info['dts']['flags']['lossless'] = (($info['dts']['raw']['bitrate'] == 31) ? true : false);
|
||||
$info['dts']['bitrate_mode'] = (($info['dts']['raw']['bitrate'] == 30) ? 'vbr' : 'cbr');
|
||||
$info['dts']['channels'] = self::numChannelsLookup($info['dts']['raw']['channel_arrangement']);
|
||||
$info['dts']['channel_arrangement'] = self::channelArrangementLookup($info['dts']['raw']['channel_arrangement']);
|
||||
|
||||
$info['audio']['dataformat'] = 'dts';
|
||||
$info['audio']['lossless'] = $info['dts']['flags']['lossless'];
|
||||
$info['audio']['bitrate_mode'] = $info['dts']['bitrate_mode'];
|
||||
$info['audio']['bits_per_sample'] = $info['dts']['bits_per_sample'];
|
||||
$info['audio']['sample_rate'] = $info['dts']['sample_rate'];
|
||||
$info['audio']['channels'] = $info['dts']['channels'];
|
||||
$info['audio']['bitrate'] = $info['dts']['bitrate'];
|
||||
if (isset($info['avdataend']) && !empty($info['dts']['bitrate']) && is_numeric($info['dts']['bitrate'])) {
|
||||
$info['playtime_seconds'] = ($info['avdataend'] - $info['avdataoffset']) / ($info['dts']['bitrate'] / 8);
|
||||
if (($encoding == 2) || ($encoding == 3)) {
|
||||
// 14-bit data packed into 16-bit words, so the playtime is wrong because only (14/16) of the bytes in the data portion of the file are used at the specified bitrate
|
||||
$info['playtime_seconds'] *= (14 / 16);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $bin
|
||||
* @param int $length
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
private function readBinData($bin, $length) {
|
||||
$data = substr($bin, $this->readBinDataOffset, $length);
|
||||
$this->readBinDataOffset += $length;
|
||||
|
||||
return bindec($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $index
|
||||
*
|
||||
* @return int|string|false
|
||||
*/
|
||||
public static function bitrateLookup($index) {
|
||||
static $lookup = array(
|
||||
0 => 32000,
|
||||
1 => 56000,
|
||||
2 => 64000,
|
||||
3 => 96000,
|
||||
4 => 112000,
|
||||
5 => 128000,
|
||||
6 => 192000,
|
||||
7 => 224000,
|
||||
8 => 256000,
|
||||
9 => 320000,
|
||||
10 => 384000,
|
||||
11 => 448000,
|
||||
12 => 512000,
|
||||
13 => 576000,
|
||||
14 => 640000,
|
||||
15 => 768000,
|
||||
16 => 960000,
|
||||
17 => 1024000,
|
||||
18 => 1152000,
|
||||
19 => 1280000,
|
||||
20 => 1344000,
|
||||
21 => 1408000,
|
||||
22 => 1411200,
|
||||
23 => 1472000,
|
||||
24 => 1536000,
|
||||
25 => 1920000,
|
||||
26 => 2048000,
|
||||
27 => 3072000,
|
||||
28 => 3840000,
|
||||
29 => 'open',
|
||||
30 => 'variable',
|
||||
31 => 'lossless',
|
||||
);
|
||||
return (isset($lookup[$index]) ? $lookup[$index] : false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $index
|
||||
*
|
||||
* @return int|string|false
|
||||
*/
|
||||
public static function sampleRateLookup($index) {
|
||||
static $lookup = array(
|
||||
0 => 'invalid',
|
||||
1 => 8000,
|
||||
2 => 16000,
|
||||
3 => 32000,
|
||||
4 => 'invalid',
|
||||
5 => 'invalid',
|
||||
6 => 11025,
|
||||
7 => 22050,
|
||||
8 => 44100,
|
||||
9 => 'invalid',
|
||||
10 => 'invalid',
|
||||
11 => 12000,
|
||||
12 => 24000,
|
||||
13 => 48000,
|
||||
14 => 'invalid',
|
||||
15 => 'invalid',
|
||||
);
|
||||
return (isset($lookup[$index]) ? $lookup[$index] : false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $index
|
||||
*
|
||||
* @return int|false
|
||||
*/
|
||||
public static function bitPerSampleLookup($index) {
|
||||
static $lookup = array(
|
||||
0 => 16,
|
||||
1 => 20,
|
||||
2 => 24,
|
||||
3 => 24,
|
||||
);
|
||||
return (isset($lookup[$index]) ? $lookup[$index] : false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $index
|
||||
*
|
||||
* @return int|false
|
||||
*/
|
||||
public static function numChannelsLookup($index) {
|
||||
switch ($index) {
|
||||
case 0:
|
||||
return 1;
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
return 2;
|
||||
case 5:
|
||||
case 6:
|
||||
return 3;
|
||||
case 7:
|
||||
case 8:
|
||||
return 4;
|
||||
case 9:
|
||||
return 5;
|
||||
case 10:
|
||||
case 11:
|
||||
case 12:
|
||||
return 6;
|
||||
case 13:
|
||||
return 7;
|
||||
case 14:
|
||||
case 15:
|
||||
return 8;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $index
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function channelArrangementLookup($index) {
|
||||
static $lookup = array(
|
||||
0 => 'A',
|
||||
1 => 'A + B (dual mono)',
|
||||
2 => 'L + R (stereo)',
|
||||
3 => '(L+R) + (L-R) (sum-difference)',
|
||||
4 => 'LT + RT (left and right total)',
|
||||
5 => 'C + L + R',
|
||||
6 => 'L + R + S',
|
||||
7 => 'C + L + R + S',
|
||||
8 => 'L + R + SL + SR',
|
||||
9 => 'C + L + R + SL + SR',
|
||||
10 => 'CL + CR + L + R + SL + SR',
|
||||
11 => 'C + L + R+ LR + RR + OV',
|
||||
12 => 'CF + CR + LF + RF + LR + RR',
|
||||
13 => 'CL + C + CR + L + R + SL + SR',
|
||||
14 => 'CL + CR + L + R + SL1 + SL2 + SR1 + SR2',
|
||||
15 => 'CL + C+ CR + L + R + SL + S + SR',
|
||||
);
|
||||
return (isset($lookup[$index]) ? $lookup[$index] : 'user-defined');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $index
|
||||
* @param int $version
|
||||
*
|
||||
* @return int|false
|
||||
*/
|
||||
public static function dialogNormalization($index, $version) {
|
||||
switch ($version) {
|
||||
case 7:
|
||||
return 0 - $index;
|
||||
case 6:
|
||||
return 0 - 16 - $index;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,454 +1,454 @@
|
||||
<?php
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
/// getID3() by James Heinrich <info@getid3.org> //
|
||||
// available at https://github.com/JamesHeinrich/getID3 //
|
||||
// or https://www.getid3.org //
|
||||
// or http://getid3.sourceforge.net //
|
||||
// see readme.txt for more details //
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// module.tag.apetag.php //
|
||||
// module for analyzing APE tags //
|
||||
// dependencies: NONE //
|
||||
// ///
|
||||
/////////////////////////////////////////////////////////////////
|
||||
|
||||
if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers
|
||||
exit;
|
||||
}
|
||||
|
||||
class getid3_apetag extends getid3_handler
|
||||
{
|
||||
/**
|
||||
* true: return full data for all attachments;
|
||||
* false: return no data for all attachments;
|
||||
* integer: return data for attachments <= than this;
|
||||
* string: save as file to this directory.
|
||||
*
|
||||
* @var int|bool|string
|
||||
*/
|
||||
public $inline_attachments = true;
|
||||
|
||||
public $overrideendoffset = 0;
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function Analyze() {
|
||||
$info = &$this->getid3->info;
|
||||
|
||||
if (!getid3_lib::intValueSupported($info['filesize'])) {
|
||||
$this->warning('Unable to check for APEtags because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB');
|
||||
return false;
|
||||
}
|
||||
|
||||
$id3v1tagsize = 128;
|
||||
$apetagheadersize = 32;
|
||||
$lyrics3tagsize = 10;
|
||||
|
||||
if ($this->overrideendoffset == 0) {
|
||||
|
||||
$this->fseek(0 - $id3v1tagsize - $apetagheadersize - $lyrics3tagsize, SEEK_END);
|
||||
$APEfooterID3v1 = $this->fread($id3v1tagsize + $apetagheadersize + $lyrics3tagsize);
|
||||
|
||||
//if (preg_match('/APETAGEX.{24}TAG.{125}$/i', $APEfooterID3v1)) {
|
||||
if (substr($APEfooterID3v1, strlen($APEfooterID3v1) - $id3v1tagsize - $apetagheadersize, 8) == 'APETAGEX') {
|
||||
|
||||
// APE tag found before ID3v1
|
||||
$info['ape']['tag_offset_end'] = $info['filesize'] - $id3v1tagsize;
|
||||
|
||||
//} elseif (preg_match('/APETAGEX.{24}$/i', $APEfooterID3v1)) {
|
||||
} elseif (substr($APEfooterID3v1, strlen($APEfooterID3v1) - $apetagheadersize, 8) == 'APETAGEX') {
|
||||
|
||||
// APE tag found, no ID3v1
|
||||
$info['ape']['tag_offset_end'] = $info['filesize'];
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
$this->fseek($this->overrideendoffset - $apetagheadersize);
|
||||
if ($this->fread(8) == 'APETAGEX') {
|
||||
$info['ape']['tag_offset_end'] = $this->overrideendoffset;
|
||||
}
|
||||
|
||||
}
|
||||
if (!isset($info['ape']['tag_offset_end'])) {
|
||||
|
||||
// APE tag not found
|
||||
unset($info['ape']);
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
// shortcut
|
||||
$thisfile_ape = &$info['ape'];
|
||||
|
||||
$this->fseek($thisfile_ape['tag_offset_end'] - $apetagheadersize);
|
||||
$APEfooterData = $this->fread(32);
|
||||
if (!($thisfile_ape['footer'] = $this->parseAPEheaderFooter($APEfooterData))) {
|
||||
$this->error('Error parsing APE footer at offset '.$thisfile_ape['tag_offset_end']);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isset($thisfile_ape['footer']['flags']['header']) && $thisfile_ape['footer']['flags']['header']) {
|
||||
$this->fseek($thisfile_ape['tag_offset_end'] - $thisfile_ape['footer']['raw']['tagsize'] - $apetagheadersize);
|
||||
$thisfile_ape['tag_offset_start'] = $this->ftell();
|
||||
$APEtagData = $this->fread($thisfile_ape['footer']['raw']['tagsize'] + $apetagheadersize);
|
||||
} else {
|
||||
$thisfile_ape['tag_offset_start'] = $thisfile_ape['tag_offset_end'] - $thisfile_ape['footer']['raw']['tagsize'];
|
||||
$this->fseek($thisfile_ape['tag_offset_start']);
|
||||
$APEtagData = $this->fread($thisfile_ape['footer']['raw']['tagsize']);
|
||||
}
|
||||
$info['avdataend'] = $thisfile_ape['tag_offset_start'];
|
||||
|
||||
if (isset($info['id3v1']['tag_offset_start']) && ($info['id3v1']['tag_offset_start'] < $thisfile_ape['tag_offset_end'])) {
|
||||
$this->warning('ID3v1 tag information ignored since it appears to be a false synch in APEtag data');
|
||||
unset($info['id3v1']);
|
||||
foreach ($info['warning'] as $key => $value) {
|
||||
if ($value == 'Some ID3v1 fields do not use NULL characters for padding') {
|
||||
unset($info['warning'][$key]);
|
||||
sort($info['warning']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$offset = 0;
|
||||
if (isset($thisfile_ape['footer']['flags']['header']) && $thisfile_ape['footer']['flags']['header']) {
|
||||
if ($thisfile_ape['header'] = $this->parseAPEheaderFooter(substr($APEtagData, 0, $apetagheadersize))) {
|
||||
$offset += $apetagheadersize;
|
||||
} else {
|
||||
$this->error('Error parsing APE header at offset '.$thisfile_ape['tag_offset_start']);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// shortcut
|
||||
$info['replay_gain'] = array();
|
||||
$thisfile_replaygain = &$info['replay_gain'];
|
||||
|
||||
for ($i = 0; $i < $thisfile_ape['footer']['raw']['tag_items']; $i++) {
|
||||
$value_size = getid3_lib::LittleEndian2Int(substr($APEtagData, $offset, 4));
|
||||
$offset += 4;
|
||||
$item_flags = getid3_lib::LittleEndian2Int(substr($APEtagData, $offset, 4));
|
||||
$offset += 4;
|
||||
if (strstr(substr($APEtagData, $offset), "\x00") === false) {
|
||||
$this->error('Cannot find null-byte (0x00) separator between ItemKey #'.$i.' and value. ItemKey starts '.$offset.' bytes into the APE tag, at file offset '.($thisfile_ape['tag_offset_start'] + $offset));
|
||||
return false;
|
||||
}
|
||||
$ItemKeyLength = strpos($APEtagData, "\x00", $offset) - $offset;
|
||||
$item_key = strtolower(substr($APEtagData, $offset, $ItemKeyLength));
|
||||
|
||||
// shortcut
|
||||
$thisfile_ape['items'][$item_key] = array();
|
||||
$thisfile_ape_items_current = &$thisfile_ape['items'][$item_key];
|
||||
|
||||
$thisfile_ape_items_current['offset'] = $thisfile_ape['tag_offset_start'] + $offset;
|
||||
|
||||
$offset += ($ItemKeyLength + 1); // skip 0x00 terminator
|
||||
$thisfile_ape_items_current['data'] = substr($APEtagData, $offset, $value_size);
|
||||
$offset += $value_size;
|
||||
|
||||
$thisfile_ape_items_current['flags'] = $this->parseAPEtagFlags($item_flags);
|
||||
switch ($thisfile_ape_items_current['flags']['item_contents_raw']) {
|
||||
case 0: // UTF-8
|
||||
case 2: // Locator (URL, filename, etc), UTF-8 encoded
|
||||
$thisfile_ape_items_current['data'] = explode("\x00", $thisfile_ape_items_current['data']);
|
||||
break;
|
||||
|
||||
case 1: // binary data
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (strtolower($item_key)) {
|
||||
// http://wiki.hydrogenaud.io/index.php?title=ReplayGain#MP3Gain
|
||||
case 'replaygain_track_gain':
|
||||
if (preg_match('#^([\\-\\+][0-9\\.,]{8})( dB)?$#', $thisfile_ape_items_current['data'][0], $matches)) {
|
||||
$thisfile_replaygain['track']['adjustment'] = (float) str_replace(',', '.', $matches[1]); // float casting will see "0,95" as zero!
|
||||
$thisfile_replaygain['track']['originator'] = 'unspecified';
|
||||
} else {
|
||||
$this->warning('MP3gainTrackGain value in APEtag appears invalid: "'.$thisfile_ape_items_current['data'][0].'"');
|
||||
}
|
||||
break;
|
||||
|
||||
case 'replaygain_track_peak':
|
||||
if (preg_match('#^([0-9\\.,]{8})$#', $thisfile_ape_items_current['data'][0], $matches)) {
|
||||
$thisfile_replaygain['track']['peak'] = (float) str_replace(',', '.', $matches[1]); // float casting will see "0,95" as zero!
|
||||
$thisfile_replaygain['track']['originator'] = 'unspecified';
|
||||
if ($thisfile_replaygain['track']['peak'] <= 0) {
|
||||
$this->warning('ReplayGain Track peak from APEtag appears invalid: '.$thisfile_replaygain['track']['peak'].' (original value = "'.$thisfile_ape_items_current['data'][0].'")');
|
||||
}
|
||||
} else {
|
||||
$this->warning('MP3gainTrackPeak value in APEtag appears invalid: "'.$thisfile_ape_items_current['data'][0].'"');
|
||||
}
|
||||
break;
|
||||
|
||||
case 'replaygain_album_gain':
|
||||
if (preg_match('#^([\\-\\+][0-9\\.,]{8})( dB)?$#', $thisfile_ape_items_current['data'][0], $matches)) {
|
||||
$thisfile_replaygain['album']['adjustment'] = (float) str_replace(',', '.', $matches[1]); // float casting will see "0,95" as zero!
|
||||
$thisfile_replaygain['album']['originator'] = 'unspecified';
|
||||
} else {
|
||||
$this->warning('MP3gainAlbumGain value in APEtag appears invalid: "'.$thisfile_ape_items_current['data'][0].'"');
|
||||
}
|
||||
break;
|
||||
|
||||
case 'replaygain_album_peak':
|
||||
if (preg_match('#^([0-9\\.,]{8})$#', $thisfile_ape_items_current['data'][0], $matches)) {
|
||||
$thisfile_replaygain['album']['peak'] = (float) str_replace(',', '.', $matches[1]); // float casting will see "0,95" as zero!
|
||||
$thisfile_replaygain['album']['originator'] = 'unspecified';
|
||||
if ($thisfile_replaygain['album']['peak'] <= 0) {
|
||||
$this->warning('ReplayGain Album peak from APEtag appears invalid: '.$thisfile_replaygain['album']['peak'].' (original value = "'.$thisfile_ape_items_current['data'][0].'")');
|
||||
}
|
||||
} else {
|
||||
$this->warning('MP3gainAlbumPeak value in APEtag appears invalid: "'.$thisfile_ape_items_current['data'][0].'"');
|
||||
}
|
||||
break;
|
||||
|
||||
case 'mp3gain_undo':
|
||||
if (preg_match('#^[\\-\\+][0-9]{3},[\\-\\+][0-9]{3},[NW]$#', $thisfile_ape_items_current['data'][0])) {
|
||||
list($mp3gain_undo_left, $mp3gain_undo_right, $mp3gain_undo_wrap) = explode(',', $thisfile_ape_items_current['data'][0]);
|
||||
$thisfile_replaygain['mp3gain']['undo_left'] = intval($mp3gain_undo_left);
|
||||
$thisfile_replaygain['mp3gain']['undo_right'] = intval($mp3gain_undo_right);
|
||||
$thisfile_replaygain['mp3gain']['undo_wrap'] = (($mp3gain_undo_wrap == 'Y') ? true : false);
|
||||
} else {
|
||||
$this->warning('MP3gainUndo value in APEtag appears invalid: "'.$thisfile_ape_items_current['data'][0].'"');
|
||||
}
|
||||
break;
|
||||
|
||||
case 'mp3gain_minmax':
|
||||
if (preg_match('#^[0-9]{3},[0-9]{3}$#', $thisfile_ape_items_current['data'][0])) {
|
||||
list($mp3gain_globalgain_min, $mp3gain_globalgain_max) = explode(',', $thisfile_ape_items_current['data'][0]);
|
||||
$thisfile_replaygain['mp3gain']['globalgain_track_min'] = intval($mp3gain_globalgain_min);
|
||||
$thisfile_replaygain['mp3gain']['globalgain_track_max'] = intval($mp3gain_globalgain_max);
|
||||
} else {
|
||||
$this->warning('MP3gainMinMax value in APEtag appears invalid: "'.$thisfile_ape_items_current['data'][0].'"');
|
||||
}
|
||||
break;
|
||||
|
||||
case 'mp3gain_album_minmax':
|
||||
if (preg_match('#^[0-9]{3},[0-9]{3}$#', $thisfile_ape_items_current['data'][0])) {
|
||||
list($mp3gain_globalgain_album_min, $mp3gain_globalgain_album_max) = explode(',', $thisfile_ape_items_current['data'][0]);
|
||||
$thisfile_replaygain['mp3gain']['globalgain_album_min'] = intval($mp3gain_globalgain_album_min);
|
||||
$thisfile_replaygain['mp3gain']['globalgain_album_max'] = intval($mp3gain_globalgain_album_max);
|
||||
} else {
|
||||
$this->warning('MP3gainAlbumMinMax value in APEtag appears invalid: "'.$thisfile_ape_items_current['data'][0].'"');
|
||||
}
|
||||
break;
|
||||
|
||||
case 'tracknumber':
|
||||
if (is_array($thisfile_ape_items_current['data'])) {
|
||||
foreach ($thisfile_ape_items_current['data'] as $comment) {
|
||||
$thisfile_ape['comments']['track_number'][] = $comment;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'cover art (artist)':
|
||||
case 'cover art (back)':
|
||||
case 'cover art (band logo)':
|
||||
case 'cover art (band)':
|
||||
case 'cover art (colored fish)':
|
||||
case 'cover art (composer)':
|
||||
case 'cover art (conductor)':
|
||||
case 'cover art (front)':
|
||||
case 'cover art (icon)':
|
||||
case 'cover art (illustration)':
|
||||
case 'cover art (lead)':
|
||||
case 'cover art (leaflet)':
|
||||
case 'cover art (lyricist)':
|
||||
case 'cover art (media)':
|
||||
case 'cover art (movie scene)':
|
||||
case 'cover art (other icon)':
|
||||
case 'cover art (other)':
|
||||
case 'cover art (performance)':
|
||||
case 'cover art (publisher logo)':
|
||||
case 'cover art (recording)':
|
||||
case 'cover art (studio)':
|
||||
// list of possible cover arts from https://github.com/mono/taglib-sharp/blob/taglib-sharp-2.0.3.2/src/TagLib/Ape/Tag.cs
|
||||
if (is_array($thisfile_ape_items_current['data'])) {
|
||||
$this->warning('APEtag "'.$item_key.'" should be flagged as Binary data, but was incorrectly flagged as UTF-8');
|
||||
$thisfile_ape_items_current['data'] = implode("\x00", $thisfile_ape_items_current['data']);
|
||||
}
|
||||
list($thisfile_ape_items_current['filename'], $thisfile_ape_items_current['data']) = explode("\x00", $thisfile_ape_items_current['data'], 2);
|
||||
$thisfile_ape_items_current['data_offset'] = $thisfile_ape_items_current['offset'] + strlen($thisfile_ape_items_current['filename']."\x00");
|
||||
$thisfile_ape_items_current['data_length'] = strlen($thisfile_ape_items_current['data']);
|
||||
|
||||
do {
|
||||
$thisfile_ape_items_current['image_mime'] = '';
|
||||
$imageinfo = array();
|
||||
$imagechunkcheck = getid3_lib::GetDataImageSize($thisfile_ape_items_current['data'], $imageinfo);
|
||||
if (($imagechunkcheck === false) || !isset($imagechunkcheck[2])) {
|
||||
$this->warning('APEtag "'.$item_key.'" contains invalid image data');
|
||||
break;
|
||||
}
|
||||
$thisfile_ape_items_current['image_mime'] = image_type_to_mime_type($imagechunkcheck[2]);
|
||||
|
||||
if ($this->inline_attachments === false) {
|
||||
// skip entirely
|
||||
unset($thisfile_ape_items_current['data']);
|
||||
break;
|
||||
}
|
||||
if ($this->inline_attachments === true) {
|
||||
// great
|
||||
} elseif (is_int($this->inline_attachments)) {
|
||||
if ($this->inline_attachments < $thisfile_ape_items_current['data_length']) {
|
||||
// too big, skip
|
||||
$this->warning('attachment at '.$thisfile_ape_items_current['offset'].' is too large to process inline ('.number_format($thisfile_ape_items_current['data_length']).' bytes)');
|
||||
unset($thisfile_ape_items_current['data']);
|
||||
break;
|
||||
}
|
||||
} elseif (is_string($this->inline_attachments)) {
|
||||
$this->inline_attachments = rtrim(str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $this->inline_attachments), DIRECTORY_SEPARATOR);
|
||||
if (!is_dir($this->inline_attachments) || !getID3::is_writable($this->inline_attachments)) {
|
||||
// cannot write, skip
|
||||
$this->warning('attachment at '.$thisfile_ape_items_current['offset'].' cannot be saved to "'.$this->inline_attachments.'" (not writable)');
|
||||
unset($thisfile_ape_items_current['data']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
// if we get this far, must be OK
|
||||
if (is_string($this->inline_attachments)) {
|
||||
$destination_filename = $this->inline_attachments.DIRECTORY_SEPARATOR.md5($info['filenamepath']).'_'.$thisfile_ape_items_current['data_offset'];
|
||||
if (!file_exists($destination_filename) || getID3::is_writable($destination_filename)) {
|
||||
file_put_contents($destination_filename, $thisfile_ape_items_current['data']);
|
||||
} else {
|
||||
$this->warning('attachment at '.$thisfile_ape_items_current['offset'].' cannot be saved to "'.$destination_filename.'" (not writable)');
|
||||
}
|
||||
$thisfile_ape_items_current['data_filename'] = $destination_filename;
|
||||
unset($thisfile_ape_items_current['data']);
|
||||
} else {
|
||||
if (!isset($info['ape']['comments']['picture'])) {
|
||||
$info['ape']['comments']['picture'] = array();
|
||||
}
|
||||
$comments_picture_data = array();
|
||||
foreach (array('data', 'image_mime', 'image_width', 'image_height', 'imagetype', 'picturetype', 'description', 'datalength') as $picture_key) {
|
||||
if (isset($thisfile_ape_items_current[$picture_key])) {
|
||||
$comments_picture_data[$picture_key] = $thisfile_ape_items_current[$picture_key];
|
||||
}
|
||||
}
|
||||
$info['ape']['comments']['picture'][] = $comments_picture_data;
|
||||
unset($comments_picture_data);
|
||||
}
|
||||
} while (false); // @phpstan-ignore-line
|
||||
break;
|
||||
|
||||
default:
|
||||
if (is_array($thisfile_ape_items_current['data'])) {
|
||||
foreach ($thisfile_ape_items_current['data'] as $comment) {
|
||||
$thisfile_ape['comments'][strtolower($item_key)][] = $comment;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
if (empty($thisfile_replaygain)) {
|
||||
unset($info['replay_gain']);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $APEheaderFooterData
|
||||
*
|
||||
* @return array|false
|
||||
*/
|
||||
public function parseAPEheaderFooter($APEheaderFooterData) {
|
||||
// http://www.uni-jena.de/~pfk/mpp/sv8/apeheader.html
|
||||
|
||||
// shortcut
|
||||
$headerfooterinfo = array();
|
||||
$headerfooterinfo['raw'] = array();
|
||||
$headerfooterinfo_raw = &$headerfooterinfo['raw'];
|
||||
|
||||
$headerfooterinfo_raw['footer_tag'] = substr($APEheaderFooterData, 0, 8);
|
||||
if ($headerfooterinfo_raw['footer_tag'] != 'APETAGEX') {
|
||||
return false;
|
||||
}
|
||||
$headerfooterinfo_raw['version'] = getid3_lib::LittleEndian2Int(substr($APEheaderFooterData, 8, 4));
|
||||
$headerfooterinfo_raw['tagsize'] = getid3_lib::LittleEndian2Int(substr($APEheaderFooterData, 12, 4));
|
||||
$headerfooterinfo_raw['tag_items'] = getid3_lib::LittleEndian2Int(substr($APEheaderFooterData, 16, 4));
|
||||
$headerfooterinfo_raw['global_flags'] = getid3_lib::LittleEndian2Int(substr($APEheaderFooterData, 20, 4));
|
||||
$headerfooterinfo_raw['reserved'] = substr($APEheaderFooterData, 24, 8);
|
||||
|
||||
$headerfooterinfo['tag_version'] = $headerfooterinfo_raw['version'] / 1000;
|
||||
if ($headerfooterinfo['tag_version'] >= 2) {
|
||||
$headerfooterinfo['flags'] = $this->parseAPEtagFlags($headerfooterinfo_raw['global_flags']);
|
||||
}
|
||||
return $headerfooterinfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $rawflagint
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function parseAPEtagFlags($rawflagint) {
|
||||
// "Note: APE Tags 1.0 do not use any of the APE Tag flags.
|
||||
// All are set to zero on creation and ignored on reading."
|
||||
// http://wiki.hydrogenaud.io/index.php?title=Ape_Tags_Flags
|
||||
$flags = array();
|
||||
$flags['header'] = (bool) ($rawflagint & 0x80000000);
|
||||
$flags['footer'] = (bool) ($rawflagint & 0x40000000);
|
||||
$flags['this_is_header'] = (bool) ($rawflagint & 0x20000000);
|
||||
$flags['item_contents_raw'] = ($rawflagint & 0x00000006) >> 1;
|
||||
$flags['read_only'] = (bool) ($rawflagint & 0x00000001);
|
||||
|
||||
$flags['item_contents'] = $this->APEcontentTypeFlagLookup($flags['item_contents_raw']);
|
||||
|
||||
return $flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $contenttypeid
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function APEcontentTypeFlagLookup($contenttypeid) {
|
||||
static $APEcontentTypeFlagLookup = array(
|
||||
0 => 'utf-8',
|
||||
1 => 'binary',
|
||||
2 => 'external',
|
||||
3 => 'reserved'
|
||||
);
|
||||
return (isset($APEcontentTypeFlagLookup[$contenttypeid]) ? $APEcontentTypeFlagLookup[$contenttypeid] : 'invalid');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $itemkey
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function APEtagItemIsUTF8Lookup($itemkey) {
|
||||
static $APEtagItemIsUTF8Lookup = array(
|
||||
'title',
|
||||
'subtitle',
|
||||
'artist',
|
||||
'album',
|
||||
'debut album',
|
||||
'publisher',
|
||||
'conductor',
|
||||
'track',
|
||||
'composer',
|
||||
'comment',
|
||||
'copyright',
|
||||
'publicationright',
|
||||
'file',
|
||||
'year',
|
||||
'record date',
|
||||
'record location',
|
||||
'genre',
|
||||
'media',
|
||||
'related',
|
||||
'isrc',
|
||||
'abstract',
|
||||
'language',
|
||||
'bibliography'
|
||||
);
|
||||
return in_array(strtolower($itemkey), $APEtagItemIsUTF8Lookup);
|
||||
}
|
||||
|
||||
}
|
||||
<?php
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
/// getID3() by James Heinrich <info@getid3.org> //
|
||||
// available at https://github.com/JamesHeinrich/getID3 //
|
||||
// or https://www.getid3.org //
|
||||
// or http://getid3.sourceforge.net //
|
||||
// see readme.txt for more details //
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// module.tag.apetag.php //
|
||||
// module for analyzing APE tags //
|
||||
// dependencies: NONE //
|
||||
// ///
|
||||
/////////////////////////////////////////////////////////////////
|
||||
|
||||
if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers
|
||||
exit;
|
||||
}
|
||||
|
||||
class getid3_apetag extends getid3_handler
|
||||
{
|
||||
/**
|
||||
* true: return full data for all attachments;
|
||||
* false: return no data for all attachments;
|
||||
* integer: return data for attachments <= than this;
|
||||
* string: save as file to this directory.
|
||||
*
|
||||
* @var int|bool|string
|
||||
*/
|
||||
public $inline_attachments = true;
|
||||
|
||||
public $overrideendoffset = 0;
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function Analyze() {
|
||||
$info = &$this->getid3->info;
|
||||
|
||||
if (!getid3_lib::intValueSupported($info['filesize'])) {
|
||||
$this->warning('Unable to check for APEtags because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB');
|
||||
return false;
|
||||
}
|
||||
|
||||
$id3v1tagsize = 128;
|
||||
$apetagheadersize = 32;
|
||||
$lyrics3tagsize = 10;
|
||||
|
||||
if ($this->overrideendoffset == 0) {
|
||||
|
||||
$this->fseek(0 - $id3v1tagsize - $apetagheadersize - $lyrics3tagsize, SEEK_END);
|
||||
$APEfooterID3v1 = $this->fread($id3v1tagsize + $apetagheadersize + $lyrics3tagsize);
|
||||
|
||||
//if (preg_match('/APETAGEX.{24}TAG.{125}$/i', $APEfooterID3v1)) {
|
||||
if (substr($APEfooterID3v1, strlen($APEfooterID3v1) - $id3v1tagsize - $apetagheadersize, 8) == 'APETAGEX') {
|
||||
|
||||
// APE tag found before ID3v1
|
||||
$info['ape']['tag_offset_end'] = $info['filesize'] - $id3v1tagsize;
|
||||
|
||||
//} elseif (preg_match('/APETAGEX.{24}$/i', $APEfooterID3v1)) {
|
||||
} elseif (substr($APEfooterID3v1, strlen($APEfooterID3v1) - $apetagheadersize, 8) == 'APETAGEX') {
|
||||
|
||||
// APE tag found, no ID3v1
|
||||
$info['ape']['tag_offset_end'] = $info['filesize'];
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
$this->fseek($this->overrideendoffset - $apetagheadersize);
|
||||
if ($this->fread(8) == 'APETAGEX') {
|
||||
$info['ape']['tag_offset_end'] = $this->overrideendoffset;
|
||||
}
|
||||
|
||||
}
|
||||
if (!isset($info['ape']['tag_offset_end'])) {
|
||||
|
||||
// APE tag not found
|
||||
unset($info['ape']);
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
// shortcut
|
||||
$thisfile_ape = &$info['ape'];
|
||||
|
||||
$this->fseek($thisfile_ape['tag_offset_end'] - $apetagheadersize);
|
||||
$APEfooterData = $this->fread(32);
|
||||
if (!($thisfile_ape['footer'] = $this->parseAPEheaderFooter($APEfooterData))) {
|
||||
$this->error('Error parsing APE footer at offset '.$thisfile_ape['tag_offset_end']);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isset($thisfile_ape['footer']['flags']['header']) && $thisfile_ape['footer']['flags']['header']) {
|
||||
$this->fseek($thisfile_ape['tag_offset_end'] - $thisfile_ape['footer']['raw']['tagsize'] - $apetagheadersize);
|
||||
$thisfile_ape['tag_offset_start'] = $this->ftell();
|
||||
$APEtagData = $this->fread($thisfile_ape['footer']['raw']['tagsize'] + $apetagheadersize);
|
||||
} else {
|
||||
$thisfile_ape['tag_offset_start'] = $thisfile_ape['tag_offset_end'] - $thisfile_ape['footer']['raw']['tagsize'];
|
||||
$this->fseek($thisfile_ape['tag_offset_start']);
|
||||
$APEtagData = $this->fread($thisfile_ape['footer']['raw']['tagsize']);
|
||||
}
|
||||
$info['avdataend'] = $thisfile_ape['tag_offset_start'];
|
||||
|
||||
if (isset($info['id3v1']['tag_offset_start']) && ($info['id3v1']['tag_offset_start'] < $thisfile_ape['tag_offset_end'])) {
|
||||
$this->warning('ID3v1 tag information ignored since it appears to be a false synch in APEtag data');
|
||||
unset($info['id3v1']);
|
||||
foreach ($info['warning'] as $key => $value) {
|
||||
if ($value == 'Some ID3v1 fields do not use NULL characters for padding') {
|
||||
unset($info['warning'][$key]);
|
||||
sort($info['warning']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$offset = 0;
|
||||
if (isset($thisfile_ape['footer']['flags']['header']) && $thisfile_ape['footer']['flags']['header']) {
|
||||
if ($thisfile_ape['header'] = $this->parseAPEheaderFooter(substr($APEtagData, 0, $apetagheadersize))) {
|
||||
$offset += $apetagheadersize;
|
||||
} else {
|
||||
$this->error('Error parsing APE header at offset '.$thisfile_ape['tag_offset_start']);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// shortcut
|
||||
$info['replay_gain'] = array();
|
||||
$thisfile_replaygain = &$info['replay_gain'];
|
||||
|
||||
for ($i = 0; $i < $thisfile_ape['footer']['raw']['tag_items']; $i++) {
|
||||
$value_size = getid3_lib::LittleEndian2Int(substr($APEtagData, $offset, 4));
|
||||
$offset += 4;
|
||||
$item_flags = getid3_lib::LittleEndian2Int(substr($APEtagData, $offset, 4));
|
||||
$offset += 4;
|
||||
if (strstr(substr($APEtagData, $offset), "\x00") === false) {
|
||||
$this->error('Cannot find null-byte (0x00) separator between ItemKey #'.$i.' and value. ItemKey starts '.$offset.' bytes into the APE tag, at file offset '.($thisfile_ape['tag_offset_start'] + $offset));
|
||||
return false;
|
||||
}
|
||||
$ItemKeyLength = strpos($APEtagData, "\x00", $offset) - $offset;
|
||||
$item_key = strtolower(substr($APEtagData, $offset, $ItemKeyLength));
|
||||
|
||||
// shortcut
|
||||
$thisfile_ape['items'][$item_key] = array();
|
||||
$thisfile_ape_items_current = &$thisfile_ape['items'][$item_key];
|
||||
|
||||
$thisfile_ape_items_current['offset'] = $thisfile_ape['tag_offset_start'] + $offset;
|
||||
|
||||
$offset += ($ItemKeyLength + 1); // skip 0x00 terminator
|
||||
$thisfile_ape_items_current['data'] = substr($APEtagData, $offset, $value_size);
|
||||
$offset += $value_size;
|
||||
|
||||
$thisfile_ape_items_current['flags'] = $this->parseAPEtagFlags($item_flags);
|
||||
switch ($thisfile_ape_items_current['flags']['item_contents_raw']) {
|
||||
case 0: // UTF-8
|
||||
case 2: // Locator (URL, filename, etc), UTF-8 encoded
|
||||
$thisfile_ape_items_current['data'] = explode("\x00", $thisfile_ape_items_current['data']);
|
||||
break;
|
||||
|
||||
case 1: // binary data
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (strtolower($item_key)) {
|
||||
// http://wiki.hydrogenaud.io/index.php?title=ReplayGain#MP3Gain
|
||||
case 'replaygain_track_gain':
|
||||
if (preg_match('#^([\\-\\+][0-9\\.,]{8})( dB)?$#', $thisfile_ape_items_current['data'][0], $matches)) {
|
||||
$thisfile_replaygain['track']['adjustment'] = (float) str_replace(',', '.', $matches[1]); // float casting will see "0,95" as zero!
|
||||
$thisfile_replaygain['track']['originator'] = 'unspecified';
|
||||
} else {
|
||||
$this->warning('MP3gainTrackGain value in APEtag appears invalid: "'.$thisfile_ape_items_current['data'][0].'"');
|
||||
}
|
||||
break;
|
||||
|
||||
case 'replaygain_track_peak':
|
||||
if (preg_match('#^([0-9\\.,]{8})$#', $thisfile_ape_items_current['data'][0], $matches)) {
|
||||
$thisfile_replaygain['track']['peak'] = (float) str_replace(',', '.', $matches[1]); // float casting will see "0,95" as zero!
|
||||
$thisfile_replaygain['track']['originator'] = 'unspecified';
|
||||
if ($thisfile_replaygain['track']['peak'] <= 0) {
|
||||
$this->warning('ReplayGain Track peak from APEtag appears invalid: '.$thisfile_replaygain['track']['peak'].' (original value = "'.$thisfile_ape_items_current['data'][0].'")');
|
||||
}
|
||||
} else {
|
||||
$this->warning('MP3gainTrackPeak value in APEtag appears invalid: "'.$thisfile_ape_items_current['data'][0].'"');
|
||||
}
|
||||
break;
|
||||
|
||||
case 'replaygain_album_gain':
|
||||
if (preg_match('#^([\\-\\+][0-9\\.,]{8})( dB)?$#', $thisfile_ape_items_current['data'][0], $matches)) {
|
||||
$thisfile_replaygain['album']['adjustment'] = (float) str_replace(',', '.', $matches[1]); // float casting will see "0,95" as zero!
|
||||
$thisfile_replaygain['album']['originator'] = 'unspecified';
|
||||
} else {
|
||||
$this->warning('MP3gainAlbumGain value in APEtag appears invalid: "'.$thisfile_ape_items_current['data'][0].'"');
|
||||
}
|
||||
break;
|
||||
|
||||
case 'replaygain_album_peak':
|
||||
if (preg_match('#^([0-9\\.,]{8})$#', $thisfile_ape_items_current['data'][0], $matches)) {
|
||||
$thisfile_replaygain['album']['peak'] = (float) str_replace(',', '.', $matches[1]); // float casting will see "0,95" as zero!
|
||||
$thisfile_replaygain['album']['originator'] = 'unspecified';
|
||||
if ($thisfile_replaygain['album']['peak'] <= 0) {
|
||||
$this->warning('ReplayGain Album peak from APEtag appears invalid: '.$thisfile_replaygain['album']['peak'].' (original value = "'.$thisfile_ape_items_current['data'][0].'")');
|
||||
}
|
||||
} else {
|
||||
$this->warning('MP3gainAlbumPeak value in APEtag appears invalid: "'.$thisfile_ape_items_current['data'][0].'"');
|
||||
}
|
||||
break;
|
||||
|
||||
case 'mp3gain_undo':
|
||||
if (preg_match('#^[\\-\\+][0-9]{3},[\\-\\+][0-9]{3},[NW]$#', $thisfile_ape_items_current['data'][0])) {
|
||||
list($mp3gain_undo_left, $mp3gain_undo_right, $mp3gain_undo_wrap) = explode(',', $thisfile_ape_items_current['data'][0]);
|
||||
$thisfile_replaygain['mp3gain']['undo_left'] = intval($mp3gain_undo_left);
|
||||
$thisfile_replaygain['mp3gain']['undo_right'] = intval($mp3gain_undo_right);
|
||||
$thisfile_replaygain['mp3gain']['undo_wrap'] = (($mp3gain_undo_wrap == 'Y') ? true : false);
|
||||
} else {
|
||||
$this->warning('MP3gainUndo value in APEtag appears invalid: "'.$thisfile_ape_items_current['data'][0].'"');
|
||||
}
|
||||
break;
|
||||
|
||||
case 'mp3gain_minmax':
|
||||
if (preg_match('#^[0-9]{3},[0-9]{3}$#', $thisfile_ape_items_current['data'][0])) {
|
||||
list($mp3gain_globalgain_min, $mp3gain_globalgain_max) = explode(',', $thisfile_ape_items_current['data'][0]);
|
||||
$thisfile_replaygain['mp3gain']['globalgain_track_min'] = intval($mp3gain_globalgain_min);
|
||||
$thisfile_replaygain['mp3gain']['globalgain_track_max'] = intval($mp3gain_globalgain_max);
|
||||
} else {
|
||||
$this->warning('MP3gainMinMax value in APEtag appears invalid: "'.$thisfile_ape_items_current['data'][0].'"');
|
||||
}
|
||||
break;
|
||||
|
||||
case 'mp3gain_album_minmax':
|
||||
if (preg_match('#^[0-9]{3},[0-9]{3}$#', $thisfile_ape_items_current['data'][0])) {
|
||||
list($mp3gain_globalgain_album_min, $mp3gain_globalgain_album_max) = explode(',', $thisfile_ape_items_current['data'][0]);
|
||||
$thisfile_replaygain['mp3gain']['globalgain_album_min'] = intval($mp3gain_globalgain_album_min);
|
||||
$thisfile_replaygain['mp3gain']['globalgain_album_max'] = intval($mp3gain_globalgain_album_max);
|
||||
} else {
|
||||
$this->warning('MP3gainAlbumMinMax value in APEtag appears invalid: "'.$thisfile_ape_items_current['data'][0].'"');
|
||||
}
|
||||
break;
|
||||
|
||||
case 'tracknumber':
|
||||
if (is_array($thisfile_ape_items_current['data'])) {
|
||||
foreach ($thisfile_ape_items_current['data'] as $comment) {
|
||||
$thisfile_ape['comments']['track_number'][] = $comment;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'cover art (artist)':
|
||||
case 'cover art (back)':
|
||||
case 'cover art (band logo)':
|
||||
case 'cover art (band)':
|
||||
case 'cover art (colored fish)':
|
||||
case 'cover art (composer)':
|
||||
case 'cover art (conductor)':
|
||||
case 'cover art (front)':
|
||||
case 'cover art (icon)':
|
||||
case 'cover art (illustration)':
|
||||
case 'cover art (lead)':
|
||||
case 'cover art (leaflet)':
|
||||
case 'cover art (lyricist)':
|
||||
case 'cover art (media)':
|
||||
case 'cover art (movie scene)':
|
||||
case 'cover art (other icon)':
|
||||
case 'cover art (other)':
|
||||
case 'cover art (performance)':
|
||||
case 'cover art (publisher logo)':
|
||||
case 'cover art (recording)':
|
||||
case 'cover art (studio)':
|
||||
// list of possible cover arts from https://github.com/mono/taglib-sharp/blob/taglib-sharp-2.0.3.2/src/TagLib/Ape/Tag.cs
|
||||
if (is_array($thisfile_ape_items_current['data'])) {
|
||||
$this->warning('APEtag "'.$item_key.'" should be flagged as Binary data, but was incorrectly flagged as UTF-8');
|
||||
$thisfile_ape_items_current['data'] = implode("\x00", $thisfile_ape_items_current['data']);
|
||||
}
|
||||
list($thisfile_ape_items_current['filename'], $thisfile_ape_items_current['data']) = explode("\x00", $thisfile_ape_items_current['data'], 2);
|
||||
$thisfile_ape_items_current['data_offset'] = $thisfile_ape_items_current['offset'] + strlen($thisfile_ape_items_current['filename']."\x00");
|
||||
$thisfile_ape_items_current['data_length'] = strlen($thisfile_ape_items_current['data']);
|
||||
|
||||
do {
|
||||
$thisfile_ape_items_current['image_mime'] = '';
|
||||
$imageinfo = array();
|
||||
$imagechunkcheck = getid3_lib::GetDataImageSize($thisfile_ape_items_current['data'], $imageinfo);
|
||||
if (($imagechunkcheck === false) || !isset($imagechunkcheck[2])) {
|
||||
$this->warning('APEtag "'.$item_key.'" contains invalid image data');
|
||||
break;
|
||||
}
|
||||
$thisfile_ape_items_current['image_mime'] = image_type_to_mime_type($imagechunkcheck[2]);
|
||||
|
||||
if ($this->inline_attachments === false) {
|
||||
// skip entirely
|
||||
unset($thisfile_ape_items_current['data']);
|
||||
break;
|
||||
}
|
||||
if ($this->inline_attachments === true) {
|
||||
// great
|
||||
} elseif (is_int($this->inline_attachments)) {
|
||||
if ($this->inline_attachments < $thisfile_ape_items_current['data_length']) {
|
||||
// too big, skip
|
||||
$this->warning('attachment at '.$thisfile_ape_items_current['offset'].' is too large to process inline ('.number_format($thisfile_ape_items_current['data_length']).' bytes)');
|
||||
unset($thisfile_ape_items_current['data']);
|
||||
break;
|
||||
}
|
||||
} elseif (is_string($this->inline_attachments)) {
|
||||
$this->inline_attachments = rtrim(str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $this->inline_attachments), DIRECTORY_SEPARATOR);
|
||||
if (!is_dir($this->inline_attachments) || !getID3::is_writable($this->inline_attachments)) {
|
||||
// cannot write, skip
|
||||
$this->warning('attachment at '.$thisfile_ape_items_current['offset'].' cannot be saved to "'.$this->inline_attachments.'" (not writable)');
|
||||
unset($thisfile_ape_items_current['data']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
// if we get this far, must be OK
|
||||
if (is_string($this->inline_attachments)) {
|
||||
$destination_filename = $this->inline_attachments.DIRECTORY_SEPARATOR.md5($info['filenamepath']).'_'.$thisfile_ape_items_current['data_offset'];
|
||||
if (!file_exists($destination_filename) || getID3::is_writable($destination_filename)) {
|
||||
file_put_contents($destination_filename, $thisfile_ape_items_current['data']);
|
||||
} else {
|
||||
$this->warning('attachment at '.$thisfile_ape_items_current['offset'].' cannot be saved to "'.$destination_filename.'" (not writable)');
|
||||
}
|
||||
$thisfile_ape_items_current['data_filename'] = $destination_filename;
|
||||
unset($thisfile_ape_items_current['data']);
|
||||
} else {
|
||||
if (!isset($info['ape']['comments']['picture'])) {
|
||||
$info['ape']['comments']['picture'] = array();
|
||||
}
|
||||
$comments_picture_data = array();
|
||||
foreach (array('data', 'image_mime', 'image_width', 'image_height', 'imagetype', 'picturetype', 'description', 'datalength') as $picture_key) {
|
||||
if (isset($thisfile_ape_items_current[$picture_key])) {
|
||||
$comments_picture_data[$picture_key] = $thisfile_ape_items_current[$picture_key];
|
||||
}
|
||||
}
|
||||
$info['ape']['comments']['picture'][] = $comments_picture_data;
|
||||
unset($comments_picture_data);
|
||||
}
|
||||
} while (false); // @phpstan-ignore-line
|
||||
break;
|
||||
|
||||
default:
|
||||
if (is_array($thisfile_ape_items_current['data'])) {
|
||||
foreach ($thisfile_ape_items_current['data'] as $comment) {
|
||||
$thisfile_ape['comments'][strtolower($item_key)][] = $comment;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
if (empty($thisfile_replaygain)) {
|
||||
unset($info['replay_gain']);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $APEheaderFooterData
|
||||
*
|
||||
* @return array|false
|
||||
*/
|
||||
public function parseAPEheaderFooter($APEheaderFooterData) {
|
||||
// http://www.uni-jena.de/~pfk/mpp/sv8/apeheader.html
|
||||
|
||||
// shortcut
|
||||
$headerfooterinfo = array();
|
||||
$headerfooterinfo['raw'] = array();
|
||||
$headerfooterinfo_raw = &$headerfooterinfo['raw'];
|
||||
|
||||
$headerfooterinfo_raw['footer_tag'] = substr($APEheaderFooterData, 0, 8);
|
||||
if ($headerfooterinfo_raw['footer_tag'] != 'APETAGEX') {
|
||||
return false;
|
||||
}
|
||||
$headerfooterinfo_raw['version'] = getid3_lib::LittleEndian2Int(substr($APEheaderFooterData, 8, 4));
|
||||
$headerfooterinfo_raw['tagsize'] = getid3_lib::LittleEndian2Int(substr($APEheaderFooterData, 12, 4));
|
||||
$headerfooterinfo_raw['tag_items'] = getid3_lib::LittleEndian2Int(substr($APEheaderFooterData, 16, 4));
|
||||
$headerfooterinfo_raw['global_flags'] = getid3_lib::LittleEndian2Int(substr($APEheaderFooterData, 20, 4));
|
||||
$headerfooterinfo_raw['reserved'] = substr($APEheaderFooterData, 24, 8);
|
||||
|
||||
$headerfooterinfo['tag_version'] = $headerfooterinfo_raw['version'] / 1000;
|
||||
if ($headerfooterinfo['tag_version'] >= 2) {
|
||||
$headerfooterinfo['flags'] = $this->parseAPEtagFlags($headerfooterinfo_raw['global_flags']);
|
||||
}
|
||||
return $headerfooterinfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $rawflagint
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function parseAPEtagFlags($rawflagint) {
|
||||
// "Note: APE Tags 1.0 do not use any of the APE Tag flags.
|
||||
// All are set to zero on creation and ignored on reading."
|
||||
// http://wiki.hydrogenaud.io/index.php?title=Ape_Tags_Flags
|
||||
$flags = array();
|
||||
$flags['header'] = (bool) ($rawflagint & 0x80000000);
|
||||
$flags['footer'] = (bool) ($rawflagint & 0x40000000);
|
||||
$flags['this_is_header'] = (bool) ($rawflagint & 0x20000000);
|
||||
$flags['item_contents_raw'] = ($rawflagint & 0x00000006) >> 1;
|
||||
$flags['read_only'] = (bool) ($rawflagint & 0x00000001);
|
||||
|
||||
$flags['item_contents'] = $this->APEcontentTypeFlagLookup($flags['item_contents_raw']);
|
||||
|
||||
return $flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $contenttypeid
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function APEcontentTypeFlagLookup($contenttypeid) {
|
||||
static $APEcontentTypeFlagLookup = array(
|
||||
0 => 'utf-8',
|
||||
1 => 'binary',
|
||||
2 => 'external',
|
||||
3 => 'reserved'
|
||||
);
|
||||
return (isset($APEcontentTypeFlagLookup[$contenttypeid]) ? $APEcontentTypeFlagLookup[$contenttypeid] : 'invalid');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $itemkey
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function APEtagItemIsUTF8Lookup($itemkey) {
|
||||
static $APEtagItemIsUTF8Lookup = array(
|
||||
'title',
|
||||
'subtitle',
|
||||
'artist',
|
||||
'album',
|
||||
'debut album',
|
||||
'publisher',
|
||||
'conductor',
|
||||
'track',
|
||||
'composer',
|
||||
'comment',
|
||||
'copyright',
|
||||
'publicationright',
|
||||
'file',
|
||||
'year',
|
||||
'record date',
|
||||
'record location',
|
||||
'genre',
|
||||
'media',
|
||||
'related',
|
||||
'isrc',
|
||||
'abstract',
|
||||
'language',
|
||||
'bibliography'
|
||||
);
|
||||
return in_array(strtolower($itemkey), $APEtagItemIsUTF8Lookup);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,480 +1,480 @@
|
||||
<?php
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
/// getID3() by James Heinrich <info@getid3.org> //
|
||||
// available at https://github.com/JamesHeinrich/getID3 //
|
||||
// or https://www.getid3.org //
|
||||
// or http://getid3.sourceforge.net //
|
||||
// see readme.txt for more details //
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// module.tag.id3v1.php //
|
||||
// module for analyzing ID3v1 tags //
|
||||
// dependencies: NONE //
|
||||
// ///
|
||||
/////////////////////////////////////////////////////////////////
|
||||
|
||||
if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers
|
||||
exit;
|
||||
}
|
||||
|
||||
class getid3_id3v1 extends getid3_handler
|
||||
{
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function Analyze() {
|
||||
$info = &$this->getid3->info;
|
||||
|
||||
if (!getid3_lib::intValueSupported($info['filesize'])) {
|
||||
$this->warning('Unable to check for ID3v1 because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB');
|
||||
return false;
|
||||
}
|
||||
|
||||
if($info['filesize'] < 256) {
|
||||
$this->fseek(-128, SEEK_END);
|
||||
$preid3v1 = '';
|
||||
$id3v1tag = $this->fread(128);
|
||||
} else {
|
||||
$this->fseek(-256, SEEK_END);
|
||||
$preid3v1 = $this->fread(128);
|
||||
$id3v1tag = $this->fread(128);
|
||||
}
|
||||
|
||||
|
||||
if (substr($id3v1tag, 0, 3) == 'TAG') {
|
||||
|
||||
$info['avdataend'] = $info['filesize'] - 128;
|
||||
|
||||
$ParsedID3v1 = array();
|
||||
$ParsedID3v1['title'] = $this->cutfield(substr($id3v1tag, 3, 30));
|
||||
$ParsedID3v1['artist'] = $this->cutfield(substr($id3v1tag, 33, 30));
|
||||
$ParsedID3v1['album'] = $this->cutfield(substr($id3v1tag, 63, 30));
|
||||
$ParsedID3v1['year'] = $this->cutfield(substr($id3v1tag, 93, 4));
|
||||
$ParsedID3v1['comment'] = substr($id3v1tag, 97, 30); // can't remove nulls yet, track detection depends on them
|
||||
$ParsedID3v1['genreid'] = ord(substr($id3v1tag, 127, 1));
|
||||
|
||||
// If second-last byte of comment field is null and last byte of comment field is non-null
|
||||
// then this is ID3v1.1 and the comment field is 28 bytes long and the 30th byte is the track number
|
||||
if (($id3v1tag[125] === "\x00") && ($id3v1tag[126] !== "\x00")) {
|
||||
$ParsedID3v1['track_number'] = ord(substr($ParsedID3v1['comment'], 29, 1));
|
||||
$ParsedID3v1['comment'] = substr($ParsedID3v1['comment'], 0, 28);
|
||||
}
|
||||
$ParsedID3v1['comment'] = $this->cutfield($ParsedID3v1['comment']);
|
||||
|
||||
$ParsedID3v1['genre'] = $this->LookupGenreName($ParsedID3v1['genreid']);
|
||||
if (!empty($ParsedID3v1['genre'])) {
|
||||
unset($ParsedID3v1['genreid']);
|
||||
}
|
||||
if (empty($ParsedID3v1['genre']) || ($ParsedID3v1['genre'] == 'Unknown')) {
|
||||
unset($ParsedID3v1['genre']);
|
||||
}
|
||||
|
||||
foreach ($ParsedID3v1 as $key => $value) {
|
||||
$ParsedID3v1['comments'][$key][0] = $value;
|
||||
}
|
||||
$ID3v1encoding = $this->getid3->encoding_id3v1;
|
||||
if ($this->getid3->encoding_id3v1_autodetect) {
|
||||
// ID3v1 encoding detection hack START
|
||||
// ID3v1 is defined as always using ISO-8859-1 encoding, but it is not uncommon to find files tagged with ID3v1 using Windows-1251 or other character sets
|
||||
// Since ID3v1 has no concept of character sets there is no certain way to know we have the correct non-ISO-8859-1 character set, but we can guess
|
||||
foreach ($ParsedID3v1['comments'] as $tag_key => $valuearray) {
|
||||
foreach ($valuearray as $key => $value) {
|
||||
if (preg_match('#^[\\x00-\\x40\\x80-\\xFF]+$#', $value) && !ctype_digit((string) $value)) { // check for strings with only characters above chr(128) and punctuation/numbers, but not just numeric strings (e.g. track numbers or years)
|
||||
foreach (array('Windows-1251', 'KOI8-R') as $id3v1_bad_encoding) {
|
||||
if (function_exists('mb_convert_encoding') && @mb_convert_encoding($value, $id3v1_bad_encoding, $id3v1_bad_encoding) === $value) {
|
||||
$ID3v1encoding = $id3v1_bad_encoding;
|
||||
$this->warning('ID3v1 detected as '.$id3v1_bad_encoding.' text encoding in '.$tag_key);
|
||||
break 3;
|
||||
} elseif (function_exists('iconv') && @iconv($id3v1_bad_encoding, $id3v1_bad_encoding, $value) === $value) {
|
||||
$ID3v1encoding = $id3v1_bad_encoding;
|
||||
$this->warning('ID3v1 detected as '.$id3v1_bad_encoding.' text encoding in '.$tag_key);
|
||||
break 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// ID3v1 encoding detection hack END
|
||||
}
|
||||
|
||||
// ID3v1 data is supposed to be padded with NULL characters, but some taggers pad with spaces
|
||||
$GoodFormatID3v1tag = $this->GenerateID3v1Tag(
|
||||
$ParsedID3v1['title'],
|
||||
$ParsedID3v1['artist'],
|
||||
$ParsedID3v1['album'],
|
||||
$ParsedID3v1['year'],
|
||||
(isset($ParsedID3v1['genre']) ? $this->LookupGenreID($ParsedID3v1['genre']) : false),
|
||||
$ParsedID3v1['comment'],
|
||||
(!empty($ParsedID3v1['track_number']) ? $ParsedID3v1['track_number'] : ''));
|
||||
$ParsedID3v1['padding_valid'] = true;
|
||||
if ($id3v1tag !== $GoodFormatID3v1tag) {
|
||||
$ParsedID3v1['padding_valid'] = false;
|
||||
$this->warning('Some ID3v1 fields do not use NULL characters for padding');
|
||||
}
|
||||
|
||||
$ParsedID3v1['tag_offset_end'] = $info['filesize'];
|
||||
$ParsedID3v1['tag_offset_start'] = $ParsedID3v1['tag_offset_end'] - 128;
|
||||
|
||||
$info['id3v1'] = $ParsedID3v1;
|
||||
$info['id3v1']['encoding'] = $ID3v1encoding;
|
||||
}
|
||||
|
||||
if (substr($preid3v1, 0, 3) == 'TAG') {
|
||||
// The way iTunes handles tags is, well, brain-damaged.
|
||||
// It completely ignores v1 if ID3v2 is present.
|
||||
// This goes as far as adding a new v1 tag *even if there already is one*
|
||||
|
||||
// A suspected double-ID3v1 tag has been detected, but it could be that
|
||||
// the "TAG" identifier is a legitimate part of an APE or Lyrics3 tag
|
||||
if (substr($preid3v1, 96, 8) == 'APETAGEX') {
|
||||
// an APE tag footer was found before the last ID3v1, assume false "TAG" synch
|
||||
} elseif (substr($preid3v1, 119, 6) == 'LYRICS') {
|
||||
// a Lyrics3 tag footer was found before the last ID3v1, assume false "TAG" synch
|
||||
} else {
|
||||
// APE and Lyrics3 footers not found - assume double ID3v1
|
||||
$this->warning('Duplicate ID3v1 tag detected - this has been known to happen with iTunes');
|
||||
$info['avdataend'] -= 128;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $str
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function cutfield($str) {
|
||||
return trim(substr($str, 0, strcspn($str, "\x00")));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $allowSCMPXextended
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public static function ArrayOfGenres($allowSCMPXextended=false) {
|
||||
static $GenreLookup = array(
|
||||
0 => 'Blues',
|
||||
1 => 'Classic Rock',
|
||||
2 => 'Country',
|
||||
3 => 'Dance',
|
||||
4 => 'Disco',
|
||||
5 => 'Funk',
|
||||
6 => 'Grunge',
|
||||
7 => 'Hip-Hop',
|
||||
8 => 'Jazz',
|
||||
9 => 'Metal',
|
||||
10 => 'New Age',
|
||||
11 => 'Oldies',
|
||||
12 => 'Other',
|
||||
13 => 'Pop',
|
||||
14 => 'R&B',
|
||||
15 => 'Rap',
|
||||
16 => 'Reggae',
|
||||
17 => 'Rock',
|
||||
18 => 'Techno',
|
||||
19 => 'Industrial',
|
||||
20 => 'Alternative',
|
||||
21 => 'Ska',
|
||||
22 => 'Death Metal',
|
||||
23 => 'Pranks',
|
||||
24 => 'Soundtrack',
|
||||
25 => 'Euro-Techno',
|
||||
26 => 'Ambient',
|
||||
27 => 'Trip-Hop',
|
||||
28 => 'Vocal',
|
||||
29 => 'Jazz+Funk',
|
||||
30 => 'Fusion',
|
||||
31 => 'Trance',
|
||||
32 => 'Classical',
|
||||
33 => 'Instrumental',
|
||||
34 => 'Acid',
|
||||
35 => 'House',
|
||||
36 => 'Game',
|
||||
37 => 'Sound Clip',
|
||||
38 => 'Gospel',
|
||||
39 => 'Noise',
|
||||
40 => 'Alt. Rock',
|
||||
41 => 'Bass',
|
||||
42 => 'Soul',
|
||||
43 => 'Punk',
|
||||
44 => 'Space',
|
||||
45 => 'Meditative',
|
||||
46 => 'Instrumental Pop',
|
||||
47 => 'Instrumental Rock',
|
||||
48 => 'Ethnic',
|
||||
49 => 'Gothic',
|
||||
50 => 'Darkwave',
|
||||
51 => 'Techno-Industrial',
|
||||
52 => 'Electronic',
|
||||
53 => 'Pop-Folk',
|
||||
54 => 'Eurodance',
|
||||
55 => 'Dream',
|
||||
56 => 'Southern Rock',
|
||||
57 => 'Comedy',
|
||||
58 => 'Cult',
|
||||
59 => 'Gangsta Rap',
|
||||
60 => 'Top 40',
|
||||
61 => 'Christian Rap',
|
||||
62 => 'Pop/Funk',
|
||||
63 => 'Jungle',
|
||||
64 => 'Native American',
|
||||
65 => 'Cabaret',
|
||||
66 => 'New Wave',
|
||||
67 => 'Psychedelic',
|
||||
68 => 'Rave',
|
||||
69 => 'Showtunes',
|
||||
70 => 'Trailer',
|
||||
71 => 'Lo-Fi',
|
||||
72 => 'Tribal',
|
||||
73 => 'Acid Punk',
|
||||
74 => 'Acid Jazz',
|
||||
75 => 'Polka',
|
||||
76 => 'Retro',
|
||||
77 => 'Musical',
|
||||
78 => 'Rock & Roll',
|
||||
79 => 'Hard Rock',
|
||||
80 => 'Folk',
|
||||
81 => 'Folk/Rock',
|
||||
82 => 'National Folk',
|
||||
83 => 'Swing',
|
||||
84 => 'Fast-Fusion',
|
||||
85 => 'Bebob',
|
||||
86 => 'Latin',
|
||||
87 => 'Revival',
|
||||
88 => 'Celtic',
|
||||
89 => 'Bluegrass',
|
||||
90 => 'Avantgarde',
|
||||
91 => 'Gothic Rock',
|
||||
92 => 'Progressive Rock',
|
||||
93 => 'Psychedelic Rock',
|
||||
94 => 'Symphonic Rock',
|
||||
95 => 'Slow Rock',
|
||||
96 => 'Big Band',
|
||||
97 => 'Chorus',
|
||||
98 => 'Easy Listening',
|
||||
99 => 'Acoustic',
|
||||
100 => 'Humour',
|
||||
101 => 'Speech',
|
||||
102 => 'Chanson',
|
||||
103 => 'Opera',
|
||||
104 => 'Chamber Music',
|
||||
105 => 'Sonata',
|
||||
106 => 'Symphony',
|
||||
107 => 'Booty Bass',
|
||||
108 => 'Primus',
|
||||
109 => 'Porn Groove',
|
||||
110 => 'Satire',
|
||||
111 => 'Slow Jam',
|
||||
112 => 'Club',
|
||||
113 => 'Tango',
|
||||
114 => 'Samba',
|
||||
115 => 'Folklore',
|
||||
116 => 'Ballad',
|
||||
117 => 'Power Ballad',
|
||||
118 => 'Rhythmic Soul',
|
||||
119 => 'Freestyle',
|
||||
120 => 'Duet',
|
||||
121 => 'Punk Rock',
|
||||
122 => 'Drum Solo',
|
||||
123 => 'A Cappella',
|
||||
124 => 'Euro-House',
|
||||
125 => 'Dance Hall',
|
||||
126 => 'Goa',
|
||||
127 => 'Drum & Bass',
|
||||
128 => 'Club-House',
|
||||
129 => 'Hardcore',
|
||||
130 => 'Terror',
|
||||
131 => 'Indie',
|
||||
132 => 'BritPop',
|
||||
133 => 'Negerpunk',
|
||||
134 => 'Polsk Punk',
|
||||
135 => 'Beat',
|
||||
136 => 'Christian Gangsta Rap',
|
||||
137 => 'Heavy Metal',
|
||||
138 => 'Black Metal',
|
||||
139 => 'Crossover',
|
||||
140 => 'Contemporary Christian',
|
||||
141 => 'Christian Rock',
|
||||
142 => 'Merengue',
|
||||
143 => 'Salsa',
|
||||
144 => 'Thrash Metal',
|
||||
145 => 'Anime',
|
||||
146 => 'JPop',
|
||||
147 => 'Synthpop',
|
||||
148 => 'Abstract',
|
||||
149 => 'Art Rock',
|
||||
150 => 'Baroque',
|
||||
151 => 'Bhangra',
|
||||
152 => 'Big Beat',
|
||||
153 => 'Breakbeat',
|
||||
154 => 'Chillout',
|
||||
155 => 'Downtempo',
|
||||
156 => 'Dub',
|
||||
157 => 'EBM',
|
||||
158 => 'Eclectic',
|
||||
159 => 'Electro',
|
||||
160 => 'Electroclash',
|
||||
161 => 'Emo',
|
||||
162 => 'Experimental',
|
||||
163 => 'Garage',
|
||||
164 => 'Global',
|
||||
165 => 'IDM',
|
||||
166 => 'Illbient',
|
||||
167 => 'Industro-Goth',
|
||||
168 => 'Jam Band',
|
||||
169 => 'Krautrock',
|
||||
170 => 'Leftfield',
|
||||
171 => 'Lounge',
|
||||
172 => 'Math Rock',
|
||||
173 => 'New Romantic',
|
||||
174 => 'Nu-Breakz',
|
||||
175 => 'Post-Punk',
|
||||
176 => 'Post-Rock',
|
||||
177 => 'Psytrance',
|
||||
178 => 'Shoegaze',
|
||||
179 => 'Space Rock',
|
||||
180 => 'Trop Rock',
|
||||
181 => 'World Music',
|
||||
182 => 'Neoclassical',
|
||||
183 => 'Audiobook',
|
||||
184 => 'Audio Theatre',
|
||||
185 => 'Neue Deutsche Welle',
|
||||
186 => 'Podcast',
|
||||
187 => 'Indie-Rock',
|
||||
188 => 'G-Funk',
|
||||
189 => 'Dubstep',
|
||||
190 => 'Garage Rock',
|
||||
191 => 'Psybient',
|
||||
|
||||
255 => 'Unknown',
|
||||
|
||||
'CR' => 'Cover',
|
||||
'RX' => 'Remix'
|
||||
);
|
||||
|
||||
static $GenreLookupSCMPX = array();
|
||||
if ($allowSCMPXextended && empty($GenreLookupSCMPX)) {
|
||||
$GenreLookupSCMPX = $GenreLookup;
|
||||
// http://www.geocities.co.jp/SiliconValley-Oakland/3664/alittle.html#GenreExtended
|
||||
// Extended ID3v1 genres invented by SCMPX
|
||||
// Note that 255 "Japanese Anime" conflicts with standard "Unknown"
|
||||
$GenreLookupSCMPX[240] = 'Sacred';
|
||||
$GenreLookupSCMPX[241] = 'Northern Europe';
|
||||
$GenreLookupSCMPX[242] = 'Irish & Scottish';
|
||||
$GenreLookupSCMPX[243] = 'Scotland';
|
||||
$GenreLookupSCMPX[244] = 'Ethnic Europe';
|
||||
$GenreLookupSCMPX[245] = 'Enka';
|
||||
$GenreLookupSCMPX[246] = 'Children\'s Song';
|
||||
$GenreLookupSCMPX[247] = 'Japanese Sky';
|
||||
$GenreLookupSCMPX[248] = 'Japanese Heavy Rock';
|
||||
$GenreLookupSCMPX[249] = 'Japanese Doom Rock';
|
||||
$GenreLookupSCMPX[250] = 'Japanese J-POP';
|
||||
$GenreLookupSCMPX[251] = 'Japanese Seiyu';
|
||||
$GenreLookupSCMPX[252] = 'Japanese Ambient Techno';
|
||||
$GenreLookupSCMPX[253] = 'Japanese Moemoe';
|
||||
$GenreLookupSCMPX[254] = 'Japanese Tokusatsu';
|
||||
//$GenreLookupSCMPX[255] = 'Japanese Anime';
|
||||
}
|
||||
|
||||
return ($allowSCMPXextended ? $GenreLookupSCMPX : $GenreLookup);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $genreid
|
||||
* @param bool $allowSCMPXextended
|
||||
*
|
||||
* @return string|false
|
||||
*/
|
||||
public static function LookupGenreName($genreid, $allowSCMPXextended=true) {
|
||||
switch ($genreid) {
|
||||
case 'RX':
|
||||
case 'CR':
|
||||
break;
|
||||
default:
|
||||
if (!is_numeric($genreid)) {
|
||||
return false;
|
||||
}
|
||||
$genreid = intval($genreid); // to handle 3 or '3' or '03'
|
||||
break;
|
||||
}
|
||||
$GenreLookup = self::ArrayOfGenres($allowSCMPXextended);
|
||||
return (isset($GenreLookup[$genreid]) ? $GenreLookup[$genreid] : false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $genre
|
||||
* @param bool $allowSCMPXextended
|
||||
*
|
||||
* @return string|false
|
||||
*/
|
||||
public static function LookupGenreID($genre, $allowSCMPXextended=false) {
|
||||
$GenreLookup = self::ArrayOfGenres($allowSCMPXextended);
|
||||
$LowerCaseNoSpaceSearchTerm = strtolower(str_replace(' ', '', $genre));
|
||||
foreach ($GenreLookup as $key => $value) {
|
||||
if (strtolower(str_replace(' ', '', $value)) == $LowerCaseNoSpaceSearchTerm) {
|
||||
return $key;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $OriginalGenre
|
||||
*
|
||||
* @return string|false
|
||||
*/
|
||||
public static function StandardiseID3v1GenreName($OriginalGenre) {
|
||||
if (($GenreID = self::LookupGenreID($OriginalGenre)) !== false) {
|
||||
return self::LookupGenreName($GenreID);
|
||||
}
|
||||
return $OriginalGenre;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $title
|
||||
* @param string $artist
|
||||
* @param string $album
|
||||
* @param string $year
|
||||
* @param int $genreid
|
||||
* @param string $comment
|
||||
* @param int|string $track
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function GenerateID3v1Tag($title, $artist, $album, $year, $genreid, $comment, $track='') {
|
||||
$ID3v1Tag = 'TAG';
|
||||
$ID3v1Tag .= str_pad(trim(substr($title, 0, 30)), 30, "\x00", STR_PAD_RIGHT);
|
||||
$ID3v1Tag .= str_pad(trim(substr($artist, 0, 30)), 30, "\x00", STR_PAD_RIGHT);
|
||||
$ID3v1Tag .= str_pad(trim(substr($album, 0, 30)), 30, "\x00", STR_PAD_RIGHT);
|
||||
$ID3v1Tag .= str_pad(trim(substr($year, 0, 4)), 4, "\x00", STR_PAD_LEFT);
|
||||
if (!empty($track) && ($track > 0) && ($track <= 255)) {
|
||||
$ID3v1Tag .= str_pad(trim(substr($comment, 0, 28)), 28, "\x00", STR_PAD_RIGHT);
|
||||
$ID3v1Tag .= "\x00";
|
||||
if (gettype($track) == 'string') {
|
||||
$track = (int) $track;
|
||||
}
|
||||
$ID3v1Tag .= chr($track);
|
||||
} else {
|
||||
$ID3v1Tag .= str_pad(trim(substr($comment, 0, 30)), 30, "\x00", STR_PAD_RIGHT);
|
||||
}
|
||||
if (($genreid < 0) || ($genreid > 147)) {
|
||||
$genreid = 255; // 'unknown' genre
|
||||
}
|
||||
switch (gettype($genreid)) {
|
||||
case 'string':
|
||||
case 'integer':
|
||||
$ID3v1Tag .= chr(intval($genreid));
|
||||
break;
|
||||
default:
|
||||
$ID3v1Tag .= chr(255); // 'unknown' genre
|
||||
break;
|
||||
}
|
||||
|
||||
return $ID3v1Tag;
|
||||
}
|
||||
|
||||
}
|
||||
<?php
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
/// getID3() by James Heinrich <info@getid3.org> //
|
||||
// available at https://github.com/JamesHeinrich/getID3 //
|
||||
// or https://www.getid3.org //
|
||||
// or http://getid3.sourceforge.net //
|
||||
// see readme.txt for more details //
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// module.tag.id3v1.php //
|
||||
// module for analyzing ID3v1 tags //
|
||||
// dependencies: NONE //
|
||||
// ///
|
||||
/////////////////////////////////////////////////////////////////
|
||||
|
||||
if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers
|
||||
exit;
|
||||
}
|
||||
|
||||
class getid3_id3v1 extends getid3_handler
|
||||
{
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function Analyze() {
|
||||
$info = &$this->getid3->info;
|
||||
|
||||
if (!getid3_lib::intValueSupported($info['filesize'])) {
|
||||
$this->warning('Unable to check for ID3v1 because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB');
|
||||
return false;
|
||||
}
|
||||
|
||||
if($info['filesize'] < 256) {
|
||||
$this->fseek(-128, SEEK_END);
|
||||
$preid3v1 = '';
|
||||
$id3v1tag = $this->fread(128);
|
||||
} else {
|
||||
$this->fseek(-256, SEEK_END);
|
||||
$preid3v1 = $this->fread(128);
|
||||
$id3v1tag = $this->fread(128);
|
||||
}
|
||||
|
||||
|
||||
if (substr($id3v1tag, 0, 3) == 'TAG') {
|
||||
|
||||
$info['avdataend'] = $info['filesize'] - 128;
|
||||
|
||||
$ParsedID3v1 = array();
|
||||
$ParsedID3v1['title'] = $this->cutfield(substr($id3v1tag, 3, 30));
|
||||
$ParsedID3v1['artist'] = $this->cutfield(substr($id3v1tag, 33, 30));
|
||||
$ParsedID3v1['album'] = $this->cutfield(substr($id3v1tag, 63, 30));
|
||||
$ParsedID3v1['year'] = $this->cutfield(substr($id3v1tag, 93, 4));
|
||||
$ParsedID3v1['comment'] = substr($id3v1tag, 97, 30); // can't remove nulls yet, track detection depends on them
|
||||
$ParsedID3v1['genreid'] = ord(substr($id3v1tag, 127, 1));
|
||||
|
||||
// If second-last byte of comment field is null and last byte of comment field is non-null
|
||||
// then this is ID3v1.1 and the comment field is 28 bytes long and the 30th byte is the track number
|
||||
if (($id3v1tag[125] === "\x00") && ($id3v1tag[126] !== "\x00")) {
|
||||
$ParsedID3v1['track_number'] = ord(substr($ParsedID3v1['comment'], 29, 1));
|
||||
$ParsedID3v1['comment'] = substr($ParsedID3v1['comment'], 0, 28);
|
||||
}
|
||||
$ParsedID3v1['comment'] = $this->cutfield($ParsedID3v1['comment']);
|
||||
|
||||
$ParsedID3v1['genre'] = $this->LookupGenreName($ParsedID3v1['genreid']);
|
||||
if (!empty($ParsedID3v1['genre'])) {
|
||||
unset($ParsedID3v1['genreid']);
|
||||
}
|
||||
if (empty($ParsedID3v1['genre']) || ($ParsedID3v1['genre'] == 'Unknown')) {
|
||||
unset($ParsedID3v1['genre']);
|
||||
}
|
||||
|
||||
foreach ($ParsedID3v1 as $key => $value) {
|
||||
$ParsedID3v1['comments'][$key][0] = $value;
|
||||
}
|
||||
$ID3v1encoding = $this->getid3->encoding_id3v1;
|
||||
if ($this->getid3->encoding_id3v1_autodetect) {
|
||||
// ID3v1 encoding detection hack START
|
||||
// ID3v1 is defined as always using ISO-8859-1 encoding, but it is not uncommon to find files tagged with ID3v1 using Windows-1251 or other character sets
|
||||
// Since ID3v1 has no concept of character sets there is no certain way to know we have the correct non-ISO-8859-1 character set, but we can guess
|
||||
foreach ($ParsedID3v1['comments'] as $tag_key => $valuearray) {
|
||||
foreach ($valuearray as $key => $value) {
|
||||
if (preg_match('#^[\\x00-\\x40\\x80-\\xFF]+$#', $value) && !ctype_digit((string) $value)) { // check for strings with only characters above chr(128) and punctuation/numbers, but not just numeric strings (e.g. track numbers or years)
|
||||
foreach (array('Windows-1251', 'KOI8-R') as $id3v1_bad_encoding) {
|
||||
if (function_exists('mb_convert_encoding') && @mb_convert_encoding($value, $id3v1_bad_encoding, $id3v1_bad_encoding) === $value) {
|
||||
$ID3v1encoding = $id3v1_bad_encoding;
|
||||
$this->warning('ID3v1 detected as '.$id3v1_bad_encoding.' text encoding in '.$tag_key);
|
||||
break 3;
|
||||
} elseif (function_exists('iconv') && @iconv($id3v1_bad_encoding, $id3v1_bad_encoding, $value) === $value) {
|
||||
$ID3v1encoding = $id3v1_bad_encoding;
|
||||
$this->warning('ID3v1 detected as '.$id3v1_bad_encoding.' text encoding in '.$tag_key);
|
||||
break 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// ID3v1 encoding detection hack END
|
||||
}
|
||||
|
||||
// ID3v1 data is supposed to be padded with NULL characters, but some taggers pad with spaces
|
||||
$GoodFormatID3v1tag = $this->GenerateID3v1Tag(
|
||||
$ParsedID3v1['title'],
|
||||
$ParsedID3v1['artist'],
|
||||
$ParsedID3v1['album'],
|
||||
$ParsedID3v1['year'],
|
||||
(isset($ParsedID3v1['genre']) ? $this->LookupGenreID($ParsedID3v1['genre']) : false),
|
||||
$ParsedID3v1['comment'],
|
||||
(!empty($ParsedID3v1['track_number']) ? $ParsedID3v1['track_number'] : ''));
|
||||
$ParsedID3v1['padding_valid'] = true;
|
||||
if ($id3v1tag !== $GoodFormatID3v1tag) {
|
||||
$ParsedID3v1['padding_valid'] = false;
|
||||
$this->warning('Some ID3v1 fields do not use NULL characters for padding');
|
||||
}
|
||||
|
||||
$ParsedID3v1['tag_offset_end'] = $info['filesize'];
|
||||
$ParsedID3v1['tag_offset_start'] = $ParsedID3v1['tag_offset_end'] - 128;
|
||||
|
||||
$info['id3v1'] = $ParsedID3v1;
|
||||
$info['id3v1']['encoding'] = $ID3v1encoding;
|
||||
}
|
||||
|
||||
if (substr($preid3v1, 0, 3) == 'TAG') {
|
||||
// The way iTunes handles tags is, well, brain-damaged.
|
||||
// It completely ignores v1 if ID3v2 is present.
|
||||
// This goes as far as adding a new v1 tag *even if there already is one*
|
||||
|
||||
// A suspected double-ID3v1 tag has been detected, but it could be that
|
||||
// the "TAG" identifier is a legitimate part of an APE or Lyrics3 tag
|
||||
if (substr($preid3v1, 96, 8) == 'APETAGEX') {
|
||||
// an APE tag footer was found before the last ID3v1, assume false "TAG" synch
|
||||
} elseif (substr($preid3v1, 119, 6) == 'LYRICS') {
|
||||
// a Lyrics3 tag footer was found before the last ID3v1, assume false "TAG" synch
|
||||
} else {
|
||||
// APE and Lyrics3 footers not found - assume double ID3v1
|
||||
$this->warning('Duplicate ID3v1 tag detected - this has been known to happen with iTunes');
|
||||
$info['avdataend'] -= 128;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $str
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function cutfield($str) {
|
||||
return trim(substr($str, 0, strcspn($str, "\x00")));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $allowSCMPXextended
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public static function ArrayOfGenres($allowSCMPXextended=false) {
|
||||
static $GenreLookup = array(
|
||||
0 => 'Blues',
|
||||
1 => 'Classic Rock',
|
||||
2 => 'Country',
|
||||
3 => 'Dance',
|
||||
4 => 'Disco',
|
||||
5 => 'Funk',
|
||||
6 => 'Grunge',
|
||||
7 => 'Hip-Hop',
|
||||
8 => 'Jazz',
|
||||
9 => 'Metal',
|
||||
10 => 'New Age',
|
||||
11 => 'Oldies',
|
||||
12 => 'Other',
|
||||
13 => 'Pop',
|
||||
14 => 'R&B',
|
||||
15 => 'Rap',
|
||||
16 => 'Reggae',
|
||||
17 => 'Rock',
|
||||
18 => 'Techno',
|
||||
19 => 'Industrial',
|
||||
20 => 'Alternative',
|
||||
21 => 'Ska',
|
||||
22 => 'Death Metal',
|
||||
23 => 'Pranks',
|
||||
24 => 'Soundtrack',
|
||||
25 => 'Euro-Techno',
|
||||
26 => 'Ambient',
|
||||
27 => 'Trip-Hop',
|
||||
28 => 'Vocal',
|
||||
29 => 'Jazz+Funk',
|
||||
30 => 'Fusion',
|
||||
31 => 'Trance',
|
||||
32 => 'Classical',
|
||||
33 => 'Instrumental',
|
||||
34 => 'Acid',
|
||||
35 => 'House',
|
||||
36 => 'Game',
|
||||
37 => 'Sound Clip',
|
||||
38 => 'Gospel',
|
||||
39 => 'Noise',
|
||||
40 => 'Alt. Rock',
|
||||
41 => 'Bass',
|
||||
42 => 'Soul',
|
||||
43 => 'Punk',
|
||||
44 => 'Space',
|
||||
45 => 'Meditative',
|
||||
46 => 'Instrumental Pop',
|
||||
47 => 'Instrumental Rock',
|
||||
48 => 'Ethnic',
|
||||
49 => 'Gothic',
|
||||
50 => 'Darkwave',
|
||||
51 => 'Techno-Industrial',
|
||||
52 => 'Electronic',
|
||||
53 => 'Pop-Folk',
|
||||
54 => 'Eurodance',
|
||||
55 => 'Dream',
|
||||
56 => 'Southern Rock',
|
||||
57 => 'Comedy',
|
||||
58 => 'Cult',
|
||||
59 => 'Gangsta Rap',
|
||||
60 => 'Top 40',
|
||||
61 => 'Christian Rap',
|
||||
62 => 'Pop/Funk',
|
||||
63 => 'Jungle',
|
||||
64 => 'Native American',
|
||||
65 => 'Cabaret',
|
||||
66 => 'New Wave',
|
||||
67 => 'Psychedelic',
|
||||
68 => 'Rave',
|
||||
69 => 'Showtunes',
|
||||
70 => 'Trailer',
|
||||
71 => 'Lo-Fi',
|
||||
72 => 'Tribal',
|
||||
73 => 'Acid Punk',
|
||||
74 => 'Acid Jazz',
|
||||
75 => 'Polka',
|
||||
76 => 'Retro',
|
||||
77 => 'Musical',
|
||||
78 => 'Rock & Roll',
|
||||
79 => 'Hard Rock',
|
||||
80 => 'Folk',
|
||||
81 => 'Folk/Rock',
|
||||
82 => 'National Folk',
|
||||
83 => 'Swing',
|
||||
84 => 'Fast-Fusion',
|
||||
85 => 'Bebob',
|
||||
86 => 'Latin',
|
||||
87 => 'Revival',
|
||||
88 => 'Celtic',
|
||||
89 => 'Bluegrass',
|
||||
90 => 'Avantgarde',
|
||||
91 => 'Gothic Rock',
|
||||
92 => 'Progressive Rock',
|
||||
93 => 'Psychedelic Rock',
|
||||
94 => 'Symphonic Rock',
|
||||
95 => 'Slow Rock',
|
||||
96 => 'Big Band',
|
||||
97 => 'Chorus',
|
||||
98 => 'Easy Listening',
|
||||
99 => 'Acoustic',
|
||||
100 => 'Humour',
|
||||
101 => 'Speech',
|
||||
102 => 'Chanson',
|
||||
103 => 'Opera',
|
||||
104 => 'Chamber Music',
|
||||
105 => 'Sonata',
|
||||
106 => 'Symphony',
|
||||
107 => 'Booty Bass',
|
||||
108 => 'Primus',
|
||||
109 => 'Porn Groove',
|
||||
110 => 'Satire',
|
||||
111 => 'Slow Jam',
|
||||
112 => 'Club',
|
||||
113 => 'Tango',
|
||||
114 => 'Samba',
|
||||
115 => 'Folklore',
|
||||
116 => 'Ballad',
|
||||
117 => 'Power Ballad',
|
||||
118 => 'Rhythmic Soul',
|
||||
119 => 'Freestyle',
|
||||
120 => 'Duet',
|
||||
121 => 'Punk Rock',
|
||||
122 => 'Drum Solo',
|
||||
123 => 'A Cappella',
|
||||
124 => 'Euro-House',
|
||||
125 => 'Dance Hall',
|
||||
126 => 'Goa',
|
||||
127 => 'Drum & Bass',
|
||||
128 => 'Club-House',
|
||||
129 => 'Hardcore',
|
||||
130 => 'Terror',
|
||||
131 => 'Indie',
|
||||
132 => 'BritPop',
|
||||
133 => 'Negerpunk',
|
||||
134 => 'Polsk Punk',
|
||||
135 => 'Beat',
|
||||
136 => 'Christian Gangsta Rap',
|
||||
137 => 'Heavy Metal',
|
||||
138 => 'Black Metal',
|
||||
139 => 'Crossover',
|
||||
140 => 'Contemporary Christian',
|
||||
141 => 'Christian Rock',
|
||||
142 => 'Merengue',
|
||||
143 => 'Salsa',
|
||||
144 => 'Thrash Metal',
|
||||
145 => 'Anime',
|
||||
146 => 'JPop',
|
||||
147 => 'Synthpop',
|
||||
148 => 'Abstract',
|
||||
149 => 'Art Rock',
|
||||
150 => 'Baroque',
|
||||
151 => 'Bhangra',
|
||||
152 => 'Big Beat',
|
||||
153 => 'Breakbeat',
|
||||
154 => 'Chillout',
|
||||
155 => 'Downtempo',
|
||||
156 => 'Dub',
|
||||
157 => 'EBM',
|
||||
158 => 'Eclectic',
|
||||
159 => 'Electro',
|
||||
160 => 'Electroclash',
|
||||
161 => 'Emo',
|
||||
162 => 'Experimental',
|
||||
163 => 'Garage',
|
||||
164 => 'Global',
|
||||
165 => 'IDM',
|
||||
166 => 'Illbient',
|
||||
167 => 'Industro-Goth',
|
||||
168 => 'Jam Band',
|
||||
169 => 'Krautrock',
|
||||
170 => 'Leftfield',
|
||||
171 => 'Lounge',
|
||||
172 => 'Math Rock',
|
||||
173 => 'New Romantic',
|
||||
174 => 'Nu-Breakz',
|
||||
175 => 'Post-Punk',
|
||||
176 => 'Post-Rock',
|
||||
177 => 'Psytrance',
|
||||
178 => 'Shoegaze',
|
||||
179 => 'Space Rock',
|
||||
180 => 'Trop Rock',
|
||||
181 => 'World Music',
|
||||
182 => 'Neoclassical',
|
||||
183 => 'Audiobook',
|
||||
184 => 'Audio Theatre',
|
||||
185 => 'Neue Deutsche Welle',
|
||||
186 => 'Podcast',
|
||||
187 => 'Indie-Rock',
|
||||
188 => 'G-Funk',
|
||||
189 => 'Dubstep',
|
||||
190 => 'Garage Rock',
|
||||
191 => 'Psybient',
|
||||
|
||||
255 => 'Unknown',
|
||||
|
||||
'CR' => 'Cover',
|
||||
'RX' => 'Remix'
|
||||
);
|
||||
|
||||
static $GenreLookupSCMPX = array();
|
||||
if ($allowSCMPXextended && empty($GenreLookupSCMPX)) {
|
||||
$GenreLookupSCMPX = $GenreLookup;
|
||||
// http://www.geocities.co.jp/SiliconValley-Oakland/3664/alittle.html#GenreExtended
|
||||
// Extended ID3v1 genres invented by SCMPX
|
||||
// Note that 255 "Japanese Anime" conflicts with standard "Unknown"
|
||||
$GenreLookupSCMPX[240] = 'Sacred';
|
||||
$GenreLookupSCMPX[241] = 'Northern Europe';
|
||||
$GenreLookupSCMPX[242] = 'Irish & Scottish';
|
||||
$GenreLookupSCMPX[243] = 'Scotland';
|
||||
$GenreLookupSCMPX[244] = 'Ethnic Europe';
|
||||
$GenreLookupSCMPX[245] = 'Enka';
|
||||
$GenreLookupSCMPX[246] = 'Children\'s Song';
|
||||
$GenreLookupSCMPX[247] = 'Japanese Sky';
|
||||
$GenreLookupSCMPX[248] = 'Japanese Heavy Rock';
|
||||
$GenreLookupSCMPX[249] = 'Japanese Doom Rock';
|
||||
$GenreLookupSCMPX[250] = 'Japanese J-POP';
|
||||
$GenreLookupSCMPX[251] = 'Japanese Seiyu';
|
||||
$GenreLookupSCMPX[252] = 'Japanese Ambient Techno';
|
||||
$GenreLookupSCMPX[253] = 'Japanese Moemoe';
|
||||
$GenreLookupSCMPX[254] = 'Japanese Tokusatsu';
|
||||
//$GenreLookupSCMPX[255] = 'Japanese Anime';
|
||||
}
|
||||
|
||||
return ($allowSCMPXextended ? $GenreLookupSCMPX : $GenreLookup);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $genreid
|
||||
* @param bool $allowSCMPXextended
|
||||
*
|
||||
* @return string|false
|
||||
*/
|
||||
public static function LookupGenreName($genreid, $allowSCMPXextended=true) {
|
||||
switch ($genreid) {
|
||||
case 'RX':
|
||||
case 'CR':
|
||||
break;
|
||||
default:
|
||||
if (!is_numeric($genreid)) {
|
||||
return false;
|
||||
}
|
||||
$genreid = intval($genreid); // to handle 3 or '3' or '03'
|
||||
break;
|
||||
}
|
||||
$GenreLookup = self::ArrayOfGenres($allowSCMPXextended);
|
||||
return (isset($GenreLookup[$genreid]) ? $GenreLookup[$genreid] : false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $genre
|
||||
* @param bool $allowSCMPXextended
|
||||
*
|
||||
* @return string|false
|
||||
*/
|
||||
public static function LookupGenreID($genre, $allowSCMPXextended=false) {
|
||||
$GenreLookup = self::ArrayOfGenres($allowSCMPXextended);
|
||||
$LowerCaseNoSpaceSearchTerm = strtolower(str_replace(' ', '', $genre));
|
||||
foreach ($GenreLookup as $key => $value) {
|
||||
if (strtolower(str_replace(' ', '', $value)) == $LowerCaseNoSpaceSearchTerm) {
|
||||
return $key;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $OriginalGenre
|
||||
*
|
||||
* @return string|false
|
||||
*/
|
||||
public static function StandardiseID3v1GenreName($OriginalGenre) {
|
||||
if (($GenreID = self::LookupGenreID($OriginalGenre)) !== false) {
|
||||
return self::LookupGenreName($GenreID);
|
||||
}
|
||||
return $OriginalGenre;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $title
|
||||
* @param string $artist
|
||||
* @param string $album
|
||||
* @param string $year
|
||||
* @param int $genreid
|
||||
* @param string $comment
|
||||
* @param int|string $track
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function GenerateID3v1Tag($title, $artist, $album, $year, $genreid, $comment, $track='') {
|
||||
$ID3v1Tag = 'TAG';
|
||||
$ID3v1Tag .= str_pad(trim(substr($title, 0, 30)), 30, "\x00", STR_PAD_RIGHT);
|
||||
$ID3v1Tag .= str_pad(trim(substr($artist, 0, 30)), 30, "\x00", STR_PAD_RIGHT);
|
||||
$ID3v1Tag .= str_pad(trim(substr($album, 0, 30)), 30, "\x00", STR_PAD_RIGHT);
|
||||
$ID3v1Tag .= str_pad(trim(substr($year, 0, 4)), 4, "\x00", STR_PAD_LEFT);
|
||||
if (!empty($track) && ($track > 0) && ($track <= 255)) {
|
||||
$ID3v1Tag .= str_pad(trim(substr($comment, 0, 28)), 28, "\x00", STR_PAD_RIGHT);
|
||||
$ID3v1Tag .= "\x00";
|
||||
if (gettype($track) == 'string') {
|
||||
$track = (int) $track;
|
||||
}
|
||||
$ID3v1Tag .= chr($track);
|
||||
} else {
|
||||
$ID3v1Tag .= str_pad(trim(substr($comment, 0, 30)), 30, "\x00", STR_PAD_RIGHT);
|
||||
}
|
||||
if (($genreid < 0) || ($genreid > 147)) {
|
||||
$genreid = 255; // 'unknown' genre
|
||||
}
|
||||
switch (gettype($genreid)) {
|
||||
case 'string':
|
||||
case 'integer':
|
||||
$ID3v1Tag .= chr(intval($genreid));
|
||||
break;
|
||||
default:
|
||||
$ID3v1Tag .= chr(255); // 'unknown' genre
|
||||
break;
|
||||
}
|
||||
|
||||
return $ID3v1Tag;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,329 +1,329 @@
|
||||
<?php
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
/// getID3() by James Heinrich <info@getid3.org> //
|
||||
// available at https://github.com/JamesHeinrich/getID3 //
|
||||
// or https://www.getid3.org //
|
||||
// or http://getid3.sourceforge.net //
|
||||
// see readme.txt for more details //
|
||||
/////////////////////////////////////////////////////////////////
|
||||
/// //
|
||||
// module.tag.lyrics3.php //
|
||||
// module for analyzing Lyrics3 tags //
|
||||
// dependencies: module.tag.apetag.php (optional) //
|
||||
// ///
|
||||
/////////////////////////////////////////////////////////////////
|
||||
|
||||
if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers
|
||||
exit;
|
||||
}
|
||||
class getid3_lyrics3 extends getid3_handler
|
||||
{
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function Analyze() {
|
||||
$info = &$this->getid3->info;
|
||||
|
||||
// http://www.volweb.cz/str/tags.htm
|
||||
|
||||
if (!getid3_lib::intValueSupported($info['filesize'])) {
|
||||
$this->warning('Unable to check for Lyrics3 because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB');
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->fseek((0 - 128 - 9 - 6), SEEK_END); // end - ID3v1 - "LYRICSEND" - [Lyrics3size]
|
||||
$lyrics3offset = null;
|
||||
$lyrics3version = null;
|
||||
$lyrics3size = null;
|
||||
$lyrics3_id3v1 = $this->fread(128 + 9 + 6);
|
||||
$lyrics3lsz = (int) substr($lyrics3_id3v1, 0, 6); // Lyrics3size
|
||||
$lyrics3end = substr($lyrics3_id3v1, 6, 9); // LYRICSEND or LYRICS200
|
||||
$id3v1tag = substr($lyrics3_id3v1, 15, 128); // ID3v1
|
||||
|
||||
if ($lyrics3end == 'LYRICSEND') {
|
||||
// Lyrics3v1, ID3v1, no APE
|
||||
|
||||
$lyrics3size = 5100;
|
||||
$lyrics3offset = $info['filesize'] - 128 - $lyrics3size;
|
||||
$lyrics3version = 1;
|
||||
|
||||
} elseif ($lyrics3end == 'LYRICS200') {
|
||||
// Lyrics3v2, ID3v1, no APE
|
||||
|
||||
// LSZ = lyrics + 'LYRICSBEGIN'; add 6-byte size field; add 'LYRICS200'
|
||||
$lyrics3size = $lyrics3lsz + 6 + strlen('LYRICS200');
|
||||
$lyrics3offset = $info['filesize'] - 128 - $lyrics3size;
|
||||
$lyrics3version = 2;
|
||||
|
||||
} elseif (substr(strrev($lyrics3_id3v1), 0, 9) == strrev('LYRICSEND')) {
|
||||
// Lyrics3v1, no ID3v1, no APE
|
||||
|
||||
$lyrics3size = 5100;
|
||||
$lyrics3offset = $info['filesize'] - $lyrics3size;
|
||||
$lyrics3version = 1;
|
||||
$lyrics3offset = $info['filesize'] - $lyrics3size;
|
||||
|
||||
} elseif (substr(strrev($lyrics3_id3v1), 0, 9) == strrev('LYRICS200')) {
|
||||
|
||||
// Lyrics3v2, no ID3v1, no APE
|
||||
|
||||
$lyrics3size = (int) strrev(substr(strrev($lyrics3_id3v1), 9, 6)) + 6 + strlen('LYRICS200'); // LSZ = lyrics + 'LYRICSBEGIN'; add 6-byte size field; add 'LYRICS200'
|
||||
$lyrics3offset = $info['filesize'] - $lyrics3size;
|
||||
$lyrics3version = 2;
|
||||
|
||||
} else {
|
||||
|
||||
if (isset($info['ape']['tag_offset_start']) && ($info['ape']['tag_offset_start'] > 15)) {
|
||||
|
||||
$this->fseek($info['ape']['tag_offset_start'] - 15);
|
||||
$lyrics3lsz = $this->fread(6);
|
||||
$lyrics3end = $this->fread(9);
|
||||
|
||||
if ($lyrics3end == 'LYRICSEND') {
|
||||
// Lyrics3v1, APE, maybe ID3v1
|
||||
|
||||
$lyrics3size = 5100;
|
||||
$lyrics3offset = $info['ape']['tag_offset_start'] - $lyrics3size;
|
||||
$info['avdataend'] = $lyrics3offset;
|
||||
$lyrics3version = 1;
|
||||
$this->warning('APE tag located after Lyrics3, will probably break Lyrics3 compatability');
|
||||
|
||||
} elseif ($lyrics3end == 'LYRICS200') {
|
||||
// Lyrics3v2, APE, maybe ID3v1
|
||||
|
||||
$lyrics3size = $lyrics3lsz + 6 + strlen('LYRICS200'); // LSZ = lyrics + 'LYRICSBEGIN'; add 6-byte size field; add 'LYRICS200'
|
||||
$lyrics3offset = $info['ape']['tag_offset_start'] - $lyrics3size;
|
||||
$lyrics3version = 2;
|
||||
$this->warning('APE tag located after Lyrics3, will probably break Lyrics3 compatability');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (isset($lyrics3offset) && isset($lyrics3version) && isset($lyrics3size)) {
|
||||
$info['avdataend'] = $lyrics3offset;
|
||||
$this->getLyrics3Data($lyrics3offset, $lyrics3version, $lyrics3size);
|
||||
|
||||
if (!isset($info['ape'])) {
|
||||
if (isset($info['lyrics3']['tag_offset_start'])) {
|
||||
$GETID3_ERRORARRAY = &$info['warning'];
|
||||
getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.apetag.php', __FILE__, true);
|
||||
$getid3_temp = new getID3();
|
||||
$getid3_temp->openfile($this->getid3->filename, $this->getid3->info['filesize'], $this->getid3->fp);
|
||||
$getid3_apetag = new getid3_apetag($getid3_temp);
|
||||
$getid3_apetag->overrideendoffset = $info['lyrics3']['tag_offset_start'];
|
||||
$getid3_apetag->Analyze();
|
||||
if (!empty($getid3_temp->info['ape'])) {
|
||||
$info['ape'] = $getid3_temp->info['ape'];
|
||||
}
|
||||
if (!empty($getid3_temp->info['replay_gain'])) {
|
||||
$info['replay_gain'] = $getid3_temp->info['replay_gain'];
|
||||
}
|
||||
unset($getid3_temp, $getid3_apetag);
|
||||
} else {
|
||||
$this->warning('Lyrics3 and APE tags appear to have become entangled (most likely due to updating the APE tags with a non-Lyrics3-aware tagger)');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $endoffset
|
||||
* @param int $version
|
||||
* @param int $length
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getLyrics3Data($endoffset, $version, $length) {
|
||||
// http://www.volweb.cz/str/tags.htm
|
||||
|
||||
$info = &$this->getid3->info;
|
||||
|
||||
if (!getid3_lib::intValueSupported($endoffset)) {
|
||||
$this->warning('Unable to check for Lyrics3 because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB');
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->fseek($endoffset);
|
||||
if ($length <= 0) {
|
||||
return false;
|
||||
}
|
||||
$rawdata = $this->fread($length);
|
||||
|
||||
$ParsedLyrics3 = array();
|
||||
|
||||
$ParsedLyrics3['raw']['lyrics3version'] = $version;
|
||||
$ParsedLyrics3['raw']['lyrics3tagsize'] = $length;
|
||||
$ParsedLyrics3['tag_offset_start'] = $endoffset;
|
||||
$ParsedLyrics3['tag_offset_end'] = $endoffset + $length - 1;
|
||||
|
||||
if (substr($rawdata, 0, 11) != 'LYRICSBEGIN') {
|
||||
if (strpos($rawdata, 'LYRICSBEGIN') !== false) {
|
||||
|
||||
$this->warning('"LYRICSBEGIN" expected at '.$endoffset.' but actually found at '.($endoffset + strpos($rawdata, 'LYRICSBEGIN')).' - this is invalid for Lyrics3 v'.$version);
|
||||
$info['avdataend'] = $endoffset + strpos($rawdata, 'LYRICSBEGIN');
|
||||
$rawdata = substr($rawdata, strpos($rawdata, 'LYRICSBEGIN'));
|
||||
$length = strlen($rawdata);
|
||||
$ParsedLyrics3['tag_offset_start'] = $info['avdataend'];
|
||||
$ParsedLyrics3['raw']['lyrics3tagsize'] = $length;
|
||||
|
||||
} else {
|
||||
|
||||
$this->error('"LYRICSBEGIN" expected at '.$endoffset.' but found "'.substr($rawdata, 0, 11).'" instead');
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
switch ($version) {
|
||||
|
||||
case 1:
|
||||
if (substr($rawdata, strlen($rawdata) - 9, 9) == 'LYRICSEND') {
|
||||
$ParsedLyrics3['raw']['LYR'] = trim(substr($rawdata, 11, strlen($rawdata) - 11 - 9));
|
||||
$this->Lyrics3LyricsTimestampParse($ParsedLyrics3);
|
||||
} else {
|
||||
$this->error('"LYRICSEND" expected at '.($this->ftell() - 11 + $length - 9).' but found "'.substr($rawdata, strlen($rawdata) - 9, 9).'" instead');
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
if (substr($rawdata, strlen($rawdata) - 9, 9) == 'LYRICS200') {
|
||||
$ParsedLyrics3['raw']['unparsed'] = substr($rawdata, 11, strlen($rawdata) - 11 - 9 - 6); // LYRICSBEGIN + LYRICS200 + LSZ
|
||||
$rawdata = $ParsedLyrics3['raw']['unparsed'];
|
||||
while (strlen($rawdata) > 0) {
|
||||
$fieldname = substr($rawdata, 0, 3);
|
||||
$fieldsize = (int) substr($rawdata, 3, 5);
|
||||
$ParsedLyrics3['raw'][$fieldname] = substr($rawdata, 8, $fieldsize);
|
||||
$rawdata = substr($rawdata, 3 + 5 + $fieldsize);
|
||||
}
|
||||
|
||||
if (isset($ParsedLyrics3['raw']['IND'])) {
|
||||
$i = 0;
|
||||
$flagnames = array('lyrics', 'timestamps', 'inhibitrandom');
|
||||
foreach ($flagnames as $flagname) {
|
||||
if (strlen($ParsedLyrics3['raw']['IND']) > $i++) {
|
||||
$ParsedLyrics3['flags'][$flagname] = $this->IntString2Bool(substr($ParsedLyrics3['raw']['IND'], $i, 1 - 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$fieldnametranslation = array('ETT'=>'title', 'EAR'=>'artist', 'EAL'=>'album', 'INF'=>'comment', 'AUT'=>'author');
|
||||
foreach ($fieldnametranslation as $key => $value) {
|
||||
if (isset($ParsedLyrics3['raw'][$key])) {
|
||||
$ParsedLyrics3['comments'][$value][] = trim($ParsedLyrics3['raw'][$key]);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($ParsedLyrics3['raw']['IMG'])) {
|
||||
$imagestrings = explode("\r\n", $ParsedLyrics3['raw']['IMG']);
|
||||
foreach ($imagestrings as $key => $imagestring) {
|
||||
if (strpos($imagestring, '||') !== false) {
|
||||
$imagearray = explode('||', $imagestring);
|
||||
$ParsedLyrics3['images'][$key]['filename'] = (isset($imagearray[0]) ? $imagearray[0] : '');
|
||||
$ParsedLyrics3['images'][$key]['description'] = (isset($imagearray[1]) ? $imagearray[1] : '');
|
||||
$ParsedLyrics3['images'][$key]['timestamp'] = $this->Lyrics3Timestamp2Seconds(isset($imagearray[2]) ? $imagearray[2] : '');
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($ParsedLyrics3['raw']['LYR'])) {
|
||||
$this->Lyrics3LyricsTimestampParse($ParsedLyrics3);
|
||||
}
|
||||
} else {
|
||||
$this->error('"LYRICS200" expected at '.($this->ftell() - 11 + $length - 9).' but found "'.substr($rawdata, strlen($rawdata) - 9, 9).'" instead');
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
$this->error('Cannot process Lyrics3 version '.$version.' (only v1 and v2)');
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (isset($info['id3v1']['tag_offset_start']) && ($info['id3v1']['tag_offset_start'] <= $ParsedLyrics3['tag_offset_end'])) {
|
||||
$this->warning('ID3v1 tag information ignored since it appears to be a false synch in Lyrics3 tag data');
|
||||
unset($info['id3v1']);
|
||||
foreach ($info['warning'] as $key => $value) {
|
||||
if ($value == 'Some ID3v1 fields do not use NULL characters for padding') {
|
||||
unset($info['warning'][$key]);
|
||||
sort($info['warning']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$info['lyrics3'] = $ParsedLyrics3;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $rawtimestamp
|
||||
*
|
||||
* @return int|false
|
||||
*/
|
||||
public function Lyrics3Timestamp2Seconds($rawtimestamp) {
|
||||
if (preg_match('#^\\[([0-9]{2}):([0-9]{2})\\]$#', $rawtimestamp, $regs)) {
|
||||
return (int) (($regs[1] * 60) + $regs[2]);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $Lyrics3data
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function Lyrics3LyricsTimestampParse(&$Lyrics3data) {
|
||||
$lyricsarray = explode("\r\n", $Lyrics3data['raw']['LYR']);
|
||||
$notimestamplyricsarray = array();
|
||||
foreach ($lyricsarray as $key => $lyricline) {
|
||||
$regs = array();
|
||||
unset($thislinetimestamps);
|
||||
while (preg_match('#^(\\[[0-9]{2}:[0-9]{2}\\])#', $lyricline, $regs)) {
|
||||
$thislinetimestamps[] = $this->Lyrics3Timestamp2Seconds($regs[0]);
|
||||
$lyricline = str_replace($regs[0], '', $lyricline);
|
||||
}
|
||||
$notimestamplyricsarray[$key] = $lyricline;
|
||||
if (isset($thislinetimestamps) && is_array($thislinetimestamps)) {
|
||||
sort($thislinetimestamps);
|
||||
foreach ($thislinetimestamps as $timestampkey => $timestamp) {
|
||||
if (isset($Lyrics3data['synchedlyrics'][$timestamp])) {
|
||||
// timestamps only have a 1-second resolution, it's possible that multiple lines
|
||||
// could have the same timestamp, if so, append
|
||||
$Lyrics3data['synchedlyrics'][$timestamp] .= "\r\n".$lyricline;
|
||||
} else {
|
||||
$Lyrics3data['synchedlyrics'][$timestamp] = $lyricline;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$Lyrics3data['unsynchedlyrics'] = implode("\r\n", $notimestamplyricsarray);
|
||||
if (isset($Lyrics3data['synchedlyrics']) && is_array($Lyrics3data['synchedlyrics'])) {
|
||||
ksort($Lyrics3data['synchedlyrics']);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $char
|
||||
*
|
||||
* @return bool|null
|
||||
*/
|
||||
public function IntString2Bool($char) {
|
||||
if ($char == '1') {
|
||||
return true;
|
||||
} elseif ($char == '0') {
|
||||
return false;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
<?php
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
/// getID3() by James Heinrich <info@getid3.org> //
|
||||
// available at https://github.com/JamesHeinrich/getID3 //
|
||||
// or https://www.getid3.org //
|
||||
// or http://getid3.sourceforge.net //
|
||||
// see readme.txt for more details //
|
||||
/////////////////////////////////////////////////////////////////
|
||||
/// //
|
||||
// module.tag.lyrics3.php //
|
||||
// module for analyzing Lyrics3 tags //
|
||||
// dependencies: module.tag.apetag.php (optional) //
|
||||
// ///
|
||||
/////////////////////////////////////////////////////////////////
|
||||
|
||||
if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers
|
||||
exit;
|
||||
}
|
||||
class getid3_lyrics3 extends getid3_handler
|
||||
{
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function Analyze() {
|
||||
$info = &$this->getid3->info;
|
||||
|
||||
// http://www.volweb.cz/str/tags.htm
|
||||
|
||||
if (!getid3_lib::intValueSupported($info['filesize'])) {
|
||||
$this->warning('Unable to check for Lyrics3 because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB');
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->fseek((0 - 128 - 9 - 6), SEEK_END); // end - ID3v1 - "LYRICSEND" - [Lyrics3size]
|
||||
$lyrics3offset = null;
|
||||
$lyrics3version = null;
|
||||
$lyrics3size = null;
|
||||
$lyrics3_id3v1 = $this->fread(128 + 9 + 6);
|
||||
$lyrics3lsz = (int) substr($lyrics3_id3v1, 0, 6); // Lyrics3size
|
||||
$lyrics3end = substr($lyrics3_id3v1, 6, 9); // LYRICSEND or LYRICS200
|
||||
$id3v1tag = substr($lyrics3_id3v1, 15, 128); // ID3v1
|
||||
|
||||
if ($lyrics3end == 'LYRICSEND') {
|
||||
// Lyrics3v1, ID3v1, no APE
|
||||
|
||||
$lyrics3size = 5100;
|
||||
$lyrics3offset = $info['filesize'] - 128 - $lyrics3size;
|
||||
$lyrics3version = 1;
|
||||
|
||||
} elseif ($lyrics3end == 'LYRICS200') {
|
||||
// Lyrics3v2, ID3v1, no APE
|
||||
|
||||
// LSZ = lyrics + 'LYRICSBEGIN'; add 6-byte size field; add 'LYRICS200'
|
||||
$lyrics3size = $lyrics3lsz + 6 + strlen('LYRICS200');
|
||||
$lyrics3offset = $info['filesize'] - 128 - $lyrics3size;
|
||||
$lyrics3version = 2;
|
||||
|
||||
} elseif (substr(strrev($lyrics3_id3v1), 0, 9) == strrev('LYRICSEND')) {
|
||||
// Lyrics3v1, no ID3v1, no APE
|
||||
|
||||
$lyrics3size = 5100;
|
||||
$lyrics3offset = $info['filesize'] - $lyrics3size;
|
||||
$lyrics3version = 1;
|
||||
$lyrics3offset = $info['filesize'] - $lyrics3size;
|
||||
|
||||
} elseif (substr(strrev($lyrics3_id3v1), 0, 9) == strrev('LYRICS200')) {
|
||||
|
||||
// Lyrics3v2, no ID3v1, no APE
|
||||
|
||||
$lyrics3size = (int) strrev(substr(strrev($lyrics3_id3v1), 9, 6)) + 6 + strlen('LYRICS200'); // LSZ = lyrics + 'LYRICSBEGIN'; add 6-byte size field; add 'LYRICS200'
|
||||
$lyrics3offset = $info['filesize'] - $lyrics3size;
|
||||
$lyrics3version = 2;
|
||||
|
||||
} else {
|
||||
|
||||
if (isset($info['ape']['tag_offset_start']) && ($info['ape']['tag_offset_start'] > 15)) {
|
||||
|
||||
$this->fseek($info['ape']['tag_offset_start'] - 15);
|
||||
$lyrics3lsz = $this->fread(6);
|
||||
$lyrics3end = $this->fread(9);
|
||||
|
||||
if ($lyrics3end == 'LYRICSEND') {
|
||||
// Lyrics3v1, APE, maybe ID3v1
|
||||
|
||||
$lyrics3size = 5100;
|
||||
$lyrics3offset = $info['ape']['tag_offset_start'] - $lyrics3size;
|
||||
$info['avdataend'] = $lyrics3offset;
|
||||
$lyrics3version = 1;
|
||||
$this->warning('APE tag located after Lyrics3, will probably break Lyrics3 compatability');
|
||||
|
||||
} elseif ($lyrics3end == 'LYRICS200') {
|
||||
// Lyrics3v2, APE, maybe ID3v1
|
||||
|
||||
$lyrics3size = $lyrics3lsz + 6 + strlen('LYRICS200'); // LSZ = lyrics + 'LYRICSBEGIN'; add 6-byte size field; add 'LYRICS200'
|
||||
$lyrics3offset = $info['ape']['tag_offset_start'] - $lyrics3size;
|
||||
$lyrics3version = 2;
|
||||
$this->warning('APE tag located after Lyrics3, will probably break Lyrics3 compatability');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (isset($lyrics3offset) && isset($lyrics3version) && isset($lyrics3size)) {
|
||||
$info['avdataend'] = $lyrics3offset;
|
||||
$this->getLyrics3Data($lyrics3offset, $lyrics3version, $lyrics3size);
|
||||
|
||||
if (!isset($info['ape'])) {
|
||||
if (isset($info['lyrics3']['tag_offset_start'])) {
|
||||
$GETID3_ERRORARRAY = &$info['warning'];
|
||||
getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.apetag.php', __FILE__, true);
|
||||
$getid3_temp = new getID3();
|
||||
$getid3_temp->openfile($this->getid3->filename, $this->getid3->info['filesize'], $this->getid3->fp);
|
||||
$getid3_apetag = new getid3_apetag($getid3_temp);
|
||||
$getid3_apetag->overrideendoffset = $info['lyrics3']['tag_offset_start'];
|
||||
$getid3_apetag->Analyze();
|
||||
if (!empty($getid3_temp->info['ape'])) {
|
||||
$info['ape'] = $getid3_temp->info['ape'];
|
||||
}
|
||||
if (!empty($getid3_temp->info['replay_gain'])) {
|
||||
$info['replay_gain'] = $getid3_temp->info['replay_gain'];
|
||||
}
|
||||
unset($getid3_temp, $getid3_apetag);
|
||||
} else {
|
||||
$this->warning('Lyrics3 and APE tags appear to have become entangled (most likely due to updating the APE tags with a non-Lyrics3-aware tagger)');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $endoffset
|
||||
* @param int $version
|
||||
* @param int $length
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getLyrics3Data($endoffset, $version, $length) {
|
||||
// http://www.volweb.cz/str/tags.htm
|
||||
|
||||
$info = &$this->getid3->info;
|
||||
|
||||
if (!getid3_lib::intValueSupported($endoffset)) {
|
||||
$this->warning('Unable to check for Lyrics3 because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB');
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->fseek($endoffset);
|
||||
if ($length <= 0) {
|
||||
return false;
|
||||
}
|
||||
$rawdata = $this->fread($length);
|
||||
|
||||
$ParsedLyrics3 = array();
|
||||
|
||||
$ParsedLyrics3['raw']['lyrics3version'] = $version;
|
||||
$ParsedLyrics3['raw']['lyrics3tagsize'] = $length;
|
||||
$ParsedLyrics3['tag_offset_start'] = $endoffset;
|
||||
$ParsedLyrics3['tag_offset_end'] = $endoffset + $length - 1;
|
||||
|
||||
if (substr($rawdata, 0, 11) != 'LYRICSBEGIN') {
|
||||
if (strpos($rawdata, 'LYRICSBEGIN') !== false) {
|
||||
|
||||
$this->warning('"LYRICSBEGIN" expected at '.$endoffset.' but actually found at '.($endoffset + strpos($rawdata, 'LYRICSBEGIN')).' - this is invalid for Lyrics3 v'.$version);
|
||||
$info['avdataend'] = $endoffset + strpos($rawdata, 'LYRICSBEGIN');
|
||||
$rawdata = substr($rawdata, strpos($rawdata, 'LYRICSBEGIN'));
|
||||
$length = strlen($rawdata);
|
||||
$ParsedLyrics3['tag_offset_start'] = $info['avdataend'];
|
||||
$ParsedLyrics3['raw']['lyrics3tagsize'] = $length;
|
||||
|
||||
} else {
|
||||
|
||||
$this->error('"LYRICSBEGIN" expected at '.$endoffset.' but found "'.substr($rawdata, 0, 11).'" instead');
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
switch ($version) {
|
||||
|
||||
case 1:
|
||||
if (substr($rawdata, strlen($rawdata) - 9, 9) == 'LYRICSEND') {
|
||||
$ParsedLyrics3['raw']['LYR'] = trim(substr($rawdata, 11, strlen($rawdata) - 11 - 9));
|
||||
$this->Lyrics3LyricsTimestampParse($ParsedLyrics3);
|
||||
} else {
|
||||
$this->error('"LYRICSEND" expected at '.($this->ftell() - 11 + $length - 9).' but found "'.substr($rawdata, strlen($rawdata) - 9, 9).'" instead');
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
if (substr($rawdata, strlen($rawdata) - 9, 9) == 'LYRICS200') {
|
||||
$ParsedLyrics3['raw']['unparsed'] = substr($rawdata, 11, strlen($rawdata) - 11 - 9 - 6); // LYRICSBEGIN + LYRICS200 + LSZ
|
||||
$rawdata = $ParsedLyrics3['raw']['unparsed'];
|
||||
while (strlen($rawdata) > 0) {
|
||||
$fieldname = substr($rawdata, 0, 3);
|
||||
$fieldsize = (int) substr($rawdata, 3, 5);
|
||||
$ParsedLyrics3['raw'][$fieldname] = substr($rawdata, 8, $fieldsize);
|
||||
$rawdata = substr($rawdata, 3 + 5 + $fieldsize);
|
||||
}
|
||||
|
||||
if (isset($ParsedLyrics3['raw']['IND'])) {
|
||||
$i = 0;
|
||||
$flagnames = array('lyrics', 'timestamps', 'inhibitrandom');
|
||||
foreach ($flagnames as $flagname) {
|
||||
if (strlen($ParsedLyrics3['raw']['IND']) > $i++) {
|
||||
$ParsedLyrics3['flags'][$flagname] = $this->IntString2Bool(substr($ParsedLyrics3['raw']['IND'], $i, 1 - 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$fieldnametranslation = array('ETT'=>'title', 'EAR'=>'artist', 'EAL'=>'album', 'INF'=>'comment', 'AUT'=>'author');
|
||||
foreach ($fieldnametranslation as $key => $value) {
|
||||
if (isset($ParsedLyrics3['raw'][$key])) {
|
||||
$ParsedLyrics3['comments'][$value][] = trim($ParsedLyrics3['raw'][$key]);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($ParsedLyrics3['raw']['IMG'])) {
|
||||
$imagestrings = explode("\r\n", $ParsedLyrics3['raw']['IMG']);
|
||||
foreach ($imagestrings as $key => $imagestring) {
|
||||
if (strpos($imagestring, '||') !== false) {
|
||||
$imagearray = explode('||', $imagestring);
|
||||
$ParsedLyrics3['images'][$key]['filename'] = (isset($imagearray[0]) ? $imagearray[0] : '');
|
||||
$ParsedLyrics3['images'][$key]['description'] = (isset($imagearray[1]) ? $imagearray[1] : '');
|
||||
$ParsedLyrics3['images'][$key]['timestamp'] = $this->Lyrics3Timestamp2Seconds(isset($imagearray[2]) ? $imagearray[2] : '');
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($ParsedLyrics3['raw']['LYR'])) {
|
||||
$this->Lyrics3LyricsTimestampParse($ParsedLyrics3);
|
||||
}
|
||||
} else {
|
||||
$this->error('"LYRICS200" expected at '.($this->ftell() - 11 + $length - 9).' but found "'.substr($rawdata, strlen($rawdata) - 9, 9).'" instead');
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
$this->error('Cannot process Lyrics3 version '.$version.' (only v1 and v2)');
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (isset($info['id3v1']['tag_offset_start']) && ($info['id3v1']['tag_offset_start'] <= $ParsedLyrics3['tag_offset_end'])) {
|
||||
$this->warning('ID3v1 tag information ignored since it appears to be a false synch in Lyrics3 tag data');
|
||||
unset($info['id3v1']);
|
||||
foreach ($info['warning'] as $key => $value) {
|
||||
if ($value == 'Some ID3v1 fields do not use NULL characters for padding') {
|
||||
unset($info['warning'][$key]);
|
||||
sort($info['warning']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$info['lyrics3'] = $ParsedLyrics3;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $rawtimestamp
|
||||
*
|
||||
* @return int|false
|
||||
*/
|
||||
public function Lyrics3Timestamp2Seconds($rawtimestamp) {
|
||||
if (preg_match('#^\\[([0-9]{2}):([0-9]{2})\\]$#', $rawtimestamp, $regs)) {
|
||||
return (int) (($regs[1] * 60) + $regs[2]);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $Lyrics3data
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function Lyrics3LyricsTimestampParse(&$Lyrics3data) {
|
||||
$lyricsarray = explode("\r\n", $Lyrics3data['raw']['LYR']);
|
||||
$notimestamplyricsarray = array();
|
||||
foreach ($lyricsarray as $key => $lyricline) {
|
||||
$regs = array();
|
||||
unset($thislinetimestamps);
|
||||
while (preg_match('#^(\\[[0-9]{2}:[0-9]{2}\\])#', $lyricline, $regs)) {
|
||||
$thislinetimestamps[] = $this->Lyrics3Timestamp2Seconds($regs[0]);
|
||||
$lyricline = str_replace($regs[0], '', $lyricline);
|
||||
}
|
||||
$notimestamplyricsarray[$key] = $lyricline;
|
||||
if (isset($thislinetimestamps) && is_array($thislinetimestamps)) {
|
||||
sort($thislinetimestamps);
|
||||
foreach ($thislinetimestamps as $timestampkey => $timestamp) {
|
||||
if (isset($Lyrics3data['synchedlyrics'][$timestamp])) {
|
||||
// timestamps only have a 1-second resolution, it's possible that multiple lines
|
||||
// could have the same timestamp, if so, append
|
||||
$Lyrics3data['synchedlyrics'][$timestamp] .= "\r\n".$lyricline;
|
||||
} else {
|
||||
$Lyrics3data['synchedlyrics'][$timestamp] = $lyricline;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$Lyrics3data['unsynchedlyrics'] = implode("\r\n", $notimestamplyricsarray);
|
||||
if (isset($Lyrics3data['synchedlyrics']) && is_array($Lyrics3data['synchedlyrics'])) {
|
||||
ksort($Lyrics3data['synchedlyrics']);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $char
|
||||
*
|
||||
* @return bool|null
|
||||
*/
|
||||
public function IntString2Bool($char) {
|
||||
if ($char == '1') {
|
||||
return true;
|
||||
} elseif ($char == '0') {
|
||||
return false;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,32 +1,32 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* IXR_Base64
|
||||
*
|
||||
* @package IXR
|
||||
* @since 1.5.0
|
||||
*/
|
||||
class IXR_Base64
|
||||
{
|
||||
var $data;
|
||||
|
||||
/**
|
||||
* PHP5 constructor.
|
||||
*/
|
||||
function __construct( $data )
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* PHP4 constructor.
|
||||
*/
|
||||
public function IXR_Base64( $data ) {
|
||||
self::__construct( $data );
|
||||
}
|
||||
|
||||
function getXml()
|
||||
{
|
||||
return '<base64>'.base64_encode($this->data).'</base64>';
|
||||
}
|
||||
}
|
||||
<?php
|
||||
|
||||
/**
|
||||
* IXR_Base64
|
||||
*
|
||||
* @package IXR
|
||||
* @since 1.5.0
|
||||
*/
|
||||
class IXR_Base64
|
||||
{
|
||||
var $data;
|
||||
|
||||
/**
|
||||
* PHP5 constructor.
|
||||
*/
|
||||
function __construct( $data )
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* PHP4 constructor.
|
||||
*/
|
||||
public function IXR_Base64( $data ) {
|
||||
self::__construct( $data );
|
||||
}
|
||||
|
||||
function getXml()
|
||||
{
|
||||
return '<base64>'.base64_encode($this->data).'</base64>';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,172 +1,172 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* IXR_Client
|
||||
*
|
||||
* @package IXR
|
||||
* @since 1.5.0
|
||||
*
|
||||
*/
|
||||
class IXR_Client
|
||||
{
|
||||
var $server;
|
||||
var $port;
|
||||
var $path;
|
||||
var $useragent;
|
||||
var $response;
|
||||
var $message = false;
|
||||
var $debug = false;
|
||||
var $timeout;
|
||||
var $headers = array();
|
||||
|
||||
// Storage place for an error message
|
||||
var $error = false;
|
||||
|
||||
/**
|
||||
* PHP5 constructor.
|
||||
*/
|
||||
function __construct( $server, $path = false, $port = 80, $timeout = 15 )
|
||||
{
|
||||
if (!$path) {
|
||||
// Assume we have been given a URL instead
|
||||
$bits = parse_url($server);
|
||||
$this->server = $bits['host'];
|
||||
$this->port = isset($bits['port']) ? $bits['port'] : 80;
|
||||
$this->path = isset($bits['path']) ? $bits['path'] : '/';
|
||||
|
||||
// Make absolutely sure we have a path
|
||||
if (!$this->path) {
|
||||
$this->path = '/';
|
||||
}
|
||||
|
||||
if ( ! empty( $bits['query'] ) ) {
|
||||
$this->path .= '?' . $bits['query'];
|
||||
}
|
||||
} else {
|
||||
$this->server = $server;
|
||||
$this->path = $path;
|
||||
$this->port = $port;
|
||||
}
|
||||
$this->useragent = 'The Incutio XML-RPC PHP Library';
|
||||
$this->timeout = $timeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* PHP4 constructor.
|
||||
*/
|
||||
public function IXR_Client( $server, $path = false, $port = 80, $timeout = 15 ) {
|
||||
self::__construct( $server, $path, $port, $timeout );
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 1.5.0
|
||||
* @since 5.5.0 Formalized the existing `...$args` parameter by adding it
|
||||
* to the function signature.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function query( ...$args )
|
||||
{
|
||||
$method = array_shift($args);
|
||||
$request = new IXR_Request($method, $args);
|
||||
$length = $request->getLength();
|
||||
$xml = $request->getXml();
|
||||
$r = "\r\n";
|
||||
$request = "POST {$this->path} HTTP/1.0$r";
|
||||
|
||||
// Merged from WP #8145 - allow custom headers
|
||||
$this->headers['Host'] = $this->server;
|
||||
$this->headers['Content-Type'] = 'text/xml';
|
||||
$this->headers['User-Agent'] = $this->useragent;
|
||||
$this->headers['Content-Length']= $length;
|
||||
|
||||
foreach( $this->headers as $header => $value ) {
|
||||
$request .= "{$header}: {$value}{$r}";
|
||||
}
|
||||
$request .= $r;
|
||||
|
||||
$request .= $xml;
|
||||
|
||||
// Now send the request
|
||||
if ($this->debug) {
|
||||
echo '<pre class="ixr_request">'.htmlspecialchars($request)."\n</pre>\n\n";
|
||||
}
|
||||
|
||||
if ($this->timeout) {
|
||||
$fp = @fsockopen($this->server, $this->port, $errno, $errstr, $this->timeout);
|
||||
} else {
|
||||
$fp = @fsockopen($this->server, $this->port, $errno, $errstr);
|
||||
}
|
||||
if (!$fp) {
|
||||
$this->error = new IXR_Error(-32300, 'transport error - could not open socket');
|
||||
return false;
|
||||
}
|
||||
fputs($fp, $request);
|
||||
$contents = '';
|
||||
$debugContents = '';
|
||||
$gotFirstLine = false;
|
||||
$gettingHeaders = true;
|
||||
while (!feof($fp)) {
|
||||
$line = fgets($fp, 4096);
|
||||
if (!$gotFirstLine) {
|
||||
// Check line for '200'
|
||||
if (strstr($line, '200') === false) {
|
||||
$this->error = new IXR_Error(-32300, 'transport error - HTTP status code was not 200');
|
||||
return false;
|
||||
}
|
||||
$gotFirstLine = true;
|
||||
}
|
||||
if (trim($line) == '') {
|
||||
$gettingHeaders = false;
|
||||
}
|
||||
if (!$gettingHeaders) {
|
||||
// merged from WP #12559 - remove trim
|
||||
$contents .= $line;
|
||||
}
|
||||
if ($this->debug) {
|
||||
$debugContents .= $line;
|
||||
}
|
||||
}
|
||||
if ($this->debug) {
|
||||
echo '<pre class="ixr_response">'.htmlspecialchars($debugContents)."\n</pre>\n\n";
|
||||
}
|
||||
|
||||
// Now parse what we've got back
|
||||
$this->message = new IXR_Message($contents);
|
||||
if (!$this->message->parse()) {
|
||||
// XML error
|
||||
$this->error = new IXR_Error(-32700, 'parse error. not well formed');
|
||||
return false;
|
||||
}
|
||||
|
||||
// Is the message a fault?
|
||||
if ($this->message->messageType == 'fault') {
|
||||
$this->error = new IXR_Error($this->message->faultCode, $this->message->faultString);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Message must be OK
|
||||
return true;
|
||||
}
|
||||
|
||||
function getResponse()
|
||||
{
|
||||
// methodResponses can only have one param - return that
|
||||
return $this->message->params[0];
|
||||
}
|
||||
|
||||
function isError()
|
||||
{
|
||||
return (is_object($this->error));
|
||||
}
|
||||
|
||||
function getErrorCode()
|
||||
{
|
||||
return $this->error->code;
|
||||
}
|
||||
|
||||
function getErrorMessage()
|
||||
{
|
||||
return $this->error->message;
|
||||
}
|
||||
}
|
||||
<?php
|
||||
|
||||
/**
|
||||
* IXR_Client
|
||||
*
|
||||
* @package IXR
|
||||
* @since 1.5.0
|
||||
*
|
||||
*/
|
||||
class IXR_Client
|
||||
{
|
||||
var $server;
|
||||
var $port;
|
||||
var $path;
|
||||
var $useragent;
|
||||
var $response;
|
||||
var $message = false;
|
||||
var $debug = false;
|
||||
var $timeout;
|
||||
var $headers = array();
|
||||
|
||||
// Storage place for an error message
|
||||
var $error = false;
|
||||
|
||||
/**
|
||||
* PHP5 constructor.
|
||||
*/
|
||||
function __construct( $server, $path = false, $port = 80, $timeout = 15 )
|
||||
{
|
||||
if (!$path) {
|
||||
// Assume we have been given a URL instead
|
||||
$bits = parse_url($server);
|
||||
$this->server = $bits['host'];
|
||||
$this->port = isset($bits['port']) ? $bits['port'] : 80;
|
||||
$this->path = isset($bits['path']) ? $bits['path'] : '/';
|
||||
|
||||
// Make absolutely sure we have a path
|
||||
if (!$this->path) {
|
||||
$this->path = '/';
|
||||
}
|
||||
|
||||
if ( ! empty( $bits['query'] ) ) {
|
||||
$this->path .= '?' . $bits['query'];
|
||||
}
|
||||
} else {
|
||||
$this->server = $server;
|
||||
$this->path = $path;
|
||||
$this->port = $port;
|
||||
}
|
||||
$this->useragent = 'The Incutio XML-RPC PHP Library';
|
||||
$this->timeout = $timeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* PHP4 constructor.
|
||||
*/
|
||||
public function IXR_Client( $server, $path = false, $port = 80, $timeout = 15 ) {
|
||||
self::__construct( $server, $path, $port, $timeout );
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 1.5.0
|
||||
* @since 5.5.0 Formalized the existing `...$args` parameter by adding it
|
||||
* to the function signature.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function query( ...$args )
|
||||
{
|
||||
$method = array_shift($args);
|
||||
$request = new IXR_Request($method, $args);
|
||||
$length = $request->getLength();
|
||||
$xml = $request->getXml();
|
||||
$r = "\r\n";
|
||||
$request = "POST {$this->path} HTTP/1.0$r";
|
||||
|
||||
// Merged from WP #8145 - allow custom headers
|
||||
$this->headers['Host'] = $this->server;
|
||||
$this->headers['Content-Type'] = 'text/xml';
|
||||
$this->headers['User-Agent'] = $this->useragent;
|
||||
$this->headers['Content-Length']= $length;
|
||||
|
||||
foreach( $this->headers as $header => $value ) {
|
||||
$request .= "{$header}: {$value}{$r}";
|
||||
}
|
||||
$request .= $r;
|
||||
|
||||
$request .= $xml;
|
||||
|
||||
// Now send the request
|
||||
if ($this->debug) {
|
||||
echo '<pre class="ixr_request">'.htmlspecialchars($request)."\n</pre>\n\n";
|
||||
}
|
||||
|
||||
if ($this->timeout) {
|
||||
$fp = @fsockopen($this->server, $this->port, $errno, $errstr, $this->timeout);
|
||||
} else {
|
||||
$fp = @fsockopen($this->server, $this->port, $errno, $errstr);
|
||||
}
|
||||
if (!$fp) {
|
||||
$this->error = new IXR_Error(-32300, 'transport error - could not open socket');
|
||||
return false;
|
||||
}
|
||||
fputs($fp, $request);
|
||||
$contents = '';
|
||||
$debugContents = '';
|
||||
$gotFirstLine = false;
|
||||
$gettingHeaders = true;
|
||||
while (!feof($fp)) {
|
||||
$line = fgets($fp, 4096);
|
||||
if (!$gotFirstLine) {
|
||||
// Check line for '200'
|
||||
if (strstr($line, '200') === false) {
|
||||
$this->error = new IXR_Error(-32300, 'transport error - HTTP status code was not 200');
|
||||
return false;
|
||||
}
|
||||
$gotFirstLine = true;
|
||||
}
|
||||
if (trim($line) == '') {
|
||||
$gettingHeaders = false;
|
||||
}
|
||||
if (!$gettingHeaders) {
|
||||
// merged from WP #12559 - remove trim
|
||||
$contents .= $line;
|
||||
}
|
||||
if ($this->debug) {
|
||||
$debugContents .= $line;
|
||||
}
|
||||
}
|
||||
if ($this->debug) {
|
||||
echo '<pre class="ixr_response">'.htmlspecialchars($debugContents)."\n</pre>\n\n";
|
||||
}
|
||||
|
||||
// Now parse what we've got back
|
||||
$this->message = new IXR_Message($contents);
|
||||
if (!$this->message->parse()) {
|
||||
// XML error
|
||||
$this->error = new IXR_Error(-32700, 'parse error. not well formed');
|
||||
return false;
|
||||
}
|
||||
|
||||
// Is the message a fault?
|
||||
if ($this->message->messageType == 'fault') {
|
||||
$this->error = new IXR_Error($this->message->faultCode, $this->message->faultString);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Message must be OK
|
||||
return true;
|
||||
}
|
||||
|
||||
function getResponse()
|
||||
{
|
||||
// methodResponses can only have one param - return that
|
||||
return $this->message->params[0];
|
||||
}
|
||||
|
||||
function isError()
|
||||
{
|
||||
return (is_object($this->error));
|
||||
}
|
||||
|
||||
function getErrorCode()
|
||||
{
|
||||
return $this->error->code;
|
||||
}
|
||||
|
||||
function getErrorMessage()
|
||||
{
|
||||
return $this->error->message;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,55 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* IXR_ClientMulticall
|
||||
*
|
||||
* @package IXR
|
||||
* @since 1.5.0
|
||||
*/
|
||||
class IXR_ClientMulticall extends IXR_Client
|
||||
{
|
||||
var $calls = array();
|
||||
|
||||
/**
|
||||
* PHP5 constructor.
|
||||
*/
|
||||
function __construct( $server, $path = false, $port = 80 )
|
||||
{
|
||||
parent::IXR_Client($server, $path, $port);
|
||||
$this->useragent = 'The Incutio XML-RPC PHP Library (multicall client)';
|
||||
}
|
||||
|
||||
/**
|
||||
* PHP4 constructor.
|
||||
*/
|
||||
public function IXR_ClientMulticall( $server, $path = false, $port = 80 ) {
|
||||
self::__construct( $server, $path, $port );
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 1.5.0
|
||||
* @since 5.5.0 Formalized the existing `...$args` parameter by adding it
|
||||
* to the function signature.
|
||||
*/
|
||||
function addCall( ...$args )
|
||||
{
|
||||
$methodName = array_shift($args);
|
||||
$struct = array(
|
||||
'methodName' => $methodName,
|
||||
'params' => $args
|
||||
);
|
||||
$this->calls[] = $struct;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 1.5.0
|
||||
* @since 5.5.0 Formalized the existing `...$args` parameter by adding it
|
||||
* to the function signature.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function query( ...$args )
|
||||
{
|
||||
// Prepare multicall, then call the parent::query() method
|
||||
return parent::query('system.multicall', $this->calls);
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* IXR_ClientMulticall
|
||||
*
|
||||
* @package IXR
|
||||
* @since 1.5.0
|
||||
*/
|
||||
class IXR_ClientMulticall extends IXR_Client
|
||||
{
|
||||
var $calls = array();
|
||||
|
||||
/**
|
||||
* PHP5 constructor.
|
||||
*/
|
||||
function __construct( $server, $path = false, $port = 80 )
|
||||
{
|
||||
parent::IXR_Client($server, $path, $port);
|
||||
$this->useragent = 'The Incutio XML-RPC PHP Library (multicall client)';
|
||||
}
|
||||
|
||||
/**
|
||||
* PHP4 constructor.
|
||||
*/
|
||||
public function IXR_ClientMulticall( $server, $path = false, $port = 80 ) {
|
||||
self::__construct( $server, $path, $port );
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 1.5.0
|
||||
* @since 5.5.0 Formalized the existing `...$args` parameter by adding it
|
||||
* to the function signature.
|
||||
*/
|
||||
function addCall( ...$args )
|
||||
{
|
||||
$methodName = array_shift($args);
|
||||
$struct = array(
|
||||
'methodName' => $methodName,
|
||||
'params' => $args
|
||||
);
|
||||
$this->calls[] = $struct;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 1.5.0
|
||||
* @since 5.5.0 Formalized the existing `...$args` parameter by adding it
|
||||
* to the function signature.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function query( ...$args )
|
||||
{
|
||||
// Prepare multicall, then call the parent::query() method
|
||||
return parent::query('system.multicall', $this->calls);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,74 +1,74 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* IXR_Date
|
||||
*
|
||||
* @package IXR
|
||||
* @since 1.5.0
|
||||
*/
|
||||
class IXR_Date {
|
||||
var $year;
|
||||
var $month;
|
||||
var $day;
|
||||
var $hour;
|
||||
var $minute;
|
||||
var $second;
|
||||
var $timezone;
|
||||
|
||||
/**
|
||||
* PHP5 constructor.
|
||||
*/
|
||||
function __construct( $time )
|
||||
{
|
||||
// $time can be a PHP timestamp or an ISO one
|
||||
if (is_numeric($time)) {
|
||||
$this->parseTimestamp($time);
|
||||
} else {
|
||||
$this->parseIso($time);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* PHP4 constructor.
|
||||
*/
|
||||
public function IXR_Date( $time ) {
|
||||
self::__construct( $time );
|
||||
}
|
||||
|
||||
function parseTimestamp($timestamp)
|
||||
{
|
||||
$this->year = gmdate('Y', $timestamp);
|
||||
$this->month = gmdate('m', $timestamp);
|
||||
$this->day = gmdate('d', $timestamp);
|
||||
$this->hour = gmdate('H', $timestamp);
|
||||
$this->minute = gmdate('i', $timestamp);
|
||||
$this->second = gmdate('s', $timestamp);
|
||||
$this->timezone = '';
|
||||
}
|
||||
|
||||
function parseIso($iso)
|
||||
{
|
||||
$this->year = substr($iso, 0, 4);
|
||||
$this->month = substr($iso, 4, 2);
|
||||
$this->day = substr($iso, 6, 2);
|
||||
$this->hour = substr($iso, 9, 2);
|
||||
$this->minute = substr($iso, 12, 2);
|
||||
$this->second = substr($iso, 15, 2);
|
||||
$this->timezone = substr($iso, 17);
|
||||
}
|
||||
|
||||
function getIso()
|
||||
{
|
||||
return $this->year.$this->month.$this->day.'T'.$this->hour.':'.$this->minute.':'.$this->second.$this->timezone;
|
||||
}
|
||||
|
||||
function getXml()
|
||||
{
|
||||
return '<dateTime.iso8601>'.$this->getIso().'</dateTime.iso8601>';
|
||||
}
|
||||
|
||||
function getTimestamp()
|
||||
{
|
||||
return mktime($this->hour, $this->minute, $this->second, $this->month, $this->day, $this->year);
|
||||
}
|
||||
}
|
||||
<?php
|
||||
|
||||
/**
|
||||
* IXR_Date
|
||||
*
|
||||
* @package IXR
|
||||
* @since 1.5.0
|
||||
*/
|
||||
class IXR_Date {
|
||||
var $year;
|
||||
var $month;
|
||||
var $day;
|
||||
var $hour;
|
||||
var $minute;
|
||||
var $second;
|
||||
var $timezone;
|
||||
|
||||
/**
|
||||
* PHP5 constructor.
|
||||
*/
|
||||
function __construct( $time )
|
||||
{
|
||||
// $time can be a PHP timestamp or an ISO one
|
||||
if (is_numeric($time)) {
|
||||
$this->parseTimestamp($time);
|
||||
} else {
|
||||
$this->parseIso($time);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* PHP4 constructor.
|
||||
*/
|
||||
public function IXR_Date( $time ) {
|
||||
self::__construct( $time );
|
||||
}
|
||||
|
||||
function parseTimestamp($timestamp)
|
||||
{
|
||||
$this->year = gmdate('Y', $timestamp);
|
||||
$this->month = gmdate('m', $timestamp);
|
||||
$this->day = gmdate('d', $timestamp);
|
||||
$this->hour = gmdate('H', $timestamp);
|
||||
$this->minute = gmdate('i', $timestamp);
|
||||
$this->second = gmdate('s', $timestamp);
|
||||
$this->timezone = '';
|
||||
}
|
||||
|
||||
function parseIso($iso)
|
||||
{
|
||||
$this->year = substr($iso, 0, 4);
|
||||
$this->month = substr($iso, 4, 2);
|
||||
$this->day = substr($iso, 6, 2);
|
||||
$this->hour = substr($iso, 9, 2);
|
||||
$this->minute = substr($iso, 12, 2);
|
||||
$this->second = substr($iso, 15, 2);
|
||||
$this->timezone = substr($iso, 17);
|
||||
}
|
||||
|
||||
function getIso()
|
||||
{
|
||||
return $this->year.$this->month.$this->day.'T'.$this->hour.':'.$this->minute.':'.$this->second.$this->timezone;
|
||||
}
|
||||
|
||||
function getXml()
|
||||
{
|
||||
return '<dateTime.iso8601>'.$this->getIso().'</dateTime.iso8601>';
|
||||
}
|
||||
|
||||
function getTimestamp()
|
||||
{
|
||||
return mktime($this->hour, $this->minute, $this->second, $this->month, $this->day, $this->year);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,53 +1,53 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* IXR_Error
|
||||
*
|
||||
* @package IXR
|
||||
* @since 1.5.0
|
||||
*/
|
||||
class IXR_Error
|
||||
{
|
||||
var $code;
|
||||
var $message;
|
||||
|
||||
/**
|
||||
* PHP5 constructor.
|
||||
*/
|
||||
function __construct( $code, $message )
|
||||
{
|
||||
$this->code = $code;
|
||||
$this->message = htmlspecialchars($message);
|
||||
}
|
||||
|
||||
/**
|
||||
* PHP4 constructor.
|
||||
*/
|
||||
public function IXR_Error( $code, $message ) {
|
||||
self::__construct( $code, $message );
|
||||
}
|
||||
|
||||
function getXml()
|
||||
{
|
||||
$xml = <<<EOD
|
||||
<methodResponse>
|
||||
<fault>
|
||||
<value>
|
||||
<struct>
|
||||
<member>
|
||||
<name>faultCode</name>
|
||||
<value><int>{$this->code}</int></value>
|
||||
</member>
|
||||
<member>
|
||||
<name>faultString</name>
|
||||
<value><string>{$this->message}</string></value>
|
||||
</member>
|
||||
</struct>
|
||||
</value>
|
||||
</fault>
|
||||
</methodResponse>
|
||||
|
||||
EOD;
|
||||
return $xml;
|
||||
}
|
||||
}
|
||||
<?php
|
||||
|
||||
/**
|
||||
* IXR_Error
|
||||
*
|
||||
* @package IXR
|
||||
* @since 1.5.0
|
||||
*/
|
||||
class IXR_Error
|
||||
{
|
||||
var $code;
|
||||
var $message;
|
||||
|
||||
/**
|
||||
* PHP5 constructor.
|
||||
*/
|
||||
function __construct( $code, $message )
|
||||
{
|
||||
$this->code = $code;
|
||||
$this->message = htmlspecialchars($message);
|
||||
}
|
||||
|
||||
/**
|
||||
* PHP4 constructor.
|
||||
*/
|
||||
public function IXR_Error( $code, $message ) {
|
||||
self::__construct( $code, $message );
|
||||
}
|
||||
|
||||
function getXml()
|
||||
{
|
||||
$xml = <<<EOD
|
||||
<methodResponse>
|
||||
<fault>
|
||||
<value>
|
||||
<struct>
|
||||
<member>
|
||||
<name>faultCode</name>
|
||||
<value><int>{$this->code}</int></value>
|
||||
</member>
|
||||
<member>
|
||||
<name>faultString</name>
|
||||
<value><string>{$this->message}</string></value>
|
||||
</member>
|
||||
</struct>
|
||||
</value>
|
||||
</fault>
|
||||
</methodResponse>
|
||||
|
||||
EOD;
|
||||
return $xml;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,174 +1,174 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* IXR_IntrospectionServer
|
||||
*
|
||||
* @package IXR
|
||||
* @since 1.5.0
|
||||
*/
|
||||
class IXR_IntrospectionServer extends IXR_Server
|
||||
{
|
||||
var $signatures;
|
||||
var $help;
|
||||
|
||||
/**
|
||||
* PHP5 constructor.
|
||||
*/
|
||||
function __construct()
|
||||
{
|
||||
$this->setCallbacks();
|
||||
$this->setCapabilities();
|
||||
$this->capabilities['introspection'] = array(
|
||||
'specUrl' => 'http://xmlrpc.usefulinc.com/doc/reserved.html',
|
||||
'specVersion' => 1
|
||||
);
|
||||
$this->addCallback(
|
||||
'system.methodSignature',
|
||||
'this:methodSignature',
|
||||
array('array', 'string'),
|
||||
'Returns an array describing the return type and required parameters of a method'
|
||||
);
|
||||
$this->addCallback(
|
||||
'system.getCapabilities',
|
||||
'this:getCapabilities',
|
||||
array('struct'),
|
||||
'Returns a struct describing the XML-RPC specifications supported by this server'
|
||||
);
|
||||
$this->addCallback(
|
||||
'system.listMethods',
|
||||
'this:listMethods',
|
||||
array('array'),
|
||||
'Returns an array of available methods on this server'
|
||||
);
|
||||
$this->addCallback(
|
||||
'system.methodHelp',
|
||||
'this:methodHelp',
|
||||
array('string', 'string'),
|
||||
'Returns a documentation string for the specified method'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* PHP4 constructor.
|
||||
*/
|
||||
public function IXR_IntrospectionServer() {
|
||||
self::__construct();
|
||||
}
|
||||
|
||||
function addCallback($method, $callback, $args, $help)
|
||||
{
|
||||
$this->callbacks[$method] = $callback;
|
||||
$this->signatures[$method] = $args;
|
||||
$this->help[$method] = $help;
|
||||
}
|
||||
|
||||
function call($methodname, $args)
|
||||
{
|
||||
// Make sure it's in an array
|
||||
if ($args && !is_array($args)) {
|
||||
$args = array($args);
|
||||
}
|
||||
|
||||
// Over-rides default call method, adds signature check
|
||||
if (!$this->hasMethod($methodname)) {
|
||||
return new IXR_Error(-32601, 'server error. requested method "'.$this->message->methodName.'" not specified.');
|
||||
}
|
||||
$method = $this->callbacks[$methodname];
|
||||
$signature = $this->signatures[$methodname];
|
||||
$returnType = array_shift($signature);
|
||||
|
||||
// Check the number of arguments
|
||||
if (count($args) != count($signature)) {
|
||||
return new IXR_Error(-32602, 'server error. wrong number of method parameters');
|
||||
}
|
||||
|
||||
// Check the argument types
|
||||
$ok = true;
|
||||
$argsbackup = $args;
|
||||
for ($i = 0, $j = count($args); $i < $j; $i++) {
|
||||
$arg = array_shift($args);
|
||||
$type = array_shift($signature);
|
||||
switch ($type) {
|
||||
case 'int':
|
||||
case 'i4':
|
||||
if (is_array($arg) || !is_int($arg)) {
|
||||
$ok = false;
|
||||
}
|
||||
break;
|
||||
case 'base64':
|
||||
case 'string':
|
||||
if (!is_string($arg)) {
|
||||
$ok = false;
|
||||
}
|
||||
break;
|
||||
case 'boolean':
|
||||
if ($arg !== false && $arg !== true) {
|
||||
$ok = false;
|
||||
}
|
||||
break;
|
||||
case 'float':
|
||||
case 'double':
|
||||
if (!is_float($arg)) {
|
||||
$ok = false;
|
||||
}
|
||||
break;
|
||||
case 'date':
|
||||
case 'dateTime.iso8601':
|
||||
if (!is_a($arg, 'IXR_Date')) {
|
||||
$ok = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (!$ok) {
|
||||
return new IXR_Error(-32602, 'server error. invalid method parameters');
|
||||
}
|
||||
}
|
||||
// It passed the test - run the "real" method call
|
||||
return parent::call($methodname, $argsbackup);
|
||||
}
|
||||
|
||||
function methodSignature($method)
|
||||
{
|
||||
if (!$this->hasMethod($method)) {
|
||||
return new IXR_Error(-32601, 'server error. requested method "'.$method.'" not specified.');
|
||||
}
|
||||
// We should be returning an array of types
|
||||
$types = $this->signatures[$method];
|
||||
$return = array();
|
||||
foreach ($types as $type) {
|
||||
switch ($type) {
|
||||
case 'string':
|
||||
$return[] = 'string';
|
||||
break;
|
||||
case 'int':
|
||||
case 'i4':
|
||||
$return[] = 42;
|
||||
break;
|
||||
case 'double':
|
||||
$return[] = 3.1415;
|
||||
break;
|
||||
case 'dateTime.iso8601':
|
||||
$return[] = new IXR_Date(time());
|
||||
break;
|
||||
case 'boolean':
|
||||
$return[] = true;
|
||||
break;
|
||||
case 'base64':
|
||||
$return[] = new IXR_Base64('base64');
|
||||
break;
|
||||
case 'array':
|
||||
$return[] = array('array');
|
||||
break;
|
||||
case 'struct':
|
||||
$return[] = array('struct' => 'struct');
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
function methodHelp($method)
|
||||
{
|
||||
return $this->help[$method];
|
||||
}
|
||||
}
|
||||
<?php
|
||||
|
||||
/**
|
||||
* IXR_IntrospectionServer
|
||||
*
|
||||
* @package IXR
|
||||
* @since 1.5.0
|
||||
*/
|
||||
class IXR_IntrospectionServer extends IXR_Server
|
||||
{
|
||||
var $signatures;
|
||||
var $help;
|
||||
|
||||
/**
|
||||
* PHP5 constructor.
|
||||
*/
|
||||
function __construct()
|
||||
{
|
||||
$this->setCallbacks();
|
||||
$this->setCapabilities();
|
||||
$this->capabilities['introspection'] = array(
|
||||
'specUrl' => 'http://xmlrpc.usefulinc.com/doc/reserved.html',
|
||||
'specVersion' => 1
|
||||
);
|
||||
$this->addCallback(
|
||||
'system.methodSignature',
|
||||
'this:methodSignature',
|
||||
array('array', 'string'),
|
||||
'Returns an array describing the return type and required parameters of a method'
|
||||
);
|
||||
$this->addCallback(
|
||||
'system.getCapabilities',
|
||||
'this:getCapabilities',
|
||||
array('struct'),
|
||||
'Returns a struct describing the XML-RPC specifications supported by this server'
|
||||
);
|
||||
$this->addCallback(
|
||||
'system.listMethods',
|
||||
'this:listMethods',
|
||||
array('array'),
|
||||
'Returns an array of available methods on this server'
|
||||
);
|
||||
$this->addCallback(
|
||||
'system.methodHelp',
|
||||
'this:methodHelp',
|
||||
array('string', 'string'),
|
||||
'Returns a documentation string for the specified method'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* PHP4 constructor.
|
||||
*/
|
||||
public function IXR_IntrospectionServer() {
|
||||
self::__construct();
|
||||
}
|
||||
|
||||
function addCallback($method, $callback, $args, $help)
|
||||
{
|
||||
$this->callbacks[$method] = $callback;
|
||||
$this->signatures[$method] = $args;
|
||||
$this->help[$method] = $help;
|
||||
}
|
||||
|
||||
function call($methodname, $args)
|
||||
{
|
||||
// Make sure it's in an array
|
||||
if ($args && !is_array($args)) {
|
||||
$args = array($args);
|
||||
}
|
||||
|
||||
// Over-rides default call method, adds signature check
|
||||
if (!$this->hasMethod($methodname)) {
|
||||
return new IXR_Error(-32601, 'server error. requested method "'.$this->message->methodName.'" not specified.');
|
||||
}
|
||||
$method = $this->callbacks[$methodname];
|
||||
$signature = $this->signatures[$methodname];
|
||||
$returnType = array_shift($signature);
|
||||
|
||||
// Check the number of arguments
|
||||
if (count($args) != count($signature)) {
|
||||
return new IXR_Error(-32602, 'server error. wrong number of method parameters');
|
||||
}
|
||||
|
||||
// Check the argument types
|
||||
$ok = true;
|
||||
$argsbackup = $args;
|
||||
for ($i = 0, $j = count($args); $i < $j; $i++) {
|
||||
$arg = array_shift($args);
|
||||
$type = array_shift($signature);
|
||||
switch ($type) {
|
||||
case 'int':
|
||||
case 'i4':
|
||||
if (is_array($arg) || !is_int($arg)) {
|
||||
$ok = false;
|
||||
}
|
||||
break;
|
||||
case 'base64':
|
||||
case 'string':
|
||||
if (!is_string($arg)) {
|
||||
$ok = false;
|
||||
}
|
||||
break;
|
||||
case 'boolean':
|
||||
if ($arg !== false && $arg !== true) {
|
||||
$ok = false;
|
||||
}
|
||||
break;
|
||||
case 'float':
|
||||
case 'double':
|
||||
if (!is_float($arg)) {
|
||||
$ok = false;
|
||||
}
|
||||
break;
|
||||
case 'date':
|
||||
case 'dateTime.iso8601':
|
||||
if (!is_a($arg, 'IXR_Date')) {
|
||||
$ok = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (!$ok) {
|
||||
return new IXR_Error(-32602, 'server error. invalid method parameters');
|
||||
}
|
||||
}
|
||||
// It passed the test - run the "real" method call
|
||||
return parent::call($methodname, $argsbackup);
|
||||
}
|
||||
|
||||
function methodSignature($method)
|
||||
{
|
||||
if (!$this->hasMethod($method)) {
|
||||
return new IXR_Error(-32601, 'server error. requested method "'.$method.'" not specified.');
|
||||
}
|
||||
// We should be returning an array of types
|
||||
$types = $this->signatures[$method];
|
||||
$return = array();
|
||||
foreach ($types as $type) {
|
||||
switch ($type) {
|
||||
case 'string':
|
||||
$return[] = 'string';
|
||||
break;
|
||||
case 'int':
|
||||
case 'i4':
|
||||
$return[] = 42;
|
||||
break;
|
||||
case 'double':
|
||||
$return[] = 3.1415;
|
||||
break;
|
||||
case 'dateTime.iso8601':
|
||||
$return[] = new IXR_Date(time());
|
||||
break;
|
||||
case 'boolean':
|
||||
$return[] = true;
|
||||
break;
|
||||
case 'base64':
|
||||
$return[] = new IXR_Base64('base64');
|
||||
break;
|
||||
case 'array':
|
||||
$return[] = array('array');
|
||||
break;
|
||||
case 'struct':
|
||||
$return[] = array('struct' => 'struct');
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
function methodHelp($method)
|
||||
{
|
||||
return $this->help[$method];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,242 +1,242 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* IXR_MESSAGE
|
||||
*
|
||||
* @package IXR
|
||||
* @since 1.5.0
|
||||
*
|
||||
*/
|
||||
class IXR_Message
|
||||
{
|
||||
var $message = false;
|
||||
var $messageType = false; // methodCall / methodResponse / fault
|
||||
var $faultCode = false;
|
||||
var $faultString = false;
|
||||
var $methodName = '';
|
||||
var $params = array();
|
||||
|
||||
// Current variable stacks
|
||||
var $_arraystructs = array(); // The stack used to keep track of the current array/struct
|
||||
var $_arraystructstypes = array(); // Stack keeping track of if things are structs or array
|
||||
var $_currentStructName = array(); // A stack as well
|
||||
var $_param;
|
||||
var $_value;
|
||||
var $_currentTag;
|
||||
var $_currentTagContents;
|
||||
// The XML parser
|
||||
var $_parser;
|
||||
|
||||
/**
|
||||
* PHP5 constructor.
|
||||
*/
|
||||
function __construct( $message )
|
||||
{
|
||||
$this->message =& $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* PHP4 constructor.
|
||||
*/
|
||||
public function IXR_Message( $message ) {
|
||||
self::__construct( $message );
|
||||
}
|
||||
|
||||
function parse()
|
||||
{
|
||||
if ( ! function_exists( 'xml_parser_create' ) ) {
|
||||
trigger_error( __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ) );
|
||||
return false;
|
||||
}
|
||||
|
||||
// first remove the XML declaration
|
||||
// merged from WP #10698 - this method avoids the RAM usage of preg_replace on very large messages
|
||||
$header = preg_replace( '/<\?xml.*?\?'.'>/s', '', substr( $this->message, 0, 100 ), 1 );
|
||||
$this->message = trim( substr_replace( $this->message, $header, 0, 100 ) );
|
||||
if ( '' == $this->message ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Then remove the DOCTYPE
|
||||
$header = preg_replace( '/^<!DOCTYPE[^>]*+>/i', '', substr( $this->message, 0, 200 ), 1 );
|
||||
$this->message = trim( substr_replace( $this->message, $header, 0, 200 ) );
|
||||
if ( '' == $this->message ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check that the root tag is valid
|
||||
$root_tag = substr( $this->message, 0, strcspn( substr( $this->message, 0, 20 ), "> \t\r\n" ) );
|
||||
if ( '<!DOCTYPE' === strtoupper( $root_tag ) ) {
|
||||
return false;
|
||||
}
|
||||
if ( ! in_array( $root_tag, array( '<methodCall', '<methodResponse', '<fault' ) ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Bail if there are too many elements to parse
|
||||
$element_limit = 30000;
|
||||
if ( function_exists( 'apply_filters' ) ) {
|
||||
/**
|
||||
* Filters the number of elements to parse in an XML-RPC response.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @param int $element_limit Default elements limit.
|
||||
*/
|
||||
$element_limit = apply_filters( 'xmlrpc_element_limit', $element_limit );
|
||||
}
|
||||
if ( $element_limit && 2 * $element_limit < substr_count( $this->message, '<' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->_parser = xml_parser_create();
|
||||
// Set XML parser to take the case of tags in to account
|
||||
xml_parser_set_option($this->_parser, XML_OPTION_CASE_FOLDING, false);
|
||||
// Set XML parser callback functions
|
||||
xml_set_object($this->_parser, $this);
|
||||
xml_set_element_handler($this->_parser, 'tag_open', 'tag_close');
|
||||
xml_set_character_data_handler($this->_parser, 'cdata');
|
||||
|
||||
// 256Kb, parse in chunks to avoid the RAM usage on very large messages
|
||||
$chunk_size = 262144;
|
||||
|
||||
/**
|
||||
* Filters the chunk size that can be used to parse an XML-RPC response message.
|
||||
*
|
||||
* @since 4.4.0
|
||||
*
|
||||
* @param int $chunk_size Chunk size to parse in bytes.
|
||||
*/
|
||||
$chunk_size = apply_filters( 'xmlrpc_chunk_parsing_size', $chunk_size );
|
||||
|
||||
$final = false;
|
||||
|
||||
do {
|
||||
if (strlen($this->message) <= $chunk_size) {
|
||||
$final = true;
|
||||
}
|
||||
|
||||
$part = substr($this->message, 0, $chunk_size);
|
||||
$this->message = substr($this->message, $chunk_size);
|
||||
|
||||
if (!xml_parse($this->_parser, $part, $final)) {
|
||||
xml_parser_free($this->_parser);
|
||||
unset($this->_parser);
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($final) {
|
||||
break;
|
||||
}
|
||||
} while (true);
|
||||
|
||||
xml_parser_free($this->_parser);
|
||||
unset($this->_parser);
|
||||
|
||||
// Grab the error messages, if any
|
||||
if ($this->messageType == 'fault') {
|
||||
$this->faultCode = $this->params[0]['faultCode'];
|
||||
$this->faultString = $this->params[0]['faultString'];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function tag_open($parser, $tag, $attr)
|
||||
{
|
||||
$this->_currentTagContents = '';
|
||||
$this->_currentTag = $tag;
|
||||
switch($tag) {
|
||||
case 'methodCall':
|
||||
case 'methodResponse':
|
||||
case 'fault':
|
||||
$this->messageType = $tag;
|
||||
break;
|
||||
/* Deal with stacks of arrays and structs */
|
||||
case 'data': // data is to all intents and puposes more interesting than array
|
||||
$this->_arraystructstypes[] = 'array';
|
||||
$this->_arraystructs[] = array();
|
||||
break;
|
||||
case 'struct':
|
||||
$this->_arraystructstypes[] = 'struct';
|
||||
$this->_arraystructs[] = array();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function cdata($parser, $cdata)
|
||||
{
|
||||
$this->_currentTagContents .= $cdata;
|
||||
}
|
||||
|
||||
function tag_close($parser, $tag)
|
||||
{
|
||||
$valueFlag = false;
|
||||
switch($tag) {
|
||||
case 'int':
|
||||
case 'i4':
|
||||
$value = (int)trim($this->_currentTagContents);
|
||||
$valueFlag = true;
|
||||
break;
|
||||
case 'double':
|
||||
$value = (double)trim($this->_currentTagContents);
|
||||
$valueFlag = true;
|
||||
break;
|
||||
case 'string':
|
||||
$value = (string)trim($this->_currentTagContents);
|
||||
$valueFlag = true;
|
||||
break;
|
||||
case 'dateTime.iso8601':
|
||||
$value = new IXR_Date(trim($this->_currentTagContents));
|
||||
$valueFlag = true;
|
||||
break;
|
||||
case 'value':
|
||||
// "If no type is indicated, the type is string."
|
||||
if (trim($this->_currentTagContents) != '') {
|
||||
$value = (string)$this->_currentTagContents;
|
||||
$valueFlag = true;
|
||||
}
|
||||
break;
|
||||
case 'boolean':
|
||||
$value = (boolean)trim($this->_currentTagContents);
|
||||
$valueFlag = true;
|
||||
break;
|
||||
case 'base64':
|
||||
$value = base64_decode($this->_currentTagContents);
|
||||
$valueFlag = true;
|
||||
break;
|
||||
/* Deal with stacks of arrays and structs */
|
||||
case 'data':
|
||||
case 'struct':
|
||||
$value = array_pop($this->_arraystructs);
|
||||
array_pop($this->_arraystructstypes);
|
||||
$valueFlag = true;
|
||||
break;
|
||||
case 'member':
|
||||
array_pop($this->_currentStructName);
|
||||
break;
|
||||
case 'name':
|
||||
$this->_currentStructName[] = trim($this->_currentTagContents);
|
||||
break;
|
||||
case 'methodName':
|
||||
$this->methodName = trim($this->_currentTagContents);
|
||||
break;
|
||||
}
|
||||
|
||||
if ($valueFlag) {
|
||||
if (count($this->_arraystructs) > 0) {
|
||||
// Add value to struct or array
|
||||
if ($this->_arraystructstypes[count($this->_arraystructstypes)-1] == 'struct') {
|
||||
// Add to struct
|
||||
$this->_arraystructs[count($this->_arraystructs)-1][$this->_currentStructName[count($this->_currentStructName)-1]] = $value;
|
||||
} else {
|
||||
// Add to array
|
||||
$this->_arraystructs[count($this->_arraystructs)-1][] = $value;
|
||||
}
|
||||
} else {
|
||||
// Just add as a parameter
|
||||
$this->params[] = $value;
|
||||
}
|
||||
}
|
||||
$this->_currentTagContents = '';
|
||||
}
|
||||
}
|
||||
<?php
|
||||
|
||||
/**
|
||||
* IXR_MESSAGE
|
||||
*
|
||||
* @package IXR
|
||||
* @since 1.5.0
|
||||
*
|
||||
*/
|
||||
class IXR_Message
|
||||
{
|
||||
var $message = false;
|
||||
var $messageType = false; // methodCall / methodResponse / fault
|
||||
var $faultCode = false;
|
||||
var $faultString = false;
|
||||
var $methodName = '';
|
||||
var $params = array();
|
||||
|
||||
// Current variable stacks
|
||||
var $_arraystructs = array(); // The stack used to keep track of the current array/struct
|
||||
var $_arraystructstypes = array(); // Stack keeping track of if things are structs or array
|
||||
var $_currentStructName = array(); // A stack as well
|
||||
var $_param;
|
||||
var $_value;
|
||||
var $_currentTag;
|
||||
var $_currentTagContents;
|
||||
// The XML parser
|
||||
var $_parser;
|
||||
|
||||
/**
|
||||
* PHP5 constructor.
|
||||
*/
|
||||
function __construct( $message )
|
||||
{
|
||||
$this->message =& $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* PHP4 constructor.
|
||||
*/
|
||||
public function IXR_Message( $message ) {
|
||||
self::__construct( $message );
|
||||
}
|
||||
|
||||
function parse()
|
||||
{
|
||||
if ( ! function_exists( 'xml_parser_create' ) ) {
|
||||
trigger_error( __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ) );
|
||||
return false;
|
||||
}
|
||||
|
||||
// first remove the XML declaration
|
||||
// merged from WP #10698 - this method avoids the RAM usage of preg_replace on very large messages
|
||||
$header = preg_replace( '/<\?xml.*?\?'.'>/s', '', substr( $this->message, 0, 100 ), 1 );
|
||||
$this->message = trim( substr_replace( $this->message, $header, 0, 100 ) );
|
||||
if ( '' == $this->message ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Then remove the DOCTYPE
|
||||
$header = preg_replace( '/^<!DOCTYPE[^>]*+>/i', '', substr( $this->message, 0, 200 ), 1 );
|
||||
$this->message = trim( substr_replace( $this->message, $header, 0, 200 ) );
|
||||
if ( '' == $this->message ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check that the root tag is valid
|
||||
$root_tag = substr( $this->message, 0, strcspn( substr( $this->message, 0, 20 ), "> \t\r\n" ) );
|
||||
if ( '<!DOCTYPE' === strtoupper( $root_tag ) ) {
|
||||
return false;
|
||||
}
|
||||
if ( ! in_array( $root_tag, array( '<methodCall', '<methodResponse', '<fault' ) ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Bail if there are too many elements to parse
|
||||
$element_limit = 30000;
|
||||
if ( function_exists( 'apply_filters' ) ) {
|
||||
/**
|
||||
* Filters the number of elements to parse in an XML-RPC response.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @param int $element_limit Default elements limit.
|
||||
*/
|
||||
$element_limit = apply_filters( 'xmlrpc_element_limit', $element_limit );
|
||||
}
|
||||
if ( $element_limit && 2 * $element_limit < substr_count( $this->message, '<' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->_parser = xml_parser_create();
|
||||
// Set XML parser to take the case of tags in to account
|
||||
xml_parser_set_option($this->_parser, XML_OPTION_CASE_FOLDING, false);
|
||||
// Set XML parser callback functions
|
||||
xml_set_object($this->_parser, $this);
|
||||
xml_set_element_handler($this->_parser, 'tag_open', 'tag_close');
|
||||
xml_set_character_data_handler($this->_parser, 'cdata');
|
||||
|
||||
// 256Kb, parse in chunks to avoid the RAM usage on very large messages
|
||||
$chunk_size = 262144;
|
||||
|
||||
/**
|
||||
* Filters the chunk size that can be used to parse an XML-RPC response message.
|
||||
*
|
||||
* @since 4.4.0
|
||||
*
|
||||
* @param int $chunk_size Chunk size to parse in bytes.
|
||||
*/
|
||||
$chunk_size = apply_filters( 'xmlrpc_chunk_parsing_size', $chunk_size );
|
||||
|
||||
$final = false;
|
||||
|
||||
do {
|
||||
if (strlen($this->message) <= $chunk_size) {
|
||||
$final = true;
|
||||
}
|
||||
|
||||
$part = substr($this->message, 0, $chunk_size);
|
||||
$this->message = substr($this->message, $chunk_size);
|
||||
|
||||
if (!xml_parse($this->_parser, $part, $final)) {
|
||||
xml_parser_free($this->_parser);
|
||||
unset($this->_parser);
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($final) {
|
||||
break;
|
||||
}
|
||||
} while (true);
|
||||
|
||||
xml_parser_free($this->_parser);
|
||||
unset($this->_parser);
|
||||
|
||||
// Grab the error messages, if any
|
||||
if ($this->messageType == 'fault') {
|
||||
$this->faultCode = $this->params[0]['faultCode'];
|
||||
$this->faultString = $this->params[0]['faultString'];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function tag_open($parser, $tag, $attr)
|
||||
{
|
||||
$this->_currentTagContents = '';
|
||||
$this->_currentTag = $tag;
|
||||
switch($tag) {
|
||||
case 'methodCall':
|
||||
case 'methodResponse':
|
||||
case 'fault':
|
||||
$this->messageType = $tag;
|
||||
break;
|
||||
/* Deal with stacks of arrays and structs */
|
||||
case 'data': // data is to all intents and puposes more interesting than array
|
||||
$this->_arraystructstypes[] = 'array';
|
||||
$this->_arraystructs[] = array();
|
||||
break;
|
||||
case 'struct':
|
||||
$this->_arraystructstypes[] = 'struct';
|
||||
$this->_arraystructs[] = array();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function cdata($parser, $cdata)
|
||||
{
|
||||
$this->_currentTagContents .= $cdata;
|
||||
}
|
||||
|
||||
function tag_close($parser, $tag)
|
||||
{
|
||||
$valueFlag = false;
|
||||
switch($tag) {
|
||||
case 'int':
|
||||
case 'i4':
|
||||
$value = (int)trim($this->_currentTagContents);
|
||||
$valueFlag = true;
|
||||
break;
|
||||
case 'double':
|
||||
$value = (double)trim($this->_currentTagContents);
|
||||
$valueFlag = true;
|
||||
break;
|
||||
case 'string':
|
||||
$value = (string)trim($this->_currentTagContents);
|
||||
$valueFlag = true;
|
||||
break;
|
||||
case 'dateTime.iso8601':
|
||||
$value = new IXR_Date(trim($this->_currentTagContents));
|
||||
$valueFlag = true;
|
||||
break;
|
||||
case 'value':
|
||||
// "If no type is indicated, the type is string."
|
||||
if (trim($this->_currentTagContents) != '') {
|
||||
$value = (string)$this->_currentTagContents;
|
||||
$valueFlag = true;
|
||||
}
|
||||
break;
|
||||
case 'boolean':
|
||||
$value = (boolean)trim($this->_currentTagContents);
|
||||
$valueFlag = true;
|
||||
break;
|
||||
case 'base64':
|
||||
$value = base64_decode($this->_currentTagContents);
|
||||
$valueFlag = true;
|
||||
break;
|
||||
/* Deal with stacks of arrays and structs */
|
||||
case 'data':
|
||||
case 'struct':
|
||||
$value = array_pop($this->_arraystructs);
|
||||
array_pop($this->_arraystructstypes);
|
||||
$valueFlag = true;
|
||||
break;
|
||||
case 'member':
|
||||
array_pop($this->_currentStructName);
|
||||
break;
|
||||
case 'name':
|
||||
$this->_currentStructName[] = trim($this->_currentTagContents);
|
||||
break;
|
||||
case 'methodName':
|
||||
$this->methodName = trim($this->_currentTagContents);
|
||||
break;
|
||||
}
|
||||
|
||||
if ($valueFlag) {
|
||||
if (count($this->_arraystructs) > 0) {
|
||||
// Add value to struct or array
|
||||
if ($this->_arraystructstypes[count($this->_arraystructstypes)-1] == 'struct') {
|
||||
// Add to struct
|
||||
$this->_arraystructs[count($this->_arraystructs)-1][$this->_currentStructName[count($this->_currentStructName)-1]] = $value;
|
||||
} else {
|
||||
// Add to array
|
||||
$this->_arraystructs[count($this->_arraystructs)-1][] = $value;
|
||||
}
|
||||
} else {
|
||||
// Just add as a parameter
|
||||
$this->params[] = $value;
|
||||
}
|
||||
}
|
||||
$this->_currentTagContents = '';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,54 +1,54 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* IXR_Request
|
||||
*
|
||||
* @package IXR
|
||||
* @since 1.5.0
|
||||
*/
|
||||
class IXR_Request
|
||||
{
|
||||
var $method;
|
||||
var $args;
|
||||
var $xml;
|
||||
|
||||
/**
|
||||
* PHP5 constructor.
|
||||
*/
|
||||
function __construct($method, $args)
|
||||
{
|
||||
$this->method = $method;
|
||||
$this->args = $args;
|
||||
$this->xml = <<<EOD
|
||||
<?xml version="1.0"?>
|
||||
<methodCall>
|
||||
<methodName>{$this->method}</methodName>
|
||||
<params>
|
||||
|
||||
EOD;
|
||||
foreach ($this->args as $arg) {
|
||||
$this->xml .= '<param><value>';
|
||||
$v = new IXR_Value($arg);
|
||||
$this->xml .= $v->getXml();
|
||||
$this->xml .= "</value></param>\n";
|
||||
}
|
||||
$this->xml .= '</params></methodCall>';
|
||||
}
|
||||
|
||||
/**
|
||||
* PHP4 constructor.
|
||||
*/
|
||||
public function IXR_Request( $method, $args ) {
|
||||
self::__construct( $method, $args );
|
||||
}
|
||||
|
||||
function getLength()
|
||||
{
|
||||
return strlen($this->xml);
|
||||
}
|
||||
|
||||
function getXml()
|
||||
{
|
||||
return $this->xml;
|
||||
}
|
||||
}
|
||||
<?php
|
||||
|
||||
/**
|
||||
* IXR_Request
|
||||
*
|
||||
* @package IXR
|
||||
* @since 1.5.0
|
||||
*/
|
||||
class IXR_Request
|
||||
{
|
||||
var $method;
|
||||
var $args;
|
||||
var $xml;
|
||||
|
||||
/**
|
||||
* PHP5 constructor.
|
||||
*/
|
||||
function __construct($method, $args)
|
||||
{
|
||||
$this->method = $method;
|
||||
$this->args = $args;
|
||||
$this->xml = <<<EOD
|
||||
<?xml version="1.0"?>
|
||||
<methodCall>
|
||||
<methodName>{$this->method}</methodName>
|
||||
<params>
|
||||
|
||||
EOD;
|
||||
foreach ($this->args as $arg) {
|
||||
$this->xml .= '<param><value>';
|
||||
$v = new IXR_Value($arg);
|
||||
$this->xml .= $v->getXml();
|
||||
$this->xml .= "</value></param>\n";
|
||||
}
|
||||
$this->xml .= '</params></methodCall>';
|
||||
}
|
||||
|
||||
/**
|
||||
* PHP4 constructor.
|
||||
*/
|
||||
public function IXR_Request( $method, $args ) {
|
||||
self::__construct( $method, $args );
|
||||
}
|
||||
|
||||
function getLength()
|
||||
{
|
||||
return strlen($this->xml);
|
||||
}
|
||||
|
||||
function getXml()
|
||||
{
|
||||
return $this->xml;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,220 +1,220 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* IXR_Server
|
||||
*
|
||||
* @package IXR
|
||||
* @since 1.5.0
|
||||
*/
|
||||
class IXR_Server
|
||||
{
|
||||
var $data;
|
||||
var $callbacks = array();
|
||||
var $message;
|
||||
var $capabilities;
|
||||
|
||||
/**
|
||||
* PHP5 constructor.
|
||||
*/
|
||||
function __construct( $callbacks = false, $data = false, $wait = false )
|
||||
{
|
||||
$this->setCapabilities();
|
||||
if ($callbacks) {
|
||||
$this->callbacks = $callbacks;
|
||||
}
|
||||
$this->setCallbacks();
|
||||
if (!$wait) {
|
||||
$this->serve($data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* PHP4 constructor.
|
||||
*/
|
||||
public function IXR_Server( $callbacks = false, $data = false, $wait = false ) {
|
||||
self::__construct( $callbacks, $data, $wait );
|
||||
}
|
||||
|
||||
function serve($data = false)
|
||||
{
|
||||
if (!$data) {
|
||||
if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
if ( function_exists( 'status_header' ) ) {
|
||||
status_header( 405 ); // WP #20986
|
||||
header( 'Allow: POST' );
|
||||
}
|
||||
header('Content-Type: text/plain'); // merged from WP #9093
|
||||
die('XML-RPC server accepts POST requests only.');
|
||||
}
|
||||
|
||||
$data = file_get_contents('php://input');
|
||||
}
|
||||
$this->message = new IXR_Message($data);
|
||||
if (!$this->message->parse()) {
|
||||
$this->error(-32700, 'parse error. not well formed');
|
||||
}
|
||||
if ($this->message->messageType != 'methodCall') {
|
||||
$this->error(-32600, 'server error. invalid xml-rpc. not conforming to spec. Request must be a methodCall');
|
||||
}
|
||||
$result = $this->call($this->message->methodName, $this->message->params);
|
||||
|
||||
// Is the result an error?
|
||||
if (is_a($result, 'IXR_Error')) {
|
||||
$this->error($result);
|
||||
}
|
||||
|
||||
// Encode the result
|
||||
$r = new IXR_Value($result);
|
||||
$resultxml = $r->getXml();
|
||||
|
||||
// Create the XML
|
||||
$xml = <<<EOD
|
||||
<methodResponse>
|
||||
<params>
|
||||
<param>
|
||||
<value>
|
||||
$resultxml
|
||||
</value>
|
||||
</param>
|
||||
</params>
|
||||
</methodResponse>
|
||||
|
||||
EOD;
|
||||
// Send it
|
||||
$this->output($xml);
|
||||
}
|
||||
|
||||
function call($methodname, $args)
|
||||
{
|
||||
if (!$this->hasMethod($methodname)) {
|
||||
return new IXR_Error(-32601, 'server error. requested method '.$methodname.' does not exist.');
|
||||
}
|
||||
$method = $this->callbacks[$methodname];
|
||||
|
||||
// Perform the callback and send the response
|
||||
if (count($args) == 1) {
|
||||
// If only one parameter just send that instead of the whole array
|
||||
$args = $args[0];
|
||||
}
|
||||
|
||||
// Are we dealing with a function or a method?
|
||||
if (is_string($method) && substr($method, 0, 5) == 'this:') {
|
||||
// It's a class method - check it exists
|
||||
$method = substr($method, 5);
|
||||
if (!method_exists($this, $method)) {
|
||||
return new IXR_Error(-32601, 'server error. requested class method "'.$method.'" does not exist.');
|
||||
}
|
||||
|
||||
//Call the method
|
||||
$result = $this->$method($args);
|
||||
} else {
|
||||
// It's a function - does it exist?
|
||||
if (is_array($method)) {
|
||||
if (!is_callable(array($method[0], $method[1]))) {
|
||||
return new IXR_Error(-32601, 'server error. requested object method "'.$method[1].'" does not exist.');
|
||||
}
|
||||
} else if (!function_exists($method)) {
|
||||
return new IXR_Error(-32601, 'server error. requested function "'.$method.'" does not exist.');
|
||||
}
|
||||
|
||||
// Call the function
|
||||
$result = call_user_func($method, $args);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
function error($error, $message = false)
|
||||
{
|
||||
// Accepts either an error object or an error code and message
|
||||
if ($message && !is_object($error)) {
|
||||
$error = new IXR_Error($error, $message);
|
||||
}
|
||||
|
||||
$this->output($error->getXml());
|
||||
}
|
||||
|
||||
function output($xml)
|
||||
{
|
||||
$charset = function_exists('get_option') ? get_option('blog_charset') : '';
|
||||
if ($charset)
|
||||
$xml = '<?xml version="1.0" encoding="'.$charset.'"?>'."\n".$xml;
|
||||
else
|
||||
$xml = '<?xml version="1.0"?>'."\n".$xml;
|
||||
$length = strlen($xml);
|
||||
header('Connection: close');
|
||||
if ($charset)
|
||||
header('Content-Type: text/xml; charset='.$charset);
|
||||
else
|
||||
header('Content-Type: text/xml');
|
||||
header('Date: '.gmdate('r'));
|
||||
echo $xml;
|
||||
exit;
|
||||
}
|
||||
|
||||
function hasMethod($method)
|
||||
{
|
||||
return in_array($method, array_keys($this->callbacks));
|
||||
}
|
||||
|
||||
function setCapabilities()
|
||||
{
|
||||
// Initialises capabilities array
|
||||
$this->capabilities = array(
|
||||
'xmlrpc' => array(
|
||||
'specUrl' => 'http://www.xmlrpc.com/spec',
|
||||
'specVersion' => 1
|
||||
),
|
||||
'faults_interop' => array(
|
||||
'specUrl' => 'http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php',
|
||||
'specVersion' => 20010516
|
||||
),
|
||||
'system.multicall' => array(
|
||||
'specUrl' => 'http://www.xmlrpc.com/discuss/msgReader$1208',
|
||||
'specVersion' => 1
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
function getCapabilities($args)
|
||||
{
|
||||
return $this->capabilities;
|
||||
}
|
||||
|
||||
function setCallbacks()
|
||||
{
|
||||
$this->callbacks['system.getCapabilities'] = 'this:getCapabilities';
|
||||
$this->callbacks['system.listMethods'] = 'this:listMethods';
|
||||
$this->callbacks['system.multicall'] = 'this:multiCall';
|
||||
}
|
||||
|
||||
function listMethods($args)
|
||||
{
|
||||
// Returns a list of methods - uses array_reverse to ensure user defined
|
||||
// methods are listed before server defined methods
|
||||
return array_reverse(array_keys($this->callbacks));
|
||||
}
|
||||
|
||||
function multiCall($methodcalls)
|
||||
{
|
||||
// See http://www.xmlrpc.com/discuss/msgReader$1208
|
||||
$return = array();
|
||||
foreach ($methodcalls as $call) {
|
||||
$method = $call['methodName'];
|
||||
$params = $call['params'];
|
||||
if ($method == 'system.multicall') {
|
||||
$result = new IXR_Error(-32600, 'Recursive calls to system.multicall are forbidden');
|
||||
} else {
|
||||
$result = $this->call($method, $params);
|
||||
}
|
||||
if (is_a($result, 'IXR_Error')) {
|
||||
$return[] = array(
|
||||
'faultCode' => $result->code,
|
||||
'faultString' => $result->message
|
||||
);
|
||||
} else {
|
||||
$return[] = array($result);
|
||||
}
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
<?php
|
||||
|
||||
/**
|
||||
* IXR_Server
|
||||
*
|
||||
* @package IXR
|
||||
* @since 1.5.0
|
||||
*/
|
||||
class IXR_Server
|
||||
{
|
||||
var $data;
|
||||
var $callbacks = array();
|
||||
var $message;
|
||||
var $capabilities;
|
||||
|
||||
/**
|
||||
* PHP5 constructor.
|
||||
*/
|
||||
function __construct( $callbacks = false, $data = false, $wait = false )
|
||||
{
|
||||
$this->setCapabilities();
|
||||
if ($callbacks) {
|
||||
$this->callbacks = $callbacks;
|
||||
}
|
||||
$this->setCallbacks();
|
||||
if (!$wait) {
|
||||
$this->serve($data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* PHP4 constructor.
|
||||
*/
|
||||
public function IXR_Server( $callbacks = false, $data = false, $wait = false ) {
|
||||
self::__construct( $callbacks, $data, $wait );
|
||||
}
|
||||
|
||||
function serve($data = false)
|
||||
{
|
||||
if (!$data) {
|
||||
if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
if ( function_exists( 'status_header' ) ) {
|
||||
status_header( 405 ); // WP #20986
|
||||
header( 'Allow: POST' );
|
||||
}
|
||||
header('Content-Type: text/plain'); // merged from WP #9093
|
||||
die('XML-RPC server accepts POST requests only.');
|
||||
}
|
||||
|
||||
$data = file_get_contents('php://input');
|
||||
}
|
||||
$this->message = new IXR_Message($data);
|
||||
if (!$this->message->parse()) {
|
||||
$this->error(-32700, 'parse error. not well formed');
|
||||
}
|
||||
if ($this->message->messageType != 'methodCall') {
|
||||
$this->error(-32600, 'server error. invalid xml-rpc. not conforming to spec. Request must be a methodCall');
|
||||
}
|
||||
$result = $this->call($this->message->methodName, $this->message->params);
|
||||
|
||||
// Is the result an error?
|
||||
if (is_a($result, 'IXR_Error')) {
|
||||
$this->error($result);
|
||||
}
|
||||
|
||||
// Encode the result
|
||||
$r = new IXR_Value($result);
|
||||
$resultxml = $r->getXml();
|
||||
|
||||
// Create the XML
|
||||
$xml = <<<EOD
|
||||
<methodResponse>
|
||||
<params>
|
||||
<param>
|
||||
<value>
|
||||
$resultxml
|
||||
</value>
|
||||
</param>
|
||||
</params>
|
||||
</methodResponse>
|
||||
|
||||
EOD;
|
||||
// Send it
|
||||
$this->output($xml);
|
||||
}
|
||||
|
||||
function call($methodname, $args)
|
||||
{
|
||||
if (!$this->hasMethod($methodname)) {
|
||||
return new IXR_Error(-32601, 'server error. requested method '.$methodname.' does not exist.');
|
||||
}
|
||||
$method = $this->callbacks[$methodname];
|
||||
|
||||
// Perform the callback and send the response
|
||||
if (count($args) == 1) {
|
||||
// If only one parameter just send that instead of the whole array
|
||||
$args = $args[0];
|
||||
}
|
||||
|
||||
// Are we dealing with a function or a method?
|
||||
if (is_string($method) && substr($method, 0, 5) == 'this:') {
|
||||
// It's a class method - check it exists
|
||||
$method = substr($method, 5);
|
||||
if (!method_exists($this, $method)) {
|
||||
return new IXR_Error(-32601, 'server error. requested class method "'.$method.'" does not exist.');
|
||||
}
|
||||
|
||||
//Call the method
|
||||
$result = $this->$method($args);
|
||||
} else {
|
||||
// It's a function - does it exist?
|
||||
if (is_array($method)) {
|
||||
if (!is_callable(array($method[0], $method[1]))) {
|
||||
return new IXR_Error(-32601, 'server error. requested object method "'.$method[1].'" does not exist.');
|
||||
}
|
||||
} else if (!function_exists($method)) {
|
||||
return new IXR_Error(-32601, 'server error. requested function "'.$method.'" does not exist.');
|
||||
}
|
||||
|
||||
// Call the function
|
||||
$result = call_user_func($method, $args);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
function error($error, $message = false)
|
||||
{
|
||||
// Accepts either an error object or an error code and message
|
||||
if ($message && !is_object($error)) {
|
||||
$error = new IXR_Error($error, $message);
|
||||
}
|
||||
|
||||
$this->output($error->getXml());
|
||||
}
|
||||
|
||||
function output($xml)
|
||||
{
|
||||
$charset = function_exists('get_option') ? get_option('blog_charset') : '';
|
||||
if ($charset)
|
||||
$xml = '<?xml version="1.0" encoding="'.$charset.'"?>'."\n".$xml;
|
||||
else
|
||||
$xml = '<?xml version="1.0"?>'."\n".$xml;
|
||||
$length = strlen($xml);
|
||||
header('Connection: close');
|
||||
if ($charset)
|
||||
header('Content-Type: text/xml; charset='.$charset);
|
||||
else
|
||||
header('Content-Type: text/xml');
|
||||
header('Date: '.gmdate('r'));
|
||||
echo $xml;
|
||||
exit;
|
||||
}
|
||||
|
||||
function hasMethod($method)
|
||||
{
|
||||
return in_array($method, array_keys($this->callbacks));
|
||||
}
|
||||
|
||||
function setCapabilities()
|
||||
{
|
||||
// Initialises capabilities array
|
||||
$this->capabilities = array(
|
||||
'xmlrpc' => array(
|
||||
'specUrl' => 'http://www.xmlrpc.com/spec',
|
||||
'specVersion' => 1
|
||||
),
|
||||
'faults_interop' => array(
|
||||
'specUrl' => 'http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php',
|
||||
'specVersion' => 20010516
|
||||
),
|
||||
'system.multicall' => array(
|
||||
'specUrl' => 'http://www.xmlrpc.com/discuss/msgReader$1208',
|
||||
'specVersion' => 1
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
function getCapabilities($args)
|
||||
{
|
||||
return $this->capabilities;
|
||||
}
|
||||
|
||||
function setCallbacks()
|
||||
{
|
||||
$this->callbacks['system.getCapabilities'] = 'this:getCapabilities';
|
||||
$this->callbacks['system.listMethods'] = 'this:listMethods';
|
||||
$this->callbacks['system.multicall'] = 'this:multiCall';
|
||||
}
|
||||
|
||||
function listMethods($args)
|
||||
{
|
||||
// Returns a list of methods - uses array_reverse to ensure user defined
|
||||
// methods are listed before server defined methods
|
||||
return array_reverse(array_keys($this->callbacks));
|
||||
}
|
||||
|
||||
function multiCall($methodcalls)
|
||||
{
|
||||
// See http://www.xmlrpc.com/discuss/msgReader$1208
|
||||
$return = array();
|
||||
foreach ($methodcalls as $call) {
|
||||
$method = $call['methodName'];
|
||||
$params = $call['params'];
|
||||
if ($method == 'system.multicall') {
|
||||
$result = new IXR_Error(-32600, 'Recursive calls to system.multicall are forbidden');
|
||||
} else {
|
||||
$result = $this->call($method, $params);
|
||||
}
|
||||
if (is_a($result, 'IXR_Error')) {
|
||||
$return[] = array(
|
||||
'faultCode' => $result->code,
|
||||
'faultString' => $result->message
|
||||
);
|
||||
} else {
|
||||
$return[] = array($result);
|
||||
}
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,138 +1,138 @@
|
||||
<?php
|
||||
/**
|
||||
* IXR_Value
|
||||
*
|
||||
* @package IXR
|
||||
* @since 1.5.0
|
||||
*/
|
||||
class IXR_Value {
|
||||
var $data;
|
||||
var $type;
|
||||
|
||||
/**
|
||||
* PHP5 constructor.
|
||||
*/
|
||||
function __construct( $data, $type = false )
|
||||
{
|
||||
$this->data = $data;
|
||||
if (!$type) {
|
||||
$type = $this->calculateType();
|
||||
}
|
||||
$this->type = $type;
|
||||
if ($type == 'struct') {
|
||||
// Turn all the values in the array in to new IXR_Value objects
|
||||
foreach ($this->data as $key => $value) {
|
||||
$this->data[$key] = new IXR_Value($value);
|
||||
}
|
||||
}
|
||||
if ($type == 'array') {
|
||||
for ($i = 0, $j = count($this->data); $i < $j; $i++) {
|
||||
$this->data[$i] = new IXR_Value($this->data[$i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* PHP4 constructor.
|
||||
*/
|
||||
public function IXR_Value( $data, $type = false ) {
|
||||
self::__construct( $data, $type );
|
||||
}
|
||||
|
||||
function calculateType()
|
||||
{
|
||||
if ($this->data === true || $this->data === false) {
|
||||
return 'boolean';
|
||||
}
|
||||
if (is_integer($this->data)) {
|
||||
return 'int';
|
||||
}
|
||||
if (is_double($this->data)) {
|
||||
return 'double';
|
||||
}
|
||||
|
||||
// Deal with IXR object types base64 and date
|
||||
if (is_object($this->data) && is_a($this->data, 'IXR_Date')) {
|
||||
return 'date';
|
||||
}
|
||||
if (is_object($this->data) && is_a($this->data, 'IXR_Base64')) {
|
||||
return 'base64';
|
||||
}
|
||||
|
||||
// If it is a normal PHP object convert it in to a struct
|
||||
if (is_object($this->data)) {
|
||||
$this->data = get_object_vars($this->data);
|
||||
return 'struct';
|
||||
}
|
||||
if (!is_array($this->data)) {
|
||||
return 'string';
|
||||
}
|
||||
|
||||
// We have an array - is it an array or a struct?
|
||||
if ($this->isStruct($this->data)) {
|
||||
return 'struct';
|
||||
} else {
|
||||
return 'array';
|
||||
}
|
||||
}
|
||||
|
||||
function getXml()
|
||||
{
|
||||
// Return XML for this value
|
||||
switch ($this->type) {
|
||||
case 'boolean':
|
||||
return '<boolean>'.(($this->data) ? '1' : '0').'</boolean>';
|
||||
break;
|
||||
case 'int':
|
||||
return '<int>'.$this->data.'</int>';
|
||||
break;
|
||||
case 'double':
|
||||
return '<double>'.$this->data.'</double>';
|
||||
break;
|
||||
case 'string':
|
||||
return '<string>'.htmlspecialchars($this->data).'</string>';
|
||||
break;
|
||||
case 'array':
|
||||
$return = '<array><data>'."\n";
|
||||
foreach ($this->data as $item) {
|
||||
$return .= ' <value>'.$item->getXml()."</value>\n";
|
||||
}
|
||||
$return .= '</data></array>';
|
||||
return $return;
|
||||
break;
|
||||
case 'struct':
|
||||
$return = '<struct>'."\n";
|
||||
foreach ($this->data as $name => $value) {
|
||||
$name = htmlspecialchars($name);
|
||||
$return .= " <member><name>$name</name><value>";
|
||||
$return .= $value->getXml()."</value></member>\n";
|
||||
}
|
||||
$return .= '</struct>';
|
||||
return $return;
|
||||
break;
|
||||
case 'date':
|
||||
case 'base64':
|
||||
return $this->data->getXml();
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether or not the supplied array is a struct or not
|
||||
*
|
||||
* @param array $array
|
||||
* @return bool
|
||||
*/
|
||||
function isStruct($array)
|
||||
{
|
||||
$expected = 0;
|
||||
foreach ($array as $key => $value) {
|
||||
if ((string)$key !== (string)$expected) {
|
||||
return true;
|
||||
}
|
||||
$expected++;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* IXR_Value
|
||||
*
|
||||
* @package IXR
|
||||
* @since 1.5.0
|
||||
*/
|
||||
class IXR_Value {
|
||||
var $data;
|
||||
var $type;
|
||||
|
||||
/**
|
||||
* PHP5 constructor.
|
||||
*/
|
||||
function __construct( $data, $type = false )
|
||||
{
|
||||
$this->data = $data;
|
||||
if (!$type) {
|
||||
$type = $this->calculateType();
|
||||
}
|
||||
$this->type = $type;
|
||||
if ($type == 'struct') {
|
||||
// Turn all the values in the array in to new IXR_Value objects
|
||||
foreach ($this->data as $key => $value) {
|
||||
$this->data[$key] = new IXR_Value($value);
|
||||
}
|
||||
}
|
||||
if ($type == 'array') {
|
||||
for ($i = 0, $j = count($this->data); $i < $j; $i++) {
|
||||
$this->data[$i] = new IXR_Value($this->data[$i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* PHP4 constructor.
|
||||
*/
|
||||
public function IXR_Value( $data, $type = false ) {
|
||||
self::__construct( $data, $type );
|
||||
}
|
||||
|
||||
function calculateType()
|
||||
{
|
||||
if ($this->data === true || $this->data === false) {
|
||||
return 'boolean';
|
||||
}
|
||||
if (is_integer($this->data)) {
|
||||
return 'int';
|
||||
}
|
||||
if (is_double($this->data)) {
|
||||
return 'double';
|
||||
}
|
||||
|
||||
// Deal with IXR object types base64 and date
|
||||
if (is_object($this->data) && is_a($this->data, 'IXR_Date')) {
|
||||
return 'date';
|
||||
}
|
||||
if (is_object($this->data) && is_a($this->data, 'IXR_Base64')) {
|
||||
return 'base64';
|
||||
}
|
||||
|
||||
// If it is a normal PHP object convert it in to a struct
|
||||
if (is_object($this->data)) {
|
||||
$this->data = get_object_vars($this->data);
|
||||
return 'struct';
|
||||
}
|
||||
if (!is_array($this->data)) {
|
||||
return 'string';
|
||||
}
|
||||
|
||||
// We have an array - is it an array or a struct?
|
||||
if ($this->isStruct($this->data)) {
|
||||
return 'struct';
|
||||
} else {
|
||||
return 'array';
|
||||
}
|
||||
}
|
||||
|
||||
function getXml()
|
||||
{
|
||||
// Return XML for this value
|
||||
switch ($this->type) {
|
||||
case 'boolean':
|
||||
return '<boolean>'.(($this->data) ? '1' : '0').'</boolean>';
|
||||
break;
|
||||
case 'int':
|
||||
return '<int>'.$this->data.'</int>';
|
||||
break;
|
||||
case 'double':
|
||||
return '<double>'.$this->data.'</double>';
|
||||
break;
|
||||
case 'string':
|
||||
return '<string>'.htmlspecialchars($this->data).'</string>';
|
||||
break;
|
||||
case 'array':
|
||||
$return = '<array><data>'."\n";
|
||||
foreach ($this->data as $item) {
|
||||
$return .= ' <value>'.$item->getXml()."</value>\n";
|
||||
}
|
||||
$return .= '</data></array>';
|
||||
return $return;
|
||||
break;
|
||||
case 'struct':
|
||||
$return = '<struct>'."\n";
|
||||
foreach ($this->data as $name => $value) {
|
||||
$name = htmlspecialchars($name);
|
||||
$return .= " <member><name>$name</name><value>";
|
||||
$return .= $value->getXml()."</value></member>\n";
|
||||
}
|
||||
$return .= '</struct>';
|
||||
return $return;
|
||||
break;
|
||||
case 'date':
|
||||
case 'base64':
|
||||
return $this->data->getXml();
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether or not the supplied array is a struct or not
|
||||
*
|
||||
* @param array $array
|
||||
* @return bool
|
||||
*/
|
||||
function isStruct($array)
|
||||
{
|
||||
$expected = 0;
|
||||
foreach ($array as $key => $value) {
|
||||
if ((string)$key !== (string)$expected) {
|
||||
return true;
|
||||
}
|
||||
$expected++;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,40 +1,40 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHPMailer Exception class.
|
||||
* PHP Version 5.5.
|
||||
*
|
||||
* @see https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project
|
||||
*
|
||||
* @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
|
||||
* @author Jim Jagielski (jimjag) <jimjag@gmail.com>
|
||||
* @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
|
||||
* @author Brent R. Matzelle (original founder)
|
||||
* @copyright 2012 - 2020 Marcus Bointon
|
||||
* @copyright 2010 - 2012 Jim Jagielski
|
||||
* @copyright 2004 - 2009 Andy Prevost
|
||||
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
|
||||
* @note This program is distributed in the hope that it will be useful - WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
namespace PHPMailer\PHPMailer;
|
||||
|
||||
/**
|
||||
* PHPMailer exception handler.
|
||||
*
|
||||
* @author Marcus Bointon <phpmailer@synchromedia.co.uk>
|
||||
*/
|
||||
class Exception extends \Exception
|
||||
{
|
||||
/**
|
||||
* Prettify error message output.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function errorMessage()
|
||||
{
|
||||
return '<strong>' . htmlspecialchars($this->getMessage(), ENT_COMPAT | ENT_HTML401) . "</strong><br />\n";
|
||||
}
|
||||
}
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHPMailer Exception class.
|
||||
* PHP Version 5.5.
|
||||
*
|
||||
* @see https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project
|
||||
*
|
||||
* @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
|
||||
* @author Jim Jagielski (jimjag) <jimjag@gmail.com>
|
||||
* @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
|
||||
* @author Brent R. Matzelle (original founder)
|
||||
* @copyright 2012 - 2020 Marcus Bointon
|
||||
* @copyright 2010 - 2012 Jim Jagielski
|
||||
* @copyright 2004 - 2009 Andy Prevost
|
||||
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
|
||||
* @note This program is distributed in the hope that it will be useful - WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
namespace PHPMailer\PHPMailer;
|
||||
|
||||
/**
|
||||
* PHPMailer exception handler.
|
||||
*
|
||||
* @author Marcus Bointon <phpmailer@synchromedia.co.uk>
|
||||
*/
|
||||
class Exception extends \Exception
|
||||
{
|
||||
/**
|
||||
* Prettify error message output.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function errorMessage()
|
||||
{
|
||||
return '<strong>' . htmlspecialchars($this->getMessage(), ENT_COMPAT | ENT_HTML401) . "</strong><br />\n";
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,12 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
* Loads the old Requests class file when the autoloader
|
||||
* references the original PSR-0 Requests class.
|
||||
*
|
||||
* @deprecated 6.2.0
|
||||
* @package WordPress
|
||||
* @subpackage Requests
|
||||
* @since 6.2.0
|
||||
*/
|
||||
|
||||
include_once ABSPATH . WPINC . '/class-requests.php';
|
||||
<?php
|
||||
/**
|
||||
* Loads the old Requests class file when the autoloader
|
||||
* references the original PSR-0 Requests class.
|
||||
*
|
||||
* @deprecated 6.2.0
|
||||
* @package WordPress
|
||||
* @subpackage Requests
|
||||
* @since 6.2.0
|
||||
*/
|
||||
|
||||
include_once ABSPATH . WPINC . '/class-requests.php';
|
||||
|
||||
@@ -1,36 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
* Authentication provider interface
|
||||
*
|
||||
* @package Requests\Authentication
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests;
|
||||
|
||||
use WpOrg\Requests\Hooks;
|
||||
|
||||
/**
|
||||
* Authentication provider interface
|
||||
*
|
||||
* Implement this interface to act as an authentication provider.
|
||||
*
|
||||
* Parameters should be passed via the constructor where possible, as this
|
||||
* makes it much easier for users to use your provider.
|
||||
*
|
||||
* @see \WpOrg\Requests\Hooks
|
||||
*
|
||||
* @package Requests\Authentication
|
||||
*/
|
||||
interface Auth {
|
||||
/**
|
||||
* Register hooks as needed
|
||||
*
|
||||
* This method is called in {@see \WpOrg\Requests\Requests::request()} when the user
|
||||
* has set an instance as the 'auth' option. Use this callback to register all the
|
||||
* hooks you'll need.
|
||||
*
|
||||
* @see \WpOrg\Requests\Hooks::register()
|
||||
* @param \WpOrg\Requests\Hooks $hooks Hook system
|
||||
*/
|
||||
public function register(Hooks $hooks);
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Authentication provider interface
|
||||
*
|
||||
* @package Requests\Authentication
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests;
|
||||
|
||||
use WpOrg\Requests\Hooks;
|
||||
|
||||
/**
|
||||
* Authentication provider interface
|
||||
*
|
||||
* Implement this interface to act as an authentication provider.
|
||||
*
|
||||
* Parameters should be passed via the constructor where possible, as this
|
||||
* makes it much easier for users to use your provider.
|
||||
*
|
||||
* @see \WpOrg\Requests\Hooks
|
||||
*
|
||||
* @package Requests\Authentication
|
||||
*/
|
||||
interface Auth {
|
||||
/**
|
||||
* Register hooks as needed
|
||||
*
|
||||
* This method is called in {@see \WpOrg\Requests\Requests::request()} when the user
|
||||
* has set an instance as the 'auth' option. Use this callback to register all the
|
||||
* hooks you'll need.
|
||||
*
|
||||
* @see \WpOrg\Requests\Hooks::register()
|
||||
* @param \WpOrg\Requests\Hooks $hooks Hook system
|
||||
*/
|
||||
public function register(Hooks $hooks);
|
||||
}
|
||||
|
||||
@@ -1,103 +1,103 @@
|
||||
<?php
|
||||
/**
|
||||
* Basic Authentication provider
|
||||
*
|
||||
* @package Requests\Authentication
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Auth;
|
||||
|
||||
use WpOrg\Requests\Auth;
|
||||
use WpOrg\Requests\Exception\ArgumentCount;
|
||||
use WpOrg\Requests\Exception\InvalidArgument;
|
||||
use WpOrg\Requests\Hooks;
|
||||
|
||||
/**
|
||||
* Basic Authentication provider
|
||||
*
|
||||
* Provides a handler for Basic HTTP authentication via the Authorization
|
||||
* header.
|
||||
*
|
||||
* @package Requests\Authentication
|
||||
*/
|
||||
class Basic implements Auth {
|
||||
/**
|
||||
* Username
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $user;
|
||||
|
||||
/**
|
||||
* Password
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $pass;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @since 2.0 Throws an `InvalidArgument` exception.
|
||||
* @since 2.0 Throws an `ArgumentCount` exception instead of the Requests base `Exception.
|
||||
*
|
||||
* @param array|null $args Array of user and password. Must have exactly two elements
|
||||
*
|
||||
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed argument is not an array or null.
|
||||
* @throws \WpOrg\Requests\Exception\ArgumentCount On incorrect number of array elements (`authbasicbadargs`).
|
||||
*/
|
||||
public function __construct($args = null) {
|
||||
if (is_array($args)) {
|
||||
if (count($args) !== 2) {
|
||||
throw ArgumentCount::create('an array with exactly two elements', count($args), 'authbasicbadargs');
|
||||
}
|
||||
|
||||
list($this->user, $this->pass) = $args;
|
||||
return;
|
||||
}
|
||||
|
||||
if ($args !== null) {
|
||||
throw InvalidArgument::create(1, '$args', 'array|null', gettype($args));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the necessary callbacks
|
||||
*
|
||||
* @see \WpOrg\Requests\Auth\Basic::curl_before_send()
|
||||
* @see \WpOrg\Requests\Auth\Basic::fsockopen_header()
|
||||
* @param \WpOrg\Requests\Hooks $hooks Hook system
|
||||
*/
|
||||
public function register(Hooks $hooks) {
|
||||
$hooks->register('curl.before_send', [$this, 'curl_before_send']);
|
||||
$hooks->register('fsockopen.after_headers', [$this, 'fsockopen_header']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set cURL parameters before the data is sent
|
||||
*
|
||||
* @param resource|\CurlHandle $handle cURL handle
|
||||
*/
|
||||
public function curl_before_send(&$handle) {
|
||||
curl_setopt($handle, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
|
||||
curl_setopt($handle, CURLOPT_USERPWD, $this->getAuthString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Add extra headers to the request before sending
|
||||
*
|
||||
* @param string $out HTTP header string
|
||||
*/
|
||||
public function fsockopen_header(&$out) {
|
||||
$out .= sprintf("Authorization: Basic %s\r\n", base64_encode($this->getAuthString()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the authentication string (user:pass)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAuthString() {
|
||||
return $this->user . ':' . $this->pass;
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Basic Authentication provider
|
||||
*
|
||||
* @package Requests\Authentication
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Auth;
|
||||
|
||||
use WpOrg\Requests\Auth;
|
||||
use WpOrg\Requests\Exception\ArgumentCount;
|
||||
use WpOrg\Requests\Exception\InvalidArgument;
|
||||
use WpOrg\Requests\Hooks;
|
||||
|
||||
/**
|
||||
* Basic Authentication provider
|
||||
*
|
||||
* Provides a handler for Basic HTTP authentication via the Authorization
|
||||
* header.
|
||||
*
|
||||
* @package Requests\Authentication
|
||||
*/
|
||||
class Basic implements Auth {
|
||||
/**
|
||||
* Username
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $user;
|
||||
|
||||
/**
|
||||
* Password
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $pass;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @since 2.0 Throws an `InvalidArgument` exception.
|
||||
* @since 2.0 Throws an `ArgumentCount` exception instead of the Requests base `Exception.
|
||||
*
|
||||
* @param array|null $args Array of user and password. Must have exactly two elements
|
||||
*
|
||||
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed argument is not an array or null.
|
||||
* @throws \WpOrg\Requests\Exception\ArgumentCount On incorrect number of array elements (`authbasicbadargs`).
|
||||
*/
|
||||
public function __construct($args = null) {
|
||||
if (is_array($args)) {
|
||||
if (count($args) !== 2) {
|
||||
throw ArgumentCount::create('an array with exactly two elements', count($args), 'authbasicbadargs');
|
||||
}
|
||||
|
||||
list($this->user, $this->pass) = $args;
|
||||
return;
|
||||
}
|
||||
|
||||
if ($args !== null) {
|
||||
throw InvalidArgument::create(1, '$args', 'array|null', gettype($args));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the necessary callbacks
|
||||
*
|
||||
* @see \WpOrg\Requests\Auth\Basic::curl_before_send()
|
||||
* @see \WpOrg\Requests\Auth\Basic::fsockopen_header()
|
||||
* @param \WpOrg\Requests\Hooks $hooks Hook system
|
||||
*/
|
||||
public function register(Hooks $hooks) {
|
||||
$hooks->register('curl.before_send', [$this, 'curl_before_send']);
|
||||
$hooks->register('fsockopen.after_headers', [$this, 'fsockopen_header']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set cURL parameters before the data is sent
|
||||
*
|
||||
* @param resource|\CurlHandle $handle cURL handle
|
||||
*/
|
||||
public function curl_before_send(&$handle) {
|
||||
curl_setopt($handle, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
|
||||
curl_setopt($handle, CURLOPT_USERPWD, $this->getAuthString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Add extra headers to the request before sending
|
||||
*
|
||||
* @param string $out HTTP header string
|
||||
*/
|
||||
public function fsockopen_header(&$out) {
|
||||
$out .= sprintf("Authorization: Basic %s\r\n", base64_encode($this->getAuthString()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the authentication string (user:pass)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAuthString() {
|
||||
return $this->user . ':' . $this->pass;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,187 +1,187 @@
|
||||
<?php
|
||||
/**
|
||||
* Autoloader for Requests for PHP.
|
||||
*
|
||||
* Include this file if you'd like to avoid having to create your own autoloader.
|
||||
*
|
||||
* @package Requests
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests;
|
||||
|
||||
/*
|
||||
* Ensure the autoloader is only declared once.
|
||||
* This safeguard is in place as this is the typical entry point for this library
|
||||
* and this file being required unconditionally could easily cause
|
||||
* fatal "Class already declared" errors.
|
||||
*/
|
||||
if (class_exists('WpOrg\Requests\Autoload') === false) {
|
||||
|
||||
/**
|
||||
* Autoloader for Requests for PHP.
|
||||
*
|
||||
* This autoloader supports the PSR-4 based Requests 2.0.0 classes in a case-sensitive manner
|
||||
* as the most common server OS-es are case-sensitive and the file names are in mixed case.
|
||||
*
|
||||
* For the PSR-0 Requests 1.x BC-layer, requested classes will be treated case-insensitively.
|
||||
*
|
||||
* @package Requests
|
||||
*/
|
||||
final class Autoload {
|
||||
|
||||
/**
|
||||
* List of the old PSR-0 class names in lowercase as keys with their PSR-4 case-sensitive name as a value.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $deprecated_classes = [
|
||||
// Interfaces.
|
||||
'requests_auth' => '\WpOrg\Requests\Auth',
|
||||
'requests_hooker' => '\WpOrg\Requests\HookManager',
|
||||
'requests_proxy' => '\WpOrg\Requests\Proxy',
|
||||
'requests_transport' => '\WpOrg\Requests\Transport',
|
||||
|
||||
// Classes.
|
||||
'requests_cookie' => '\WpOrg\Requests\Cookie',
|
||||
'requests_exception' => '\WpOrg\Requests\Exception',
|
||||
'requests_hooks' => '\WpOrg\Requests\Hooks',
|
||||
'requests_idnaencoder' => '\WpOrg\Requests\IdnaEncoder',
|
||||
'requests_ipv6' => '\WpOrg\Requests\Ipv6',
|
||||
'requests_iri' => '\WpOrg\Requests\Iri',
|
||||
'requests_response' => '\WpOrg\Requests\Response',
|
||||
'requests_session' => '\WpOrg\Requests\Session',
|
||||
'requests_ssl' => '\WpOrg\Requests\Ssl',
|
||||
'requests_auth_basic' => '\WpOrg\Requests\Auth\Basic',
|
||||
'requests_cookie_jar' => '\WpOrg\Requests\Cookie\Jar',
|
||||
'requests_proxy_http' => '\WpOrg\Requests\Proxy\Http',
|
||||
'requests_response_headers' => '\WpOrg\Requests\Response\Headers',
|
||||
'requests_transport_curl' => '\WpOrg\Requests\Transport\Curl',
|
||||
'requests_transport_fsockopen' => '\WpOrg\Requests\Transport\Fsockopen',
|
||||
'requests_utility_caseinsensitivedictionary' => '\WpOrg\Requests\Utility\CaseInsensitiveDictionary',
|
||||
'requests_utility_filterediterator' => '\WpOrg\Requests\Utility\FilteredIterator',
|
||||
'requests_exception_http' => '\WpOrg\Requests\Exception\Http',
|
||||
'requests_exception_transport' => '\WpOrg\Requests\Exception\Transport',
|
||||
'requests_exception_transport_curl' => '\WpOrg\Requests\Exception\Transport\Curl',
|
||||
'requests_exception_http_304' => '\WpOrg\Requests\Exception\Http\Status304',
|
||||
'requests_exception_http_305' => '\WpOrg\Requests\Exception\Http\Status305',
|
||||
'requests_exception_http_306' => '\WpOrg\Requests\Exception\Http\Status306',
|
||||
'requests_exception_http_400' => '\WpOrg\Requests\Exception\Http\Status400',
|
||||
'requests_exception_http_401' => '\WpOrg\Requests\Exception\Http\Status401',
|
||||
'requests_exception_http_402' => '\WpOrg\Requests\Exception\Http\Status402',
|
||||
'requests_exception_http_403' => '\WpOrg\Requests\Exception\Http\Status403',
|
||||
'requests_exception_http_404' => '\WpOrg\Requests\Exception\Http\Status404',
|
||||
'requests_exception_http_405' => '\WpOrg\Requests\Exception\Http\Status405',
|
||||
'requests_exception_http_406' => '\WpOrg\Requests\Exception\Http\Status406',
|
||||
'requests_exception_http_407' => '\WpOrg\Requests\Exception\Http\Status407',
|
||||
'requests_exception_http_408' => '\WpOrg\Requests\Exception\Http\Status408',
|
||||
'requests_exception_http_409' => '\WpOrg\Requests\Exception\Http\Status409',
|
||||
'requests_exception_http_410' => '\WpOrg\Requests\Exception\Http\Status410',
|
||||
'requests_exception_http_411' => '\WpOrg\Requests\Exception\Http\Status411',
|
||||
'requests_exception_http_412' => '\WpOrg\Requests\Exception\Http\Status412',
|
||||
'requests_exception_http_413' => '\WpOrg\Requests\Exception\Http\Status413',
|
||||
'requests_exception_http_414' => '\WpOrg\Requests\Exception\Http\Status414',
|
||||
'requests_exception_http_415' => '\WpOrg\Requests\Exception\Http\Status415',
|
||||
'requests_exception_http_416' => '\WpOrg\Requests\Exception\Http\Status416',
|
||||
'requests_exception_http_417' => '\WpOrg\Requests\Exception\Http\Status417',
|
||||
'requests_exception_http_418' => '\WpOrg\Requests\Exception\Http\Status418',
|
||||
'requests_exception_http_428' => '\WpOrg\Requests\Exception\Http\Status428',
|
||||
'requests_exception_http_429' => '\WpOrg\Requests\Exception\Http\Status429',
|
||||
'requests_exception_http_431' => '\WpOrg\Requests\Exception\Http\Status431',
|
||||
'requests_exception_http_500' => '\WpOrg\Requests\Exception\Http\Status500',
|
||||
'requests_exception_http_501' => '\WpOrg\Requests\Exception\Http\Status501',
|
||||
'requests_exception_http_502' => '\WpOrg\Requests\Exception\Http\Status502',
|
||||
'requests_exception_http_503' => '\WpOrg\Requests\Exception\Http\Status503',
|
||||
'requests_exception_http_504' => '\WpOrg\Requests\Exception\Http\Status504',
|
||||
'requests_exception_http_505' => '\WpOrg\Requests\Exception\Http\Status505',
|
||||
'requests_exception_http_511' => '\WpOrg\Requests\Exception\Http\Status511',
|
||||
'requests_exception_http_unknown' => '\WpOrg\Requests\Exception\Http\StatusUnknown',
|
||||
];
|
||||
|
||||
/**
|
||||
* Register the autoloader.
|
||||
*
|
||||
* Note: the autoloader is *prepended* in the autoload queue.
|
||||
* This is done to ensure that the Requests 2.0 autoloader takes precedence
|
||||
* over a potentially (dependency-registered) Requests 1.x autoloader.
|
||||
*
|
||||
* @internal This method contains a safeguard against the autoloader being
|
||||
* registered multiple times. This safeguard uses a global constant to
|
||||
* (hopefully/in most cases) still function correctly, even if the
|
||||
* class would be renamed.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function register() {
|
||||
if (defined('REQUESTS_AUTOLOAD_REGISTERED') === false) {
|
||||
spl_autoload_register([self::class, 'load'], true);
|
||||
define('REQUESTS_AUTOLOAD_REGISTERED', true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Autoloader.
|
||||
*
|
||||
* @param string $class_name Name of the class name to load.
|
||||
*
|
||||
* @return bool Whether a class was loaded or not.
|
||||
*/
|
||||
public static function load($class_name) {
|
||||
// Check that the class starts with "Requests" (PSR-0) or "WpOrg\Requests" (PSR-4).
|
||||
$psr_4_prefix_pos = strpos($class_name, 'WpOrg\\Requests\\');
|
||||
|
||||
if (stripos($class_name, 'Requests') !== 0 && $psr_4_prefix_pos !== 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$class_lower = strtolower($class_name);
|
||||
|
||||
if ($class_lower === 'requests') {
|
||||
// Reference to the original PSR-0 Requests class.
|
||||
$file = dirname(__DIR__) . '/library/Requests.php';
|
||||
} elseif ($psr_4_prefix_pos === 0) {
|
||||
// PSR-4 classname.
|
||||
$file = __DIR__ . '/' . strtr(substr($class_name, 15), '\\', '/') . '.php';
|
||||
}
|
||||
|
||||
if (isset($file) && file_exists($file)) {
|
||||
include $file;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Okay, so the class starts with "Requests", but we couldn't find the file.
|
||||
* If this is one of the deprecated/renamed PSR-0 classes being requested,
|
||||
* let's alias it to the new name and throw a deprecation notice.
|
||||
*/
|
||||
if (isset(self::$deprecated_classes[$class_lower])) {
|
||||
/*
|
||||
* Integrators who cannot yet upgrade to the PSR-4 class names can silence deprecations
|
||||
* by defining a `REQUESTS_SILENCE_PSR0_DEPRECATIONS` constant and setting it to `true`.
|
||||
* The constant needs to be defined before the first deprecated class is requested
|
||||
* via this autoloader.
|
||||
*/
|
||||
if (!defined('REQUESTS_SILENCE_PSR0_DEPRECATIONS') || REQUESTS_SILENCE_PSR0_DEPRECATIONS !== true) {
|
||||
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error
|
||||
trigger_error(
|
||||
'The PSR-0 `Requests_...` class names in the Requests library are deprecated.'
|
||||
. ' Switch to the PSR-4 `WpOrg\Requests\...` class names at your earliest convenience.',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
|
||||
// Prevent the deprecation notice from being thrown twice.
|
||||
if (!defined('REQUESTS_SILENCE_PSR0_DEPRECATIONS')) {
|
||||
define('REQUESTS_SILENCE_PSR0_DEPRECATIONS', true);
|
||||
}
|
||||
}
|
||||
|
||||
// Create an alias and let the autoloader recursively kick in to load the PSR-4 class.
|
||||
return class_alias(self::$deprecated_classes[$class_lower], $class_name, true);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Autoloader for Requests for PHP.
|
||||
*
|
||||
* Include this file if you'd like to avoid having to create your own autoloader.
|
||||
*
|
||||
* @package Requests
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests;
|
||||
|
||||
/*
|
||||
* Ensure the autoloader is only declared once.
|
||||
* This safeguard is in place as this is the typical entry point for this library
|
||||
* and this file being required unconditionally could easily cause
|
||||
* fatal "Class already declared" errors.
|
||||
*/
|
||||
if (class_exists('WpOrg\Requests\Autoload') === false) {
|
||||
|
||||
/**
|
||||
* Autoloader for Requests for PHP.
|
||||
*
|
||||
* This autoloader supports the PSR-4 based Requests 2.0.0 classes in a case-sensitive manner
|
||||
* as the most common server OS-es are case-sensitive and the file names are in mixed case.
|
||||
*
|
||||
* For the PSR-0 Requests 1.x BC-layer, requested classes will be treated case-insensitively.
|
||||
*
|
||||
* @package Requests
|
||||
*/
|
||||
final class Autoload {
|
||||
|
||||
/**
|
||||
* List of the old PSR-0 class names in lowercase as keys with their PSR-4 case-sensitive name as a value.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $deprecated_classes = [
|
||||
// Interfaces.
|
||||
'requests_auth' => '\WpOrg\Requests\Auth',
|
||||
'requests_hooker' => '\WpOrg\Requests\HookManager',
|
||||
'requests_proxy' => '\WpOrg\Requests\Proxy',
|
||||
'requests_transport' => '\WpOrg\Requests\Transport',
|
||||
|
||||
// Classes.
|
||||
'requests_cookie' => '\WpOrg\Requests\Cookie',
|
||||
'requests_exception' => '\WpOrg\Requests\Exception',
|
||||
'requests_hooks' => '\WpOrg\Requests\Hooks',
|
||||
'requests_idnaencoder' => '\WpOrg\Requests\IdnaEncoder',
|
||||
'requests_ipv6' => '\WpOrg\Requests\Ipv6',
|
||||
'requests_iri' => '\WpOrg\Requests\Iri',
|
||||
'requests_response' => '\WpOrg\Requests\Response',
|
||||
'requests_session' => '\WpOrg\Requests\Session',
|
||||
'requests_ssl' => '\WpOrg\Requests\Ssl',
|
||||
'requests_auth_basic' => '\WpOrg\Requests\Auth\Basic',
|
||||
'requests_cookie_jar' => '\WpOrg\Requests\Cookie\Jar',
|
||||
'requests_proxy_http' => '\WpOrg\Requests\Proxy\Http',
|
||||
'requests_response_headers' => '\WpOrg\Requests\Response\Headers',
|
||||
'requests_transport_curl' => '\WpOrg\Requests\Transport\Curl',
|
||||
'requests_transport_fsockopen' => '\WpOrg\Requests\Transport\Fsockopen',
|
||||
'requests_utility_caseinsensitivedictionary' => '\WpOrg\Requests\Utility\CaseInsensitiveDictionary',
|
||||
'requests_utility_filterediterator' => '\WpOrg\Requests\Utility\FilteredIterator',
|
||||
'requests_exception_http' => '\WpOrg\Requests\Exception\Http',
|
||||
'requests_exception_transport' => '\WpOrg\Requests\Exception\Transport',
|
||||
'requests_exception_transport_curl' => '\WpOrg\Requests\Exception\Transport\Curl',
|
||||
'requests_exception_http_304' => '\WpOrg\Requests\Exception\Http\Status304',
|
||||
'requests_exception_http_305' => '\WpOrg\Requests\Exception\Http\Status305',
|
||||
'requests_exception_http_306' => '\WpOrg\Requests\Exception\Http\Status306',
|
||||
'requests_exception_http_400' => '\WpOrg\Requests\Exception\Http\Status400',
|
||||
'requests_exception_http_401' => '\WpOrg\Requests\Exception\Http\Status401',
|
||||
'requests_exception_http_402' => '\WpOrg\Requests\Exception\Http\Status402',
|
||||
'requests_exception_http_403' => '\WpOrg\Requests\Exception\Http\Status403',
|
||||
'requests_exception_http_404' => '\WpOrg\Requests\Exception\Http\Status404',
|
||||
'requests_exception_http_405' => '\WpOrg\Requests\Exception\Http\Status405',
|
||||
'requests_exception_http_406' => '\WpOrg\Requests\Exception\Http\Status406',
|
||||
'requests_exception_http_407' => '\WpOrg\Requests\Exception\Http\Status407',
|
||||
'requests_exception_http_408' => '\WpOrg\Requests\Exception\Http\Status408',
|
||||
'requests_exception_http_409' => '\WpOrg\Requests\Exception\Http\Status409',
|
||||
'requests_exception_http_410' => '\WpOrg\Requests\Exception\Http\Status410',
|
||||
'requests_exception_http_411' => '\WpOrg\Requests\Exception\Http\Status411',
|
||||
'requests_exception_http_412' => '\WpOrg\Requests\Exception\Http\Status412',
|
||||
'requests_exception_http_413' => '\WpOrg\Requests\Exception\Http\Status413',
|
||||
'requests_exception_http_414' => '\WpOrg\Requests\Exception\Http\Status414',
|
||||
'requests_exception_http_415' => '\WpOrg\Requests\Exception\Http\Status415',
|
||||
'requests_exception_http_416' => '\WpOrg\Requests\Exception\Http\Status416',
|
||||
'requests_exception_http_417' => '\WpOrg\Requests\Exception\Http\Status417',
|
||||
'requests_exception_http_418' => '\WpOrg\Requests\Exception\Http\Status418',
|
||||
'requests_exception_http_428' => '\WpOrg\Requests\Exception\Http\Status428',
|
||||
'requests_exception_http_429' => '\WpOrg\Requests\Exception\Http\Status429',
|
||||
'requests_exception_http_431' => '\WpOrg\Requests\Exception\Http\Status431',
|
||||
'requests_exception_http_500' => '\WpOrg\Requests\Exception\Http\Status500',
|
||||
'requests_exception_http_501' => '\WpOrg\Requests\Exception\Http\Status501',
|
||||
'requests_exception_http_502' => '\WpOrg\Requests\Exception\Http\Status502',
|
||||
'requests_exception_http_503' => '\WpOrg\Requests\Exception\Http\Status503',
|
||||
'requests_exception_http_504' => '\WpOrg\Requests\Exception\Http\Status504',
|
||||
'requests_exception_http_505' => '\WpOrg\Requests\Exception\Http\Status505',
|
||||
'requests_exception_http_511' => '\WpOrg\Requests\Exception\Http\Status511',
|
||||
'requests_exception_http_unknown' => '\WpOrg\Requests\Exception\Http\StatusUnknown',
|
||||
];
|
||||
|
||||
/**
|
||||
* Register the autoloader.
|
||||
*
|
||||
* Note: the autoloader is *prepended* in the autoload queue.
|
||||
* This is done to ensure that the Requests 2.0 autoloader takes precedence
|
||||
* over a potentially (dependency-registered) Requests 1.x autoloader.
|
||||
*
|
||||
* @internal This method contains a safeguard against the autoloader being
|
||||
* registered multiple times. This safeguard uses a global constant to
|
||||
* (hopefully/in most cases) still function correctly, even if the
|
||||
* class would be renamed.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function register() {
|
||||
if (defined('REQUESTS_AUTOLOAD_REGISTERED') === false) {
|
||||
spl_autoload_register([self::class, 'load'], true);
|
||||
define('REQUESTS_AUTOLOAD_REGISTERED', true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Autoloader.
|
||||
*
|
||||
* @param string $class_name Name of the class name to load.
|
||||
*
|
||||
* @return bool Whether a class was loaded or not.
|
||||
*/
|
||||
public static function load($class_name) {
|
||||
// Check that the class starts with "Requests" (PSR-0) or "WpOrg\Requests" (PSR-4).
|
||||
$psr_4_prefix_pos = strpos($class_name, 'WpOrg\\Requests\\');
|
||||
|
||||
if (stripos($class_name, 'Requests') !== 0 && $psr_4_prefix_pos !== 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$class_lower = strtolower($class_name);
|
||||
|
||||
if ($class_lower === 'requests') {
|
||||
// Reference to the original PSR-0 Requests class.
|
||||
$file = dirname(__DIR__) . '/library/Requests.php';
|
||||
} elseif ($psr_4_prefix_pos === 0) {
|
||||
// PSR-4 classname.
|
||||
$file = __DIR__ . '/' . strtr(substr($class_name, 15), '\\', '/') . '.php';
|
||||
}
|
||||
|
||||
if (isset($file) && file_exists($file)) {
|
||||
include $file;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Okay, so the class starts with "Requests", but we couldn't find the file.
|
||||
* If this is one of the deprecated/renamed PSR-0 classes being requested,
|
||||
* let's alias it to the new name and throw a deprecation notice.
|
||||
*/
|
||||
if (isset(self::$deprecated_classes[$class_lower])) {
|
||||
/*
|
||||
* Integrators who cannot yet upgrade to the PSR-4 class names can silence deprecations
|
||||
* by defining a `REQUESTS_SILENCE_PSR0_DEPRECATIONS` constant and setting it to `true`.
|
||||
* The constant needs to be defined before the first deprecated class is requested
|
||||
* via this autoloader.
|
||||
*/
|
||||
if (!defined('REQUESTS_SILENCE_PSR0_DEPRECATIONS') || REQUESTS_SILENCE_PSR0_DEPRECATIONS !== true) {
|
||||
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error
|
||||
trigger_error(
|
||||
'The PSR-0 `Requests_...` class names in the Requests library are deprecated.'
|
||||
. ' Switch to the PSR-4 `WpOrg\Requests\...` class names at your earliest convenience.',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
|
||||
// Prevent the deprecation notice from being thrown twice.
|
||||
if (!defined('REQUESTS_SILENCE_PSR0_DEPRECATIONS')) {
|
||||
define('REQUESTS_SILENCE_PSR0_DEPRECATIONS', true);
|
||||
}
|
||||
}
|
||||
|
||||
// Create an alias and let the autoloader recursively kick in to load the PSR-4 class.
|
||||
return class_alias(self::$deprecated_classes[$class_lower], $class_name, true);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,36 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
* Capability interface declaring the known capabilities.
|
||||
*
|
||||
* @package Requests\Utilities
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests;
|
||||
|
||||
/**
|
||||
* Capability interface declaring the known capabilities.
|
||||
*
|
||||
* This is used as the authoritative source for which capabilities can be queried.
|
||||
*
|
||||
* @package Requests\Utilities
|
||||
*/
|
||||
interface Capability {
|
||||
|
||||
/**
|
||||
* Support for SSL.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const SSL = 'ssl';
|
||||
|
||||
/**
|
||||
* Collection of all capabilities supported in Requests.
|
||||
*
|
||||
* Note: this does not automatically mean that the capability will be supported for your chosen transport!
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
const ALL = [
|
||||
self::SSL,
|
||||
];
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Capability interface declaring the known capabilities.
|
||||
*
|
||||
* @package Requests\Utilities
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests;
|
||||
|
||||
/**
|
||||
* Capability interface declaring the known capabilities.
|
||||
*
|
||||
* This is used as the authoritative source for which capabilities can be queried.
|
||||
*
|
||||
* @package Requests\Utilities
|
||||
*/
|
||||
interface Capability {
|
||||
|
||||
/**
|
||||
* Support for SSL.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const SSL = 'ssl';
|
||||
|
||||
/**
|
||||
* Collection of all capabilities supported in Requests.
|
||||
*
|
||||
* Note: this does not automatically mean that the capability will be supported for your chosen transport!
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
const ALL = [
|
||||
self::SSL,
|
||||
];
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,187 +1,187 @@
|
||||
<?php
|
||||
/**
|
||||
* Cookie holder object
|
||||
*
|
||||
* @package Requests\Cookies
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Cookie;
|
||||
|
||||
use ArrayAccess;
|
||||
use ArrayIterator;
|
||||
use IteratorAggregate;
|
||||
use ReturnTypeWillChange;
|
||||
use WpOrg\Requests\Cookie;
|
||||
use WpOrg\Requests\Exception;
|
||||
use WpOrg\Requests\Exception\InvalidArgument;
|
||||
use WpOrg\Requests\HookManager;
|
||||
use WpOrg\Requests\Iri;
|
||||
use WpOrg\Requests\Response;
|
||||
|
||||
/**
|
||||
* Cookie holder object
|
||||
*
|
||||
* @package Requests\Cookies
|
||||
*/
|
||||
class Jar implements ArrayAccess, IteratorAggregate {
|
||||
/**
|
||||
* Actual item data
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $cookies = [];
|
||||
|
||||
/**
|
||||
* Create a new jar
|
||||
*
|
||||
* @param array $cookies Existing cookie values
|
||||
*
|
||||
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed argument is not an array.
|
||||
*/
|
||||
public function __construct($cookies = []) {
|
||||
if (is_array($cookies) === false) {
|
||||
throw InvalidArgument::create(1, '$cookies', 'array', gettype($cookies));
|
||||
}
|
||||
|
||||
$this->cookies = $cookies;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalise cookie data into a \WpOrg\Requests\Cookie
|
||||
*
|
||||
* @param string|\WpOrg\Requests\Cookie $cookie Cookie header value, possibly pre-parsed (object).
|
||||
* @param string $key Optional. The name for this cookie.
|
||||
* @return \WpOrg\Requests\Cookie
|
||||
*/
|
||||
public function normalize_cookie($cookie, $key = '') {
|
||||
if ($cookie instanceof Cookie) {
|
||||
return $cookie;
|
||||
}
|
||||
|
||||
return Cookie::parse($cookie, $key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given item exists
|
||||
*
|
||||
* @param string $offset Item key
|
||||
* @return boolean Does the item exist?
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function offsetExists($offset) {
|
||||
return isset($this->cookies[$offset]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value for the item
|
||||
*
|
||||
* @param string $offset Item key
|
||||
* @return string|null Item value (null if offsetExists is false)
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function offsetGet($offset) {
|
||||
if (!isset($this->cookies[$offset])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->cookies[$offset];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the given item
|
||||
*
|
||||
* @param string $offset Item name
|
||||
* @param string $value Item value
|
||||
*
|
||||
* @throws \WpOrg\Requests\Exception On attempting to use dictionary as list (`invalidset`)
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function offsetSet($offset, $value) {
|
||||
if ($offset === null) {
|
||||
throw new Exception('Object is a dictionary, not a list', 'invalidset');
|
||||
}
|
||||
|
||||
$this->cookies[$offset] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unset the given header
|
||||
*
|
||||
* @param string $offset The key for the item to unset.
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function offsetUnset($offset) {
|
||||
unset($this->cookies[$offset]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an iterator for the data
|
||||
*
|
||||
* @return \ArrayIterator
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function getIterator() {
|
||||
return new ArrayIterator($this->cookies);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the cookie handler with the request's hooking system
|
||||
*
|
||||
* @param \WpOrg\Requests\HookManager $hooks Hooking system
|
||||
*/
|
||||
public function register(HookManager $hooks) {
|
||||
$hooks->register('requests.before_request', [$this, 'before_request']);
|
||||
$hooks->register('requests.before_redirect_check', [$this, 'before_redirect_check']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Cookie header to a request if we have any
|
||||
*
|
||||
* As per RFC 6265, cookies are separated by '; '
|
||||
*
|
||||
* @param string $url
|
||||
* @param array $headers
|
||||
* @param array $data
|
||||
* @param string $type
|
||||
* @param array $options
|
||||
*/
|
||||
public function before_request($url, &$headers, &$data, &$type, &$options) {
|
||||
if (!$url instanceof Iri) {
|
||||
$url = new Iri($url);
|
||||
}
|
||||
|
||||
if (!empty($this->cookies)) {
|
||||
$cookies = [];
|
||||
foreach ($this->cookies as $key => $cookie) {
|
||||
$cookie = $this->normalize_cookie($cookie, $key);
|
||||
|
||||
// Skip expired cookies
|
||||
if ($cookie->is_expired()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($cookie->domain_matches($url->host)) {
|
||||
$cookies[] = $cookie->format_for_header();
|
||||
}
|
||||
}
|
||||
|
||||
$headers['Cookie'] = implode('; ', $cookies);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse all cookies from a response and attach them to the response
|
||||
*
|
||||
* @param \WpOrg\Requests\Response $response Response as received.
|
||||
*/
|
||||
public function before_redirect_check(Response $response) {
|
||||
$url = $response->url;
|
||||
if (!$url instanceof Iri) {
|
||||
$url = new Iri($url);
|
||||
}
|
||||
|
||||
$cookies = Cookie::parse_from_headers($response->headers, $url);
|
||||
$this->cookies = array_merge($this->cookies, $cookies);
|
||||
$response->cookies = $this;
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Cookie holder object
|
||||
*
|
||||
* @package Requests\Cookies
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Cookie;
|
||||
|
||||
use ArrayAccess;
|
||||
use ArrayIterator;
|
||||
use IteratorAggregate;
|
||||
use ReturnTypeWillChange;
|
||||
use WpOrg\Requests\Cookie;
|
||||
use WpOrg\Requests\Exception;
|
||||
use WpOrg\Requests\Exception\InvalidArgument;
|
||||
use WpOrg\Requests\HookManager;
|
||||
use WpOrg\Requests\Iri;
|
||||
use WpOrg\Requests\Response;
|
||||
|
||||
/**
|
||||
* Cookie holder object
|
||||
*
|
||||
* @package Requests\Cookies
|
||||
*/
|
||||
class Jar implements ArrayAccess, IteratorAggregate {
|
||||
/**
|
||||
* Actual item data
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $cookies = [];
|
||||
|
||||
/**
|
||||
* Create a new jar
|
||||
*
|
||||
* @param array $cookies Existing cookie values
|
||||
*
|
||||
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed argument is not an array.
|
||||
*/
|
||||
public function __construct($cookies = []) {
|
||||
if (is_array($cookies) === false) {
|
||||
throw InvalidArgument::create(1, '$cookies', 'array', gettype($cookies));
|
||||
}
|
||||
|
||||
$this->cookies = $cookies;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalise cookie data into a \WpOrg\Requests\Cookie
|
||||
*
|
||||
* @param string|\WpOrg\Requests\Cookie $cookie Cookie header value, possibly pre-parsed (object).
|
||||
* @param string $key Optional. The name for this cookie.
|
||||
* @return \WpOrg\Requests\Cookie
|
||||
*/
|
||||
public function normalize_cookie($cookie, $key = '') {
|
||||
if ($cookie instanceof Cookie) {
|
||||
return $cookie;
|
||||
}
|
||||
|
||||
return Cookie::parse($cookie, $key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given item exists
|
||||
*
|
||||
* @param string $offset Item key
|
||||
* @return boolean Does the item exist?
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function offsetExists($offset) {
|
||||
return isset($this->cookies[$offset]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value for the item
|
||||
*
|
||||
* @param string $offset Item key
|
||||
* @return string|null Item value (null if offsetExists is false)
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function offsetGet($offset) {
|
||||
if (!isset($this->cookies[$offset])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->cookies[$offset];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the given item
|
||||
*
|
||||
* @param string $offset Item name
|
||||
* @param string $value Item value
|
||||
*
|
||||
* @throws \WpOrg\Requests\Exception On attempting to use dictionary as list (`invalidset`)
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function offsetSet($offset, $value) {
|
||||
if ($offset === null) {
|
||||
throw new Exception('Object is a dictionary, not a list', 'invalidset');
|
||||
}
|
||||
|
||||
$this->cookies[$offset] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unset the given header
|
||||
*
|
||||
* @param string $offset The key for the item to unset.
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function offsetUnset($offset) {
|
||||
unset($this->cookies[$offset]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an iterator for the data
|
||||
*
|
||||
* @return \ArrayIterator
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function getIterator() {
|
||||
return new ArrayIterator($this->cookies);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the cookie handler with the request's hooking system
|
||||
*
|
||||
* @param \WpOrg\Requests\HookManager $hooks Hooking system
|
||||
*/
|
||||
public function register(HookManager $hooks) {
|
||||
$hooks->register('requests.before_request', [$this, 'before_request']);
|
||||
$hooks->register('requests.before_redirect_check', [$this, 'before_redirect_check']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Cookie header to a request if we have any
|
||||
*
|
||||
* As per RFC 6265, cookies are separated by '; '
|
||||
*
|
||||
* @param string $url
|
||||
* @param array $headers
|
||||
* @param array $data
|
||||
* @param string $type
|
||||
* @param array $options
|
||||
*/
|
||||
public function before_request($url, &$headers, &$data, &$type, &$options) {
|
||||
if (!$url instanceof Iri) {
|
||||
$url = new Iri($url);
|
||||
}
|
||||
|
||||
if (!empty($this->cookies)) {
|
||||
$cookies = [];
|
||||
foreach ($this->cookies as $key => $cookie) {
|
||||
$cookie = $this->normalize_cookie($cookie, $key);
|
||||
|
||||
// Skip expired cookies
|
||||
if ($cookie->is_expired()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($cookie->domain_matches($url->host)) {
|
||||
$cookies[] = $cookie->format_for_header();
|
||||
}
|
||||
}
|
||||
|
||||
$headers['Cookie'] = implode('; ', $cookies);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse all cookies from a response and attach them to the response
|
||||
*
|
||||
* @param \WpOrg\Requests\Response $response Response as received.
|
||||
*/
|
||||
public function before_redirect_check(Response $response) {
|
||||
$url = $response->url;
|
||||
if (!$url instanceof Iri) {
|
||||
$url = new Iri($url);
|
||||
}
|
||||
|
||||
$cookies = Cookie::parse_from_headers($response->headers, $url);
|
||||
$this->cookies = array_merge($this->cookies, $cookies);
|
||||
$response->cookies = $this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,66 +1,66 @@
|
||||
<?php
|
||||
/**
|
||||
* Exception for HTTP requests
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests;
|
||||
|
||||
use Exception as PHPException;
|
||||
|
||||
/**
|
||||
* Exception for HTTP requests
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
class Exception extends PHPException {
|
||||
/**
|
||||
* Type of exception
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $type;
|
||||
|
||||
/**
|
||||
* Data associated with the exception
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $data;
|
||||
|
||||
/**
|
||||
* Create a new exception
|
||||
*
|
||||
* @param string $message Exception message
|
||||
* @param string $type Exception type
|
||||
* @param mixed $data Associated data
|
||||
* @param integer $code Exception numerical code, if applicable
|
||||
*/
|
||||
public function __construct($message, $type, $data = null, $code = 0) {
|
||||
parent::__construct($message, $code);
|
||||
|
||||
$this->type = $type;
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Like {@see \Exception::getCode()}, but a string code.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @return string
|
||||
*/
|
||||
public function getType() {
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gives any relevant data
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @return mixed
|
||||
*/
|
||||
public function getData() {
|
||||
return $this->data;
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Exception for HTTP requests
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests;
|
||||
|
||||
use Exception as PHPException;
|
||||
|
||||
/**
|
||||
* Exception for HTTP requests
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
class Exception extends PHPException {
|
||||
/**
|
||||
* Type of exception
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $type;
|
||||
|
||||
/**
|
||||
* Data associated with the exception
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $data;
|
||||
|
||||
/**
|
||||
* Create a new exception
|
||||
*
|
||||
* @param string $message Exception message
|
||||
* @param string $type Exception type
|
||||
* @param mixed $data Associated data
|
||||
* @param integer $code Exception numerical code, if applicable
|
||||
*/
|
||||
public function __construct($message, $type, $data = null, $code = 0) {
|
||||
parent::__construct($message, $code);
|
||||
|
||||
$this->type = $type;
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Like {@see \Exception::getCode()}, but a string code.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @return string
|
||||
*/
|
||||
public function getType() {
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gives any relevant data
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @return mixed
|
||||
*/
|
||||
public function getData() {
|
||||
return $this->data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,47 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace WpOrg\Requests\Exception;
|
||||
|
||||
use WpOrg\Requests\Exception;
|
||||
|
||||
/**
|
||||
* Exception for when an incorrect number of arguments are passed to a method.
|
||||
*
|
||||
* Typically, this exception is used when all arguments for a method are optional,
|
||||
* but certain arguments need to be passed together, i.e. a method which can be called
|
||||
* with no arguments or with two arguments, but not with one argument.
|
||||
*
|
||||
* Along the same lines, this exception is also used if a method expects an array
|
||||
* with a certain number of elements and the provided number of elements does not comply.
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
* @since 2.0.0
|
||||
*/
|
||||
final class ArgumentCount extends Exception {
|
||||
|
||||
/**
|
||||
* Create a new argument count exception with a standardized text.
|
||||
*
|
||||
* @param string $expected The argument count expected as a phrase.
|
||||
* For example: `at least 2 arguments` or `exactly 1 argument`.
|
||||
* @param int $received The actual argument count received.
|
||||
* @param string $type Exception type.
|
||||
*
|
||||
* @return \WpOrg\Requests\Exception\ArgumentCount
|
||||
*/
|
||||
public static function create($expected, $received, $type) {
|
||||
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_debug_backtrace
|
||||
$stack = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
|
||||
|
||||
return new self(
|
||||
sprintf(
|
||||
'%s::%s() expects %s, %d given',
|
||||
$stack[1]['class'],
|
||||
$stack[1]['function'],
|
||||
$expected,
|
||||
$received
|
||||
),
|
||||
$type
|
||||
);
|
||||
}
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace WpOrg\Requests\Exception;
|
||||
|
||||
use WpOrg\Requests\Exception;
|
||||
|
||||
/**
|
||||
* Exception for when an incorrect number of arguments are passed to a method.
|
||||
*
|
||||
* Typically, this exception is used when all arguments for a method are optional,
|
||||
* but certain arguments need to be passed together, i.e. a method which can be called
|
||||
* with no arguments or with two arguments, but not with one argument.
|
||||
*
|
||||
* Along the same lines, this exception is also used if a method expects an array
|
||||
* with a certain number of elements and the provided number of elements does not comply.
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
* @since 2.0.0
|
||||
*/
|
||||
final class ArgumentCount extends Exception {
|
||||
|
||||
/**
|
||||
* Create a new argument count exception with a standardized text.
|
||||
*
|
||||
* @param string $expected The argument count expected as a phrase.
|
||||
* For example: `at least 2 arguments` or `exactly 1 argument`.
|
||||
* @param int $received The actual argument count received.
|
||||
* @param string $type Exception type.
|
||||
*
|
||||
* @return \WpOrg\Requests\Exception\ArgumentCount
|
||||
*/
|
||||
public static function create($expected, $received, $type) {
|
||||
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_debug_backtrace
|
||||
$stack = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
|
||||
|
||||
return new self(
|
||||
sprintf(
|
||||
'%s::%s() expects %s, %d given',
|
||||
$stack[1]['class'],
|
||||
$stack[1]['function'],
|
||||
$expected,
|
||||
$received
|
||||
),
|
||||
$type
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,78 +1,78 @@
|
||||
<?php
|
||||
/**
|
||||
* Exception based on HTTP response
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception;
|
||||
|
||||
use WpOrg\Requests\Exception;
|
||||
use WpOrg\Requests\Exception\Http\StatusUnknown;
|
||||
|
||||
/**
|
||||
* Exception based on HTTP response
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
class Http extends Exception {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 0;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Unknown';
|
||||
|
||||
/**
|
||||
* Create a new exception
|
||||
*
|
||||
* There is no mechanism to pass in the status code, as this is set by the
|
||||
* subclass used. Reason phrases can vary, however.
|
||||
*
|
||||
* @param string|null $reason Reason phrase
|
||||
* @param mixed $data Associated data
|
||||
*/
|
||||
public function __construct($reason = null, $data = null) {
|
||||
if ($reason !== null) {
|
||||
$this->reason = $reason;
|
||||
}
|
||||
|
||||
$message = sprintf('%d %s', $this->code, $this->reason);
|
||||
parent::__construct($message, 'httpresponse', $data, $this->code);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the status message.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getReason() {
|
||||
return $this->reason;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the correct exception class for a given error code
|
||||
*
|
||||
* @param int|bool $code HTTP status code, or false if unavailable
|
||||
* @return string Exception class name to use
|
||||
*/
|
||||
public static function get_class($code) {
|
||||
if (!$code) {
|
||||
return StatusUnknown::class;
|
||||
}
|
||||
|
||||
$class = sprintf('\WpOrg\Requests\Exception\Http\Status%d', $code);
|
||||
if (class_exists($class)) {
|
||||
return $class;
|
||||
}
|
||||
|
||||
return StatusUnknown::class;
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Exception based on HTTP response
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception;
|
||||
|
||||
use WpOrg\Requests\Exception;
|
||||
use WpOrg\Requests\Exception\Http\StatusUnknown;
|
||||
|
||||
/**
|
||||
* Exception based on HTTP response
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
class Http extends Exception {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 0;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Unknown';
|
||||
|
||||
/**
|
||||
* Create a new exception
|
||||
*
|
||||
* There is no mechanism to pass in the status code, as this is set by the
|
||||
* subclass used. Reason phrases can vary, however.
|
||||
*
|
||||
* @param string|null $reason Reason phrase
|
||||
* @param mixed $data Associated data
|
||||
*/
|
||||
public function __construct($reason = null, $data = null) {
|
||||
if ($reason !== null) {
|
||||
$this->reason = $reason;
|
||||
}
|
||||
|
||||
$message = sprintf('%d %s', $this->code, $this->reason);
|
||||
parent::__construct($message, 'httpresponse', $data, $this->code);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the status message.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getReason() {
|
||||
return $this->reason;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the correct exception class for a given error code
|
||||
*
|
||||
* @param int|bool $code HTTP status code, or false if unavailable
|
||||
* @return string Exception class name to use
|
||||
*/
|
||||
public static function get_class($code) {
|
||||
if (!$code) {
|
||||
return StatusUnknown::class;
|
||||
}
|
||||
|
||||
$class = sprintf('\WpOrg\Requests\Exception\Http\Status%d', $code);
|
||||
if (class_exists($class)) {
|
||||
return $class;
|
||||
}
|
||||
|
||||
return StatusUnknown::class;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Exception for 304 Not Modified responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 304 Not Modified responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status304 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 304;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Not Modified';
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Exception for 304 Not Modified responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 304 Not Modified responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status304 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 304;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Not Modified';
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Exception for 305 Use Proxy responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 305 Use Proxy responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status305 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 305;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Use Proxy';
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Exception for 305 Use Proxy responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 305 Use Proxy responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status305 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 305;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Use Proxy';
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Exception for 306 Switch Proxy responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 306 Switch Proxy responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status306 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 306;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Switch Proxy';
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Exception for 306 Switch Proxy responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 306 Switch Proxy responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status306 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 306;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Switch Proxy';
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Exception for 400 Bad Request responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 400 Bad Request responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status400 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 400;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Bad Request';
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Exception for 400 Bad Request responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 400 Bad Request responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status400 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 400;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Bad Request';
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Exception for 401 Unauthorized responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 401 Unauthorized responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status401 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 401;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Unauthorized';
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Exception for 401 Unauthorized responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 401 Unauthorized responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status401 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 401;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Unauthorized';
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Exception for 402 Payment Required responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 402 Payment Required responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status402 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 402;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Payment Required';
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Exception for 402 Payment Required responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 402 Payment Required responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status402 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 402;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Payment Required';
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Exception for 403 Forbidden responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 403 Forbidden responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status403 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 403;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Forbidden';
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Exception for 403 Forbidden responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 403 Forbidden responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status403 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 403;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Forbidden';
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Exception for 404 Not Found responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 404 Not Found responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status404 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 404;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Not Found';
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Exception for 404 Not Found responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 404 Not Found responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status404 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 404;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Not Found';
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Exception for 405 Method Not Allowed responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 405 Method Not Allowed responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status405 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 405;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Method Not Allowed';
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Exception for 405 Method Not Allowed responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 405 Method Not Allowed responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status405 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 405;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Method Not Allowed';
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Exception for 406 Not Acceptable responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 406 Not Acceptable responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status406 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 406;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Not Acceptable';
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Exception for 406 Not Acceptable responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 406 Not Acceptable responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status406 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 406;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Not Acceptable';
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Exception for 407 Proxy Authentication Required responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 407 Proxy Authentication Required responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status407 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 407;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Proxy Authentication Required';
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Exception for 407 Proxy Authentication Required responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 407 Proxy Authentication Required responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status407 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 407;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Proxy Authentication Required';
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Exception for 408 Request Timeout responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 408 Request Timeout responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status408 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 408;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Request Timeout';
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Exception for 408 Request Timeout responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 408 Request Timeout responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status408 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 408;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Request Timeout';
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Exception for 409 Conflict responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 409 Conflict responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status409 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 409;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Conflict';
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Exception for 409 Conflict responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 409 Conflict responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status409 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 409;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Conflict';
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Exception for 410 Gone responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 410 Gone responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status410 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 410;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Gone';
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Exception for 410 Gone responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 410 Gone responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status410 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 410;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Gone';
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Exception for 411 Length Required responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 411 Length Required responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status411 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 411;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Length Required';
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Exception for 411 Length Required responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 411 Length Required responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status411 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 411;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Length Required';
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Exception for 412 Precondition Failed responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 412 Precondition Failed responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status412 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 412;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Precondition Failed';
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Exception for 412 Precondition Failed responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 412 Precondition Failed responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status412 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 412;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Precondition Failed';
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Exception for 413 Request Entity Too Large responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 413 Request Entity Too Large responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status413 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 413;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Request Entity Too Large';
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Exception for 413 Request Entity Too Large responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 413 Request Entity Too Large responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status413 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 413;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Request Entity Too Large';
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Exception for 414 Request-URI Too Large responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 414 Request-URI Too Large responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status414 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 414;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Request-URI Too Large';
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Exception for 414 Request-URI Too Large responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 414 Request-URI Too Large responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status414 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 414;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Request-URI Too Large';
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Exception for 415 Unsupported Media Type responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 415 Unsupported Media Type responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status415 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 415;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Unsupported Media Type';
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Exception for 415 Unsupported Media Type responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 415 Unsupported Media Type responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status415 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 415;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Unsupported Media Type';
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Exception for 416 Requested Range Not Satisfiable responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 416 Requested Range Not Satisfiable responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status416 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 416;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Requested Range Not Satisfiable';
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Exception for 416 Requested Range Not Satisfiable responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 416 Requested Range Not Satisfiable responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status416 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 416;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Requested Range Not Satisfiable';
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Exception for 417 Expectation Failed responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 417 Expectation Failed responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status417 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 417;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Expectation Failed';
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Exception for 417 Expectation Failed responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 417 Expectation Failed responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status417 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 417;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Expectation Failed';
|
||||
}
|
||||
|
||||
@@ -1,35 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
* Exception for 418 I'm A Teapot responses
|
||||
*
|
||||
* @link https://tools.ietf.org/html/rfc2324
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 418 I'm A Teapot responses
|
||||
*
|
||||
* @link https://tools.ietf.org/html/rfc2324
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status418 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 418;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = "I'm A Teapot";
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Exception for 418 I'm A Teapot responses
|
||||
*
|
||||
* @link https://tools.ietf.org/html/rfc2324
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 418 I'm A Teapot responses
|
||||
*
|
||||
* @link https://tools.ietf.org/html/rfc2324
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status418 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 418;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = "I'm A Teapot";
|
||||
}
|
||||
|
||||
@@ -1,35 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
* Exception for 428 Precondition Required responses
|
||||
*
|
||||
* @link https://tools.ietf.org/html/rfc6585
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 428 Precondition Required responses
|
||||
*
|
||||
* @link https://tools.ietf.org/html/rfc6585
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status428 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 428;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Precondition Required';
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Exception for 428 Precondition Required responses
|
||||
*
|
||||
* @link https://tools.ietf.org/html/rfc6585
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 428 Precondition Required responses
|
||||
*
|
||||
* @link https://tools.ietf.org/html/rfc6585
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status428 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 428;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Precondition Required';
|
||||
}
|
||||
|
||||
@@ -1,35 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
* Exception for 429 Too Many Requests responses
|
||||
*
|
||||
* @link https://tools.ietf.org/html/draft-nottingham-http-new-status-04
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 429 Too Many Requests responses
|
||||
*
|
||||
* @link https://tools.ietf.org/html/draft-nottingham-http-new-status-04
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status429 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 429;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Too Many Requests';
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Exception for 429 Too Many Requests responses
|
||||
*
|
||||
* @link https://tools.ietf.org/html/draft-nottingham-http-new-status-04
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 429 Too Many Requests responses
|
||||
*
|
||||
* @link https://tools.ietf.org/html/draft-nottingham-http-new-status-04
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status429 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 429;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Too Many Requests';
|
||||
}
|
||||
|
||||
@@ -1,35 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
* Exception for 431 Request Header Fields Too Large responses
|
||||
*
|
||||
* @link https://tools.ietf.org/html/rfc6585
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 431 Request Header Fields Too Large responses
|
||||
*
|
||||
* @link https://tools.ietf.org/html/rfc6585
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status431 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 431;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Request Header Fields Too Large';
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Exception for 431 Request Header Fields Too Large responses
|
||||
*
|
||||
* @link https://tools.ietf.org/html/rfc6585
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 431 Request Header Fields Too Large responses
|
||||
*
|
||||
* @link https://tools.ietf.org/html/rfc6585
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status431 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 431;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Request Header Fields Too Large';
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Exception for 500 Internal Server Error responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 500 Internal Server Error responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status500 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 500;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Internal Server Error';
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Exception for 500 Internal Server Error responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 500 Internal Server Error responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status500 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 500;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Internal Server Error';
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Exception for 501 Not Implemented responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 501 Not Implemented responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status501 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 501;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Not Implemented';
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Exception for 501 Not Implemented responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 501 Not Implemented responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status501 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 501;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Not Implemented';
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Exception for 502 Bad Gateway responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 502 Bad Gateway responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status502 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 502;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Bad Gateway';
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Exception for 502 Bad Gateway responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 502 Bad Gateway responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status502 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 502;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Bad Gateway';
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Exception for 503 Service Unavailable responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 503 Service Unavailable responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status503 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 503;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Service Unavailable';
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Exception for 503 Service Unavailable responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 503 Service Unavailable responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status503 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 503;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Service Unavailable';
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Exception for 504 Gateway Timeout responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 504 Gateway Timeout responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status504 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 504;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Gateway Timeout';
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Exception for 504 Gateway Timeout responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 504 Gateway Timeout responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status504 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 504;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Gateway Timeout';
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Exception for 505 HTTP Version Not Supported responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 505 HTTP Version Not Supported responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status505 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 505;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'HTTP Version Not Supported';
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Exception for 505 HTTP Version Not Supported responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 505 HTTP Version Not Supported responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status505 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 505;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'HTTP Version Not Supported';
|
||||
}
|
||||
|
||||
@@ -1,35 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
* Exception for 511 Network Authentication Required responses
|
||||
*
|
||||
* @link https://tools.ietf.org/html/rfc6585
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 511 Network Authentication Required responses
|
||||
*
|
||||
* @link https://tools.ietf.org/html/rfc6585
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status511 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 511;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Network Authentication Required';
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Exception for 511 Network Authentication Required responses
|
||||
*
|
||||
* @link https://tools.ietf.org/html/rfc6585
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception for 511 Network Authentication Required responses
|
||||
*
|
||||
* @link https://tools.ietf.org/html/rfc6585
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Status511 extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = 511;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Network Authentication Required';
|
||||
}
|
||||
|
||||
@@ -1,49 +1,49 @@
|
||||
<?php
|
||||
/**
|
||||
* Exception for unknown status responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
use WpOrg\Requests\Response;
|
||||
|
||||
/**
|
||||
* Exception for unknown status responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class StatusUnknown extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer|bool Code if available, false if an error occurred
|
||||
*/
|
||||
protected $code = 0;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Unknown';
|
||||
|
||||
/**
|
||||
* Create a new exception
|
||||
*
|
||||
* If `$data` is an instance of {@see \WpOrg\Requests\Response}, uses the status
|
||||
* code from it. Otherwise, sets as 0
|
||||
*
|
||||
* @param string|null $reason Reason phrase
|
||||
* @param mixed $data Associated data
|
||||
*/
|
||||
public function __construct($reason = null, $data = null) {
|
||||
if ($data instanceof Response) {
|
||||
$this->code = (int) $data->status_code;
|
||||
}
|
||||
|
||||
parent::__construct($reason, $data);
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Exception for unknown status responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Http;
|
||||
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
use WpOrg\Requests\Response;
|
||||
|
||||
/**
|
||||
* Exception for unknown status responses
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class StatusUnknown extends Http {
|
||||
/**
|
||||
* HTTP status code
|
||||
*
|
||||
* @var integer|bool Code if available, false if an error occurred
|
||||
*/
|
||||
protected $code = 0;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Unknown';
|
||||
|
||||
/**
|
||||
* Create a new exception
|
||||
*
|
||||
* If `$data` is an instance of {@see \WpOrg\Requests\Response}, uses the status
|
||||
* code from it. Otherwise, sets as 0
|
||||
*
|
||||
* @param string|null $reason Reason phrase
|
||||
* @param mixed $data Associated data
|
||||
*/
|
||||
public function __construct($reason = null, $data = null) {
|
||||
if ($data instanceof Response) {
|
||||
$this->code = (int) $data->status_code;
|
||||
}
|
||||
|
||||
parent::__construct($reason, $data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,41 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace WpOrg\Requests\Exception;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Exception for an invalid argument passed.
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
* @since 2.0.0
|
||||
*/
|
||||
final class InvalidArgument extends InvalidArgumentException {
|
||||
|
||||
/**
|
||||
* Create a new invalid argument exception with a standardized text.
|
||||
*
|
||||
* @param int $position The argument position in the function signature. 1-based.
|
||||
* @param string $name The argument name in the function signature.
|
||||
* @param string $expected The argument type expected as a string.
|
||||
* @param string $received The actual argument type received.
|
||||
*
|
||||
* @return \WpOrg\Requests\Exception\InvalidArgument
|
||||
*/
|
||||
public static function create($position, $name, $expected, $received) {
|
||||
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_debug_backtrace
|
||||
$stack = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
|
||||
|
||||
return new self(
|
||||
sprintf(
|
||||
'%s::%s(): Argument #%d (%s) must be of type %s, %s given',
|
||||
$stack[1]['class'],
|
||||
$stack[1]['function'],
|
||||
$position,
|
||||
$name,
|
||||
$expected,
|
||||
$received
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace WpOrg\Requests\Exception;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Exception for an invalid argument passed.
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
* @since 2.0.0
|
||||
*/
|
||||
final class InvalidArgument extends InvalidArgumentException {
|
||||
|
||||
/**
|
||||
* Create a new invalid argument exception with a standardized text.
|
||||
*
|
||||
* @param int $position The argument position in the function signature. 1-based.
|
||||
* @param string $name The argument name in the function signature.
|
||||
* @param string $expected The argument type expected as a string.
|
||||
* @param string $received The actual argument type received.
|
||||
*
|
||||
* @return \WpOrg\Requests\Exception\InvalidArgument
|
||||
*/
|
||||
public static function create($position, $name, $expected, $received) {
|
||||
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_debug_backtrace
|
||||
$stack = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
|
||||
|
||||
return new self(
|
||||
sprintf(
|
||||
'%s::%s(): Argument #%d (%s) must be of type %s, %s given',
|
||||
$stack[1]['class'],
|
||||
$stack[1]['function'],
|
||||
$position,
|
||||
$name,
|
||||
$expected,
|
||||
$received
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* Transport Exception
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception;
|
||||
|
||||
use WpOrg\Requests\Exception;
|
||||
|
||||
/**
|
||||
* Transport Exception
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
class Transport extends Exception {}
|
||||
<?php
|
||||
/**
|
||||
* Transport Exception
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception;
|
||||
|
||||
use WpOrg\Requests\Exception;
|
||||
|
||||
/**
|
||||
* Transport Exception
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
class Transport extends Exception {}
|
||||
|
||||
@@ -1,80 +1,80 @@
|
||||
<?php
|
||||
/**
|
||||
* CURL Transport Exception.
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Transport;
|
||||
|
||||
use WpOrg\Requests\Exception\Transport;
|
||||
|
||||
/**
|
||||
* CURL Transport Exception.
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Curl extends Transport {
|
||||
|
||||
const EASY = 'cURLEasy';
|
||||
const MULTI = 'cURLMulti';
|
||||
const SHARE = 'cURLShare';
|
||||
|
||||
/**
|
||||
* cURL error code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = -1;
|
||||
|
||||
/**
|
||||
* Which type of cURL error
|
||||
*
|
||||
* EASY|MULTI|SHARE
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $type = 'Unknown';
|
||||
|
||||
/**
|
||||
* Clear text error message
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Unknown';
|
||||
|
||||
/**
|
||||
* Create a new exception.
|
||||
*
|
||||
* @param string $message Exception message.
|
||||
* @param string $type Exception type.
|
||||
* @param mixed $data Associated data, if applicable.
|
||||
* @param int $code Exception numerical code, if applicable.
|
||||
*/
|
||||
public function __construct($message, $type, $data = null, $code = 0) {
|
||||
if ($type !== null) {
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
if ($code !== null) {
|
||||
$this->code = (int) $code;
|
||||
}
|
||||
|
||||
if ($message !== null) {
|
||||
$this->reason = $message;
|
||||
}
|
||||
|
||||
$message = sprintf('%d %s', $this->code, $this->reason);
|
||||
parent::__construct($message, $this->type, $data, $this->code);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the error message.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getReason() {
|
||||
return $this->reason;
|
||||
}
|
||||
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* CURL Transport Exception.
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Exception\Transport;
|
||||
|
||||
use WpOrg\Requests\Exception\Transport;
|
||||
|
||||
/**
|
||||
* CURL Transport Exception.
|
||||
*
|
||||
* @package Requests\Exceptions
|
||||
*/
|
||||
final class Curl extends Transport {
|
||||
|
||||
const EASY = 'cURLEasy';
|
||||
const MULTI = 'cURLMulti';
|
||||
const SHARE = 'cURLShare';
|
||||
|
||||
/**
|
||||
* cURL error code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $code = -1;
|
||||
|
||||
/**
|
||||
* Which type of cURL error
|
||||
*
|
||||
* EASY|MULTI|SHARE
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $type = 'Unknown';
|
||||
|
||||
/**
|
||||
* Clear text error message
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reason = 'Unknown';
|
||||
|
||||
/**
|
||||
* Create a new exception.
|
||||
*
|
||||
* @param string $message Exception message.
|
||||
* @param string $type Exception type.
|
||||
* @param mixed $data Associated data, if applicable.
|
||||
* @param int $code Exception numerical code, if applicable.
|
||||
*/
|
||||
public function __construct($message, $type, $data = null, $code = 0) {
|
||||
if ($type !== null) {
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
if ($code !== null) {
|
||||
$this->code = (int) $code;
|
||||
}
|
||||
|
||||
if ($message !== null) {
|
||||
$this->reason = $message;
|
||||
}
|
||||
|
||||
$message = sprintf('%d %s', $this->code, $this->reason);
|
||||
parent::__construct($message, $this->type, $data, $this->code);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the error message.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getReason() {
|
||||
return $this->reason;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,33 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* Event dispatcher
|
||||
*
|
||||
* @package Requests\EventDispatcher
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests;
|
||||
|
||||
/**
|
||||
* Event dispatcher
|
||||
*
|
||||
* @package Requests\EventDispatcher
|
||||
*/
|
||||
interface HookManager {
|
||||
/**
|
||||
* Register a callback for a hook
|
||||
*
|
||||
* @param string $hook Hook name
|
||||
* @param callable $callback Function/method to call on event
|
||||
* @param int $priority Priority number. <0 is executed earlier, >0 is executed later
|
||||
*/
|
||||
public function register($hook, $callback, $priority = 0);
|
||||
|
||||
/**
|
||||
* Dispatch a message
|
||||
*
|
||||
* @param string $hook Hook name
|
||||
* @param array $parameters Parameters to pass to callbacks
|
||||
* @return boolean Successfulness
|
||||
*/
|
||||
public function dispatch($hook, $parameters = []);
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Event dispatcher
|
||||
*
|
||||
* @package Requests\EventDispatcher
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests;
|
||||
|
||||
/**
|
||||
* Event dispatcher
|
||||
*
|
||||
* @package Requests\EventDispatcher
|
||||
*/
|
||||
interface HookManager {
|
||||
/**
|
||||
* Register a callback for a hook
|
||||
*
|
||||
* @param string $hook Hook name
|
||||
* @param callable $callback Function/method to call on event
|
||||
* @param int $priority Priority number. <0 is executed earlier, >0 is executed later
|
||||
*/
|
||||
public function register($hook, $callback, $priority = 0);
|
||||
|
||||
/**
|
||||
* Dispatch a message
|
||||
*
|
||||
* @param string $hook Hook name
|
||||
* @param array $parameters Parameters to pass to callbacks
|
||||
* @return boolean Successfulness
|
||||
*/
|
||||
public function dispatch($hook, $parameters = []);
|
||||
}
|
||||
|
||||
@@ -1,103 +1,103 @@
|
||||
<?php
|
||||
/**
|
||||
* Handles adding and dispatching events
|
||||
*
|
||||
* @package Requests\EventDispatcher
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests;
|
||||
|
||||
use WpOrg\Requests\Exception\InvalidArgument;
|
||||
use WpOrg\Requests\HookManager;
|
||||
use WpOrg\Requests\Utility\InputValidator;
|
||||
|
||||
/**
|
||||
* Handles adding and dispatching events
|
||||
*
|
||||
* @package Requests\EventDispatcher
|
||||
*/
|
||||
class Hooks implements HookManager {
|
||||
/**
|
||||
* Registered callbacks for each hook
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $hooks = [];
|
||||
|
||||
/**
|
||||
* Register a callback for a hook
|
||||
*
|
||||
* @param string $hook Hook name
|
||||
* @param callable $callback Function/method to call on event
|
||||
* @param int $priority Priority number. <0 is executed earlier, >0 is executed later
|
||||
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $hook argument is not a string.
|
||||
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $callback argument is not callable.
|
||||
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $priority argument is not an integer.
|
||||
*/
|
||||
public function register($hook, $callback, $priority = 0) {
|
||||
if (is_string($hook) === false) {
|
||||
throw InvalidArgument::create(1, '$hook', 'string', gettype($hook));
|
||||
}
|
||||
|
||||
if (is_callable($callback) === false) {
|
||||
throw InvalidArgument::create(2, '$callback', 'callable', gettype($callback));
|
||||
}
|
||||
|
||||
if (InputValidator::is_numeric_array_key($priority) === false) {
|
||||
throw InvalidArgument::create(3, '$priority', 'integer', gettype($priority));
|
||||
}
|
||||
|
||||
if (!isset($this->hooks[$hook])) {
|
||||
$this->hooks[$hook] = [
|
||||
$priority => [],
|
||||
];
|
||||
} elseif (!isset($this->hooks[$hook][$priority])) {
|
||||
$this->hooks[$hook][$priority] = [];
|
||||
}
|
||||
|
||||
$this->hooks[$hook][$priority][] = $callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch a message
|
||||
*
|
||||
* @param string $hook Hook name
|
||||
* @param array $parameters Parameters to pass to callbacks
|
||||
* @return boolean Successfulness
|
||||
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $hook argument is not a string.
|
||||
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $parameters argument is not an array.
|
||||
*/
|
||||
public function dispatch($hook, $parameters = []) {
|
||||
if (is_string($hook) === false) {
|
||||
throw InvalidArgument::create(1, '$hook', 'string', gettype($hook));
|
||||
}
|
||||
|
||||
// Check strictly against array, as Array* objects don't work in combination with `call_user_func_array()`.
|
||||
if (is_array($parameters) === false) {
|
||||
throw InvalidArgument::create(2, '$parameters', 'array', gettype($parameters));
|
||||
}
|
||||
|
||||
if (empty($this->hooks[$hook])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!empty($parameters)) {
|
||||
// Strip potential keys from the array to prevent them being interpreted as parameter names in PHP 8.0.
|
||||
$parameters = array_values($parameters);
|
||||
}
|
||||
|
||||
ksort($this->hooks[$hook]);
|
||||
|
||||
foreach ($this->hooks[$hook] as $priority => $hooked) {
|
||||
foreach ($hooked as $callback) {
|
||||
$callback(...$parameters);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function __wakeup() {
|
||||
throw new \LogicException( __CLASS__ . ' should never be unserialized' );
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Handles adding and dispatching events
|
||||
*
|
||||
* @package Requests\EventDispatcher
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests;
|
||||
|
||||
use WpOrg\Requests\Exception\InvalidArgument;
|
||||
use WpOrg\Requests\HookManager;
|
||||
use WpOrg\Requests\Utility\InputValidator;
|
||||
|
||||
/**
|
||||
* Handles adding and dispatching events
|
||||
*
|
||||
* @package Requests\EventDispatcher
|
||||
*/
|
||||
class Hooks implements HookManager {
|
||||
/**
|
||||
* Registered callbacks for each hook
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $hooks = [];
|
||||
|
||||
/**
|
||||
* Register a callback for a hook
|
||||
*
|
||||
* @param string $hook Hook name
|
||||
* @param callable $callback Function/method to call on event
|
||||
* @param int $priority Priority number. <0 is executed earlier, >0 is executed later
|
||||
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $hook argument is not a string.
|
||||
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $callback argument is not callable.
|
||||
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $priority argument is not an integer.
|
||||
*/
|
||||
public function register($hook, $callback, $priority = 0) {
|
||||
if (is_string($hook) === false) {
|
||||
throw InvalidArgument::create(1, '$hook', 'string', gettype($hook));
|
||||
}
|
||||
|
||||
if (is_callable($callback) === false) {
|
||||
throw InvalidArgument::create(2, '$callback', 'callable', gettype($callback));
|
||||
}
|
||||
|
||||
if (InputValidator::is_numeric_array_key($priority) === false) {
|
||||
throw InvalidArgument::create(3, '$priority', 'integer', gettype($priority));
|
||||
}
|
||||
|
||||
if (!isset($this->hooks[$hook])) {
|
||||
$this->hooks[$hook] = [
|
||||
$priority => [],
|
||||
];
|
||||
} elseif (!isset($this->hooks[$hook][$priority])) {
|
||||
$this->hooks[$hook][$priority] = [];
|
||||
}
|
||||
|
||||
$this->hooks[$hook][$priority][] = $callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch a message
|
||||
*
|
||||
* @param string $hook Hook name
|
||||
* @param array $parameters Parameters to pass to callbacks
|
||||
* @return boolean Successfulness
|
||||
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $hook argument is not a string.
|
||||
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $parameters argument is not an array.
|
||||
*/
|
||||
public function dispatch($hook, $parameters = []) {
|
||||
if (is_string($hook) === false) {
|
||||
throw InvalidArgument::create(1, '$hook', 'string', gettype($hook));
|
||||
}
|
||||
|
||||
// Check strictly against array, as Array* objects don't work in combination with `call_user_func_array()`.
|
||||
if (is_array($parameters) === false) {
|
||||
throw InvalidArgument::create(2, '$parameters', 'array', gettype($parameters));
|
||||
}
|
||||
|
||||
if (empty($this->hooks[$hook])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!empty($parameters)) {
|
||||
// Strip potential keys from the array to prevent them being interpreted as parameter names in PHP 8.0.
|
||||
$parameters = array_values($parameters);
|
||||
}
|
||||
|
||||
ksort($this->hooks[$hook]);
|
||||
|
||||
foreach ($this->hooks[$hook] as $priority => $hooked) {
|
||||
foreach ($hooked as $callback) {
|
||||
$callback(...$parameters);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function __wakeup() {
|
||||
throw new \LogicException( __CLASS__ . ' should never be unserialized' );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,412 +1,412 @@
|
||||
<?php
|
||||
|
||||
namespace WpOrg\Requests;
|
||||
|
||||
use WpOrg\Requests\Exception;
|
||||
use WpOrg\Requests\Exception\InvalidArgument;
|
||||
use WpOrg\Requests\Utility\InputValidator;
|
||||
|
||||
/**
|
||||
* IDNA URL encoder
|
||||
*
|
||||
* Note: Not fully compliant, as nameprep does nothing yet.
|
||||
*
|
||||
* @package Requests\Utilities
|
||||
*
|
||||
* @link https://tools.ietf.org/html/rfc3490 IDNA specification
|
||||
* @link https://tools.ietf.org/html/rfc3492 Punycode/Bootstrap specification
|
||||
*/
|
||||
class IdnaEncoder {
|
||||
/**
|
||||
* ACE prefix used for IDNA
|
||||
*
|
||||
* @link https://tools.ietf.org/html/rfc3490#section-5
|
||||
* @var string
|
||||
*/
|
||||
const ACE_PREFIX = 'xn--';
|
||||
|
||||
/**
|
||||
* Maximum length of a IDNA URL in ASCII.
|
||||
*
|
||||
* @see \WpOrg\Requests\IdnaEncoder::to_ascii()
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const MAX_LENGTH = 64;
|
||||
|
||||
/**#@+
|
||||
* Bootstrap constant for Punycode
|
||||
*
|
||||
* @link https://tools.ietf.org/html/rfc3492#section-5
|
||||
* @var int
|
||||
*/
|
||||
const BOOTSTRAP_BASE = 36;
|
||||
const BOOTSTRAP_TMIN = 1;
|
||||
const BOOTSTRAP_TMAX = 26;
|
||||
const BOOTSTRAP_SKEW = 38;
|
||||
const BOOTSTRAP_DAMP = 700;
|
||||
const BOOTSTRAP_INITIAL_BIAS = 72;
|
||||
const BOOTSTRAP_INITIAL_N = 128;
|
||||
/**#@-*/
|
||||
|
||||
/**
|
||||
* Encode a hostname using Punycode
|
||||
*
|
||||
* @param string|Stringable $hostname Hostname
|
||||
* @return string Punycode-encoded hostname
|
||||
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed argument is not a string or a stringable object.
|
||||
*/
|
||||
public static function encode($hostname) {
|
||||
if (InputValidator::is_string_or_stringable($hostname) === false) {
|
||||
throw InvalidArgument::create(1, '$hostname', 'string|Stringable', gettype($hostname));
|
||||
}
|
||||
|
||||
$parts = explode('.', $hostname);
|
||||
foreach ($parts as &$part) {
|
||||
$part = self::to_ascii($part);
|
||||
}
|
||||
|
||||
return implode('.', $parts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a UTF-8 text string to an ASCII string using Punycode
|
||||
*
|
||||
* @param string $text ASCII or UTF-8 string (max length 64 characters)
|
||||
* @return string ASCII string
|
||||
*
|
||||
* @throws \WpOrg\Requests\Exception Provided string longer than 64 ASCII characters (`idna.provided_too_long`)
|
||||
* @throws \WpOrg\Requests\Exception Prepared string longer than 64 ASCII characters (`idna.prepared_too_long`)
|
||||
* @throws \WpOrg\Requests\Exception Provided string already begins with xn-- (`idna.provided_is_prefixed`)
|
||||
* @throws \WpOrg\Requests\Exception Encoded string longer than 64 ASCII characters (`idna.encoded_too_long`)
|
||||
*/
|
||||
public static function to_ascii($text) {
|
||||
// Step 1: Check if the text is already ASCII
|
||||
if (self::is_ascii($text)) {
|
||||
// Skip to step 7
|
||||
if (strlen($text) < self::MAX_LENGTH) {
|
||||
return $text;
|
||||
}
|
||||
|
||||
throw new Exception('Provided string is too long', 'idna.provided_too_long', $text);
|
||||
}
|
||||
|
||||
// Step 2: nameprep
|
||||
$text = self::nameprep($text);
|
||||
|
||||
// Step 3: UseSTD3ASCIIRules is false, continue
|
||||
// Step 4: Check if it's ASCII now
|
||||
if (self::is_ascii($text)) {
|
||||
// Skip to step 7
|
||||
/*
|
||||
* As the `nameprep()` method returns the original string, this code will never be reached until
|
||||
* that method is properly implemented.
|
||||
*/
|
||||
// @codeCoverageIgnoreStart
|
||||
if (strlen($text) < self::MAX_LENGTH) {
|
||||
return $text;
|
||||
}
|
||||
|
||||
throw new Exception('Prepared string is too long', 'idna.prepared_too_long', $text);
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
// Step 5: Check ACE prefix
|
||||
if (strpos($text, self::ACE_PREFIX) === 0) {
|
||||
throw new Exception('Provided string begins with ACE prefix', 'idna.provided_is_prefixed', $text);
|
||||
}
|
||||
|
||||
// Step 6: Encode with Punycode
|
||||
$text = self::punycode_encode($text);
|
||||
|
||||
// Step 7: Prepend ACE prefix
|
||||
$text = self::ACE_PREFIX . $text;
|
||||
|
||||
// Step 8: Check size
|
||||
if (strlen($text) < self::MAX_LENGTH) {
|
||||
return $text;
|
||||
}
|
||||
|
||||
throw new Exception('Encoded string is too long', 'idna.encoded_too_long', $text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a given text string contains only ASCII characters
|
||||
*
|
||||
* @internal (Testing found regex was the fastest implementation)
|
||||
*
|
||||
* @param string $text Text to examine.
|
||||
* @return bool Is the text string ASCII-only?
|
||||
*/
|
||||
protected static function is_ascii($text) {
|
||||
return (preg_match('/(?:[^\x00-\x7F])/', $text) !== 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare a text string for use as an IDNA name
|
||||
*
|
||||
* @todo Implement this based on RFC 3491 and the newer 5891
|
||||
* @param string $text Text to prepare.
|
||||
* @return string Prepared string
|
||||
*/
|
||||
protected static function nameprep($text) {
|
||||
return $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a UTF-8 string to a UCS-4 codepoint array
|
||||
*
|
||||
* Based on \WpOrg\Requests\Iri::replace_invalid_with_pct_encoding()
|
||||
*
|
||||
* @param string $input Text to convert.
|
||||
* @return array Unicode code points
|
||||
*
|
||||
* @throws \WpOrg\Requests\Exception Invalid UTF-8 codepoint (`idna.invalidcodepoint`)
|
||||
*/
|
||||
protected static function utf8_to_codepoints($input) {
|
||||
$codepoints = [];
|
||||
|
||||
// Get number of bytes
|
||||
$strlen = strlen($input);
|
||||
|
||||
// phpcs:ignore Generic.CodeAnalysis.JumbledIncrementer -- This is a deliberate choice.
|
||||
for ($position = 0; $position < $strlen; $position++) {
|
||||
$value = ord($input[$position]);
|
||||
|
||||
if ((~$value & 0x80) === 0x80) { // One byte sequence:
|
||||
$character = $value;
|
||||
$length = 1;
|
||||
$remaining = 0;
|
||||
} elseif (($value & 0xE0) === 0xC0) { // Two byte sequence:
|
||||
$character = ($value & 0x1F) << 6;
|
||||
$length = 2;
|
||||
$remaining = 1;
|
||||
} elseif (($value & 0xF0) === 0xE0) { // Three byte sequence:
|
||||
$character = ($value & 0x0F) << 12;
|
||||
$length = 3;
|
||||
$remaining = 2;
|
||||
} elseif (($value & 0xF8) === 0xF0) { // Four byte sequence:
|
||||
$character = ($value & 0x07) << 18;
|
||||
$length = 4;
|
||||
$remaining = 3;
|
||||
} else { // Invalid byte:
|
||||
throw new Exception('Invalid Unicode codepoint', 'idna.invalidcodepoint', $value);
|
||||
}
|
||||
|
||||
if ($remaining > 0) {
|
||||
if ($position + $length > $strlen) {
|
||||
throw new Exception('Invalid Unicode codepoint', 'idna.invalidcodepoint', $character);
|
||||
}
|
||||
|
||||
for ($position++; $remaining > 0; $position++) {
|
||||
$value = ord($input[$position]);
|
||||
|
||||
// If it is invalid, count the sequence as invalid and reprocess the current byte:
|
||||
if (($value & 0xC0) !== 0x80) {
|
||||
throw new Exception('Invalid Unicode codepoint', 'idna.invalidcodepoint', $character);
|
||||
}
|
||||
|
||||
--$remaining;
|
||||
$character |= ($value & 0x3F) << ($remaining * 6);
|
||||
}
|
||||
|
||||
$position--;
|
||||
}
|
||||
|
||||
if (// Non-shortest form sequences are invalid
|
||||
$length > 1 && $character <= 0x7F
|
||||
|| $length > 2 && $character <= 0x7FF
|
||||
|| $length > 3 && $character <= 0xFFFF
|
||||
// Outside of range of ucschar codepoints
|
||||
// Noncharacters
|
||||
|| ($character & 0xFFFE) === 0xFFFE
|
||||
|| $character >= 0xFDD0 && $character <= 0xFDEF
|
||||
|| (
|
||||
// Everything else not in ucschar
|
||||
$character > 0xD7FF && $character < 0xF900
|
||||
|| $character < 0x20
|
||||
|| $character > 0x7E && $character < 0xA0
|
||||
|| $character > 0xEFFFD
|
||||
)
|
||||
) {
|
||||
throw new Exception('Invalid Unicode codepoint', 'idna.invalidcodepoint', $character);
|
||||
}
|
||||
|
||||
$codepoints[] = $character;
|
||||
}
|
||||
|
||||
return $codepoints;
|
||||
}
|
||||
|
||||
/**
|
||||
* RFC3492-compliant encoder
|
||||
*
|
||||
* @internal Pseudo-code from Section 6.3 is commented with "#" next to relevant code
|
||||
*
|
||||
* @param string $input UTF-8 encoded string to encode
|
||||
* @return string Punycode-encoded string
|
||||
*
|
||||
* @throws \WpOrg\Requests\Exception On character outside of the domain (never happens with Punycode) (`idna.character_outside_domain`)
|
||||
*/
|
||||
public static function punycode_encode($input) {
|
||||
$output = '';
|
||||
// let n = initial_n
|
||||
$n = self::BOOTSTRAP_INITIAL_N;
|
||||
// let delta = 0
|
||||
$delta = 0;
|
||||
// let bias = initial_bias
|
||||
$bias = self::BOOTSTRAP_INITIAL_BIAS;
|
||||
// let h = b = the number of basic code points in the input
|
||||
$h = 0;
|
||||
$b = 0; // see loop
|
||||
// copy them to the output in order
|
||||
$codepoints = self::utf8_to_codepoints($input);
|
||||
$extended = [];
|
||||
|
||||
foreach ($codepoints as $char) {
|
||||
if ($char < 128) {
|
||||
// Character is valid ASCII
|
||||
// TODO: this should also check if it's valid for a URL
|
||||
$output .= chr($char);
|
||||
$h++;
|
||||
|
||||
// Check if the character is non-ASCII, but below initial n
|
||||
// This never occurs for Punycode, so ignore in coverage
|
||||
// @codeCoverageIgnoreStart
|
||||
} elseif ($char < $n) {
|
||||
throw new Exception('Invalid character', 'idna.character_outside_domain', $char);
|
||||
// @codeCoverageIgnoreEnd
|
||||
} else {
|
||||
$extended[$char] = true;
|
||||
}
|
||||
}
|
||||
|
||||
$extended = array_keys($extended);
|
||||
sort($extended);
|
||||
$b = $h;
|
||||
// [copy them] followed by a delimiter if b > 0
|
||||
if (strlen($output) > 0) {
|
||||
$output .= '-';
|
||||
}
|
||||
|
||||
// {if the input contains a non-basic code point < n then fail}
|
||||
// while h < length(input) do begin
|
||||
$codepointcount = count($codepoints);
|
||||
while ($h < $codepointcount) {
|
||||
// let m = the minimum code point >= n in the input
|
||||
$m = array_shift($extended);
|
||||
//printf('next code point to insert is %s' . PHP_EOL, dechex($m));
|
||||
// let delta = delta + (m - n) * (h + 1), fail on overflow
|
||||
$delta += ($m - $n) * ($h + 1);
|
||||
// let n = m
|
||||
$n = $m;
|
||||
// for each code point c in the input (in order) do begin
|
||||
for ($num = 0; $num < $codepointcount; $num++) {
|
||||
$c = $codepoints[$num];
|
||||
// if c < n then increment delta, fail on overflow
|
||||
if ($c < $n) {
|
||||
$delta++;
|
||||
} elseif ($c === $n) { // if c == n then begin
|
||||
// let q = delta
|
||||
$q = $delta;
|
||||
// for k = base to infinity in steps of base do begin
|
||||
for ($k = self::BOOTSTRAP_BASE; ; $k += self::BOOTSTRAP_BASE) {
|
||||
// let t = tmin if k <= bias {+ tmin}, or
|
||||
// tmax if k >= bias + tmax, or k - bias otherwise
|
||||
if ($k <= ($bias + self::BOOTSTRAP_TMIN)) {
|
||||
$t = self::BOOTSTRAP_TMIN;
|
||||
} elseif ($k >= ($bias + self::BOOTSTRAP_TMAX)) {
|
||||
$t = self::BOOTSTRAP_TMAX;
|
||||
} else {
|
||||
$t = $k - $bias;
|
||||
}
|
||||
|
||||
// if q < t then break
|
||||
if ($q < $t) {
|
||||
break;
|
||||
}
|
||||
|
||||
// output the code point for digit t + ((q - t) mod (base - t))
|
||||
$digit = (int) ($t + (($q - $t) % (self::BOOTSTRAP_BASE - $t)));
|
||||
$output .= self::digit_to_char($digit);
|
||||
// let q = (q - t) div (base - t)
|
||||
$q = (int) floor(($q - $t) / (self::BOOTSTRAP_BASE - $t));
|
||||
} // end
|
||||
// output the code point for digit q
|
||||
$output .= self::digit_to_char($q);
|
||||
// let bias = adapt(delta, h + 1, test h equals b?)
|
||||
$bias = self::adapt($delta, $h + 1, $h === $b);
|
||||
// let delta = 0
|
||||
$delta = 0;
|
||||
// increment h
|
||||
$h++;
|
||||
} // end
|
||||
} // end
|
||||
// increment delta and n
|
||||
$delta++;
|
||||
$n++;
|
||||
} // end
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a digit to its respective character
|
||||
*
|
||||
* @link https://tools.ietf.org/html/rfc3492#section-5
|
||||
*
|
||||
* @param int $digit Digit in the range 0-35
|
||||
* @return string Single character corresponding to digit
|
||||
*
|
||||
* @throws \WpOrg\Requests\Exception On invalid digit (`idna.invalid_digit`)
|
||||
*/
|
||||
protected static function digit_to_char($digit) {
|
||||
// @codeCoverageIgnoreStart
|
||||
// As far as I know, this never happens, but still good to be sure.
|
||||
if ($digit < 0 || $digit > 35) {
|
||||
throw new Exception(sprintf('Invalid digit %d', $digit), 'idna.invalid_digit', $digit);
|
||||
}
|
||||
|
||||
// @codeCoverageIgnoreEnd
|
||||
$digits = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
||||
return substr($digits, $digit, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adapt the bias
|
||||
*
|
||||
* @link https://tools.ietf.org/html/rfc3492#section-6.1
|
||||
* @param int $delta
|
||||
* @param int $numpoints
|
||||
* @param bool $firsttime
|
||||
* @return int|float New bias
|
||||
*
|
||||
* function adapt(delta,numpoints,firsttime):
|
||||
*/
|
||||
protected static function adapt($delta, $numpoints, $firsttime) {
|
||||
// if firsttime then let delta = delta div damp
|
||||
if ($firsttime) {
|
||||
$delta = floor($delta / self::BOOTSTRAP_DAMP);
|
||||
} else {
|
||||
// else let delta = delta div 2
|
||||
$delta = floor($delta / 2);
|
||||
}
|
||||
|
||||
// let delta = delta + (delta div numpoints)
|
||||
$delta += floor($delta / $numpoints);
|
||||
// let k = 0
|
||||
$k = 0;
|
||||
// while delta > ((base - tmin) * tmax) div 2 do begin
|
||||
$max = floor(((self::BOOTSTRAP_BASE - self::BOOTSTRAP_TMIN) * self::BOOTSTRAP_TMAX) / 2);
|
||||
while ($delta > $max) {
|
||||
// let delta = delta div (base - tmin)
|
||||
$delta = floor($delta / (self::BOOTSTRAP_BASE - self::BOOTSTRAP_TMIN));
|
||||
// let k = k + base
|
||||
$k += self::BOOTSTRAP_BASE;
|
||||
} // end
|
||||
// return k + (((base - tmin + 1) * delta) div (delta + skew))
|
||||
return $k + floor(((self::BOOTSTRAP_BASE - self::BOOTSTRAP_TMIN + 1) * $delta) / ($delta + self::BOOTSTRAP_SKEW));
|
||||
}
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace WpOrg\Requests;
|
||||
|
||||
use WpOrg\Requests\Exception;
|
||||
use WpOrg\Requests\Exception\InvalidArgument;
|
||||
use WpOrg\Requests\Utility\InputValidator;
|
||||
|
||||
/**
|
||||
* IDNA URL encoder
|
||||
*
|
||||
* Note: Not fully compliant, as nameprep does nothing yet.
|
||||
*
|
||||
* @package Requests\Utilities
|
||||
*
|
||||
* @link https://tools.ietf.org/html/rfc3490 IDNA specification
|
||||
* @link https://tools.ietf.org/html/rfc3492 Punycode/Bootstrap specification
|
||||
*/
|
||||
class IdnaEncoder {
|
||||
/**
|
||||
* ACE prefix used for IDNA
|
||||
*
|
||||
* @link https://tools.ietf.org/html/rfc3490#section-5
|
||||
* @var string
|
||||
*/
|
||||
const ACE_PREFIX = 'xn--';
|
||||
|
||||
/**
|
||||
* Maximum length of a IDNA URL in ASCII.
|
||||
*
|
||||
* @see \WpOrg\Requests\IdnaEncoder::to_ascii()
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const MAX_LENGTH = 64;
|
||||
|
||||
/**#@+
|
||||
* Bootstrap constant for Punycode
|
||||
*
|
||||
* @link https://tools.ietf.org/html/rfc3492#section-5
|
||||
* @var int
|
||||
*/
|
||||
const BOOTSTRAP_BASE = 36;
|
||||
const BOOTSTRAP_TMIN = 1;
|
||||
const BOOTSTRAP_TMAX = 26;
|
||||
const BOOTSTRAP_SKEW = 38;
|
||||
const BOOTSTRAP_DAMP = 700;
|
||||
const BOOTSTRAP_INITIAL_BIAS = 72;
|
||||
const BOOTSTRAP_INITIAL_N = 128;
|
||||
/**#@-*/
|
||||
|
||||
/**
|
||||
* Encode a hostname using Punycode
|
||||
*
|
||||
* @param string|Stringable $hostname Hostname
|
||||
* @return string Punycode-encoded hostname
|
||||
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed argument is not a string or a stringable object.
|
||||
*/
|
||||
public static function encode($hostname) {
|
||||
if (InputValidator::is_string_or_stringable($hostname) === false) {
|
||||
throw InvalidArgument::create(1, '$hostname', 'string|Stringable', gettype($hostname));
|
||||
}
|
||||
|
||||
$parts = explode('.', $hostname);
|
||||
foreach ($parts as &$part) {
|
||||
$part = self::to_ascii($part);
|
||||
}
|
||||
|
||||
return implode('.', $parts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a UTF-8 text string to an ASCII string using Punycode
|
||||
*
|
||||
* @param string $text ASCII or UTF-8 string (max length 64 characters)
|
||||
* @return string ASCII string
|
||||
*
|
||||
* @throws \WpOrg\Requests\Exception Provided string longer than 64 ASCII characters (`idna.provided_too_long`)
|
||||
* @throws \WpOrg\Requests\Exception Prepared string longer than 64 ASCII characters (`idna.prepared_too_long`)
|
||||
* @throws \WpOrg\Requests\Exception Provided string already begins with xn-- (`idna.provided_is_prefixed`)
|
||||
* @throws \WpOrg\Requests\Exception Encoded string longer than 64 ASCII characters (`idna.encoded_too_long`)
|
||||
*/
|
||||
public static function to_ascii($text) {
|
||||
// Step 1: Check if the text is already ASCII
|
||||
if (self::is_ascii($text)) {
|
||||
// Skip to step 7
|
||||
if (strlen($text) < self::MAX_LENGTH) {
|
||||
return $text;
|
||||
}
|
||||
|
||||
throw new Exception('Provided string is too long', 'idna.provided_too_long', $text);
|
||||
}
|
||||
|
||||
// Step 2: nameprep
|
||||
$text = self::nameprep($text);
|
||||
|
||||
// Step 3: UseSTD3ASCIIRules is false, continue
|
||||
// Step 4: Check if it's ASCII now
|
||||
if (self::is_ascii($text)) {
|
||||
// Skip to step 7
|
||||
/*
|
||||
* As the `nameprep()` method returns the original string, this code will never be reached until
|
||||
* that method is properly implemented.
|
||||
*/
|
||||
// @codeCoverageIgnoreStart
|
||||
if (strlen($text) < self::MAX_LENGTH) {
|
||||
return $text;
|
||||
}
|
||||
|
||||
throw new Exception('Prepared string is too long', 'idna.prepared_too_long', $text);
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
// Step 5: Check ACE prefix
|
||||
if (strpos($text, self::ACE_PREFIX) === 0) {
|
||||
throw new Exception('Provided string begins with ACE prefix', 'idna.provided_is_prefixed', $text);
|
||||
}
|
||||
|
||||
// Step 6: Encode with Punycode
|
||||
$text = self::punycode_encode($text);
|
||||
|
||||
// Step 7: Prepend ACE prefix
|
||||
$text = self::ACE_PREFIX . $text;
|
||||
|
||||
// Step 8: Check size
|
||||
if (strlen($text) < self::MAX_LENGTH) {
|
||||
return $text;
|
||||
}
|
||||
|
||||
throw new Exception('Encoded string is too long', 'idna.encoded_too_long', $text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a given text string contains only ASCII characters
|
||||
*
|
||||
* @internal (Testing found regex was the fastest implementation)
|
||||
*
|
||||
* @param string $text Text to examine.
|
||||
* @return bool Is the text string ASCII-only?
|
||||
*/
|
||||
protected static function is_ascii($text) {
|
||||
return (preg_match('/(?:[^\x00-\x7F])/', $text) !== 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare a text string for use as an IDNA name
|
||||
*
|
||||
* @todo Implement this based on RFC 3491 and the newer 5891
|
||||
* @param string $text Text to prepare.
|
||||
* @return string Prepared string
|
||||
*/
|
||||
protected static function nameprep($text) {
|
||||
return $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a UTF-8 string to a UCS-4 codepoint array
|
||||
*
|
||||
* Based on \WpOrg\Requests\Iri::replace_invalid_with_pct_encoding()
|
||||
*
|
||||
* @param string $input Text to convert.
|
||||
* @return array Unicode code points
|
||||
*
|
||||
* @throws \WpOrg\Requests\Exception Invalid UTF-8 codepoint (`idna.invalidcodepoint`)
|
||||
*/
|
||||
protected static function utf8_to_codepoints($input) {
|
||||
$codepoints = [];
|
||||
|
||||
// Get number of bytes
|
||||
$strlen = strlen($input);
|
||||
|
||||
// phpcs:ignore Generic.CodeAnalysis.JumbledIncrementer -- This is a deliberate choice.
|
||||
for ($position = 0; $position < $strlen; $position++) {
|
||||
$value = ord($input[$position]);
|
||||
|
||||
if ((~$value & 0x80) === 0x80) { // One byte sequence:
|
||||
$character = $value;
|
||||
$length = 1;
|
||||
$remaining = 0;
|
||||
} elseif (($value & 0xE0) === 0xC0) { // Two byte sequence:
|
||||
$character = ($value & 0x1F) << 6;
|
||||
$length = 2;
|
||||
$remaining = 1;
|
||||
} elseif (($value & 0xF0) === 0xE0) { // Three byte sequence:
|
||||
$character = ($value & 0x0F) << 12;
|
||||
$length = 3;
|
||||
$remaining = 2;
|
||||
} elseif (($value & 0xF8) === 0xF0) { // Four byte sequence:
|
||||
$character = ($value & 0x07) << 18;
|
||||
$length = 4;
|
||||
$remaining = 3;
|
||||
} else { // Invalid byte:
|
||||
throw new Exception('Invalid Unicode codepoint', 'idna.invalidcodepoint', $value);
|
||||
}
|
||||
|
||||
if ($remaining > 0) {
|
||||
if ($position + $length > $strlen) {
|
||||
throw new Exception('Invalid Unicode codepoint', 'idna.invalidcodepoint', $character);
|
||||
}
|
||||
|
||||
for ($position++; $remaining > 0; $position++) {
|
||||
$value = ord($input[$position]);
|
||||
|
||||
// If it is invalid, count the sequence as invalid and reprocess the current byte:
|
||||
if (($value & 0xC0) !== 0x80) {
|
||||
throw new Exception('Invalid Unicode codepoint', 'idna.invalidcodepoint', $character);
|
||||
}
|
||||
|
||||
--$remaining;
|
||||
$character |= ($value & 0x3F) << ($remaining * 6);
|
||||
}
|
||||
|
||||
$position--;
|
||||
}
|
||||
|
||||
if (// Non-shortest form sequences are invalid
|
||||
$length > 1 && $character <= 0x7F
|
||||
|| $length > 2 && $character <= 0x7FF
|
||||
|| $length > 3 && $character <= 0xFFFF
|
||||
// Outside of range of ucschar codepoints
|
||||
// Noncharacters
|
||||
|| ($character & 0xFFFE) === 0xFFFE
|
||||
|| $character >= 0xFDD0 && $character <= 0xFDEF
|
||||
|| (
|
||||
// Everything else not in ucschar
|
||||
$character > 0xD7FF && $character < 0xF900
|
||||
|| $character < 0x20
|
||||
|| $character > 0x7E && $character < 0xA0
|
||||
|| $character > 0xEFFFD
|
||||
)
|
||||
) {
|
||||
throw new Exception('Invalid Unicode codepoint', 'idna.invalidcodepoint', $character);
|
||||
}
|
||||
|
||||
$codepoints[] = $character;
|
||||
}
|
||||
|
||||
return $codepoints;
|
||||
}
|
||||
|
||||
/**
|
||||
* RFC3492-compliant encoder
|
||||
*
|
||||
* @internal Pseudo-code from Section 6.3 is commented with "#" next to relevant code
|
||||
*
|
||||
* @param string $input UTF-8 encoded string to encode
|
||||
* @return string Punycode-encoded string
|
||||
*
|
||||
* @throws \WpOrg\Requests\Exception On character outside of the domain (never happens with Punycode) (`idna.character_outside_domain`)
|
||||
*/
|
||||
public static function punycode_encode($input) {
|
||||
$output = '';
|
||||
// let n = initial_n
|
||||
$n = self::BOOTSTRAP_INITIAL_N;
|
||||
// let delta = 0
|
||||
$delta = 0;
|
||||
// let bias = initial_bias
|
||||
$bias = self::BOOTSTRAP_INITIAL_BIAS;
|
||||
// let h = b = the number of basic code points in the input
|
||||
$h = 0;
|
||||
$b = 0; // see loop
|
||||
// copy them to the output in order
|
||||
$codepoints = self::utf8_to_codepoints($input);
|
||||
$extended = [];
|
||||
|
||||
foreach ($codepoints as $char) {
|
||||
if ($char < 128) {
|
||||
// Character is valid ASCII
|
||||
// TODO: this should also check if it's valid for a URL
|
||||
$output .= chr($char);
|
||||
$h++;
|
||||
|
||||
// Check if the character is non-ASCII, but below initial n
|
||||
// This never occurs for Punycode, so ignore in coverage
|
||||
// @codeCoverageIgnoreStart
|
||||
} elseif ($char < $n) {
|
||||
throw new Exception('Invalid character', 'idna.character_outside_domain', $char);
|
||||
// @codeCoverageIgnoreEnd
|
||||
} else {
|
||||
$extended[$char] = true;
|
||||
}
|
||||
}
|
||||
|
||||
$extended = array_keys($extended);
|
||||
sort($extended);
|
||||
$b = $h;
|
||||
// [copy them] followed by a delimiter if b > 0
|
||||
if (strlen($output) > 0) {
|
||||
$output .= '-';
|
||||
}
|
||||
|
||||
// {if the input contains a non-basic code point < n then fail}
|
||||
// while h < length(input) do begin
|
||||
$codepointcount = count($codepoints);
|
||||
while ($h < $codepointcount) {
|
||||
// let m = the minimum code point >= n in the input
|
||||
$m = array_shift($extended);
|
||||
//printf('next code point to insert is %s' . PHP_EOL, dechex($m));
|
||||
// let delta = delta + (m - n) * (h + 1), fail on overflow
|
||||
$delta += ($m - $n) * ($h + 1);
|
||||
// let n = m
|
||||
$n = $m;
|
||||
// for each code point c in the input (in order) do begin
|
||||
for ($num = 0; $num < $codepointcount; $num++) {
|
||||
$c = $codepoints[$num];
|
||||
// if c < n then increment delta, fail on overflow
|
||||
if ($c < $n) {
|
||||
$delta++;
|
||||
} elseif ($c === $n) { // if c == n then begin
|
||||
// let q = delta
|
||||
$q = $delta;
|
||||
// for k = base to infinity in steps of base do begin
|
||||
for ($k = self::BOOTSTRAP_BASE; ; $k += self::BOOTSTRAP_BASE) {
|
||||
// let t = tmin if k <= bias {+ tmin}, or
|
||||
// tmax if k >= bias + tmax, or k - bias otherwise
|
||||
if ($k <= ($bias + self::BOOTSTRAP_TMIN)) {
|
||||
$t = self::BOOTSTRAP_TMIN;
|
||||
} elseif ($k >= ($bias + self::BOOTSTRAP_TMAX)) {
|
||||
$t = self::BOOTSTRAP_TMAX;
|
||||
} else {
|
||||
$t = $k - $bias;
|
||||
}
|
||||
|
||||
// if q < t then break
|
||||
if ($q < $t) {
|
||||
break;
|
||||
}
|
||||
|
||||
// output the code point for digit t + ((q - t) mod (base - t))
|
||||
$digit = (int) ($t + (($q - $t) % (self::BOOTSTRAP_BASE - $t)));
|
||||
$output .= self::digit_to_char($digit);
|
||||
// let q = (q - t) div (base - t)
|
||||
$q = (int) floor(($q - $t) / (self::BOOTSTRAP_BASE - $t));
|
||||
} // end
|
||||
// output the code point for digit q
|
||||
$output .= self::digit_to_char($q);
|
||||
// let bias = adapt(delta, h + 1, test h equals b?)
|
||||
$bias = self::adapt($delta, $h + 1, $h === $b);
|
||||
// let delta = 0
|
||||
$delta = 0;
|
||||
// increment h
|
||||
$h++;
|
||||
} // end
|
||||
} // end
|
||||
// increment delta and n
|
||||
$delta++;
|
||||
$n++;
|
||||
} // end
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a digit to its respective character
|
||||
*
|
||||
* @link https://tools.ietf.org/html/rfc3492#section-5
|
||||
*
|
||||
* @param int $digit Digit in the range 0-35
|
||||
* @return string Single character corresponding to digit
|
||||
*
|
||||
* @throws \WpOrg\Requests\Exception On invalid digit (`idna.invalid_digit`)
|
||||
*/
|
||||
protected static function digit_to_char($digit) {
|
||||
// @codeCoverageIgnoreStart
|
||||
// As far as I know, this never happens, but still good to be sure.
|
||||
if ($digit < 0 || $digit > 35) {
|
||||
throw new Exception(sprintf('Invalid digit %d', $digit), 'idna.invalid_digit', $digit);
|
||||
}
|
||||
|
||||
// @codeCoverageIgnoreEnd
|
||||
$digits = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
||||
return substr($digits, $digit, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adapt the bias
|
||||
*
|
||||
* @link https://tools.ietf.org/html/rfc3492#section-6.1
|
||||
* @param int $delta
|
||||
* @param int $numpoints
|
||||
* @param bool $firsttime
|
||||
* @return int|float New bias
|
||||
*
|
||||
* function adapt(delta,numpoints,firsttime):
|
||||
*/
|
||||
protected static function adapt($delta, $numpoints, $firsttime) {
|
||||
// if firsttime then let delta = delta div damp
|
||||
if ($firsttime) {
|
||||
$delta = floor($delta / self::BOOTSTRAP_DAMP);
|
||||
} else {
|
||||
// else let delta = delta div 2
|
||||
$delta = floor($delta / 2);
|
||||
}
|
||||
|
||||
// let delta = delta + (delta div numpoints)
|
||||
$delta += floor($delta / $numpoints);
|
||||
// let k = 0
|
||||
$k = 0;
|
||||
// while delta > ((base - tmin) * tmax) div 2 do begin
|
||||
$max = floor(((self::BOOTSTRAP_BASE - self::BOOTSTRAP_TMIN) * self::BOOTSTRAP_TMAX) / 2);
|
||||
while ($delta > $max) {
|
||||
// let delta = delta div (base - tmin)
|
||||
$delta = floor($delta / (self::BOOTSTRAP_BASE - self::BOOTSTRAP_TMIN));
|
||||
// let k = k + base
|
||||
$k += self::BOOTSTRAP_BASE;
|
||||
} // end
|
||||
// return k + (((base - tmin + 1) * delta) div (delta + skew))
|
||||
return $k + floor(((self::BOOTSTRAP_BASE - self::BOOTSTRAP_TMIN + 1) * $delta) / ($delta + self::BOOTSTRAP_SKEW));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,203 +1,203 @@
|
||||
<?php
|
||||
/**
|
||||
* Class to validate and to work with IPv6 addresses
|
||||
*
|
||||
* @package Requests\Utilities
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests;
|
||||
|
||||
use WpOrg\Requests\Exception\InvalidArgument;
|
||||
use WpOrg\Requests\Utility\InputValidator;
|
||||
|
||||
/**
|
||||
* Class to validate and to work with IPv6 addresses
|
||||
*
|
||||
* This was originally based on the PEAR class of the same name, but has been
|
||||
* entirely rewritten.
|
||||
*
|
||||
* @package Requests\Utilities
|
||||
*/
|
||||
final class Ipv6 {
|
||||
/**
|
||||
* Uncompresses an IPv6 address
|
||||
*
|
||||
* RFC 4291 allows you to compress consecutive zero pieces in an address to
|
||||
* '::'. This method expects a valid IPv6 address and expands the '::' to
|
||||
* the required number of zero pieces.
|
||||
*
|
||||
* Example: FF01::101 -> FF01:0:0:0:0:0:0:101
|
||||
* ::1 -> 0:0:0:0:0:0:0:1
|
||||
*
|
||||
* @author Alexander Merz <alexander.merz@web.de>
|
||||
* @author elfrink at introweb dot nl
|
||||
* @author Josh Peck <jmp at joshpeck dot org>
|
||||
* @copyright 2003-2005 The PHP Group
|
||||
* @license https://opensource.org/licenses/bsd-license.php
|
||||
*
|
||||
* @param string|Stringable $ip An IPv6 address
|
||||
* @return string The uncompressed IPv6 address
|
||||
*
|
||||
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed argument is not a string or a stringable object.
|
||||
*/
|
||||
public static function uncompress($ip) {
|
||||
if (InputValidator::is_string_or_stringable($ip) === false) {
|
||||
throw InvalidArgument::create(1, '$ip', 'string|Stringable', gettype($ip));
|
||||
}
|
||||
|
||||
$ip = (string) $ip;
|
||||
|
||||
if (substr_count($ip, '::') !== 1) {
|
||||
return $ip;
|
||||
}
|
||||
|
||||
list($ip1, $ip2) = explode('::', $ip);
|
||||
$c1 = ($ip1 === '') ? -1 : substr_count($ip1, ':');
|
||||
$c2 = ($ip2 === '') ? -1 : substr_count($ip2, ':');
|
||||
|
||||
if (strpos($ip2, '.') !== false) {
|
||||
$c2++;
|
||||
}
|
||||
|
||||
if ($c1 === -1 && $c2 === -1) {
|
||||
// ::
|
||||
$ip = '0:0:0:0:0:0:0:0';
|
||||
} elseif ($c1 === -1) {
|
||||
// ::xxx
|
||||
$fill = str_repeat('0:', 7 - $c2);
|
||||
$ip = str_replace('::', $fill, $ip);
|
||||
} elseif ($c2 === -1) {
|
||||
// xxx::
|
||||
$fill = str_repeat(':0', 7 - $c1);
|
||||
$ip = str_replace('::', $fill, $ip);
|
||||
} else {
|
||||
// xxx::xxx
|
||||
$fill = ':' . str_repeat('0:', 6 - $c2 - $c1);
|
||||
$ip = str_replace('::', $fill, $ip);
|
||||
}
|
||||
|
||||
return $ip;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compresses an IPv6 address
|
||||
*
|
||||
* RFC 4291 allows you to compress consecutive zero pieces in an address to
|
||||
* '::'. This method expects a valid IPv6 address and compresses consecutive
|
||||
* zero pieces to '::'.
|
||||
*
|
||||
* Example: FF01:0:0:0:0:0:0:101 -> FF01::101
|
||||
* 0:0:0:0:0:0:0:1 -> ::1
|
||||
*
|
||||
* @see \WpOrg\Requests\Ipv6::uncompress()
|
||||
*
|
||||
* @param string $ip An IPv6 address
|
||||
* @return string The compressed IPv6 address
|
||||
*/
|
||||
public static function compress($ip) {
|
||||
// Prepare the IP to be compressed.
|
||||
// Note: Input validation is handled in the `uncompress()` method, which is the first call made in this method.
|
||||
$ip = self::uncompress($ip);
|
||||
$ip_parts = self::split_v6_v4($ip);
|
||||
|
||||
// Replace all leading zeros
|
||||
$ip_parts[0] = preg_replace('/(^|:)0+([0-9])/', '\1\2', $ip_parts[0]);
|
||||
|
||||
// Find bunches of zeros
|
||||
if (preg_match_all('/(?:^|:)(?:0(?::|$))+/', $ip_parts[0], $matches, PREG_OFFSET_CAPTURE)) {
|
||||
$max = 0;
|
||||
$pos = null;
|
||||
foreach ($matches[0] as $match) {
|
||||
if (strlen($match[0]) > $max) {
|
||||
$max = strlen($match[0]);
|
||||
$pos = $match[1];
|
||||
}
|
||||
}
|
||||
|
||||
$ip_parts[0] = substr_replace($ip_parts[0], '::', $pos, $max);
|
||||
}
|
||||
|
||||
if ($ip_parts[1] !== '') {
|
||||
return implode(':', $ip_parts);
|
||||
} else {
|
||||
return $ip_parts[0];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits an IPv6 address into the IPv6 and IPv4 representation parts
|
||||
*
|
||||
* RFC 4291 allows you to represent the last two parts of an IPv6 address
|
||||
* using the standard IPv4 representation
|
||||
*
|
||||
* Example: 0:0:0:0:0:0:13.1.68.3
|
||||
* 0:0:0:0:0:FFFF:129.144.52.38
|
||||
*
|
||||
* @param string $ip An IPv6 address
|
||||
* @return string[] [0] contains the IPv6 represented part, and [1] the IPv4 represented part
|
||||
*/
|
||||
private static function split_v6_v4($ip) {
|
||||
if (strpos($ip, '.') !== false) {
|
||||
$pos = strrpos($ip, ':');
|
||||
$ipv6_part = substr($ip, 0, $pos);
|
||||
$ipv4_part = substr($ip, $pos + 1);
|
||||
return [$ipv6_part, $ipv4_part];
|
||||
} else {
|
||||
return [$ip, ''];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks an IPv6 address
|
||||
*
|
||||
* Checks if the given IP is a valid IPv6 address
|
||||
*
|
||||
* @param string $ip An IPv6 address
|
||||
* @return bool true if $ip is a valid IPv6 address
|
||||
*/
|
||||
public static function check_ipv6($ip) {
|
||||
// Note: Input validation is handled in the `uncompress()` method, which is the first call made in this method.
|
||||
$ip = self::uncompress($ip);
|
||||
list($ipv6, $ipv4) = self::split_v6_v4($ip);
|
||||
$ipv6 = explode(':', $ipv6);
|
||||
$ipv4 = explode('.', $ipv4);
|
||||
if (count($ipv6) === 8 && count($ipv4) === 1 || count($ipv6) === 6 && count($ipv4) === 4) {
|
||||
foreach ($ipv6 as $ipv6_part) {
|
||||
// The section can't be empty
|
||||
if ($ipv6_part === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Nor can it be over four characters
|
||||
if (strlen($ipv6_part) > 4) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Remove leading zeros (this is safe because of the above)
|
||||
$ipv6_part = ltrim($ipv6_part, '0');
|
||||
if ($ipv6_part === '') {
|
||||
$ipv6_part = '0';
|
||||
}
|
||||
|
||||
// Check the value is valid
|
||||
$value = hexdec($ipv6_part);
|
||||
if (dechex($value) !== strtolower($ipv6_part) || $value < 0 || $value > 0xFFFF) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (count($ipv4) === 4) {
|
||||
foreach ($ipv4 as $ipv4_part) {
|
||||
$value = (int) $ipv4_part;
|
||||
if ((string) $value !== $ipv4_part || $value < 0 || $value > 0xFF) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Class to validate and to work with IPv6 addresses
|
||||
*
|
||||
* @package Requests\Utilities
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests;
|
||||
|
||||
use WpOrg\Requests\Exception\InvalidArgument;
|
||||
use WpOrg\Requests\Utility\InputValidator;
|
||||
|
||||
/**
|
||||
* Class to validate and to work with IPv6 addresses
|
||||
*
|
||||
* This was originally based on the PEAR class of the same name, but has been
|
||||
* entirely rewritten.
|
||||
*
|
||||
* @package Requests\Utilities
|
||||
*/
|
||||
final class Ipv6 {
|
||||
/**
|
||||
* Uncompresses an IPv6 address
|
||||
*
|
||||
* RFC 4291 allows you to compress consecutive zero pieces in an address to
|
||||
* '::'. This method expects a valid IPv6 address and expands the '::' to
|
||||
* the required number of zero pieces.
|
||||
*
|
||||
* Example: FF01::101 -> FF01:0:0:0:0:0:0:101
|
||||
* ::1 -> 0:0:0:0:0:0:0:1
|
||||
*
|
||||
* @author Alexander Merz <alexander.merz@web.de>
|
||||
* @author elfrink at introweb dot nl
|
||||
* @author Josh Peck <jmp at joshpeck dot org>
|
||||
* @copyright 2003-2005 The PHP Group
|
||||
* @license https://opensource.org/licenses/bsd-license.php
|
||||
*
|
||||
* @param string|Stringable $ip An IPv6 address
|
||||
* @return string The uncompressed IPv6 address
|
||||
*
|
||||
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed argument is not a string or a stringable object.
|
||||
*/
|
||||
public static function uncompress($ip) {
|
||||
if (InputValidator::is_string_or_stringable($ip) === false) {
|
||||
throw InvalidArgument::create(1, '$ip', 'string|Stringable', gettype($ip));
|
||||
}
|
||||
|
||||
$ip = (string) $ip;
|
||||
|
||||
if (substr_count($ip, '::') !== 1) {
|
||||
return $ip;
|
||||
}
|
||||
|
||||
list($ip1, $ip2) = explode('::', $ip);
|
||||
$c1 = ($ip1 === '') ? -1 : substr_count($ip1, ':');
|
||||
$c2 = ($ip2 === '') ? -1 : substr_count($ip2, ':');
|
||||
|
||||
if (strpos($ip2, '.') !== false) {
|
||||
$c2++;
|
||||
}
|
||||
|
||||
if ($c1 === -1 && $c2 === -1) {
|
||||
// ::
|
||||
$ip = '0:0:0:0:0:0:0:0';
|
||||
} elseif ($c1 === -1) {
|
||||
// ::xxx
|
||||
$fill = str_repeat('0:', 7 - $c2);
|
||||
$ip = str_replace('::', $fill, $ip);
|
||||
} elseif ($c2 === -1) {
|
||||
// xxx::
|
||||
$fill = str_repeat(':0', 7 - $c1);
|
||||
$ip = str_replace('::', $fill, $ip);
|
||||
} else {
|
||||
// xxx::xxx
|
||||
$fill = ':' . str_repeat('0:', 6 - $c2 - $c1);
|
||||
$ip = str_replace('::', $fill, $ip);
|
||||
}
|
||||
|
||||
return $ip;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compresses an IPv6 address
|
||||
*
|
||||
* RFC 4291 allows you to compress consecutive zero pieces in an address to
|
||||
* '::'. This method expects a valid IPv6 address and compresses consecutive
|
||||
* zero pieces to '::'.
|
||||
*
|
||||
* Example: FF01:0:0:0:0:0:0:101 -> FF01::101
|
||||
* 0:0:0:0:0:0:0:1 -> ::1
|
||||
*
|
||||
* @see \WpOrg\Requests\Ipv6::uncompress()
|
||||
*
|
||||
* @param string $ip An IPv6 address
|
||||
* @return string The compressed IPv6 address
|
||||
*/
|
||||
public static function compress($ip) {
|
||||
// Prepare the IP to be compressed.
|
||||
// Note: Input validation is handled in the `uncompress()` method, which is the first call made in this method.
|
||||
$ip = self::uncompress($ip);
|
||||
$ip_parts = self::split_v6_v4($ip);
|
||||
|
||||
// Replace all leading zeros
|
||||
$ip_parts[0] = preg_replace('/(^|:)0+([0-9])/', '\1\2', $ip_parts[0]);
|
||||
|
||||
// Find bunches of zeros
|
||||
if (preg_match_all('/(?:^|:)(?:0(?::|$))+/', $ip_parts[0], $matches, PREG_OFFSET_CAPTURE)) {
|
||||
$max = 0;
|
||||
$pos = null;
|
||||
foreach ($matches[0] as $match) {
|
||||
if (strlen($match[0]) > $max) {
|
||||
$max = strlen($match[0]);
|
||||
$pos = $match[1];
|
||||
}
|
||||
}
|
||||
|
||||
$ip_parts[0] = substr_replace($ip_parts[0], '::', $pos, $max);
|
||||
}
|
||||
|
||||
if ($ip_parts[1] !== '') {
|
||||
return implode(':', $ip_parts);
|
||||
} else {
|
||||
return $ip_parts[0];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits an IPv6 address into the IPv6 and IPv4 representation parts
|
||||
*
|
||||
* RFC 4291 allows you to represent the last two parts of an IPv6 address
|
||||
* using the standard IPv4 representation
|
||||
*
|
||||
* Example: 0:0:0:0:0:0:13.1.68.3
|
||||
* 0:0:0:0:0:FFFF:129.144.52.38
|
||||
*
|
||||
* @param string $ip An IPv6 address
|
||||
* @return string[] [0] contains the IPv6 represented part, and [1] the IPv4 represented part
|
||||
*/
|
||||
private static function split_v6_v4($ip) {
|
||||
if (strpos($ip, '.') !== false) {
|
||||
$pos = strrpos($ip, ':');
|
||||
$ipv6_part = substr($ip, 0, $pos);
|
||||
$ipv4_part = substr($ip, $pos + 1);
|
||||
return [$ipv6_part, $ipv4_part];
|
||||
} else {
|
||||
return [$ip, ''];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks an IPv6 address
|
||||
*
|
||||
* Checks if the given IP is a valid IPv6 address
|
||||
*
|
||||
* @param string $ip An IPv6 address
|
||||
* @return bool true if $ip is a valid IPv6 address
|
||||
*/
|
||||
public static function check_ipv6($ip) {
|
||||
// Note: Input validation is handled in the `uncompress()` method, which is the first call made in this method.
|
||||
$ip = self::uncompress($ip);
|
||||
list($ipv6, $ipv4) = self::split_v6_v4($ip);
|
||||
$ipv6 = explode(':', $ipv6);
|
||||
$ipv4 = explode('.', $ipv4);
|
||||
if (count($ipv6) === 8 && count($ipv4) === 1 || count($ipv6) === 6 && count($ipv4) === 4) {
|
||||
foreach ($ipv6 as $ipv6_part) {
|
||||
// The section can't be empty
|
||||
if ($ipv6_part === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Nor can it be over four characters
|
||||
if (strlen($ipv6_part) > 4) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Remove leading zeros (this is safe because of the above)
|
||||
$ipv6_part = ltrim($ipv6_part, '0');
|
||||
if ($ipv6_part === '') {
|
||||
$ipv6_part = '0';
|
||||
}
|
||||
|
||||
// Check the value is valid
|
||||
$value = hexdec($ipv6_part);
|
||||
if (dechex($value) !== strtolower($ipv6_part) || $value < 0 || $value > 0xFFFF) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (count($ipv4) === 4) {
|
||||
foreach ($ipv4 as $ipv4_part) {
|
||||
$value = (int) $ipv4_part;
|
||||
if ((string) $value !== $ipv4_part || $value < 0 || $value > 0xFF) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,75 +1,75 @@
|
||||
<?php
|
||||
/**
|
||||
* Port utilities for Requests
|
||||
*
|
||||
* @package Requests\Utilities
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests;
|
||||
|
||||
use WpOrg\Requests\Exception;
|
||||
use WpOrg\Requests\Exception\InvalidArgument;
|
||||
|
||||
/**
|
||||
* Find the correct port depending on the Request type.
|
||||
*
|
||||
* @package Requests\Utilities
|
||||
* @since 2.0.0
|
||||
*/
|
||||
final class Port {
|
||||
|
||||
/**
|
||||
* Port to use with Acap requests.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const ACAP = 674;
|
||||
|
||||
/**
|
||||
* Port to use with Dictionary requests.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const DICT = 2628;
|
||||
|
||||
/**
|
||||
* Port to use with HTTP requests.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const HTTP = 80;
|
||||
|
||||
/**
|
||||
* Port to use with HTTP over SSL requests.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const HTTPS = 443;
|
||||
|
||||
/**
|
||||
* Retrieve the port number to use.
|
||||
*
|
||||
* @param string $type Request type.
|
||||
* The following requests types are supported:
|
||||
* 'acap', 'dict', 'http' and 'https'.
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @throws \WpOrg\Requests\Exception\InvalidArgument When a non-string input has been passed.
|
||||
* @throws \WpOrg\Requests\Exception When a non-supported port is requested ('portnotsupported').
|
||||
*/
|
||||
public static function get($type) {
|
||||
if (!is_string($type)) {
|
||||
throw InvalidArgument::create(1, '$type', 'string', gettype($type));
|
||||
}
|
||||
|
||||
$type = strtoupper($type);
|
||||
if (!defined("self::{$type}")) {
|
||||
$message = sprintf('Invalid port type (%s) passed', $type);
|
||||
throw new Exception($message, 'portnotsupported');
|
||||
}
|
||||
|
||||
return constant("self::{$type}");
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Port utilities for Requests
|
||||
*
|
||||
* @package Requests\Utilities
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests;
|
||||
|
||||
use WpOrg\Requests\Exception;
|
||||
use WpOrg\Requests\Exception\InvalidArgument;
|
||||
|
||||
/**
|
||||
* Find the correct port depending on the Request type.
|
||||
*
|
||||
* @package Requests\Utilities
|
||||
* @since 2.0.0
|
||||
*/
|
||||
final class Port {
|
||||
|
||||
/**
|
||||
* Port to use with Acap requests.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const ACAP = 674;
|
||||
|
||||
/**
|
||||
* Port to use with Dictionary requests.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const DICT = 2628;
|
||||
|
||||
/**
|
||||
* Port to use with HTTP requests.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const HTTP = 80;
|
||||
|
||||
/**
|
||||
* Port to use with HTTP over SSL requests.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const HTTPS = 443;
|
||||
|
||||
/**
|
||||
* Retrieve the port number to use.
|
||||
*
|
||||
* @param string $type Request type.
|
||||
* The following requests types are supported:
|
||||
* 'acap', 'dict', 'http' and 'https'.
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @throws \WpOrg\Requests\Exception\InvalidArgument When a non-string input has been passed.
|
||||
* @throws \WpOrg\Requests\Exception When a non-supported port is requested ('portnotsupported').
|
||||
*/
|
||||
public static function get($type) {
|
||||
if (!is_string($type)) {
|
||||
throw InvalidArgument::create(1, '$type', 'string', gettype($type));
|
||||
}
|
||||
|
||||
$type = strtoupper($type);
|
||||
if (!defined("self::{$type}")) {
|
||||
$message = sprintf('Invalid port type (%s) passed', $type);
|
||||
throw new Exception($message, 'portnotsupported');
|
||||
}
|
||||
|
||||
return constant("self::{$type}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,38 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
* Proxy connection interface
|
||||
*
|
||||
* @package Requests\Proxy
|
||||
* @since 1.6
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests;
|
||||
|
||||
use WpOrg\Requests\Hooks;
|
||||
|
||||
/**
|
||||
* Proxy connection interface
|
||||
*
|
||||
* Implement this interface to handle proxy settings and authentication
|
||||
*
|
||||
* Parameters should be passed via the constructor where possible, as this
|
||||
* makes it much easier for users to use your provider.
|
||||
*
|
||||
* @see \WpOrg\Requests\Hooks
|
||||
*
|
||||
* @package Requests\Proxy
|
||||
* @since 1.6
|
||||
*/
|
||||
interface Proxy {
|
||||
/**
|
||||
* Register hooks as needed
|
||||
*
|
||||
* This method is called in {@see \WpOrg\Requests\Requests::request()} when the user
|
||||
* has set an instance as the 'auth' option. Use this callback to register all the
|
||||
* hooks you'll need.
|
||||
*
|
||||
* @see \WpOrg\Requests\Hooks::register()
|
||||
* @param \WpOrg\Requests\Hooks $hooks Hook system
|
||||
*/
|
||||
public function register(Hooks $hooks);
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Proxy connection interface
|
||||
*
|
||||
* @package Requests\Proxy
|
||||
* @since 1.6
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests;
|
||||
|
||||
use WpOrg\Requests\Hooks;
|
||||
|
||||
/**
|
||||
* Proxy connection interface
|
||||
*
|
||||
* Implement this interface to handle proxy settings and authentication
|
||||
*
|
||||
* Parameters should be passed via the constructor where possible, as this
|
||||
* makes it much easier for users to use your provider.
|
||||
*
|
||||
* @see \WpOrg\Requests\Hooks
|
||||
*
|
||||
* @package Requests\Proxy
|
||||
* @since 1.6
|
||||
*/
|
||||
interface Proxy {
|
||||
/**
|
||||
* Register hooks as needed
|
||||
*
|
||||
* This method is called in {@see \WpOrg\Requests\Requests::request()} when the user
|
||||
* has set an instance as the 'auth' option. Use this callback to register all the
|
||||
* hooks you'll need.
|
||||
*
|
||||
* @see \WpOrg\Requests\Hooks::register()
|
||||
* @param \WpOrg\Requests\Hooks $hooks Hook system
|
||||
*/
|
||||
public function register(Hooks $hooks);
|
||||
}
|
||||
|
||||
@@ -1,164 +1,164 @@
|
||||
<?php
|
||||
/**
|
||||
* HTTP Proxy connection interface
|
||||
*
|
||||
* @package Requests\Proxy
|
||||
* @since 1.6
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Proxy;
|
||||
|
||||
use WpOrg\Requests\Exception\ArgumentCount;
|
||||
use WpOrg\Requests\Exception\InvalidArgument;
|
||||
use WpOrg\Requests\Hooks;
|
||||
use WpOrg\Requests\Proxy;
|
||||
|
||||
/**
|
||||
* HTTP Proxy connection interface
|
||||
*
|
||||
* Provides a handler for connection via an HTTP proxy
|
||||
*
|
||||
* @package Requests\Proxy
|
||||
* @since 1.6
|
||||
*/
|
||||
final class Http implements Proxy {
|
||||
/**
|
||||
* Proxy host and port
|
||||
*
|
||||
* Notation: "host:port" (eg 127.0.0.1:8080 or someproxy.com:3128)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $proxy;
|
||||
|
||||
/**
|
||||
* Username
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $user;
|
||||
|
||||
/**
|
||||
* Password
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $pass;
|
||||
|
||||
/**
|
||||
* Do we need to authenticate? (ie username & password have been provided)
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $use_authentication;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @since 1.6
|
||||
*
|
||||
* @param array|string|null $args Proxy as a string or an array of proxy, user and password.
|
||||
* When passed as an array, must have exactly one (proxy)
|
||||
* or three elements (proxy, user, password).
|
||||
*
|
||||
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed argument is not an array, a string or null.
|
||||
* @throws \WpOrg\Requests\Exception\ArgumentCount On incorrect number of arguments (`proxyhttpbadargs`)
|
||||
*/
|
||||
public function __construct($args = null) {
|
||||
if (is_string($args)) {
|
||||
$this->proxy = $args;
|
||||
} elseif (is_array($args)) {
|
||||
if (count($args) === 1) {
|
||||
list($this->proxy) = $args;
|
||||
} elseif (count($args) === 3) {
|
||||
list($this->proxy, $this->user, $this->pass) = $args;
|
||||
$this->use_authentication = true;
|
||||
} else {
|
||||
throw ArgumentCount::create(
|
||||
'an array with exactly one element or exactly three elements',
|
||||
count($args),
|
||||
'proxyhttpbadargs'
|
||||
);
|
||||
}
|
||||
} elseif ($args !== null) {
|
||||
throw InvalidArgument::create(1, '$args', 'array|string|null', gettype($args));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the necessary callbacks
|
||||
*
|
||||
* @since 1.6
|
||||
* @see \WpOrg\Requests\Proxy\Http::curl_before_send()
|
||||
* @see \WpOrg\Requests\Proxy\Http::fsockopen_remote_socket()
|
||||
* @see \WpOrg\Requests\Proxy\Http::fsockopen_remote_host_path()
|
||||
* @see \WpOrg\Requests\Proxy\Http::fsockopen_header()
|
||||
* @param \WpOrg\Requests\Hooks $hooks Hook system
|
||||
*/
|
||||
public function register(Hooks $hooks) {
|
||||
$hooks->register('curl.before_send', [$this, 'curl_before_send']);
|
||||
|
||||
$hooks->register('fsockopen.remote_socket', [$this, 'fsockopen_remote_socket']);
|
||||
$hooks->register('fsockopen.remote_host_path', [$this, 'fsockopen_remote_host_path']);
|
||||
if ($this->use_authentication) {
|
||||
$hooks->register('fsockopen.after_headers', [$this, 'fsockopen_header']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set cURL parameters before the data is sent
|
||||
*
|
||||
* @since 1.6
|
||||
* @param resource|\CurlHandle $handle cURL handle
|
||||
*/
|
||||
public function curl_before_send(&$handle) {
|
||||
curl_setopt($handle, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
|
||||
curl_setopt($handle, CURLOPT_PROXY, $this->proxy);
|
||||
|
||||
if ($this->use_authentication) {
|
||||
curl_setopt($handle, CURLOPT_PROXYAUTH, CURLAUTH_ANY);
|
||||
curl_setopt($handle, CURLOPT_PROXYUSERPWD, $this->get_auth_string());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Alter remote socket information before opening socket connection
|
||||
*
|
||||
* @since 1.6
|
||||
* @param string $remote_socket Socket connection string
|
||||
*/
|
||||
public function fsockopen_remote_socket(&$remote_socket) {
|
||||
$remote_socket = $this->proxy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alter remote path before getting stream data
|
||||
*
|
||||
* @since 1.6
|
||||
* @param string $path Path to send in HTTP request string ("GET ...")
|
||||
* @param string $url Full URL we're requesting
|
||||
*/
|
||||
public function fsockopen_remote_host_path(&$path, $url) {
|
||||
$path = $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add extra headers to the request before sending
|
||||
*
|
||||
* @since 1.6
|
||||
* @param string $out HTTP header string
|
||||
*/
|
||||
public function fsockopen_header(&$out) {
|
||||
$out .= sprintf("Proxy-Authorization: Basic %s\r\n", base64_encode($this->get_auth_string()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the authentication string (user:pass)
|
||||
*
|
||||
* @since 1.6
|
||||
* @return string
|
||||
*/
|
||||
public function get_auth_string() {
|
||||
return $this->user . ':' . $this->pass;
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* HTTP Proxy connection interface
|
||||
*
|
||||
* @package Requests\Proxy
|
||||
* @since 1.6
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Proxy;
|
||||
|
||||
use WpOrg\Requests\Exception\ArgumentCount;
|
||||
use WpOrg\Requests\Exception\InvalidArgument;
|
||||
use WpOrg\Requests\Hooks;
|
||||
use WpOrg\Requests\Proxy;
|
||||
|
||||
/**
|
||||
* HTTP Proxy connection interface
|
||||
*
|
||||
* Provides a handler for connection via an HTTP proxy
|
||||
*
|
||||
* @package Requests\Proxy
|
||||
* @since 1.6
|
||||
*/
|
||||
final class Http implements Proxy {
|
||||
/**
|
||||
* Proxy host and port
|
||||
*
|
||||
* Notation: "host:port" (eg 127.0.0.1:8080 or someproxy.com:3128)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $proxy;
|
||||
|
||||
/**
|
||||
* Username
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $user;
|
||||
|
||||
/**
|
||||
* Password
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $pass;
|
||||
|
||||
/**
|
||||
* Do we need to authenticate? (ie username & password have been provided)
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $use_authentication;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @since 1.6
|
||||
*
|
||||
* @param array|string|null $args Proxy as a string or an array of proxy, user and password.
|
||||
* When passed as an array, must have exactly one (proxy)
|
||||
* or three elements (proxy, user, password).
|
||||
*
|
||||
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed argument is not an array, a string or null.
|
||||
* @throws \WpOrg\Requests\Exception\ArgumentCount On incorrect number of arguments (`proxyhttpbadargs`)
|
||||
*/
|
||||
public function __construct($args = null) {
|
||||
if (is_string($args)) {
|
||||
$this->proxy = $args;
|
||||
} elseif (is_array($args)) {
|
||||
if (count($args) === 1) {
|
||||
list($this->proxy) = $args;
|
||||
} elseif (count($args) === 3) {
|
||||
list($this->proxy, $this->user, $this->pass) = $args;
|
||||
$this->use_authentication = true;
|
||||
} else {
|
||||
throw ArgumentCount::create(
|
||||
'an array with exactly one element or exactly three elements',
|
||||
count($args),
|
||||
'proxyhttpbadargs'
|
||||
);
|
||||
}
|
||||
} elseif ($args !== null) {
|
||||
throw InvalidArgument::create(1, '$args', 'array|string|null', gettype($args));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the necessary callbacks
|
||||
*
|
||||
* @since 1.6
|
||||
* @see \WpOrg\Requests\Proxy\Http::curl_before_send()
|
||||
* @see \WpOrg\Requests\Proxy\Http::fsockopen_remote_socket()
|
||||
* @see \WpOrg\Requests\Proxy\Http::fsockopen_remote_host_path()
|
||||
* @see \WpOrg\Requests\Proxy\Http::fsockopen_header()
|
||||
* @param \WpOrg\Requests\Hooks $hooks Hook system
|
||||
*/
|
||||
public function register(Hooks $hooks) {
|
||||
$hooks->register('curl.before_send', [$this, 'curl_before_send']);
|
||||
|
||||
$hooks->register('fsockopen.remote_socket', [$this, 'fsockopen_remote_socket']);
|
||||
$hooks->register('fsockopen.remote_host_path', [$this, 'fsockopen_remote_host_path']);
|
||||
if ($this->use_authentication) {
|
||||
$hooks->register('fsockopen.after_headers', [$this, 'fsockopen_header']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set cURL parameters before the data is sent
|
||||
*
|
||||
* @since 1.6
|
||||
* @param resource|\CurlHandle $handle cURL handle
|
||||
*/
|
||||
public function curl_before_send(&$handle) {
|
||||
curl_setopt($handle, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
|
||||
curl_setopt($handle, CURLOPT_PROXY, $this->proxy);
|
||||
|
||||
if ($this->use_authentication) {
|
||||
curl_setopt($handle, CURLOPT_PROXYAUTH, CURLAUTH_ANY);
|
||||
curl_setopt($handle, CURLOPT_PROXYUSERPWD, $this->get_auth_string());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Alter remote socket information before opening socket connection
|
||||
*
|
||||
* @since 1.6
|
||||
* @param string $remote_socket Socket connection string
|
||||
*/
|
||||
public function fsockopen_remote_socket(&$remote_socket) {
|
||||
$remote_socket = $this->proxy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alter remote path before getting stream data
|
||||
*
|
||||
* @since 1.6
|
||||
* @param string $path Path to send in HTTP request string ("GET ...")
|
||||
* @param string $url Full URL we're requesting
|
||||
*/
|
||||
public function fsockopen_remote_host_path(&$path, $url) {
|
||||
$path = $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add extra headers to the request before sending
|
||||
*
|
||||
* @since 1.6
|
||||
* @param string $out HTTP header string
|
||||
*/
|
||||
public function fsockopen_header(&$out) {
|
||||
$out .= sprintf("Proxy-Authorization: Basic %s\r\n", base64_encode($this->get_auth_string()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the authentication string (user:pass)
|
||||
*
|
||||
* @since 1.6
|
||||
* @return string
|
||||
*/
|
||||
public function get_auth_string() {
|
||||
return $this->user . ':' . $this->pass;
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,165 +1,165 @@
|
||||
<?php
|
||||
/**
|
||||
* HTTP response class
|
||||
*
|
||||
* Contains a response from \WpOrg\Requests\Requests::request()
|
||||
*
|
||||
* @package Requests
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests;
|
||||
|
||||
use WpOrg\Requests\Cookie\Jar;
|
||||
use WpOrg\Requests\Exception;
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
use WpOrg\Requests\Response\Headers;
|
||||
|
||||
/**
|
||||
* HTTP response class
|
||||
*
|
||||
* Contains a response from \WpOrg\Requests\Requests::request()
|
||||
*
|
||||
* @package Requests
|
||||
*/
|
||||
class Response {
|
||||
|
||||
/**
|
||||
* Response body
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $body = '';
|
||||
|
||||
/**
|
||||
* Raw HTTP data from the transport
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $raw = '';
|
||||
|
||||
/**
|
||||
* Headers, as an associative array
|
||||
*
|
||||
* @var \WpOrg\Requests\Response\Headers Array-like object representing headers
|
||||
*/
|
||||
public $headers = [];
|
||||
|
||||
/**
|
||||
* Status code, false if non-blocking
|
||||
*
|
||||
* @var integer|boolean
|
||||
*/
|
||||
public $status_code = false;
|
||||
|
||||
/**
|
||||
* Protocol version, false if non-blocking
|
||||
*
|
||||
* @var float|boolean
|
||||
*/
|
||||
public $protocol_version = false;
|
||||
|
||||
/**
|
||||
* Whether the request succeeded or not
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $success = false;
|
||||
|
||||
/**
|
||||
* Number of redirects the request used
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
public $redirects = 0;
|
||||
|
||||
/**
|
||||
* URL requested
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $url = '';
|
||||
|
||||
/**
|
||||
* Previous requests (from redirects)
|
||||
*
|
||||
* @var array Array of \WpOrg\Requests\Response objects
|
||||
*/
|
||||
public $history = [];
|
||||
|
||||
/**
|
||||
* Cookies from the request
|
||||
*
|
||||
* @var \WpOrg\Requests\Cookie\Jar Array-like object representing a cookie jar
|
||||
*/
|
||||
public $cookies = [];
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->headers = new Headers();
|
||||
$this->cookies = new Jar();
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the response a redirect?
|
||||
*
|
||||
* @return boolean True if redirect (3xx status), false if not.
|
||||
*/
|
||||
public function is_redirect() {
|
||||
$code = $this->status_code;
|
||||
return in_array($code, [300, 301, 302, 303, 307], true) || $code > 307 && $code < 400;
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws an exception if the request was not successful
|
||||
*
|
||||
* @param boolean $allow_redirects Set to false to throw on a 3xx as well
|
||||
*
|
||||
* @throws \WpOrg\Requests\Exception If `$allow_redirects` is false, and code is 3xx (`response.no_redirects`)
|
||||
* @throws \WpOrg\Requests\Exception\Http On non-successful status code. Exception class corresponds to "Status" + code (e.g. {@see \WpOrg\Requests\Exception\Http\Status404})
|
||||
*/
|
||||
public function throw_for_status($allow_redirects = true) {
|
||||
if ($this->is_redirect()) {
|
||||
if ($allow_redirects !== true) {
|
||||
throw new Exception('Redirection not allowed', 'response.no_redirects', $this);
|
||||
}
|
||||
} elseif (!$this->success) {
|
||||
$exception = Http::get_class($this->status_code);
|
||||
throw new $exception(null, $this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* JSON decode the response body.
|
||||
*
|
||||
* The method parameters are the same as those for the PHP native `json_decode()` function.
|
||||
*
|
||||
* @link https://php.net/json-decode
|
||||
*
|
||||
* @param bool|null $associative Optional. When `true`, JSON objects will be returned as associative arrays;
|
||||
* When `false`, JSON objects will be returned as objects.
|
||||
* When `null`, JSON objects will be returned as associative arrays
|
||||
* or objects depending on whether `JSON_OBJECT_AS_ARRAY` is set in the flags.
|
||||
* Defaults to `true` (in contrast to the PHP native default of `null`).
|
||||
* @param int $depth Optional. Maximum nesting depth of the structure being decoded.
|
||||
* Defaults to `512`.
|
||||
* @param int $options Optional. Bitmask of JSON_BIGINT_AS_STRING, JSON_INVALID_UTF8_IGNORE,
|
||||
* JSON_INVALID_UTF8_SUBSTITUTE, JSON_OBJECT_AS_ARRAY, JSON_THROW_ON_ERROR.
|
||||
* Defaults to `0` (no options set).
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws \WpOrg\Requests\Exception If `$this->body` is not valid json.
|
||||
*/
|
||||
public function decode_body($associative = true, $depth = 512, $options = 0) {
|
||||
$data = json_decode($this->body, $associative, $depth, $options);
|
||||
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
$last_error = json_last_error_msg();
|
||||
throw new Exception('Unable to parse JSON data: ' . $last_error, 'response.invalid', $this);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* HTTP response class
|
||||
*
|
||||
* Contains a response from \WpOrg\Requests\Requests::request()
|
||||
*
|
||||
* @package Requests
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests;
|
||||
|
||||
use WpOrg\Requests\Cookie\Jar;
|
||||
use WpOrg\Requests\Exception;
|
||||
use WpOrg\Requests\Exception\Http;
|
||||
use WpOrg\Requests\Response\Headers;
|
||||
|
||||
/**
|
||||
* HTTP response class
|
||||
*
|
||||
* Contains a response from \WpOrg\Requests\Requests::request()
|
||||
*
|
||||
* @package Requests
|
||||
*/
|
||||
class Response {
|
||||
|
||||
/**
|
||||
* Response body
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $body = '';
|
||||
|
||||
/**
|
||||
* Raw HTTP data from the transport
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $raw = '';
|
||||
|
||||
/**
|
||||
* Headers, as an associative array
|
||||
*
|
||||
* @var \WpOrg\Requests\Response\Headers Array-like object representing headers
|
||||
*/
|
||||
public $headers = [];
|
||||
|
||||
/**
|
||||
* Status code, false if non-blocking
|
||||
*
|
||||
* @var integer|boolean
|
||||
*/
|
||||
public $status_code = false;
|
||||
|
||||
/**
|
||||
* Protocol version, false if non-blocking
|
||||
*
|
||||
* @var float|boolean
|
||||
*/
|
||||
public $protocol_version = false;
|
||||
|
||||
/**
|
||||
* Whether the request succeeded or not
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $success = false;
|
||||
|
||||
/**
|
||||
* Number of redirects the request used
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
public $redirects = 0;
|
||||
|
||||
/**
|
||||
* URL requested
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $url = '';
|
||||
|
||||
/**
|
||||
* Previous requests (from redirects)
|
||||
*
|
||||
* @var array Array of \WpOrg\Requests\Response objects
|
||||
*/
|
||||
public $history = [];
|
||||
|
||||
/**
|
||||
* Cookies from the request
|
||||
*
|
||||
* @var \WpOrg\Requests\Cookie\Jar Array-like object representing a cookie jar
|
||||
*/
|
||||
public $cookies = [];
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->headers = new Headers();
|
||||
$this->cookies = new Jar();
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the response a redirect?
|
||||
*
|
||||
* @return boolean True if redirect (3xx status), false if not.
|
||||
*/
|
||||
public function is_redirect() {
|
||||
$code = $this->status_code;
|
||||
return in_array($code, [300, 301, 302, 303, 307], true) || $code > 307 && $code < 400;
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws an exception if the request was not successful
|
||||
*
|
||||
* @param boolean $allow_redirects Set to false to throw on a 3xx as well
|
||||
*
|
||||
* @throws \WpOrg\Requests\Exception If `$allow_redirects` is false, and code is 3xx (`response.no_redirects`)
|
||||
* @throws \WpOrg\Requests\Exception\Http On non-successful status code. Exception class corresponds to "Status" + code (e.g. {@see \WpOrg\Requests\Exception\Http\Status404})
|
||||
*/
|
||||
public function throw_for_status($allow_redirects = true) {
|
||||
if ($this->is_redirect()) {
|
||||
if ($allow_redirects !== true) {
|
||||
throw new Exception('Redirection not allowed', 'response.no_redirects', $this);
|
||||
}
|
||||
} elseif (!$this->success) {
|
||||
$exception = Http::get_class($this->status_code);
|
||||
throw new $exception(null, $this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* JSON decode the response body.
|
||||
*
|
||||
* The method parameters are the same as those for the PHP native `json_decode()` function.
|
||||
*
|
||||
* @link https://php.net/json-decode
|
||||
*
|
||||
* @param bool|null $associative Optional. When `true`, JSON objects will be returned as associative arrays;
|
||||
* When `false`, JSON objects will be returned as objects.
|
||||
* When `null`, JSON objects will be returned as associative arrays
|
||||
* or objects depending on whether `JSON_OBJECT_AS_ARRAY` is set in the flags.
|
||||
* Defaults to `true` (in contrast to the PHP native default of `null`).
|
||||
* @param int $depth Optional. Maximum nesting depth of the structure being decoded.
|
||||
* Defaults to `512`.
|
||||
* @param int $options Optional. Bitmask of JSON_BIGINT_AS_STRING, JSON_INVALID_UTF8_IGNORE,
|
||||
* JSON_INVALID_UTF8_SUBSTITUTE, JSON_OBJECT_AS_ARRAY, JSON_THROW_ON_ERROR.
|
||||
* Defaults to `0` (no options set).
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws \WpOrg\Requests\Exception If `$this->body` is not valid json.
|
||||
*/
|
||||
public function decode_body($associative = true, $depth = 512, $options = 0) {
|
||||
$data = json_decode($this->body, $associative, $depth, $options);
|
||||
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
$last_error = json_last_error_msg();
|
||||
throw new Exception('Unable to parse JSON data: ' . $last_error, 'response.invalid', $this);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,127 +1,127 @@
|
||||
<?php
|
||||
/**
|
||||
* Case-insensitive dictionary, suitable for HTTP headers
|
||||
*
|
||||
* @package Requests
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Response;
|
||||
|
||||
use WpOrg\Requests\Exception;
|
||||
use WpOrg\Requests\Exception\InvalidArgument;
|
||||
use WpOrg\Requests\Utility\CaseInsensitiveDictionary;
|
||||
use WpOrg\Requests\Utility\FilteredIterator;
|
||||
|
||||
/**
|
||||
* Case-insensitive dictionary, suitable for HTTP headers
|
||||
*
|
||||
* @package Requests
|
||||
*/
|
||||
class Headers extends CaseInsensitiveDictionary {
|
||||
/**
|
||||
* Get the given header
|
||||
*
|
||||
* Unlike {@see \WpOrg\Requests\Response\Headers::getValues()}, this returns a string. If there are
|
||||
* multiple values, it concatenates them with a comma as per RFC2616.
|
||||
*
|
||||
* Avoid using this where commas may be used unquoted in values, such as
|
||||
* Set-Cookie headers.
|
||||
*
|
||||
* @param string $offset Name of the header to retrieve.
|
||||
* @return string|null Header value
|
||||
*/
|
||||
public function offsetGet($offset) {
|
||||
if (is_string($offset)) {
|
||||
$offset = strtolower($offset);
|
||||
}
|
||||
|
||||
if (!isset($this->data[$offset])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->flatten($this->data[$offset]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the given item
|
||||
*
|
||||
* @param string $offset Item name
|
||||
* @param string $value Item value
|
||||
*
|
||||
* @throws \WpOrg\Requests\Exception On attempting to use dictionary as list (`invalidset`)
|
||||
*/
|
||||
public function offsetSet($offset, $value) {
|
||||
if ($offset === null) {
|
||||
throw new Exception('Object is a dictionary, not a list', 'invalidset');
|
||||
}
|
||||
|
||||
if (is_string($offset)) {
|
||||
$offset = strtolower($offset);
|
||||
}
|
||||
|
||||
if (!isset($this->data[$offset])) {
|
||||
$this->data[$offset] = [];
|
||||
}
|
||||
|
||||
$this->data[$offset][] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all values for a given header
|
||||
*
|
||||
* @param string $offset Name of the header to retrieve.
|
||||
* @return array|null Header values
|
||||
*
|
||||
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed argument is not valid as an array key.
|
||||
*/
|
||||
public function getValues($offset) {
|
||||
if (!is_string($offset) && !is_int($offset)) {
|
||||
throw InvalidArgument::create(1, '$offset', 'string|int', gettype($offset));
|
||||
}
|
||||
|
||||
if (is_string($offset)) {
|
||||
$offset = strtolower($offset);
|
||||
}
|
||||
|
||||
if (!isset($this->data[$offset])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->data[$offset];
|
||||
}
|
||||
|
||||
/**
|
||||
* Flattens a value into a string
|
||||
*
|
||||
* Converts an array into a string by imploding values with a comma, as per
|
||||
* RFC2616's rules for folding headers.
|
||||
*
|
||||
* @param string|array $value Value to flatten
|
||||
* @return string Flattened value
|
||||
*
|
||||
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed argument is not a string or an array.
|
||||
*/
|
||||
public function flatten($value) {
|
||||
if (is_string($value)) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
if (is_array($value)) {
|
||||
return implode(',', $value);
|
||||
}
|
||||
|
||||
throw InvalidArgument::create(1, '$value', 'string|array', gettype($value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an iterator for the data
|
||||
*
|
||||
* Converts the internally stored values to a comma-separated string if there is more
|
||||
* than one value for a key.
|
||||
*
|
||||
* @return \ArrayIterator
|
||||
*/
|
||||
public function getIterator() {
|
||||
return new FilteredIterator($this->data, [$this, 'flatten']);
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Case-insensitive dictionary, suitable for HTTP headers
|
||||
*
|
||||
* @package Requests
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Response;
|
||||
|
||||
use WpOrg\Requests\Exception;
|
||||
use WpOrg\Requests\Exception\InvalidArgument;
|
||||
use WpOrg\Requests\Utility\CaseInsensitiveDictionary;
|
||||
use WpOrg\Requests\Utility\FilteredIterator;
|
||||
|
||||
/**
|
||||
* Case-insensitive dictionary, suitable for HTTP headers
|
||||
*
|
||||
* @package Requests
|
||||
*/
|
||||
class Headers extends CaseInsensitiveDictionary {
|
||||
/**
|
||||
* Get the given header
|
||||
*
|
||||
* Unlike {@see \WpOrg\Requests\Response\Headers::getValues()}, this returns a string. If there are
|
||||
* multiple values, it concatenates them with a comma as per RFC2616.
|
||||
*
|
||||
* Avoid using this where commas may be used unquoted in values, such as
|
||||
* Set-Cookie headers.
|
||||
*
|
||||
* @param string $offset Name of the header to retrieve.
|
||||
* @return string|null Header value
|
||||
*/
|
||||
public function offsetGet($offset) {
|
||||
if (is_string($offset)) {
|
||||
$offset = strtolower($offset);
|
||||
}
|
||||
|
||||
if (!isset($this->data[$offset])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->flatten($this->data[$offset]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the given item
|
||||
*
|
||||
* @param string $offset Item name
|
||||
* @param string $value Item value
|
||||
*
|
||||
* @throws \WpOrg\Requests\Exception On attempting to use dictionary as list (`invalidset`)
|
||||
*/
|
||||
public function offsetSet($offset, $value) {
|
||||
if ($offset === null) {
|
||||
throw new Exception('Object is a dictionary, not a list', 'invalidset');
|
||||
}
|
||||
|
||||
if (is_string($offset)) {
|
||||
$offset = strtolower($offset);
|
||||
}
|
||||
|
||||
if (!isset($this->data[$offset])) {
|
||||
$this->data[$offset] = [];
|
||||
}
|
||||
|
||||
$this->data[$offset][] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all values for a given header
|
||||
*
|
||||
* @param string $offset Name of the header to retrieve.
|
||||
* @return array|null Header values
|
||||
*
|
||||
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed argument is not valid as an array key.
|
||||
*/
|
||||
public function getValues($offset) {
|
||||
if (!is_string($offset) && !is_int($offset)) {
|
||||
throw InvalidArgument::create(1, '$offset', 'string|int', gettype($offset));
|
||||
}
|
||||
|
||||
if (is_string($offset)) {
|
||||
$offset = strtolower($offset);
|
||||
}
|
||||
|
||||
if (!isset($this->data[$offset])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->data[$offset];
|
||||
}
|
||||
|
||||
/**
|
||||
* Flattens a value into a string
|
||||
*
|
||||
* Converts an array into a string by imploding values with a comma, as per
|
||||
* RFC2616's rules for folding headers.
|
||||
*
|
||||
* @param string|array $value Value to flatten
|
||||
* @return string Flattened value
|
||||
*
|
||||
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed argument is not a string or an array.
|
||||
*/
|
||||
public function flatten($value) {
|
||||
if (is_string($value)) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
if (is_array($value)) {
|
||||
return implode(',', $value);
|
||||
}
|
||||
|
||||
throw InvalidArgument::create(1, '$value', 'string|array', gettype($value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an iterator for the data
|
||||
*
|
||||
* Converts the internally stored values to a comma-separated string if there is more
|
||||
* than one value for a key.
|
||||
*
|
||||
* @return \ArrayIterator
|
||||
*/
|
||||
public function getIterator() {
|
||||
return new FilteredIterator($this->data, [$this, 'flatten']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,308 +1,308 @@
|
||||
<?php
|
||||
/**
|
||||
* Session handler for persistent requests and default parameters
|
||||
*
|
||||
* @package Requests\SessionHandler
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests;
|
||||
|
||||
use WpOrg\Requests\Cookie\Jar;
|
||||
use WpOrg\Requests\Exception\InvalidArgument;
|
||||
use WpOrg\Requests\Iri;
|
||||
use WpOrg\Requests\Requests;
|
||||
use WpOrg\Requests\Utility\InputValidator;
|
||||
|
||||
/**
|
||||
* Session handler for persistent requests and default parameters
|
||||
*
|
||||
* Allows various options to be set as default values, and merges both the
|
||||
* options and URL properties together. A base URL can be set for all requests,
|
||||
* with all subrequests resolved from this. Base options can be set (including
|
||||
* a shared cookie jar), then overridden for individual requests.
|
||||
*
|
||||
* @package Requests\SessionHandler
|
||||
*/
|
||||
class Session {
|
||||
/**
|
||||
* Base URL for requests
|
||||
*
|
||||
* URLs will be made absolute using this as the base
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
public $url = null;
|
||||
|
||||
/**
|
||||
* Base headers for requests
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $headers = [];
|
||||
|
||||
/**
|
||||
* Base data for requests
|
||||
*
|
||||
* If both the base data and the per-request data are arrays, the data will
|
||||
* be merged before sending the request.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $data = [];
|
||||
|
||||
/**
|
||||
* Base options for requests
|
||||
*
|
||||
* The base options are merged with the per-request data for each request.
|
||||
* The only default option is a shared cookie jar between requests.
|
||||
*
|
||||
* Values here can also be set directly via properties on the Session
|
||||
* object, e.g. `$session->useragent = 'X';`
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $options = [];
|
||||
|
||||
/**
|
||||
* Create a new session
|
||||
*
|
||||
* @param string|Stringable|null $url Base URL for requests
|
||||
* @param array $headers Default headers for requests
|
||||
* @param array $data Default data for requests
|
||||
* @param array $options Default options for requests
|
||||
*
|
||||
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $url argument is not a string, Stringable or null.
|
||||
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $headers argument is not an array.
|
||||
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $data argument is not an array.
|
||||
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $options argument is not an array.
|
||||
*/
|
||||
public function __construct($url = null, $headers = [], $data = [], $options = []) {
|
||||
if ($url !== null && InputValidator::is_string_or_stringable($url) === false) {
|
||||
throw InvalidArgument::create(1, '$url', 'string|Stringable|null', gettype($url));
|
||||
}
|
||||
|
||||
if (is_array($headers) === false) {
|
||||
throw InvalidArgument::create(2, '$headers', 'array', gettype($headers));
|
||||
}
|
||||
|
||||
if (is_array($data) === false) {
|
||||
throw InvalidArgument::create(3, '$data', 'array', gettype($data));
|
||||
}
|
||||
|
||||
if (is_array($options) === false) {
|
||||
throw InvalidArgument::create(4, '$options', 'array', gettype($options));
|
||||
}
|
||||
|
||||
$this->url = $url;
|
||||
$this->headers = $headers;
|
||||
$this->data = $data;
|
||||
$this->options = $options;
|
||||
|
||||
if (empty($this->options['cookies'])) {
|
||||
$this->options['cookies'] = new Jar();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a property's value
|
||||
*
|
||||
* @param string $name Property name.
|
||||
* @return mixed|null Property value, null if none found
|
||||
*/
|
||||
public function __get($name) {
|
||||
if (isset($this->options[$name])) {
|
||||
return $this->options[$name];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a property's value
|
||||
*
|
||||
* @param string $name Property name.
|
||||
* @param mixed $value Property value
|
||||
*/
|
||||
public function __set($name, $value) {
|
||||
$this->options[$name] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a property's value
|
||||
*
|
||||
* @param string $name Property name.
|
||||
*/
|
||||
public function __isset($name) {
|
||||
return isset($this->options[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a property's value
|
||||
*
|
||||
* @param string $name Property name.
|
||||
*/
|
||||
public function __unset($name) {
|
||||
unset($this->options[$name]);
|
||||
}
|
||||
|
||||
/**#@+
|
||||
* @see \WpOrg\Requests\Session::request()
|
||||
* @param string $url
|
||||
* @param array $headers
|
||||
* @param array $options
|
||||
* @return \WpOrg\Requests\Response
|
||||
*/
|
||||
/**
|
||||
* Send a GET request
|
||||
*/
|
||||
public function get($url, $headers = [], $options = []) {
|
||||
return $this->request($url, $headers, null, Requests::GET, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a HEAD request
|
||||
*/
|
||||
public function head($url, $headers = [], $options = []) {
|
||||
return $this->request($url, $headers, null, Requests::HEAD, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a DELETE request
|
||||
*/
|
||||
public function delete($url, $headers = [], $options = []) {
|
||||
return $this->request($url, $headers, null, Requests::DELETE, $options);
|
||||
}
|
||||
/**#@-*/
|
||||
|
||||
/**#@+
|
||||
* @see \WpOrg\Requests\Session::request()
|
||||
* @param string $url
|
||||
* @param array $headers
|
||||
* @param array $data
|
||||
* @param array $options
|
||||
* @return \WpOrg\Requests\Response
|
||||
*/
|
||||
/**
|
||||
* Send a POST request
|
||||
*/
|
||||
public function post($url, $headers = [], $data = [], $options = []) {
|
||||
return $this->request($url, $headers, $data, Requests::POST, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a PUT request
|
||||
*/
|
||||
public function put($url, $headers = [], $data = [], $options = []) {
|
||||
return $this->request($url, $headers, $data, Requests::PUT, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a PATCH request
|
||||
*
|
||||
* Note: Unlike {@see \WpOrg\Requests\Session::post()} and {@see \WpOrg\Requests\Session::put()},
|
||||
* `$headers` is required, as the specification recommends that should send an ETag
|
||||
*
|
||||
* @link https://tools.ietf.org/html/rfc5789
|
||||
*/
|
||||
public function patch($url, $headers, $data = [], $options = []) {
|
||||
return $this->request($url, $headers, $data, Requests::PATCH, $options);
|
||||
}
|
||||
/**#@-*/
|
||||
|
||||
/**
|
||||
* Main interface for HTTP requests
|
||||
*
|
||||
* This method initiates a request and sends it via a transport before
|
||||
* parsing.
|
||||
*
|
||||
* @see \WpOrg\Requests\Requests::request()
|
||||
*
|
||||
* @param string $url URL to request
|
||||
* @param array $headers Extra headers to send with the request
|
||||
* @param array|null $data Data to send either as a query string for GET/HEAD requests, or in the body for POST requests
|
||||
* @param string $type HTTP request type (use \WpOrg\Requests\Requests constants)
|
||||
* @param array $options Options for the request (see {@see \WpOrg\Requests\Requests::request()})
|
||||
* @return \WpOrg\Requests\Response
|
||||
*
|
||||
* @throws \WpOrg\Requests\Exception On invalid URLs (`nonhttp`)
|
||||
*/
|
||||
public function request($url, $headers = [], $data = [], $type = Requests::GET, $options = []) {
|
||||
$request = $this->merge_request(compact('url', 'headers', 'data', 'options'));
|
||||
|
||||
return Requests::request($request['url'], $request['headers'], $request['data'], $type, $request['options']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send multiple HTTP requests simultaneously
|
||||
*
|
||||
* @see \WpOrg\Requests\Requests::request_multiple()
|
||||
*
|
||||
* @param array $requests Requests data (see {@see \WpOrg\Requests\Requests::request_multiple()})
|
||||
* @param array $options Global and default options (see {@see \WpOrg\Requests\Requests::request()})
|
||||
* @return array Responses (either \WpOrg\Requests\Response or a \WpOrg\Requests\Exception object)
|
||||
*
|
||||
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $requests argument is not an array or iterable object with array access.
|
||||
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $options argument is not an array.
|
||||
*/
|
||||
public function request_multiple($requests, $options = []) {
|
||||
if (InputValidator::has_array_access($requests) === false || InputValidator::is_iterable($requests) === false) {
|
||||
throw InvalidArgument::create(1, '$requests', 'array|ArrayAccess&Traversable', gettype($requests));
|
||||
}
|
||||
|
||||
if (is_array($options) === false) {
|
||||
throw InvalidArgument::create(2, '$options', 'array', gettype($options));
|
||||
}
|
||||
|
||||
foreach ($requests as $key => $request) {
|
||||
$requests[$key] = $this->merge_request($request, false);
|
||||
}
|
||||
|
||||
$options = array_merge($this->options, $options);
|
||||
|
||||
// Disallow forcing the type, as that's a per request setting
|
||||
unset($options['type']);
|
||||
|
||||
return Requests::request_multiple($requests, $options);
|
||||
}
|
||||
|
||||
public function __wakeup() {
|
||||
throw new \LogicException( __CLASS__ . ' should never be unserialized' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge a request's data with the default data
|
||||
*
|
||||
* @param array $request Request data (same form as {@see \WpOrg\Requests\Session::request_multiple()})
|
||||
* @param boolean $merge_options Should we merge options as well?
|
||||
* @return array Request data
|
||||
*/
|
||||
protected function merge_request($request, $merge_options = true) {
|
||||
if ($this->url !== null) {
|
||||
$request['url'] = Iri::absolutize($this->url, $request['url']);
|
||||
$request['url'] = $request['url']->uri;
|
||||
}
|
||||
|
||||
if (empty($request['headers'])) {
|
||||
$request['headers'] = [];
|
||||
}
|
||||
|
||||
$request['headers'] = array_merge($this->headers, $request['headers']);
|
||||
|
||||
if (empty($request['data'])) {
|
||||
if (is_array($this->data)) {
|
||||
$request['data'] = $this->data;
|
||||
}
|
||||
} elseif (is_array($request['data']) && is_array($this->data)) {
|
||||
$request['data'] = array_merge($this->data, $request['data']);
|
||||
}
|
||||
|
||||
if ($merge_options === true) {
|
||||
$request['options'] = array_merge($this->options, $request['options']);
|
||||
|
||||
// Disallow forcing the type, as that's a per request setting
|
||||
unset($request['options']['type']);
|
||||
}
|
||||
|
||||
return $request;
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Session handler for persistent requests and default parameters
|
||||
*
|
||||
* @package Requests\SessionHandler
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests;
|
||||
|
||||
use WpOrg\Requests\Cookie\Jar;
|
||||
use WpOrg\Requests\Exception\InvalidArgument;
|
||||
use WpOrg\Requests\Iri;
|
||||
use WpOrg\Requests\Requests;
|
||||
use WpOrg\Requests\Utility\InputValidator;
|
||||
|
||||
/**
|
||||
* Session handler for persistent requests and default parameters
|
||||
*
|
||||
* Allows various options to be set as default values, and merges both the
|
||||
* options and URL properties together. A base URL can be set for all requests,
|
||||
* with all subrequests resolved from this. Base options can be set (including
|
||||
* a shared cookie jar), then overridden for individual requests.
|
||||
*
|
||||
* @package Requests\SessionHandler
|
||||
*/
|
||||
class Session {
|
||||
/**
|
||||
* Base URL for requests
|
||||
*
|
||||
* URLs will be made absolute using this as the base
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
public $url = null;
|
||||
|
||||
/**
|
||||
* Base headers for requests
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $headers = [];
|
||||
|
||||
/**
|
||||
* Base data for requests
|
||||
*
|
||||
* If both the base data and the per-request data are arrays, the data will
|
||||
* be merged before sending the request.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $data = [];
|
||||
|
||||
/**
|
||||
* Base options for requests
|
||||
*
|
||||
* The base options are merged with the per-request data for each request.
|
||||
* The only default option is a shared cookie jar between requests.
|
||||
*
|
||||
* Values here can also be set directly via properties on the Session
|
||||
* object, e.g. `$session->useragent = 'X';`
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $options = [];
|
||||
|
||||
/**
|
||||
* Create a new session
|
||||
*
|
||||
* @param string|Stringable|null $url Base URL for requests
|
||||
* @param array $headers Default headers for requests
|
||||
* @param array $data Default data for requests
|
||||
* @param array $options Default options for requests
|
||||
*
|
||||
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $url argument is not a string, Stringable or null.
|
||||
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $headers argument is not an array.
|
||||
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $data argument is not an array.
|
||||
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $options argument is not an array.
|
||||
*/
|
||||
public function __construct($url = null, $headers = [], $data = [], $options = []) {
|
||||
if ($url !== null && InputValidator::is_string_or_stringable($url) === false) {
|
||||
throw InvalidArgument::create(1, '$url', 'string|Stringable|null', gettype($url));
|
||||
}
|
||||
|
||||
if (is_array($headers) === false) {
|
||||
throw InvalidArgument::create(2, '$headers', 'array', gettype($headers));
|
||||
}
|
||||
|
||||
if (is_array($data) === false) {
|
||||
throw InvalidArgument::create(3, '$data', 'array', gettype($data));
|
||||
}
|
||||
|
||||
if (is_array($options) === false) {
|
||||
throw InvalidArgument::create(4, '$options', 'array', gettype($options));
|
||||
}
|
||||
|
||||
$this->url = $url;
|
||||
$this->headers = $headers;
|
||||
$this->data = $data;
|
||||
$this->options = $options;
|
||||
|
||||
if (empty($this->options['cookies'])) {
|
||||
$this->options['cookies'] = new Jar();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a property's value
|
||||
*
|
||||
* @param string $name Property name.
|
||||
* @return mixed|null Property value, null if none found
|
||||
*/
|
||||
public function __get($name) {
|
||||
if (isset($this->options[$name])) {
|
||||
return $this->options[$name];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a property's value
|
||||
*
|
||||
* @param string $name Property name.
|
||||
* @param mixed $value Property value
|
||||
*/
|
||||
public function __set($name, $value) {
|
||||
$this->options[$name] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a property's value
|
||||
*
|
||||
* @param string $name Property name.
|
||||
*/
|
||||
public function __isset($name) {
|
||||
return isset($this->options[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a property's value
|
||||
*
|
||||
* @param string $name Property name.
|
||||
*/
|
||||
public function __unset($name) {
|
||||
unset($this->options[$name]);
|
||||
}
|
||||
|
||||
/**#@+
|
||||
* @see \WpOrg\Requests\Session::request()
|
||||
* @param string $url
|
||||
* @param array $headers
|
||||
* @param array $options
|
||||
* @return \WpOrg\Requests\Response
|
||||
*/
|
||||
/**
|
||||
* Send a GET request
|
||||
*/
|
||||
public function get($url, $headers = [], $options = []) {
|
||||
return $this->request($url, $headers, null, Requests::GET, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a HEAD request
|
||||
*/
|
||||
public function head($url, $headers = [], $options = []) {
|
||||
return $this->request($url, $headers, null, Requests::HEAD, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a DELETE request
|
||||
*/
|
||||
public function delete($url, $headers = [], $options = []) {
|
||||
return $this->request($url, $headers, null, Requests::DELETE, $options);
|
||||
}
|
||||
/**#@-*/
|
||||
|
||||
/**#@+
|
||||
* @see \WpOrg\Requests\Session::request()
|
||||
* @param string $url
|
||||
* @param array $headers
|
||||
* @param array $data
|
||||
* @param array $options
|
||||
* @return \WpOrg\Requests\Response
|
||||
*/
|
||||
/**
|
||||
* Send a POST request
|
||||
*/
|
||||
public function post($url, $headers = [], $data = [], $options = []) {
|
||||
return $this->request($url, $headers, $data, Requests::POST, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a PUT request
|
||||
*/
|
||||
public function put($url, $headers = [], $data = [], $options = []) {
|
||||
return $this->request($url, $headers, $data, Requests::PUT, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a PATCH request
|
||||
*
|
||||
* Note: Unlike {@see \WpOrg\Requests\Session::post()} and {@see \WpOrg\Requests\Session::put()},
|
||||
* `$headers` is required, as the specification recommends that should send an ETag
|
||||
*
|
||||
* @link https://tools.ietf.org/html/rfc5789
|
||||
*/
|
||||
public function patch($url, $headers, $data = [], $options = []) {
|
||||
return $this->request($url, $headers, $data, Requests::PATCH, $options);
|
||||
}
|
||||
/**#@-*/
|
||||
|
||||
/**
|
||||
* Main interface for HTTP requests
|
||||
*
|
||||
* This method initiates a request and sends it via a transport before
|
||||
* parsing.
|
||||
*
|
||||
* @see \WpOrg\Requests\Requests::request()
|
||||
*
|
||||
* @param string $url URL to request
|
||||
* @param array $headers Extra headers to send with the request
|
||||
* @param array|null $data Data to send either as a query string for GET/HEAD requests, or in the body for POST requests
|
||||
* @param string $type HTTP request type (use \WpOrg\Requests\Requests constants)
|
||||
* @param array $options Options for the request (see {@see \WpOrg\Requests\Requests::request()})
|
||||
* @return \WpOrg\Requests\Response
|
||||
*
|
||||
* @throws \WpOrg\Requests\Exception On invalid URLs (`nonhttp`)
|
||||
*/
|
||||
public function request($url, $headers = [], $data = [], $type = Requests::GET, $options = []) {
|
||||
$request = $this->merge_request(compact('url', 'headers', 'data', 'options'));
|
||||
|
||||
return Requests::request($request['url'], $request['headers'], $request['data'], $type, $request['options']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send multiple HTTP requests simultaneously
|
||||
*
|
||||
* @see \WpOrg\Requests\Requests::request_multiple()
|
||||
*
|
||||
* @param array $requests Requests data (see {@see \WpOrg\Requests\Requests::request_multiple()})
|
||||
* @param array $options Global and default options (see {@see \WpOrg\Requests\Requests::request()})
|
||||
* @return array Responses (either \WpOrg\Requests\Response or a \WpOrg\Requests\Exception object)
|
||||
*
|
||||
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $requests argument is not an array or iterable object with array access.
|
||||
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $options argument is not an array.
|
||||
*/
|
||||
public function request_multiple($requests, $options = []) {
|
||||
if (InputValidator::has_array_access($requests) === false || InputValidator::is_iterable($requests) === false) {
|
||||
throw InvalidArgument::create(1, '$requests', 'array|ArrayAccess&Traversable', gettype($requests));
|
||||
}
|
||||
|
||||
if (is_array($options) === false) {
|
||||
throw InvalidArgument::create(2, '$options', 'array', gettype($options));
|
||||
}
|
||||
|
||||
foreach ($requests as $key => $request) {
|
||||
$requests[$key] = $this->merge_request($request, false);
|
||||
}
|
||||
|
||||
$options = array_merge($this->options, $options);
|
||||
|
||||
// Disallow forcing the type, as that's a per request setting
|
||||
unset($options['type']);
|
||||
|
||||
return Requests::request_multiple($requests, $options);
|
||||
}
|
||||
|
||||
public function __wakeup() {
|
||||
throw new \LogicException( __CLASS__ . ' should never be unserialized' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge a request's data with the default data
|
||||
*
|
||||
* @param array $request Request data (same form as {@see \WpOrg\Requests\Session::request_multiple()})
|
||||
* @param boolean $merge_options Should we merge options as well?
|
||||
* @return array Request data
|
||||
*/
|
||||
protected function merge_request($request, $merge_options = true) {
|
||||
if ($this->url !== null) {
|
||||
$request['url'] = Iri::absolutize($this->url, $request['url']);
|
||||
$request['url'] = $request['url']->uri;
|
||||
}
|
||||
|
||||
if (empty($request['headers'])) {
|
||||
$request['headers'] = [];
|
||||
}
|
||||
|
||||
$request['headers'] = array_merge($this->headers, $request['headers']);
|
||||
|
||||
if (empty($request['data'])) {
|
||||
if (is_array($this->data)) {
|
||||
$request['data'] = $this->data;
|
||||
}
|
||||
} elseif (is_array($request['data']) && is_array($this->data)) {
|
||||
$request['data'] = array_merge($this->data, $request['data']);
|
||||
}
|
||||
|
||||
if ($merge_options === true) {
|
||||
$request['options'] = array_merge($this->options, $request['options']);
|
||||
|
||||
// Disallow forcing the type, as that's a per request setting
|
||||
unset($request['options']['type']);
|
||||
}
|
||||
|
||||
return $request;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,182 +1,182 @@
|
||||
<?php
|
||||
/**
|
||||
* SSL utilities for Requests
|
||||
*
|
||||
* @package Requests\Utilities
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests;
|
||||
|
||||
use WpOrg\Requests\Exception\InvalidArgument;
|
||||
use WpOrg\Requests\Utility\InputValidator;
|
||||
|
||||
/**
|
||||
* SSL utilities for Requests
|
||||
*
|
||||
* Collection of utilities for working with and verifying SSL certificates.
|
||||
*
|
||||
* @package Requests\Utilities
|
||||
*/
|
||||
final class Ssl {
|
||||
/**
|
||||
* Verify the certificate against common name and subject alternative names
|
||||
*
|
||||
* Unfortunately, PHP doesn't check the certificate against the alternative
|
||||
* names, leading things like 'https://www.github.com/' to be invalid.
|
||||
*
|
||||
* @link https://tools.ietf.org/html/rfc2818#section-3.1 RFC2818, Section 3.1
|
||||
*
|
||||
* @param string|Stringable $host Host name to verify against
|
||||
* @param array $cert Certificate data from openssl_x509_parse()
|
||||
* @return bool
|
||||
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $host argument is not a string or a stringable object.
|
||||
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $cert argument is not an array or array accessible.
|
||||
*/
|
||||
public static function verify_certificate($host, $cert) {
|
||||
if (InputValidator::is_string_or_stringable($host) === false) {
|
||||
throw InvalidArgument::create(1, '$host', 'string|Stringable', gettype($host));
|
||||
}
|
||||
|
||||
if (InputValidator::has_array_access($cert) === false) {
|
||||
throw InvalidArgument::create(2, '$cert', 'array|ArrayAccess', gettype($cert));
|
||||
}
|
||||
|
||||
$has_dns_alt = false;
|
||||
|
||||
// Check the subjectAltName
|
||||
if (!empty($cert['extensions']['subjectAltName'])) {
|
||||
$altnames = explode(',', $cert['extensions']['subjectAltName']);
|
||||
foreach ($altnames as $altname) {
|
||||
$altname = trim($altname);
|
||||
if (strpos($altname, 'DNS:') !== 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$has_dns_alt = true;
|
||||
|
||||
// Strip the 'DNS:' prefix and trim whitespace
|
||||
$altname = trim(substr($altname, 4));
|
||||
|
||||
// Check for a match
|
||||
if (self::match_domain($host, $altname) === true) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($has_dns_alt === true) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Fall back to checking the common name if we didn't get any dNSName
|
||||
// alt names, as per RFC2818
|
||||
if (!empty($cert['subject']['CN'])) {
|
||||
// Check for a match
|
||||
return (self::match_domain($host, $cert['subject']['CN']) === true);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that a reference name is valid
|
||||
*
|
||||
* Verifies a dNSName for HTTPS usage, (almost) as per Firefox's rules:
|
||||
* - Wildcards can only occur in a name with more than 3 components
|
||||
* - Wildcards can only occur as the last character in the first
|
||||
* component
|
||||
* - Wildcards may be preceded by additional characters
|
||||
*
|
||||
* We modify these rules to be a bit stricter and only allow the wildcard
|
||||
* character to be the full first component; that is, with the exclusion of
|
||||
* the third rule.
|
||||
*
|
||||
* @param string|Stringable $reference Reference dNSName
|
||||
* @return boolean Is the name valid?
|
||||
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed argument is not a string or a stringable object.
|
||||
*/
|
||||
public static function verify_reference_name($reference) {
|
||||
if (InputValidator::is_string_or_stringable($reference) === false) {
|
||||
throw InvalidArgument::create(1, '$reference', 'string|Stringable', gettype($reference));
|
||||
}
|
||||
|
||||
if ($reference === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (preg_match('`\s`', $reference) > 0) {
|
||||
// Whitespace detected. This can never be a dNSName.
|
||||
return false;
|
||||
}
|
||||
|
||||
$parts = explode('.', $reference);
|
||||
if ($parts !== array_filter($parts)) {
|
||||
// DNSName cannot contain two dots next to each other.
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check the first part of the name
|
||||
$first = array_shift($parts);
|
||||
|
||||
if (strpos($first, '*') !== false) {
|
||||
// Check that the wildcard is the full part
|
||||
if ($first !== '*') {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check that we have at least 3 components (including first)
|
||||
if (count($parts) < 2) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Check the remaining parts
|
||||
foreach ($parts as $part) {
|
||||
if (strpos($part, '*') !== false) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Nothing found, verified!
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Match a hostname against a dNSName reference
|
||||
*
|
||||
* @param string|Stringable $host Requested host
|
||||
* @param string|Stringable $reference dNSName to match against
|
||||
* @return boolean Does the domain match?
|
||||
* @throws \WpOrg\Requests\Exception\InvalidArgument When either of the passed arguments is not a string or a stringable object.
|
||||
*/
|
||||
public static function match_domain($host, $reference) {
|
||||
if (InputValidator::is_string_or_stringable($host) === false) {
|
||||
throw InvalidArgument::create(1, '$host', 'string|Stringable', gettype($host));
|
||||
}
|
||||
|
||||
// Check if the reference is blocklisted first
|
||||
if (self::verify_reference_name($reference) !== true) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check for a direct match
|
||||
if ((string) $host === (string) $reference) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Calculate the valid wildcard match if the host is not an IP address
|
||||
// Also validates that the host has 3 parts or more, as per Firefox's ruleset,
|
||||
// as a wildcard reference is only allowed with 3 parts or more, so the
|
||||
// comparison will never match if host doesn't contain 3 parts or more as well.
|
||||
if (ip2long($host) === false) {
|
||||
$parts = explode('.', $host);
|
||||
$parts[0] = '*';
|
||||
$wildcard = implode('.', $parts);
|
||||
if ($wildcard === (string) $reference) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* SSL utilities for Requests
|
||||
*
|
||||
* @package Requests\Utilities
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests;
|
||||
|
||||
use WpOrg\Requests\Exception\InvalidArgument;
|
||||
use WpOrg\Requests\Utility\InputValidator;
|
||||
|
||||
/**
|
||||
* SSL utilities for Requests
|
||||
*
|
||||
* Collection of utilities for working with and verifying SSL certificates.
|
||||
*
|
||||
* @package Requests\Utilities
|
||||
*/
|
||||
final class Ssl {
|
||||
/**
|
||||
* Verify the certificate against common name and subject alternative names
|
||||
*
|
||||
* Unfortunately, PHP doesn't check the certificate against the alternative
|
||||
* names, leading things like 'https://www.github.com/' to be invalid.
|
||||
*
|
||||
* @link https://tools.ietf.org/html/rfc2818#section-3.1 RFC2818, Section 3.1
|
||||
*
|
||||
* @param string|Stringable $host Host name to verify against
|
||||
* @param array $cert Certificate data from openssl_x509_parse()
|
||||
* @return bool
|
||||
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $host argument is not a string or a stringable object.
|
||||
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $cert argument is not an array or array accessible.
|
||||
*/
|
||||
public static function verify_certificate($host, $cert) {
|
||||
if (InputValidator::is_string_or_stringable($host) === false) {
|
||||
throw InvalidArgument::create(1, '$host', 'string|Stringable', gettype($host));
|
||||
}
|
||||
|
||||
if (InputValidator::has_array_access($cert) === false) {
|
||||
throw InvalidArgument::create(2, '$cert', 'array|ArrayAccess', gettype($cert));
|
||||
}
|
||||
|
||||
$has_dns_alt = false;
|
||||
|
||||
// Check the subjectAltName
|
||||
if (!empty($cert['extensions']['subjectAltName'])) {
|
||||
$altnames = explode(',', $cert['extensions']['subjectAltName']);
|
||||
foreach ($altnames as $altname) {
|
||||
$altname = trim($altname);
|
||||
if (strpos($altname, 'DNS:') !== 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$has_dns_alt = true;
|
||||
|
||||
// Strip the 'DNS:' prefix and trim whitespace
|
||||
$altname = trim(substr($altname, 4));
|
||||
|
||||
// Check for a match
|
||||
if (self::match_domain($host, $altname) === true) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($has_dns_alt === true) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Fall back to checking the common name if we didn't get any dNSName
|
||||
// alt names, as per RFC2818
|
||||
if (!empty($cert['subject']['CN'])) {
|
||||
// Check for a match
|
||||
return (self::match_domain($host, $cert['subject']['CN']) === true);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that a reference name is valid
|
||||
*
|
||||
* Verifies a dNSName for HTTPS usage, (almost) as per Firefox's rules:
|
||||
* - Wildcards can only occur in a name with more than 3 components
|
||||
* - Wildcards can only occur as the last character in the first
|
||||
* component
|
||||
* - Wildcards may be preceded by additional characters
|
||||
*
|
||||
* We modify these rules to be a bit stricter and only allow the wildcard
|
||||
* character to be the full first component; that is, with the exclusion of
|
||||
* the third rule.
|
||||
*
|
||||
* @param string|Stringable $reference Reference dNSName
|
||||
* @return boolean Is the name valid?
|
||||
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed argument is not a string or a stringable object.
|
||||
*/
|
||||
public static function verify_reference_name($reference) {
|
||||
if (InputValidator::is_string_or_stringable($reference) === false) {
|
||||
throw InvalidArgument::create(1, '$reference', 'string|Stringable', gettype($reference));
|
||||
}
|
||||
|
||||
if ($reference === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (preg_match('`\s`', $reference) > 0) {
|
||||
// Whitespace detected. This can never be a dNSName.
|
||||
return false;
|
||||
}
|
||||
|
||||
$parts = explode('.', $reference);
|
||||
if ($parts !== array_filter($parts)) {
|
||||
// DNSName cannot contain two dots next to each other.
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check the first part of the name
|
||||
$first = array_shift($parts);
|
||||
|
||||
if (strpos($first, '*') !== false) {
|
||||
// Check that the wildcard is the full part
|
||||
if ($first !== '*') {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check that we have at least 3 components (including first)
|
||||
if (count($parts) < 2) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Check the remaining parts
|
||||
foreach ($parts as $part) {
|
||||
if (strpos($part, '*') !== false) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Nothing found, verified!
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Match a hostname against a dNSName reference
|
||||
*
|
||||
* @param string|Stringable $host Requested host
|
||||
* @param string|Stringable $reference dNSName to match against
|
||||
* @return boolean Does the domain match?
|
||||
* @throws \WpOrg\Requests\Exception\InvalidArgument When either of the passed arguments is not a string or a stringable object.
|
||||
*/
|
||||
public static function match_domain($host, $reference) {
|
||||
if (InputValidator::is_string_or_stringable($host) === false) {
|
||||
throw InvalidArgument::create(1, '$host', 'string|Stringable', gettype($host));
|
||||
}
|
||||
|
||||
// Check if the reference is blocklisted first
|
||||
if (self::verify_reference_name($reference) !== true) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check for a direct match
|
||||
if ((string) $host === (string) $reference) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Calculate the valid wildcard match if the host is not an IP address
|
||||
// Also validates that the host has 3 parts or more, as per Firefox's ruleset,
|
||||
// as a wildcard reference is only allowed with 3 parts or more, so the
|
||||
// comparison will never match if host doesn't contain 3 parts or more as well.
|
||||
if (ip2long($host) === false) {
|
||||
$parts = explode('.', $host);
|
||||
$parts[0] = '*';
|
||||
$wildcard = implode('.', $parts);
|
||||
if ($wildcard === (string) $reference) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,45 +1,45 @@
|
||||
<?php
|
||||
/**
|
||||
* Base HTTP transport
|
||||
*
|
||||
* @package Requests\Transport
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests;
|
||||
|
||||
/**
|
||||
* Base HTTP transport
|
||||
*
|
||||
* @package Requests\Transport
|
||||
*/
|
||||
interface Transport {
|
||||
/**
|
||||
* Perform a request
|
||||
*
|
||||
* @param string $url URL to request
|
||||
* @param array $headers Associative array of request headers
|
||||
* @param string|array $data Data to send either as the POST body, or as parameters in the URL for a GET/HEAD
|
||||
* @param array $options Request options, see {@see \WpOrg\Requests\Requests::response()} for documentation
|
||||
* @return string Raw HTTP result
|
||||
*/
|
||||
public function request($url, $headers = [], $data = [], $options = []);
|
||||
|
||||
/**
|
||||
* Send multiple requests simultaneously
|
||||
*
|
||||
* @param array $requests Request data (array of 'url', 'headers', 'data', 'options') as per {@see \WpOrg\Requests\Transport::request()}
|
||||
* @param array $options Global options, see {@see \WpOrg\Requests\Requests::response()} for documentation
|
||||
* @return array Array of \WpOrg\Requests\Response objects (may contain \WpOrg\Requests\Exception or string responses as well)
|
||||
*/
|
||||
public function request_multiple($requests, $options);
|
||||
|
||||
/**
|
||||
* Self-test whether the transport can be used.
|
||||
*
|
||||
* The available capabilities to test for can be found in {@see \WpOrg\Requests\Capability}.
|
||||
*
|
||||
* @param array<string, bool> $capabilities Optional. Associative array of capabilities to test against, i.e. `['<capability>' => true]`.
|
||||
* @return bool Whether the transport can be used.
|
||||
*/
|
||||
public static function test($capabilities = []);
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Base HTTP transport
|
||||
*
|
||||
* @package Requests\Transport
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests;
|
||||
|
||||
/**
|
||||
* Base HTTP transport
|
||||
*
|
||||
* @package Requests\Transport
|
||||
*/
|
||||
interface Transport {
|
||||
/**
|
||||
* Perform a request
|
||||
*
|
||||
* @param string $url URL to request
|
||||
* @param array $headers Associative array of request headers
|
||||
* @param string|array $data Data to send either as the POST body, or as parameters in the URL for a GET/HEAD
|
||||
* @param array $options Request options, see {@see \WpOrg\Requests\Requests::response()} for documentation
|
||||
* @return string Raw HTTP result
|
||||
*/
|
||||
public function request($url, $headers = [], $data = [], $options = []);
|
||||
|
||||
/**
|
||||
* Send multiple requests simultaneously
|
||||
*
|
||||
* @param array $requests Request data (array of 'url', 'headers', 'data', 'options') as per {@see \WpOrg\Requests\Transport::request()}
|
||||
* @param array $options Global options, see {@see \WpOrg\Requests\Requests::response()} for documentation
|
||||
* @return array Array of \WpOrg\Requests\Response objects (may contain \WpOrg\Requests\Exception or string responses as well)
|
||||
*/
|
||||
public function request_multiple($requests, $options);
|
||||
|
||||
/**
|
||||
* Self-test whether the transport can be used.
|
||||
*
|
||||
* The available capabilities to test for can be found in {@see \WpOrg\Requests\Capability}.
|
||||
*
|
||||
* @param array<string, bool> $capabilities Optional. Associative array of capabilities to test against, i.e. `['<capability>' => true]`.
|
||||
* @return bool Whether the transport can be used.
|
||||
*/
|
||||
public static function test($capabilities = []);
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,127 +1,127 @@
|
||||
<?php
|
||||
/**
|
||||
* Case-insensitive dictionary, suitable for HTTP headers
|
||||
*
|
||||
* @package Requests\Utilities
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Utility;
|
||||
|
||||
use ArrayAccess;
|
||||
use ArrayIterator;
|
||||
use IteratorAggregate;
|
||||
use ReturnTypeWillChange;
|
||||
use WpOrg\Requests\Exception;
|
||||
|
||||
/**
|
||||
* Case-insensitive dictionary, suitable for HTTP headers
|
||||
*
|
||||
* @package Requests\Utilities
|
||||
*/
|
||||
class CaseInsensitiveDictionary implements ArrayAccess, IteratorAggregate {
|
||||
/**
|
||||
* Actual item data
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $data = [];
|
||||
|
||||
/**
|
||||
* Creates a case insensitive dictionary.
|
||||
*
|
||||
* @param array $data Dictionary/map to convert to case-insensitive
|
||||
*/
|
||||
public function __construct(array $data = []) {
|
||||
foreach ($data as $offset => $value) {
|
||||
$this->offsetSet($offset, $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given item exists
|
||||
*
|
||||
* @param string $offset Item key
|
||||
* @return boolean Does the item exist?
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function offsetExists($offset) {
|
||||
if (is_string($offset)) {
|
||||
$offset = strtolower($offset);
|
||||
}
|
||||
|
||||
return isset($this->data[$offset]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value for the item
|
||||
*
|
||||
* @param string $offset Item key
|
||||
* @return string|null Item value (null if the item key doesn't exist)
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function offsetGet($offset) {
|
||||
if (is_string($offset)) {
|
||||
$offset = strtolower($offset);
|
||||
}
|
||||
|
||||
if (!isset($this->data[$offset])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->data[$offset];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the given item
|
||||
*
|
||||
* @param string $offset Item name
|
||||
* @param string $value Item value
|
||||
*
|
||||
* @throws \WpOrg\Requests\Exception On attempting to use dictionary as list (`invalidset`)
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function offsetSet($offset, $value) {
|
||||
if ($offset === null) {
|
||||
throw new Exception('Object is a dictionary, not a list', 'invalidset');
|
||||
}
|
||||
|
||||
if (is_string($offset)) {
|
||||
$offset = strtolower($offset);
|
||||
}
|
||||
|
||||
$this->data[$offset] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unset the given header
|
||||
*
|
||||
* @param string $offset The key for the item to unset.
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function offsetUnset($offset) {
|
||||
if (is_string($offset)) {
|
||||
$offset = strtolower($offset);
|
||||
}
|
||||
|
||||
unset($this->data[$offset]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an iterator for the data
|
||||
*
|
||||
* @return \ArrayIterator
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function getIterator() {
|
||||
return new ArrayIterator($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the headers as an array
|
||||
*
|
||||
* @return array Header data
|
||||
*/
|
||||
public function getAll() {
|
||||
return $this->data;
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Case-insensitive dictionary, suitable for HTTP headers
|
||||
*
|
||||
* @package Requests\Utilities
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Utility;
|
||||
|
||||
use ArrayAccess;
|
||||
use ArrayIterator;
|
||||
use IteratorAggregate;
|
||||
use ReturnTypeWillChange;
|
||||
use WpOrg\Requests\Exception;
|
||||
|
||||
/**
|
||||
* Case-insensitive dictionary, suitable for HTTP headers
|
||||
*
|
||||
* @package Requests\Utilities
|
||||
*/
|
||||
class CaseInsensitiveDictionary implements ArrayAccess, IteratorAggregate {
|
||||
/**
|
||||
* Actual item data
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $data = [];
|
||||
|
||||
/**
|
||||
* Creates a case insensitive dictionary.
|
||||
*
|
||||
* @param array $data Dictionary/map to convert to case-insensitive
|
||||
*/
|
||||
public function __construct(array $data = []) {
|
||||
foreach ($data as $offset => $value) {
|
||||
$this->offsetSet($offset, $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given item exists
|
||||
*
|
||||
* @param string $offset Item key
|
||||
* @return boolean Does the item exist?
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function offsetExists($offset) {
|
||||
if (is_string($offset)) {
|
||||
$offset = strtolower($offset);
|
||||
}
|
||||
|
||||
return isset($this->data[$offset]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value for the item
|
||||
*
|
||||
* @param string $offset Item key
|
||||
* @return string|null Item value (null if the item key doesn't exist)
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function offsetGet($offset) {
|
||||
if (is_string($offset)) {
|
||||
$offset = strtolower($offset);
|
||||
}
|
||||
|
||||
if (!isset($this->data[$offset])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->data[$offset];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the given item
|
||||
*
|
||||
* @param string $offset Item name
|
||||
* @param string $value Item value
|
||||
*
|
||||
* @throws \WpOrg\Requests\Exception On attempting to use dictionary as list (`invalidset`)
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function offsetSet($offset, $value) {
|
||||
if ($offset === null) {
|
||||
throw new Exception('Object is a dictionary, not a list', 'invalidset');
|
||||
}
|
||||
|
||||
if (is_string($offset)) {
|
||||
$offset = strtolower($offset);
|
||||
}
|
||||
|
||||
$this->data[$offset] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unset the given header
|
||||
*
|
||||
* @param string $offset The key for the item to unset.
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function offsetUnset($offset) {
|
||||
if (is_string($offset)) {
|
||||
$offset = strtolower($offset);
|
||||
}
|
||||
|
||||
unset($this->data[$offset]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an iterator for the data
|
||||
*
|
||||
* @return \ArrayIterator
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function getIterator() {
|
||||
return new ArrayIterator($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the headers as an array
|
||||
*
|
||||
* @return array Header data
|
||||
*/
|
||||
public function getAll() {
|
||||
return $this->data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,97 +1,97 @@
|
||||
<?php
|
||||
/**
|
||||
* Iterator for arrays requiring filtered values
|
||||
*
|
||||
* @package Requests\Utilities
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Utility;
|
||||
|
||||
use ArrayIterator;
|
||||
use ReturnTypeWillChange;
|
||||
use WpOrg\Requests\Exception\InvalidArgument;
|
||||
use WpOrg\Requests\Utility\InputValidator;
|
||||
|
||||
/**
|
||||
* Iterator for arrays requiring filtered values
|
||||
*
|
||||
* @package Requests\Utilities
|
||||
*/
|
||||
final class FilteredIterator extends ArrayIterator {
|
||||
/**
|
||||
* Callback to run as a filter
|
||||
*
|
||||
* @var callable
|
||||
*/
|
||||
private $callback;
|
||||
|
||||
/**
|
||||
* Create a new iterator
|
||||
*
|
||||
* @param array $data The array or object to be iterated on.
|
||||
* @param callable $callback Callback to be called on each value
|
||||
*
|
||||
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $data argument is not iterable.
|
||||
*/
|
||||
public function __construct($data, $callback) {
|
||||
if (InputValidator::is_iterable($data) === false) {
|
||||
throw InvalidArgument::create(1, '$data', 'iterable', gettype($data));
|
||||
}
|
||||
|
||||
parent::__construct($data);
|
||||
|
||||
if (is_callable($callback)) {
|
||||
$this->callback = $callback;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevent unserialization of the object for security reasons.
|
||||
*
|
||||
* @phpcs:disable PHPCompatibility.FunctionNameRestrictions.NewMagicMethods.__unserializeFound
|
||||
*
|
||||
* @param array $data Restored array of data originally serialized.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function __unserialize($data) {}
|
||||
// phpcs:enable
|
||||
|
||||
/**
|
||||
* Perform reinitialization tasks.
|
||||
*
|
||||
* Prevents a callback from being injected during unserialization of an object.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __wakeup() {
|
||||
unset($this->callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current item's value after filtering
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function current() {
|
||||
$value = parent::current();
|
||||
|
||||
if (is_callable($this->callback)) {
|
||||
$value = call_user_func($this->callback, $value);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevent creating a PHP value from a stored representation of the object for security reasons.
|
||||
*
|
||||
* @param string $data The serialized string.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function unserialize($data) {}
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Iterator for arrays requiring filtered values
|
||||
*
|
||||
* @package Requests\Utilities
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Utility;
|
||||
|
||||
use ArrayIterator;
|
||||
use ReturnTypeWillChange;
|
||||
use WpOrg\Requests\Exception\InvalidArgument;
|
||||
use WpOrg\Requests\Utility\InputValidator;
|
||||
|
||||
/**
|
||||
* Iterator for arrays requiring filtered values
|
||||
*
|
||||
* @package Requests\Utilities
|
||||
*/
|
||||
final class FilteredIterator extends ArrayIterator {
|
||||
/**
|
||||
* Callback to run as a filter
|
||||
*
|
||||
* @var callable
|
||||
*/
|
||||
private $callback;
|
||||
|
||||
/**
|
||||
* Create a new iterator
|
||||
*
|
||||
* @param array $data The array or object to be iterated on.
|
||||
* @param callable $callback Callback to be called on each value
|
||||
*
|
||||
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $data argument is not iterable.
|
||||
*/
|
||||
public function __construct($data, $callback) {
|
||||
if (InputValidator::is_iterable($data) === false) {
|
||||
throw InvalidArgument::create(1, '$data', 'iterable', gettype($data));
|
||||
}
|
||||
|
||||
parent::__construct($data);
|
||||
|
||||
if (is_callable($callback)) {
|
||||
$this->callback = $callback;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevent unserialization of the object for security reasons.
|
||||
*
|
||||
* @phpcs:disable PHPCompatibility.FunctionNameRestrictions.NewMagicMethods.__unserializeFound
|
||||
*
|
||||
* @param array $data Restored array of data originally serialized.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function __unserialize($data) {}
|
||||
// phpcs:enable
|
||||
|
||||
/**
|
||||
* Perform reinitialization tasks.
|
||||
*
|
||||
* Prevents a callback from being injected during unserialization of an object.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __wakeup() {
|
||||
unset($this->callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current item's value after filtering
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function current() {
|
||||
$value = parent::current();
|
||||
|
||||
if (is_callable($this->callback)) {
|
||||
$value = call_user_func($this->callback, $value);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevent creating a PHP value from a stored representation of the object for security reasons.
|
||||
*
|
||||
* @param string $data The serialized string.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function unserialize($data) {}
|
||||
}
|
||||
|
||||
@@ -1,109 +1,109 @@
|
||||
<?php
|
||||
/**
|
||||
* Input validation utilities.
|
||||
*
|
||||
* @package Requests\Utilities
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Utility;
|
||||
|
||||
use ArrayAccess;
|
||||
use CurlHandle;
|
||||
use Traversable;
|
||||
|
||||
/**
|
||||
* Input validation utilities.
|
||||
*
|
||||
* @package Requests\Utilities
|
||||
*/
|
||||
final class InputValidator {
|
||||
|
||||
/**
|
||||
* Verify that a received input parameter is of type string or is "stringable".
|
||||
*
|
||||
* @param mixed $input Input parameter to verify.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_string_or_stringable($input) {
|
||||
return is_string($input) || self::is_stringable_object($input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify whether a received input parameter is usable as an integer array key.
|
||||
*
|
||||
* @param mixed $input Input parameter to verify.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_numeric_array_key($input) {
|
||||
if (is_int($input)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!is_string($input)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (bool) preg_match('`^-?[0-9]+$`', $input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify whether a received input parameter is "stringable".
|
||||
*
|
||||
* @param mixed $input Input parameter to verify.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_stringable_object($input) {
|
||||
return is_object($input) && method_exists($input, '__toString');
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify whether a received input parameter is _accessible as if it were an array_.
|
||||
*
|
||||
* @param mixed $input Input parameter to verify.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function has_array_access($input) {
|
||||
return is_array($input) || $input instanceof ArrayAccess;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify whether a received input parameter is "iterable".
|
||||
*
|
||||
* @internal The PHP native `is_iterable()` function was only introduced in PHP 7.1
|
||||
* and this library still supports PHP 5.6.
|
||||
*
|
||||
* @param mixed $input Input parameter to verify.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_iterable($input) {
|
||||
return is_array($input) || $input instanceof Traversable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify whether a received input parameter is a Curl handle.
|
||||
*
|
||||
* The PHP Curl extension worked with resources prior to PHP 8.0 and with
|
||||
* an instance of the `CurlHandle` class since PHP 8.0.
|
||||
* {@link https://www.php.net/manual/en/migration80.incompatible.php#migration80.incompatible.resource2object}
|
||||
*
|
||||
* @param mixed $input Input parameter to verify.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_curl_handle($input) {
|
||||
if (is_resource($input)) {
|
||||
return get_resource_type($input) === 'curl';
|
||||
}
|
||||
|
||||
if (is_object($input)) {
|
||||
return $input instanceof CurlHandle;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* Input validation utilities.
|
||||
*
|
||||
* @package Requests\Utilities
|
||||
*/
|
||||
|
||||
namespace WpOrg\Requests\Utility;
|
||||
|
||||
use ArrayAccess;
|
||||
use CurlHandle;
|
||||
use Traversable;
|
||||
|
||||
/**
|
||||
* Input validation utilities.
|
||||
*
|
||||
* @package Requests\Utilities
|
||||
*/
|
||||
final class InputValidator {
|
||||
|
||||
/**
|
||||
* Verify that a received input parameter is of type string or is "stringable".
|
||||
*
|
||||
* @param mixed $input Input parameter to verify.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_string_or_stringable($input) {
|
||||
return is_string($input) || self::is_stringable_object($input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify whether a received input parameter is usable as an integer array key.
|
||||
*
|
||||
* @param mixed $input Input parameter to verify.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_numeric_array_key($input) {
|
||||
if (is_int($input)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!is_string($input)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (bool) preg_match('`^-?[0-9]+$`', $input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify whether a received input parameter is "stringable".
|
||||
*
|
||||
* @param mixed $input Input parameter to verify.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_stringable_object($input) {
|
||||
return is_object($input) && method_exists($input, '__toString');
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify whether a received input parameter is _accessible as if it were an array_.
|
||||
*
|
||||
* @param mixed $input Input parameter to verify.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function has_array_access($input) {
|
||||
return is_array($input) || $input instanceof ArrayAccess;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify whether a received input parameter is "iterable".
|
||||
*
|
||||
* @internal The PHP native `is_iterable()` function was only introduced in PHP 7.1
|
||||
* and this library still supports PHP 5.6.
|
||||
*
|
||||
* @param mixed $input Input parameter to verify.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_iterable($input) {
|
||||
return is_array($input) || $input instanceof Traversable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify whether a received input parameter is a Curl handle.
|
||||
*
|
||||
* The PHP Curl extension worked with resources prior to PHP 8.0 and with
|
||||
* an instance of the `CurlHandle` class since PHP 8.0.
|
||||
* {@link https://www.php.net/manual/en/migration80.incompatible.php#migration80.incompatible.resource2object}
|
||||
*
|
||||
* @param mixed $input Input parameter to verify.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_curl_handle($input) {
|
||||
if (is_resource($input)) {
|
||||
return get_resource_type($input) === 'curl';
|
||||
}
|
||||
|
||||
if (is_object($input)) {
|
||||
return $input instanceof CurlHandle;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,149 +1,149 @@
|
||||
<?php
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2016, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the SimplePie Team nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
|
||||
* AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @package SimplePie
|
||||
* @copyright 2004-2016 Ryan Parman, Sam Sneddon, Ryan McCue
|
||||
* @author Ryan Parman
|
||||
* @author Sam Sneddon
|
||||
* @author Ryan McCue
|
||||
* @link http://simplepie.org/ SimplePie
|
||||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Manages all author-related data
|
||||
*
|
||||
* Used by {@see SimplePie_Item::get_author()} and {@see SimplePie::get_authors()}
|
||||
*
|
||||
* This class can be overloaded with {@see SimplePie::set_author_class()}
|
||||
*
|
||||
* @package SimplePie
|
||||
* @subpackage API
|
||||
*/
|
||||
class SimplePie_Author
|
||||
{
|
||||
/**
|
||||
* Author's name
|
||||
*
|
||||
* @var string
|
||||
* @see get_name()
|
||||
*/
|
||||
var $name;
|
||||
|
||||
/**
|
||||
* Author's link
|
||||
*
|
||||
* @var string
|
||||
* @see get_link()
|
||||
*/
|
||||
var $link;
|
||||
|
||||
/**
|
||||
* Author's email address
|
||||
*
|
||||
* @var string
|
||||
* @see get_email()
|
||||
*/
|
||||
var $email;
|
||||
|
||||
/**
|
||||
* Constructor, used to input the data
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $link
|
||||
* @param string $email
|
||||
*/
|
||||
public function __construct($name = null, $link = null, $email = null)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->link = $link;
|
||||
$this->email = $email;
|
||||
}
|
||||
|
||||
/**
|
||||
* String-ified version
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
// There is no $this->data here
|
||||
return md5(serialize($this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Author's name
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function get_name()
|
||||
{
|
||||
if ($this->name !== null)
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Author's link
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function get_link()
|
||||
{
|
||||
if ($this->link !== null)
|
||||
{
|
||||
return $this->link;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Author's email address
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function get_email()
|
||||
{
|
||||
if ($this->email !== null)
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2016, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the SimplePie Team nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
|
||||
* AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @package SimplePie
|
||||
* @copyright 2004-2016 Ryan Parman, Sam Sneddon, Ryan McCue
|
||||
* @author Ryan Parman
|
||||
* @author Sam Sneddon
|
||||
* @author Ryan McCue
|
||||
* @link http://simplepie.org/ SimplePie
|
||||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Manages all author-related data
|
||||
*
|
||||
* Used by {@see SimplePie_Item::get_author()} and {@see SimplePie::get_authors()}
|
||||
*
|
||||
* This class can be overloaded with {@see SimplePie::set_author_class()}
|
||||
*
|
||||
* @package SimplePie
|
||||
* @subpackage API
|
||||
*/
|
||||
class SimplePie_Author
|
||||
{
|
||||
/**
|
||||
* Author's name
|
||||
*
|
||||
* @var string
|
||||
* @see get_name()
|
||||
*/
|
||||
var $name;
|
||||
|
||||
/**
|
||||
* Author's link
|
||||
*
|
||||
* @var string
|
||||
* @see get_link()
|
||||
*/
|
||||
var $link;
|
||||
|
||||
/**
|
||||
* Author's email address
|
||||
*
|
||||
* @var string
|
||||
* @see get_email()
|
||||
*/
|
||||
var $email;
|
||||
|
||||
/**
|
||||
* Constructor, used to input the data
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $link
|
||||
* @param string $email
|
||||
*/
|
||||
public function __construct($name = null, $link = null, $email = null)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->link = $link;
|
||||
$this->email = $email;
|
||||
}
|
||||
|
||||
/**
|
||||
* String-ified version
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
// There is no $this->data here
|
||||
return md5(serialize($this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Author's name
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function get_name()
|
||||
{
|
||||
if ($this->name !== null)
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Author's link
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function get_link()
|
||||
{
|
||||
if ($this->link !== null)
|
||||
{
|
||||
return $this->link;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Author's email address
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function get_email()
|
||||
{
|
||||
if ($this->email !== null)
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,134 +1,134 @@
|
||||
<?php
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2016, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the SimplePie Team nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
|
||||
* AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @package SimplePie
|
||||
* @copyright 2004-2016 Ryan Parman, Sam Sneddon, Ryan McCue
|
||||
* @author Ryan Parman
|
||||
* @author Sam Sneddon
|
||||
* @author Ryan McCue
|
||||
* @link http://simplepie.org/ SimplePie
|
||||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Used to create cache objects
|
||||
*
|
||||
* This class can be overloaded with {@see SimplePie::set_cache_class()},
|
||||
* although the preferred way is to create your own handler
|
||||
* via {@see register()}
|
||||
*
|
||||
* @package SimplePie
|
||||
* @subpackage Caching
|
||||
*/
|
||||
class SimplePie_Cache
|
||||
{
|
||||
/**
|
||||
* Cache handler classes
|
||||
*
|
||||
* These receive 3 parameters to their constructor, as documented in
|
||||
* {@see register()}
|
||||
* @var array
|
||||
*/
|
||||
protected static $handlers = array(
|
||||
'mysql' => 'SimplePie_Cache_MySQL',
|
||||
'memcache' => 'SimplePie_Cache_Memcache',
|
||||
'memcached' => 'SimplePie_Cache_Memcached',
|
||||
'redis' => 'SimplePie_Cache_Redis'
|
||||
);
|
||||
|
||||
/**
|
||||
* Don't call the constructor. Please.
|
||||
*/
|
||||
private function __construct() { }
|
||||
|
||||
/**
|
||||
* Create a new SimplePie_Cache object
|
||||
*
|
||||
* @param string $location URL location (scheme is used to determine handler)
|
||||
* @param string $filename Unique identifier for cache object
|
||||
* @param string $extension 'spi' or 'spc'
|
||||
* @return SimplePie_Cache_Base Type of object depends on scheme of `$location`
|
||||
*/
|
||||
public static function get_handler($location, $filename, $extension)
|
||||
{
|
||||
$type = explode(':', $location, 2);
|
||||
$type = $type[0];
|
||||
if (!empty(self::$handlers[$type]))
|
||||
{
|
||||
$class = self::$handlers[$type];
|
||||
return new $class($location, $filename, $extension);
|
||||
}
|
||||
|
||||
return new SimplePie_Cache_File($location, $filename, $extension);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new SimplePie_Cache object
|
||||
*
|
||||
* @deprecated Use {@see get_handler} instead
|
||||
*/
|
||||
public function create($location, $filename, $extension)
|
||||
{
|
||||
trigger_error('Cache::create() has been replaced with Cache::get_handler(). Switch to the registry system to use this.', E_USER_DEPRECATED);
|
||||
return self::get_handler($location, $filename, $extension);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a handler
|
||||
*
|
||||
* @param string $type DSN type to register for
|
||||
* @param string $class Name of handler class. Must implement SimplePie_Cache_Base
|
||||
*/
|
||||
public static function register($type, $class)
|
||||
{
|
||||
self::$handlers[$type] = $class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a URL into an array
|
||||
*
|
||||
* @param string $url
|
||||
* @return array
|
||||
*/
|
||||
public static function parse_URL($url)
|
||||
{
|
||||
$params = parse_url($url);
|
||||
$params['extras'] = array();
|
||||
if (isset($params['query']))
|
||||
{
|
||||
parse_str($params['query'], $params['extras']);
|
||||
}
|
||||
return $params;
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2016, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the SimplePie Team nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
|
||||
* AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @package SimplePie
|
||||
* @copyright 2004-2016 Ryan Parman, Sam Sneddon, Ryan McCue
|
||||
* @author Ryan Parman
|
||||
* @author Sam Sneddon
|
||||
* @author Ryan McCue
|
||||
* @link http://simplepie.org/ SimplePie
|
||||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Used to create cache objects
|
||||
*
|
||||
* This class can be overloaded with {@see SimplePie::set_cache_class()},
|
||||
* although the preferred way is to create your own handler
|
||||
* via {@see register()}
|
||||
*
|
||||
* @package SimplePie
|
||||
* @subpackage Caching
|
||||
*/
|
||||
class SimplePie_Cache
|
||||
{
|
||||
/**
|
||||
* Cache handler classes
|
||||
*
|
||||
* These receive 3 parameters to their constructor, as documented in
|
||||
* {@see register()}
|
||||
* @var array
|
||||
*/
|
||||
protected static $handlers = array(
|
||||
'mysql' => 'SimplePie_Cache_MySQL',
|
||||
'memcache' => 'SimplePie_Cache_Memcache',
|
||||
'memcached' => 'SimplePie_Cache_Memcached',
|
||||
'redis' => 'SimplePie_Cache_Redis'
|
||||
);
|
||||
|
||||
/**
|
||||
* Don't call the constructor. Please.
|
||||
*/
|
||||
private function __construct() { }
|
||||
|
||||
/**
|
||||
* Create a new SimplePie_Cache object
|
||||
*
|
||||
* @param string $location URL location (scheme is used to determine handler)
|
||||
* @param string $filename Unique identifier for cache object
|
||||
* @param string $extension 'spi' or 'spc'
|
||||
* @return SimplePie_Cache_Base Type of object depends on scheme of `$location`
|
||||
*/
|
||||
public static function get_handler($location, $filename, $extension)
|
||||
{
|
||||
$type = explode(':', $location, 2);
|
||||
$type = $type[0];
|
||||
if (!empty(self::$handlers[$type]))
|
||||
{
|
||||
$class = self::$handlers[$type];
|
||||
return new $class($location, $filename, $extension);
|
||||
}
|
||||
|
||||
return new SimplePie_Cache_File($location, $filename, $extension);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new SimplePie_Cache object
|
||||
*
|
||||
* @deprecated Use {@see get_handler} instead
|
||||
*/
|
||||
public function create($location, $filename, $extension)
|
||||
{
|
||||
trigger_error('Cache::create() has been replaced with Cache::get_handler(). Switch to the registry system to use this.', E_USER_DEPRECATED);
|
||||
return self::get_handler($location, $filename, $extension);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a handler
|
||||
*
|
||||
* @param string $type DSN type to register for
|
||||
* @param string $class Name of handler class. Must implement SimplePie_Cache_Base
|
||||
*/
|
||||
public static function register($type, $class)
|
||||
{
|
||||
self::$handlers[$type] = $class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a URL into an array
|
||||
*
|
||||
* @param string $url
|
||||
* @return array
|
||||
*/
|
||||
public static function parse_URL($url)
|
||||
{
|
||||
$params = parse_url($url);
|
||||
$params['extras'] = array();
|
||||
if (isset($params['query']))
|
||||
{
|
||||
parse_str($params['query'], $params['extras']);
|
||||
}
|
||||
return $params;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,113 +1,113 @@
|
||||
<?php
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2016, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the SimplePie Team nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
|
||||
* AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @package SimplePie
|
||||
* @copyright 2004-2016 Ryan Parman, Sam Sneddon, Ryan McCue
|
||||
* @author Ryan Parman
|
||||
* @author Sam Sneddon
|
||||
* @author Ryan McCue
|
||||
* @link http://simplepie.org/ SimplePie
|
||||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base for cache objects
|
||||
*
|
||||
* Classes to be used with {@see SimplePie_Cache::register()} are expected
|
||||
* to implement this interface.
|
||||
*
|
||||
* @package SimplePie
|
||||
* @subpackage Caching
|
||||
*/
|
||||
interface SimplePie_Cache_Base
|
||||
{
|
||||
/**
|
||||
* Feed cache type
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const TYPE_FEED = 'spc';
|
||||
|
||||
/**
|
||||
* Image cache type
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const TYPE_IMAGE = 'spi';
|
||||
|
||||
/**
|
||||
* Create a new cache object
|
||||
*
|
||||
* @param string $location Location string (from SimplePie::$cache_location)
|
||||
* @param string $name Unique ID for the cache
|
||||
* @param string $type Either TYPE_FEED for SimplePie data, or TYPE_IMAGE for image data
|
||||
*/
|
||||
public function __construct($location, $name, $type);
|
||||
|
||||
/**
|
||||
* Save data to the cache
|
||||
*
|
||||
* @param array|SimplePie $data Data to store in the cache. If passed a SimplePie object, only cache the $data property
|
||||
* @return bool Successfulness
|
||||
*/
|
||||
public function save($data);
|
||||
|
||||
/**
|
||||
* Retrieve the data saved to the cache
|
||||
*
|
||||
* @return array Data for SimplePie::$data
|
||||
*/
|
||||
public function load();
|
||||
|
||||
/**
|
||||
* Retrieve the last modified time for the cache
|
||||
*
|
||||
* @return int Timestamp
|
||||
*/
|
||||
public function mtime();
|
||||
|
||||
/**
|
||||
* Set the last modified time to the current time
|
||||
*
|
||||
* @return bool Success status
|
||||
*/
|
||||
public function touch();
|
||||
|
||||
/**
|
||||
* Remove the cache
|
||||
*
|
||||
* @return bool Success status
|
||||
*/
|
||||
public function unlink();
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2016, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the SimplePie Team nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
|
||||
* AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @package SimplePie
|
||||
* @copyright 2004-2016 Ryan Parman, Sam Sneddon, Ryan McCue
|
||||
* @author Ryan Parman
|
||||
* @author Sam Sneddon
|
||||
* @author Ryan McCue
|
||||
* @link http://simplepie.org/ SimplePie
|
||||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base for cache objects
|
||||
*
|
||||
* Classes to be used with {@see SimplePie_Cache::register()} are expected
|
||||
* to implement this interface.
|
||||
*
|
||||
* @package SimplePie
|
||||
* @subpackage Caching
|
||||
*/
|
||||
interface SimplePie_Cache_Base
|
||||
{
|
||||
/**
|
||||
* Feed cache type
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const TYPE_FEED = 'spc';
|
||||
|
||||
/**
|
||||
* Image cache type
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const TYPE_IMAGE = 'spi';
|
||||
|
||||
/**
|
||||
* Create a new cache object
|
||||
*
|
||||
* @param string $location Location string (from SimplePie::$cache_location)
|
||||
* @param string $name Unique ID for the cache
|
||||
* @param string $type Either TYPE_FEED for SimplePie data, or TYPE_IMAGE for image data
|
||||
*/
|
||||
public function __construct($location, $name, $type);
|
||||
|
||||
/**
|
||||
* Save data to the cache
|
||||
*
|
||||
* @param array|SimplePie $data Data to store in the cache. If passed a SimplePie object, only cache the $data property
|
||||
* @return bool Successfulness
|
||||
*/
|
||||
public function save($data);
|
||||
|
||||
/**
|
||||
* Retrieve the data saved to the cache
|
||||
*
|
||||
* @return array Data for SimplePie::$data
|
||||
*/
|
||||
public function load();
|
||||
|
||||
/**
|
||||
* Retrieve the last modified time for the cache
|
||||
*
|
||||
* @return int Timestamp
|
||||
*/
|
||||
public function mtime();
|
||||
|
||||
/**
|
||||
* Set the last modified time to the current time
|
||||
*
|
||||
* @return bool Success status
|
||||
*/
|
||||
public function touch();
|
||||
|
||||
/**
|
||||
* Remove the cache
|
||||
*
|
||||
* @return bool Success status
|
||||
*/
|
||||
public function unlink();
|
||||
}
|
||||
|
||||
@@ -1,136 +1,136 @@
|
||||
<?php
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2016, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the SimplePie Team nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
|
||||
* AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @package SimplePie
|
||||
* @copyright 2004-2016 Ryan Parman, Sam Sneddon, Ryan McCue
|
||||
* @author Ryan Parman
|
||||
* @author Sam Sneddon
|
||||
* @author Ryan McCue
|
||||
* @link http://simplepie.org/ SimplePie
|
||||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for database-based caches
|
||||
*
|
||||
* @package SimplePie
|
||||
* @subpackage Caching
|
||||
*/
|
||||
abstract class SimplePie_Cache_DB implements SimplePie_Cache_Base
|
||||
{
|
||||
/**
|
||||
* Helper for database conversion
|
||||
*
|
||||
* Converts a given {@see SimplePie} object into data to be stored
|
||||
*
|
||||
* @param SimplePie $data
|
||||
* @return array First item is the serialized data for storage, second item is the unique ID for this item
|
||||
*/
|
||||
protected static function prepare_simplepie_object_for_cache($data)
|
||||
{
|
||||
$items = $data->get_items();
|
||||
$items_by_id = array();
|
||||
|
||||
if (!empty($items))
|
||||
{
|
||||
foreach ($items as $item)
|
||||
{
|
||||
$items_by_id[$item->get_id()] = $item;
|
||||
}
|
||||
|
||||
if (count($items_by_id) !== count($items))
|
||||
{
|
||||
$items_by_id = array();
|
||||
foreach ($items as $item)
|
||||
{
|
||||
$items_by_id[$item->get_id(true)] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]))
|
||||
{
|
||||
$channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0];
|
||||
}
|
||||
elseif (isset($data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]))
|
||||
{
|
||||
$channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0];
|
||||
}
|
||||
elseif (isset($data->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]))
|
||||
{
|
||||
$channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0];
|
||||
}
|
||||
elseif (isset($data->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['channel'][0]))
|
||||
{
|
||||
$channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['channel'][0];
|
||||
}
|
||||
else
|
||||
{
|
||||
$channel = null;
|
||||
}
|
||||
|
||||
if ($channel !== null)
|
||||
{
|
||||
if (isset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['entry']))
|
||||
{
|
||||
unset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['entry']);
|
||||
}
|
||||
if (isset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['entry']))
|
||||
{
|
||||
unset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['entry']);
|
||||
}
|
||||
if (isset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_10]['item']))
|
||||
{
|
||||
unset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_10]['item']);
|
||||
}
|
||||
if (isset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_090]['item']))
|
||||
{
|
||||
unset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_090]['item']);
|
||||
}
|
||||
if (isset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_20]['item']))
|
||||
{
|
||||
unset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_20]['item']);
|
||||
}
|
||||
}
|
||||
if (isset($data->data['items']))
|
||||
{
|
||||
unset($data->data['items']);
|
||||
}
|
||||
if (isset($data->data['ordered_items']))
|
||||
{
|
||||
unset($data->data['ordered_items']);
|
||||
}
|
||||
}
|
||||
return array(serialize($data->data), $items_by_id);
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2016, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the SimplePie Team nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
|
||||
* AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @package SimplePie
|
||||
* @copyright 2004-2016 Ryan Parman, Sam Sneddon, Ryan McCue
|
||||
* @author Ryan Parman
|
||||
* @author Sam Sneddon
|
||||
* @author Ryan McCue
|
||||
* @link http://simplepie.org/ SimplePie
|
||||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for database-based caches
|
||||
*
|
||||
* @package SimplePie
|
||||
* @subpackage Caching
|
||||
*/
|
||||
abstract class SimplePie_Cache_DB implements SimplePie_Cache_Base
|
||||
{
|
||||
/**
|
||||
* Helper for database conversion
|
||||
*
|
||||
* Converts a given {@see SimplePie} object into data to be stored
|
||||
*
|
||||
* @param SimplePie $data
|
||||
* @return array First item is the serialized data for storage, second item is the unique ID for this item
|
||||
*/
|
||||
protected static function prepare_simplepie_object_for_cache($data)
|
||||
{
|
||||
$items = $data->get_items();
|
||||
$items_by_id = array();
|
||||
|
||||
if (!empty($items))
|
||||
{
|
||||
foreach ($items as $item)
|
||||
{
|
||||
$items_by_id[$item->get_id()] = $item;
|
||||
}
|
||||
|
||||
if (count($items_by_id) !== count($items))
|
||||
{
|
||||
$items_by_id = array();
|
||||
foreach ($items as $item)
|
||||
{
|
||||
$items_by_id[$item->get_id(true)] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]))
|
||||
{
|
||||
$channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0];
|
||||
}
|
||||
elseif (isset($data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]))
|
||||
{
|
||||
$channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0];
|
||||
}
|
||||
elseif (isset($data->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]))
|
||||
{
|
||||
$channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0];
|
||||
}
|
||||
elseif (isset($data->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['channel'][0]))
|
||||
{
|
||||
$channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['channel'][0];
|
||||
}
|
||||
else
|
||||
{
|
||||
$channel = null;
|
||||
}
|
||||
|
||||
if ($channel !== null)
|
||||
{
|
||||
if (isset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['entry']))
|
||||
{
|
||||
unset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['entry']);
|
||||
}
|
||||
if (isset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['entry']))
|
||||
{
|
||||
unset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['entry']);
|
||||
}
|
||||
if (isset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_10]['item']))
|
||||
{
|
||||
unset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_10]['item']);
|
||||
}
|
||||
if (isset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_090]['item']))
|
||||
{
|
||||
unset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_090]['item']);
|
||||
}
|
||||
if (isset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_20]['item']))
|
||||
{
|
||||
unset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_20]['item']);
|
||||
}
|
||||
}
|
||||
if (isset($data->data['items']))
|
||||
{
|
||||
unset($data->data['items']);
|
||||
}
|
||||
if (isset($data->data['ordered_items']))
|
||||
{
|
||||
unset($data->data['ordered_items']);
|
||||
}
|
||||
}
|
||||
return array(serialize($data->data), $items_by_id);
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user