/**
 * Get details about a specific video by GUID:
 *
 * @param $guid string
 * @return object
 */
function videopress_get_video_details($guid)
{
    if (!videopress_is_valid_guid($guid)) {
        return new WP_Error('bad-guid-format', __('Invalid Video GUID!', 'jetpack'));
    }
    $version = '1.1';
    $endpoint = sprintf('/videos/%1$s', $guid);
    $query_url = sprintf('https://public-api.wordpress.com/rest/v%1$s%2$s', $version, $endpoint);
    // Look for data in our transient. If nothing, let's make a new query.
    $data_from_cache = get_transient('jetpack_videopress_' . $guid);
    if (false === $data_from_cache) {
        $response = wp_remote_get(esc_url_raw($query_url));
        $data = json_decode(wp_remote_retrieve_body($response));
        // Cache the response for an hour.
        set_transient('jetpack_videopress_' . $guid, $data, HOUR_IN_SECONDS);
    } else {
        $data = $data_from_cache;
    }
    /**
     * Allow functions to modify fetched video details.
     *
     * This filter allows third-party code to modify the return data
     * about a given video.  It may involve swapping some data out or
     * adding new parameters.
     *
     * @since 4.0.0
     *
     * @param object $data The data returned by the WPCOM API. See: https://developer.wordpress.com/docs/api/1.1/get/videos/%24guid/
     * @param string $guid The GUID of the VideoPress video in question.
     */
    return apply_filters('videopress_get_video_details', $data, $guid);
}
/**
 * Get details about a specific video by GUID:
 *
 * @param $guid string
 * @return object
 */
function videopress_get_video_details($guid)
{
    if (!videopress_is_valid_guid($guid)) {
        return new WP_Error('bad-guid-format', __('Invalid Video GUID!', 'jetpack'));
    }
    $version = '1.1';
    $endpoint = sprintf('/videos/%1$s', $guid);
    $response = wp_remote_get(sprintf('https://public-api.wordpress.com/rest/v%1$s%2$s', $version, $endpoint));
    $data = json_decode(wp_remote_retrieve_body($response));
    /**
     * Allow functions to modify fetched video details.
     *
     * This filter allows third-party code to modify the return data
     * about a given video.  It may involve swapping some data out or
     * adding new parameters.
     *
     * @since 4.0.0
     *
     * @param object $data The data returned by the WPCOM API. See: https://developer.wordpress.com/docs/api/1.1/get/videos/%24guid/
     * @param string $guid The GUID of the VideoPress video in question.
     */
    return apply_filters('videopress_get_video_details', $data, $guid);
}
Exemple #3
0
/**
 * Translate a 'videopress' or 'wpvideo' shortcode and arguments into a video player display.
 *
 * Expected input formats:
 *
 * [videopress OcobLTqC]
 * [wpvideo OcobLTqC]
 *
 * @link http://codex.wordpress.org/Shortcode_API Shortcode API
 * @param array $attr shortcode attributes
 * @return string HTML markup or blank string on fail
 */
function videopress_shortcode_callback($attr)
{
    global $content_width;
    /**
     * We only accept GUIDs as a first unnamed argument.
     */
    $guid = $attr[0];
    /**
     * Make sure the GUID passed in matches how actual GUIDs are formatted.
     */
    if (!videopress_is_valid_guid($guid)) {
        return '';
    }
    /**
     * Set the defaults
     */
    $defaults = array('w' => 0, 'at' => 0, 'hd' => true, 'loop' => false, 'freedom' => false, 'autoplay' => false, 'permalink' => true, 'flashonly' => false, 'defaultlangcode' => false);
    $attr = shortcode_atts($defaults, $attr, 'videopress');
    /**
     * Cast the attributes, post-input.
     */
    $attr['width'] = absint($attr['w']);
    $attr['hd'] = (bool) $attr['hd'];
    $attr['freedom'] = (bool) $attr['freedom'];
    /**
     * If the provided width is less than the minimum allowed
     * width, or greater than `$content_width` ignore.
     */
    if ($attr['width'] < VIDEOPRESS_MIN_WIDTH) {
        $attr['width'] = 0;
    } elseif (isset($content_width) && $content_width > VIDEOPRESS_MIN_WIDTH && $attr['width'] > $content_width) {
        $attr['width'] = 0;
    }
    /**
     * If there was an invalid or unspecified width, set the width equal to the theme's `$content_width`.
     */
    if (0 === $attr['width'] && isset($content_width) && $content_width >= VIDEOPRESS_MIN_WIDTH) {
        $attr['width'] = $content_width;
    }
    /**
     * If the width isn't an even number, reduce it by one (making it even).
     */
    if (1 === $attr['width'] % 2) {
        $attr['width']--;
    }
    /**
     * Filter the default VideoPress shortcode options.
     *
     * @module videopress
     *
     * @since 2.5.0
     *
     * @param array $args Array of VideoPress shortcode options.
     */
    $options = apply_filters('videopress_shortcode_options', array('at' => (int) $attr['at'], 'hd' => $attr['hd'], 'loop' => $attr['autoplay'] || $attr['loop'], 'freedom' => $attr['freedom'], 'autoplay' => $attr['autoplay'], 'permalink' => $attr['permalink'], 'force_flash' => (bool) $attr['flashonly'], 'defaultlangcode' => $attr['defaultlangcode'], 'forcestatic' => false));
    // Register VideoPress scripts
    wp_register_script('videopress', 'https://v0.wordpress.com/js/videopress.js', array('jquery', 'swfobject'), '1.09');
    require_once dirname(__FILE__) . '/class.videopress-video.php';
    require_once dirname(__FILE__) . '/class.videopress-player.php';
    $player = new VideoPress_Player($guid, $attr['width'], $options);
    if (is_feed()) {
        return $player->asXML();
    } else {
        return $player->asHTML();
    }
}
function videopress_media_send_to_editor($html, $id, $attachment)
{
    $videopress_guid = get_post_meta($id, 'videopress_guid', true);
    if ($videopress_guid && videopress_is_valid_guid($videopress_guid)) {
        if ('[video ' === substr($html, 0, 7)) {
            $replace = sprintf(' videopress_guid="%1$s"][/video]', esc_attr($videopress_guid));
            $html = str_replace('][/video]', $replace, $html);
        } elseif ('<a href=' === substr($html, 0, 8)) {
            // We got here because `wp_attachment_is()` returned false for
            // video, because there isn't a local copy of the file.
            $html = sprintf('[videopress %1$s]', esc_attr($videopress_guid));
        }
    }
    return $html;
}