/**
 * Get the Attachments Uploads dir data
 *
 * @since  2.4.0
 *
 * @param  string        $data The data to get. Possible values are: 'dir', 'basedir' & 'baseurl'
 *                       Leave empty to get all datas.
 * @return string|array  The needed Upload dir data.
 */
function bp_attachments_uploads_dir_get($data = '')
{
    $attachments_dir = 'buddypress';
    $retval = '';
    if ('dir' === $data) {
        $retval = $attachments_dir;
    } else {
        $upload_data = bp_upload_dir();
        // Build the Upload data array for BuddyPress attachments
        foreach ($upload_data as $key => $value) {
            if ('basedir' === $key || 'baseurl' === $key) {
                $upload_data[$key] = trailingslashit($value) . $attachments_dir;
            } else {
                unset($upload_data[$key]);
            }
        }
        // Add the dir to the array
        $upload_data['dir'] = $attachments_dir;
        if (empty($data)) {
            $retval = $upload_data;
        } elseif (isset($upload_data[$data])) {
            $retval = $upload_data[$data];
        }
    }
    /**
     * Filter here to edit the Attachments upload dir data.
     *
     * @since  2.4.0
     *
     * @param  string|array $retval      The needed Upload dir data or the full array of data
     * @param  string       $data        The data requested
     */
    return apply_filters('bp_attachments_uploads_dir_get', $retval, $data);
}
 /**
  * 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();
     }
 }
 public function test_bp_attachment_set_upload_dir()
 {
     $upload_dir = bp_upload_dir();
     $attachment_class = new BPTest_Attachment_Extension(array('action' => 'attachment_action', 'file_input' => 'attachment_file_input'));
     $this->assertSame($attachment_class->upload_dir, bp_upload_dir());
     $attachment_class = new BPTest_Attachment_Extension(array('action' => 'attachment_action', 'file_input' => 'attachment_file_input', 'base_dir' => 'attachment_base_dir'));
     $this->assertTrue(file_exists($upload_dir['basedir'] . '/attachment_base_dir'));
     // clean up
     $this->clean_files();
 }
/**
 * Get the Attachments Uploads dir data.
 *
 * @since 2.4.0
 *
 * @param string $data The data to get. Possible values are: 'dir', 'basedir' & 'baseurl'.
 *                     Leave empty to get all datas.
 * @return string|array The needed Upload dir data.
 */
function bp_attachments_uploads_dir_get($data = '')
{
    $attachments_dir = 'buddypress';
    $retval = '';
    if ('dir' === $data) {
        $retval = $attachments_dir;
    } else {
        $upload_data = bp_upload_dir();
        // Return empty string, if Uploads data are not available.
        if (!$upload_data) {
            return $retval;
        }
        // Build the Upload data array for BuddyPress attachments.
        foreach ($upload_data as $key => $value) {
            if ('basedir' === $key || 'baseurl' === $key) {
                $upload_data[$key] = trailingslashit($value) . $attachments_dir;
                // Fix for HTTPS.
                if ('baseurl' === $key && is_ssl()) {
                    $upload_data[$key] = str_replace('http://', 'https://', $upload_data[$key]);
                }
            } else {
                unset($upload_data[$key]);
            }
        }
        // Add the dir to the array.
        $upload_data['dir'] = $attachments_dir;
        if (empty($data)) {
            $retval = $upload_data;
        } elseif (isset($upload_data[$data])) {
            $retval = $upload_data[$data];
        }
    }
    /**
     * Filter here to edit the Attachments upload dir data.
     *
     * @since 2.4.0
     *
     * @param string|array $retval The needed Upload dir data or the full array of data
     * @param string       $data   The data requested
     */
    return apply_filters('bp_attachments_uploads_dir_get', $retval, $data);
}
Example #5
0
/**
 * Fetch data from the BP root blog's upload directory.
 *
 * @since 1.8.0
 *
 * @param string $type The variable we want to return from the $bp->avatars object.
 *                     Only 'upload_path' and 'url' are supported. Default: 'upload_path'.
 *
 * @return string The avatar upload directory path.
 */
