104 lines
2.9 KiB
PHP
104 lines
2.9 KiB
PHP
<?php
|
|
session_start();
|
|
|
|
/** require autoloading to manage namespaces */
|
|
require __DIR__ . '/vendor/autoload.php';
|
|
|
|
use PhotoPrismUpload\API\PhotoPrism;
|
|
use PhotoPrismUpload\Entities\Album;
|
|
use PhotoPrismUpload\Entities\Photo;
|
|
|
|
?>
|
|
<html>
|
|
<head>
|
|
<title>Collagen Abstimmung</title>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<meta charset="utf-8">
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
<link href="vote.css" rel="stylesheet">
|
|
</head>
|
|
<body>
|
|
<?php
|
|
|
|
$footer = '</body></html>';
|
|
|
|
/** @var array $config configuration options */
|
|
$config = require(__DIR__ . '/config.php');
|
|
|
|
/** @var PhotoPrism $api API object to interface with PhotoPrism */
|
|
$api = new PhotoPrism($config);
|
|
|
|
/** @var Album[] $albums List of PhotoPrism albums */
|
|
$albums = [];
|
|
try {
|
|
$api->login();
|
|
} catch (\Exception $e) {
|
|
die('Fehler: ' . $e->getMessage().$footer.'</body></html>');
|
|
}
|
|
|
|
/** @var string $token Tokens for which album(s) are visible in the dropdown */
|
|
$token = $_GET['token'];
|
|
|
|
/** @var int $page Page number of photos to load */
|
|
$page = 1;
|
|
|
|
/** @var int $count Number of pictures to load */
|
|
$count = 200;
|
|
|
|
/** @var int $offset Tokens for which album(s) are visible in the dropdown */
|
|
$offset = ($page - 1) * $count;
|
|
|
|
/** @var string $album_url URL path to the selected album */
|
|
$album_url = '/';
|
|
|
|
$votes_file = 'votes.json';
|
|
|
|
$contents = file_get_contents($votes_file);
|
|
if ($contents === false) {
|
|
$contents = '{}';
|
|
}
|
|
$contents = json_decode($contents, true);
|
|
|
|
$vote_counts = [];
|
|
foreach ($contents as $votes) {
|
|
foreach ($votes as $photo_uid => $vote_value) {
|
|
if (!array_key_exists($photo_uid, $vote_counts)) {
|
|
$vote_counts[$photo_uid] = 0;
|
|
}
|
|
$vote_counts[$photo_uid] += intval($vote_value);
|
|
}
|
|
}
|
|
|
|
$page_sizes = array_values(array_unique([10, 20, 50, 100, $count]));
|
|
sort($page_sizes);
|
|
$link_class = $page === 1 ? 'pageLink disabled' : 'pageLink';
|
|
|
|
try {
|
|
$album = $api->getAlbumByToken($token);
|
|
if ($album === null) {
|
|
die('Album nicht gefunden' . $footer . '</body></html>');
|
|
}
|
|
$photos = $api->getAlbumPhotos($album, $count, $offset);
|
|
$photos = array_filter($photos, function (Photo $a) use ($vote_counts) {
|
|
$vote_a = $vote_counts[$a->uid] ?? 0;
|
|
return $vote_a >= 0;
|
|
});
|
|
usort($photos, function (Photo $a, Photo $b) use ($vote_counts) {
|
|
$vote_a = $vote_counts[$a->uid] ?? 0;
|
|
$vote_b = $vote_counts[$b->uid] ?? 0;
|
|
return $vote_b - $vote_a;
|
|
});
|
|
?>
|
|
<?php
|
|
foreach ($photos as $photo) {
|
|
$thumb = $photo->getThumbnailUrl();?>
|
|
<div class="photowrapper">
|
|
<img src="<?= $api->api_url.$thumb?>" id="<?= $photo->uid?>" loading="lazy" data-votes="<?=$vote_counts[$photo->uid]?>">
|
|
</div>
|
|
<?php
|
|
}
|
|
} catch (\Exception $e) {
|
|
die('Fehler: ' . $footer . $e->getMessage() . '</body></html>');
|
|
}
|
|
?>
|