function um_admin_addon_hook($hook) { global $ultimatemember; switch ($hook) { case 'bp_avatar_transfer': if (class_exists('BuddyPress')) { $path = bp_core_avatar_upload_path() . '/avatars'; $files = glob($path . '/*'); $i = 0; foreach ($files as $key) { $q = count(glob("{$key}/*")) === 0 ? 0 : 1; if ($q == 1) { $photo = glob($key . '/*'); foreach ($photo as $file) { if (strstr($file, 'bpfull')) { $get_user_id = explode('/', $file); array_pop($get_user_id); $user_id = end($get_user_id); if (!file_exists($ultimatemember->files->upload_basedir . $user_id . '/profile_photo.jpg')) { $ultimatemember->files->new_user($user_id); copy($file, $ultimatemember->files->upload_basedir . $user_id . '/profile_photo.jpg'); update_user_meta($user_id, 'profile_photo', 'profile_photo.jpg'); $i++; } } } } } $this->content = '<p><strong>Done. Process completed!</p>'; $this->content .= $i . ' user(s) changed.</strong></p>'; } break; } }
private function clean_existing_avatars($type = 'user') { if ('user' === $type) { $avatar_dir = 'avatars'; } elseif ('group' === $object) { $avatar_dir = 'group-avatars'; } $this->rrmdir(bp_core_avatar_upload_path() . '/' . $avatar_dir); }
/** * Set Upload Dir data for avatars. * * @since 2.3.0 * * @uses bp_core_avatar_upload_path() * @uses bp_core_avatar_url() * @uses bp_upload_dir() * @uses BP_Attachment::set_upload_dir() */ public function set_upload_dir() { if (bp_core_avatar_upload_path() && bp_core_avatar_url()) { $this->upload_path = bp_core_avatar_upload_path(); $this->url = bp_core_avatar_url(); $this->upload_dir = bp_upload_dir(); } else { parent::set_upload_dir(); } }
function bp_core_set_avatar_constants() { global $bp; if (!defined('BP_AVATAR_UPLOAD_PATH')) { define('BP_AVATAR_UPLOAD_PATH', bp_core_avatar_upload_path()); } if (!defined('BP_AVATAR_URL')) { define('BP_AVATAR_URL', bp_core_avatar_url()); } if (!defined('BP_AVATAR_THUMB_WIDTH')) { define('BP_AVATAR_THUMB_WIDTH', 32); } if (!defined('BP_AVATAR_THUMB_HEIGHT')) { define('BP_AVATAR_THUMB_HEIGHT', 32); } if (!defined('BP_AVATAR_FULL_WIDTH')) { define('BP_AVATAR_FULL_WIDTH', 184); } if (!defined('BP_AVATAR_FULL_HEIGHT')) { define('BP_AVATAR_FULL_HEIGHT', 184); } if (!defined('BP_AVATAR_ORIGINAL_MAX_WIDTH')) { define('BP_AVATAR_ORIGINAL_MAX_WIDTH', 450); } if (!defined('BP_AVATAR_ORIGINAL_MAX_FILESIZE')) { if (!$bp->site_options['fileupload_maxk']) { define('BP_AVATAR_ORIGINAL_MAX_FILESIZE', 5120000); } else { define('BP_AVATAR_ORIGINAL_MAX_FILESIZE', $bp->site_options['fileupload_maxk'] * 1024); } } if (!defined('BP_AVATAR_DEFAULT')) { define('BP_AVATAR_DEFAULT', BP_PLUGIN_URL . '/bp-core/images/mystery-man.jpg'); } if (!defined('BP_AVATAR_DEFAULT_THUMB')) { define('BP_AVATAR_DEFAULT_THUMB', BP_PLUGIN_URL . '/bp-core/images/mystery-man-50.jpg'); } }
/** * fetch the cover photo of group/user * * @return string url */ function bcp_fetch_cover_photo($args) { $cover_photos_collection = array(); $r = wp_parse_args($args, array('object_id' => 0, 'type' => 'user')); extract($r, EXTR_SKIP); if (0 == $object_id) { return $cover_photos_collection; } $upload_dir = wp_upload_dir(); $avatars_dir = $type == 'user' ? 'avatars' : 'group-avatars'; // begin fetching avatar $avatar_upload_dir = bp_core_avatar_upload_path() . '/' . $avatars_dir . '/' . $object_id . '/'; $avatar_upload_url = $upload_dir['baseurl'] . '/' . $avatars_dir . '/' . $object_id . '/'; // open the dir if (!file_exists($avatar_upload_dir)) { return $cover_photos_collection; } if ($handle = opendir($avatar_upload_dir)) { while (false !== ($entry = readdir($handle))) { if ($entry != "." && $entry != "..") { $file_info = pathinfo($entry); $file_name = $file_info['filename']; $file_ext = $file_info['extension']; $cover_photos = array('coverphoto-full', 'coverphoto-thumb'); if (in_array($file_name, $cover_photos)) { // cover photo exists $cover_photo_url = $avatar_upload_url . $file_name . '.' . $file_ext; $cover_timestamp = '?bcp_cover=' . get_user_meta($object_id, 'cover-photo-timestamp', true); if ('user' !== $type) { $cover_timestamp = '?bcp_group_cover=' . groups_get_groupmeta($object_id, 'cover-photo-timestamp'); } if ('coverphoto-full' == $file_name) { $cover_photos_collection['full'] = $cover_photo_url . $cover_timestamp; } else { $cover_photos_collection['thumb'] = $cover_photo_url . $cover_timestamp; } } } } // close the directory closedir($handle); } return $cover_photos_collection; }
/** * Output the inline JS needed for the cropper to work on a per-page basis. * * @since 1.1.0 */ function bp_core_add_cropper_inline_js() { /** * Filters the return value of getimagesize to determine if an image was uploaded. * * @since 1.1.0 * * @param array $value Array of data found by getimagesize. */ $image = apply_filters('bp_inline_cropper_image', getimagesize(bp_core_avatar_upload_path() . buddypress()->avatar_admin->image->dir)); if (empty($image)) { return; } // Get avatar full width and height. $full_height = bp_core_avatar_full_height(); $full_width = bp_core_avatar_full_width(); // Calculate Aspect Ratio. if (!empty($full_height) && $full_width != $full_height) { $aspect_ratio = $full_width / $full_height; } else { $aspect_ratio = 1; } // Default cropper coordinates. // Smaller than full-width: cropper defaults to entire image. if ($image[0] < $full_width) { $crop_left = 0; $crop_right = $image[0]; // Less than 2x full-width: cropper defaults to full-width. } elseif ($image[0] < $full_width * 2) { $padding_w = round(($image[0] - $full_width) / 2); $crop_left = $padding_w; $crop_right = $image[0] - $padding_w; // Larger than 2x full-width: cropper defaults to 1/2 image width. } else { $crop_left = round($image[0] / 4); $crop_right = $image[0] - $crop_left; } // Smaller than full-height: cropper defaults to entire image. if ($image[1] < $full_height) { $crop_top = 0; $crop_bottom = $image[1]; // Less than double full-height: cropper defaults to full-height. } elseif ($image[1] < $full_height * 2) { $padding_h = round(($image[1] - $full_height) / 2); $crop_top = $padding_h; $crop_bottom = $image[1] - $padding_h; // Larger than 2x full-height: cropper defaults to 1/2 image height. } else { $crop_top = round($image[1] / 4); $crop_bottom = $image[1] - $crop_top; } ?> <script type="text/javascript"> jQuery(window).load( function(){ jQuery('#avatar-to-crop').Jcrop({ onChange: showPreview, onSelect: updateCoords, aspectRatio: <?php echo (int) $aspect_ratio; ?> , setSelect: [ <?php echo (int) $crop_left; ?> , <?php echo (int) $crop_top; ?> , <?php echo (int) $crop_right; ?> , <?php echo (int) $crop_bottom; ?> ] }); }); function updateCoords(c) { jQuery('#x').val(c.x); jQuery('#y').val(c.y); jQuery('#w').val(c.w); jQuery('#h').val(c.h); } function showPreview(coords) { if ( parseInt(coords.w) > 0 ) { var fw = <?php echo (int) $full_width; ?> ; var fh = <?php echo (int) $full_height; ?> ; var rx = fw / coords.w; var ry = fh / coords.h; jQuery( '#avatar-crop-preview' ).css({ width: Math.round(rx * <?php echo (int) $image[0]; ?> ) + 'px', height: Math.round(ry * <?php echo (int) $image[1]; ?> ) + 'px', marginLeft: '-' + Math.round(rx * coords.x) + 'px', marginTop: '-' + Math.round(ry * coords.y) + 'px' }); } } </script> <?php }
/** * Handle the loading of the Activate screen. * * @todo Move the actual activation process into an action in bp-members-actions.php */ function bp_core_screen_activation() { // Bail if not viewing the activation page if (!bp_is_current_component('activate')) { return false; } // If the user is already logged in, redirect away from here if (is_user_logged_in()) { // If activation page is also front page, set to members directory to // avoid an infinite loop. Otherwise, set to root domain. $redirect_to = bp_is_component_front_page('activate') ? bp_get_root_domain() . '/' . bp_get_members_root_slug() : bp_get_root_domain(); // Trailing slash it, as we expect these URL's to be $redirect_to = trailingslashit($redirect_to); /** * Filters the URL to redirect logged in users to when visiting activation page. * * @since BuddyPress (1.9.0) * * @param string $redirect_to URL to redirect user to. */ $redirect_to = apply_filters('bp_loggedin_activate_page_redirect_to', $redirect_to); // Redirect away from the activation page bp_core_redirect($redirect_to); } // grab the key (the old way) $key = isset($_GET['key']) ? $_GET['key'] : ''; // grab the key (the new way) if (empty($key)) { $key = bp_current_action(); } // Get BuddyPress $bp = buddypress(); // we've got a key; let's attempt to activate the signup if (!empty($key)) { /** * Filters the activation signup. * * @since BuddyPress (1.1.0) * * @param bool|int $value Value returned by activation. * Integer on success, boolean on failure. */ $user = apply_filters('bp_core_activate_account', bp_core_activate_signup($key)); // If there were errors, add a message and redirect if (!empty($user->errors)) { bp_core_add_message($user->get_error_message(), 'error'); bp_core_redirect(trailingslashit(bp_get_root_domain() . '/' . $bp->pages->activate->slug)); } $hashed_key = wp_hash($key); // Check if the signup avatar folder exists. If it does, move the folder to // the BP user avatars directory if (file_exists(bp_core_avatar_upload_path() . '/avatars/signups/' . $hashed_key)) { @rename(bp_core_avatar_upload_path() . '/avatars/signups/' . $hashed_key, bp_core_avatar_upload_path() . '/avatars/' . $user); } bp_core_add_message(__('Your account is now active!', 'buddypress')); $bp->activation_complete = true; } /** * Filters the template to load for the Member activation page screen. * * @since BuddyPress (1.1.1) * * @param string $value Path to the Member activation template to load. */ bp_core_load_template(apply_filters('bp_core_template_activate', array('activate', 'registration/activate'))); }
/** * Crop an uploaded avatar. * * $args has the following parameters: * object - What component the avatar is for, e.g. "user" * avatar_dir The absolute path to the avatar * item_id - Item ID * original_file - The absolute path to the original avatar file * crop_w - Crop width * crop_h - Crop height * crop_x - The horizontal starting point of the crop * crop_y - The vertical starting point of the crop * * @param array $args { * Array of function parameters. * @type string $object Object type of the item whose avatar you're * handling. 'user', 'group', 'blog', or custom. Default: 'user'. * @type string $avatar_dir Subdirectory where avatar should be stored. * Default: 'avatars'. * @type bool|int $item_id ID of the item that the avatar belongs to. * @type bool|string $original_file Absolute papth to the original avatar * file. * @type int $crop_w Crop width. Default: the global 'full' avatar width, * as retrieved by bp_core_avatar_full_width(). * @type int $crop_h Crop height. Default: the global 'full' avatar height, * as retrieved by bp_core_avatar_full_height(). * @type int $crop_x The horizontal starting point of the crop. Default: 0. * @type int $crop_y The vertical starting point of the crop. Default: 0. * } * @return bool True on success, false on failure. */ function bp_core_avatar_handle_crop($args = '') { $r = wp_parse_args($args, array('object' => 'user', 'avatar_dir' => 'avatars', 'item_id' => false, 'original_file' => false, 'crop_w' => bp_core_avatar_full_width(), 'crop_h' => bp_core_avatar_full_height(), 'crop_x' => 0, 'crop_y' => 0)); /*** * You may want to hook into this filter if you want to override this function. * Make sure you return false. */ if (!apply_filters('bp_core_pre_avatar_handle_crop', true, $r)) { return true; } extract($r, EXTR_SKIP); if (empty($original_file)) { return false; } $original_file = bp_core_avatar_upload_path() . $original_file; if (!file_exists($original_file)) { return false; } if (empty($item_id)) { $avatar_folder_dir = apply_filters('bp_core_avatar_folder_dir', dirname($original_file), $item_id, $object, $avatar_dir); } else { $avatar_folder_dir = apply_filters('bp_core_avatar_folder_dir', bp_core_avatar_upload_path() . '/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir); } if (!file_exists($avatar_folder_dir)) { return false; } require_once ABSPATH . '/wp-admin/includes/image.php'; require_once ABSPATH . '/wp-admin/includes/file.php'; // Delete the existing avatar files for the object $existing_avatar = bp_core_fetch_avatar(array('object' => $object, 'item_id' => $item_id, 'html' => false)); if (!empty($existing_avatar)) { // Check that the new avatar doesn't have the same name as the // old one before deleting $upload_dir = wp_upload_dir(); $existing_avatar_path = str_replace($upload_dir['baseurl'], '', $existing_avatar); $new_avatar_path = str_replace($upload_dir['basedir'], '', $original_file); if ($existing_avatar_path !== $new_avatar_path) { bp_core_delete_existing_avatar(array('object' => $object, 'item_id' => $item_id, 'avatar_path' => $avatar_folder_dir)); } } // Make sure we at least have a width and height for cropping if (empty($crop_w)) { $crop_w = bp_core_avatar_full_width(); } if (empty($crop_h)) { $crop_h = bp_core_avatar_full_height(); } // Get the file extension $data = @getimagesize($original_file); $ext = $data['mime'] == 'image/png' ? 'png' : 'jpg'; // Set the full and thumb filenames $full_filename = wp_hash($original_file . time()) . '-bpfull.' . $ext; $thumb_filename = wp_hash($original_file . time()) . '-bpthumb.' . $ext; // Crop the image $full_cropped = wp_crop_image($original_file, (int) $crop_x, (int) $crop_y, (int) $crop_w, (int) $crop_h, bp_core_avatar_full_width(), bp_core_avatar_full_height(), false, $avatar_folder_dir . '/' . $full_filename); $thumb_cropped = wp_crop_image($original_file, (int) $crop_x, (int) $crop_y, (int) $crop_w, (int) $crop_h, bp_core_avatar_thumb_width(), bp_core_avatar_thumb_height(), false, $avatar_folder_dir . '/' . $thumb_filename); // Check for errors if (empty($full_cropped) || empty($thumb_cropped) || is_wp_error($full_cropped) || is_wp_error($thumb_cropped)) { return false; } // Remove the original @unlink($original_file); return true; }
public function handle_crop() { require_once ABSPATH . '/wp-admin/includes/image.php'; $user_id = bp_displayed_user_id(); $cover_photo = get_transient('profile_cover_photo_' . $user_id); // Get the file extension $data = @getimagesize($cover_photo); $ext = $data['mime'] == 'image/png' ? 'png' : 'jpg'; $base_filename = basename($cover_photo, '.' . $ext); // create a new filename but, if it's already been cropped, strip out the -cropped $new_filename = str_replace('-cropped', '', $base_filename) . '-cropped.' . $ext; $new_filepath = bp_core_avatar_upload_path() . '/cover-photo/' . $user_id . '/' . $new_filename; $new_fileurl = bp_core_avatar_url() . '/cover-photo/' . $user_id . '/' . $new_filename; $crop_fileurl = str_replace(trailingslashit(get_home_url()), '', bp_core_avatar_url()) . '/cover-photo/' . $user_id . '/' . $new_filename; // delete the old cover photo if it exists if (file_exists($new_filepath)) { @unlink($new_filepath); } $cropped_header = wp_crop_image($cover_photo, $_POST['x'], $_POST['y'], $_POST['w'], $_POST['h'], $this->width, $this->height, false, $crop_fileurl); if (!is_wp_error($cropped_header)) { $old_file_path = get_user_meta(bp_loggedin_user_id(), 'profile_cover_photo_path', true); if (file_exists($old_file_path)) { @unlink($old_file_path); } // update with the new image and path bp_update_user_meta(bp_loggedin_user_id(), 'profile_cover_photo', $new_fileurl); bp_update_user_meta(bp_loggedin_user_id(), 'profile_cover_photo_path', $new_filepath); delete_transient('is_cover_photo_uploaded_' . bp_displayed_user_id()); delete_transient('profile_cover_photo_' . bp_displayed_user_id()); } }
function tv_bp_core_avatar_handle_upload($file, $upload_dir_filter) { /*** * You may want to hook into this filter if you want to override this function. * Make sure you return false. */ if (!apply_filters('bp_core_pre_avatar_handle_upload', true, $file, $upload_dir_filter)) { return true; } require_once ABSPATH . '/wp-admin/includes/file.php'; $uploadErrors = array(0 => __('The image was uploaded successfully', 'buddypress'), 1 => __('The image exceeds the maximum allowed file size of: ', 'buddypress') . size_format(bp_core_avatar_original_max_filesize()), 2 => __('The image exceeds the maximum allowed file size of: ', 'buddypress') . size_format(bp_core_avatar_original_max_filesize()), 3 => __('The uploaded file was only partially uploaded.', 'buddypress'), 4 => __('The image was not uploaded.', 'buddypress'), 6 => __('Missing a temporary folder.', 'buddypress')); if (!bp_core_check_avatar_upload($file)) { bp_core_add_message(sprintf(__('Your upload failed, please try again. Error was: %s', 'buddypress'), $uploadErrors[$file['file']['error']]), 'error'); return false; } if (!bp_core_check_avatar_size($file)) { bp_core_add_message(sprintf(__('The file you uploaded is too big. Please upload a file under %s', 'buddypress'), size_format(bp_core_avatar_original_max_filesize())), 'error'); return false; } if (!bp_core_check_avatar_type($file)) { bp_core_add_message(__('Please upload only JPG, GIF or PNG photos.', 'buddypress'), 'error'); return false; } // Filter the upload location add_filter('upload_dir', $upload_dir_filter, 10, 0); $upload_dir = wp_upload_dir(); emptyDirectory($upload_dir['path']); $bp = buddypress(); $bp->avatar_admin->original = wp_handle_upload($file['file'], array('test_form' => false)); // Remove the upload_dir filter, so that other upload URLs on the page // don't break remove_filter('upload_dir', $upload_dir_filter, 10, 0); // Move the file to the correct upload location. if (!empty($bp->avatar_admin->original['error'])) { bp_core_add_message(sprintf(__('Upload Failed! Error was: %s', 'buddypress'), $bp->avatar_admin->original['error']), 'error'); return false; } // Get image size $size = @getimagesize($bp->avatar_admin->original['file']); $error = false; // Check image size and shrink if too large if ($size[0] > bp_core_avatar_original_max_width()) { $editor = wp_get_image_editor($bp->avatar_admin->original['file']); if (!is_wp_error($editor)) { $editor->set_quality(100); $resized = $editor->resize(bp_core_avatar_original_max_width(), bp_core_avatar_original_max_width(), false); if (!is_wp_error($resized)) { $thumb = $editor->save($editor->generate_filename()); } else { $error = $resized; } // Check for thumbnail creation errors if (false === $error && is_wp_error($thumb)) { $error = $thumb; } // Thumbnail is good so proceed if (false === $error) { $bp->avatar_admin->resized = $thumb; } } else { $error = $editor; } if (false !== $error) { bp_core_add_message(sprintf(__('Upload Failed! Error was: %s', 'buddypress'), $error->get_error_message()), 'error'); return false; } } if (!isset($bp->avatar_admin->image)) { $bp->avatar_admin->image = new stdClass(); } // We only want to handle one image after resize. if (empty($bp->avatar_admin->resized)) { $bp->avatar_admin->image->dir = str_replace(bp_core_avatar_upload_path(), '', $bp->avatar_admin->original['file']); } else { $bp->avatar_admin->image->dir = str_replace(bp_core_avatar_upload_path(), '', $bp->avatar_admin->resized['path']); @unlink($bp->avatar_admin->original['file']); } // Check for WP_Error on what should be an image if (is_wp_error($bp->avatar_admin->image->dir)) { bp_core_add_message(sprintf(__('Upload failed! Error was: %s', 'buddypress'), $bp->avatar_admin->image->dir->get_error_message()), 'error'); return false; } // Set the url value for the image $bp->avatar_admin->image->url = bp_core_avatar_url() . $bp->avatar_admin->image->dir; return true; }
function bp_caver_avatar_handle_upload() { global $bp; if ($_POST['encodedimg']) { $user_id = !empty($_POST['user_id']) ? $_POST['user_id'] : bp_displayed_user_id(); $imgresponse = array(); $uploaddir = bp_core_avatar_upload_path() . '/avatars'; if (!file_exists($uploaddir)) { mkdir($uploaddir); } $img = $_POST['encodedimg']; $img = str_replace('data:' . $_POST['imgtype'] . ';base64,', '', $img); $img = str_replace(' ', '+', $img); $data = base64_decode($img); $filepath = $uploaddir . '/' . $user_id; if (!file_exists($filepath)) { mkdir($filepath); } $imgname = wp_unique_filename($uploaddir, $_POST['imgname']); $fileurl = $filepath . '/' . $imgname; $siteurl = trailingslashit(get_blog_option(1, 'siteurl')); $url = str_replace(ABSPATH, $siteurl, $fileurl); $success = file_put_contents($fileurl, $data); $file = $_POST['imgsize']; $max_upload_size = bp_cover_get_max_media_size(); if ($max_upload_size > $file) { if ($success) { $imgresponse[0] = "1"; $imgresponse[1] = $fileurl; $size = getimagesize($fileurl); /* Check image size and shrink if too large */ if ($size[0] > 150) { $original_file = image_resize($fileurl, 150, 150, true); //$ava_file = image_resize( $fileurl, 250, 250, true ); /* Check for thumbnail creation errors */ if (is_wp_error($original_file)) { $imgresponse[0] = "0"; $imgresponse[1] = sprintf(__('Upload Failed! Error was: %s', 'bp-cover'), $original_file->get_error_message()); die; } $avatar_to_crop = str_replace(bp_core_avatar_upload_path(), '', $original_file); bp_core_delete_existing_avatar(array('item_id' => $user_id, 'avatar_path' => bp_core_avatar_upload_path() . '/avatars/' . $user_id)); $crop_args = array('item_id' => $user_id, 'original_file' => $avatar_to_crop, 'crop_w' => 0, 'crop_h' => 0); bp_core_avatar_handle_crop($crop_args); //$url = str_replace(ABSPATH,$siteurl,$ava_file); update_user_meta(bp_loggedin_user_id(), 'profile_avatar', $url); do_action('xprofile_avatar_uploaded'); } else { $imgresponse[0] = "0"; $imgresponse[1] = __('Upload Failed! Your photo must be larger than 150px', 'bp-cover'); } } else { $imgresponse[0] = "0"; $imgresponse[1] = __('Upload Failed! Unable to write the image on server', 'bp-cover'); } } else { $imgresponse[0] = "0"; $imgresponse[1] = sprintf(__('The file you uploaded is too big. Please upload a file under %s', 'bp-cover'), size_format($max_upload_size)); } } else { $imgresponse[0] = "0"; $imgresponse[1] = __('Upload Failed! No image sent', 'bp-cover'); } /* if everything is ok, we send back url to thumbnail and to full image */ echo json_encode($imgresponse); die; }
function bp_core_screen_activation() { global $bp; if (!bp_is_current_component('activate')) { return false; } // Check if an activation key has been passed if (isset($_GET['key'])) { // Activate the signup $user = apply_filters('bp_core_activate_account', bp_core_activate_signup($_GET['key'])); // If there were errors, add a message and redirect if (!empty($user->errors)) { bp_core_add_message($user->get_error_message(), 'error'); bp_core_redirect(trailingslashit(bp_get_root_domain() . '/' . $bp->pages->activate->slug)); } // Check for an uploaded avatar and move that to the correct user folder if (is_multisite()) { $hashed_key = wp_hash($_GET['key']); } else { $hashed_key = wp_hash($user); } // Check if the avatar folder exists. If it does, move rename it, move // it and delete the signup avatar dir if (file_exists(bp_core_avatar_upload_path() . '/avatars/signups/' . $hashed_key)) { @rename(bp_core_avatar_upload_path() . '/avatars/signups/' . $hashed_key, bp_core_avatar_upload_path() . '/avatars/' . $user); } bp_core_add_message(__('Your account is now active!', 'buddypress')); $bp->activation_complete = true; } if ('' != locate_template(array('registration/activate'), false)) { bp_core_load_template(apply_filters('bp_core_template_activate', 'activate')); } else { bp_core_load_template(apply_filters('bp_core_template_activate', 'registration/activate')); } }
/** * Remove IMAP connection marker file. * * @since 1.0-RC4 * * @see bp_rbe_add_imap_lock() */ function bp_rbe_remove_imap_connection_marker() { clearstatcache(); if (file_exists(bp_core_avatar_upload_path() . '/bp-rbe-connected.txt')) { unlink(bp_core_avatar_upload_path() . '/bp-rbe-connected.txt'); } }
/** * Handle the loading of the Activate screen. */ function bp_core_screen_activation() { global $bp; if (!bp_is_current_component('activate')) { return false; } // If the user is logged in, redirect away from here if (is_user_logged_in()) { if (bp_is_component_front_page('activate')) { $redirect_to = trailingslashit(bp_get_root_domain() . '/' . bp_get_members_root_slug()); } else { $redirect_to = trailingslashit(bp_get_root_domain()); } bp_core_redirect(apply_filters('bp_loggedin_activate_page_redirect_to', $redirect_to)); return; } // Check if an activation key has been passed if (isset($_GET['key'])) { // Activate the signup $user = apply_filters('bp_core_activate_account', bp_core_activate_signup($_GET['key'])); // If there were errors, add a message and redirect if (!empty($user->errors)) { bp_core_add_message($user->get_error_message(), 'error'); bp_core_redirect(trailingslashit(bp_get_root_domain() . '/' . $bp->pages->activate->slug)); } $hashed_key = wp_hash($_GET['key']); // Check if the avatar folder exists. If it does, move rename it, move // it and delete the signup avatar dir if (file_exists(bp_core_avatar_upload_path() . '/avatars/signups/' . $hashed_key)) { @rename(bp_core_avatar_upload_path() . '/avatars/signups/' . $hashed_key, bp_core_avatar_upload_path() . '/avatars/' . $user); } bp_core_add_message(__('Your account is now active!', 'buddypress')); $bp->activation_complete = true; } bp_core_load_template(apply_filters('bp_core_template_activate', array('activate', 'registration/activate'))); }
/** * Setup the avatar upload directory for a user. * * @since BuddyPress (1.0.0) * * @package BuddyPress Core * * @param string $directory The root directory name. Optional. * @param int $user_id The user ID. Optional. * * @return array() Array containing the path, URL, and other helpful settings. */ function xprofile_avatar_upload_dir($directory = 'avatars', $user_id = 0) { // Use displayed user if no user ID was passed if (empty($user_id)) { $user_id = bp_displayed_user_id(); } // Failsafe against accidentally nooped $directory parameter if (empty($directory)) { $directory = 'avatars'; } $path = bp_core_avatar_upload_path() . '/' . $directory . '/' . $user_id; $newbdir = $path; if (!file_exists($path)) { @wp_mkdir_p($path); } $newurl = bp_core_avatar_url() . '/' . $directory . '/' . $user_id; $newburl = $newurl; $newsubdir = '/' . $directory . '/' . $user_id; return apply_filters('xprofile_avatar_upload_dir', array('path' => $path, 'url' => $newurl, 'subdir' => $newsubdir, 'basedir' => $newbdir, 'baseurl' => $newburl, 'error' => false)); }
function groups_avatar_upload_dir($group_id = 0) { global $bp; if (!$group_id) { $group_id = $bp->groups->current_group->id; } $path = bp_core_avatar_upload_path() . '/group-avatars/' . $group_id; $newbdir = $path; if (!file_exists($path)) { @wp_mkdir_p($path); } $newurl = bp_core_avatar_url() . '/group-avatars/' . $group_id; $newburl = $newurl; $newsubdir = '/group-avatars/' . $group_id; return apply_filters('groups_avatar_upload_dir', array('path' => $path, 'url' => $newurl, 'subdir' => $newsubdir, 'basedir' => $newbdir, 'baseurl' => $newburl, 'error' => false)); }
function bp_core_signup_avatar_upload_dir() { global $bp; if (!$bp->signup->avatar_dir) { return false; } $path = bp_core_avatar_upload_path() . '/avatars/signups/' . $bp->signup->avatar_dir; $newbdir = $path; if (!file_exists($path)) { @wp_mkdir_p($path); } $newurl = bp_core_avatar_url() . '/avatars/signups/' . $bp->signup->avatar_dir; $newburl = $newurl; $newsubdir = '/avatars/signups/' . $bp->signup->avatar_dir; return apply_filters('bp_core_signup_avatar_upload_dir', array('path' => $path, 'url' => $newurl, 'subdir' => $newsubdir, 'basedir' => $newbdir, 'baseurl' => $newburl, 'error' => false)); }
/** * Handle avatar webcam capture. * * @since BuddyPress (2.3.0) * * @param string $data base64 encoded image. * @param int $item_id. * @return bool True on success, false on failure. */ function bp_avatar_handle_capture($data = '', $item_id = 0) { if (empty($data) || empty($item_id)) { return false; } $avatar_dir = bp_core_avatar_upload_path() . '/avatars'; // It's not a regular upload, we may need to create this folder if (!file_exists($avatar_dir)) { if (!wp_mkdir_p($avatar_dir)) { return false; } } $avatar_folder_dir = apply_filters('bp_core_avatar_folder_dir', $avatar_dir . '/' . $item_id, $item_id, 'user', 'avatars'); // It's not a regular upload, we may need to create this folder if (!is_dir($avatar_folder_dir)) { if (!wp_mkdir_p($avatar_folder_dir)) { return false; } } $original_file = $avatar_folder_dir . '/webcam-capture-' . $item_id . '.png'; if (file_put_contents($original_file, $data)) { $avatar_to_crop = str_replace(bp_core_avatar_upload_path(), '', $original_file); // Crop to default values $crop_args = array('item_id' => $item_id, 'original_file' => $avatar_to_crop, 'crop_x' => 0, 'crop_y' => 0); return bp_core_avatar_handle_crop($crop_args); } else { return false; } }
/** * Setup the avatar upload directory for a user. * * @package BuddyPress Core * @param $directory The root directory name * @param $user_id The user ID. * @return array() containing the path and URL plus some other settings. */ function xprofile_avatar_upload_dir($directory = false, $user_id = 0) { global $bp; if (empty($user_id)) { $user_id = $bp->displayed_user->id; } if (empty($directory)) { $directory = 'avatars'; } $path = bp_core_avatar_upload_path() . '/avatars/' . $user_id; $newbdir = $path; if (!file_exists($path)) { @nxt_mkdir_p($path); } $newurl = bp_core_avatar_url() . '/avatars/' . $user_id; $newburl = $newurl; $newsubdir = '/avatars/' . $user_id; return apply_filters('xprofile_avatar_upload_dir', array('path' => $path, 'url' => $newurl, 'subdir' => $newsubdir, 'basedir' => $newbdir, 'baseurl' => $newburl, 'error' => false)); }
public function get_path($legacy_check = 0, $create_folders = 0) { /*** * place 'group-documents' on the same level as 'group-avatars' * organize docs within group sub-folders */ $document_dir = bp_core_avatar_upload_path() . '/group-documents/' . $this->group_id; if ($create_folders && !is_dir($document_dir)) { mkdir($document_dir, 0755, true); } /* ideal location - use this if possible */ $document_path = $document_dir . '/' . $this->file; /*** * if we're getting the existing file to display, it may not be there * if file is not there, check in legacy locations */ if ($legacy_check && !file_exists($document_path)) { /* check legacy override */ if (defined('BP_GROUP_DOCUMENTS_FILE_PATH')) { $document_path = BP_GROUP_DOCUMENTS_FILE_PATH . $this->file; } else { $document_path = WP_PLUGIN_DIR . '/buddypress-group-documents/documents/' . $this->file; } } return apply_filters('bp_group_documents_file_path', $document_path, $this->group_id, $this->file); }
/** * Get the avatar storage directory for use during registration. * * @since 1.1.0 * * @return string|bool Directory path on success, false on failure. */ function bp_core_signup_avatar_upload_dir() { $bp = buddypress(); if (empty($bp->signup->avatar_dir)) { return false; } $directory = 'avatars/signups'; $path = bp_core_avatar_upload_path() . '/' . $directory . '/' . $bp->signup->avatar_dir; $newbdir = $path; $newurl = bp_core_avatar_url() . '/' . $directory . '/' . $bp->signup->avatar_dir; $newburl = $newurl; $newsubdir = '/' . $directory . '/' . $bp->signup->avatar_dir; /** * Filters the avatar storage directory for use during registration. * * @since 1.1.1 * * @param array $value Array of path and URL values for created storage directory. */ return apply_filters('bp_core_signup_avatar_upload_dir', array('path' => $path, 'url' => $newurl, 'subdir' => $newsubdir, 'basedir' => $newbdir, 'baseurl' => $newburl, 'error' => false)); }
/** * Gets FB profile image and sets it as BuddyPress avatar. */ function set_fb_image_as_bp_avatar($user_id, $me) { if (!defined('BP_VERSION')) { return true; } if (!function_exists('bp_core_avatar_upload_path')) { return true; } if (!$me || !@$me['id']) { return false; } $fb_uid = $me['id']; if (function_exists('xprofile_avatar_upload_dir')) { $xpath = xprofile_avatar_upload_dir(false, $user_id); $path = $xpath['path']; } if (!function_exists('xprofile_avatar_upload_dir') || empty($path)) { $object = 'user'; $avatar_dir = apply_filters('bp_core_avatar_dir', 'avatars', $object); $path = bp_core_avatar_upload_path() . "/{$avatar_dir}/" . $user_id; $path = apply_filters('bp_core_avatar_folder_dir', $path, $user_id, $object, $avatar_dir); if (!realpath($path)) { @wp_mkdir_p($path); } } // Get FB picture //$fb_img = file_get_contents("http://graph.facebook.com/{$fb_uid}/picture?type=large"); $page = wp_remote_get("http://graph.facebook.com/{$fb_uid}/picture?type=large", array('method' => 'GET', 'timeout' => '5', 'redirection' => '5', 'user-agent' => 'wdfb', 'blocking' => true, 'compress' => false, 'decompress' => true, 'sslverify' => false)); if (is_wp_error($page)) { return false; } // Request fail if ((int) $page['response']['code'] != 200) { return false; } // Request fail $fb_img = $page['body']; $filename = md5($fb_uid); $filepath = "{$path}/{$filename}"; file_put_contents($filepath, $fb_img); // Determine the right extension $info = getimagesize($filepath); $extension = false; if (function_exists('image_type_to_extension')) { $extension = image_type_to_extension($info[2], false); } else { switch ($info[2]) { case IMAGETYPE_GIF: $extension = 'gif'; break; case IMAGETYPE_JPEG: $extension = 'jpg'; break; case IMAGETYPE_PNG: $extension = 'png'; break; } } // Unknown file type, clean up if (!$extension) { @unlink($filepath); return false; } $extension = 'jpeg' == strtolower($extension) ? 'jpg' : $extension; // Forcing .jpg extension for JPEGs // Clear old avatars $imgs = glob($path . '/*.{gif,png,jpg}', GLOB_BRACE); if (is_array($imgs)) { foreach ($imgs as $old) { @unlink($old); } } // Create and set new avatar if (defined('WDFB_BP_AVATAR_AUTO_CROP') && WDFB_BP_AVATAR_AUTO_CROP) { // Explicitly requested thumbnail processing // First, determine the centering position for cropping if ($info && isset($info[0]) && $info[0] && isset($info[1]) && $info[1]) { $full = apply_filters('wdfb-avatar-auto_crop', array('x' => (int) (($info[0] - bp_core_avatar_full_width()) / 2), 'y' => (int) (($info[1] - bp_core_avatar_full_height()) / 2), 'width' => bp_core_avatar_full_width(), 'height' => bp_core_avatar_full_height()), $filepath, $info); } $crop = $full ? wp_crop_image($filepath, $full['x'], $full['y'], $full['width'], $full['height'], bp_core_avatar_full_width(), bp_core_avatar_full_height(), false, "{$filepath}-bpfull.{$extension}") : false; if (!$crop) { @unlink($filepath); return false; } // Now, the thumbnail. First, try to resize the full avatar $thumb_file = wp_create_thumbnail("{$filepath}-bpfull.{$extension}", bp_core_avatar_thumb_width()); if (!is_wp_error($thumb_file)) { // All good! We're done - clean up copy($thumb_file, "{$filepath}-bpthumb.{$extension}"); @unlink($thumb_file); } else { // Sigh. Let's just fake it by using the original file then. copy("{$filepath}-bpfull.{$extension}", "{$filepath}-bpthumb.{$extension}"); } @unlink($filepath); return true; } else { // No auto-crop, move on copy($filepath, "{$filepath}-bpfull.{$extension}"); copy($filepath, "{$filepath}-bpthumb.{$extension}"); @unlink($filepath); return true; } return false; }
/** * Setup the avatar upload directory for a user. * * @since BuddyPress (1.0.0) * * @package BuddyPress Core * * @param string $directory The root directory name. Optional. * @param int $user_id The user ID. Optional. * * @return array() Array containing the path, URL, and other helpful settings. */ function xprofile_avatar_upload_dir($directory = 'avatars', $user_id = 0) { // Use displayed user if no user ID was passed if (empty($user_id)) { $user_id = bp_displayed_user_id(); } // Failsafe against accidentally nooped $directory parameter if (empty($directory)) { $directory = 'avatars'; } $path = bp_core_avatar_upload_path() . '/' . $directory . '/' . $user_id; $newbdir = $path; $newurl = bp_core_avatar_url() . '/' . $directory . '/' . $user_id; $newburl = $newurl; $newsubdir = '/' . $directory . '/' . $user_id; /** * Filters the avatar upload directory for a user. * * @since BuddyPress (1.1.0) * * @param array $value Array containing the path, URL, and other helpful settings. */ return apply_filters('xprofile_avatar_upload_dir', array('path' => $path, 'url' => $newurl, 'subdir' => $newsubdir, 'basedir' => $newbdir, 'baseurl' => $newburl, 'error' => false)); }
/** * Output the inline JS needed for the cropper to work on a per-page basis. */ function bp_core_add_cropper_inline_js() { // Bail if no image was uploaded $image = apply_filters('bp_inline_cropper_image', getimagesize(bp_core_avatar_upload_path() . buddypress()->avatar_admin->image->dir)); if (empty($image)) { return; } // $full_height = bp_core_avatar_full_height(); $full_width = bp_core_avatar_full_width(); // Calculate Aspect Ratio if (!empty($full_height) && $full_width != $full_height) { $aspect_ratio = $full_width / $full_height; } else { $aspect_ratio = 1; } // Default cropper coordinates $crop_left = round($image[0] / 4); $crop_top = round($image[1] / 4); $crop_right = $image[0] - $crop_left; $crop_bottom = $image[1] - $crop_top; ?> <script type="text/javascript"> jQuery(window).load( function(){ jQuery('#avatar-to-crop').Jcrop({ onChange: showPreview, onSelect: showPreview, onSelect: updateCoords, aspectRatio: <?php echo $aspect_ratio; ?> , setSelect: [ <?php echo $crop_left; ?> , <?php echo $crop_top; ?> , <?php echo $crop_right; ?> , <?php echo $crop_bottom; ?> ] }); updateCoords({x: <?php echo $crop_left; ?> , y: <?php echo $crop_top; ?> , w: <?php echo $crop_right; ?> , h: <?php echo $crop_bottom; ?> }); }); function updateCoords(c) { jQuery('#x').val(c.x); jQuery('#y').val(c.y); jQuery('#w').val(c.w); jQuery('#h').val(c.h); } function showPreview(coords) { if ( parseInt(coords.w) > 0 ) { var fw = <?php echo $full_width; ?> ; var fh = <?php echo $full_height; ?> ; var rx = fw / coords.w; var ry = fh / coords.h; jQuery( '#avatar-crop-preview' ).css({ width: Math.round(rx * <?php echo $image[0]; ?> ) + 'px', height: Math.round(ry * <?php echo $image[1]; ?> ) + 'px', marginLeft: '-' + Math.round(rx * coords.x) + 'px', marginTop: '-' + Math.round(ry * coords.y) + 'px' }); } } </script> <?php }
/** * Handle avatar webcam capture. * * @since 2.3.0 * * @param string $data Base64 encoded image. * @param int $item_id Item to associate. * * @return bool True on success, false on failure. */ function bp_avatar_handle_capture($data = '', $item_id = 0) { if (empty($data) || empty($item_id)) { return false; } $avatar_dir = bp_core_avatar_upload_path() . '/avatars'; // It's not a regular upload, we may need to create this folder. if (!file_exists($avatar_dir)) { if (!wp_mkdir_p($avatar_dir)) { return false; } } /** * Filters the Avatar folder directory. * * @since 2.3.0 * * @param string $avatar_dir Directory for storing avatars. * @param int $item_id ID of the item being acted on. * @param string $value Avatar type. * @param string $value Avatars word. */ $avatar_folder_dir = apply_filters('bp_core_avatar_folder_dir', $avatar_dir . '/' . $item_id, $item_id, 'user', 'avatars'); // It's not a regular upload, we may need to create this folder. if (!is_dir($avatar_folder_dir)) { if (!wp_mkdir_p($avatar_folder_dir)) { return false; } } $original_file = $avatar_folder_dir . '/webcam-capture-' . $item_id . '.png'; if (file_put_contents($original_file, $data)) { $avatar_to_crop = str_replace(bp_core_avatar_upload_path(), '', $original_file); // Crop to default values $crop_args = array('item_id' => $item_id, 'original_file' => $avatar_to_crop, 'crop_x' => 0, 'crop_y' => 0); return bp_core_avatar_handle_crop($crop_args); } else { return false; } }
/** * Crop an uploaded avatar * * $args has the following parameters: * object - What component the avatar is for, e.g. "user" * avatar_dir The absolute path to the avatar * item_id - Item ID * original_file - The absolute path to the original avatar file * crop_w - Crop width * crop_h - Crop height * crop_x - The horizontal starting point of the crop * crop_y - The vertical starting point of the crop * * @global object $bp BuddyPress global settings * @param mixed $args * @return bool Success/failure */ function bp_core_avatar_handle_crop($args = '') { global $bp; $defaults = array('object' => 'user', 'avatar_dir' => 'avatars', 'item_id' => false, 'original_file' => false, 'crop_w' => bp_core_avatar_full_width(), 'crop_h' => bp_core_avatar_full_height(), 'crop_x' => 0, 'crop_y' => 0); $r = nxt_parse_args($args, $defaults); /*** * You may want to hook into this filter if you want to override this function. * Make sure you return false. */ if (!apply_filters('bp_core_pre_avatar_handle_crop', true, $r)) { return true; } extract($r, EXTR_SKIP); if (!$original_file) { return false; } $original_file = bp_core_avatar_upload_path() . $original_file; if (!file_exists($original_file)) { return false; } if (!$item_id) { $avatar_folder_dir = apply_filters('bp_core_avatar_folder_dir', dirname($original_file), $item_id, $object, $avatar_dir); } else { $avatar_folder_dir = apply_filters('bp_core_avatar_folder_dir', bp_core_avatar_upload_path() . '/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir); } if (!file_exists($avatar_folder_dir)) { return false; } require_once ABSPATH . '/nxt-admin/includes/image.php'; require_once ABSPATH . '/nxt-admin/includes/file.php'; // Delete the existing avatar files for the object bp_core_delete_existing_avatar(array('object' => $object, 'avatar_path' => $avatar_folder_dir)); // Make sure we at least have a width and height for cropping if (!(int) $crop_w) { $crop_w = bp_core_avatar_full_width(); } if (!(int) $crop_h) { $crop_h = bp_core_avatar_full_height(); } // Set the full and thumb filenames $full_filename = nxt_hash($original_file . time()) . '-bpfull.jpg'; $thumb_filename = nxt_hash($original_file . time()) . '-bpthumb.jpg'; // Crop the image $full_cropped = nxt_crop_image($original_file, (int) $crop_x, (int) $crop_y, (int) $crop_w, (int) $crop_h, bp_core_avatar_full_width(), bp_core_avatar_full_height(), false, $avatar_folder_dir . '/' . $full_filename); $thumb_cropped = nxt_crop_image($original_file, (int) $crop_x, (int) $crop_y, (int) $crop_w, (int) $crop_h, bp_core_avatar_thumb_width(), bp_core_avatar_thumb_height(), false, $avatar_folder_dir . '/' . $thumb_filename); // Remove the original @unlink($original_file); return true; }
/** * bp_core_add_cropper_inline_js() * * Adds the inline JS needed for the cropper to work on a per-page basis. * * @package BuddyPress Core */ function bp_core_add_cropper_inline_js() { global $bp; $image = apply_filters('bp_inline_cropper_image', getimagesize(bp_core_avatar_upload_path() . $bp->avatar_admin->image->dir)); $aspect_ratio = 1; $full_height = bp_core_avatar_full_height(); $full_width = bp_core_avatar_full_width(); // Calculate Aspect Ratio if ($full_height && $full_width != $full_height) { $aspect_ratio = $full_width / $full_height; } $width = $image[0] / 2; $height = $image[1] / 2; ?> <script type="text/javascript"> jQuery(window).load( function(){ jQuery('#avatar-to-crop').Jcrop({ onChange: shonxtreview, onSelect: shonxtreview, onSelect: updateCoords, aspectRatio: <?php echo $aspect_ratio; ?> , setSelect: [ 50, 50, <?php echo $width; ?> , <?php echo $height; ?> ] }); updateCoords({x: 50, y: 50, w: <?php echo $width; ?> , h: <?php echo $height; ?> }); }); function updateCoords(c) { jQuery('#x').val(c.x); jQuery('#y').val(c.y); jQuery('#w').val(c.w); jQuery('#h').val(c.h); }; function shonxtreview(coords) { if ( parseInt(coords.w) > 0 ) { var rx = <?php echo $full_width; ?> / coords.w; var ry = <?php echo $full_height; ?> / coords.h; jQuery('#avatar-crop-preview').css({ <?php if ($image) { ?> width: Math.round(rx * <?php echo $image[0]; ?> ) + 'px', height: Math.round(ry * <?php echo $image[1]; ?> ) + 'px', <?php } ?> marginLeft: '-' + Math.round(rx * coords.x) + 'px', marginTop: '-' + Math.round(ry * coords.y) + 'px' }); } } </script> <?php }
/** * Clean up created directories/files */ public function rrmdir($dir) { // Make sure we are only removing files/dir from uploads if (0 !== strpos($dir, bp_core_avatar_upload_path())) { return; } $d = glob($dir . '/*'); if (!empty($d)) { foreach ($d as $file) { if (is_dir($file)) { $this->rrmdir($file); } else { @unlink($file); } } } @rmdir($dir); }
/** * Generate the avatar upload directory path for a given group. * * @param int $group_id Optional. ID of the group. Default: ID of the * current group. * @return string */ function groups_avatar_upload_dir($group_id = 0) { if (empty($group_id)) { $group_id = bp_get_current_group_id(); } $directory = 'group-avatars'; $path = bp_core_avatar_upload_path() . '/' . $directory . '/' . $group_id; $newbdir = $path; $newurl = bp_core_avatar_url() . '/' . $directory . '/' . $group_id; $newburl = $newurl; $newsubdir = '/' . $directory . '/' . $group_id; /** * Filters the avatar upload directory path for a given group. * * @since 1.1.0 * * @param array $value Array of parts related to the groups avatar upload directory. */ return apply_filters('groups_avatar_upload_dir', array('path' => $path, 'url' => $newurl, 'subdir' => $newsubdir, 'basedir' => $newbdir, 'baseurl' => $newburl, 'error' => false)); }
/** * * @param type $legacy_check * @param type $create_folders * @return type * @version 2, 30/4/2013, stergatu in order to hardening the security */ public function get_path($legacy_check = 0, $create_folders = 0) { /* * * * place 'group-documents' on the same level as 'group-avatars' * organize docs within group sub-folders */ if (function_exists('bp_core_avatar_upload_path')) { //bp 1.2 and later $document_dir = bp_core_avatar_upload_path() . '/group-documents/' . $this->group_id; } else { //bp 1.1 $path = get_blog_option(BP_ROOT_BLOG, 'upload_path'); //wp-content/blogs.dir/1/files $document_dir = WP_CONTENT_DIR . str_replace('wp-content', '', $path); $document_dir .= '/group-documents/' . $this->group_id; } $this->create_dir_or_htaccess($document_dir); /* ideal location - use this if possible */ $document_path = $document_dir . '/' . $this->file; /* * * * if we're getting the existing file to display, it may not be there * if file is not there, check in legacy locations */ if ($legacy_check && !file_exists($document_path)) { /* check legacy override */ if (defined('BP_GROUP_DOCUMENTS_FILE_PATH')) { $document_path = BP_GROUP_DOCUMENTS_FILE_PATH . $this->file; } else { $document_path = WP_PLUGIN_DIR . '/' . BP_GROUP_DOCUMENTS_DIR . '/documents/' . $this->file; } } return apply_filters('bp_group_documents_file_path', $document_path, $this->group_id, $this->file); }