Modified WP plugin for image_src tag

Original script from http://www.fedmich.com/tools/facebook-and-digg-thumbnail-generator/
by Fedmich

Modified by Victor on 2011-02-06
– this is what I’m using now
– currently the script grabs all images from the content and prints multiple lines of <link rel=”image_src” href= …> tags.

<?php
/*

Plugin Name: Facebook and Digg Thumbnail generator
Plugin URI: http://www.fedmich.com/tools/facebook-and-digg-thumbnail-generator
Description: This plugin will automatically add meta tags on the HEAD section of a post which will be used by Facebook and Digg as the share preview. And will also enhance
Author: Fedmich
Author URI: http://www.fedmich.com/tools/category/tools/wordpress
Version: 1.4
*/

define(“FBTHU_VERSION”, “1.4”);

function fbthu_social_img() {

global $post;
if (is_single () or is_page()){
//$this_image = get_post_meta($post->ID, ‘thumbnail’, true);
//if($this_image){
//    $image[] = get_post_meta($post->ID, ‘post_image’, true);
//}
//unset($this_image);
//$this_image = get_post_meta($post->ID, ‘post_image’, true);
//if($this_image){
//    $image[] = get_post_meta($post->ID, ‘post_image’, true);
//}
preg_match_all(‘/<img.*src=”(.*?)”/i’,$post->post_content,$m);
if (isset($m[1])){
foreach ($m[1] as $i => $value) {
$image[] = $value;
}
}

//print_r($m);
//preg_match(‘@www.(youtube-nocookie|youtube).com/v/(.*?)&@i’,$post->post_content,$m);
//$yt_id = isset($m[2])?$m[2]:”;
//if(! $yt_id){
//    if($image){
//        // check pattern against a youtube image
//        preg_match(‘@\.ytimg\.com/vi/(.*?)/.*\.jpg@i’,$image,$m);
//        $yt_id = isset($m[1])?$m[1]:”;
//    }
//}

//if($yt_id){
//    $yt_id = explode(‘?’,$yt_id);
//    $yt_id = $yt_id[0];
//
//    $yt_id = explode(‘&’,$yt_id);
//    $yt_id = $yt_id[0];
//
//}
//if($yt_id){
//    $video_src = “http://www.youtube.com/v/$yt_id&hl=en&fs=1&rel=0&autoplay=1″;
//}
//else{
//    $video_src = ”;
//}

echo “<!– fedmich facebook/digg thumbnail v”.FBTHU_VERSION.” –>\r\n”;

if($image){
foreach ($image as $i => $value) {
echo ‘<link rel=”image_src” href=”‘.$value.'” />’.”\r\n”;
}
}
else{
if($yt_id){
$image = “http://i4.ytimg.com/vi/$yt_id/default.jpg”;
echo ‘<link rel=”image_src” href=”‘.$image.'” />’.”\r\n”;
$image = “http://i4.ytimg.com/vi/$yt_id/0.jpg”;
echo ‘<link rel=”image_src” href=”‘.$image.'” />’.”\r\n”;
$image = “http://i4.ytimg.com/vi/$yt_id/1.jpg”;
echo ‘<link rel=”image_src” href=”‘.$image.'” />’.”\r\n”;
$image = “http://i4.ytimg.com/vi/$yt_id/2.jpg”;
echo ‘<link rel=”image_src” href=”‘.$image.'” />’.”\r\n”;
}
}

if($video_src){
echo ‘<link rel=”video_src” href=”‘.$video_src.'” />’.”\r\n”;
}
echo “<!– /fedmich facebook/digg thumbnail –>\r\n”;
}
}
add_action(‘wp_head’, ‘fbthu_social_img’);

function set_plugin_meta($links, $file) {
$plugin = plugin_basename(__FILE__);
if ($file == $plugin) {
return array_merge( $links, array( sprintf( ‘<a target=”_blank” href=”http://www.fedmich.com/tools/facebook-and-digg-thumbnail-generator”>%s</a>’, __(‘Help and FAQ’) ) ));
}
return $links;
}
add_filter( ‘plugin_row_meta’, ‘set_plugin_meta’, 10, 2 );

?>