1:  2:  3:  4:  5:  6:  7:  8:  9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 
<?php
namespace Omeka\Media\Renderer;

use Omeka\Api\Representation\MediaRepresentation;
use Zend\View\Renderer\PhpRenderer;

class OEmbed implements RendererInterface
{
    public function render(PhpRenderer $view, MediaRepresentation $media,
        array $options = []
    ) {
        $data = $media->mediaData();

        if ($data['type'] == 'photo') {
            $url = $data['url'];
            $width = $data['width'];
            $height = $data['height'];
            if (!empty($data['title'])) {
                $title = $data['title'];
            } else {
                $title = $url;
            }
            return sprintf(
                '<img src="%s" width="%s" height="%s" alt="%s">',
                $view->escapeHtml($url),
                $view->escapeHtml($width),
                $view->escapeHtml($height),
                $view->escapeHtml($title)
            );
        } elseif (!empty($data['html'])) {
            return $data['html'];
        } else {
            $source = $media->source();
            if (!$empty($data['title'])) {
                $title = $data['title'];
            } else {
                $title = $source;
            }
            return $view->hyperlink($title, $source);
        }
    }
}