/**
  * Validate mpx Settings for invalid input
  *
  * @param array $input Passed by Wordpress, an Array of mpx options
  *
  * @return array A cleaned up copy of the array, invalid values will be cleared.
  */
 function theplatform_preferences_options_validate($input)
 {
     require_once dirname(__FILE__) . '/thePlatform-API.php';
     $tp_api = new ThePlatform_API();
     $account_is_verified = $tp_api->verify_account_settings();
     if ($account_is_verified) {
         $region_is_verified = $tp_api->verify_account_region();
         if (isset($input['default_player_name']) && strpos($input['default_player_name'], '|') !== false) {
             $ids = explode('|', $input['default_player_name']);
             $input['default_player_name'] = $ids[0];
             $input['default_player_pid'] = $ids[1];
         }
         // If the account is selected, but no player has been set, use the first
         // returned as the default.
         if (!isset($input['default_player_name']) || empty($input['default_player_name'])) {
             if ($region_is_verified) {
                 $players = $tp_api->get_players();
                 $player = $players[0];
                 $input['default_player_name'] = $player['title'];
                 $input['default_player_pid'] = $player['pid'];
             } else {
                 $input['default_player_name'] = '';
                 $input['default_player_pid'] = '';
             }
         }
         // If the account is selected, but no upload server has been set, use the first
         // returned as the default.
         if (!isset($input['mpx_server_id']) || empty($input['mpx_server_id'])) {
             $input['mpx_server_id'] = 'DEFAULT_SERVER';
         }
         foreach ($input as $key => $value) {
             if ($key == 'videos_per_page' || $key === 'default_width' || $key === 'default_height') {
                 $input[$key] = intval($value);
             } else {
                 $input[$key] = sanitize_text_field($value);
             }
         }
     }
     return $input;
 }
}
if (!class_exists('ThePlatform_API')) {
    require_once dirname(__FILE__) . '/thePlatform-API.php';
}
$tp_api = new ThePlatform_API();
$metadata = $tp_api->get_metadata_fields();
define('TP_MEDIA_BROWSER', true);
$metadata_options = get_option(TP_METADATA_OPTIONS_KEY, array());
$upload_options = get_option(TP_UPLOAD_OPTIONS_KEY, TP_UPLOAD_FIELDS_DEFAULTS());
$preferences = get_option(TP_PREFERENCES_OPTIONS_KEY);
$account = get_option(TP_ACCOUNT_OPTIONS_KEY);
if (strcmp($account['mpx_account_id'], "") == 0) {
    wp_die('MPX Account ID is not set, please configure the plugin before attempting to manage media');
}
//Embed only stuff
$players = $tp_api->get_players();
$IS_EMBED = isset($_GET['embed']) ? true : false;
function writePlayers($players, $preferences)
{
    $html = '<p class="navbar-text sort-bar-text">Player:</p><form class="navbar-form navbar-left sort-bar-nav" role="sort"><select id="selectpick-player" class="form-control">';
    foreach ($players as $player) {
        $html .= '<option value="' . esc_attr($player['pid']) . '"' . selected($player['pid'], $preferences['default_player_pid'], false) . '>' . esc_html($player['title']) . '</option>';
    }
    $html .= '</select></form>';
    echo $html;
}
?>

		<script type="text/javascript">
			tpHelper = { };
			tpHelper.token = "<?php