OEmbedVideo.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * OEmbedVideo
  4. *
  5. * This file is part of Grav MediaEmbed plugin.
  6. *
  7. * Dual licensed under the MIT or GPL Version 3 licenses, see LICENSE.
  8. * http://benjamin-regler.de/license/
  9. */
  10. namespace Grav\Plugin\MediaEmbed\OEmbed;
  11. use Grav\Plugin\MediaEmbed\OEmbed\OEmbed;
  12. /**
  13. * OEmbedVideo
  14. *
  15. * This type is used for representing playable videos. The following
  16. * parameters are defined:
  17. *
  18. * html (required)
  19. * The HTML required to embed a video player. The HTML should have
  20. * no padding or margins. Consumers may wish to load the HTML in an
  21. * off-domain iframe to avoid XSS vulnerabilities.
  22. *
  23. * width (required)
  24. * The width in pixels required to display the HTML.
  25. *
  26. * height (required)
  27. * The height in pixels required to display the HTML.
  28. *
  29. * Responses of this type must obey the maxwidth and maxheight request
  30. * parameters. If a provider wishes the consumer to just provide a
  31. * thumbnail, rather than an embeddable player, they should instead
  32. * return a photo response type.
  33. */
  34. class OEmbedVideo extends OEmbed
  35. {
  36. public function getOEmbed()
  37. {
  38. $oembed = parent::getOEmbed();
  39. if ($this->embedCode && $this->oembed) {
  40. $width = $this->oembed->get('width');
  41. $height = $this->oembed->get('height');
  42. $this->attributes(['width' => $width, 'height' => $height]);
  43. }
  44. return $oembed;
  45. }
  46. public function getEmbedCode($params = [])
  47. {
  48. $embed = parent::getEmbedCode($params);
  49. if (mb_strlen($embed) == 0 && $this->embedCode && $this->oembed) {
  50. $embed = $this->oembed->get('html', '');
  51. }
  52. return $embed;
  53. }
  54. }