mirror of
https://github.com/10h30/ultimatemember.git
synced 2026-07-19 14:43:49 +09:00
Initial File and Image Uploader
This commit is contained in:
@@ -774,6 +774,63 @@ function um_is_temp_image( $url ) {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check user's file ownership
|
||||
* @param string $url
|
||||
* @param integer $user_id
|
||||
* @return bool
|
||||
*/
|
||||
function um_is_file_owner( $url, $user_id = null, $image_path = false ){
|
||||
|
||||
if( strpos( $url, "/uploads/ultimatemember/{$user_id}/" ) !== false && is_user_logged_in() ){
|
||||
|
||||
$user_basedir = UM()->uploader()->get_upload_user_base_dir( $user_id );
|
||||
|
||||
$filename = wp_basename( parse_url( $url, PHP_URL_PATH ) );
|
||||
|
||||
$file = $user_basedir . '/' . $filename;
|
||||
if( file_exists( $file ) ){
|
||||
if( $image_path ){
|
||||
return $file;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}else{
|
||||
$user_basedir = UM()->uploader()->get_upload_user_base_dir( 'temp' );
|
||||
|
||||
$filename = wp_basename( parse_url( $url, PHP_URL_PATH ) );
|
||||
|
||||
$file = $user_basedir . '/' . $filename;
|
||||
if( file_exists( $file ) ){
|
||||
if( $image_path ){
|
||||
return $file;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if file is temporary
|
||||
* @param string $filename
|
||||
* @return bool
|
||||
*/
|
||||
function um_is_temp_file( $filename ){
|
||||
$user_basedir = UM()->uploader()->get_upload_user_base_dir( 'temp' );
|
||||
|
||||
$file = $user_basedir . '/' . $filename;
|
||||
|
||||
if( file_exists( $file ) ){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get core page url
|
||||
*
|
||||
@@ -1645,8 +1702,8 @@ function um_user_uploads_dir() {
|
||||
*/
|
||||
function um_closest_num( $array, $number ) {
|
||||
sort( $array );
|
||||
foreach ($array as $a) {
|
||||
if ($a >= $number) return $a;
|
||||
foreach ( $array as $a ) {
|
||||
if ( $a >= $number ) return $a;
|
||||
}
|
||||
|
||||
return end( $array );
|
||||
@@ -1664,17 +1721,20 @@ function um_closest_num( $array, $number ) {
|
||||
function um_get_cover_uri( $image, $attrs ) {
|
||||
$uri = false;
|
||||
$ext = '.' . pathinfo( $image, PATHINFO_EXTENSION );
|
||||
if (file_exists( UM()->files()->upload_basedir . um_user( 'ID' ) . '/cover_photo' . $ext )) {
|
||||
$uri = um_user_uploads_uri() . 'cover_photo' . $ext . '?' . current_time( 'timestamp' );
|
||||
if (file_exists( UM()->files()->upload_basedir . um_user( 'ID' ) . "/cover_photo{$ext}" ) ) {
|
||||
$uri = um_user_uploads_uri() . "/cover_photo{$ext}?" . current_time( 'timestamp' );
|
||||
}
|
||||
if (file_exists( UM()->files()->upload_basedir . um_user( 'ID' ) . '/cover_photo-' . $attrs . $ext )) {
|
||||
$uri = um_user_uploads_uri() . 'cover_photo-' . $attrs . $ext . '?' . current_time( 'timestamp' );
|
||||
|
||||
if ( file_exists( UM()->files()->upload_basedir . um_user( 'ID' ) . "/cover_photo-{$attrs}x{$attrs}{$ext}" ) ) {
|
||||
$uri = um_user_uploads_uri() . "/cover_photo-{$attrs}x{$attrs}{$ext}?". current_time( 'timestamp' );
|
||||
}else if ( file_exists( UM()->files()->upload_basedir . um_user( 'ID' ) . "/cover_photo-{$attrs}{$ext}" ) ) {
|
||||
$uri = um_user_uploads_uri() . "/cover_photo-{$attrs}{$ext}?" . current_time( 'timestamp' );
|
||||
}
|
||||
|
||||
return $uri;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* get avatar URL instead of image
|
||||
*
|
||||
@@ -1701,7 +1761,6 @@ function um_get_avatar_uri( $image, $attrs ) {
|
||||
$uri = false;
|
||||
$find = false;
|
||||
$ext = '.' . pathinfo( $image, PATHINFO_EXTENSION );
|
||||
|
||||
/**
|
||||
* UM hook
|
||||
*
|
||||
@@ -1724,26 +1783,26 @@ function um_get_avatar_uri( $image, $attrs ) {
|
||||
* ?>
|
||||
*/
|
||||
$cache_time = apply_filters( 'um_filter_avatar_cache_time', current_time( 'timestamp' ), um_user( 'ID' ) );
|
||||
|
||||
if( $attrs == 'original' && file_exists( um_user_uploads_dir() . "profile_photo{$ext}" ) ) {
|
||||
$uri = um_user_uploads_uri() . "profile_photo{$ext}";
|
||||
} else if (file_exists( um_user_uploads_dir() . "profile_photo-{$attrs}{$ext}" )) {
|
||||
} else if ( file_exists( um_user_uploads_dir() . "profile_photo-{$attrs}x{$attrs}{$ext}" ) ) {
|
||||
$uri = um_user_uploads_uri() . "profile_photo-{$attrs}x{$attrs}{$ext}";
|
||||
} else if ( file_exists( um_user_uploads_dir() . "profile_photo-{$attrs}{$ext}" ) ) {
|
||||
$uri = um_user_uploads_uri() . "profile_photo-{$attrs}{$ext}";
|
||||
} else {
|
||||
$sizes = UM()->options()->get( 'photo_thumb_sizes' );
|
||||
if (is_array( $sizes )) $find = um_closest_num( $sizes, $attrs );
|
||||
|
||||
if (file_exists( um_user_uploads_dir() . "profile_photo-{$find}{$ext}" )) {
|
||||
if ( is_array( $sizes ) ) $find = um_closest_num( $sizes, $attrs );
|
||||
if ( file_exists( um_user_uploads_dir() . "profile_photo-{$find}x{$find}{$ext}" ) ) {
|
||||
$uri = um_user_uploads_uri() . "profile_photo-{$find}x{$find}{$ext}";
|
||||
}else if ( file_exists( um_user_uploads_dir() . "profile_photo-{$find}{$ext}" ) ) {
|
||||
$uri = um_user_uploads_uri() . "profile_photo-{$find}{$ext}";
|
||||
} else if (file_exists( um_user_uploads_dir() . "profile_photo{$ext}" )) {
|
||||
} else if ( file_exists( um_user_uploads_dir() . "profile_photo{$ext}" ) ) {
|
||||
$uri = um_user_uploads_uri() . "profile_photo{$ext}";
|
||||
}
|
||||
}
|
||||
|
||||
if ( !empty( $cache_time ) ) {
|
||||
$uri .= "?{$cache_time}";
|
||||
}
|
||||
|
||||
return $uri;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user