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