Edit File by line
/home/zeestwma/ceyloniy.../wp-inclu.../SimplePi.../src
File: SimplePie.php
*/
[1500] Fix | Delete
public function rename_attributes($attribs = '')
[1501] Fix | Delete
{
[1502] Fix | Delete
if ($attribs === '') {
[1503] Fix | Delete
$attribs = $this->rename_attributes;
[1504] Fix | Delete
}
[1505] Fix | Delete
$this->sanitize->rename_attributes($attribs);
[1506] Fix | Delete
}
[1507] Fix | Delete
[1508] Fix | Delete
/**
[1509] Fix | Delete
* @param string[]|string $attribs
[1510] Fix | Delete
* @return void
[1511] Fix | Delete
*/
[1512] Fix | Delete
public function strip_attributes($attribs = '')
[1513] Fix | Delete
{
[1514] Fix | Delete
if ($attribs === '') {
[1515] Fix | Delete
$attribs = $this->strip_attributes;
[1516] Fix | Delete
}
[1517] Fix | Delete
$this->sanitize->strip_attributes($attribs);
[1518] Fix | Delete
}
[1519] Fix | Delete
[1520] Fix | Delete
/**
[1521] Fix | Delete
* @param array<string, array<string, string>>|'' $attribs
[1522] Fix | Delete
* @return void
[1523] Fix | Delete
*/
[1524] Fix | Delete
public function add_attributes($attribs = '')
[1525] Fix | Delete
{
[1526] Fix | Delete
if ($attribs === '') {
[1527] Fix | Delete
$attribs = $this->add_attributes;
[1528] Fix | Delete
}
[1529] Fix | Delete
$this->sanitize->add_attributes($attribs);
[1530] Fix | Delete
}
[1531] Fix | Delete
[1532] Fix | Delete
/**
[1533] Fix | Delete
* Set the output encoding
[1534] Fix | Delete
*
[1535] Fix | Delete
* Allows you to override SimplePie's output to match that of your webpage.
[1536] Fix | Delete
* This is useful for times when your webpages are not being served as
[1537] Fix | Delete
* UTF-8. This setting will be obeyed by {@see handle_content_type()}, and
[1538] Fix | Delete
* is similar to {@see set_input_encoding()}.
[1539] Fix | Delete
*
[1540] Fix | Delete
* It should be noted, however, that not all character encodings can support
[1541] Fix | Delete
* all characters. If your page is being served as ISO-8859-1 and you try
[1542] Fix | Delete
* to display a Japanese feed, you'll likely see garbled characters.
[1543] Fix | Delete
* Because of this, it is highly recommended to ensure that your webpages
[1544] Fix | Delete
* are served as UTF-8.
[1545] Fix | Delete
*
[1546] Fix | Delete
* The number of supported character encodings depends on whether your web
[1547] Fix | Delete
* host supports {@link http://php.net/mbstring mbstring},
[1548] Fix | Delete
* {@link http://php.net/iconv iconv}, or both. See
[1549] Fix | Delete
* {@link http://simplepie.org/wiki/faq/Supported_Character_Encodings} for
[1550] Fix | Delete
* more information.
[1551] Fix | Delete
*
[1552] Fix | Delete
* @param string $encoding
[1553] Fix | Delete
* @return void
[1554] Fix | Delete
*/
[1555] Fix | Delete
public function set_output_encoding(string $encoding = 'UTF-8')
[1556] Fix | Delete
{
[1557] Fix | Delete
$this->sanitize->set_output_encoding($encoding);
[1558] Fix | Delete
}
[1559] Fix | Delete
[1560] Fix | Delete
/**
[1561] Fix | Delete
* @return void
[1562] Fix | Delete
*/
[1563] Fix | Delete
public function strip_comments(bool $strip = false)
[1564] Fix | Delete
{
[1565] Fix | Delete
$this->sanitize->strip_comments($strip);
[1566] Fix | Delete
}
[1567] Fix | Delete
[1568] Fix | Delete
/**
[1569] Fix | Delete
* Set element/attribute key/value pairs of HTML attributes
[1570] Fix | Delete
* containing URLs that need to be resolved relative to the feed
[1571] Fix | Delete
*
[1572] Fix | Delete
* Defaults to |a|@href, |area|@href, |blockquote|@cite, |del|@cite,
[1573] Fix | Delete
* |form|@action, |img|@longdesc, |img|@src, |input|@src, |ins|@cite,
[1574] Fix | Delete
* |q|@cite
[1575] Fix | Delete
*
[1576] Fix | Delete
* @since 1.0
[1577] Fix | Delete
* @param array<string, string|string[]>|null $element_attribute Element/attribute key/value pairs, null for default
[1578] Fix | Delete
* @return void
[1579] Fix | Delete
*/
[1580] Fix | Delete
public function set_url_replacements(?array $element_attribute = null)
[1581] Fix | Delete
{
[1582] Fix | Delete
$this->sanitize->set_url_replacements($element_attribute);
[1583] Fix | Delete
}
[1584] Fix | Delete
[1585] Fix | Delete
/**
[1586] Fix | Delete
* Set the list of domains for which to force HTTPS.
[1587] Fix | Delete
* @see Sanitize::set_https_domains()
[1588] Fix | Delete
* @param array<string> $domains List of HTTPS domains. Example array('biz', 'example.com', 'example.org', 'www.example.net').
[1589] Fix | Delete
* @return void
[1590] Fix | Delete
*/
[1591] Fix | Delete
public function set_https_domains(array $domains = [])
[1592] Fix | Delete
{
[1593] Fix | Delete
$this->sanitize->set_https_domains($domains);
[1594] Fix | Delete
}
[1595] Fix | Delete
[1596] Fix | Delete
/**
[1597] Fix | Delete
* Set the handler to enable the display of cached images.
[1598] Fix | Delete
*
[1599] Fix | Delete
* @param string|false $page Web-accessible path to the handler_image.php file.
[1600] Fix | Delete
* @param string $qs The query string that the value should be passed to.
[1601] Fix | Delete
* @return void
[1602] Fix | Delete
*/
[1603] Fix | Delete
public function set_image_handler($page = false, string $qs = 'i')
[1604] Fix | Delete
{
[1605] Fix | Delete
if ($page !== false) {
[1606] Fix | Delete
$this->sanitize->set_image_handler($page . '?' . $qs . '=');
[1607] Fix | Delete
} else {
[1608] Fix | Delete
$this->image_handler = '';
[1609] Fix | Delete
}
[1610] Fix | Delete
}
[1611] Fix | Delete
[1612] Fix | Delete
/**
[1613] Fix | Delete
* Set the limit for items returned per-feed with multifeeds
[1614] Fix | Delete
*
[1615] Fix | Delete
* @param int $limit The maximum number of items to return.
[1616] Fix | Delete
* @return void
[1617] Fix | Delete
*/
[1618] Fix | Delete
public function set_item_limit(int $limit = 0)
[1619] Fix | Delete
{
[1620] Fix | Delete
$this->item_limit = $limit;
[1621] Fix | Delete
}
[1622] Fix | Delete
[1623] Fix | Delete
/**
[1624] Fix | Delete
* Enable throwing exceptions
[1625] Fix | Delete
*
[1626] Fix | Delete
* @param bool $enable Should we throw exceptions, or use the old-style error property?
[1627] Fix | Delete
* @return void
[1628] Fix | Delete
*/
[1629] Fix | Delete
public function enable_exceptions(bool $enable = true)
[1630] Fix | Delete
{
[1631] Fix | Delete
$this->enable_exceptions = $enable;
[1632] Fix | Delete
}
[1633] Fix | Delete
[1634] Fix | Delete
/**
[1635] Fix | Delete
* Initialize the feed object
[1636] Fix | Delete
*
[1637] Fix | Delete
* This is what makes everything happen. Period. This is where all of the
[1638] Fix | Delete
* configuration options get processed, feeds are fetched, cached, and
[1639] Fix | Delete
* parsed, and all of that other good stuff.
[1640] Fix | Delete
*
[1641] Fix | Delete
* @return bool True if successful, false otherwise
[1642] Fix | Delete
*/
[1643] Fix | Delete
public function init()
[1644] Fix | Delete
{
[1645] Fix | Delete
// Check absolute bare minimum requirements.
[1646] Fix | Delete
if (!extension_loaded('xml') || !extension_loaded('pcre')) {
[1647] Fix | Delete
$this->error = 'XML or PCRE extensions not loaded!';
[1648] Fix | Delete
return false;
[1649] Fix | Delete
}
[1650] Fix | Delete
// Then check the xml extension is sane (i.e., libxml 2.7.x issue on PHP < 5.2.9 and libxml 2.7.0 to 2.7.2 on any version) if we don't have xmlreader.
[1651] Fix | Delete
elseif (!extension_loaded('xmlreader')) {
[1652] Fix | Delete
static $xml_is_sane = null;
[1653] Fix | Delete
if ($xml_is_sane === null) {
[1654] Fix | Delete
$parser_check = xml_parser_create();
[1655] Fix | Delete
xml_parse_into_struct($parser_check, '<foo>&amp;</foo>', $values);
[1656] Fix | Delete
if (\PHP_VERSION_ID < 80000) {
[1657] Fix | Delete
xml_parser_free($parser_check);
[1658] Fix | Delete
}
[1659] Fix | Delete
$xml_is_sane = isset($values[0]['value']);
[1660] Fix | Delete
}
[1661] Fix | Delete
if (!$xml_is_sane) {
[1662] Fix | Delete
return false;
[1663] Fix | Delete
}
[1664] Fix | Delete
}
[1665] Fix | Delete
[1666] Fix | Delete
// The default sanitize class gets set in the constructor, check if it has
[1667] Fix | Delete
// changed.
[1668] Fix | Delete
if ($this->registry->get_class(Sanitize::class) !== Sanitize::class) {
[1669] Fix | Delete
$this->sanitize = $this->registry->create(Sanitize::class);
[1670] Fix | Delete
}
[1671] Fix | Delete
if (method_exists($this->sanitize, 'set_registry')) {
[1672] Fix | Delete
$this->sanitize->set_registry($this->registry);
[1673] Fix | Delete
}
[1674] Fix | Delete
[1675] Fix | Delete
// Pass whatever was set with config options over to the sanitizer.
[1676] Fix | Delete
// Pass the classes in for legacy support; new classes should use the registry instead
[1677] Fix | Delete
$cache = $this->registry->get_class(Cache::class);
[1678] Fix | Delete
\assert($cache !== null, 'Cache must be defined');
[1679] Fix | Delete
$this->sanitize->pass_cache_data(
[1680] Fix | Delete
$this->enable_cache,
[1681] Fix | Delete
$this->cache_location,
[1682] Fix | Delete
$this->cache_namefilter,
[1683] Fix | Delete
$cache,
[1684] Fix | Delete
$this->cache
[1685] Fix | Delete
);
[1686] Fix | Delete
[1687] Fix | Delete
$http_client = $this->get_http_client();
[1688] Fix | Delete
[1689] Fix | Delete
if ($http_client instanceof Psr18Client) {
[1690] Fix | Delete
$this->sanitize->set_http_client(
[1691] Fix | Delete
$http_client->getHttpClient(),
[1692] Fix | Delete
$http_client->getRequestFactory(),
[1693] Fix | Delete
$http_client->getUriFactory()
[1694] Fix | Delete
);
[1695] Fix | Delete
}
[1696] Fix | Delete
[1697] Fix | Delete
if (!empty($this->multifeed_url)) {
[1698] Fix | Delete
$i = 0;
[1699] Fix | Delete
$success = 0;
[1700] Fix | Delete
$this->multifeed_objects = [];
[1701] Fix | Delete
$this->error = [];
[1702] Fix | Delete
foreach ($this->multifeed_url as $url) {
[1703] Fix | Delete
$this->multifeed_objects[$i] = clone $this;
[1704] Fix | Delete
$this->multifeed_objects[$i]->set_feed_url($url);
[1705] Fix | Delete
$single_success = $this->multifeed_objects[$i]->init();
[1706] Fix | Delete
$success |= $single_success;
[1707] Fix | Delete
if (!$single_success) {
[1708] Fix | Delete
$this->error[$i] = $this->multifeed_objects[$i]->error();
[1709] Fix | Delete
}
[1710] Fix | Delete
$i++;
[1711] Fix | Delete
}
[1712] Fix | Delete
return (bool) $success;
[1713] Fix | Delete
} elseif ($this->feed_url === null && $this->raw_data === null) {
[1714] Fix | Delete
return false;
[1715] Fix | Delete
}
[1716] Fix | Delete
[1717] Fix | Delete
$this->error = null;
[1718] Fix | Delete
$this->data = [];
[1719] Fix | Delete
$this->check_modified = false;
[1720] Fix | Delete
$this->multifeed_objects = [];
[1721] Fix | Delete
$cache = false;
[1722] Fix | Delete
[1723] Fix | Delete
if ($this->feed_url !== null) {
[1724] Fix | Delete
$parsed_feed_url = $this->registry->call(Misc::class, 'parse_url', [$this->feed_url]);
[1725] Fix | Delete
[1726] Fix | Delete
// Decide whether to enable caching
[1727] Fix | Delete
if ($this->enable_cache && $parsed_feed_url['scheme'] !== '') {
[1728] Fix | Delete
$cache = $this->get_cache($this->feed_url);
[1729] Fix | Delete
}
[1730] Fix | Delete
[1731] Fix | Delete
// Fetch the data into $this->raw_data
[1732] Fix | Delete
if (($fetched = $this->fetch_data($cache)) === true) {
[1733] Fix | Delete
return true;
[1734] Fix | Delete
} elseif ($fetched === false) {
[1735] Fix | Delete
return false;
[1736] Fix | Delete
}
[1737] Fix | Delete
[1738] Fix | Delete
[$headers, $sniffed] = $fetched;
[1739] Fix | Delete
}
[1740] Fix | Delete
[1741] Fix | Delete
// Empty response check
[1742] Fix | Delete
if (empty($this->raw_data)) {
[1743] Fix | Delete
$this->error = "A feed could not be found at `$this->feed_url`. Empty body.";
[1744] Fix | Delete
$this->registry->call(Misc::class, 'error', [$this->error, E_USER_NOTICE, __FILE__, __LINE__]);
[1745] Fix | Delete
return false;
[1746] Fix | Delete
}
[1747] Fix | Delete
[1748] Fix | Delete
// Set up array of possible encodings
[1749] Fix | Delete
$encodings = [];
[1750] Fix | Delete
[1751] Fix | Delete
// First check to see if input has been overridden.
[1752] Fix | Delete
if ($this->input_encoding !== false) {
[1753] Fix | Delete
$encodings[] = strtoupper($this->input_encoding);
[1754] Fix | Delete
}
[1755] Fix | Delete
[1756] Fix | Delete
$application_types = ['application/xml', 'application/xml-dtd', 'application/xml-external-parsed-entity'];
[1757] Fix | Delete
$text_types = ['text/xml', 'text/xml-external-parsed-entity'];
[1758] Fix | Delete
[1759] Fix | Delete
// RFC 3023 (only applies to sniffed content)
[1760] Fix | Delete
if (isset($sniffed)) {
[1761] Fix | Delete
if (in_array($sniffed, $application_types) || substr($sniffed, 0, 12) === 'application/' && substr($sniffed, -4) === '+xml') {
[1762] Fix | Delete
if (isset($headers['content-type']) && preg_match('/;\x20?charset=([^;]*)/i', $headers['content-type'], $charset)) {
[1763] Fix | Delete
$encodings[] = strtoupper($charset[1]);
[1764] Fix | Delete
}
[1765] Fix | Delete
$encodings = array_merge($encodings, $this->registry->call(Misc::class, 'xml_encoding', [$this->raw_data, &$this->registry]));
[1766] Fix | Delete
$encodings[] = 'UTF-8';
[1767] Fix | Delete
} elseif (in_array($sniffed, $text_types) || substr($sniffed, 0, 5) === 'text/' && substr($sniffed, -4) === '+xml') {
[1768] Fix | Delete
if (isset($headers['content-type']) && preg_match('/;\x20?charset=([^;]*)/i', $headers['content-type'], $charset)) {
[1769] Fix | Delete
$encodings[] = strtoupper($charset[1]);
[1770] Fix | Delete
}
[1771] Fix | Delete
$encodings[] = 'US-ASCII';
[1772] Fix | Delete
}
[1773] Fix | Delete
// Text MIME-type default
[1774] Fix | Delete
elseif (substr($sniffed, 0, 5) === 'text/') {
[1775] Fix | Delete
$encodings[] = 'UTF-8';
[1776] Fix | Delete
}
[1777] Fix | Delete
}
[1778] Fix | Delete
[1779] Fix | Delete
// Fallback to XML 1.0 Appendix F.1/UTF-8/ISO-8859-1
[1780] Fix | Delete
$encodings = array_merge($encodings, $this->registry->call(Misc::class, 'xml_encoding', [$this->raw_data, &$this->registry]));
[1781] Fix | Delete
$encodings[] = 'UTF-8';
[1782] Fix | Delete
$encodings[] = 'ISO-8859-1';
[1783] Fix | Delete
[1784] Fix | Delete
// There's no point in trying an encoding twice
[1785] Fix | Delete
$encodings = array_unique($encodings);
[1786] Fix | Delete
[1787] Fix | Delete
// Loop through each possible encoding, till we return something, or run out of possibilities
[1788] Fix | Delete
foreach ($encodings as $encoding) {
[1789] Fix | Delete
// Change the encoding to UTF-8 (as we always use UTF-8 internally)
[1790] Fix | Delete
if ($utf8_data = $this->registry->call(Misc::class, 'change_encoding', [$this->raw_data, $encoding, 'UTF-8'])) {
[1791] Fix | Delete
// Create new parser
[1792] Fix | Delete
$parser = $this->registry->create(Parser::class);
[1793] Fix | Delete
[1794] Fix | Delete
// If it's parsed fine
[1795] Fix | Delete
if ($parser->parse($utf8_data, 'UTF-8', $this->permanent_url ?? '')) {
[1796] Fix | Delete
$this->data = $parser->get_data();
[1797] Fix | Delete
if (!($this->get_type() & ~self::TYPE_NONE)) {
[1798] Fix | Delete
$this->error = "A feed could not be found at `$this->feed_url`. This does not appear to be a valid RSS or Atom feed.";
[1799] Fix | Delete
$this->registry->call(Misc::class, 'error', [$this->error, E_USER_NOTICE, __FILE__, __LINE__]);
[1800] Fix | Delete
return false;
[1801] Fix | Delete
}
[1802] Fix | Delete
[1803] Fix | Delete
if (isset($headers)) {
[1804] Fix | Delete
$this->data['headers'] = $headers;
[1805] Fix | Delete
}
[1806] Fix | Delete
$this->data['build'] = Misc::get_build();
[1807] Fix | Delete
[1808] Fix | Delete
// Cache the file if caching is enabled
[1809] Fix | Delete
$this->data['cache_expiration_time'] = $this->cache_duration + time();
[1810] Fix | Delete
[1811] Fix | Delete
if ($cache && !$cache->set_data($this->get_cache_filename($this->feed_url), $this->data, $this->cache_duration)) {
[1812] Fix | Delete
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);
[1813] Fix | Delete
}
[1814] Fix | Delete
return true;
[1815] Fix | Delete
}
[1816] Fix | Delete
}
[1817] Fix | Delete
}
[1818] Fix | Delete
[1819] Fix | Delete
if (isset($parser)) {
[1820] Fix | Delete
// We have an error, just set Misc::error to it and quit
[1821] Fix | Delete
$this->error = $this->feed_url;
[1822] Fix | Delete
$this->error .= sprintf(' is invalid XML, likely due to invalid characters. XML error: %s at line %d, column %d', $parser->get_error_string(), $parser->get_current_line(), $parser->get_current_column());
[1823] Fix | Delete
} else {
[1824] Fix | Delete
$this->error = 'The data could not be converted to UTF-8.';
[1825] Fix | Delete
if (!extension_loaded('mbstring') && !extension_loaded('iconv') && !class_exists('\UConverter')) {
[1826] Fix | Delete
$this->error .= ' You MUST have either the iconv, mbstring or intl (PHP 5.5+) extension installed and enabled.';
[1827] Fix | Delete
} else {
[1828] Fix | Delete
$missingExtensions = [];
[1829] Fix | Delete
if (!extension_loaded('iconv')) {
[1830] Fix | Delete
$missingExtensions[] = 'iconv';
[1831] Fix | Delete
}
[1832] Fix | Delete
if (!extension_loaded('mbstring')) {
[1833] Fix | Delete
$missingExtensions[] = 'mbstring';
[1834] Fix | Delete
}
[1835] Fix | Delete
if (!class_exists('\UConverter')) {
[1836] Fix | Delete
$missingExtensions[] = 'intl (PHP 5.5+)';
[1837] Fix | Delete
}
[1838] Fix | Delete
$this->error .= ' Try installing/enabling the ' . implode(' or ', $missingExtensions) . ' extension.';
[1839] Fix | Delete
}
[1840] Fix | Delete
}
[1841] Fix | Delete
[1842] Fix | Delete
$this->registry->call(Misc::class, 'error', [$this->error, E_USER_NOTICE, __FILE__, __LINE__]);
[1843] Fix | Delete
[1844] Fix | Delete
return false;
[1845] Fix | Delete
}
[1846] Fix | Delete
[1847] Fix | Delete
/**
[1848] Fix | Delete
* Fetch the data
[1849] Fix | Delete
*
[1850] Fix | Delete
* If the data is already cached, attempt to fetch it from there instead
[1851] Fix | Delete
*
[1852] Fix | Delete
* @param Base|DataCache|false $cache Cache handler, or false to not load from the cache
[1853] Fix | Delete
* @return array{array<string, string>, string}|bool Returns true if the data was loaded from the cache, or an array of HTTP headers and sniffed type
[1854] Fix | Delete
*/
[1855] Fix | Delete
protected function fetch_data(&$cache)
[1856] Fix | Delete
{
[1857] Fix | Delete
if ($cache instanceof Base) {
[1858] Fix | Delete
// @trigger_error(sprintf('Providing $cache as "\SimplePie\Cache\Base" in %s() is deprecated since SimplePie 1.8.0, please provide "\SimplePie\Cache\DataCache" implementation instead.', __METHOD__), \E_USER_DEPRECATED);
[1859] Fix | Delete
$cache = new BaseDataCache($cache);
[1860] Fix | Delete
}
[1861] Fix | Delete
[1862] Fix | Delete
// @phpstan-ignore-next-line Enforce PHPDoc type.
[1863] Fix | Delete
if ($cache !== false && !$cache instanceof DataCache) {
[1864] Fix | Delete
throw new InvalidArgumentException(sprintf(
[1865] Fix | Delete
'%s(): Argument #1 ($cache) must be of type %s|false',
[1866] Fix | Delete
__METHOD__,
[1867] Fix | Delete
DataCache::class
[1868] Fix | Delete
), 1);
[1869] Fix | Delete
}
[1870] Fix | Delete
[1871] Fix | Delete
$cacheKey = $this->get_cache_filename($this->feed_url);
[1872] Fix | Delete
[1873] Fix | Delete
// If it's enabled, use the cache
[1874] Fix | Delete
if ($cache) {
[1875] Fix | Delete
// Load the Cache
[1876] Fix | Delete
$this->data = $cache->get_data($cacheKey, []);
[1877] Fix | Delete
[1878] Fix | Delete
if (!empty($this->data)) {
[1879] Fix | Delete
// If the cache is for an outdated build of SimplePie
[1880] Fix | Delete
if (!isset($this->data['build']) || $this->data['build'] !== Misc::get_build()) {
[1881] Fix | Delete
$cache->delete_data($cacheKey);
[1882] Fix | Delete
$this->data = [];
[1883] Fix | Delete
}
[1884] Fix | Delete
// If we've hit a collision just rerun it with caching disabled
[1885] Fix | Delete
elseif (isset($this->data['url']) && $this->data['url'] !== $this->feed_url) {
[1886] Fix | Delete
$cache = false;
[1887] Fix | Delete
$this->data = [];
[1888] Fix | Delete
}
[1889] Fix | Delete
// If we've got a non feed_url stored (if the page isn't actually a feed, or is a redirect) use that URL.
[1890] Fix | Delete
elseif (isset($this->data['feed_url'])) {
[1891] Fix | Delete
// Do not need to do feed autodiscovery yet.
[1892] Fix | Delete
if ($this->data['feed_url'] !== $this->data['url']) {
[1893] Fix | Delete
$this->set_feed_url($this->data['feed_url']);
[1894] Fix | Delete
$this->data['url'] = $this->data['feed_url'];
[1895] Fix | Delete
[1896] Fix | Delete
$cache->set_data($this->get_cache_filename($this->feed_url), $this->data, $this->autodiscovery_cache_duration);
[1897] Fix | Delete
[1898] Fix | Delete
return $this->init();
[1899] Fix | Delete
}
[1900] Fix | Delete
[1901] Fix | Delete
$cache->delete_data($this->get_cache_filename($this->feed_url));
[1902] Fix | Delete
$this->data = [];
[1903] Fix | Delete
}
[1904] Fix | Delete
// Check if the cache has been updated
[1905] Fix | Delete
elseif (!isset($this->data['cache_expiration_time']) || $this->data['cache_expiration_time'] < time()) {
[1906] Fix | Delete
// Want to know if we tried to send last-modified and/or etag headers
[1907] Fix | Delete
// when requesting this file. (Note that it's up to the file to
[1908] Fix | Delete
// support this, but we don't always send the headers either.)
[1909] Fix | Delete
$this->check_modified = true;
[1910] Fix | Delete
if (isset($this->data['headers']['last-modified']) || isset($this->data['headers']['etag'])) {
[1911] Fix | Delete
$headers = [
[1912] Fix | Delete
'Accept' => SimplePie::DEFAULT_HTTP_ACCEPT_HEADER,
[1913] Fix | Delete
];
[1914] Fix | Delete
if (isset($this->data['headers']['last-modified'])) {
[1915] Fix | Delete
$headers['if-modified-since'] = $this->data['headers']['last-modified'];
[1916] Fix | Delete
}
[1917] Fix | Delete
if (isset($this->data['headers']['etag'])) {
[1918] Fix | Delete
$headers['if-none-match'] = $this->data['headers']['etag'];
[1919] Fix | Delete
}
[1920] Fix | Delete
[1921] Fix | Delete
try {
[1922] Fix | Delete
$file = $this->get_http_client()->request(Client::METHOD_GET, $this->feed_url, $headers);
[1923] Fix | Delete
$this->status_code = $file->get_status_code();
[1924] Fix | Delete
} catch (ClientException $th) {
[1925] Fix | Delete
$this->check_modified = false;
[1926] Fix | Delete
$this->status_code = 0;
[1927] Fix | Delete
[1928] Fix | Delete
if ($this->force_cache_fallback) {
[1929] Fix | Delete
$this->data['cache_expiration_time'] = $this->cache_duration + time();
[1930] Fix | Delete
$cache->set_data($cacheKey, $this->data, $this->cache_duration);
[1931] Fix | Delete
[1932] Fix | Delete
return true;
[1933] Fix | Delete
}
[1934] Fix | Delete
[1935] Fix | Delete
$failedFileReason = $th->getMessage();
[1936] Fix | Delete
}
[1937] Fix | Delete
[1938] Fix | Delete
if ($this->status_code === 304) {
[1939] Fix | Delete
// Set raw_data to false here too, to signify that the cache
[1940] Fix | Delete
// is still valid.
[1941] Fix | Delete
$this->raw_data = false;
[1942] Fix | Delete
$this->data['cache_expiration_time'] = $this->cache_duration + time();
[1943] Fix | Delete
$cache->set_data($cacheKey, $this->data, $this->cache_duration);
[1944] Fix | Delete
[1945] Fix | Delete
return true;
[1946] Fix | Delete
}
[1947] Fix | Delete
}
[1948] Fix | Delete
}
[1949] Fix | Delete
// If the cache is still valid, just return true
[1950] Fix | Delete
else {
[1951] Fix | Delete
$this->raw_data = false;
[1952] Fix | Delete
return true;
[1953] Fix | Delete
}
[1954] Fix | Delete
}
[1955] Fix | Delete
// If the cache is empty
[1956] Fix | Delete
else {
[1957] Fix | Delete
$this->data = [];
[1958] Fix | Delete
}
[1959] Fix | Delete
}
[1960] Fix | Delete
[1961] Fix | Delete
// If we don't already have the file (it'll only exist if we've opened it to check if the cache has been modified), open it.
[1962] Fix | Delete
if (!isset($file)) {
[1963] Fix | Delete
if ($this->file instanceof File && $this->file->get_final_requested_uri() === $this->feed_url) {
[1964] Fix | Delete
$file = &$this->file;
[1965] Fix | Delete
} elseif (isset($failedFileReason)) {
[1966] Fix | Delete
// Do not try to fetch again if we already failed once.
[1967] Fix | Delete
// If the file connection had an error, set SimplePie::error to that and quit
[1968] Fix | Delete
$this->error = $failedFileReason;
[1969] Fix | Delete
[1970] Fix | Delete
return !empty($this->data);
[1971] Fix | Delete
} else {
[1972] Fix | Delete
$headers = [
[1973] Fix | Delete
'Accept' => SimplePie::DEFAULT_HTTP_ACCEPT_HEADER,
[1974] Fix | Delete
];
[1975] Fix | Delete
try {
[1976] Fix | Delete
$file = $this->get_http_client()->request(Client::METHOD_GET, $this->feed_url, $headers);
[1977] Fix | Delete
} catch (ClientException $th) {
[1978] Fix | Delete
// If the file connection has an error, set SimplePie::error to that and quit
[1979] Fix | Delete
$this->error = $th->getMessage();
[1980] Fix | Delete
[1981] Fix | Delete
return !empty($this->data);
[1982] Fix | Delete
}
[1983] Fix | Delete
}
[1984] Fix | Delete
}
[1985] Fix | Delete
$this->status_code = $file->get_status_code();
[1986] Fix | Delete
[1987] Fix | Delete
// If the file connection has an error, set SimplePie::error to that and quit
[1988] Fix | Delete
if (!(!Misc::is_remote_uri($file->get_final_requested_uri()) || ($file->get_status_code() === 200 || $file->get_status_code() > 206 && $file->get_status_code() < 300))) {
[1989] Fix | Delete
$this->error = 'Retrieved unsupported status code "' . $this->status_code . '"';
[1990] Fix | Delete
return !empty($this->data);
[1991] Fix | Delete
}
[1992] Fix | Delete
[1993] Fix | Delete
if (!$this->force_feed) {
[1994] Fix | Delete
// Check if the supplied URL is a feed, if it isn't, look for it.
[1995] Fix | Delete
$locate = $this->registry->create(Locator::class, [
[1996] Fix | Delete
(!$file instanceof File) ? File::fromResponse($file) : $file,
[1997] Fix | Delete
$this->timeout,
[1998] Fix | Delete
$this->useragent,
[1999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function