diff options
-rw-r--r-- | app/Core/User/Avatar/AvatarManager.php | 26 | ||||
-rw-r--r-- | app/Helper/UserHelper.php | 7 |
2 files changed, 32 insertions, 1 deletions
diff --git a/app/Core/User/Avatar/AvatarManager.php b/app/Core/User/Avatar/AvatarManager.php index afaf79d2..71bd8aa5 100644 --- a/app/Core/User/Avatar/AvatarManager.php +++ b/app/Core/User/Avatar/AvatarManager.php @@ -61,4 +61,30 @@ class AvatarManager return ''; } + + /** + * Render default provider for unknown users (first provider registered) + * + * @access public + * @param integer $size + * @return string + */ + public function renderDefault($size) + { + if (count($this->providers) > 0) { + ksort($this->providers); + $provider = current($this->providers); + + $user = array( + 'id' => 0, + 'username' => '', + 'name' => '?', + 'email' => '', + ); + + return $provider->render($user, $size); + } + + return ''; + } } diff --git a/app/Helper/UserHelper.php b/app/Helper/UserHelper.php index 90f84033..c60c35c2 100644 --- a/app/Helper/UserHelper.php +++ b/app/Helper/UserHelper.php @@ -171,7 +171,12 @@ class UserHelper extends Base */ public function avatar($user_id, $username, $name, $email) { - $html = $this->avatarManager->render($user_id, $username, $name, $email, 48); + if (empty($user_id) && empty($username)) { + $html = $this->avatarManager->renderDefault(48); + } else { + $html = $this->avatarManager->render($user_id, $username, $name, $email, 48); + } + return '<div class="avatar">'.$html.'</div>'; } } |