Public feed #381523

Something

public php v1 · immutable
Raw Edit
·published 2007-03-04 22:30 UTC
rendered paste body
<?php  /*   Plugin Name: MyTube Thumbnail   Plugin URI: http:/www.markchaney.com/category/wp-plugins/   Description: Fetches YouTube thumbnail from MyTube video post.   Author: MACscr   Version: 1.0   Author URI: http:/www.markchaney.com   */      function macscr_create_thumb($video_id)  {      $url = 'http://www.youtube.com/api2_rest?method=youtube.videos.get_details&dev_id=rG48P7iz0eo&video_id=' . $video_id . '';            $curl_handle = curl_init();      curl_setopt($curl_handle, CURLOPT_URL, $url);      curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);      curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);      $buffer = curl_exec($curl_handle);      curl_close($curl_handle);            if (empty($buffer)) {          print "Sorry, video unavailable";      } else {          $youtube_XML = $buffer;                    $begin = strpos($youtube_XML, '<thumbnail_url>');          $end = strpos($youtube_XML, '</thumbnail_url>', $begin);                    if ($begin !== false && $end !== false) {              // numbers may be wrong, change them if you get wrong URL.              $thumbnail_url = substr($youtube_XML, $begin + 15, $end - $begin - 15);          }                    $thumbnail_path = '' . get_option('upload_path') . '/ytube_thumbs/';          $upload_path = ABSPATH . $thumbnail_path;                    $thumbnail_image = '' . $video_id . '.jpg';                    if (!copy($thumbnail_url, $upload_path . $thumbnail_image)) {              $thumb_final = '<img class="mytube_thumb" src="' . get_bloginfo('url') . '/wp-content/plugins/mytube_thumb/images/nothumb.gif" alt="Thumbnail Unavailable" />';          } else {              $thumb_final = '<img class="mytube_thumb" src="' . get_bloginfo('url') . '/' . $thumbnail_path . $thumbnail_image . '" alt="" /> ';          }      }      return $thumb_final;  }     function macscr_get_thumbnail($video_id)  {      $thumbnail_path = '' . get_option('upload_path') . '/ytube_thumbs/';      $upload_path = ABSPATH . $thumbnail_path;            $thumbnail_image = '' . $video_id . '.jpg';            if (file_exists($upload_path . $thumbnail_image)) {          $thumb_final = '<img class="mytube_thumb" src="' . get_bloginfo('url') . '/' . $thumbnail_path . $thumbnail_image . '" alt="" /> ';           $thumb_final;      } else {          return macscr_create_thumb($video_id);      }  }  function macscr_video_id($leftdelim, $rightdelim, $content)  {      $begin = strpos($content, $leftdelim);      $end = strpos($content, $rightdelim, $begin);           if ($begin !== false && $end !== false) {          // numbers may be wrong, change them if you get wrong URL.          $video_id = substr($content, $begin + 15, $end - $begin - 15);          return $video_id;      }  }    function macscr_add_thumbnail($content)  {      $leftdelim ='<!--yt_video-->';      $rightdelim = '<!--/yt_video-->';      $video_id = macscr_video_id($leftdelim, $rightdelim, $content);	  global $mytube_thumb;      $mytube_thumb = "test";            return str_replace($leftdelim.$video_id.$rightdelim, '<!--'.$video_id.'-->', $content);  }   add_filter('the_excerpt', 'macscr_add_thumbnail', $priority = '1');?>