getThumberExtensions() ); } /** * Used in sorting an array of thumbers. * * @param $t1 DG_AbstractThumber First thumber. * @param $t2 DG_AbstractThumber Second thumber. * @return int Negative if $t1 has a higher priority, positive if $t1 has a lower priority. */ public static function cmpThumberByPriority( $t1, $t2 ) { return $t2->getPriority() - $t1->getPriority(); } /** * Checks whether exec() may be used. * Source: http://stackoverflow.com/a/12980534/866618 * * @return bool Whether exec() is available. */ public static function isExecAvailable() { static $available = null; if ( is_null( $available ) ) { $available = true; if ( ini_get( 'safe_mode' ) ) { $available = false; } else { $d = ini_get( 'disable_functions' ); $s = ini_get( 'suhosin.executor.func.blacklist' ); if ( "$d$s" ) { $array = preg_split( '/,\s*/', "$d,$s" ); $available = ! in_array( 'exec', $array ); } } } return $available; } /** * @param $ID int The attachment ID. * @return bool|string The attachment extension on success, false on failure. */ protected static function getAttachmentExt( $ID ) { return self::getExt( get_attached_file( $ID ) ); } /** * Formerly achieved with wp_check_filetype(), but it was only returning * valid results if the active user had permission to upload the given filetype. * * @param string $filename Name of the file to get extension from. * * @return bool|string Returns the file extension on success, false on failure. */ protected static function getExt( $filename ) { if ( $ext = pathinfo( $filename, PATHINFO_EXTENSION ) ) { $res = preg_grep( '/^(?:.*\|)?' . $ext . '(?:\|.*)?$/i', self::getAllExts() ); $res = reset( $res ); if ( $res === false ) { $ext = false; } } if ( ! $ext && ( $info = getimagesize( $filename ) ) && ( $ext = image_type_to_extension( $info[2], false ) ) ) { return $ext; } return $ext; } /** * Addresses issues with getting a complete list of supported MIME types as * described in this issue: https://core.trac.wordpress.org/ticket/32544 * @return string[] Contains all MIME types supported by WordPress, including custom types added by plugins. */ protected static function getAllExts() { static $exts = null; if ( is_null( $exts ) ) { $exts = array_keys( array_merge( wp_get_mime_types(), get_allowed_mime_types() ) ); } return $exts; } }