Edit File by line
/home/zeestwma/richards.../wp-inclu.../SimplePi.../src
File: SimplePie.php
$this->enable_exceptions = $enable;
[1500] Fix | Delete
}
[1501] Fix | Delete
[1502] Fix | Delete
/**
[1503] Fix | Delete
* Initialize the feed object
[1504] Fix | Delete
*
[1505] Fix | Delete
* This is what makes everything happen. Period. This is where all of the
[1506] Fix | Delete
* configuration options get processed, feeds are fetched, cached, and
[1507] Fix | Delete
* parsed, and all of that other good stuff.
[1508] Fix | Delete
*
[1509] Fix | Delete
* @return boolean True if successful, false otherwise
[1510] Fix | Delete
*/
[1511] Fix | Delete
public function init()
[1512] Fix | Delete
{
[1513] Fix | Delete
// Check absolute bare minimum requirements.
[1514] Fix | Delete
if (!extension_loaded('xml') || !extension_loaded('pcre')) {
[1515] Fix | Delete
$this->error = 'XML or PCRE extensions not loaded!';
[1516] Fix | Delete
return false;
[1517] Fix | Delete
}
[1518] 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.
[1519] Fix | Delete
elseif (!extension_loaded('xmlreader')) {
[1520] Fix | Delete
static $xml_is_sane = null;
[1521] Fix | Delete
if ($xml_is_sane === null) {
[1522] Fix | Delete
$parser_check = xml_parser_create();
[1523] Fix | Delete
xml_parse_into_struct($parser_check, '<foo>&amp;</foo>', $values);
[1524] Fix | Delete
xml_parser_free($parser_check);
[1525] Fix | Delete
$xml_is_sane = isset($values[0]['value']);
[1526] Fix | Delete
}
[1527] Fix | Delete
if (!$xml_is_sane) {
[1528] Fix | Delete
return false;
[1529] Fix | Delete
}
[1530] Fix | Delete
}
[1531] Fix | Delete
[1532] Fix | Delete
// The default sanitize class gets set in the constructor, check if it has
[1533] Fix | Delete
// changed.
[1534] Fix | Delete
if ($this->registry->get_class(Sanitize::class) !== 'SimplePie\Sanitize') {
[1535] Fix | Delete
$this->sanitize = $this->registry->create(Sanitize::class);
[1536] Fix | Delete
}
[1537] Fix | Delete
if (method_exists($this->sanitize, 'set_registry')) {
[1538] Fix | Delete
$this->sanitize->set_registry($this->registry);
[1539] Fix | Delete
}
[1540] Fix | Delete
[1541] Fix | Delete
// Pass whatever was set with config options over to the sanitizer.
[1542] Fix | Delete
// Pass the classes in for legacy support; new classes should use the registry instead
[1543] Fix | Delete
$this->sanitize->pass_cache_data(
[1544] Fix | Delete
$this->enable_cache,
[1545] Fix | Delete
$this->cache_location,
[1546] Fix | Delete
$this->cache_namefilter,
[1547] Fix | Delete
$this->registry->get_class(Cache::class),
[1548] Fix | Delete
$this->cache
[1549] Fix | Delete
);
[1550] Fix | Delete
$this->sanitize->pass_file_data($this->registry->get_class(File::class), $this->timeout, $this->useragent, $this->force_fsockopen, $this->curl_options);
[1551] Fix | Delete
[1552] Fix | Delete
if (!empty($this->multifeed_url)) {
[1553] Fix | Delete
$i = 0;
[1554] Fix | Delete
$success = 0;
[1555] Fix | Delete
$this->multifeed_objects = [];
[1556] Fix | Delete
$this->error = [];
[1557] Fix | Delete
foreach ($this->multifeed_url as $url) {
[1558] Fix | Delete
$this->multifeed_objects[$i] = clone $this;
[1559] Fix | Delete
$this->multifeed_objects[$i]->set_feed_url($url);
[1560] Fix | Delete
$single_success = $this->multifeed_objects[$i]->init();
[1561] Fix | Delete
$success |= $single_success;
[1562] Fix | Delete
if (!$single_success) {
[1563] Fix | Delete
$this->error[$i] = $this->multifeed_objects[$i]->error();
[1564] Fix | Delete
}
[1565] Fix | Delete
$i++;
[1566] Fix | Delete
}
[1567] Fix | Delete
return (bool) $success;
[1568] Fix | Delete
} elseif ($this->feed_url === null && $this->raw_data === null) {
[1569] Fix | Delete
return false;
[1570] Fix | Delete
}
[1571] Fix | Delete
[1572] Fix | Delete
$this->error = null;
[1573] Fix | Delete
$this->data = [];
[1574] Fix | Delete
$this->check_modified = false;
[1575] Fix | Delete
$this->multifeed_objects = [];
[1576] Fix | Delete
$cache = false;
[1577] Fix | Delete
[1578] Fix | Delete
if ($this->feed_url !== null) {
[1579] Fix | Delete
$parsed_feed_url = $this->registry->call(Misc::class, 'parse_url', [$this->feed_url]);
[1580] Fix | Delete
[1581] Fix | Delete
// Decide whether to enable caching
[1582] Fix | Delete
if ($this->enable_cache && $parsed_feed_url['scheme'] !== '') {
[1583] Fix | Delete
$cache = $this->get_cache($this->feed_url);
[1584] Fix | Delete
}
[1585] Fix | Delete
[1586] Fix | Delete
// Fetch the data via \SimplePie\File into $this->raw_data
[1587] Fix | Delete
if (($fetched = $this->fetch_data($cache)) === true) {
[1588] Fix | Delete
return true;
[1589] Fix | Delete
} elseif ($fetched === false) {
[1590] Fix | Delete
return false;
[1591] Fix | Delete
}
[1592] Fix | Delete
[1593] Fix | Delete
[$headers, $sniffed] = $fetched;
[1594] Fix | Delete
}
[1595] Fix | Delete
[1596] Fix | Delete
// Empty response check
[1597] Fix | Delete
if (empty($this->raw_data)) {
[1598] Fix | Delete
$this->error = "A feed could not be found at `$this->feed_url`. Empty body.";
[1599] Fix | Delete
$this->registry->call(Misc::class, 'error', [$this->error, E_USER_NOTICE, __FILE__, __LINE__]);
[1600] Fix | Delete
return false;
[1601] Fix | Delete
}
[1602] Fix | Delete
[1603] Fix | Delete
// Set up array of possible encodings
[1604] Fix | Delete
$encodings = [];
[1605] Fix | Delete
[1606] Fix | Delete
// First check to see if input has been overridden.
[1607] Fix | Delete
if ($this->input_encoding !== false) {
[1608] Fix | Delete
$encodings[] = strtoupper($this->input_encoding);
[1609] Fix | Delete
}
[1610] Fix | Delete
[1611] Fix | Delete
$application_types = ['application/xml', 'application/xml-dtd', 'application/xml-external-parsed-entity'];
[1612] Fix | Delete
$text_types = ['text/xml', 'text/xml-external-parsed-entity'];
[1613] Fix | Delete
[1614] Fix | Delete
// RFC 3023 (only applies to sniffed content)
[1615] Fix | Delete
if (isset($sniffed)) {
[1616] Fix | Delete
if (in_array($sniffed, $application_types) || substr($sniffed, 0, 12) === 'application/' && substr($sniffed, -4) === '+xml') {
[1617] Fix | Delete
if (isset($headers['content-type']) && preg_match('/;\x20?charset=([^;]*)/i', $headers['content-type'], $charset)) {
[1618] Fix | Delete
$encodings[] = strtoupper($charset[1]);
[1619] Fix | Delete
}
[1620] Fix | Delete
$encodings = array_merge($encodings, $this->registry->call(Misc::class, 'xml_encoding', [$this->raw_data, &$this->registry]));
[1621] Fix | Delete
$encodings[] = 'UTF-8';
[1622] Fix | Delete
} elseif (in_array($sniffed, $text_types) || substr($sniffed, 0, 5) === 'text/' && substr($sniffed, -4) === '+xml') {
[1623] Fix | Delete
if (isset($headers['content-type']) && preg_match('/;\x20?charset=([^;]*)/i', $headers['content-type'], $charset)) {
[1624] Fix | Delete
$encodings[] = strtoupper($charset[1]);
[1625] Fix | Delete
}
[1626] Fix | Delete
$encodings[] = 'US-ASCII';
[1627] Fix | Delete
}
[1628] Fix | Delete
// Text MIME-type default
[1629] Fix | Delete
elseif (substr($sniffed, 0, 5) === 'text/') {
[1630] Fix | Delete
$encodings[] = 'UTF-8';
[1631] Fix | Delete
}
[1632] Fix | Delete
}
[1633] Fix | Delete
[1634] Fix | Delete
// Fallback to XML 1.0 Appendix F.1/UTF-8/ISO-8859-1
[1635] Fix | Delete
$encodings = array_merge($encodings, $this->registry->call(Misc::class, 'xml_encoding', [$this->raw_data, &$this->registry]));
[1636] Fix | Delete
$encodings[] = 'UTF-8';
[1637] Fix | Delete
$encodings[] = 'ISO-8859-1';
[1638] Fix | Delete
[1639] Fix | Delete
// There's no point in trying an encoding twice
[1640] Fix | Delete
$encodings = array_unique($encodings);
[1641] Fix | Delete
[1642] Fix | Delete
// Loop through each possible encoding, till we return something, or run out of possibilities
[1643] Fix | Delete
foreach ($encodings as $encoding) {
[1644] Fix | Delete
// Change the encoding to UTF-8 (as we always use UTF-8 internally)
[1645] Fix | Delete
if ($utf8_data = $this->registry->call(Misc::class, 'change_encoding', [$this->raw_data, $encoding, 'UTF-8'])) {
[1646] Fix | Delete
// Create new parser
[1647] Fix | Delete
$parser = $this->registry->create(Parser::class);
[1648] Fix | Delete
[1649] Fix | Delete
// If it's parsed fine
[1650] Fix | Delete
if ($parser->parse($utf8_data, 'UTF-8', $this->permanent_url)) {
[1651] Fix | Delete
$this->data = $parser->get_data();
[1652] Fix | Delete
if (!($this->get_type() & ~self::TYPE_NONE)) {
[1653] 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.";
[1654] Fix | Delete
$this->registry->call(Misc::class, 'error', [$this->error, E_USER_NOTICE, __FILE__, __LINE__]);
[1655] Fix | Delete
return false;
[1656] Fix | Delete
}
[1657] Fix | Delete
[1658] Fix | Delete
if (isset($headers)) {
[1659] Fix | Delete
$this->data['headers'] = $headers;
[1660] Fix | Delete
}
[1661] Fix | Delete
$this->data['build'] = \SimplePie\Misc::get_build();
[1662] Fix | Delete
[1663] Fix | Delete
// Cache the file if caching is enabled
[1664] Fix | Delete
$this->data['cache_expiration_time'] = $this->cache_duration + time();
[1665] Fix | Delete
if ($cache && !$cache->set_data($this->get_cache_filename($this->feed_url), $this->data, $this->cache_duration)) {
[1666] 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);
[1667] Fix | Delete
}
[1668] Fix | Delete
return true;
[1669] Fix | Delete
}
[1670] Fix | Delete
}
[1671] Fix | Delete
}
[1672] Fix | Delete
[1673] Fix | Delete
if (isset($parser)) {
[1674] Fix | Delete
// We have an error, just set \SimplePie\Misc::error to it and quit
[1675] Fix | Delete
$this->error = $this->feed_url;
[1676] 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());
[1677] Fix | Delete
} else {
[1678] Fix | Delete
$this->error = 'The data could not be converted to UTF-8.';
[1679] Fix | Delete
if (!extension_loaded('mbstring') && !extension_loaded('iconv') && !class_exists('\UConverter')) {
[1680] Fix | Delete
$this->error .= ' You MUST have either the iconv, mbstring or intl (PHP 5.5+) extension installed and enabled.';
[1681] Fix | Delete
} else {
[1682] Fix | Delete
$missingExtensions = [];
[1683] Fix | Delete
if (!extension_loaded('iconv')) {
[1684] Fix | Delete
$missingExtensions[] = 'iconv';
[1685] Fix | Delete
}
[1686] Fix | Delete
if (!extension_loaded('mbstring')) {
[1687] Fix | Delete
$missingExtensions[] = 'mbstring';
[1688] Fix | Delete
}
[1689] Fix | Delete
if (!class_exists('\UConverter')) {
[1690] Fix | Delete
$missingExtensions[] = 'intl (PHP 5.5+)';
[1691] Fix | Delete
}
[1692] Fix | Delete
$this->error .= ' Try installing/enabling the ' . implode(' or ', $missingExtensions) . ' extension.';
[1693] Fix | Delete
}
[1694] Fix | Delete
}
[1695] Fix | Delete
[1696] Fix | Delete
$this->registry->call(Misc::class, 'error', [$this->error, E_USER_NOTICE, __FILE__, __LINE__]);
[1697] Fix | Delete
[1698] Fix | Delete
return false;
[1699] Fix | Delete
}
[1700] Fix | Delete
[1701] Fix | Delete
/**
[1702] Fix | Delete
* Fetch the data via \SimplePie\File
[1703] Fix | Delete
*
[1704] Fix | Delete
* If the data is already cached, attempt to fetch it from there instead
[1705] Fix | Delete
* @param Base|DataCache|false $cache Cache handler, or false to not load from the cache
[1706] Fix | Delete
* @return array|true Returns true if the data was loaded from the cache, or an array of HTTP headers and sniffed type
[1707] Fix | Delete
*/
[1708] Fix | Delete
protected function fetch_data(&$cache)
[1709] Fix | Delete
{
[1710] Fix | Delete
if (is_object($cache) && $cache instanceof Base) {
[1711] 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);
[1712] Fix | Delete
$cache = new BaseDataCache($cache);
[1713] Fix | Delete
}
[1714] Fix | Delete
[1715] Fix | Delete
if ($cache !== false && !$cache instanceof DataCache) {
[1716] Fix | Delete
throw new InvalidArgumentException(sprintf(
[1717] Fix | Delete
'%s(): Argument #1 ($cache) must be of type %s|false',
[1718] Fix | Delete
__METHOD__,
[1719] Fix | Delete
DataCache::class
[1720] Fix | Delete
), 1);
[1721] Fix | Delete
}
[1722] Fix | Delete
[1723] Fix | Delete
$cacheKey = $this->get_cache_filename($this->feed_url);
[1724] Fix | Delete
[1725] Fix | Delete
// If it's enabled, use the cache
[1726] Fix | Delete
if ($cache) {
[1727] Fix | Delete
// Load the Cache
[1728] Fix | Delete
$this->data = $cache->get_data($cacheKey, []);
[1729] Fix | Delete
[1730] Fix | Delete
if (!empty($this->data)) {
[1731] Fix | Delete
// If the cache is for an outdated build of SimplePie
[1732] Fix | Delete
if (!isset($this->data['build']) || $this->data['build'] !== \SimplePie\Misc::get_build()) {
[1733] Fix | Delete
$cache->delete_data($cacheKey);
[1734] Fix | Delete
$this->data = [];
[1735] Fix | Delete
}
[1736] Fix | Delete
// If we've hit a collision just rerun it with caching disabled
[1737] Fix | Delete
elseif (isset($this->data['url']) && $this->data['url'] !== $this->feed_url) {
[1738] Fix | Delete
$cache = false;
[1739] Fix | Delete
$this->data = [];
[1740] Fix | Delete
}
[1741] 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.
[1742] Fix | Delete
elseif (isset($this->data['feed_url'])) {
[1743] Fix | Delete
// Do not need to do feed autodiscovery yet.
[1744] Fix | Delete
if ($this->data['feed_url'] !== $this->data['url']) {
[1745] Fix | Delete
$this->set_feed_url($this->data['feed_url']);
[1746] Fix | Delete
$this->data['url'] = $this->data['feed_url'];
[1747] Fix | Delete
[1748] Fix | Delete
$cache->set_data($this->get_cache_filename($this->feed_url), $this->data, $this->autodiscovery_cache_duration);
[1749] Fix | Delete
[1750] Fix | Delete
return $this->init();
[1751] Fix | Delete
}
[1752] Fix | Delete
[1753] Fix | Delete
$cache->delete_data($this->get_cache_filename($this->feed_url));
[1754] Fix | Delete
$this->data = [];
[1755] Fix | Delete
}
[1756] Fix | Delete
// Check if the cache has been updated
[1757] Fix | Delete
elseif (isset($this->data['cache_expiration_time']) && $this->data['cache_expiration_time'] > time()) {
[1758] Fix | Delete
// Want to know if we tried to send last-modified and/or etag headers
[1759] Fix | Delete
// when requesting this file. (Note that it's up to the file to
[1760] Fix | Delete
// support this, but we don't always send the headers either.)
[1761] Fix | Delete
$this->check_modified = true;
[1762] Fix | Delete
if (isset($this->data['headers']['last-modified']) || isset($this->data['headers']['etag'])) {
[1763] Fix | Delete
$headers = [
[1764] Fix | Delete
'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',
[1765] Fix | Delete
];
[1766] Fix | Delete
if (isset($this->data['headers']['last-modified'])) {
[1767] Fix | Delete
$headers['if-modified-since'] = $this->data['headers']['last-modified'];
[1768] Fix | Delete
}
[1769] Fix | Delete
if (isset($this->data['headers']['etag'])) {
[1770] Fix | Delete
$headers['if-none-match'] = $this->data['headers']['etag'];
[1771] Fix | Delete
}
[1772] Fix | Delete
[1773] Fix | Delete
$file = $this->registry->create(File::class, [$this->feed_url, $this->timeout / 10, 5, $headers, $this->useragent, $this->force_fsockopen, $this->curl_options]);
[1774] Fix | Delete
$this->status_code = $file->status_code;
[1775] Fix | Delete
[1776] Fix | Delete
if ($file->success) {
[1777] Fix | Delete
if ($file->status_code === 304) {
[1778] Fix | Delete
// Set raw_data to false here too, to signify that the cache
[1779] Fix | Delete
// is still valid.
[1780] Fix | Delete
$this->raw_data = false;
[1781] Fix | Delete
$cache->set_data($cacheKey, $this->data, $this->cache_duration);
[1782] Fix | Delete
return true;
[1783] Fix | Delete
}
[1784] Fix | Delete
} else {
[1785] Fix | Delete
$this->check_modified = false;
[1786] Fix | Delete
if ($this->force_cache_fallback) {
[1787] Fix | Delete
$cache->set_data($cacheKey, $this->data, $this->cache_duration);
[1788] Fix | Delete
return true;
[1789] Fix | Delete
}
[1790] Fix | Delete
[1791] Fix | Delete
unset($file);
[1792] Fix | Delete
}
[1793] Fix | Delete
}
[1794] Fix | Delete
}
[1795] Fix | Delete
// If the cache is still valid, just return true
[1796] Fix | Delete
else {
[1797] Fix | Delete
$this->raw_data = false;
[1798] Fix | Delete
return true;
[1799] Fix | Delete
}
[1800] Fix | Delete
}
[1801] Fix | Delete
// If the cache is empty
[1802] Fix | Delete
else {
[1803] Fix | Delete
$this->data = [];
[1804] Fix | Delete
}
[1805] Fix | Delete
}
[1806] Fix | Delete
[1807] 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.
[1808] Fix | Delete
if (!isset($file)) {
[1809] Fix | Delete
if ($this->file instanceof \SimplePie\File && $this->file->url === $this->feed_url) {
[1810] Fix | Delete
$file = &$this->file;
[1811] Fix | Delete
} else {
[1812] Fix | Delete
$headers = [
[1813] Fix | Delete
'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',
[1814] Fix | Delete
];
[1815] Fix | Delete
$file = $this->registry->create(File::class, [$this->feed_url, $this->timeout, 5, $headers, $this->useragent, $this->force_fsockopen, $this->curl_options]);
[1816] Fix | Delete
}
[1817] Fix | Delete
}
[1818] Fix | Delete
$this->status_code = $file->status_code;
[1819] Fix | Delete
[1820] Fix | Delete
// If the file connection has an error, set SimplePie::error to that and quit
[1821] Fix | Delete
if (!$file->success && !($file->method & self::FILE_SOURCE_REMOTE === 0 || ($file->status_code === 200 || $file->status_code > 206 && $file->status_code < 300))) {
[1822] Fix | Delete
$this->error = $file->error;
[1823] Fix | Delete
return !empty($this->data);
[1824] Fix | Delete
}
[1825] Fix | Delete
[1826] Fix | Delete
if (!$this->force_feed) {
[1827] Fix | Delete
// Check if the supplied URL is a feed, if it isn't, look for it.
[1828] Fix | Delete
$locate = $this->registry->create(Locator::class, [&$file, $this->timeout, $this->useragent, $this->max_checked_feeds, $this->force_fsockopen, $this->curl_options]);
[1829] Fix | Delete
[1830] Fix | Delete
if (!$locate->is_feed($file)) {
[1831] Fix | Delete
$copyStatusCode = $file->status_code;
[1832] Fix | Delete
$copyContentType = $file->headers['content-type'];
[1833] Fix | Delete
try {
[1834] Fix | Delete
$microformats = false;
[1835] Fix | Delete
if (class_exists('DOMXpath') && function_exists('Mf2\parse')) {
[1836] Fix | Delete
$doc = new \DOMDocument();
[1837] Fix | Delete
@$doc->loadHTML($file->body);
[1838] Fix | Delete
$xpath = new \DOMXpath($doc);
[1839] Fix | Delete
// Check for both h-feed and h-entry, as both a feed with no entries
[1840] Fix | Delete
// and a list of entries without an h-feed wrapper are both valid.
[1841] Fix | Delete
$query = '//*[contains(concat(" ", @class, " "), " h-feed ") or '.
[1842] Fix | Delete
'contains(concat(" ", @class, " "), " h-entry ")]';
[1843] Fix | Delete
$result = $xpath->query($query);
[1844] Fix | Delete
$microformats = $result->length !== 0;
[1845] Fix | Delete
}
[1846] Fix | Delete
// Now also do feed discovery, but if microformats were found don't
[1847] Fix | Delete
// overwrite the current value of file.
[1848] Fix | Delete
$discovered = $locate->find(
[1849] Fix | Delete
$this->autodiscovery,
[1850] Fix | Delete
$this->all_discovered_feeds
[1851] Fix | Delete
);
[1852] Fix | Delete
if ($microformats) {
[1853] Fix | Delete
if ($hub = $locate->get_rel_link('hub')) {
[1854] Fix | Delete
$self = $locate->get_rel_link('self');
[1855] Fix | Delete
$this->store_links($file, $hub, $self);
[1856] Fix | Delete
}
[1857] Fix | Delete
// Push the current file onto all_discovered feeds so the user can
[1858] Fix | Delete
// be shown this as one of the options.
[1859] Fix | Delete
if (isset($this->all_discovered_feeds)) {
[1860] Fix | Delete
$this->all_discovered_feeds[] = $file;
[1861] Fix | Delete
}
[1862] Fix | Delete
} else {
[1863] Fix | Delete
if ($discovered) {
[1864] Fix | Delete
$file = $discovered;
[1865] Fix | Delete
} else {
[1866] Fix | Delete
// We need to unset this so that if SimplePie::set_file() has
[1867] Fix | Delete
// been called that object is untouched
[1868] Fix | Delete
unset($file);
[1869] Fix | Delete
$this->error = "A feed could not be found at `$this->feed_url`; the status code is `$copyStatusCode` and content-type is `$copyContentType`";
[1870] Fix | Delete
$this->registry->call(Misc::class, 'error', [$this->error, E_USER_NOTICE, __FILE__, __LINE__]);
[1871] Fix | Delete
return false;
[1872] Fix | Delete
}
[1873] Fix | Delete
}
[1874] Fix | Delete
} catch (\SimplePie\Exception $e) {
[1875] Fix | Delete
// We need to unset this so that if SimplePie::set_file() has been called that object is untouched
[1876] Fix | Delete
unset($file);
[1877] Fix | Delete
// This is usually because DOMDocument doesn't exist
[1878] Fix | Delete
$this->error = $e->getMessage();
[1879] Fix | Delete
$this->registry->call(Misc::class, 'error', [$this->error, E_USER_NOTICE, $e->getFile(), $e->getLine()]);
[1880] Fix | Delete
return false;
[1881] Fix | Delete
}
[1882] Fix | Delete
[1883] Fix | Delete
if ($cache) {
[1884] Fix | Delete
$this->data = [
[1885] Fix | Delete
'url' => $this->feed_url,
[1886] Fix | Delete
'feed_url' => $file->url,
[1887] Fix | Delete
'build' => \SimplePie\Misc::get_build(),
[1888] Fix | Delete
'cache_expiration_time' => $this->cache_duration + time(),
[1889] Fix | Delete
];
[1890] Fix | Delete
[1891] Fix | Delete
if (!$cache->set_data($cacheKey, $this->data, $this->cache_duration)) {
[1892] 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);
[1893] Fix | Delete
}
[1894] Fix | Delete
}
[1895] Fix | Delete
}
[1896] Fix | Delete
$this->feed_url = $file->url;
[1897] Fix | Delete
$locate = null;
[1898] Fix | Delete
}
[1899] Fix | Delete
[1900] Fix | Delete
$this->raw_data = $file->body;
[1901] Fix | Delete
$this->permanent_url = $file->permanent_url;
[1902] Fix | Delete
$headers = $file->headers;
[1903] Fix | Delete
$sniffer = $this->registry->create(Sniffer::class, [&$file]);
[1904] Fix | Delete
$sniffed = $sniffer->get_type();
[1905] Fix | Delete
[1906] Fix | Delete
return [$headers, $sniffed];
[1907] Fix | Delete
}
[1908] Fix | Delete
[1909] Fix | Delete
/**
[1910] Fix | Delete
* Get the error message for the occurred error
[1911] Fix | Delete
*
[1912] Fix | Delete
* @return string|array Error message, or array of messages for multifeeds
[1913] Fix | Delete
*/
[1914] Fix | Delete
public function error()
[1915] Fix | Delete
{
[1916] Fix | Delete
return $this->error;
[1917] Fix | Delete
}
[1918] Fix | Delete
[1919] Fix | Delete
/**
[1920] Fix | Delete
* Get the last HTTP status code
[1921] Fix | Delete
*
[1922] Fix | Delete
* @return int Status code
[1923] Fix | Delete
*/
[1924] Fix | Delete
public function status_code()
[1925] Fix | Delete
{
[1926] Fix | Delete
return $this->status_code;
[1927] Fix | Delete
}
[1928] Fix | Delete
[1929] Fix | Delete
/**
[1930] Fix | Delete
* Get the raw XML
[1931] Fix | Delete
*
[1932] Fix | Delete
* This is the same as the old `$feed->enable_xml_dump(true)`, but returns
[1933] Fix | Delete
* the data instead of printing it.
[1934] Fix | Delete
*
[1935] Fix | Delete
* @return string|boolean Raw XML data, false if the cache is used
[1936] Fix | Delete
*/
[1937] Fix | Delete
public function get_raw_data()
[1938] Fix | Delete
{
[1939] Fix | Delete
return $this->raw_data;
[1940] Fix | Delete
}
[1941] Fix | Delete
[1942] Fix | Delete
/**
[1943] Fix | Delete
* Get the character encoding used for output
[1944] Fix | Delete
*
[1945] Fix | Delete
* @since Preview Release
[1946] Fix | Delete
* @return string
[1947] Fix | Delete
*/
[1948] Fix | Delete
public function get_encoding()
[1949] Fix | Delete
{
[1950] Fix | Delete
return $this->sanitize->output_encoding;
[1951] Fix | Delete
}
[1952] Fix | Delete
[1953] Fix | Delete
/**
[1954] Fix | Delete
* Send the content-type header with correct encoding
[1955] Fix | Delete
*
[1956] Fix | Delete
* This method ensures that the SimplePie-enabled page is being served with
[1957] Fix | Delete
* the correct {@link http://www.iana.org/assignments/media-types/ mime-type}
[1958] Fix | Delete
* and character encoding HTTP headers (character encoding determined by the
[1959] Fix | Delete
* {@see set_output_encoding} config option).
[1960] Fix | Delete
*
[1961] Fix | Delete
* This won't work properly if any content or whitespace has already been
[1962] Fix | Delete
* sent to the browser, because it relies on PHP's
[1963] Fix | Delete
* {@link http://php.net/header header()} function, and these are the
[1964] Fix | Delete
* circumstances under which the function works.
[1965] Fix | Delete
*
[1966] Fix | Delete
* Because it's setting these settings for the entire page (as is the nature
[1967] Fix | Delete
* of HTTP headers), this should only be used once per page (again, at the
[1968] Fix | Delete
* top).
[1969] Fix | Delete
*
[1970] Fix | Delete
* @param string $mime MIME type to serve the page as
[1971] Fix | Delete
*/
[1972] Fix | Delete
public function handle_content_type($mime = 'text/html')
[1973] Fix | Delete
{
[1974] Fix | Delete
if (!headers_sent()) {
[1975] Fix | Delete
$header = "Content-type: $mime;";
[1976] Fix | Delete
if ($this->get_encoding()) {
[1977] Fix | Delete
$header .= ' charset=' . $this->get_encoding();
[1978] Fix | Delete
} else {
[1979] Fix | Delete
$header .= ' charset=UTF-8';
[1980] Fix | Delete
}
[1981] Fix | Delete
header($header);
[1982] Fix | Delete
}
[1983] Fix | Delete
}
[1984] Fix | Delete
[1985] Fix | Delete
/**
[1986] Fix | Delete
* Get the type of the feed
[1987] Fix | Delete
*
[1988] Fix | Delete
* This returns a \SimplePie\SimplePie::TYPE_* constant, which can be tested against
[1989] Fix | Delete
* using {@link http://php.net/language.operators.bitwise bitwise operators}
[1990] Fix | Delete
*
[1991] Fix | Delete
* @since 0.8 (usage changed to using constants in 1.0)
[1992] Fix | Delete
* @see \SimplePie\SimplePie::TYPE_NONE Unknown.
[1993] Fix | Delete
* @see \SimplePie\SimplePie::TYPE_RSS_090 RSS 0.90.
[1994] Fix | Delete
* @see \SimplePie\SimplePie::TYPE_RSS_091_NETSCAPE RSS 0.91 (Netscape).
[1995] Fix | Delete
* @see \SimplePie\SimplePie::TYPE_RSS_091_USERLAND RSS 0.91 (Userland).
[1996] Fix | Delete
* @see \SimplePie\SimplePie::TYPE_RSS_091 RSS 0.91.
[1997] Fix | Delete
* @see \SimplePie\SimplePie::TYPE_RSS_092 RSS 0.92.
[1998] Fix | Delete
* @see \SimplePie\SimplePie::TYPE_RSS_093 RSS 0.93.
[1999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function