X-Git-Url: https://git.ao2.it/tweeper.git/blobdiff_plain/50842e9d4c8ba313313710d0b4472548390cd77b..547175cc33bb2aa612c706eac783d8f506fe9e7e:/tweeper.php diff --git a/tweeper.php b/tweeper.php index 17fff8b..d084398 100644 --- a/tweeper.php +++ b/tweeper.php @@ -96,7 +96,11 @@ class Tweeper { "video/ogg", ); - $url_info = Tweeper::get_info($url); + // The RSS specification says that the enclosure element url must be http. + // See http://sourceforge.net/p/feedvalidator/bugs/72/ + $http_url = preg_replace("/^https/", "http", $url); + + $url_info = Tweeper::get_info($http_url); $supported = in_array($url_info['content_type'], $supported_content_types); if (!$supported) { @@ -164,6 +168,21 @@ class Tweeper { return $xsltProcessor; } + private function html_to_xml($html) { + $xmlDoc = new DOMDocument(); + + // Handle warnings and errors when loading invalid HTML. + $xml_errors_value = libxml_use_internal_errors(true); + $xmlDoc->loadHTML($html); + foreach (libxml_get_errors() as $xml_error) { + $this->log_xml_error($xml_error); + } + libxml_clear_errors(); + libxml_use_internal_errors($xml_errors_value); + + return $xmlDoc; + } + public function tweep($src_url) { $url = parse_url($src_url); if (FALSE === $url || empty($url["host"])) { @@ -176,18 +195,15 @@ class Tweeper { return NULL; } - $html = Tweeper::get_contents($src_url); - - $xmlDoc = new DOMDocument(); + $html = $this->get_contents($src_url); + if (FALSE === $html) { + return NULL; + } - // Handle warnings and errors when loading invalid HTML. - $xml_errors_value = libxml_use_internal_errors(true); - $xmlDoc->loadHTML($html); - foreach (libxml_get_errors() as $xml_error) { - $this->log_xml_error($xml_error); + $xmlDoc = $this->html_to_xml($html); + if (NULL === $xmlDoc) { + return NULL; } - libxml_clear_errors(); - libxml_use_internal_errors($xml_errors_value); $output = $xsltProcessor->transformToXML($xmlDoc);