@@ 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 | /** |
@@ 1972-2019 (lines=48) @@ | ||
1969 | * |
|
1970 | * @return bool |
|
1971 | */ |
|
1972 | protected function is_file_supported_for_sideloading( $file ) { |
|
1973 | if ( class_exists( 'finfo' ) ) { // php 5.3+ |
|
1974 | // phpcs:ignore PHPCompatibility.PHP.NewClasses.finfoFound |
|
1975 | $finfo = new finfo( FILEINFO_MIME ); |
|
1976 | $mime = explode( '; ', $finfo->file( $file ) ); |
|
1977 | $type = $mime[0]; |
|
1978 | ||
1979 | } elseif ( function_exists( 'mime_content_type' ) ) { // PHP 5.2 |
|
1980 | $type = mime_content_type( $file ); |
|
1981 | ||
1982 | } else { |
|
1983 | return false; |
|
1984 | } |
|
1985 | ||
1986 | /** |
|
1987 | * Filter the list of supported mime types for media sideloading. |
|
1988 | * |
|
1989 | * @since 4.0.0 |
|
1990 | * |
|
1991 | * @module json-api |
|
1992 | * |
|
1993 | * @param array $supported_mime_types Array of the supported mime types for media sideloading. |
|
1994 | */ |
|
1995 | $supported_mime_types = apply_filters( |
|
1996 | 'jetpack_supported_media_sideload_types', |
|
1997 | array( |
|
1998 | 'image/png', |
|
1999 | 'image/jpeg', |
|
2000 | 'image/gif', |
|
2001 | 'image/bmp', |
|
2002 | 'video/quicktime', |
|
2003 | 'video/mp4', |
|
2004 | 'video/mpeg', |
|
2005 | 'video/ogg', |
|
2006 | 'video/3gpp', |
|
2007 | 'video/3gpp2', |
|
2008 | 'video/h261', |
|
2009 | 'video/h262', |
|
2010 | 'video/h264', |
|
2011 | 'video/x-msvideo', |
|
2012 | 'video/x-ms-wmv', |
|
2013 | 'video/x-ms-asf', |
|
2014 | ) |
|
2015 | ); |
|
2016 | ||
2017 | // If the type returned was not an array as expected, then we know we don't have a match. |
|
2018 | if ( ! is_array( $supported_mime_types ) ) { |
|
2019 | return false; |
|
2020 | } |
|
2021 | ||
2022 | return in_array( $type, $supported_mime_types ); |