You are here

public static function Reader::findFeedLinks in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/zendframework/zend-feed/src/Reader/Reader.php \Zend\Feed\Reader\Reader::findFeedLinks()

Find feed links

Parameters

$uri:

Return value

FeedSet

Throws

Exception\RuntimeException

File

vendor/zendframework/zend-feed/src/Reader/Reader.php, line 372

Class

Reader

Namespace

Zend\Feed\Reader

Code

public static function findFeedLinks($uri) {
  $client = static::getHttpClient();
  $client
    ->setUri($uri);
  $response = $client
    ->send();
  if ($response
    ->getStatusCode() !== 200) {
    throw new Exception\RuntimeException("Failed to access {$uri}, got response code " . $response
      ->getStatusCode());
  }
  $responseHtml = $response
    ->getBody();
  $libxmlErrflag = libxml_use_internal_errors(true);
  $oldValue = libxml_disable_entity_loader(true);
  $dom = new DOMDocument();
  $status = $dom
    ->loadHTML(trim($responseHtml));
  libxml_disable_entity_loader($oldValue);
  libxml_use_internal_errors($libxmlErrflag);
  if (!$status) {

    // Build error message
    $error = libxml_get_last_error();
    if ($error && $error->message) {
      $error->message = trim($error->message);
      $errormsg = "DOMDocument cannot parse HTML: {$error->message}";
    }
    else {
      $errormsg = "DOMDocument cannot parse HTML: Please check the XML document's validity";
    }
    throw new Exception\RuntimeException($errormsg);
  }
  $feedSet = new FeedSet();
  $links = $dom
    ->getElementsByTagName('link');
  $feedSet
    ->addLinks($links, $uri);
  return $feedSet;
}