mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-09-25 18:59:04 +02:00
parent
4fa5c69e57
commit
86f1c87fed
49
modules/gravatar/application/controllers/IndexController.php
Normal file
49
modules/gravatar/application/controllers/IndexController.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
22
modules/gravatar/library/Gravatar/Gravatar.php
Normal file
22
modules/gravatar/library/Gravatar/Gravatar.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
4
modules/gravatar/module.info
Normal file
4
modules/gravatar/module.info
Normal 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
3
modules/gravatar/run.php
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
$this->registerHook('gravatar', '\\Icinga\\Module\\Gravatar\\Gravatar');
|
Loading…
x
Reference in New Issue
Block a user