post_content; //Get the urls out of the page preg_match_all("/href=\"(.*?)\"/", $contents, $matches); foreach($matches[1] as $link) { $pos = strpos($link, current_domain()); if ($pos == false) { $get_ext_link = $link; return $get_ext_link; break; } } //Do find external link in content END }else { if($gimg_external == 'gimg_autoblog') { if(get_post_meta($post_id, "external_link", true)) // for autoblogged { $get_ext_link = get_post_meta($post_id , "external_link", true); return $get_ext_link; } if(get_post_meta($post_id, "link", true)) // for autoblogged old { $get_ext_link = get_post_meta($post_id , "link", true); return $get_ext_link; } if(get_post_meta($post_id, "source", true)) // for WP robot { $get_ext_link = get_post_meta($post_id , "source", true); return $get_ext_link; } }else { if(get_post_meta($post_id, $gimg_custom_value, true)) // get Custom post meta Value to external link { $get_ext_link = get_post_meta($post_id , $gimg_custom_value, true); return $get_ext_link; } } } } // Look for external link redirect function redirec_url_link($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_NOBODY, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 10); $result = curl_exec($ch); if (preg_match("/Location\:/","$result")) { $url = explode("Location: ",$result); $reversed_url = explode("\r",$url[1]); return $reversed_url[0]; } else { return $url; // original print_r($result); } } //Scrap images function grab_pic($ext_url) { if( $ext_url ){ if( !strstr($ext_url,"http://") && !strstr($ext_url,"https://") ){ $ext_url = "http://".$ext_url; }} $text = @file_get_contents($ext_url); $motif='/src=[\'"]?([^\'" >]+(jpe?g|JPE?G|png|PNG))[\'"]?/im'; // Regex to Look for PNG or Jpeg image only, not gif preg_match_all($motif,$text,$out,PREG_PATTERN_ORDER); foreach ($out[1] as $link) { if( $link ){ if( !strstr($link,"http://") && !strstr($link,"https://") ){ $showhost = $ext_url; $showhost = parse_url($showhost); $link = "http://{$showhost['host']}/".$link; }} // Sometime the image url is not complete with base url and path //print_r ($link); list($width, $height, $type, $attr) = @getimagesize($link); if ($width > 124 and $height > 130 ) { //look for image equal or bigger than these value //echo $link.'
'; $img_link = $link; break; } } return $img_link; } //Scrap images end function upload_featured($img_url,$post_id) { //Find upload directory $upload_dir = wp_upload_dir(); $upload_dir_base = $upload_dir['baseurl']; //Find upload directory done $path_parts = pathinfo($img_url); $filename = $path_parts['basename']; $file = $img_url; //$newfile = ''.$upload_dir_base.'/'.$filename.''; $newfile = 'wp-content/uploads/'.$filename.''; if (!copy($file, $newfile)) { echo "failed to copy $file...\n"; } $wp_filetype = wp_check_filetype(basename($newfile), null ); $attachment = array( 'post_mime_type' => $wp_filetype['type'], 'post_title' => preg_replace('/\.[^.]+$/', '', basename($newfile)), 'post_content' => '', 'post_status' => 'inherit' ); $attach_id = wp_insert_attachment( $attachment, $newfile, $post_id ); require_once(ABSPATH . 'wp-admin/includes/image.php'); $attach_data = wp_generate_attachment_metadata( $attach_id, $newfile ); wp_update_attachment_metadata( $attach_id, $attach_data ); update_post_meta( $post_id, '_thumbnail_id', $attach_id ); // Make thumbs post-thumbnail or Featured $full_img_url = get_bloginfo('url').'/'.$newfile; update_post_meta( $post_id, 'gc_thumb', $full_img_url ); // Add a custom field of img url //update_post_meta( $post_id, 'gc_thumb_checked', 'checked' ); // look at this custom field to not run script if image was previousely not found // Add image in Post $gimg_in_post = get_option('gimg_in_post'); $gimg_class = get_option('gimg_class'); if($gimg_in_post == 'checked') { if (!empty($gimg_class)) { // Continu if external url exist $class = $gimg_class; } else { $class = 'alignleft'; } $title = get_the_title($post_id); $queried_post = get_post($post_id); $contents = $queried_post->post_content; $img_url = ''; $update_content = $img_url.''. $contents; $my_post = array( 'ID' => $post_id, 'post_title' => $title, 'post_content' => $update_content, //'post_status' => 'publish', //'post_author' => 1, //'post_category' => array(8,39) ); // Insert the post into the database wp_update_post( $my_post ); } // Add image in Post END } // Upload image as featured end ?>

Options Saved

'; } $gimg_external = get_option('gimg_external'); $gimg_custom_value = get_option('gimg_custom_value'); $gimg_custom_value = trim($gimg_custom_value); $gimg_in_post = get_option('gimg_in_post'); $gimg_class = get_option('gimg_class'); ?>
'.$message.'

Add image to Post Settings

'?>
';?>

External links (Source to find images)

type="radio" name="gimg_external" value="gimg_autoblog" /> External link from Autoblogged / WP robot (If it doesn't work, try custom field)
type="radio" name="gimg_external" value="gimg_content" /> External link from post content (Find the first external link in blog content)
type="radio" name="gimg_external" value="gimg_custom" /> Custom field: (Do your blog already have a custom field to external link?) *help

Image in post options

type="checkbox" name="gimg_in_post" value="checked" /> Insert image in post (added at the top)

Enter your own image css class (alignleft)
Settings'; return array_merge($links,$new_links ); } ?>