mirror of
https://github.com/flarum/framework.git
synced 2025-01-19 16:52:46 +08:00
Allow full URLs to be used as the avatar path
This is useful for forums integrating with an external website (eg. a WordPress site), so they can reference existing avatars directly. For alternative storage locations (eg. S3) the best practice will still be to store a relative path and then configure an external base "assets URL" (this is not currently possible - TODO). Given this change, I think it would probably make sense to rename the column to `avatar_url` in the upcoming batch of database naming changes - then it can contain either a relative or an absolute URL - @franzliedke do you agree?
This commit is contained in:
parent
5bfe75c763
commit
5fc3ea94b5
|
@ -323,7 +323,14 @@ class User extends AbstractModel
|
|||
*/
|
||||
public function getAvatarUrlAttribute()
|
||||
{
|
||||
$urlGenerator = app('Flarum\Forum\UrlGenerator');
|
||||
if ($this->avatar_path) {
|
||||
if (strpos($this->avatar_path, '://') !== false) {
|
||||
return $this->avatar_path;
|
||||
} else {
|
||||
return app('Flarum\Forum\UrlGenerator')->toPath('assets/avatars/'.$this->avatar_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->avatar_path ? $urlGenerator->toPath('assets/avatars/'.$this->avatar_path) : null;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user