function jwplayer_validate_player($player_key) { $api_key = get_option('jwplayer_api_key'); $loggedin = !empty($api_key); if ($loggedin) { $response = jwplayer_api_call('/players/list'); foreach ($response['players'] as $i => $p) { if ($player_key === $p['key']) { return $player_key; } } return $response['players'][0]['key']; } return ''; }
function jwplayer_setting_player() { $api_key = get_option('jwplayer_api_key'); $loggedin = !empty($api_key); if ($loggedin) { $response = jwplayer_api_call('/players/list'); $player = get_option('jwplayer_player'); echo '<select name="jwplayer_player" id="jwplayer_player" />'; foreach ($response['players'] as $i => $p) { $key = $p['key']; if ($p['responsive']) { $description = htmlentities($p['name']) . ' (Responsive, ' . $p['aspectratio'] . ')'; } else { $description = htmlentities($p['name']) . ' (Fixed size, ' . $p['width'] . 'x' . $p['height'] . ')'; } echo '<option value="' . esc_attr($key) . '"' . esc_attr(selected($key === $player, true, false)) . '>' . esc_html($description) . '</option>'; } echo '</select>'; echo ' <p class="description"> Embedded videos will use this player if no other is specified. To edit this player, <a href="' . esc_url(JWPLAYER_DASHBOARD . '#/players/list') . '">go to your JW Player dashboard</a>.<br /> To override this selection, add a dash and the corresponding player key to the video key in the shortcode.<br /> For example: <code>[jwplayer MdkflPz7-35rdi1pO]</code> </p> '; } else { echo '<input type="hidden" name="jwplayer_player" value="' . esc_attr(JWPLAYER_PLAYER) . '" />'; echo 'You have to save log in before you can set this option.'; } }
function jwplayer_media_add_external_source($url, $title = null) { $extension = pathinfo($url, PATHINFO_EXTENSION); $sourceformat = 'mp4'; foreach (json_decode(JWPLAYER_SOURCE_FORMAT_EXTENSIONS) as $format => $extensions) { if (in_array($extension, $extensions, true)) { $sourceformat = $format; break; } } $params = array('sourcetype' => 'url', 'sourceurl' => $url, 'sourceformat' => $sourceformat, 'tags' => 'wp_media'); if (null !== $title) { $params['title'] = $title; } $response = jwplayer_api_call('/videos/create', $params); if (jwplayer_api_response_ok($response)) { return $response['video']['key']; } return null; }
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(); }