init.php 926 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. class Af_Youtube_Embed extends Plugin {
  3. private $host;
  4. function about() {
  5. return array(1.0,
  6. "Embed videos in Youtube RSS feeds",
  7. "fox");
  8. }
  9. function init($host) {
  10. $this->host = $host;
  11. $host->add_hook($host::HOOK_RENDER_ENCLOSURE, $this);
  12. }
  13. /**
  14. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  15. */
  16. function hook_render_enclosure($entry, $hide_images) {
  17. $matches = array();
  18. if (preg_match("/\/\/www\.youtube\.com\/v\/([\w-]+)/", $entry["url"], $matches) ||
  19. preg_match("/\/\/www\.youtube\.com\/watch?v=([\w-]+)/", $entry["url"], $matches) ||
  20. preg_match("/\/\/youtu.be\/([\w-]+)/", $entry["url"], $matches)) {
  21. $vid_id = $matches[1];
  22. return "<iframe class=\"youtube-player\"
  23. type=\"text/html\" width=\"640\" height=\"385\"
  24. src=\"https://www.youtube.com/embed/$vid_id\"
  25. allowfullscreen frameborder=\"0\"></iframe>";
  26. }
  27. }
  28. function api_version() {
  29. return 2;
  30. }
  31. }