You are here

protected function Rss::_setImage in Zircon Profile 8

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

Set feed channel image

Parameters

DOMDocument $dom:

DOMElement $root:

Return value

void

Throws

Writer\Exception\InvalidArgumentException

1 call to Rss::_setImage()
Rss::render in vendor/zendframework/zend-feed/src/Writer/Renderer/Feed/Rss.php
Render RSS feed

File

vendor/zendframework/zend-feed/src/Writer/Renderer/Feed/Rss.php, line 303

Class

Rss

Namespace

Zend\Feed\Writer\Renderer\Feed

Code

protected function _setImage(DOMDocument $dom, DOMElement $root) {
  $image = $this
    ->getDataContainer()
    ->getImage();
  if (!$image) {
    return;
  }
  if (!isset($image['title']) || empty($image['title']) || !is_string($image['title'])) {
    $message = 'RSS 2.0 feed images must include a title';
    $exception = new Writer\Exception\InvalidArgumentException($message);
    if (!$this->ignoreExceptions) {
      throw $exception;
    }
    else {
      $this->exceptions[] = $exception;
      return;
    }
  }
  if (empty($image['link']) || !is_string($image['link']) || !Uri::factory($image['link'])
    ->isValid()) {
    $message = 'Invalid parameter: parameter \'link\'' . ' must be a non-empty string and valid URI/IRI';
    $exception = new Writer\Exception\InvalidArgumentException($message);
    if (!$this->ignoreExceptions) {
      throw $exception;
    }
    else {
      $this->exceptions[] = $exception;
      return;
    }
  }
  $img = $dom
    ->createElement('image');
  $root
    ->appendChild($img);
  $url = $dom
    ->createElement('url');
  $text = $dom
    ->createTextNode($image['uri']);
  $url
    ->appendChild($text);
  $title = $dom
    ->createElement('title');
  $text = $dom
    ->createTextNode($image['title']);
  $title
    ->appendChild($text);
  $link = $dom
    ->createElement('link');
  $text = $dom
    ->createTextNode($image['link']);
  $link
    ->appendChild($text);
  $img
    ->appendChild($url);
  $img
    ->appendChild($title);
  $img
    ->appendChild($link);
  if (isset($image['height'])) {
    if (!ctype_digit((string) $image['height']) || $image['height'] > 400) {
      $message = 'Invalid parameter: parameter \'height\'' . ' must be an integer not exceeding 400';
      $exception = new Writer\Exception\InvalidArgumentException($message);
      if (!$this->ignoreExceptions) {
        throw $exception;
      }
      else {
        $this->exceptions[] = $exception;
        return;
      }
    }
    $height = $dom
      ->createElement('height');
    $text = $dom
      ->createTextNode($image['height']);
    $height
      ->appendChild($text);
    $img
      ->appendChild($height);
  }
  if (isset($image['width'])) {
    if (!ctype_digit((string) $image['width']) || $image['width'] > 144) {
      $message = 'Invalid parameter: parameter \'width\'' . ' must be an integer not exceeding 144';
      $exception = new Writer\Exception\InvalidArgumentException($message);
      if (!$this->ignoreExceptions) {
        throw $exception;
      }
      else {
        $this->exceptions[] = $exception;
        return;
      }
    }
    $width = $dom
      ->createElement('width');
    $text = $dom
      ->createTextNode($image['width']);
    $width
      ->appendChild($text);
    $img
      ->appendChild($width);
  }
  if (isset($image['description'])) {
    if (empty($image['description']) || !is_string($image['description'])) {
      $message = 'Invalid parameter: parameter \'description\'' . ' must be a non-empty string';
      $exception = new Writer\Exception\InvalidArgumentException($message);
      if (!$this->ignoreExceptions) {
        throw $exception;
      }
      else {
        $this->exceptions[] = $exception;
        return;
      }
    }
    $desc = $dom
      ->createElement('description');
    $text = $dom
      ->createTextNode($image['description']);
    $desc
      ->appendChild($text);
    $img
      ->appendChild($desc);
  }
}