| @@ 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. | |
| @@ 1829-1876 (lines=48) @@ | ||
| 1826 | * | |
| 1827 | * @return bool | |
| 1828 | */ | |
| 1829 | 	protected function is_file_supported_for_sideloading( $file ) { | |
| 1830 | 		if ( class_exists( 'finfo' ) ) { // php 5.3+ | |
| 1831 | $finfo = new finfo( FILEINFO_MIME ); | |
| 1832 | $mime = explode( '; ', $finfo->file( $file ) ); | |
| 1833 | $type = $mime[0]; | |
| 1834 | ||
| 1835 | 		} elseif ( function_exists( 'mime_content_type' ) ) { // PHP 5.2 | |
| 1836 | $type = mime_content_type( $file ); | |
| 1837 | ||
| 1838 | 		} else { | |
| 1839 | return false; | |
| 1840 | } | |
| 1841 | ||
| 1842 | /** | |
| 1843 | * Filter the list of supported mime types for media sideloading. | |
| 1844 | * | |
| 1845 | * @since 4.0.0 | |
| 1846 | * | |
| 1847 | * @module json-api | |
| 1848 | * | |
| 1849 | * @param array $supported_mime_types Array of the supported mime types for media sideloading. | |
| 1850 | */ | |
| 1851 | $supported_mime_types = apply_filters( 'jetpack_supported_media_sideload_types', array( | |
| 1852 | 'image/png', | |
| 1853 | 'image/jpeg', | |
| 1854 | 'image/gif', | |
| 1855 | 'image/bmp', | |
| 1856 | 'video/quicktime', | |
| 1857 | 'video/mp4', | |
| 1858 | 'video/mpeg', | |
| 1859 | 'video/ogg', | |
| 1860 | 'video/3gpp', | |
| 1861 | 'video/3gpp2', | |
| 1862 | 'video/h261', | |
| 1863 | 'video/h262', | |
| 1864 | 'video/h264', | |
| 1865 | 'video/x-msvideo', | |
| 1866 | 'video/x-ms-wmv', | |
| 1867 | 'video/x-ms-asf', | |
| 1868 | ) ); | |
| 1869 | ||
| 1870 | // If the type returned was not an array as expected, then we know we don't have a match. | |
| 1871 | 		if ( ! is_array( $supported_mime_types ) ) { | |
| 1872 | return false; | |
| 1873 | } | |
| 1874 | ||
| 1875 | return in_array( $type, $supported_mime_types ); | |
| 1876 | } | |
| 1877 | ||
| 1878 | 	function allow_video_uploads( $mimes ) { | |
| 1879 | // if we are on Jetpack, bail - Videos are already allowed | |