Esempio n. 1
0
 public function get_data($url = '', $args = '')
 {
     if ($url) {
         $this->url = $url;
     }
     if (!$this->url) {
         return false;
     }
     //if it was already fetched
     if ($this->data) {
         return $this->data;
     }
     $provider = self::$oembed->get_provider($this->url, $args);
     if (!$provider) {
         return false;
     }
     $data = self::$oembed->fetch($provider, $this->url, $args);
     if (!$data) {
         return false;
     }
     $this->data = $data;
     return $this->data;
 }
Esempio n. 2
0
function ale_get_embed_video($url)
{
    require_once ABSPATH . WPINC . '/class-oembed.php';
    $WP_oEmbed = new WP_oEmbed();
    $provider = $WP_oEmbed->discover($url);
    $data = $WP_oEmbed->fetch($provider, $url);
    return $data;
}
Esempio n. 3
0
/**
 * Add Meta Keys for Fancybox Link & Embed for Video Posts 
 */
function orbitnews_fancy_video($post_ID)
{
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return;
    }
    if (get_post_status($post_ID) != 'publish') {
        return;
    }
    /* Delete Existing Metakeys */
    delete_post_meta($post_ID, '_orn_oembed_body');
    delete_post_meta($post_ID, '_orn_embed_link');
    // Video Formats
    $video_link = trim(get_post_meta($post_ID, "orn_oembed_videos", true));
    $video_format = has_post_format('video', $post_ID);
    // Video Type Embed
    if (!empty($video_link) && $video_format) {
        // Get Video Data with wordpress oembed class
        require_once ABSPATH . WPINC . '/class-oembed.php';
        $oembed = new WP_oEmbed();
        $provider = $oembed->discover($video_link);
        $data = $oembed->fetch($provider, $video_link);
        if (isset($data) && $data != false) {
            // Setup variables
            $provider = $data->provider_name;
            // Video Provider Name
            $html_embed = $data->html;
            // Video Embed html
            $thumb_link = $data->thumbnail_url;
            // Video Post Thumbnail
            preg_match('/<iframe.*src=\\"(.*)\\".*><\\/iframe>/isU', $html_embed, $url_embed);
            $url_embed = $url_embed[1];
            // Embed Url
            $filename = sanitize_title($data->title);
            // Create filename from video title
            //Set meta key with feteched video embed html
            update_post_meta($post_ID, '_orn_oembed_body', $html_embed);
            //Video link and thumbnail for video posts
            switch ($provider) {
                case 'YouTube':
                    $url_embed .= '&amp;showinfo=0&amp;iv_load_policy=3&amp;modestbranding=0&amp;nologo=1&amp;vq=large&amp;autoplay=1&amp;ps=docs&amp;wmode=opaque&amp;rel=0';
                    break;
                case 'Vimeo':
                    $thumb_link = str_replace('_295.jpg', '_640.jpg', $thumb_link);
                    break;
                default:
                    // do nothing;
                    break;
            }
            //end switch
            // Add Meta key with embed link
            update_post_meta($post_ID, '_orn_embed_link', $url_embed);
            if (!has_post_thumbnail($post_ID)) {
                //Fetch and Store the Image
                $remote_file = wp_remote_get($thumb_link, array('sslverify' => false));
                $file_type = wp_remote_retrieve_header($remote_file, 'content-type');
                // Get image type
                $filename .= '-' . rawurldecode(basename($thumb_link));
                // add image file name to file
                $local_file_url = wp_upload_bits($filename, '', $remote_file['body']);
                // save image in local server
                //Attachment options
                $attachment = array('post_title' => $filename, 'post_mime_type' => $file_type, 'post_content' => '', 'post_status' => 'inherit', 'ping_status' => 'closed');
                // Add the image to your media library and set as featured image
                $attach_id = wp_insert_attachment($attachment, $local_file_url['file'], $post_ID);
                $attach_data = wp_generate_attachment_metadata($attach_id, $local_file_url['file']);
                wp_update_attachment_metadata($attach_id, $attach_data);
                set_post_thumbnail($post_ID, $attach_id);
            }
            // end !has_post_thumbnail()
        }
        //end isset( $data )
    }
    //end $video_link empty
}
Esempio n. 4
0
/**
 * Import a video thumbnail from an oEmbed endpoint into the media library.
 *
 * @todo Considering doing video URL comparison rather than oembed thumbnail
 *       comparison?
 *
 * @since 1.8.0
 *
 * @param int $post_id Video post ID.
 * @param string $url Video URL.
 */
function audiotheme_video_sideload_thumbnail($post_id, $url)
{
    require_once ABSPATH . WPINC . '/class-oembed.php';
    $oembed = new \WP_oEmbed();
    $provider = $oembed->get_provider($url);
    if (!$provider || false === ($data = $oembed->fetch($provider, $url)) || !isset($data->thumbnail_url)) {
        return;
    }
    $current_thumb_id = get_post_thumbnail_id($post_id);
    $oembed_thumb_id = get_post_meta($post_id, '_audiotheme_oembed_thumbnail_id', true);
    $oembed_thumb_url = get_post_meta($post_id, '_audiotheme_oembed_thumbnail_url', true);
    // Re-use the existing oEmbed data instead of making another copy of the thumbnail.
    if ($data->thumbnail_url == $oembed_thumb_url && (!$current_thumb_id || $current_thumb_id != $oembed_thumb_id)) {
        set_post_thumbnail($post_id, $oembed_thumb_id);
    } elseif (!$current_thumb_id || $data->thumbnail_url != $oembed_thumb_url) {
        $attachment_id = audiotheme_video_sideload_image($data->thumbnail_url, $post_id);
        if (!empty($attachment_id) && !is_wp_error($attachment_id)) {
            set_post_thumbnail($post_id, $attachment_id);
            // Store the oEmbed thumb data so the same image isn't copied on repeated requests.
            update_post_meta($post_id, '_audiotheme_oembed_thumbnail_id', $attachment_id);
            update_post_meta($post_id, '_audiotheme_oembed_thumbnail_url', $data->thumbnail_url);
        }
    }
}