Advertisement
Guest User

Catconvert plugin

a guest
Feb 22nd, 2015
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.67 KB | None | 0 0
  1. // support for
  2. // - Default Wordpress behavior without any wordpress plugin,
  3. // - Smart Youtube PRO
  4. // - YouTube
  5. // - Advanced YouTube Embed by Embed Plus
  6. foreach ($iframes as $iframe) {
  7. $url = $iframe->getAttribute('src');
  8. $videoId = $this->get_youtube_id_from_url($url);
  9.  
  10. $containerElement = $dom->createElement('div');
  11. $containerClassAttribute = $this->createAttribute($dom, 'class', $containerCssClass);
  12. $containerElement->appendChild($containerClassAttribute);
  13.  
  14. $linkElement = $dom->createElement('a', $linkText);
  15. $linkClassAttribute = $this->createAttribute($dom, 'class', $linkCssClass);
  16. $linkElement->appendChild($linkClassAttribute);
  17.  
  18. $linkNoFollowAttribute = $this->createAttribute($dom, 'rel', 'nofollow');
  19. $linkElement->appendChild($linkNoFollowAttribute);
  20.  
  21. $linkTargetAttribute = $this->createAttribute($dom, 'target', '_blank');
  22. $linkElement->appendChild($linkTargetAttribute);
  23.  
  24. $Youtube2mp3Url = "http://www.yt-mp3.com/?url=http://www.youtube.com/watch?v=".$videoId;
  25. $linkHrefAttribute = $this->createAttribute($dom, 'href', $Youtube2mp3Url);
  26. $linkElement->appendChild($linkHrefAttribute);
  27.  
  28. $containerElement->appendChild($linkElement);
  29.  
  30. if($iframe->parentNode->nodeName != 'object'){
  31. $iframe->parentNode->appendChild($containerElement);
  32. }else{
  33. $iframe->parentNode->parentNode->appendChild($containerElement);
  34. }
  35. }
  36.  
  37. // support for
  38. // - viper plugin
  39. $iframes = $xpath->query("//span[contains(@class,'vvqbox')]/span/a ");
  40. foreach ($iframes as $iframe) {
  41. $url = $iframe->getAttribute('href');
  42. $videoId = $this->get_youtube_id_from_url($url);
  43.  
  44. $containerElement = $dom->createElement('div');
  45. $containerClassAttribute = $this->createAttribute($dom, 'class', $containerCssClass);
  46. $containerStyleAttribute = $this->createAttribute($dom, 'style', 'margin-top: -7px;');
  47. $containerElement->appendChild($containerStyleAttribute);
  48. $containerElement->appendChild($containerClassAttribute);
  49.  
  50. $linkElement = $dom->createElement('a', $linkText);
  51. $linkClassAttribute = $this->createAttribute($dom, 'class', $linkCssClass);
  52. $linkElement->appendChild($linkClassAttribute);
  53.  
  54. $linkNoFollowAttribute = $this->createAttribute($dom, 'rel', 'nofollow');
  55. $linkElement->appendChild($linkNoFollowAttribute);
  56.  
  57. $linkTargetAttribute = $this->createAttribute($dom, 'target', '_blank');
  58. $linkElement->appendChild($linkTargetAttribute);
  59.  
  60. $Youtube2mp3Url = "http://www.youtube-mp3.org/get?video_id=".$videoId;
  61. $linkHrefAttribute = $this->createAttribute($dom, 'href', $Youtube2mp3Url);
  62. $linkElement->appendChild($linkHrefAttribute);
  63.  
  64. $containerElement->appendChild($linkElement);
  65.  
  66. $iframe->parentNode->parentNode->appendChild($containerElement);
  67. }
  68.  
  69. return utf8_decode($dom->saveHTML());
  70. }
  71.  
  72. function createAttribute($dom, $name, $value){
  73. $attribute = $dom->createAttribute($name);
  74. $attribute->value = $value;
  75. return $attribute;
  76. }
  77.  
  78. function get_youtube_id_from_url($url)
  79. {
  80. if (preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $url, $match)) {
  81. return $match[1];
  82. }
  83. }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement