Code Duplication    Length = 14-17 lines in 2 locations

modules/shortcodes/instagram.php 1 location

@@ 34-50 (lines=17) @@
31
	// Let's play nice with the visual editor too.
32
	$regexes[] = '#<iframe(?:[^&]|&(?!gt;))+?src="(?:https?:)?//instagram\.com/p/([^"\'/]++)[^"\']*?"(?:[^&]|&(?!gt;))*+>\s*?</iframe>#i';
33
34
	foreach ( $regexes as $regex ) {
35
		if ( ! preg_match_all( $regex, $content, $matches, PREG_SET_ORDER ) ) {
36
			continue;
37
		}
38
39
		foreach ( $matches as $match ) {
40
			if ( ! preg_match( '#(https?:)?//instagr(\.am|am\.com)/p/([^/]*)#i', $match[2], $url_matches ) ) {
41
				continue;
42
			}
43
44
			// Since we support Instagram via oEmbed, we simply leave a link on a line by itself.
45
			$replace_regex = sprintf( '#\s*%s\s*#', preg_quote( $match[0], '#' ) );
46
			$url           = esc_url( $url_matches[0] );
47
48
			$content = preg_replace( $replace_regex, sprintf( "\n\n%s\n\n", $url ), $content );
49
			/** This action is documented in modules/shortcodes/youtube.php */
50
			do_action( 'jetpack_embed_to_shortcode', 'instagram', $url );
51
		}
52
	}
53

modules/shortcodes/dailymotion.php 1 location

@@ 311-324 (lines=14) @@
308
	(?: <a(?:[^&]|&(?!gt;))+?href=" (?:https?:)?//(?:www\.)?dailymotion\.com/[^"\']++ "(?:[^&]|&(?!gt;))*+>.+?</a>\s*+ )?
309
	(?: <i>.*?<a(?:[^&]|&(?!gt;))+?href=" (?:https?:)?//(?:www\.)?dailymotion\.com/[^"\']++ "(?:[^&]|&(?!gt;))*+>.+?</a>\s*+</i> )?#ix';
310
311
	foreach ( $regexes as $regex ) {
312
		if ( ! preg_match_all( $regex, $content, $matches, PREG_SET_ORDER ) ) {
313
			continue;
314
		}
315
316
		foreach ( $matches as $match ) {
317
			$url           = esc_url( sprintf( 'https://dailymotion.com/video/%s', $match[1] ) );
318
			$replace_regex = sprintf( '#\s*%s\s*#', preg_quote( $match[0], '#' ) );
319
			$content       = preg_replace( $replace_regex, sprintf( "\n\n%s\n\n", $url ), $content );
320
321
			/** This action is documented in modules/shortcodes/youtube.php */
322
			do_action( 'jetpack_embed_to_shortcode', 'dailymotion', $url );
323
		}
324
	}
325
326
	return $content;
327
}