Ticket #4948: 4948.02.patch
File 4948.02.patch, 5.2 KB (added by , 11 years ago) |
---|
-
bp-core/bp-core-avatars.php
function bp_core_check_avatar_type($file) { 783 783 } 784 784 785 785 /** 786 * bp_core_avatar_upload_path()786 * Fetches data from the BP root blog's upload directory. 787 787 * 788 * Returns the absolute upload path for the WP installation 788 * Handy for multisite instances because all uploads are made on the BP root 789 * blog and we need to query the BP root blog for the upload directory data. 789 790 * 790 * @uses wp_upload_dir To get upload directory info 791 * @return string Absolute path to WP upload directory 791 * This function ensures that we only need to use {@link switch_to_blog()} 792 * once to get what we need. 793 * 794 * @since BuddyPress (1.7.1) 795 * 796 * @uses wp_upload_dir() 797 * 798 * @param string $type The variable we want to return from the $bp->avatars object. 799 * Only 'upload_path' and 'url' are supported. 800 * @return string 792 801 */ 793 function bp_core_ avatar_upload_path() {802 function bp_core_get_upload_dir( $type = 'upload_path' ) { 794 803 $bp = buddypress(); 795 804 805 switch ( $type ) { 806 case 'upload_path' : 807 $constant = 'BP_AVATAR_UPLOAD_PATH'; 808 $key = 'basedir'; 809 810 break; 811 812 case 'url' : 813 $constant = 'BP_AVATAR_URL'; 814 $key = 'baseurl'; 815 816 break; 817 818 default : 819 return false; 820 821 break; 822 } 823 796 824 // See if the value has already been calculated and stashed in the $bp global 797 if ( isset( $bp->avatar-> upload_path) ) {798 $ basedir = $bp->avatar->upload_path;825 if ( isset( $bp->avatar->$type ) ) { 826 $retval = $bp->avatar->$type; 799 827 } else { 800 828 // If this value has been set in a constant, just use that 801 if ( defined( 'BP_AVATAR_UPLOAD_PATH') ) {802 $ basedir = BP_AVATAR_UPLOAD_PATH;829 if ( defined( $constant ) ) { 830 $retval = constant( $constant ); 803 831 } else { 804 if ( !bp_is_root_blog() ) {805 // Switch dynamically in order to support BP_ENABLE_MULTIBLOG806 switch_to_blog( bp_get_root_blog_id() );807 }808 832 809 // Get upload directory information from current site 810 $upload_dir = wp_upload_dir(); 833 // Use cached upload dir data if available 834 if ( ! empty( $bp->avatar->upload_dir ) ) { 835 $upload_dir = $bp->avatar->upload_dir; 836 837 // No cache, so query for it 838 } else { 839 // We need to switch to the root blog on multisite installs 840 if ( is_multisite() ) { 841 switch_to_blog( bp_get_root_blog_id() ); 842 } 843 844 // Get upload directory information from current site 845 $upload_dir = wp_upload_dir(); 846 847 // Will bail if not switched 848 restore_current_blog(); 849 850 // Stash upload directory data for later use 851 $bp->avatar->upload_dir = $upload_dir; 852 } 811 853 812 854 // Directory does not exist and cannot be created 813 if ( ! empty( $upload_dir['error'] ) ) {814 $ basedir= '';855 if ( ! empty( $upload_dir['error'] ) ) { 856 $retval = ''; 815 857 816 858 } else { 817 $basedir = $upload_dir['basedir']; 859 $retval = $upload_dir[$key]; 860 861 // If $key is 'baseurl', check to see if we're on SSL 862 // Workaround for WP13941, WP15928, WP19037. 863 if ( $key == 'baseurl' && is_ssl() ) { 864 $retval = str_replace( 'http://', 'https://', $retval ); 865 } 818 866 } 819 867 820 // Will bail if not switched821 restore_current_blog();822 868 } 823 869 824 870 // Stash in $bp for later use 825 $bp->avatar-> upload_path = $basedir;871 $bp->avatar->$type = $retval; 826 872 } 827 873 828 return apply_filters( 'bp_core_avatar_upload_path', $basedir ); 874 return $retval; 875 } 876 877 /** 878 * bp_core_avatar_upload_path() 879 * 880 * Returns the absolute upload path for the WP installation 881 * 882 * @uses wp_upload_dir To get upload directory info 883 * @return string Absolute path to WP upload directory 884 */ 885 function bp_core_avatar_upload_path() { 886 return apply_filters( 'bp_core_avatar_upload_path', bp_core_get_upload_dir() ); 829 887 } 830 888 831 889 /** … … function bp_core_avatar_upload_path() { 837 895 * @return string Full URL to current upload location 838 896 */ 839 897 function bp_core_avatar_url() { 840 $bp = buddypress(); 841 842 // See if the value has already been calculated and stashed in the $bp global 843 if ( isset( $bp->avatar->url ) ) { 844 $baseurl = $bp->avatar->url; 845 846 } else { 847 // If this value has been set in a constant, just use that 848 if ( defined( 'BP_AVATAR_URL' ) ) { 849 $baseurl = BP_AVATAR_URL; 850 } else { 851 // Get upload directory information from current site 852 $upload_dir = wp_upload_dir(); 853 854 // Directory does not exist and cannot be created 855 if ( !empty( $upload_dir['error'] ) ) { 856 $baseurl = ''; 857 858 } else { 859 $baseurl = $upload_dir['baseurl']; 860 861 // If we're using https, update the protocol. Workaround for WP13941, WP15928, WP19037. 862 if ( is_ssl() ) 863 $baseurl = str_replace( 'http://', 'https://', $baseurl ); 864 865 // If multisite, and current blog does not match root blog, make adjustments 866 if ( is_multisite() && bp_get_root_blog_id() != get_current_blog_id() ) 867 $baseurl = trailingslashit( get_blog_option( bp_get_root_blog_id(), 'home' ) ) . get_blog_option( bp_get_root_blog_id(), 'upload_path' ); 868 } 869 } 870 871 // Stash in $bp for later use 872 $bp->avatar->url = $baseurl; 873 } 874 875 return apply_filters( 'bp_core_avatar_url', $baseurl ); 898 return apply_filters( 'bp_core_avatar_url', bp_core_get_upload_dir( 'url' ) ); 876 899 } 877 900 878 901 /**