code cleanup
This commit is contained in:
@@ -15,27 +15,27 @@ class Configuration {
|
||||
|
||||
$class = \Configuration\Database::class;
|
||||
$path = getClassPath($class, true);
|
||||
if(file_exists($path) && is_readable($path)) {
|
||||
if (file_exists($path) && is_readable($path)) {
|
||||
include_once $path;
|
||||
if(class_exists($class)) {
|
||||
if (class_exists($class)) {
|
||||
$this->database = new \Configuration\Database();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getDatabase() : ?ConnectionData {
|
||||
public function getDatabase(): ?ConnectionData {
|
||||
return $this->database;
|
||||
}
|
||||
|
||||
public function getSettings() : Settings {
|
||||
public function getSettings(): Settings {
|
||||
return $this->settings;
|
||||
}
|
||||
|
||||
public function create(string $className, $data) {
|
||||
$path = getClassPath("\\Configuration\\$className");
|
||||
|
||||
if($data) {
|
||||
if(is_string($data)) {
|
||||
if ($data) {
|
||||
if (is_string($data)) {
|
||||
$key = addslashes($data);
|
||||
$code = intendCode(
|
||||
"<?php
|
||||
@@ -50,7 +50,7 @@ class Configuration {
|
||||
|
||||
}", false
|
||||
);
|
||||
} else if($data instanceof ConnectionData) {
|
||||
} else if ($data instanceof ConnectionData) {
|
||||
$superClass = get_class($data);
|
||||
$host = addslashes($data->getHost());
|
||||
$port = intval($data->getPort());
|
||||
@@ -58,7 +58,7 @@ class Configuration {
|
||||
$password = addslashes($data->getPassword());
|
||||
|
||||
$properties = "";
|
||||
foreach($data->getProperties() as $key => $val) {
|
||||
foreach ($data->getProperties() as $key => $val) {
|
||||
$key = addslashes($key);
|
||||
$val = is_string($val) ? "'" . addslashes($val) . "'" : $val;
|
||||
$properties .= "\n\$this->setProperty('$key', $val);";
|
||||
@@ -86,9 +86,9 @@ class Configuration {
|
||||
return @file_put_contents($path, $code);
|
||||
}
|
||||
|
||||
public function delete(string $className) {
|
||||
public function delete(string $className): bool {
|
||||
$path = getClassPath("\\Configuration\\$className");
|
||||
if(file_exists($path)) {
|
||||
if (file_exists($path)) {
|
||||
return unlink($path);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ class CreateDatabase extends DatabaseScript {
|
||||
// NOTE:
|
||||
// explicit serial ids removed due to postgres' serial implementation
|
||||
|
||||
public static function createQueries(SQL $sql) {
|
||||
public static function createQueries(SQL $sql): array {
|
||||
$queries = array();
|
||||
|
||||
// Language
|
||||
@@ -24,8 +24,8 @@ class CreateDatabase extends DatabaseScript {
|
||||
->unique("name");
|
||||
|
||||
$queries[] = $sql->insert("Language", array("code", "name"))
|
||||
->addRow( "en_US", 'American English')
|
||||
->addRow( "de_DE", 'Deutsch Standard');
|
||||
->addRow("en_US", 'American English')
|
||||
->addRow("de_DE", 'Deutsch Standard');
|
||||
|
||||
$queries[] = $sql->createTable("User")
|
||||
->addSerial("uid")
|
||||
@@ -50,7 +50,7 @@ class CreateDatabase extends DatabaseScript {
|
||||
->addString("browser", 64)
|
||||
->addJson("data", false, '{}')
|
||||
->addBool("stay_logged_in", true)
|
||||
->addString("csrf_token", 16 )
|
||||
->addString("csrf_token", 16)
|
||||
->primaryKey("uid", "user_id")
|
||||
->foreignKey("user_id", "User", "uid", new CascadeStrategy());
|
||||
|
||||
@@ -82,7 +82,7 @@ class CreateDatabase extends DatabaseScript {
|
||||
|
||||
$queries[] = $sql->createTable("Notification")
|
||||
->addSerial("uid")
|
||||
->addEnum("type", array("default","message","warning"), false, "default")
|
||||
->addEnum("type", array("default", "message", "warning"), false, "default")
|
||||
->addDateTime("created_at", false, $sql->currentTimestamp())
|
||||
->addString("title", 32)
|
||||
->addString("message", 256)
|
||||
@@ -200,7 +200,7 @@ class CreateDatabase extends DatabaseScript {
|
||||
return $queries;
|
||||
}
|
||||
|
||||
private static function MessageConfirmEmail() : string {
|
||||
private static function MessageConfirmEmail(): string {
|
||||
return "Hello {{username}},<br>" .
|
||||
"You recently created an account on {{site_name}}. Please click on the following link to " .
|
||||
"confirm your email address and complete your registration. If you haven't registered an " .
|
||||
@@ -210,7 +210,7 @@ class CreateDatabase extends DatabaseScript {
|
||||
"{{site_name}} Administration";
|
||||
}
|
||||
|
||||
private static function MessageAcceptInvite() : string {
|
||||
private static function MessageAcceptInvite(): string {
|
||||
return "Hello {{username}},<br>" .
|
||||
"You were invited to create an account on {{site_name}}. Please click on the following link to " .
|
||||
"confirm your email address and complete your registration by choosing a new password. " .
|
||||
@@ -220,7 +220,7 @@ class CreateDatabase extends DatabaseScript {
|
||||
"{{site_name}} Administration";
|
||||
}
|
||||
|
||||
private static function MessageResetPassword() : string {
|
||||
private static function MessageResetPassword(): string {
|
||||
return "Hello {{username}},<br>" .
|
||||
"you requested a password reset on {{site_name}}. Please click on the following link to " .
|
||||
"choose a new password. If this request was not intended, you can simply ignore the email. The Link is valid for one hour:<br><br>" .
|
||||
@@ -233,7 +233,7 @@ class CreateDatabase extends DatabaseScript {
|
||||
$patchDirectory = './core/Configuration/Patch/';
|
||||
if (file_exists($patchDirectory) && is_dir($patchDirectory)) {
|
||||
$scan_arr = scandir($patchDirectory);
|
||||
$files_arr = array_diff($scan_arr, array('.','..'));
|
||||
$files_arr = array_diff($scan_arr, array('.', '..'));
|
||||
foreach ($files_arr as $file) {
|
||||
$suffix = ".class.php";
|
||||
if (endsWith($file, $suffix)) {
|
||||
@@ -241,7 +241,7 @@ class CreateDatabase extends DatabaseScript {
|
||||
$className = "\\Configuration\\Patch\\$className";
|
||||
$method = "$className::createQueries";
|
||||
$patchQueries = call_user_func($method, $sql);
|
||||
foreach($patchQueries as $query) $queries[] = $query;
|
||||
foreach ($patchQueries as $query) $queries[] = $query;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ use Driver\SQL\Strategy\UpdateStrategy;
|
||||
|
||||
class file_api extends DatabaseScript {
|
||||
|
||||
public static function createQueries(SQL $sql) {
|
||||
public static function createQueries(SQL $sql): array {
|
||||
|
||||
$queries = array();
|
||||
|
||||
|
||||
@@ -11,12 +11,16 @@ use Objects\User;
|
||||
|
||||
class Settings {
|
||||
|
||||
//
|
||||
private bool $installationComplete;
|
||||
|
||||
// settings
|
||||
private string $siteName;
|
||||
private string $baseUrl;
|
||||
private string $jwtSecret;
|
||||
private bool $installationComplete;
|
||||
private bool $registrationAllowed;
|
||||
private bool $recaptchaEnabled;
|
||||
private bool $mailEnabled;
|
||||
private string $recaptchaPublicKey;
|
||||
private string $recaptchaPrivateKey;
|
||||
|
||||
@@ -24,11 +28,11 @@ class Settings {
|
||||
return $this->jwtSecret;
|
||||
}
|
||||
|
||||
public function isInstalled() {
|
||||
public function isInstalled(): bool {
|
||||
return $this->installationComplete;
|
||||
}
|
||||
|
||||
public static function loadDefaults() : Settings {
|
||||
public static function loadDefaults(): Settings {
|
||||
$hostname = $_SERVER["SERVER_NAME"];
|
||||
$protocol = getProtocol();
|
||||
$jwt = generateRandomString(32);
|
||||
@@ -42,10 +46,11 @@ class Settings {
|
||||
$settings->recaptchaPublicKey = "";
|
||||
$settings->recaptchaPrivateKey = "";
|
||||
$settings->recaptchaEnabled = false;
|
||||
$settings->mailEnabled = false;
|
||||
return $settings;
|
||||
}
|
||||
|
||||
public function loadFromDatabase(User $user) {
|
||||
public function loadFromDatabase(User $user): bool {
|
||||
$req = new \Api\Settings\Get($user);
|
||||
$success = $req->execute();
|
||||
|
||||
@@ -58,6 +63,7 @@ class Settings {
|
||||
$this->recaptchaEnabled = $result["recaptcha_enabled"] ?? $this->recaptchaEnabled;
|
||||
$this->recaptchaPublicKey = $result["recaptcha_public_key"] ?? $this->recaptchaPublicKey;
|
||||
$this->recaptchaPrivateKey = $result["recaptcha_private_key"] ?? $this->recaptchaPrivateKey;
|
||||
$this->mailEnabled = $result["mail_enabled"] ?? $this->mailEnabled;
|
||||
|
||||
if (!isset($result["jwt_secret"])) {
|
||||
$req = new \Api\Settings\Set($user);
|
||||
@@ -81,27 +87,27 @@ class Settings {
|
||||
->addRow("recaptcha_private_key", $this->recaptchaPrivateKey, true, false);
|
||||
}
|
||||
|
||||
public function getSiteName() : string {
|
||||
public function getSiteName(): string {
|
||||
return $this->siteName;
|
||||
}
|
||||
|
||||
public function getBaseUrl() : string {
|
||||
public function getBaseUrl(): string {
|
||||
return $this->baseUrl;
|
||||
}
|
||||
|
||||
public function isRecaptchaEnabled() : bool {
|
||||
public function isRecaptchaEnabled(): bool {
|
||||
return $this->recaptchaEnabled;
|
||||
}
|
||||
|
||||
public function getRecaptchaSiteKey() : string {
|
||||
public function getRecaptchaSiteKey(): string {
|
||||
return $this->recaptchaPublicKey;
|
||||
}
|
||||
|
||||
public function getRecaptchaSecretKey() : string {
|
||||
public function getRecaptchaSecretKey(): string {
|
||||
return $this->recaptchaPrivateKey;
|
||||
}
|
||||
|
||||
public function isRegistrationAllowed() : bool {
|
||||
public function isRegistrationAllowed(): bool {
|
||||
return $this->registrationAllowed;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user