Added landscape and portrait compatibility.
This commit is contained in:
parent
a8f493fc34
commit
4bd0ae9c93
2 changed files with 59 additions and 41 deletions
|
|
@ -7,7 +7,6 @@
|
|||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
width: 100%;
|
||||
|
|
|
|||
99
module.php
99
module.php
|
|
@ -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;
|
||||
}
|
||||
// folder path of gallery
|
||||
$gallery_folder = Resolve::toFilepath([
|
||||
$folderpaths[$i],
|
||||
$options[self::KEY_GALLERY_FOLDER_ID]
|
||||
]);
|
||||
// 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;
|
||||
}
|
||||
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,
|
||||
$this->getModuleId()
|
||||
);
|
||||
$div->appendChild(
|
||||
$this->importNode($rwd->getPictureTag(), true)
|
||||
);
|
||||
}
|
||||
break; // the loop should only run one time to the end
|
||||
$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;
|
||||
}
|
||||
|
||||
foreach ($fileids_first as $image) {
|
||||
$landscape = Resolve::arrayToId([
|
||||
$options[self::KEY_GALLERY_LANDSCAPE_FOLDER_ID],
|
||||
$image
|
||||
]);
|
||||
$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
|
||||
]);;
|
||||
}
|
||||
$rwd = new RwdPicture(
|
||||
$landscape,
|
||||
$portrait,
|
||||
$this->getModuleId()
|
||||
);
|
||||
$div->appendChild(
|
||||
$this->importNode($rwd->getPictureTag(), true)
|
||||
);
|
||||
}
|
||||
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(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue