コード例 #1
0
function jwplayer_import_playlists()
{
    if (!current_user_can('manage_options')) {
        return;
    }
    $imported_playlists = get_option('jwplayer_imported_playlists');
    if (!$imported_playlists) {
        $imported_playlists = array();
        add_option('jwplayer_imported_playlists', $imported_playlists);
    }
    $playlists = jwplayer_import_legacy_playlists();
    foreach ($playlists as $playlist) {
        if (array_key_exists($playlist->ID, $imported_playlists)) {
            continue;
        }
        $media_ids = explode(',', get_post_meta($playlist->ID, 'jwplayermodule_playlist_items', true));
        $media_hashes = array();
        foreach ($media_ids as $media_id) {
            $media_hash = jwplayer_media_hash(intval($media_id));
            $media_hashes[] = $media_hash;
        }
        if (empty($media_hashes)) {
            continue;
        }
        $params = array('title' => $playlist->post_title, 'type' => 'manual');
        $response = jwplayer_api_call('/channels/create', $params);
        if (jwplayer_api_response_ok($response)) {
            $hash = $response['channel']['key'];
            $imported_playlists[$playlist->ID] = $hash;
            foreach ($media_hashes as $media_hash) {
                $params = array('channel_key' => $hash, 'video_key' => $media_hash);
                $response = jwplayer_api_call('/channels/videos/create', $params);
                if (!jwplayer_api_response_ok($response)) {
                    jwplayer_log('ERROR ADDING VIDEO TO PLAYLIST');
                    jwplayer_log($params, true);
                    jwplayer_log($response, true);
                }
            }
        } else {
            jwplayer_log('ERROR CREATING NEW PLAYLIST');
            jwplayer_log($params, true);
            jwplayer_log($response, true);
        }
    }
    update_option('jwplayer_imported_playlists', $imported_playlists);
    jwplayer_import_check_redirect();
}
コード例 #2
0
function jwplayer_shortcode_handle_legacy($atts)
{
    // Try to get media
    if (isset($atts['mediaid'])) {
        $hash = jwplayer_media_hash(intval($atts['mediaid']));
        if (!isset($atts['image'])) {
            $thumb = get_post_meta($atts['mediaid'], 'jwplayermodule_thumbnail', true);
            if ($thumb) {
                $atts['image'] = $thumb;
            }
        }
        unset($atts['mediaid']);
        // };
    } elseif (isset($atts['file'])) {
        $title = isset($atts['title']) ? $atts['title'] : null;
        $hash = jwplayer_media_legacy_external_source($atts['file'], $title);
        unset($atts['file']);
    } elseif (isset($atts['playlistid'])) {
        $imported_playlists = get_option('jwplayer_imported_playlists');
        if ($imported_playlists && array_key_exists($atts['playlistid'], $imported_playlists)) {
            $hash = $imported_playlists[$atts['playlistid']];
        }
        unset($atts['playlistid']);
    }
    // Try to get player
    $player_hash = null;
    if (isset($atts['player'])) {
        $imported_players = get_option('jwplayer_imported_players');
        if ($imported_players && array_key_exists($atts['player'], $imported_players)) {
            $player_hash = $imported_players[$atts['player']];
        }
    }
    // Return the old stuff
    if (isset($hash)) {
        return jwplayer_shortcode_create_js_embed($hash, $player_hash, $atts);
    }
    return '<!-- ERROR PARSING SHORTCODE -->';
}