Start on fixing errors and semi-automatic setup

This commit is contained in:
Michał Gdula 2022-10-19 10:57:46 +00:00
parent d897215023
commit c3814000c0
10 changed files with 180 additions and 57 deletions

3
.gitignore vendored
View file

@ -1,5 +1,6 @@
# Images from uploads to the website, including thumbnails
# Dont include user generated content in github repo
images/
conf/
# CSS map, I don't think its needed for upload... I think?
*.map

View file

@ -42,9 +42,9 @@
</form>
<?php
if (is_file("usr/images/pfp/".$profile_info['pfp_path'])) {
echo "<img src='usr/images/pfp/".$profile_info['pfp_path']."'>";
echo "<img alt='profile picture' src='usr/images/pfp/".$profile_info['pfp_path']."'>";
} else {
echo "<img src='assets/no_image.png'>";
echo "<img alt='profile picture' src='assets/no_image.png'>";
}
?>
<script>
@ -166,7 +166,7 @@
$token_request = mysqli_query($conn, "SELECT * FROM tokens WHERE used = 0");
while ($token = mysqli_fetch_array($token_request)) {
?>
<button onclick='copyCode()' class='btn btn-neutral'><?php echo $token['code']; ?></button>
<button onclick='copyCode()' class='btn btn-neutral btn-code'><?php echo $token['code']; ?></button>
<script>
function copyCode() {
navigator.clipboard.writeText("<?php echo $token['code']; ?>");

5
app/app.json Normal file
View file

@ -0,0 +1,5 @@
{
"license": "GPL 3.0",
"version": "22.10.19",
"branch": "main"
}

View file

@ -332,6 +332,71 @@ class Diff {
}
}
class Setup {
function create_tables($conn, $sql): bool
{
/*
$sql = "CREATE TABLE IF NOT EXISTS users ()";
if ($conn->query($sql) === TRUE) {
echo "Table users created successfully";
}
$sql = "CREATE TABLE IF NOT EXISTS images ()";
if ($conn->query($sql) === TRUE) {
echo "Table images created successfully";
}
$sql = "CREATE TABLE IF NOT EXISTS groups ()";
if ($conn->query($sql) === TRUE) {
echo "Table groups created successfully";
}
$sql = "CREATE TABLE IF NOT EXISTS logs ()";
if ($conn->query($sql) === TRUE) {
echo "Table logs created successfully";
}
*/
return True;
}
function create_usr() {
if (!is_dir(__DIR__."/../usr")) {
mkdir("usr");
}
if (!is_dir(__DIR__."/../usr/images")) {
mkdir("usr/images");
}
if (!is_dir(__DIR__."/../usr/images/thumbnails")) {
mkdir("usr/images/thumbnails");
}
if (!is_dir(__DIR__."/../usr/images/previews")) {
mkdir("usr/images/previews");
}
if (!is_dir(__DIR__."/../usr/conf")) {
mkdir("usr/conf");
}
if (!is_file(__DIR__."/../usr/conf/manifest.json")) {
$manifest = array(
"website_name" => "Only Legs",
"website_description" => "A simple PHP gallery with multiple users in mind",
"welcome_message" => array("*internal screaming*", "Welcome to Only Legs!"),
"user_name" => "[your name]",
"is_test" => true,
"upload" => array(
"max_filesize" => 35,
"rename_on_upload" => true,
"rename_to" => "IMG_{{username}}_{{time}}",
"allowed_extensions" => array("jpg", "jpeg", "png", "webp")
)
);
file_put_contents(__DIR__."/../usr/conf/manifest.json", json_encode($manifest));
}
}
}
class Sanity {
function check_json(): array
{
@ -398,25 +463,22 @@ class Sanity {
function check_version(): array
{
$results = array();
$results = array();
$app_local = json_decode(file_get_contents(__DIR__."/app.json"), true);
$url = "https://raw.githubusercontent.com/Fluffy-Bean/image-gallery/main/app/settings/manifest.json";
$curl_url = "https://raw.githubusercontent.com/Fluffy-Bean/image-gallery/".$app_local['branch']."/app/settings/manifest.json";
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_URL, $curl_url);
$result = curl_exec($curl);
curl_close($curl);
$ch = curl_init();
$app_repo = json_decode($result, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
$result = curl_exec($ch);
curl_close($ch);
$manifest_repo = json_decode($result, true);
$manifest_local = json_decode(file_get_contents(__DIR__."/../usr/conf/manifest.json"), true);
if ($manifest_local['version'] < $manifest_repo['version']) {
$results[] = "Critical: You are not running the latest version of the app v".$manifest_repo['version']."";
} else if ($manifest_local['version'] > $manifest_repo['version']) {
$results[] = "Warning: You are running a version of the app that is newer than the latest release v".$manifest_repo['version']."";
if ($app_local['version'] < $app_repo['version']) {
$results[] = "Critical: You are not running the latest version of the app v".$app_repo['version']."";
} elseif ($app_local['version'] > $app_repo['version']) {
$results[] = "Warning: You are running a version of the app that is newer than the latest release v".$app_repo['version']."";
}
if (PHP_VERSION_ID < 80000) {

View file

@ -30,7 +30,12 @@ if (isset($_POST['submit'])) {
$tags = $make_stuff->tags(trim($_POST['tags']));
// Check filetype
$allowed_types = array('jpg', 'jpeg', 'png', 'webp');
if (isset($upload_conf['allowed_extentions'])) {
$allowed_types = $upload_conf['allowed_extentions'];
} else {
$allowed_types = array('jpg', 'jpeg', 'png', 'webp');
}
if (!in_array($file_type, $allowed_types)) {
?>
<script>

View file

@ -8,6 +8,7 @@
| the default background and accent colour
|-------------------------------------------------------------
*/
$user_import = file_get_contents(__DIR__."/../usr/conf/manifest.json");
$user_settings = json_decode($user_import, true);
$user_settings = json_decode(file_get_contents(__DIR__."/../usr/conf/manifest.json"), true);
$web_info = json_decode(file_get_contents(__DIR__."/app.json"), true);
$upload_conf = $user_settings["upload"];

View file

@ -27,7 +27,7 @@
<hr>
<a class='link' href="https://github.com/Fluffy-Bean/image-gallery">Made by Fluffy</a>
<hr>
<p>V<?php echo $user_settings['version']; ?></p>
<p>V<?php echo $web_info['version']; ?></p>
<?php
if ($exec_time != 0) {
echo "<hr>

View file

@ -759,21 +759,22 @@ nav .btn {
display: flex;
flex-direction: row;
}
.pfp-upload > img {
margin-left: 0.5rem;
width: 7.813rem;
height: 7.813rem;
-o-object-fit: cover;
object-fit: cover;
border-radius: 3px;
background-color: #121212;
}
.pfp-upload form > * {
margin: 0 0 0.5rem 0;
}
.pfp-upload form > *:last-child {
margin: 0 0 0 0;
}
.pfp-upload > img {
margin-left: 0.5rem;
width: 8rem;
height: 8rem;
-o-object-fit: cover;
object-fit: cover;
float: right;
border-radius: 3px;
background-color: #121212;
}
@media (max-width: 621px) {
.pfp-upload {
@ -782,8 +783,8 @@ nav .btn {
}
.pfp-upload > img {
margin: 0 auto 1rem;
width: 10rem;
height: 10rem;
width: 12rem;
height: 12rem;
}
}
.tabs {
@ -961,6 +962,25 @@ nav .btn {
top: 0;
}
.btn-code {
color: rgba(0, 0, 0, 0);
position: relative;
}
.btn-code::after {
content: "Hover to show code";
color: #E8E3E3;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.btn-code:hover {
color: #E8E3E3;
}
.btn-code:hover::after {
content: "";
}
/*
|-------------------------------------------------------------
| FOOTER

View file

@ -736,29 +736,31 @@
display: flex;
flex-direction: row;
& > img {
margin-left: 0.5rem;
width: 7.813rem;
height: 7.813rem;
object-fit: cover;
@if calc($rad - 0.5rem) > 0 {
border-radius: calc($rad - 0.5rem);
} @else {
border-radius: 3px;
}
background-color: $black;
}
form > * {
margin: 0 0 0.5rem 0;
}
form > *:last-child {
margin: 0 0 0 0;
}
& > img {
margin-left: 0.5rem;
width: 8rem;
height: 8rem;
object-fit: cover;
float: right;
@if calc($rad - 0.5rem) > 0 {
border-radius: calc($rad - 0.5rem);
} @else {
border-radius: 3px;
}
background-color: $black;
}
}
@media (max-width: 621px) {
.pfp-upload {
@ -768,8 +770,8 @@
& > img {
margin: 0 auto 1rem;
width: 10rem;
height: 10rem;
width: 12rem;
height: 12rem;
}
}
}
@ -971,4 +973,27 @@
background-color: $bg;
position: sticky;
top: 0;
}
.btn-code {
color: #00000000;
position: relative;
&::after {
content: "Hover to show code";
color: $fg;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
&:hover {
color: $fg;
&::after {
content: "";
}
}
}

View file

@ -23,13 +23,17 @@
"Gods die too.",
"Eat hotchip and lie"
],
"license":"GPL 3.0",
"version": "22.10.13",
"user_name": "[your name]",
"is_testing": true,
"upload": {
"max_filesize": "32",
"rename_on_upload": true,
"rename_to": "IMG_{{username}}_{{time}}"
"rename_to": "IMG_{{username}}_{{time}}",
"allowed_extentions": [
"jpg",
"jpeg",
"png",
"webp"
]
}
}