From 5fc3ea94b544f5f43b2db3d14a62a4816bbdc1ec Mon Sep 17 00:00:00 2001 From: Toby Zerner <toby.zerner@gmail.com> Date: Tue, 19 Sep 2017 19:03:12 +0930 Subject: [PATCH] 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? --- framework/core/src/Core/User.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/framework/core/src/Core/User.php b/framework/core/src/Core/User.php index 32f58e86a..338d38d47 100755 --- a/framework/core/src/Core/User.php +++ b/framework/core/src/Core/User.php @@ -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; }