diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index c946212..6a30319 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -20,7 +20,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} - extensions: mbstring, openssl + extensions: mbstring, openssl, imagick coverage: none - name: Get Composer cache directory diff --git a/PHPUtils/Crypto.php b/PHPUtils/Crypto.php index 7f0dd0c..453abcd 100755 --- a/PHPUtils/Crypto.php +++ b/PHPUtils/Crypto.php @@ -41,7 +41,7 @@ public function genIV(string $method): string { public function encryptwithpw(string $str, string $password, string $method = 'aes-256-cbc', bool $iv = false): string { if ($iv) { $ivRaw = hex2bin($this->genIV($method)); - $encrypted = openssl_encrypt($str, $method, $password, iv: $ivRaw); + $encrypted = openssl_encrypt($str, $method, $password, OPENSSL_RAW_DATA, $ivRaw); return base64_encode($ivRaw . $encrypted); } return openssl_encrypt($str, $method, $password); @@ -63,13 +63,13 @@ public function decryptwithpw(string $str, string $password, string $method = 'a if ($iv !== '') { $ivRaw = hex2bin($iv); $ciphertext = base64_decode($str, true) ?: $str; - return openssl_decrypt($ciphertext, $method, $password, iv: $ivRaw); + return openssl_decrypt($ciphertext, $method, $password, OPENSSL_RAW_DATA, $ivRaw); } $decoded = base64_decode($str, true); if ($decoded !== false && strlen($decoded) > $ivLen) { $ivRaw = substr($decoded, 0, $ivLen); $ciphertext = substr($decoded, $ivLen); - return openssl_decrypt($ciphertext, $method, $password, iv: $ivRaw); + return openssl_decrypt($ciphertext, $method, $password, OPENSSL_RAW_DATA, $ivRaw); } return openssl_decrypt($str, $method, $password); } diff --git a/PHPUtils/SQLite.php b/PHPUtils/SQLite.php index 49a0534..c163fb6 100755 --- a/PHPUtils/SQLite.php +++ b/PHPUtils/SQLite.php @@ -113,7 +113,7 @@ public function sqlite_get_tables(\SQLite3 $db) : array { $tables[] = $row['name']; } return $this->res("SUCCESS", $tables); - } catch (Exception $e) { + } catch (\Exception $e) { return $this->res("ERROR", $e->getMessage()); } } @@ -130,7 +130,7 @@ public function sqlite_get_tables(\SQLite3 $db) : array { */ public function sqlite_create_table(\SQLite3 $db, string $table_name, array $columns = ["column_name" => "column_type"]) : array { try { - if (sqlite_table_exists($db, $table_name)) { + if ($this->sqlite_table_exists($db, $table_name)) { return $this->res("ERROR", "Table $table_name already exists."); } $query = 'CREATE TABLE IF NOT EXISTS "'.$table_name.'" ( @@ -142,7 +142,7 @@ public function sqlite_create_table(\SQLite3 $db, string $table_name, array $col $query = rtrim($query, ', '); $query .= ');'; return $this->res("SUCCESS", $db->query($query)); - } catch (Exception $e) { + } catch (\Exception $e) { return $this->res("ERROR", $e->getMessage()); } } @@ -158,7 +158,7 @@ public function sqlite_drop_table(\SQLite3 $db, string $table_name) : array { try { $query = 'DROP TABLE IF EXISTS "'.$table_name.'";'; return $this->res("SUCCESS", $db->query($query)); - } catch (Exception $e) { + } catch (\Exception $e) { return $this->res("ERROR", $e->getMessage()); } } @@ -174,7 +174,7 @@ public function sqlite_empty_table(\SQLite3 $db, string $table_name) : array { try { $query = 'DELETE FROM "'.$table_name.'";'; return $this->res("SUCCESS", $db->query($query)); - } catch (Exception $e) { + } catch (\Exception $e) { return $this->res("ERROR", $e->getMessage()); } } @@ -193,7 +193,7 @@ public function sqlite_table_exists(\SQLite3 $db, string $table_name) : array { $query = 'SELECT name FROM sqlite_master WHERE type="table" AND name="'.$table_name.'";'; $result = $db->querySingle($query); return $this->res("SUCCESS", ($result === $table_name)); - } catch (Exception $e) { + } catch (\Exception $e) { return $this->res("ERROR", $e->getMessage()); } } @@ -219,7 +219,7 @@ public function sqlite_get_columns(\SQLite3 $db, string $table_name) : array { ]; } return $this->res("SUCCESS", $columns); - } catch (Exception $e) { + } catch (\Exception $e) { return $this->res("ERROR", $e->getMessage()); } } @@ -243,7 +243,7 @@ public function sqlite_query(?\SQLite3 $db, $query) : array { return $this->res("ERROR", $db->lastErrorMsg()); } return $this->res("SUCCESS", $query); - } catch (Exception $e) { + } catch (\Exception $e) { return $this->res("ERROR", $e->getMessage()); } } @@ -277,7 +277,7 @@ public function sqlite_insert(\SQLite3 $db, string $table, array $data) : array return $this->res("ERROR", $db->lastErrorMsg()); } return $this->res("SUCCESS", $insert); - } catch (Exception $e) { + } catch (\Exception $e) { return $this->res("ERROR", $e->getMessage()); } } @@ -296,7 +296,7 @@ public function sqlite_insert(\SQLite3 $db, string $table, array $data) : array */ public function sqlite_select(\SQLite3 $db, string $table, array $columns = ["*"], string $where = "", array $params = [], string $order = "", string $limit = "") : array { try { - if (!sqlite_table_exists($db, $table)) { + if (!$this->sqlite_table_exists($db, $table)) { return $this->res("ERROR", "Table $table does not exist."); } $columns = implode(', ', $columns); @@ -324,7 +324,7 @@ public function sqlite_select(\SQLite3 $db, string $table, array $columns = ["*" return $this->res("ERROR", "No columns returned."); } return $this->res("SUCCESS", $result); - } catch (Exception $e) { + } catch (\Exception $e) { return $this->res("ERROR", $e->getMessage()); } } @@ -365,7 +365,7 @@ public function sqlite_update(\SQLite3 $db, string $table, array $data, string $ $stmt->execute(); return $this->res("SUCCESS", $stmt->changes > 0); - } catch (Exception $e) { + } catch (\Exception $e) { return $this->res("ERROR", $e->getMessage()); } } @@ -394,7 +394,7 @@ public function sqlite_delete(\SQLite3 $db, string $table, string $where, array $stmt->execute(); return $this->res("SUCCESS", $stmt->changes > 0); - } catch (Exception $e) { + } catch (\Exception $e) { return $this->res("ERROR", $e->getMessage()); } } @@ -425,20 +425,7 @@ public function sqlite_function($func_name, ...$params) : array { } $call = call_user_func($func_name, ...$params); return $this->res($call["status"], $call["data"]); - $call_status = $call["status"]; - $call_data = $call["data"]; - if (is_string($call_data)) { - $call_data = clean($call_data); - } - if ($call_status == "ERROR") { - return $this->res("ERROR", $call_data); - } - if ($call_data["status"] == "ERROR") { - return $this->res("ERROR", $call_data); - } - return $this->res($call_status, $call_data); - - } catch (Exception $e) { + } catch (\Exception $e) { return $this->res("ERROR", $e->getMessage()); } } diff --git a/PHPUtils/Times.php b/PHPUtils/Times.php index bf9d9d0..7af30c7 100755 --- a/PHPUtils/Times.php +++ b/PHPUtils/Times.php @@ -42,9 +42,9 @@ public function getCurrentTime(string $format, string $timezone): string { * @return string The relative time */ public function relativeTime($time, $format = null) { - $now = new \DateTime('now'); - $then = new \DateTime($time); - $diff = $now->diff($then); + $currentTime = new \DateTime('now'); + $inputTime = new \DateTime($time); + $diff = $currentTime->diff($inputTime); # Translate the format $formats = [