/** * Publish an uploaded media asset using the 'Wordpress' profile * @return mixed JSON response or instance of WP_Error */ public function publish_media() { $this->check_nonce_and_permissions($_POST['action']); if ($_POST['profile'] == 'wp_tp_none') { wp_send_json_success(); } $profileUrl = TP_API_PUBLISH_PROFILE_ENDPOINT; $profileUrl .= '&byTitle=' . urlencode($_POST['profile']); $profileUrl .= '&token=' . $_POST['token']; $profileUrl .= '&account=' . urlencode($_POST['account']); $profileResponse = ThePlatform_API_HTTP::get(esc_url_raw($profileUrl)); $content = theplatform_decode_json_from_server($profileResponse, TRUE); if ($content['entryCount'] == 0) { wp_send_json_error("No Publishing Profile Found"); } $profileId = $content['entries'][0]['id']; $mediaId = $_POST['mediaId']; $publishUrl = TP_API_PUBLISH_BASE_URL; $publishUrl .= '&token=' . $_POST['token']; $publishUrl .= '&account=' . urlencode($_POST['account']); $publishUrl .= '&_mediaId=' . urlencode($mediaId); $publishUrl .= '&_profileId=' . urlencode($profileId); $response = ThePlatform_API_HTTP::get(esc_url_raw($publishUrl), array("timeout" => 120)); $this->check_theplatform_proxy_response($response, true); }
/** * AJAX callback for account verification button */ function theplatform_verify_account_settings() { //User capability check check_admin_referer('theplatform-ajax-nonce-verify_account'); $hash = $_POST['auth_hash']; $response = ThePlatform_API_HTTP::get(TP_API_SIGNIN_URL, array('headers' => array('Authorization' => 'Basic ' . $hash))); $payload = theplatform_decode_json_from_server($response, TRUE); if (!array_key_exists('isException', $payload)) { $account_is_verified = TRUE; wp_send_json_success(); } $account_is_verified = FALSE; wp_send_json_error(); }
/** * Used to verify the account server settings on the server side * @return type */ function internal_verify_account_settings() { $this->get_account(); $username = trim($this->account['mpx_username']); $password = trim($this->account['mpx_password']); if ($username === "mpx/" || $username === "" || $password === "") { return FALSE; } $hash = base64_encode($username . ':' . $password); $response = ThePlatform_API_HTTP::get(TP_API_SIGNIN_URL, array('headers' => array('Authorization' => 'Basic ' . $hash))); $payload = theplatform_decode_json_from_server($response, TRUE, FALSE); if (is_null($response)) { return FALSE; } if (!array_key_exists('isException', $payload)) { update_option(TP_TOKEN_OPTIONS_KEY, $payload['signInResponse']['token']); return TRUE; } else { return FALSE; } }
/** * AJAX callback for account verification button */ function verify_account_settings_ajax() { $this->check_nonce_and_permissions($_POST['action'], TP_ADMIN_CAP); $this->get_api(); $hash = $_POST['auth_hash']; $response = ThePlatform_API_HTTP::get(TP_API_SIGNIN_URL, array('headers' => array('Authorization' => 'Basic ' . $hash))); $data = $this->get_api()->decode_json_from_server($response); if (array_key_exists('success', $data) && $data['success'] == false) { wp_send_json_error("Unable to verify account"); } wp_send_json_success("Account Verified"); }