Code Duplication    Length = 43-43 lines in 2 locations

modules/videopress-v2/class.videopress-video.php 1 location

@@ 301-343 (lines=43) @@
298
	 * @since 1.3
299
	 * @return stdClass|WP_Error parsed JSON response or WP_Error if request unsuccessful
300
	 */
301
	private function get_data() {
302
		global $wp_version;
303
304
		$domain = self::hostname( home_url() );
305
		$request_params = array( 'guid' => $this->guid, 'domain' => $domain );
306
		if ( isset( $this->maxwidth ) && $this->maxwidth > 0 )
307
			$request_params['maxwidth'] = $this->maxwidth;
308
309
		$url = 'http://videopress.com/data/wordpress.json';
310
		if ( is_ssl() )
311
			$url = 'https://v.wordpress.com/data/wordpress.json';
312
313
		$response = wp_remote_get( add_query_arg( $request_params, $url ), array(
314
			'redirection' => 1,
315
			'user-agent' => 'VideoPress plugin ' . $this->version . '; WordPress ' . $wp_version . ' (' . home_url('/') . ')',
316
		) );
317
318
		unset( $request_params );
319
		unset( $url );
320
		$response_body = wp_remote_retrieve_body( $response );
321
		$response_code = absint( wp_remote_retrieve_response_code( $response ) );
322
323
		if ( is_wp_error( $response ) ) {
324
			return $response;
325
		} elseif ( $response_code === 400 ) {
326
			return new WP_Error( 'bad_config', __( 'The VideoPress plugin could not communicate with the VideoPress servers. This error is most likely caused by a misconfigured plugin. Please reinstall or upgrade.', 'jetpack' ) );
327
		} elseif ( $response_code === 403 ) {
328
			return new WP_Error( 'http_forbidden', '<p>' . sprintf( __( '<strong>%s</strong> is not an allowed embed site.' , 'jetpack' ), esc_html( $domain ) ) . '</p><p>' . __( 'Publisher limits playback of video embeds.', 'jetpack' ) . '</p>' );
329
		} elseif ( $response_code === 404 ) {
330
			return new WP_Error( 'http_not_found', '<p>' . sprintf( __( 'No data found for VideoPress identifier: <strong>%s</strong>.', 'jetpack' ), $this->guid ) . '</p>' );
331
		} elseif ( $response_code !== 200 || empty( $response_body ) ) {
332
			return;
333
		} else {
334
			$expires_header = wp_remote_retrieve_header( $response, 'Expires' );
335
			if ( ! empty( $expires_header ) ) {
336
				$expires = self::calculate_expiration( $expires_header );
337
				if ( ! empty( $expires ) )
338
					$this->expires = $expires;
339
340
			}
341
			return json_decode( $response_body );
342
		}
343
	}
344
}
345

modules/videopress/class.videopress-video.php 1 location

@@ 290-332 (lines=43) @@
287
	 * @since 1.3
288
	 * @return stdClass|WP_Error parsed JSON response or WP_Error if request unsuccessful
289
	 */
290
	private function get_data() {
291
		global $wp_version;
292
293
		$domain = self::hostname( home_url() );
294
		$request_params = array( 'guid' => $this->guid, 'domain' => $domain );
295
		if ( isset( $this->maxwidth ) && $this->maxwidth > 0 )
296
			$request_params['maxwidth'] = $this->maxwidth;
297
298
		$url = 'http://videopress.com/data/wordpress.json';
299
		if ( is_ssl() )
300
			$url = 'https://v.wordpress.com/data/wordpress.json';
301
302
		$response = wp_remote_get( add_query_arg( $request_params, $url ), array(
303
			'redirection' => 1,
304
			'user-agent' => 'VideoPress plugin ' . $this->version . '; WordPress ' . $wp_version . ' (' . home_url('/') . ')',
305
		) );
306
307
		unset( $request_params );
308
		unset( $url );
309
		$response_body = wp_remote_retrieve_body( $response );
310
		$response_code = absint( wp_remote_retrieve_response_code( $response ) );
311
312
		if ( is_wp_error( $response ) ) {
313
			return $response;
314
		} elseif ( $response_code === 400 ) {
315
			return new WP_Error( 'bad_config', __( 'The VideoPress plugin could not communicate with the VideoPress servers. This error is most likely caused by a misconfigured plugin. Please reinstall or upgrade.', 'jetpack' ) );
316
		} elseif ( $response_code === 403 ) {
317
			return new WP_Error( 'http_forbidden', '<p>' . sprintf( __( '<strong>%s</strong> is not an allowed embed site.' , 'jetpack' ), esc_html( $domain ) ) . '</p><p>' . __( 'Publisher limits playback of video embeds.', 'jetpack' ) . '</p>' );
318
		} elseif ( $response_code === 404 ) {
319
			return new WP_Error( 'http_not_found', '<p>' . sprintf( __( 'No data found for VideoPress identifier: <strong>%s</strong>.', 'jetpack' ), $this->guid ) . '</p>' );
320
		} elseif ( $response_code !== 200 || empty( $response_body ) ) {
321
			return;
322
		} else {
323
			$expires_header = wp_remote_retrieve_header( $response, 'Expires' );
324
			if ( ! empty( $expires_header ) ) {
325
				$expires = self::calculate_expiration( $expires_header );
326
				if ( ! empty( $expires ) )
327
					$this->expires = $expires;
328
329
			}
330
			return json_decode( $response_body );
331
		}
332
	}
333
}
334