Slides.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * Slides.com
  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\Services;
  11. use Grav\Plugin\MediaEmbed\OEmbed\OEmbedRich;
  12. /**
  13. * Slides
  14. */
  15. class Slides extends OEmbedRich
  16. {
  17. public function getOEmbed()
  18. {
  19. if ($this->oembed) {
  20. return $this->oembed;
  21. }
  22. $endpoint = $this->format($this->config->get('endpoint', ''));
  23. if (!$endpoint) {
  24. return [];
  25. }
  26. // Extract owner from embed code
  27. list($owner, $id) = explode('/', $this->embedCode, 2);
  28. // Fake response
  29. $this->oembed = [
  30. 'type' => 'rich',
  31. 'title' => '',
  32. 'description' => '',
  33. 'author_name' => $owner,
  34. 'author_url' => 'http://slides.com/'.$owner,
  35. 'provider' => 'Slides',
  36. 'provider_url' => 'http://slides.com',
  37. 'url' => 'http://slides.com/'.$this->embedCode,
  38. 'html' => '<iframe src="//slides.com/'.rtrim($this->embedCode, '/').'/embed" width="576" height="420" scrolling="no" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>',
  39. 'width' => 576,
  40. 'height' => 420,
  41. ];
  42. return $this->oembed;
  43. }
  44. public function getEmbedCode($params = [])
  45. {
  46. $embed = parent::getEmbedCode($params);
  47. if ($this->embedCode && $this->oembed) {
  48. // Inject parameters directly into HTML OEmbed attribute
  49. $query = http_build_query($this->params());
  50. $url = $this->attributes['protocol'].'slides.com/'.rtrim($this->embedCode, '/').'/embed';
  51. if (mb_strlen($query) > 0) {
  52. $url .= (false === strpos($url, '?') ? '?' : '&') . $query;
  53. }
  54. // Get width and height
  55. $width = $this->attributes['width'];
  56. $height = $this->attributes['height'];
  57. $embed = '<iframe src="'.$url.'" width="'.$width.'" height="'.$height.'" scrolling="no" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>';
  58. }
  59. return $embed;
  60. }
  61. }