public function addEnclosure($url, $length, $type, $multiple = TRUE)
    {
        if ($this->version == Feed::RSS1)
            throw new InvalidOperationException('Media attachment is not supported in RSS1 feeds.');

        // the length parameter should be set to 0 if it can't be determined
        // see http://www.rssboard.org/rss-profile#element-channel-item-enclosure
        if (!is_numeric($length) || $length < 0)
            throw new \InvalidArgumentException('The length parameter must be an integer and greater or equals to zero.');

        // Regex used from RFC 4287, page 41
        if (!is_string($type) || preg_match('/.+\/.+/', $type) != 1)
            throw new \InvalidArgumentException('type parameter must be a string and a MIME type.');

        $attributes = array('length' => $length, 'type' => $type);

        if ($this->version == Feed::RSS2) {
            $attributes['url'] = $url;
            $this->addElement('enclosure', '', $attributes, FALSE, $multiple);
        } else {
            $attributes['href'] = $url;
            $attributes['rel'] = 'enclosure';
            $this->addElement('atom:link', '', $attributes, FALSE, $multiple);
        }

        return $this;
    }
public function addEnclosure($url, $length, $type, $multiple = TRUE)
    {
        if ($this->version == Feed::RSS1)
            throw new InvalidOperationException('Media attachment is not supported in RSS1 feeds.');

        // the length parameter should be set to 0 if it can't be determined
        // see http://www.rssboard.org/rss-profile#element-channel-item-enclosure
        if (!is_numeric($length) || $length < 0)
            throw new \InvalidArgumentException('The length parameter must be an integer and greater or equals to zero.');

        // Regex used from RFC 4287, page 41
        if (!is_string($type) || preg_match('/.+\/.+/', $type) != 1)
            throw new \InvalidArgumentException('type parameter must be a string and a MIME type.');

        $attributes = array('length' => $length, 'type' => $type);

        if ($this->version == Feed::RSS2) {
            $attributes['url'] = $url;
            $this->addElement('enclosure', '', $attributes, FALSE, $multiple);
        } else {
            $attributes['href'] = $url;
            $attributes['rel'] = 'enclosure';
            $this->addElement('atom:link', '', $attributes, FALSE, $multiple);
        }

        return $this;
    }
public function addEnclosure ( $ url , $ length , $ type , $ multiple = TRUE ) { if ( $ this -> version == Feed :: RSS1 ) throw new InvalidOperationException ( 'Media attachment is not supported in RSS1 feeds.' ) ; // the length parameter should be set to 0 if it can't be determined // see http://www.rssboard.org/rss-profile#element-channel-item-enclosure if ( ! is_numeric ( $ length ) || $ length < 0 ) throw new \ InvalidArgumentException ( 'The length parameter must be an integer and greater or equals to zero.' ) ; // Regex used from RFC 4287, page 41 if ( ! is_string ( $ type ) || preg_match ( '/.+\/.+/' , $ type ) != 1 ) throw new \ InvalidArgumentException ( 'type parameter must be a string and a MIME type.' ) ; $ attributes = array ( 'length' => $ length , 'type' => $ type ) ; if ( $ this -> version == Feed :: RSS2 ) { $ attributes [ 'url' ] = $ url ; $ this -> addElement ( 'enclosure' , '' , $ attributes , FALSE , $ multiple ) ; } else { $ attributes [ 'href' ] = $ url ; $ attributes [ 'rel' ] = 'enclosure' ; $ this -> addElement ( 'atom:link' , '' , $ attributes , FALSE , $ multiple ) ; } return $ this ; }
Attach a external media to the feed item.
Not supported in RSS 1.0 feeds.

See RFC 4288 for syntactical correct MIME types.

Note that you should avoid the use of more than one enclosure in one item,
since some RSS aggregators don't support it.

@access   public
@param    string $url       The URL of the media.
@param    integer $length   The length of the media.
@param    string  $type     The MIME type attribute of the media.
@param    boolean $multiple Specifies if multiple enclosures are allowed
@return   self
@link     https://tools.ietf.org/html/rfc4288
@throws   \InvalidArgumentException if the length or type parameter is invalid.
@throws   InvalidOperationException if this method is called on RSS1 feeds.
Attach a external media to the feed item . Not supported in RSS 1 . 0 feeds .