Merge pull request #640 from internetisalie/avatar-custom

Add avatar url customization
This commit is contained in:
Gary Green
2016-01-22 12:06:22 +00:00
7 changed files with 25 additions and 8 deletions

View File

@@ -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'

View File

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

View File

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

View File

@@ -17,7 +17,7 @@
{% if commit.body is not empty %}
<p>{{ commit.body | nl2br }}</p>
{% endif %}
<img src="https://gravatar.com/avatar/{{ commit.author.email | lower | md5 }}?s=32" class="pull-left space-right" />
<img src="{{ avatar(commit.author.email, 32) }}" class="pull-left space-right" />
<span>
<a href="mailto:{{ commit.author.email }}">{{ commit.author.name }}</a> authored on {{ commit.date | format_date }}
{% if commit.author.email != commit.commiter.email %}

View File

@@ -9,7 +9,7 @@
<tbody>
{% for item in commit %}
<tr>
<td width="5%"><img src="https://gravatar.com/avatar/{{ item.author.email | lower | md5 }}?s=40" /></td>
<td width="5%"><img src="{{ avatar(item.author.email, 40) }}" /></td>
<td width="95%">
<span class="pull-right"><a class="btn btn-default btn-sm" href="{{ path('commit', {repo: repo, commit: item.hash}) }}"><span class="fa fa-list-alt"></span> View {{ item.shortHash }}</a></span>
<h4>{{ item.message }}</h4>

View File

@@ -16,7 +16,7 @@
{% if commit.body is not empty %}
<p>{{ commit.body | nl2br }}</p>
{% endif %}
<img src="https://gravatar.com/avatar/{{ commit.author.email | lower | md5 }}?s=32" class="pull-left space-right" />
<img src="{{ avatar(commit.author.email, 32) }}" class="pull-left space-right" />
<span>
<a href="mailto:{{ commit.author.email }}">{{ commit.author.name }}</a> authored on {{ commit.date | format_date }}
{% if commit.author.email != commit.commiter.email %}

View File

@@ -9,7 +9,7 @@
<tbody>
{% for item in commit %}
<tr>
<td width="5%"><img src="https://gravatar.com/avatar/{{ item.author.email | lower | md5 }}?s=40" /></td>
<td width="5%"><img src="{{ avatar( item.author.email, 40 ) }}" /></td>
<td width="95%">
<span class="pull-right"><a class="btn btn-small" href="{{ path('commit', {repo: repo, commit: item.hash}) }}"><i class="icon-list-alt"></i> View {{ item.shortHash }}</a></span>
<h4>{{ item.message }}</h4>