diff options
author | 2020-01-06 14:32:30 -0500 | |
---|---|---|
committer | 2020-01-06 14:32:30 -0500 | |
commit | 10ef81bf85ad0a4bad0d204838e14c99ca2526f7 (patch) | |
tree | b4bb36a326d41de12d1a6181d2a2baf34696ac24 /plugins/jetpack/_inc/lib/class.media.php | |
parent | Updating script for Update (diff) | |
download | blogs-gentoo-10ef81bf85ad0a4bad0d204838e14c99ca2526f7.tar.gz blogs-gentoo-10ef81bf85ad0a4bad0d204838e14c99ca2526f7.tar.bz2 blogs-gentoo-10ef81bf85ad0a4bad0d204838e14c99ca2526f7.zip |
Update jetpack 8.0
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
Diffstat (limited to 'plugins/jetpack/_inc/lib/class.media.php')
-rw-r--r-- | plugins/jetpack/_inc/lib/class.media.php | 80 |
1 files changed, 17 insertions, 63 deletions
diff --git a/plugins/jetpack/_inc/lib/class.media.php b/plugins/jetpack/_inc/lib/class.media.php index e48c4aad..9e419580 100644 --- a/plugins/jetpack/_inc/lib/class.media.php +++ b/plugins/jetpack/_inc/lib/class.media.php @@ -16,7 +16,7 @@ class Jetpack_Media { * The returned name has the `{basename}-{hash}-{random-number}.{ext}` shape. * The hash is built according to the filename trying to avoid name collisions * with other media files. - * + * * @param number $media_id - media post ID * @param string $new_filename - the new filename * @return string A random filename. @@ -85,7 +85,7 @@ class Jetpack_Media { /** * Return an array of allowed mime_type items used to upload a media file. - * + * * @return array mime_type array */ static function get_allowed_mime_types( $default_mime_types ) { @@ -110,58 +110,12 @@ class Jetpack_Media { * @return bool */ protected static function is_file_supported_for_sideloading( $file ) { - if ( class_exists( 'finfo' ) ) { // php 5.3+ - // phpcs:ignore PHPCompatibility.PHP.NewClasses.finfoFound - $finfo = new finfo( FILEINFO_MIME ); - $mime = explode( '; ', $finfo->file( $file ) ); - $type = $mime[0]; - - } elseif ( function_exists( 'mime_content_type' ) ) { // PHP 5.2 - $type = mime_content_type( $file ); - - } else { - return false; - } - - /** - * Filter the list of supported mime types for media sideloading. - * - * @since 4.0 - * - * @module json-api - * - * @param array $supported_mime_types Array of the supported mime types for media sideloading. - */ - $supported_mime_types = apply_filters( 'jetpack_supported_media_sideload_types', array( - 'image/png', - 'image/jpeg', - 'image/gif', - 'image/bmp', - 'video/quicktime', - 'video/mp4', - 'video/mpeg', - 'video/ogg', - 'video/3gpp', - 'video/3gpp2', - 'video/h261', - 'video/h262', - 'video/h264', - 'video/x-msvideo', - 'video/x-ms-wmv', - 'video/x-ms-asf', - ) ); - - // If the type returned was not an array as expected, then we know we don't have a match. - if ( ! is_array( $supported_mime_types ) ) { - return false; - } - - return in_array( $type, $supported_mime_types ); + return jetpack_is_file_supported_for_sideloading( $file ); } /** * Try to remove the temporal file from the given file array. - * + * * @param array $file_array Array with data about the temporal file * @return bool `true` if the file has been removed. `false` either the file doesn't exist or it couldn't be removed. */ @@ -173,11 +127,11 @@ class Jetpack_Media { } /** - * Save the given temporal file considering file type, + * Save the given temporal file considering file type, * correct location according to the original file path, etc. * The file type control is done through of `jetpack_supported_media_sideload_types` filter, * which allows define to the users their own file types list. - * + * * @param array $file_array file to save * @param number $media_id * @return array|WP_Error an array with information about the new file saved or a WP_Error is something went wrong. @@ -228,9 +182,9 @@ class Jetpack_Media { /** * Return an object with an snapshot of a revision item. - * + * * @param object $media_item - media post object - * @return object a revision item + * @return object a revision item */ public static function get_snapshot( $media_item ) { $current_file = get_attached_file( $media_item->ID ); @@ -242,7 +196,7 @@ class Jetpack_Media { 'file' => (string) $file_paths['basename'], 'extension' => (string) $file_paths['extension'], 'mime_type' => (string) $media_item->post_mime_type, - 'size' => (int) filesize( $current_file ) + 'size' => (int) filesize( $current_file ), ); return (object) $snapshot; @@ -250,7 +204,7 @@ class Jetpack_Media { /** * Add a new item into revision_history array. - * + * * @param object $media_item - media post object * @param file $file - file recently added * @param bool $has_original_media - condition is the original media has been already added @@ -265,7 +219,7 @@ class Jetpack_Media { } /** * Return the `revision_history` of the given media. - * + * * @param number $media_id - media post ID * @return array `revision_history` array */ @@ -294,7 +248,7 @@ class Jetpack_Media { /** * Try to delete a file according to the dirname of * the media attached file and the filename. - * + * * @param number $media_id - media post ID * @param string $filename - basename of the file ( name-of-file.ext ) * @return bool `true` is the file has been removed, `false` if not. @@ -325,7 +279,7 @@ class Jetpack_Media { * 'from' => (int) <from>, * 'to' => (int) <to>, * ) - * + * * Also, it removes the file defined in each item. * * @param number $media_id - media post ID @@ -364,7 +318,7 @@ class Jetpack_Media { /** * Limit the number of items of the `revision_history` array. * When the stack is overflowing the oldest item is remove from there (FIFO). - * + * * @param number $media_id - media post ID * @param number [$limit] - maximun amount of items. 20 as default. * @return array items removed from `revision_history` @@ -393,7 +347,7 @@ class Jetpack_Media { /** * Remove the original file and clean the post metadata. - * + * * @param number $media_id - media post ID */ public static function clean_original_media( $media_id ) { @@ -412,7 +366,7 @@ class Jetpack_Media { * - remove all media files tied to the `revision_history` items. * - clean `revision_history` meta data. * - remove and clean the `original_media` - * + * * @param number $media_id - media post ID * @return array results of removing these files */ @@ -442,7 +396,7 @@ class Jetpack_Media { * - update attachment file * - preserve original media file * - trace revision history - * + * * @param number $media_id - media post ID * @param array $file_array - temporal file * @return {Post|WP_Error} Updated media item or a WP_Error is something went wrong. |