Gravatar Module: Add the gravatar module

refs #9916
This commit is contained in:
Alexander Fuhr 2015-08-25 17:21:01 +02:00
parent 4fa5c69e57
commit 86f1c87fed
4 changed files with 78 additions and 0 deletions

View File

@ -0,0 +1,49 @@
<?php
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
use Icinga\Web\Controller;
use Icinga\Web\FileCache;
class Gravatar_IndexController extends Controller
{
/**
* Static routes don't require authentication
*
* @var bool
*/
protected $requiresAuthentication = false;
/**
* Disable layout rendering as this controller doesn't provide any html layouts
*/
public function init()
{
$this->_helper->viewRenderer->setNoRender(true);
$this->_helper->layout()->disableLayout();
}
public function indexAction()
{
$cache = FileCache::instance();
$filename = md5(strtolower(trim($this->_request->getParam('email'))));
$cacheFile = 'gravatar-' . $filename;
header('Cache-Control: public');
header('Pragma: cache');
if ($etag = $cache->etagMatchesCachedFile($cacheFile)) {
header("HTTP/1.1 304 Not Modified");
return;
}
header('Content-Type: image/jpg');
if ($cache->has($cacheFile)) {
header('ETag: "' . $cache->etagForCachedFile($cacheFile) . '"');
$cache->send($cacheFile);
return;
}
$img = file_get_contents('http://www.gravatar.com/avatar/' . $filename . '?s=120&d=mm');
$cache->store($cacheFile, $img);
header('ETag: "' . $cache->etagForCachedFile($cacheFile) . '"');
return $img;
}
}

View File

@ -0,0 +1,22 @@
<?php
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
namespace Icinga\Module\Gravatar;
use Icinga\Web\Hook\GravatarHook;
/**
* Class Gravatar
*/
class Gravatar extends GravatarHook
{
/**
* {@inheritdoc}
*/
public function getAvatar($email)
{
$baseUrl = $this->getView()->baseUrl();
return $baseUrl . '/gravatar/?email=' . $email;
}
}

View File

@ -0,0 +1,4 @@
Module: gravatar
Version: 2.0.0-rc1
Description: Gravatar module
User images provided by Gravatar.

3
modules/gravatar/run.php Normal file
View File

@ -0,0 +1,3 @@
<?php
$this->registerHook('gravatar', '\\Icinga\\Module\\Gravatar\\Gravatar');