diff --git a/config.ini-example b/config.ini-example index 5c2aa51..30bd699 100644 --- a/config.ini-example +++ b/config.ini-example @@ -32,3 +32,8 @@ title = "" [date] ; timezone = UTC ; format = 'd/m/Y H:i:s' + +; custom avatar service +[avatar] +; url = '//gravatar.com/avatar/' +; query[] = 'd=identicon' \ No newline at end of file diff --git a/src/Application.php b/src/Application.php index f538a77..4217d31 100644 --- a/src/Application.php +++ b/src/Application.php @@ -37,6 +37,8 @@ class Application extends SilexApplication $this['filetypes'] = $config->getSection('filetypes'); $this['binary_filetypes'] = $config->getSection('binary_filetypes'); $this['cache.archives'] = $this->getCachePath() . 'archives'; + $this['avatar.url'] = $config->get('avatar', 'url'); + $this['avatar.query'] = $config->get('avatar', 'query'); // Register services $this->register(new TwigServiceProvider(), array( @@ -67,6 +69,7 @@ class Application extends SilexApplication $twig->addFilter(new \Twig_SimpleFilter('md5', 'md5')); $twig->addFilter(new \Twig_SimpleFilter('format_date', array($app, 'formatDate'))); $twig->addFilter(new \Twig_SimpleFilter('format_size', array($app, 'formatSize'))); + $twig->addFunction(new \Twig_SimpleFunction('avatar', array($app, 'getAvatar'))); return $twig; })); @@ -107,6 +110,18 @@ class Application extends SilexApplication return round($size, 2) . $units[$i]; } + public function getAvatar($email, $size) + { + $url = $this['avatar.url'] ? $this['avatar.url'] : "//gravatar.com/avatar/"; + $query = array("s=$size"); + if (is_string($this['avatar.query'])) + $query[] = $this['avatar.query']; + else if (is_array($this['avatar.query'])) + $query = array_merge($query, $this['avatar.query']); + $id = md5(strtolower($email)); + return $url . $id . "?" . implode('&', $query); + } + public function getPath() { return $this->path . DIRECTORY_SEPARATOR; diff --git a/src/Controller/NetworkController.php b/src/Controller/NetworkController.php index 70f339f..27f8a19 100644 --- a/src/Controller/NetworkController.php +++ b/src/Controller/NetworkController.php @@ -46,10 +46,7 @@ class NetworkController implements ControllerProviderInterface 'author' => array( 'name' => $commit->getAuthor()->getName(), 'email' => $commit->getAuthor()->getEmail(), - // due to the lack of a inbuilt javascript md5 mechanism, build the full avatar url on the php side - 'image' => '//gravatar.com/avatar/' . md5( - strtolower($commit->getAuthor()->getEmail()) - ) . '?s=40' + 'image' => $app->getAvatar($commit->getAuthor()->getEmail(), 40) ) ); } diff --git a/themes/bootstrap3/twig/commit.twig b/themes/bootstrap3/twig/commit.twig index 7293935..7a9863e 100644 --- a/themes/bootstrap3/twig/commit.twig +++ b/themes/bootstrap3/twig/commit.twig @@ -17,7 +17,7 @@ {% if commit.body is not empty %}
{{ commit.body | nl2br }}
{% endif %} -{{ commit.body | nl2br }}
{% endif %} -