2022-09-12 14:15:16 +00:00
|
|
|
<?php
|
|
|
|
namespace App;
|
|
|
|
|
|
|
|
class Make {
|
|
|
|
/*
|
|
|
|
|-------------------------------------------------------------
|
|
|
|
| Create Thumbnails
|
|
|
|
|-------------------------------------------------------------
|
|
|
|
| Default resolution for a preview image is 300px (max-width)
|
|
|
|
| ** Not yet implemented **
|
|
|
|
|-------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
function thumbnail($image_path, $thumbnail_path, $resolution) {
|
|
|
|
try {
|
2022-09-12 14:30:57 +00:00
|
|
|
$thumbnail = new \Imagick($image_path);
|
2022-09-12 14:15:16 +00:00
|
|
|
$thumbnail->resizeImage($resolution,null,null,1,null);
|
|
|
|
$thumbnail->writeImage($thumbnail_path);
|
|
|
|
|
|
|
|
return "success";
|
2022-09-12 14:30:57 +00:00
|
|
|
} catch (\Exception $e) {
|
2022-09-12 14:15:16 +00:00
|
|
|
return $e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2022-09-14 14:08:50 +00:00
|
|
|
Clean up long text input and turn into an array for tags
|
2022-09-12 14:15:16 +00:00
|
|
|
|
2022-09-14 14:08:50 +00:00
|
|
|
Returns clean string of words with equal white space between it
|
2022-09-12 14:15:16 +00:00
|
|
|
*/
|
|
|
|
function tags($string) {
|
|
|
|
// Replace hyphens
|
|
|
|
$string = str_replace('-', '_', $string);
|
|
|
|
// Regex
|
|
|
|
$string = preg_replace('/[^A-Za-z0-9\_ ]/', '', $string);
|
|
|
|
// Change to lowercase
|
|
|
|
$string = strtolower($string);
|
|
|
|
// Removing extra spaces
|
|
|
|
$string = preg_replace('/ +/', ' ', $string);
|
|
|
|
|
|
|
|
return $string;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Account {
|
|
|
|
/*
|
2022-09-14 14:08:50 +00:00
|
|
|
Check if user is loggedin
|
2022-09-12 14:15:16 +00:00
|
|
|
|
2022-09-14 14:08:50 +00:00
|
|
|
Returns True if user is
|
|
|
|
Returns False if user is NOT
|
2022-09-12 14:15:16 +00:00
|
|
|
*/
|
|
|
|
function is_loggedin() {
|
|
|
|
if (isset($_SESSION["loggedin"]) && $_SESSION["loggedin"] === true) {
|
|
|
|
return True;
|
|
|
|
} else {
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
2022-09-14 14:08:50 +00:00
|
|
|
Get full user info from database
|
2022-09-12 14:15:16 +00:00
|
|
|
|
2022-09-14 14:08:50 +00:00
|
|
|
Returns array with user info
|
2022-09-12 14:15:16 +00:00
|
|
|
*/
|
|
|
|
function get_user_info($conn, $id) {
|
|
|
|
// Setting SQL query
|
|
|
|
$sql = "SELECT * FROM users WHERE id = ".$id;
|
|
|
|
// Getting results
|
|
|
|
$query = mysqli_query($conn, $sql);
|
|
|
|
// Fetching associated info
|
|
|
|
$user_array = mysqli_fetch_assoc($query);
|
|
|
|
|
|
|
|
return($user_array);
|
|
|
|
}
|
|
|
|
/*
|
2022-09-14 14:08:50 +00:00
|
|
|
Check if user is admin
|
2022-09-12 14:15:16 +00:00
|
|
|
|
2022-09-14 14:08:50 +00:00
|
|
|
Returns True if user is privilaged
|
|
|
|
Returns False if user is NOT privilaged
|
2022-09-12 14:15:16 +00:00
|
|
|
*/
|
|
|
|
function is_admin($id) {
|
|
|
|
if (isset($id) || !empty($id)) {
|
|
|
|
if ($id == 1) {
|
|
|
|
return True;
|
|
|
|
} else {
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
}
|
2022-09-14 14:08:50 +00:00
|
|
|
/*
|
|
|
|
Get target IP, used for logging
|
|
|
|
*/
|
|
|
|
function get_ip() {
|
|
|
|
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
|
|
|
|
$target_ip = $_SERVER['HTTP_CLIENT_IP'];
|
|
|
|
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
|
|
|
|
$target_ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
|
|
|
|
} else {
|
|
|
|
$target_ip = $_SERVER['REMOTE_ADDR'];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $target_ip;
|
|
|
|
}
|
2022-09-12 14:15:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class Image {
|
|
|
|
/*
|
|
|
|
Get full image info from database
|
|
|
|
|
|
|
|
Returns array with image info
|
|
|
|
*/
|
|
|
|
function get_image_info($conn, $id) {
|
|
|
|
// Setting SQL query
|
2022-09-14 10:41:20 +00:00
|
|
|
$sql = "SELECT * FROM images WHERE id = ".$id;
|
2022-09-12 14:15:16 +00:00
|
|
|
// Getting results
|
|
|
|
$query = mysqli_query($conn, $sql);
|
|
|
|
// Fetching associated info
|
|
|
|
$image_array = mysqli_fetch_assoc($query);
|
|
|
|
|
|
|
|
return($image_array);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
Check if user is image owner
|
|
|
|
|
|
|
|
Returns True if user is privilaged
|
|
|
|
Returns False if user is NOT privilaged
|
|
|
|
*/
|
|
|
|
function image_privilage($id) {
|
|
|
|
$session_id = $_SESSION['id'];
|
|
|
|
if (isset($session_id) || !empty($session_id)) {
|
|
|
|
if ($session_id == $id) {
|
|
|
|
return True;
|
|
|
|
} else {
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|