]> jfr.im git - uguu.git/blobdiff - static/php/includes/Core.namespace.php
refactoring
[uguu.git] / static / php / includes / Core.namespace.php
index 464d2a19d2dd982ca2b2ead02358392f219fcfd5..fcd1d50af12c864c5e35031c3ab27767f93dac89 100644 (file)
@@ -3,7 +3,7 @@
 /*
  * Uguu
  *
- * @copyright Copyright (c) 2022 Go Johansson (nekunekus) <neku@pomf.se> <github.com/nokonoko>
+ * @copyright Copyright (c) 2022 Go Johansson (nokonoko) <neku@pomf.se>
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -51,7 +51,6 @@ namespace Core {
 
         public static int $NAME_LENGTH;
         public static string $ID_CHARSET;
-        public static array $DOUBLE_DOTS;
         public static array $BLOCKED_EXTENSIONS;
         public static array $BLOCKED_MIME;
 
@@ -61,12 +60,12 @@ namespace Core {
          */
         public static function loadConfig()
         {
-            if (!file_exists('/Users/go.johansson/PERSONAL_REPOS/Uguu/dist.json')) {
+            if (!file_exists('/var/www/uguu/dist.json')) {
                 throw new Exception('Cant read settings file.', 500);
             }
             try {
                 $settings_array = json_decode(
-                    file_get_contents('/Users/go.johansson/PERSONAL_REPOS/Uguu/dist.json'),
+                    file_get_contents('/var/www/uguu/dist.json'),
                     true
                 );
                 self::$DB_MODE = $settings_array['DB_MODE'];
@@ -85,11 +84,10 @@ namespace Core {
                 self::$ID_CHARSET = $settings_array['ID_CHARSET'];
                 self::$BLOCKED_EXTENSIONS = $settings_array['BLOCKED_EXTENSIONS'];
                 self::$BLOCKED_MIME = $settings_array['BLOCKED_MIME'];
-                self::$DOUBLE_DOTS = $settings_array['DOUBLE_DOTS'];
             } catch (Exception) {
                 throw new Exception('Cant populate settings.', 500);
             }
-            (new Database())->assemblePDO();
+            Database::assemblePDO();
         }
     }
 
@@ -285,7 +283,7 @@ namespace Core {
         /**
          * @throws Exception
          */
-        public function dbCheckNameExists()
+        public static function dbCheckNameExists()
         {
             try {
                 $q = Settings::$DB->prepare('SELECT COUNT(filename) FROM files WHERE filename = (:name)');
@@ -300,7 +298,7 @@ namespace Core {
         /**
          * @throws Exception
          */
-        public function checkFileBlacklist()
+        public static function checkFileBlacklist()
         {
             try {
                 $q = Settings::$DB->prepare('SELECT hash, COUNT(*) AS count FROM blacklist WHERE hash = (:hash)');
@@ -318,7 +316,7 @@ namespace Core {
         /**
          * @throws Exception
          */
-        public function antiDupe()
+        public static function antiDupe()
         {
             try {
                 $q = Settings::$DB->prepare(
@@ -330,6 +328,8 @@ namespace Core {
                 $result = $q->fetch();
                 if ($result['count'] > 0) {
                     Upload::$NEW_NAME_FULL = $result['filename'];
+                } else {
+                    Upload::generateName();
                 }
             } catch (Exception) {
                 throw new Exception('Cant check for dupes in DB.', 500);
@@ -339,7 +339,7 @@ namespace Core {
         /**
          * @throws Exception
          */
-        public function newIntoDB()
+        public static function newIntoDB()
         {
             try {
                 $q = Settings::$DB->prepare(
@@ -347,10 +347,10 @@ namespace Core {
                     'VALUES (:hash, :orig, :name, :size, :date, :ip)'
                 );
                 $q->bindValue(':hash', Upload::$SHA1, PDO::PARAM_STR);
-                $q->bindValue(':orig', strip_tags(Upload::$FILE_NAME), PDO::PARAM_STR);
+                $q->bindValue(':orig', Upload::$FILE_NAME, PDO::PARAM_STR);
                 $q->bindValue(':name', Upload::$NEW_NAME_FULL, PDO::PARAM_STR);
                 $q->bindValue(':size', Upload::$FILE_SIZE, PDO::PARAM_INT);
-                $q->bindValue(':date', time(), PDO::PARAM_STR);
+                $q->bindValue(':date', time(), PDO::PARAM_INT);
                 $q->bindValue(':ip', Upload::$IP, PDO::PARAM_STR);
                 $q->execute();
             } catch (Exception) {
@@ -361,4 +361,3 @@ namespace Core {
 }
 
 
-