Merge branch 'release/2.0.22' of https://github.com/ultimatemember/ultimatemember into release/2.0.22

This commit is contained in:
nikitozzzzzzz
2018-08-01 11:11:56 +03:00
16 changed files with 1616 additions and 360 deletions
+19
View File
@@ -32,6 +32,25 @@ if ( ! class_exists( 'um\core\AJAX_Common' ) ) {
}
add_action( 'wp_ajax_um_remove_file', array( UM()->files(), 'ajax_remove_file' ) );
add_action( 'wp_ajax_um_delete_profile_photo', array( UM()->profile(), 'ajax_delete_profile_photo' ) );
add_action( 'wp_ajax_um_delete_cover_photo', array( UM()->profile(), 'ajax_delete_cover_photo' ) );
add_action( 'wp_ajax_um_select_options', array( UM()->form(), 'ajax_select_options' ) );
add_action( 'wp_ajax_um_ajax_paginate', array( UM()->query(), 'ajax_paginate' ) );
add_action( 'wp_ajax_um_muted_action', array( UM()->form(), 'ajax_muted_action' ) );
add_action( 'wp_ajax_nopriv_um_remove_file', array( UM()->files(), 'ajax_remove_file' ) );
add_action( 'wp_ajax_um_remove_file', array( UM()->files(), 'ajax_remove_file' ) );
add_action( 'wp_ajax_nopriv_um_fileupload', array( UM()->files(), 'ajax_file_upload' ) );
add_action( 'wp_ajax_um_fileupload', array( UM()->files(), 'ajax_file_upload' ) );
add_action( 'wp_ajax_nopriv_um_imageupload', array( UM()->files(), 'ajax_image_upload' ) );
add_action( 'wp_ajax_um_imageupload', array( UM()->files(), 'ajax_image_upload' ) );
add_action( 'wp_ajax_nopriv_um_resize_image', array( UM()->files(), 'ajax_resize_image' ) );
add_action( 'wp_ajax_um_resize_image', array( UM()->files(), 'ajax_resize_image' ) );
/**
* Fallback for ajax urls
+25 -63
View File
@@ -2219,28 +2219,21 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
/* Single Image Upload */
case 'image':
$output .= '<div class="um-field' . $classes . '"' . $conditional . ' data-key="' . $key . '">';
if (in_array( $key, array( 'profile_photo', 'cover_photo' ) )) {
$field_value = '';
} else {
$field_value = $this->field_value( $key, $default, $data );
}
$output .= '<input type="hidden" name="' . $key . UM()->form()->form_suffix . '" id="' . $key . UM()->form()->form_suffix . '" value="' . $field_value . '" />';
if (isset( $data['label'] )) {
$output .= $this->field_label( $label, $key, $data );
}
$modal_label = ( isset( $data['label'] ) ) ? $data['label'] : __( 'Upload Photo', 'ultimate-member' );
$output .= '<div class="um-field-area" style="text-align: center">';
if ($this->field_value( $key, $default, $data )) {
if (!in_array( $key, array( 'profile_photo', 'cover_photo' ) )) {
if ( ! in_array( $key, array( 'profile_photo', 'cover_photo' ) ) ) {
if (isset( $this->set_mode ) && $this->set_mode == 'register') {
$imgValue = $this->field_value( $key, $default, $data );
$imgValue = UM()->uploader()->get_core_temp_url() . "/" . $this->field_value( $key, $default, $data );
} else {
$imgValue = um_user_uploads_uri() . $this->field_value( $key, $default, $data );
}
@@ -2248,29 +2241,20 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
} else {
$img = '';
}
$output .= '<div class="um-single-image-preview show ' . $crop_class . '" data-crop="' . $crop_data . '" data-key="' . $key . '">
<a href="#" class="cancel"><i class="um-icon-close"></i></a>' . $img . '
</div><a href="#" data-modal="um_upload_single" data-modal-size="' . $modal_size . '" data-modal-copy="1" class="um-button um-btn-auto-width">' . __( 'Change photo', 'ultimate-member' ) . '</a>';
} else {
$output .= '<div class="um-single-image-preview ' . $crop_class . '" data-crop="' . $crop_data . '" data-key="' . $key . '">
<a href="#" class="cancel"><i class="um-icon-close"></i></a>
<img src="" alt="" />
<div class="um-clear"></div></div><a href="#" data-modal="um_upload_single" data-modal-size="' . $modal_size . '" data-modal-copy="1" class="um-button um-btn-auto-width">' . $button_text . '</a>';
}
$output .= '</div>';
/* modal hidden */
$output .= '<div class="um-modal-hidden-content">';
$output .= '<div class="um-modal-header"> ' . $modal_label . '</div>';
$output .= '<div class="um-modal-body">';
if (isset( $this->set_id )) {
$set_id = $this->set_id;
$set_mode = $this->set_mode;
@@ -2278,12 +2262,9 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
$set_id = 0;
$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-upload" 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">
<a href="#" class="um-modal-btn um-finish-upload image disabled" data-key="' . $key . '" data-change="' . __( 'Change photo', 'ultimate-member' ) . '" data-processing="' . __( 'Processing...', 'ultimate-member' ) . '"> ' . __( 'Apply', 'ultimate-member' ) . '</a>
@@ -2291,65 +2272,55 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
</div>
<div class="um-clear"></div>
</div>';
$output .= '</div>';
$output .= '</div>';
/* end */
if ($this->is_error( $key )) {
$output .= $this->field_error( $this->show_error( $key ) );
}
$output .= '</div>';
break;
break;
/* Single File Upload */
case 'file':
$output .= '<div class="um-field' . $classes . '"' . $conditional . ' data-key="' . $key . '">';
$output .= '<input type="hidden" name="' . $key . UM()->form()->form_suffix . '" id="' . $key . UM()->form()->form_suffix . '" value="' . $this->field_value( $key, $default, $data ) . '" />';
if (isset( $data['label'] )) {
$output .= $this->field_label( $label, $key, $data );
}
$modal_label = ( isset( $data['label'] ) ) ? $data['label'] : __( 'Upload Photo', 'ultimate-member' );
$output .= '<div class="um-field-area" style="text-align: center">';
if ($this->field_value( $key, $default, $data )) {
$extension = pathinfo( $this->field_value( $key, $default, $data ), PATHINFO_EXTENSION );
$output .= '<div class="um-single-file-preview show" data-key="' . $key . '">
<a href="#" class="cancel"><i class="um-icon-close"></i></a>
<div class="um-single-fileinfo">
<a href="' . um_user_uploads_uri() . $this->field_value( $key, $default, $data ) . '" target="_blank">
<span class="icon" style="background:' . UM()->files()->get_fonticon_bg_by_ext( $extension ) . '"><i class="' . UM()->files()->get_fonticon_by_ext( $extension ) . '"></i></span>
<span class="filename">' . $this->field_value( $key, $default, $data ) . '</span>
$file_field_value = $this->field_value( $key, $default, $data );
$file_type = wp_check_filetype( $file_field_value );
$file_info = um_user( $data['metakey']."_metadata" );
if( isset( $file_info['original_name'] ) && ! empty( $file_info['original_name'] ) ){
$file_field_value = $file_info['original_name'];
}
if( 'register' == $this->set_mode ){
$file_url = UM()->uploader()->get_core_temp_dir() . "/" . $this->field_value( $key, $default, $data );
}else{
$file_url = um_user_uploads_uri() . $this->field_value( $key, $default, $data );
}
$output .= "<div class=\"um-single-file-preview show\" data-key=\"{$key}\">
<a href=\"#\" class=\"cancel\"><i class=\"um-icon-close\"></i></a>
<div class=\"um-single-fileinfo\">
<a href=\"{$file_url}\" target=\"_blank\">
<span class=\"icon\" style=\"background:" . UM()->files()->get_fonticon_bg_by_ext( $file_type['ext'] ) . "\"><i class=\"" . UM()->files()->get_fonticon_by_ext( $file_type['ext'] ) . "\"></i></span>
<span class=\"filename\">{$file_field_value}</span>
</a>
</div>
</div><a href="#" data-modal="um_upload_single" data-modal-size="' . $modal_size . '" data-modal-copy="1" class="um-button um-btn-auto-width">' . __( 'Change file', 'ultimate-member' ) . '</a>';
</div><a href=\"#\" data-modal=\"um_upload_single\" data-modal-size=\"{$modal_size}\" data-modal-copy=\"1\" class=\"um-button um-btn-auto-width\">" . __( 'Change file', 'ultimate-member' ) . "</a>";
} else {
$output .= '<div class="um-single-file-preview" data-key="' . $key . '">
</div><a href="#" data-modal="um_upload_single" data-modal-size="' . $modal_size . '" data-modal-copy="1" class="um-button um-btn-auto-width">' . $button_text . '</a>';
$output .= '<div class="um-single-file-preview" data-key="{$key}">
</div><a href="#" data-modal="um_upload_single" data-modal-size="{$modal_size}" data-modal-copy="1" class="um-button um-btn-auto-width">{$button_text}</a>';
}
$output .= '</div>';
/* modal hidden */
$output .= '<div class="um-modal-hidden-content">';
$output .= '<div class="um-modal-header"> ' . $modal_label . '</div>';
$output .= '<div class="um-modal-body">';
if (isset( $this->set_id )) {
$set_id = $this->set_id;
$set_mode = $this->set_mode;
@@ -2357,7 +2328,6 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
$set_id = 0;
$set_mode = '';
}
$output .= '<div class="um-single-file-preview">
<a href="#" class="cancel"><i class="um-icon-close"></i></a>
<div class="um-single-fileinfo">
@@ -2367,11 +2337,8 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
</a>
</div>
</div>';
$nonce = wp_create_nonce( 'um_upload_nonce-' . $this->timestamp );
$output .= '<div class="um-single-file-upload" data-timestamp="' . esc_attr( $this->timestamp ) . '" data-nonce="' . $nonce . '" 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">
<a href="#" class="um-modal-btn um-finish-upload file disabled" data-key="' . $key . '" data-change="' . __( 'Change file' ) . '" data-processing="' . __( 'Processing...', 'ultimate-member' ) . '"> ' . __( 'Save', 'ultimate-member' ) . '</a>
@@ -2379,20 +2346,15 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
</div>
<div class="um-clear"></div>
</div>';
$output .= '</div>';
$output .= '</div>';
/* end */
if ($this->is_error( $key )) {
$output .= $this->field_error( $this->show_error( $key ) );
}
$output .= '</div>';
break;
break;
/* Select dropdown */
case 'select':
+229 -214
View File
@@ -70,11 +70,15 @@ if ( ! class_exists( 'um\core\Files' ) ) {
* Remove file by AJAX
*/
function ajax_remove_file() {
UM()->check_frontend_ajax_nonce();
/**
* @var $src
*/
extract( $_REQUEST );
$this->delete_file( $src );
wp_send_json_success();
}
@@ -82,33 +86,191 @@ if ( ! class_exists( 'um\core\Files' ) ) {
* Resize image AJAX handler
*/
function ajax_resize_image() {
$output = 0;
UM()->check_frontend_ajax_nonce();
/**
* @var $key
* @var $src
* @var $coord
* @var $user_id
*/
extract( $_REQUEST );
if ( !isset($src) || !isset($coord) ) die( __('Invalid parameters') );
$coord_n = substr_count($coord, ",");
if ( $coord_n != 3 ) die( __('Invalid coordinates') );
$um_is_temp_image = um_is_temp_image( $src );
if ( !$um_is_temp_image ) die( __('Invalid Image file') );
$crop = explode(',', $coord );
$crop = array_map('intval', $crop);
$uri = UM()->files()->resize_image( $um_is_temp_image, $crop );
// If you're updating a user
if ( isset( $user_id ) && $user_id > 0 ) {
$uri = UM()->files()->new_user_upload( $user_id, $um_is_temp_image, $key );
if ( ! isset( $src ) || ! isset( $coord ) ) {
wp_send_json_error( esc_js( __( 'Invalid parameters', 'ultimate-member' ) ) );
}
$output = $uri;
$coord_n = substr_count( $coord, "," );
if ( $coord_n != 3 ) {
wp_send_json_error( esc_js( __( 'Invalid coordinates', 'ultimate-member' ) ) );
}
$image_path = um_is_file_owner( $src, $user_id, true );
if ( ! $image_path ) {
wp_send_json_error( esc_js( __( 'Invalid file ownership', 'ultimate-member' ) ) );
}
$output = UM()->uploader()->resize_image( $image_path, $src, $key, $user_id, $coord );
delete_option( "um_cache_userdata_{$user_id}" );
if(is_array($output)){ print_r($output); }else{ echo $output; } die;
wp_send_json_success( $output );
}
/**
* Image upload by AJAX
*/
function ajax_image_upload() {
$ret['error'] = null;
$ret = array();
$id = $_POST['key'];
$timestamp = $_POST['timestamp'];
$nonce = $_POST['_wpnonce'];
$user_id = $_POST['user_id'];
UM()->fields()->set_id = $_POST['set_id'];
UM()->fields()->set_mode = $_POST['set_mode'];
/**
* UM hook
*
* @type filter
* @title um_image_upload_nonce
* @description Change Image Upload nonce
* @input_vars
* [{"var":"$nonce","type":"bool","desc":"Nonce"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_image_upload_nonce', 'function_name', 10, 1 ); ?>
* @example
* <?php
* add_filter( 'um_image_upload_nonce', 'my_image_upload_nonce', 10, 1 );
* function my_image_upload_nonce( $nonce ) {
* // your code here
* return $nonce;
* }
* ?>
*/
$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() ) {
// This nonce is not valid.
$ret['error'] = 'Invalid nonce';
wp_send_json_error( $ret );
}
}
if( isset( $_FILES[ $id ]['name'] ) ) {
if( ! is_array( $_FILES[ $id ]['name'] ) ) {
$uploaded = UM()->uploader()->upload_image( $_FILES[ $id ], $user_id, $id );
if ( isset( $uploaded['error'] ) ){
$ret['error'] = $uploaded['error'];
}else{
$ts = current_time( 'timestamp' );
$ret[ ] = $uploaded['handle_upload'];
}
}
} else {
$ret['error'] = __('A theme or plugin compatibility issue','ultimate-member');
}
wp_send_json_success( $ret );
}
/**
* File upload by AJAX
*/
function ajax_file_upload(){
$ret['error'] = null;
$ret = array();
/* commented for enable download files on registration form
* if ( ! is_user_logged_in() ) {
$ret['error'] = 'Invalid user';
die( json_encode( $ret ) );
}*/
$nonce = $_POST['_wpnonce'];
$id = $_POST['key'];
$timestamp = $_POST['timestamp'];
UM()->fields()->set_id = $_POST['set_id'];
UM()->fields()->set_mode = $_POST['set_mode'];
/**
* UM hook
*
* @type filter
* @title um_file_upload_nonce
* @description Change File Upload nonce
* @input_vars
* [{"var":"$nonce","type":"bool","desc":"Nonce"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_file_upload_nonce', 'function_name', 10, 1 ); ?>
* @example
* <?php
* add_filter( 'um_file_upload_nonce', 'my_file_upload_nonce', 10, 1 );
* function my_file_upload_nonce( $nonce ) {
* // your code here
* return $nonce;
* }
* ?>
*/
$um_file_upload_nonce = apply_filters("um_file_upload_nonce", true );
if ( $um_file_upload_nonce ) {
if ( ! wp_verify_nonce( $nonce, 'um_upload_nonce-'.$timestamp ) && is_user_logged_in() ) {
// This nonce is not valid.
$ret['error'] = 'Invalid nonce';
wp_send_json_error( $ret );
}
}
if( isset( $_FILES[ $id ]['name'] ) ) {
if( ! is_array( $_FILES[ $id ]['name'] ) ) {
$uploaded = UM()->uploader()->upload_file( $_FILES[ $id ], $user_id, $id );
if ( isset( $uploaded['error'] ) ){
$ret['error'] = $uploaded['error'];
}else{
$uploaded_file = $uploaded['handle_upload'];
$ret['url'] = $uploaded_file['file_info']['name'];
$ret['icon'] = UM()->files()->get_fonticon_by_ext( $uploaded_file['file_info']['ext'] );
$ret['icon_bg'] = UM()->files()->get_fonticon_bg_by_ext( $uploaded_file['file_info']['ext'] );
$ret['filename'] = $uploaded_file['file_info']['basename'];
$ret['original_name'] = $uploaded_file['file_info']['original_name'];
}
}
} else {
$ret['error'] = __('A theme or plugin compatibility issue','ultimate-member');
}
wp_send_json_success( $ret );
}
@@ -331,6 +493,7 @@ if ( ! class_exists( 'um\core\Files' ) ) {
* @return string
*/
function path_only( $file ) {
return trailingslashit( dirname( $file ) );
}
@@ -457,6 +620,7 @@ if ( ! class_exists( 'um\core\Files' ) ) {
* @param $destination
*/
function upload_temp_file( $source, $destination ) {
move_uploaded_file( $source, $destination );
}
@@ -553,31 +717,62 @@ if ( ! class_exists( 'um\core\Files' ) ) {
*
* @return mixed
*/
function get_image_data( $file ) {
function get_image_data( $file ) {
$array['size'] = filesize( $file );
$finfo = finfo_open( FILEINFO_MIME_TYPE );
$mime_type = finfo_file( $finfo, $file );
$array['image'] = @getimagesize( $file );
if( function_exists('exif_imagetype') ){
$array_exif_image_mimes = array( IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG );
$allowed_types = apply_filters('um_image_upload_allowed_exif_mimes', $array_exif_image_mimes );
if ( $array['image'] > 0 ) {
if( ! in_array( @exif_imagetype( $file ), $allowed_types ) ) {
$array['invalid_image'] = true;
$array['invalid_image'] = false;
return $array;
}
list($width, $height, $type, $attr) = @getimagesize( $file );
}else{
$array_image_mimes = array('image/jpeg','image/png','image/gif');
$allowed_types = apply_filters('um_image_upload_allowed_mimes', $array_image_mimes );
$array['width'] = $width;
$array['height'] = $height;
$array['ratio'] = $width / $height;
if ( ! in_array( $mime_type, $allowed_types ) ) {
$array['extension'] = $this->get_extension_by_mime_type( $array['image']['mime'] );
$array['invalid_image'] = true;
} else {
$array['invalid_image'] = true;
return $array;
}
}
$array['size'] = filesize( $file );
$image_data = @getimagesize( $file );
$array['image'] = $image_data;
$array['invalid_image'] = false;
list($width, $height, $type, $attr) = $image_data;
$array['width'] = $width;
$array['height'] = $height;
$array['ratio'] = $width / $height;
$array['extension'] = $this->get_extension_by_mime_type( $mime_type );
return $array;
}
@@ -589,7 +784,7 @@ if ( ! class_exists( 'um\core\Files' ) ) {
*
* @return null|string|void
*/
function check_image_upload( $file, $field ) {
function check_image_upload( $file, $field, $stream_photo = false ) {
$error = null;
$fileinfo = $this->get_image_data( $file );
@@ -667,8 +862,6 @@ if ( ! class_exists( 'um\core\Files' ) ) {
if ( $fileinfo['invalid_image'] == true ) {
$error = sprintf(__('Your image is invalid or too large!','ultimate-member') );
} elseif ( isset( $data['allowed_types'] ) && !$this->in_array( $fileinfo['extension'], $data['allowed_types'] ) ) {
$error = ( isset( $data['extension_error'] ) && !empty( $data['extension_error'] ) ) ? $data['extension_error'] : 'not allowed';
} elseif ( isset($data['min_size']) && ( $fileinfo['size'] < $data['min_size'] ) ) {
$error = $data['min_size_error'];
} elseif ( isset($data['min_width']) && ( $fileinfo['width'] < $data['min_width'] ) ) {
@@ -696,9 +889,7 @@ if ( ! class_exists( 'um\core\Files' ) ) {
$fileinfo = $this->get_file_data( $file );
$data = UM()->fields()->get_field( $field );
if ( !$this->in_array( $extension, $data['allowed_types'] ) ) {
$error = ( isset( $data['extension_error'] ) && !empty( $data['extension_error'] ) ) ? $data['extension_error'] : 'not allowed';
} elseif ( isset($data['min_size']) && ( $fileinfo['size'] < $data['min_size'] ) ) {
if ( isset($data['min_size']) && ( $fileinfo['size'] < $data['min_size'] ) ) {
$error = $data['min_size_error'];
}
@@ -1146,181 +1337,5 @@ if ( ! class_exists( 'um\core\Files' ) ) {
}
/**
* Image upload by AJAX
*/
function ajax_image_upload() {
$ret['error'] = null;
$ret = array();
$id = $_POST['key'];
$timestamp = $_POST['timestamp'];
$nonce = $_POST['_wpnonce'];
UM()->fields()->set_id = $_POST['set_id'];
UM()->fields()->set_mode = $_POST['set_mode'];
/**
* UM hook
*
* @type filter
* @title um_image_upload_nonce
* @description Change Image Upload nonce
* @input_vars
* [{"var":"$nonce","type":"bool","desc":"Nonce"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_image_upload_nonce', 'function_name', 10, 1 ); ?>
* @example
* <?php
* add_filter( 'um_image_upload_nonce', 'my_image_upload_nonce', 10, 1 );
* function my_image_upload_nonce( $nonce ) {
* // your code here
* return $nonce;
* }
* ?>
*/
$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() ) {
// This nonce is not valid.
$ret['error'] = 'Invalid nonce';
die( json_encode( $ret ) );
}
}
if(isset($_FILES[$id]['name'])) {
if(!is_array($_FILES[$id]['name'])) {
$temp = $_FILES[$id]["tmp_name"];
$file = $id."-".$_FILES[$id]["name"];
$file = sanitize_file_name($file);
$ext = strtolower( pathinfo($file, PATHINFO_EXTENSION) );
$error = UM()->files()->check_image_upload( $temp, $id );
if ( $error ){
$ret['error'] = $error;
} else {
$file = "stream_photo_".md5($file)."_".uniqid().".".$ext;
$ret[ ] = UM()->files()->new_image_upload_temp( $temp, $file, UM()->options()->get('image_compression') );
}
}
} else {
$ret['error'] = __('A theme or plugin compatibility issue','ultimate-member');
}
echo json_encode($ret);
exit;
}
/**
*
*/
function ajax_file_upload(){
$ret['error'] = null;
$ret = array();
/* commented for enable download files on registration form
* if ( ! is_user_logged_in() ) {
$ret['error'] = 'Invalid user';
die( json_encode( $ret ) );
}*/
$nonce = $_POST['_wpnonce'];
$id = $_POST['key'];
$timestamp = $_POST['timestamp'];
UM()->fields()->set_id = $_POST['set_id'];
UM()->fields()->set_mode = $_POST['set_mode'];
/**
* UM hook
*
* @type filter
* @title um_file_upload_nonce
* @description Change File Upload nonce
* @input_vars
* [{"var":"$nonce","type":"bool","desc":"Nonce"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_file_upload_nonce', 'function_name', 10, 1 ); ?>
* @example
* <?php
* add_filter( 'um_file_upload_nonce', 'my_file_upload_nonce', 10, 1 );
* function my_file_upload_nonce( $nonce ) {
* // your code here
* return $nonce;
* }
* ?>
*/
$um_file_upload_nonce = apply_filters("um_file_upload_nonce", true );
if ( $um_file_upload_nonce ) {
if ( ! wp_verify_nonce( $nonce, 'um_upload_nonce-'.$timestamp ) && is_user_logged_in()) {
// This nonce is not valid.
$ret['error'] = 'Invalid nonce';
die( json_encode( $ret ) );
}
}
if(isset($_FILES[$id]['name'])) {
if(!is_array($_FILES[$id]['name'])) {
$temp = $_FILES[$id]["tmp_name"];
/**
* UM hook
*
* @type filter
* @title um_upload_file_name
* @description Change File Upload nonce
* @input_vars
* [{"var":"$filename","type":"string","desc":"Filename"},
* {"var":"$id","type":"int","desc":"ID"},
* {"var":"$name","type":"string","desc":"Name"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_upload_file_name', 'function_name', 10, 3 ); ?>
* @example
* <?php
* add_filter( 'um_upload_file_name', 'my_upload_file_name', 10, 3 );
* function my_upload_file_name( $filename, $id, $name ) {
* // your code here
* return $filename;
* }
* ?>
*/
$file = apply_filters( 'um_upload_file_name', $id . "-" . $_FILES[$id]["name"], $id, $_FILES[$id]["name"] );
$file = sanitize_file_name($file);
$extension = strtolower( pathinfo($file, PATHINFO_EXTENSION) );
$error = UM()->files()->check_file_upload( $temp, $extension, $id );
if ( $error ){
$ret['error'] = $error;
} else {
$ret[] = UM()->files()->new_file_upload_temp( $temp, $file );
$ret['icon'] = UM()->files()->get_fonticon_by_ext( $extension );
$ret['icon_bg'] = UM()->files()->get_fonticon_bg_by_ext( $extension );
$ret['filename'] = $file;
}
}
} else {
$ret['error'] = __('A theme or plugin compatibility issue','ultimate-member');
}
echo json_encode($ret);
exit;
}
}
}
File diff suppressed because it is too large Load Diff
+50
View File
@@ -1885,5 +1885,55 @@ if ( ! class_exists( 'um\core\User' ) ) {
return $hash_email_address;
}
/**
* Move temporary files
*
* @param array $user_id
* @param array $files
*/
function move_temporary_files( $user_id, $files, $move_only = false ){
foreach ( $files as $key => $filename ) {
if( empty( $filename ) ) continue;
$user_basedir = UM()->uploader()->get_upload_user_base_dir( $user_id, true );
$temp_file_path = UM()->uploader()->get_core_temp_dir() . "/" . $filename;
if( file_exists( $temp_file_path ) ){
$extra_hash = hash( 'crc32b', current_time('timestamp') );
if ( strpos( $filename , 'stream_photo_' ) !== false ) {
$new_filename = str_replace("stream_photo_","stream_photo_{$extra_hash}_", $filename );
}else{
$new_filename = str_replace("file_","file_{$extra_hash}_", $filename );
}
if( $move_only ){
$file = $user_basedir. "/" . $filename;
rename( $temp_file_path, $file );
}else{
$file = $user_basedir. "/" . $new_filename;
if( rename( $temp_file_path, $file ) ){
$file_info = get_transient("um_{$filename}");
update_user_meta( $user_id, $key, $new_filename );
update_user_meta( $user_id, "{$key}_metadata", $file_info );
delete_transient("um_{$filename}");
}
}
}
}
}
}
}
+6 -2
View File
@@ -234,7 +234,7 @@ function um_user_edit_profile( $args ) {
if ( isset( $args['submitted'][ $key ] ) ) {
if ( isset( $fields[ $key ]['type'] ) && in_array( $fields[ $key ]['type'], array( 'image', 'file' ) ) &&
( um_is_temp_upload( $args['submitted'][ $key ] ) || $args['submitted'][ $key ] == 'empty_file' ) ) {
( um_is_temp_file( $args['submitted'][ $key ] ) || $args['submitted'][ $key ] == 'empty_file' ) ) {
$files[ $key ] = $args['submitted'][ $key ];
@@ -391,7 +391,11 @@ function um_user_edit_profile( $args ) {
* ?>
*/
do_action( 'um_before_user_upload', um_user( 'ID' ), $files );
UM()->user()->update_files( $files );
//UM()->user()->update_files( $files );
UM()->user()->move_temporary_files( um_user( 'ID' ), $files );
/**
* UM hook
*
+6 -2
View File
@@ -637,7 +637,7 @@ function um_registration_save_files( $user_id, $args ) {
if ( isset( $args['submitted'][$key] ) ) {
if ( isset( $fields[$key]['type'] ) && in_array( $fields[$key]['type'], array( 'image', 'file' ) ) &&
( um_is_temp_upload( $args['submitted'][$key] ) || $args['submitted'][$key] == 'empty_file' )
( um_is_temp_file( $args['submitted'][$key] ) || $args['submitted'][$key] == 'empty_file' )
) {
$files[$key] = $args['submitted'][$key];
@@ -692,7 +692,11 @@ function um_registration_save_files( $user_id, $args ) {
* ?>
*/
do_action( 'um_before_user_upload', $user_id, $files );
UM()->user()->update_files( $files );
//UM()->user()->update_files( $files );
UM()->user()->move_temporary_files( $user_id, $files );
/**
* UM hook
*
+11 -7
View File
@@ -224,21 +224,25 @@ add_filter( 'um_profile_field_filter_hook__date', 'um_profile_field_filter_hook_
*/
function um_profile_field_filter_hook__file( $value, $data ) {
$uri = um_user_uploads_uri() . $value;
$extension = pathinfo( $uri, PATHINFO_EXTENSION);
if ( !file_exists( um_user_uploads_dir() . $value ) ) {
$value = __('This file has been removed.');
$file_type = wp_check_filetype( $value );
if ( ! file_exists( um_user_uploads_dir() . $value ) ) {
$value = __('This file has been removed.','ultimate-member');
} else {
$file_info = um_user( $data['metakey']."_metadata" );
if( isset( $file_info['original_name'] ) && ! empty( $file_info['original_name'] ) ){
$value = $file_info['original_name'];
}
$value = '<div class="um-single-file-preview show">
<div class="um-single-fileinfo">
<a href="' . $uri . '" target="_blank">
<span class="icon" style="background:'. UM()->files()->get_fonticon_bg_by_ext( $extension ) . '"><i class="'. UM()->files()->get_fonticon_by_ext( $extension ) .'"></i></span>
<span class="filename">' . $value . '</span>
<span class="icon" style="background:'. UM()->files()->get_fonticon_bg_by_ext( $file_type['ext'] ) . '"><i class="'. UM()->files()->get_fonticon_by_ext( $file_type['ext'] ) .'"></i></span>
<span class="filename">' . esc_attr( $value ) . '</span>
</a>
</div>
</div>';
}
return $value;
}
add_filter( 'um_profile_field_filter_hook__file', 'um_profile_field_filter_hook__file', 99, 2 );