function bp_core_get_upload_dir($type = 'upload_path')
{
    $bp = buddypress();
    switch ($type) {
        case 'upload_path':
            $constant = 'BP_AVATAR_UPLOAD_PATH';
            $key = 'basedir';
            break;
        case 'url':
            $constant = 'BP_AVATAR_URL';
            $key = 'baseurl';
            break;
        default:
            return false;
            break;
    }
    // See if the value has already been calculated and stashed in the $bp global.
    if (isset($bp->avatar->{$type})) {
        $retval = $bp->avatar->{$type};
    } else {
        // If this value has been set in a constant, just use that.
        if (defined($constant)) {
            $retval = constant($constant);
        } else {
            // Use cached upload dir data if available.
            if (!empty($bp->avatar->upload_dir)) {
                $upload_dir = $bp->avatar->upload_dir;
                // No cache, so query for it.
            } else {
                // Get upload directory information from current site.
                $upload_dir = bp_upload_dir();
                // Stash upload directory data for later use.
                $bp->avatar->upload_dir = $upload_dir;
            }
            // Directory does not exist and cannot be created.
            if (!empty($upload_dir['error'])) {
                $retval = '';
            } else {
                $retval = $upload_dir[$key];
                // If $key is 'baseurl', check to see if we're on SSL
                // Workaround for WP13941, WP15928, WP19037.
                if ($key == 'baseurl' && is_ssl()) {
                    $retval = str_replace('http://', 'https://', $retval);
                }
            }
        }
        // Stash in $bp for later use.
        $bp->avatar->{$type} = $retval;
    }
    return $retval;
}
 /**
  * Set upload path and url for the component.
  *
  * @since 2.3.0
  *
  */
 public function set_upload_dir()
 {
     // Set the directory, path, & url variables.
     $this->upload_dir = bp_upload_dir();
     if (empty($this->upload_dir)) {
         return false;
     }
     $this->upload_path = $this->upload_dir['basedir'];
     $this->url = $this->upload_dir['baseurl'];
     // Ensure URL is https if SSL is set/forced.
     if (is_ssl()) {
         $this->url = str_replace('http://', 'https://', $this->url);
     }
     /**
      * Custom base dir.
      *
      * If the component set this property, set the specific path, url and create the dir
      */
     if (!empty($this->base_dir)) {
         $this->upload_path = trailingslashit($this->upload_path) . $this->base_dir;
         $this->url = trailingslashit($this->url) . $this->base_dir;
         // Finally create the base dir.
         $this->create_dir();
     }
 }
Example #7
0
 public function setUp()
 {
     parent::setUp();
     $this->upload_data = bp_upload_dir();
 }
 /**
  * @group shrink
  * @group avatars
  */
 public function test_bp_attachment_avatar_shrink()
 {
     $image = BP_TESTS_DIR . 'assets/upside-down.jpg';
     $dir_copy = bp_upload_dir();
     // in case cleaning files fails
     if (!is_dir($dir_copy['basedir'] . '/shrink')) {
         mkdir($dir_copy['basedir'] . '/shrink');
     }
     $abs_path_copy = $dir_copy['basedir'] . '/shrink/upside-down.jpg';
     copy($image, $abs_path_copy);
     add_filter('bp_core_avatar_original_max_width', array($this, 'limit_to_50px'));
     $shrink = BP_Attachment_Avatar::shrink($abs_path_copy);
     remove_filter('bp_core_avatar_original_max_width', array($this, 'limit_to_50px'));
     $this->assertTrue(50 === $shrink['width'] && 50 === $shrink['height']);
     // Cleanup
     $this->clean_files('shrink');
 }
Example #9
0
 /**
  * @group bp_attachments
  * @group bp_upload_dir
  */
 public function test_bp_upload_dir()
 {
     $expected_upload_dir = wp_upload_dir();
     if (is_multisite()) {
         $b = $this->factory->blog->create();
         switch_to_blog($b);
     }
     $tested_upload_dir = bp_upload_dir();
     if (is_multisite()) {
         restore_current_blog();
     }
     $this->assertSame($expected_upload_dir, $tested_upload_dir);
 }
/**
 * Change the relative path to match with WordPress upload organisation
 *
 * @since 1.3.0
 *
 * @param  string $new_path the relative path to the protected file
 * @return string           the path to the public file
 */
function buddydrive_public_relative_path($new_path = '', $path = '')
{
    $bp_upload_dir = bp_upload_dir();
    $bd_relative = ltrim(str_replace($bp_upload_dir['basedir'], '', buddydrive()->upload_dir), '/');
    return ltrim(str_replace($bd_relative, '', $new_path), '/');
}
Example #11
0
 /**
  * @group bp_attachments
  * @group bp_upload_dir
  */
 public function test_bp_upload_dir_ms()
 {
     if (!is_multisite()) {
         $this->markTestSkipped(__METHOD__ . ' is a multisite-only test.');
     }
     $expected_upload_dir = wp_upload_dir();
     $b = $this->factory->blog->create();
     switch_to_blog($b);
     $tested_upload_dir = bp_upload_dir();
     restore_current_blog();
     $this->assertSame($expected_upload_dir, $tested_upload_dir);
 }