Code Duplication    Length = 48-48 lines in 2 locations

_inc/lib/class.media.php 1 location

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

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 ) {