OEmbedRich.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * OEmbedRich
  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. * OEmbedRich
  14. *
  15. * This type is used for rich HTML content that does not fall under one
  16. * of the other categories. The following parameters are defined:
  17. *
  18. * html (required)
  19. * The HTML required to display the resource. The HTML should have no
  20. * padding or margins. Consumers may wish to load the HTML in an
  21. * off-domain iframe to avoid XSS vulnerabilities. The markup should
  22. * be valid XHTML 1.0 Basic.
  23. *
  24. * width (required)
  25. * The width in pixels required to display the HTML.
  26. *
  27. * height (required)
  28. * The height in pixels required to display the HTML.
  29. *
  30. * Responses of this type must obey the maxwidth and maxheight request
  31. * parameters.
  32. */
  33. class OEmbedRich extends OEmbed
  34. {
  35. public function getOEmbed()
  36. {
  37. $oembed = parent::getOEmbed();
  38. $sizes = ['width', 'height'];
  39. foreach ($sizes as $key) {
  40. $size = isset($oembed[$key]) ? $oembed[$key] : 0;
  41. if (!preg_match('~^\d+$~', $size)) {
  42. $oembed[$key] = 0;
  43. }
  44. }
  45. return $oembed;
  46. }
  47. public function getEmbedCode($params = [])
  48. {
  49. $embed = parent::getEmbedCode($params);
  50. if ($this->embedCode && $this->oembed) {
  51. $embed = $this->oembed->get('html', '');
  52. }
  53. return $embed;
  54. }
  55. }