diff --git a/ChangeLog b/ChangeLog
index 79c389a9e..ef24f4862 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,7 @@ Version 1.0.27 (unreleased)
Improvements:
+* Added pluggable Avatar providers
* Improve task summary sections
* Put back the action sidebar in task view
* Added support for multiple placeholders for LDAP_USER_FILTER
diff --git a/app/Core/Base.php b/app/Core/Base.php
index e53f299aa..f87f271a9 100644
--- a/app/Core/Base.php
+++ b/app/Core/Base.php
@@ -41,6 +41,7 @@ use Pimple\Container;
* @property \Kanboard\Core\Session\FlashMessage $flash
* @property \Kanboard\Core\Session\SessionManager $sessionManager
* @property \Kanboard\Core\Session\SessionStorage $sessionStorage
+ * @property \Kanboard\Core\User\Avatar\AvatarManager $avatarManager
* @property \Kanboard\Core\User\GroupSync $groupSync
* @property \Kanboard\Core\User\UserProfile $userProfile
* @property \Kanboard\Core\User\UserSync $userSync
diff --git a/app/Core/User/Avatar/AvatarManager.php b/app/Core/User/Avatar/AvatarManager.php
new file mode 100644
index 000000000..4b0c52983
--- /dev/null
+++ b/app/Core/User/Avatar/AvatarManager.php
@@ -0,0 +1,62 @@
+providers[] = $provider;
+ return $this;
+ }
+
+ /**
+ * Render avatar html element
+ *
+ * @access public
+ * @param string $user_id
+ * @param string $username
+ * @param string $name
+ * @param string $email
+ * @param int $size
+ * @return string
+ */
+ public function render($user_id, $username, $name, $email, $size)
+ {
+ $user = array(
+ 'id' => $user_id,
+ 'username' => $username,
+ 'name' => $name,
+ 'email' => $email,
+ );
+
+ foreach ($this->providers as $provider) {
+ if ($provider->isActive($user)) {
+ return $provider->render($user, $size);
+ }
+ }
+
+ return '';
+ }
+}
diff --git a/app/Core/User/Avatar/AvatarProviderInterface.php b/app/Core/User/Avatar/AvatarProviderInterface.php
new file mode 100644
index 000000000..e0375d261
--- /dev/null
+++ b/app/Core/User/Avatar/AvatarProviderInterface.php
@@ -0,0 +1,30 @@
+config->get('integration_gravatar') == 1) {
- return '';
- }
-
- return '';
+ $html = $this->avatarManager->render($user_id, $username, $name, $email, 25);
+ return '
= e('%s created a subtask for the task %s', $this->text->e($author), diff --git a/app/Template/event/subtask_update.php b/app/Template/event/subtask_update.php index e9ff6ac61..1d560fb05 100644 --- a/app/Template/event/subtask_update.php +++ b/app/Template/event/subtask_update.php @@ -1,5 +1,3 @@ -= $this->user->avatar($email, $author) ?> -
= e('%s updated a subtask for the task %s', $this->text->e($author), diff --git a/app/Template/event/task_assignee_change.php b/app/Template/event/task_assignee_change.php index 580176c7e..6964a50e5 100644 --- a/app/Template/event/task_assignee_change.php +++ b/app/Template/event/task_assignee_change.php @@ -1,5 +1,3 @@ -= $this->user->avatar($email, $author) ?> -
diff --git a/app/Template/event/task_close.php b/app/Template/event/task_close.php index 361458d38..2ba77156c 100644 --- a/app/Template/event/task_close.php +++ b/app/Template/event/task_close.php @@ -1,5 +1,3 @@ -= $this->user->avatar($email, $author) ?> -
= e('%s closed the task %s', $this->text->e($author), diff --git a/app/Template/event/task_create.php b/app/Template/event/task_create.php index 655bf8f31..21facc9ec 100644 --- a/app/Template/event/task_create.php +++ b/app/Template/event/task_create.php @@ -1,5 +1,3 @@ -= $this->user->avatar($email, $author) ?> -
= e('%s created the task %s', $this->text->e($author), diff --git a/app/Template/event/task_file_create.php b/app/Template/event/task_file_create.php index 61bf3d61f..837f5dc09 100644 --- a/app/Template/event/task_file_create.php +++ b/app/Template/event/task_file_create.php @@ -1,5 +1,3 @@ -= $this->user->avatar($email, $author) ?> -
= e('%s attached a new file to the task %s', $this->text->e($author), diff --git a/app/Template/event/task_move_column.php b/app/Template/event/task_move_column.php index 904c956cc..b9ae65ccc 100644 --- a/app/Template/event/task_move_column.php +++ b/app/Template/event/task_move_column.php @@ -1,5 +1,3 @@ -= $this->user->avatar($email, $author) ?> -
= e('%s moved the task %s to the column "%s"', $this->text->e($author), diff --git a/app/Template/event/task_move_position.php b/app/Template/event/task_move_position.php index 6580bb79b..dbe73f4b0 100644 --- a/app/Template/event/task_move_position.php +++ b/app/Template/event/task_move_position.php @@ -1,5 +1,3 @@ -= $this->user->avatar($email, $author) ?> -
= e('%s moved the task %s to the position #%d in the column "%s"', $this->text->e($author), diff --git a/app/Template/event/task_move_swimlane.php b/app/Template/event/task_move_swimlane.php index 9ffa554c3..b0635a067 100644 --- a/app/Template/event/task_move_swimlane.php +++ b/app/Template/event/task_move_swimlane.php @@ -1,5 +1,3 @@ -= $this->user->avatar($email, $author) ?> -
= e('%s moved the task %s to the first swimlane', diff --git a/app/Template/event/task_open.php b/app/Template/event/task_open.php index 9db2e3c97..ce92bb18c 100644 --- a/app/Template/event/task_open.php +++ b/app/Template/event/task_open.php @@ -1,5 +1,3 @@ -= $this->user->avatar($email, $author) ?> -
= e('%s opened the task %s', $this->text->e($author), diff --git a/app/Template/event/task_update.php b/app/Template/event/task_update.php index 72d704956..83f1661b9 100644 --- a/app/Template/event/task_update.php +++ b/app/Template/event/task_update.php @@ -1,5 +1,3 @@ -= $this->user->avatar($email, $author) ?> -
= e('%s updated the task %s',
$this->text->e($author),
diff --git a/app/User/Avatar/GravatarProvider.php b/app/User/Avatar/GravatarProvider.php
new file mode 100644
index 000000000..10ab43900
--- /dev/null
+++ b/app/User/Avatar/GravatarProvider.php
@@ -0,0 +1,35 @@
+helper->text->e($user['name'] ?: $user['username']);
+ return '';
+ }
+
+ /**
+ * Determine if the provider is active
+ *
+ * @access public
+ * @param array $user
+ * @return boolean
+ */
+ public function isActive(array $user)
+ {
+ return !empty($user['email']) && $this->config->get('integration_gravatar') == 1;
+ }
+}
diff --git a/app/common.php b/app/common.php
index 71f80c751..7dbd75870 100644
--- a/app/common.php
+++ b/app/common.php
@@ -38,4 +38,5 @@ $container->register(new Kanboard\ServiceProvider\GroupProvider);
$container->register(new Kanboard\ServiceProvider\RouteProvider);
$container->register(new Kanboard\ServiceProvider\ActionProvider);
$container->register(new Kanboard\ServiceProvider\ExternalLinkProvider);
+$container->register(new Kanboard\ServiceProvider\AvatarProvider);
$container->register(new Kanboard\ServiceProvider\PluginProvider);
diff --git a/doc/plugin-avatar-provider.markdown b/doc/plugin-avatar-provider.markdown
new file mode 100644
index 000000000..62941e5c2
--- /dev/null
+++ b/doc/plugin-avatar-provider.markdown
@@ -0,0 +1,32 @@
+Adding a new Avatar Provider
+=============================
+
+Registration
+------------
+
+```php
+$this->avatarManager->register(new CustomAvatarProvider());
+```
+
+Interface
+---------
+
+The provider must implements the interface `Kanboard\Core\User\Avatar\AvatarProviderInterface`:
+
+
+| Method | Description |
+|-------------------------------|---------------------------------------------------------------|
+| `render(array $user, $size)` | Render HTML |
+| `isActive(array $user)` | Returns a boolean if the provider is able to render something |
+
+
+The `$user` argument is a dictionary that contains these keys:
+
+```php
+[
+ 'id' => 123,
+ 'username' => 'admin',
+ 'name' => 'Administrator',
+ 'email' => 'me@localhost',
+]
+```
diff --git a/doc/plugins.markdown b/doc/plugins.markdown
index e38c887fa..475bc2497 100644
--- a/doc/plugins.markdown
+++ b/doc/plugins.markdown
@@ -20,9 +20,10 @@ Plugin creators should specify explicitly the compatible versions of Kanboard. I
- [Attach metadata to users, tasks and projects](plugin-metadata.markdown)
- [Authentication architecture](plugin-authentication-architecture.markdown)
- [Authentication plugin registration](plugin-authentication.markdown)
-- [Authorization Architecture](plugin-authorization-architecture.markdown)
-- [Custom Group Providers](plugin-group-provider.markdown)
-- [External Link Providers](plugin-external-link.markdown)
+- [Authorization architecture](plugin-authorization-architecture.markdown)
+- [Custom group providers](plugin-group-provider.markdown)
+- [External link providers](plugin-external-link.markdown)
+- [Add avatar providers](plugin-avatar-provider.markdown)
- [LDAP client](plugin-ldap-client.markdown)
Examples of plugins
- - = $this->user->avatar($comment['email'], $comment['name'] ?: $comment['username']) ?> - + = $this->user->avatar($comment['user_id'], $comment['username'], $comment['name'], $comment['email']) ?> = $this->text->e($comment['name'] ?: $comment['username']) ?> @ diff --git a/app/Template/event/comment_create.php b/app/Template/event/comment_create.php index 063736b38..43c521cf6 100644 --- a/app/Template/event/comment_create.php +++ b/app/Template/event/comment_create.php @@ -1,5 +1,3 @@ -= $this->user->avatar($email, $author) ?> -
= e('%s commented the task %s', $this->text->e($author), diff --git a/app/Template/event/comment_update.php b/app/Template/event/comment_update.php index 93f24d8a6..80a330315 100644 --- a/app/Template/event/comment_update.php +++ b/app/Template/event/comment_update.php @@ -1,5 +1,3 @@ -= $this->user->avatar($email, $author) ?> -
= e('%s updated a comment on the task %s', $this->text->e($author), diff --git a/app/Template/event/events.php b/app/Template/event/events.php index bbb01be49..097da3189 100644 --- a/app/Template/event/events.php +++ b/app/Template/event/events.php @@ -16,7 +16,16 @@ = $this->dt->datetime($event['date_creation']) ?>
-