asset_media_renderer.class.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * Media renderer. I.e. video streams that can be embeded through an embed tag.
  4. *
  5. * @copyright (c) 2011 University of Geneva
  6. * @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html
  7. * @author Laurent Opprecht
  8. */
  9. class AssetMediaRenderer extends AssetRenderer
  10. {
  11. /**
  12. *
  13. * @param HttpResource $asset
  14. */
  15. public function accept($asset)
  16. {
  17. if ($asset->is_video())
  18. {
  19. return true;
  20. }
  21. //swf mime type is application/x-shockwave-flash
  22. return $asset->has_ext('swf');
  23. }
  24. /**
  25. *
  26. * @param HttpResource $asset
  27. */
  28. public function render($asset)
  29. {
  30. if (!$this->accept($asset))
  31. {
  32. return;
  33. }
  34. $url = $asset->url();
  35. $title = $asset->title();
  36. $description = $asset->get_meta('description');
  37. $keywords = $asset->get_meta('keywords');
  38. $size = (int) $asset->config('size');
  39. $size = (24 <= $size && $size <= 800) ? $size : 300;
  40. $width = $size;
  41. $height = $size *9/16;
  42. $embed = <<<EOT
  43. <div style="text-align:center;"><embed style="display:inline-block;" width="{$width}px" height="{$height}px" name="plugin" src="$url" ></div>
  44. EOT;
  45. $result = array();
  46. $result[self::EMBED_SNIPPET] = $embed;
  47. $result[self::TITLE] = $title;
  48. $result[self::DESCRIPTION] = $description;
  49. $result[self::TAGS] = $keywords;
  50. return $result;
  51. }
  52. }