diff --git a/about.php b/about.php
index a50808e..65e180f 100644
--- a/about.php
+++ b/about.php
@@ -35,15 +35,15 @@
Admin controlls
@@ -37,7 +41,7 @@
resizeImage($resolution,null,null,1,null);
+ $thumbnail->writeImage($thumbnail_path);
+
+ return "success";
+ } catch (Exception $e) {
+ return $e;
+ }
+ }
+
+ /*
+ Clean up long text input and turn into an array for tags
+
+ Returns clean string of words with equal white space between it
+ */
+ 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 {
+ /*
+ Check if user is loggedin
+
+ Returns True if user is
+ Returns False if user is NOT
+ */
+ function is_loggedin() {
+ if (isset($_SESSION["loggedin"]) && $_SESSION["loggedin"] === true) {
+ return True;
+ } else {
+ return False;
+ }
+ }
+ /*
+ Get full user info from database
+
+ Returns array with user info
+ */
+ 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);
+ }
+ /*
+ Check if user is admin
+
+ Returns True if user is privilaged
+ Returns False if user is NOT privilaged
+ */
+ function is_admin($id) {
+ if (isset($id) || !empty($id)) {
+ if ($id == 1) {
+ return True;
+ } else {
+ return False;
+ }
+ } else {
+ return False;
+ }
+ }
+}
+
+class Image {
+ /*
+ Get full image info from database
+
+ Returns array with image info
+ */
+ function get_image_info($conn, $id) {
+ // Setting SQL query
+ $sql = "SELECT * FROM swag_table WHERE id = ".$id;
+ // 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;
+ }
+ }
+
+}
diff --git a/app/format/create_thumbnail.php b/app/format/create_thumbnail.php
deleted file mode 100644
index 92debfc..0000000
--- a/app/format/create_thumbnail.php
+++ /dev/null
@@ -1,20 +0,0 @@
-resizeImage($resolution,null,null,1,null);
- $thumbnail->writeImage($thumbnail_path);
-
- return "success";
- } catch (Exception $e) {
- return $e;
- }
-}
\ No newline at end of file
diff --git a/app/format/string_to_tags.php b/app/format/string_to_tags.php
deleted file mode 100644
index 0c8d2a5..0000000
--- a/app/format/string_to_tags.php
+++ /dev/null
@@ -1,18 +0,0 @@
-get_image_info($conn, $_POST['id']);
// If user owns image or has the ID of 1
- if (image_privilage($image_array['author']) || $_SESSION['id'] == 1) {
+ if ($image_info->image_privilage($image_array['author']) || $_SESSION['id'] == 1) {
// Delete from table
$sql = "DELETE FROM swag_table WHERE id = ?";
if ($stmt = mysqli_prepare($conn, $sql)) {
@@ -92,9 +96,9 @@ if (isset($_POST['submit_delete'])) {
*/
if (isset($_POST['submit_description'])) {
// Get all image info
- $image_array = get_image_info($conn, $_POST['id']);
+ $image_array = $image_info->get_image_info($conn, $_POST['id']);
// If user owns image or has the ID of 1
- if (image_privilage($image_array['author']) || $_SESSION['id'] == 1) {
+ if ($image_info->image_privilage($image_array['author']) || $_SESSION['id'] == 1) {
// getting ready forSQL asky asky
$sql = "UPDATE swag_table SET alt=? WHERE id=?";
@@ -150,11 +154,11 @@ if (isset($_POST['submit_description'])) {
*/
if (isset($_POST['submit_tags'])) {
// Get all image info
- $image_array = get_image_info($conn, $_POST['id']);
+ $image_array = $image_info->get_image_info($conn, $_POST['id']);
// If user owns image or has the ID of 1
- if (image_privilage($image_array['author']) || $_SESSION['id'] == 1) {
+ if ($image_info->image_privilage($image_array['author']) || $_SESSION['id'] == 1) {
// Clean input
- $tags_string = tag_clean(trim($_POST['input']));
+ $tags_string = $make_stuff->tags(trim($_POST['input']));
// getting ready forSQL asky asky
$sql = "UPDATE swag_table SET tags=? WHERE id=?";
@@ -211,7 +215,7 @@ if (isset($_POST['submit_tags'])) {
*/
if (isset($_POST['submit_author'])) {
// If user has the ID of 1
- if ($_SESSION['id'] == 1) {
+ if ($user_info->is_admin($_SESSION['id'])) {
// getting ready forSQL asky asky
$sql = "UPDATE swag_table SET author=? WHERE id=?";
diff --git a/app/image/image_privilage.php b/app/image/image_privilage.php
deleted file mode 100644
index 439e3fa..0000000
--- a/app/image/image_privilage.php
+++ /dev/null
@@ -1,19 +0,0 @@
-tags(trim($_POST['tags']));
// Allowed file types
$allowed_types = array('jpg', 'jpeg', 'png', 'webp');
@@ -35,7 +38,7 @@ if (isset($_POST['submit'])) {
// Attempt making a thumbnail
list($width, $height) = getimagesize($image_path);
if ($width > 300) {
- $make_thumbnail = make_thumbnail($image_path, $thumb_dir.$image_newname, 300);
+ $make_stuff->thumbnail($image_path, $thumb_dir.$image_newname, 300);
if ($make_thumbnail != "success") {
?>
-
- get_user_info($conn, $image['author']);
if (isset($user['username'])) {
$image_author = $user['username'];
@@ -123,7 +123,7 @@
| Check user privilge
|-------------------------------------------------------------
*/
- if (image_privilage($image['author']) || is_admin($_SESSION['id'])) {
+ if ($image_info->image_privilage($image['author']) || $user_info->is_admin($_SESSION['id'])) {
$privilaged = True;
} else {
$privilaged = False;
@@ -363,7 +363,7 @@
|-------------------------------------------------------------
-->
is_admin($_SESSION['id'])) {
?>
+
+
- ";
+ if (!$user_info->is_loggedin()) {
+ ?>
+
+