Skip to content

Commit

Permalink
Add option whether to crop thumbnails.
Browse files Browse the repository at this point in the history
  • Loading branch information
ric2016 committed Jul 4, 2020
1 parent 5596c03 commit a4f379b
Show file tree
Hide file tree
Showing 8 changed files with 406 additions and 86 deletions.
13 changes: 10 additions & 3 deletions ClassicLAFModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,23 @@ public function resourcesFolder(): string {
return __DIR__ . '/resources/';
}

public function onBoot(): void {
public function onBoot(): void {
// Register a namespace for our views.
View::registerNamespace($this->name(), $this->resourcesFolder() . 'views/');

$compactIndividualPage = boolval($this->getPreference('COMPACT_INDI_PAGE', '1'));
$cropThumbnails = boolval($this->getPreference('CROP_THUMBNAILS', '1'));

if ($compactIndividualPage) {
if ($compactIndividualPage || !$cropThumbnails) {
// Replace an existing view with our own version.
View::registerCustomView('::individual-page', $this->name() . '::individual-page');
}

if (!$cropThumbnails) {
View::registerCustomView('::chart-box', $this->name() . '::chart-box');
View::registerCustomView('::selects/individual', $this->name() . '::selects/individual');
View::registerCustomView('::selects/media', $this->name() . '::selects/media');
}

$nickBeforeSurn = boolval($this->getPreference('NICK_BEFORE_SURN', '1'));

Expand All @@ -85,7 +92,7 @@ public function onBoot(): void {
app()->instance(IndividualNameHandler::class, $handler);

$cache = app('cache.array');
Factory::individual(new CustomIndividualFactory($cache));
Factory::individual(new CustomIndividualFactory($cache, $compactIndividualPage, $cropThumbnails));

$customPrefixes = boolval($this->getPreference('CUSTOM_PREFIXES', '0'));
app()->instance(TreeService::class, new CustomTreeService($customPrefixes?$this:null));
Expand Down
9 changes: 9 additions & 0 deletions ClassicLAFModuleTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ protected function createPrefs() {
'COMPACT_EDIT',
'1')));

$layout[] = new ControlPanelSubsection(
/* I18N: Module Configuration */I18N::translate('Image Thumbnails'),
array(new ControlPanelCheckbox(
/* I18N: Module Configuration */I18N::translate('Crop Thumbnails'),
/* I18N: Module Configuration */I18N::translate('Webtrees crops thumbnails in order to produce images with a consistent width and height. This is problematic if you have images of individals with a non-standard aspect ratio, where the head of the respective person is not centered and may therefore be cut off. Deselect this option to handle these cases.') . ' '.
/* I18N: Module Configuration */I18N::translate('When switching this option, you will have to reset your thumbnail cache manually by deleting the folder %1$s.', '\'data/media/thumbnail-cache\''),
'CROP_THUMBNAILS',
'1')));

$general[] = new ControlPanelSubsection(
/* I18N: Module Configuration */I18N::translate('XREF prefixes'),
array(new ControlPanelCheckbox(
Expand Down
20 changes: 17 additions & 3 deletions patchedWebtrees/CustomIndividualFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,29 @@

namespace Cissee\WebtreesExt;

use Fisharebest\Webtrees\Cache;
use Fisharebest\Webtrees\Contracts\IndividualFactoryInterface;
use Fisharebest\Webtrees\Factories\IndividualFactory;
use Fisharebest\Webtrees\Tree;
use Fisharebest\Webtrees\Individual;
use Fisharebest\Webtrees\Tree;

class CustomIndividualFactory extends IndividualFactory implements IndividualFactoryInterface {

private const TYPE_CHECK_REGEX = '/^0 @[^@]+@ ' . Individual::RECORD_TYPE . '/';

protected $compactIndividualPage;
protected $cropThumbnails;

public function __construct(
Cache $cache,
bool $compactIndividualPage,
bool $cropThumbnails)
{
parent::__construct($cache);
$this->compactIndividualPage = $compactIndividualPage;
$this->cropThumbnails = $cropThumbnails;
}

public function make(string $xref, Tree $tree, string $gedcom = null): ?Individual
{
return $this->cache->remember(__CLASS__ . $xref . '@' . $tree->id(), function () use ($xref, $tree, $gedcom) {
Expand All @@ -22,13 +36,13 @@ public function make(string $xref, Tree $tree, string $gedcom = null): ?Individu
}
$xref = $this->extractXref($gedcom ?? $pending, $xref);

return new IndividualExt($xref, $gedcom ?? '', $pending, $tree);
return new IndividualExt($xref, $gedcom ?? '', $pending, $tree, $this->compactIndividualPage, $this->cropThumbnails);
});
}

public function new(string $xref, string $gedcom, ?string $pending, Tree $tree): Individual
{
return new IndividualExt($xref, $gedcom, $pending, $tree);
return new IndividualExt($xref, $gedcom, $pending, $tree, $this->compactIndividualPage, $this->cropThumbnails);
}
}

Expand Down
27 changes: 26 additions & 1 deletion patchedWebtrees/IndividualExt.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,32 @@ class IndividualExt extends Individual

/** @var Date The estimated date of death */
private $estimated_death_date;


protected $compactIndividualPage;
protected $cropThumbnails;

public function compactIndividualPage(): bool {
return $this->compactIndividualPage;
}

public function cropThumbnails(): bool {
return $this->cropThumbnails;
}

public function __construct(
string $xref,
string $gedcom,
?string $pending,
Tree $tree,
bool $compactIndividualPage,
bool $cropThumbnails)
{
parent::__construct($xref, $gedcom, $pending, $tree);

$this->compactIndividualPage = $compactIndividualPage;
$this->cropThumbnails = $cropThumbnails;
}

/**
* A closure which will create a record from a database row.
*
Expand Down
200 changes: 200 additions & 0 deletions resources/views/chart-box.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
<?php

declare(strict_types=1);

use Fisharebest\Webtrees\Auth;
use Fisharebest\Webtrees\Fact;
use Fisharebest\Webtrees\Gedcom;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Individual;
use Fisharebest\Webtrees\Menu;
use Fisharebest\Webtrees\Module\ModuleChartInterface;
use Fisharebest\Webtrees\Services\ModuleService;
use Illuminate\Support\Collection;
use Ramsey\Uuid\Uuid;

/**
* @var Individual|null $individual
* @var ModuleService $module_service
* @var Collection|Menu[] $menus
*/

if ($individual === null) {
echo '<div class="wt-chart-box"></div>';

return;
}

$module_service = app(ModuleService::class);

$menus = $module_service->findByComponent(ModuleChartInterface::class, $individual->tree(), Auth::user())->map(static function (ModuleChartInterface $module) use ($individual): ?Menu {
return $module->chartBoxMenu($individual);
})->filter();

foreach ($individual->spouseFamilies() as $family) {
$menus->push(new Menu('<strong>' . I18N::translate('Family with spouse') . '</strong>', $family->url()));
$spouse = $family->spouse($individual);
if ($spouse && $spouse->canShow()) {
$menus->push(new Menu($spouse->fullName(), $spouse->url()));
}
foreach ($family->children() as $child) {
if ($child->canShow()) {
$menus->push(new Menu($child->fullName(), $child->url()));
}
}
}

// Do not show these facts in the expanded chart boxes.
$exclude = [
'ADDR',
'ALIA',
'ASSO',
'CHAN',
'CHIL',
'EMAIL',
'FAMC',
'FAMS',
'HUSB',
'NAME',
'NOTE',
'OBJE',
'PHON',
'RESI',
'RESN',
'SEX',
'SOUR',
'SSN',
'SUBM',
'TITL',
'URL',
'WIFE',
'WWW',
'_EMAIL',
'_TODO',
'_UID',
'_WT_OBJE_SORT',
];

/** @var Collection|Fact[] $all_facts */
$all_facts = $individual->facts();
foreach ($individual->spouseFamilies() as $family) {
foreach ($family->facts() as $fact) {
$all_facts->push($fact);
}
}

$all_facts = $all_facts->filter(static function (Fact $fact) use ($exclude): bool {
return !in_array($fact->getTag(), $exclude, true);
});

$all_facts = Fact::sortFacts($all_facts);

$id = Uuid::uuid4()->toString();
?>

<div class="wt-chart-box wt-chart-box-<?= strtolower($individual->sex()) ?> <?= $individual->isPendingAddition() ? 'wt-new' : '' ?> <?= $individual->isPendingDeletion() ? 'wt-old' : '' ?> overflow-hidden" data-xref="<?= e($individual->xref()) ?>" data-tree="<?= e($individual->tree()->name()) ?>">
<?php if ($individual->canShow() && $individual->tree()->getPreference('SHOW_HIGHLIGHT_IMAGES')) : ?>
<div class="wt-chart-box-thumbnail float-left mr-1">
<?php
//[RC] adjusted: do not 'crop'
?>
<?= $individual->displayImage(40, 50, 'contain', ['class' => 'wt-chart-box-thumbnail']) ?>
</div>
<?php endif ?>

<?php if ($individual->canShow()) : ?>
<div class="wt-chart-box-extra d-print-none float-right ml-1">
<div class="dropdown position-static wt-chart-box-zoom">
<a class="wt-chart-box-icon" href="#" role="button" id="chart-box-zoom-<?= $id ?>" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<div ><?= view('icons/zoom-in') ?></div>
<div class="d-none"><?= view('icons/zoom-out') ?></div>
<span class="sr-only"><?= I18N::translate('Links') ?></span>
</a>

<div class="dropdown-menu dropdown-menu-right wt-chart-box-dropdown wt-chart-box-zoom-dropdown" style="position: inherit" aria-labelledby="#chart-box-zoom-<?= $id ?>">
<?php foreach ($all_facts as $fact) : ?>
<?= $fact->summary() ?>
<?php endforeach ?>
</div>
</div>

<div class="dropdown position-static wt-chart-box-links">
<a class="wt-chart-box-icon" href="#" role="button" id="chart-box-menu-<?= $id ?>" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="icon-pedigree" title="<?= I18N::translate('Links') ?>"></i>
<span class="sr-only"><?= I18N::translate('Links') ?></span>
</a>

<div class="dropdown-menu dropdown-menu-right wt-chart-box-dropdown wt-chart-box-links-dropdown" style="position: inherit" aria-labelledby="#chart-box-menu-<?= $id ?>">
<?php foreach ($menus as $menu) : ?>
<a class="dropdown-item p-1 <?= e($menu->getClass()) ?>" href="<?= e($menu->getLink()) ?>">
<?= $menu->getLabel() ?>
</a>
<?php endforeach ?>
</div>
</div>
</div>
<?php endif ?>

<div class="wt-chart-box-name font-weight-bold">
<?php if ($individual->canShow()) : ?>
<a href="<?= e($individual->url()) ?>" class="wt-chart-box-name"><?= $individual->fullName() ?></a>
<?php else : ?>
<span class="wt-chart-box-name"><?= $individual->fullName() ?></span>
<?php endif ?>
</div>

<div class="wt-chart-box-name font-weight-bold">
<?= $individual->alternateName() ?>
</div>

<div class="wt-chart-box-lifespan">
<?= $individual->lifespan() ?>
</div>

<div class="wt-chart-box-facts">
<div class="wt-chart-box-fact small">
<?php
$opt_tags = preg_split('/\W/', $individual->tree()->getPreference('CHART_BOX_TAGS'), 0, PREG_SPLIT_NO_EMPTY);
// Show BIRT or equivalent event

foreach (Gedcom::BIRTH_EVENTS as $birttag) {
if (!in_array($birttag, $opt_tags, true)) {
$event = $individual->facts([$birttag])->first();
if ($event instanceof Fact) {
echo $event->summary();
break;
}
}
}
// Show optional events (before death)
foreach ($opt_tags as $key => $tag) {
if (!in_array($tag, Gedcom::DEATH_EVENTS, true)) {
$event = $individual->facts([$tag])->first();
if ($event instanceof Fact) {
echo $event->summary();
unset($opt_tags[$key]);
}
}
}
// Show DEAT or equivalent event
foreach (Gedcom::DEATH_EVENTS as $deattag) {
$event = $individual->facts([$deattag])->first();
if ($event instanceof Fact) {
echo $event->summary();
if (in_array($deattag, $opt_tags, true)) {
unset($opt_tags[array_search($deattag, $opt_tags, true)]);
}
break;
}
}
// Show remaining optional events (after death)
foreach ($opt_tags as $tag) {
$event = $individual->facts([$tag])->first();
if ($event instanceof Fact) {
echo $event->summary();
}
}
?>
</div>
</div>
</div>
Loading

0 comments on commit a4f379b

Please sign in to comment.