mirror of
https://github.com/10h30/ultimatemember.git
synced 2026-07-19 14:43:49 +09:00
- fixed issue with avatars/cover photos upload without crop;
This commit is contained in:
@@ -2479,7 +2479,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
|
||||
$set_mode = '';
|
||||
}
|
||||
$nonce = wp_create_nonce( 'um_upload_nonce-' . $this->timestamp );
|
||||
$output .= '<div class="um-single-image-preview ' . $crop_class . '" data-crop="' . $crop_data . '" data-ratio="' . $ratio . '" data-min_width="' . $min_width . '" data-min_height="' . $min_height . '" data-coord=""><a href="#" class="cancel"><i class="um-icon-close"></i></a><img src="" alt="" /><div class="um-clear"></div></div><div class="um-clear"></div>';
|
||||
$output .= '<div class="um-single-image-preview ' . $crop_class . '" data-crop="' . $crop_data . '" data-ratio="' . $ratio . '" data-min_width="' . $min_width . '" data-min_height="' . $min_height . '" data-coord=""><a href="javascript:void(0);" class="cancel"><i class="um-icon-close"></i></a><img src="" alt="" /><div class="um-clear"></div></div><div class="um-clear"></div>';
|
||||
$output .= '<div class="um-single-image-upload" data-user_id="' . esc_attr( $_um_profile_id ) . '" data-nonce="' . $nonce . '" data-timestamp="' . esc_attr( $this->timestamp ) . '" data-icon="' . esc_attr( $icon ) . '" data-set_id="' . esc_attr( $set_id ) . '" data-set_mode="' . esc_attr( $set_mode ) . '" data-type="' . esc_attr( $type ) . '" data-key="' . esc_attr( $key ) . '" data-max_size="' . esc_attr( $max_size ) . '" data-max_size_error="' . esc_attr( $max_size_error ) . '" data-min_size_error="' . esc_attr( $min_size_error ) . '" data-extension_error="' . esc_attr( $extension_error ) . '" data-allowed_types="' . esc_attr( $allowed_types ) . '" data-upload_text="' . esc_attr( $upload_text ) . '" data-max_files_error="' . esc_attr( $max_files_error ) . '" data-upload_help_text="' . esc_attr( $upload_help_text ) . '">' . $button_text . '</div>';
|
||||
$output .= '<div class="um-modal-footer">
|
||||
<div class="um-modal-right">
|
||||
|
||||
@@ -302,9 +302,10 @@ if ( ! class_exists( 'um\core\Files' ) ) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Image upload by AJAX
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
function ajax_image_upload() {
|
||||
$ret['error'] = null;
|
||||
@@ -339,7 +340,7 @@ if ( ! class_exists( 'um\core\Files' ) ) {
|
||||
* }
|
||||
* ?>
|
||||
*/
|
||||
$um_image_upload_nonce = apply_filters( "um_image_upload_nonce", true );
|
||||
$um_image_upload_nonce = apply_filters( 'um_image_upload_nonce', true );
|
||||
|
||||
if ( $um_image_upload_nonce ) {
|
||||
if ( ! wp_verify_nonce( $nonce, "um_upload_nonce-{$timestamp}" ) && is_user_logged_in() ) {
|
||||
@@ -356,11 +357,10 @@ if ( ! class_exists( 'um\core\Files' ) ) {
|
||||
UM()->uploader()->replace_upload_dir = true;
|
||||
$uploaded = UM()->uploader()->upload_image( $_FILES[ $id ], $user_id, $id );
|
||||
UM()->uploader()->replace_upload_dir = false;
|
||||
if ( isset( $uploaded['error'] ) ){
|
||||
if ( isset( $uploaded['error'] ) ) {
|
||||
$ret['error'] = $uploaded['error'];
|
||||
} else {
|
||||
$ts = current_time( 'timestamp' );
|
||||
$ret[ ] = $uploaded['handle_upload'];
|
||||
$ret[] = $uploaded['handle_upload'];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1118,250 +1118,13 @@ if ( ! class_exists( 'um\core\Files' ) ) {
|
||||
* @param $source
|
||||
* @param $key
|
||||
*
|
||||
* @deprecated 2.1.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function new_user_upload( $user_id, $source, $key ) {
|
||||
|
||||
if( ! is_numeric( $user_id ) ){
|
||||
wp_die( __("Invalid user ID: ".json_encode( $user_id )." ",'ultimate-member') );
|
||||
}
|
||||
|
||||
$user_id = trim( $user_id );
|
||||
|
||||
// if he does not have uploads dir yet
|
||||
$this->new_user( $user_id );
|
||||
|
||||
if ( is_user_logged_in() && ( get_current_user_id() != $user_id ) && ! UM()->roles()->um_user_can( 'can_edit_everyone' ) ) {
|
||||
wp_die( __( 'Unauthorized to do this attempt.', 'ultimate-member' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* UM hook
|
||||
*
|
||||
* @type filter
|
||||
* @title um_allow_frontend_image_uploads
|
||||
* @description Allow Fronend Image uploads
|
||||
* @input_vars
|
||||
* [{"var":"$allow","type":"bool","desc":"Allow"},
|
||||
* {"var":"$user_id","type":"int","desc":"User ID"},
|
||||
* {"var":"$key","type":"string","desc":"Field Key"}]
|
||||
* @change_log
|
||||
* ["Since: 2.0"]
|
||||
* @usage add_filter( 'um_allow_frontend_image_uploads', 'function_name', 10, 3 );
|
||||
* @example
|
||||
* <?php
|
||||
* add_filter( 'um_allow_frontend_image_uploads', 'my_allow_frontend_image_uploads', 10, 3 );
|
||||
* function my_allow_frontend_image_uploads( $data ) {
|
||||
* // your code here
|
||||
* return $data;
|
||||
* }
|
||||
* ?>
|
||||
*/
|
||||
$allow_frontend_image_uploads = apply_filters( 'um_allow_frontend_image_uploads', false, $user_id, $key );
|
||||
|
||||
if ( $allow_frontend_image_uploads == false && ! is_user_logged_in() && ( $key == 'profile_photo' || $key == 'cover_photo' ) ) {
|
||||
wp_die( __('Unauthorized to do this attempt.','ultimate-member') );
|
||||
}
|
||||
|
||||
$ext = '.' . pathinfo($source, PATHINFO_EXTENSION);
|
||||
|
||||
// copy & overwrite file
|
||||
|
||||
if( in_array( $key , array('profile_photo','cover_photo') ) ){
|
||||
$filename = $key . $ext;
|
||||
$name = $key;
|
||||
}else{
|
||||
$filename = basename( $source );
|
||||
}
|
||||
|
||||
|
||||
|
||||
if ( file_exists( $this->upload_basedir . $user_id . '/' . $filename ) ) {
|
||||
unlink( $this->upload_basedir . $user_id . '/' . $filename );
|
||||
}
|
||||
copy( $source, $this->upload_basedir . $user_id . '/' . $filename );
|
||||
|
||||
$info = @getimagesize( $source );
|
||||
|
||||
// thumbs
|
||||
if ( $key == 'profile_photo' ) {
|
||||
|
||||
list($w, $h) = @getimagesize( $source );
|
||||
|
||||
|
||||
$sizes = UM()->options()->get( 'photo_thumb_sizes' );
|
||||
foreach( $sizes as $size ) {
|
||||
|
||||
$ratio = round( $w / $h, 2 );
|
||||
$height = round( $size / $ratio, 2 );
|
||||
|
||||
if ( file_exists( $this->upload_basedir . $user_id . '/' . $name . '-' . $size . $ext ) ) {
|
||||
unlink( $this->upload_basedir . $user_id . '/' . $name . '-' . $size . $ext );
|
||||
}
|
||||
|
||||
if ( $size < $w ) {
|
||||
|
||||
if ( $info['mime'] == 'image/jpeg' ){
|
||||
$thumb_s = imagecreatefromjpeg( $source );
|
||||
$thumb = imagecreatetruecolor( $size, $size );
|
||||
imagecopyresampled( $thumb, $thumb_s, 0, 0, 0, 0, $size, $size, $w, $h );
|
||||
imagejpeg( $thumb, $this->upload_basedir . $user_id . '/' . $name . '-' . $size . $ext, 100);
|
||||
imagejpeg( $thumb, $this->upload_basedir . $user_id . '/' . $name . $ext, 100);
|
||||
}else if ( $info['mime'] == 'image/png' ){
|
||||
$thumb_s = imagecreatefrompng( $source );
|
||||
$thumb = imagecreatetruecolor( $size, $size );
|
||||
imagealphablending( $thumb, false);
|
||||
imagesavealpha( $thumb, true);
|
||||
imagecopyresampled( $thumb, $thumb_s, 0, 0, 0, 0, $size, $size, $w, $h );
|
||||
imagepng( $thumb, $this->upload_basedir . $user_id . '/' . $name . '-' . $size . $ext );
|
||||
}else if ( $info['mime'] == 'image/gif' ){
|
||||
$thumb_s = imagecreatefromgif( $source );
|
||||
$thumb = imagecreatetruecolor( $size, $size );
|
||||
imagecopyresampled( $thumb, $thumb_s, 0, 0, 0, 0, $size, $size, $w, $h );
|
||||
imagegif( $thumb, $this->upload_basedir . $user_id . '/' . $name . '-' . $size . $ext);
|
||||
imagegif( $thumb, $this->upload_basedir . $user_id . '/' . $name . $ext);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// removes a synced profile photo
|
||||
delete_user_meta( $user_id, 'synced_profile_photo' );
|
||||
|
||||
} else if ( $key == 'cover_photo' ) {
|
||||
|
||||
list($w, $h) = @getimagesize( $source );
|
||||
|
||||
$sizes = UM()->options()->get( 'cover_thumb_sizes' );
|
||||
foreach ( $sizes as $size ) {
|
||||
|
||||
$ratio = round( $w / $h, 2 );
|
||||
$height = round( $size / $ratio, 2 );
|
||||
|
||||
if ( file_exists( $this->upload_basedir . $user_id . '/' . $name . '-' . $size . $ext ) ) {
|
||||
unlink( $this->upload_basedir . $user_id . '/' . $name . '-' . $size . $ext );
|
||||
}
|
||||
|
||||
if ( $size < $w ) {
|
||||
|
||||
if ( $info['mime'] == 'image/jpeg' ){
|
||||
$thumb = imagecreatetruecolor( $size, $height );
|
||||
$thumb_s = imagecreatefromjpeg( $source );
|
||||
imagecopyresampled( $thumb, $thumb_s, 0, 0, 0, 0, $size, $height, $w, $h );
|
||||
imagejpeg( $thumb, $this->upload_basedir . $user_id . '/' . $name . '-' . $size . $ext, 100);
|
||||
}else if ( $info['mime'] == 'image/png' ){
|
||||
$thumb_s = imagecreatefrompng( $source );
|
||||
$thumb = imagecreatetruecolor( $size, $height );
|
||||
imagealphablending( $thumb, false);
|
||||
imagesavealpha( $thumb, true);
|
||||
imagecopyresampled( $thumb, $thumb_s, 0, 0, 0, 0, $size, $height, $w, $h );
|
||||
imagepng( $thumb, $this->upload_basedir . $user_id . '/' . $name . '-' . $size . $ext );
|
||||
}else if ( $info['mime'] == 'image/gif' ){
|
||||
$thumb = imagecreatetruecolor( $size, $height );
|
||||
$thumb_s = imagecreatefromgif( $source );
|
||||
imagecopyresampled( $thumb, $thumb_s, 0, 0, 0, 0, $size, $height, $w, $h );
|
||||
imagegif( $thumb, $this->upload_basedir . $user_id . '/' . $name . '-' . $size . $ext);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// clean up temp
|
||||
$dir = dirname( $source );
|
||||
unlink( $source );
|
||||
rmdir( $dir );
|
||||
|
||||
/**
|
||||
* UM hook
|
||||
*
|
||||
* @type action
|
||||
* @title um_before_upload_db_meta
|
||||
* @description Update user's meta before upload
|
||||
* @input_vars
|
||||
* [{"var":"$user_id","type":"int","desc":"User ID"},
|
||||
* {"var":"$key","type":"string","desc":"Meta key"}]
|
||||
* @change_log
|
||||
* ["Since: 2.0"]
|
||||
* @usage add_action( 'um_before_upload_db_meta', 'function_name', 10, 2 );
|
||||
* @example
|
||||
* <?php
|
||||
* add_action( 'um_before_upload_db_meta', 'my_before_upload_db_meta', 10, 2 );
|
||||
* function my_before_upload_db_meta( $user_id, $key ) {
|
||||
* // your code here
|
||||
* }
|
||||
* ?>
|
||||
*/
|
||||
do_action( 'um_before_upload_db_meta', $user_id, $key );
|
||||
/**
|
||||
* UM hook
|
||||
*
|
||||
* @type action
|
||||
* @title um_before_upload_db_meta_{$key}
|
||||
* @description Update user's meta before upload
|
||||
* @input_vars
|
||||
* [{"var":"$user_id","type":"int","desc":"User ID"}]
|
||||
* @change_log
|
||||
* ["Since: 2.0"]
|
||||
* @usage add_action( 'um_before_upload_db_meta_{$key}', 'function_name', 10, 1 );
|
||||
* @example
|
||||
* <?php
|
||||
* add_action( 'um_before_upload_db_meta_{$key}', 'my_before_upload_db_meta', 10, 1 );
|
||||
* function my_before_upload_db_meta( $user_id ) {
|
||||
* // your code here
|
||||
* }
|
||||
* ?>
|
||||
*/
|
||||
do_action( "um_before_upload_db_meta_{$key}", $user_id );
|
||||
|
||||
update_user_meta( $user_id, $key, $filename );
|
||||
|
||||
/**
|
||||
* UM hook
|
||||
*
|
||||
* @type action
|
||||
* @title um_after_upload_db_meta
|
||||
* @description Update user's meta before upload
|
||||
* @input_vars
|
||||
* [{"var":"$user_id","type":"int","desc":"User ID"},
|
||||
* {"var":"$key","type":"string","desc":"Meta key"}]
|
||||
* @change_log
|
||||
* ["Since: 2.0"]
|
||||
* @usage add_action( 'um_after_upload_db_meta', 'function_name', 10, 2 );
|
||||
* @example
|
||||
* <?php
|
||||
* add_action( 'um_after_upload_db_meta', 'my_after_upload_db_meta', 10, 2 );
|
||||
* function my_after_upload_db_meta( $user_id, $key ) {
|
||||
* // your code here
|
||||
* }
|
||||
* ?>
|
||||
*/
|
||||
do_action( 'um_after_upload_db_meta', $user_id, $key );
|
||||
/**
|
||||
* UM hook
|
||||
*
|
||||
* @type action
|
||||
* @title um_after_upload_db_meta_{$key}
|
||||
* @description Update user's meta after upload
|
||||
* @input_vars
|
||||
* [{"var":"$user_id","type":"int","desc":"User ID"}]
|
||||
* @change_log
|
||||
* ["Since: 2.0"]
|
||||
* @usage add_action( 'um_after_upload_db_meta_{$key}', 'function_name', 10, 1 );
|
||||
* @example
|
||||
* <?php
|
||||
* add_action( 'um_after_upload_db_meta_{$key}', 'my_after_upload_db_meta', 10, 1 );
|
||||
* function my_after_upload_db_meta( $user_id ) {
|
||||
* // your code here
|
||||
* }
|
||||
* ?>
|
||||
*/
|
||||
do_action( "um_after_upload_db_meta_{$key}", $user_id );
|
||||
|
||||
// the url of upload
|
||||
return $this->upload_baseurl . $user_id . '/' . $filename;
|
||||
|
||||
um_deprecated_function( 'new_user_upload', '2.1.0', '' );
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -98,20 +98,20 @@ if ( ! class_exists( 'um\core\Uploader' ) ) {
|
||||
* Uploader constructor.
|
||||
*/
|
||||
function __construct() {
|
||||
$this->core_upload_dir = DIRECTORY_SEPARATOR . "ultimatemember" . DIRECTORY_SEPARATOR;
|
||||
$this->core_upload_url = "/ultimatemember/";
|
||||
$this->core_upload_dir = DIRECTORY_SEPARATOR . 'ultimatemember' . DIRECTORY_SEPARATOR;
|
||||
$this->core_upload_url = '/ultimatemember/';
|
||||
$this->upload_image_type = 'stream_photo';
|
||||
$this->wp_upload_dir = wp_upload_dir();
|
||||
$this->temp_upload_dir = "temp";
|
||||
$this->temp_upload_dir = 'temp';
|
||||
|
||||
add_filter( "upload_dir", array( $this, "set_upload_directory" ), 10, 1 );
|
||||
add_filter( "wp_handle_upload_prefilter", array( $this, "validate_upload" ) );
|
||||
add_filter( "um_upload_image_process__profile_photo", array( $this, "profile_photo" ), 10, 6 );
|
||||
add_filter( "um_upload_image_process__cover_photo", array( $this, "cover_photo" ), 10, 6 );
|
||||
add_filter( "um_upload_stream_image_process", array( $this, "stream_photo" ), 10, 6 );
|
||||
add_filter( "um_custom_image_handle_wall_img_upload", array( $this, "stream_photo_data"), 10, 1 );
|
||||
add_filter( 'upload_dir', array( $this, 'set_upload_directory' ), 10, 1 );
|
||||
add_filter( 'wp_handle_upload_prefilter', array( $this, 'validate_upload' ) );
|
||||
|
||||
add_action( "init", array( $this, "init" ) );
|
||||
add_filter( 'um_upload_image_process__profile_photo', array( $this, 'profile_photo' ), 10, 7 );
|
||||
add_filter( 'um_upload_image_process__cover_photo', array( $this, 'cover_photo' ), 10, 7 );
|
||||
add_action( 'um_upload_stream_image_process', array( $this, 'stream_photo' ), 10, 7 );
|
||||
|
||||
add_action( 'init', array( $this, 'init' ) );
|
||||
}
|
||||
|
||||
|
||||
@@ -286,7 +286,7 @@ if ( ! class_exists( 'um\core\Uploader' ) ) {
|
||||
|
||||
|
||||
/**
|
||||
* Upload Image files
|
||||
* Upload Image files
|
||||
*
|
||||
* @param array $uploadedfile
|
||||
* @param int|null $user_id
|
||||
@@ -296,6 +296,7 @@ if ( ! class_exists( 'um\core\Uploader' ) ) {
|
||||
* @since 2.0.22
|
||||
*
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function upload_image( $uploadedfile, $user_id = null, $field_key = '', $upload_type = 'stream_photo' ) {
|
||||
$response = array();
|
||||
@@ -305,7 +306,7 @@ if ( ! class_exists( 'um\core\Uploader' ) ) {
|
||||
}
|
||||
|
||||
if ( empty( $field_key ) ) {
|
||||
$field_key = "custom_field";
|
||||
$field_key = 'custom_field';
|
||||
}
|
||||
|
||||
$this->field_key = $field_key;
|
||||
@@ -318,16 +319,16 @@ if ( ! class_exists( 'um\core\Uploader' ) ) {
|
||||
$this->user_id = $user_id;
|
||||
}
|
||||
|
||||
if ( in_array( $field_key, array( 'profile_photo','cover_photo' ) ) ) {
|
||||
if ( in_array( $field_key, array( 'profile_photo', 'cover_photo' ) ) ) {
|
||||
$this->upload_image_type = $field_key;
|
||||
}
|
||||
|
||||
$field_data = UM()->fields()->get_field( $field_key );
|
||||
|
||||
if ( isset( $field_data['allowed_types'] ) && ! empty( $field_data['allowed_types'] ) ) {
|
||||
$field_allowed_file_types = explode(",", $field_data['allowed_types'] );
|
||||
if ( ! empty( $field_data['allowed_types'] ) ) {
|
||||
$field_allowed_file_types = explode( ',', $field_data['allowed_types'] );
|
||||
} else {
|
||||
$field_allowed_file_types = apply_filters("um_uploader_image_default_filetypes", array('JPG','JPEG','PNG','GIF') );
|
||||
$field_allowed_file_types = apply_filters( 'um_uploader_image_default_filetypes', array( 'JPG', 'JPEG', 'PNG', 'GIF' ) );
|
||||
}
|
||||
|
||||
$allowed_image_mimes = array();
|
||||
@@ -337,12 +338,10 @@ if ( ! class_exists( 'um\core\Uploader' ) ) {
|
||||
$allowed_image_mimes[ $atype['ext'] ] = $atype['type'];
|
||||
}
|
||||
|
||||
$image_compression = UM()->options()->get( 'image_compression' );
|
||||
|
||||
$upload_overrides = array(
|
||||
'test_form' => false,
|
||||
'mimes' => apply_filters( "um_uploader_allowed_image_mimes", $allowed_image_mimes ),
|
||||
'unique_filename_callback' => array( $this, "unique_filename"),
|
||||
'test_form' => false,
|
||||
'mimes' => apply_filters( 'um_uploader_allowed_image_mimes', $allowed_image_mimes ),
|
||||
'unique_filename_callback' => array( $this, 'unique_filename' ),
|
||||
);
|
||||
|
||||
$upload_overrides = apply_filters( "um_image_upload_handler_overrides__{$field_key}", $upload_overrides );
|
||||
@@ -456,10 +455,6 @@ if ( ! class_exists( 'um\core\Uploader' ) ) {
|
||||
*/
|
||||
do_action( "um_after_upload_db_meta_{$field_key}", $this->user_id );
|
||||
|
||||
if ( 'stream_photo' !== $this->upload_image_type ) {
|
||||
update_user_meta( $this->user_id, $field_key, wp_basename( $movefile['url'] ) );
|
||||
}
|
||||
|
||||
$filename = wp_basename( $movefile['url'] );
|
||||
|
||||
$transient = set_transient( "um_{$filename}", $movefile['file_info'], 2 * HOUR_IN_SECONDS );
|
||||
@@ -515,9 +510,9 @@ if ( ! class_exists( 'um\core\Uploader' ) ) {
|
||||
}
|
||||
|
||||
$upload_overrides = array(
|
||||
'test_form' => false,
|
||||
'mimes' => apply_filters( "um_uploader_allowed_file_mimes", $allowed_file_mimes ),
|
||||
'unique_filename_callback' => array( $this, "unique_filename"),
|
||||
'test_form' => false,
|
||||
'mimes' => apply_filters( 'um_uploader_allowed_file_mimes', $allowed_file_mimes ),
|
||||
'unique_filename_callback' => array( $this, 'unique_filename' ),
|
||||
);
|
||||
|
||||
$upload_overrides = apply_filters( "um_file_upload_handler_overrides__{$field_key}", $upload_overrides );
|
||||
@@ -874,6 +869,7 @@ if ( ! class_exists( 'um\core\Uploader' ) ) {
|
||||
|
||||
/**
|
||||
* Make unique filename
|
||||
*
|
||||
* @param string $dir
|
||||
* @param string $filename
|
||||
* @param string $ext
|
||||
@@ -886,8 +882,7 @@ if ( ! class_exists( 'um\core\Uploader' ) ) {
|
||||
if ( empty( $ext ) ) {
|
||||
$image_type = wp_check_filetype( $filename );
|
||||
$ext = strtolower( trim( $image_type['ext'], ' \/.' ) );
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$ext = strtolower( trim( $ext, ' \/.' ) );
|
||||
}
|
||||
|
||||
@@ -896,25 +891,23 @@ if ( ! class_exists( 'um\core\Uploader' ) ) {
|
||||
switch ( $this->upload_image_type ) {
|
||||
|
||||
case 'stream_photo':
|
||||
$hashed = hash('ripemd160', time(). mt_rand(10,1000) );
|
||||
$hashed = hash('ripemd160', time() . mt_rand( 10, 1000 ) );
|
||||
$filename = "stream_photo_{$hashed}.{$ext}";
|
||||
break;
|
||||
break;
|
||||
|
||||
case 'profile_photo':
|
||||
$filename = "profile_photo.{$ext}";
|
||||
break;
|
||||
|
||||
case 'cover_photo':
|
||||
$filename = "cover_photo.{$ext}";
|
||||
break;
|
||||
$filename = "{$this->upload_image_type}_temp.{$ext}";
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
} elseif ( 'file' == $this->upload_type ) {
|
||||
$hashed = hash('ripemd160', time(). mt_rand(10,1000) );
|
||||
$hashed = hash('ripemd160', time() . mt_rand( 10, 1000 ) );
|
||||
$filename = "file_{$hashed}.{$ext}";
|
||||
}
|
||||
|
||||
$this->delete_existing_file( $filename, $ext, $dir );
|
||||
$this->delete_existing_file( $filename, $ext, $dir );
|
||||
|
||||
return $filename;
|
||||
}
|
||||
@@ -929,28 +922,38 @@ if ( ! class_exists( 'um\core\Uploader' ) ) {
|
||||
* @since 2.0.22
|
||||
*/
|
||||
public function delete_existing_file( $filename, $ext = '', $dir = '' ) {
|
||||
if( file_exists( $this->upload_user_basedir . DIRECTORY_SEPARATOR . $filename ) && ! empty( $filename ) ) {
|
||||
unlink( $this->upload_user_basedir . DIRECTORY_SEPARATOR . $filename );
|
||||
if ( file_exists( $this->upload_user_basedir . DIRECTORY_SEPARATOR . $filename ) && ! empty( $filename ) ) {
|
||||
unlink( $this->upload_user_basedir . DIRECTORY_SEPARATOR . $filename );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Profile photo image process
|
||||
*
|
||||
* @param array $response
|
||||
* @param string $image_path
|
||||
* @param string $src
|
||||
* @param string $key
|
||||
* @param integer $user_id
|
||||
* @param string $coord
|
||||
* @param array $crop
|
||||
*
|
||||
* @since 2.0.22
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function profile_photo( $image_path, $src, $key, $user_id, $coord, $crop ) {
|
||||
public function profile_photo( $response, $image_path, $src, $key, $user_id, $coord, $crop ) {
|
||||
$sizes = UM()->options()->get( 'photo_thumb_sizes' );
|
||||
|
||||
$quality = UM()->options()->get( 'image_compression' );
|
||||
|
||||
$image = wp_get_image_editor( $image_path ); // Return an implementation that extends WP_Image_Editor
|
||||
|
||||
$temp_image_path = $image_path;
|
||||
//refresh image_path to make temporary image permanently after upload
|
||||
$image_path = pathinfo( $image_path, PATHINFO_DIRNAME ) . DIRECTORY_SEPARATOR . $key . '.' . pathinfo( $image_path, PATHINFO_EXTENSION );
|
||||
|
||||
if ( ! is_wp_error( $image ) ) {
|
||||
$src_x = $crop[0];
|
||||
$src_y = $crop[1];
|
||||
@@ -959,7 +962,7 @@ if ( ! class_exists( 'um\core\Uploader' ) ) {
|
||||
|
||||
$image->crop( $src_x, $src_y, $src_w, $src_h );
|
||||
|
||||
$max_w = UM()->options()->get('image_max_width');
|
||||
$max_w = UM()->options()->get( 'image_max_width' );
|
||||
if ( $src_w > $max_w ) {
|
||||
$image->resize( $max_w, $src_h );
|
||||
}
|
||||
@@ -970,30 +973,46 @@ if ( ! class_exists( 'um\core\Uploader' ) ) {
|
||||
|
||||
$sizes_array = array();
|
||||
|
||||
foreach( $sizes as $size ){
|
||||
$sizes_array[ ] = array ('width' => $size );
|
||||
foreach ( $sizes as $size ) {
|
||||
$sizes_array[] = array( 'width' => $size );
|
||||
}
|
||||
|
||||
$image->multi_resize( $sizes_array );
|
||||
|
||||
delete_user_meta( $user_id, 'synced_profile_photo' );
|
||||
|
||||
unlink( $temp_image_path );
|
||||
|
||||
$src = str_replace( '/' . $key . '_temp.', '/' . $key . '.', $src );
|
||||
|
||||
$response['image']['source_url'] = $src;
|
||||
$response['image']['source_path'] = $image_path;
|
||||
$response['image']['filename'] = wp_basename( $image_path );
|
||||
|
||||
update_user_meta( $this->user_id, $key, wp_basename( wp_basename( $image_path ) ) );
|
||||
delete_user_meta( $this->user_id, "{$key}_metadata_temp" );
|
||||
} else {
|
||||
wp_send_json_error( esc_js( __( "Unable to crop image file: {$src}", 'ultimate-member' ) ) );
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Cover photo image process
|
||||
*
|
||||
* @param string $src
|
||||
* @param integer $user_id
|
||||
* @param string $coord
|
||||
* @param array $crop
|
||||
* @param array $response
|
||||
*
|
||||
* @since 2.0.22
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function cover_photo( $image_path, $src, $key, $user_id, $coord, $crop ){
|
||||
public function cover_photo( $response, $image_path, $src, $key, $user_id, $coord, $crop ) {
|
||||
|
||||
$sizes = UM()->options()->get( 'cover_thumb_sizes' );
|
||||
|
||||
@@ -1001,6 +1020,11 @@ if ( ! class_exists( 'um\core\Uploader' ) ) {
|
||||
|
||||
$image = wp_get_image_editor( $image_path ); // Return an implementation that extends WP_Image_Editor
|
||||
|
||||
$temp_image_path = $image_path;
|
||||
|
||||
//refresh image_path to make temporary image permanently after upload
|
||||
$image_path = pathinfo( $image_path, PATHINFO_DIRNAME ) . DIRECTORY_SEPARATOR . $key . '.' . pathinfo( $image_path, PATHINFO_EXTENSION );
|
||||
|
||||
if ( ! is_wp_error( $image ) ) {
|
||||
|
||||
$src_x = $crop[0];
|
||||
@@ -1010,7 +1034,7 @@ if ( ! class_exists( 'um\core\Uploader' ) ) {
|
||||
|
||||
$image->crop( $src_x, $src_y, $src_w, $src_h );
|
||||
|
||||
$max_w = UM()->options()->get('image_max_width');
|
||||
$max_w = UM()->options()->get( 'image_max_width' );
|
||||
if ( $src_w > $max_w ) {
|
||||
$image->resize( $max_w, $src_h );
|
||||
}
|
||||
@@ -1021,36 +1045,53 @@ if ( ! class_exists( 'um\core\Uploader' ) ) {
|
||||
|
||||
$sizes_array = array();
|
||||
|
||||
foreach( $sizes as $size ){
|
||||
$sizes_array[ ] = array ('width' => $size );
|
||||
foreach ( $sizes as $size ) {
|
||||
$sizes_array[] = array( 'width' => $size );
|
||||
}
|
||||
|
||||
$resize = $image->multi_resize( $sizes_array );
|
||||
|
||||
// change filenames of resized images
|
||||
foreach( $resize as $row ){
|
||||
$new_filename = str_replace( "x{$row['height']}" , "", $row["file"] );
|
||||
$old_filename = $row["file"];
|
||||
foreach ( $resize as $row ) {
|
||||
$new_filename = str_replace( "x{$row['height']}" , '', $row['file'] );
|
||||
$old_filename = $row['file'];
|
||||
|
||||
rename( dirname( $image_path ) . DIRECTORY_SEPARATOR . $old_filename, dirname( $image_path ) . DIRECTORY_SEPARATOR . $new_filename );
|
||||
}
|
||||
|
||||
unlink( $temp_image_path );
|
||||
|
||||
$src = str_replace( '/' . $key . '_temp.', '/' . $key . '.', $src );
|
||||
|
||||
$response['image']['source_url'] = $src;
|
||||
$response['image']['source_path'] = $image_path;
|
||||
$response['image']['filename'] = wp_basename( $image_path );
|
||||
|
||||
update_user_meta( $this->user_id, $key, wp_basename( wp_basename( $image_path ) ) );
|
||||
delete_user_meta( $this->user_id, "{$key}_metadata_temp" );
|
||||
} else {
|
||||
wp_send_json_error( esc_js( __( "Unable to crop image file: {$src}", 'ultimate-member' ) ) );
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Stream photo image process
|
||||
*
|
||||
* @param array $response
|
||||
* @param string $image_path
|
||||
* @param string $src
|
||||
* @param integer $user_id
|
||||
* @param string $coord
|
||||
* @param array $crop
|
||||
*
|
||||
* @since 2.0.22
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function stream_photo( $image_path, $src, $key, $user_id, $coord, $crop ){
|
||||
public function stream_photo( $response, $image_path, $src, $key, $user_id, $coord, $crop ) {
|
||||
|
||||
$image = wp_get_image_editor( $image_path ); // Return an implementation that extends WP_Image_Editor
|
||||
|
||||
@@ -1059,8 +1100,8 @@ if ( ! class_exists( 'um\core\Uploader' ) ) {
|
||||
if ( ! is_wp_error( $image ) ) {
|
||||
if ( ! empty( $crop ) ) {
|
||||
|
||||
if( ! is_array( $crop ) ) {
|
||||
$crop = explode(",", $crop );
|
||||
if ( ! is_array( $crop ) ) {
|
||||
$crop = explode( ",", $crop );
|
||||
}
|
||||
|
||||
$src_x = $crop[0];
|
||||
@@ -1070,7 +1111,7 @@ if ( ! class_exists( 'um\core\Uploader' ) ) {
|
||||
|
||||
$image->crop( $src_x, $src_y, $src_w, $src_h );
|
||||
|
||||
$max_w = UM()->options()->get('image_max_width');
|
||||
$max_w = UM()->options()->get( 'image_max_width' );
|
||||
if ( $src_w > $max_w ) {
|
||||
$image->resize( $max_w, $src_h );
|
||||
}
|
||||
@@ -1083,26 +1124,14 @@ if ( ! class_exists( 'um\core\Uploader' ) ) {
|
||||
} else {
|
||||
wp_send_json_error( esc_js( __( "Unable to crop stream image file: {$image_path}", 'ultimate-member' ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set stream photo default settings
|
||||
* @param array $args
|
||||
* @return array
|
||||
*
|
||||
* @since 2.0.22
|
||||
*/
|
||||
public function stream_photo_data( $args ) {
|
||||
$args['max_file_size'] = apply_filters( "um_upload_images_stream_maximum_file_size", 9999999 );
|
||||
$args['max_file_size_error'] = sprintf( __( "Maximum file size allowed: %s", 'ultimate-member' ), size_format( $args['max_file_size'] ) );
|
||||
|
||||
return $args;
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Resize Image
|
||||
*
|
||||
* @param string $image_path
|
||||
* @param string $src
|
||||
* @param string $key
|
||||
@@ -1117,24 +1146,30 @@ if ( ! class_exists( 'um\core\Uploader' ) ) {
|
||||
$crop = explode( ',', $coord );
|
||||
$crop = array_map( 'intval', $crop );
|
||||
|
||||
do_action("um_upload_image_process__{$key}", $image_path, $src, $key, $user_id, $coord, $crop );
|
||||
$response = array(
|
||||
'image' => array(
|
||||
'source_url' => $src,
|
||||
'source_path' => $image_path,
|
||||
'filename' => wp_basename( $image_path ),
|
||||
),
|
||||
);
|
||||
|
||||
if ( ! in_array( $key, array('profile_photo','cover_photo') ) ) {
|
||||
do_action( "um_upload_stream_image_process", $image_path, $src, $key, $user_id, $coord, $crop );
|
||||
$response = apply_filters( "um_upload_image_process__{$key}", $response, $image_path, $src, $key, $user_id, $coord, $crop );
|
||||
|
||||
if ( ! in_array( $key, array( 'profile_photo', 'cover_photo' ) ) ) {
|
||||
$response = apply_filters( 'um_upload_stream_image_process', $response, $image_path, $src, $key, $user_id, $coord, $crop );
|
||||
}
|
||||
|
||||
$ret = array();
|
||||
$ret['image']['source_url'] = $src;
|
||||
$ret['image']['source_path'] = $image_path;
|
||||
$ret['image']['filename'] = wp_basename( $image_path );
|
||||
|
||||
return $ret;
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Move temporary files
|
||||
*
|
||||
* run when uploaded files are from custom fields
|
||||
* move them to the users' folder after form submitted
|
||||
*
|
||||
* @param $user_id
|
||||
* @param $files
|
||||
* @param bool $move_only
|
||||
|
||||
@@ -1640,14 +1640,11 @@ if ( ! class_exists( 'um\core\User' ) ) {
|
||||
* Update files
|
||||
*
|
||||
* @param $changes
|
||||
*
|
||||
* @deprecated 2.1.0
|
||||
*/
|
||||
function update_files( $changes ) {
|
||||
|
||||
foreach ( $changes as $key => $uri ) {
|
||||
$src = um_is_temp_upload( $uri );
|
||||
UM()->files()->new_user_upload( $this->id, $src, $key );
|
||||
}
|
||||
|
||||
um_deprecated_function( 'update_files', '2.1.0', '' );
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user