Пример #1
0
/**
 * 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));
}
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)) {
        @nxt_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));
}
Пример #3
0
/**
 * Create a file in the upload folder with given content.
 *
 * If there is an error, then the key 'error' will exist with the error message.
 * If success, then the key 'file' will have the unique file path, the 'url' key
 * will have the link to the new file. and the 'error' key will be set to false.
 *
 * This function will not move an uploaded file to the upload folder. It will
 * create a new file with the content in $bits parameter. If you move the upload
 * file, read the content of the uploaded file, and then you can give the
 * filename and content to this function, which will add it to the upload
 * folder.
 *
 * The permissions will be set on the new file automatically by this function.
 *
 * @since 2.0.0
 *
 * @param string $name
 * @param null $deprecated Never used. Set to null.
 * @param mixed $bits File content
 * @param string $time Optional. Time formatted in 'yyyy/mm'.
 * @return array
 */
function nxt_upload_bits($name, $deprecated, $bits, $time = null)
{
    if (!empty($deprecated)) {
        _deprecated_argument(__FUNCTION__, '2.0');
    }
    if (empty($name)) {
        return array('error' => __('Empty filename'));
    }
    $nxt_filetype = nxt_check_filetype($name);
    if (!$nxt_filetype['ext']) {
        return array('error' => __('Invalid file type'));
    }
    $upload = nxt_upload_dir($time);
    if ($upload['error'] !== false) {
        return $upload;
    }
    $upload_bits_error = apply_filters('nxt_upload_bits', array('name' => $name, 'bits' => $bits, 'time' => $time));
    if (!is_array($upload_bits_error)) {
        $upload['error'] = $upload_bits_error;
        return $upload;
    }
    $filename = nxt_unique_filename($upload['path'], $name);
    $new_file = $upload['path'] . "/{$filename}";
    if (!nxt_mkdir_p(dirname($new_file))) {
        $message = sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?'), dirname($new_file));
        return array('error' => $message);
    }
    $ifp = @fopen($new_file, 'wb');
    if (!$ifp) {
        return array('error' => sprintf(__('Could not write file %s'), $new_file));
    }
    @fwrite($ifp, $bits);
    fclose($ifp);
    clearstatcache();
    // Set correct file permissions
    $stat = @stat(dirname($new_file));
    $perms = $stat['mode'] & 07777;
    $perms = $perms & 0666;
    @chmod($new_file, $perms);
    clearstatcache();
    // Compute the URL
    $url = $upload['url'] . "/{$filename}";
    return array('file' => $new_file, 'url' => $url, 'error' => false);
}
Пример #4
0
 /**
  * Write data to the file
  *
  * @param string $data
  * @return boolean
  */
 public function write($data = null)
 {
     // make sure the export dir exists
     if (nxt_mkdir_p(self::$export_dir)) {
         // can we write to the export dir?
         if (ICE_Files::cache(self::$export_dir)->refresh()->is_writable()) {
             // get file instance
             $file = ICE_Files::cache($this->path)->refresh();
             // if file already exists, puke if not writeable
             if ($file->exists() && !$file->is_writable()) {
                 throw new ICE_Export_Exception('Unable to write to the file: ' . $this->path);
             }
             // try to write it
             $bytes = file_put_contents($file->getPathname(), $data);
             // any bytes written
             if ($bytes) {
                 // yep, refresh file
                 $file->refresh();
                 // return bytes written
                 return $bytes;
             }
             return false;
         } else {
             throw new ICE_Export_Exception('Unable to create the file: ' . $this->path);
         }
     } else {
         throw new ICE_Export_Exception('Unable to create the directory: ' . self::$export_dir);
     }
 }
Пример #5
0
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)) {
        @nxt_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));
}
Пример #6
0
function et_create_images_temp_folder()
{
    #clean et_temp folder once per week
    if (false !== ($last_time = get_option('et_schedule_clean_images_last_time'))) {
        $timeout = 86400 * 7;
        if ($timeout < time() - $last_time && '' != get_option('et_images_temp_folder')) {
            et_clean_temp_images(get_option('et_images_temp_folder'));
        }
    }
    if (false !== get_option('et_images_temp_folder')) {
        return;
    }
    $uploads_dir = nxt_upload_dir();
    $destination_dir = false === $uploads_dir['error'] ? path_join($uploads_dir['basedir'], 'et_temp') : null;
    if (!nxt_mkdir_p($destination_dir)) {
        update_option('et_images_temp_folder', '');
    } else {
        update_option('et_images_temp_folder', $destination_dir);
        update_option('et_schedule_clean_images_last_time', time());
    }
}