Check for http or https in avatar value

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2023-05-10 02:18:38 -07:00
parent 2dd32d8785
commit 7062583710

View file

@ -7,6 +7,7 @@ use App\Models\Setting;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Gate; use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
/** /**
* Class UserPresenter * Class UserPresenter
@ -399,17 +400,25 @@ class UserPresenter extends Presenter
public function gravatar() public function gravatar()
{ {
if ($this->avatar) { if ($this->avatar) {
// Check if it's a google avatar or some external avatar
if (Str::startsWith($this->avatar, ['http://', 'https://'])) {
return $this->avatar;
}
// Otherwise assume it's an uploaded image
return Storage::disk('public')->url('avatars/'.e($this->avatar)); return Storage::disk('public')->url('avatars/'.e($this->avatar));
} }
if (Setting::getSettings()->load_remote == '1') { if (Setting::getSettings()->load_remote == '1') {
if ($this->model->gravatar != '') { if ($this->model->gravatar != '') {
$gravatar = md5(strtolower(trim($this->model->gravatar))); $gravatar = md5(strtolower(trim($this->model->gravatar)));
return '//gravatar.com/avatar/'.$gravatar; return '//gravatar.com/avatar/'.$gravatar;
} elseif ($this->email != '') {
$gravatar = md5(strtolower(trim($this->email)));
} elseif ($this->email != '') {
$gravatar = md5(strtolower(trim($this->email)));
return '//gravatar.com/avatar/'.$gravatar; return '//gravatar.com/avatar/'.$gravatar;
} }
} }