Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eventbrite block #14075

Merged
merged 63 commits into from
Jan 24, 2020
Merged
Show file tree
Hide file tree
Changes from 58 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
5908898
Initial scaffolding for Eventbrite block
creativecoder Nov 19, 2019
515534b
Request Eventbrite events when block is inserted
creativecoder Nov 19, 2019
e031766
Displays select dropdown of events from Eventbrite
creativecoder Nov 19, 2019
e0746be
Saves event id as block attribute
creativecoder Nov 20, 2019
3eeeb5f
Render the Eventbrite widget code in PHP, rather than saving it in th…
pento Nov 20, 2019
686c3bf
Add the new endpoint file the the phpcs whitelist.
pento Nov 21, 2019
8737182
Add a spinner while loading events
pento Nov 21, 2019
67d30d8
Add an option for switching between inline and modal embeds
pento Nov 21, 2019
f586388
Don't load the block if Jetpack isn't connected.
pento Nov 22, 2019
c3536a6
Add a (currently not building) connect button.
pento Nov 22, 2019
dba1132
Update webpack config to include _inc/client in blocks
pento Nov 22, 2019
aa8a194
Don't open a new Eventbrite connect dialog every time the block renders.
pento Nov 22, 2019
7e5ca98
Removes integrations proxy endpoint (unneeded with simple embed)
creativecoder Dec 12, 2019
0989c81
Set Eventbrite block to beta, for testing
creativecoder Dec 12, 2019
9404d07
Replace event list with placeholder in Eventbrite block
creativecoder Dec 12, 2019
5a5ba98
Adds embed parsing and a non-working embed preview
creativecoder Dec 14, 2019
e8c181c
Use @wordpress/embed-block to generate the block.
pento Dec 16, 2019
fd0681d
Eventbrite embed using prior art from Pinterest block
creativecoder Dec 16, 2019
3d68c8d
Add the Eventbrite icon
pento Dec 17, 2019
10a08e2
Rename block to Eventbrite Tickets
pento Dec 17, 2019
35ace42
Remove some old code
pento Dec 17, 2019
7bb710e
Add block previews when editing
pento Dec 17, 2019
899891d
Refactor Eventbrite embed edit
creativecoder Dec 17, 2019
e2beef9
Add a user agent when following redirects to avoid 403 Forbidden with
creativecoder Dec 17, 2019
0fc8261
Fixes eventId property for creating the Eventbrite embed
creativecoder Dec 17, 2019
e80bee5
Show sidebar options all the time, edit button only with embed preview
creativecoder Dec 18, 2019
e14ebd6
Fix styles that remove Eventbrite transitions so preview can resize
creativecoder Dec 19, 2019
1fbb47d
Re-render preview when embed type is changed
creativecoder Dec 19, 2019
1d5165e
Removes interactivity with the preview to prevent Sandbox resizing
creativecoder Dec 19, 2019
1b63d2e
Updates block title and adds keywords
creativecoder Dec 19, 2019
5f19609
Resolves the Eventbrite URL before embedding to ensure the event exists.
creativecoder Dec 19, 2019
403981d
Removes duplicate controls from sidebar
creativecoder Dec 19, 2019
9fa106e
Use a variation of the block editor button for the modal embed
creativecoder Dec 20, 2019
055012f
Adds comment explaining header for reqeuest to resolve redirect
creativecoder Jan 8, 2020
58c7d38
Adds comments to files adapted from @wordpress/block-library
creativecoder Jan 8, 2020
d0cb298
Share block settings between php and js
creativecoder Jan 9, 2020
de0b30e
Translates noscript message
creativecoder Jan 9, 2020
6c8b9ca
Adds embed type picker similar to block styles UI
creativecoder Jan 14, 2020
72e4303
Add instructions, icon color, and support link to placeholder
creativecoder Jan 14, 2020
ec954e9
Adds button styles when using the modal embed type
creativecoder Jan 15, 2020
05a35c9
Additional tweaks
creativecoder Jan 16, 2020
1f44ea6
Initial scaffolding for Eventbrite block
creativecoder Nov 19, 2019
3d52353
Request Eventbrite events when block is inserted
creativecoder Nov 19, 2019
77225b3
Add the new endpoint file the the phpcs whitelist.
pento Nov 21, 2019
73f6b7d
Add a (currently not building) connect button.
pento Nov 22, 2019
3d2cabd
Removes integrations proxy endpoint (unneeded with simple embed)
creativecoder Dec 12, 2019
efa3f09
Adds comments to files adapted from @wordpress/block-library
creativecoder Jan 8, 2020
1594818
Updates modal embed type preview to use block attributes
creativecoder Jan 17, 2020
97d9d6f
Update convert block button text
creativecoder Jan 20, 2020
ca08a49
Removes color from icon to be consistent with other blocks
creativecoder Jan 20, 2020
296f4a0
Removes spaceing from block declaration
creativecoder Jan 20, 2020
e523eed
Fix rebase leftover
Copons Jan 20, 2020
9b353db
Make the icon monochrome
Copons Jan 20, 2020
4311c9b
Clarify what the fallback does
Copons Jan 20, 2020
b40ea8b
Fix incorrect inline-block display of the modal button
Copons Jan 22, 2020
d6e6902
Add Jetpack text domain where missing
Copons Jan 22, 2020
ec71e8d
Remove unnecessary block attribute definitions
Copons Jan 22, 2020
c8c675e
Add todo comment and compress image
Copons Jan 22, 2020
183d63c
Escape PHP output
Copons Jan 23, 2020
b3d6e74
Remove unnecessary change to the Webpack config
Copons Jan 23, 2020
1691393
Improve the URL redirects endpoint
Copons Jan 23, 2020
25e0fb9
Save the event ID as block attribute
Copons Jan 23, 2020
338da38
Also update the event ID on url resolve
Copons Jan 24, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,45 +50,83 @@ 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( '' );
}

$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(
'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:71.0) Gecko/20100101 Firefox/71.0',
Copons marked this conversation as resolved.
Show resolved Hide resolved
),
)
);

$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' => null,
Copons marked this conversation as resolved.
Show resolved Hide resolved
)
);
}

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