140 lines
3.3 KiB
PHP
140 lines
3.3 KiB
PHP
<?php
|
|
/**
|
|
* Layout components
|
|
* Components that are general to the layout of the
|
|
* PAE site
|
|
*
|
|
* @package pae
|
|
* @subpackage layout
|
|
* @author Benjamin Ramey <ben.ramey@gmail.com>
|
|
**/
|
|
class layoutComponents extends sfComponents
|
|
{
|
|
/**
|
|
* Shows a link to the contact page to easily be put
|
|
* on any page after larger blocks of text
|
|
*
|
|
* @return void
|
|
* @author Benjamin Ramey <ben.ramey@gmail.com>
|
|
**/
|
|
public function executeContactUsLink()
|
|
{
|
|
}
|
|
|
|
/**
|
|
* Logic behind sidebarPicture component
|
|
* Grabs a random picture from the sidebar images folder
|
|
* and gives it to the partial template
|
|
*
|
|
* @return void
|
|
* @author Benjamin Ramey <ben.ramey@gmail.com>
|
|
**/
|
|
public function executeSidebarPicture()
|
|
{
|
|
$imagesDir = implode(DIRECTORY_SEPARATOR, array(sfConfig::get('sf_web_dir'), "images", "sidebar"));
|
|
|
|
if(!$this->OnHomePage())
|
|
{
|
|
$this->pictureURL = $this->GetRandomImage($imagesDir);
|
|
}
|
|
else
|
|
{
|
|
$this->pictureURL = sfConfig::get("app_home_sidebar_image");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Logic behind panoramaPicture component
|
|
* Grabs a random picture from the panorama images folder
|
|
* and gives it to the partial template
|
|
*
|
|
* @return void
|
|
* @author Benjamin Ramey <ben.ramey@gmail.com>
|
|
**/
|
|
public function executePanoramaPicture()
|
|
{
|
|
$imagesDir = implode(DIRECTORY_SEPARATOR, array(sfConfig::get('sf_web_dir'), "images", "panorama"));
|
|
|
|
if($this->ShowPanorama())
|
|
{
|
|
$this->pictureURL = $this->GetRandomImage($imagesDir);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Returns true if we are on the homepage
|
|
*
|
|
* @return boolean
|
|
* @author Benjamin Ramey <ben.ramey@gmail.com>
|
|
**/
|
|
private function OnHomePage()
|
|
{
|
|
$routing = sfRouting::getInstance();
|
|
$homepageRte = $routing->getRouteByName('homepage');
|
|
$homepageMod = $homepageRte[4]["module"];
|
|
$homepageAction = $homepageRte[4]["action"];
|
|
|
|
if($this->getModuleName() == $homepageMod
|
|
&& $this->getActionName() == $homepageAction)
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Determines whether the panorama image should be show
|
|
* Some pages do not display it
|
|
*
|
|
* @return boolean
|
|
* @author Benjamin Ramey <ben.ramey@gmail.com>
|
|
**/
|
|
private function ShowPanorama()
|
|
{
|
|
if($this->OnHomePage()
|
|
|| $this->getModuleName() == "whoarewe"
|
|
|| ($this->getModuleName() == "info"
|
|
&& ($this->getActionName() == "events"
|
|
|| $this->getActionName() == "film")))
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Returns a random file name from the
|
|
* directory that is passed to it
|
|
*
|
|
* @return void
|
|
* @author Benjamin Ramey <ben.ramey@gmail.com>
|
|
**/
|
|
private function GetRandomImage($imagesDir)
|
|
{
|
|
$images = scandir($imagesDir);
|
|
$images = $this->GetImagesFromFolder($images,$imagesDir);
|
|
|
|
$count = count($images);
|
|
$randomImage = null;
|
|
if($count > 0)
|
|
$randomImage = $images[floor(rand(0,$count - 1))];
|
|
|
|
return($randomImage);
|
|
}
|
|
|
|
private function GetImagesFromFolder($files)
|
|
{
|
|
$images = array();
|
|
foreach($files as $key => $value)
|
|
{
|
|
if(preg_match("/(png|jpg|gif)$/i", $value) > 0)
|
|
{
|
|
array_push($images, $value);
|
|
}
|
|
}
|
|
|
|
return($images);
|
|
}
|
|
} |