Code Duplication    Length = 48-48 lines in 2 locations

class.json-api-endpoints.php 1 location

@@ 1927-1974 (lines=48) @@
1924
	 *
1925
	 * @return bool
1926
	 */
1927
	protected function is_file_supported_for_sideloading( $file ) {
1928
		if ( class_exists( 'finfo' ) ) { // php 5.3+
1929
			// phpcs:ignore PHPCompatibility.PHP.NewClasses.finfoFound
1930
			$finfo = new finfo( FILEINFO_MIME );
1931
			$mime = explode( '; ', $finfo->file( $file ) );
1932
			$type = $mime[0];
1933
1934
		} elseif ( function_exists( 'mime_content_type' ) ) { // PHP 5.2
1935
			$type = mime_content_type( $file );
1936
1937
		} else {
1938
			return false;
1939
		}
1940
1941
		/**
1942
		 * Filter the list of supported mime types for media sideloading.
1943
		 *
1944
		 * @since 4.0.0
1945
		 *
1946
		 * @module json-api
1947
		 *
1948
		 * @param array $supported_mime_types Array of the supported mime types for media sideloading.
1949
		 */
1950
		$supported_mime_types = apply_filters( 'jetpack_supported_media_sideload_types', array(
1951
			'image/png',
1952
			'image/jpeg',
1953
			'image/gif',
1954
			'image/bmp',
1955
			'video/quicktime',
1956
			'video/mp4',
1957
			'video/mpeg',
1958
			'video/ogg',
1959
			'video/3gpp',
1960
			'video/3gpp2',
1961
			'video/h261',
1962
			'video/h262',
1963
			'video/h264',
1964
			'video/x-msvideo',
1965
			'video/x-ms-wmv',
1966
			'video/x-ms-asf',
1967
		) );
1968
1969
		// If the type returned was not an array as expected, then we know we don't have a match.
1970
		if ( ! is_array( $supported_mime_types ) ) {
1971
			return false;
1972
		}
1973
1974
		return in_array( $type, $supported_mime_types );
1975
	}
1976
1977
	function allow_video_uploads( $mimes ) {

packages/jetpack-core/legacy/class.media.php 1 location

@@ 110-157 (lines=48) @@
107
	 * @param  string $file Path to file to get its mime type.
108
	 * @return bool
109
	 */
110
	protected static function is_file_supported_for_sideloading( $file ) {
111
		if ( class_exists( 'finfo' ) ) { // php 5.3+
112
			// phpcs:ignore PHPCompatibility.PHP.NewClasses.finfoFound
113
			$finfo = new finfo( FILEINFO_MIME );
114
			$mime = explode( '; ', $finfo->file( $file ) );
115
			$type = $mime[0];
116
117
		} elseif ( function_exists( 'mime_content_type' ) ) { // PHP 5.2
118
			$type = mime_content_type( $file );
119
120
		} else {
121
			return false;
122
		}
123
124
		/**
125
		 * Filter the list of supported mime types for media sideloading.
126
		 *
127
		 * @since 4.0
128
		 *
129
		 * @module json-api
130
		 *
131
		 * @param array $supported_mime_types Array of the supported mime types for media sideloading.
132
		 */
133
		$supported_mime_types = apply_filters( 'jetpack_supported_media_sideload_types', array(
134
			'image/png',
135
			'image/jpeg',
136
			'image/gif',
137
			'image/bmp',
138
			'video/quicktime',
139
			'video/mp4',
140
			'video/mpeg',
141
			'video/ogg',
142
			'video/3gpp',
143
			'video/3gpp2',
144
			'video/h261',
145
			'video/h262',
146
			'video/h264',
147
			'video/x-msvideo',
148
			'video/x-ms-wmv',
149
			'video/x-ms-asf',
150
		) );
151
152
		// If the type returned was not an array as expected, then we know we don't have a match.
153
		if ( ! is_array( $supported_mime_types ) ) {
154
			return false;
155
		}
156
157
		return in_array( $type, $supported_mime_types );
158
	}
159
160
	/**