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

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