forked from Public/pics
268 lines
5.4 KiB
PHP
268 lines
5.4 KiB
PHP
<?php
|
|
/*****************************************************************************
|
|
* PhotosIndex.php
|
|
* Contains the project index template.
|
|
*
|
|
* Kabuki CMS (C) 2013-2015, Aaron van Geffen
|
|
*****************************************************************************/
|
|
|
|
class PhotosIndex extends SubTemplate
|
|
{
|
|
protected $mosaic;
|
|
protected $show_edit_buttons;
|
|
protected $show_labels;
|
|
protected $row_limit = 1000;
|
|
protected $previous_header = '';
|
|
protected $url_suffix;
|
|
|
|
const PANORAMA_WIDTH = 1280;
|
|
const PANORAMA_HEIGHT = null;
|
|
|
|
const PORTRAIT_WIDTH = 400;
|
|
const PORTRAIT_HEIGHT = 645;
|
|
|
|
const LANDSCAPE_WIDTH = 850;
|
|
const LANDSCAPE_HEIGHT = 640;
|
|
|
|
const DUO_WIDTH = 618;
|
|
const DUO_HEIGHT = 412;
|
|
|
|
const SINGLE_WIDTH = 618;
|
|
const SINGLE_HEIGHT = 412;
|
|
|
|
const TILE_WIDTH = 400;
|
|
const TILE_HEIGHT = 300;
|
|
|
|
public function __construct(PhotoMosaic $mosaic, $show_edit_buttons = false, $show_labels = false, $show_headers = true)
|
|
{
|
|
$this->mosaic = $mosaic;
|
|
$this->show_edit_buttons = $show_edit_buttons;
|
|
$this->show_headers = $show_headers;
|
|
$this->show_labels = $show_labels;
|
|
}
|
|
|
|
protected function html_content()
|
|
{
|
|
echo '
|
|
<div class="tiled_grid">';
|
|
|
|
for ($i = $this->row_limit; $i > 0 && $row = $this->mosaic->getRow(); $i--)
|
|
{
|
|
list($photos, $what) = $row;
|
|
$this->header($photos);
|
|
$this->$what($photos);
|
|
}
|
|
|
|
echo '
|
|
</div>
|
|
<script type="text/javascript" src="', BASEURL, '/js/albumnav.js"></script>';
|
|
}
|
|
|
|
protected function header($photos)
|
|
{
|
|
if (!$this->show_headers)
|
|
return;
|
|
|
|
$date = $photos[0]->getDateCaptured();
|
|
if (!$date)
|
|
return;
|
|
|
|
$header = $date->format('F Y');
|
|
if ($header === $this->previous_header)
|
|
return;
|
|
|
|
$name = str_replace(' ', '', strtolower($header));
|
|
echo '
|
|
<div class="tiled_header" id="', $name, '">
|
|
<a href="#', $name, '">', $header, '</a>
|
|
</div>';
|
|
|
|
$this->previous_header = $header;
|
|
}
|
|
|
|
protected function color(Image $image)
|
|
{
|
|
$color = $image->bestColor();
|
|
if ($color == 'FFFFFF')
|
|
$color = 'ccc';
|
|
|
|
return $color;
|
|
}
|
|
|
|
protected function photo(Image $image, $width, $height, $crop = true, $fit = true)
|
|
{
|
|
if ($this->show_edit_buttons)
|
|
echo '
|
|
<a class="edit" href="', BASEURL, '/editasset/?id=', $image->getId(), '">Edit</a>';
|
|
|
|
echo '
|
|
<a href="', $image->getPageUrl(), $this->url_suffix, '">
|
|
<img src="', $image->getThumbnailUrl($width, $height, $crop, $fit), '" alt="" title="', $image->getTitle(), '">';
|
|
|
|
if ($this->show_labels)
|
|
echo '
|
|
<h4>', $image->getTitle(), '</h4>';
|
|
|
|
echo '
|
|
</a>';
|
|
}
|
|
|
|
protected function panorama(array $photos)
|
|
{
|
|
foreach ($photos as $image)
|
|
{
|
|
echo '
|
|
<div style="border-color: #', $this->color($image), '" class="panorama">';
|
|
|
|
$this->photo($image, static::PANORAMA_WIDTH, static::PANORAMA_HEIGHT, false, false);
|
|
|
|
echo '
|
|
</div>';
|
|
}
|
|
}
|
|
|
|
protected function portrait(array $photos)
|
|
{
|
|
$image = array_shift($photos);
|
|
|
|
echo '
|
|
<div class="tiled_row">
|
|
<div class="column_portrait">
|
|
<div style="border-color: #', $this->color($image), '" class="portrait">';
|
|
|
|
$this->photo($image, static::PORTRAIT_WIDTH, static::PORTRAIT_HEIGHT, 'top');
|
|
|
|
echo '
|
|
</div>
|
|
</div>
|
|
<div class="column_tiles_four">';
|
|
|
|
foreach ($photos as $image)
|
|
{
|
|
echo '
|
|
<div style="border-color: #', $this->color($image), '" class="landscape">';
|
|
|
|
$this->photo($image, static::TILE_WIDTH, static::TILE_HEIGHT, 'top');
|
|
|
|
echo '
|
|
</div>';
|
|
}
|
|
|
|
echo '
|
|
</div>
|
|
</div>';
|
|
}
|
|
|
|
protected function landscape(array $photos)
|
|
{
|
|
$image = array_shift($photos);
|
|
|
|
echo '
|
|
<div class="tiled_row">
|
|
<div class="column_landscape">
|
|
<div style="border-color: #', $this->color($image), '" class="landscape">';
|
|
|
|
$this->photo($image, static::LANDSCAPE_WIDTH, static::LANDSCAPE_HEIGHT, 'top');
|
|
|
|
echo '
|
|
</div>
|
|
</div>
|
|
<div class="column_tiles_two">';
|
|
|
|
foreach ($photos as $image)
|
|
{
|
|
echo '
|
|
<div style="border-color: #', $this->color($image), '" class="landscape">';
|
|
|
|
$this->photo($image, static::TILE_WIDTH, static::TILE_HEIGHT, 'top');
|
|
|
|
echo '
|
|
</div>';
|
|
}
|
|
|
|
echo '
|
|
</div>
|
|
</div>';
|
|
}
|
|
|
|
protected function duo(array $photos)
|
|
{
|
|
echo '
|
|
<div class="tiled_row">';
|
|
|
|
foreach ($photos as $image)
|
|
{
|
|
echo '
|
|
<div style="border-color: #', $this->color($image), '" class="duo">';
|
|
|
|
$this->photo($image, static::DUO_WIDTH, static::DUO_HEIGHT, true);
|
|
|
|
echo '
|
|
</div>';
|
|
}
|
|
|
|
echo '
|
|
</div>';
|
|
}
|
|
|
|
protected function single(array $photos)
|
|
{
|
|
$image = array_shift($photos);
|
|
|
|
echo '
|
|
<div class="tiled_row">
|
|
<div style="border-color: #', $this->color($image), '" class="single">';
|
|
|
|
$this->photo($image, static::SINGLE_WIDTH, static::SINGLE_HEIGHT, 'top');
|
|
|
|
echo '
|
|
</div>
|
|
</div>';
|
|
}
|
|
|
|
protected function row(array $photos)
|
|
{
|
|
echo '
|
|
<div class="tiled_row">';
|
|
|
|
foreach ($photos as $image)
|
|
{
|
|
echo '
|
|
<div style="border-color: #', $this->color($image), '" class="landscape">';
|
|
|
|
$this->photo($image, static::TILE_WIDTH, static::TILE_HEIGHT, true);
|
|
|
|
echo '
|
|
</div>';
|
|
}
|
|
|
|
echo '
|
|
</div>';
|
|
}
|
|
|
|
protected function portraits(array $photos)
|
|
{
|
|
echo '
|
|
<div class="tiled_row">';
|
|
|
|
foreach ($photos as $image)
|
|
{
|
|
echo '
|
|
<div style="border-color: #', $this->color($image), '" class="portrait">';
|
|
|
|
$this->photo($image, static::PORTRAIT_WIDTH, static::PORTRAIT_HEIGHT, true);
|
|
|
|
echo '
|
|
</div>';
|
|
}
|
|
|
|
echo '
|
|
</div>';
|
|
}
|
|
|
|
public function setUrlSuffix($suffix)
|
|
{
|
|
$this->url_suffix = $suffix;
|
|
}
|
|
}
|