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:
Toby Zerner 2017-09-19 19:03:12 +09:30
parent 5bfe75c763
commit 5fc3ea94b5

View File

@ -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;
}