Code Duplication    Length = 38-43 lines in 2 locations

projects/packages/post-images/src/class-post-images.php 1 location

@@ 57-99 (lines=43) @@
54
55
		ob_start(); // The slideshow shortcode handler calls wp_print_scripts and wp_print_styles... not too happy about that.
56
57
		foreach ( $slideshow_matches as $slideshow_match ) {
58
			$slideshow = do_shortcode_tag( $slideshow_match );
59
			$pos       = stripos( $slideshow, 'jetpack-slideshow' );
60
61
			// must be something wrong - or we changed the output format in which case none of the following will work.
62
			if ( false === $pos ) {
63
				continue;
64
			}
65
66
			$start       = strpos( $slideshow, '[', $pos );
67
			$end         = strpos( $slideshow, ']', $start );
68
			$post_images = json_decode( wp_specialchars_decode( str_replace( "'", '"', substr( $slideshow, $start, $end - $start + 1 ) ), ENT_QUOTES ) ); // parse via JSON
69
			// If the JSON didn't decode don't try and act on it.
70
			if ( is_array( $post_images ) ) {
71
				foreach ( $post_images as $post_image ) {
72
					$post_image_id = absint( $post_image->id );
73
					if ( ! $post_image_id ) {
74
						continue;
75
					}
76
77
					$meta = wp_get_attachment_metadata( $post_image_id );
78
79
					// Must be larger than 200x200 (or user-specified).
80
					if ( ! isset( $meta['width'] ) || $meta['width'] < $width ) {
81
						continue;
82
					}
83
					if ( ! isset( $meta['height'] ) || $meta['height'] < $height ) {
84
						continue;
85
					}
86
87
					$url = wp_get_attachment_url( $post_image_id );
88
89
					$images[] = array(
90
						'type'       => 'image',
91
						'from'       => 'slideshow',
92
						'src'        => $url,
93
						'src_width'  => $meta['width'],
94
						'src_height' => $meta['height'],
95
						'href'       => $permalink,
96
					);
97
				}
98
			}
99
		}
100
		ob_end_clean();
101
102
		$GLOBALS['shortcode_tags'] = $old_shortcodes;

projects/plugins/jetpack/class.jetpack-post-images.php 1 location

@@ 53-90 (lines=38) @@
50
51
		ob_start(); // The slideshow shortcode handler calls wp_print_scripts and wp_print_styles... not too happy about that
52
53
		foreach ( $slideshow_matches as $slideshow_match ) {
54
			$slideshow = do_shortcode_tag( $slideshow_match );
55
			if ( false === $pos = stripos( $slideshow, 'jetpack-slideshow' ) ) { // must be something wrong - or we changed the output format in which case none of the following will work
56
				continue;
57
			}
58
			$start       = strpos( $slideshow, '[', $pos );
59
			$end         = strpos( $slideshow, ']', $start );
60
			$post_images = json_decode( wp_specialchars_decode( str_replace( "'", '"', substr( $slideshow, $start, $end - $start + 1 ) ), ENT_QUOTES ) ); // parse via JSON
61
			// If the JSON didn't decode don't try and act on it.
62
			if ( is_array( $post_images ) ) {
63
				foreach ( $post_images as $post_image ) {
64
					if ( ! $post_image_id = absint( $post_image->id ) ) {
65
						continue;
66
					}
67
68
					$meta = wp_get_attachment_metadata( $post_image_id );
69
70
					// Must be larger than 200x200 (or user-specified)
71
					if ( ! isset( $meta['width'] ) || $meta['width'] < $width ) {
72
						continue;
73
					}
74
					if ( ! isset( $meta['height'] ) || $meta['height'] < $height ) {
75
						continue;
76
					}
77
78
					$url = wp_get_attachment_url( $post_image_id );
79
80
					$images[] = array(
81
						'type'       => 'image',
82
						'from'       => 'slideshow',
83
						'src'        => $url,
84
						'src_width'  => $meta['width'],
85
						'src_height' => $meta['height'],
86
						'href'       => $permalink,
87
					);
88
				}
89
			}
90
		}
91
		ob_end_clean();
92
93
		// Operator: Main screen turn on