Added landscape and portrait compatibility.

This commit is contained in:
Lewin Probst 2019-08-03 22:47:48 +02:00
parent a8f493fc34
commit 4bd0ae9c93
2 changed files with 59 additions and 41 deletions

View file

@ -7,7 +7,6 @@
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
position: fixed;
bottom: 0;
width: 100%;

View file

@ -10,7 +10,10 @@ return new class extends Lewp\Module
const KEY_START_LANDSCAPE_ID = "start_landscape_id";
const KEY_START_PORTRAIT_ID = "start_portrait_id";
const KEY_START_MODULE_ID = "start_module_id";
const KEY_GALLERY_FOLDER_ID = "gallery_folder_id";
const KEY_GALLERY_LANDSCAPE_FOLDER_ID = "gallery_landscape_folder_id";
const KEY_GALLERY_PORTRAIT_FOLDER_ID = "gallery_portrait_folder_id";
const KEY_GALLERY_IMAGE_EXTENSION = "image_extension";
const KEY_ORIENTATION_PRIORITY = "orientation_priority";
private function createBigImageContainer()
{
@ -50,12 +53,23 @@ return new class extends Lewp\Module
private function galleryAvailable(array $options) : bool
{
$retval = true;
if (!isset($options[self::KEY_GALLERY_FOLDER_ID])) {
if (!isset($options[self::KEY_GALLERY_LANDSCAPE_FOLDER_ID])) {
$retval = false;
}
if (!isset($options[self::KEY_GALLERY_PORTRAIT_FOLDER_ID])) {
$retval = false;
}
return $retval;
}
private function generateGalleryPath(string $base_path, string $folder_id) : string
{
return Resolve::toFilepath([
$base_path,
Resolve::idToFilepathRel($folder_id)
]);
}
private function createGallery(array $options)
{
$div = $this->createAndSetupElement(
@ -67,51 +81,56 @@ return new class extends Lewp\Module
);
// get all filenames
$folderpaths = $this->findFolderPaths('res-images');
for ($i = 0; $i < sizeof($folderpaths); ++$i) {
if ($folderpaths[$i] === false) {
continue;
$fileids_first = $this->collectResourceFileIds(
'res-images',
$options[self::KEY_GALLERY_LANDSCAPE_FOLDER_ID],
'*.'.$options[self::KEY_GALLERY_IMAGE_EXTENSION]
);
$tmp = $this->collectResourceFileIds(
'res-images',
$options[self::KEY_GALLERY_PORTRAIT_FOLDER_ID],
'*.'.$options[self::KEY_GALLERY_IMAGE_EXTENSION]
);
if ($options[self::KEY_ORIENTATION_PRIORITY] === 'portrait') {
$fileids_second = $fileids_first;
$fileids_first = $tmp;
} else {
$fileids_second = $tmp;
}
// folder path of gallery
$gallery_folder = Resolve::toFilepath([
$folderpaths[$i],
$options[self::KEY_GALLERY_FOLDER_ID]
foreach ($fileids_first as $image) {
$landscape = Resolve::arrayToId([
$options[self::KEY_GALLERY_LANDSCAPE_FOLDER_ID],
$image
]);
// all images in the folder
$gallery_filenames = scandir($gallery_folder);
// check if folder is empty or not available
if (
($gallery_filenames === false)
|| (sizeof($gallery_filenames) == 2)
) {
continue;
$portrait = $landscape;
// check if the portrait file is available
if (in_array($image, $fileids_second)) {
$portrait = Resolve::arrayToId([
$options[self::KEY_GALLERY_PORTRAIT_FOLDER_ID],
$image
]);;
}
foreach ($gallery_filenames as $image) {
if ($image === '..' || $image === '.') {
continue;
}
$landscape =
$options[self::KEY_GALLERY_FOLDER_ID]
.Resolve::ID_SEPARATOR
.$image;
$rwd = new RwdPicture(
$landscape,
$landscape,
$portrait,
$this->getModuleId()
);
$div->appendChild(
$this->importNode($rwd->getPictureTag(), true)
);
}
break; // the loop should only run one time to the end
}
return $div;
}
public function run(array $options = []) : bool
{
// add default options
$options += [
self::KEY_ORIENTATION_PRIORITY => 'landscape',
self::KEY_GALLERY_IMAGE_EXTENSION => 'jpg'
];
$big_image_container = $this->createBigImageContainer();
if ($this->bigImageAvailable($options)) {
$big_image = $this->createBigImage(