コード例 #1
0
/**
 * Returns embed code for a given video ID
 * @param string $video_id
 */
function cvm_video_embed($video_id)
{
    $options = cvm_get_player_settings();
    return sprintf('<iframe src="http://player.vimeo.com/video/%s?title=%d&amp;byline=%d&amp;portrait=%d&amp;color=%s" width="%d" height="%d" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>', $video_id, $options['title'], $options['byline'], $options['portrait'], $options['color'], $options['width'], cvm_player_height($options['aspect_ratio'], $options['width']));
}
コード例 #2
0
function cvm_output_playlist($videos = 'latest', $results = 5, $theme = 'default', $player_settings = array())
{
    global $CVM_POST_TYPE;
    $args = array('post_type' => $CVM_POST_TYPE->get_post_type(), 'posts_per_page' => absint($results), 'numberposts' => absint($results), 'post_status' => 'publish', 'supress_filters' => true);
    // if $videos is array, the function was called with an array of video ids
    if (is_array($videos)) {
        $ids = array();
        foreach ($videos as $video_id) {
            $ids[] = absint($video_id);
        }
        $args['include'] = $ids;
        $args['posts_per_page'] = count($ids);
        $args['numberposts'] = count($ids);
    } elseif (is_string($videos)) {
        $found = false;
        switch ($videos) {
            case 'latest':
                $args['orderby'] = 'post_date';
                $args['order'] = 'DESC';
                $found = true;
                break;
        }
        if (!$found) {
            return;
        }
    } else {
        // if $videos is anything else other than array or string, bail out
        return;
    }
    // get video posts
    $posts = get_posts($args);
    if (!$posts) {
        return;
    }
    $videos = array();
    foreach ($posts as $post_key => $post) {
        if (isset($ids)) {
            $key = array_search($post->ID, $ids);
        } else {
            $key = $post_key;
        }
        if (is_numeric($key)) {
            $videos[$key] = array('ID' => $post->ID, 'title' => $post->post_title, 'video_data' => get_post_meta($post->ID, '__cvm_video_data', true));
        }
    }
    ksort($videos);
    ob_start();
    // set custom player settings if any
    global $CVM_PLAYER_SETTINGS;
    if ($player_settings && is_array($player_settings)) {
        $defaults = cvm_get_player_settings();
        foreach ($defaults as $setting => $value) {
            if (isset($player_settings[$setting]) && !empty($player_settings[$setting])) {
                $defaults[$setting] = $player_settings[$setting];
            }
        }
        $CVM_PLAYER_SETTINGS = $defaults;
    }
    global $cvm_video;
    if (!array_key_exists($theme, cvm_playlist_themes())) {
        $theme = 'default';
    }
    $file = CVM_PATH . 'themes/' . $theme . '/player.php';
    if (!is_file($file)) {
        $theme = 'default';
    }
    include CVM_PATH . 'themes/' . $theme . '/player.php';
    $content = ob_get_contents();
    ob_end_clean();
    cvm_enqueue_player();
    wp_enqueue_script('cvm-vim-player-' . $theme, CVM_URL . 'themes/' . $theme . '/assets/script.js', array('cvm-video-player'), '1.0');
    wp_enqueue_style('cvm-vim-player-' . $theme, CVM_URL . 'themes/' . $theme . '/assets/stylesheet.css', false, '1.0');
    // remove custom player settings
    $CVM_PLAYER_SETTINGS = false;
    return $content;
}
コード例 #3
0
 /**
  * Output plugin settings page
  */
 public function plugin_settings()
 {
     $options = cvm_get_settings();
     $player_opt = cvm_get_player_settings();
     // fire up Vimeo class
     require_once CVM_PATH . 'includes/libs/vimeo.class.php';
     $vimeo = new CVM_Vimeo();
     if (!empty($options['vimeo_consumer_key']) && !empty($options['vimeo_secret_key'])) {
         if (empty($options['oauth_token'])) {
             // account token
             $token = $vimeo->get_unauth_token();
             if (!is_wp_error($token)) {
                 $options['oauth_token'] = $token;
                 update_option('_cvm_plugin_settings', $options);
             } else {
                 $authorize_error = $token->get_error_message();
             }
         }
     }
     include CVM_PATH . 'views/plugin_settings.php';
 }
コード例 #4
0
 /**
  * Default widget values
  */
 private function get_defaults()
 {
     $player_defaults = cvm_get_player_settings();
     $defaults = array('cvm_widget_title' => '', 'cvm_posts_number' => 5, 'cvm_vim_image' => false);
     return $defaults;
 }