8719
class SimplePie_Cache_DB
8721
function prepare_simplepie_object_for_cache($data)
8723
$items = $data->get_items();
8724
$items_by_id = array();
8728
foreach ($items as $item)
8730
$items_by_id[$item->get_id()] = $item;
8733
if (count($items_by_id) !== count($items))
8735
$items_by_id = array();
8736
foreach ($items as $item)
8738
$items_by_id[$item->get_id(true)] = $item;
8742
if (isset($data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]))
8744
$channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0];
8746
elseif (isset($data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]))
8748
$channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0];
8750
elseif (isset($data->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]))
8752
$channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0];
8754
elseif (isset($data->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['channel'][0]))
8756
$channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['channel'][0];
8763
if ($channel !== null)
8765
if (isset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['entry']))
8767
unset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['entry']);
8769
if (isset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['entry']))
8771
unset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['entry']);
8773
if (isset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_10]['item']))
8775
unset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_10]['item']);
8777
if (isset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_090]['item']))
8779
unset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_090]['item']);
8781
if (isset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_20]['item']))
8783
unset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_20]['item']);
8786
if (isset($data->data['items']))
8788
unset($data->data['items']);
8790
if (isset($data->data['ordered_items']))
8792
unset($data->data['ordered_items']);
8795
return array(serialize($data->data), $items_by_id);
8799
class SimplePie_Cache_MySQL extends SimplePie_Cache_DB
8805
function SimplePie_Cache_MySQL($mysql_location, $name, $extension)
8807
$host = $mysql_location->get_host();
8808
if (SimplePie_Misc::stripos($host, 'unix(') === 0 && substr($host, -1) === ')')
8810
$server = ':' . substr($host, 5, -1);
8815
if ($mysql_location->get_port() !== null)
8817
$server .= ':' . $mysql_location->get_port();
8821
if (strpos($mysql_location->get_userinfo(), ':') !== false)
8823
list($username, $password) = explode(':', $mysql_location->get_userinfo(), 2);
8827
$username = $mysql_location->get_userinfo();
8831
if ($this->mysql = mysql_connect($server, $username, $password))
8833
$this->id = $name . $extension;
8834
$this->options = SimplePie_Misc::parse_str($mysql_location->get_query());
8835
if (!isset($this->options['prefix'][0]))
8837
$this->options['prefix'][0] = '';
8840
if (mysql_select_db(ltrim($mysql_location->get_path(), '/'))
8841
&& mysql_query('SET NAMES utf8')
8842
&& ($query = mysql_unbuffered_query('SHOW TABLES')))
8845
while ($row = mysql_fetch_row($query))
8850
if (!in_array($this->options['prefix'][0] . 'cache_data', $db))
8852
if (!mysql_query('CREATE TABLE `' . $this->options['prefix'][0] . '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)))'))
8854
$this->mysql = null;
8858
if (!in_array($this->options['prefix'][0] . 'items', $db))
8860
if (!mysql_query('CREATE TABLE `' . $this->options['prefix'][0] . 'items` (`feed_id` TEXT CHARACTER SET utf8 NOT NULL, `id` TEXT CHARACTER SET utf8 NOT NULL, `data` TEXT CHARACTER SET utf8 NOT NULL, `posted` INT UNSIGNED NOT NULL, INDEX `feed_id` (`feed_id`(125)))'))
8862
$this->mysql = null;
8868
$this->mysql = null;
8873
function save($data)
8877
$feed_id = "'" . mysql_real_escape_string($this->id) . "'";
8879
if (is_a($data, 'SimplePie'))
8883
// This keyword needs to defy coding standards for PHP4 compatibility
8884
$data = clone($data);
8887
$prepared = $this->prepare_simplepie_object_for_cache($data);
8889
if ($query = mysql_query('SELECT `id` FROM `' . $this->options['prefix'][0] . 'cache_data` WHERE `id` = ' . $feed_id, $this->mysql))
8891
if (mysql_num_rows($query))
8893
$items = count($prepared[1]);
8896
$sql = 'UPDATE `' . $this->options['prefix'][0] . 'cache_data` SET `items` = ' . $items . ', `data` = \'' . mysql_real_escape_string($prepared[0]) . '\', `mtime` = ' . time() . ' WHERE `id` = ' . $feed_id;
8900
$sql = 'UPDATE `' . $this->options['prefix'][0] . 'cache_data` SET `data` = \'' . mysql_real_escape_string($prepared[0]) . '\', `mtime` = ' . time() . ' WHERE `id` = ' . $feed_id;
8903
if (!mysql_query($sql, $this->mysql))
8908
elseif (!mysql_query('INSERT INTO `' . $this->options['prefix'][0] . 'cache_data` (`id`, `items`, `data`, `mtime`) VALUES(' . $feed_id . ', ' . count($prepared[1]) . ', \'' . mysql_real_escape_string($prepared[0]) . '\', ' . time() . ')', $this->mysql))
8913
$ids = array_keys($prepared[1]);
8916
foreach ($ids as $id)
8918
$database_ids[] = mysql_real_escape_string($id);
8921
if ($query = mysql_unbuffered_query('SELECT `id` FROM `' . $this->options['prefix'][0] . 'items` WHERE `id` = \'' . implode('\' OR `id` = \'', $database_ids) . '\' AND `feed_id` = ' . $feed_id, $this->mysql))
8923
$existing_ids = array();
8924
while ($row = mysql_fetch_row($query))
8926
$existing_ids[] = $row[0];
8929
$new_ids = array_diff($ids, $existing_ids);
8931
foreach ($new_ids as $new_id)
8933
if (!($date = $prepared[1][$new_id]->get_date('U')))
8938
if (!mysql_query('INSERT INTO `' . $this->options['prefix'][0] . 'items` (`feed_id`, `id`, `data`, `posted`) VALUES(' . $feed_id . ', \'' . mysql_real_escape_string($new_id) . '\', \'' . mysql_real_escape_string(serialize($prepared[1][$new_id]->data)) . '\', ' . $date . ')', $this->mysql))
8952
elseif ($query = mysql_query('SELECT `id` FROM `' . $this->options['prefix'][0] . 'cache_data` WHERE `id` = ' . $feed_id, $this->mysql))
8954
if (mysql_num_rows($query))
8956
if (mysql_query('UPDATE `' . $this->options['prefix'][0] . 'cache_data` SET `items` = 0, `data` = \'' . mysql_real_escape_string(serialize($data)) . '\', `mtime` = ' . time() . ' WHERE `id` = ' . $feed_id, $this->mysql))
8961
elseif (mysql_query('INSERT INTO `' . $this->options['prefix'][0] . 'cache_data` (`id`, `items`, `data`, `mtime`) VALUES(\'' . mysql_real_escape_string($this->id) . '\', 0, \'' . mysql_real_escape_string(serialize($data)) . '\', ' . time() . ')', $this->mysql))
8972
if ($this->mysql && ($query = mysql_query('SELECT `items`, `data` FROM `' . $this->options['prefix'][0] . 'cache_data` WHERE `id` = \'' . mysql_real_escape_string($this->id) . "'", $this->mysql)) && ($row = mysql_fetch_row($query)))
8974
$data = unserialize($row[1]);
8976
if (isset($this->options['items'][0]))
8978
$items = (int) $this->options['items'][0];
8982
$items = (int) $row[0];
8987
if (isset($data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]))
8989
$feed =& $data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0];
8991
elseif (isset($data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]))
8993
$feed =& $data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0];
8995
elseif (isset($data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]))
8997
$feed =& $data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0];
8999
elseif (isset($data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]))
9001
$feed =& $data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0];
9010
$sql = 'SELECT `data` FROM `' . $this->options['prefix'][0] . 'items` WHERE `feed_id` = \'' . mysql_real_escape_string($this->id) . '\' ORDER BY `posted` DESC';
9013
$sql .= ' LIMIT ' . $items;
9016
if ($query = mysql_unbuffered_query($sql, $this->mysql))
9018
while ($row = mysql_fetch_row($query))
9020
$feed['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['entry'][] = unserialize($row[0]);
9036
if ($this->mysql && ($query = mysql_query('SELECT `mtime` FROM `' . $this->options['prefix'][0] . 'cache_data` WHERE `id` = \'' . mysql_real_escape_string($this->id) . "'", $this->mysql)) && ($row = mysql_fetch_row($query)))
9048
if ($this->mysql && ($query = mysql_query('UPDATE `' . $this->options['prefix'][0] . 'cache_data` SET `mtime` = ' . time() . ' WHERE `id` = \'' . mysql_real_escape_string($this->id) . "'", $this->mysql)) && mysql_affected_rows($this->mysql))
9060
if ($this->mysql && ($query = mysql_query('DELETE FROM `' . $this->options['prefix'][0] . 'cache_data` WHERE `id` = \'' . mysql_real_escape_string($this->id) . "'", $this->mysql)) && ($query2 = mysql_query('DELETE FROM `' . $this->options['prefix'][0] . 'items` WHERE `feed_id` = \'' . mysql_real_escape_string($this->id) . "'", $this->mysql)))
8644
9071
class SimplePie_Misc
8646
9073
function time_hms($seconds)
11569
* IRI parser/serialiser
11571
* @package SimplePie
11573
class SimplePie_IRI
11632
* Whether the object represents a valid IRI
11637
var $valid = array();
11640
* Return the entire IRI when you try and read the object as a string
11645
function __toString()
11647
return $this->get_iri();
11651
* Create a new IRI object, from a specified string
11654
* @param string $iri
11655
* @return SimplePie_IRI
11657
function SimplePie_IRI($iri)
11659
$iri = (string) $iri;
11662
$parsed = $this->parse_iri($iri);
11663
$this->set_scheme($parsed['scheme']);
11664
$this->set_authority($parsed['authority']);
11665
$this->set_path($parsed['path']);
11666
$this->set_query($parsed['query']);
11667
$this->set_fragment($parsed['fragment']);
11672
* Create a new IRI object by resolving a relative IRI
11676
* @param SimplePie_IRI $base Base IRI
11677
* @param string $relative Relative IRI
11678
* @return SimplePie_IRI
11680
function absolutize($base, $relative)
11682
$relative = (string) $relative;
11683
if ($relative !== '')
11685
$relative =& new SimplePie_IRI($relative);
11686
if ($relative->get_scheme() !== null)
11688
$target = $relative;
11690
elseif ($base->get_iri() !== null)
11692
if ($relative->get_authority() !== null)
11694
$target = $relative;
11695
$target->set_scheme($base->get_scheme());
11699
$target =& new SimplePie_IRI('');
11700
$target->set_scheme($base->get_scheme());
11701
$target->set_userinfo($base->get_userinfo());
11702
$target->set_host($base->get_host());
11703
$target->set_port($base->get_port());
11704
if ($relative->get_path() !== null)
11706
if (strpos($relative->get_path(), '/') === 0)
11708
$target->set_path($relative->get_path());
11710
elseif (($base->get_userinfo() !== null || $base->get_host() !== null || $base->get_port() !== null) && $base->get_path() === null)
11712
$target->set_path('/' . $relative->get_path());
11714
elseif (($last_segment = strrpos($base->get_path(), '/')) !== false)
11716
$target->set_path(substr($base->get_path(), 0, $last_segment + 1) . $relative->get_path());
11720
$target->set_path($relative->get_path());
11722
$target->set_query($relative->get_query());
11726
$target->set_path($base->get_path());
11727
if ($relative->get_query() !== null)
11729
$target->set_query($relative->get_query());
11731
elseif ($base->get_query() !== null)
11733
$target->set_query($base->get_query());
11737
$target->set_fragment($relative->get_fragment());
11741
// No base URL, just return the relative URL
11742
$target = $relative;
11753
* Parse an IRI into scheme/authority/path/query/fragment segments
11756
* @param string $iri
11759
function parse_iri($iri)
11761
preg_match('/^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/', $iri, $match);
11762
for ($i = count($match); $i <= 9; $i++)
11766
return array('scheme' => $match[2], 'authority' => $match[4], 'path' => $match[5], 'query' => $match[7], 'fragment' => $match[9]);
11770
* Remove dot segments from a path
11773
* @param string $input
11776
function remove_dot_segments($input)
11779
while (strpos($input, './') !== false || strpos($input, '/.') !== false || $input === '.' || $input === '..')
11781
// A: If the input buffer begins with a prefix of "../" or "./", then remove that prefix from the input buffer; otherwise,
11782
if (strpos($input, '../') === 0)
11784
$input = substr($input, 3);
11786
elseif (strpos($input, './') === 0)
11788
$input = substr($input, 2);
11790
// B: if the input buffer begins with a prefix of "/./" or "/.", where "." is a complete path segment, then replace that prefix with "/" in the input buffer; otherwise,
11791
elseif (strpos($input, '/./') === 0)
11793
$input = substr_replace($input, '/', 0, 3);
11795
elseif ($input === '/.')
11799
// C: if the input buffer begins with a prefix of "/../" or "/..", where ".." is a complete path segment, then replace that prefix with "/" in the input buffer and remove the last segment and its preceding "/" (if any) from the output buffer; otherwise,
11800
elseif (strpos($input, '/../') === 0)
11802
$input = substr_replace($input, '/', 0, 4);
11803
$output = substr_replace($output, '', strrpos($output, '/'));
11805
elseif ($input === '/..')
11808
$output = substr_replace($output, '', strrpos($output, '/'));
11810
// D: if the input buffer consists only of "." or "..", then remove that from the input buffer; otherwise,
11811
elseif ($input === '.' || $input === '..')
11815
// E: move the first path segment in the input buffer to the end of the output buffer, including the initial "/" character (if any) and any subsequent characters up to, but not including, the next "/" character or the end of the input buffer
11816
elseif (($pos = strpos($input, '/', 1)) !== false)
11818
$output .= substr($input, 0, $pos);
11819
$input = substr_replace($input, '', 0, $pos);
11827
return $output . $input;
11831
* Replace invalid character with percent encoding
11834
* @param string $string Input string
11835
* @param string $valid_chars Valid characters
11836
* @param int $case Normalise case
11839
function replace_invalid_with_pct_encoding($string, $valid_chars, $case = SIMPLEPIE_SAME_CASE)
11842
if ($case & SIMPLEPIE_LOWERCASE)
11844
$string = strtolower($string);
11846
elseif ($case & SIMPLEPIE_UPPERCASE)
11848
$string = strtoupper($string);
11851
// Store position and string length (to avoid constantly recalculating this)
11853
$strlen = strlen($string);
11855
// Loop as long as we have invalid characters, advancing the position to the next invalid character
11856
while (($position += strspn($string, $valid_chars, $position)) < $strlen)
11858
// If we have a % character
11859
if ($string[$position] === '%')
11861
// If we have a pct-encoded section
11862
if ($position + 2 < $strlen && strspn($string, '0123456789ABCDEFabcdef', $position + 1, 2) === 2)
11864
// Get the the represented character
11865
$chr = chr(hexdec(substr($string, $position + 1, 2)));
11867
// If the character is valid, replace the pct-encoded with the actual character while normalising case
11868
if (strpos($valid_chars, $chr) !== false)
11870
if ($case & SIMPLEPIE_LOWERCASE)
11872
$chr = strtolower($chr);
11874
elseif ($case & SIMPLEPIE_UPPERCASE)
11876
$chr = strtoupper($chr);
11878
$string = substr_replace($string, $chr, $position, 3);
11883
// Otherwise just normalise the pct-encoded to uppercase
11886
$string = substr_replace($string, strtoupper(substr($string, $position + 1, 2)), $position + 1, 2);
11890
// If we don't have a pct-encoded section, just replace the % with its own esccaped form
11893
$string = substr_replace($string, '%25', $position, 1);
11898
// If we have an invalid character, change into its pct-encoded form
11901
$replacement = sprintf("%%%02X", ord($string[$position]));
11902
$string = str_replace($string[$position], $replacement, $string);
11903
$strlen = strlen($string);
11910
* Check if the object represents a valid IRI
11915
function is_valid()
11917
return array_sum($this->valid) === count($this->valid);
11921
* Set the scheme. Returns true on success, false on failure (if there are
11922
* any invalid characters).
11925
* @param string $scheme
11928
function set_scheme($scheme)
11930
if ($scheme === null || $scheme === '')
11932
$this->scheme = null;
11936
$len = strlen($scheme);
11940
if (!strspn($scheme, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-.', 1))
11942
$this->scheme = null;
11943
$this->valid[__FUNCTION__] = false;
11948
if (!strspn($scheme, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz', 0, 1))
11950
$this->scheme = null;
11951
$this->valid[__FUNCTION__] = false;
11955
$this->scheme = strtolower($scheme);
11957
$this->valid[__FUNCTION__] = true;
11962
* Set the authority. Returns true on success, false on failure (if there are
11963
* any invalid characters).
11966
* @param string $authority
11969
function set_authority($authority)
11971
if (($userinfo_end = strrpos($authority, '@')) !== false)
11973
$userinfo = substr($authority, 0, $userinfo_end);
11974
$authority = substr($authority, $userinfo_end + 1);
11981
if (($port_start = strpos($authority, ':')) !== false)
11983
$port = substr($authority, $port_start + 1);
11984
$authority = substr($authority, 0, $port_start);
11991
return $this->set_userinfo($userinfo) && $this->set_host($authority) && $this->set_port($port);
11995
* Set the userinfo.
11998
* @param string $userinfo
12001
function set_userinfo($userinfo)
12003
if ($userinfo === null || $userinfo === '')
12005
$this->userinfo = null;
12009
$this->userinfo = $this->replace_invalid_with_pct_encoding($userinfo, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~!$&\'()*+,;=:');
12011
$this->valid[__FUNCTION__] = true;
12016
* Set the host. Returns true on success, false on failure (if there are
12017
* any invalid characters).
12020
* @param string $host
12023
function set_host($host)
12025
if ($host === null || $host === '')
12027
$this->host = null;
12028
$this->valid[__FUNCTION__] = true;
12031
elseif ($host[0] === '[' && substr($host, -1) === ']')
12033
if (Net_IPv6::checkIPv6(substr($host, 1, -1)))
12035
$this->host = $host;
12036
$this->valid[__FUNCTION__] = true;
12041
$this->host = null;
12042
$this->valid[__FUNCTION__] = false;
12048
$this->host = $this->replace_invalid_with_pct_encoding($host, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~!$&\'()*+,;=', SIMPLEPIE_LOWERCASE);
12049
$this->valid[__FUNCTION__] = true;
12055
* Set the port. Returns true on success, false on failure (if there are
12056
* any invalid characters).
12059
* @param string $port
12062
function set_port($port)
12064
if ($port === null || $port === '')
12066
$this->port = null;
12067
$this->valid[__FUNCTION__] = true;
12070
elseif (strspn($port, '0123456789') === strlen($port))
12072
$this->port = (int) $port;
12073
$this->valid[__FUNCTION__] = true;
12078
$this->port = null;
12079
$this->valid[__FUNCTION__] = false;
12088
* @param string $path
12091
function set_path($path)
12093
if ($path === null || $path === '')
12095
$this->path = null;
12096
$this->valid[__FUNCTION__] = true;
12099
elseif (substr($path, 0, 2) === '//' && $this->userinfo === null && $this->host === null && $this->port === null)
12101
$this->path = null;
12102
$this->valid[__FUNCTION__] = false;
12107
$this->path = $this->replace_invalid_with_pct_encoding($path, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~!$&\'()*+,;=@/');
12108
if ($this->scheme !== null)
12110
$this->path = $this->remove_dot_segments($this->path);
12112
$this->valid[__FUNCTION__] = true;
12121
* @param string $query
12124
function set_query($query)
12126
if ($query === null || $query === '')
12128
$this->query = null;
12132
$this->query = $this->replace_invalid_with_pct_encoding($query, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~!$&\'()*+,;=:@/?');
12134
$this->valid[__FUNCTION__] = true;
12139
* Set the fragment.
12142
* @param string $fragment
12145
function set_fragment($fragment)
12147
if ($fragment === null || $fragment === '')
12149
$this->fragment = null;
12153
$this->fragment = $this->replace_invalid_with_pct_encoding($fragment, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~!$&\'()*+,;=:@/?');
12155
$this->valid[__FUNCTION__] = true;
12160
* Get the complete IRI
12168
if ($this->scheme !== null)
12170
$iri .= $this->scheme . ':';
12172
if (($authority = $this->get_authority()) !== null)
12174
$iri .= '//' . $authority;
12176
if ($this->path !== null)
12178
$iri .= $this->path;
12180
if ($this->query !== null)
12182
$iri .= '?' . $this->query;
12184
if ($this->fragment !== null)
12186
$iri .= '#' . $this->fragment;
12205
function get_scheme()
12207
return $this->scheme;
12211
* Get the complete authority
12216
function get_authority()
12219
if ($this->userinfo !== null)
12221
$authority .= $this->userinfo . '@';
12223
if ($this->host !== null)
12225
$authority .= $this->host;
12227
if ($this->port !== null)
12229
$authority .= ':' . $this->port;
12232
if ($authority !== '')
12243
* Get the user information
12248
function get_userinfo()
12250
return $this->userinfo;
12259
function get_host()
12261
return $this->host;
12270
function get_port()
12272
return $this->port;
12281
function get_path()
12283
return $this->path;
12292
function get_query()
12294
return $this->query;
12303
function get_fragment()
12305
return $this->fragment;
12310
* Class to validate and to work with IPv6 addresses.
12312
* @package SimplePie
12313
* @copyright 2003-2005 The PHP Group
12314
* @license http://www.opensource.org/licenses/bsd-license.php
12315
* @link http://pear.php.net/package/Net_IPv6
12316
* @author Alexander Merz <alexander.merz@web.de>
12317
* @author elfrink at introweb dot nl
12318
* @author Josh Peck <jmp at joshpeck dot org>
12319
* @author Geoffrey Sneddon <geoffers@gmail.com>
12321
class SimplePie_Net_IPv6
12324
* Removes a possible existing netmask specification of an IP address.
12326
* @param string $ip the (compressed) IP as Hex representation
12327
* @return string the IP the without netmask
12332
function removeNetmaskSpec($ip)
12334
if (strpos($ip, '/') !== false)
12336
list($addr, $nm) = explode('/', $ip);
12346
* Uncompresses an IPv6 address
12348
* RFC 2373 allows you to compress zeros in an address to '::'. This
12349
* function expects an valid IPv6 address and expands the '::' to
12350
* the required zeros.
12352
* Example: FF01::101 -> FF01:0:0:0:0:0:0:101
12353
* ::1 -> 0:0:0:0:0:0:0:1
12357
* @param string $ip a valid IPv6-address (hex format)
12358
* @return string the uncompressed IPv6-address (hex format)
12360
function Uncompress($ip)
12362
$uip = SimplePie_Net_IPv6::removeNetmaskSpec($ip);
12365
if (strpos($ip, '::') !== false)
12367
list($ip1, $ip2) = explode('::', $ip);
12375
if (($pos = substr_count($ip1, ':')) > 0)
12391
if (($pos = substr_count($ip2, ':')) > 0)
12400
if (strstr($ip2, '.'))
12405
if ($c1 === -1 && $c2 === -1)
12407
$uip = '0:0:0:0:0:0:0:0';
12410
else if ($c1 === -1)
12412
$fill = str_repeat('0:', 7 - $c2);
12413
$uip = str_replace('::', $fill, $uip);
12416
else if ($c2 === -1)
12418
$fill = str_repeat(':0', 7 - $c1);
12419
$uip = str_replace('::', $fill, $uip);
12424
$fill = str_repeat(':0:', 6 - $c2 - $c1);
12425
$uip = str_replace('::', $fill, $uip);
12426
$uip = str_replace('::', ':', $uip);
12433
* Splits an IPv6 address into the IPv6 and a possible IPv4 part
12435
* RFC 2373 allows you to note the last two parts of an IPv6 address as
12436
* an IPv4 compatible address
12438
* Example: 0:0:0:0:0:0:13.1.68.3
12439
* 0:0:0:0:0:FFFF:129.144.52.38
12443
* @param string $ip a valid IPv6-address (hex format)
12444
* @return array [0] contains the IPv6 part, [1] the IPv4 part (hex format)
12446
function SplitV64($ip)
12448
$ip = SimplePie_Net_IPv6::Uncompress($ip);
12449
if (strstr($ip, '.'))
12451
$pos = strrpos($ip, ':');
12453
$ipPart = explode('_', $ip);
12458
return array($ip, '');
12463
* Checks an IPv6 address
12465
* Checks if the given IP is IPv6-compatible
12469
* @param string $ip a valid IPv6-address
12470
* @return bool true if $ip is an IPv6 address
12472
function checkIPv6($ip)
12474
$ipPart = SimplePie_Net_IPv6::SplitV64($ip);
12476
if (!empty($ipPart[0]))
12478
$ipv6 = explode(':', $ipPart[0]);
12479
for ($i = 0; $i < count($ipv6); $i++)
12481
$dec = hexdec($ipv6[$i]);
12482
$hex = strtoupper(preg_replace('/^[0]{1,3}(.*[0-9a-fA-F])$/', '\\1', $ipv6[$i]));
12483
if ($ipv6[$i] >= 0 && $dec <= 65535 && $hex === strtoupper(dechex($dec)))
12492
elseif ($count === 6 && !empty($ipPart[1]))
12494
$ipv4 = explode('.', $ipPart[1]);
12496
foreach ($ipv4 as $ipv4_part)
12498
if ($ipv4_part >= 0 && $ipv4_part <= 255 && preg_match('/^\d{1,3}$/', $ipv4_part))
11217
12522
* Date Parser
11219
12524
* @package SimplePie
13068
// Work around libxml bug
13069
$data = str_replace('<', '<', $data);
13070
$data = str_replace('>', '>', $data);
13071
$data = str_replace('&', '&', $data);
13072
$data = str_replace(''', ''', $data);
13073
$data = str_replace('"', '"', $data);
13075
14380
$return = true;
14382
static $xml_is_sane = null;
14383
if ($xml_is_sane === null)
14385
$parser_check = xml_parser_create();
14386
xml_parse_into_struct($parser_check, '<foo>&</foo>', $values);
14387
xml_parser_free($parser_check);
14388
$xml_is_sane = isset($values[0]['value']);
13077
14391
// Create the parser
13078
$xml = xml_parser_create_ns($this->encoding, $this->separator);
13079
xml_parser_set_option($xml, XML_OPTION_SKIP_WHITE, 1);
13080
xml_parser_set_option($xml, XML_OPTION_CASE_FOLDING, 0);
13081
xml_set_object($xml, $this);
13082
xml_set_character_data_handler($xml, 'cdata');
13083
xml_set_element_handler($xml, 'tag_open', 'tag_close');
13086
if (!xml_parse($xml, $data, true))
13088
$this->error_code = xml_get_error_code($xml);
13089
$this->error_string = xml_error_string($this->error_code);
13092
$this->current_line = xml_get_current_line_number($xml);
13093
$this->current_column = xml_get_current_column_number($xml);
13094
$this->current_byte = xml_get_current_byte_index($xml);
13095
xml_parser_free($xml);
14394
$xml = xml_parser_create_ns($this->encoding, $this->separator);
14395
xml_parser_set_option($xml, XML_OPTION_SKIP_WHITE, 1);
14396
xml_parser_set_option($xml, XML_OPTION_CASE_FOLDING, 0);
14397
xml_set_object($xml, $this);
14398
xml_set_character_data_handler($xml, 'cdata');
14399
xml_set_element_handler($xml, 'tag_open', 'tag_close');
14402
if (!xml_parse($xml, $data, true))
14404
$this->error_code = xml_get_error_code($xml);
14405
$this->error_string = xml_error_string($this->error_code);
14408
$this->current_line = xml_get_current_line_number($xml);
14409
$this->current_column = xml_get_current_column_number($xml);
14410
$this->current_byte = xml_get_current_byte_index($xml);
14411
xml_parser_free($xml);
14416
libxml_clear_errors();
14417
$xml =& new XMLReader();
14419
while (@$xml->read())
14421
switch ($xml->nodeType)
14424
case constant('XMLReader::END_ELEMENT'):
14425
if ($xml->namespaceURI !== '')
14427
$tagName = "{$xml->namespaceURI}{$this->separator}{$xml->localName}";
14431
$tagName = $xml->localName;
14433
$this->tag_close(null, $tagName);
14435
case constant('XMLReader::ELEMENT'):
14436
$empty = $xml->isEmptyElement;
14437
if ($xml->namespaceURI !== '')
14439
$tagName = "{$xml->namespaceURI}{$this->separator}{$xml->localName}";
14443
$tagName = $xml->localName;
14445
$attributes = array();
14446
while ($xml->moveToNextAttribute())
14448
if ($xml->namespaceURI !== '')
14450
$attrName = "{$xml->namespaceURI}{$this->separator}{$xml->localName}";
14454
$attrName = $xml->localName;
14456
$attributes[$attrName] = $xml->value;
14458
$this->tag_open(null, $tagName, $attributes);
14461
$this->tag_close(null, $tagName);
14464
case constant('XMLReader::TEXT'):
14466
case constant('XMLReader::CDATA'):
14467
$this->cdata(null, $xml->value);
14471
if ($error = libxml_get_last_error())
14473
$this->error_code = $error->code;
14474
$this->error_string = $error->message;
14475
$this->current_line = $error->line;
14476
$this->current_column = $error->column;
13099
14486
function get_error_code()