diff --git a/core/Api/ApiKeyAPI.class.php b/core/Api/ApiKeyAPI.class.php
index b0ce080..d4fb59c 100644
--- a/core/Api/ApiKeyAPI.class.php
+++ b/core/Api/ApiKeyAPI.class.php
@@ -44,7 +44,7 @@ namespace Api\ApiKey {
$this->loginRequired = true;
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if(!parent::execute($values)) {
return false;
@@ -81,7 +81,7 @@ namespace Api\ApiKey {
$this->loginRequired = true;
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if(!parent::execute($values)) {
return false;
}
@@ -127,7 +127,7 @@ namespace Api\ApiKey {
$this->loginRequired = true;
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if(!parent::execute($values)) {
return false;
}
@@ -162,7 +162,7 @@ namespace Api\ApiKey {
$this->loginRequired = true;
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if(!parent::execute($values)) {
return false;
}
diff --git a/core/Api/ContactAPI.class.php b/core/Api/ContactAPI.class.php
index cb4a4d7..2021fc2 100644
--- a/core/Api/ContactAPI.class.php
+++ b/core/Api/ContactAPI.class.php
@@ -34,7 +34,7 @@ namespace Api\Contact {
parent::__construct($user, $externalCall, $parameters);
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
diff --git a/core/Api/FileAPI.class.php b/core/Api/FileAPI.class.php
index c63ce26..644c51b 100644
--- a/core/Api/FileAPI.class.php
+++ b/core/Api/FileAPI.class.php
@@ -238,7 +238,7 @@ namespace Api\File {
$this->csrfTokenRequired = false;
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@@ -292,7 +292,7 @@ namespace Api\File {
$this->loginRequired = true;
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@@ -316,7 +316,7 @@ namespace Api\File {
$this->csrfTokenRequired = true;
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@@ -360,7 +360,7 @@ namespace Api\File {
$this->csrfTokenRequired = false;
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@@ -407,7 +407,7 @@ namespace Api\File {
$this->csrfTokenRequired = false;
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@@ -450,7 +450,7 @@ namespace Api\File {
$this->loginRequired = true;
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@@ -482,7 +482,7 @@ namespace Api\File {
));
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@@ -551,7 +551,7 @@ namespace Api\File {
$this->loginRequired = true;
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@@ -653,7 +653,7 @@ namespace Api\File {
$this->csrfTokenRequired = false;
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@@ -826,7 +826,7 @@ namespace Api\File {
$this->csrfTokenRequired = false;
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@@ -891,7 +891,7 @@ namespace Api\File {
$this->csrfTokenRequired = true;
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@@ -946,7 +946,7 @@ namespace Api\File {
$this->csrfTokenRequired = false;
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@@ -1017,7 +1017,7 @@ namespace Api\File {
$this->csrfTokenRequired = false;
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
diff --git a/core/Api/GroupsAPI.class.php b/core/Api/GroupsAPI.class.php
index 3a81581..5b7a5f2 100644
--- a/core/Api/GroupsAPI.class.php
+++ b/core/Api/GroupsAPI.class.php
@@ -54,7 +54,7 @@ namespace Api\Groups {
return $this->success;
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if(!parent::execute($values)) {
return false;
}
@@ -116,7 +116,7 @@ namespace Api\Groups {
));
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@@ -162,7 +162,7 @@ namespace Api\Groups {
));
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
diff --git a/core/Api/LanguageAPI.class.php b/core/Api/LanguageAPI.class.php
index 89d6487..e61165e 100644
--- a/core/Api/LanguageAPI.class.php
+++ b/core/Api/LanguageAPI.class.php
@@ -23,7 +23,7 @@ namespace Api\Language {
parent::__construct($user, $externalCall, array());
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if(!parent::execute($values)) {
return false;
}
@@ -108,7 +108,7 @@ namespace Api\Language {
return $this->success;
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if(!parent::execute($values)) {
return false;
}
diff --git a/core/Api/MailAPI.class.php b/core/Api/MailAPI.class.php
index 13211fa..2dc81ed 100644
--- a/core/Api/MailAPI.class.php
+++ b/core/Api/MailAPI.class.php
@@ -24,7 +24,7 @@ namespace Api\Mail {
));
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@@ -77,7 +77,7 @@ namespace Api\Mail {
return null;
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if(!parent::execute($values)) {
return false;
}
diff --git a/core/Api/NotificationsAPI.class.php b/core/Api/NotificationsAPI.class.php
index 8b12b10..123523b 100644
--- a/core/Api/NotificationsAPI.class.php
+++ b/core/Api/NotificationsAPI.class.php
@@ -107,7 +107,7 @@ namespace Api\Notifications {
return $this->success;
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if(!parent::execute($values)) {
return false;
}
@@ -213,7 +213,7 @@ namespace Api\Notifications {
return $this->success;
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if(!parent::execute($values)) {
return false;
}
@@ -235,7 +235,7 @@ namespace Api\Notifications {
$this->loginRequired = true;
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
diff --git a/core/Api/Parameter/ArrayType.class.php b/core/Api/Parameter/ArrayType.class.php
index 77c89e9..7e0e1ff 100644
--- a/core/Api/Parameter/ArrayType.class.php
+++ b/core/Api/Parameter/ArrayType.class.php
@@ -8,14 +8,22 @@ class ArrayType extends Parameter {
public int $elementType;
public int $canBeOne;
- public function __construct($name, $elementType = Parameter::TYPE_MIXED, $canBeOne=false, $optional = FALSE, $defaultValue = NULL) {
+ /**
+ * ArrayType constructor.
+ * @param string $name the name of the parameter
+ * @param int $elementType element type inside the array, for example, allow only integer values (Parameter::TYPE_INT)
+ * @param bool $canBeOne true, if a single element can be passed inside the request (e.g. array=1 instead of array[]=1). Will be automatically casted to an array
+ * @param bool $optional true if the parameter is optional
+ * @param array|null $defaultValue the default value to use, if the parameter is not given
+ */
+ public function __construct(string $name, int $elementType = Parameter::TYPE_MIXED, bool $canBeOne = false, bool $optional = FALSE, ?array $defaultValue = NULL) {
$this->elementType = $elementType;
$this->elementParameter = new Parameter('', $elementType);
$this->canBeOne = $canBeOne;
parent::__construct($name, Parameter::TYPE_ARRAY, $optional, $defaultValue);
}
- public function parseParam($value) {
+ public function parseParam($value): bool {
if(!is_array($value)) {
if (!$this->canBeOne) {
return false;
@@ -38,12 +46,12 @@ class ArrayType extends Parameter {
return true;
}
- public function getTypeName() {
+ public function getTypeName(): string {
$elementType = $this->elementParameter->getTypeName();
return parent::getTypeName() . "($elementType)";
}
- public function toString() {
+ public function toString(): string {
$typeName = $this->getTypeName();
$str = "$typeName $this->name";
$defaultValue = (is_null($this->value) ? 'NULL' : (is_array($this->value) ? '[' . implode(",", $this->value) . ']' : $this->value));
diff --git a/core/Api/Parameter/Parameter.class.php b/core/Api/Parameter/Parameter.class.php
index f58b749..3212538 100644
--- a/core/Api/Parameter/Parameter.class.php
+++ b/core/Api/Parameter/Parameter.class.php
@@ -26,11 +26,11 @@ class Parameter {
public string $name;
public $value;
- public $optional;
+ public bool $optional;
public int $type;
public string $typeName;
- public function __construct($name, $type, $optional = FALSE, $defaultValue = NULL) {
+ public function __construct(string $name, int $type, bool $optional = FALSE, $defaultValue = NULL) {
$this->name = $name;
$this->optional = $optional;
$this->value = $defaultValue;
@@ -38,11 +38,11 @@ class Parameter {
$this->typeName = $this->getTypeName();
}
- public function getTypeName() {
+ public function getTypeName(): string {
return ($this->type >= 0 && $this->type < count(Parameter::names)) ? Parameter::names[$this->type] : "INVALID";
}
- public function toString() {
+ public function toString(): string {
$typeName = Parameter::names[$this->type];
$str = "$typeName $this->name";
@@ -54,7 +54,7 @@ class Parameter {
return $str;
}
- public static function parseType($value) {
+ public static function parseType($value): int {
if(is_array($value))
return Parameter::TYPE_ARRAY;
else if(is_numeric($value) && intval($value) == $value)
@@ -77,7 +77,7 @@ class Parameter {
return Parameter::TYPE_STRING;
}
- public function parseParam($value) {
+ public function parseParam($value): bool {
switch($this->type) {
case Parameter::TYPE_INT:
if(is_numeric($value) && intval($value) == $value) {
diff --git a/core/Api/Parameter/StringType.class.php b/core/Api/Parameter/StringType.class.php
index dc5bc35..4bca3f0 100644
--- a/core/Api/Parameter/StringType.class.php
+++ b/core/Api/Parameter/StringType.class.php
@@ -5,12 +5,12 @@ namespace Api\Parameter;
class StringType extends Parameter {
public int $maxLength;
- public function __construct($name, $maxLength = -1, $optional = FALSE, $defaultValue = NULL) {
+ public function __construct(string $name, int $maxLength = -1, bool $optional = FALSE, ?string $defaultValue = NULL) {
$this->maxLength = $maxLength;
parent::__construct($name, Parameter::TYPE_STRING, $optional, $defaultValue);
}
- public function parseParam($value) {
+ public function parseParam($value): bool {
if(!is_string($value)) {
return false;
}
@@ -23,12 +23,12 @@ class StringType extends Parameter {
return true;
}
- public function getTypeName() {
+ public function getTypeName(): string {
$maxLength = ($this->maxLength > 0 ? "($this->maxLength)" : "");
return parent::getTypeName() . $maxLength;
}
- public function toString() {
+ public function toString(): string {
$typeName = $this->getTypeName();
$str = "$typeName $this->name";
$defaultValue = (is_null($this->value) ? 'NULL' : $this->value);
diff --git a/core/Api/PatchSQL.class.php b/core/Api/PatchSQL.class.php
index a985a32..3c12800 100644
--- a/core/Api/PatchSQL.class.php
+++ b/core/Api/PatchSQL.class.php
@@ -16,7 +16,7 @@ class PatchSQL extends Request {
$this->csrfTokenRequired = false;
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
diff --git a/core/Api/PermissionAPI.class.php b/core/Api/PermissionAPI.class.php
index 24ad282..dd91f75 100644
--- a/core/Api/PermissionAPI.class.php
+++ b/core/Api/PermissionAPI.class.php
@@ -35,7 +35,7 @@ namespace Api\Permission {
$this->isPublic = false;
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@@ -102,7 +102,7 @@ namespace Api\Permission {
return $this->success;
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@@ -147,7 +147,7 @@ namespace Api\Permission {
));
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
diff --git a/core/Api/Request.class.php b/core/Api/Request.class.php
index 7576df4..6364f95 100644
--- a/core/Api/Request.class.php
+++ b/core/Api/Request.class.php
@@ -41,33 +41,34 @@ class Request {
protected function forbidMethod($method) {
if (($key = array_search($method, $this->allowedMethods)) !== false) {
- unset($this->allowedMethods[$key]);
+ unset($this->allowedMethods[$key]);
}
}
- public function parseParams($values) {
+ public function parseParams($values): bool {
- foreach($this->params as $name => $param) {
+ foreach ($this->params as $name => $param) {
$value = $values[$name] ?? NULL;
$isEmpty = (is_string($value) && strlen($value) === 0) || (is_array($value) && empty($value));
- if(!$param->optional && (is_null($value) || $isEmpty)) {
+ if (!$param->optional && (is_null($value) || $isEmpty)) {
return $this->createError("Missing parameter: $name");
}
- if(!is_null($value) && !$isEmpty) {
- if(!$param->parseParam($value)) {
+ if (!is_null($value) && !$isEmpty) {
+ if (!$param->parseParam($value)) {
$value = print_r($value, true);
return $this->createError("Invalid Type for parameter: $name '$value' (Required: " . $param->getTypeName() . ")");
}
}
}
+
return true;
}
public function parseVariableParams($values) {
- foreach($values as $name => $value) {
- if(isset($this->params[$name])) continue;
+ foreach ($values as $name => $value) {
+ if (isset($this->params[$name])) continue;
$type = Parameter\Parameter::parseType($value);
$param = new Parameter\Parameter($name, $type, true);
$param->parseParam($value);
@@ -75,19 +76,19 @@ class Request {
}
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
$this->params = $this->aDefaultParams;
$this->success = false;
$this->result = array();
$this->lastError = '';
- if($this->user->isLoggedIn()) {
+ if ($this->user->isLoggedIn()) {
$this->result['logoutIn'] = $this->user->getSession()->getExpiresSeconds();
}
- if($this->externalCall) {
+ if ($this->externalCall) {
$values = $_REQUEST;
- if($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_SERVER["CONTENT_TYPE"]) && in_array("application/json", explode(";", $_SERVER["CONTENT_TYPE"]))) {
+ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_SERVER["CONTENT_TYPE"]) && in_array("application/json", explode(";", $_SERVER["CONTENT_TYPE"]))) {
$jsonData = json_decode(file_get_contents('php://input'), true);
if ($jsonData) {
$values = array_merge($values, $jsonData);
@@ -99,34 +100,34 @@ class Request {
}
}
- if($this->isDisabled) {
+ if ($this->isDisabled) {
$this->lastError = "This function is currently disabled.";
return false;
}
- if($this->externalCall && !$this->isPublic) {
+ if ($this->externalCall && !$this->isPublic) {
$this->lastError = 'This function is private.';
header('HTTP 1.1 403 Forbidden');
return false;
}
- if(!in_array($_SERVER['REQUEST_METHOD'], $this->allowedMethods)) {
+ if (!in_array($_SERVER['REQUEST_METHOD'], $this->allowedMethods)) {
$this->lastError = 'This method is not allowed';
header('HTTP 1.1 405 Method Not Allowed');
return false;
}
- if($this->externalCall) {
+ if ($this->externalCall) {
$apiKeyAuthorized = false;
// Logged in or api key authorized?
if ($this->loginRequired) {
- if(isset($values['api_key']) && $this->apiKeyAllowed) {
+ if (isset($values['api_key']) && $this->apiKeyAllowed) {
$apiKey = $values['api_key'];
$apiKeyAuthorized = $this->user->authorize($apiKey);
}
- if(!$this->user->isLoggedIn() && !$apiKeyAuthorized) {
+ if (!$this->user->isLoggedIn() && !$apiKeyAuthorized) {
$this->lastError = 'You are not logged in.';
header('HTTP 1.1 401 Unauthorized');
return false;
@@ -134,7 +135,7 @@ class Request {
}
// CSRF Token
- if($this->csrfTokenRequired && $this->user->isLoggedIn()) {
+ if ($this->csrfTokenRequired && $this->user->isLoggedIn()) {
// csrf token required + external call
// if it's not a call with API_KEY, check for csrf_token
if (!isset($values["csrf_token"]) || strcmp($values["csrf_token"], $this->user->getSession()->getCsrfToken()) !== 0) {
@@ -155,13 +156,15 @@ class Request {
}
}
- if(!$this->parseParams($values))
+ if (!$this->parseParams($values)) {
return false;
+ }
- if($this->variableParamCount)
+ if ($this->variableParamCount) {
$this->parseVariableParams($values);
+ }
- if(!$this->user->getSQL()->isConnected()) {
+ if (!$this->user->getSQL()->isConnected()) {
$this->lastError = $this->user->getSQL()->getLastError();
return false;
}
@@ -171,23 +174,39 @@ class Request {
return true;
}
- protected function createError($err) {
+ protected function createError($err): bool {
$this->success = false;
$this->lastError = $err;
return false;
}
protected function getParam($name) {
- return isset($this->params[$name]) ? $this->params[$name]->value : NULL;
+ return $this->params[$name] ?? NULL;
}
- public function isPublic() { return $this->isPublic; }
- public function getLastError() { return $this->lastError; }
- public function getResult() { return $this->result; }
- public function success() { return $this->success; }
- public function loginRequired() { return $this->loginRequired; }
- public function isExternalCall() { return $this->externalCall; }
- public function clearError() { $this->success = true; $this->lastError = ""; }
+ public function isPublic(): bool {
+ return $this->isPublic;
+ }
+
+ public function getLastError(): string {
+ return $this->lastError;
+ }
+
+ public function getResult(): array {
+ return $this->result;
+ }
+
+ public function success(): bool {
+ return $this->success;
+ }
+
+ public function loginRequired(): bool {
+ return $this->loginRequired;
+ }
+
+ public function isExternalCall(): bool {
+ return $this->externalCall;
+ }
private function getMethod() {
$class = str_replace("\\", "/", get_class($this));
@@ -195,7 +214,7 @@ class Request {
return $class;
}
- public function getJsonResult() {
+ public function getJsonResult(): string {
$this->result['success'] = $this->success;
$this->result['msg'] = $this->lastError;
return json_encode($this->result);
diff --git a/core/Api/RoutesAPI.class.php b/core/Api/RoutesAPI.class.php
index ef4c0a2..3247d42 100644
--- a/core/Api/RoutesAPI.class.php
+++ b/core/Api/RoutesAPI.class.php
@@ -34,7 +34,7 @@ namespace Api\Routes {
parent::__construct($user, $externalCall, array());
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if(!parent::execute($values)) {
return false;
}
@@ -81,7 +81,7 @@ namespace Api\Routes {
$this->isPublic = false;
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if(!parent::execute($values)) {
return false;
}
@@ -133,7 +133,7 @@ namespace Api\Routes {
));
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if(!parent::execute($values)) {
return false;
}
diff --git a/core/Api/SettingsAPI.class.php b/core/Api/SettingsAPI.class.php
index cecb991..9ddf4c3 100644
--- a/core/Api/SettingsAPI.class.php
+++ b/core/Api/SettingsAPI.class.php
@@ -29,7 +29,7 @@ namespace Api\Settings {
));
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if(!parent::execute($values)) {
return false;
}
@@ -72,7 +72,7 @@ namespace Api\Settings {
));
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
diff --git a/core/Api/Stats.class.php b/core/Api/Stats.class.php
index 3844943..8bb1cb7 100644
--- a/core/Api/Stats.class.php
+++ b/core/Api/Stats.class.php
@@ -66,7 +66,7 @@ class Stats extends Request {
return ($this->success ? $res[0]["count"] : $this->success);
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if(!parent::execute($values)) {
return false;
}
diff --git a/core/Api/UserAPI.class.php b/core/Api/UserAPI.class.php
index a759fb9..8083657 100644
--- a/core/Api/UserAPI.class.php
+++ b/core/Api/UserAPI.class.php
@@ -9,11 +9,11 @@ namespace Api {
protected function userExists(?string $username, ?string $email) {
$conditions = array();
- if (!is_null($username) && !empty($username)) {
+ if ($username) {
$conditions[] = new Compare("User.name", $username);
}
- if (!is_null($email) && !empty($email)) {
+ if ($email) {
$conditions[] = new Compare("User.email", $email);
}
@@ -152,7 +152,7 @@ namespace Api\User {
$this->loginRequired = true;
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@@ -229,7 +229,7 @@ namespace Api\User {
return false;
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@@ -306,7 +306,7 @@ namespace Api\User {
));
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@@ -350,7 +350,7 @@ namespace Api\User {
$this->csrfTokenRequired = false;
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@@ -377,7 +377,7 @@ namespace Api\User {
$this->loginRequired = true;
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@@ -469,7 +469,7 @@ namespace Api\User {
return $this->success;
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@@ -533,7 +533,7 @@ namespace Api\User {
return $this->success;
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@@ -586,7 +586,7 @@ namespace Api\User {
return $this->createError(L('Wrong username or password'));
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@@ -648,7 +648,7 @@ namespace Api\User {
$this->apiKeyAllowed = false;
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@@ -693,7 +693,7 @@ namespace Api\User {
return $this->success;
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@@ -804,7 +804,7 @@ namespace Api\User {
return array();
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@@ -847,7 +847,7 @@ namespace Api\User {
$this->loginRequired = true;
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@@ -945,7 +945,7 @@ namespace Api\User {
$this->loginRequired = true;
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@@ -986,7 +986,7 @@ namespace Api\User {
$this->csrfTokenRequired = false;
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@@ -1105,7 +1105,7 @@ namespace Api\User {
return $this->success;
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
diff --git a/core/Api/VerifyCaptcha.class.php b/core/Api/VerifyCaptcha.class.php
index 2e41c22..51ae427 100644
--- a/core/Api/VerifyCaptcha.class.php
+++ b/core/Api/VerifyCaptcha.class.php
@@ -16,7 +16,7 @@ class VerifyCaptcha extends Request {
$this->isPublic = false;
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if(!parent::execute($values)) {
return false;
}
diff --git a/core/Api/VisitorsAPI.class.php b/core/Api/VisitorsAPI.class.php
index 97f46b1..7614d6f 100644
--- a/core/Api/VisitorsAPI.class.php
+++ b/core/Api/VisitorsAPI.class.php
@@ -27,7 +27,7 @@ namespace Api\Visitors {
$this->isPublic = false;
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
@@ -75,7 +75,7 @@ namespace Api\Visitors {
}
}
- public function execute($values = array()) {
+ public function execute($values = array()): bool {
if (!parent::execute($values)) {
return false;
}
diff --git a/core/Configuration/Configuration.class.php b/core/Configuration/Configuration.class.php
index 6230d75..4763720 100755
--- a/core/Configuration/Configuration.class.php
+++ b/core/Configuration/Configuration.class.php
@@ -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(
"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);
}
diff --git a/core/Configuration/CreateDatabase.class.php b/core/Configuration/CreateDatabase.class.php
index 6567751..5de3e77 100755
--- a/core/Configuration/CreateDatabase.class.php
+++ b/core/Configuration/CreateDatabase.class.php
@@ -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}},
" .
"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}},
" .
"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}},
" .
"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:
" .
@@ -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;
}
}
}
diff --git a/core/Configuration/Patch/file_api.class.php b/core/Configuration/Patch/file_api.class.php
index 506fdea..2a09cd5 100644
--- a/core/Configuration/Patch/file_api.class.php
+++ b/core/Configuration/Patch/file_api.class.php
@@ -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();
diff --git a/core/Configuration/Settings.class.php b/core/Configuration/Settings.class.php
index 27904a5..7a981aa 100644
--- a/core/Configuration/Settings.class.php
+++ b/core/Configuration/Settings.class.php
@@ -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;
}
}
\ No newline at end of file
diff --git a/core/Documents/Account.class.php b/core/Documents/Account.class.php
index 8b811a6..27c6843 100644
--- a/core/Documents/Account.class.php
+++ b/core/Documents/Account.class.php
@@ -34,7 +34,7 @@ namespace Documents\Account {
$this->loadFontawesome();
}
- protected function initMetas() {
+ protected function initMetas(): array {
return array(
array('name' => 'viewport', 'content' => 'width=device-width, initial-scale=1.0'),
array('name' => 'format-detection', 'content' => 'telephone=yes'),
@@ -44,11 +44,11 @@ namespace Documents\Account {
);
}
- protected function initRawFields() {
+ protected function initRawFields(): array {
return array();
}
- protected function initTitle() {
+ protected function initTitle(): string {
return "Account";
}
}
@@ -59,7 +59,7 @@ namespace Documents\Account {
parent::__construct($document);
}
- protected function getContent() {
+ protected function getContent(): string {
$view = $this->getDocument()->getView();
if ($view === null) {
diff --git a/core/Documents/Admin.class.php b/core/Documents/Admin.class.php
index 662e0da..8056640 100644
--- a/core/Documents/Admin.class.php
+++ b/core/Documents/Admin.class.php
@@ -19,8 +19,6 @@ namespace Documents {
namespace Documents\Admin {
use Elements\Head;
- use Elements\Link;
- use Elements\Script;
class AdminHead extends Head {
@@ -32,7 +30,7 @@ namespace Documents\Admin {
$this->loadFontawesome();
}
- protected function initMetas() {
+ protected function initMetas(): array {
return array(
array('name' => 'viewport', 'content' => 'width=device-width, initial-scale=1.0'),
array('name' => 'format-detection', 'content' => 'telephone=yes'),
@@ -42,12 +40,12 @@ namespace Documents\Admin {
);
}
- protected function initRawFields() {
+ protected function initRawFields(): array {
return array();
}
- protected function initTitle() {
- return "WebBase - Administration";
+ protected function initTitle(): string {
+ return $this->getSiteName() . " - Administration";
}
}
}
\ No newline at end of file
diff --git a/core/Documents/Document404.class.php b/core/Documents/Document404.class.php
index fa97af3..376039b 100644
--- a/core/Documents/Document404.class.php
+++ b/core/Documents/Document404.class.php
@@ -15,7 +15,6 @@ namespace Documents {
namespace Documents\Document404 {
- use Elements\Body;
use Elements\Head;
use Elements\SimpleBody;
use Views\View404;
@@ -29,7 +28,7 @@ namespace Documents\Document404 {
protected function initSources() {
}
- protected function initMetas() {
+ protected function initMetas(): array {
return array(
array('name' => 'viewport', 'content' => 'width=device-width, initial-scale=1.0'),
array('name' => 'format-detection', 'content' => 'telephone=yes'),
@@ -39,11 +38,11 @@ namespace Documents\Document404 {
);
}
- protected function initRawFields() {
+ protected function initRawFields(): array {
return array();
}
- protected function initTitle() {
+ protected function initTitle(): string {
return "WebBase - Not Found";
}
}
@@ -58,7 +57,7 @@ namespace Documents\Document404 {
http_response_code(404);
}
- protected function getContent() {
+ protected function getContent(): string {
return $this->load(View404::class);
}
}
diff --git a/core/Documents/Files.class.php b/core/Documents/Files.class.php
index 7927b0d..37db052 100644
--- a/core/Documents/Files.class.php
+++ b/core/Documents/Files.class.php
@@ -28,7 +28,7 @@ namespace Documents\Files {
$this->loadFontawesome();
}
- protected function initMetas() {
+ protected function initMetas(): array {
return array(
array('name' => 'viewport', 'content' => 'width=device-width, initial-scale=1.0'),
array('name' => 'format-detection', 'content' => 'telephone=yes'),
@@ -39,11 +39,11 @@ namespace Documents\Files {
);
}
- protected function initRawFields() {
+ protected function initRawFields(): array {
return array();
}
- protected function initTitle() {
+ protected function initTitle(): string {
return "File Control Panel";
}
}
@@ -54,7 +54,7 @@ namespace Documents\Files {
parent::__construct($document);
}
- protected function getContent() {
+ protected function getContent(): string {
$html = "";
$html .= "
$content
"; } - public function createParagraph($title, $id, $content) { + public function createParagraph($title, $id, $content): string { $id = replaceCssSelector($id); $iconId = urlencode("$id-icon"); return " @@ -166,7 +168,7 @@ abstract class View extends StaticView { "; } - protected function createBootstrapTable($data, string $classes="") { + protected function createBootstrapTable($data, string $classes=""): string { $classes = empty($classes) ? "" : " $classes"; $code = "