updated composer dependencies
This commit is contained in:
parent
a46a37efcf
commit
2afbbbaeea
|
@ -258,16 +258,16 @@
|
|||
},
|
||||
{
|
||||
"name": "phpseclib/phpseclib",
|
||||
"version": "2.0.31",
|
||||
"version": "2.0.41",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/phpseclib/phpseclib.git",
|
||||
"reference": "233a920cb38636a43b18d428f9a8db1f0a1a08f4"
|
||||
"reference": "7e763c6f97ec1fcb37c46aa8ecfc20a2c71d9c1b"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/233a920cb38636a43b18d428f9a8db1f0a1a08f4",
|
||||
"reference": "233a920cb38636a43b18d428f9a8db1f0a1a08f4",
|
||||
"url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/7e763c6f97ec1fcb37c46aa8ecfc20a2c71d9c1b",
|
||||
"reference": "7e763c6f97ec1fcb37c46aa8ecfc20a2c71d9c1b",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -282,7 +282,8 @@
|
|||
"ext-gmp": "Install the GMP (GNU Multiple Precision) extension in order to speed up arbitrary precision integer arithmetic operations.",
|
||||
"ext-libsodium": "SSH2/SFTP can make use of some algorithms provided by the libsodium-php extension.",
|
||||
"ext-mcrypt": "Install the Mcrypt extension in order to speed up a few other cryptographic operations.",
|
||||
"ext-openssl": "Install the OpenSSL extension in order to speed up a wide variety of cryptographic operations."
|
||||
"ext-openssl": "Install the OpenSSL extension in order to speed up a wide variety of cryptographic operations.",
|
||||
"ext-xml": "Install the XML extension to load XML formatted public keys."
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
|
@ -347,7 +348,7 @@
|
|||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/phpseclib/phpseclib/issues",
|
||||
"source": "https://github.com/phpseclib/phpseclib/tree/2.0.31"
|
||||
"source": "https://github.com/phpseclib/phpseclib/tree/2.0.41"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
|
@ -363,30 +364,32 @@
|
|||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2021-04-06T13:56:45+00:00"
|
||||
"time": "2022-12-23T16:44:18+00:00"
|
||||
},
|
||||
{
|
||||
"name": "simplepie/simplepie",
|
||||
"version": "1.5.6",
|
||||
"version": "1.8.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/simplepie/simplepie.git",
|
||||
"reference": "1c68e14ca3ac84346b6e6fe3c5eedf725d0f92c6"
|
||||
"reference": "65b095d87bc00898d8fa7737bdbcda93a3fbcc55"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/simplepie/simplepie/zipball/1c68e14ca3ac84346b6e6fe3c5eedf725d0f92c6",
|
||||
"reference": "1c68e14ca3ac84346b6e6fe3c5eedf725d0f92c6",
|
||||
"url": "https://api.github.com/repos/simplepie/simplepie/zipball/65b095d87bc00898d8fa7737bdbcda93a3fbcc55",
|
||||
"reference": "65b095d87bc00898d8fa7737bdbcda93a3fbcc55",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-pcre": "*",
|
||||
"ext-xml": "*",
|
||||
"ext-xmlreader": "*",
|
||||
"php": ">=5.6.0"
|
||||
"php": ">=7.2.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "~5.4.3 || ~6.5"
|
||||
"friendsofphp/php-cs-fixer": "^2.19 || ^3.8",
|
||||
"psr/simple-cache": "^1 || ^2 || ^3",
|
||||
"yoast/phpunit-polyfills": "^1.0.1"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-curl": "",
|
||||
|
@ -399,6 +402,9 @@
|
|||
"autoload": {
|
||||
"psr-0": {
|
||||
"SimplePie": "library"
|
||||
},
|
||||
"psr-4": {
|
||||
"SimplePie\\": "src"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
|
@ -432,26 +438,26 @@
|
|||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/simplepie/simplepie/issues",
|
||||
"source": "https://github.com/simplepie/simplepie/tree/1.5.6"
|
||||
"source": "https://github.com/simplepie/simplepie/tree/1.8.0"
|
||||
},
|
||||
"time": "2020-10-14T07:17:22+00:00"
|
||||
"time": "2023-01-20T08:37:35+00:00"
|
||||
},
|
||||
{
|
||||
"name": "splitbrain/php-archive",
|
||||
"version": "1.2.1",
|
||||
"version": "1.3.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/splitbrain/php-archive.git",
|
||||
"reference": "211a2198b73b233d7d2b6159462e11cd9a91348a"
|
||||
"reference": "d274e5190ba309777926348900cf9578d9e533c9"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/splitbrain/php-archive/zipball/211a2198b73b233d7d2b6159462e11cd9a91348a",
|
||||
"reference": "211a2198b73b233d7d2b6159462e11cd9a91348a",
|
||||
"url": "https://api.github.com/repos/splitbrain/php-archive/zipball/d274e5190ba309777926348900cf9578d9e533c9",
|
||||
"reference": "d274e5190ba309777926348900cf9578d9e533c9",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.4"
|
||||
"php": ">=7.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"ext-bz2": "*",
|
||||
|
@ -460,8 +466,10 @@
|
|||
"phpunit/phpunit": "^8"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-bz2": "For bz2 compression",
|
||||
"ext-iconv": "Used for proper filename encode handling",
|
||||
"ext-mbstring": "Can be used alternatively for handling filename encoding"
|
||||
"ext-mbstring": "Can be used alternatively for handling filename encoding",
|
||||
"ext-zlib": "For zlib compression"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
|
@ -490,22 +498,22 @@
|
|||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/splitbrain/php-archive/issues",
|
||||
"source": "https://github.com/splitbrain/php-archive/tree/1.2.1"
|
||||
"source": "https://github.com/splitbrain/php-archive/tree/1.3.1"
|
||||
},
|
||||
"time": "2021-02-22T17:59:24+00:00"
|
||||
"time": "2022-03-23T09:21:55+00:00"
|
||||
},
|
||||
{
|
||||
"name": "splitbrain/php-cli",
|
||||
"version": "1.1.8",
|
||||
"version": "1.2.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/splitbrain/php-cli.git",
|
||||
"reference": "8c2c001b1b55d194402cf18aad2757049ac6d575"
|
||||
"reference": "47cd2b2c1d976d22afb01e121985d59c4f98c031"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/splitbrain/php-cli/zipball/8c2c001b1b55d194402cf18aad2757049ac6d575",
|
||||
"reference": "8c2c001b1b55d194402cf18aad2757049ac6d575",
|
||||
"url": "https://api.github.com/repos/splitbrain/php-cli/zipball/47cd2b2c1d976d22afb01e121985d59c4f98c031",
|
||||
"reference": "47cd2b2c1d976d22afb01e121985d59c4f98c031",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -545,9 +553,9 @@
|
|||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/splitbrain/php-cli/issues",
|
||||
"source": "https://github.com/splitbrain/php-cli/tree/1.1.8"
|
||||
"source": "https://github.com/splitbrain/php-cli/tree/1.2.1"
|
||||
},
|
||||
"time": "2021-02-05T12:02:46+00:00"
|
||||
"time": "2022-11-04T11:59:39+00:00"
|
||||
},
|
||||
{
|
||||
"name": "splitbrain/slika",
|
||||
|
|
|
@ -11,5 +11,6 @@ return array(
|
|||
'splitbrain\\phpcli\\' => array($vendorDir . '/splitbrain/php-cli/src'),
|
||||
'splitbrain\\PHPArchive\\' => array($vendorDir . '/splitbrain/php-archive/src'),
|
||||
'phpseclib\\' => array($vendorDir . '/phpseclib/phpseclib/phpseclib'),
|
||||
'SimplePie\\' => array($vendorDir . '/simplepie/simplepie/src'),
|
||||
'IXR\\' => array($vendorDir . '/kissifrot/php-ixr/src'),
|
||||
);
|
||||
|
|
|
@ -23,6 +23,10 @@ class ComposerStaticInita19a915ee98347a0c787119619d2ff9b
|
|||
array (
|
||||
'phpseclib\\' => 10,
|
||||
),
|
||||
'S' =>
|
||||
array (
|
||||
'SimplePie\\' => 10,
|
||||
),
|
||||
'I' =>
|
||||
array (
|
||||
'IXR\\' => 4,
|
||||
|
@ -50,6 +54,10 @@ class ComposerStaticInita19a915ee98347a0c787119619d2ff9b
|
|||
array (
|
||||
0 => __DIR__ . '/..' . '/phpseclib/phpseclib/phpseclib',
|
||||
),
|
||||
'SimplePie\\' =>
|
||||
array (
|
||||
0 => __DIR__ . '/..' . '/simplepie/simplepie/src',
|
||||
),
|
||||
'IXR\\' =>
|
||||
array (
|
||||
0 => __DIR__ . '/..' . '/kissifrot/php-ixr/src',
|
||||
|
|
|
@ -252,17 +252,17 @@
|
|||
},
|
||||
{
|
||||
"name": "phpseclib/phpseclib",
|
||||
"version": "2.0.31",
|
||||
"version_normalized": "2.0.31.0",
|
||||
"version": "2.0.41",
|
||||
"version_normalized": "2.0.41.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/phpseclib/phpseclib.git",
|
||||
"reference": "233a920cb38636a43b18d428f9a8db1f0a1a08f4"
|
||||
"reference": "7e763c6f97ec1fcb37c46aa8ecfc20a2c71d9c1b"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/233a920cb38636a43b18d428f9a8db1f0a1a08f4",
|
||||
"reference": "233a920cb38636a43b18d428f9a8db1f0a1a08f4",
|
||||
"url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/7e763c6f97ec1fcb37c46aa8ecfc20a2c71d9c1b",
|
||||
"reference": "7e763c6f97ec1fcb37c46aa8ecfc20a2c71d9c1b",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -277,9 +277,10 @@
|
|||
"ext-gmp": "Install the GMP (GNU Multiple Precision) extension in order to speed up arbitrary precision integer arithmetic operations.",
|
||||
"ext-libsodium": "SSH2/SFTP can make use of some algorithms provided by the libsodium-php extension.",
|
||||
"ext-mcrypt": "Install the Mcrypt extension in order to speed up a few other cryptographic operations.",
|
||||
"ext-openssl": "Install the OpenSSL extension in order to speed up a wide variety of cryptographic operations."
|
||||
"ext-openssl": "Install the OpenSSL extension in order to speed up a wide variety of cryptographic operations.",
|
||||
"ext-xml": "Install the XML extension to load XML formatted public keys."
|
||||
},
|
||||
"time": "2021-04-06T13:56:45+00:00",
|
||||
"time": "2022-12-23T16:44:18+00:00",
|
||||
"type": "library",
|
||||
"installation-source": "dist",
|
||||
"autoload": {
|
||||
|
@ -342,6 +343,10 @@
|
|||
"x.509",
|
||||
"x509"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/phpseclib/phpseclib/issues",
|
||||
"source": "https://github.com/phpseclib/phpseclib/tree/2.0.41"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://github.com/terrafrost",
|
||||
|
@ -360,27 +365,29 @@
|
|||
},
|
||||
{
|
||||
"name": "simplepie/simplepie",
|
||||
"version": "1.5.6",
|
||||
"version_normalized": "1.5.6.0",
|
||||
"version": "1.8.0",
|
||||
"version_normalized": "1.8.0.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/simplepie/simplepie.git",
|
||||
"reference": "1c68e14ca3ac84346b6e6fe3c5eedf725d0f92c6"
|
||||
"reference": "65b095d87bc00898d8fa7737bdbcda93a3fbcc55"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/simplepie/simplepie/zipball/1c68e14ca3ac84346b6e6fe3c5eedf725d0f92c6",
|
||||
"reference": "1c68e14ca3ac84346b6e6fe3c5eedf725d0f92c6",
|
||||
"url": "https://api.github.com/repos/simplepie/simplepie/zipball/65b095d87bc00898d8fa7737bdbcda93a3fbcc55",
|
||||
"reference": "65b095d87bc00898d8fa7737bdbcda93a3fbcc55",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-pcre": "*",
|
||||
"ext-xml": "*",
|
||||
"ext-xmlreader": "*",
|
||||
"php": ">=5.6.0"
|
||||
"php": ">=7.2.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "~5.4.3 || ~6.5"
|
||||
"friendsofphp/php-cs-fixer": "^2.19 || ^3.8",
|
||||
"psr/simple-cache": "^1 || ^2 || ^3",
|
||||
"yoast/phpunit-polyfills": "^1.0.1"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-curl": "",
|
||||
|
@ -389,12 +396,15 @@
|
|||
"ext-mbstring": "",
|
||||
"mf2/mf2": "Microformat module that allows for parsing HTML for microformats"
|
||||
},
|
||||
"time": "2020-10-14T07:17:22+00:00",
|
||||
"time": "2023-01-20T08:37:35+00:00",
|
||||
"type": "library",
|
||||
"installation-source": "dist",
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"SimplePie": "library"
|
||||
},
|
||||
"psr-4": {
|
||||
"SimplePie\\": "src"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
|
@ -426,25 +436,29 @@
|
|||
"feeds",
|
||||
"rss"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/simplepie/simplepie/issues",
|
||||
"source": "https://github.com/simplepie/simplepie/tree/1.8.0"
|
||||
},
|
||||
"install-path": "../simplepie/simplepie"
|
||||
},
|
||||
{
|
||||
"name": "splitbrain/php-archive",
|
||||
"version": "1.2.1",
|
||||
"version_normalized": "1.2.1.0",
|
||||
"version": "1.3.1",
|
||||
"version_normalized": "1.3.1.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/splitbrain/php-archive.git",
|
||||
"reference": "211a2198b73b233d7d2b6159462e11cd9a91348a"
|
||||
"reference": "d274e5190ba309777926348900cf9578d9e533c9"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/splitbrain/php-archive/zipball/211a2198b73b233d7d2b6159462e11cd9a91348a",
|
||||
"reference": "211a2198b73b233d7d2b6159462e11cd9a91348a",
|
||||
"url": "https://api.github.com/repos/splitbrain/php-archive/zipball/d274e5190ba309777926348900cf9578d9e533c9",
|
||||
"reference": "d274e5190ba309777926348900cf9578d9e533c9",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.4"
|
||||
"php": ">=7.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"ext-bz2": "*",
|
||||
|
@ -453,10 +467,12 @@
|
|||
"phpunit/phpunit": "^8"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-bz2": "For bz2 compression",
|
||||
"ext-iconv": "Used for proper filename encode handling",
|
||||
"ext-mbstring": "Can be used alternatively for handling filename encoding"
|
||||
"ext-mbstring": "Can be used alternatively for handling filename encoding",
|
||||
"ext-zlib": "For zlib compression"
|
||||
},
|
||||
"time": "2021-02-22T17:59:24+00:00",
|
||||
"time": "2022-03-23T09:21:55+00:00",
|
||||
"type": "library",
|
||||
"installation-source": "dist",
|
||||
"autoload": {
|
||||
|
@ -483,21 +499,25 @@
|
|||
"unzip",
|
||||
"zip"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/splitbrain/php-archive/issues",
|
||||
"source": "https://github.com/splitbrain/php-archive/tree/1.3.1"
|
||||
},
|
||||
"install-path": "../splitbrain/php-archive"
|
||||
},
|
||||
{
|
||||
"name": "splitbrain/php-cli",
|
||||
"version": "1.1.8",
|
||||
"version_normalized": "1.1.8.0",
|
||||
"version": "1.2.1",
|
||||
"version_normalized": "1.2.1.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/splitbrain/php-cli.git",
|
||||
"reference": "8c2c001b1b55d194402cf18aad2757049ac6d575"
|
||||
"reference": "47cd2b2c1d976d22afb01e121985d59c4f98c031"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/splitbrain/php-cli/zipball/8c2c001b1b55d194402cf18aad2757049ac6d575",
|
||||
"reference": "8c2c001b1b55d194402cf18aad2757049ac6d575",
|
||||
"url": "https://api.github.com/repos/splitbrain/php-cli/zipball/47cd2b2c1d976d22afb01e121985d59c4f98c031",
|
||||
"reference": "47cd2b2c1d976d22afb01e121985d59c4f98c031",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -509,7 +529,7 @@
|
|||
"suggest": {
|
||||
"psr/log": "Allows you to make the CLI available as PSR-3 logger"
|
||||
},
|
||||
"time": "2021-02-05T12:02:46+00:00",
|
||||
"time": "2022-11-04T11:59:39+00:00",
|
||||
"type": "library",
|
||||
"installation-source": "dist",
|
||||
"autoload": {
|
||||
|
@ -537,6 +557,10 @@
|
|||
"optparse",
|
||||
"terminal"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/splitbrain/php-cli/issues",
|
||||
"source": "https://github.com/splitbrain/php-cli/tree/1.2.1"
|
||||
},
|
||||
"install-path": "../splitbrain/php-cli"
|
||||
},
|
||||
{
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
'type' => 'project',
|
||||
'install_path' => __DIR__ . '/../../',
|
||||
'aliases' => array(),
|
||||
'reference' => '11ad7f4705aea641b0f6f4997c153001bc4522d6',
|
||||
'reference' => 'a46a37efcf1638f0307b96eab90ec9138202a230',
|
||||
'name' => 'splitbrain/dokuwiki',
|
||||
'dev' => true,
|
||||
),
|
||||
|
@ -59,21 +59,21 @@
|
|||
'dev_requirement' => false,
|
||||
),
|
||||
'phpseclib/phpseclib' => array(
|
||||
'pretty_version' => '2.0.31',
|
||||
'version' => '2.0.31.0',
|
||||
'pretty_version' => '2.0.41',
|
||||
'version' => '2.0.41.0',
|
||||
'type' => 'library',
|
||||
'install_path' => __DIR__ . '/../phpseclib/phpseclib',
|
||||
'aliases' => array(),
|
||||
'reference' => '233a920cb38636a43b18d428f9a8db1f0a1a08f4',
|
||||
'reference' => '7e763c6f97ec1fcb37c46aa8ecfc20a2c71d9c1b',
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
'simplepie/simplepie' => array(
|
||||
'pretty_version' => '1.5.6',
|
||||
'version' => '1.5.6.0',
|
||||
'pretty_version' => '1.8.0',
|
||||
'version' => '1.8.0.0',
|
||||
'type' => 'library',
|
||||
'install_path' => __DIR__ . '/../simplepie/simplepie',
|
||||
'aliases' => array(),
|
||||
'reference' => '1c68e14ca3ac84346b6e6fe3c5eedf725d0f92c6',
|
||||
'reference' => '65b095d87bc00898d8fa7737bdbcda93a3fbcc55',
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
'splitbrain/dokuwiki' => array(
|
||||
|
@ -82,25 +82,25 @@
|
|||
'type' => 'project',
|
||||
'install_path' => __DIR__ . '/../../',
|
||||
'aliases' => array(),
|
||||
'reference' => '11ad7f4705aea641b0f6f4997c153001bc4522d6',
|
||||
'reference' => 'a46a37efcf1638f0307b96eab90ec9138202a230',
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
'splitbrain/php-archive' => array(
|
||||
'pretty_version' => '1.2.1',
|
||||
'version' => '1.2.1.0',
|
||||
'pretty_version' => '1.3.1',
|
||||
'version' => '1.3.1.0',
|
||||
'type' => 'library',
|
||||
'install_path' => __DIR__ . '/../splitbrain/php-archive',
|
||||
'aliases' => array(),
|
||||
'reference' => '211a2198b73b233d7d2b6159462e11cd9a91348a',
|
||||
'reference' => 'd274e5190ba309777926348900cf9578d9e533c9',
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
'splitbrain/php-cli' => array(
|
||||
'pretty_version' => '1.1.8',
|
||||
'version' => '1.1.8.0',
|
||||
'pretty_version' => '1.2.1',
|
||||
'version' => '1.2.1.0',
|
||||
'type' => 'library',
|
||||
'install_path' => __DIR__ . '/../splitbrain/php-cli',
|
||||
'aliases' => array(),
|
||||
'reference' => '8c2c001b1b55d194402cf18aad2757049ac6d575',
|
||||
'reference' => '47cd2b2c1d976d22afb01e121985d59c4f98c031',
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
'splitbrain/slika' => array(
|
||||
|
|
|
@ -4,3 +4,4 @@ phpseclib Developers: monnerat (Patrick Monnerat)
|
|||
bantu (Andreas Fischer)
|
||||
petrich (Hans-Jürgen Petrich)
|
||||
GrahamCampbell (Graham Campbell)
|
||||
hc-jworman
|
|
@ -4,5 +4,11 @@ phpseclib ongoing development is made possible by [Tidelift](https://tidelift.co
|
|||
|
||||
## Backers
|
||||
|
||||
- Allan Simon
|
||||
- [ChargeOver](https://chargeover.com/)
|
||||
- Raghu Veer Dendukuri
|
||||
- Zane Hooper
|
||||
- [Setasign](https://www.setasign.com/)
|
||||
- [Setasign](https://www.setasign.com/)
|
||||
- [Charles Severance](https://github.com/csev)
|
||||
- [Rachel Fish](https://github.com/itsrachelfish)
|
||||
- Tharyrok
|
|
@ -1,6 +1,6 @@
|
|||
# phpseclib - PHP Secure Communications Library
|
||||
|
||||
[![Build Status](https://travis-ci.com/phpseclib/phpseclib.svg?branch=2.0)](https://travis-ci.com/phpseclib/phpseclib)
|
||||
[![Build Status](https://travis-ci.com/phpseclib/phpseclib.svg?branch=2.0)](https://travis-ci.com/github/phpseclib/phpseclib)
|
||||
|
||||
## Supporting phpseclib
|
||||
|
||||
|
@ -52,7 +52,7 @@ SSH-2, SFTP, X.509, an arbitrary-precision integer arithmetic library, Ed25519 /
|
|||
* Composer compatible (PSR-0 autoloading)
|
||||
* Install using Composer: `composer require phpseclib/phpseclib:~1.0`
|
||||
* Install using PEAR: See [phpseclib PEAR Channel Documentation](http://phpseclib.sourceforge.net/pear.htm)
|
||||
* [Download 1.0.19 as ZIP](http://sourceforge.net/projects/phpseclib/files/phpseclib1.0.19.zip/download)
|
||||
* [Download 1.0.20 as ZIP](http://sourceforge.net/projects/phpseclib/files/phpseclib1.0.20.zip/download)
|
||||
|
||||
## Security contact information
|
||||
|
||||
|
@ -66,6 +66,13 @@ Need Support?
|
|||
* [Create a Support Ticket on GitHub](https://github.com/phpseclib/phpseclib/issues/new)
|
||||
* [Browse the Support Forum](http://www.frostjedi.com/phpbb/viewforum.php?f=46) (no longer in use)
|
||||
|
||||
## Special Thanks
|
||||
|
||||
Special Thanks to our $50+ sponsors!:
|
||||
|
||||
- Allan Simon
|
||||
- [ChargeOver](https://chargeover.com/)
|
||||
|
||||
## Contributing
|
||||
|
||||
1. Fork the Project
|
||||
|
|
|
@ -62,7 +62,8 @@
|
|||
"ext-libsodium": "SSH2/SFTP can make use of some algorithms provided by the libsodium-php extension.",
|
||||
"ext-openssl": "Install the OpenSSL extension in order to speed up a wide variety of cryptographic operations.",
|
||||
"ext-mcrypt": "Install the Mcrypt extension in order to speed up a few other cryptographic operations.",
|
||||
"ext-gmp": "Install the GMP (GNU Multiple Precision) extension in order to speed up arbitrary precision integer arithmetic operations."
|
||||
"ext-gmp": "Install the GMP (GNU Multiple Precision) extension in order to speed up arbitrary precision integer arithmetic operations.",
|
||||
"ext-xml": "Install the XML extension to load XML formatted public keys."
|
||||
},
|
||||
"autoload": {
|
||||
"files": [
|
||||
|
|
|
@ -79,7 +79,11 @@ abstract class Base
|
|||
/**
|
||||
* Encrypt / decrypt using the Cipher Feedback mode (8bit)
|
||||
*/
|
||||
const MODE_CFB8 = 38;
|
||||
const MODE_CFB8 = 6;
|
||||
/**
|
||||
* Encrypt / decrypt using the Output Feedback mode (8bit)
|
||||
*/
|
||||
const MODE_OFB8 = 7;
|
||||
/**
|
||||
* Encrypt / decrypt using the Output Feedback mode.
|
||||
*
|
||||
|
@ -152,7 +156,7 @@ abstract class Base
|
|||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $iv;
|
||||
var $iv = '';
|
||||
|
||||
/**
|
||||
* A "sliding" Initialization Vector
|
||||
|
@ -484,6 +488,7 @@ abstract class Base
|
|||
case self::MODE_CTR:
|
||||
case self::MODE_CFB:
|
||||
case self::MODE_CFB8:
|
||||
case self::MODE_OFB8:
|
||||
case self::MODE_OFB:
|
||||
case self::MODE_STREAM:
|
||||
$this->mode = $mode;
|
||||
|
@ -495,6 +500,44 @@ abstract class Base
|
|||
}
|
||||
|
||||
$this->_setEngine();
|
||||
|
||||
// Determining whether inline crypting can be used by the cipher
|
||||
if ($this->use_inline_crypt !== false) {
|
||||
$this->use_inline_crypt = version_compare(PHP_VERSION, '5.3.0') >= 0 || function_exists('create_function');
|
||||
}
|
||||
|
||||
if (!defined('PHP_INT_SIZE')) {
|
||||
define('PHP_INT_SIZE', 4);
|
||||
}
|
||||
|
||||
if (!defined('CRYPT_BASE_USE_REG_INTVAL')) {
|
||||
switch (true) {
|
||||
// PHP_OS & "\xDF\xDF\xDF" == strtoupper(substr(PHP_OS, 0, 3)), but a lot faster
|
||||
case (PHP_OS & "\xDF\xDF\xDF") === 'WIN':
|
||||
case (php_uname('m') & "\xDF\xDF\xDF") != 'ARM':
|
||||
case PHP_INT_SIZE == 8:
|
||||
define('CRYPT_BASE_USE_REG_INTVAL', true);
|
||||
break;
|
||||
case (php_uname('m') & "\xDF\xDF\xDF") == 'ARM':
|
||||
switch (true) {
|
||||
/* PHP 7.0.0 introduced a bug that affected 32-bit ARM processors:
|
||||
|
||||
https://github.com/php/php-src/commit/716da71446ebbd40fa6cf2cea8a4b70f504cc3cd
|
||||
|
||||
altho the changelogs make no mention of it, this bug was fixed with this commit:
|
||||
|
||||
https://github.com/php/php-src/commit/c1729272b17a1fe893d1a54e423d3b71470f3ee8
|
||||
|
||||
affected versions of PHP are: 7.0.x, 7.1.0 - 7.1.23 and 7.2.0 - 7.2.11 */
|
||||
case PHP_VERSION_ID >= 70000 && PHP_VERSION_ID <= 70123:
|
||||
case PHP_VERSION_ID >= 70200 && PHP_VERSION_ID <= 70211:
|
||||
define('CRYPT_BASE_USE_REG_INTVAL', false);
|
||||
break;
|
||||
default:
|
||||
define('CRYPT_BASE_USE_REG_INTVAL', true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -588,6 +631,10 @@ abstract class Base
|
|||
* $hash, $salt, $count, $dkLen
|
||||
*
|
||||
* Where $hash (default = sha1) currently supports the following hashes: see: Crypt/Hash.php
|
||||
* {@link https://en.wikipedia.org/wiki/Bcrypt bcypt}:
|
||||
* $salt, $rounds, $keylen
|
||||
*
|
||||
* This is a modified version of bcrypt used by OpenSSH.
|
||||
*
|
||||
* @see Crypt/Hash.php
|
||||
* @param string $password
|
||||
|
@ -601,6 +648,28 @@ abstract class Base
|
|||
$key = '';
|
||||
|
||||
switch ($method) {
|
||||
case 'bcrypt':
|
||||
$func_args = func_get_args();
|
||||
|
||||
if (!isset($func_args[2])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$salt = $func_args[2];
|
||||
|
||||
$rounds = isset($func_args[3]) ? $func_args[3] : 16;
|
||||
$keylen = isset($func_args[4]) ? $func_args[4] : $this->key_length;
|
||||
|
||||
$bf = new Blowfish();
|
||||
$key = $bf->bcrypt_pbkdf($password, $salt, $keylen + $this->block_size, $rounds);
|
||||
if (!$key) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->setKey(substr($key, 0, $keylen));
|
||||
$this->setIV(substr($key, $keylen));
|
||||
|
||||
return true;
|
||||
default: // 'pbkdf2' or 'pbkdf1'
|
||||
$func_args = func_get_args();
|
||||
|
||||
|
@ -773,6 +842,22 @@ abstract class Base
|
|||
}
|
||||
}
|
||||
return $ciphertext;
|
||||
case self::MODE_OFB8:
|
||||
// OpenSSL has built in support for cfb8 but not ofb8
|
||||
$ciphertext = '';
|
||||
$len = strlen($plaintext);
|
||||
$iv = $this->encryptIV;
|
||||
|
||||
for ($i = 0; $i < $len; ++$i) {
|
||||
$xor = openssl_encrypt($iv, $this->cipher_name_openssl_ecb, $this->key, $this->openssl_options, $this->decryptIV);
|
||||
$ciphertext.= $plaintext[$i] ^ $xor;
|
||||
$iv = substr($iv, 1) . $xor[0];
|
||||
}
|
||||
|
||||
if ($this->continuousBuffer) {
|
||||
$this->encryptIV = $iv;
|
||||
}
|
||||
break;
|
||||
case self::MODE_OFB:
|
||||
return $this->_openssl_ofb_process($plaintext, $this->encryptIV, $this->enbuffer);
|
||||
}
|
||||
|
@ -896,8 +981,8 @@ abstract class Base
|
|||
$block = substr($plaintext, $i, $block_size);
|
||||
if (strlen($block) > strlen($buffer['ciphertext'])) {
|
||||
$buffer['ciphertext'].= $this->_encryptBlock($xor);
|
||||
$this->_increment_str($xor);
|
||||
}
|
||||
$this->_increment_str($xor);
|
||||
$key = $this->_string_shift($buffer['ciphertext'], $block_size);
|
||||
$ciphertext.= $block ^ $key;
|
||||
}
|
||||
|
@ -959,12 +1044,14 @@ abstract class Base
|
|||
}
|
||||
break;
|
||||
case self::MODE_CFB8:
|
||||
// compared to regular CFB, which encrypts a block at a time,
|
||||
// here, we're encrypting a byte at a time
|
||||
$ciphertext = '';
|
||||
$len = strlen($plaintext);
|
||||
$iv = $this->encryptIV;
|
||||
|
||||
for ($i = 0; $i < $len; ++$i) {
|
||||
$ciphertext .= ($c = $plaintext[$i] ^ $this->_encryptBlock($iv));
|
||||
$ciphertext.= ($c = $plaintext[$i] ^ $this->_encryptBlock($iv));
|
||||
$iv = substr($iv, 1) . $c;
|
||||
}
|
||||
|
||||
|
@ -976,6 +1063,21 @@ abstract class Base
|
|||
}
|
||||
}
|
||||
break;
|
||||
case self::MODE_OFB8:
|
||||
$ciphertext = '';
|
||||
$len = strlen($plaintext);
|
||||
$iv = $this->encryptIV;
|
||||
|
||||
for ($i = 0; $i < $len; ++$i) {
|
||||
$xor = $this->_encryptBlock($iv);
|
||||
$ciphertext.= $plaintext[$i] ^ $xor;
|
||||
$iv = substr($iv, 1) . $xor[0];
|
||||
}
|
||||
|
||||
if ($this->continuousBuffer) {
|
||||
$this->encryptIV = $iv;
|
||||
}
|
||||
break;
|
||||
case self::MODE_OFB:
|
||||
$xor = $this->encryptIV;
|
||||
if (strlen($buffer['xor'])) {
|
||||
|
@ -1067,7 +1169,7 @@ abstract class Base
|
|||
$plaintext = '';
|
||||
if ($this->continuousBuffer) {
|
||||
$iv = &$this->decryptIV;
|
||||
$pos = &$this->buffer['pos'];
|
||||
$pos = &$this->debuffer['pos'];
|
||||
} else {
|
||||
$iv = $this->decryptIV;
|
||||
$pos = 0;
|
||||
|
@ -1116,6 +1218,21 @@ abstract class Base
|
|||
}
|
||||
}
|
||||
break;
|
||||
case self::MODE_OFB8:
|
||||
$plaintext = '';
|
||||
$len = strlen($ciphertext);
|
||||
$iv = $this->decryptIV;
|
||||
|
||||
for ($i = 0; $i < $len; ++$i) {
|
||||
$xor = openssl_encrypt($iv, $this->cipher_name_openssl_ecb, $this->key, $this->openssl_options, $this->decryptIV);
|
||||
$plaintext.= $ciphertext[$i] ^ $xor;
|
||||
$iv = substr($iv, 1) . $xor[0];
|
||||
}
|
||||
|
||||
if ($this->continuousBuffer) {
|
||||
$this->decryptIV = $iv;
|
||||
}
|
||||
break;
|
||||
case self::MODE_OFB:
|
||||
$plaintext = $this->_openssl_ofb_process($ciphertext, $this->decryptIV, $this->debuffer);
|
||||
}
|
||||
|
@ -1290,7 +1407,7 @@ abstract class Base
|
|||
$iv = $this->decryptIV;
|
||||
|
||||
for ($i = 0; $i < $len; ++$i) {
|
||||
$plaintext .= $ciphertext[$i] ^ $this->_encryptBlock($iv);
|
||||
$plaintext.= $ciphertext[$i] ^ $this->_encryptBlock($iv);
|
||||
$iv = substr($iv, 1) . $ciphertext[$i];
|
||||
}
|
||||
|
||||
|
@ -1302,6 +1419,21 @@ abstract class Base
|
|||
}
|
||||
}
|
||||
break;
|
||||
case self::MODE_OFB8:
|
||||
$plaintext = '';
|
||||
$len = strlen($ciphertext);
|
||||
$iv = $this->decryptIV;
|
||||
|
||||
for ($i = 0; $i < $len; ++$i) {
|
||||
$xor = $this->_encryptBlock($iv);
|
||||
$plaintext.= $ciphertext[$i] ^ $xor;
|
||||
$iv = substr($iv, 1) . $xor[0];
|
||||
}
|
||||
|
||||
if ($this->continuousBuffer) {
|
||||
$this->decryptIV = $iv;
|
||||
}
|
||||
break;
|
||||
case self::MODE_OFB:
|
||||
$xor = $this->decryptIV;
|
||||
if (strlen($buffer['xor'])) {
|
||||
|
@ -1864,6 +1996,7 @@ abstract class Base
|
|||
self::MODE_CFB => 'ncfb',
|
||||
self::MODE_CFB8 => MCRYPT_MODE_CFB,
|
||||
self::MODE_OFB => MCRYPT_MODE_NOFB,
|
||||
self::MODE_OFB8 => MCRYPT_MODE_OFB,
|
||||
self::MODE_STREAM => MCRYPT_MODE_STREAM,
|
||||
);
|
||||
|
||||
|
@ -2009,6 +2142,13 @@ abstract class Base
|
|||
*/
|
||||
function _increment_str(&$var)
|
||||
{
|
||||
if (function_exists('sodium_increment')) {
|
||||
$var = strrev($var);
|
||||
sodium_increment($var);
|
||||
$var = strrev($var);
|
||||
return;
|
||||
}
|
||||
|
||||
for ($i = 4; $i <= strlen($var); $i+= 4) {
|
||||
$temp = substr($var, -$i, 4);
|
||||
switch ($temp) {
|
||||
|
@ -2446,7 +2586,7 @@ abstract class Base
|
|||
for ($_i = 0; $_i < $_len; ++$_i) {
|
||||
$in = $_iv;
|
||||
'.$encrypt_block.'
|
||||
$_ciphertext .= ($_c = $_text[$_i] ^ $in);
|
||||
$_ciphertext.= ($_c = $_text[$_i] ^ $in);
|
||||
$_iv = substr($_iv, 1) . $_c;
|
||||
}
|
||||
|
||||
|
@ -2468,7 +2608,7 @@ abstract class Base
|
|||
for ($_i = 0; $_i < $_len; ++$_i) {
|
||||
$in = $_iv;
|
||||
'.$encrypt_block.'
|
||||
$_plaintext .= $_text[$_i] ^ $in;
|
||||
$_plaintext.= $_text[$_i] ^ $in;
|
||||
$_iv = substr($_iv, 1) . $_text[$_i];
|
||||
}
|
||||
|
||||
|
@ -2480,6 +2620,44 @@ abstract class Base
|
|||
}
|
||||
}
|
||||
|
||||
return $_plaintext;
|
||||
';
|
||||
break;
|
||||
case self::MODE_OFB8:
|
||||
$encrypt = $init_encrypt . '
|
||||
$_ciphertext = "";
|
||||
$_len = strlen($_text);
|
||||
$_iv = $self->encryptIV;
|
||||
|
||||
for ($_i = 0; $_i < $_len; ++$_i) {
|
||||
$in = $_iv;
|
||||
'.$encrypt_block.'
|
||||
$_ciphertext.= $_text[$_i] ^ $in;
|
||||
$_iv = substr($_iv, 1) . $in[0];
|
||||
}
|
||||
|
||||
if ($self->continuousBuffer) {
|
||||
$self->encryptIV = $_iv;
|
||||
}
|
||||
|
||||
return $_ciphertext;
|
||||
';
|
||||
$decrypt = $init_encrypt . '
|
||||
$_plaintext = "";
|
||||
$_len = strlen($_text);
|
||||
$_iv = $self->decryptIV;
|
||||
|
||||
for ($_i = 0; $_i < $_len; ++$_i) {
|
||||
$in = $_iv;
|
||||
'.$encrypt_block.'
|
||||
$_plaintext.= $_text[$_i] ^ $in;
|
||||
$_iv = substr($_iv, 1) . $in[0];
|
||||
}
|
||||
|
||||
if ($self->continuousBuffer) {
|
||||
$self->decryptIV = $_iv;
|
||||
}
|
||||
|
||||
return $_plaintext;
|
||||
';
|
||||
break;
|
||||
|
@ -2684,11 +2862,8 @@ abstract class Base
|
|||
*/
|
||||
function safe_intval($x)
|
||||
{
|
||||
switch (true) {
|
||||
case is_int($x):
|
||||
// PHP 5.3, per http://php.net/releases/5_3_0.php, introduced "more consistent float rounding"
|
||||
case (php_uname('m') & "\xDF\xDF\xDF") != 'ARM':
|
||||
return $x;
|
||||
if (is_int($x)) {
|
||||
return $x;
|
||||
}
|
||||
return (fmod($x, 0x80000000) & 0x7FFFFFFF) |
|
||||
((fmod(floor($x / 0x80000000), 2) & 1) << 31);
|
||||
|
@ -2702,15 +2877,12 @@ abstract class Base
|
|||
*/
|
||||
function safe_intval_inline()
|
||||
{
|
||||
switch (true) {
|
||||
case defined('PHP_INT_SIZE') && PHP_INT_SIZE == 8:
|
||||
case (php_uname('m') & "\xDF\xDF\xDF") != 'ARM':
|
||||
return '%s';
|
||||
break;
|
||||
default:
|
||||
$safeint = '(is_int($temp = %s) ? $temp : (fmod($temp, 0x80000000) & 0x7FFFFFFF) | ';
|
||||
return $safeint . '((fmod(floor($temp / 0x80000000), 2) & 1) << 31))';
|
||||
if (CRYPT_BASE_USE_REG_INTVAL) {
|
||||
return PHP_INT_SIZE == 4 ? 'intval(%s)' : '%s';
|
||||
}
|
||||
|
||||
$safeint = '(is_int($temp = %s) ? $temp : (fmod($temp, 0x80000000) & 0x7FFFFFFF) | ';
|
||||
return $safeint . '((fmod(floor($temp / 0x80000000), 2) & 1) << 31))';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2721,4 +2893,15 @@ abstract class Base
|
|||
function do_nothing()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the continuous buffer enabled?
|
||||
*
|
||||
* @access public
|
||||
* @return boolean
|
||||
*/
|
||||
function continuousBufferEnabled()
|
||||
{
|
||||
return $this->continuousBuffer;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,87 @@
|
|||
*
|
||||
* - {@link http://en.wikipedia.org/wiki/Blowfish_(cipher) Wikipedia description of Blowfish}
|
||||
*
|
||||
* # An overview of bcrypt vs Blowfish
|
||||
*
|
||||
* OpenSSH private keys use a customized version of bcrypt. Specifically, instead of
|
||||
* encrypting OrpheanBeholderScryDoubt 64 times OpenSSH's bcrypt variant encrypts
|
||||
* OxychromaticBlowfishSwatDynamite 64 times. so we can't use crypt().
|
||||
*
|
||||
* bcrypt is basically Blowfish but instead of performing the key expansion once it performs
|
||||
* the expansion 129 times for each round, with the first key expansion interleaving the salt
|
||||
* and password. This renders OpenSSL unusable and forces us to use a pure-PHP implementation
|
||||
* of blowfish.
|
||||
*
|
||||
* # phpseclib's four different _encryptBlock() implementations
|
||||
*
|
||||
* When using Blowfish as an encryption algorithm, _encryptBlock() is called 9 + 512 +
|
||||
* (the number of blocks in the plaintext) times.
|
||||
*
|
||||
* Each of the first 9 calls to _encryptBlock() modify the P-array. Each of the next 512
|
||||
* calls modify the S-boxes. The remaining _encryptBlock() calls operate on the plaintext to
|
||||
* produce the ciphertext. In the pure-PHP implementation of Blowfish these remaining
|
||||
* _encryptBlock() calls are highly optimized through the use of eval(). Among other things,
|
||||
* P-array lookups are eliminated by hard-coding the key-dependent P-array values, and thus we
|
||||
* have explained 2 of the 4 different _encryptBlock() implementations.
|
||||
*
|
||||
* With bcrypt things are a bit different. _encryptBlock() is called 1,079,296 times,
|
||||
* assuming 16 rounds (which is what OpenSSH's bcrypt defaults to). The eval()-optimized
|
||||
* _encryptBlock() isn't as beneficial because the P-array values are not constant. Well, they
|
||||
* are constant, but only for, at most, 777 _encryptBlock() calls, which is equivalent to ~6KB
|
||||
* of data. The average length of back to back _encryptBlock() calls with a fixed P-array is
|
||||
* 514.12, which is ~4KB of data. Creating an eval()-optimized _encryptBlock() has an upfront
|
||||
* cost, which is CPU dependent and is probably not going to be worth it for just ~4KB of
|
||||
* data. Conseqeuently, bcrypt does not benefit from the eval()-optimized _encryptBlock().
|
||||
*
|
||||
* The regular _encryptBlock() does unpack() and pack() on every call, as well, and that can
|
||||
* begin to add up after one million function calls.
|
||||
*
|
||||
* In theory, one might think that it might be beneficial to rewrite all block ciphers so
|
||||
* that, instead of passing strings to _encryptBlock(), you convert the string to an array of
|
||||
* integers and then pass successive subarrays of that array to _encryptBlock. This, however,
|
||||
* kills PHP's memory use. Like let's say you have a 1MB long string. After doing
|
||||
* $in = str_repeat('a', 1024 * 1024); PHP's memory utilization jumps up by ~1MB. After doing
|
||||
* $blocks = str_split($in, 4); it jumps up by an additional ~16MB. After
|
||||
* $blocks = array_map(fn($x) => unpack('N*', $x), $blocks); it jumps up by an additional
|
||||
* ~90MB, yielding a 106x increase in memory usage. Consequently, it bcrypt calls a different
|
||||
* _encryptBlock() then the regular Blowfish does. That said, the Blowfish _encryptBlock() is
|
||||
* basically just a thin wrapper around the bcrypt _encryptBlock(), so there's that.
|
||||
*
|
||||
* This explains 3 of the 4 _encryptBlock() implementations. the last _encryptBlock()
|
||||
* implementation can best be understood by doing Ctrl + F and searching for where
|
||||
* CRYPT_BASE_USE_REG_INTVAL is defined.
|
||||
*
|
||||
* # phpseclib's three different _setupKey() implementations
|
||||
*
|
||||
* Every bcrypt round is the equivalent of encrypting 512KB of data. Since OpenSSH uses 16
|
||||
* rounds by default that's ~8MB of data that's essentially being encrypted whenever
|
||||
* you use bcrypt. That's a lot of data, however, bcrypt operates within tighter constraints
|
||||
* than regular Blowfish, so we can use that to our advantage. In particular, whereas Blowfish
|
||||
* supports variable length keys, in bcrypt, the initial "key" is the sha512 hash of the
|
||||
* password. sha512 hashes are 512 bits or 64 bytes long and thus the bcrypt keys are of a
|
||||
* fixed length whereas Blowfish keys are not of a fixed length.
|
||||
*
|
||||
* bcrypt actually has two different key expansion steps. The first one (expandstate) is
|
||||
* constantly XOR'ing every _encryptBlock() parameter against the salt prior _encryptBlock()'s
|
||||
* being called. The second one (expand0state) is more similar to Blowfish's _setupKey()
|
||||
* but it can still use the fixed length key optimization discussed above and can do away with
|
||||
* the pack() / unpack() calls.
|
||||
*
|
||||
* I suppose _setupKey() could be made to be a thin wrapper around expandstate() but idk it's
|
||||
* just a lot of work for very marginal benefits as _setupKey() is only called once for
|
||||
* regular Blowfish vs the 128 times it's called --per round-- with bcrypt.
|
||||
*
|
||||
* # blowfish + bcrypt in the same class
|
||||
*
|
||||
* Altho there's a lot of Blowfish code that bcrypt doesn't re-use, bcrypt does re-use the
|
||||
* initial S-boxes, the initial P-array and the int-only _encryptBlock() implementation.
|
||||
*
|
||||
* # Credit
|
||||
*
|
||||
* phpseclib's bcrypt implementation is based losely off of OpenSSH's implementation:
|
||||
*
|
||||
* https://github.com/openssh/openssh-portable/blob/master/openbsd-compat/bcrypt_pbkdf.c
|
||||
*
|
||||
* Here's a short example of how to use this library:
|
||||
* <code>
|
||||
* <?php
|
||||
|
@ -74,6 +155,15 @@ class Blowfish extends Base
|
|||
*/
|
||||
var $cfb_init_len = 500;
|
||||
|
||||
/**
|
||||
* SHA512 Object
|
||||
*
|
||||
* @see self::bcrypt_pbkdf
|
||||
* @var object
|
||||
* @access private
|
||||
*/
|
||||
var $sha512;
|
||||
|
||||
/**
|
||||
* The fixed subkeys boxes ($sbox0 - $sbox3) with 256 entries each
|
||||
*
|
||||
|
@ -283,6 +373,41 @@ class Blowfish extends Base
|
|||
*/
|
||||
var $key_length = 16;
|
||||
|
||||
/**
|
||||
* Default Constructor.
|
||||
*
|
||||
* Determines whether or not the mcrypt extension should be used.
|
||||
*
|
||||
* $mode could be:
|
||||
*
|
||||
* - CRYPT_MODE_ECB
|
||||
*
|
||||
* - CRYPT_MODE_CBC
|
||||
*
|
||||
* - CRYPT_MODE_CTR
|
||||
*
|
||||
* - CRYPT_MODE_CFB
|
||||
*
|
||||
* - CRYPT_MODE_OFB
|
||||
*
|
||||
* (or the alias constants of the chosen cipher, for example for AES: CRYPT_AES_MODE_ECB or CRYPT_AES_MODE_CBC ...)
|
||||
*
|
||||
* If not explicitly set, CRYPT_MODE_CBC will be used.
|
||||
*
|
||||
* @param int $mode
|
||||
* @access public
|
||||
*/
|
||||
function __construct($mode = self::MODE_CBC)
|
||||
{
|
||||
parent::__construct($mode);
|
||||
|
||||
$this->sbox0 = array_map('intval', $this->sbox0);
|
||||
$this->sbox1 = array_map('intval', $this->sbox1);
|
||||
$this->sbox2 = array_map('intval', $this->sbox2);
|
||||
$this->sbox3 = array_map('intval', $this->sbox3);
|
||||
$this->parray = array_map('intval', $this->parray);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the key length.
|
||||
*
|
||||
|
@ -317,6 +442,12 @@ class Blowfish extends Base
|
|||
function isValidEngine($engine)
|
||||
{
|
||||
if ($engine == self::ENGINE_OPENSSL) {
|
||||
// quoting https://www.openssl.org/news/openssl-3.0-notes.html, OpenSSL 3.0.1
|
||||
// "Moved all variations of the EVP ciphers CAST5, BF, IDEA, SEED, RC2, RC4, RC5, and DES to the legacy provider"
|
||||
// in theory openssl_get_cipher_methods() should catch this but, on GitHub Actions, at least, it does not
|
||||
if (version_compare(preg_replace('#OpenSSL (\d+\.\d+\.\d+) .*#', '$1', OPENSSL_VERSION_TEXT), '3.0.1', '>=')) {
|
||||
return false;
|
||||
}
|
||||
if (version_compare(PHP_VERSION, '5.3.7') < 0 && $this->key_length != 16) {
|
||||
return false;
|
||||
}
|
||||
|
@ -358,6 +489,7 @@ class Blowfish extends Base
|
|||
// unpack binary string in unsigned chars
|
||||
$key = array_values(unpack('C*', $this->key));
|
||||
$keyl = count($key);
|
||||
// with bcrypt $keyl will always be 16 (because the key is the sha512 of the key you provide)
|
||||
for ($j = 0, $i = 0; $i < 18; ++$i) {
|
||||
// xor P1 with the first 32-bits of the key, xor P2 with the second 32-bits ...
|
||||
for ($data = 0, $k = 0; $k < 4; ++$k) {
|
||||
|
@ -366,7 +498,7 @@ class Blowfish extends Base
|
|||
$j = 0;
|
||||
}
|
||||
}
|
||||
$this->bctx['p'][] = $this->parray[$i] ^ $data;
|
||||
$this->bctx['p'][] = $this->parray[$i] ^ intval($data);
|
||||
}
|
||||
|
||||
// encrypt the zero-string, replace P1 and P2 with the encrypted data,
|
||||
|
@ -386,6 +518,230 @@ class Blowfish extends Base
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* bcrypt
|
||||
*
|
||||
* @param string $sha2pass
|
||||
* @param string $sha2salt
|
||||
* @access private
|
||||
* @return string
|
||||
*/
|
||||
function _bcrypt_hash($sha2pass, $sha2salt)
|
||||
{
|
||||
$p = $this->parray;
|
||||
$sbox0 = $this->sbox0;
|
||||
$sbox1 = $this->sbox1;
|
||||
$sbox2 = $this->sbox2;
|
||||
$sbox3 = $this->sbox3;
|
||||
|
||||
$cdata = array_values(unpack('N*', 'OxychromaticBlowfishSwatDynamite'));
|
||||
$sha2pass = array_values(unpack('N*', $sha2pass));
|
||||
$sha2salt = array_values(unpack('N*', $sha2salt));
|
||||
|
||||
$this->_expandstate($sha2salt, $sha2pass, $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
for ($i = 0; $i < 64; $i++) {
|
||||
$this->_expand0state($sha2salt, $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
$this->_expand0state($sha2pass, $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
}
|
||||
|
||||
for ($i = 0; $i < 64; $i++) {
|
||||
for ($j = 0; $j < 8; $j+= 2) { // count($cdata) == 8
|
||||
list($cdata[$j], $cdata[$j + 1]) = $this->_encryptBlockHelperFast($cdata[$j], $cdata[$j + 1], $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
}
|
||||
}
|
||||
|
||||
$output = '';
|
||||
for ($i = 0; $i < count($cdata); $i++) {
|
||||
$output.= pack('L*', $cdata[$i]);
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs OpenSSH-style bcrypt
|
||||
*
|
||||
* @param string $pass
|
||||
* @param string $salt
|
||||
* @param int $keylen
|
||||
* @param int $rounds
|
||||
* @access public
|
||||
* @return false|string
|
||||
*/
|
||||
function bcrypt_pbkdf($pass, $salt, $keylen, $rounds)
|
||||
{
|
||||
if (PHP_INT_SIZE == 4) {
|
||||
user_error('bcrypt is far too slow to be practical on 32-bit versions of PHP');
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isset($this->sha512)) {
|
||||
$this->sha512 = new Hash('sha512');
|
||||
}
|
||||
|
||||
$sha2pass = $this->sha512->hash($pass);
|
||||
$results = array();
|
||||
$count = 1;
|
||||
while (32 * count($results) < $keylen) {
|
||||
$countsalt = $salt . pack('N', $count++);
|
||||
$sha2salt = $this->sha512->hash($countsalt);
|
||||
$out = $tmpout = $this->_bcrypt_hash($sha2pass, $sha2salt);
|
||||
for ($i = 1; $i < $rounds; $i++) {
|
||||
$sha2salt = $this->sha512->hash($tmpout);
|
||||
$tmpout = $this->_bcrypt_hash($sha2pass, $sha2salt);
|
||||
$out^= $tmpout;
|
||||
}
|
||||
$results[] = $out;
|
||||
}
|
||||
$output = '';
|
||||
for ($i = 0; $i < 32; $i++) {
|
||||
foreach ($results as $result) {
|
||||
$output.= $result[$i];
|
||||
}
|
||||
}
|
||||
return substr($output, 0, $keylen);
|
||||
}
|
||||
|
||||
/**
|
||||
* Key expansion without salt
|
||||
*
|
||||
* @access private
|
||||
* @param int[] $key
|
||||
* @param int[] $sbox0
|
||||
* @param int[] $sbox1
|
||||
* @param int[] $sbox2
|
||||
* @param int[] $sbox3
|
||||
* @param int[] $p
|
||||
* @see self::_bcrypt_hash()
|
||||
*/
|
||||
function _expand0state($key, &$sbox0, &$sbox1, &$sbox2, &$sbox3, &$p)
|
||||
{
|
||||
// expand0state is basically the same thing as this:
|
||||
//return $this->_expandstate(array_fill(0, 16, 0), $key);
|
||||
// but this separate function eliminates a bunch of XORs and array lookups
|
||||
|
||||
$p = array(
|
||||
$p[0] ^ $key[0],
|
||||
$p[1] ^ $key[1],
|
||||
$p[2] ^ $key[2],
|
||||
$p[3] ^ $key[3],
|
||||
$p[4] ^ $key[4],
|
||||
$p[5] ^ $key[5],
|
||||
$p[6] ^ $key[6],
|
||||
$p[7] ^ $key[7],
|
||||
$p[8] ^ $key[8],
|
||||
$p[9] ^ $key[9],
|
||||
$p[10] ^ $key[10],
|
||||
$p[11] ^ $key[11],
|
||||
$p[12] ^ $key[12],
|
||||
$p[13] ^ $key[13],
|
||||
$p[14] ^ $key[14],
|
||||
$p[15] ^ $key[15],
|
||||
$p[16] ^ $key[0],
|
||||
$p[17] ^ $key[1]
|
||||
);
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
list( $p[0], $p[1]) = $this->_encryptBlockHelperFast( 0, 0, $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
list( $p[2], $p[3]) = $this->_encryptBlockHelperFast($p[ 0], $p[ 1], $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
list( $p[4], $p[5]) = $this->_encryptBlockHelperFast($p[ 2], $p[ 3], $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
list( $p[6], $p[7]) = $this->_encryptBlockHelperFast($p[ 4], $p[ 5], $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
list( $p[8], $p[9]) = $this->_encryptBlockHelperFast($p[ 6], $p[ 7], $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
list($p[10], $p[11]) = $this->_encryptBlockHelperFast($p[ 8], $p[ 9], $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
list($p[12], $p[13]) = $this->_encryptBlockHelperFast($p[10], $p[11], $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
list($p[14], $p[15]) = $this->_encryptBlockHelperFast($p[12], $p[13], $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
list($p[16], $p[17]) = $this->_encryptBlockHelperFast($p[14], $p[15], $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
list($sbox0[0], $sbox0[1]) = $this->_encryptBlockHelperFast($p[16], $p[17], $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
for ($i = 2; $i < 256; $i+= 2) {
|
||||
list($sbox0[$i], $sbox0[$i + 1]) = $this->_encryptBlockHelperFast($sbox0[$i - 2], $sbox0[$i - 1], $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
}
|
||||
|
||||
list($sbox1[0], $sbox1[1]) = $this->_encryptBlockHelperFast($sbox0[254], $sbox0[255], $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
for ($i = 2; $i < 256; $i+= 2) {
|
||||
list($sbox1[$i], $sbox1[$i + 1]) = $this->_encryptBlockHelperFast($sbox1[$i - 2], $sbox1[$i - 1], $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
}
|
||||
|
||||
list($sbox2[0], $sbox2[1]) = $this->_encryptBlockHelperFast($sbox1[254], $sbox1[255], $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
for ($i = 2; $i < 256; $i+= 2) {
|
||||
list($sbox2[$i], $sbox2[$i + 1]) = $this->_encryptBlockHelperFast($sbox2[$i - 2], $sbox2[$i - 1], $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
}
|
||||
|
||||
list($sbox3[0], $sbox3[1]) = $this->_encryptBlockHelperFast($sbox2[254], $sbox2[255], $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
for ($i = 2; $i < 256; $i+= 2) {
|
||||
list($sbox3[$i], $sbox3[$i + 1]) = $this->_encryptBlockHelperFast($sbox3[$i - 2], $sbox3[$i - 1], $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Key expansion with salt
|
||||
*
|
||||
* @access private
|
||||
* @param int[] $data
|
||||
* @param int[] $key
|
||||
* @param int[] $sbox0
|
||||
* @param int[] $sbox1
|
||||
* @param int[] $sbox2
|
||||
* @param int[] $sbox3
|
||||
* @param int[] $p
|
||||
* @see self::_bcrypt_hash()
|
||||
*/
|
||||
function _expandstate($data, $key, &$sbox0, &$sbox1, &$sbox2, &$sbox3, &$p)
|
||||
{
|
||||
$p = array(
|
||||
$p[0] ^ $key[0],
|
||||
$p[1] ^ $key[1],
|
||||
$p[2] ^ $key[2],
|
||||
$p[3] ^ $key[3],
|
||||
$p[4] ^ $key[4],
|
||||
$p[5] ^ $key[5],
|
||||
$p[6] ^ $key[6],
|
||||
$p[7] ^ $key[7],
|
||||
$p[8] ^ $key[8],
|
||||
$p[9] ^ $key[9],
|
||||
$p[10] ^ $key[10],
|
||||
$p[11] ^ $key[11],
|
||||
$p[12] ^ $key[12],
|
||||
$p[13] ^ $key[13],
|
||||
$p[14] ^ $key[14],
|
||||
$p[15] ^ $key[15],
|
||||
$p[16] ^ $key[0],
|
||||
$p[17] ^ $key[1]
|
||||
);
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
list( $p[0], $p[1]) = $this->_encryptBlockHelperFast($data[ 0] , $data[ 1] , $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
list( $p[2], $p[3]) = $this->_encryptBlockHelperFast($data[ 2] ^ $p[ 0], $data[ 3] ^ $p[ 1], $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
list( $p[4], $p[5]) = $this->_encryptBlockHelperFast($data[ 4] ^ $p[ 2], $data[ 5] ^ $p[ 3], $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
list( $p[6], $p[7]) = $this->_encryptBlockHelperFast($data[ 6] ^ $p[ 4], $data[ 7] ^ $p[ 5], $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
list( $p[8], $p[9]) = $this->_encryptBlockHelperFast($data[ 8] ^ $p[ 6], $data[ 9] ^ $p[ 7], $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
list($p[10], $p[11]) = $this->_encryptBlockHelperFast($data[10] ^ $p[ 8], $data[11] ^ $p[ 9], $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
list($p[12], $p[13]) = $this->_encryptBlockHelperFast($data[12] ^ $p[10], $data[13] ^ $p[11], $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
list($p[14], $p[15]) = $this->_encryptBlockHelperFast($data[14] ^ $p[12], $data[15] ^ $p[13], $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
list($p[16], $p[17]) = $this->_encryptBlockHelperFast($data[ 0] ^ $p[14], $data[ 1] ^ $p[15], $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
list($sbox0[0], $sbox0[1]) = $this->_encryptBlockHelperFast($data[2] ^ $p[16], $data[3] ^ $p[17], $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
for ($i = 2, $j = 4; $i < 256; $i+= 2, $j = ($j + 2) % 16) { // instead of 16 maybe count($data) would be better?
|
||||
list($sbox0[$i], $sbox0[$i + 1]) = $this->_encryptBlockHelperFast($data[$j] ^ $sbox0[$i - 2], $data[$j + 1] ^ $sbox0[$i - 1], $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
}
|
||||
|
||||
list($sbox1[0], $sbox1[1]) = $this->_encryptBlockHelperFast($data[2] ^ $sbox0[254], $data[3] ^ $sbox0[255], $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
for ($i = 2, $j = 4; $i < 256; $i+= 2, $j = ($j + 2) % 16) {
|
||||
list($sbox1[$i], $sbox1[$i + 1]) = $this->_encryptBlockHelperFast($data[$j] ^ $sbox1[$i - 2], $data[$j + 1] ^ $sbox1[$i - 1], $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
}
|
||||
|
||||
list($sbox2[0], $sbox2[1]) = $this->_encryptBlockHelperFast($data[2] ^ $sbox1[254], $data[3] ^ $sbox1[255], $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
for ($i = 2, $j = 4; $i < 256; $i+= 2, $j = ($j + 2) % 16) {
|
||||
list($sbox2[$i], $sbox2[$i + 1]) = $this->_encryptBlockHelperFast($data[$j] ^ $sbox2[$i - 2], $data[$j + 1] ^ $sbox2[$i - 1], $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
}
|
||||
|
||||
list($sbox3[0], $sbox3[1]) = $this->_encryptBlockHelperFast($data[2] ^ $sbox2[254], $data[3] ^ $sbox2[255], $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
for ($i = 2, $j = 4; $i < 256; $i+= 2, $j = ($j + 2) % 16) {
|
||||
list($sbox3[$i], $sbox3[$i + 1]) = $this->_encryptBlockHelperFast($data[$j] ^ $sbox3[$i - 2], $data[$j + 1] ^ $sbox3[$i - 1], $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Encrypts a block
|
||||
*
|
||||
|
@ -406,18 +762,83 @@ class Blowfish extends Base
|
|||
$l = $in[1];
|
||||
$r = $in[2];
|
||||
|
||||
for ($i = 0; $i < 16; $i+= 2) {
|
||||
$l^= $p[$i];
|
||||
$r^= $this->safe_intval(($this->safe_intval($sb_0[$l >> 24 & 0xff] + $sb_1[$l >> 16 & 0xff]) ^
|
||||
$sb_2[$l >> 8 & 0xff]) +
|
||||
$sb_3[$l & 0xff]);
|
||||
list($r, $l) = CRYPT_BASE_USE_REG_INTVAL ?
|
||||
$this->_encryptBlockHelperFast($l, $r, $sb_0, $sb_1, $sb_2, $sb_3, $p) :
|
||||
$this->_encryptBlockHelperSlow($l, $r, $sb_0, $sb_1, $sb_2, $sb_3, $p);
|
||||
|
||||
$r^= $p[$i + 1];
|
||||
$l^= $this->safe_intval(($this->safe_intval($sb_0[$r >> 24 & 0xff] + $sb_1[$r >> 16 & 0xff]) ^
|
||||
$sb_2[$r >> 8 & 0xff]) +
|
||||
$sb_3[$r & 0xff]);
|
||||
}
|
||||
return pack("N*", $r ^ $p[17], $l ^ $p[16]);
|
||||
return pack("N*", $r, $l);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fast helper function for block encryption
|
||||
*
|
||||
* @access private
|
||||
* @param int $x0
|
||||
* @param int $x1
|
||||
* @param int[] $sbox0
|
||||
* @param int[] $sbox1
|
||||
* @param int[] $sbox2
|
||||
* @param int[] $sbox3
|
||||
* @param int[] $p
|
||||
* @return int[]
|
||||
*/
|
||||
function _encryptBlockHelperFast($x0, $x1, $sbox0, $sbox1, $sbox2, $sbox3, $p)
|
||||
{
|
||||
$x0 ^= $p[0];
|
||||
$x1 ^= ((($sbox0[($x0 & 0xFF000000) >> 24] + $sbox1[($x0 & 0xFF0000) >> 16]) ^ $sbox2[($x0 & 0xFF00) >> 8]) + $sbox3[$x0 & 0xFF]) ^ $p[1];
|
||||
$x0 ^= ((($sbox0[($x1 & 0xFF000000) >> 24] + $sbox1[($x1 & 0xFF0000) >> 16]) ^ $sbox2[($x1 & 0xFF00) >> 8]) + $sbox3[$x1 & 0xFF]) ^ $p[2];
|
||||
$x1 ^= ((($sbox0[($x0 & 0xFF000000) >> 24] + $sbox1[($x0 & 0xFF0000) >> 16]) ^ $sbox2[($x0 & 0xFF00) >> 8]) + $sbox3[$x0 & 0xFF]) ^ $p[3];
|
||||
$x0 ^= ((($sbox0[($x1 & 0xFF000000) >> 24] + $sbox1[($x1 & 0xFF0000) >> 16]) ^ $sbox2[($x1 & 0xFF00) >> 8]) + $sbox3[$x1 & 0xFF]) ^ $p[4];
|
||||
$x1 ^= ((($sbox0[($x0 & 0xFF000000) >> 24] + $sbox1[($x0 & 0xFF0000) >> 16]) ^ $sbox2[($x0 & 0xFF00) >> 8]) + $sbox3[$x0 & 0xFF]) ^ $p[5];
|
||||
$x0 ^= ((($sbox0[($x1 & 0xFF000000) >> 24] + $sbox1[($x1 & 0xFF0000) >> 16]) ^ $sbox2[($x1 & 0xFF00) >> 8]) + $sbox3[$x1 & 0xFF]) ^ $p[6];
|
||||
$x1 ^= ((($sbox0[($x0 & 0xFF000000) >> 24] + $sbox1[($x0 & 0xFF0000) >> 16]) ^ $sbox2[($x0 & 0xFF00) >> 8]) + $sbox3[$x0 & 0xFF]) ^ $p[7];
|
||||
$x0 ^= ((($sbox0[($x1 & 0xFF000000) >> 24] + $sbox1[($x1 & 0xFF0000) >> 16]) ^ $sbox2[($x1 & 0xFF00) >> 8]) + $sbox3[$x1 & 0xFF]) ^ $p[8];
|
||||
$x1 ^= ((($sbox0[($x0 & 0xFF000000) >> 24] + $sbox1[($x0 & 0xFF0000) >> 16]) ^ $sbox2[($x0 & 0xFF00) >> 8]) + $sbox3[$x0 & 0xFF]) ^ $p[9];
|
||||
$x0 ^= ((($sbox0[($x1 & 0xFF000000) >> 24] + $sbox1[($x1 & 0xFF0000) >> 16]) ^ $sbox2[($x1 & 0xFF00) >> 8]) + $sbox3[$x1 & 0xFF]) ^ $p[10];
|
||||
$x1 ^= ((($sbox0[($x0 & 0xFF000000) >> 24] + $sbox1[($x0 & 0xFF0000) >> 16]) ^ $sbox2[($x0 & 0xFF00) >> 8]) + $sbox3[$x0 & 0xFF]) ^ $p[11];
|
||||
$x0 ^= ((($sbox0[($x1 & 0xFF000000) >> 24] + $sbox1[($x1 & 0xFF0000) >> 16]) ^ $sbox2[($x1 & 0xFF00) >> 8]) + $sbox3[$x1 & 0xFF]) ^ $p[12];
|
||||
$x1 ^= ((($sbox0[($x0 & 0xFF000000) >> 24] + $sbox1[($x0 & 0xFF0000) >> 16]) ^ $sbox2[($x0 & 0xFF00) >> 8]) + $sbox3[$x0 & 0xFF]) ^ $p[13];
|
||||
$x0 ^= ((($sbox0[($x1 & 0xFF000000) >> 24] + $sbox1[($x1 & 0xFF0000) >> 16]) ^ $sbox2[($x1 & 0xFF00) >> 8]) + $sbox3[$x1 & 0xFF]) ^ $p[14];
|
||||
$x1 ^= ((($sbox0[($x0 & 0xFF000000) >> 24] + $sbox1[($x0 & 0xFF0000) >> 16]) ^ $sbox2[($x0 & 0xFF00) >> 8]) + $sbox3[$x0 & 0xFF]) ^ $p[15];
|
||||
$x0 ^= ((($sbox0[($x1 & 0xFF000000) >> 24] + $sbox1[($x1 & 0xFF0000) >> 16]) ^ $sbox2[($x1 & 0xFF00) >> 8]) + $sbox3[$x1 & 0xFF]) ^ $p[16];
|
||||
|
||||
return array($x1 & 0xFFFFFFFF ^ $p[17], $x0 & 0xFFFFFFFF);
|
||||
}
|
||||
|
||||
/**
|
||||
* Slow helper function for block encryption
|
||||
*
|
||||
* @access private
|
||||
* @param int $x0
|
||||
* @param int $x1
|
||||
* @param int[] $sbox0
|
||||
* @param int[] $sbox1
|
||||
* @param int[] $sbox2
|
||||
* @param int[] $sbox3
|
||||
* @param int[] $p
|
||||
* @return int[]
|
||||
*/
|
||||
function _encryptBlockHelperSlow($x0, $x1, $sbox0, $sbox1, $sbox2, $sbox3, $p)
|
||||
{
|
||||
$x0^= $p[0];
|
||||
$x1^= $this->safe_intval(($this->safe_intval($sbox0[($x0 & 0xFF000000) >> 24] + $sbox1[($x0 & 0xFF0000) >> 16]) ^ $sbox2[($x0 & 0xFF00) >> 8]) + $sbox3[$x0 & 0xFF]) ^ $p[1];
|
||||
$x0^= $this->safe_intval(($this->safe_intval($sbox0[($x1 & 0xFF000000) >> 24] + $sbox1[($x1 & 0xFF0000) >> 16]) ^ $sbox2[($x1 & 0xFF00) >> 8]) + $sbox3[$x1 & 0xFF]) ^ $p[2];
|
||||
$x1^= $this->safe_intval(($this->safe_intval($sbox0[($x0 & 0xFF000000) >> 24] + $sbox1[($x0 & 0xFF0000) >> 16]) ^ $sbox2[($x0 & 0xFF00) >> 8]) + $sbox3[$x0 & 0xFF]) ^ $p[3];
|
||||
$x0^= $this->safe_intval(($this->safe_intval($sbox0[($x1 & 0xFF000000) >> 24] + $sbox1[($x1 & 0xFF0000) >> 16]) ^ $sbox2[($x1 & 0xFF00) >> 8]) + $sbox3[$x1 & 0xFF]) ^ $p[4];
|
||||
$x1^= $this->safe_intval(($this->safe_intval($sbox0[($x0 & 0xFF000000) >> 24] + $sbox1[($x0 & 0xFF0000) >> 16]) ^ $sbox2[($x0 & 0xFF00) >> 8]) + $sbox3[$x0 & 0xFF]) ^ $p[5];
|
||||
$x0^= $this->safe_intval(($this->safe_intval($sbox0[($x1 & 0xFF000000) >> 24] + $sbox1[($x1 & 0xFF0000) >> 16]) ^ $sbox2[($x1 & 0xFF00) >> 8]) + $sbox3[$x1 & 0xFF]) ^ $p[6];
|
||||
$x1^= $this->safe_intval(($this->safe_intval($sbox0[($x0 & 0xFF000000) >> 24] + $sbox1[($x0 & 0xFF0000) >> 16]) ^ $sbox2[($x0 & 0xFF00) >> 8]) + $sbox3[$x0 & 0xFF]) ^ $p[7];
|
||||
$x0^= $this->safe_intval(($this->safe_intval($sbox0[($x1 & 0xFF000000) >> 24] + $sbox1[($x1 & 0xFF0000) >> 16]) ^ $sbox2[($x1 & 0xFF00) >> 8]) + $sbox3[$x1 & 0xFF]) ^ $p[8];
|
||||
$x1^= $this->safe_intval(($this->safe_intval($sbox0[($x0 & 0xFF000000) >> 24] + $sbox1[($x0 & 0xFF0000) >> 16]) ^ $sbox2[($x0 & 0xFF00) >> 8]) + $sbox3[$x0 & 0xFF]) ^ $p[9];
|
||||
$x0^= $this->safe_intval(($this->safe_intval($sbox0[($x1 & 0xFF000000) >> 24] + $sbox1[($x1 & 0xFF0000) >> 16]) ^ $sbox2[($x1 & 0xFF00) >> 8]) + $sbox3[$x1 & 0xFF]) ^ $p[10];
|
||||
$x1^= $this->safe_intval(($this->safe_intval($sbox0[($x0 & 0xFF000000) >> 24] + $sbox1[($x0 & 0xFF0000) >> 16]) ^ $sbox2[($x0 & 0xFF00) >> 8]) + $sbox3[$x0 & 0xFF]) ^ $p[11];
|
||||
$x0^= $this->safe_intval(($this->safe_intval($sbox0[($x1 & 0xFF000000) >> 24] + $sbox1[($x1 & 0xFF0000) >> 16]) ^ $sbox2[($x1 & 0xFF00) >> 8]) + $sbox3[$x1 & 0xFF]) ^ $p[12];
|
||||
$x1^= $this->safe_intval(($this->safe_intval($sbox0[($x0 & 0xFF000000) >> 24] + $sbox1[($x0 & 0xFF0000) >> 16]) ^ $sbox2[($x0 & 0xFF00) >> 8]) + $sbox3[$x0 & 0xFF]) ^ $p[13];
|
||||
$x0^= $this->safe_intval(($this->safe_intval($sbox0[($x1 & 0xFF000000) >> 24] + $sbox1[($x1 & 0xFF0000) >> 16]) ^ $sbox2[($x1 & 0xFF00) >> 8]) + $sbox3[$x1 & 0xFF]) ^ $p[14];
|
||||
$x1^= $this->safe_intval(($this->safe_intval($sbox0[($x0 & 0xFF000000) >> 24] + $sbox1[($x0 & 0xFF0000) >> 16]) ^ $sbox2[($x0 & 0xFF00) >> 8]) + $sbox3[$x0 & 0xFF]) ^ $p[15];
|
||||
$x0^= $this->safe_intval(($this->safe_intval($sbox0[($x1 & 0xFF000000) >> 24] + $sbox1[($x1 & 0xFF0000) >> 16]) ^ $sbox2[($x1 & 0xFF00) >> 8]) + $sbox3[$x1 & 0xFF]) ^ $p[16];
|
||||
|
||||
return array($x1 & 0xFFFFFFFF ^ $p[17], $x0 & 0xFFFFFFFF);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -592,6 +592,12 @@ class DES extends Base
|
|||
{
|
||||
if ($this->key_length_max == 8) {
|
||||
if ($engine == self::ENGINE_OPENSSL) {
|
||||
// quoting https://www.openssl.org/news/openssl-3.0-notes.html, OpenSSL 3.0.1
|
||||
// "Moved all variations of the EVP ciphers CAST5, BF, IDEA, SEED, RC2, RC4, RC5, and DES to the legacy provider"
|
||||
// in theory openssl_get_cipher_methods() should catch this but, on GitHub Actions, at least, it does not
|
||||
if (version_compare(preg_replace('#OpenSSL (\d+\.\d+\.\d+) .*#', '$1', OPENSSL_VERSION_TEXT), '3.0.1', '>=')) {
|
||||
return false;
|
||||
}
|
||||
$this->cipher_name_openssl_ecb = 'des-ecb';
|
||||
$this->cipher_name_openssl = 'des-' . $this->_openssl_translate_mode();
|
||||
}
|
||||
|
@ -1246,9 +1252,9 @@ class DES extends Base
|
|||
$pc2mapd3[($d >> 8) & 0xFF] | $pc2mapd4[ $d & 0xFF];
|
||||
|
||||
// Reorder: odd bytes/even bytes. Push the result in key schedule.
|
||||
$val1 = ( $cp & 0xFF000000) | (($cp << 8) & 0x00FF0000) |
|
||||
$val1 = ( $cp & intval(0xFF000000)) | (($cp << 8) & 0x00FF0000) |
|
||||
(($dp >> 16) & 0x0000FF00) | (($dp >> 8) & 0x000000FF);
|
||||
$val2 = (($cp << 8) & 0xFF000000) | (($cp << 16) & 0x00FF0000) |
|
||||
$val2 = (($cp << 8) & intval(0xFF000000)) | (($cp << 16) & 0x00FF0000) |
|
||||
(($dp >> 8) & 0x0000FF00) | ( $dp & 0x000000FF);
|
||||
$keys[$des_round][self::ENCRYPT][ ] = $val1;
|
||||
$keys[$des_round][self::DECRYPT][$ki - 1] = $val1;
|
||||
|
|
|
@ -72,7 +72,7 @@ class RC2 extends Base
|
|||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $orig_key;
|
||||
var $orig_key = '';
|
||||
|
||||
/**
|
||||
* Don't truncate / null pad key
|
||||
|
@ -273,6 +273,12 @@ class RC2 extends Base
|
|||
{
|
||||
switch ($engine) {
|
||||
case self::ENGINE_OPENSSL:
|
||||
// quoting https://www.openssl.org/news/openssl-3.0-notes.html, OpenSSL 3.0.1
|
||||
// "Moved all variations of the EVP ciphers CAST5, BF, IDEA, SEED, RC2, RC4, RC5, and DES to the legacy provider"
|
||||
// in theory openssl_get_cipher_methods() should catch this but, on GitHub Actions, at least, it does not
|
||||
if (version_compare(preg_replace('#OpenSSL (\d+\.\d+\.\d+) .*#', '$1', OPENSSL_VERSION_TEXT), '3.0.1', '>=')) {
|
||||
return false;
|
||||
}
|
||||
if ($this->current_key_length != 128 || strlen($this->orig_key) < 16) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -144,7 +144,13 @@ class RC4 extends Base
|
|||
*/
|
||||
function isValidEngine($engine)
|
||||
{
|
||||
if ($engine == Base::ENGINE_OPENSSL) {
|
||||
if ($engine == self::ENGINE_OPENSSL) {
|
||||
// quoting https://www.openssl.org/news/openssl-3.0-notes.html, OpenSSL 3.0.1
|
||||
// "Moved all variations of the EVP ciphers CAST5, BF, IDEA, SEED, RC2, RC4, RC5, and DES to the legacy provider"
|
||||
// in theory openssl_get_cipher_methods() should catch this but, on GitHub Actions, at least, it does not
|
||||
if (version_compare(preg_replace('#OpenSSL (\d+\.\d+\.\d+) .*#', '$1', OPENSSL_VERSION_TEXT), '3.0.1', '>=')) {
|
||||
return false;
|
||||
}
|
||||
if (version_compare(PHP_VERSION, '5.3.7') >= 0) {
|
||||
$this->cipher_name_openssl = 'rc4-40';
|
||||
} else {
|
||||
|
@ -222,7 +228,7 @@ class RC4 extends Base
|
|||
*/
|
||||
function encrypt($plaintext)
|
||||
{
|
||||
if ($this->engine != Base::ENGINE_INTERNAL) {
|
||||
if ($this->engine != self::ENGINE_INTERNAL) {
|
||||
return parent::encrypt($plaintext);
|
||||
}
|
||||
return $this->_crypt($plaintext, self::ENCRYPT);
|
||||
|
@ -242,7 +248,7 @@ class RC4 extends Base
|
|||
*/
|
||||
function decrypt($ciphertext)
|
||||
{
|
||||
if ($this->engine != Base::ENGINE_INTERNAL) {
|
||||
if ($this->engine != self::ENGINE_INTERNAL) {
|
||||
return parent::decrypt($ciphertext);
|
||||
}
|
||||
return $this->_crypt($ciphertext, self::DECRYPT);
|
||||
|
|
|
@ -470,7 +470,7 @@ class RSA
|
|||
case defined('MATH_BIGINTEGER_OPENSSL_DISABLE'):
|
||||
define('CRYPT_RSA_MODE', self::MODE_INTERNAL);
|
||||
break;
|
||||
case extension_loaded('openssl') && file_exists($this->configFile):
|
||||
case function_exists('phpinfo') && extension_loaded('openssl') && file_exists($this->configFile):
|
||||
// some versions of XAMPP have mismatched versions of OpenSSL which causes it not to work
|
||||
$versions = array();
|
||||
|
||||
|
@ -878,9 +878,9 @@ class RSA
|
|||
);
|
||||
$key = "openssh-key-v1\0$key";
|
||||
|
||||
return "-----BEGIN OPENSSH PRIVATE KEY-----\r\n" .
|
||||
chunk_split(base64_encode($key), 70) .
|
||||
"-----END OPENSSH PRIVATE KEY-----";
|
||||
return "-----BEGIN OPENSSH PRIVATE KEY-----\n" .
|
||||
chunk_split(base64_encode($key), 70, "\n") .
|
||||
"-----END OPENSSH PRIVATE KEY-----\n";
|
||||
default: // eg. self::PRIVATE_FORMAT_PKCS1
|
||||
$components = array();
|
||||
foreach ($raw as $name => $value) {
|
||||
|
@ -1388,6 +1388,10 @@ class RSA
|
|||
// http://en.wikipedia.org/wiki/XML_Signature
|
||||
case self::PRIVATE_FORMAT_XML:
|
||||
case self::PUBLIC_FORMAT_XML:
|
||||
if (!extension_loaded('xml')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->components = array();
|
||||
|
||||
$xml = xml_parser_create('UTF-8');
|
||||
|
@ -1405,11 +1409,18 @@ class RSA
|
|||
unset($xml);
|
||||
|
||||
return isset($this->components['modulus']) && isset($this->components['publicExponent']) ? $this->components : false;
|
||||
// from PuTTY's SSHPUBK.C
|
||||
// see PuTTY's SSHPUBK.C and https://tartarus.org/~simon/putty-snapshots/htmldoc/AppendixC.html
|
||||
case self::PRIVATE_FORMAT_PUTTY:
|
||||
$components = array();
|
||||
$key = preg_split('#\r\n|\r|\n#', $key);
|
||||
$type = trim(preg_replace('#PuTTY-User-Key-File-2: (.+)#', '$1', $key[0]));
|
||||
if ($this->_string_shift($key[0], strlen('PuTTY-User-Key-File-')) != 'PuTTY-User-Key-File-') {
|
||||
return false;
|
||||
}
|
||||
$version = (int) $this->_string_shift($key[0], 3); // should be either "2: " or "3: 0" prior to int casting
|
||||
if ($version != 2 && $version != 3) {
|
||||
return false;
|
||||
}
|
||||
$type = rtrim($key[0]);
|
||||
if ($type != 'ssh-rsa') {
|
||||
return false;
|
||||
}
|
||||
|
@ -1424,23 +1435,55 @@ class RSA
|
|||
extract(unpack('Nlength', $this->_string_shift($public, 4)));
|
||||
$components['modulus'] = new BigInteger($this->_string_shift($public, $length), -256);
|
||||
|
||||
$privateLength = trim(preg_replace('#Private-Lines: (\d+)#', '$1', $key[$publicLength + 4]));
|
||||
$private = base64_decode(implode('', array_map('trim', array_slice($key, $publicLength + 5, $privateLength))));
|
||||
|
||||
$offset = $publicLength + 4;
|
||||
switch ($encryption) {
|
||||
case 'aes256-cbc':
|
||||
$symkey = '';
|
||||
$sequence = 0;
|
||||
while (strlen($symkey) < 32) {
|
||||
$temp = pack('Na*', $sequence++, $this->password);
|
||||
$symkey.= pack('H*', sha1($temp));
|
||||
}
|
||||
$symkey = substr($symkey, 0, 32);
|
||||
$crypto = new AES();
|
||||
switch ($version) {
|
||||
case 3:
|
||||
if (!function_exists('sodium_crypto_pwhash')) {
|
||||
return false;
|
||||
}
|
||||
$flavour = trim(preg_replace('#Key-Derivation: (.*)#', '$1', $key[$offset++]));
|
||||
switch ($flavour) {
|
||||
case 'Argon2i':
|
||||
$flavour = SODIUM_CRYPTO_PWHASH_ALG_ARGON2I13;
|
||||
break;
|
||||
case 'Argon2id':
|
||||
$flavour = SODIUM_CRYPTO_PWHASH_ALG_ARGON2ID13;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
$memory = trim(preg_replace('#Argon2-Memory: (\d+)#', '$1', $key[$offset++]));
|
||||
$passes = trim(preg_replace('#Argon2-Passes: (\d+)#', '$1', $key[$offset++]));
|
||||
$parallelism = trim(preg_replace('#Argon2-Parallelism: (\d+)#', '$1', $key[$offset++]));
|
||||
$salt = pack('H*', trim(preg_replace('#Argon2-Salt: ([0-9a-f]+)#', '$1', $key[$offset++])));
|
||||
|
||||
$length = 80; // keylen + ivlen + mac_keylen
|
||||
$temp = sodium_crypto_pwhash($length, $this->password, $salt, $passes, $memory << 10, $flavour);
|
||||
|
||||
$symkey = substr($temp, 0, 32);
|
||||
$symiv = substr($temp, 32, 16);
|
||||
break;
|
||||
case 2:
|
||||
$symkey = '';
|
||||
$sequence = 0;
|
||||
while (strlen($symkey) < 32) {
|
||||
$temp = pack('Na*', $sequence++, $this->password);
|
||||
$symkey.= pack('H*', sha1($temp));
|
||||
}
|
||||
$symkey = substr($symkey, 0, 32);
|
||||
$symiv = str_repeat("\0", 16);
|
||||
}
|
||||
}
|
||||
|
||||
$privateLength = trim(preg_replace('#Private-Lines: (\d+)#', '$1', $key[$offset++]));
|
||||
$private = base64_decode(implode('', array_map('trim', array_slice($key, $offset, $privateLength))));
|
||||
|
||||
if ($encryption != 'none') {
|
||||
$crypto->setKey($symkey);
|
||||
$crypto->setIV($symiv);
|
||||
$crypto->disablePadding();
|
||||
$private = $crypto->decrypt($private);
|
||||
if ($private === false) {
|
||||
|
@ -1483,14 +1526,44 @@ class RSA
|
|||
if ($magic !== "openssh-key-v1\0") {
|
||||
return false;
|
||||
}
|
||||
$options = $this->_string_shift($decoded, 24);
|
||||
// \0\0\0\4none = ciphername
|
||||
// \0\0\0\4none = kdfname
|
||||
// \0\0\0\0 = kdfoptions
|
||||
// \0\0\0\1 = numkeys
|
||||
if ($options != "\0\0\0\4none\0\0\0\4none\0\0\0\0\0\0\0\1") {
|
||||
extract(unpack('Nlength', $this->_string_shift($decoded, 4)));
|
||||
if (strlen($decoded) < $length) {
|
||||
return false;
|
||||
}
|
||||
$ciphername = $this->_string_shift($decoded, $length);
|
||||
extract(unpack('Nlength', $this->_string_shift($decoded, 4)));
|
||||
if (strlen($decoded) < $length) {
|
||||
return false;
|
||||
}
|
||||
$kdfname = $this->_string_shift($decoded, $length);
|
||||
extract(unpack('Nlength', $this->_string_shift($decoded, 4)));
|
||||
if (strlen($decoded) < $length) {
|
||||
return false;
|
||||
}
|
||||
$kdfoptions = $this->_string_shift($decoded, $length);
|
||||
extract(unpack('Nnumkeys', $this->_string_shift($decoded, 4)));
|
||||
if ($numkeys != 1 || ($ciphername != 'none' && $kdfname != 'bcrypt')) {
|
||||
return false;
|
||||
}
|
||||
switch ($ciphername) {
|
||||
case 'none':
|
||||
break;
|
||||
case 'aes256-ctr':
|
||||
extract(unpack('Nlength', $this->_string_shift($kdfoptions, 4)));
|
||||
if (strlen($kdfoptions) < $length) {
|
||||
return false;
|
||||
}
|
||||
$salt = $this->_string_shift($kdfoptions, $length);
|
||||
extract(unpack('Nrounds', $this->_string_shift($kdfoptions, 4)));
|
||||
$crypto = new AES(AES::MODE_CTR);
|
||||
$crypto->disablePadding();
|
||||
if (!$crypto->setPassword($this->password, 'bcrypt', $salt, $rounds, 32)) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
extract(unpack('Nlength', $this->_string_shift($decoded, 4)));
|
||||
if (strlen($decoded) < $length) {
|
||||
return false;
|
||||
|
@ -1500,12 +1573,16 @@ class RSA
|
|||
if (strlen($decoded) < $length) {
|
||||
return false;
|
||||
}
|
||||
$paddedKey = $this->_string_shift($decoded, $length);
|
||||
|
||||
if ($this->_string_shift($publicKey, 11) !== "\0\0\0\7ssh-rsa") {
|
||||
return false;
|
||||
}
|
||||
|
||||
$paddedKey = $this->_string_shift($decoded, $length);
|
||||
if (isset($crypto)) {
|
||||
$paddedKey = $crypto->decrypt($paddedKey);
|
||||
}
|
||||
|
||||
$checkint1 = $this->_string_shift($paddedKey, 4);
|
||||
$checkint2 = $this->_string_shift($paddedKey, 4);
|
||||
if (strlen($checkint1) != 4 || $checkint1 !== $checkint2) {
|
||||
|
@ -2580,9 +2657,9 @@ class RSA
|
|||
$offset+= $patternMatch ? 0 : 1;
|
||||
}
|
||||
|
||||
// we do & instead of && to avoid https://en.wikipedia.org/wiki/Short-circuit_evaluation
|
||||
// we do | instead of || to avoid https://en.wikipedia.org/wiki/Short-circuit_evaluation
|
||||
// to protect against timing attacks
|
||||
if (!$hashesMatch & !$patternMatch) {
|
||||
if (!$hashesMatch | !$patternMatch) {
|
||||
user_error('Decryption error');
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -151,7 +151,10 @@ class Random
|
|||
(isset($_POST) ? phpseclib_safe_serialize($_POST) : '') .
|
||||
(isset($_GET) ? phpseclib_safe_serialize($_GET) : '') .
|
||||
(isset($_COOKIE) ? phpseclib_safe_serialize($_COOKIE) : '') .
|
||||
phpseclib_safe_serialize($GLOBALS) .
|
||||
// as of PHP 8.1 $GLOBALS can't be accessed by reference, which eliminates
|
||||
// the need for phpseclib_safe_serialize. see https://wiki.php.net/rfc/restrict_globals_usage
|
||||
// for more info
|
||||
(version_compare(PHP_VERSION, '8.1.0', '>=') ? serialize($GLOBALS) : phpseclib_safe_serialize($GLOBALS)) .
|
||||
phpseclib_safe_serialize($_SESSION) .
|
||||
phpseclib_safe_serialize($_OLD_SESSION)
|
||||
));
|
||||
|
|
|
@ -340,7 +340,7 @@ class Rijndael extends Base
|
|||
$k = $c[2];
|
||||
$l = $c[3];
|
||||
while ($i < $Nb) {
|
||||
$temp[$i] = ($state[$i] & 0xFF000000) ^
|
||||
$temp[$i] = ($state[$i] & intval(0xFF000000)) ^
|
||||
($state[$j] & 0x00FF0000) ^
|
||||
($state[$k] & 0x0000FF00) ^
|
||||
($state[$l] & 0x000000FF) ^
|
||||
|
@ -426,7 +426,7 @@ class Rijndael extends Base
|
|||
$l = $Nb - $c[3];
|
||||
|
||||
while ($i < $Nb) {
|
||||
$word = ($state[$i] & 0xFF000000) |
|
||||
$word = ($state[$i] & intval(0xFF000000)) |
|
||||
($state[$j] & 0x00FF0000) |
|
||||
($state[$k] & 0x0000FF00) |
|
||||
($state[$l] & 0x000000FF);
|
||||
|
@ -465,14 +465,19 @@ class Rijndael extends Base
|
|||
{
|
||||
// Each number in $rcon is equal to the previous number multiplied by two in Rijndael's finite field.
|
||||
// See http://en.wikipedia.org/wiki/Finite_field_arithmetic#Multiplicative_inverse
|
||||
static $rcon = array(0,
|
||||
0x01000000, 0x02000000, 0x04000000, 0x08000000, 0x10000000,
|
||||
0x20000000, 0x40000000, 0x80000000, 0x1B000000, 0x36000000,
|
||||
0x6C000000, 0xD8000000, 0xAB000000, 0x4D000000, 0x9A000000,
|
||||
0x2F000000, 0x5E000000, 0xBC000000, 0x63000000, 0xC6000000,
|
||||
0x97000000, 0x35000000, 0x6A000000, 0xD4000000, 0xB3000000,
|
||||
0x7D000000, 0xFA000000, 0xEF000000, 0xC5000000, 0x91000000
|
||||
);
|
||||
static $rcon;
|
||||
|
||||
if (!isset($rcon)) {
|
||||
$rcon = array(0,
|
||||
0x01000000, 0x02000000, 0x04000000, 0x08000000, 0x10000000,
|
||||
0x20000000, 0x40000000, 0x80000000, 0x1B000000, 0x36000000,
|
||||
0x6C000000, 0xD8000000, 0xAB000000, 0x4D000000, 0x9A000000,
|
||||
0x2F000000, 0x5E000000, 0xBC000000, 0x63000000, 0xC6000000,
|
||||
0x97000000, 0x35000000, 0x6A000000, 0xD4000000, 0xB3000000,
|
||||
0x7D000000, 0xFA000000, 0xEF000000, 0xC5000000, 0x91000000
|
||||
);
|
||||
$rcon = array_map('intval', $rcon);
|
||||
}
|
||||
|
||||
if (isset($this->kl['key']) && $this->key === $this->kl['key'] && $this->key_length === $this->kl['key_length'] && $this->block_size === $this->kl['block_size']) {
|
||||
// already expanded
|
||||
|
@ -511,7 +516,7 @@ class Rijndael extends Base
|
|||
// on a 32-bit machine, it's 32-bits, and on a 64-bit machine, it's 64-bits. on a 32-bit machine,
|
||||
// 0xFFFFFFFF << 8 == 0xFFFFFF00, but on a 64-bit machine, it equals 0xFFFFFFFF00. as such, doing 'and'
|
||||
// with 0xFFFFFFFF (or 0xFFFFFF00) on a 32-bit machine is unnecessary, but on a 64-bit machine, it is.
|
||||
$temp = (($temp << 8) & 0xFFFFFF00) | (($temp >> 24) & 0x000000FF); // rotWord
|
||||
$temp = (($temp << 8) & intval(0xFFFFFF00)) | (($temp >> 24) & 0x000000FF); // rotWord
|
||||
$temp = $this->_subWord($temp) ^ $rcon[$i / $this->Nk];
|
||||
} elseif ($this->Nk > 6 && $i % $this->Nk == 4) {
|
||||
$temp = $this->_subWord($temp);
|
||||
|
@ -641,9 +646,9 @@ class Rijndael extends Base
|
|||
));
|
||||
|
||||
foreach ($t3 as $t3i) {
|
||||
$t0[] = (($t3i << 24) & 0xFF000000) | (($t3i >> 8) & 0x00FFFFFF);
|
||||
$t1[] = (($t3i << 16) & 0xFFFF0000) | (($t3i >> 16) & 0x0000FFFF);
|
||||
$t2[] = (($t3i << 8) & 0xFFFFFF00) | (($t3i >> 24) & 0x000000FF);
|
||||
$t0[] = (($t3i << 24) & intval(0xFF000000)) | (($t3i >> 8) & 0x00FFFFFF);
|
||||
$t1[] = (($t3i << 16) & intval(0xFFFF0000)) | (($t3i >> 16) & 0x0000FFFF);
|
||||
$t2[] = (($t3i << 8) & intval(0xFFFFFF00)) | (($t3i >> 24) & 0x000000FF);
|
||||
}
|
||||
|
||||
$tables = array(
|
||||
|
@ -725,9 +730,9 @@ class Rijndael extends Base
|
|||
));
|
||||
|
||||
foreach ($dt3 as $dt3i) {
|
||||
$dt0[] = (($dt3i << 24) & 0xFF000000) | (($dt3i >> 8) & 0x00FFFFFF);
|
||||
$dt1[] = (($dt3i << 16) & 0xFFFF0000) | (($dt3i >> 16) & 0x0000FFFF);
|
||||
$dt2[] = (($dt3i << 8) & 0xFFFFFF00) | (($dt3i >> 24) & 0x000000FF);
|
||||
$dt0[] = (($dt3i << 24) & intval(0xFF000000)) | (($dt3i >> 8) & 0x00FFFFFF);
|
||||
$dt1[] = (($dt3i << 16) & intval(0xFFFF0000)) | (($dt3i >> 16) & 0x0000FFFF);
|
||||
$dt2[] = (($dt3i << 8) & intval(0xFFFFFF00)) | (($dt3i >> 24) & 0x000000FF);
|
||||
};
|
||||
|
||||
$tables = array(
|
||||
|
|
|
@ -57,7 +57,7 @@ class TripleDES extends DES
|
|||
*
|
||||
* Outer chaining is used by SSH-2 and when the mode is set to \phpseclib\Crypt\Base::MODE_CBC.
|
||||
*/
|
||||
const MODE_CBC3 = Base::MODE_CBC;
|
||||
const MODE_CBC3 = self::MODE_CBC;
|
||||
|
||||
/**
|
||||
* Key Length (in bytes)
|
||||
|
@ -151,20 +151,20 @@ class TripleDES extends DES
|
|||
* @param int $mode
|
||||
* @access public
|
||||
*/
|
||||
function __construct($mode = Base::MODE_CBC)
|
||||
function __construct($mode = self::MODE_CBC)
|
||||
{
|
||||
switch ($mode) {
|
||||
// In case of self::MODE_3CBC, we init as CRYPT_DES_MODE_CBC
|
||||
// and additional flag us internally as 3CBC
|
||||
case self::MODE_3CBC:
|
||||
parent::__construct(Base::MODE_CBC);
|
||||
parent::__construct(self::MODE_CBC);
|
||||
$this->mode_3cbc = true;
|
||||
|
||||
// This three $des'es will do the 3CBC work (if $key > 64bits)
|
||||
$this->des = array(
|
||||
new DES(Base::MODE_CBC),
|
||||
new DES(Base::MODE_CBC),
|
||||
new DES(Base::MODE_CBC),
|
||||
new DES(self::MODE_CBC),
|
||||
new DES(self::MODE_CBC),
|
||||
new DES(self::MODE_CBC),
|
||||
);
|
||||
|
||||
// we're going to be doing the padding, ourselves, so disable it in the \phpseclib\Crypt\DES objects
|
||||
|
|
|
@ -368,6 +368,42 @@ class Twofish extends Base
|
|||
*/
|
||||
var $key_length = 16;
|
||||
|
||||
/**
|
||||
* Default Constructor.
|
||||
*
|
||||
* Determines whether or not the mcrypt extension should be used.
|
||||
*
|
||||
* $mode could be:
|
||||
*
|
||||
* - CRYPT_MODE_ECB
|
||||
*
|
||||
* - CRYPT_MODE_CBC
|
||||
*
|
||||
* - CRYPT_MODE_CTR
|
||||
*
|
||||
* - CRYPT_MODE_CFB
|
||||
*
|
||||
* - CRYPT_MODE_OFB
|
||||
*
|
||||
* (or the alias constants of the chosen cipher, for example for AES: CRYPT_AES_MODE_ECB or CRYPT_AES_MODE_CBC ...)
|
||||
*
|
||||
* If not explicitly set, CRYPT_MODE_CBC will be used.
|
||||
*
|
||||
* @param int $mode
|
||||
* @access public
|
||||
*/
|
||||
function __construct($mode = self::MODE_CBC)
|
||||
{
|
||||
parent::__construct($mode);
|
||||
|
||||
$this->m0 = array_map('intval', $this->m0);
|
||||
$this->m1 = array_map('intval', $this->m1);
|
||||
$this->m2 = array_map('intval', $this->m2);
|
||||
$this->m3 = array_map('intval', $this->m3);
|
||||
$this->q0 = array_map('intval', $this->q0);
|
||||
$this->q1 = array_map('intval', $this->q1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the key length.
|
||||
*
|
||||
|
|
|
@ -143,6 +143,16 @@ class ASN1
|
|||
*/
|
||||
var $filters;
|
||||
|
||||
/**
|
||||
* Current Location of most recent ASN.1 encode process
|
||||
*
|
||||
* Useful for debug purposes
|
||||
*
|
||||
* @var array
|
||||
* @see self::encode_der()
|
||||
*/
|
||||
var $location;
|
||||
|
||||
/**
|
||||
* Type mapping table for the ANY type.
|
||||
*
|
||||
|
@ -234,6 +244,9 @@ class ASN1
|
|||
{
|
||||
$current = array('start' => $start);
|
||||
|
||||
if (!isset($encoded[$encoded_pos])) {
|
||||
return false;
|
||||
}
|
||||
$type = ord($encoded[$encoded_pos++]);
|
||||
$startOffset = 1;
|
||||
|
||||
|
@ -244,6 +257,9 @@ class ASN1
|
|||
$tag = 0;
|
||||
// process septets (since the eighth bit is ignored, it's not an octet)
|
||||
do {
|
||||
if (!isset($encoded[$encoded_pos])) {
|
||||
return false;
|
||||
}
|
||||
$temp = ord($encoded[$encoded_pos++]);
|
||||
$startOffset++;
|
||||
$loop = $temp >> 7;
|
||||
|
@ -260,6 +276,9 @@ class ASN1
|
|||
$start+= $startOffset;
|
||||
|
||||
// Length, as discussed in paragraph 8.1.3 of X.690-0207.pdf#page=13
|
||||
if (!isset($encoded[$encoded_pos])) {
|
||||
return false;
|
||||
}
|
||||
$length = ord($encoded[$encoded_pos++]);
|
||||
$start++;
|
||||
if ($length == 0x80) { // indefinite length
|
||||
|
@ -993,7 +1012,10 @@ class ASN1
|
|||
case self::TYPE_GENERALIZED_TIME:
|
||||
$format = $mapping['type'] == self::TYPE_UTC_TIME ? 'y' : 'Y';
|
||||
$format.= 'mdHis';
|
||||
// if $source does _not_ include timezone information within it then assume that the timezone is GMT
|
||||
$date = new DateTime($source, new DateTimeZone('GMT'));
|
||||
// if $source _does_ include timezone information within it then convert the time to GMT
|
||||
$date->setTimezone(new DateTimeZone('GMT'));
|
||||
$value = $date->format($format) . 'Z';
|
||||
break;
|
||||
case self::TYPE_BIT_STRING:
|
||||
|
|
|
@ -145,6 +145,7 @@ class X509
|
|||
var $AuthorityKeyIdentifier;
|
||||
var $CertificatePolicies;
|
||||
var $AuthorityInfoAccessSyntax;
|
||||
var $SubjectInfoAccessSyntax;
|
||||
var $SubjectAltName;
|
||||
var $SubjectDirectoryAttributes;
|
||||
var $PrivateKeyUsagePeriod;
|
||||
|
@ -1622,7 +1623,6 @@ class X509
|
|||
$id = $extensions[$i]['extnId'];
|
||||
$value = &$extensions[$i]['extnValue'];
|
||||
$value = base64_decode($value);
|
||||
$decoded = $asn1->decodeBER($value);
|
||||
/* [extnValue] contains the DER encoding of an ASN.1 value
|
||||
corresponding to the extension type identified by extnID */
|
||||
$map = $this->_getMapping($id);
|
||||
|
@ -1630,6 +1630,7 @@ class X509
|
|||
$decoder = $id == 'id-ce-nameConstraints' ?
|
||||
array($this, '_decodeNameConstraintIP') :
|
||||
array($this, '_decodeIP');
|
||||
$decoded = $asn1->decodeBER($value);
|
||||
$mapped = $asn1->asn1map($decoded[0], $map, array('iPAddress' => $decoder));
|
||||
$value = $mapped === false ? $decoded[0] : $mapped;
|
||||
|
||||
|
@ -2163,7 +2164,11 @@ class X509
|
|||
if (!$fsock) {
|
||||
return false;
|
||||
}
|
||||
fputs($fsock, "GET $parts[path] HTTP/1.0\r\n");
|
||||
$path = $parts['path'];
|
||||
if (isset($parts['query'])) {
|
||||
$path.= '?' . $parts['query'];
|
||||
}
|
||||
fputs($fsock, "GET $path HTTP/1.0\r\n");
|
||||
fputs($fsock, "Host: $parts[host]\r\n\r\n");
|
||||
$line = fgets($fsock, 1024);
|
||||
if (strlen($line) < 3) {
|
||||
|
@ -5058,7 +5063,7 @@ class X509
|
|||
$temp = $str;
|
||||
} else {
|
||||
$temp = preg_replace('#.*?^-+[^-]+-+[\r\n ]*$#ms', '', $str, 1);
|
||||
$temp = preg_replace('#-+END.*[\r\n ]*.*#ms', '', $str, 1);
|
||||
$temp = preg_replace('#-+END.*[\r\n ]*.*#ms', '', $temp, 1);
|
||||
}
|
||||
// remove new lines
|
||||
$temp = str_replace(array("\r", "\n", ' '), '', $temp);
|
||||
|
|
|
@ -268,7 +268,7 @@ class BigInteger
|
|||
$versions = array();
|
||||
|
||||
// avoid generating errors (even with suppression) when phpinfo() is disabled (common in production systems)
|
||||
if (strpos(ini_get('disable_functions'), 'phpinfo') === false) {
|
||||
if (function_exists('phpinfo')) {
|
||||
ob_start();
|
||||
@phpinfo();
|
||||
$content = ob_get_contents();
|
||||
|
@ -372,7 +372,7 @@ class BigInteger
|
|||
break;
|
||||
case self::MODE_BCMATH:
|
||||
// round $len to the nearest 4 (thanks, DavidMJ!)
|
||||
$len = (strlen($x) + 3) & 0xFFFFFFFC;
|
||||
$len = (strlen($x) + 3) & ~3;
|
||||
|
||||
$x = str_pad($x, $len, chr(0), STR_PAD_LEFT);
|
||||
|
||||
|
|
|
@ -247,6 +247,13 @@ class SCP
|
|||
$content = '';
|
||||
while ($size < $info['size']) {
|
||||
$data = $this->_receive();
|
||||
|
||||
// Terminate the loop in case the server repeatedly sends an empty response
|
||||
if ($data === false) {
|
||||
user_error('No data received from server', E_USER_NOTICE);
|
||||
return false;
|
||||
}
|
||||
|
||||
// SCP usually seems to split stuff out into 16k chunks
|
||||
$size+= strlen($data);
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -205,6 +205,10 @@ class SSH1
|
|||
* Dumps the content real-time to a file
|
||||
*/
|
||||
const LOG_REALTIME_FILE = 4;
|
||||
/**
|
||||
* Make sure that the log never gets larger than this
|
||||
*/
|
||||
const LOG_MAX_SIZE = 1048576; // 1024 * 1024
|
||||
/**#@-*/
|
||||
|
||||
/**#@+
|
||||
|
@ -360,7 +364,7 @@ class SSH1
|
|||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $protocol_flag_log = array();
|
||||
var $protocol_flags_log = array();
|
||||
|
||||
/**
|
||||
* Message Log
|
||||
|
@ -407,6 +411,18 @@ class SSH1
|
|||
*/
|
||||
var $interactiveBuffer = '';
|
||||
|
||||
/**
|
||||
* Current log size
|
||||
*
|
||||
* Should never exceed self::LOG_MAX_SIZE
|
||||
*
|
||||
* @see self::_send_binary_packet()
|
||||
* @see self::_get_binary_packet()
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $log_size;
|
||||
|
||||
/**
|
||||
* Timeout
|
||||
*
|
||||
|
@ -1418,7 +1434,7 @@ class SSH1
|
|||
|
||||
switch (NET_SSH1_LOGGING) {
|
||||
case self::LOG_SIMPLE:
|
||||
return $this->message_number_log;
|
||||
return $this->protocol_flags_log;
|
||||
break;
|
||||
case self::LOG_COMPLEX:
|
||||
return $this->_format_log($this->message_log, $this->protocol_flags_log);
|
||||
|
|
|
@ -70,6 +70,25 @@ use phpseclib\System\SSH\Agent;
|
|||
*/
|
||||
class SSH2
|
||||
{
|
||||
/**#@+
|
||||
* Compression Types
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
/**
|
||||
* No compression
|
||||
*/
|
||||
const NET_SSH2_COMPRESSION_NONE = 1;
|
||||
/**
|
||||
* zlib compression
|
||||
*/
|
||||
const NET_SSH2_COMPRESSION_ZLIB = 2;
|
||||
/**
|
||||
* zlib@openssh.com
|
||||
*/
|
||||
const NET_SSH2_COMPRESSION_ZLIB_AT_OPENSSH = 3;
|
||||
/**#@-*/
|
||||
|
||||
/**#@+
|
||||
* Execution Bitmap Masks
|
||||
*
|
||||
|
@ -254,6 +273,18 @@ class SSH2
|
|||
*/
|
||||
var $server_host_key_algorithms = false;
|
||||
|
||||
/**
|
||||
* Supported Private Key Algorithms
|
||||
*
|
||||
* In theory this should be the same as the Server Host Key Algorithms but, in practice,
|
||||
* some servers (eg. Azure) will support rsa-sha2-512 as a server host key algorithm but
|
||||
* not a private key algorithm
|
||||
*
|
||||
* @see self::privatekey_login()
|
||||
* @var array|false
|
||||
*/
|
||||
var $supported_private_key_algorithms = false;
|
||||
|
||||
/**
|
||||
* Encryption Algorithms: Client to Server
|
||||
*
|
||||
|
@ -970,6 +1001,71 @@ class SSH2
|
|||
*/
|
||||
var $auth = array();
|
||||
|
||||
/**
|
||||
* The authentication methods that may productively continue authentication.
|
||||
*
|
||||
* @see https://tools.ietf.org/html/rfc4252#section-5.1
|
||||
* @var array|null
|
||||
* @access private
|
||||
*/
|
||||
var $auth_methods_to_continue = null;
|
||||
|
||||
/**
|
||||
* Compression method
|
||||
*
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $compress = self::NET_SSH2_COMPRESSION_NONE;
|
||||
|
||||
/**
|
||||
* Decompression method
|
||||
*
|
||||
* @var resource|object
|
||||
* @access private
|
||||
*/
|
||||
var $decompress = self::NET_SSH2_COMPRESSION_NONE;
|
||||
|
||||
/**
|
||||
* Compression context
|
||||
*
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $compress_context;
|
||||
|
||||
/**
|
||||
* Decompression context
|
||||
*
|
||||
* @var resource|object
|
||||
* @access private
|
||||
*/
|
||||
var $decompress_context;
|
||||
|
||||
/**
|
||||
* Regenerate Compression Context
|
||||
*
|
||||
* @var bool
|
||||
* @access private
|
||||
*/
|
||||
var $regenerate_compression_context = false;
|
||||
|
||||
/**
|
||||
* Regenerate Decompression Context
|
||||
*
|
||||
* @var bool
|
||||
* @access private
|
||||
*/
|
||||
var $regenerate_decompression_context = false;
|
||||
|
||||
/**
|
||||
* Smart multi-factor authentication flag
|
||||
*
|
||||
* @var bool
|
||||
* @access private
|
||||
*/
|
||||
var $smartMFA = true;
|
||||
|
||||
/**
|
||||
* Default Constructor.
|
||||
*
|
||||
|
@ -1210,8 +1306,8 @@ class SSH2
|
|||
$read = array($this->fsock);
|
||||
$write = $except = null;
|
||||
$start = microtime(true);
|
||||
$sec = floor($this->curTimeout);
|
||||
$usec = 1000000 * ($this->curTimeout - $sec);
|
||||
$sec = (int) floor($this->curTimeout);
|
||||
$usec = (int) (1000000 * ($this->curTimeout - $sec));
|
||||
// on windows this returns a "Warning: Invalid CRT parameters detected" error
|
||||
// the !count() is done as a workaround for <https://bugs.php.net/42682>
|
||||
if (!@stream_select($read, $write, $except, $sec, $usec) && !count($read)) {
|
||||
|
@ -1226,6 +1322,7 @@ class SSH2
|
|||
if (strlen($temp) == 255) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($temp === false) {
|
||||
return false;
|
||||
}
|
||||
|
@ -1347,6 +1444,7 @@ class SSH2
|
|||
function _key_exchange($kexinit_payload_server = false)
|
||||
{
|
||||
$preferred = $this->preferred;
|
||||
$send_kex = true;
|
||||
|
||||
$kex_algorithms = isset($preferred['kex']) ?
|
||||
$preferred['kex'] :
|
||||
|
@ -1430,7 +1528,7 @@ class SSH2
|
|||
0
|
||||
);
|
||||
|
||||
if ($this->send_kex_first) {
|
||||
if ($kexinit_payload_server === false) {
|
||||
if (!$this->_send_binary_packet($kexinit_payload_client)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -1446,6 +1544,8 @@ class SSH2
|
|||
user_error('Expected SSH_MSG_KEXINIT');
|
||||
return false;
|
||||
}
|
||||
|
||||
$send_kex = false;
|
||||
}
|
||||
|
||||
$response = $kexinit_payload_server;
|
||||
|
@ -1464,6 +1564,8 @@ class SSH2
|
|||
$temp = unpack('Nlength', $this->_string_shift($response, 4));
|
||||
$this->server_host_key_algorithms = explode(',', $this->_string_shift($response, $temp['length']));
|
||||
|
||||
$this->supported_private_key_algorithms = $this->server_host_key_algorithms;
|
||||
|
||||
if (strlen($response) < 4) {
|
||||
return false;
|
||||
}
|
||||
|
@ -1518,7 +1620,7 @@ class SSH2
|
|||
extract(unpack('Cfirst_kex_packet_follows', $this->_string_shift($response, 1)));
|
||||
$first_kex_packet_follows = $first_kex_packet_follows != 0;
|
||||
|
||||
if (!$this->send_kex_first && !$this->_send_binary_packet($kexinit_payload_client)) {
|
||||
if ($send_kex && !$this->_send_binary_packet($kexinit_payload_client)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1558,19 +1660,25 @@ class SSH2
|
|||
return $this->_disconnect(NET_SSH2_DISCONNECT_KEY_EXCHANGE_FAILED);
|
||||
}
|
||||
|
||||
$compression_map = array(
|
||||
'none' => self::NET_SSH2_COMPRESSION_NONE,
|
||||
'zlib' => self::NET_SSH2_COMPRESSION_ZLIB,
|
||||
'zlib@openssh.com' => self::NET_SSH2_COMPRESSION_ZLIB_AT_OPENSSH
|
||||
);
|
||||
|
||||
$compression_algorithm_out = $this->_array_intersect_first($c2s_compression_algorithms, $this->compression_algorithms_client_to_server);
|
||||
if ($compression_algorithm_out === false) {
|
||||
user_error('No compatible client to server compression algorithms found');
|
||||
return $this->_disconnect(NET_SSH2_DISCONNECT_KEY_EXCHANGE_FAILED);
|
||||
}
|
||||
//$this->decompress = $compression_algorithm_out == 'zlib';
|
||||
$this->compress = $compression_map[$compression_algorithm_out];
|
||||
|
||||
$compression_algorithm_in = $this->_array_intersect_first($s2c_compression_algorithms, $this->compression_algorithms_client_to_server);
|
||||
$compression_algorithm_in = $this->_array_intersect_first($s2c_compression_algorithms, $this->compression_algorithms_server_to_client);
|
||||
if ($compression_algorithm_in === false) {
|
||||
user_error('No compatible server to client compression algorithms found');
|
||||
return $this->_disconnect(NET_SSH2_DISCONNECT_KEY_EXCHANGE_FAILED);
|
||||
}
|
||||
//$this->compress = $compression_algorithm_in == 'zlib';
|
||||
$this->decompress = $compression_map[$compression_algorithm_in];
|
||||
|
||||
// Only relevant in diffie-hellman-group-exchange-sha{1,256}, otherwise empty.
|
||||
$exchange_hash_rfc4419 = '';
|
||||
|
@ -2003,6 +2111,8 @@ class SSH2
|
|||
}
|
||||
$this->hmac_check->setKey(substr($key, 0, $checkKeyLength));
|
||||
|
||||
$this->regenerate_compression_context = $this->regenerate_decompression_context = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -2131,7 +2241,7 @@ class SSH2
|
|||
|
||||
// try logging with 'none' as an authentication method first since that's what
|
||||
// PuTTY does
|
||||
if (substr($this->server_identifier, 0, 13) != 'SSH-2.0-CoreFTP') {
|
||||
if (substr($this->server_identifier, 0, 15) != 'SSH-2.0-CoreFTP' && $this->auth_methods_to_continue === null) {
|
||||
if ($this->_login($username)) {
|
||||
return true;
|
||||
}
|
||||
|
@ -2163,9 +2273,61 @@ class SSH2
|
|||
return $this->_login_helper($username);
|
||||
}
|
||||
|
||||
foreach ($args as $arg) {
|
||||
if ($this->_login_helper($username, $arg)) {
|
||||
return true;
|
||||
while (count($args)) {
|
||||
if (!$this->auth_methods_to_continue || !$this->smartMFA) {
|
||||
$newargs = $args;
|
||||
$args = array();
|
||||
} else {
|
||||
$newargs = array();
|
||||
foreach ($this->auth_methods_to_continue as $method) {
|
||||
switch ($method) {
|
||||
case 'publickey':
|
||||
foreach ($args as $key => $arg) {
|
||||
if (is_object($arg)) {
|
||||
$newargs[] = $arg;
|
||||
unset($args[$key]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'keyboard-interactive':
|
||||
$hasArray = $hasString = false;
|
||||
foreach ($args as $arg) {
|
||||
if ($hasArray || is_array($arg)) {
|
||||
$hasArray = true;
|
||||
break;
|
||||
}
|
||||
if ($hasString || is_string($arg)) {
|
||||
$hasString = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($hasArray && $hasString) {
|
||||
foreach ($args as $key => $arg) {
|
||||
if (is_array($arg)) {
|
||||
$newargs[] = $arg;
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
case 'password':
|
||||
foreach ($args as $key => $arg) {
|
||||
$newargs[] = $arg;
|
||||
unset($args[$key]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!count($newargs)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($newargs as $arg) {
|
||||
if ($this->_login_helper($username, $arg)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
@ -2275,7 +2437,9 @@ class SSH2
|
|||
case NET_SSH2_MSG_USERAUTH_SUCCESS:
|
||||
$this->bitmap |= self::MASK_LOGIN;
|
||||
return true;
|
||||
//case NET_SSH2_MSG_USERAUTH_FAILURE:
|
||||
case NET_SSH2_MSG_USERAUTH_FAILURE:
|
||||
extract(unpack('Nmethodlistlen', $this->_string_shift($response, 4)));
|
||||
$this->auth_methods_to_continue = explode(',', $this->_string_shift($response, $methodlistlen));
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
@ -2347,6 +2511,7 @@ class SSH2
|
|||
}
|
||||
extract(unpack('Nlength', $this->_string_shift($response, 4)));
|
||||
$auth_methods = explode(',', $this->_string_shift($response, $length));
|
||||
$this->auth_methods_to_continue = $auth_methods;
|
||||
if (!strlen($response)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -2519,6 +2684,8 @@ class SSH2
|
|||
case NET_SSH2_MSG_USERAUTH_SUCCESS:
|
||||
return true;
|
||||
case NET_SSH2_MSG_USERAUTH_FAILURE:
|
||||
extract(unpack('Nmethodlistlen', $this->_string_shift($response, 4)));
|
||||
$this->auth_methods_to_continue = explode(',', $this->_string_shift($response, $methodlistlen));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -2578,7 +2745,13 @@ class SSH2
|
|||
$publickey['n']
|
||||
);
|
||||
|
||||
switch ($this->signature_format) {
|
||||
$algos = ['rsa-sha2-256', 'rsa-sha2-512', 'ssh-rsa'];
|
||||
if (isset($this->preferred['hostkey'])) {
|
||||
$algos = array_intersect($this->preferred['hostkey'], $algos);
|
||||
}
|
||||
$algo = $this->_array_intersect_first($algos, $this->supported_private_key_algorithms);
|
||||
|
||||
switch ($algo) {
|
||||
case 'rsa-sha2-512':
|
||||
$hash = 'sha512';
|
||||
$signatureType = 'rsa-sha2-512';
|
||||
|
@ -2627,8 +2800,14 @@ class SSH2
|
|||
if (strlen($response) < 4) {
|
||||
return false;
|
||||
}
|
||||
extract(unpack('Nlength', $this->_string_shift($response, 4)));
|
||||
$this->errors[] = 'SSH_MSG_USERAUTH_FAILURE: ' . $this->_string_shift($response, $length);
|
||||
extract(unpack('Nmethodlistlen', $this->_string_shift($response, 4)));
|
||||
$auth_methods = explode(',', $this->_string_shift($response, $methodlistlen));
|
||||
if (in_array('publickey', $auth_methods) && substr($signatureType, 0, 9) == 'rsa-sha2-') {
|
||||
$this->supported_private_key_algorithms = array_diff($this->supported_private_key_algorithms, array('rsa-sha2-256', 'rsa-sha2-512'));
|
||||
return $this->_privatekey_login($username, $privatekey);
|
||||
}
|
||||
$this->auth_methods_to_continue = $auth_methods;
|
||||
$this->errors[] = 'SSH_MSG_USERAUTH_FAILURE';
|
||||
return false;
|
||||
case NET_SSH2_MSG_USERAUTH_PK_OK:
|
||||
// we'll just take it on faith that the public key blob and the public key algorithm name are as
|
||||
|
@ -2669,6 +2848,8 @@ class SSH2
|
|||
switch ($type) {
|
||||
case NET_SSH2_MSG_USERAUTH_FAILURE:
|
||||
// either the login is bad or the server employs multi-factor authentication
|
||||
extract(unpack('Nmethodlistlen', $this->_string_shift($response, 4)));
|
||||
$this->auth_methods_to_continue = explode(',', $this->_string_shift($response, $methodlistlen));
|
||||
return false;
|
||||
case NET_SSH2_MSG_USERAUTH_SUCCESS:
|
||||
$this->bitmap |= self::MASK_LOGIN;
|
||||
|
@ -2795,26 +2976,12 @@ class SSH2
|
|||
return false;
|
||||
}
|
||||
|
||||
$response = $this->_get_binary_packet();
|
||||
if ($response === false) {
|
||||
$this->bitmap = 0;
|
||||
user_error('Connection closed by server');
|
||||
return false;
|
||||
$this->channel_status[self::CHANNEL_EXEC] = NET_SSH2_MSG_CHANNEL_REQUEST;
|
||||
if (!$this->_get_channel_packet(self::CHANNEL_EXEC)) {
|
||||
user_error('Unable to request pseudo-terminal');
|
||||
return $this->_disconnect(NET_SSH2_DISCONNECT_BY_APPLICATION);
|
||||
}
|
||||
|
||||
if (!strlen($response)) {
|
||||
return false;
|
||||
}
|
||||
list(, $type) = unpack('C', $this->_string_shift($response, 1));
|
||||
|
||||
switch ($type) {
|
||||
case NET_SSH2_MSG_CHANNEL_SUCCESS:
|
||||
break;
|
||||
case NET_SSH2_MSG_CHANNEL_FAILURE:
|
||||
default:
|
||||
user_error('Unable to request pseudo-terminal');
|
||||
return $this->_disconnect(NET_SSH2_DISCONNECT_BY_APPLICATION);
|
||||
}
|
||||
$this->in_request_pty_exec = true;
|
||||
}
|
||||
|
||||
|
@ -2935,6 +3102,13 @@ class SSH2
|
|||
return false;
|
||||
}
|
||||
|
||||
$this->channel_status[self::CHANNEL_SHELL] = NET_SSH2_MSG_CHANNEL_REQUEST;
|
||||
|
||||
if (!$this->_get_channel_packet(self::CHANNEL_SHELL)) {
|
||||
user_error('Unable to request pseudo-terminal');
|
||||
return $this->_disconnect(NET_SSH2_DISCONNECT_BY_APPLICATION);
|
||||
}
|
||||
|
||||
$packet = pack(
|
||||
'CNNa*C',
|
||||
NET_SSH2_MSG_CHANNEL_REQUEST,
|
||||
|
@ -2947,7 +3121,12 @@ class SSH2
|
|||
return false;
|
||||
}
|
||||
|
||||
$this->channel_status[self::CHANNEL_SHELL] = NET_SSH2_MSG_IGNORE;
|
||||
$response = $this->_get_channel_packet(self::CHANNEL_SHELL);
|
||||
if ($response === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->channel_status[self::CHANNEL_SHELL] = NET_SSH2_MSG_CHANNEL_DATA;
|
||||
|
||||
$this->bitmap |= self::MASK_SHELL;
|
||||
|
||||
|
@ -3319,7 +3498,7 @@ class SSH2
|
|||
$read = array($this->fsock);
|
||||
$write = $except = null;
|
||||
|
||||
if ($this->curTimeout <= 0) {
|
||||
if (!$this->curTimeout) {
|
||||
if ($this->keepAlive <= 0) {
|
||||
@stream_select($read, $write, $except, null);
|
||||
} else {
|
||||
|
@ -3350,8 +3529,8 @@ class SSH2
|
|||
$this->curTimeout-= $elapsed;
|
||||
}
|
||||
|
||||
$sec = floor($this->curTimeout);
|
||||
$usec = 1000000 * ($this->curTimeout - $sec);
|
||||
$sec = (int)floor($this->curTimeout);
|
||||
$usec = (int)(1000000 * ($this->curTimeout - $sec));
|
||||
|
||||
// on windows this returns a "Warning: Invalid CRT parameters detected" error
|
||||
if (!@stream_select($read, $write, $except, $sec, $usec) && !count($read)) {
|
||||
|
@ -3365,7 +3544,11 @@ class SSH2
|
|||
|
||||
if (!is_resource($this->fsock) || feof($this->fsock)) {
|
||||
$this->bitmap = 0;
|
||||
user_error('Connection closed prematurely');
|
||||
$str = 'Connection closed (by server) prematurely';
|
||||
if (isset($elapsed)) {
|
||||
$str.= ' ' . $elapsed . 's';
|
||||
}
|
||||
user_error($str);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -3373,7 +3556,8 @@ class SSH2
|
|||
$raw = stream_get_contents($this->fsock, $this->decrypt_block_size);
|
||||
|
||||
if (!strlen($raw)) {
|
||||
return '';
|
||||
user_error('No data received from server');
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->decrypt !== false) {
|
||||
|
@ -3436,9 +3620,41 @@ class SSH2
|
|||
}
|
||||
}
|
||||
|
||||
//if ($this->decompress) {
|
||||
// $payload = gzinflate(substr($payload, 2));
|
||||
//}
|
||||
switch ($this->decompress) {
|
||||
case self::NET_SSH2_COMPRESSION_ZLIB_AT_OPENSSH:
|
||||
if (!$this->isAuthenticated()) {
|
||||
break;
|
||||
}
|
||||
case self::NET_SSH2_COMPRESSION_ZLIB:
|
||||
if ($this->regenerate_decompression_context) {
|
||||
$this->regenerate_decompression_context = false;
|
||||
|
||||
$cmf = ord($payload[0]);
|
||||
$cm = $cmf & 0x0F;
|
||||
if ($cm != 8) { // deflate
|
||||
user_error("Only CM = 8 ('deflate') is supported ($cm)");
|
||||
}
|
||||
$cinfo = ($cmf & 0xF0) >> 4;
|
||||
if ($cinfo > 7) {
|
||||
user_error("CINFO above 7 is not allowed ($cinfo)");
|
||||
}
|
||||
$windowSize = 1 << ($cinfo + 8);
|
||||
|
||||
$flg = ord($payload[1]);
|
||||
//$fcheck = $flg && 0x0F;
|
||||
if ((($cmf << 8) | $flg) % 31) {
|
||||
user_error('fcheck failed');
|
||||
}
|
||||
$fdict = boolval($flg & 0x20);
|
||||
$flevel = ($flg & 0xC0) >> 6;
|
||||
|
||||
$this->decompress_context = inflate_init(ZLIB_ENCODING_RAW, array('window' => $cinfo + 8));
|
||||
$payload = substr($payload, 2);
|
||||
}
|
||||
if ($this->decompress_context) {
|
||||
$payload = inflate_add($this->decompress_context, $payload, ZLIB_PARTIAL_FLUSH);
|
||||
}
|
||||
}
|
||||
|
||||
$this->get_seq_no++;
|
||||
|
||||
|
@ -3513,6 +3729,10 @@ class SSH2
|
|||
|
||||
// only called when we've already logged in
|
||||
if (($this->bitmap & self::MASK_CONNECTED) && $this->isAuthenticated()) {
|
||||
if (is_bool($payload)) {
|
||||
return $payload;
|
||||
}
|
||||
|
||||
switch (ord($payload[0])) {
|
||||
case NET_SSH2_MSG_CHANNEL_REQUEST:
|
||||
if (strlen($payload) == 31) {
|
||||
|
@ -3714,7 +3934,20 @@ class SSH2
|
|||
function _get_channel_packet($client_channel, $skip_extended = false)
|
||||
{
|
||||
if (!empty($this->channel_buffers[$client_channel])) {
|
||||
return array_shift($this->channel_buffers[$client_channel]);
|
||||
switch ($this->channel_status[$client_channel]) {
|
||||
case NET_SSH2_MSG_CHANNEL_REQUEST:
|
||||
foreach ($this->channel_buffers[$client_channel] as $i => $packet) {
|
||||
switch (ord($packet[0])) {
|
||||
case NET_SSH2_MSG_CHANNEL_SUCCESS:
|
||||
case NET_SSH2_MSG_CHANNEL_FAILURE:
|
||||
unset($this->channel_buffers[$client_channel][$i]);
|
||||
return substr($packet, 1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return substr(array_shift($this->channel_buffers[$client_channel]), 1);
|
||||
}
|
||||
}
|
||||
|
||||
while (true) {
|
||||
|
@ -3788,10 +4021,7 @@ class SSH2
|
|||
if ($client_channel == $channel && $this->channel_status[$channel] == NET_SSH2_MSG_CHANNEL_DATA) {
|
||||
return $data;
|
||||
}
|
||||
if (!isset($this->channel_buffers[$channel])) {
|
||||
$this->channel_buffers[$channel] = array();
|
||||
}
|
||||
$this->channel_buffers[$channel][] = $data;
|
||||
$this->channel_buffers[$channel][] = chr($type) . $data;
|
||||
|
||||
continue 2;
|
||||
case NET_SSH2_MSG_CHANNEL_REQUEST:
|
||||
|
@ -3870,20 +4100,15 @@ class SSH2
|
|||
$result = $client_channel == $channel ? true : $this->_get_channel_packet($client_channel, $skip_extended);
|
||||
$this->_on_channel_open();
|
||||
return $result;
|
||||
//case NET_SSH2_MSG_CHANNEL_OPEN_FAILURE:
|
||||
default:
|
||||
case NET_SSH2_MSG_CHANNEL_OPEN_FAILURE:
|
||||
user_error('Unable to open channel');
|
||||
return $this->_disconnect(NET_SSH2_DISCONNECT_BY_APPLICATION);
|
||||
}
|
||||
break;
|
||||
case NET_SSH2_MSG_IGNORE:
|
||||
switch ($type) {
|
||||
case NET_SSH2_MSG_CHANNEL_SUCCESS:
|
||||
//$this->channel_status[$channel] = NET_SSH2_MSG_CHANNEL_DATA;
|
||||
continue 3;
|
||||
case NET_SSH2_MSG_CHANNEL_FAILURE:
|
||||
user_error('Error opening channel');
|
||||
return $this->_disconnect(NET_SSH2_DISCONNECT_BY_APPLICATION);
|
||||
default:
|
||||
if ($client_channel == $channel) {
|
||||
user_error('Unexpected response to open request');
|
||||
return $this->_disconnect(NET_SSH2_DISCONNECT_BY_APPLICATION);
|
||||
}
|
||||
return $this->_get_channel_packet($client_channel, $skip_extended);
|
||||
}
|
||||
break;
|
||||
case NET_SSH2_MSG_CHANNEL_REQUEST:
|
||||
|
@ -3892,6 +4117,14 @@ class SSH2
|
|||
return true;
|
||||
case NET_SSH2_MSG_CHANNEL_FAILURE:
|
||||
return false;
|
||||
case NET_SSH2_MSG_CHANNEL_DATA:
|
||||
if (strlen($response) < 4) {
|
||||
return false;
|
||||
}
|
||||
extract(unpack('Nlength', $this->_string_shift($response, 4)));
|
||||
$data = $this->_string_shift($response, $length);
|
||||
$this->channel_buffers[$channel][] = chr($type) . $data;
|
||||
return $this->_get_channel_packet($client_channel, $skip_extended);
|
||||
default:
|
||||
user_error('Unable to fulfill channel request');
|
||||
return $this->_disconnect(NET_SSH2_DISCONNECT_BY_APPLICATION);
|
||||
|
@ -3905,10 +4138,6 @@ class SSH2
|
|||
|
||||
switch ($type) {
|
||||
case NET_SSH2_MSG_CHANNEL_DATA:
|
||||
//if ($this->channel_status[$channel] == NET_SSH2_MSG_IGNORE) {
|
||||
// $this->channel_status[$channel] = NET_SSH2_MSG_CHANNEL_DATA;
|
||||
//}
|
||||
|
||||
/*
|
||||
if ($channel == self::CHANNEL_EXEC) {
|
||||
// SCP requires null packets, such as this, be sent. further, in the case of the ssh.com SSH server
|
||||
|
@ -3935,10 +4164,7 @@ class SSH2
|
|||
if ($client_channel == $channel) {
|
||||
return $data;
|
||||
}
|
||||
if (!isset($this->channel_buffers[$channel])) {
|
||||
$this->channel_buffers[$channel] = array();
|
||||
}
|
||||
$this->channel_buffers[$channel][] = $data;
|
||||
$this->channel_buffers[$channel][] = chr($type) . $data;
|
||||
break;
|
||||
case NET_SSH2_MSG_CHANNEL_CLOSE:
|
||||
$this->curTimeout = 5;
|
||||
|
@ -3957,7 +4183,7 @@ class SSH2
|
|||
case NET_SSH2_MSG_CHANNEL_EOF:
|
||||
break;
|
||||
default:
|
||||
user_error('Error reading channel data');
|
||||
user_error("Error reading channel data ($type)");
|
||||
return $this->_disconnect(NET_SSH2_DISCONNECT_BY_APPLICATION);
|
||||
}
|
||||
}
|
||||
|
@ -3982,11 +4208,27 @@ class SSH2
|
|||
return false;
|
||||
}
|
||||
|
||||
//if ($this->compress) {
|
||||
// // the -4 removes the checksum:
|
||||
// // http://php.net/function.gzcompress#57710
|
||||
// $data = substr(gzcompress($data), 0, -4);
|
||||
//}
|
||||
if (!isset($logged)) {
|
||||
$logged = $data;
|
||||
}
|
||||
|
||||
switch ($this->compress) {
|
||||
case self::NET_SSH2_COMPRESSION_ZLIB_AT_OPENSSH:
|
||||
if (!$this->isAuthenticated()) {
|
||||
break;
|
||||
}
|
||||
case self::NET_SSH2_COMPRESSION_ZLIB:
|
||||
if (!$this->regenerate_compression_context) {
|
||||
$header = '';
|
||||
} else {
|
||||
$this->regenerate_compression_context = false;
|
||||
$this->compress_context = deflate_init(ZLIB_ENCODING_RAW, array('window' => 15));
|
||||
$header = "\x78\x9C";
|
||||
}
|
||||
if ($this->compress_context) {
|
||||
$data = $header . deflate_add($this->compress_context, $data, ZLIB_PARTIAL_FLUSH);
|
||||
}
|
||||
}
|
||||
|
||||
// 4 (packet length) + 1 (padding length) + 4 (minimal padding amount) == 9
|
||||
$packet_length = strlen($data) + 9;
|
||||
|
@ -4014,10 +4256,10 @@ class SSH2
|
|||
|
||||
if (defined('NET_SSH2_LOGGING')) {
|
||||
$current = microtime(true);
|
||||
$message_number = isset($this->message_numbers[ord($data[0])]) ? $this->message_numbers[ord($data[0])] : 'UNKNOWN (' . ord($data[0]) . ')';
|
||||
$message_number = isset($this->message_numbers[ord($logged[0])]) ? $this->message_numbers[ord($logged[0])] : 'UNKNOWN (' . ord($logged[0]) . ')';
|
||||
$message_number = '-> ' . $message_number .
|
||||
' (since last: ' . round($current - $this->last_packet, 4) . ', network: ' . round($stop - $start, 4) . 's)';
|
||||
$this->_append_log($message_number, isset($logged) ? $logged : $data);
|
||||
$this->_append_log($message_number, $logged);
|
||||
$this->last_packet = $current;
|
||||
}
|
||||
|
||||
|
@ -4712,10 +4954,12 @@ class SSH2
|
|||
*/
|
||||
function getSupportedCompressionAlgorithms()
|
||||
{
|
||||
return array(
|
||||
'none' // REQUIRED no compression
|
||||
//'zlib' // OPTIONAL ZLIB (LZ77) compression
|
||||
);
|
||||
$algos = array('none'); // REQUIRED no compression
|
||||
if (function_exists('deflate_init')) {
|
||||
$algos[] = 'zlib@openssh.com'; // https://datatracker.ietf.org/doc/html/draft-miller-secsh-compression-delayed
|
||||
$algos[] = 'zlib';
|
||||
}
|
||||
return $algos;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4730,18 +4974,24 @@ class SSH2
|
|||
{
|
||||
$this->_connect();
|
||||
|
||||
$compression_map = array(
|
||||
self::NET_SSH2_COMPRESSION_NONE => 'none',
|
||||
self::NET_SSH2_COMPRESSION_ZLIB => 'zlib',
|
||||
self::NET_SSH2_COMPRESSION_ZLIB_AT_OPENSSH => 'zlib@openssh.com'
|
||||
);
|
||||
|
||||
return array(
|
||||
'kex' => $this->kex_algorithm,
|
||||
'hostkey' => $this->signature_format,
|
||||
'client_to_server' => array(
|
||||
'crypt' => $this->encrypt->name,
|
||||
'mac' => $this->hmac_create->name,
|
||||
'comp' => 'none',
|
||||
'comp' => $compression_map[$this->compress],
|
||||
),
|
||||
'server_to_client' => array(
|
||||
'crypt' => $this->decrypt->name,
|
||||
'mac' => $this->hmac_check->name,
|
||||
'comp' => 'none',
|
||||
'comp' => $compression_map[$this->decompress],
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -5143,4 +5393,31 @@ class SSH2
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the list of authentication methods that may productively continue authentication.
|
||||
*
|
||||
* @see https://tools.ietf.org/html/rfc4252#section-5.1
|
||||
* @return array|null
|
||||
*/
|
||||
function getAuthMethodsToContinue()
|
||||
{
|
||||
return $this->auth_methods_to_continue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables "smart" multi-factor authentication (MFA)
|
||||
*/
|
||||
function enableSmartMFA()
|
||||
{
|
||||
$this->smartMFA = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables "smart" multi-factor authentication (MFA)
|
||||
*/
|
||||
function disableSmartMFA()
|
||||
{
|
||||
$this->smartMFA = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -133,9 +133,20 @@ class Agent
|
|||
}
|
||||
}
|
||||
|
||||
$this->fsock = fsockopen('unix://' . $address, 0, $errno, $errstr);
|
||||
if (!$this->fsock) {
|
||||
user_error("Unable to connect to ssh-agent (Error $errno: $errstr)");
|
||||
if (in_array('unix', stream_get_transports())) {
|
||||
$this->fsock = fsockopen('unix://' . $address, 0, $errno, $errstr);
|
||||
if (!$this->fsock) {
|
||||
user_error("Unable to connect to ssh-agent (Error $errno: $errstr)");
|
||||
}
|
||||
} else {
|
||||
if (substr($address, 0, 9) != '\\\\.\\pipe\\' || strpos(substr($address, 9), '\\') !== false) {
|
||||
user_error('Address is not formatted as a named pipe should be');
|
||||
} else {
|
||||
$this->fsock = fopen($address, 'r+b');
|
||||
if (!$this->fsock) {
|
||||
user_error('Unable to open address');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -234,11 +245,10 @@ class Agent
|
|||
* Signal that agent forwarding should
|
||||
* be requested when a channel is opened
|
||||
*
|
||||
* @param Net_SSH2 $ssh
|
||||
* @return bool
|
||||
* @access public
|
||||
*/
|
||||
function startSSHForwarding($ssh)
|
||||
function startSSHForwarding()
|
||||
{
|
||||
if ($this->forward_status == self::FORWARD_NONE) {
|
||||
$this->forward_status = self::FORWARD_REQUEST;
|
||||
|
|
|
@ -7,7 +7,8 @@
|
|||
|
||||
if (extension_loaded('mbstring')) {
|
||||
// 2 - MB_OVERLOAD_STRING
|
||||
if (ini_get('mbstring.func_overload') & 2) {
|
||||
// mbstring.func_overload is deprecated in php 7.2 and removed in php 8.0.
|
||||
if (version_compare(PHP_VERSION, '8.0.0') < 0 && ini_get('mbstring.func_overload') & 2) {
|
||||
throw new \UnexpectedValueException(
|
||||
'Overloading of string functions using mbstring.func_overload ' .
|
||||
'is not supported by phpseclib.'
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
# https://EditorConfig.org
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.{css,js,json,sql}]
|
||||
indent_style = tab
|
||||
|
||||
[*.html]
|
||||
indent_size = 2
|
||||
indent_style = space
|
||||
|
||||
[*.{markdown,md}]
|
||||
indent_size = 4
|
||||
indent_style = space
|
||||
max_line_length = off
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
[*.php]
|
||||
indent_size = 4
|
||||
indent_style = space
|
||||
|
||||
[*.{yaml,yml}]
|
||||
indent_size = 2
|
||||
indent_style = space
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
$finder = (new PhpCsFixer\Finder())
|
||||
->in('build')
|
||||
->in('library')
|
||||
->in('src')
|
||||
->in('tests')
|
||||
;
|
||||
|
||||
return (new PhpCsFixer\Config())
|
||||
->setRules([
|
||||
'@PSR12' => true,
|
||||
'@PHP71Migration' => true,
|
||||
'@PHP71Migration:risky' => true,
|
||||
'void_return' => false,
|
||||
'@PHPUnit84Migration:risky' => true,
|
||||
])
|
||||
->setFinder($finder)
|
||||
;
|
|
@ -1,10 +1,165 @@
|
|||
## 1.5.5 (May 1, 2020)
|
||||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [Unreleased](https://github.com/simplepie/simplepie/compare/1.8.0...master)
|
||||
|
||||
## [1.8.0](https://github.com/simplepie/simplepie/compare/1.7.0...1.8.0) - 2023-01-20
|
||||
|
||||
### Added
|
||||
|
||||
- New method `SimplePie\SimplePie::set_cache()` for providing a PSR-16 cache implementation by @Art4 in [#742](https://github.com/simplepie/simplepie/pull/742)
|
||||
- New method `SimplePie\SimplePie::set_cache_namefilter()` for customize the cache key in [#762](https://github.com/simplepie/simplepie/pull/762)
|
||||
- New class `SimplePie\Cache\CallableNameFilter` to provide a `callable` to customize the cache key in [#762](https://github.com/simplepie/simplepie/pull/762)
|
||||
- New interface `SimplePie\RegistryAware` to inject the `Registry` instance into classes created by `Registry` by @Art4 in [#760](https://github.com/simplepie/simplepie/pull/760)
|
||||
- update PHP versions in GH Actions workflows by @jrfnl in [#767](https://github.com/simplepie/simplepie/pull/767)
|
||||
- Registry: Allow using class-strings instead of magic strings by @jtojnar and @Art4 in [#766](https://github.com/simplepie/simplepie/pull/766)
|
||||
|
||||
### Changed
|
||||
|
||||
- Clarify branching strategy by @Art4 in [#751](https://github.com/simplepie/simplepie/pull/751)
|
||||
- Use native array_replace_recursive() by @Alkarex in [#749](https://github.com/simplepie/simplepie/pull/749)
|
||||
- PHP 7.2 or newer is now required by @Art4 in [#743](https://github.com/simplepie/simplepie/pull/743)
|
||||
- Parse\Date: Clean up regex structure by @jtojnar in [#765](https://github.com/simplepie/simplepie/pull/765)
|
||||
- Declare strict_types=1 in every file by @Art4 in [#763](https://github.com/simplepie/simplepie/pull/763)
|
||||
|
||||
### Fixed
|
||||
|
||||
- Item::get_date(): fix return type on unparsable date by @jtojnar in [#753](https://github.com/simplepie/simplepie/pull/753)
|
||||
- Fix error handling for PHP 8.1 by @cedric-anne in [#747](https://github.com/simplepie/simplepie/pull/747)
|
||||
- The method `SimplePie\SimplePie::get_image_height()` returns the pixel number as `int` instead of `float` by @Art4 in [#763](https://github.com/simplepie/simplepie/pull/763)
|
||||
- The method `SimplePie\SimplePie::get_image_width()` returns the pixel number as `int` instead of `float` by @Art4 in [#763](https://github.com/simplepie/simplepie/pull/763)
|
||||
- No URL Decode for enclosure links by @Alkarex in [#768](https://github.com/simplepie/simplepie/pull/768)
|
||||
- Sanitize thumbnail URL by @Alkarex in [#770](https://github.com/simplepie/simplepie/pull/770)
|
||||
- Fix case of multiple RSS2.0 enclosures by @Alkarex in [#769](https://github.com/simplepie/simplepie/pull/769)
|
||||
- Fix broken phpdoc references by @jtojnar in [#771](https://github.com/simplepie/simplepie/pull/771)
|
||||
|
||||
### Deprecated
|
||||
|
||||
- The method `SimplePie\Misc::array_merge_recursive()` is deprecated, use native `array_replace_recursive()` instead
|
||||
- The method `SimplePie\SimplePie::set_cache_name_function()` is deprecated, use `SimplePie\SimplePie::set_cache_namefilter()` instead
|
||||
- The method `SimplePie\SimplePie::set_cache_location()` is deprecated, use `SimplePie\SimplePie::set_cache()` instead
|
||||
- The method `SimplePie\SimplePie::force_cache_fallback()` is deprecated, expired cache will not be used anymore
|
||||
- The class `SimplePie\Cache` is deprecated, use implementation of `SimplePie\SimplePie::set_cache()` instead
|
||||
- The class `SimplePie\Cache\DB` is deprecated, use implementation of `Psr\SimpleCache\CacheInterface` instead
|
||||
- The class `SimplePie\Cache\File` is deprecated, use implementation of `Psr\SimpleCache\CacheInterface` instead
|
||||
- The class `SimplePie\Cache\Memcache` is deprecated, use implementation of `Psr\SimpleCache\CacheInterface` instead
|
||||
- The class `SimplePie\Cache\Memcached` is deprecated, use implementation of `Psr\SimpleCache\CacheInterface` instead
|
||||
- The class `SimplePie\Cache\MySQL` is deprecated, use implementation of `Psr\SimpleCache\CacheInterface` instead
|
||||
- The class `SimplePie\Cache\Redis` is deprecated, use implementation of `Psr\SimpleCache\CacheInterface` instead
|
||||
- The interface `SimplePie\Cache\Base` is deprecated, use interface `Psr\SimpleCache\CacheInterface` instead
|
||||
|
||||
### Removed
|
||||
|
||||
- ROADMAP.md removed by @Art4 in [#748](https://github.com/simplepie/simplepie/pull/748)
|
||||
- remove check for E_USER_DEPRECATED definition by @Art4 in [#750](https://github.com/simplepie/simplepie/pull/750)
|
||||
- remove broken BC code in Registry by @Art4 in [#764](https://github.com/simplepie/simplepie/pull/764)
|
||||
|
||||
## [1.7.0](https://github.com/simplepie/simplepie/compare/1.6.0...1.7.0) - 2022-09-30
|
||||
|
||||
### Added
|
||||
|
||||
- New class `SimplePie\SimplePie` as a replacement for class `SimplePie`
|
||||
- New method `SimplePie\Misc::get_default_useragent()` as a replacement for constant `SIMPLEPIE_USERAGENT`
|
||||
|
||||
### Changed
|
||||
|
||||
- Do not use magic values for state machine state by @jtojnar in [#735](https://github.com/simplepie/simplepie/pull/735)
|
||||
- Use PSR-4 classes in Registry by @Art4 in [#736](https://github.com/simplepie/simplepie/pull/736)
|
||||
- GH Actions: run tests against PHP 8.2 by @jrfnl in [#739](https://github.com/simplepie/simplepie/pull/739)
|
||||
- Change code style to PSR-12 by @Art4 in [#738](https://github.com/simplepie/simplepie/pull/738)
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fix status_code type by @Alkarex in [#728](https://github.com/simplepie/simplepie/pull/728)
|
||||
- Fix parsing of HTTP Links by @Alkarex in [#729](https://github.com/simplepie/simplepie/pull/729)
|
||||
- Fix using the best base link for an item content by @Alkarex in [#744](https://github.com/simplepie/simplepie/pull/744)
|
||||
- Fix .editorconfig regression by @Alkarex in [#745](https://github.com/simplepie/simplepie/pull/745)
|
||||
|
||||
### Deprecated
|
||||
|
||||
- The class `SimplePie` is deprecated, use class `SimplePie\SimplePie` instead
|
||||
- The use of PSR-0 classes (all classes without namespaces in the `library` directory) is deprecated, use PSR-4 classes (see `src` directory) instead
|
||||
- The constant `SIMPLEPIE_BUILD` is deprecated, use `SimplePie\Misc::get_build()` instead
|
||||
- The constant `SIMPLEPIE_USERAGENT` is deprecated, use `SimplePie\Misc::get_default_useragent()` instead
|
||||
- All global constants are deprecated, use the constants from the class `SimplePie\SimplePie` instead (e.g. replace `SIMPLEPIE_VERSION` with `SimplePie\SimplePie::VERSION`)
|
||||
|
||||
## [1.6.0](https://github.com/simplepie/simplepie/compare/1.5.8...1.6.0) - 2022-04-21
|
||||
|
||||
### Added
|
||||
|
||||
- New methods `SimplePie::rename_attributes()` and `SimplePie_Sanitize::rename_attributes()` allow renaming attributes by @math-GH in [#717](https://github.com/simplepie/simplepie/pull/717)
|
||||
- Add audio, video @src elements/attribute for URL resolution by @rdalverny in [#716](https://github.com/simplepie/simplepie/pull/716)
|
||||
- Added new namespaced aliases and PSR-4 support for every class by @Art4 in [#711](https://github.com/simplepie/simplepie/pull/711)
|
||||
- Add .editorconfig by @Alkarex in [#724](https://github.com/simplepie/simplepie/pull/724)
|
||||
- Upload compiled file as release asset by @Art4 in [#725](https://github.com/simplepie/simplepie/pull/725)
|
||||
|
||||
### Changed
|
||||
|
||||
- GH Actions: version update for ramsey/composer-install by @jrfnl in [#713](https://github.com/simplepie/simplepie/pull/713)
|
||||
|
||||
### Fixed
|
||||
|
||||
- Bugfix in MySQL cache by @Art4 in [#720](https://github.com/simplepie/simplepie/pull/720)
|
||||
- Re-enable xml:base for all supported RSS formats by @Alkarex in [#723](https://github.com/simplepie/simplepie/pull/723)
|
||||
|
||||
## [1.5.8](https://github.com/simplepie/simplepie/compare/1.5.7...1.5.8) - 2021-12-24
|
||||
|
||||
### Changed
|
||||
|
||||
- Update CHANGELOG.md, follow keepachangelog format by @Art4 in [#709](https://github.com/simplepie/simplepie/pull/709)
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fix a small typo in the error() function Docblock by @audrasjb in [#712](https://github.com/simplepie/simplepie/pull/712)
|
||||
- Fix/708 version bump for constant `SIMPLEPIE_VERSION` for 1.5.8 release by @faisal-alvi in [#710](https://github.com/simplepie/simplepie/pull/710)
|
||||
|
||||
## [1.5.7](https://github.com/simplepie/simplepie/compare/1.5.6...1.5.7) - 2021-12-19
|
||||
|
||||
* Fix PHP8 crash due to insufficient isset test by @Alkarex in [#670](https://github.com/simplepie/simplepie/pull/670)
|
||||
* gitignore tests by @Alkarex in [#671](https://github.com/simplepie/simplepie/pull/671)
|
||||
* Reduce memory when parsing large feeds by @Alkarex in [#672](https://github.com/simplepie/simplepie/pull/672)
|
||||
* PHP8 catch ValueError for loadHTML() by @Alkarex in [#673](https://github.com/simplepie/simplepie/pull/673)
|
||||
* Provide access to HTTP status code by @Alkarex in [#674](https://github.com/simplepie/simplepie/pull/674)
|
||||
* Fix wrong type hint by @Alkarex in [#678](https://github.com/simplepie/simplepie/pull/678)
|
||||
* Force HTTPS for selected domains by @Alkarex in [#676](https://github.com/simplepie/simplepie/pull/676)
|
||||
* Prevent cache polution by @Alkarex in [#675](https://github.com/simplepie/simplepie/pull/675)
|
||||
* Fix typo in comment by @Alkarex in [#680](https://github.com/simplepie/simplepie/pull/680)
|
||||
* Remove HTTP credentials in HTTP Referer by @Alkarex in [#681](https://github.com/simplepie/simplepie/pull/681)
|
||||
* CI: switch to GH Actions by @jrfnl in [#688](https://github.com/simplepie/simplepie/pull/688)
|
||||
* PHP 8.1: fix "passing null to non-nullable" deprecation notice by @jrfnl in [#689](https://github.com/simplepie/simplepie/pull/689)
|
||||
* Tests: PHPUnit cross-version compatibility by @jrfnl in [#690](https://github.com/simplepie/simplepie/pull/690)
|
||||
* Tests: use strict assertions by @jrfnl in [#692](https://github.com/simplepie/simplepie/pull/692)
|
||||
* CacheTest: handle different exceptions PHP cross-version by @jrfnl in [#691](https://github.com/simplepie/simplepie/pull/691)
|
||||
* GH Actions: don't allow builds to fail on PHP 8.0 or 8.1 by @jrfnl in [#693](https://github.com/simplepie/simplepie/pull/693)
|
||||
* Tests: use the correct parameter order by @jrfnl in [#694](https://github.com/simplepie/simplepie/pull/694)
|
||||
* PHPUnit: update configuration by @jrfnl in [#696](https://github.com/simplepie/simplepie/pull/696)
|
||||
* fix: better deal with proxy returning proxy headers (in response to cURL's Proxy-Connection header) by @shunf4 in [#698](https://github.com/simplepie/simplepie/pull/698)
|
||||
* Handle multiple Link headers by @voegelas in [#700](https://github.com/simplepie/simplepie/pull/700)
|
||||
* PHP 8.2: explicitly declare properties by @jrfnl in [#705](https://github.com/simplepie/simplepie/pull/705)
|
||||
* New Contributor: @shunf4 made their first contribution in [#698](https://github.com/simplepie/simplepie/pull/698)
|
||||
* New Contributor: @voegelas made their first contribution in [#700](https://github.com/simplepie/simplepie/pull/700)
|
||||
|
||||
## [1.5.6](https://github.com/simplepie/simplepie/compare/1.5.5...1.5.6) - 2020-10-14
|
||||
|
||||
* PHP 8.0: prevent ValueError for invalid encoding [#657](https://github.com/simplepie/simplepie/pull/657)
|
||||
* Travis: test against more recent PHP versions [#653](https://github.com/simplepie/simplepie/pull/653)
|
||||
* PHP 8.0: handle removal of get_magic_quotes_gpc() [#654](https://github.com/simplepie/simplepie/pull/654)
|
||||
* PHP 7.4/8.0: curly brace array access deprecated & removed [#655](https://github.com/simplepie/simplepie/pull/655)
|
||||
* PHP 8.0: required parameters are no longer allowed after optional parameters [#656](https://github.com/simplepie/simplepie/pull/656)
|
||||
* Fix permanent_url for HTTP 301 [#660](https://github.com/simplepie/simplepie/pull/660)
|
||||
* Fix typo in MIME type in Content_Type_Sniffer [#661](https://github.com/simplepie/simplepie/pull/661)
|
||||
|
||||
## [1.5.5](https://github.com/simplepie/simplepie/compare/1.5.4...1.5.5) - 2020-05-01
|
||||
|
||||
* Ensure that feeds retrieved with `force_feed` do not share the same cache as those retrieved without. [#643](https://github.com/simplepie/simplepie/pull/643)
|
||||
* Removed references to removed PHP directives and some PHP < 5.6 checks. [#645](https://github.com/simplepie/simplepie/pull/645)
|
||||
* Corrected incorrect alumni name. [#638](https://github.com/simplepie/simplepie/pull/638)
|
||||
|
||||
## 1.5.4 (December 17, 2019)
|
||||
## [1.5.4](https://github.com/simplepie/simplepie/compare/1.5.3...1.5.4) - 2019-12-17
|
||||
|
||||
* PHP 5.6 or newer is now required. [#625](https://github.com/simplepie/simplepie/pull/625)
|
||||
* Fixed invalid docblock parameter types [#633](https://github.com/simplepie/simplepie/pull/633)
|
||||
|
@ -12,7 +167,7 @@
|
|||
* PHP 7.4 support: Fixed instances of accessing array offset on null type values. [#628](https://github.com/simplepie/simplepie/pull/628)
|
||||
* Return an effective feed URL when asking for non-permanent `subscribe_url`. [#627](https://github.com/simplepie/simplepie/pull/627)
|
||||
|
||||
## 1.5.3 (September 22, 2019)
|
||||
## [1.5.3](https://github.com/simplepie/simplepie/compare/1.5.2...1.5.3) - 2019-09-22
|
||||
|
||||
* Replaced `pow()` call with `**` operator (micro performance optimization). [#622](https://github.com/simplepie/simplepie/pull/622)
|
||||
* Match links containing `feed` in the Locator class. [#621](https://github.com/simplepie/simplepie/pull/621)
|
||||
|
@ -20,7 +175,7 @@
|
|||
* Added support for Russian dates. [#607](https://github.com/simplepie/simplepie/pull/607)
|
||||
* Preemptively changed `is_writeable()` calls to `is_writable()` in case the former is deprecated in PHP. [#604](https://github.com/simplepie/simplepie/pull/604)
|
||||
|
||||
## 1.5.2 (August 2, 2018)
|
||||
## [1.5.2](https://github.com/simplepie/simplepie/compare/1.5.1...1.5.2) - 2018-08-02
|
||||
|
||||
* Added support for PHPUnit 6. [#565](https://github.com/simplepie/simplepie/pull/565)
|
||||
* Added PHP module requirements to Composer. [#590](https://github.com/simplepie/simplepie/pull/590)
|
||||
|
@ -35,7 +190,7 @@
|
|||
* Fixed a bug where URL fragments are included when `SimplePie_File` normalizes URLs when really old versions of cURL are used. [#564](https://github.com/simplepie/simplepie/pull/564)
|
||||
* Updated `SimplePie_Locator` to respect cURL options specified. [#561](https://github.com/simplepie/simplepie/pull/561)
|
||||
|
||||
## 1.5.1 (November 17, 2017)
|
||||
## [1.5.1](https://github.com/simplepie/simplepie/compare/1.5...1.5.1) - 2017-11-17
|
||||
|
||||
* Fixed photos so they are not added if the URL is empty. [#530](https://github.com/simplepie/simplepie/pull/530)
|
||||
* Fixed issues with retrieving feeds from behind a proxy. [#512](https://github.com/simplepie/simplepie/pull/512)/[#548](https://github.com/simplepie/simplepie/pull/548)
|
||||
|
@ -48,14 +203,14 @@
|
|||
* Update the registry if the Sanitize class has been changed. [#532](https://github.com/simplepie/simplepie/pull/532)
|
||||
* Changed the sanitization type for author and category back to text from HTML. [#531](https://github.com/simplepie/simplepie/pull/531)
|
||||
|
||||
## 1.5 (April 17, 2017)
|
||||
## [1.5](https://github.com/simplepie/simplepie/compare/1.4.3...1.5) - 2017-04-17
|
||||
|
||||
* Introduced `SimplePie_Category->get_type()` for retrieving category type. [#492](https://github.com/simplepie/simplepie/pull/492)
|
||||
* Added `$enable_exceptions` to the class property declarations for `SimplePie` class. [#504](https://github.com/simplepie/simplepie/pull/504)
|
||||
* Titles are now parsed for ATOM10 enclosure links. [#507](https://github.com/simplepie/simplepie/pull/507)
|
||||
* `$item->get_id()` can now be forced to return the supplied ID instead of generating a new one. [#509](https://github.com/simplepie/simplepie/pull/509)
|
||||
|
||||
## 1.4.3 (November 26, 2016)
|
||||
## [1.4.3](https://github.com/simplepie/simplepie/compare/1.4.2...1.4.3) - 2016-11-26
|
||||
|
||||
* Removed support for PHP 5.2. [#469](https://github.com/simplepie/simplepie/pull/469)
|
||||
* Added support for the PHP `UConverter` class. [#485](https://github.com/simplepie/simplepie/pull/485)
|
||||
|
@ -73,21 +228,21 @@
|
|||
* Use the latest HHVM version in testing (3.15.2). [#480](https://github.com/simplepie/simplepie/pull/480)
|
||||
* Added PHPUnit as a `dev-dependency` in Composer. [#463](https://github.com/simplepie/simplepie/pull/463)
|
||||
* Added `mf2/mf2` as a suggestion in Composer for use with microformats. [#491](https://github.com/simplepie/simplepie/pull/491)
|
||||
* Fixed misspelled occurrences of "separated". [#459](https://github.com/simplepie/simplepie/pull/459)
|
||||
* Fixed misspelled occurrences of "separated". [#459](https://github.com/simplepie/simplepie/pull/459)
|
||||
* Improvements to the compatibility test and error messages. [#488](https://github.com/simplepie/simplepie/pull/488)
|
||||
|
||||
## 1.4.2 (June 14, 2016)
|
||||
## [1.4.2](https://github.com/simplepie/simplepie/compare/1.4.1...1.4.2) - 2016-06-14
|
||||
|
||||
* Fixed a bug with IRI parsing.
|
||||
* More cleanly separates discovery of microformats and parsing when php-mf2 is not present.
|
||||
* More cleanly separates discovery of microformats and parsing when php-mf2 is not present.
|
||||
|
||||
## 1.4.1 (June 2, 2016)
|
||||
## [1.4.1](https://github.com/simplepie/simplepie/compare/1.4.0...1.4.1) - 2016-06-02
|
||||
|
||||
* Fixed inconsistent hash results in `SimplePie_Item->get_id()`.
|
||||
* Leading and trailing whitespace is now trimmed from XML feed content to prevent errors. [#445](https://github.com/simplepie/simplepie/pull/445)
|
||||
* Improved support for microformat feeds.
|
||||
|
||||
## 1.4.0 (April 25, 2016)
|
||||
## [1.4.0](https://github.com/simplepie/simplepie/compare/1.4-beta...1.4.0) - 2016-04-25
|
||||
|
||||
* Dropped support for PHP 5.2. [#348](https://github.com/simplepie/simplepie/pull/348)
|
||||
* Serialized data is now used for hashing in `SimplePie_Item->get_id()`. [#348](https://github.com/simplepie/simplepie/pull/348)
|
||||
|
@ -102,7 +257,7 @@
|
|||
* Added support for `application/x-rss+xml` in `SimplePie_Locator`. [#348](https://github.com/simplepie/simplepie/pull/348)
|
||||
* Added photo de-duping in microformats. [#348](https://github.com/simplepie/simplepie/pull/348)
|
||||
* Added decoding for special characters in MAYBE_HTML. [#400](https://github.com/simplepie/simplepie/pull/400)
|
||||
* Added `SimplePie_Exception` for internally reporting errors. Also, use this to show an error when trying to load the class instead of causing a failure. [#241](https://github.com/simplepie/simplepie/pull/241)
|
||||
* Added `SimplePie_Exception` for internally reporting errors. Also, use this to show an error when trying to load the class instead of causing a failure. [#241](https://github.com/simplepie/simplepie/pull/241)
|
||||
* Added sanitization of the `</html>` and `</body>` tags. [#348](https://github.com/simplepie/simplepie/pull/348)
|
||||
* Added support for media thumbnails through `SimplePie_Item->get_thumbnail()`. [#348](https://github.com/simplepie/simplepie/pull/348)
|
||||
* Added the `feed_url` to a returned error message. [#348](https://github.com/simplepie/simplepie/pull/348)
|
||||
|
@ -125,7 +280,7 @@
|
|||
* Fixed an error caused when trying to instantiate a `SimplePie_File` object with a bad URI. [#272](https://github.com/simplepie/simplepie/pull/272)
|
||||
* Fixed a PHP notice that occurs when a date starts with `(`. [#348](https://github.com/simplepie/simplepie/pull/348)
|
||||
* Fixed uninitialized string offeset PHP notices. [#353](https://github.com/simplepie/simplepie/pull/353)
|
||||
* Fixed call to non-existent property in Memcache. [#311](https://github.com/simplepie/simplepie/pull/311)
|
||||
* Fixed call to non-existent property in Memcache. [#311](https://github.com/simplepie/simplepie/pull/311)
|
||||
* Fixed a bug where MySQL statements were not being passed thorugh `prepare()`. [#348](https://github.com/simplepie/simplepie/pull/348)
|
||||
* Fixed an instance where an error message in `SimplePie` was not being triggered correctly. [#348](https://github.com/simplepie/simplepie/pull/348)
|
||||
* Fixed a bug with Russian feeds. [#348](https://github.com/simplepie/simplepie/pull/348)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Copyright (c) 2004-2007, Ryan Parman and Sam Sneddon.
|
||||
Copyright (c) 2004-2022, Ryan Parman and Sam Sneddon.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are
|
||||
|
|
|
@ -11,7 +11,7 @@ compatibility and standards compliance][what_is].
|
|||
|
||||
Requirements
|
||||
------------
|
||||
* PHP 5.6+ (Required since SimplePie 1.5.3)
|
||||
* PHP 7.2+ (Required since SimplePie 1.8.0)
|
||||
* libxml2 (certain 2.7.x releases are too buggy for words, and will crash)
|
||||
* One of iconv, mbstring or intl extensions
|
||||
* cURL or fsockopen()
|
||||
|
@ -20,7 +20,7 @@ Requirements
|
|||
|
||||
What comes in the package?
|
||||
--------------------------
|
||||
1. `library/` - SimplePie classes for use with the autoloader
|
||||
1. `src/` - SimplePie classes for use with the autoloader
|
||||
2. `autoloader.php` - The SimplePie Autoloader if you want to use the separate
|
||||
file version.
|
||||
3. `README.markdown` - This document.
|
||||
|
@ -38,8 +38,9 @@ What comes in the package?
|
|||
Since SimplePie 1.3, we've split the classes into separate files to make it easier
|
||||
to maintain and use.
|
||||
|
||||
If you'd like a single monolithic file, you can run `php build/compile.php` to
|
||||
generate `SimplePie.compiled.php`.
|
||||
If you'd like a single monolithic file, see the assets in the
|
||||
[releases](https://github.com/simplepie/simplepie/releases), or you can
|
||||
run `php build/compile.php` to generate `SimplePie.compiled.php` yourself.
|
||||
|
||||
To start the demo
|
||||
-----------------
|
||||
|
@ -74,9 +75,20 @@ to be prioritized.
|
|||
|
||||
If you'd like to contribute to SimplePie, the best way to get started is to fork
|
||||
the project on GitHub and send pull requests for patches. When doing so, please
|
||||
be aware of our [coding standards][].
|
||||
be aware of our [coding standards](http://simplepie.org/wiki/misc/coding_standards).
|
||||
|
||||
[coding standards]: http://simplepie.org/wiki/misc/coding_standards
|
||||
The main development for the next minor release happens in `master` branch.
|
||||
Please create your pull requests primarily against this branch.
|
||||
|
||||
We do not actively provide bug fixes or security fixes for older versions. Nevertheless,
|
||||
you are welcome to create backport PRs if you still need support for older PHP versions.
|
||||
Please open your PR against the appropriate branch.
|
||||
|
||||
| branch | requires |
|
||||
|----------------------------------------------------------------------------|-------------|
|
||||
| [master](https://github.com/simplepie/simplepie/tree/master) | PHP 7.2.0+ |
|
||||
| [one-dot-seven](https://github.com/simplepie/simplepie/tree/one-dot-seven) | PHP 5.6.0+ |
|
||||
| [one-dot-three](https://github.com/simplepie/simplepie/tree/one-dot-three) | PHP 5.2.0+ |
|
||||
|
||||
|
||||
Authors and contributors
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* 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
|
||||
* Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
|
@ -42,6 +42,47 @@
|
|||
*/
|
||||
|
||||
|
||||
/**
|
||||
* PSR-4 implementation for SimplePie.
|
||||
*
|
||||
* After registering this autoload function with SPL, the following line
|
||||
* would cause the function to attempt to load the \SimplePie\SimplePie class
|
||||
* from /src/SimplePie.php:
|
||||
*
|
||||
* new \SimplePie\SimplePie();
|
||||
*
|
||||
* @param string $class The fully-qualified class name.
|
||||
* @return void
|
||||
*/
|
||||
spl_autoload_register(function ($class) {
|
||||
|
||||
// project-specific namespace prefix
|
||||
$prefix = 'SimplePie\\';
|
||||
|
||||
// base directory for the namespace prefix
|
||||
$base_dir = __DIR__ . '/src/';
|
||||
|
||||
// does the class use the namespace prefix?
|
||||
$len = strlen($prefix);
|
||||
if (strncmp($prefix, $class, $len) !== 0) {
|
||||
// no, move to the next registered autoloader
|
||||
return;
|
||||
}
|
||||
|
||||
// get the relative class name
|
||||
$relative_class = substr($class, $len);
|
||||
|
||||
// replace the namespace prefix with the base directory, replace namespace
|
||||
// separators with directory separators in the relative class name, append
|
||||
// with .php
|
||||
$file = $base_dir . str_replace('\\', '/', $relative_class) . '.php';
|
||||
|
||||
// if the file exists, require it
|
||||
if (file_exists($file)) {
|
||||
require $file;
|
||||
}
|
||||
});
|
||||
|
||||
// autoloader
|
||||
spl_autoload_register(array(new SimplePie_Autoloader(), 'autoload'));
|
||||
|
||||
|
@ -58,6 +99,8 @@ if (!class_exists('SimplePie'))
|
|||
*/
|
||||
class SimplePie_Autoloader
|
||||
{
|
||||
protected $path;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
|
@ -82,4 +125,4 @@ class SimplePie_Autoloader
|
|||
$filename = $this->path . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php';
|
||||
include $filename;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,51 +1,63 @@
|
|||
{
|
||||
"name": "simplepie/simplepie",
|
||||
"description": "A simple Atom/RSS parsing library for PHP",
|
||||
"type": "library",
|
||||
"keywords": ["rss", "atom", "feeds"],
|
||||
"homepage": "http://simplepie.org/",
|
||||
"license": "BSD-3-Clause",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Ryan Parman",
|
||||
"homepage": "http://ryanparman.com/",
|
||||
"role": "Creator, alumnus developer"
|
||||
},
|
||||
{
|
||||
"name": "Sam Sneddon",
|
||||
"homepage": "https://gsnedders.com/",
|
||||
"role": "Alumnus developer"
|
||||
},
|
||||
{
|
||||
"name": "Ryan McCue",
|
||||
"email": "me@ryanmccue.info",
|
||||
"homepage": "http://ryanmccue.info/",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.6.0",
|
||||
"ext-pcre": "*",
|
||||
"ext-xml": "*",
|
||||
"ext-xmlreader": "*"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "~5.4.3 || ~6.5"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-curl": "",
|
||||
"ext-iconv": "",
|
||||
"ext-intl": "",
|
||||
"ext-mbstring": "",
|
||||
"mf2/mf2": "Microformat module that allows for parsing HTML for microformats"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"SimplePie": "library"
|
||||
}
|
||||
"name": "simplepie/simplepie",
|
||||
"description": "A simple Atom/RSS parsing library for PHP",
|
||||
"type": "library",
|
||||
"keywords": ["rss", "atom", "feeds"],
|
||||
"homepage": "http://simplepie.org/",
|
||||
"license": "BSD-3-Clause",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Ryan Parman",
|
||||
"homepage": "http://ryanparman.com/",
|
||||
"role": "Creator, alumnus developer"
|
||||
},
|
||||
{
|
||||
"name": "Sam Sneddon",
|
||||
"homepage": "https://gsnedders.com/",
|
||||
"role": "Alumnus developer"
|
||||
},
|
||||
{
|
||||
"name": "Ryan McCue",
|
||||
"email": "me@ryanmccue.info",
|
||||
"homepage": "http://ryanmccue.info/",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=7.2.0",
|
||||
"ext-pcre": "*",
|
||||
"ext-xml": "*",
|
||||
"ext-xmlreader": "*"
|
||||
},
|
||||
"require-dev": {
|
||||
"friendsofphp/php-cs-fixer": "^2.19 || ^3.8",
|
||||
"psr/simple-cache": "^1 || ^2 || ^3",
|
||||
"yoast/phpunit-polyfills": "^1.0.1"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-curl": "",
|
||||
"ext-iconv": "",
|
||||
"ext-intl": "",
|
||||
"ext-mbstring": "",
|
||||
"mf2/mf2": "Microformat module that allows for parsing HTML for microformats"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"SimplePie\\": "src"
|
||||
},
|
||||
"psr-0": {
|
||||
"SimplePie": "library"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"SimplePie\\Tests\\Fixtures\\": "tests/Fixtures",
|
||||
"SimplePie\\Tests\\Unit\\": "tests/Unit"
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
"bin-dir": "bin"
|
||||
"bin-dir": "bin",
|
||||
"sort-packages": true
|
||||
},
|
||||
"scripts": {
|
||||
"test": "phpunit"
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,11 +1,13 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* 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
|
||||
* Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
|
@ -41,109 +43,15 @@
|
|||
* @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;
|
||||
use SimplePie\Author;
|
||||
|
||||
/**
|
||||
* Author's link
|
||||
*
|
||||
* @var string
|
||||
* @see get_link()
|
||||
*/
|
||||
var $link;
|
||||
class_exists('SimplePie\Author');
|
||||
|
||||
/**
|
||||
* Author's email address
|
||||
*
|
||||
* @var string
|
||||
* @see get_email()
|
||||
*/
|
||||
var $email;
|
||||
// @trigger_error(sprintf('Using the "SimplePie_Author" class is deprecated since SimplePie 1.7.0, use "SimplePie\Author" instead.'), \E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
if (\false) {
|
||||
/** @deprecated since SimplePie 1.7.0, use "SimplePie\Author" instead */
|
||||
class SimplePie_Author extends Author
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* 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
|
||||
* Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
|
@ -41,94 +43,15 @@
|
|||
* @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'
|
||||
);
|
||||
use SimplePie\Cache;
|
||||
|
||||
/**
|
||||
* Don't call the constructor. Please.
|
||||
*/
|
||||
private function __construct() { }
|
||||
class_exists('SimplePie\Cache');
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
// @trigger_error(sprintf('Using the "SimplePie_Cache" class is deprecated since SimplePie 1.7.0, use "SimplePie\Cache" instead.'), \E_USER_DEPRECATED);
|
||||
|
||||
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;
|
||||
}
|
||||
if (\false) {
|
||||
/** @deprecated since SimplePie 1.7.0, use "SimplePie\Cache" instead */
|
||||
class SimplePie_Cache extends Cache
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* 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
|
||||
* Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
|
@ -41,73 +43,15 @@
|
|||
* @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';
|
||||
use SimplePie\Cache\Base;
|
||||
|
||||
/**
|
||||
* Image cache type
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const TYPE_IMAGE = 'spi';
|
||||
interface_exists('SimplePie\Cache\Base');
|
||||
|
||||
/**
|
||||
* 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);
|
||||
// @trigger_error(sprintf('Using the "SimplePie_Cache_Base" class is deprecated since SimplePie 1.7.0, use "SimplePie\Cache\Base" instead.'), \E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* 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();
|
||||
if (\false) {
|
||||
/** @deprecated since SimplePie 1.7.0, use "SimplePie\Cache\Base" instead */
|
||||
interface SimplePie_Cache_Base extends Base
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* 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
|
||||
* Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
|
@ -41,96 +43,15 @@
|
|||
* @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();
|
||||
use SimplePie\Cache\DB;
|
||||
|
||||
if (!empty($items))
|
||||
{
|
||||
foreach ($items as $item)
|
||||
{
|
||||
$items_by_id[$item->get_id()] = $item;
|
||||
}
|
||||
class_exists('SimplePie\Cache\DB');
|
||||
|
||||
if (count($items_by_id) !== count($items))
|
||||
{
|
||||
$items_by_id = array();
|
||||
foreach ($items as $item)
|
||||
{
|
||||
$items_by_id[$item->get_id(true)] = $item;
|
||||
}
|
||||
}
|
||||
// @trigger_error(sprintf('Using the "SimplePie_Cache_DB" class is deprecated since SimplePie 1.7.0, use "SimplePie\Cache\DB" instead.'), \E_USER_DEPRECATED);
|
||||
|
||||
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);
|
||||
}
|
||||
if (\false) {
|
||||
/** @deprecated since SimplePie 1.7.0, use "SimplePie\Cache\DB" instead */
|
||||
abstract class SimplePie_Cache_DB extends DB
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* 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
|
||||
* Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
|
@ -41,124 +43,15 @@
|
|||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Caches data to the filesystem
|
||||
*
|
||||
* @package SimplePie
|
||||
* @subpackage Caching
|
||||
*/
|
||||
class SimplePie_Cache_File implements SimplePie_Cache_Base
|
||||
{
|
||||
/**
|
||||
* Location string
|
||||
*
|
||||
* @see SimplePie::$cache_location
|
||||
* @var string
|
||||
*/
|
||||
protected $location;
|
||||
use SimplePie\Cache\File;
|
||||
|
||||
/**
|
||||
* Filename
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $filename;
|
||||
class_exists('SimplePie\Cache\File');
|
||||
|
||||
/**
|
||||
* File extension
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $extension;
|
||||
// @trigger_error(sprintf('Using the "SimplePie_Cache_File" class is deprecated since SimplePie 1.7.0, use "SimplePie\Cache\File" instead.'), \E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* File path
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
$this->location = $location;
|
||||
$this->filename = $name;
|
||||
$this->extension = $type;
|
||||
$this->name = "$this->location/$this->filename.$this->extension";
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
if (file_exists($this->name) && is_writable($this->name) || file_exists($this->location) && is_writable($this->location))
|
||||
{
|
||||
if ($data instanceof SimplePie)
|
||||
{
|
||||
$data = $data->data;
|
||||
}
|
||||
|
||||
$data = serialize($data);
|
||||
return (bool) file_put_contents($this->name, $data);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the data saved to the cache
|
||||
*
|
||||
* @return array Data for SimplePie::$data
|
||||
*/
|
||||
public function load()
|
||||
{
|
||||
if (file_exists($this->name) && is_readable($this->name))
|
||||
{
|
||||
return unserialize(file_get_contents($this->name));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the last modified time for the cache
|
||||
*
|
||||
* @return int Timestamp
|
||||
*/
|
||||
public function mtime()
|
||||
{
|
||||
return @filemtime($this->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the last modified time to the current time
|
||||
*
|
||||
* @return bool Success status
|
||||
*/
|
||||
public function touch()
|
||||
{
|
||||
return @touch($this->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the cache
|
||||
*
|
||||
* @return bool Success status
|
||||
*/
|
||||
public function unlink()
|
||||
{
|
||||
if (file_exists($this->name))
|
||||
{
|
||||
return unlink($this->name);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (\false) {
|
||||
/** @deprecated since SimplePie 1.7.0, use "SimplePie\Cache\File" instead */
|
||||
class SimplePie_Cache_File extends File
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* 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
|
||||
* Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
|
@ -41,140 +43,15 @@
|
|||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Caches data to memcache
|
||||
*
|
||||
* Registered for URLs with the "memcache" protocol
|
||||
*
|
||||
* For example, `memcache://localhost:11211/?timeout=3600&prefix=sp_` will
|
||||
* connect to memcache on `localhost` on port 11211. All tables will be
|
||||
* prefixed with `sp_` and data will expire after 3600 seconds
|
||||
*
|
||||
* @package SimplePie
|
||||
* @subpackage Caching
|
||||
* @uses Memcache
|
||||
*/
|
||||
class SimplePie_Cache_Memcache implements SimplePie_Cache_Base
|
||||
{
|
||||
/**
|
||||
* Memcache instance
|
||||
*
|
||||
* @var Memcache
|
||||
*/
|
||||
protected $cache;
|
||||
use SimplePie\Cache\Memcache;
|
||||
|
||||
/**
|
||||
* Options
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options;
|
||||
class_exists('SimplePie\Cache\Memcache');
|
||||
|
||||
/**
|
||||
* Cache name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
// @trigger_error(sprintf('Using the "SimplePie_Cache_Memcache" class is deprecated since SimplePie 1.7.0, use "SimplePie\Cache\Memcache" instead.'), \E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
$this->options = array(
|
||||
'host' => '127.0.0.1',
|
||||
'port' => 11211,
|
||||
'extras' => array(
|
||||
'timeout' => 3600, // one hour
|
||||
'prefix' => 'simplepie_',
|
||||
),
|
||||
);
|
||||
$this->options = SimplePie_Misc::array_merge_recursive($this->options, SimplePie_Cache::parse_URL($location));
|
||||
|
||||
$this->name = $this->options['extras']['prefix'] . md5("$name:$type");
|
||||
|
||||
$this->cache = new Memcache();
|
||||
$this->cache->addServer($this->options['host'], (int) $this->options['port']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
if ($data instanceof SimplePie)
|
||||
{
|
||||
$data = $data->data;
|
||||
}
|
||||
return $this->cache->set($this->name, serialize($data), MEMCACHE_COMPRESSED, (int) $this->options['extras']['timeout']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the data saved to the cache
|
||||
*
|
||||
* @return array Data for SimplePie::$data
|
||||
*/
|
||||
public function load()
|
||||
{
|
||||
$data = $this->cache->get($this->name);
|
||||
|
||||
if ($data !== false)
|
||||
{
|
||||
return unserialize($data);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the last modified time for the cache
|
||||
*
|
||||
* @return int Timestamp
|
||||
*/
|
||||
public function mtime()
|
||||
{
|
||||
$data = $this->cache->get($this->name);
|
||||
|
||||
if ($data !== false)
|
||||
{
|
||||
// essentially ignore the mtime because Memcache expires on its own
|
||||
return time();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the last modified time to the current time
|
||||
*
|
||||
* @return bool Success status
|
||||
*/
|
||||
public function touch()
|
||||
{
|
||||
$data = $this->cache->get($this->name);
|
||||
|
||||
if ($data !== false)
|
||||
{
|
||||
return $this->cache->set($this->name, $data, MEMCACHE_COMPRESSED, (int) $this->options['extras']['timeout']);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the cache
|
||||
*
|
||||
* @return bool Success status
|
||||
*/
|
||||
public function unlink()
|
||||
{
|
||||
return $this->cache->delete($this->name, 0);
|
||||
}
|
||||
if (\false) {
|
||||
/** @deprecated since SimplePie 1.7.0, use "SimplePie\Cache\Memcache" instead */
|
||||
class SimplePie_Cache_Memcache extends Memcache
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* 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
|
||||
* Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
|
@ -41,126 +43,15 @@
|
|||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Caches data to memcached
|
||||
*
|
||||
* Registered for URLs with the "memcached" protocol
|
||||
*
|
||||
* For example, `memcached://localhost:11211/?timeout=3600&prefix=sp_` will
|
||||
* connect to memcached on `localhost` on port 11211. All tables will be
|
||||
* prefixed with `sp_` and data will expire after 3600 seconds
|
||||
*
|
||||
* @package SimplePie
|
||||
* @subpackage Caching
|
||||
* @author Paul L. McNeely
|
||||
* @uses Memcached
|
||||
*/
|
||||
class SimplePie_Cache_Memcached implements SimplePie_Cache_Base
|
||||
{
|
||||
/**
|
||||
* Memcached instance
|
||||
* @var Memcached
|
||||
*/
|
||||
protected $cache;
|
||||
use SimplePie\Cache\Memcached;
|
||||
|
||||
/**
|
||||
* Options
|
||||
* @var array
|
||||
*/
|
||||
protected $options;
|
||||
class_exists('SimplePie\Cache\Memcached');
|
||||
|
||||
/**
|
||||
* Cache name
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
// @trigger_error(sprintf('Using the "SimplePie_Cache_Memcached" class is deprecated since SimplePie 1.7.0, use "SimplePie\Cache\Memcached" instead.'), \E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
$this->options = array(
|
||||
'host' => '127.0.0.1',
|
||||
'port' => 11211,
|
||||
'extras' => array(
|
||||
'timeout' => 3600, // one hour
|
||||
'prefix' => 'simplepie_',
|
||||
),
|
||||
);
|
||||
$this->options = SimplePie_Misc::array_merge_recursive($this->options, SimplePie_Cache::parse_URL($location));
|
||||
|
||||
$this->name = $this->options['extras']['prefix'] . md5("$name:$type");
|
||||
|
||||
$this->cache = new Memcached();
|
||||
$this->cache->addServer($this->options['host'], (int)$this->options['port']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
if ($data instanceof SimplePie) {
|
||||
$data = $data->data;
|
||||
}
|
||||
|
||||
return $this->setData(serialize($data));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the data saved to the cache
|
||||
* @return array Data for SimplePie::$data
|
||||
*/
|
||||
public function load() {
|
||||
$data = $this->cache->get($this->name);
|
||||
|
||||
if ($data !== false) {
|
||||
return unserialize($data);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the last modified time for the cache
|
||||
* @return int Timestamp
|
||||
*/
|
||||
public function mtime() {
|
||||
$data = $this->cache->get($this->name . '_mtime');
|
||||
return (int) $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the last modified time to the current time
|
||||
* @return bool Success status
|
||||
*/
|
||||
public function touch() {
|
||||
$data = $this->cache->get($this->name);
|
||||
return $this->setData($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the cache
|
||||
* @return bool Success status
|
||||
*/
|
||||
public function unlink() {
|
||||
return $this->cache->delete($this->name, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the last modified time and data to Memcached
|
||||
* @return bool Success status
|
||||
*/
|
||||
private function setData($data) {
|
||||
|
||||
if ($data !== false) {
|
||||
$this->cache->set($this->name . '_mtime', time(), (int)$this->options['extras']['timeout']);
|
||||
return $this->cache->set($this->name, $data, (int)$this->options['extras']['timeout']);
|
||||
}
|
||||
|
||||
return false;
|
||||
if (\false) {
|
||||
/** @deprecated since SimplePie 1.7.0, use "SimplePie\Cache\Memcached" instead */
|
||||
class SimplePie_Cache_Memcached extends Memcached
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* 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
|
||||
* Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
|
@ -41,400 +43,15 @@
|
|||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Caches data to a MySQL database
|
||||
*
|
||||
* Registered for URLs with the "mysql" protocol
|
||||
*
|
||||
* For example, `mysql://root:password@localhost:3306/mydb?prefix=sp_` will
|
||||
* connect to the `mydb` database on `localhost` on port 3306, with the user
|
||||
* `root` and the password `password`. All tables will be prefixed with `sp_`
|
||||
*
|
||||
* @package SimplePie
|
||||
* @subpackage Caching
|
||||
*/
|
||||
class SimplePie_Cache_MySQL extends SimplePie_Cache_DB
|
||||
{
|
||||
/**
|
||||
* PDO instance
|
||||
*
|
||||
* @var PDO
|
||||
*/
|
||||
protected $mysql;
|
||||
use SimplePie\Cache\MySQL;
|
||||
|
||||
/**
|
||||
* Options
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options;
|
||||
class_exists('SimplePie\Cache\MySQL');
|
||||
|
||||
/**
|
||||
* Cache ID
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $id;
|
||||
// @trigger_error(sprintf('Using the "SimplePie_Cache_MySQL" class is deprecated since SimplePie 1.7.0, use "SimplePie\Cache\MySQL" instead.'), \E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
$this->options = array(
|
||||
'user' => null,
|
||||
'pass' => null,
|
||||
'host' => '127.0.0.1',
|
||||
'port' => '3306',
|
||||
'path' => '',
|
||||
'extras' => array(
|
||||
'prefix' => '',
|
||||
'cache_purge_time' => 2592000
|
||||
),
|
||||
);
|
||||
|
||||
$this->options = SimplePie_Misc::array_merge_recursive($this->options, SimplePie_Cache::parse_URL($location));
|
||||
|
||||
// Path is prefixed with a "/"
|
||||
$this->options['dbname'] = substr($this->options['path'], 1);
|
||||
|
||||
try
|
||||
{
|
||||
$this->mysql = new PDO("mysql:dbname={$this->options['dbname']};host={$this->options['host']};port={$this->options['port']}", $this->options['user'], $this->options['pass'], array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
|
||||
}
|
||||
catch (PDOException $e)
|
||||
{
|
||||
$this->mysql = null;
|
||||
return;
|
||||
}
|
||||
|
||||
$this->id = $name . $type;
|
||||
|
||||
if (!$query = $this->mysql->query('SHOW TABLES'))
|
||||
{
|
||||
$this->mysql = null;
|
||||
return;
|
||||
}
|
||||
|
||||
$db = array();
|
||||
while ($row = $query->fetchColumn())
|
||||
{
|
||||
$db[] = $row;
|
||||
}
|
||||
|
||||
if (!in_array($this->options['extras']['prefix'] . 'cache_data', $db))
|
||||
{
|
||||
$query = $this->mysql->exec('CREATE TABLE `' . $this->options['extras']['prefix'] . 'cache_data` (`id` TEXT CHARACTER SET utf8 NOT NULL, `items` SMALLINT NOT NULL DEFAULT 0, `data` BLOB NOT NULL, `mtime` INT UNSIGNED NOT NULL, UNIQUE (`id`(125)))');
|
||||
if ($query === false)
|
||||
{
|
||||
trigger_error("Can't create " . $this->options['extras']['prefix'] . "cache_data table, check permissions", E_USER_WARNING);
|
||||
$this->mysql = null;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!in_array($this->options['extras']['prefix'] . 'items', $db))
|
||||
{
|
||||
$query = $this->mysql->exec('CREATE TABLE `' . $this->options['extras']['prefix'] . 'items` (`feed_id` TEXT CHARACTER SET utf8 NOT NULL, `id` TEXT CHARACTER SET utf8 NOT NULL, `data` MEDIUMBLOB NOT NULL, `posted` INT UNSIGNED NOT NULL, INDEX `feed_id` (`feed_id`(125)))');
|
||||
if ($query === false)
|
||||
{
|
||||
trigger_error("Can't create " . $this->options['extras']['prefix'] . "items table, check permissions", E_USER_WARNING);
|
||||
$this->mysql = null;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
if ($this->mysql === null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$query = $this->mysql->prepare('DELETE i, cd FROM `' . $this->options['extras']['prefix'] . 'cache_data` cd, ' .
|
||||
'`' . $this->options['extras']['prefix'] . 'items` i ' .
|
||||
'WHERE cd.id = i.feed_id ' .
|
||||
'AND cd.mtime < (unix_timestamp() - :purge_time)');
|
||||
$query->bindValue(':purge_time', $this->options['extras']['cache_purge_time']);
|
||||
|
||||
if (!$query->execute())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($data instanceof SimplePie)
|
||||
{
|
||||
$data = clone $data;
|
||||
|
||||
$prepared = self::prepare_simplepie_object_for_cache($data);
|
||||
|
||||
$query = $this->mysql->prepare('SELECT COUNT(*) FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :feed');
|
||||
$query->bindValue(':feed', $this->id);
|
||||
if ($query->execute())
|
||||
{
|
||||
if ($query->fetchColumn() > 0)
|
||||
{
|
||||
$items = count($prepared[1]);
|
||||
if ($items)
|
||||
{
|
||||
$sql = 'UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `items` = :items, `data` = :data, `mtime` = :time WHERE `id` = :feed';
|
||||
$query = $this->mysql->prepare($sql);
|
||||
$query->bindValue(':items', $items);
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql = 'UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `data` = :data, `mtime` = :time WHERE `id` = :feed';
|
||||
$query = $this->mysql->prepare($sql);
|
||||
}
|
||||
|
||||
$query->bindValue(':data', $prepared[0]);
|
||||
$query->bindValue(':time', time());
|
||||
$query->bindValue(':feed', $this->id);
|
||||
if (!$query->execute())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$query = $this->mysql->prepare('INSERT INTO `' . $this->options['extras']['prefix'] . 'cache_data` (`id`, `items`, `data`, `mtime`) VALUES(:feed, :count, :data, :time)');
|
||||
$query->bindValue(':feed', $this->id);
|
||||
$query->bindValue(':count', count($prepared[1]));
|
||||
$query->bindValue(':data', $prepared[0]);
|
||||
$query->bindValue(':time', time());
|
||||
if (!$query->execute())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$ids = array_keys($prepared[1]);
|
||||
if (!empty($ids))
|
||||
{
|
||||
foreach ($ids as $id)
|
||||
{
|
||||
$database_ids[] = $this->mysql->quote($id);
|
||||
}
|
||||
|
||||
$query = $this->mysql->prepare('SELECT `id` FROM `' . $this->options['extras']['prefix'] . 'items` WHERE `id` = ' . implode(' OR `id` = ', $database_ids) . ' AND `feed_id` = :feed');
|
||||
$query->bindValue(':feed', $this->id);
|
||||
|
||||
if ($query->execute())
|
||||
{
|
||||
$existing_ids = array();
|
||||
while ($row = $query->fetchColumn())
|
||||
{
|
||||
$existing_ids[] = $row;
|
||||
}
|
||||
|
||||
$new_ids = array_diff($ids, $existing_ids);
|
||||
|
||||
foreach ($new_ids as $new_id)
|
||||
{
|
||||
if (!($date = $prepared[1][$new_id]->get_date('U')))
|
||||
{
|
||||
$date = time();
|
||||
}
|
||||
|
||||
$query = $this->mysql->prepare('INSERT INTO `' . $this->options['extras']['prefix'] . 'items` (`feed_id`, `id`, `data`, `posted`) VALUES(:feed, :id, :data, :date)');
|
||||
$query->bindValue(':feed', $this->id);
|
||||
$query->bindValue(':id', $new_id);
|
||||
$query->bindValue(':data', serialize($prepared[1][$new_id]->data));
|
||||
$query->bindValue(':date', $date);
|
||||
if (!$query->execute())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$query = $this->mysql->prepare('SELECT `id` FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :feed');
|
||||
$query->bindValue(':feed', $this->id);
|
||||
if ($query->execute())
|
||||
{
|
||||
if ($query->rowCount() > 0)
|
||||
{
|
||||
$query = $this->mysql->prepare('UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `items` = 0, `data` = :data, `mtime` = :time WHERE `id` = :feed');
|
||||
$query->bindValue(':data', serialize($data));
|
||||
$query->bindValue(':time', time());
|
||||
$query->bindValue(':feed', $this->id);
|
||||
if ($this->execute())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$query = $this->mysql->prepare('INSERT INTO `' . $this->options['extras']['prefix'] . 'cache_data` (`id`, `items`, `data`, `mtime`) VALUES(:id, 0, :data, :time)');
|
||||
$query->bindValue(':id', $this->id);
|
||||
$query->bindValue(':data', serialize($data));
|
||||
$query->bindValue(':time', time());
|
||||
if ($query->execute())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the data saved to the cache
|
||||
*
|
||||
* @return array Data for SimplePie::$data
|
||||
*/
|
||||
public function load()
|
||||
{
|
||||
if ($this->mysql === null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$query = $this->mysql->prepare('SELECT `items`, `data` FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :id');
|
||||
$query->bindValue(':id', $this->id);
|
||||
if ($query->execute() && ($row = $query->fetch()))
|
||||
{
|
||||
$data = unserialize($row[1]);
|
||||
|
||||
if (isset($this->options['items'][0]))
|
||||
{
|
||||
$items = (int) $this->options['items'][0];
|
||||
}
|
||||
else
|
||||
{
|
||||
$items = (int) $row[0];
|
||||
}
|
||||
|
||||
if ($items !== 0)
|
||||
{
|
||||
if (isset($data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]))
|
||||
{
|
||||
$feed =& $data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0];
|
||||
}
|
||||
elseif (isset($data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]))
|
||||
{
|
||||
$feed =& $data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0];
|
||||
}
|
||||
elseif (isset($data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]))
|
||||
{
|
||||
$feed =& $data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0];
|
||||
}
|
||||
elseif (isset($data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]))
|
||||
{
|
||||
$feed =& $data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0];
|
||||
}
|
||||
else
|
||||
{
|
||||
$feed = null;
|
||||
}
|
||||
|
||||
if ($feed !== null)
|
||||
{
|
||||
$sql = 'SELECT `data` FROM `' . $this->options['extras']['prefix'] . 'items` WHERE `feed_id` = :feed ORDER BY `posted` DESC';
|
||||
if ($items > 0)
|
||||
{
|
||||
$sql .= ' LIMIT ' . $items;
|
||||
}
|
||||
|
||||
$query = $this->mysql->prepare($sql);
|
||||
$query->bindValue(':feed', $this->id);
|
||||
if ($query->execute())
|
||||
{
|
||||
while ($row = $query->fetchColumn())
|
||||
{
|
||||
$feed['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['entry'][] = unserialize($row);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the last modified time for the cache
|
||||
*
|
||||
* @return int Timestamp
|
||||
*/
|
||||
public function mtime()
|
||||
{
|
||||
if ($this->mysql === null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$query = $this->mysql->prepare('SELECT `mtime` FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :id');
|
||||
$query->bindValue(':id', $this->id);
|
||||
if ($query->execute() && ($time = $query->fetchColumn()))
|
||||
{
|
||||
return $time;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the last modified time to the current time
|
||||
*
|
||||
* @return bool Success status
|
||||
*/
|
||||
public function touch()
|
||||
{
|
||||
if ($this->mysql === null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$query = $this->mysql->prepare('UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `mtime` = :time WHERE `id` = :id');
|
||||
$query->bindValue(':time', time());
|
||||
$query->bindValue(':id', $this->id);
|
||||
|
||||
return $query->execute() && $query->rowCount() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the cache
|
||||
*
|
||||
* @return bool Success status
|
||||
*/
|
||||
public function unlink()
|
||||
{
|
||||
if ($this->mysql === null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$query = $this->mysql->prepare('DELETE FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :id');
|
||||
$query->bindValue(':id', $this->id);
|
||||
$query2 = $this->mysql->prepare('DELETE FROM `' . $this->options['extras']['prefix'] . 'items` WHERE `feed_id` = :id');
|
||||
$query2->bindValue(':id', $this->id);
|
||||
|
||||
return $query->execute() && $query2->execute();
|
||||
}
|
||||
if (\false) {
|
||||
/** @deprecated since SimplePie 1.7.0, use "SimplePie\Cache\MySQL" instead */
|
||||
class SimplePie_Cache_MySQL extends MySQL
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SimplePie Redis Cache Extension
|
||||
*
|
||||
|
@ -10,163 +12,15 @@
|
|||
* @version 0.2.9
|
||||
*/
|
||||
|
||||
use SimplePie\Cache\Redis;
|
||||
|
||||
/**
|
||||
* Caches data to redis
|
||||
*
|
||||
* Registered for URLs with the "redis" protocol
|
||||
*
|
||||
* For example, `redis://localhost:6379/?timeout=3600&prefix=sp_&dbIndex=0` will
|
||||
* connect to redis on `localhost` on port 6379. All tables will be
|
||||
* prefixed with `simple_primary-` and data will expire after 3600 seconds
|
||||
*
|
||||
* @package SimplePie
|
||||
* @subpackage Caching
|
||||
* @uses Redis
|
||||
*/
|
||||
class SimplePie_Cache_Redis implements SimplePie_Cache_Base {
|
||||
/**
|
||||
* Redis instance
|
||||
*
|
||||
* @var \Redis
|
||||
*/
|
||||
protected $cache;
|
||||
class_exists('SimplePie\Cache\Redis');
|
||||
|
||||
/**
|
||||
* Options
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options;
|
||||
// @trigger_error(sprintf('Using the "SimplePie_Cache_Redis" class is deprecated since SimplePie 1.7.0, use "SimplePie\Cache\Redis" instead.'), \E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* Cache name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Cache Data
|
||||
*
|
||||
* @var type
|
||||
*/
|
||||
protected $data;
|
||||
|
||||
/**
|
||||
* 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, $options = null) {
|
||||
//$this->cache = \flow\simple\cache\Redis::getRedisClientInstance();
|
||||
$parsed = SimplePie_Cache::parse_URL($location);
|
||||
$redis = new Redis();
|
||||
$redis->connect($parsed['host'], $parsed['port']);
|
||||
if (isset($parsed['pass'])) {
|
||||
$redis->auth($parsed['pass']);
|
||||
}
|
||||
if (isset($parsed['path'])) {
|
||||
$redis->select((int)substr($parsed['path'], 1));
|
||||
}
|
||||
$this->cache = $redis;
|
||||
|
||||
if (!is_null($options) && is_array($options)) {
|
||||
$this->options = $options;
|
||||
} else {
|
||||
$this->options = array (
|
||||
'prefix' => 'rss:simple_primary:',
|
||||
'expire' => 0,
|
||||
);
|
||||
}
|
||||
|
||||
$this->name = $this->options['prefix'] . $name;
|
||||
if (\false) {
|
||||
/** @deprecated since SimplePie 1.7.0, use "SimplePie\Cache\Redis" instead */
|
||||
class SimplePie_Cache_Redis extends Redis
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Redis $cache
|
||||
*/
|
||||
public function setRedisClient(\Redis $cache) {
|
||||
$this->cache = $cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
if ($data instanceof SimplePie) {
|
||||
$data = $data->data;
|
||||
}
|
||||
$response = $this->cache->set($this->name, serialize($data));
|
||||
if ($this->options['expire']) {
|
||||
$this->cache->expire($this->name, $this->options['expire']);
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the data saved to the cache
|
||||
*
|
||||
* @return array Data for SimplePie::$data
|
||||
*/
|
||||
public function load() {
|
||||
$data = $this->cache->get($this->name);
|
||||
|
||||
if ($data !== false) {
|
||||
return unserialize($data);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the last modified time for the cache
|
||||
*
|
||||
* @return int Timestamp
|
||||
*/
|
||||
public function mtime() {
|
||||
|
||||
$data = $this->cache->get($this->name);
|
||||
|
||||
if ($data !== false) {
|
||||
return time();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the last modified time to the current time
|
||||
*
|
||||
* @return bool Success status
|
||||
*/
|
||||
public function touch() {
|
||||
|
||||
$data = $this->cache->get($this->name);
|
||||
|
||||
if ($data !== false) {
|
||||
$return = $this->cache->set($this->name, $data);
|
||||
if ($this->options['expire']) {
|
||||
return $this->cache->expire($this->name, $this->ttl);
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the cache
|
||||
*
|
||||
* @return bool Success status
|
||||
*/
|
||||
public function unlink() {
|
||||
return $this->cache->set($this->name, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* 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
|
||||
* Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
|
@ -41,158 +43,15 @@
|
|||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
*/
|
||||
|
||||
use SimplePie\Caption;
|
||||
|
||||
/**
|
||||
* Handles `<media:text>` captions as defined in Media RSS.
|
||||
*
|
||||
* Used by {@see SimplePie_Enclosure::get_caption()} and {@see SimplePie_Enclosure::get_captions()}
|
||||
*
|
||||
* This class can be overloaded with {@see SimplePie::set_caption_class()}
|
||||
*
|
||||
* @package SimplePie
|
||||
* @subpackage API
|
||||
*/
|
||||
class SimplePie_Caption
|
||||
{
|
||||
/**
|
||||
* Content type
|
||||
*
|
||||
* @var string
|
||||
* @see get_type()
|
||||
*/
|
||||
var $type;
|
||||
class_exists('SimplePie\Caption');
|
||||
|
||||
/**
|
||||
* Language
|
||||
*
|
||||
* @var string
|
||||
* @see get_language()
|
||||
*/
|
||||
var $lang;
|
||||
// @trigger_error(sprintf('Using the "SimplePie_Caption" class is deprecated since SimplePie 1.7.0, use "SimplePie\Caption" instead.'), \E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* Start time
|
||||
*
|
||||
* @var string
|
||||
* @see get_starttime()
|
||||
*/
|
||||
var $startTime;
|
||||
|
||||
/**
|
||||
* End time
|
||||
*
|
||||
* @var string
|
||||
* @see get_endtime()
|
||||
*/
|
||||
var $endTime;
|
||||
|
||||
/**
|
||||
* Caption text
|
||||
*
|
||||
* @var string
|
||||
* @see get_text()
|
||||
*/
|
||||
var $text;
|
||||
|
||||
/**
|
||||
* Constructor, used to input the data
|
||||
*
|
||||
* For documentation on all the parameters, see the corresponding
|
||||
* properties and their accessors
|
||||
*/
|
||||
public function __construct($type = null, $lang = null, $startTime = null, $endTime = null, $text = null)
|
||||
{
|
||||
$this->type = $type;
|
||||
$this->lang = $lang;
|
||||
$this->startTime = $startTime;
|
||||
$this->endTime = $endTime;
|
||||
$this->text = $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* String-ified version
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
// There is no $this->data here
|
||||
return md5(serialize($this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the end time
|
||||
*
|
||||
* @return string|null Time in the format 'hh:mm:ss.SSS'
|
||||
*/
|
||||
public function get_endtime()
|
||||
{
|
||||
if ($this->endTime !== null)
|
||||
{
|
||||
return $this->endTime;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the language
|
||||
*
|
||||
* @link http://tools.ietf.org/html/rfc3066
|
||||
* @return string|null Language code as per RFC 3066
|
||||
*/
|
||||
public function get_language()
|
||||
{
|
||||
if ($this->lang !== null)
|
||||
{
|
||||
return $this->lang;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the start time
|
||||
*
|
||||
* @return string|null Time in the format 'hh:mm:ss.SSS'
|
||||
*/
|
||||
public function get_starttime()
|
||||
{
|
||||
if ($this->startTime !== null)
|
||||
{
|
||||
return $this->startTime;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the text of the caption
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function get_text()
|
||||
{
|
||||
if ($this->text !== null)
|
||||
{
|
||||
return $this->text;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the content type (not MIME type)
|
||||
*
|
||||
* @return string|null Either 'text' or 'html'
|
||||
*/
|
||||
public function get_type()
|
||||
{
|
||||
if ($this->type !== null)
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
if (\false) {
|
||||
/** @deprecated since SimplePie 1.7.0, use "SimplePie\Caption" instead */
|
||||
class SimplePie_Caption extends Caption
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* 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
|
||||
* Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
|
@ -41,123 +43,15 @@
|
|||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Manages all category-related data
|
||||
*
|
||||
* Used by {@see SimplePie_Item::get_category()} and {@see SimplePie_Item::get_categories()}
|
||||
*
|
||||
* This class can be overloaded with {@see SimplePie::set_category_class()}
|
||||
*
|
||||
* @package SimplePie
|
||||
* @subpackage API
|
||||
*/
|
||||
class SimplePie_Category
|
||||
{
|
||||
/**
|
||||
* Category identifier
|
||||
*
|
||||
* @var string|null
|
||||
* @see get_term
|
||||
*/
|
||||
var $term;
|
||||
use SimplePie\Category;
|
||||
|
||||
/**
|
||||
* Categorization scheme identifier
|
||||
*
|
||||
* @var string|null
|
||||
* @see get_scheme()
|
||||
*/
|
||||
var $scheme;
|
||||
class_exists('SimplePie\Category');
|
||||
|
||||
/**
|
||||
* Human readable label
|
||||
*
|
||||
* @var string|null
|
||||
* @see get_label()
|
||||
*/
|
||||
var $label;
|
||||
// @trigger_error(sprintf('Using the "SimplePie_Category" class is deprecated since SimplePie 1.7.0, use "SimplePie\Category" instead.'), \E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* Category type
|
||||
*
|
||||
* category for <category>
|
||||
* subject for <dc:subject>
|
||||
*
|
||||
* @var string|null
|
||||
* @see get_type()
|
||||
*/
|
||||
var $type;
|
||||
|
||||
/**
|
||||
* Constructor, used to input the data
|
||||
*
|
||||
* @param string|null $term
|
||||
* @param string|null $scheme
|
||||
* @param string|null $label
|
||||
* @param string|null $type
|
||||
*/
|
||||
public function __construct($term = null, $scheme = null, $label = null, $type = null)
|
||||
{
|
||||
$this->term = $term;
|
||||
$this->scheme = $scheme;
|
||||
$this->label = $label;
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* String-ified version
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
// There is no $this->data here
|
||||
return md5(serialize($this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the category identifier
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function get_term()
|
||||
{
|
||||
return $this->term;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the categorization scheme identifier
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function get_scheme()
|
||||
{
|
||||
return $this->scheme;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the human readable label
|
||||
*
|
||||
* @param bool $strict
|
||||
* @return string|null
|
||||
*/
|
||||
public function get_label($strict = false)
|
||||
{
|
||||
if ($this->label === null && $strict !== true)
|
||||
{
|
||||
return $this->get_term();
|
||||
}
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the category type
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function get_type()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
if (\false) {
|
||||
/** @deprecated since SimplePie 1.7.0, use "SimplePie\Category" instead */
|
||||
class SimplePie_Category extends Category
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* 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
|
||||
* Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
|
@ -41,278 +43,15 @@
|
|||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
*/
|
||||
|
||||
use SimplePie\Content\Type\Sniffer;
|
||||
|
||||
/**
|
||||
* Content-type sniffing
|
||||
*
|
||||
* Based on the rules in http://tools.ietf.org/html/draft-abarth-mime-sniff-06
|
||||
*
|
||||
* This is used since we can't always trust Content-Type headers, and is based
|
||||
* upon the HTML5 parsing rules.
|
||||
*
|
||||
*
|
||||
* This class can be overloaded with {@see SimplePie::set_content_type_sniffer_class()}
|
||||
*
|
||||
* @package SimplePie
|
||||
* @subpackage HTTP
|
||||
*/
|
||||
class SimplePie_Content_Type_Sniffer
|
||||
{
|
||||
/**
|
||||
* File object
|
||||
*
|
||||
* @var SimplePie_File
|
||||
*/
|
||||
var $file;
|
||||
class_exists('SimplePie\Content\Type\Sniffer');
|
||||
|
||||
/**
|
||||
* Create an instance of the class with the input file
|
||||
*
|
||||
* @param SimplePie_Content_Type_Sniffer $file Input file
|
||||
*/
|
||||
public function __construct($file)
|
||||
{
|
||||
$this->file = $file;
|
||||
}
|
||||
// @trigger_error(sprintf('Using the "SimplePie_Content_Type_Sniffer" class is deprecated since SimplePie 1.7.0, use "SimplePie\Content\Type\Sniffer" instead.'), \E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* Get the Content-Type of the specified file
|
||||
*
|
||||
* @return string Actual Content-Type
|
||||
*/
|
||||
public function get_type()
|
||||
{
|
||||
if (isset($this->file->headers['content-type']))
|
||||
{
|
||||
if (!isset($this->file->headers['content-encoding'])
|
||||
&& ($this->file->headers['content-type'] === 'text/plain'
|
||||
|| $this->file->headers['content-type'] === 'text/plain; charset=ISO-8859-1'
|
||||
|| $this->file->headers['content-type'] === 'text/plain; charset=iso-8859-1'
|
||||
|| $this->file->headers['content-type'] === 'text/plain; charset=UTF-8'))
|
||||
{
|
||||
return $this->text_or_binary();
|
||||
}
|
||||
|
||||
if (($pos = strpos($this->file->headers['content-type'], ';')) !== false)
|
||||
{
|
||||
$official = substr($this->file->headers['content-type'], 0, $pos);
|
||||
}
|
||||
else
|
||||
{
|
||||
$official = $this->file->headers['content-type'];
|
||||
}
|
||||
$official = trim(strtolower($official));
|
||||
|
||||
if ($official === 'unknown/unknown'
|
||||
|| $official === 'application/unknown')
|
||||
{
|
||||
return $this->unknown();
|
||||
}
|
||||
elseif (substr($official, -4) === '+xml'
|
||||
|| $official === 'text/xml'
|
||||
|| $official === 'application/xml')
|
||||
{
|
||||
return $official;
|
||||
}
|
||||
elseif (substr($official, 0, 6) === 'image/')
|
||||
{
|
||||
if ($return = $this->image())
|
||||
{
|
||||
return $return;
|
||||
}
|
||||
|
||||
return $official;
|
||||
}
|
||||
elseif ($official === 'text/html')
|
||||
{
|
||||
return $this->feed_or_html();
|
||||
}
|
||||
|
||||
return $official;
|
||||
}
|
||||
|
||||
return $this->unknown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sniff text or binary
|
||||
*
|
||||
* @return string Actual Content-Type
|
||||
*/
|
||||
public function text_or_binary()
|
||||
{
|
||||
if (substr($this->file->body, 0, 2) === "\xFE\xFF"
|
||||
|| substr($this->file->body, 0, 2) === "\xFF\xFE"
|
||||
|| substr($this->file->body, 0, 4) === "\x00\x00\xFE\xFF"
|
||||
|| substr($this->file->body, 0, 3) === "\xEF\xBB\xBF")
|
||||
{
|
||||
return 'text/plain';
|
||||
}
|
||||
elseif (preg_match('/[\x00-\x08\x0E-\x1A\x1C-\x1F]/', $this->file->body))
|
||||
{
|
||||
return 'application/octet-stream';
|
||||
}
|
||||
|
||||
return 'text/plain';
|
||||
}
|
||||
|
||||
/**
|
||||
* Sniff unknown
|
||||
*
|
||||
* @return string Actual Content-Type
|
||||
*/
|
||||
public function unknown()
|
||||
{
|
||||
$ws = strspn($this->file->body, "\x09\x0A\x0B\x0C\x0D\x20");
|
||||
if (strtolower(substr($this->file->body, $ws, 14)) === '<!doctype html'
|
||||
|| strtolower(substr($this->file->body, $ws, 5)) === '<html'
|
||||
|| strtolower(substr($this->file->body, $ws, 7)) === '<script')
|
||||
{
|
||||
return 'text/html';
|
||||
}
|
||||
elseif (substr($this->file->body, 0, 5) === '%PDF-')
|
||||
{
|
||||
return 'application/pdf';
|
||||
}
|
||||
elseif (substr($this->file->body, 0, 11) === '%!PS-Adobe-')
|
||||
{
|
||||
return 'application/postscript';
|
||||
}
|
||||
elseif (substr($this->file->body, 0, 6) === 'GIF87a'
|
||||
|| substr($this->file->body, 0, 6) === 'GIF89a')
|
||||
{
|
||||
return 'image/gif';
|
||||
}
|
||||
elseif (substr($this->file->body, 0, 8) === "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A")
|
||||
{
|
||||
return 'image/png';
|
||||
}
|
||||
elseif (substr($this->file->body, 0, 3) === "\xFF\xD8\xFF")
|
||||
{
|
||||
return 'image/jpeg';
|
||||
}
|
||||
elseif (substr($this->file->body, 0, 2) === "\x42\x4D")
|
||||
{
|
||||
return 'image/bmp';
|
||||
}
|
||||
elseif (substr($this->file->body, 0, 4) === "\x00\x00\x01\x00")
|
||||
{
|
||||
return 'image/vnd.microsoft.icon';
|
||||
}
|
||||
|
||||
return $this->text_or_binary();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sniff images
|
||||
*
|
||||
* @return string Actual Content-Type
|
||||
*/
|
||||
public function image()
|
||||
{
|
||||
if (substr($this->file->body, 0, 6) === 'GIF87a'
|
||||
|| substr($this->file->body, 0, 6) === 'GIF89a')
|
||||
{
|
||||
return 'image/gif';
|
||||
}
|
||||
elseif (substr($this->file->body, 0, 8) === "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A")
|
||||
{
|
||||
return 'image/png';
|
||||
}
|
||||
elseif (substr($this->file->body, 0, 3) === "\xFF\xD8\xFF")
|
||||
{
|
||||
return 'image/jpeg';
|
||||
}
|
||||
elseif (substr($this->file->body, 0, 2) === "\x42\x4D")
|
||||
{
|
||||
return 'image/bmp';
|
||||
}
|
||||
elseif (substr($this->file->body, 0, 4) === "\x00\x00\x01\x00")
|
||||
{
|
||||
return 'image/vnd.microsoft.icon';
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sniff HTML
|
||||
*
|
||||
* @return string Actual Content-Type
|
||||
*/
|
||||
public function feed_or_html()
|
||||
{
|
||||
$len = strlen($this->file->body);
|
||||
$pos = strspn($this->file->body, "\x09\x0A\x0D\x20\xEF\xBB\xBF");
|
||||
|
||||
while ($pos < $len)
|
||||
{
|
||||
switch ($this->file->body[$pos])
|
||||
{
|
||||
case "\x09":
|
||||
case "\x0A":
|
||||
case "\x0D":
|
||||
case "\x20":
|
||||
$pos += strspn($this->file->body, "\x09\x0A\x0D\x20", $pos);
|
||||
continue 2;
|
||||
|
||||
case '<':
|
||||
$pos++;
|
||||
break;
|
||||
|
||||
default:
|
||||
return 'text/html';
|
||||
}
|
||||
|
||||
if (substr($this->file->body, $pos, 3) === '!--')
|
||||
{
|
||||
$pos += 3;
|
||||
if ($pos < $len && ($pos = strpos($this->file->body, '-->', $pos)) !== false)
|
||||
{
|
||||
$pos += 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 'text/html';
|
||||
}
|
||||
}
|
||||
elseif (substr($this->file->body, $pos, 1) === '!')
|
||||
{
|
||||
if ($pos < $len && ($pos = strpos($this->file->body, '>', $pos)) !== false)
|
||||
{
|
||||
$pos++;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 'text/html';
|
||||
}
|
||||
}
|
||||
elseif (substr($this->file->body, $pos, 1) === '?')
|
||||
{
|
||||
if ($pos < $len && ($pos = strpos($this->file->body, '?>', $pos)) !== false)
|
||||
{
|
||||
$pos += 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 'text/html';
|
||||
}
|
||||
}
|
||||
elseif (substr($this->file->body, $pos, 3) === 'rss'
|
||||
|| substr($this->file->body, $pos, 7) === 'rdf:RDF')
|
||||
{
|
||||
return 'application/rss+xml';
|
||||
}
|
||||
elseif (substr($this->file->body, $pos, 4) === 'feed')
|
||||
{
|
||||
return 'application/atom+xml';
|
||||
}
|
||||
else
|
||||
{
|
||||
return 'text/html';
|
||||
}
|
||||
}
|
||||
|
||||
return 'text/html';
|
||||
}
|
||||
if (\false) {
|
||||
/** @deprecated since SimplePie 1.7.0, use "SimplePie\Content\Type\Sniffer" instead */
|
||||
class SimplePie_Content_Type_Sniffer extends Sniffer
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* 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
|
||||
* Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
|
@ -41,84 +43,15 @@
|
|||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Manages `<media:copyright>` copyright tags as defined in Media RSS
|
||||
*
|
||||
* Used by {@see SimplePie_Enclosure::get_copyright()}
|
||||
*
|
||||
* This class can be overloaded with {@see SimplePie::set_copyright_class()}
|
||||
*
|
||||
* @package SimplePie
|
||||
* @subpackage API
|
||||
*/
|
||||
class SimplePie_Copyright
|
||||
{
|
||||
/**
|
||||
* Copyright URL
|
||||
*
|
||||
* @var string
|
||||
* @see get_url()
|
||||
*/
|
||||
var $url;
|
||||
use SimplePie\Copyright;
|
||||
|
||||
/**
|
||||
* Attribution
|
||||
*
|
||||
* @var string
|
||||
* @see get_attribution()
|
||||
*/
|
||||
var $label;
|
||||
class_exists('SimplePie\Copyright');
|
||||
|
||||
/**
|
||||
* Constructor, used to input the data
|
||||
*
|
||||
* For documentation on all the parameters, see the corresponding
|
||||
* properties and their accessors
|
||||
*/
|
||||
public function __construct($url = null, $label = null)
|
||||
{
|
||||
$this->url = $url;
|
||||
$this->label = $label;
|
||||
}
|
||||
// @trigger_error(sprintf('Using the "SimplePie_Copyright" class is deprecated since SimplePie 1.7.0, use "SimplePie\Copyright" instead.'), \E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* String-ified version
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
// There is no $this->data here
|
||||
return md5(serialize($this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the copyright URL
|
||||
*
|
||||
* @return string|null URL to copyright information
|
||||
*/
|
||||
public function get_url()
|
||||
{
|
||||
if ($this->url !== null)
|
||||
{
|
||||
return $this->url;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the attribution text
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function get_attribution()
|
||||
{
|
||||
if ($this->label !== null)
|
||||
{
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
if (\false) {
|
||||
/** @deprecated since SimplePie 1.7.0, use "SimplePie\Copyright" instead */
|
||||
class SimplePie_Copyright extends Copyright
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* 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
|
||||
* Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
|
@ -52,5 +54,4 @@
|
|||
*/
|
||||
class SimplePie_Core extends SimplePie
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* 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
|
||||
* Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
|
@ -41,108 +43,15 @@
|
|||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Handles `<media:credit>` as defined in Media RSS
|
||||
*
|
||||
* Used by {@see SimplePie_Enclosure::get_credit()} and {@see SimplePie_Enclosure::get_credits()}
|
||||
*
|
||||
* This class can be overloaded with {@see SimplePie::set_credit_class()}
|
||||
*
|
||||
* @package SimplePie
|
||||
* @subpackage API
|
||||
*/
|
||||
class SimplePie_Credit
|
||||
{
|
||||
/**
|
||||
* Credited role
|
||||
*
|
||||
* @var string
|
||||
* @see get_role()
|
||||
*/
|
||||
var $role;
|
||||
use SimplePie\Credit;
|
||||
|
||||
/**
|
||||
* Organizational scheme
|
||||
*
|
||||
* @var string
|
||||
* @see get_scheme()
|
||||
*/
|
||||
var $scheme;
|
||||
class_exists('SimplePie\Credit');
|
||||
|
||||
/**
|
||||
* Credited name
|
||||
*
|
||||
* @var string
|
||||
* @see get_name()
|
||||
*/
|
||||
var $name;
|
||||
// @trigger_error(sprintf('Using the "SimplePie_Credit" class is deprecated since SimplePie 1.7.0, use "SimplePie\Credit" instead.'), \E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* Constructor, used to input the data
|
||||
*
|
||||
* For documentation on all the parameters, see the corresponding
|
||||
* properties and their accessors
|
||||
*/
|
||||
public function __construct($role = null, $scheme = null, $name = null)
|
||||
{
|
||||
$this->role = $role;
|
||||
$this->scheme = $scheme;
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* String-ified version
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
// There is no $this->data here
|
||||
return md5(serialize($this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the role of the person receiving credit
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function get_role()
|
||||
{
|
||||
if ($this->role !== null)
|
||||
{
|
||||
return $this->role;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the organizational scheme
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function get_scheme()
|
||||
{
|
||||
if ($this->scheme !== null)
|
||||
{
|
||||
return $this->scheme;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the credited person/entity's name
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function get_name()
|
||||
{
|
||||
if ($this->name !== null)
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
if (\false) {
|
||||
/** @deprecated since SimplePie 1.7.0, use "SimplePie\Credit" instead */
|
||||
class SimplePie_Credit extends Credit
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -1,11 +1,13 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* 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
|
||||
* Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
|
@ -41,11 +43,15 @@
|
|||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
*/
|
||||
|
||||
/**
|
||||
* General SimplePie exception class
|
||||
*
|
||||
* @package SimplePie
|
||||
*/
|
||||
class SimplePie_Exception extends Exception
|
||||
{
|
||||
}
|
||||
use SimplePie\Exception as SimplePieException;
|
||||
|
||||
class_exists('SimplePie\Exception');
|
||||
|
||||
// @trigger_error(sprintf('Using the "SimplePie_Exception" class is deprecated since SimplePie 1.7.0, use "SimplePie\Exception" instead.'), \E_USER_DEPRECATED);
|
||||
|
||||
if (\false) {
|
||||
/** @deprecated since SimplePie 1.7.0, use "SimplePie\Exception" instead */
|
||||
class SimplePie_Exception extends SimplePieException
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* 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
|
||||
* Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
|
@ -41,260 +43,15 @@
|
|||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Used for fetching remote files and reading local files
|
||||
*
|
||||
* Supports HTTP 1.0 via cURL or fsockopen, with spotty HTTP 1.1 support
|
||||
*
|
||||
* This class can be overloaded with {@see SimplePie::set_file_class()}
|
||||
*
|
||||
* @package SimplePie
|
||||
* @subpackage HTTP
|
||||
* @todo Move to properly supporting RFC2616 (HTTP/1.1)
|
||||
*/
|
||||
class SimplePie_File
|
||||
{
|
||||
var $url;
|
||||
var $useragent;
|
||||
var $success = true;
|
||||
var $headers = array();
|
||||
var $body;
|
||||
var $status_code;
|
||||
var $redirects = 0;
|
||||
var $error;
|
||||
var $method = SIMPLEPIE_FILE_SOURCE_NONE;
|
||||
var $permanent_url;
|
||||
use SimplePie\File;
|
||||
|
||||
public function __construct($url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null, $force_fsockopen = false, $curl_options = array())
|
||||
{
|
||||
if (class_exists('idna_convert'))
|
||||
{
|
||||
$idn = new idna_convert();
|
||||
$parsed = SimplePie_Misc::parse_url($url);
|
||||
$url = SimplePie_Misc::compress_parse_url($parsed['scheme'], $idn->encode($parsed['authority']), $parsed['path'], $parsed['query'], NULL);
|
||||
}
|
||||
$this->url = $url;
|
||||
$this->permanent_url = $url;
|
||||
$this->useragent = $useragent;
|
||||
if (preg_match('/^http(s)?:\/\//i', $url))
|
||||
{
|
||||
if ($useragent === null)
|
||||
{
|
||||
$useragent = ini_get('user_agent');
|
||||
$this->useragent = $useragent;
|
||||
}
|
||||
if (!is_array($headers))
|
||||
{
|
||||
$headers = array();
|
||||
}
|
||||
if (!$force_fsockopen && function_exists('curl_exec'))
|
||||
{
|
||||
$this->method = SIMPLEPIE_FILE_SOURCE_REMOTE | SIMPLEPIE_FILE_SOURCE_CURL;
|
||||
$fp = curl_init();
|
||||
$headers2 = array();
|
||||
foreach ($headers as $key => $value)
|
||||
{
|
||||
$headers2[] = "$key: $value";
|
||||
}
|
||||
if (version_compare(SimplePie_Misc::get_curl_version(), '7.10.5', '>='))
|
||||
{
|
||||
curl_setopt($fp, CURLOPT_ENCODING, '');
|
||||
}
|
||||
curl_setopt($fp, CURLOPT_URL, $url);
|
||||
curl_setopt($fp, CURLOPT_HEADER, 1);
|
||||
curl_setopt($fp, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($fp, CURLOPT_FAILONERROR, 1);
|
||||
curl_setopt($fp, CURLOPT_TIMEOUT, $timeout);
|
||||
curl_setopt($fp, CURLOPT_CONNECTTIMEOUT, $timeout);
|
||||
curl_setopt($fp, CURLOPT_REFERER, $url);
|
||||
curl_setopt($fp, CURLOPT_USERAGENT, $useragent);
|
||||
curl_setopt($fp, CURLOPT_HTTPHEADER, $headers2);
|
||||
foreach ($curl_options as $curl_param => $curl_value) {
|
||||
curl_setopt($fp, $curl_param, $curl_value);
|
||||
}
|
||||
class_exists('SimplePie\File');
|
||||
|
||||
$this->headers = curl_exec($fp);
|
||||
if (curl_errno($fp) === 23 || curl_errno($fp) === 61)
|
||||
{
|
||||
curl_setopt($fp, CURLOPT_ENCODING, 'none');
|
||||
$this->headers = curl_exec($fp);
|
||||
}
|
||||
if (curl_errno($fp))
|
||||
{
|
||||
$this->error = 'cURL error ' . curl_errno($fp) . ': ' . curl_error($fp);
|
||||
$this->success = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Use the updated url provided by curl_getinfo after any redirects.
|
||||
if ($info = curl_getinfo($fp)) {
|
||||
$this->url = $info['url'];
|
||||
}
|
||||
curl_close($fp);
|
||||
$this->headers = SimplePie_HTTP_Parser::prepareHeaders($this->headers, $info['redirect_count'] + 1);
|
||||
$parser = new SimplePie_HTTP_Parser($this->headers);
|
||||
if ($parser->parse())
|
||||
{
|
||||
$this->headers = $parser->headers;
|
||||
$this->body = trim($parser->body);
|
||||
$this->status_code = $parser->status_code;
|
||||
if ((in_array($this->status_code, array(300, 301, 302, 303, 307)) || $this->status_code > 307 && $this->status_code < 400) && isset($this->headers['location']) && $this->redirects < $redirects)
|
||||
{
|
||||
$this->redirects++;
|
||||
$location = SimplePie_Misc::absolutize_url($this->headers['location'], $url);
|
||||
$previousStatusCode = $this->status_code;
|
||||
$this->__construct($location, $timeout, $redirects, $headers, $useragent, $force_fsockopen, $curl_options);
|
||||
$this->permanent_url = ($previousStatusCode == 301) ? $location : $url;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->method = SIMPLEPIE_FILE_SOURCE_REMOTE | SIMPLEPIE_FILE_SOURCE_FSOCKOPEN;
|
||||
$url_parts = parse_url($url);
|
||||
$socket_host = $url_parts['host'];
|
||||
if (isset($url_parts['scheme']) && strtolower($url_parts['scheme']) === 'https')
|
||||
{
|
||||
$socket_host = "ssl://$url_parts[host]";
|
||||
$url_parts['port'] = 443;
|
||||
}
|
||||
if (!isset($url_parts['port']))
|
||||
{
|
||||
$url_parts['port'] = 80;
|
||||
}
|
||||
$fp = @fsockopen($socket_host, $url_parts['port'], $errno, $errstr, $timeout);
|
||||
if (!$fp)
|
||||
{
|
||||
$this->error = 'fsockopen error: ' . $errstr;
|
||||
$this->success = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
stream_set_timeout($fp, $timeout);
|
||||
if (isset($url_parts['path']))
|
||||
{
|
||||
if (isset($url_parts['query']))
|
||||
{
|
||||
$get = "$url_parts[path]?$url_parts[query]";
|
||||
}
|
||||
else
|
||||
{
|
||||
$get = $url_parts['path'];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$get = '/';
|
||||
}
|
||||
$out = "GET $get HTTP/1.1\r\n";
|
||||
$out .= "Host: $url_parts[host]\r\n";
|
||||
$out .= "User-Agent: $useragent\r\n";
|
||||
if (extension_loaded('zlib'))
|
||||
{
|
||||
$out .= "Accept-Encoding: x-gzip,gzip,deflate\r\n";
|
||||
}
|
||||
// @trigger_error(sprintf('Using the "SimplePie_File" class is deprecated since SimplePie 1.7.0, use "SimplePie\File" instead.'), \E_USER_DEPRECATED);
|
||||
|
||||
if (isset($url_parts['user']) && isset($url_parts['pass']))
|
||||
{
|
||||
$out .= "Authorization: Basic " . base64_encode("$url_parts[user]:$url_parts[pass]") . "\r\n";
|
||||
}
|
||||
foreach ($headers as $key => $value)
|
||||
{
|
||||
$out .= "$key: $value\r\n";
|
||||
}
|
||||
$out .= "Connection: Close\r\n\r\n";
|
||||
fwrite($fp, $out);
|
||||
|
||||
$info = stream_get_meta_data($fp);
|
||||
|
||||
$this->headers = '';
|
||||
while (!$info['eof'] && !$info['timed_out'])
|
||||
{
|
||||
$this->headers .= fread($fp, 1160);
|
||||
$info = stream_get_meta_data($fp);
|
||||
}
|
||||
if (!$info['timed_out'])
|
||||
{
|
||||
$parser = new SimplePie_HTTP_Parser($this->headers);
|
||||
if ($parser->parse())
|
||||
{
|
||||
$this->headers = $parser->headers;
|
||||
$this->body = $parser->body;
|
||||
$this->status_code = $parser->status_code;
|
||||
if ((in_array($this->status_code, array(300, 301, 302, 303, 307)) || $this->status_code > 307 && $this->status_code < 400) && isset($this->headers['location']) && $this->redirects < $redirects)
|
||||
{
|
||||
$this->redirects++;
|
||||
$location = SimplePie_Misc::absolutize_url($this->headers['location'], $url);
|
||||
$previousStatusCode = $this->status_code;
|
||||
$this->__construct($location, $timeout, $redirects, $headers, $useragent, $force_fsockopen, $curl_options);
|
||||
$this->permanent_url = ($previousStatusCode == 301) ? $location : $url;
|
||||
return;
|
||||
}
|
||||
if (isset($this->headers['content-encoding']))
|
||||
{
|
||||
// Hey, we act dumb elsewhere, so let's do that here too
|
||||
switch (strtolower(trim($this->headers['content-encoding'], "\x09\x0A\x0D\x20")))
|
||||
{
|
||||
case 'gzip':
|
||||
case 'x-gzip':
|
||||
$decoder = new SimplePie_gzdecode($this->body);
|
||||
if (!$decoder->parse())
|
||||
{
|
||||
$this->error = 'Unable to decode HTTP "gzip" stream';
|
||||
$this->success = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->body = trim($decoder->data);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'deflate':
|
||||
if (($decompressed = gzinflate($this->body)) !== false)
|
||||
{
|
||||
$this->body = $decompressed;
|
||||
}
|
||||
else if (($decompressed = gzuncompress($this->body)) !== false)
|
||||
{
|
||||
$this->body = $decompressed;
|
||||
}
|
||||
else if (function_exists('gzdecode') && ($decompressed = gzdecode($this->body)) !== false)
|
||||
{
|
||||
$this->body = $decompressed;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error = 'Unable to decode HTTP "deflate" stream';
|
||||
$this->success = false;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
$this->error = 'Unknown content coding';
|
||||
$this->success = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error = 'fsocket timed out';
|
||||
$this->success = false;
|
||||
}
|
||||
fclose($fp);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->method = SIMPLEPIE_FILE_SOURCE_LOCAL | SIMPLEPIE_FILE_SOURCE_FILE_GET_CONTENTS;
|
||||
if (empty($url) || !($this->body = trim(file_get_contents($url))))
|
||||
{
|
||||
$this->error = 'file_get_contents could not read the file';
|
||||
$this->success = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (\false) {
|
||||
/** @deprecated since SimplePie 1.7.0, use "SimplePie\File" instead */
|
||||
class SimplePie_File extends File
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* 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
|
||||
* Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
|
@ -41,478 +43,15 @@
|
|||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
*/
|
||||
|
||||
use SimplePie\HTTP\Parser;
|
||||
|
||||
/**
|
||||
* HTTP Response Parser
|
||||
*
|
||||
* @package SimplePie
|
||||
* @subpackage HTTP
|
||||
*/
|
||||
class SimplePie_HTTP_Parser
|
||||
{
|
||||
/**
|
||||
* HTTP Version
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
public $http_version = 0.0;
|
||||
class_exists('SimplePie\HTTP\Parser');
|
||||
|
||||
/**
|
||||
* Status code
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $status_code = 0;
|
||||
// @trigger_error(sprintf('Using the "SimplePie_HTTP_Parser" class is deprecated since SimplePie 1.7.0, use "SimplePie\HTTP\Parser" instead.'), \E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $reason = '';
|
||||
|
||||
/**
|
||||
* Key/value pairs of the headers
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $headers = array();
|
||||
|
||||
/**
|
||||
* Body of the response
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $body = '';
|
||||
|
||||
/**
|
||||
* Current state of the state machine
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $state = 'http_version';
|
||||
|
||||
/**
|
||||
* Input data
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $data = '';
|
||||
|
||||
/**
|
||||
* Input data length (to avoid calling strlen() everytime this is needed)
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $data_length = 0;
|
||||
|
||||
/**
|
||||
* Current position of the pointer
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $position = 0;
|
||||
|
||||
/**
|
||||
* Name of the hedaer currently being parsed
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = '';
|
||||
|
||||
/**
|
||||
* Value of the hedaer currently being parsed
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $value = '';
|
||||
|
||||
/**
|
||||
* Create an instance of the class with the input data
|
||||
*
|
||||
* @param string $data Input data
|
||||
*/
|
||||
public function __construct($data)
|
||||
{
|
||||
$this->data = $data;
|
||||
$this->data_length = strlen($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the input data
|
||||
*
|
||||
* @return bool true on success, false on failure
|
||||
*/
|
||||
public function parse()
|
||||
{
|
||||
while ($this->state && $this->state !== 'emit' && $this->has_data())
|
||||
{
|
||||
$state = $this->state;
|
||||
$this->$state();
|
||||
}
|
||||
$this->data = '';
|
||||
if ($this->state === 'emit' || $this->state === 'body')
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->http_version = '';
|
||||
$this->status_code = '';
|
||||
$this->reason = '';
|
||||
$this->headers = array();
|
||||
$this->body = '';
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether there is data beyond the pointer
|
||||
*
|
||||
* @return bool true if there is further data, false if not
|
||||
*/
|
||||
protected function has_data()
|
||||
{
|
||||
return (bool) ($this->position < $this->data_length);
|
||||
}
|
||||
|
||||
/**
|
||||
* See if the next character is LWS
|
||||
*
|
||||
* @return bool true if the next character is LWS, false if not
|
||||
*/
|
||||
protected function is_linear_whitespace()
|
||||
{
|
||||
return (bool) ($this->data[$this->position] === "\x09"
|
||||
|| $this->data[$this->position] === "\x20"
|
||||
|| ($this->data[$this->position] === "\x0A"
|
||||
&& isset($this->data[$this->position + 1])
|
||||
&& ($this->data[$this->position + 1] === "\x09" || $this->data[$this->position + 1] === "\x20")));
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the HTTP version
|
||||
*/
|
||||
protected function http_version()
|
||||
{
|
||||
if (strpos($this->data, "\x0A") !== false && strtoupper(substr($this->data, 0, 5)) === 'HTTP/')
|
||||
{
|
||||
$len = strspn($this->data, '0123456789.', 5);
|
||||
$this->http_version = substr($this->data, 5, $len);
|
||||
$this->position += 5 + $len;
|
||||
if (substr_count($this->http_version, '.') <= 1)
|
||||
{
|
||||
$this->http_version = (float) $this->http_version;
|
||||
$this->position += strspn($this->data, "\x09\x20", $this->position);
|
||||
$this->state = 'status';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->state = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->state = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the status code
|
||||
*/
|
||||
protected function status()
|
||||
{
|
||||
if ($len = strspn($this->data, '0123456789', $this->position))
|
||||
{
|
||||
$this->status_code = (int) substr($this->data, $this->position, $len);
|
||||
$this->position += $len;
|
||||
$this->state = 'reason';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->state = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the reason phrase
|
||||
*/
|
||||
protected function reason()
|
||||
{
|
||||
$len = strcspn($this->data, "\x0A", $this->position);
|
||||
$this->reason = trim(substr($this->data, $this->position, $len), "\x09\x0D\x20");
|
||||
$this->position += $len + 1;
|
||||
$this->state = 'new_line';
|
||||
}
|
||||
|
||||
/**
|
||||
* Deal with a new line, shifting data around as needed
|
||||
*/
|
||||
protected function new_line()
|
||||
{
|
||||
$this->value = trim($this->value, "\x0D\x20");
|
||||
if ($this->name !== '' && $this->value !== '')
|
||||
{
|
||||
$this->name = strtolower($this->name);
|
||||
// We should only use the last Content-Type header. c.f. issue #1
|
||||
if (isset($this->headers[$this->name]) && $this->name !== 'content-type')
|
||||
{
|
||||
$this->headers[$this->name] .= ', ' . $this->value;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->headers[$this->name] = $this->value;
|
||||
}
|
||||
}
|
||||
$this->name = '';
|
||||
$this->value = '';
|
||||
if (substr($this->data[$this->position], 0, 2) === "\x0D\x0A")
|
||||
{
|
||||
$this->position += 2;
|
||||
$this->state = 'body';
|
||||
}
|
||||
elseif ($this->data[$this->position] === "\x0A")
|
||||
{
|
||||
$this->position++;
|
||||
$this->state = 'body';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->state = 'name';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a header name
|
||||
*/
|
||||
protected function name()
|
||||
{
|
||||
$len = strcspn($this->data, "\x0A:", $this->position);
|
||||
if (isset($this->data[$this->position + $len]))
|
||||
{
|
||||
if ($this->data[$this->position + $len] === "\x0A")
|
||||
{
|
||||
$this->position += $len;
|
||||
$this->state = 'new_line';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->name = substr($this->data, $this->position, $len);
|
||||
$this->position += $len + 1;
|
||||
$this->state = 'value';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->state = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse LWS, replacing consecutive LWS characters with a single space
|
||||
*/
|
||||
protected function linear_whitespace()
|
||||
{
|
||||
do
|
||||
{
|
||||
if (substr($this->data, $this->position, 2) === "\x0D\x0A")
|
||||
{
|
||||
$this->position += 2;
|
||||
}
|
||||
elseif ($this->data[$this->position] === "\x0A")
|
||||
{
|
||||
$this->position++;
|
||||
}
|
||||
$this->position += strspn($this->data, "\x09\x20", $this->position);
|
||||
} while ($this->has_data() && $this->is_linear_whitespace());
|
||||
$this->value .= "\x20";
|
||||
}
|
||||
|
||||
/**
|
||||
* See what state to move to while within non-quoted header values
|
||||
*/
|
||||
protected function value()
|
||||
{
|
||||
if ($this->is_linear_whitespace())
|
||||
{
|
||||
$this->linear_whitespace();
|
||||
}
|
||||
else
|
||||
{
|
||||
switch ($this->data[$this->position])
|
||||
{
|
||||
case '"':
|
||||
// Workaround for ETags: we have to include the quotes as
|
||||
// part of the tag.
|
||||
if (strtolower($this->name) === 'etag')
|
||||
{
|
||||
$this->value .= '"';
|
||||
$this->position++;
|
||||
$this->state = 'value_char';
|
||||
break;
|
||||
}
|
||||
$this->position++;
|
||||
$this->state = 'quote';
|
||||
break;
|
||||
|
||||
case "\x0A":
|
||||
$this->position++;
|
||||
$this->state = 'new_line';
|
||||
break;
|
||||
|
||||
default:
|
||||
$this->state = 'value_char';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a header value while outside quotes
|
||||
*/
|
||||
protected function value_char()
|
||||
{
|
||||
$len = strcspn($this->data, "\x09\x20\x0A\"", $this->position);
|
||||
$this->value .= substr($this->data, $this->position, $len);
|
||||
$this->position += $len;
|
||||
$this->state = 'value';
|
||||
}
|
||||
|
||||
/**
|
||||
* See what state to move to while within quoted header values
|
||||
*/
|
||||
protected function quote()
|
||||
{
|
||||
if ($this->is_linear_whitespace())
|
||||
{
|
||||
$this->linear_whitespace();
|
||||
}
|
||||
else
|
||||
{
|
||||
switch ($this->data[$this->position])
|
||||
{
|
||||
case '"':
|
||||
$this->position++;
|
||||
$this->state = 'value';
|
||||
break;
|
||||
|
||||
case "\x0A":
|
||||
$this->position++;
|
||||
$this->state = 'new_line';
|
||||
break;
|
||||
|
||||
case '\\':
|
||||
$this->position++;
|
||||
$this->state = 'quote_escaped';
|
||||
break;
|
||||
|
||||
default:
|
||||
$this->state = 'quote_char';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a header value while within quotes
|
||||
*/
|
||||
protected function quote_char()
|
||||
{
|
||||
$len = strcspn($this->data, "\x09\x20\x0A\"\\", $this->position);
|
||||
$this->value .= substr($this->data, $this->position, $len);
|
||||
$this->position += $len;
|
||||
$this->state = 'value';
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse an escaped character within quotes
|
||||
*/
|
||||
protected function quote_escaped()
|
||||
{
|
||||
$this->value .= $this->data[$this->position];
|
||||
$this->position++;
|
||||
$this->state = 'quote';
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the body
|
||||
*/
|
||||
protected function body()
|
||||
{
|
||||
$this->body = substr($this->data, $this->position);
|
||||
if (!empty($this->headers['transfer-encoding']))
|
||||
{
|
||||
unset($this->headers['transfer-encoding']);
|
||||
$this->state = 'chunked';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->state = 'emit';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parsed a "Transfer-Encoding: chunked" body
|
||||
*/
|
||||
protected function chunked()
|
||||
{
|
||||
if (!preg_match('/^([0-9a-f]+)[^\r\n]*\r\n/i', trim($this->body)))
|
||||
{
|
||||
$this->state = 'emit';
|
||||
return;
|
||||
}
|
||||
|
||||
$decoded = '';
|
||||
$encoded = $this->body;
|
||||
|
||||
while (true)
|
||||
{
|
||||
$is_chunked = (bool) preg_match( '/^([0-9a-f]+)[^\r\n]*\r\n/i', $encoded, $matches );
|
||||
if (!$is_chunked)
|
||||
{
|
||||
// Looks like it's not chunked after all
|
||||
$this->state = 'emit';
|
||||
return;
|
||||
}
|
||||
|
||||
$length = hexdec(trim($matches[1]));
|
||||
if ($length === 0)
|
||||
{
|
||||
// Ignore trailer headers
|
||||
$this->state = 'emit';
|
||||
$this->body = $decoded;
|
||||
return;
|
||||
}
|
||||
|
||||
$chunk_length = strlen($matches[0]);
|
||||
$decoded .= $part = substr($encoded, $chunk_length, $length);
|
||||
$encoded = substr($encoded, $chunk_length + $length + 2);
|
||||
|
||||
if (trim($encoded) === '0' || empty($encoded))
|
||||
{
|
||||
$this->state = 'emit';
|
||||
$this->body = $decoded;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare headers (take care of proxies headers)
|
||||
*
|
||||
* @param string $headers Raw headers
|
||||
* @param integer $count Redirection count. Default to 1.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
static public function prepareHeaders($headers, $count = 1)
|
||||
{
|
||||
$data = explode("\r\n\r\n", $headers, $count);
|
||||
$data = array_pop($data);
|
||||
if (false !== stripos($data, "HTTP/1.0 200 Connection established\r\n\r\n")) {
|
||||
$data = str_ireplace("HTTP/1.0 200 Connection established\r\n\r\n", '', $data);
|
||||
}
|
||||
if (false !== stripos($data, "HTTP/1.1 200 Connection established\r\n\r\n")) {
|
||||
$data = str_ireplace("HTTP/1.1 200 Connection established\r\n\r\n", '', $data);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
if (\false) {
|
||||
/** @deprecated since SimplePie 1.7.0, use "SimplePie\HTTP\Parser" instead */
|
||||
class SimplePie_HTTP_Parser extends Parser
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -1,11 +1,13 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* 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
|
||||
* Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
|
@ -41,384 +43,15 @@
|
|||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Used for feed auto-discovery
|
||||
*
|
||||
*
|
||||
* This class can be overloaded with {@see SimplePie::set_locator_class()}
|
||||
*
|
||||
* @package SimplePie
|
||||
*/
|
||||
class SimplePie_Locator
|
||||
{
|
||||
var $useragent;
|
||||
var $timeout;
|
||||
var $file;
|
||||
var $local = array();
|
||||
var $elsewhere = array();
|
||||
var $cached_entities = array();
|
||||
var $http_base;
|
||||
var $base;
|
||||
var $base_location = 0;
|
||||
var $checked_feeds = 0;
|
||||
var $max_checked_feeds = 10;
|
||||
var $force_fsockopen = false;
|
||||
var $curl_options = array();
|
||||
protected $registry;
|
||||
use SimplePie\Locator;
|
||||
|
||||
public function __construct(SimplePie_File $file, $timeout = 10, $useragent = null, $max_checked_feeds = 10, $force_fsockopen = false, $curl_options = array())
|
||||
{
|
||||
$this->file = $file;
|
||||
$this->useragent = $useragent;
|
||||
$this->timeout = $timeout;
|
||||
$this->max_checked_feeds = $max_checked_feeds;
|
||||
$this->force_fsockopen = $force_fsockopen;
|
||||
$this->curl_options = $curl_options;
|
||||
class_exists('SimplePie\Locator');
|
||||
|
||||
if (class_exists('DOMDocument'))
|
||||
{
|
||||
$this->dom = new DOMDocument();
|
||||
// @trigger_error(sprintf('Using the "SimplePie_Locator" class is deprecated since SimplePie 1.7.0, use "SimplePie\Locator" instead.'), \E_USER_DEPRECATED);
|
||||
|
||||
set_error_handler(array('SimplePie_Misc', 'silence_errors'));
|
||||
$this->dom->loadHTML($this->file->body);
|
||||
restore_error_handler();
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->dom = null;
|
||||
}
|
||||
}
|
||||
|
||||
public function set_registry(SimplePie_Registry $registry)
|
||||
{
|
||||
$this->registry = $registry;
|
||||
}
|
||||
|
||||
public function find($type = SIMPLEPIE_LOCATOR_ALL, &$working = null)
|
||||
{
|
||||
if ($this->is_feed($this->file))
|
||||
{
|
||||
return $this->file;
|
||||
}
|
||||
|
||||
if ($this->file->method & SIMPLEPIE_FILE_SOURCE_REMOTE)
|
||||
{
|
||||
$sniffer = $this->registry->create('Content_Type_Sniffer', array($this->file));
|
||||
if ($sniffer->get_type() !== 'text/html')
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if ($type & ~SIMPLEPIE_LOCATOR_NONE)
|
||||
{
|
||||
$this->get_base();
|
||||
}
|
||||
|
||||
if ($type & SIMPLEPIE_LOCATOR_AUTODISCOVERY && $working = $this->autodiscovery())
|
||||
{
|
||||
return $working[0];
|
||||
}
|
||||
|
||||
if ($type & (SIMPLEPIE_LOCATOR_LOCAL_EXTENSION | SIMPLEPIE_LOCATOR_LOCAL_BODY | SIMPLEPIE_LOCATOR_REMOTE_EXTENSION | SIMPLEPIE_LOCATOR_REMOTE_BODY) && $this->get_links())
|
||||
{
|
||||
if ($type & SIMPLEPIE_LOCATOR_LOCAL_EXTENSION && $working = $this->extension($this->local))
|
||||
{
|
||||
return $working[0];
|
||||
}
|
||||
|
||||
if ($type & SIMPLEPIE_LOCATOR_LOCAL_BODY && $working = $this->body($this->local))
|
||||
{
|
||||
return $working[0];
|
||||
}
|
||||
|
||||
if ($type & SIMPLEPIE_LOCATOR_REMOTE_EXTENSION && $working = $this->extension($this->elsewhere))
|
||||
{
|
||||
return $working[0];
|
||||
}
|
||||
|
||||
if ($type & SIMPLEPIE_LOCATOR_REMOTE_BODY && $working = $this->body($this->elsewhere))
|
||||
{
|
||||
return $working[0];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function is_feed($file, $check_html = false)
|
||||
{
|
||||
if ($file->method & SIMPLEPIE_FILE_SOURCE_REMOTE)
|
||||
{
|
||||
$sniffer = $this->registry->create('Content_Type_Sniffer', array($file));
|
||||
$sniffed = $sniffer->get_type();
|
||||
$mime_types = array('application/rss+xml', 'application/rdf+xml',
|
||||
'text/rdf', 'application/atom+xml', 'text/xml',
|
||||
'application/xml', 'application/x-rss+xml');
|
||||
if ($check_html)
|
||||
{
|
||||
$mime_types[] = 'text/html';
|
||||
}
|
||||
|
||||
return in_array($sniffed, $mime_types);
|
||||
}
|
||||
elseif ($file->method & SIMPLEPIE_FILE_SOURCE_LOCAL)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_base()
|
||||
{
|
||||
if ($this->dom === null)
|
||||
{
|
||||
throw new SimplePie_Exception('DOMDocument not found, unable to use locator');
|
||||
}
|
||||
$this->http_base = $this->file->url;
|
||||
$this->base = $this->http_base;
|
||||
$elements = $this->dom->getElementsByTagName('base');
|
||||
foreach ($elements as $element)
|
||||
{
|
||||
if ($element->hasAttribute('href'))
|
||||
{
|
||||
$base = $this->registry->call('Misc', 'absolutize_url', array(trim($element->getAttribute('href')), $this->http_base));
|
||||
if ($base === false)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
$this->base = $base;
|
||||
$this->base_location = method_exists($element, 'getLineNo') ? $element->getLineNo() : 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function autodiscovery()
|
||||
{
|
||||
$done = array();
|
||||
$feeds = array();
|
||||
$feeds = array_merge($feeds, $this->search_elements_by_tag('link', $done, $feeds));
|
||||
$feeds = array_merge($feeds, $this->search_elements_by_tag('a', $done, $feeds));
|
||||
$feeds = array_merge($feeds, $this->search_elements_by_tag('area', $done, $feeds));
|
||||
|
||||
if (!empty($feeds))
|
||||
{
|
||||
return array_values($feeds);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function search_elements_by_tag($name, &$done, $feeds)
|
||||
{
|
||||
if ($this->dom === null)
|
||||
{
|
||||
throw new SimplePie_Exception('DOMDocument not found, unable to use locator');
|
||||
}
|
||||
|
||||
$links = $this->dom->getElementsByTagName($name);
|
||||
foreach ($links as $link)
|
||||
{
|
||||
if ($this->checked_feeds === $this->max_checked_feeds)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if ($link->hasAttribute('href') && $link->hasAttribute('rel'))
|
||||
{
|
||||
$rel = array_unique($this->registry->call('Misc', 'space_separated_tokens', array(strtolower($link->getAttribute('rel')))));
|
||||
$line = method_exists($link, 'getLineNo') ? $link->getLineNo() : 1;
|
||||
|
||||
if ($this->base_location < $line)
|
||||
{
|
||||
$href = $this->registry->call('Misc', 'absolutize_url', array(trim($link->getAttribute('href')), $this->base));
|
||||
}
|
||||
else
|
||||
{
|
||||
$href = $this->registry->call('Misc', 'absolutize_url', array(trim($link->getAttribute('href')), $this->http_base));
|
||||
}
|
||||
if ($href === false)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!in_array($href, $done) && in_array('feed', $rel) || (in_array('alternate', $rel) && !in_array('stylesheet', $rel) && $link->hasAttribute('type') && in_array(strtolower($this->registry->call('Misc', 'parse_mime', array($link->getAttribute('type')))), array('text/html', 'application/rss+xml', 'application/atom+xml'))) && !isset($feeds[$href]))
|
||||
{
|
||||
$this->checked_feeds++;
|
||||
$headers = array(
|
||||
'Accept' => 'application/atom+xml, application/rss+xml, application/rdf+xml;q=0.9, application/xml;q=0.8, text/xml;q=0.8, text/html;q=0.7, unknown/unknown;q=0.1, application/unknown;q=0.1, */*;q=0.1',
|
||||
);
|
||||
$feed = $this->registry->create('File', array($href, $this->timeout, 5, $headers, $this->useragent, $this->force_fsockopen, $this->curl_options));
|
||||
if ($feed->success && ($feed->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($feed->status_code === 200 || $feed->status_code > 206 && $feed->status_code < 300)) && $this->is_feed($feed, true))
|
||||
{
|
||||
$feeds[$href] = $feed;
|
||||
}
|
||||
}
|
||||
$done[] = $href;
|
||||
}
|
||||
}
|
||||
|
||||
return $feeds;
|
||||
}
|
||||
|
||||
public function get_links()
|
||||
{
|
||||
if ($this->dom === null)
|
||||
{
|
||||
throw new SimplePie_Exception('DOMDocument not found, unable to use locator');
|
||||
}
|
||||
|
||||
$links = $this->dom->getElementsByTagName('a');
|
||||
foreach ($links as $link)
|
||||
{
|
||||
if ($link->hasAttribute('href'))
|
||||
{
|
||||
$href = trim($link->getAttribute('href'));
|
||||
$parsed = $this->registry->call('Misc', 'parse_url', array($href));
|
||||
if ($parsed['scheme'] === '' || preg_match('/^(https?|feed)?$/i', $parsed['scheme']))
|
||||
{
|
||||
if (method_exists($link, 'getLineNo') && $this->base_location < $link->getLineNo())
|
||||
{
|
||||
$href = $this->registry->call('Misc', 'absolutize_url', array(trim($link->getAttribute('href')), $this->base));
|
||||
}
|
||||
else
|
||||
{
|
||||
$href = $this->registry->call('Misc', 'absolutize_url', array(trim($link->getAttribute('href')), $this->http_base));
|
||||
}
|
||||
if ($href === false)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$current = $this->registry->call('Misc', 'parse_url', array($this->file->url));
|
||||
|
||||
if ($parsed['authority'] === '' || $parsed['authority'] === $current['authority'])
|
||||
{
|
||||
$this->local[] = $href;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->elsewhere[] = $href;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->local = array_unique($this->local);
|
||||
$this->elsewhere = array_unique($this->elsewhere);
|
||||
if (!empty($this->local) || !empty($this->elsewhere))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function get_rel_link($rel)
|
||||
{
|
||||
if ($this->dom === null)
|
||||
{
|
||||
throw new SimplePie_Exception('DOMDocument not found, unable to use '.
|
||||
'locator');
|
||||
}
|
||||
if (!class_exists('DOMXpath'))
|
||||
{
|
||||
throw new SimplePie_Exception('DOMXpath not found, unable to use '.
|
||||
'get_rel_link');
|
||||
}
|
||||
|
||||
$xpath = new DOMXpath($this->dom);
|
||||
$query = '//a[@rel and @href] | //link[@rel and @href]';
|
||||
foreach ($xpath->query($query) as $link)
|
||||
{
|
||||
$href = trim($link->getAttribute('href'));
|
||||
$parsed = $this->registry->call('Misc', 'parse_url', array($href));
|
||||
if ($parsed['scheme'] === '' ||
|
||||
preg_match('/^https?$/i', $parsed['scheme']))
|
||||
{
|
||||
if (method_exists($link, 'getLineNo') &&
|
||||
$this->base_location < $link->getLineNo())
|
||||
{
|
||||
$href =
|
||||
$this->registry->call('Misc', 'absolutize_url',
|
||||
array(trim($link->getAttribute('href')),
|
||||
$this->base));
|
||||
}
|
||||
else
|
||||
{
|
||||
$href =
|
||||
$this->registry->call('Misc', 'absolutize_url',
|
||||
array(trim($link->getAttribute('href')),
|
||||
$this->http_base));
|
||||
}
|
||||
if ($href === false)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
$rel_values = explode(' ', strtolower($link->getAttribute('rel')));
|
||||
if (in_array($rel, $rel_values))
|
||||
{
|
||||
return $href;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function extension(&$array)
|
||||
{
|
||||
foreach ($array as $key => $value)
|
||||
{
|
||||
if ($this->checked_feeds === $this->max_checked_feeds)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (in_array(strtolower(strrchr($value, '.')), array('.rss', '.rdf', '.atom', '.xml')))
|
||||
{
|
||||
$this->checked_feeds++;
|
||||
|
||||
$headers = array(
|
||||
'Accept' => 'application/atom+xml, application/rss+xml, application/rdf+xml;q=0.9, application/xml;q=0.8, text/xml;q=0.8, text/html;q=0.7, unknown/unknown;q=0.1, application/unknown;q=0.1, */*;q=0.1',
|
||||
);
|
||||
$feed = $this->registry->create('File', array($value, $this->timeout, 5, $headers, $this->useragent, $this->force_fsockopen, $this->curl_options));
|
||||
if ($feed->success && ($feed->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($feed->status_code === 200 || $feed->status_code > 206 && $feed->status_code < 300)) && $this->is_feed($feed))
|
||||
{
|
||||
return array($feed);
|
||||
}
|
||||
else
|
||||
{
|
||||
unset($array[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function body(&$array)
|
||||
{
|
||||
foreach ($array as $key => $value)
|
||||
{
|
||||
if ($this->checked_feeds === $this->max_checked_feeds)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (preg_match('/(feed|rss|rdf|atom|xml)/i', $value))
|
||||
{
|
||||
$this->checked_feeds++;
|
||||
$headers = array(
|
||||
'Accept' => 'application/atom+xml, application/rss+xml, application/rdf+xml;q=0.9, application/xml;q=0.8, text/xml;q=0.8, text/html;q=0.7, unknown/unknown;q=0.1, application/unknown;q=0.1, */*;q=0.1',
|
||||
);
|
||||
$feed = $this->registry->create('File', array($value, $this->timeout, 5, null, $this->useragent, $this->force_fsockopen, $this->curl_options));
|
||||
if ($feed->success && ($feed->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($feed->status_code === 200 || $feed->status_code > 206 && $feed->status_code < 300)) && $this->is_feed($feed))
|
||||
{
|
||||
return array($feed);
|
||||
}
|
||||
else
|
||||
{
|
||||
unset($array[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
if (\false) {
|
||||
/** @deprecated since SimplePie 1.7.0, use "SimplePie\Locator" instead */
|
||||
class SimplePie_Locator extends Locator
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,11 +1,13 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* 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
|
||||
* Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
|
@ -41,229 +43,15 @@
|
|||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
*/
|
||||
|
||||
use SimplePie\Net\IPv6;
|
||||
|
||||
/**
|
||||
* Class to validate and to work with IPv6 addresses.
|
||||
*
|
||||
* @package SimplePie
|
||||
* @subpackage HTTP
|
||||
* @copyright 2003-2005 The PHP Group
|
||||
* @license http://www.opensource.org/licenses/bsd-license.php
|
||||
* @link http://pear.php.net/package/Net_IPv6
|
||||
* @author Alexander Merz <alexander.merz@web.de>
|
||||
* @author elfrink at introweb dot nl
|
||||
* @author Josh Peck <jmp at joshpeck dot org>
|
||||
* @author Sam Sneddon <geoffers@gmail.com>
|
||||
*/
|
||||
class SimplePie_Net_IPv6
|
||||
{
|
||||
/**
|
||||
* Uncompresses an IPv6 address
|
||||
*
|
||||
* RFC 4291 allows you to compress concecutive 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 http://www.opensource.org/licenses/bsd-license.php
|
||||
* @param string $ip An IPv6 address
|
||||
* @return string The uncompressed IPv6 address
|
||||
*/
|
||||
public static function uncompress($ip)
|
||||
{
|
||||
$c1 = -1;
|
||||
$c2 = -1;
|
||||
if (substr_count($ip, '::') === 1)
|
||||
{
|
||||
list($ip1, $ip2) = explode('::', $ip);
|
||||
if ($ip1 === '')
|
||||
{
|
||||
$c1 = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$c1 = substr_count($ip1, ':');
|
||||
}
|
||||
if ($ip2 === '')
|
||||
{
|
||||
$c2 = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$c2 = substr_count($ip2, ':');
|
||||
}
|
||||
if (strpos($ip2, '.') !== false)
|
||||
{
|
||||
$c2++;
|
||||
}
|
||||
// ::
|
||||
if ($c1 === -1 && $c2 === -1)
|
||||
{
|
||||
$ip = '0:0:0:0:0:0:0:0';
|
||||
}
|
||||
// ::xxx
|
||||
else if ($c1 === -1)
|
||||
{
|
||||
$fill = str_repeat('0:', 7 - $c2);
|
||||
$ip = str_replace('::', $fill, $ip);
|
||||
}
|
||||
// xxx::
|
||||
else if ($c2 === -1)
|
||||
{
|
||||
$fill = str_repeat(':0', 7 - $c1);
|
||||
$ip = str_replace('::', $fill, $ip);
|
||||
}
|
||||
// xxx::xxx
|
||||
else
|
||||
{
|
||||
$fill = ':' . str_repeat('0:', 6 - $c2 - $c1);
|
||||
$ip = str_replace('::', $fill, $ip);
|
||||
}
|
||||
}
|
||||
return $ip;
|
||||
}
|
||||
class_exists('SimplePie\Net\IPv6');
|
||||
|
||||
/**
|
||||
* Compresses an IPv6 address
|
||||
*
|
||||
* RFC 4291 allows you to compress concecutive 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 uncompress()
|
||||
* @param string $ip An IPv6 address
|
||||
* @return string The compressed IPv6 address
|
||||
*/
|
||||
public static function compress($ip)
|
||||
{
|
||||
// Prepare the IP to be compressed
|
||||
$ip = self::uncompress($ip);
|
||||
$ip_parts = self::split_v6_v4($ip);
|
||||
// @trigger_error(sprintf('Using the "SimplePie_Net_IPv6" class is deprecated since SimplePie 1.7.0, use "SimplePie\Net\IPv6" instead.'), \E_USER_DEPRECATED);
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
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 array [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 array($ipv6_part, $ipv4_part);
|
||||
}
|
||||
|
||||
return array($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)
|
||||
{
|
||||
$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;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given IP is a valid IPv6 address
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated Use {@see SimplePie_Net_IPv6::check_ipv6()} instead
|
||||
* @see check_ipv6
|
||||
* @param string $ip An IPv6 address
|
||||
* @return bool true if $ip is a valid IPv6 address
|
||||
*/
|
||||
public static function checkIPv6($ip)
|
||||
{
|
||||
return self::check_ipv6($ip);
|
||||
}
|
||||
if (\false) {
|
||||
/** @deprecated since SimplePie 1.7.0, use "SimplePie\Net\IPv6" instead */
|
||||
class SimplePie_Net_IPv6 extends IPv6
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
|
@ -1,11 +1,13 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* 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
|
||||
* Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
|
@ -41,84 +43,15 @@
|
|||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Handles `<media:rating>` or `<itunes:explicit>` tags as defined in Media RSS and iTunes RSS respectively
|
||||
*
|
||||
* Used by {@see SimplePie_Enclosure::get_rating()} and {@see SimplePie_Enclosure::get_ratings()}
|
||||
*
|
||||
* This class can be overloaded with {@see SimplePie::set_rating_class()}
|
||||
*
|
||||
* @package SimplePie
|
||||
* @subpackage API
|
||||
*/
|
||||
class SimplePie_Rating
|
||||
{
|
||||
/**
|
||||
* Rating scheme
|
||||
*
|
||||
* @var string
|
||||
* @see get_scheme()
|
||||
*/
|
||||
var $scheme;
|
||||
use SimplePie\Rating;
|
||||
|
||||
/**
|
||||
* Rating value
|
||||
*
|
||||
* @var string
|
||||
* @see get_value()
|
||||
*/
|
||||
var $value;
|
||||
class_exists('SimplePie\Rating');
|
||||
|
||||
/**
|
||||
* Constructor, used to input the data
|
||||
*
|
||||
* For documentation on all the parameters, see the corresponding
|
||||
* properties and their accessors
|
||||
*/
|
||||
public function __construct($scheme = null, $value = null)
|
||||
{
|
||||
$this->scheme = $scheme;
|
||||
$this->value = $value;
|
||||
}
|
||||
// @trigger_error(sprintf('Using the "SimplePie_Rating" class is deprecated since SimplePie 1.7.0, use "SimplePie\Rating" instead.'), \E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* String-ified version
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
// There is no $this->data here
|
||||
return md5(serialize($this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the organizational scheme for the rating
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function get_scheme()
|
||||
{
|
||||
if ($this->scheme !== null)
|
||||
{
|
||||
return $this->scheme;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of the rating
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function get_value()
|
||||
{
|
||||
if ($this->value !== null)
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
if (\false) {
|
||||
/** @deprecated since SimplePie 1.7.0, use "SimplePie\Rating" instead */
|
||||
class SimplePie_Rating extends Rating
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* 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
|
||||
* Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
|
@ -41,184 +43,15 @@
|
|||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Handles creating objects and calling methods
|
||||
*
|
||||
* Access this via {@see SimplePie::get_registry()}
|
||||
*
|
||||
* @package SimplePie
|
||||
*/
|
||||
class SimplePie_Registry
|
||||
{
|
||||
/**
|
||||
* Default class mapping
|
||||
*
|
||||
* Overriding classes *must* subclass these.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $default = array(
|
||||
'Cache' => 'SimplePie_Cache',
|
||||
'Locator' => 'SimplePie_Locator',
|
||||
'Parser' => 'SimplePie_Parser',
|
||||
'File' => 'SimplePie_File',
|
||||
'Sanitize' => 'SimplePie_Sanitize',
|
||||
'Item' => 'SimplePie_Item',
|
||||
'Author' => 'SimplePie_Author',
|
||||
'Category' => 'SimplePie_Category',
|
||||
'Enclosure' => 'SimplePie_Enclosure',
|
||||
'Caption' => 'SimplePie_Caption',
|
||||
'Copyright' => 'SimplePie_Copyright',
|
||||
'Credit' => 'SimplePie_Credit',
|
||||
'Rating' => 'SimplePie_Rating',
|
||||
'Restriction' => 'SimplePie_Restriction',
|
||||
'Content_Type_Sniffer' => 'SimplePie_Content_Type_Sniffer',
|
||||
'Source' => 'SimplePie_Source',
|
||||
'Misc' => 'SimplePie_Misc',
|
||||
'XML_Declaration_Parser' => 'SimplePie_XML_Declaration_Parser',
|
||||
'Parse_Date' => 'SimplePie_Parse_Date',
|
||||
);
|
||||
use SimplePie\Registry;
|
||||
|
||||
/**
|
||||
* Class mapping
|
||||
*
|
||||
* @see register()
|
||||
* @var array
|
||||
*/
|
||||
protected $classes = array();
|
||||
class_exists('SimplePie\Registry');
|
||||
|
||||
/**
|
||||
* Legacy classes
|
||||
*
|
||||
* @see register()
|
||||
* @var array
|
||||
*/
|
||||
protected $legacy = array();
|
||||
// @trigger_error(sprintf('Using the "SimplePie_Registry" class is deprecated since SimplePie 1.7.0, use "SimplePie\Registry" instead.'), \E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* No-op
|
||||
*/
|
||||
public function __construct() { }
|
||||
|
||||
/**
|
||||
* Register a class
|
||||
*
|
||||
* @param string $type See {@see $default} for names
|
||||
* @param string $class Class name, must subclass the corresponding default
|
||||
* @param bool $legacy Whether to enable legacy support for this class
|
||||
* @return bool Successfulness
|
||||
*/
|
||||
public function register($type, $class, $legacy = false)
|
||||
{
|
||||
if (!@is_subclass_of($class, $this->default[$type]))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->classes[$type] = $class;
|
||||
|
||||
if ($legacy)
|
||||
{
|
||||
$this->legacy[] = $class;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the class registered for a type
|
||||
*
|
||||
* Where possible, use {@see create()} or {@see call()} instead
|
||||
*
|
||||
* @param string $type
|
||||
* @return string|null
|
||||
*/
|
||||
public function get_class($type)
|
||||
{
|
||||
if (!empty($this->classes[$type]))
|
||||
{
|
||||
return $this->classes[$type];
|
||||
}
|
||||
if (!empty($this->default[$type]))
|
||||
{
|
||||
return $this->default[$type];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance of a given type
|
||||
*
|
||||
* @param string $type
|
||||
* @param array $parameters Parameters to pass to the constructor
|
||||
* @return object Instance of class
|
||||
*/
|
||||
public function &create($type, $parameters = array())
|
||||
{
|
||||
$class = $this->get_class($type);
|
||||
|
||||
if (in_array($class, $this->legacy))
|
||||
{
|
||||
switch ($type)
|
||||
{
|
||||
case 'locator':
|
||||
// Legacy: file, timeout, useragent, file_class, max_checked_feeds, content_type_sniffer_class
|
||||
// Specified: file, timeout, useragent, max_checked_feeds
|
||||
$replacement = array($this->get_class('file'), $parameters[3], $this->get_class('content_type_sniffer'));
|
||||
array_splice($parameters, 3, 1, $replacement);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!method_exists($class, '__construct'))
|
||||
{
|
||||
$instance = new $class;
|
||||
}
|
||||
else
|
||||
{
|
||||
$reflector = new ReflectionClass($class);
|
||||
$instance = $reflector->newInstanceArgs($parameters);
|
||||
}
|
||||
|
||||
if (method_exists($instance, 'set_registry'))
|
||||
{
|
||||
$instance->set_registry($this);
|
||||
}
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call a static method for a type
|
||||
*
|
||||
* @param string $type
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
* @return mixed
|
||||
*/
|
||||
public function &call($type, $method, $parameters = array())
|
||||
{
|
||||
$class = $this->get_class($type);
|
||||
|
||||
if (in_array($class, $this->legacy))
|
||||
{
|
||||
switch ($type)
|
||||
{
|
||||
case 'Cache':
|
||||
// For backwards compatibility with old non-static
|
||||
// Cache::create() methods
|
||||
if ($method === 'get_handler')
|
||||
{
|
||||
$result = @call_user_func_array(array($class, 'create'), $parameters);
|
||||
return $result;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$result = call_user_func_array(array($class, $method), $parameters);
|
||||
return $result;
|
||||
}
|
||||
if (\false) {
|
||||
/** @deprecated since SimplePie 1.7.0, use "SimplePie\Registry" instead */
|
||||
class SimplePie_Registry extends Registry
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* 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
|
||||
* Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
|
@ -41,108 +43,15 @@
|
|||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Handles `<media:restriction>` as defined in Media RSS
|
||||
*
|
||||
* Used by {@see SimplePie_Enclosure::get_restriction()} and {@see SimplePie_Enclosure::get_restrictions()}
|
||||
*
|
||||
* This class can be overloaded with {@see SimplePie::set_restriction_class()}
|
||||
*
|
||||
* @package SimplePie
|
||||
* @subpackage API
|
||||
*/
|
||||
class SimplePie_Restriction
|
||||
{
|
||||
/**
|
||||
* Relationship ('allow'/'deny')
|
||||
*
|
||||
* @var string
|
||||
* @see get_relationship()
|
||||
*/
|
||||
var $relationship;
|
||||
use SimplePie\Restriction;
|
||||
|
||||
/**
|
||||
* Type of restriction
|
||||
*
|
||||
* @var string
|
||||
* @see get_type()
|
||||
*/
|
||||
var $type;
|
||||
class_exists('SimplePie\Restriction');
|
||||
|
||||
/**
|
||||
* Restricted values
|
||||
*
|
||||
* @var string
|
||||
* @see get_value()
|
||||
*/
|
||||
var $value;
|
||||
// @trigger_error(sprintf('Using the "SimplePie_Restriction" class is deprecated since SimplePie 1.7.0, use "SimplePie\Restriction" instead.'), \E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* Constructor, used to input the data
|
||||
*
|
||||
* For documentation on all the parameters, see the corresponding
|
||||
* properties and their accessors
|
||||
*/
|
||||
public function __construct($relationship = null, $type = null, $value = null)
|
||||
{
|
||||
$this->relationship = $relationship;
|
||||
$this->type = $type;
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* String-ified version
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
// There is no $this->data here
|
||||
return md5(serialize($this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the relationship
|
||||
*
|
||||
* @return string|null Either 'allow' or 'deny'
|
||||
*/
|
||||
public function get_relationship()
|
||||
{
|
||||
if ($this->relationship !== null)
|
||||
{
|
||||
return $this->relationship;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the type
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function get_type()
|
||||
{
|
||||
if ($this->type !== null)
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of restricted things
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function get_value()
|
||||
{
|
||||
if ($this->value !== null)
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
if (\false) {
|
||||
/** @deprecated since SimplePie 1.7.0, use "SimplePie\Restriction" instead */
|
||||
class SimplePie_Restriction extends Restriction
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* 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
|
||||
* Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
|
@ -41,544 +43,15 @@
|
|||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Used for data cleanup and post-processing
|
||||
*
|
||||
*
|
||||
* This class can be overloaded with {@see SimplePie::set_sanitize_class()}
|
||||
*
|
||||
* @package SimplePie
|
||||
* @todo Move to using an actual HTML parser (this will allow tags to be properly stripped, and to switch between HTML and XHTML), this will also make it easier to shorten a string while preserving HTML tags
|
||||
*/
|
||||
class SimplePie_Sanitize
|
||||
{
|
||||
// Private vars
|
||||
var $base;
|
||||
use SimplePie\Sanitize;
|
||||
|
||||
// Options
|
||||
var $remove_div = true;
|
||||
var $image_handler = '';
|
||||
var $strip_htmltags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style');
|
||||
var $encode_instead_of_strip = false;
|
||||
var $strip_attributes = array('bgsound', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc');
|
||||
var $add_attributes = array('audio' => array('preload' => 'none'), 'iframe' => array('sandbox' => 'allow-scripts allow-same-origin'), 'video' => array('preload' => 'none'));
|
||||
var $strip_comments = false;
|
||||
var $output_encoding = 'UTF-8';
|
||||
var $enable_cache = true;
|
||||
var $cache_location = './cache';
|
||||
var $cache_name_function = 'md5';
|
||||
var $timeout = 10;
|
||||
var $useragent = '';
|
||||
var $force_fsockopen = false;
|
||||
var $replace_url_attributes = null;
|
||||
class_exists('SimplePie\Sanitize');
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
// Set defaults
|
||||
$this->set_url_replacements(null);
|
||||
}
|
||||
// @trigger_error(sprintf('Using the "SimplePie_Sanitize" class is deprecated since SimplePie 1.7.0, use "SimplePie\Sanitize" instead.'), \E_USER_DEPRECATED);
|
||||
|
||||
public function remove_div($enable = true)
|
||||
{
|
||||
$this->remove_div = (bool) $enable;
|
||||
}
|
||||
|
||||
public function set_image_handler($page = false)
|
||||
{
|
||||
if ($page)
|
||||
{
|
||||
$this->image_handler = (string) $page;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->image_handler = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function set_registry(SimplePie_Registry $registry)
|
||||
{
|
||||
$this->registry = $registry;
|
||||
}
|
||||
|
||||
public function pass_cache_data($enable_cache = true, $cache_location = './cache', $cache_name_function = 'md5', $cache_class = 'SimplePie_Cache')
|
||||
{
|
||||
if (isset($enable_cache))
|
||||
{
|
||||
$this->enable_cache = (bool) $enable_cache;
|
||||
}
|
||||
|
||||
if ($cache_location)
|
||||
{
|
||||
$this->cache_location = (string) $cache_location;
|
||||
}
|
||||
|
||||
if ($cache_name_function)
|
||||
{
|
||||
$this->cache_name_function = (string) $cache_name_function;
|
||||
}
|
||||
}
|
||||
|
||||
public function pass_file_data($file_class = 'SimplePie_File', $timeout = 10, $useragent = '', $force_fsockopen = false)
|
||||
{
|
||||
if ($timeout)
|
||||
{
|
||||
$this->timeout = (string) $timeout;
|
||||
}
|
||||
|
||||
if ($useragent)
|
||||
{
|
||||
$this->useragent = (string) $useragent;
|
||||
}
|
||||
|
||||
if ($force_fsockopen)
|
||||
{
|
||||
$this->force_fsockopen = (string) $force_fsockopen;
|
||||
}
|
||||
}
|
||||
|
||||
public function strip_htmltags($tags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style'))
|
||||
{
|
||||
if ($tags)
|
||||
{
|
||||
if (is_array($tags))
|
||||
{
|
||||
$this->strip_htmltags = $tags;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->strip_htmltags = explode(',', $tags);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->strip_htmltags = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function encode_instead_of_strip($encode = false)
|
||||
{
|
||||
$this->encode_instead_of_strip = (bool) $encode;
|
||||
}
|
||||
|
||||
public function strip_attributes($attribs = array('bgsound', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc'))
|
||||
{
|
||||
if ($attribs)
|
||||
{
|
||||
if (is_array($attribs))
|
||||
{
|
||||
$this->strip_attributes = $attribs;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->strip_attributes = explode(',', $attribs);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->strip_attributes = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function add_attributes($attribs = array('audio' => array('preload' => 'none'), 'iframe' => array('sandbox' => 'allow-scripts allow-same-origin'), 'video' => array('preload' => 'none')))
|
||||
{
|
||||
if ($attribs)
|
||||
{
|
||||
if (is_array($attribs))
|
||||
{
|
||||
$this->add_attributes = $attribs;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->add_attributes = explode(',', $attribs);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->add_attributes = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function strip_comments($strip = false)
|
||||
{
|
||||
$this->strip_comments = (bool) $strip;
|
||||
}
|
||||
|
||||
public function set_output_encoding($encoding = 'UTF-8')
|
||||
{
|
||||
$this->output_encoding = (string) $encoding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set element/attribute key/value pairs of HTML attributes
|
||||
* containing URLs that need to be resolved relative to the feed
|
||||
*
|
||||
* Defaults to |a|@href, |area|@href, |blockquote|@cite, |del|@cite,
|
||||
* |form|@action, |img|@longdesc, |img|@src, |input|@src, |ins|@cite,
|
||||
* |q|@cite
|
||||
*
|
||||
* @since 1.0
|
||||
* @param array|null $element_attribute Element/attribute key/value pairs, null for default
|
||||
*/
|
||||
public function set_url_replacements($element_attribute = null)
|
||||
{
|
||||
if ($element_attribute === null)
|
||||
{
|
||||
$element_attribute = array(
|
||||
'a' => 'href',
|
||||
'area' => 'href',
|
||||
'blockquote' => 'cite',
|
||||
'del' => 'cite',
|
||||
'form' => 'action',
|
||||
'img' => array(
|
||||
'longdesc',
|
||||
'src'
|
||||
),
|
||||
'input' => 'src',
|
||||
'ins' => 'cite',
|
||||
'q' => 'cite'
|
||||
);
|
||||
}
|
||||
$this->replace_url_attributes = (array) $element_attribute;
|
||||
}
|
||||
|
||||
public function sanitize($data, $type, $base = '')
|
||||
{
|
||||
$data = trim($data);
|
||||
if ($data !== '' || $type & SIMPLEPIE_CONSTRUCT_IRI)
|
||||
{
|
||||
if ($type & SIMPLEPIE_CONSTRUCT_MAYBE_HTML)
|
||||
{
|
||||
if (preg_match('/(&(#(x[0-9a-fA-F]+|[0-9]+)|[a-zA-Z0-9]+)|<\/[A-Za-z][^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3E]*' . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . '>)/', $data))
|
||||
{
|
||||
$type |= SIMPLEPIE_CONSTRUCT_HTML;
|
||||
}
|
||||
else
|
||||
{
|
||||
$type |= SIMPLEPIE_CONSTRUCT_TEXT;
|
||||
}
|
||||
}
|
||||
|
||||
if ($type & SIMPLEPIE_CONSTRUCT_BASE64)
|
||||
{
|
||||
$data = base64_decode($data);
|
||||
}
|
||||
|
||||
if ($type & (SIMPLEPIE_CONSTRUCT_HTML | SIMPLEPIE_CONSTRUCT_XHTML))
|
||||
{
|
||||
|
||||
if (!class_exists('DOMDocument'))
|
||||
{
|
||||
throw new SimplePie_Exception('DOMDocument not found, unable to use sanitizer');
|
||||
}
|
||||
$document = new DOMDocument();
|
||||
$document->encoding = 'UTF-8';
|
||||
|
||||
$data = $this->preprocess($data, $type);
|
||||
|
||||
set_error_handler(array('SimplePie_Misc', 'silence_errors'));
|
||||
$document->loadHTML($data);
|
||||
restore_error_handler();
|
||||
|
||||
$xpath = new DOMXPath($document);
|
||||
|
||||
// Strip comments
|
||||
if ($this->strip_comments)
|
||||
{
|
||||
$comments = $xpath->query('//comment()');
|
||||
|
||||
foreach ($comments as $comment)
|
||||
{
|
||||
$comment->parentNode->removeChild($comment);
|
||||
}
|
||||
}
|
||||
|
||||
// Strip out HTML tags and attributes that might cause various security problems.
|
||||
// Based on recommendations by Mark Pilgrim at:
|
||||
// http://diveintomark.org/archives/2003/06/12/how_to_consume_rss_safely
|
||||
if ($this->strip_htmltags)
|
||||
{
|
||||
foreach ($this->strip_htmltags as $tag)
|
||||
{
|
||||
$this->strip_tag($tag, $document, $xpath, $type);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->strip_attributes)
|
||||
{
|
||||
foreach ($this->strip_attributes as $attrib)
|
||||
{
|
||||
$this->strip_attr($attrib, $xpath);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->add_attributes)
|
||||
{
|
||||
foreach ($this->add_attributes as $tag => $valuePairs)
|
||||
{
|
||||
$this->add_attr($tag, $valuePairs, $document);
|
||||
}
|
||||
}
|
||||
|
||||
// Replace relative URLs
|
||||
$this->base = $base;
|
||||
foreach ($this->replace_url_attributes as $element => $attributes)
|
||||
{
|
||||
$this->replace_urls($document, $element, $attributes);
|
||||
}
|
||||
|
||||
// If image handling (caching, etc.) is enabled, cache and rewrite all the image tags.
|
||||
if (isset($this->image_handler) && ((string) $this->image_handler) !== '' && $this->enable_cache)
|
||||
{
|
||||
$images = $document->getElementsByTagName('img');
|
||||
foreach ($images as $img)
|
||||
{
|
||||
if ($img->hasAttribute('src'))
|
||||
{
|
||||
$image_url = call_user_func($this->cache_name_function, $img->getAttribute('src'));
|
||||
$cache = $this->registry->call('Cache', 'get_handler', array($this->cache_location, $image_url, 'spi'));
|
||||
|
||||
if ($cache->load())
|
||||
{
|
||||
$img->setAttribute('src', $this->image_handler . $image_url);
|
||||
}
|
||||
else
|
||||
{
|
||||
$file = $this->registry->create('File', array($img->getAttribute('src'), $this->timeout, 5, array('X-FORWARDED-FOR' => $_SERVER['REMOTE_ADDR']), $this->useragent, $this->force_fsockopen));
|
||||
$headers = $file->headers;
|
||||
|
||||
if ($file->success && ($file->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($file->status_code === 200 || $file->status_code > 206 && $file->status_code < 300)))
|
||||
{
|
||||
if ($cache->save(array('headers' => $file->headers, 'body' => $file->body)))
|
||||
{
|
||||
$img->setAttribute('src', $this->image_handler . $image_url);
|
||||
}
|
||||
else
|
||||
{
|
||||
trigger_error("$this->cache_location is not writable. Make sure you've set the correct relative or absolute path, and that the location is server-writable.", E_USER_WARNING);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get content node
|
||||
$div = $document->getElementsByTagName('body')->item(0)->firstChild;
|
||||
// Finally, convert to a HTML string
|
||||
$data = trim($document->saveHTML($div));
|
||||
|
||||
if ($this->remove_div)
|
||||
{
|
||||
$data = preg_replace('/^<div' . SIMPLEPIE_PCRE_XML_ATTRIBUTE . '>/', '', $data);
|
||||
$data = preg_replace('/<\/div>$/', '', $data);
|
||||
}
|
||||
else
|
||||
{
|
||||
$data = preg_replace('/^<div' . SIMPLEPIE_PCRE_XML_ATTRIBUTE . '>/', '<div>', $data);
|
||||
}
|
||||
}
|
||||
|
||||
if ($type & SIMPLEPIE_CONSTRUCT_IRI)
|
||||
{
|
||||
$absolute = $this->registry->call('Misc', 'absolutize_url', array($data, $base));
|
||||
if ($absolute !== false)
|
||||
{
|
||||
$data = $absolute;
|
||||
}
|
||||
}
|
||||
|
||||
if ($type & (SIMPLEPIE_CONSTRUCT_TEXT | SIMPLEPIE_CONSTRUCT_IRI))
|
||||
{
|
||||
$data = htmlspecialchars($data, ENT_COMPAT, 'UTF-8');
|
||||
}
|
||||
|
||||
if ($this->output_encoding !== 'UTF-8')
|
||||
{
|
||||
$data = $this->registry->call('Misc', 'change_encoding', array($data, 'UTF-8', $this->output_encoding));
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function preprocess($html, $type)
|
||||
{
|
||||
$ret = '';
|
||||
$html = preg_replace('%</?(?:html|body)[^>]*?'.'>%is', '', $html);
|
||||
if ($type & ~SIMPLEPIE_CONSTRUCT_XHTML)
|
||||
{
|
||||
// Atom XHTML constructs are wrapped with a div by default
|
||||
// Note: No protection if $html contains a stray </div>!
|
||||
$html = '<div>' . $html . '</div>';
|
||||
$ret .= '<!DOCTYPE html>';
|
||||
$content_type = 'text/html';
|
||||
}
|
||||
else
|
||||
{
|
||||
$ret .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
|
||||
$content_type = 'application/xhtml+xml';
|
||||
}
|
||||
|
||||
$ret .= '<html><head>';
|
||||
$ret .= '<meta http-equiv="Content-Type" content="' . $content_type . '; charset=utf-8" />';
|
||||
$ret .= '</head><body>' . $html . '</body></html>';
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function replace_urls($document, $tag, $attributes)
|
||||
{
|
||||
if (!is_array($attributes))
|
||||
{
|
||||
$attributes = array($attributes);
|
||||
}
|
||||
|
||||
if (!is_array($this->strip_htmltags) || !in_array($tag, $this->strip_htmltags))
|
||||
{
|
||||
$elements = $document->getElementsByTagName($tag);
|
||||
foreach ($elements as $element)
|
||||
{
|
||||
foreach ($attributes as $attribute)
|
||||
{
|
||||
if ($element->hasAttribute($attribute))
|
||||
{
|
||||
$value = $this->registry->call('Misc', 'absolutize_url', array($element->getAttribute($attribute), $this->base));
|
||||
if ($value !== false)
|
||||
{
|
||||
$element->setAttribute($attribute, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function do_strip_htmltags($match)
|
||||
{
|
||||
if ($this->encode_instead_of_strip)
|
||||
{
|
||||
if (isset($match[4]) && !in_array(strtolower($match[1]), array('script', 'style')))
|
||||
{
|
||||
$match[1] = htmlspecialchars($match[1], ENT_COMPAT, 'UTF-8');
|
||||
$match[2] = htmlspecialchars($match[2], ENT_COMPAT, 'UTF-8');
|
||||
return "<$match[1]$match[2]>$match[3]</$match[1]>";
|
||||
}
|
||||
else
|
||||
{
|
||||
return htmlspecialchars($match[0], ENT_COMPAT, 'UTF-8');
|
||||
}
|
||||
}
|
||||
elseif (isset($match[4]) && !in_array(strtolower($match[1]), array('script', 'style')))
|
||||
{
|
||||
return $match[4];
|
||||
}
|
||||
else
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
protected function strip_tag($tag, $document, $xpath, $type)
|
||||
{
|
||||
$elements = $xpath->query('body//' . $tag);
|
||||
if ($this->encode_instead_of_strip)
|
||||
{
|
||||
foreach ($elements as $element)
|
||||
{
|
||||
$fragment = $document->createDocumentFragment();
|
||||
|
||||
// For elements which aren't script or style, include the tag itself
|
||||
if (!in_array($tag, array('script', 'style')))
|
||||
{
|
||||
$text = '<' . $tag;
|
||||
if ($element->hasAttributes())
|
||||
{
|
||||
$attrs = array();
|
||||
foreach ($element->attributes as $name => $attr)
|
||||
{
|
||||
$value = $attr->value;
|
||||
|
||||
// In XHTML, empty values should never exist, so we repeat the value
|
||||
if (empty($value) && ($type & SIMPLEPIE_CONSTRUCT_XHTML))
|
||||
{
|
||||
$value = $name;
|
||||
}
|
||||
// For HTML, empty is fine
|
||||
elseif (empty($value) && ($type & SIMPLEPIE_CONSTRUCT_HTML))
|
||||
{
|
||||
$attrs[] = $name;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Standard attribute text
|
||||
$attrs[] = $name . '="' . $attr->value . '"';
|
||||
}
|
||||
$text .= ' ' . implode(' ', $attrs);
|
||||
}
|
||||
$text .= '>';
|
||||
$fragment->appendChild(new DOMText($text));
|
||||
}
|
||||
|
||||
$number = $element->childNodes->length;
|
||||
for ($i = $number; $i > 0; $i--)
|
||||
{
|
||||
$child = $element->childNodes->item(0);
|
||||
$fragment->appendChild($child);
|
||||
}
|
||||
|
||||
if (!in_array($tag, array('script', 'style')))
|
||||
{
|
||||
$fragment->appendChild(new DOMText('</' . $tag . '>'));
|
||||
}
|
||||
|
||||
$element->parentNode->replaceChild($fragment, $element);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
elseif (in_array($tag, array('script', 'style')))
|
||||
{
|
||||
foreach ($elements as $element)
|
||||
{
|
||||
$element->parentNode->removeChild($element);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach ($elements as $element)
|
||||
{
|
||||
$fragment = $document->createDocumentFragment();
|
||||
$number = $element->childNodes->length;
|
||||
for ($i = $number; $i > 0; $i--)
|
||||
{
|
||||
$child = $element->childNodes->item(0);
|
||||
$fragment->appendChild($child);
|
||||
}
|
||||
|
||||
$element->parentNode->replaceChild($fragment, $element);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function strip_attr($attrib, $xpath)
|
||||
{
|
||||
$elements = $xpath->query('//*[@' . $attrib . ']');
|
||||
|
||||
foreach ($elements as $element)
|
||||
{
|
||||
$element->removeAttribute($attrib);
|
||||
}
|
||||
}
|
||||
|
||||
protected function add_attr($tag, $valuePairs, $document)
|
||||
{
|
||||
$elements = $document->getElementsByTagName($tag);
|
||||
foreach ($elements as $element)
|
||||
{
|
||||
foreach ($valuePairs as $attrib => $value)
|
||||
{
|
||||
$element->setAttribute($attrib, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (\false) {
|
||||
/** @deprecated since SimplePie 1.7.0, use "SimplePie\Sanitize" instead */
|
||||
class SimplePie_Sanitize extends Sanitize
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* 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
|
||||
* Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
|
@ -41,537 +43,15 @@
|
|||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Handles `<atom:source>`
|
||||
*
|
||||
* Used by {@see SimplePie_Item::get_source()}
|
||||
*
|
||||
* This class can be overloaded with {@see SimplePie::set_source_class()}
|
||||
*
|
||||
* @package SimplePie
|
||||
* @subpackage API
|
||||
*/
|
||||
class SimplePie_Source
|
||||
{
|
||||
var $item;
|
||||
var $data = array();
|
||||
protected $registry;
|
||||
use SimplePie\Source;
|
||||
|
||||
public function __construct($item, $data)
|
||||
{
|
||||
$this->item = $item;
|
||||
$this->data = $data;
|
||||
}
|
||||
class_exists('SimplePie\Source');
|
||||
|
||||
public function set_registry(SimplePie_Registry $registry)
|
||||
{
|
||||
$this->registry = $registry;
|
||||
}
|
||||
// @trigger_error(sprintf('Using the "SimplePie_Source" class is deprecated since SimplePie 1.7.0, use "SimplePie\Source" instead.'), \E_USER_DEPRECATED);
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return md5(serialize($this->data));
|
||||
}
|
||||
|
||||
public function get_source_tags($namespace, $tag)
|
||||
{
|
||||
if (isset($this->data['child'][$namespace][$tag]))
|
||||
{
|
||||
return $this->data['child'][$namespace][$tag];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function get_base($element = array())
|
||||
{
|
||||
return $this->item->get_base($element);
|
||||
}
|
||||
|
||||
public function sanitize($data, $type, $base = '')
|
||||
{
|
||||
return $this->item->sanitize($data, $type, $base);
|
||||
}
|
||||
|
||||
public function get_item()
|
||||
{
|
||||
return $this->item;
|
||||
}
|
||||
|
||||
public function get_title()
|
||||
{
|
||||
if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'title'))
|
||||
{
|
||||
return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
|
||||
}
|
||||
elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'title'))
|
||||
{
|
||||
return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
|
||||
}
|
||||
elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title'))
|
||||
{
|
||||
return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
|
||||
}
|
||||
elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title'))
|
||||
{
|
||||
return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
|
||||
}
|
||||
elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title'))
|
||||
{
|
||||
return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
|
||||
}
|
||||
elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title'))
|
||||
{
|
||||
return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
|
||||
}
|
||||
elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title'))
|
||||
{
|
||||
return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function get_category($key = 0)
|
||||
{
|
||||
$categories = $this->get_categories();
|
||||
if (isset($categories[$key]))
|
||||
{
|
||||
return $categories[$key];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function get_categories()
|
||||
{
|
||||
$categories = array();
|
||||
|
||||
foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'category') as $category)
|
||||
{
|
||||
$term = null;
|
||||
$scheme = null;
|
||||
$label = null;
|
||||
if (isset($category['attribs']['']['term']))
|
||||
{
|
||||
$term = $this->sanitize($category['attribs']['']['term'], SIMPLEPIE_CONSTRUCT_TEXT);
|
||||
}
|
||||
if (isset($category['attribs']['']['scheme']))
|
||||
{
|
||||
$scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
|
||||
}
|
||||
if (isset($category['attribs']['']['label']))
|
||||
{
|
||||
$label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
|
||||
}
|
||||
$categories[] = $this->registry->create('Category', array($term, $scheme, $label));
|
||||
}
|
||||
foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'category') as $category)
|
||||
{
|
||||
// This is really the label, but keep this as the term also for BC.
|
||||
// Label will also work on retrieving because that falls back to term.
|
||||
$term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
|
||||
if (isset($category['attribs']['']['domain']))
|
||||
{
|
||||
$scheme = $this->sanitize($category['attribs']['']['domain'], SIMPLEPIE_CONSTRUCT_TEXT);
|
||||
}
|
||||
else
|
||||
{
|
||||
$scheme = null;
|
||||
}
|
||||
$categories[] = $this->registry->create('Category', array($term, $scheme, null));
|
||||
}
|
||||
foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'subject') as $category)
|
||||
{
|
||||
$categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
|
||||
}
|
||||
foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'subject') as $category)
|
||||
{
|
||||
$categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
|
||||
}
|
||||
|
||||
if (!empty($categories))
|
||||
{
|
||||
return array_unique($categories);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function get_author($key = 0)
|
||||
{
|
||||
$authors = $this->get_authors();
|
||||
if (isset($authors[$key]))
|
||||
{
|
||||
return $authors[$key];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function get_authors()
|
||||
{
|
||||
$authors = array();
|
||||
foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author') as $author)
|
||||
{
|
||||
$name = null;
|
||||
$uri = null;
|
||||
$email = null;
|
||||
if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
|
||||
{
|
||||
$name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
|
||||
}
|
||||
if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
|
||||
{
|
||||
$uri = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]));
|
||||
}
|
||||
if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
|
||||
{
|
||||
$email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
|
||||
}
|
||||
if ($name !== null || $email !== null || $uri !== null)
|
||||
{
|
||||
$authors[] = $this->registry->create('Author', array($name, $uri, $email));
|
||||
}
|
||||
}
|
||||
if ($author = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author'))
|
||||
{
|
||||
$name = null;
|
||||
$url = null;
|
||||
$email = null;
|
||||
if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
|
||||
{
|
||||
$name = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
|
||||
}
|
||||
if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
|
||||
{
|
||||
$url = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]));
|
||||
}
|
||||
if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
|
||||
{
|
||||
$email = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
|
||||
}
|
||||
if ($name !== null || $email !== null || $url !== null)
|
||||
{
|
||||
$authors[] = $this->registry->create('Author', array($name, $url, $email));
|
||||
}
|
||||
}
|
||||
foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'creator') as $author)
|
||||
{
|
||||
$authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
|
||||
}
|
||||
foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'creator') as $author)
|
||||
{
|
||||
$authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
|
||||
}
|
||||
foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'author') as $author)
|
||||
{
|
||||
$authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
|
||||
}
|
||||
|
||||
if (!empty($authors))
|
||||
{
|
||||
return array_unique($authors);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function get_contributor($key = 0)
|
||||
{
|
||||
$contributors = $this->get_contributors();
|
||||
if (isset($contributors[$key]))
|
||||
{
|
||||
return $contributors[$key];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function get_contributors()
|
||||
{
|
||||
$contributors = array();
|
||||
foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'contributor') as $contributor)
|
||||
{
|
||||
$name = null;
|
||||
$uri = null;
|
||||
$email = null;
|
||||
if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
|
||||
{
|
||||
$name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
|
||||
}
|
||||
if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
|
||||
{
|
||||
$uri = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]));
|
||||
}
|
||||
if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
|
||||
{
|
||||
$email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
|
||||
}
|
||||
if ($name !== null || $email !== null || $uri !== null)
|
||||
{
|
||||
$contributors[] = $this->registry->create('Author', array($name, $uri, $email));
|
||||
}
|
||||
}
|
||||
foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'contributor') as $contributor)
|
||||
{
|
||||
$name = null;
|
||||
$url = null;
|
||||
$email = null;
|
||||
if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
|
||||
{
|
||||
$name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
|
||||
}
|
||||
if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
|
||||
{
|
||||
$url = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]));
|
||||
}
|
||||
if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
|
||||
{
|
||||
$email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
|
||||
}
|
||||
if ($name !== null || $email !== null || $url !== null)
|
||||
{
|
||||
$contributors[] = $this->registry->create('Author', array($name, $url, $email));
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($contributors))
|
||||
{
|
||||
return array_unique($contributors);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function get_link($key = 0, $rel = 'alternate')
|
||||
{
|
||||
$links = $this->get_links($rel);
|
||||
if (isset($links[$key]))
|
||||
{
|
||||
return $links[$key];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Added for parity between the parent-level and the item/entry-level.
|
||||
*/
|
||||
public function get_permalink()
|
||||
{
|
||||
return $this->get_link(0);
|
||||
}
|
||||
|
||||
public function get_links($rel = 'alternate')
|
||||
{
|
||||
if (!isset($this->data['links']))
|
||||
{
|
||||
$this->data['links'] = array();
|
||||
if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link'))
|
||||
{
|
||||
foreach ($links as $link)
|
||||
{
|
||||
if (isset($link['attribs']['']['href']))
|
||||
{
|
||||
$link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
|
||||
$this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link'))
|
||||
{
|
||||
foreach ($links as $link)
|
||||
{
|
||||
if (isset($link['attribs']['']['href']))
|
||||
{
|
||||
$link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
|
||||
$this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link'))
|
||||
{
|
||||
$this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
|
||||
}
|
||||
if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link'))
|
||||
{
|
||||
$this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
|
||||
}
|
||||
if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link'))
|
||||
{
|
||||
$this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
|
||||
}
|
||||
|
||||
$keys = array_keys($this->data['links']);
|
||||
foreach ($keys as $key)
|
||||
{
|
||||
if ($this->registry->call('Misc', 'is_isegment_nz_nc', array($key)))
|
||||
{
|
||||
if (isset($this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]))
|
||||
{
|
||||
$this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]);
|
||||
$this->data['links'][$key] =& $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key];
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] =& $this->data['links'][$key];
|
||||
}
|
||||
}
|
||||
elseif (substr($key, 0, 41) === SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY)
|
||||
{
|
||||
$this->data['links'][substr($key, 41)] =& $this->data['links'][$key];
|
||||
}
|
||||
$this->data['links'][$key] = array_unique($this->data['links'][$key]);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($this->data['links'][$rel]))
|
||||
{
|
||||
return $this->data['links'][$rel];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function get_description()
|
||||
{
|
||||
if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'subtitle'))
|
||||
{
|
||||
return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
|
||||
}
|
||||
elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'tagline'))
|
||||
{
|
||||
return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
|
||||
}
|
||||
elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'description'))
|
||||
{
|
||||
return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
|
||||
}
|
||||
elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'description'))
|
||||
{
|
||||
return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
|
||||
}
|
||||
elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'description'))
|
||||
{
|
||||
return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
|
||||
}
|
||||
elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'description'))
|
||||
{
|
||||
return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
|
||||
}
|
||||
elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'description'))
|
||||
{
|
||||
return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
|
||||
}
|
||||
elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'summary'))
|
||||
{
|
||||
return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
|
||||
}
|
||||
elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'subtitle'))
|
||||
{
|
||||
return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function get_copyright()
|
||||
{
|
||||
if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'rights'))
|
||||
{
|
||||
return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
|
||||
}
|
||||
elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'copyright'))
|
||||
{
|
||||
return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
|
||||
}
|
||||
elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'copyright'))
|
||||
{
|
||||
return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
|
||||
}
|
||||
elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'rights'))
|
||||
{
|
||||
return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
|
||||
}
|
||||
elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'rights'))
|
||||
{
|
||||
return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function get_language()
|
||||
{
|
||||
if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'language'))
|
||||
{
|
||||
return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
|
||||
}
|
||||
elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'language'))
|
||||
{
|
||||
return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
|
||||
}
|
||||
elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'language'))
|
||||
{
|
||||
return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
|
||||
}
|
||||
elseif (isset($this->data['xml_lang']))
|
||||
{
|
||||
return $this->sanitize($this->data['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function get_latitude()
|
||||
{
|
||||
if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lat'))
|
||||
{
|
||||
return (float) $return[0]['data'];
|
||||
}
|
||||
elseif (($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', trim($return[0]['data']), $match))
|
||||
{
|
||||
return (float) $match[1];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function get_longitude()
|
||||
{
|
||||
if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'long'))
|
||||
{
|
||||
return (float) $return[0]['data'];
|
||||
}
|
||||
elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lon'))
|
||||
{
|
||||
return (float) $return[0]['data'];
|
||||
}
|
||||
elseif (($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', trim($return[0]['data']), $match))
|
||||
{
|
||||
return (float) $match[2];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function get_image_url()
|
||||
{
|
||||
if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'image'))
|
||||
{
|
||||
return $this->sanitize($return[0]['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI);
|
||||
}
|
||||
elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'logo'))
|
||||
{
|
||||
return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
|
||||
}
|
||||
elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'icon'))
|
||||
{
|
||||
return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
if (\false) {
|
||||
/** @deprecated since SimplePie 1.7.0, use "SimplePie\Source" instead */
|
||||
class SimplePie_Source extends Source
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* 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
|
||||
* Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
|
@ -41,319 +43,15 @@
|
|||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
*/
|
||||
|
||||
use SimplePie\XML\Declaration\Parser;
|
||||
|
||||
/**
|
||||
* Parses the XML Declaration
|
||||
*
|
||||
* @package SimplePie
|
||||
* @subpackage Parsing
|
||||
*/
|
||||
class SimplePie_XML_Declaration_Parser
|
||||
{
|
||||
/**
|
||||
* XML Version
|
||||
*
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
var $version = '1.0';
|
||||
class_exists('SimplePie\XML\Declaration\Parser');
|
||||
|
||||
/**
|
||||
* Encoding
|
||||
*
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
var $encoding = 'UTF-8';
|
||||
// @trigger_error(sprintf('Using the "SimplePie_XML_Declaration_Parser" class is deprecated since SimplePie 1.7.0, use "SimplePie\XML\Declaration\Parser" instead.'), \E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* Standalone
|
||||
*
|
||||
* @access public
|
||||
* @var bool
|
||||
*/
|
||||
var $standalone = false;
|
||||
|
||||
/**
|
||||
* Current state of the state machine
|
||||
*
|
||||
* @access private
|
||||
* @var string
|
||||
*/
|
||||
var $state = 'before_version_name';
|
||||
|
||||
/**
|
||||
* Input data
|
||||
*
|
||||
* @access private
|
||||
* @var string
|
||||
*/
|
||||
var $data = '';
|
||||
|
||||
/**
|
||||
* Input data length (to avoid calling strlen() everytime this is needed)
|
||||
*
|
||||
* @access private
|
||||
* @var int
|
||||
*/
|
||||
var $data_length = 0;
|
||||
|
||||
/**
|
||||
* Current position of the pointer
|
||||
*
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $position = 0;
|
||||
|
||||
/**
|
||||
* Create an instance of the class with the input data
|
||||
*
|
||||
* @access public
|
||||
* @param string $data Input data
|
||||
*/
|
||||
public function __construct($data)
|
||||
{
|
||||
$this->data = $data;
|
||||
$this->data_length = strlen($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the input data
|
||||
*
|
||||
* @access public
|
||||
* @return bool true on success, false on failure
|
||||
*/
|
||||
public function parse()
|
||||
{
|
||||
while ($this->state && $this->state !== 'emit' && $this->has_data())
|
||||
{
|
||||
$state = $this->state;
|
||||
$this->$state();
|
||||
}
|
||||
$this->data = '';
|
||||
if ($this->state === 'emit')
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->version = '';
|
||||
$this->encoding = '';
|
||||
$this->standalone = '';
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether there is data beyond the pointer
|
||||
*
|
||||
* @access private
|
||||
* @return bool true if there is further data, false if not
|
||||
*/
|
||||
public function has_data()
|
||||
{
|
||||
return (bool) ($this->position < $this->data_length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Advance past any whitespace
|
||||
*
|
||||
* @return int Number of whitespace characters passed
|
||||
*/
|
||||
public function skip_whitespace()
|
||||
{
|
||||
$whitespace = strspn($this->data, "\x09\x0A\x0D\x20", $this->position);
|
||||
$this->position += $whitespace;
|
||||
return $whitespace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read value
|
||||
*/
|
||||
public function get_value()
|
||||
{
|
||||
$quote = substr($this->data, $this->position, 1);
|
||||
if ($quote === '"' || $quote === "'")
|
||||
{
|
||||
$this->position++;
|
||||
$len = strcspn($this->data, $quote, $this->position);
|
||||
if ($this->has_data())
|
||||
{
|
||||
$value = substr($this->data, $this->position, $len);
|
||||
$this->position += $len + 1;
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function before_version_name()
|
||||
{
|
||||
if ($this->skip_whitespace())
|
||||
{
|
||||
$this->state = 'version_name';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->state = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function version_name()
|
||||
{
|
||||
if (substr($this->data, $this->position, 7) === 'version')
|
||||
{
|
||||
$this->position += 7;
|
||||
$this->skip_whitespace();
|
||||
$this->state = 'version_equals';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->state = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function version_equals()
|
||||
{
|
||||
if (substr($this->data, $this->position, 1) === '=')
|
||||
{
|
||||
$this->position++;
|
||||
$this->skip_whitespace();
|
||||
$this->state = 'version_value';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->state = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function version_value()
|
||||
{
|
||||
if ($this->version = $this->get_value())
|
||||
{
|
||||
$this->skip_whitespace();
|
||||
if ($this->has_data())
|
||||
{
|
||||
$this->state = 'encoding_name';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->state = 'emit';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->state = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function encoding_name()
|
||||
{
|
||||
if (substr($this->data, $this->position, 8) === 'encoding')
|
||||
{
|
||||
$this->position += 8;
|
||||
$this->skip_whitespace();
|
||||
$this->state = 'encoding_equals';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->state = 'standalone_name';
|
||||
}
|
||||
}
|
||||
|
||||
public function encoding_equals()
|
||||
{
|
||||
if (substr($this->data, $this->position, 1) === '=')
|
||||
{
|
||||
$this->position++;
|
||||
$this->skip_whitespace();
|
||||
$this->state = 'encoding_value';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->state = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function encoding_value()
|
||||
{
|
||||
if ($this->encoding = $this->get_value())
|
||||
{
|
||||
$this->skip_whitespace();
|
||||
if ($this->has_data())
|
||||
{
|
||||
$this->state = 'standalone_name';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->state = 'emit';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->state = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function standalone_name()
|
||||
{
|
||||
if (substr($this->data, $this->position, 10) === 'standalone')
|
||||
{
|
||||
$this->position += 10;
|
||||
$this->skip_whitespace();
|
||||
$this->state = 'standalone_equals';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->state = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function standalone_equals()
|
||||
{
|
||||
if (substr($this->data, $this->position, 1) === '=')
|
||||
{
|
||||
$this->position++;
|
||||
$this->skip_whitespace();
|
||||
$this->state = 'standalone_value';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->state = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function standalone_value()
|
||||
{
|
||||
if ($standalone = $this->get_value())
|
||||
{
|
||||
switch ($standalone)
|
||||
{
|
||||
case 'yes':
|
||||
$this->standalone = true;
|
||||
break;
|
||||
|
||||
case 'no':
|
||||
$this->standalone = false;
|
||||
break;
|
||||
|
||||
default:
|
||||
$this->state = false;
|
||||
return;
|
||||
}
|
||||
|
||||
$this->skip_whitespace();
|
||||
if ($this->has_data())
|
||||
{
|
||||
$this->state = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->state = 'emit';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->state = false;
|
||||
}
|
||||
}
|
||||
if (\false) {
|
||||
/** @deprecated since SimplePie 1.7.0, use "SimplePie\XML\Declaration\Parser" instead */
|
||||
class SimplePie_XML_Declaration_Parser extends Parser
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* 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
|
||||
* Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
|
@ -41,326 +43,15 @@
|
|||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
*/
|
||||
|
||||
use SimplePie\Gzdecode;
|
||||
|
||||
/**
|
||||
* Decode 'gzip' encoded HTTP data
|
||||
*
|
||||
* @package SimplePie
|
||||
* @subpackage HTTP
|
||||
* @link http://www.gzip.org/format.txt
|
||||
*/
|
||||
class SimplePie_gzdecode
|
||||
{
|
||||
/**
|
||||
* Compressed data
|
||||
*
|
||||
* @access private
|
||||
* @var string
|
||||
* @see gzdecode::$data
|
||||
*/
|
||||
var $compressed_data;
|
||||
class_exists('SimplePie\Gzdecode');
|
||||
|
||||
/**
|
||||
* Size of compressed data
|
||||
*
|
||||
* @access private
|
||||
* @var int
|
||||
*/
|
||||
var $compressed_size;
|
||||
// @trigger_error(sprintf('Using the "SimplePie_gzdecode" class is deprecated since SimplePie 1.7.0, use "SimplePie\Gzdecode" instead.'), \E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* Minimum size of a valid gzip string
|
||||
*
|
||||
* @access private
|
||||
* @var int
|
||||
*/
|
||||
var $min_compressed_size = 18;
|
||||
|
||||
/**
|
||||
* Current position of pointer
|
||||
*
|
||||
* @access private
|
||||
* @var int
|
||||
*/
|
||||
var $position = 0;
|
||||
|
||||
/**
|
||||
* Flags (FLG)
|
||||
*
|
||||
* @access private
|
||||
* @var int
|
||||
*/
|
||||
var $flags;
|
||||
|
||||
/**
|
||||
* Uncompressed data
|
||||
*
|
||||
* @access public
|
||||
* @see gzdecode::$compressed_data
|
||||
* @var string
|
||||
*/
|
||||
var $data;
|
||||
|
||||
/**
|
||||
* Modified time
|
||||
*
|
||||
* @access public
|
||||
* @var int
|
||||
*/
|
||||
var $MTIME;
|
||||
|
||||
/**
|
||||
* Extra Flags
|
||||
*
|
||||
* @access public
|
||||
* @var int
|
||||
*/
|
||||
var $XFL;
|
||||
|
||||
/**
|
||||
* Operating System
|
||||
*
|
||||
* @access public
|
||||
* @var int
|
||||
*/
|
||||
var $OS;
|
||||
|
||||
/**
|
||||
* Subfield ID 1
|
||||
*
|
||||
* @access public
|
||||
* @see gzdecode::$extra_field
|
||||
* @see gzdecode::$SI2
|
||||
* @var string
|
||||
*/
|
||||
var $SI1;
|
||||
|
||||
/**
|
||||
* Subfield ID 2
|
||||
*
|
||||
* @access public
|
||||
* @see gzdecode::$extra_field
|
||||
* @see gzdecode::$SI1
|
||||
* @var string
|
||||
*/
|
||||
var $SI2;
|
||||
|
||||
/**
|
||||
* Extra field content
|
||||
*
|
||||
* @access public
|
||||
* @see gzdecode::$SI1
|
||||
* @see gzdecode::$SI2
|
||||
* @var string
|
||||
*/
|
||||
var $extra_field;
|
||||
|
||||
/**
|
||||
* Original filename
|
||||
*
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
var $filename;
|
||||
|
||||
/**
|
||||
* Human readable comment
|
||||
*
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
var $comment;
|
||||
|
||||
/**
|
||||
* Don't allow anything to be set
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function __set($name, $value)
|
||||
{
|
||||
trigger_error("Cannot write property $name", E_USER_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the compressed string and related properties
|
||||
*
|
||||
* @param string $data
|
||||
*/
|
||||
public function __construct($data)
|
||||
{
|
||||
$this->compressed_data = $data;
|
||||
$this->compressed_size = strlen($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode the GZIP stream
|
||||
*
|
||||
* @return bool Successfulness
|
||||
*/
|
||||
public function parse()
|
||||
{
|
||||
if ($this->compressed_size >= $this->min_compressed_size)
|
||||
{
|
||||
// Check ID1, ID2, and CM
|
||||
if (substr($this->compressed_data, 0, 3) !== "\x1F\x8B\x08")
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get the FLG (FLaGs)
|
||||
$this->flags = ord($this->compressed_data[3]);
|
||||
|
||||
// FLG bits above (1 << 4) are reserved
|
||||
if ($this->flags > 0x1F)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Advance the pointer after the above
|
||||
$this->position += 4;
|
||||
|
||||
// MTIME
|
||||
$mtime = substr($this->compressed_data, $this->position, 4);
|
||||
// Reverse the string if we're on a big-endian arch because l is the only signed long and is machine endianness
|
||||
if (current(unpack('S', "\x00\x01")) === 1)
|
||||
{
|
||||
$mtime = strrev($mtime);
|
||||
}
|
||||
$this->MTIME = current(unpack('l', $mtime));
|
||||
$this->position += 4;
|
||||
|
||||
// Get the XFL (eXtra FLags)
|
||||
$this->XFL = ord($this->compressed_data[$this->position++]);
|
||||
|
||||
// Get the OS (Operating System)
|
||||
$this->OS = ord($this->compressed_data[$this->position++]);
|
||||
|
||||
// Parse the FEXTRA
|
||||
if ($this->flags & 4)
|
||||
{
|
||||
// Read subfield IDs
|
||||
$this->SI1 = $this->compressed_data[$this->position++];
|
||||
$this->SI2 = $this->compressed_data[$this->position++];
|
||||
|
||||
// SI2 set to zero is reserved for future use
|
||||
if ($this->SI2 === "\x00")
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get the length of the extra field
|
||||
$len = current(unpack('v', substr($this->compressed_data, $this->position, 2)));
|
||||
$this->position += 2;
|
||||
|
||||
// Check the length of the string is still valid
|
||||
$this->min_compressed_size += $len + 4;
|
||||
if ($this->compressed_size >= $this->min_compressed_size)
|
||||
{
|
||||
// Set the extra field to the given data
|
||||
$this->extra_field = substr($this->compressed_data, $this->position, $len);
|
||||
$this->position += $len;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Parse the FNAME
|
||||
if ($this->flags & 8)
|
||||
{
|
||||
// Get the length of the filename
|
||||
$len = strcspn($this->compressed_data, "\x00", $this->position);
|
||||
|
||||
// Check the length of the string is still valid
|
||||
$this->min_compressed_size += $len + 1;
|
||||
if ($this->compressed_size >= $this->min_compressed_size)
|
||||
{
|
||||
// Set the original filename to the given string
|
||||
$this->filename = substr($this->compressed_data, $this->position, $len);
|
||||
$this->position += $len + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Parse the FCOMMENT
|
||||
if ($this->flags & 16)
|
||||
{
|
||||
// Get the length of the comment
|
||||
$len = strcspn($this->compressed_data, "\x00", $this->position);
|
||||
|
||||
// Check the length of the string is still valid
|
||||
$this->min_compressed_size += $len + 1;
|
||||
if ($this->compressed_size >= $this->min_compressed_size)
|
||||
{
|
||||
// Set the original comment to the given string
|
||||
$this->comment = substr($this->compressed_data, $this->position, $len);
|
||||
$this->position += $len + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Parse the FHCRC
|
||||
if ($this->flags & 2)
|
||||
{
|
||||
// Check the length of the string is still valid
|
||||
$this->min_compressed_size += $len + 2;
|
||||
if ($this->compressed_size >= $this->min_compressed_size)
|
||||
{
|
||||
// Read the CRC
|
||||
$crc = current(unpack('v', substr($this->compressed_data, $this->position, 2)));
|
||||
|
||||
// Check the CRC matches
|
||||
if ((crc32(substr($this->compressed_data, 0, $this->position)) & 0xFFFF) === $crc)
|
||||
{
|
||||
$this->position += 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Decompress the actual data
|
||||
if (($this->data = gzinflate(substr($this->compressed_data, $this->position, -8))) === false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->position = $this->compressed_size - 8;
|
||||
|
||||
// Check CRC of data
|
||||
$crc = current(unpack('V', substr($this->compressed_data, $this->position, 4)));
|
||||
$this->position += 4;
|
||||
/*if (extension_loaded('hash') && sprintf('%u', current(unpack('V', hash('crc32b', $this->data)))) !== sprintf('%u', $crc))
|
||||
{
|
||||
return false;
|
||||
}*/
|
||||
|
||||
// Check ISIZE of data
|
||||
$isize = current(unpack('V', substr($this->compressed_data, $this->position, 4)));
|
||||
$this->position += 4;
|
||||
if (sprintf('%u', strlen($this->data) & 0xFFFFFFFF) !== sprintf('%u', $isize))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Wow, against all odds, we've actually got a valid gzip string
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
if (\false) {
|
||||
/** @deprecated since SimplePie 1.7.0, use "SimplePie\Gzdecode" instead */
|
||||
class SimplePie_gzdecode extends Gzdecode
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,152 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2022, 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
|
||||
*/
|
||||
|
||||
namespace SimplePie;
|
||||
|
||||
/**
|
||||
* Manages all author-related data
|
||||
*
|
||||
* Used by {@see Item::get_author()} and {@see SimplePie::get_authors()}
|
||||
*
|
||||
* This class can be overloaded with {@see SimplePie::set_author_class()}
|
||||
*
|
||||
* @package SimplePie
|
||||
* @subpackage API
|
||||
*/
|
||||
class Author
|
||||
{
|
||||
/**
|
||||
* Author's name
|
||||
*
|
||||
* @var string
|
||||
* @see get_name()
|
||||
*/
|
||||
public $name;
|
||||
|
||||
/**
|
||||
* Author's link
|
||||
*
|
||||
* @var string
|
||||
* @see get_link()
|
||||
*/
|
||||
public $link;
|
||||
|
||||
/**
|
||||
* Author's email address
|
||||
*
|
||||
* @var string
|
||||
* @see get_email()
|
||||
*/
|
||||
public $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;
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('SimplePie\Author', 'SimplePie_Author');
|
|
@ -0,0 +1,144 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2022, 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
|
||||
*/
|
||||
|
||||
namespace SimplePie;
|
||||
|
||||
use SimplePie\Cache\Base;
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @deprecated since SimplePie 1.8.0, use "SimplePie\SimplePie::set_cache()" instead
|
||||
*/
|
||||
class Cache
|
||||
{
|
||||
/**
|
||||
* Cache handler classes
|
||||
*
|
||||
* These receive 3 parameters to their constructor, as documented in
|
||||
* {@see register()}
|
||||
* @var array
|
||||
*/
|
||||
protected static $handlers = [
|
||||
'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 Base::TYPE_FEED|Base::TYPE_IMAGE $extension 'spi' or 'spc'
|
||||
* @return 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 since SimplePie 1.3.1, use {@see get_handler()} instead
|
||||
*/
|
||||
public function create($location, $filename, $extension)
|
||||
{
|
||||
trigger_error('Cache::create() has been replaced with Cache::get_handler() since SimplePie 1.3.1, use the registry system instead.', \E_USER_DEPRECATED);
|
||||
|
||||
return self::get_handler($location, $filename, $extension);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a handler
|
||||
*
|
||||
* @param string $type DSN type to register for
|
||||
* @param class-string<Base> $class Name of handler class. Must implement 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'] = [];
|
||||
if (isset($params['query'])) {
|
||||
parse_str($params['query'], $params['extras']);
|
||||
}
|
||||
return $params;
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('SimplePie\Cache', 'SimplePie_Cache');
|
|
@ -0,0 +1,120 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2022, 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
|
||||
*/
|
||||
|
||||
namespace SimplePie\Cache;
|
||||
|
||||
/**
|
||||
* Base for cache objects
|
||||
*
|
||||
* Classes to be used with {@see \SimplePie\Cache::register()} are expected
|
||||
* to implement this interface.
|
||||
*
|
||||
* @package SimplePie
|
||||
* @subpackage Caching
|
||||
* @deprecated since SimplePie 1.8.0, use "Psr\SimpleCache\CacheInterface" instead
|
||||
*/
|
||||
interface Base
|
||||
{
|
||||
/**
|
||||
* Feed cache type
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public const TYPE_FEED = 'spc';
|
||||
|
||||
/**
|
||||
* Image cache type
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public 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 Base::TYPE_FEED|Base::TYPE_IMAGE $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\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();
|
||||
}
|
||||
|
||||
class_alias('SimplePie\Cache\Base', 'SimplePie_Cache_Base');
|
|
@ -0,0 +1,159 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2022, 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-2022 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
|
||||
*/
|
||||
|
||||
namespace SimplePie\Cache;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Adapter for deprecated \SimplePie\Cache\Base implementations
|
||||
*
|
||||
* @package SimplePie
|
||||
* @subpackage Caching
|
||||
* @internal
|
||||
*/
|
||||
final class BaseDataCache implements DataCache
|
||||
{
|
||||
/**
|
||||
* @var Base
|
||||
*/
|
||||
private $cache;
|
||||
|
||||
public function __construct(Base $cache)
|
||||
{
|
||||
$this->cache = $cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches a value from the cache.
|
||||
*
|
||||
* Equivalent to \Psr\SimpleCache\CacheInterface::get()
|
||||
* <code>
|
||||
* public function get(string $key, mixed $default = null): mixed;
|
||||
* </code>
|
||||
*
|
||||
* @param string $key The unique key of this item in the cache.
|
||||
* @param mixed $default Default value to return if the key does not exist.
|
||||
*
|
||||
* @return array|mixed The value of the item from the cache, or $default in case of cache miss.
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
* MUST be thrown if the $key string is not a legal value.
|
||||
*/
|
||||
public function get_data(string $key, $default = null)
|
||||
{
|
||||
$data = $this->cache->load();
|
||||
|
||||
if (! is_array($data)) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
// ignore data if internal cache expiration time is not set
|
||||
if (! array_key_exists('__cache_expiration_time', $data)) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
// ignore data if internal cache expiration time is expired
|
||||
if ($data['__cache_expiration_time'] < time()) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
// remove internal cache expiration time
|
||||
unset($data['__cache_expiration_time']);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Persists data in the cache, uniquely referenced by a key with an optional expiration TTL time.
|
||||
*
|
||||
* Equivalent to \Psr\SimpleCache\CacheInterface::set()
|
||||
* <code>
|
||||
* public function set(string $key, mixed $value, null|int|\DateInterval $ttl = null): bool;
|
||||
* </code>
|
||||
*
|
||||
* @param string $key The key of the item to store.
|
||||
* @param array $value The value of the item to store, must be serializable.
|
||||
* @param null|int $ttl Optional. The TTL value of this item. If no value is sent and
|
||||
* the driver supports TTL then the library may set a default value
|
||||
* for it or let the driver take care of that.
|
||||
*
|
||||
* @return bool True on success and false on failure.
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
* MUST be thrown if the $key string is not a legal value.
|
||||
*/
|
||||
public function set_data(string $key, array $value, ?int $ttl = null): bool
|
||||
{
|
||||
if ($ttl === null) {
|
||||
$ttl = 3600;
|
||||
}
|
||||
|
||||
// place internal cache expiration time
|
||||
$value['__cache_expiration_time'] = time() + $ttl;
|
||||
|
||||
return $this->cache->save($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an item from the cache by its unique key.
|
||||
*
|
||||
* Equivalent to \Psr\SimpleCache\CacheInterface::delete()
|
||||
* <code>
|
||||
* public function delete(string $key): bool;
|
||||
* </code>
|
||||
*
|
||||
* @param string $key The unique cache key of the item to delete.
|
||||
*
|
||||
* @return bool True if the item was successfully removed. False if there was an error.
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
* MUST be thrown if the $key string is not a legal value.
|
||||
*/
|
||||
public function delete_data(string $key): bool
|
||||
{
|
||||
return $this->cache->unlink();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
<?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-2022, 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-2022 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
|
||||
*/
|
||||
|
||||
namespace SimplePie\Cache;
|
||||
|
||||
/**
|
||||
* Creating a cache filename with callables
|
||||
*
|
||||
* @package SimplePie
|
||||
* @subpackage Caching
|
||||
*/
|
||||
final class CallableNameFilter implements NameFilter
|
||||
{
|
||||
/**
|
||||
* @var callable
|
||||
*/
|
||||
private $callable;
|
||||
|
||||
public function __construct(callable $callable)
|
||||
{
|
||||
$this->callable = $callable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to create cache filename with.
|
||||
*
|
||||
* The returning name MUST follow the rules for keys in PSR-16.
|
||||
*
|
||||
* @link https://www.php-fig.org/psr/psr-16/
|
||||
*
|
||||
* The returning name MUST be a string of at least one character
|
||||
* that uniquely identifies a cached item, MUST only contain the
|
||||
* characters A-Z, a-z, 0-9, _, and . in any order in UTF-8 encoding
|
||||
* and MUST not longer then 64 characters. The following characters
|
||||
* are reserved for future extensions and MUST NOT be used: {}()/\@:
|
||||
*
|
||||
* A provided implementing library MAY support additional characters
|
||||
* and encodings or longer lengths, but MUST support at least that
|
||||
* minimum.
|
||||
*
|
||||
* @param string $name The name for the cache will be most likly an url with query string
|
||||
*
|
||||
* @return string the new cache name
|
||||
*/
|
||||
public function filter(string $name): string
|
||||
{
|
||||
return call_user_func($this->callable, $name);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,122 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2022, 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
|
||||
*/
|
||||
|
||||
namespace SimplePie\Cache;
|
||||
|
||||
/**
|
||||
* Base class for database-based caches
|
||||
*
|
||||
* @package SimplePie
|
||||
* @subpackage Caching
|
||||
* @deprecated since SimplePie 1.8.0, use implementation of "Psr\SimpleCache\CacheInterface" instead
|
||||
*/
|
||||
abstract class DB implements Base
|
||||
{
|
||||
/**
|
||||
* Helper for database conversion
|
||||
*
|
||||
* Converts a given {@see SimplePie} object into data to be stored
|
||||
*
|
||||
* @param \SimplePie\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 = [];
|
||||
|
||||
if (!empty($items)) {
|
||||
foreach ($items as $item) {
|
||||
$items_by_id[$item->get_id()] = $item;
|
||||
}
|
||||
|
||||
if (count($items_by_id) !== count($items)) {
|
||||
$items_by_id = [];
|
||||
foreach ($items as $item) {
|
||||
$items_by_id[$item->get_id(true)] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data->data['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['feed'][0])) {
|
||||
$channel =& $data->data['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['feed'][0];
|
||||
} elseif (isset($data->data['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_03]['feed'][0])) {
|
||||
$channel =& $data->data['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_03]['feed'][0];
|
||||
} elseif (isset($data->data['child'][\SimplePie\SimplePie::NAMESPACE_RDF]['RDF'][0])) {
|
||||
$channel =& $data->data['child'][\SimplePie\SimplePie::NAMESPACE_RDF]['RDF'][0];
|
||||
} elseif (isset($data->data['child'][\SimplePie\SimplePie::NAMESPACE_RSS_20]['rss'][0]['child'][\SimplePie\SimplePie::NAMESPACE_RSS_20]['channel'][0])) {
|
||||
$channel =& $data->data['child'][\SimplePie\SimplePie::NAMESPACE_RSS_20]['rss'][0]['child'][\SimplePie\SimplePie::NAMESPACE_RSS_20]['channel'][0];
|
||||
} else {
|
||||
$channel = null;
|
||||
}
|
||||
|
||||
if ($channel !== null) {
|
||||
if (isset($channel['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['entry'])) {
|
||||
unset($channel['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['entry']);
|
||||
}
|
||||
if (isset($channel['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_03]['entry'])) {
|
||||
unset($channel['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_03]['entry']);
|
||||
}
|
||||
if (isset($channel['child'][\SimplePie\SimplePie::NAMESPACE_RSS_10]['item'])) {
|
||||
unset($channel['child'][\SimplePie\SimplePie::NAMESPACE_RSS_10]['item']);
|
||||
}
|
||||
if (isset($channel['child'][\SimplePie\SimplePie::NAMESPACE_RSS_090]['item'])) {
|
||||
unset($channel['child'][\SimplePie\SimplePie::NAMESPACE_RSS_090]['item']);
|
||||
}
|
||||
if (isset($channel['child'][\SimplePie\SimplePie::NAMESPACE_RSS_20]['item'])) {
|
||||
unset($channel['child'][\SimplePie\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 [serialize($data->data), $items_by_id];
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('SimplePie\Cache\DB', 'SimplePie_Cache_DB');
|
|
@ -0,0 +1,120 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2022, 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-2022 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
|
||||
*/
|
||||
|
||||
namespace SimplePie\Cache;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Subset of PSR-16 Cache client for caching data arrays
|
||||
*
|
||||
* Only get(), set() and delete() methods are used,
|
||||
* but not has(), getMultiple(), setMultiple() or deleteMultiple().
|
||||
*
|
||||
* The methods names must be different, but should be compatible to the
|
||||
* methods of \Psr\SimpleCache\CacheInterface.
|
||||
*
|
||||
* @package SimplePie
|
||||
* @subpackage Caching
|
||||
* @internal
|
||||
*/
|
||||
interface DataCache
|
||||
{
|
||||
/**
|
||||
* Fetches a value from the cache.
|
||||
*
|
||||
* Equivalent to \Psr\SimpleCache\CacheInterface::get()
|
||||
* <code>
|
||||
* public function get(string $key, mixed $default = null): mixed;
|
||||
* </code>
|
||||
*
|
||||
* @param string $key The unique key of this item in the cache.
|
||||
* @param mixed $default Default value to return if the key does not exist.
|
||||
*
|
||||
* @return array|mixed The value of the item from the cache, or $default in case of cache miss.
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
* MUST be thrown if the $key string is not a legal value.
|
||||
*/
|
||||
public function get_data(string $key, $default = null);
|
||||
|
||||
/**
|
||||
* Persists data in the cache, uniquely referenced by a key with an optional expiration TTL time.
|
||||
*
|
||||
* Equivalent to \Psr\SimpleCache\CacheInterface::set()
|
||||
* <code>
|
||||
* public function set(string $key, mixed $value, null|int|\DateInterval $ttl = null): bool;
|
||||
* </code>
|
||||
*
|
||||
* @param string $key The key of the item to store.
|
||||
* @param array $value The value of the item to store, must be serializable.
|
||||
* @param null|int $ttl Optional. The TTL value of this item. If no value is sent and
|
||||
* the driver supports TTL then the library may set a default value
|
||||
* for it or let the driver take care of that.
|
||||
*
|
||||
* @return bool True on success and false on failure.
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
* MUST be thrown if the $key string is not a legal value.
|
||||
*/
|
||||
public function set_data(string $key, array $value, ?int $ttl = null): bool;
|
||||
|
||||
/**
|
||||
* Delete an item from the cache by its unique key.
|
||||
*
|
||||
* Equivalent to \Psr\SimpleCache\CacheInterface::delete()
|
||||
* <code>
|
||||
* public function delete(string $key): bool;
|
||||
* </code>
|
||||
*
|
||||
* @param string $key The unique cache key of the item to delete.
|
||||
*
|
||||
* @return bool True if the item was successfully removed. False if there was an error.
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
* MUST be thrown if the $key string is not a legal value.
|
||||
*/
|
||||
public function delete_data(string $key): bool;
|
||||
}
|
|
@ -0,0 +1,167 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2022, 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
|
||||
*/
|
||||
|
||||
namespace SimplePie\Cache;
|
||||
|
||||
/**
|
||||
* Caches data to the filesystem
|
||||
*
|
||||
* @package SimplePie
|
||||
* @subpackage Caching
|
||||
* @deprecated since SimplePie 1.8.0, use implementation of "Psr\SimpleCache\CacheInterface" instead
|
||||
*/
|
||||
class File implements Base
|
||||
{
|
||||
/**
|
||||
* Location string
|
||||
*
|
||||
* @see SimplePie::$cache_location
|
||||
* @var string
|
||||
*/
|
||||
protected $location;
|
||||
|
||||
/**
|
||||
* Filename
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $filename;
|
||||
|
||||
/**
|
||||
* File extension
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $extension;
|
||||
|
||||
/**
|
||||
* File path
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Create a new cache object
|
||||
*
|
||||
* @param string $location Location string (from SimplePie::$cache_location)
|
||||
* @param string $name Unique ID for the cache
|
||||
* @param Base::TYPE_FEED|Base::TYPE_IMAGE $type Either TYPE_FEED for SimplePie data, or TYPE_IMAGE for image data
|
||||
*/
|
||||
public function __construct($location, $name, $type)
|
||||
{
|
||||
$this->location = $location;
|
||||
$this->filename = $name;
|
||||
$this->extension = $type;
|
||||
$this->name = "$this->location/$this->filename.$this->extension";
|
||||
}
|
||||
|
||||
/**
|
||||
* Save data to the cache
|
||||
*
|
||||
* @param array|\SimplePie\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)
|
||||
{
|
||||
if (file_exists($this->name) && is_writable($this->name) || file_exists($this->location) && is_writable($this->location)) {
|
||||
if ($data instanceof \SimplePie\SimplePie) {
|
||||
$data = $data->data;
|
||||
}
|
||||
|
||||
$data = serialize($data);
|
||||
return (bool) file_put_contents($this->name, $data);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the data saved to the cache
|
||||
*
|
||||
* @return array Data for SimplePie::$data
|
||||
*/
|
||||
public function load()
|
||||
{
|
||||
if (file_exists($this->name) && is_readable($this->name)) {
|
||||
return unserialize(file_get_contents($this->name));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the last modified time for the cache
|
||||
*
|
||||
* @return int Timestamp
|
||||
*/
|
||||
public function mtime()
|
||||
{
|
||||
return @filemtime($this->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the last modified time to the current time
|
||||
*
|
||||
* @return bool Success status
|
||||
*/
|
||||
public function touch()
|
||||
{
|
||||
return @touch($this->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the cache
|
||||
*
|
||||
* @return bool Success status
|
||||
*/
|
||||
public function unlink()
|
||||
{
|
||||
if (file_exists($this->name)) {
|
||||
return unlink($this->name);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('SimplePie\Cache\File', 'SimplePie_Cache_File');
|
|
@ -0,0 +1,185 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2022, 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
|
||||
*/
|
||||
|
||||
namespace SimplePie\Cache;
|
||||
|
||||
use Memcache as NativeMemcache;
|
||||
|
||||
/**
|
||||
* Caches data to memcache
|
||||
*
|
||||
* Registered for URLs with the "memcache" protocol
|
||||
*
|
||||
* For example, `memcache://localhost:11211/?timeout=3600&prefix=sp_` will
|
||||
* connect to memcache on `localhost` on port 11211. All tables will be
|
||||
* prefixed with `sp_` and data will expire after 3600 seconds
|
||||
*
|
||||
* @package SimplePie
|
||||
* @subpackage Caching
|
||||
* @uses Memcache
|
||||
* @deprecated since SimplePie 1.8.0, use implementation of "Psr\SimpleCache\CacheInterface" instead
|
||||
*/
|
||||
class Memcache implements Base
|
||||
{
|
||||
/**
|
||||
* Memcache instance
|
||||
*
|
||||
* @var Memcache
|
||||
*/
|
||||
protected $cache;
|
||||
|
||||
/**
|
||||
* Options
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options;
|
||||
|
||||
/**
|
||||
* Cache name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Create a new cache object
|
||||
*
|
||||
* @param string $location Location string (from SimplePie::$cache_location)
|
||||
* @param string $name Unique ID for the cache
|
||||
* @param Base::TYPE_FEED|Base::TYPE_IMAGE $type Either TYPE_FEED for SimplePie data, or TYPE_IMAGE for image data
|
||||
*/
|
||||
public function __construct($location, $name, $type)
|
||||
{
|
||||
$this->options = [
|
||||
'host' => '127.0.0.1',
|
||||
'port' => 11211,
|
||||
'extras' => [
|
||||
'timeout' => 3600, // one hour
|
||||
'prefix' => 'simplepie_',
|
||||
],
|
||||
];
|
||||
$this->options = array_replace_recursive($this->options, \SimplePie\Cache::parse_URL($location));
|
||||
|
||||
$this->name = $this->options['extras']['prefix'] . md5("$name:$type");
|
||||
|
||||
$this->cache = new NativeMemcache();
|
||||
$this->cache->addServer($this->options['host'], (int) $this->options['port']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save data to the cache
|
||||
*
|
||||
* @param array|\SimplePie\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)
|
||||
{
|
||||
if ($data instanceof \SimplePie\SimplePie) {
|
||||
$data = $data->data;
|
||||
}
|
||||
return $this->cache->set($this->name, serialize($data), MEMCACHE_COMPRESSED, (int) $this->options['extras']['timeout']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the data saved to the cache
|
||||
*
|
||||
* @return array Data for SimplePie::$data
|
||||
*/
|
||||
public function load()
|
||||
{
|
||||
$data = $this->cache->get($this->name);
|
||||
|
||||
if ($data !== false) {
|
||||
return unserialize($data);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the last modified time for the cache
|
||||
*
|
||||
* @return int Timestamp
|
||||
*/
|
||||
public function mtime()
|
||||
{
|
||||
$data = $this->cache->get($this->name);
|
||||
|
||||
if ($data !== false) {
|
||||
// essentially ignore the mtime because Memcache expires on its own
|
||||
return time();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the last modified time to the current time
|
||||
*
|
||||
* @return bool Success status
|
||||
*/
|
||||
public function touch()
|
||||
{
|
||||
$data = $this->cache->get($this->name);
|
||||
|
||||
if ($data !== false) {
|
||||
return $this->cache->set($this->name, $data, MEMCACHE_COMPRESSED, (int) $this->options['extras']['timeout']);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the cache
|
||||
*
|
||||
* @return bool Success status
|
||||
*/
|
||||
public function unlink()
|
||||
{
|
||||
return $this->cache->delete($this->name, 0);
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('SimplePie\Cache\Memcache', 'SimplePie_Cache_Memcache');
|
|
@ -0,0 +1,181 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2022, 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
|
||||
*/
|
||||
|
||||
namespace SimplePie\Cache;
|
||||
|
||||
use Memcached as NativeMemcached;
|
||||
|
||||
/**
|
||||
* Caches data to memcached
|
||||
*
|
||||
* Registered for URLs with the "memcached" protocol
|
||||
*
|
||||
* For example, `memcached://localhost:11211/?timeout=3600&prefix=sp_` will
|
||||
* connect to memcached on `localhost` on port 11211. All tables will be
|
||||
* prefixed with `sp_` and data will expire after 3600 seconds
|
||||
*
|
||||
* @package SimplePie
|
||||
* @subpackage Caching
|
||||
* @author Paul L. McNeely
|
||||
* @uses Memcached
|
||||
* @deprecated since SimplePie 1.8.0, use implementation of "Psr\SimpleCache\CacheInterface" instead
|
||||
*/
|
||||
class Memcached implements Base
|
||||
{
|
||||
/**
|
||||
* NativeMemcached instance
|
||||
* @var NativeMemcached
|
||||
*/
|
||||
protected $cache;
|
||||
|
||||
/**
|
||||
* Options
|
||||
* @var array
|
||||
*/
|
||||
protected $options;
|
||||
|
||||
/**
|
||||
* Cache name
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Create a new cache object
|
||||
* @param string $location Location string (from SimplePie::$cache_location)
|
||||
* @param string $name Unique ID for the cache
|
||||
* @param Base::TYPE_FEED|Base::TYPE_IMAGE $type Either TYPE_FEED for SimplePie data, or TYPE_IMAGE for image data
|
||||
*/
|
||||
public function __construct($location, $name, $type)
|
||||
{
|
||||
$this->options = [
|
||||
'host' => '127.0.0.1',
|
||||
'port' => 11211,
|
||||
'extras' => [
|
||||
'timeout' => 3600, // one hour
|
||||
'prefix' => 'simplepie_',
|
||||
],
|
||||
];
|
||||
$this->options = array_replace_recursive($this->options, \SimplePie\Cache::parse_URL($location));
|
||||
|
||||
$this->name = $this->options['extras']['prefix'] . md5("$name:$type");
|
||||
|
||||
$this->cache = new NativeMemcached();
|
||||
$this->cache->addServer($this->options['host'], (int)$this->options['port']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save data to the cache
|
||||
* @param array|\SimplePie\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)
|
||||
{
|
||||
if ($data instanceof \SimplePie\SimplePie) {
|
||||
$data = $data->data;
|
||||
}
|
||||
|
||||
return $this->setData(serialize($data));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the data saved to the cache
|
||||
* @return array Data for SimplePie::$data
|
||||
*/
|
||||
public function load()
|
||||
{
|
||||
$data = $this->cache->get($this->name);
|
||||
|
||||
if ($data !== false) {
|
||||
return unserialize($data);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the last modified time for the cache
|
||||
* @return int Timestamp
|
||||
*/
|
||||
public function mtime()
|
||||
{
|
||||
$data = $this->cache->get($this->name . '_mtime');
|
||||
return (int) $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the last modified time to the current time
|
||||
* @return bool Success status
|
||||
*/
|
||||
public function touch()
|
||||
{
|
||||
$data = $this->cache->get($this->name);
|
||||
return $this->setData($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the cache
|
||||
* @return bool Success status
|
||||
*/
|
||||
public function unlink()
|
||||
{
|
||||
return $this->cache->delete($this->name, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the last modified time and data to NativeMemcached
|
||||
* @return bool Success status
|
||||
*/
|
||||
private function setData($data)
|
||||
{
|
||||
if ($data !== false) {
|
||||
$this->cache->set($this->name . '_mtime', time(), (int)$this->options['extras']['timeout']);
|
||||
return $this->cache->set($this->name, $data, (int)$this->options['extras']['timeout']);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('SimplePie\Cache\Memcached', 'SimplePie_Cache_Memcached');
|
|
@ -0,0 +1,384 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2022, 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
|
||||
*/
|
||||
|
||||
namespace SimplePie\Cache;
|
||||
|
||||
/**
|
||||
* Caches data to a MySQL database
|
||||
*
|
||||
* Registered for URLs with the "mysql" protocol
|
||||
*
|
||||
* For example, `mysql://root:password@localhost:3306/mydb?prefix=sp_` will
|
||||
* connect to the `mydb` database on `localhost` on port 3306, with the user
|
||||
* `root` and the password `password`. All tables will be prefixed with `sp_`
|
||||
*
|
||||
* @package SimplePie
|
||||
* @subpackage Caching
|
||||
* @deprecated since SimplePie 1.8.0, use implementation of "Psr\SimpleCache\CacheInterface" instead
|
||||
*/
|
||||
class MySQL extends DB
|
||||
{
|
||||
/**
|
||||
* PDO instance
|
||||
*
|
||||
* @var \PDO
|
||||
*/
|
||||
protected $mysql;
|
||||
|
||||
/**
|
||||
* Options
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options;
|
||||
|
||||
/**
|
||||
* Cache ID
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* Create a new cache object
|
||||
*
|
||||
* @param string $location Location string (from SimplePie::$cache_location)
|
||||
* @param string $name Unique ID for the cache
|
||||
* @param Base::TYPE_FEED|Base::TYPE_IMAGE $type Either TYPE_FEED for SimplePie data, or TYPE_IMAGE for image data
|
||||
*/
|
||||
public function __construct($location, $name, $type)
|
||||
{
|
||||
$this->options = [
|
||||
'user' => null,
|
||||
'pass' => null,
|
||||
'host' => '127.0.0.1',
|
||||
'port' => '3306',
|
||||
'path' => '',
|
||||
'extras' => [
|
||||
'prefix' => '',
|
||||
'cache_purge_time' => 2592000
|
||||
],
|
||||
];
|
||||
|
||||
$this->options = array_replace_recursive($this->options, \SimplePie\Cache::parse_URL($location));
|
||||
|
||||
// Path is prefixed with a "/"
|
||||
$this->options['dbname'] = substr($this->options['path'], 1);
|
||||
|
||||
try {
|
||||
$this->mysql = new \PDO("mysql:dbname={$this->options['dbname']};host={$this->options['host']};port={$this->options['port']}", $this->options['user'], $this->options['pass'], [\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8']);
|
||||
} catch (\PDOException $e) {
|
||||
$this->mysql = null;
|
||||
return;
|
||||
}
|
||||
|
||||
$this->id = $name . $type;
|
||||
|
||||
if (!$query = $this->mysql->query('SHOW TABLES')) {
|
||||
$this->mysql = null;
|
||||
return;
|
||||
}
|
||||
|
||||
$db = [];
|
||||
while ($row = $query->fetchColumn()) {
|
||||
$db[] = $row;
|
||||
}
|
||||
|
||||
if (!in_array($this->options['extras']['prefix'] . 'cache_data', $db)) {
|
||||
$query = $this->mysql->exec('CREATE TABLE `' . $this->options['extras']['prefix'] . 'cache_data` (`id` TEXT CHARACTER SET utf8 NOT NULL, `items` SMALLINT NOT NULL DEFAULT 0, `data` BLOB NOT NULL, `mtime` INT UNSIGNED NOT NULL, UNIQUE (`id`(125)))');
|
||||
if ($query === false) {
|
||||
trigger_error("Can't create " . $this->options['extras']['prefix'] . "cache_data table, check permissions", \E_USER_WARNING);
|
||||
$this->mysql = null;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!in_array($this->options['extras']['prefix'] . 'items', $db)) {
|
||||
$query = $this->mysql->exec('CREATE TABLE `' . $this->options['extras']['prefix'] . 'items` (`feed_id` TEXT CHARACTER SET utf8 NOT NULL, `id` TEXT CHARACTER SET utf8 NOT NULL, `data` MEDIUMBLOB NOT NULL, `posted` INT UNSIGNED NOT NULL, INDEX `feed_id` (`feed_id`(125)))');
|
||||
if ($query === false) {
|
||||
trigger_error("Can't create " . $this->options['extras']['prefix'] . "items table, check permissions", \E_USER_WARNING);
|
||||
$this->mysql = null;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save data to the cache
|
||||
*
|
||||
* @param array|\SimplePie\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)
|
||||
{
|
||||
if ($this->mysql === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$query = $this->mysql->prepare('DELETE i, cd FROM `' . $this->options['extras']['prefix'] . 'cache_data` cd, ' .
|
||||
'`' . $this->options['extras']['prefix'] . 'items` i ' .
|
||||
'WHERE cd.id = i.feed_id ' .
|
||||
'AND cd.mtime < (unix_timestamp() - :purge_time)');
|
||||
$query->bindValue(':purge_time', $this->options['extras']['cache_purge_time']);
|
||||
|
||||
if (!$query->execute()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($data instanceof \SimplePie\SimplePie) {
|
||||
$data = clone $data;
|
||||
|
||||
$prepared = self::prepare_simplepie_object_for_cache($data);
|
||||
|
||||
$query = $this->mysql->prepare('SELECT COUNT(*) FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :feed');
|
||||
$query->bindValue(':feed', $this->id);
|
||||
if ($query->execute()) {
|
||||
if ($query->fetchColumn() > 0) {
|
||||
$items = count($prepared[1]);
|
||||
if ($items) {
|
||||
$sql = 'UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `items` = :items, `data` = :data, `mtime` = :time WHERE `id` = :feed';
|
||||
$query = $this->mysql->prepare($sql);
|
||||
$query->bindValue(':items', $items);
|
||||
} else {
|
||||
$sql = 'UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `data` = :data, `mtime` = :time WHERE `id` = :feed';
|
||||
$query = $this->mysql->prepare($sql);
|
||||
}
|
||||
|
||||
$query->bindValue(':data', $prepared[0]);
|
||||
$query->bindValue(':time', time());
|
||||
$query->bindValue(':feed', $this->id);
|
||||
if (!$query->execute()) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
$query = $this->mysql->prepare('INSERT INTO `' . $this->options['extras']['prefix'] . 'cache_data` (`id`, `items`, `data`, `mtime`) VALUES(:feed, :count, :data, :time)');
|
||||
$query->bindValue(':feed', $this->id);
|
||||
$query->bindValue(':count', count($prepared[1]));
|
||||
$query->bindValue(':data', $prepared[0]);
|
||||
$query->bindValue(':time', time());
|
||||
if (!$query->execute()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$ids = array_keys($prepared[1]);
|
||||
if (!empty($ids)) {
|
||||
foreach ($ids as $id) {
|
||||
$database_ids[] = $this->mysql->quote($id);
|
||||
}
|
||||
|
||||
$query = $this->mysql->prepare('SELECT `id` FROM `' . $this->options['extras']['prefix'] . 'items` WHERE `id` = ' . implode(' OR `id` = ', $database_ids) . ' AND `feed_id` = :feed');
|
||||
$query->bindValue(':feed', $this->id);
|
||||
|
||||
if ($query->execute()) {
|
||||
$existing_ids = [];
|
||||
while ($row = $query->fetchColumn()) {
|
||||
$existing_ids[] = $row;
|
||||
}
|
||||
|
||||
$new_ids = array_diff($ids, $existing_ids);
|
||||
|
||||
foreach ($new_ids as $new_id) {
|
||||
if (!($date = $prepared[1][$new_id]->get_date('U'))) {
|
||||
$date = time();
|
||||
}
|
||||
|
||||
$query = $this->mysql->prepare('INSERT INTO `' . $this->options['extras']['prefix'] . 'items` (`feed_id`, `id`, `data`, `posted`) VALUES(:feed, :id, :data, :date)');
|
||||
$query->bindValue(':feed', $this->id);
|
||||
$query->bindValue(':id', $new_id);
|
||||
$query->bindValue(':data', serialize($prepared[1][$new_id]->data));
|
||||
$query->bindValue(':date', $date);
|
||||
if (!$query->execute()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$query = $this->mysql->prepare('SELECT `id` FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :feed');
|
||||
$query->bindValue(':feed', $this->id);
|
||||
if ($query->execute()) {
|
||||
if ($query->rowCount() > 0) {
|
||||
$query = $this->mysql->prepare('UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `items` = 0, `data` = :data, `mtime` = :time WHERE `id` = :feed');
|
||||
$query->bindValue(':data', serialize($data));
|
||||
$query->bindValue(':time', time());
|
||||
$query->bindValue(':feed', $this->id);
|
||||
if ($query->execute()) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
$query = $this->mysql->prepare('INSERT INTO `' . $this->options['extras']['prefix'] . 'cache_data` (`id`, `items`, `data`, `mtime`) VALUES(:id, 0, :data, :time)');
|
||||
$query->bindValue(':id', $this->id);
|
||||
$query->bindValue(':data', serialize($data));
|
||||
$query->bindValue(':time', time());
|
||||
if ($query->execute()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the data saved to the cache
|
||||
*
|
||||
* @return array Data for SimplePie::$data
|
||||
*/
|
||||
public function load()
|
||||
{
|
||||
if ($this->mysql === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$query = $this->mysql->prepare('SELECT `items`, `data` FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :id');
|
||||
$query->bindValue(':id', $this->id);
|
||||
if ($query->execute() && ($row = $query->fetch())) {
|
||||
$data = unserialize($row[1]);
|
||||
|
||||
if (isset($this->options['items'][0])) {
|
||||
$items = (int) $this->options['items'][0];
|
||||
} else {
|
||||
$items = (int) $row[0];
|
||||
}
|
||||
|
||||
if ($items !== 0) {
|
||||
if (isset($data['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['feed'][0])) {
|
||||
$feed =& $data['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['feed'][0];
|
||||
} elseif (isset($data['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_03]['feed'][0])) {
|
||||
$feed =& $data['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_03]['feed'][0];
|
||||
} elseif (isset($data['child'][\SimplePie\SimplePie::NAMESPACE_RDF]['RDF'][0])) {
|
||||
$feed =& $data['child'][\SimplePie\SimplePie::NAMESPACE_RDF]['RDF'][0];
|
||||
} elseif (isset($data['child'][\SimplePie\SimplePie::NAMESPACE_RSS_20]['rss'][0])) {
|
||||
$feed =& $data['child'][\SimplePie\SimplePie::NAMESPACE_RSS_20]['rss'][0];
|
||||
} else {
|
||||
$feed = null;
|
||||
}
|
||||
|
||||
if ($feed !== null) {
|
||||
$sql = 'SELECT `data` FROM `' . $this->options['extras']['prefix'] . 'items` WHERE `feed_id` = :feed ORDER BY `posted` DESC';
|
||||
if ($items > 0) {
|
||||
$sql .= ' LIMIT ' . $items;
|
||||
}
|
||||
|
||||
$query = $this->mysql->prepare($sql);
|
||||
$query->bindValue(':feed', $this->id);
|
||||
if ($query->execute()) {
|
||||
while ($row = $query->fetchColumn()) {
|
||||
$feed['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['entry'][] = unserialize($row);
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the last modified time for the cache
|
||||
*
|
||||
* @return int Timestamp
|
||||
*/
|
||||
public function mtime()
|
||||
{
|
||||
if ($this->mysql === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$query = $this->mysql->prepare('SELECT `mtime` FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :id');
|
||||
$query->bindValue(':id', $this->id);
|
||||
if ($query->execute() && ($time = $query->fetchColumn())) {
|
||||
return $time;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the last modified time to the current time
|
||||
*
|
||||
* @return bool Success status
|
||||
*/
|
||||
public function touch()
|
||||
{
|
||||
if ($this->mysql === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$query = $this->mysql->prepare('UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `mtime` = :time WHERE `id` = :id');
|
||||
$query->bindValue(':time', time());
|
||||
$query->bindValue(':id', $this->id);
|
||||
|
||||
return $query->execute() && $query->rowCount() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the cache
|
||||
*
|
||||
* @return bool Success status
|
||||
*/
|
||||
public function unlink()
|
||||
{
|
||||
if ($this->mysql === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$query = $this->mysql->prepare('DELETE FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :id');
|
||||
$query->bindValue(':id', $this->id);
|
||||
$query2 = $this->mysql->prepare('DELETE FROM `' . $this->options['extras']['prefix'] . 'items` WHERE `feed_id` = :id');
|
||||
$query2->bindValue(':id', $this->id);
|
||||
|
||||
return $query->execute() && $query2->execute();
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('SimplePie\Cache\MySQL', 'SimplePie_Cache_MySQL');
|
|
@ -0,0 +1,76 @@
|
|||
<?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-2022, 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-2022 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
|
||||
*/
|
||||
|
||||
namespace SimplePie\Cache;
|
||||
|
||||
/**
|
||||
* Interface for creating a cache filename
|
||||
*
|
||||
* @package SimplePie
|
||||
* @subpackage Caching
|
||||
*/
|
||||
interface NameFilter
|
||||
{
|
||||
/**
|
||||
* Method to create cache filename with.
|
||||
*
|
||||
* The returning name MUST follow the rules for keys in PSR-16.
|
||||
*
|
||||
* @link https://www.php-fig.org/psr/psr-16/
|
||||
*
|
||||
* The returning name MUST be a string of at least one character
|
||||
* that uniquely identifies a cached item, MUST only contain the
|
||||
* characters A-Z, a-z, 0-9, _, and . in any order in UTF-8 encoding
|
||||
* and MUST not longer then 64 characters. The following characters
|
||||
* are reserved for future extensions and MUST NOT be used: {}()/\@:
|
||||
*
|
||||
* A provided implementing library MAY support additional characters
|
||||
* and encodings or longer lengths, but MUST support at least that
|
||||
* minimum.
|
||||
*
|
||||
* @param string $name The name for the cache will be most likly an url with query string
|
||||
*
|
||||
* @return string the new cache name
|
||||
*/
|
||||
public function filter(string $name): string;
|
||||
}
|
|
@ -0,0 +1,147 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2022, 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-2022 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
|
||||
*/
|
||||
|
||||
namespace SimplePie\Cache;
|
||||
|
||||
use Psr\SimpleCache\CacheInterface;
|
||||
use Psr\SimpleCache\InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Caches data into a PSR-16 cache implementation
|
||||
*
|
||||
* @package SimplePie
|
||||
* @subpackage Caching
|
||||
* @internal
|
||||
*/
|
||||
final class Psr16 implements DataCache
|
||||
{
|
||||
/**
|
||||
* PSR-16 cache implementation
|
||||
*
|
||||
* @var CacheInterface
|
||||
*/
|
||||
private $cache;
|
||||
|
||||
/**
|
||||
* PSR-16 cache implementation
|
||||
*
|
||||
* @param CacheInterface $cache
|
||||
*/
|
||||
public function __construct(CacheInterface $cache)
|
||||
{
|
||||
$this->cache = $cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches a value from the cache.
|
||||
*
|
||||
* Equivalent to \Psr\SimpleCache\CacheInterface::get()
|
||||
* <code>
|
||||
* public function get(string $key, mixed $default = null): mixed;
|
||||
* </code>
|
||||
*
|
||||
* @param string $key The unique key of this item in the cache.
|
||||
* @param mixed $default Default value to return if the key does not exist.
|
||||
*
|
||||
* @return array|mixed The value of the item from the cache, or $default in case of cache miss.
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
* MUST be thrown if the $key string is not a legal value.
|
||||
*/
|
||||
public function get_data(string $key, $default = null)
|
||||
{
|
||||
$data = $this->cache->get($key, $default);
|
||||
|
||||
if (! is_array($data) || $data === $default) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Persists data in the cache, uniquely referenced by a key with an optional expiration TTL time.
|
||||
*
|
||||
* Equivalent to \Psr\SimpleCache\CacheInterface::set()
|
||||
* <code>
|
||||
* public function set(string $key, mixed $value, null|int|\DateInterval $ttl = null): bool;
|
||||
* </code>
|
||||
*
|
||||
* @param string $key The key of the item to store.
|
||||
* @param array $value The value of the item to store, must be serializable.
|
||||
* @param null|int $ttl Optional. The TTL value of this item. If no value is sent and
|
||||
* the driver supports TTL then the library may set a default value
|
||||
* for it or let the driver take care of that.
|
||||
*
|
||||
* @return bool True on success and false on failure.
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
* MUST be thrown if the $key string is not a legal value.
|
||||
*/
|
||||
public function set_data(string $key, array $value, ?int $ttl = null): bool
|
||||
{
|
||||
return $this->cache->set($key, $value, $ttl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an item from the cache by its unique key.
|
||||
*
|
||||
* Equivalent to \Psr\SimpleCache\CacheInterface::delete()
|
||||
* <code>
|
||||
* public function delete(string $key): bool;
|
||||
* </code>
|
||||
*
|
||||
* @param string $key The unique cache key of the item to delete.
|
||||
*
|
||||
* @return bool True if the item was successfully removed. False if there was an error.
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
* MUST be thrown if the $key string is not a legal value.
|
||||
*/
|
||||
public function delete_data(string $key): bool
|
||||
{
|
||||
return $this->cache->delete($key);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,209 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2022, 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
|
||||
*/
|
||||
|
||||
namespace SimplePie\Cache;
|
||||
|
||||
use Redis as NativeRedis;
|
||||
|
||||
/**
|
||||
* Caches data to redis
|
||||
*
|
||||
* Registered for URLs with the "redis" protocol
|
||||
*
|
||||
* For example, `redis://localhost:6379/?timeout=3600&prefix=sp_&dbIndex=0` will
|
||||
* connect to redis on `localhost` on port 6379. All tables will be
|
||||
* prefixed with `simple_primary-` and data will expire after 3600 seconds
|
||||
*
|
||||
* @package SimplePie
|
||||
* @subpackage Caching
|
||||
* @uses Redis
|
||||
* @deprecated since SimplePie 1.8.0, use implementation of "Psr\SimpleCache\CacheInterface" instead
|
||||
*/
|
||||
class Redis implements Base
|
||||
{
|
||||
/**
|
||||
* Redis instance
|
||||
*
|
||||
* @var NativeRedis
|
||||
*/
|
||||
protected $cache;
|
||||
|
||||
/**
|
||||
* Options
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options;
|
||||
|
||||
/**
|
||||
* Cache name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Create a new cache object
|
||||
*
|
||||
* @param string $location Location string (from SimplePie::$cache_location)
|
||||
* @param string $name Unique ID for the cache
|
||||
* @param Base::TYPE_FEED|Base::TYPE_IMAGE $type Either TYPE_FEED for SimplePie data, or TYPE_IMAGE for image data
|
||||
*/
|
||||
public function __construct($location, $name, $options = null)
|
||||
{
|
||||
//$this->cache = \flow\simple\cache\Redis::getRedisClientInstance();
|
||||
$parsed = \SimplePie\Cache::parse_URL($location);
|
||||
$redis = new NativeRedis();
|
||||
$redis->connect($parsed['host'], $parsed['port']);
|
||||
if (isset($parsed['pass'])) {
|
||||
$redis->auth($parsed['pass']);
|
||||
}
|
||||
if (isset($parsed['path'])) {
|
||||
$redis->select((int)substr($parsed['path'], 1));
|
||||
}
|
||||
$this->cache = $redis;
|
||||
|
||||
if (!is_null($options) && is_array($options)) {
|
||||
$this->options = $options;
|
||||
} else {
|
||||
$this->options = [
|
||||
'prefix' => 'rss:simple_primary:',
|
||||
'expire' => 0,
|
||||
];
|
||||
}
|
||||
|
||||
$this->name = $this->options['prefix'] . $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param NativeRedis $cache
|
||||
*/
|
||||
public function setRedisClient(NativeRedis $cache)
|
||||
{
|
||||
$this->cache = $cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save data to the cache
|
||||
*
|
||||
* @param array|\SimplePie\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)
|
||||
{
|
||||
if ($data instanceof \SimplePie\SimplePie) {
|
||||
$data = $data->data;
|
||||
}
|
||||
$response = $this->cache->set($this->name, serialize($data));
|
||||
if ($this->options['expire']) {
|
||||
$this->cache->expire($this->name, $this->options['expire']);
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the data saved to the cache
|
||||
*
|
||||
* @return array Data for SimplePie::$data
|
||||
*/
|
||||
public function load()
|
||||
{
|
||||
$data = $this->cache->get($this->name);
|
||||
|
||||
if ($data !== false) {
|
||||
return unserialize($data);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the last modified time for the cache
|
||||
*
|
||||
* @return int Timestamp
|
||||
*/
|
||||
public function mtime()
|
||||
{
|
||||
$data = $this->cache->get($this->name);
|
||||
|
||||
if ($data !== false) {
|
||||
return time();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the last modified time to the current time
|
||||
*
|
||||
* @return bool Success status
|
||||
*/
|
||||
public function touch()
|
||||
{
|
||||
$data = $this->cache->get($this->name);
|
||||
|
||||
if ($data !== false) {
|
||||
$return = $this->cache->set($this->name, $data);
|
||||
if ($this->options['expire']) {
|
||||
return $this->cache->expire($this->name, $this->options['expire']);
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the cache
|
||||
*
|
||||
* @return bool Success status
|
||||
*/
|
||||
public function unlink()
|
||||
{
|
||||
return $this->cache->set($this->name, null);
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('SimplePie\Cache\Redis', 'SimplePie_Cache_Redis');
|
|
@ -0,0 +1,198 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2022, 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
|
||||
*/
|
||||
|
||||
namespace SimplePie;
|
||||
|
||||
/**
|
||||
* Handles `<media:text>` captions as defined in Media RSS.
|
||||
*
|
||||
* Used by {@see \SimplePie\Enclosure::get_caption()} and {@see \SimplePie\Enclosure::get_captions()}
|
||||
*
|
||||
* This class can be overloaded with {@see \SimplePie\SimplePie::set_caption_class()}
|
||||
*
|
||||
* @package SimplePie
|
||||
* @subpackage API
|
||||
*/
|
||||
class Caption
|
||||
{
|
||||
/**
|
||||
* Content type
|
||||
*
|
||||
* @var string
|
||||
* @see get_type()
|
||||
*/
|
||||
public $type;
|
||||
|
||||
/**
|
||||
* Language
|
||||
*
|
||||
* @var string
|
||||
* @see get_language()
|
||||
*/
|
||||
public $lang;
|
||||
|
||||
/**
|
||||
* Start time
|
||||
*
|
||||
* @var string
|
||||
* @see get_starttime()
|
||||
*/
|
||||
public $startTime;
|
||||
|
||||
/**
|
||||
* End time
|
||||
*
|
||||
* @var string
|
||||
* @see get_endtime()
|
||||
*/
|
||||
public $endTime;
|
||||
|
||||
/**
|
||||
* Caption text
|
||||
*
|
||||
* @var string
|
||||
* @see get_text()
|
||||
*/
|
||||
public $text;
|
||||
|
||||
/**
|
||||
* Constructor, used to input the data
|
||||
*
|
||||
* For documentation on all the parameters, see the corresponding
|
||||
* properties and their accessors
|
||||
*/
|
||||
public function __construct($type = null, $lang = null, $startTime = null, $endTime = null, $text = null)
|
||||
{
|
||||
$this->type = $type;
|
||||
$this->lang = $lang;
|
||||
$this->startTime = $startTime;
|
||||
$this->endTime = $endTime;
|
||||
$this->text = $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* String-ified version
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
// There is no $this->data here
|
||||
return md5(serialize($this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the end time
|
||||
*
|
||||
* @return string|null Time in the format 'hh:mm:ss.SSS'
|
||||
*/
|
||||
public function get_endtime()
|
||||
{
|
||||
if ($this->endTime !== null) {
|
||||
return $this->endTime;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the language
|
||||
*
|
||||
* @link http://tools.ietf.org/html/rfc3066
|
||||
* @return string|null Language code as per RFC 3066
|
||||
*/
|
||||
public function get_language()
|
||||
{
|
||||
if ($this->lang !== null) {
|
||||
return $this->lang;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the start time
|
||||
*
|
||||
* @return string|null Time in the format 'hh:mm:ss.SSS'
|
||||
*/
|
||||
public function get_starttime()
|
||||
{
|
||||
if ($this->startTime !== null) {
|
||||
return $this->startTime;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the text of the caption
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function get_text()
|
||||
{
|
||||
if ($this->text !== null) {
|
||||
return $this->text;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the content type (not MIME type)
|
||||
*
|
||||
* @return string|null Either 'text' or 'html'
|
||||
*/
|
||||
public function get_type()
|
||||
{
|
||||
if ($this->type !== null) {
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('SimplePie\Caption', 'SimplePie_Caption');
|
|
@ -0,0 +1,167 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2022, 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
|
||||
*/
|
||||
|
||||
namespace SimplePie;
|
||||
|
||||
/**
|
||||
* Manages all category-related data
|
||||
*
|
||||
* Used by {@see \SimplePie\Item::get_category()} and {@see \SimplePie\Item::get_categories()}
|
||||
*
|
||||
* This class can be overloaded with {@see \SimplePie\SimplePie::set_category_class()}
|
||||
*
|
||||
* @package SimplePie
|
||||
* @subpackage API
|
||||
*/
|
||||
class Category
|
||||
{
|
||||
/**
|
||||
* Category identifier
|
||||
*
|
||||
* @var string|null
|
||||
* @see get_term
|
||||
*/
|
||||
public $term;
|
||||
|
||||
/**
|
||||
* Categorization scheme identifier
|
||||
*
|
||||
* @var string|null
|
||||
* @see get_scheme()
|
||||
*/
|
||||
public $scheme;
|
||||
|
||||
/**
|
||||
* Human readable label
|
||||
*
|
||||
* @var string|null
|
||||
* @see get_label()
|
||||
*/
|
||||
public $label;
|
||||
|
||||
/**
|
||||
* Category type
|
||||
*
|
||||
* category for <category>
|
||||
* subject for <dc:subject>
|
||||
*
|
||||
* @var string|null
|
||||
* @see get_type()
|
||||
*/
|
||||
public $type;
|
||||
|
||||
/**
|
||||
* Constructor, used to input the data
|
||||
*
|
||||
* @param string|null $term
|
||||
* @param string|null $scheme
|
||||
* @param string|null $label
|
||||
* @param string|null $type
|
||||
*/
|
||||
public function __construct($term = null, $scheme = null, $label = null, $type = null)
|
||||
{
|
||||
$this->term = $term;
|
||||
$this->scheme = $scheme;
|
||||
$this->label = $label;
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* String-ified version
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
// There is no $this->data here
|
||||
return md5(serialize($this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the category identifier
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function get_term()
|
||||
{
|
||||
return $this->term;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the categorization scheme identifier
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function get_scheme()
|
||||
{
|
||||
return $this->scheme;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the human readable label
|
||||
*
|
||||
* @param bool $strict
|
||||
* @return string|null
|
||||
*/
|
||||
public function get_label($strict = false)
|
||||
{
|
||||
if ($this->label === null && $strict !== true) {
|
||||
return $this->get_term();
|
||||
}
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the category type
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function get_type()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('SimplePie\Category', 'SimplePie_Category');
|
|
@ -0,0 +1,261 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2022, 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
|
||||
*/
|
||||
|
||||
namespace SimplePie\Content\Type;
|
||||
|
||||
/**
|
||||
* Content-type sniffing
|
||||
*
|
||||
* Based on the rules in http://tools.ietf.org/html/draft-abarth-mime-sniff-06
|
||||
*
|
||||
* This is used since we can't always trust Content-Type headers, and is based
|
||||
* upon the HTML5 parsing rules.
|
||||
*
|
||||
*
|
||||
* This class can be overloaded with {@see \SimplePie\SimplePie::set_content_type_sniffer_class()}
|
||||
*
|
||||
* @package SimplePie
|
||||
* @subpackage HTTP
|
||||
*/
|
||||
class Sniffer
|
||||
{
|
||||
/**
|
||||
* File object
|
||||
*
|
||||
* @var \SimplePie\File
|
||||
*/
|
||||
public $file;
|
||||
|
||||
/**
|
||||
* Create an instance of the class with the input file
|
||||
*
|
||||
* @param Sniffer $file Input file
|
||||
*/
|
||||
public function __construct($file)
|
||||
{
|
||||
$this->file = $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Content-Type of the specified file
|
||||
*
|
||||
* @return string Actual Content-Type
|
||||
*/
|
||||
public function get_type()
|
||||
{
|
||||
if (isset($this->file->headers['content-type'])) {
|
||||
if (!isset($this->file->headers['content-encoding'])
|
||||
&& ($this->file->headers['content-type'] === 'text/plain'
|
||||
|| $this->file->headers['content-type'] === 'text/plain; charset=ISO-8859-1'
|
||||
|| $this->file->headers['content-type'] === 'text/plain; charset=iso-8859-1'
|
||||
|| $this->file->headers['content-type'] === 'text/plain; charset=UTF-8')) {
|
||||
return $this->text_or_binary();
|
||||
}
|
||||
|
||||
if (($pos = strpos($this->file->headers['content-type'], ';')) !== false) {
|
||||
$official = substr($this->file->headers['content-type'], 0, $pos);
|
||||
} else {
|
||||
$official = $this->file->headers['content-type'];
|
||||
}
|
||||
$official = trim(strtolower($official));
|
||||
|
||||
if ($official === 'unknown/unknown'
|
||||
|| $official === 'application/unknown') {
|
||||
return $this->unknown();
|
||||
} elseif (substr($official, -4) === '+xml'
|
||||
|| $official === 'text/xml'
|
||||
|| $official === 'application/xml') {
|
||||
return $official;
|
||||
} elseif (substr($official, 0, 6) === 'image/') {
|
||||
if ($return = $this->image()) {
|
||||
return $return;
|
||||
}
|
||||
|
||||
return $official;
|
||||
} elseif ($official === 'text/html') {
|
||||
return $this->feed_or_html();
|
||||
}
|
||||
|
||||
return $official;
|
||||
}
|
||||
|
||||
return $this->unknown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sniff text or binary
|
||||
*
|
||||
* @return string Actual Content-Type
|
||||
*/
|
||||
public function text_or_binary()
|
||||
{
|
||||
if (substr($this->file->body, 0, 2) === "\xFE\xFF"
|
||||
|| substr($this->file->body, 0, 2) === "\xFF\xFE"
|
||||
|| substr($this->file->body, 0, 4) === "\x00\x00\xFE\xFF"
|
||||
|| substr($this->file->body, 0, 3) === "\xEF\xBB\xBF") {
|
||||
return 'text/plain';
|
||||
} elseif (preg_match('/[\x00-\x08\x0E-\x1A\x1C-\x1F]/', $this->file->body)) {
|
||||
return 'application/octet-stream';
|
||||
}
|
||||
|
||||
return 'text/plain';
|
||||
}
|
||||
|
||||
/**
|
||||
* Sniff unknown
|
||||
*
|
||||
* @return string Actual Content-Type
|
||||
*/
|
||||
public function unknown()
|
||||
{
|
||||
$ws = strspn($this->file->body, "\x09\x0A\x0B\x0C\x0D\x20");
|
||||
if (strtolower(substr($this->file->body, $ws, 14)) === '<!doctype html'
|
||||
|| strtolower(substr($this->file->body, $ws, 5)) === '<html'
|
||||
|| strtolower(substr($this->file->body, $ws, 7)) === '<script') {
|
||||
return 'text/html';
|
||||
} elseif (substr($this->file->body, 0, 5) === '%PDF-') {
|
||||
return 'application/pdf';
|
||||
} elseif (substr($this->file->body, 0, 11) === '%!PS-Adobe-') {
|
||||
return 'application/postscript';
|
||||
} elseif (substr($this->file->body, 0, 6) === 'GIF87a'
|
||||
|| substr($this->file->body, 0, 6) === 'GIF89a') {
|
||||
return 'image/gif';
|
||||
} elseif (substr($this->file->body, 0, 8) === "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A") {
|
||||
return 'image/png';
|
||||
} elseif (substr($this->file->body, 0, 3) === "\xFF\xD8\xFF") {
|
||||
return 'image/jpeg';
|
||||
} elseif (substr($this->file->body, 0, 2) === "\x42\x4D") {
|
||||
return 'image/bmp';
|
||||
} elseif (substr($this->file->body, 0, 4) === "\x00\x00\x01\x00") {
|
||||
return 'image/vnd.microsoft.icon';
|
||||
}
|
||||
|
||||
return $this->text_or_binary();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sniff images
|
||||
*
|
||||
* @return string Actual Content-Type
|
||||
*/
|
||||
public function image()
|
||||
{
|
||||
if (substr($this->file->body, 0, 6) === 'GIF87a'
|
||||
|| substr($this->file->body, 0, 6) === 'GIF89a') {
|
||||
return 'image/gif';
|
||||
} elseif (substr($this->file->body, 0, 8) === "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A") {
|
||||
return 'image/png';
|
||||
} elseif (substr($this->file->body, 0, 3) === "\xFF\xD8\xFF") {
|
||||
return 'image/jpeg';
|
||||
} elseif (substr($this->file->body, 0, 2) === "\x42\x4D") {
|
||||
return 'image/bmp';
|
||||
} elseif (substr($this->file->body, 0, 4) === "\x00\x00\x01\x00") {
|
||||
return 'image/vnd.microsoft.icon';
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sniff HTML
|
||||
*
|
||||
* @return string Actual Content-Type
|
||||
*/
|
||||
public function feed_or_html()
|
||||
{
|
||||
$len = strlen($this->file->body);
|
||||
$pos = strspn($this->file->body, "\x09\x0A\x0D\x20\xEF\xBB\xBF");
|
||||
|
||||
while ($pos < $len) {
|
||||
switch ($this->file->body[$pos]) {
|
||||
case "\x09":
|
||||
case "\x0A":
|
||||
case "\x0D":
|
||||
case "\x20":
|
||||
$pos += strspn($this->file->body, "\x09\x0A\x0D\x20", $pos);
|
||||
continue 2;
|
||||
|
||||
case '<':
|
||||
$pos++;
|
||||
break;
|
||||
|
||||
default:
|
||||
return 'text/html';
|
||||
}
|
||||
|
||||
if (substr($this->file->body, $pos, 3) === '!--') {
|
||||
$pos += 3;
|
||||
if ($pos < $len && ($pos = strpos($this->file->body, '-->', $pos)) !== false) {
|
||||
$pos += 3;
|
||||
} else {
|
||||
return 'text/html';
|
||||
}
|
||||
} elseif (substr($this->file->body, $pos, 1) === '!') {
|
||||
if ($pos < $len && ($pos = strpos($this->file->body, '>', $pos)) !== false) {
|
||||
$pos++;
|
||||
} else {
|
||||
return 'text/html';
|
||||
}
|
||||
} elseif (substr($this->file->body, $pos, 1) === '?') {
|
||||
if ($pos < $len && ($pos = strpos($this->file->body, '?>', $pos)) !== false) {
|
||||
$pos += 2;
|
||||
} else {
|
||||
return 'text/html';
|
||||
}
|
||||
} elseif (substr($this->file->body, $pos, 3) === 'rss'
|
||||
|| substr($this->file->body, $pos, 7) === 'rdf:RDF') {
|
||||
return 'application/rss+xml';
|
||||
} elseif (substr($this->file->body, $pos, 4) === 'feed') {
|
||||
return 'application/atom+xml';
|
||||
} else {
|
||||
return 'text/html';
|
||||
}
|
||||
}
|
||||
|
||||
return 'text/html';
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('SimplePie\Content\Type\Sniffer', 'SimplePie_Content_Type_Sniffer');
|
|
@ -0,0 +1,128 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2022, 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
|
||||
*/
|
||||
|
||||
namespace SimplePie;
|
||||
|
||||
/**
|
||||
* Manages `<media:copyright>` copyright tags as defined in Media RSS
|
||||
*
|
||||
* Used by {@see \SimplePie\Enclosure::get_copyright()}
|
||||
*
|
||||
* This class can be overloaded with {@see \SimplePie\SimplePie::set_copyright_class()}
|
||||
*
|
||||
* @package SimplePie
|
||||
* @subpackage API
|
||||
*/
|
||||
class Copyright
|
||||
{
|
||||
/**
|
||||
* Copyright URL
|
||||
*
|
||||
* @var string
|
||||
* @see get_url()
|
||||
*/
|
||||
public $url;
|
||||
|
||||
/**
|
||||
* Attribution
|
||||
*
|
||||
* @var string
|
||||
* @see get_attribution()
|
||||
*/
|
||||
public $label;
|
||||
|
||||
/**
|
||||
* Constructor, used to input the data
|
||||
*
|
||||
* For documentation on all the parameters, see the corresponding
|
||||
* properties and their accessors
|
||||
*/
|
||||
public function __construct($url = null, $label = null)
|
||||
{
|
||||
$this->url = $url;
|
||||
$this->label = $label;
|
||||
}
|
||||
|
||||
/**
|
||||
* String-ified version
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
// There is no $this->data here
|
||||
return md5(serialize($this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the copyright URL
|
||||
*
|
||||
* @return string|null URL to copyright information
|
||||
*/
|
||||
public function get_url()
|
||||
{
|
||||
if ($this->url !== null) {
|
||||
return $this->url;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the attribution text
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function get_attribution()
|
||||
{
|
||||
if ($this->label !== null) {
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('SimplePie\Copyright', 'SimplePie_Copyright');
|
|
@ -0,0 +1,151 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2022, 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
|
||||
*/
|
||||
|
||||
namespace SimplePie;
|
||||
|
||||
/**
|
||||
* Handles `<media:credit>` as defined in Media RSS
|
||||
*
|
||||
* Used by {@see \SimplePie\Enclosure::get_credit()} and {@see \SimplePie\Enclosure::get_credits()}
|
||||
*
|
||||
* This class can be overloaded with {@see \SimplePie\SimplePie::set_credit_class()}
|
||||
*
|
||||
* @package SimplePie
|
||||
* @subpackage API
|
||||
*/
|
||||
class Credit
|
||||
{
|
||||
/**
|
||||
* Credited role
|
||||
*
|
||||
* @var string
|
||||
* @see get_role()
|
||||
*/
|
||||
public $role;
|
||||
|
||||
/**
|
||||
* Organizational scheme
|
||||
*
|
||||
* @var string
|
||||
* @see get_scheme()
|
||||
*/
|
||||
public $scheme;
|
||||
|
||||
/**
|
||||
* Credited name
|
||||
*
|
||||
* @var string
|
||||
* @see get_name()
|
||||
*/
|
||||
public $name;
|
||||
|
||||
/**
|
||||
* Constructor, used to input the data
|
||||
*
|
||||
* For documentation on all the parameters, see the corresponding
|
||||
* properties and their accessors
|
||||
*/
|
||||
public function __construct($role = null, $scheme = null, $name = null)
|
||||
{
|
||||
$this->role = $role;
|
||||
$this->scheme = $scheme;
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* String-ified version
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
// There is no $this->data here
|
||||
return md5(serialize($this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the role of the person receiving credit
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function get_role()
|
||||
{
|
||||
if ($this->role !== null) {
|
||||
return $this->role;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the organizational scheme
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function get_scheme()
|
||||
{
|
||||
if ($this->scheme !== null) {
|
||||
return $this->scheme;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the credited person/entity's name
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function get_name()
|
||||
{
|
||||
if ($this->name !== null) {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('SimplePie\Credit', 'SimplePie_Credit');
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2022, 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
|
||||
*/
|
||||
|
||||
namespace SimplePie;
|
||||
|
||||
use Exception as NativeException;
|
||||
|
||||
/**
|
||||
* General SimplePie exception class
|
||||
*
|
||||
* @package SimplePie
|
||||
*/
|
||||
class Exception extends NativeException
|
||||
{
|
||||
}
|
||||
|
||||
class_alias('SimplePie\Exception', 'SimplePie_Exception');
|
|
@ -0,0 +1,257 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2022, 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
|
||||
*/
|
||||
|
||||
namespace SimplePie;
|
||||
|
||||
/**
|
||||
* Used for fetching remote files and reading local files
|
||||
*
|
||||
* Supports HTTP 1.0 via cURL or fsockopen, with spotty HTTP 1.1 support
|
||||
*
|
||||
* This class can be overloaded with {@see \SimplePie\SimplePie::set_file_class()}
|
||||
*
|
||||
* @package SimplePie
|
||||
* @subpackage HTTP
|
||||
* @todo Move to properly supporting RFC2616 (HTTP/1.1)
|
||||
*/
|
||||
class File
|
||||
{
|
||||
public $url;
|
||||
public $useragent;
|
||||
public $success = true;
|
||||
public $headers = [];
|
||||
public $body;
|
||||
public $status_code = 0;
|
||||
public $redirects = 0;
|
||||
public $error;
|
||||
public $method = \SimplePie\SimplePie::FILE_SOURCE_NONE;
|
||||
public $permanent_url;
|
||||
|
||||
public function __construct($url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null, $force_fsockopen = false, $curl_options = [])
|
||||
{
|
||||
if (class_exists('idna_convert')) {
|
||||
$idn = new \idna_convert();
|
||||
$parsed = \SimplePie\Misc::parse_url($url);
|
||||
$url = \SimplePie\Misc::compress_parse_url($parsed['scheme'], $idn->encode($parsed['authority']), $parsed['path'], $parsed['query'], null);
|
||||
}
|
||||
$this->url = $url;
|
||||
$this->permanent_url = $url;
|
||||
$this->useragent = $useragent;
|
||||
if (preg_match('/^http(s)?:\/\//i', $url)) {
|
||||
if ($useragent === null) {
|
||||
$useragent = ini_get('user_agent');
|
||||
$this->useragent = $useragent;
|
||||
}
|
||||
if (!is_array($headers)) {
|
||||
$headers = [];
|
||||
}
|
||||
if (!$force_fsockopen && function_exists('curl_exec')) {
|
||||
$this->method = \SimplePie\SimplePie::FILE_SOURCE_REMOTE | \SimplePie\SimplePie::FILE_SOURCE_CURL;
|
||||
$fp = curl_init();
|
||||
$headers2 = [];
|
||||
foreach ($headers as $key => $value) {
|
||||
$headers2[] = "$key: $value";
|
||||
}
|
||||
if (version_compare(\SimplePie\Misc::get_curl_version(), '7.10.5', '>=')) {
|
||||
curl_setopt($fp, CURLOPT_ENCODING, '');
|
||||
}
|
||||
curl_setopt($fp, CURLOPT_URL, $url);
|
||||
curl_setopt($fp, CURLOPT_HEADER, 1);
|
||||
curl_setopt($fp, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($fp, CURLOPT_FAILONERROR, 1);
|
||||
curl_setopt($fp, CURLOPT_TIMEOUT, $timeout);
|
||||
curl_setopt($fp, CURLOPT_CONNECTTIMEOUT, $timeout);
|
||||
curl_setopt($fp, CURLOPT_REFERER, \SimplePie\Misc::url_remove_credentials($url));
|
||||
curl_setopt($fp, CURLOPT_USERAGENT, $useragent);
|
||||
curl_setopt($fp, CURLOPT_HTTPHEADER, $headers2);
|
||||
foreach ($curl_options as $curl_param => $curl_value) {
|
||||
curl_setopt($fp, $curl_param, $curl_value);
|
||||
}
|
||||
|
||||
$this->headers = curl_exec($fp);
|
||||
if (curl_errno($fp) === 23 || curl_errno($fp) === 61) {
|
||||
curl_setopt($fp, CURLOPT_ENCODING, 'none');
|
||||
$this->headers = curl_exec($fp);
|
||||
}
|
||||
$this->status_code = curl_getinfo($fp, CURLINFO_HTTP_CODE);
|
||||
if (curl_errno($fp)) {
|
||||
$this->error = 'cURL error ' . curl_errno($fp) . ': ' . curl_error($fp);
|
||||
$this->success = false;
|
||||
} else {
|
||||
// Use the updated url provided by curl_getinfo after any redirects.
|
||||
if ($info = curl_getinfo($fp)) {
|
||||
$this->url = $info['url'];
|
||||
}
|
||||
curl_close($fp);
|
||||
$this->headers = \SimplePie\HTTP\Parser::prepareHeaders($this->headers, $info['redirect_count'] + 1);
|
||||
$parser = new \SimplePie\HTTP\Parser($this->headers);
|
||||
if ($parser->parse()) {
|
||||
$this->headers = $parser->headers;
|
||||
$this->body = trim($parser->body);
|
||||
$this->status_code = $parser->status_code;
|
||||
if ((in_array($this->status_code, [300, 301, 302, 303, 307]) || $this->status_code > 307 && $this->status_code < 400) && isset($this->headers['location']) && $this->redirects < $redirects) {
|
||||
$this->redirects++;
|
||||
$location = \SimplePie\Misc::absolutize_url($this->headers['location'], $url);
|
||||
$previousStatusCode = $this->status_code;
|
||||
$this->__construct($location, $timeout, $redirects, $headers, $useragent, $force_fsockopen, $curl_options);
|
||||
$this->permanent_url = ($previousStatusCode == 301) ? $location : $url;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->method = \SimplePie\SimplePie::FILE_SOURCE_REMOTE | \SimplePie\SimplePie::FILE_SOURCE_FSOCKOPEN;
|
||||
$url_parts = parse_url($url);
|
||||
$socket_host = $url_parts['host'];
|
||||
if (isset($url_parts['scheme']) && strtolower($url_parts['scheme']) === 'https') {
|
||||
$socket_host = "ssl://$url_parts[host]";
|
||||
$url_parts['port'] = 443;
|
||||
}
|
||||
if (!isset($url_parts['port'])) {
|
||||
$url_parts['port'] = 80;
|
||||
}
|
||||
$fp = @fsockopen($socket_host, $url_parts['port'], $errno, $errstr, $timeout);
|
||||
if (!$fp) {
|
||||
$this->error = 'fsockopen error: ' . $errstr;
|
||||
$this->success = false;
|
||||
} else {
|
||||
stream_set_timeout($fp, $timeout);
|
||||
if (isset($url_parts['path'])) {
|
||||
if (isset($url_parts['query'])) {
|
||||
$get = "$url_parts[path]?$url_parts[query]";
|
||||
} else {
|
||||
$get = $url_parts['path'];
|
||||
}
|
||||
} else {
|
||||
$get = '/';
|
||||
}
|
||||
$out = "GET $get HTTP/1.1\r\n";
|
||||
$out .= "Host: $url_parts[host]\r\n";
|
||||
$out .= "User-Agent: $useragent\r\n";
|
||||
if (extension_loaded('zlib')) {
|
||||
$out .= "Accept-Encoding: x-gzip,gzip,deflate\r\n";
|
||||
}
|
||||
|
||||
if (isset($url_parts['user']) && isset($url_parts['pass'])) {
|
||||
$out .= "Authorization: Basic " . base64_encode("$url_parts[user]:$url_parts[pass]") . "\r\n";
|
||||
}
|
||||
foreach ($headers as $key => $value) {
|
||||
$out .= "$key: $value\r\n";
|
||||
}
|
||||
$out .= "Connection: Close\r\n\r\n";
|
||||
fwrite($fp, $out);
|
||||
|
||||
$info = stream_get_meta_data($fp);
|
||||
|
||||
$this->headers = '';
|
||||
while (!$info['eof'] && !$info['timed_out']) {
|
||||
$this->headers .= fread($fp, 1160);
|
||||
$info = stream_get_meta_data($fp);
|
||||
}
|
||||
if (!$info['timed_out']) {
|
||||
$parser = new \SimplePie\HTTP\Parser($this->headers);
|
||||
if ($parser->parse()) {
|
||||
$this->headers = $parser->headers;
|
||||
$this->body = $parser->body;
|
||||
$this->status_code = $parser->status_code;
|
||||
if ((in_array($this->status_code, [300, 301, 302, 303, 307]) || $this->status_code > 307 && $this->status_code < 400) && isset($this->headers['location']) && $this->redirects < $redirects) {
|
||||
$this->redirects++;
|
||||
$location = \SimplePie\Misc::absolutize_url($this->headers['location'], $url);
|
||||
$previousStatusCode = $this->status_code;
|
||||
$this->__construct($location, $timeout, $redirects, $headers, $useragent, $force_fsockopen, $curl_options);
|
||||
$this->permanent_url = ($previousStatusCode == 301) ? $location : $url;
|
||||
return;
|
||||
}
|
||||
if (isset($this->headers['content-encoding'])) {
|
||||
// Hey, we act dumb elsewhere, so let's do that here too
|
||||
switch (strtolower(trim($this->headers['content-encoding'], "\x09\x0A\x0D\x20"))) {
|
||||
case 'gzip':
|
||||
case 'x-gzip':
|
||||
$decoder = new \SimplePie\Gzdecode($this->body);
|
||||
if (!$decoder->parse()) {
|
||||
$this->error = 'Unable to decode HTTP "gzip" stream';
|
||||
$this->success = false;
|
||||
} else {
|
||||
$this->body = trim($decoder->data);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'deflate':
|
||||
if (($decompressed = gzinflate($this->body)) !== false) {
|
||||
$this->body = $decompressed;
|
||||
} elseif (($decompressed = gzuncompress($this->body)) !== false) {
|
||||
$this->body = $decompressed;
|
||||
} elseif (function_exists('gzdecode') && ($decompressed = gzdecode($this->body)) !== false) {
|
||||
$this->body = $decompressed;
|
||||
} else {
|
||||
$this->error = 'Unable to decode HTTP "deflate" stream';
|
||||
$this->success = false;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
$this->error = 'Unknown content coding';
|
||||
$this->success = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->error = 'fsocket timed out';
|
||||
$this->success = false;
|
||||
}
|
||||
fclose($fp);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->method = \SimplePie\SimplePie::FILE_SOURCE_LOCAL | \SimplePie\SimplePie::FILE_SOURCE_FILE_GET_CONTENTS;
|
||||
if (empty($url) || !($this->body = trim(file_get_contents($url)))) {
|
||||
$this->error = 'file_get_contents could not read the file';
|
||||
$this->success = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('SimplePie\File', 'SimplePie_File');
|
|
@ -0,0 +1,347 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2022, 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
|
||||
*/
|
||||
|
||||
namespace SimplePie;
|
||||
|
||||
/**
|
||||
* Decode 'gzip' encoded HTTP data
|
||||
*
|
||||
* @package SimplePie
|
||||
* @subpackage HTTP
|
||||
* @link http://www.gzip.org/format.txt
|
||||
*/
|
||||
class Gzdecode
|
||||
{
|
||||
/**
|
||||
* Compressed data
|
||||
*
|
||||
* @access private
|
||||
* @var string
|
||||
* @see gzdecode::$data
|
||||
*/
|
||||
public $compressed_data;
|
||||
|
||||
/**
|
||||
* Size of compressed data
|
||||
*
|
||||
* @access private
|
||||
* @var int
|
||||
*/
|
||||
public $compressed_size;
|
||||
|
||||
/**
|
||||
* Minimum size of a valid gzip string
|
||||
*
|
||||
* @access private
|
||||
* @var int
|
||||
*/
|
||||
public $min_compressed_size = 18;
|
||||
|
||||
/**
|
||||
* Current position of pointer
|
||||
*
|
||||
* @access private
|
||||
* @var int
|
||||
*/
|
||||
public $position = 0;
|
||||
|
||||
/**
|
||||
* Flags (FLG)
|
||||
*
|
||||
* @access private
|
||||
* @var int
|
||||
*/
|
||||
public $flags;
|
||||
|
||||
/**
|
||||
* Uncompressed data
|
||||
*
|
||||
* @access public
|
||||
* @see gzdecode::$compressed_data
|
||||
* @var string
|
||||
*/
|
||||
public $data;
|
||||
|
||||
/**
|
||||
* Modified time
|
||||
*
|
||||
* @access public
|
||||
* @var int
|
||||
*/
|
||||
public $MTIME;
|
||||
|
||||
/**
|
||||
* Extra Flags
|
||||
*
|
||||
* @access public
|
||||
* @var int
|
||||
*/
|
||||
public $XFL;
|
||||
|
||||
/**
|
||||
* Operating System
|
||||
*
|
||||
* @access public
|
||||
* @var int
|
||||
*/
|
||||
public $OS;
|
||||
|
||||
/**
|
||||
* Subfield ID 1
|
||||
*
|
||||
* @access public
|
||||
* @see gzdecode::$extra_field
|
||||
* @see gzdecode::$SI2
|
||||
* @var string
|
||||
*/
|
||||
public $SI1;
|
||||
|
||||
/**
|
||||
* Subfield ID 2
|
||||
*
|
||||
* @access public
|
||||
* @see gzdecode::$extra_field
|
||||
* @see gzdecode::$SI1
|
||||
* @var string
|
||||
*/
|
||||
public $SI2;
|
||||
|
||||
/**
|
||||
* Extra field content
|
||||
*
|
||||
* @access public
|
||||
* @see gzdecode::$SI1
|
||||
* @see gzdecode::$SI2
|
||||
* @var string
|
||||
*/
|
||||
public $extra_field;
|
||||
|
||||
/**
|
||||
* Original filename
|
||||
*
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
public $filename;
|
||||
|
||||
/**
|
||||
* Human readable comment
|
||||
*
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
public $comment;
|
||||
|
||||
/**
|
||||
* Don't allow anything to be set
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function __set($name, $value)
|
||||
{
|
||||
trigger_error("Cannot write property $name", E_USER_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the compressed string and related properties
|
||||
*
|
||||
* @param string $data
|
||||
*/
|
||||
public function __construct($data)
|
||||
{
|
||||
$this->compressed_data = $data;
|
||||
$this->compressed_size = strlen($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode the GZIP stream
|
||||
*
|
||||
* @return bool Successfulness
|
||||
*/
|
||||
public function parse()
|
||||
{
|
||||
if ($this->compressed_size >= $this->min_compressed_size) {
|
||||
$len = 0;
|
||||
|
||||
// Check ID1, ID2, and CM
|
||||
if (substr($this->compressed_data, 0, 3) !== "\x1F\x8B\x08") {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get the FLG (FLaGs)
|
||||
$this->flags = ord($this->compressed_data[3]);
|
||||
|
||||
// FLG bits above (1 << 4) are reserved
|
||||
if ($this->flags > 0x1F) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Advance the pointer after the above
|
||||
$this->position += 4;
|
||||
|
||||
// MTIME
|
||||
$mtime = substr($this->compressed_data, $this->position, 4);
|
||||
// Reverse the string if we're on a big-endian arch because l is the only signed long and is machine endianness
|
||||
if (current(unpack('S', "\x00\x01")) === 1) {
|
||||
$mtime = strrev($mtime);
|
||||
}
|
||||
$this->MTIME = current(unpack('l', $mtime));
|
||||
$this->position += 4;
|
||||
|
||||
// Get the XFL (eXtra FLags)
|
||||
$this->XFL = ord($this->compressed_data[$this->position++]);
|
||||
|
||||
// Get the OS (Operating System)
|
||||
$this->OS = ord($this->compressed_data[$this->position++]);
|
||||
|
||||
// Parse the FEXTRA
|
||||
if ($this->flags & 4) {
|
||||
// Read subfield IDs
|
||||
$this->SI1 = $this->compressed_data[$this->position++];
|
||||
$this->SI2 = $this->compressed_data[$this->position++];
|
||||
|
||||
// SI2 set to zero is reserved for future use
|
||||
if ($this->SI2 === "\x00") {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get the length of the extra field
|
||||
$len = current(unpack('v', substr($this->compressed_data, $this->position, 2)));
|
||||
$this->position += 2;
|
||||
|
||||
// Check the length of the string is still valid
|
||||
$this->min_compressed_size += $len + 4;
|
||||
if ($this->compressed_size >= $this->min_compressed_size) {
|
||||
// Set the extra field to the given data
|
||||
$this->extra_field = substr($this->compressed_data, $this->position, $len);
|
||||
$this->position += $len;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Parse the FNAME
|
||||
if ($this->flags & 8) {
|
||||
// Get the length of the filename
|
||||
$len = strcspn($this->compressed_data, "\x00", $this->position);
|
||||
|
||||
// Check the length of the string is still valid
|
||||
$this->min_compressed_size += $len + 1;
|
||||
if ($this->compressed_size >= $this->min_compressed_size) {
|
||||
// Set the original filename to the given string
|
||||
$this->filename = substr($this->compressed_data, $this->position, $len);
|
||||
$this->position += $len + 1;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Parse the FCOMMENT
|
||||
if ($this->flags & 16) {
|
||||
// Get the length of the comment
|
||||
$len = strcspn($this->compressed_data, "\x00", $this->position);
|
||||
|
||||
// Check the length of the string is still valid
|
||||
$this->min_compressed_size += $len + 1;
|
||||
if ($this->compressed_size >= $this->min_compressed_size) {
|
||||
// Set the original comment to the given string
|
||||
$this->comment = substr($this->compressed_data, $this->position, $len);
|
||||
$this->position += $len + 1;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Parse the FHCRC
|
||||
if ($this->flags & 2) {
|
||||
// Check the length of the string is still valid
|
||||
$this->min_compressed_size += $len + 2;
|
||||
if ($this->compressed_size >= $this->min_compressed_size) {
|
||||
// Read the CRC
|
||||
$crc = current(unpack('v', substr($this->compressed_data, $this->position, 2)));
|
||||
|
||||
// Check the CRC matches
|
||||
if ((crc32(substr($this->compressed_data, 0, $this->position)) & 0xFFFF) === $crc) {
|
||||
$this->position += 2;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Decompress the actual data
|
||||
if (($this->data = gzinflate(substr($this->compressed_data, $this->position, -8))) === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->position = $this->compressed_size - 8;
|
||||
|
||||
// Check CRC of data
|
||||
$crc = current(unpack('V', substr($this->compressed_data, $this->position, 4)));
|
||||
$this->position += 4;
|
||||
/*if (extension_loaded('hash') && sprintf('%u', current(unpack('V', hash('crc32b', $this->data)))) !== sprintf('%u', $crc))
|
||||
{
|
||||
return false;
|
||||
}*/
|
||||
|
||||
// Check ISIZE of data
|
||||
$isize = current(unpack('V', substr($this->compressed_data, $this->position, 4)));
|
||||
$this->position += 4;
|
||||
if (sprintf('%u', strlen($this->data) & 0xFFFFFFFF) !== sprintf('%u', $isize)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Wow, against all odds, we've actually got a valid gzip string
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('SimplePie\Gzdecode', 'SimplePie_gzdecode');
|
|
@ -0,0 +1,509 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2022, 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
|
||||
*/
|
||||
|
||||
namespace SimplePie\HTTP;
|
||||
|
||||
/**
|
||||
* HTTP Response Parser
|
||||
*
|
||||
* @package SimplePie
|
||||
* @subpackage HTTP
|
||||
*/
|
||||
class Parser
|
||||
{
|
||||
/**
|
||||
* HTTP Version
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
public $http_version = 0.0;
|
||||
|
||||
/**
|
||||
* Status code
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $status_code = 0;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $reason = '';
|
||||
|
||||
/**
|
||||
* Key/value pairs of the headers
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $headers = [];
|
||||
|
||||
/**
|
||||
* Body of the response
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $body = '';
|
||||
|
||||
private const STATE_HTTP_VERSION = 'http_version';
|
||||
|
||||
private const STATE_STATUS = 'status';
|
||||
|
||||
private const STATE_REASON = 'reason';
|
||||
|
||||
private const STATE_NEW_LINE = 'new_line';
|
||||
|
||||
private const STATE_BODY = 'body';
|
||||
|
||||
private const STATE_NAME = 'name';
|
||||
|
||||
private const STATE_VALUE = 'value';
|
||||
|
||||
private const STATE_VALUE_CHAR = 'value_char';
|
||||
|
||||
private const STATE_QUOTE = 'quote';
|
||||
|
||||
private const STATE_QUOTE_ESCAPED = 'quote_escaped';
|
||||
|
||||
private const STATE_QUOTE_CHAR = 'quote_char';
|
||||
|
||||
private const STATE_CHUNKED = 'chunked';
|
||||
|
||||
private const STATE_EMIT = 'emit';
|
||||
|
||||
private const STATE_ERROR = false;
|
||||
|
||||
/**
|
||||
* Current state of the state machine
|
||||
*
|
||||
* @var self::STATE_*
|
||||
*/
|
||||
protected $state = self::STATE_HTTP_VERSION;
|
||||
|
||||
/**
|
||||
* Input data
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $data = '';
|
||||
|
||||
/**
|
||||
* Input data length (to avoid calling strlen() everytime this is needed)
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $data_length = 0;
|
||||
|
||||
/**
|
||||
* Current position of the pointer
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $position = 0;
|
||||
|
||||
/**
|
||||
* Name of the hedaer currently being parsed
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = '';
|
||||
|
||||
/**
|
||||
* Value of the hedaer currently being parsed
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $value = '';
|
||||
|
||||
/**
|
||||
* Create an instance of the class with the input data
|
||||
*
|
||||
* @param string $data Input data
|
||||
*/
|
||||
public function __construct($data)
|
||||
{
|
||||
$this->data = $data;
|
||||
$this->data_length = strlen($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the input data
|
||||
*
|
||||
* @return bool true on success, false on failure
|
||||
*/
|
||||
public function parse()
|
||||
{
|
||||
while ($this->state && $this->state !== self::STATE_EMIT && $this->has_data()) {
|
||||
$state = $this->state;
|
||||
$this->$state();
|
||||
}
|
||||
$this->data = '';
|
||||
if ($this->state === self::STATE_EMIT || $this->state === self::STATE_BODY) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->http_version = '';
|
||||
$this->status_code = 0;
|
||||
$this->reason = '';
|
||||
$this->headers = [];
|
||||
$this->body = '';
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether there is data beyond the pointer
|
||||
*
|
||||
* @return bool true if there is further data, false if not
|
||||
*/
|
||||
protected function has_data()
|
||||
{
|
||||
return (bool) ($this->position < $this->data_length);
|
||||
}
|
||||
|
||||
/**
|
||||
* See if the next character is LWS
|
||||
*
|
||||
* @return bool true if the next character is LWS, false if not
|
||||
*/
|
||||
protected function is_linear_whitespace()
|
||||
{
|
||||
return (bool) ($this->data[$this->position] === "\x09"
|
||||
|| $this->data[$this->position] === "\x20"
|
||||
|| ($this->data[$this->position] === "\x0A"
|
||||
&& isset($this->data[$this->position + 1])
|
||||
&& ($this->data[$this->position + 1] === "\x09" || $this->data[$this->position + 1] === "\x20")));
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the HTTP version
|
||||
*/
|
||||
protected function http_version()
|
||||
{
|
||||
if (strpos($this->data, "\x0A") !== false && strtoupper(substr($this->data, 0, 5)) === 'HTTP/') {
|
||||
$len = strspn($this->data, '0123456789.', 5);
|
||||
$this->http_version = substr($this->data, 5, $len);
|
||||
$this->position += 5 + $len;
|
||||
if (substr_count($this->http_version, '.') <= 1) {
|
||||
$this->http_version = (float) $this->http_version;
|
||||
$this->position += strspn($this->data, "\x09\x20", $this->position);
|
||||
$this->state = self::STATE_STATUS;
|
||||
} else {
|
||||
$this->state = self::STATE_ERROR;
|
||||
}
|
||||
} else {
|
||||
$this->state = self::STATE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the status code
|
||||
*/
|
||||
protected function status()
|
||||
{
|
||||
if ($len = strspn($this->data, '0123456789', $this->position)) {
|
||||
$this->status_code = (int) substr($this->data, $this->position, $len);
|
||||
$this->position += $len;
|
||||
$this->state = self::STATE_REASON;
|
||||
} else {
|
||||
$this->state = self::STATE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the reason phrase
|
||||
*/
|
||||
protected function reason()
|
||||
{
|
||||
$len = strcspn($this->data, "\x0A", $this->position);
|
||||
$this->reason = trim(substr($this->data, $this->position, $len), "\x09\x0D\x20");
|
||||
$this->position += $len + 1;
|
||||
$this->state = self::STATE_NEW_LINE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deal with a new line, shifting data around as needed
|
||||
*/
|
||||
protected function new_line()
|
||||
{
|
||||
$this->value = trim($this->value, "\x0D\x20");
|
||||
if ($this->name !== '' && $this->value !== '') {
|
||||
$this->name = strtolower($this->name);
|
||||
// We should only use the last Content-Type header. c.f. issue #1
|
||||
if (isset($this->headers[$this->name]) && $this->name !== 'content-type') {
|
||||
$this->headers[$this->name] .= ', ' . $this->value;
|
||||
} else {
|
||||
$this->headers[$this->name] = $this->value;
|
||||
}
|
||||
}
|
||||
$this->name = '';
|
||||
$this->value = '';
|
||||
if (substr($this->data[$this->position], 0, 2) === "\x0D\x0A") {
|
||||
$this->position += 2;
|
||||
$this->state = self::STATE_BODY;
|
||||
} elseif ($this->data[$this->position] === "\x0A") {
|
||||
$this->position++;
|
||||
$this->state = self::STATE_BODY;
|
||||
} else {
|
||||
$this->state = self::STATE_NAME;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a header name
|
||||
*/
|
||||
protected function name()
|
||||
{
|
||||
$len = strcspn($this->data, "\x0A:", $this->position);
|
||||
if (isset($this->data[$this->position + $len])) {
|
||||
if ($this->data[$this->position + $len] === "\x0A") {
|
||||
$this->position += $len;
|
||||
$this->state = self::STATE_NEW_LINE;
|
||||
} else {
|
||||
$this->name = substr($this->data, $this->position, $len);
|
||||
$this->position += $len + 1;
|
||||
$this->state = self::STATE_VALUE;
|
||||
}
|
||||
} else {
|
||||
$this->state = self::STATE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse LWS, replacing consecutive LWS characters with a single space
|
||||
*/
|
||||
protected function linear_whitespace()
|
||||
{
|
||||
do {
|
||||
if (substr($this->data, $this->position, 2) === "\x0D\x0A") {
|
||||
$this->position += 2;
|
||||
} elseif ($this->data[$this->position] === "\x0A") {
|
||||
$this->position++;
|
||||
}
|
||||
$this->position += strspn($this->data, "\x09\x20", $this->position);
|
||||
} while ($this->has_data() && $this->is_linear_whitespace());
|
||||
$this->value .= "\x20";
|
||||
}
|
||||
|
||||
/**
|
||||
* See what state to move to while within non-quoted header values
|
||||
*/
|
||||
protected function value()
|
||||
{
|
||||
if ($this->is_linear_whitespace()) {
|
||||
$this->linear_whitespace();
|
||||
} else {
|
||||
switch ($this->data[$this->position]) {
|
||||
case '"':
|
||||
// Workaround for ETags: we have to include the quotes as
|
||||
// part of the tag.
|
||||
if (strtolower($this->name) === 'etag') {
|
||||
$this->value .= '"';
|
||||
$this->position++;
|
||||
$this->state = self::STATE_VALUE_CHAR;
|
||||
break;
|
||||
}
|
||||
$this->position++;
|
||||
$this->state = self::STATE_QUOTE;
|
||||
break;
|
||||
|
||||
case "\x0A":
|
||||
$this->position++;
|
||||
$this->state = self::STATE_NEW_LINE;
|
||||
break;
|
||||
|
||||
default:
|
||||
$this->state = self::STATE_VALUE_CHAR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a header value while outside quotes
|
||||
*/
|
||||
protected function value_char()
|
||||
{
|
||||
$len = strcspn($this->data, "\x09\x20\x0A\"", $this->position);
|
||||
$this->value .= substr($this->data, $this->position, $len);
|
||||
$this->position += $len;
|
||||
$this->state = self::STATE_VALUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* See what state to move to while within quoted header values
|
||||
*/
|
||||
protected function quote()
|
||||
{
|
||||
if ($this->is_linear_whitespace()) {
|
||||
$this->linear_whitespace();
|
||||
} else {
|
||||
switch ($this->data[$this->position]) {
|
||||
case '"':
|
||||
$this->position++;
|
||||
$this->state = self::STATE_VALUE;
|
||||
break;
|
||||
|
||||
case "\x0A":
|
||||
$this->position++;
|
||||
$this->state = self::STATE_NEW_LINE;
|
||||
break;
|
||||
|
||||
case '\\':
|
||||
$this->position++;
|
||||
$this->state = self::STATE_QUOTE_ESCAPED;
|
||||
break;
|
||||
|
||||
default:
|
||||
$this->state = self::STATE_QUOTE_CHAR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a header value while within quotes
|
||||
*/
|
||||
protected function quote_char()
|
||||
{
|
||||
$len = strcspn($this->data, "\x09\x20\x0A\"\\", $this->position);
|
||||
$this->value .= substr($this->data, $this->position, $len);
|
||||
$this->position += $len;
|
||||
$this->state = self::STATE_VALUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse an escaped character within quotes
|
||||
*/
|
||||
protected function quote_escaped()
|
||||
{
|
||||
$this->value .= $this->data[$this->position];
|
||||
$this->position++;
|
||||
$this->state = self::STATE_QUOTE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the body
|
||||
*/
|
||||
protected function body()
|
||||
{
|
||||
$this->body = substr($this->data, $this->position);
|
||||
if (!empty($this->headers['transfer-encoding'])) {
|
||||
unset($this->headers['transfer-encoding']);
|
||||
$this->state = self::STATE_CHUNKED;
|
||||
} else {
|
||||
$this->state = self::STATE_EMIT;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parsed a "Transfer-Encoding: chunked" body
|
||||
*/
|
||||
protected function chunked()
|
||||
{
|
||||
if (!preg_match('/^([0-9a-f]+)[^\r\n]*\r\n/i', trim($this->body))) {
|
||||
$this->state = self::STATE_EMIT;
|
||||
return;
|
||||
}
|
||||
|
||||
$decoded = '';
|
||||
$encoded = $this->body;
|
||||
|
||||
while (true) {
|
||||
$is_chunked = (bool) preg_match('/^([0-9a-f]+)[^\r\n]*\r\n/i', $encoded, $matches);
|
||||
if (!$is_chunked) {
|
||||
// Looks like it's not chunked after all
|
||||
$this->state = self::STATE_EMIT;
|
||||
return;
|
||||
}
|
||||
|
||||
$length = hexdec(trim($matches[1]));
|
||||
if ($length === 0) {
|
||||
// Ignore trailer headers
|
||||
$this->state = self::STATE_EMIT;
|
||||
$this->body = $decoded;
|
||||
return;
|
||||
}
|
||||
|
||||
$chunk_length = strlen($matches[0]);
|
||||
$decoded .= substr($encoded, $chunk_length, $length);
|
||||
$encoded = substr($encoded, $chunk_length + $length + 2);
|
||||
|
||||
// BC for PHP < 8.0: substr() can return bool instead of string
|
||||
$encoded = ($encoded === false) ? '' : $encoded;
|
||||
|
||||
if (trim($encoded) === '0' || empty($encoded)) {
|
||||
$this->state = self::STATE_EMIT;
|
||||
$this->body = $decoded;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare headers (take care of proxies headers)
|
||||
*
|
||||
* @param string $headers Raw headers
|
||||
* @param integer $count Redirection count. Default to 1.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function prepareHeaders($headers, $count = 1)
|
||||
{
|
||||
$data = explode("\r\n\r\n", $headers, $count);
|
||||
$data = array_pop($data);
|
||||
if (false !== stripos($data, "HTTP/1.0 200 Connection established\r\n")) {
|
||||
$exploded = explode("\r\n\r\n", $data, 2);
|
||||
$data = end($exploded);
|
||||
}
|
||||
if (false !== stripos($data, "HTTP/1.1 200 Connection established\r\n")) {
|
||||
$exploded = explode("\r\n\r\n", $data, 2);
|
||||
$data = end($exploded);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('SimplePie\HTTP\Parser', 'SimplePie_HTTP_Parser');
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,370 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2022, 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
|
||||
*/
|
||||
|
||||
namespace SimplePie;
|
||||
|
||||
/**
|
||||
* Used for feed auto-discovery
|
||||
*
|
||||
*
|
||||
* This class can be overloaded with {@see \SimplePie\SimplePie::set_locator_class()}
|
||||
*
|
||||
* @package SimplePie
|
||||
*/
|
||||
class Locator implements RegistryAware
|
||||
{
|
||||
public $useragent;
|
||||
public $timeout;
|
||||
public $file;
|
||||
public $local = [];
|
||||
public $elsewhere = [];
|
||||
public $cached_entities = [];
|
||||
public $http_base;
|
||||
public $base;
|
||||
public $base_location = 0;
|
||||
public $checked_feeds = 0;
|
||||
public $max_checked_feeds = 10;
|
||||
public $force_fsockopen = false;
|
||||
public $curl_options = [];
|
||||
public $dom;
|
||||
protected $registry;
|
||||
|
||||
public function __construct(\SimplePie\File $file, $timeout = 10, $useragent = null, $max_checked_feeds = 10, $force_fsockopen = false, $curl_options = [])
|
||||
{
|
||||
$this->file = $file;
|
||||
$this->useragent = $useragent;
|
||||
$this->timeout = $timeout;
|
||||
$this->max_checked_feeds = $max_checked_feeds;
|
||||
$this->force_fsockopen = $force_fsockopen;
|
||||
$this->curl_options = $curl_options;
|
||||
|
||||
if (class_exists('DOMDocument') && $this->file->body != '') {
|
||||
$this->dom = new \DOMDocument();
|
||||
|
||||
set_error_handler(['SimplePie\Misc', 'silence_errors']);
|
||||
try {
|
||||
$this->dom->loadHTML($this->file->body);
|
||||
} catch (\Throwable $ex) {
|
||||
$this->dom = null;
|
||||
}
|
||||
restore_error_handler();
|
||||
} else {
|
||||
$this->dom = null;
|
||||
}
|
||||
}
|
||||
|
||||
public function set_registry(\SimplePie\Registry $registry)/* : void */
|
||||
{
|
||||
$this->registry = $registry;
|
||||
}
|
||||
|
||||
public function find($type = \SimplePie\SimplePie::LOCATOR_ALL, &$working = null)
|
||||
{
|
||||
if ($this->is_feed($this->file)) {
|
||||
return $this->file;
|
||||
}
|
||||
|
||||
if ($this->file->method & \SimplePie\SimplePie::FILE_SOURCE_REMOTE) {
|
||||
$sniffer = $this->registry->create(Content\Type\Sniffer::class, [$this->file]);
|
||||
if ($sniffer->get_type() !== 'text/html') {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if ($type & ~\SimplePie\SimplePie::LOCATOR_NONE) {
|
||||
$this->get_base();
|
||||
}
|
||||
|
||||
if ($type & \SimplePie\SimplePie::LOCATOR_AUTODISCOVERY && $working = $this->autodiscovery()) {
|
||||
return $working[0];
|
||||
}
|
||||
|
||||
if ($type & (\SimplePie\SimplePie::LOCATOR_LOCAL_EXTENSION | \SimplePie\SimplePie::LOCATOR_LOCAL_BODY | \SimplePie\SimplePie::LOCATOR_REMOTE_EXTENSION | \SimplePie\SimplePie::LOCATOR_REMOTE_BODY) && $this->get_links()) {
|
||||
if ($type & \SimplePie\SimplePie::LOCATOR_LOCAL_EXTENSION && $working = $this->extension($this->local)) {
|
||||
return $working[0];
|
||||
}
|
||||
|
||||
if ($type & \SimplePie\SimplePie::LOCATOR_LOCAL_BODY && $working = $this->body($this->local)) {
|
||||
return $working[0];
|
||||
}
|
||||
|
||||
if ($type & \SimplePie\SimplePie::LOCATOR_REMOTE_EXTENSION && $working = $this->extension($this->elsewhere)) {
|
||||
return $working[0];
|
||||
}
|
||||
|
||||
if ($type & \SimplePie\SimplePie::LOCATOR_REMOTE_BODY && $working = $this->body($this->elsewhere)) {
|
||||
return $working[0];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function is_feed($file, $check_html = false)
|
||||
{
|
||||
if ($file->method & \SimplePie\SimplePie::FILE_SOURCE_REMOTE) {
|
||||
$sniffer = $this->registry->create(Content\Type\Sniffer::class, [$file]);
|
||||
$sniffed = $sniffer->get_type();
|
||||
$mime_types = ['application/rss+xml', 'application/rdf+xml',
|
||||
'text/rdf', 'application/atom+xml', 'text/xml',
|
||||
'application/xml', 'application/x-rss+xml'];
|
||||
if ($check_html) {
|
||||
$mime_types[] = 'text/html';
|
||||
}
|
||||
|
||||
return in_array($sniffed, $mime_types);
|
||||
} elseif ($file->method & \SimplePie\SimplePie::FILE_SOURCE_LOCAL) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_base()
|
||||
{
|
||||
if ($this->dom === null) {
|
||||
throw new \SimplePie\Exception('DOMDocument not found, unable to use locator');
|
||||
}
|
||||
$this->http_base = $this->file->url;
|
||||
$this->base = $this->http_base;
|
||||
$elements = $this->dom->getElementsByTagName('base');
|
||||
foreach ($elements as $element) {
|
||||
if ($element->hasAttribute('href')) {
|
||||
$base = $this->registry->call(Misc::class, 'absolutize_url', [trim($element->getAttribute('href')), $this->http_base]);
|
||||
if ($base === false) {
|
||||
continue;
|
||||
}
|
||||
$this->base = $base;
|
||||
$this->base_location = method_exists($element, 'getLineNo') ? $element->getLineNo() : 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function autodiscovery()
|
||||
{
|
||||
$done = [];
|
||||
$feeds = [];
|
||||
$feeds = array_merge($feeds, $this->search_elements_by_tag('link', $done, $feeds));
|
||||
$feeds = array_merge($feeds, $this->search_elements_by_tag('a', $done, $feeds));
|
||||
$feeds = array_merge($feeds, $this->search_elements_by_tag('area', $done, $feeds));
|
||||
|
||||
if (!empty($feeds)) {
|
||||
return array_values($feeds);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function search_elements_by_tag($name, &$done, $feeds)
|
||||
{
|
||||
if ($this->dom === null) {
|
||||
throw new \SimplePie\Exception('DOMDocument not found, unable to use locator');
|
||||
}
|
||||
|
||||
$links = $this->dom->getElementsByTagName($name);
|
||||
foreach ($links as $link) {
|
||||
if ($this->checked_feeds === $this->max_checked_feeds) {
|
||||
break;
|
||||
}
|
||||
if ($link->hasAttribute('href') && $link->hasAttribute('rel')) {
|
||||
$rel = array_unique($this->registry->call(Misc::class, 'space_separated_tokens', [strtolower($link->getAttribute('rel'))]));
|
||||
$line = method_exists($link, 'getLineNo') ? $link->getLineNo() : 1;
|
||||
|
||||
if ($this->base_location < $line) {
|
||||
$href = $this->registry->call(Misc::class, 'absolutize_url', [trim($link->getAttribute('href')), $this->base]);
|
||||
} else {
|
||||
$href = $this->registry->call(Misc::class, 'absolutize_url', [trim($link->getAttribute('href')), $this->http_base]);
|
||||
}
|
||||
if ($href === false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!in_array($href, $done) && in_array('feed', $rel) || (in_array('alternate', $rel) && !in_array('stylesheet', $rel) && $link->hasAttribute('type') && in_array(strtolower($this->registry->call(Misc::class, 'parse_mime', [$link->getAttribute('type')])), ['text/html', 'application/rss+xml', 'application/atom+xml'])) && !isset($feeds[$href])) {
|
||||
$this->checked_feeds++;
|
||||
$headers = [
|
||||
'Accept' => 'application/atom+xml, application/rss+xml, application/rdf+xml;q=0.9, application/xml;q=0.8, text/xml;q=0.8, text/html;q=0.7, unknown/unknown;q=0.1, application/unknown;q=0.1, */*;q=0.1',
|
||||
];
|
||||
$feed = $this->registry->create(File::class, [$href, $this->timeout, 5, $headers, $this->useragent, $this->force_fsockopen, $this->curl_options]);
|
||||
if ($feed->success && ($feed->method & \SimplePie\SimplePie::FILE_SOURCE_REMOTE === 0 || ($feed->status_code === 200 || $feed->status_code > 206 && $feed->status_code < 300)) && $this->is_feed($feed, true)) {
|
||||
$feeds[$href] = $feed;
|
||||
}
|
||||
}
|
||||
$done[] = $href;
|
||||
}
|
||||
}
|
||||
|
||||
return $feeds;
|
||||
}
|
||||
|
||||
public function get_links()
|
||||
{
|
||||
if ($this->dom === null) {
|
||||
throw new \SimplePie\Exception('DOMDocument not found, unable to use locator');
|
||||
}
|
||||
|
||||
$links = $this->dom->getElementsByTagName('a');
|
||||
foreach ($links as $link) {
|
||||
if ($link->hasAttribute('href')) {
|
||||
$href = trim($link->getAttribute('href'));
|
||||
$parsed = $this->registry->call(Misc::class, 'parse_url', [$href]);
|
||||
if ($parsed['scheme'] === '' || preg_match('/^(https?|feed)?$/i', $parsed['scheme'])) {
|
||||
if (method_exists($link, 'getLineNo') && $this->base_location < $link->getLineNo()) {
|
||||
$href = $this->registry->call(Misc::class, 'absolutize_url', [trim($link->getAttribute('href')), $this->base]);
|
||||
} else {
|
||||
$href = $this->registry->call(Misc::class, 'absolutize_url', [trim($link->getAttribute('href')), $this->http_base]);
|
||||
}
|
||||
if ($href === false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$current = $this->registry->call(Misc::class, 'parse_url', [$this->file->url]);
|
||||
|
||||
if ($parsed['authority'] === '' || $parsed['authority'] === $current['authority']) {
|
||||
$this->local[] = $href;
|
||||
} else {
|
||||
$this->elsewhere[] = $href;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->local = array_unique($this->local);
|
||||
$this->elsewhere = array_unique($this->elsewhere);
|
||||
if (!empty($this->local) || !empty($this->elsewhere)) {
|
||||
return true;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function get_rel_link($rel)
|
||||
{
|
||||
if ($this->dom === null) {
|
||||
throw new \SimplePie\Exception('DOMDocument not found, unable to use '.
|
||||
'locator');
|
||||
}
|
||||
if (!class_exists('DOMXpath')) {
|
||||
throw new \SimplePie\Exception('DOMXpath not found, unable to use '.
|
||||
'get_rel_link');
|
||||
}
|
||||
|
||||
$xpath = new \DOMXpath($this->dom);
|
||||
$query = '//a[@rel and @href] | //link[@rel and @href]';
|
||||
foreach ($xpath->query($query) as $link) {
|
||||
$href = trim($link->getAttribute('href'));
|
||||
$parsed = $this->registry->call(Misc::class, 'parse_url', [$href]);
|
||||
if ($parsed['scheme'] === '' ||
|
||||
preg_match('/^https?$/i', $parsed['scheme'])) {
|
||||
if (method_exists($link, 'getLineNo') &&
|
||||
$this->base_location < $link->getLineNo()) {
|
||||
$href = $this->registry->call(
|
||||
Misc::class,
|
||||
'absolutize_url',
|
||||
[trim($link->getAttribute('href')), $this->base]
|
||||
);
|
||||
} else {
|
||||
$href = $this->registry->call(
|
||||
Misc::class,
|
||||
'absolutize_url',
|
||||
[trim($link->getAttribute('href')), $this->http_base]
|
||||
);
|
||||
}
|
||||
if ($href === false) {
|
||||
return null;
|
||||
}
|
||||
$rel_values = explode(' ', strtolower($link->getAttribute('rel')));
|
||||
if (in_array($rel, $rel_values)) {
|
||||
return $href;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function extension(&$array)
|
||||
{
|
||||
foreach ($array as $key => $value) {
|
||||
if ($this->checked_feeds === $this->max_checked_feeds) {
|
||||
break;
|
||||
}
|
||||
if (in_array(strtolower(strrchr($value, '.')), ['.rss', '.rdf', '.atom', '.xml'])) {
|
||||
$this->checked_feeds++;
|
||||
|
||||
$headers = [
|
||||
'Accept' => 'application/atom+xml, application/rss+xml, application/rdf+xml;q=0.9, application/xml;q=0.8, text/xml;q=0.8, text/html;q=0.7, unknown/unknown;q=0.1, application/unknown;q=0.1, */*;q=0.1',
|
||||
];
|
||||
$feed = $this->registry->create(File::class, [$value, $this->timeout, 5, $headers, $this->useragent, $this->force_fsockopen, $this->curl_options]);
|
||||
if ($feed->success && ($feed->method & \SimplePie\SimplePie::FILE_SOURCE_REMOTE === 0 || ($feed->status_code === 200 || $feed->status_code > 206 && $feed->status_code < 300)) && $this->is_feed($feed)) {
|
||||
return [$feed];
|
||||
} else {
|
||||
unset($array[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function body(&$array)
|
||||
{
|
||||
foreach ($array as $key => $value) {
|
||||
if ($this->checked_feeds === $this->max_checked_feeds) {
|
||||
break;
|
||||
}
|
||||
if (preg_match('/(feed|rss|rdf|atom|xml)/i', $value)) {
|
||||
$this->checked_feeds++;
|
||||
$headers = [
|
||||
'Accept' => 'application/atom+xml, application/rss+xml, application/rdf+xml;q=0.9, application/xml;q=0.8, text/xml;q=0.8, text/html;q=0.7, unknown/unknown;q=0.1, application/unknown;q=0.1, */*;q=0.1',
|
||||
];
|
||||
$feed = $this->registry->create(File::class, [$value, $this->timeout, 5, null, $this->useragent, $this->force_fsockopen, $this->curl_options]);
|
||||
if ($feed->success && ($feed->method & \SimplePie\SimplePie::FILE_SOURCE_REMOTE === 0 || ($feed->status_code === 200 || $feed->status_code > 206 && $feed->status_code < 300)) && $this->is_feed($feed)) {
|
||||
return [$feed];
|
||||
} else {
|
||||
unset($array[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('SimplePie\Locator', 'SimplePie_Locator', false);
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,258 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2022, 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
|
||||
*/
|
||||
|
||||
namespace SimplePie\Net;
|
||||
|
||||
/**
|
||||
* Class to validate and to work with IPv6 addresses.
|
||||
*
|
||||
* @package SimplePie
|
||||
* @subpackage HTTP
|
||||
* @copyright 2003-2005 The PHP Group
|
||||
* @license http://www.opensource.org/licenses/bsd-license.php
|
||||
* @link http://pear.php.net/package/Net_IPv6
|
||||
* @author Alexander Merz <alexander.merz@web.de>
|
||||
* @author elfrink at introweb dot nl
|
||||
* @author Josh Peck <jmp at joshpeck dot org>
|
||||
* @author Sam Sneddon <geoffers@gmail.com>
|
||||
*/
|
||||
class IPv6
|
||||
{
|
||||
/**
|
||||
* Uncompresses an IPv6 address
|
||||
*
|
||||
* RFC 4291 allows you to compress concecutive 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 http://www.opensource.org/licenses/bsd-license.php
|
||||
* @param string $ip An IPv6 address
|
||||
* @return string The uncompressed IPv6 address
|
||||
*/
|
||||
public static function uncompress($ip)
|
||||
{
|
||||
$c1 = -1;
|
||||
$c2 = -1;
|
||||
if (substr_count($ip, '::') === 1) {
|
||||
[$ip1, $ip2] = explode('::', $ip);
|
||||
if ($ip1 === '') {
|
||||
$c1 = -1;
|
||||
} else {
|
||||
$c1 = substr_count($ip1, ':');
|
||||
}
|
||||
if ($ip2 === '') {
|
||||
$c2 = -1;
|
||||
} else {
|
||||
$c2 = substr_count($ip2, ':');
|
||||
}
|
||||
if (strpos($ip2, '.') !== false) {
|
||||
$c2++;
|
||||
}
|
||||
// ::
|
||||
if ($c1 === -1 && $c2 === -1) {
|
||||
$ip = '0:0:0:0:0:0:0:0';
|
||||
}
|
||||
// ::xxx
|
||||
elseif ($c1 === -1) {
|
||||
$fill = str_repeat('0:', 7 - $c2);
|
||||
$ip = str_replace('::', $fill, $ip);
|
||||
}
|
||||
// xxx::
|
||||
elseif ($c2 === -1) {
|
||||
$fill = str_repeat(':0', 7 - $c1);
|
||||
$ip = str_replace('::', $fill, $ip);
|
||||
}
|
||||
// xxx::xxx
|
||||
else {
|
||||
$fill = ':' . str_repeat('0:', 6 - $c2 - $c1);
|
||||
$ip = str_replace('::', $fill, $ip);
|
||||
}
|
||||
}
|
||||
return $ip;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compresses an IPv6 address
|
||||
*
|
||||
* RFC 4291 allows you to compress concecutive 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 uncompress()
|
||||
* @param string $ip An IPv6 address
|
||||
* @return string The compressed IPv6 address
|
||||
*/
|
||||
public static function compress($ip)
|
||||
{
|
||||
// Prepare the IP to be compressed
|
||||
$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);
|
||||
}
|
||||
|
||||
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 array [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];
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
$ip = self::uncompress($ip);
|
||||
[$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;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given IP is a valid IPv6 address
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated Use {@see IPv6::check_ipv6()} instead
|
||||
* @see check_ipv6
|
||||
* @param string $ip An IPv6 address
|
||||
* @return bool true if $ip is a valid IPv6 address
|
||||
*/
|
||||
public static function checkIPv6($ip)
|
||||
{
|
||||
return self::check_ipv6($ip);
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('SimplePie\Net\IPv6', 'SimplePie_Net_IPv6');
|
|
@ -0,0 +1,989 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2022, 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
|
||||
*/
|
||||
|
||||
namespace SimplePie\Parse;
|
||||
|
||||
/**
|
||||
* Date Parser
|
||||
*
|
||||
* @package SimplePie
|
||||
* @subpackage Parsing
|
||||
*/
|
||||
class Date
|
||||
{
|
||||
/**
|
||||
* Input data
|
||||
*
|
||||
* @access protected
|
||||
* @var string
|
||||
*/
|
||||
public $date;
|
||||
|
||||
/**
|
||||
* List of days, calendar day name => ordinal day number in the week
|
||||
*
|
||||
* @access protected
|
||||
* @var array
|
||||
*/
|
||||
public $day = [
|
||||
// English
|
||||
'mon' => 1,
|
||||
'monday' => 1,
|
||||
'tue' => 2,
|
||||
'tuesday' => 2,
|
||||
'wed' => 3,
|
||||
'wednesday' => 3,
|
||||
'thu' => 4,
|
||||
'thursday' => 4,
|
||||
'fri' => 5,
|
||||
'friday' => 5,
|
||||
'sat' => 6,
|
||||
'saturday' => 6,
|
||||
'sun' => 7,
|
||||
'sunday' => 7,
|
||||
// Dutch
|
||||
'maandag' => 1,
|
||||
'dinsdag' => 2,
|
||||
'woensdag' => 3,
|
||||
'donderdag' => 4,
|
||||
'vrijdag' => 5,
|
||||
'zaterdag' => 6,
|
||||
'zondag' => 7,
|
||||
// French
|
||||
'lundi' => 1,
|
||||
'mardi' => 2,
|
||||
'mercredi' => 3,
|
||||
'jeudi' => 4,
|
||||
'vendredi' => 5,
|
||||
'samedi' => 6,
|
||||
'dimanche' => 7,
|
||||
// German
|
||||
'montag' => 1,
|
||||
'mo' => 1,
|
||||
'dienstag' => 2,
|
||||
'di' => 2,
|
||||
'mittwoch' => 3,
|
||||
'mi' => 3,
|
||||
'donnerstag' => 4,
|
||||
'do' => 4,
|
||||
'freitag' => 5,
|
||||
'fr' => 5,
|
||||
'samstag' => 6,
|
||||
'sa' => 6,
|
||||
'sonnabend' => 6,
|
||||
// AFAIK no short form for sonnabend
|
||||
'so' => 7,
|
||||
'sonntag' => 7,
|
||||
// Italian
|
||||
'lunedì' => 1,
|
||||
'martedì' => 2,
|
||||
'mercoledì' => 3,
|
||||
'giovedì' => 4,
|
||||
'venerdì' => 5,
|
||||
'sabato' => 6,
|
||||
'domenica' => 7,
|
||||
// Spanish
|
||||
'lunes' => 1,
|
||||
'martes' => 2,
|
||||
'miércoles' => 3,
|
||||
'jueves' => 4,
|
||||
'viernes' => 5,
|
||||
'sábado' => 6,
|
||||
'domingo' => 7,
|
||||
// Finnish
|
||||
'maanantai' => 1,
|
||||
'tiistai' => 2,
|
||||
'keskiviikko' => 3,
|
||||
'torstai' => 4,
|
||||
'perjantai' => 5,
|
||||
'lauantai' => 6,
|
||||
'sunnuntai' => 7,
|
||||
// Hungarian
|
||||
'hétfő' => 1,
|
||||
'kedd' => 2,
|
||||
'szerda' => 3,
|
||||
'csütörtok' => 4,
|
||||
'péntek' => 5,
|
||||
'szombat' => 6,
|
||||
'vasárnap' => 7,
|
||||
// Greek
|
||||
'Δευ' => 1,
|
||||
'Τρι' => 2,
|
||||
'Τετ' => 3,
|
||||
'Πεμ' => 4,
|
||||
'Παρ' => 5,
|
||||
'Σαβ' => 6,
|
||||
'Κυρ' => 7,
|
||||
// Russian
|
||||
'Пн.' => 1,
|
||||
'Вт.' => 2,
|
||||
'Ср.' => 3,
|
||||
'Чт.' => 4,
|
||||
'Пт.' => 5,
|
||||
'Сб.' => 6,
|
||||
'Вс.' => 7,
|
||||
];
|
||||
|
||||
/**
|
||||
* List of months, calendar month name => calendar month number
|
||||
*
|
||||
* @access protected
|
||||
* @var array
|
||||
*/
|
||||
public $month = [
|
||||
// English
|
||||
'jan' => 1,
|
||||
'january' => 1,
|
||||
'feb' => 2,
|
||||
'february' => 2,
|
||||
'mar' => 3,
|
||||
'march' => 3,
|
||||
'apr' => 4,
|
||||
'april' => 4,
|
||||
'may' => 5,
|
||||
// No long form of May
|
||||
'jun' => 6,
|
||||
'june' => 6,
|
||||
'jul' => 7,
|
||||
'july' => 7,
|
||||
'aug' => 8,
|
||||
'august' => 8,
|
||||
'sep' => 9,
|
||||
'september' => 9,
|
||||
'oct' => 10,
|
||||
'october' => 10,
|
||||
'nov' => 11,
|
||||
'november' => 11,
|
||||
'dec' => 12,
|
||||
'december' => 12,
|
||||
// Dutch
|
||||
'januari' => 1,
|
||||
'februari' => 2,
|
||||
'maart' => 3,
|
||||
'april' => 4,
|
||||
'mei' => 5,
|
||||
'juni' => 6,
|
||||
'juli' => 7,
|
||||
'augustus' => 8,
|
||||
'september' => 9,
|
||||
'oktober' => 10,
|
||||
'november' => 11,
|
||||
'december' => 12,
|
||||
// French
|
||||
'janvier' => 1,
|
||||
'février' => 2,
|
||||
'mars' => 3,
|
||||
'avril' => 4,
|
||||
'mai' => 5,
|
||||
'juin' => 6,
|
||||
'juillet' => 7,
|
||||
'août' => 8,
|
||||
'septembre' => 9,
|
||||
'octobre' => 10,
|
||||
'novembre' => 11,
|
||||
'décembre' => 12,
|
||||
// German
|
||||
'januar' => 1,
|
||||
'jan' => 1,
|
||||
'februar' => 2,
|
||||
'feb' => 2,
|
||||
'märz' => 3,
|
||||
'mär' => 3,
|
||||
'april' => 4,
|
||||
'apr' => 4,
|
||||
'mai' => 5, // no short form for may
|
||||
'juni' => 6,
|
||||
'jun' => 6,
|
||||
'juli' => 7,
|
||||
'jul' => 7,
|
||||
'august' => 8,
|
||||
'aug' => 8,
|
||||
'september' => 9,
|
||||
'sep' => 9,
|
||||
'oktober' => 10,
|
||||
'okt' => 10,
|
||||
'november' => 11,
|
||||
'nov' => 11,
|
||||
'dezember' => 12,
|
||||
'dez' => 12,
|
||||
// Italian
|
||||
'gennaio' => 1,
|
||||
'febbraio' => 2,
|
||||
'marzo' => 3,
|
||||
'aprile' => 4,
|
||||
'maggio' => 5,
|
||||
'giugno' => 6,
|
||||
'luglio' => 7,
|
||||
'agosto' => 8,
|
||||
'settembre' => 9,
|
||||
'ottobre' => 10,
|
||||
'novembre' => 11,
|
||||
'dicembre' => 12,
|
||||
// Spanish
|
||||
'enero' => 1,
|
||||
'febrero' => 2,
|
||||
'marzo' => 3,
|
||||
'abril' => 4,
|
||||
'mayo' => 5,
|
||||
'junio' => 6,
|
||||
'julio' => 7,
|
||||
'agosto' => 8,
|
||||
'septiembre' => 9,
|
||||
'setiembre' => 9,
|
||||
'octubre' => 10,
|
||||
'noviembre' => 11,
|
||||
'diciembre' => 12,
|
||||
// Finnish
|
||||
'tammikuu' => 1,
|
||||
'helmikuu' => 2,
|
||||
'maaliskuu' => 3,
|
||||
'huhtikuu' => 4,
|
||||
'toukokuu' => 5,
|
||||
'kesäkuu' => 6,
|
||||
'heinäkuu' => 7,
|
||||
'elokuu' => 8,
|
||||
'suuskuu' => 9,
|
||||
'lokakuu' => 10,
|
||||
'marras' => 11,
|
||||
'joulukuu' => 12,
|
||||
// Hungarian
|
||||
'január' => 1,
|
||||
'február' => 2,
|
||||
'március' => 3,
|
||||
'április' => 4,
|
||||
'május' => 5,
|
||||
'június' => 6,
|
||||
'július' => 7,
|
||||
'augusztus' => 8,
|
||||
'szeptember' => 9,
|
||||
'október' => 10,
|
||||
'november' => 11,
|
||||
'december' => 12,
|
||||
// Greek
|
||||
'Ιαν' => 1,
|
||||
'Φεβ' => 2,
|
||||
'Μάώ' => 3,
|
||||
'Μαώ' => 3,
|
||||
'Απρ' => 4,
|
||||
'Μάι' => 5,
|
||||
'Μαϊ' => 5,
|
||||
'Μαι' => 5,
|
||||
'Ιούν' => 6,
|
||||
'Ιον' => 6,
|
||||
'Ιούλ' => 7,
|
||||
'Ιολ' => 7,
|
||||
'Αύγ' => 8,
|
||||
'Αυγ' => 8,
|
||||
'Σεπ' => 9,
|
||||
'Οκτ' => 10,
|
||||
'Νοέ' => 11,
|
||||
'Δεκ' => 12,
|
||||
// Russian
|
||||
'Янв' => 1,
|
||||
'января' => 1,
|
||||
'Фев' => 2,
|
||||
'февраля' => 2,
|
||||
'Мар' => 3,
|
||||
'марта' => 3,
|
||||
'Апр' => 4,
|
||||
'апреля' => 4,
|
||||
'Май' => 5,
|
||||
'мая' => 5,
|
||||
'Июн' => 6,
|
||||
'июня' => 6,
|
||||
'Июл' => 7,
|
||||
'июля' => 7,
|
||||
'Авг' => 8,
|
||||
'августа' => 8,
|
||||
'Сен' => 9,
|
||||
'сентября' => 9,
|
||||
'Окт' => 10,
|
||||
'октября' => 10,
|
||||
'Ноя' => 11,
|
||||
'ноября' => 11,
|
||||
'Дек' => 12,
|
||||
'декабря' => 12,
|
||||
|
||||
];
|
||||
|
||||
/**
|
||||
* List of timezones, abbreviation => offset from UTC
|
||||
*
|
||||
* @access protected
|
||||
* @var array
|
||||
*/
|
||||
public $timezone = [
|
||||
'ACDT' => 37800,
|
||||
'ACIT' => 28800,
|
||||
'ACST' => 34200,
|
||||
'ACT' => -18000,
|
||||
'ACWDT' => 35100,
|
||||
'ACWST' => 31500,
|
||||
'AEDT' => 39600,
|
||||
'AEST' => 36000,
|
||||
'AFT' => 16200,
|
||||
'AKDT' => -28800,
|
||||
'AKST' => -32400,
|
||||
'AMDT' => 18000,
|
||||
'AMT' => -14400,
|
||||
'ANAST' => 46800,
|
||||
'ANAT' => 43200,
|
||||
'ART' => -10800,
|
||||
'AZOST' => -3600,
|
||||
'AZST' => 18000,
|
||||
'AZT' => 14400,
|
||||
'BIOT' => 21600,
|
||||
'BIT' => -43200,
|
||||
'BOT' => -14400,
|
||||
'BRST' => -7200,
|
||||
'BRT' => -10800,
|
||||
'BST' => 3600,
|
||||
'BTT' => 21600,
|
||||
'CAST' => 18000,
|
||||
'CAT' => 7200,
|
||||
'CCT' => 23400,
|
||||
'CDT' => -18000,
|
||||
'CEDT' => 7200,
|
||||
'CEST' => 7200,
|
||||
'CET' => 3600,
|
||||
'CGST' => -7200,
|
||||
'CGT' => -10800,
|
||||
'CHADT' => 49500,
|
||||
'CHAST' => 45900,
|
||||
'CIST' => -28800,
|
||||
'CKT' => -36000,
|
||||
'CLDT' => -10800,
|
||||
'CLST' => -14400,
|
||||
'COT' => -18000,
|
||||
'CST' => -21600,
|
||||
'CVT' => -3600,
|
||||
'CXT' => 25200,
|
||||
'DAVT' => 25200,
|
||||
'DTAT' => 36000,
|
||||
'EADT' => -18000,
|
||||
'EAST' => -21600,
|
||||
'EAT' => 10800,
|
||||
'ECT' => -18000,
|
||||
'EDT' => -14400,
|
||||
'EEST' => 10800,
|
||||
'EET' => 7200,
|
||||
'EGT' => -3600,
|
||||
'EKST' => 21600,
|
||||
'EST' => -18000,
|
||||
'FJT' => 43200,
|
||||
'FKDT' => -10800,
|
||||
'FKST' => -14400,
|
||||
'FNT' => -7200,
|
||||
'GALT' => -21600,
|
||||
'GEDT' => 14400,
|
||||
'GEST' => 10800,
|
||||
'GFT' => -10800,
|
||||
'GILT' => 43200,
|
||||
'GIT' => -32400,
|
||||
'GST' => 14400,
|
||||
'GST' => -7200,
|
||||
'GYT' => -14400,
|
||||
'HAA' => -10800,
|
||||
'HAC' => -18000,
|
||||
'HADT' => -32400,
|
||||
'HAE' => -14400,
|
||||
'HAP' => -25200,
|
||||
'HAR' => -21600,
|
||||
'HAST' => -36000,
|
||||
'HAT' => -9000,
|
||||
'HAY' => -28800,
|
||||
'HKST' => 28800,
|
||||
'HMT' => 18000,
|
||||
'HNA' => -14400,
|
||||
'HNC' => -21600,
|
||||
'HNE' => -18000,
|
||||
'HNP' => -28800,
|
||||
'HNR' => -25200,
|
||||
'HNT' => -12600,
|
||||
'HNY' => -32400,
|
||||
'IRDT' => 16200,
|
||||
'IRKST' => 32400,
|
||||
'IRKT' => 28800,
|
||||
'IRST' => 12600,
|
||||
'JFDT' => -10800,
|
||||
'JFST' => -14400,
|
||||
'JST' => 32400,
|
||||
'KGST' => 21600,
|
||||
'KGT' => 18000,
|
||||
'KOST' => 39600,
|
||||
'KOVST' => 28800,
|
||||
'KOVT' => 25200,
|
||||
'KRAST' => 28800,
|
||||
'KRAT' => 25200,
|
||||
'KST' => 32400,
|
||||
'LHDT' => 39600,
|
||||
'LHST' => 37800,
|
||||
'LINT' => 50400,
|
||||
'LKT' => 21600,
|
||||
'MAGST' => 43200,
|
||||
'MAGT' => 39600,
|
||||
'MAWT' => 21600,
|
||||
'MDT' => -21600,
|
||||
'MESZ' => 7200,
|
||||
'MEZ' => 3600,
|
||||
'MHT' => 43200,
|
||||
'MIT' => -34200,
|
||||
'MNST' => 32400,
|
||||
'MSDT' => 14400,
|
||||
'MSST' => 10800,
|
||||
'MST' => -25200,
|
||||
'MUT' => 14400,
|
||||
'MVT' => 18000,
|
||||
'MYT' => 28800,
|
||||
'NCT' => 39600,
|
||||
'NDT' => -9000,
|
||||
'NFT' => 41400,
|
||||
'NMIT' => 36000,
|
||||
'NOVST' => 25200,
|
||||
'NOVT' => 21600,
|
||||
'NPT' => 20700,
|
||||
'NRT' => 43200,
|
||||
'NST' => -12600,
|
||||
'NUT' => -39600,
|
||||
'NZDT' => 46800,
|
||||
'NZST' => 43200,
|
||||
'OMSST' => 25200,
|
||||
'OMST' => 21600,
|
||||
'PDT' => -25200,
|
||||
'PET' => -18000,
|
||||
'PETST' => 46800,
|
||||
'PETT' => 43200,
|
||||
'PGT' => 36000,
|
||||
'PHOT' => 46800,
|
||||
'PHT' => 28800,
|
||||
'PKT' => 18000,
|
||||
'PMDT' => -7200,
|
||||
'PMST' => -10800,
|
||||
'PONT' => 39600,
|
||||
'PST' => -28800,
|
||||
'PWT' => 32400,
|
||||
'PYST' => -10800,
|
||||
'PYT' => -14400,
|
||||
'RET' => 14400,
|
||||
'ROTT' => -10800,
|
||||
'SAMST' => 18000,
|
||||
'SAMT' => 14400,
|
||||
'SAST' => 7200,
|
||||
'SBT' => 39600,
|
||||
'SCDT' => 46800,
|
||||
'SCST' => 43200,
|
||||
'SCT' => 14400,
|
||||
'SEST' => 3600,
|
||||
'SGT' => 28800,
|
||||
'SIT' => 28800,
|
||||
'SRT' => -10800,
|
||||
'SST' => -39600,
|
||||
'SYST' => 10800,
|
||||
'SYT' => 7200,
|
||||
'TFT' => 18000,
|
||||
'THAT' => -36000,
|
||||
'TJT' => 18000,
|
||||
'TKT' => -36000,
|
||||
'TMT' => 18000,
|
||||
'TOT' => 46800,
|
||||
'TPT' => 32400,
|
||||
'TRUT' => 36000,
|
||||
'TVT' => 43200,
|
||||
'TWT' => 28800,
|
||||
'UYST' => -7200,
|
||||
'UYT' => -10800,
|
||||
'UZT' => 18000,
|
||||
'VET' => -14400,
|
||||
'VLAST' => 39600,
|
||||
'VLAT' => 36000,
|
||||
'VOST' => 21600,
|
||||
'VUT' => 39600,
|
||||
'WAST' => 7200,
|
||||
'WAT' => 3600,
|
||||
'WDT' => 32400,
|
||||
'WEST' => 3600,
|
||||
'WFT' => 43200,
|
||||
'WIB' => 25200,
|
||||
'WIT' => 32400,
|
||||
'WITA' => 28800,
|
||||
'WKST' => 18000,
|
||||
'WST' => 28800,
|
||||
'YAKST' => 36000,
|
||||
'YAKT' => 32400,
|
||||
'YAPT' => 36000,
|
||||
'YEKST' => 21600,
|
||||
'YEKT' => 18000,
|
||||
];
|
||||
|
||||
/**
|
||||
* Cached PCRE for Date::$day
|
||||
*
|
||||
* @access protected
|
||||
* @var string
|
||||
*/
|
||||
public $day_pcre;
|
||||
|
||||
/**
|
||||
* Cached PCRE for Date::$month
|
||||
*
|
||||
* @access protected
|
||||
* @var string
|
||||
*/
|
||||
public $month_pcre;
|
||||
|
||||
/**
|
||||
* Array of user-added callback methods
|
||||
*
|
||||
* @access private
|
||||
* @var array
|
||||
*/
|
||||
public $built_in = [];
|
||||
|
||||
/**
|
||||
* Array of user-added callback methods
|
||||
*
|
||||
* @access private
|
||||
* @var array
|
||||
*/
|
||||
public $user = [];
|
||||
|
||||
/**
|
||||
* Create new Date object, and set self::day_pcre,
|
||||
* self::month_pcre, and self::built_in
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->day_pcre = '(' . implode('|', array_keys($this->day)) . ')';
|
||||
$this->month_pcre = '(' . implode('|', array_keys($this->month)) . ')';
|
||||
|
||||
static $cache;
|
||||
if (!isset($cache[get_class($this)])) {
|
||||
$all_methods = get_class_methods($this);
|
||||
|
||||
foreach ($all_methods as $method) {
|
||||
if (strtolower(substr($method, 0, 5)) === 'date_') {
|
||||
$cache[get_class($this)][] = $method;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($cache[get_class($this)] as $method) {
|
||||
$this->built_in[] = $method;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the object
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public static function get()
|
||||
{
|
||||
static $object;
|
||||
if (!$object) {
|
||||
$object = new Date();
|
||||
}
|
||||
return $object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a date
|
||||
*
|
||||
* @final
|
||||
* @access public
|
||||
* @param string $date Date to parse
|
||||
* @return int Timestamp corresponding to date string, or false on failure
|
||||
*/
|
||||
public function parse($date)
|
||||
{
|
||||
foreach ($this->user as $method) {
|
||||
if (($returned = call_user_func($method, $date)) !== false) {
|
||||
return $returned;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->built_in as $method) {
|
||||
if (($returned = call_user_func([$this, $method], $date)) !== false) {
|
||||
return $returned;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a callback method to parse a date
|
||||
*
|
||||
* @final
|
||||
* @access public
|
||||
* @param callable $callback
|
||||
*/
|
||||
public function add_callback($callback)
|
||||
{
|
||||
if (is_callable($callback)) {
|
||||
$this->user[] = $callback;
|
||||
} else {
|
||||
trigger_error('User-supplied function must be a valid callback', E_USER_WARNING);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a superset of W3C-DTF (allows hyphens and colons to be omitted, as
|
||||
* well as allowing any of upper or lower case "T", horizontal tabs, or
|
||||
* spaces to be used as the time separator (including more than one))
|
||||
*
|
||||
* @access protected
|
||||
* @return int Timestamp
|
||||
*/
|
||||
public function date_w3cdtf($date)
|
||||
{
|
||||
$pcre = <<<'PCRE'
|
||||
/
|
||||
^
|
||||
(?P<year>[0-9]{4})
|
||||
(?:
|
||||
-?
|
||||
(?P<month>[0-9]{2})
|
||||
(?:
|
||||
-?
|
||||
(?P<day>[0-9]{2})
|
||||
(?:
|
||||
[Tt\x09\x20]+
|
||||
(?P<hour>[0-9]{2})
|
||||
(?:
|
||||
:?
|
||||
(?P<minute>[0-9]{2})
|
||||
(?:
|
||||
:?
|
||||
(?P<second>[0-9]{2})
|
||||
(?:
|
||||
.
|
||||
(?P<second_fraction>[0-9]*)
|
||||
)?
|
||||
)?
|
||||
)?
|
||||
(?:
|
||||
(?P<zulu>Z)
|
||||
| (?P<tz_sign>[+\-])
|
||||
(?P<tz_hour>[0-9]{1,2})
|
||||
:?
|
||||
(?P<tz_minute>[0-9]{1,2})
|
||||
)
|
||||
)?
|
||||
)?
|
||||
)?
|
||||
$
|
||||
/x
|
||||
PCRE;
|
||||
if (preg_match($pcre, $date, $match)) {
|
||||
// Fill in empty matches and convert to proper types.
|
||||
$year = (int) $match['year'];
|
||||
$month = isset($match['month']) ? (int) $match['month'] : 1;
|
||||
$day = isset($match['day']) ? (int) $match['day'] : 1;
|
||||
$hour = isset($match['hour']) ? (int) $match['hour'] : 0;
|
||||
$minute = isset($match['minute']) ? (int) $match['minute'] : 0;
|
||||
$second = isset($match['second']) ? (int) $match['second'] : 0;
|
||||
$second_fraction = isset($match['second_fraction']) ? ((int) $match['second_fraction']) / (10 ** strlen($match['second_fraction'])) : 0;
|
||||
$tz_sign = ($match['tz_sign'] ?? '') === '-' ? -1 : 1;
|
||||
$tz_hour = isset($match['tz_hour']) ? (int) $match['tz_hour'] : 0;
|
||||
$tz_minute = isset($match['tz_minute']) ? (int) $match['tz_minute'] : 0;
|
||||
|
||||
// Numeric timezone
|
||||
$timezone = $tz_hour * 3600;
|
||||
$timezone += $tz_minute * 60;
|
||||
$timezone *= $tz_sign;
|
||||
|
||||
// Convert the number of seconds to an integer, taking decimals into account
|
||||
$second = (int) round($second + $second_fraction);
|
||||
|
||||
return gmmktime($hour, $minute, $second, $month, $day, $year) - $timezone;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove RFC822 comments
|
||||
*
|
||||
* @access protected
|
||||
* @param string $data Data to strip comments from
|
||||
* @return string Comment stripped string
|
||||
*/
|
||||
public function remove_rfc2822_comments($string)
|
||||
{
|
||||
$string = (string) $string;
|
||||
$position = 0;
|
||||
$length = strlen($string);
|
||||
$depth = 0;
|
||||
|
||||
$output = '';
|
||||
|
||||
while ($position < $length && ($pos = strpos($string, '(', $position)) !== false) {
|
||||
$output .= substr($string, $position, $pos - $position);
|
||||
$position = $pos + 1;
|
||||
if ($pos === 0 || $string[$pos - 1] !== '\\') {
|
||||
$depth++;
|
||||
while ($depth && $position < $length) {
|
||||
$position += strcspn($string, '()', $position);
|
||||
if ($string[$position - 1] === '\\') {
|
||||
$position++;
|
||||
continue;
|
||||
} elseif (isset($string[$position])) {
|
||||
switch ($string[$position]) {
|
||||
case '(':
|
||||
$depth++;
|
||||
break;
|
||||
|
||||
case ')':
|
||||
$depth--;
|
||||
break;
|
||||
}
|
||||
$position++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$output .= '(';
|
||||
}
|
||||
}
|
||||
$output .= substr($string, $position);
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse RFC2822's date format
|
||||
*
|
||||
* @access protected
|
||||
* @return int Timestamp
|
||||
*/
|
||||
public function date_rfc2822($date)
|
||||
{
|
||||
static $pcre;
|
||||
if (!$pcre) {
|
||||
$wsp = '[\x09\x20]';
|
||||
$fws = '(?:' . $wsp . '+|' . $wsp . '*(?:\x0D\x0A' . $wsp . '+)+)';
|
||||
$optional_fws = $fws . '?';
|
||||
$day_name = $this->day_pcre;
|
||||
$month = $this->month_pcre;
|
||||
$day = '([0-9]{1,2})';
|
||||
$hour = $minute = $second = '([0-9]{2})';
|
||||
$year = '([0-9]{2,4})';
|
||||
$num_zone = '([+\-])([0-9]{2})([0-9]{2})';
|
||||
$character_zone = '([A-Z]{1,5})';
|
||||
$zone = '(?:' . $num_zone . '|' . $character_zone . ')';
|
||||
$pcre = '/(?:' . $optional_fws . $day_name . $optional_fws . ',)?' . $optional_fws . $day . $fws . $month . $fws . $year . $fws . $hour . $optional_fws . ':' . $optional_fws . $minute . '(?:' . $optional_fws . ':' . $optional_fws . $second . ')?' . $fws . $zone . '/i';
|
||||
}
|
||||
if (preg_match($pcre, $this->remove_rfc2822_comments($date), $match)) {
|
||||
/*
|
||||
Capturing subpatterns:
|
||||
1: Day name
|
||||
2: Day
|
||||
3: Month
|
||||
4: Year
|
||||
5: Hour
|
||||
6: Minute
|
||||
7: Second
|
||||
8: Timezone ±
|
||||
9: Timezone hours
|
||||
10: Timezone minutes
|
||||
11: Alphabetic timezone
|
||||
*/
|
||||
|
||||
// Find the month number
|
||||
$month = $this->month[strtolower($match[3])];
|
||||
|
||||
// Numeric timezone
|
||||
if ($match[8] !== '') {
|
||||
$timezone = $match[9] * 3600;
|
||||
$timezone += $match[10] * 60;
|
||||
if ($match[8] === '-') {
|
||||
$timezone = 0 - $timezone;
|
||||
}
|
||||
}
|
||||
// Character timezone
|
||||
elseif (isset($this->timezone[strtoupper($match[11])])) {
|
||||
$timezone = $this->timezone[strtoupper($match[11])];
|
||||
}
|
||||
// Assume everything else to be -0000
|
||||
else {
|
||||
$timezone = 0;
|
||||
}
|
||||
|
||||
// Deal with 2/3 digit years
|
||||
if ($match[4] < 50) {
|
||||
$match[4] += 2000;
|
||||
} elseif ($match[4] < 1000) {
|
||||
$match[4] += 1900;
|
||||
}
|
||||
|
||||
// Second is optional, if it is empty set it to zero
|
||||
if ($match[7] !== '') {
|
||||
$second = $match[7];
|
||||
} else {
|
||||
$second = 0;
|
||||
}
|
||||
|
||||
return gmmktime(intval($match[5]), intval($match[6]), intval($second), intval($month), intval($match[2]), intval($match[4])) - $timezone;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse RFC850's date format
|
||||
*
|
||||
* @access protected
|
||||
* @return int Timestamp
|
||||
*/
|
||||
public function date_rfc850($date)
|
||||
{
|
||||
static $pcre;
|
||||
if (!$pcre) {
|
||||
$space = '[\x09\x20]+';
|
||||
$day_name = $this->day_pcre;
|
||||
$month = $this->month_pcre;
|
||||
$day = '([0-9]{1,2})';
|
||||
$year = $hour = $minute = $second = '([0-9]{2})';
|
||||
$zone = '([A-Z]{1,5})';
|
||||
$pcre = '/^' . $day_name . ',' . $space . $day . '-' . $month . '-' . $year . $space . $hour . ':' . $minute . ':' . $second . $space . $zone . '$/i';
|
||||
}
|
||||
if (preg_match($pcre, $date, $match)) {
|
||||
/*
|
||||
Capturing subpatterns:
|
||||
1: Day name
|
||||
2: Day
|
||||
3: Month
|
||||
4: Year
|
||||
5: Hour
|
||||
6: Minute
|
||||
7: Second
|
||||
8: Timezone
|
||||
*/
|
||||
|
||||
// Month
|
||||
$month = $this->month[strtolower($match[3])];
|
||||
|
||||
// Character timezone
|
||||
if (isset($this->timezone[strtoupper($match[8])])) {
|
||||
$timezone = $this->timezone[strtoupper($match[8])];
|
||||
}
|
||||
// Assume everything else to be -0000
|
||||
else {
|
||||
$timezone = 0;
|
||||
}
|
||||
|
||||
// Deal with 2 digit year
|
||||
if ($match[4] < 50) {
|
||||
$match[4] += 2000;
|
||||
} else {
|
||||
$match[4] += 1900;
|
||||
}
|
||||
|
||||
return gmmktime($match[5], $match[6], $match[7], $month, $match[2], $match[4]) - $timezone;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse C99's asctime()'s date format
|
||||
*
|
||||
* @access protected
|
||||
* @return int Timestamp
|
||||
*/
|
||||
public function date_asctime($date)
|
||||
{
|
||||
static $pcre;
|
||||
if (!$pcre) {
|
||||
$space = '[\x09\x20]+';
|
||||
$wday_name = $this->day_pcre;
|
||||
$mon_name = $this->month_pcre;
|
||||
$day = '([0-9]{1,2})';
|
||||
$hour = $sec = $min = '([0-9]{2})';
|
||||
$year = '([0-9]{4})';
|
||||
$terminator = '\x0A?\x00?';
|
||||
$pcre = '/^' . $wday_name . $space . $mon_name . $space . $day . $space . $hour . ':' . $min . ':' . $sec . $space . $year . $terminator . '$/i';
|
||||
}
|
||||
if (preg_match($pcre, $date, $match)) {
|
||||
/*
|
||||
Capturing subpatterns:
|
||||
1: Day name
|
||||
2: Month
|
||||
3: Day
|
||||
4: Hour
|
||||
5: Minute
|
||||
6: Second
|
||||
7: Year
|
||||
*/
|
||||
|
||||
$month = $this->month[strtolower($match[2])];
|
||||
return gmmktime((int) $match[4], (int) $match[5], (int) $match[6], $month, (int) $match[3], (int) $match[7]);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse dates using strtotime()
|
||||
*
|
||||
* @access protected
|
||||
* @return int Timestamp
|
||||
*/
|
||||
public function date_strtotime($date)
|
||||
{
|
||||
$strtotime = strtotime($date);
|
||||
if ($strtotime === -1 || $strtotime === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $strtotime;
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('SimplePie\Parse\Date', 'SimplePie_Parse_Date');
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue