Skip to content

Commit

Permalink
Remove unneed replacements
Browse files Browse the repository at this point in the history
  • Loading branch information
obenland authored and getdave committed Jan 2, 2020
1 parent a2b901a commit a5d9c25
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions lib/class-wp-rest-url-details-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,9 @@ public function get_title( $request ) {
/**
* Checks whether a given request has permission to read remote urls.
*
* phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
*
* @param WP_REST_Request $request Full details about the request.
* @return WP_Error|bool True if the request has access, WP_Error object otherwise.
*/
public function get_remote_url_permissions_check( $request ) {
/* phpcs:enable */
public function get_remote_url_permissions_check() {
if ( ! current_user_can( 'edit_posts' ) ) {
return new WP_Error(
'rest_user_cannot_view',
Expand All @@ -102,21 +98,17 @@ private function get_remote_url_title( $url ) {
if ( empty( $title ) ) {
$request = wp_safe_remote_get( $url, array(
'timeout' => 10,
'limit_response_size' => 153600, // 150 KB
'limit_response_size' => 153600, // 150 KB.
) );
$remote_source = wp_remote_retrieve_body( $request );

if ( ! $remote_source ) {
return new WP_Error( 'no_response', __( 'The source URL does not exist.', 'gutenberg' ), array( 'status' => 404 ) );
}

// Work around bug in strip_tags():
$remote_source = str_replace( '<!DOC', '<DOC', $remote_source );
$remote_source = preg_replace( '/[\r\n\t ]+/', ' ', $remote_source ); // Normalize spaces.
$remote_source = preg_replace( '/<\/*(h1|h2|h3|h4|h5|h6|p|th|td|li|dt|dd|pre|caption|input|textarea|button|body)[^>]*>/', "\n\n", $remote_source );

preg_match( '|<title>([^<]*?)</title>|is', $remote_source, $match_title );
$title = isset( $match_title[1] ) ? $match_title[1] : '';
$title = isset( $match_title[1] ) ? trim( $match_title[1] ) : '';

if ( empty( $title ) ) {
return new WP_Error( 'no_title', __( 'No document title at remote url.', 'gutenberg' ), array( 'status' => 404 ) );
}
Expand Down

0 comments on commit a5d9c25

Please sign in to comment.