denbooru-php/tag.php

156 lines
3.9 KiB
PHP

<?php session_start(); ?>
<html>
<head>
<?php $thumb_size = 150; ?>
<title>Dendy\'s image gallery</title>
<style>
.title{
text-align: left;
}
.page-num{
width:30px;
display:inline-block;
}
#content{
float: right;
display: flex;
flex-direction: row;
Flex-wrap: wrap;
align-items: center;
justify-content: center;
width: 100%;
margin: 30px 20px;
}
.thumb{
border:1px solid grey;
float:left;
margin:5px;
}
.thumb div{
<?php echo "width:".$thumb_size."px;height:".$thumb_size."px;" ?>
position: relative;
}
.thumb div img{
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
</style>
</head>
<body>
<?php
include("include/header.php");
include("config.php");
function thumbmake($path){
$image_hash = hash_file("sha256", $path);
$x = pathinfo($path,PATHINFO_EXTENSION);
$thumb_path = ".thumb/" . $image_hash . "." . $x;
if(!file_exists($thumb_path)){
global $thumb_size;
$image = new Imagick($path);
$image->setImageFormat($x);
$image->thumbnailImage($thumb_size, $thumb_size, TRUE);
$image->writeImage($thumb_path);
echo "creating thumb";
}
return "<img src='" . $thumb_path . "'/>";
}
echo "<a href='/'>return</a>";
echo("<h2 class='title'>" . $_GET ["t"] . "</h2>");
/* Get image paths */
/* Queries */
// Handle * and void to show everything
if(!$_GET["t"] || $_GET["t"] == "*"){
exec($tmsu . "files " . $alone_exclude_query, $output);
}
// regular query
else exec($tmsu . "files " . escape_cmd($_GET["t"] . $exclude_query), $output);
/* Purge things that aren't images */
$total = sizeof($output);
for($i = 0; $i < $total; $i++){
$x = pathinfo($output[$i],PATHINFO_EXTENSION);
if($x != "jpg" && $x != "jpeg" && $x != "png") unset($output[$i]);
}
$output = array_values($output);
$total = sizeof($output);
// Set base directory
$basedir = "/tag.php?";
if($_GET["t"]) $basedir = $basedir . "t=".$_GET["t"] . "&";
$basedir = $basedir . "p=";
$max = 25;
/* PAGE SELECTION BAR */
$num_pages = ceil($total/$max);
$num_page_selector = 3; //number of pages selectable before and after
if($_GET["p"] - $num_page_selector < 1) $lower_page_num = 1;
else if($_GET["p"] + $num_page_selector > $num_pages) $lower_page_num = $num_pages - $num_page_selector*2;
else $lower_page_num = $_GET["p"] - $num_page_selector;
if(!$_GET["p"]) $_GET["p"] = 1;
$step = ($_GET["p"] - 1) * $max;
$psb = "";
$psb = $psb . "<div style='text-align:center;clear:both'>\n";
if($_GET["p"] > 2){
$psb = $psb . "<div class='page-num'><a href='".$basedir."1'>|<</a></div>\n";
}
if($_GET["p"] != 1){
$psb = $psb . "<div class='page-num'><a href='". $basedir . ($_GET["p"] - 1) . "'><</a></div>\n";
}
for($i = $lower_page_num; $i < $lower_page_num + $num_page_selector*2 + 1 && $i < $num_pages + 1; $i++){
$psb = $psb . "<div class='page-num'>\n";
if($i != $_GET["p"]) $psb = $psb . "<a href=".$basedir.$i.">".$i." </a>\n";
else $psb = $psb . $i . " \n";
$psb = $psb . "</div>\n";
}
if($_GET["p"] != $num_pages){
$psb = $psb . "<div class='page-num'><a href='". $basedir . ($_GET["p"] + 1) . "'>></a></div>\n";
}
if($_GET["p"] < $num_pages - 1){
$psb = $psb . "<div class='page-num'><a href='".$basedir.$num_pages."'>>|</a></div>\n";
}
$psb = $psb . "<div>\n";
/* END OF PAGE SELECTION BAR */
// Title
if($total != 0) echo "<p>There are a total of " . $total . " images under the tag(s) " . $_GET["t"] . ".</p>\n";
else echo "There aren't any images with that tag query";
echo $psb;
/* ACTUAL IMAGES */
echo "<div id='container'><div id='content'>";
for($i = 0 + $step; $i < $max + $step && $i < $total; $i++){
echo "<a href='/view.php?i=" . $output[$i] . "'>";
echo "\n\t<div class='thumb'>\n";
//echo "\t\t" . basename($output[$i]) . "<br/>\n";
echo "<div>" . thumbmake($output[$i]) . "</div>";
echo "\t</div>\n";
echo "</a>\n\n";
}
echo "</div></div>";
echo $psb;
?>
</body>
</html>