Skip to content

Commit

Permalink
Eventbrite block (#14075)
Browse files Browse the repository at this point in the history
* Initial scaffolding for Eventbrite block

* Request Eventbrite events when block is inserted

* Displays select dropdown of events from Eventbrite

* Saves event id as block attribute

* Render the Eventbrite widget code in PHP, rather than saving it in the block.

* Add the new endpoint file the the phpcs whitelist.

* Add a spinner while loading events

* Add an option for switching between inline and modal embeds

* Don't load the block if Jetpack isn't connected.

* Add a (currently not building) connect button.

* Update webpack config to include _inc/client in blocks

* Don't open a new Eventbrite connect dialog every time the block renders.

* Removes integrations proxy endpoint (unneeded with simple embed)

* Set Eventbrite block to beta, for testing

* Replace event list with placeholder in Eventbrite block

* Adds embed parsing and a non-working embed preview

* Use @wordpress/embed-block to generate the block.

* Eventbrite embed using prior art from Pinterest block

* Add the Eventbrite icon

* Rename block to Eventbrite Tickets

* Remove some old code

* Add block previews when editing

* Refactor Eventbrite embed edit

- Break up the component into multiple render functions
- Re-add the functionality to resolve redirects for custom Eventbrite
  urls
- Add working regexs for embedable and custom Eventbrite URLs

* Add a user agent when following redirects to avoid 403 Forbidden with
Eventrbrite custom urls

* Fixes eventId property for creating the Eventbrite embed

* Show sidebar options all the time, edit button only with embed preview

* Fix styles that remove Eventbrite transitions so preview can resize

* Re-render preview when embed type is changed

* Removes interactivity with the preview to prevent Sandbox resizing
problems

* Updates block title and adds keywords

* Resolves the Eventbrite URL before embedding to ensure the event exists.

* Removes duplicate controls from sidebar

* Use a variation of the block editor button for the modal embed

* Adds comment explaining header for reqeuest to resolve redirect

* Adds comments to files adapted from @wordpress/block-library

* Share block settings between php and js

- Consolidate and update event url regexes
- Consolidate generation of widget html id

* Translates noscript message

* Adds embed type picker similar to block styles UI

* Add instructions, icon color, and support link to placeholder

* Adds button styles when using the modal embed type

* Additional tweaks

- Add code comments and doc blocks
- Show/hide modal button styles only when previewing embed

* Initial scaffolding for Eventbrite block

* Request Eventbrite events when block is inserted

* Add the new endpoint file the the phpcs whitelist.

* Add a (currently not building) connect button.

* Removes integrations proxy endpoint (unneeded with simple embed)

* Adds comments to files adapted from @wordpress/block-library

* Updates modal embed type preview to use block attributes

* Update convert block button text

* Removes color from icon to be consistent with other blocks

* Removes spaceing from block declaration

* Fix rebase leftover

* Make the icon monochrome

* Clarify what the fallback does

* Fix incorrect inline-block display of the modal button

* Add Jetpack text domain where missing

* Remove unnecessary block attribute definitions

* Add todo comment and compress image

* Escape PHP output

* Remove unnecessary change to the Webpack config

* Improve the URL redirects endpoint

* Save the event ID as block attribute

* Also update the event ID on url resolve

Co-authored-by: Gary Pendergast <gary@pento.net>
Co-authored-by: Jacopo Tomasone <Copons@users.noreply.github.com>
  • Loading branch information
3 people authored and jeherve committed Jan 24, 2020
1 parent b37441d commit 5fcf116
Show file tree
Hide file tree
Showing 12 changed files with 969 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,45 +50,86 @@ public function register_routes() {
}

/**
* Follows 301/302 redirect for the passed URL, and returns the final destination.
* Follows 301/302 redirect for the passed URL, and returns the final destination and status code.
*
* @param WP_REST_Request $request The REST API request data.
* @return WP_REST_Response The REST API response.
*/
public function follow_redirect( $request ) {
$response = wp_safe_remote_get( $request['url'] );
if ( is_wp_error( $response ) ) {
return rest_ensure_response( '' );
}
global $wp_version;

$history = $response['http_response']->get_response_object()->history;
if ( ! $history ) {
return response_ensure_response( $request['url'] );
}
// Add a User-Agent header since the request is sometimes blocked without it.
$response = wp_safe_remote_get(
$request['url'],
array(
'headers' => array(
// @see https://github.com/Automattic/jetpack/blob/fe51754410f97e0f20908ebb7fdbfbc62e703987/modules/protect.php#L534
'User-Agent' => "WordPress/{$wp_version} | Jetpack/" . constant( 'JETPACK__VERSION' ),
),
)
);

$location = $history[0]->headers->getValues( 'location' );
if ( ! $location ) {
return response_ensure_response( $request['url'] );
if ( is_wp_error( $response ) ) {
return rest_ensure_response(
array(
'url' => '',
'status' => $response->get_error_code(),
)
);
}

return rest_ensure_response( $location[0] );
return rest_ensure_response(
array(
'url' => $this->get_response_url( $response['http_response']->get_response_object() ),
'status' => wp_remote_retrieve_response_code( $response ),
)
);
}

/**
* Retrieves the comment's schema, conforming to JSON Schema.
* Retrieves the response schema, conforming to JSON Schema.
*
* @return array
*/
public function get_item_schema() {
$schema = array(
'$schema' => 'http://json-schema.org/draft-04/schema#',
'title' => 'resolve-redirect',
'type' => 'string',
'description' => __( 'The final destination of the URL being checked for redirects.', 'jetpack' ),
'$schema' => 'http://json-schema.org/draft-04/schema#',
'title' => 'resolve-redirect',
'type' => 'object',
'properties' => array(
'url' => array(
'description' => __( 'The final destination of the URL being checked for redirects.', 'jetpack' ),
'type' => 'string',
),
'status' => array(
'description' => __( 'The status code of the URL\'s response.', 'jetpack' ),
'type' => 'integer',
),
),
);

return $schema;
}

/**
* Finds the destination url from an http response.
*
* @param Requests_Response $response Response object.
* @return string Final url of the response.
*/
protected function get_response_url( Requests_Response $response ) {
$history = $response->history;
if ( ! $history ) {
return $response->url;
}

$location = $history[0]->headers->getValues( 'location' );
if ( ! $location ) {
return $response->url;
}

return $location[0];
}
}

wpcom_rest_api_v2_load_plugin( 'WPCOM_REST_API_V2_Endpoint_Resolve_Redirect' );
Loading

0 comments on commit 5fcf116

Please sign in to comment.