diff options
author | Friendika <info@friendika.com> | 2011-04-04 19:36:18 -0700 |
---|---|---|
committer | Friendika <info@friendika.com> | 2011-04-04 19:36:18 -0700 |
commit | 793967a1d3c23fcf1f3b00a2832f51e6f473f4bd (patch) | |
tree | ec045409190c042c621874f10cf38cf00488b9b3 /boot.php | |
parent | 178362e50b846aef1caf4e191ea0394c5d636857 (diff) | |
download | volse-hubzilla-793967a1d3c23fcf1f3b00a2832f51e6f473f4bd.tar.gz volse-hubzilla-793967a1d3c23fcf1f3b00a2832f51e6f473f4bd.tar.bz2 volse-hubzilla-793967a1d3c23fcf1f3b00a2832f51e6f473f4bd.zip |
better handling of troublesome feeds.
Diffstat (limited to 'boot.php')
-rw-r--r-- | boot.php | 44 |
1 files changed, 32 insertions, 12 deletions
@@ -1478,7 +1478,9 @@ function lrdd($uri) { return array(); logger('lrdd: host_meta: ' . $xml, LOGGER_DATA); - $h = simplexml_load_string($xml); + + $h = parse_xml_string($xml); + $arr = convert_xml_element_to_array($h); if(isset($arr['xrd']['property'])) { @@ -1550,16 +1552,19 @@ function lrdd($uri) { $headers = $a->get_curl_headers(); logger('lrdd: headers=' . $headers, LOGGER_DEBUG); - require_once('library/HTML5/Parser.php'); - $dom = @HTML5_Parser::parse($html); - - if($dom) { - $items = $dom->getElementsByTagName('link'); - foreach($items as $item) { - $x = $item->getAttribute('rel'); - if($x == "lrdd") { - $pagelink = $item->getAttribute('href'); - break; + // don't try and parse raw xml as html + if(! strstr($html,'<?xml')) { + require_once('library/HTML5/Parser.php'); + $dom = @HTML5_Parser::parse($html); + + if($dom) { + $items = $dom->getElementsByTagName('link'); + foreach($items as $item) { + $x = $item->getAttribute('rel'); + if($x == "lrdd") { + $pagelink = $item->getAttribute('href'); + break; + } } } } @@ -1638,7 +1643,7 @@ function fetch_xrd_links($url) { return array(); logger('fetch_xrd_links: ' . $xml, LOGGER_DATA); - $h = simplexml_load_string($xml); + $h = parse_xml_string($xml); $arr = convert_xml_element_to_array($h); $links = array(); @@ -2759,3 +2764,18 @@ function lang_selector() { $o .= '</select></form></div>'; return $o; }} + + +if(! function_exists('parse_xml_string')) { +function parse_xml_string($s) { + if(! strstr($s,'<?xml')) + return false; + $s2 = substr($s,strpos($s,'<?xml')); + libxml_use_internal_errors(true); + $x = @simplexml_load_string($s2); + if(count(libxml_get_errors())) + foreach(libxml_get_errors() as $err) + logger('libxml: parse: ' . $err, LOGGER_DATA); + libxml_clear_errors(); + return $x; +}} |