Media enclosure addon for Autoblog

Hi,

Has anyone written a media enclosure addon for Autoblog?

I am looking to locally cache the second image found in a feed (first image is a thumbnail, second is the larger image). Then set that larger second image as featured.

For example,

http://www.guardian.co.uk/sport/nottinghamshire/rss

  • aecnu

    Greetings ballsmania,

    Welcome to WPMU Dev!

    Thank you for the great question about the media enclosure and the answer to the best of my knowledge is no it has not yet been done but I do recall something mentioned about it in the recent past.

    Of course the major authority on this and if it is ever going to happen will be delegated and in the confidence of the lead developer.

    Therefore I will see if I can get the lead developer in here with his invaluable insight into this plugin for his advice/advise for us.

    Though this may take a bit longer then a normal ticket, I will try to get him in here asap.

    Cheers, Joe

  • ballsmania
    class A_EnclosureCacheAddon {
    
    	function __construct() {
    		add_action( 'autoblog_post_post_insert', array(&$this, 'process_enclosure'), 10, 3 );
    	}
    
    	function A_EnclosureCacheAddon() {
    		$this->__construct();
    	}
    
    	function process_enclosure( $post_data, $ablog, $item ) {
    
    		require_once( ABSPATH . 'wp-admin/includes/file.php' );
    		require_once( ABSPATH . 'wp-admin/includes/media.php' );
    		set_time_limit(300);
    
    		extract($post_data);
    
    		// get first enclosure item
                    $enclosure = $item->get_enclosure(0,1);
    		$desc = "Enclosure-1";
    	        update_post_meta( $post_ID , 'enclosure-1', $enclosure->get_link() );
                    $img = media_sideload_image($image, $post_ID, $desc);
    
    		// get second enclosure item
                    $enclosure = $item->get_enclosure(1,1);
    		$desc = "Enclosure-2";
    	        update_post_meta( $post_ID , 'enclosure-2', $enclosure->get_link() );
    		$img = media_sideload_image($image, $post_ID, $desc);
    
    	}
    }
    
    $aenclosurecacheaddon = new A_EnclosureCacheAddon();
  • aecnu

    Greetings David,

    Thank you for your additional coding and we appreciate the effort to build your "enclosure" add on.

    I admit that I cannot help you due to the fact that I am not a coder, and perhaps Barry will though it is far beyond the mandate of this forum but I am not qualified to make that decision.

    I have responded here so you know that you are not being ignored and to thank you for working on this add on and I hope all your efforts to be fruitful.

    Cheers, Joe

  • ballsmania

    Hi. I've got something more or less working.

    class A_EnclosureCacheAddon {
    
    	function __construct() {
    
    		add_action( 'autoblog_post_post_insert', array(&$this, 'process_enclosure'), 10, 3 );
    	}
    
    	function A_EnclosureCacheAddon() {
    		$this->__construct();
    	}
    
    	function process_enclosure( $post_ID, $ablog, $item ) {
    
    		require_once( ABSPATH . 'wp-admin/includes/file.php' );
    		require_once( ABSPATH . 'wp-admin/includes/media.php' );
    
    		set_time_limit(300);
    
    		// get first enclosure item
                    $enclosure = $item->get_enclosure(0,1);
    		$desc = "Enclosure-1";
                    $image = $enclosure->get_link();
    	        update_post_meta( $post_ID , 'enclosure-1', $enclosure->get_link() );
                    $img = media_sideload_image($image, $post_ID, $desc);
    
    		// get second enclosure item
                    $enclosure = $item->get_enclosure(1,1);
    		$desc = "Enclosure-2";
    		$image = $enclosure->get_link();
    	        update_post_meta( $post_ID , 'enclosure-2', $enclosure->get_link() );
    		$img = media_sideload_image($image, $post_ID, $desc);
    
    		// Returning the $post_ID even though it's an action and we really don't need to
    		return $post_ID;
    	}
    }
    
    $aenclosurecacheaddon = new A_EnclosureCacheAddon();
    
    ?>
  • ballsmania

    This add-on grabs the second media enclosure image then assigns the image as the featured image.

    <?php
    /*
    Addon Name: Import enclosure images
    Description: Experimental rss enclosure importer - attaches images to posts.
    Author: David Smith
    Author URI: http://www.ballsmania.com
    */
    
    class A_EnclosureCacheAddon {
    
    	function __construct() {
    
    		add_action( 'autoblog_post_post_insert', array(&$this, 'process_enclosure'), 10, 3 );
    	}
    
    	function A_EnclosureCacheAddon() {
    		$this->__construct();
    	}
    
    	function process_enclosure( $post_ID, $ablog, $item ) {
    
    		require_once( ABSPATH . 'wp-admin/includes/file.php' );
    		require_once( ABSPATH . 'wp-admin/includes/media.php' );
    
    		set_time_limit(300);
    
    		// get second enclosure item
                 	$enclosure = $item->get_enclosure(1,1);
    		$desc = $enclosure->get_description();
    		$image = $enclosure->get_link();
    	        update_post_meta( $post_ID , 'enclosure-2', $enclosure->get_link() );
    		$img = media_sideload_image($image, $post_ID, $desc);
    
    		// find the last image added to the post attachments
    		$attachments = get_posts(array(	'numberposts' => '1',
    						'post_parent' =>     $post_ID,
    						'post_type' => 'attachment',
    						'post_mime_type' => 'image',
    						'order' => 'ASC'));
    
                    // set last image added as featured image
    		set_post_thumbnail($post_ID, $attachments[0]->ID);  
    
    		// Returning the $post_ID even though it's an action and we really don't need to
    		return $post_ID;
    	}
    }
    
    $aenclosurecacheaddon = new A_EnclosureCacheAddon();
    
    ?>
  • ballsmania

    The code above grabs the second enclosure item and also sets it as featured image. If you want to grab the first enclosure item and set that as featured replace line 36/37 with

    $enclosure = $item->get_enclosure(0,1);

    The first number in brackets is the get_enclosure start position (0 = first, 1 = second etc), and the second number is how many results to return. In this case we only want one image retuned. In my case I wanted the second image as that's the largest version on The Guardian news feed.

    Hope that makes sense.

  • PC

    Hiya,

    Greetings and thanks for being a great community member.

    We haven't heard from you on this one for long and I am doing a regular followup to see if there is still something we can assist you on this thread.

    Just to manage the support issues more efficiently, I am marking this thread as resolved for now however this is not being done to avoid your questions in any ways.

    Please feel free to mark this is "Not resolved" in case you have further questions and we would be back on it.

    Thanks a lot for being with WPMU DEV.

    Cheers
    PC
    Sales &Support

    Did you know we offer FREE lifetime memberships? Click here to learn more.

  • aristath

    Hello there @Daniel, I hope you're well today!

    This is an almost 3-year-old thread... and it doesn't look like the query on your above comment has anything to do with the original post.

    Can you please create a new post instead of commenting here so that we may better assist you and keep threads a bit organised?

    P.S. I'm also closing this thread to future comments since the original poster as well as other commenters on this thread are no longer active members on these forums and I don't think they would appreciate getting emails constantly from a 2-3 year old post.

    Cheers,
    Ari.