WordPress.org

Plugin Directory

Changeset 676261


Ignore:
Timestamp:
03/04/13 23:43:09 (5 years ago)
Author:
distrify
Message:

update to 0.3

Location:
distrify-embed/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • distrify-embed/trunk/readme.txt

    r446676 r676261  
    22Contributors: distrify 
    33Donate link: http://distrify.com/ 
    4 Tags: video, movies, embed, share 
     4Tags: video, movies, embed, share, distrify, muvies 
    55Requires at least: 2.9.0 
    6 Tested up to: 3.2.1 
     6Tested up to: 3.5.1 
    77Stable tag: trunk 
    88 
    9 Extends Wordpress's Embeds allowing bloggers to easily embed movie trailers from Distrify. 
     9Extends WordPress's Embeds allowing bloggers to easily embed movie trailers from Distrify. 
    1010 
    1111== Description == 
    1212 
    13 Extends Wordpress's [Embeds](http://codex.wordpress.org/Embeds "Wordpress Embeds") allowing bloggers to easily embed videos from Distrify. Just go to the Distrify film page and copy the URL. Paste that URL in any Wordpress blog and it will automatically be converted to an embedded Distrify player. If you are logged in to [distrify.com](http://distrify.com/) it will automatically add your affiliate tracking code to your embeds. Make sure you turn on Auto-embeds in your WP settings and also make sure that the URL is on its own line and not hyperlinked (clickable when viewing the post). 
     13Extends WordPress's [Embeds](http://codex.wordpress.org/Embeds "WordPress Embeds") allowing bloggers to easily embed videos from Distrify. Just go to any Distrify film page or player and copy the URL. Paste that URL in any WordPress blog and it will automatically be converted to an embedded Distrify player. If you are logged in to [distrify.com](http://distrify.com/) it will automatically add your affiliate tracking code to your embeds. Make sure you turn on Auto-embeds in your WP settings and also make sure that the URL is on its own line and not hyperlinked (clickable when viewing the post). 
     14 
     15The plugin also extracts the still image from the film and saves it as the [Featured Image](http://codex.wordpress.org/Post_Thumbnails "WordPress Featured Images") for the post. This actually works for any Embed (not just Distrify) that you embed into your WordPress blog. 
    1416 
    1517== Installation == 
     
    4244= Can I embed a Distrify player on a blog hosted on WordPress.COM? = 
    4345 
    44 Currently the "hosted" version of WordPress does not support many external embeds and won't let you install themes or plugins. If you're using the WordPress.com service, why not move your blog to a different host? Or you can ask them to support the Distrify player: http://en.support.wordpress.com/contact/ 
     46Currently the "hosted" version of WordPress does not support many external embeds and won't let you install themes or plugins. If you're using the WordPress.com service, why not move your blog to a different host?  
     47Or you can ask WordPress to support the Distrify player Embed. Contact WordPress here: http://en.support.wordpress.com/contact/ 
     48 
     49= Where can I find more films to embed? = 
     50 
     51Have a look at the films on [muvies.com](http://muvies.com/ "Muvies") 
    4552 
    4653== Screenshots == 
     
    5057 
    5158== Changelog == 
     59 
     60= 0.3 =  
     61* Added support for muvies.com URLs and for URLs from Muvies collections. 
     62* Save Featured Image to the post (affects all WordPress Embeds, not just Distrify). 
    5263 
    5364= 0.2 =  
  • distrify-embed/trunk/wp_distrify.php

    r446676 r676261  
    33Plugin Name: Distrify Embed 
    44Plugin URI: http://www.distrify.com 
    5 Description: Extends Wordpress's <a href="http://codex.wordpress.org/Embeds">Embeds</a> allowing bloggers to easily embed videos from Distrify. Just go to the Distrify film page and copy the URL. Paste that URL in any Wordpress blog and it will automatically be converted to an embedded Distrify player. If you are logged in to http://www.distrify.com it will automatically add your affiliate tracking code to your embeds. Make sure you turn on Auto-embeds in your WP settings and also make sure that the URL is on its own line and not hyperlinked (clickable when viewing the post). 
     5Description: Extends WordPress's [Embeds](http://codex.wordpress.org/Embeds "WordPress Embeds") allowing bloggers to easily embed videos from Distrify. Just go to any Distrify film page or player and copy the URL. Paste that URL in any WordPress blog and it will automatically be converted to an embedded Distrify player. If you are logged in to [distrify.com](http://distrify.com/) it will automatically add your affiliate tracking code to your embeds. Make sure you turn on Auto-embeds in your WP settings and also make sure that the URL is on its own line and not hyperlinked (clickable when viewing the post). The plugin also extracts the still image from the film and saves it as the [Featured Image](http://codex.wordpress.org/Post_Thumbnails "WordPress Featured Images") for the post. This actually works for any Embed (not just Distrify) that you embed into your WordPress blog. 
    66Author: Distrify Limited 
    7 Version: 0.2 
     7Version: 0.3 
    88Author URI: http://www.distrify.com 
    99License: GPL2 
    1010 
    11 Copyright 2011  Distrify  (email : hello@distrify.com) 
     11Copyright 2011-2013  Distrify  (email : hello@distrify.com) 
    1212 
    1313This program is free software; you can redistribute it and/or modify 
     
    3131function add_distrify_provider($the_content){ 
    3232    require_once( ABSPATH . WPINC . '/class-oembed.php' ); 
    33     //$oembed = _wp_oembed_get_object(); 
    34     //$oembed->providers = array();  
    35   wp_oembed_add_provider('#http://(www\.)?distrify.com/films/.*#i', 'http://distrify.com/oembed.json', true ); 
    36   wp_oembed_add_provider('#https://(www\.)?distrify.com/films/.*#i', 'http://distrify.com/oembed.json', true );  
     33  wp_oembed_add_provider('#https?://(www\.)?(distrify|muvies).com/films/.*#i', 'http://distrify.com/oembed.json', true );    
    3734  wp_oembed_add_provider('http://muvi.es/*', 'http://distrify.com/oembed.json' );    
     35  wp_oembed_add_provider('#https?://.*\.muvies.com/.*reviews/.*#i', 'http://distrify.com/oembed.json', true );   
    3836} 
    3937//add the provider on plugins_loaded. 
    4038add_action('plugins_loaded', 'add_distrify_provider'); 
    4139 
     40 
     41/** 
     42 * from http://wordpress.stackexchange.com/q/70752/1685 
     43 * Automatically set the featured image if an oEmbed-compatible embed is found in the post content. 
     44 * author: TheDeadMedic 
     45 * author URI: http://wordpress.stackexchange.com/users/1685/thedeadmedic 
     46 * 
     47 */ 
     48 
     49add_action( 'wp_insert_post', array( 'ofi', 'init' ) ); 
     50 
     51class ofi 
     52{ 
     53    /** 
     54     * The post thumbnail ID 
     55     * 
     56     * @var int 
     57     */ 
     58    private $_thumb_id; 
     59 
     60    /** 
     61     * The post ID 
     62     * 
     63     * @var int 
     64     */ 
     65    private $_post_id; 
     66 
     67    /** 
     68     * Sets up an instance if called statically, and attempts to set the featured 
     69     * image from an embed in the post content (if one has not already been set). 
     70     * 
     71     * @param  int $post_id 
     72     * @return object|null 
     73     */ 
     74    public function init( $post_id ) 
     75    { 
     76        if ( ! isset( $this ) ) 
     77            return new ofi( $post_id ); 
     78 
     79        global $wp_embed; 
     80 
     81        $this->_post_id = absint( $post_id ); 
     82 
     83        if ( ! $this->_thumb_id = get_post_meta( $this->_post_id, '_thumbnail_id', true ) ) { 
     84            if ( $content = get_post_field( 'post_content', $this->_post_id, 'raw' ) ) { 
     85 
     86                add_filter( 'oembed_dataparse', array( $this, 'oembed_dataparse' ), 10, 3 ); 
     87                $wp_embed->autoembed( $content ); 
     88                remove_filter( 'oembed_dataparse', array( $this, 'oembed_dataparse' ), 10, 3 ); 
     89 
     90            } 
     91        } 
     92    } 
     93 
     94    /** 
     95     * @see init() 
     96     */ 
     97    public function __construct( $post_id ) 
     98    { 
     99        $this->init( $post_id ); 
     100    } 
     101 
     102    /** 
     103     * Callback for the "oembed_dataparse" hook, which will fire on a successful 
     104     * response from the oEmbed provider. 
     105     * 
     106     * @see WP_oEmbed::data2html() 
     107     * 
     108     * @param string $return The embed HTML 
     109     * @param object $data   The oEmbed response 
     110     * @param string $url    The oEmbed content URL 
     111     */ 
     112    public function oembed_dataparse( $return, $data, $url ) 
     113    { 
     114        if ( ! empty( $data->thumbnail_url ) && ! $this->_thumb_id ) { 
     115            // if ( in_array( @ $data->type, array( 'video' ) ) ) // Only set for video embeds 
     116                $this->set_thumb_by_url( $data->thumbnail_url, @ $data->title ); 
     117        } 
     118    } 
     119 
     120    /** 
     121     * Attempt to download the image from the URL, add it to the media library, 
     122     * and set as the featured image. 
     123     * 
     124     * @see media_sideload_image() 
     125     * 
     126     * @param string $url 
     127     * @param string $title Optionally set attachment title 
     128     */ 
     129    public function set_thumb_by_url( $url, $title = null ) 
     130    { 
     131        /* Following assets will already be loaded if in admin */ 
     132        require_once ABSPATH . 'wp-admin/includes/file.php'; 
     133        require_once ABSPATH . 'wp-admin/includes/media.php'; 
     134        require_once ABSPATH . 'wp-admin/includes/image.php'; 
     135 
     136        $temp = download_url( $url ); 
     137 
     138        if ( ! is_wp_error( $temp ) && $info = @ getimagesize( $temp ) ) { 
     139            if ( ! strlen( $title ) ) 
     140                $title = null; 
     141 
     142            if ( ! $ext = image_type_to_extension( $info[2] ) ) 
     143                $ext = '.jpg'; 
     144 
     145            $data = array( 
     146                'name'     => md5( $url ) . $ext, 
     147                'tmp_name' => $temp, 
     148            ); 
     149 
     150            $id = media_handle_sideload( $data, $this->_post_id, $title ); 
     151            if ( ! is_wp_error( $id ) ) 
     152                return update_post_meta( $this->_post_id, '_thumbnail_id', $this->_thumb_id = $id ); 
     153        } 
     154 
     155        if ( ! is_wp_error( $temp ) ) 
     156            @ unlink( $temp ); 
     157    } 
     158} 
     159 
    42160?> 
Note: See TracChangeset for help on using the changeset viewer.