PageRenderTime 42ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/broken-link-checker/modules/extras/youtube-iframe.php

https://bitbucket.org/lgorence/quickpress
PHP | 77 lines | 32 code | 13 blank | 32 comment | 2 complexity | 8b9dc87d15775936219df839ea2b1a26 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, AGPL-1.0
  1. <?php
  2. /*
  3. Plugin Name: Embedded YouTube videos
  4. Description: Parse embedded videos from YouTube
  5. Version: 1.0
  6. Author: Janis Elsts
  7. ModuleCategory: parser
  8. ModuleClassName: blcYouTubeIframe
  9. ModuleContext: on-demand
  10. ModuleLazyInit: true
  11. ModulePriority: 120
  12. */
  13. if ( !class_exists('blcEmbedParserBase') ){
  14. require 'embed-parser-base.php';
  15. }
  16. class blcYouTubeIframe extends blcEmbedParserBase {
  17. var $supported_formats = array('html');
  18. function init(){
  19. parent::init();
  20. $this->short_title = __('YouTube Video', 'broken-link-checker');
  21. $this->long_title = __('Embedded YouTube video', 'broken-link-checker');
  22. $this->url_search_string = 'youtube.com/embed/';
  23. }
  24. /**
  25. * Extract embedded elements from a HTML string.
  26. *
  27. * Returns an array of IFrame elements found in the input string.
  28. * Elements without a 'src' attribute are skipped.
  29. *
  30. * Each array item has the same basic structure as the array items
  31. * returned by blcUtility::extract_tags(), plus an additional 'embed_code' key
  32. * that contains the full HTML code for the entire <ifram> tag.
  33. *
  34. * @uses blcUtility::extract_tags() This function is a simple wrapper around extract_tags()
  35. *
  36. * @param string $html
  37. * @return array
  38. */
  39. function extract_embeds($html){
  40. $results = array();
  41. //remove all <code></code> blocks first
  42. $html = preg_replace('/<code[^>]*>.+?<\/code>/si', ' ', $html);
  43. //Find likely-looking <object> elements
  44. $iframes = blcUtility::extract_tags($html, 'iframe', false, true);
  45. foreach($iframes as $embed){
  46. if ( empty($embed['attributes']['src']) ){
  47. continue;
  48. }
  49. $embed['embed_code'] = $embed['full_tag'];
  50. $results[] = $embed;
  51. }
  52. return $results;
  53. }
  54. function link_url_from_src($src){
  55. //Extract video ID from the SRC. The ID is always 11 characters.
  56. $video_id = substr( end(explode('/', $src)), 0, 11 );
  57. //Reconstruct the video permalink based on the ID
  58. $url = 'http://www.youtube.com/watch?v='.$video_id;
  59. return $url;
  60. }
  61. }
  62. ?>