Exemplo n.º 1
0
 /**
  * @param $user
  * @param $sizex
  * @param $sizey
  *
  * @return string
  */
 protected function _getURL($user, $sizex, $sizey)
 {
     $user = KunenaFactory::getUser($user);
     $avatar = $user->avatar;
     $config = KunenaFactory::getConfig();
     $path = KPATH_MEDIA . "/avatars";
     $origPath = "{$path}/{$avatar}";
     if (!is_file($origPath)) {
         // If avatar does not exist use default image.
         if ($sizex <= 90) {
             $avatar = 's_nophoto.jpg';
         } else {
             $avatar = 'nophoto.jpg';
         }
         // Search from the template.
         $template = KunenaFactory::getTemplate();
         $origPath = JPATH_SITE . '/' . $template->getAvatarPath($avatar);
         $avatar = $template->name . '/' . $avatar;
     }
     $dir = dirname($avatar);
     $file = basename($avatar);
     if ($sizex == $sizey) {
         $resized = "resized/size{$sizex}/{$dir}";
     } else {
         $resized = "resized/size{$sizex}x{$sizey}/{$dir}";
     }
     // TODO: make timestamp configurable?
     $timestamp = '';
     if (!is_file("{$path}/{$resized}/{$file}")) {
         KunenaImageHelper::version($origPath, "{$path}/{$resized}", $file, $sizex, $sizey, intval($config->avatarquality), KunenaImage::SCALE_INSIDE, intval($config->avatarcrop));
         $timestamp = '?' . round(microtime(true));
     }
     return KURL_MEDIA . "avatars/{$resized}/{$file}{$timestamp}";
 }
Exemplo n.º 2
0
 /**
  * Upload and resize if needed the new avatar for user, or set one from the gallery or the default one
  *
  * @return boolean
  */
 protected function saveAvatar()
 {
     $action = JRequest::getString('avatar', 'keep');
     $current_avatar = $this->me->avatar;
     $avatarFile = $this->app->input->files->get('avatarfile');
     if (!empty($avatarFile['tmp_name'])) {
         $this->deleteOldAvatars();
         $upload = KunenaUpload::getInstance(array('gif, jpeg, jpg, png'));
         $uploaded = $upload->upload($avatarFile, KPATH_MEDIA . '/avatars/users/avatar' . $this->me->userid, 'avatar');
         if (!empty($uploaded)) {
             $imageInfo = KunenaImage::getImageFileProperties($uploaded->destination);
             // If image is not inside allowed size limits, resize it
             if ($uploaded->size > intval($this->config->avatarsize) * 1024 || $imageInfo->width > '200' || $imageInfo->height > '200') {
                 if ($this->config->avatarquality < 1 || $this->config->avatarquality > 100) {
                     $quality = 70;
                 } else {
                     $quality = $this->config->avatarquality;
                 }
                 $resized = KunenaImageHelper::version($uploaded->destination, KPATH_MEDIA . '/avatars/users', 'avatar' . $this->me->userid . '.' . $uploaded->ext, 200, 200, $quality, KunenaImage::SCALE_INSIDE, $this->config->avatarcrop);
             }
             $this->app->enqueueMessage(JText::sprintf('COM_KUNENA_PROFILE_AVATAR_UPLOADED'));
             $this->me->avatar = 'users/avatar' . $this->me->userid . '.' . $uploaded->ext;
         } else {
             $this->me->avatar = $current_avatar;
             return false;
         }
     } elseif ($action == 'delete') {
         $this->deleteOldAvatars();
         // Set default avatar
         $this->me->avatar = '';
     } elseif (substr($action, 0, 8) == 'gallery/' && strpos($action, '..') === false) {
         $this->me->avatar = $action;
     }
     return true;
 }