Added a randomiyed header image

This commit is contained in:
Gergely Polonkai (W00d5t0ck) 2012-09-05 17:41:00 +02:00
parent a2f2fd7317
commit e1037a1c55
6 changed files with 55 additions and 1 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

View File

@ -11,7 +11,7 @@
</head> </head>
<body> <body>
<div id="content-wrapper"> <div id="content-wrapper">
<div id="header"> <div id="header" style="background-image: url('{{ asset('bundles/gergelypolonkaifront/images/' ~ random_header) }}');">
<h1><a href="{{ path('GergelyPolonkaiFrontBundle_homepage') }}">Gergely Polonkai</a></h1> <h1><a href="{{ path('GergelyPolonkaiFrontBundle_homepage') }}">Gergely Polonkai</a></h1>
<h2>developer, systems engineer and administrator</h2> <h2>developer, systems engineer and administrator</h2>
<div id="contact-list"> <div id="contact-list">

View File

@ -0,0 +1,54 @@
<?php
namespace GergelyPolonkai\FrontBundle\Twig;
use JMS\DiExtraBundle\Annotation as DI;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Description of RandomHeader
*
* @author polonkai.gergely
*
* @DI\Service
* @DI\Tag("twig.extension")
*/
class RandomHeader extends \Twig_Extension
{
/**
* @var string $rootDir
*/
private $rootDir;
/**
* @DI\InjectParams({
* "kernelRootDir" = @DI\Inject("%kernel.root_dir%")
* })
*/
public function __construct($kernelRootDir)
{
$this->rootDir = $kernelRootDir;
}
public function getGlobals()
{
return array(
'random_header' => $this->randomHeader(),
);
}
private function randomHeader()
{
$dh = opendir($this->rootDir . '/../web/bundles/gergelypolonkaifront/images');
$files = array();
while ($fn = readdir($dh)) {
if (preg_match('/^header_\d+\.png/', $fn)) {
$files[] = $fn;
}
}
return $files[array_rand($files)];
}
public function getName() {
return 'random_header';
}
}