Browse Source

initial commit

master
Pòsweg 2 years ago
commit
9956c737cb
  1. 3
      .gitignore
  2. 46
      admin.php
  3. 23
      config.php
  4. 33
      include/header.php
  5. 35
      index.php
  6. 29
      login.php
  7. 6
      logout.php
  8. 153
      tag.php
  9. 29
      view.php

3
.gitignore

@ -0,0 +1,3 @@
drw
.thumb/

46
admin.php

@ -0,0 +1,46 @@
<?php
session_start();
if(!isset($_SESSION["login"])) header("Location: /img/login.php");
?>
<html>
<head>
<title>Pòsweg's image gallery</title>
</head>
<body>
<?php
include("include/header.php");
include("config.php");
echo "<h2>Woah</h2>";
$images = array();
$dir = "drw";
if(isset($_GET["l"])) $dir = $_GET["l"];
if ($handle = opendir($dir)) {
while (false !== ($entry = readdir($handle))) {
$x = pathinfo($entry,PATHINFO_EXTENSION);
if ($x == "" && $entry != ".") {
echo("<a href='/img/admin.php?l=$dir/$entry'>$entry</a><br/>\n");
}
else if($x == "jpg" || $x == "jpeg" || $x == "png"){
array_push($images, $entry);
}
}
closedir($handle);
}
foreach($images as $img){
$output = "";
exec($tmsu . "tags -1 '$dir/$img'", $output);
$num_tags = sizeof($output);
echo("<div style='float:left';>");
echo("<img width='100px' src='/img/$dir/$img'/>");
echo("<form><input type='text' value='");
for($i = 1; $i < $num_tags; $i++) echo $output[$i] . " ";
echo("'/></form>");
echo("</div>");
}
?>
</body>
</html>

23
config.php

@ -0,0 +1,23 @@
<?php
$tmsu = "tmsu -D drw/.tmsu/db ";
/* Exclude */
$exclude = "";
$exclude_query = "";
$alone_exclude_query = "";
if(!isset($_SESSION["login"])){
$exclude = array("nipples", "nude", "lewd", "dick");
$exclude_copy = $exclude;
$exclude_query = $exclude_query . " and ";
$alone_exclude_query = " not " . $exclude_copy[0];
unset($exclude_copy[0]);
foreach($exclude_copy as $ex_tag){
$alone_exclude_query = $alone_exclude_query . " and not " . $ex_tag;
}
$exclude_query = $exclude_query . $alone_exclude_query;
$alone_exclude_query = "'" . $alone_exclude_query . "'";
}
?>

33
include/header.php

@ -0,0 +1,33 @@
<?php session_start(); ?>
<style>
body{
background-color: black;
}
*{
color: white;
font-family: monospace;
}
input{
background-color: black;
padding: 5px;
border: 1px solid white;
}
a:visited{
color: grey;
}
#header{
text-align: center;
}
</style>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<div id="header">
<?php
if($_SESSION["login"] === true) echo "You are logged in - <a href='/img/logout.php'>logout</a>";
else echo "<a href='/img/login.php'>Login</a>";
?>
<h1>Pòsweg's Suckless Booru</h1>
<form method="GET" action="tag.php">
<input type="text" name="t" value="<?php if($_GET["t"]) echo $_GET["t"]; ?>">
<input type="submit">
</form>
</div>

35
index.php

@ -0,0 +1,35 @@
<html>
<head>
<title>Pòsweg's image gallery</title>
</head>
<body>
<?php
include("include/header.php");
include("config.php");
echo "<h2>Tag list</h2>";
exec($tmsu . "tags", $output);
$tag_num = sizeof($output);
for($i = 0; $i < $tag_num; $i++){
foreach($exclude as $excluded_tag){
if($excluded_tag == $output[$i]){
unset($output[$i]);
}
}
}
$tag_num = sizeof($output);
// Echo total tag count
echo "<p>There is a total of " . $tag_num . " tags</p>";
//Tag list
foreach($output as $tag){
$count = "";
exec($tmsu . "files -c " . $tag . $exclude_query, $count);
echo("<a href='http://" . $_SERVER['HTTP_HOST'] . "/tag.php?t=" . $tag . "'>(" . $count[0] .") " . $tag ."</a>, ");
}
?>
</body>
</html>

29
login.php

@ -0,0 +1,29 @@
<?php
include("include/header.php");
$errorMsg = "";
$validUser = $_SESSION["login"] === true;
$hash = "$2y$10\$AEErDtoqRrizUSS.uIlkDOcX/w3mAxCDo28QnfSNg9FTMC8eQVpeC";
if(isset($_POST["sub"])) {
$validUser = $_POST["username"] == "admin" && password_verify($_POST["password"], $hash);
if(!$validUser) $errorMsg = "Invalid username or password.";
else $_SESSION["login"] = true;
}
if($validUser) {
header("Location: /index.php"); die();
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>Login</title>
</head>
<body>
<form name="input" action="" method="post">
<label for="username">Username:</label><input type="text" value="<?= $_POST["username"] ?>" id="username" name="username" /><br/>
<label for="password">Password:</label><input type="password" value="" id="password" name="password" />
<div class="error"><?= $errorMsg ?></div>
<input type="submit" value="Home" name="sub" />
</form>
</body>
</html>

6
logout.php

@ -0,0 +1,6 @@
<?php
session_start();
session_unset();
session_destroy();
header("Location: /img/index.php"); die();
?>

153
tag.php

@ -0,0 +1,153 @@
<html>
<head>
<?php $thumb_size = 150; ?>
<title>Pòsweg'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 '" . $_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>

29
view.php

@ -0,0 +1,29 @@
<html>
<head>
<title>Pòsweg's image gallery</title>
<style>
#img{
height: 70vh;
float: right;
}
</style>
</head>
<body>
<?php
include("include/header.php");
include("config.php");
echo "<h1>Tag list</h1>";
echo "<img id=\"img\" src=\"/" . $_GET["i"] . "\">";
//Tag list
echo "Tags:<br/>";
exec($tmsu . "tags -1 \"" . $_GET["i"] . $excluded_query . "\"", $output);
$num_tags = sizeof($output);
for($i = 1; $i < $num_tags; $i++){
echo("<a href='http://" . $_SERVER['HTTP_HOST'] . "/tag.php?t=" . $output[$i] . "'>" . $output[$i] ."</a><br/>");
}
?>
</body>
</html>
Loading…
Cancel
Save