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
			$finfo = new finfo( FILEINFO_MIME );
115
			$mime = explode( '; ', $finfo->file( $file ) );
116
			$type = $mime[0];
117
118
		} elseif ( function_exists( 'mime_content_type' ) ) { // PHP 5.2
119
			$type = mime_content_type( $file );
120
121
		} else {
122
			return false;
123
		}
124
125
		/**
126
		 * Filter the list of supported mime types for media sideloading.
127
		 *
128
		 * @since 4.0
129
		 *
130
		 * @module json-api
131
		 *
132
		 * @param array $supported_mime_types Array of the supported mime types for media sideloading.
133
		 */
134
		$supported_mime_types = apply_filters( 'jetpack_supported_media_sideload_types', array(
135
			'image/png',
136
			'image/jpeg',
137
			'image/gif',
138
			'image/bmp',
139
			'video/quicktime',
140
			'video/mp4',
141
			'video/mpeg',
142
			'video/ogg',
143
			'video/3gpp',
144
			'video/3gpp2',
145
			'video/h261',
146
			'video/h262',
147
			'video/h264',
148
			'video/x-msvideo',
149
			'video/x-ms-wmv',
150
			'video/x-ms-asf',
151
		) );
152
153
		// If the type returned was not an array as expected, then we know we don't have a match.
154
		if ( ! is_array( $supported_mime_types ) ) {
155
			return false;
156
		}
157
158
		return in_array( $type, $supported_mime_types );
159
	}
160
161
	/**
162
	 * Try to remove the temporal file from the given file array.

class.json-api-endpoints.php 1 location

@@ 1900-1947 (lines=48) @@
1897
	 *
1898
	 * @return bool
1899
	 */
1900
	protected function is_file_supported_for_sideloading( $file ) {
1901
		if ( class_exists( 'finfo' ) ) { // php 5.3+
1902
			$finfo = new finfo( FILEINFO_MIME );
1903
			$mime = explode( '; ', $finfo->file( $file ) );
1904
			$type = $mime[0];
1905
1906
		} elseif ( function_exists( 'mime_content_type' ) ) { // PHP 5.2
1907
			$type = mime_content_type( $file );
1908
1909
		} else {
1910
			return false;
1911
		}
1912
1913
		/**
1914
		 * Filter the list of supported mime types for media sideloading.
1915
		 *
1916
		 * @since 4.0.0
1917
		 *
1918
		 * @module json-api
1919
		 *
1920
		 * @param array $supported_mime_types Array of the supported mime types for media sideloading.
1921
		 */
1922
		$supported_mime_types = apply_filters( 'jetpack_supported_media_sideload_types', array(
1923
			'image/png',
1924
			'image/jpeg',
1925
			'image/gif',
1926
			'image/bmp',
1927
			'video/quicktime',
1928
			'video/mp4',
1929
			'video/mpeg',
1930
			'video/ogg',
1931
			'video/3gpp',
1932
			'video/3gpp2',
1933
			'video/h261',
1934
			'video/h262',
1935
			'video/h264',
1936
			'video/x-msvideo',
1937
			'video/x-ms-wmv',
1938
			'video/x-ms-asf',
1939
		) );
1940
1941
		// If the type returned was not an array as expected, then we know we don't have a match.
1942
		if ( ! is_array( $supported_mime_types ) ) {
1943
			return false;
1944
		}
1945
1946
		return in_array( $type, $supported_mime_types );
1947
	}
1948
1949
	function allow_video_uploads( $mimes ) {
1950
		// if we are on Jetpack, bail - Videos are already allowed