Code Duplication    Length = 18-18 lines in 2 locations

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

@@ 264-281 (lines=18) @@
261
	 * @var string $expires_header
262
	 * @return int|bool Unix time or false
263
	 */
264
	public static function calculate_expiration( $expires_header ) {
265
		if ( empty( $expires_header ) || ! is_string( $expires_header ) )
266
			return false;
267
268
		if (
269
			class_exists( 'DateTimeZone' )
270
			&& method_exists( 'DateTime', 'createFromFormat' )
271
		) {
272
			$expires_date = DateTime::createFromFormat( 'D, d M Y H:i:s T', $expires_header, new DateTimeZone( 'UTC' ) );
273
			if ( $expires_date instanceOf DateTime )
274
				return date_format( $expires_date, 'U' );
275
		} else {
276
			$expires_array = strptime( $expires_header, '%a, %d %b %Y %H:%M:%S %Z' );
277
			if ( is_array( $expires_array ) && isset( $expires_array['tm_hour'] ) && isset( $expires_array['tm_min'] ) && isset( $expires_array['tm_sec'] ) && isset( $expires_array['tm_mon'] ) && isset( $expires_array['tm_mday'] ) && isset( $expires_array['tm_year'] ) )
278
				return gmmktime( $expires_array['tm_hour'], $expires_array['tm_min'], $expires_array['tm_sec'], 1 + $expires_array['tm_mon'], $expires_array['tm_mday'], 1900 + $expires_array['tm_year'] );
279
		}
280
		return false;
281
	}
282
283
	/**
284
	 * Extract the site's host domain for statistics and comparison against an allowed site list in the case of restricted embeds.

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

@@ 253-270 (lines=18) @@
250
	 * @var string $expires_header
251
	 * @return int|bool Unix time or false
252
	 */
253
	public static function calculate_expiration( $expires_header ) {
254
		if ( empty( $expires_header ) || ! is_string( $expires_header ) )
255
			return false;
256
257
		if (
258
			class_exists( 'DateTimeZone' )
259
			&& method_exists( 'DateTime', 'createFromFormat' )
260
		) {
261
			$expires_date = DateTime::createFromFormat( 'D, d M Y H:i:s T', $expires_header, new DateTimeZone( 'UTC' ) );
262
			if ( $expires_date instanceOf DateTime )
263
				return date_format( $expires_date, 'U' );
264
		} else {
265
			$expires_array = strptime( $expires_header, '%a, %d %b %Y %H:%M:%S %Z' );
266
			if ( is_array( $expires_array ) && isset( $expires_array['tm_hour'] ) && isset( $expires_array['tm_min'] ) && isset( $expires_array['tm_sec'] ) && isset( $expires_array['tm_mon'] ) && isset( $expires_array['tm_mday'] ) && isset( $expires_array['tm_year'] ) )
267
				return gmmktime( $expires_array['tm_hour'], $expires_array['tm_min'], $expires_array['tm_sec'], 1 + $expires_array['tm_mon'], $expires_array['tm_mday'], 1900 + $expires_array['tm_year'] );
268
		}
269
		return false;
270
	}
271
272
	/**
273
	 * Extract the site's host domain for statistics and comparison against an allowed site list in the case of restricted embeds.