init.php 868 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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. function hook_render_enclosure($entry, $hide_images) {
  14. $matches = array();
  15. if (preg_match("/\/\/www\.youtube\.com\/v\/([\w-]+)/", $entry["url"], $matches) ||
  16. preg_match("/\/\/www\.youtube\.com\/watch?v=([\w-]+)/", $entry["url"], $matches) ||
  17. preg_match("/\/\/youtu.be\/([\w-]+)/", $entry["url"], $matches)) {
  18. $vid_id = $matches[1];
  19. return "<iframe class=\"youtube-player\"
  20. type=\"text/html\" width=\"640\" height=\"385\"
  21. src=\"https://www.youtube.com/embed/$vid_id\"
  22. allowfullscreen frameborder=\"0\"></iframe>";
  23. }
  24. }
  25. function api_version() {
  26. return 2;
  27. }
  28. }
  29. ?>