From: Banana Date: Sun, 14 Aug 2022 09:37:19 +0000 (+0200) Subject: php 8.1 changes and fixes X-Git-Tag: 1.3~11 X-Git-Url: http://91.132.146.200/gitweb/?a=commitdiff_plain;h=5baa3bc3b5414b471b52c14814d3a6c156ce1a06;p=bibliotheca-php.git php 8.1 changes and fixes --- diff --git a/webclient/lib/doomguy.class.php b/webclient/lib/doomguy.class.php index dd6bf4b..ed2d028 100644 --- a/webclient/lib/doomguy.class.php +++ b/webclient/lib/doomguy.class.php @@ -27,28 +27,28 @@ class Doomguy { * * @var mysqli */ - private $_DB; + private mysqli $_DB; /** * if the user is logged in or not * * @var boolean */ - protected $isSignedIn = false; + protected bool $isSignedIn = false; /** * the data from the current user * * @var array */ - protected $userData = false; + protected array $userData = array(); /** * the user ID from user management or default * - * @var integer + * @var string|int */ - protected $userID = 0; + protected string|int $userID = 0; /** * the rights string defined the mysql query ! @@ -56,7 +56,7 @@ class Doomguy { * * @var array */ - protected $_rightsArray = array( + protected array $_rightsArray = array( 'user' => array( 'read' => 'r________', 'write' => 'rw_______', @@ -100,7 +100,7 @@ class Doomguy { * @param string $param * @return bool|mixed */ - public function param(string $param) { + public function param(string $param): mixed { $ret = false; $param = trim($param); @@ -223,7 +223,7 @@ class Doomguy { * @param string $token * @return void */ - public function authByApiToken(string $token) { + public function authByApiToken(string $token): void { if(!empty($token)) { $queryStr = "SELECT `id` FROM `".DB_PREFIX."_user` @@ -250,10 +250,10 @@ class Doomguy { * create the sql string for rights sql * * @param string $mode - * @param bool $tableName + * @param string $tableName * @return string */ - public function getSQLRightsString($mode = "read", $tableName=false): string { + public function getSQLRightsString(string $mode = "read", string $tableName = ''): string { $str = ''; $prefix = ''; @@ -298,7 +298,6 @@ class Doomguy { return false; } - $garbage_timeout = SESSION_LIFETIME + 300; ini_set('session.gc_maxlifetime', $garbage_timeout); # the % rate how often the session.gc is run @@ -343,13 +342,19 @@ class Doomguy { # existing session info $result = $query->fetch_assoc(); - # valide the token + # validate the token $_check = $this->_createToken($result['salt']); if (!empty($_check) && $result['token'] === $_check['token']) { $this->userID = $result['fk_user_id']; - $ret = true; } + else { + error_log("[ERROR] ".__METHOD__." mismatched token."); + if(isset($result['fk_user_id']) && !empty($result['fk_user_id'])) { + $this->userID = $result['fk_user_id']; + } + $this->_destroySession(); + } } } catch (Exception $e) { @@ -396,7 +401,7 @@ class Doomguy { * * @return void */ - protected function _loginActions() { + protected function _loginActions(): void { # clean old sessions on session table $timeframe = date("Y-m-d H:i:s",time()-SESSION_LIFETIME); $queryStr = "DELETE FROM `".DB_PREFIX."_userSession` @@ -415,7 +420,7 @@ class Doomguy { * * @return void */ - protected function _loadUser() { + protected function _loadUser(): void { if(!empty($this->userID)) { $queryStr = "SELECT u.`id`, u.`baseGroupId`,u.`protected`,u.`password`,u.`login`,u.`name`, u.`apiToken`,u.`apiTokenValidDate`, @@ -491,11 +496,11 @@ class Doomguy { * HTTP_ACCEPT_ENCODING, HTTP_VIA * and a salt * - * @param bool $salt - * @return bool|array + * @param string $salt + * @return array */ - protected function _createToken($salt=false) { - $ret = false; + protected function _createToken(string $salt = ''): array { + $ret = array(); $defaultStr = "unknown"; diff --git a/webclient/lib/mancubus.class.php b/webclient/lib/mancubus.class.php index 1fe1d00..9ddb5be 100644 --- a/webclient/lib/mancubus.class.php +++ b/webclient/lib/mancubus.class.php @@ -25,21 +25,21 @@ class Mancubus { * * @var mysqli */ - private $_DB; + private mysqli $_DB; /** * The user object to query with * * @var Doomguy */ - private $_User; + private Doomguy $_User; /** * Currently loaded collection to work with * * @var string Number */ - private $_collectionId; + private string $_collectionId; /** * Options for db queries @@ -50,21 +50,21 @@ class Mancubus { * * @var array */ - private $_queryOptions; + private array $_queryOptions; /** * Store the all the values for an entry from lookup table * * @var array */ - private $_cacheLookupValuesForEntry = array(); + private array $_cacheLookupValuesForEntry = array(); /** * Store entryFields for run time * * @var array */ - private $_cacheEntryFields = array(); + private array $_cacheEntryFields = array(); /** * Mancubus constructor. @@ -84,7 +84,7 @@ class Mancubus { * * @param string $collectionId Number */ - public function setCollection(string $collectionId) { + public function setCollection(string $collectionId): void { if(!empty($collectionId)) { $this->_collectionId = $collectionId; } @@ -101,7 +101,7 @@ class Mancubus { * * @param array $options */ - public function setQueryOptions(array $options) { + public function setQueryOptions(array $options): void { if(!isset($options['limit'])) $options['limit'] = 5; if(!isset($options['offset'])) $options['offset'] = false; @@ -119,7 +119,7 @@ class Mancubus { * @param string $search Search string to search for * @return array */ - public function getLatest(string $selections, string $entries, $search=''): array { + public function getLatest(string $selections, string $entries, string $search = ''): array { $ret = array(); $queryStr = "SELECT `c`.`id`, `c`.`name`, `c`.`description`, `c`.`created`, @@ -192,7 +192,7 @@ class Mancubus { * @param array $searchData * @return array */ - public function getEntries($searchData=array()): array { + public function getEntries(array $searchData = array()): array { $ret = array(); if(!empty($this->_collectionId)) { @@ -304,7 +304,7 @@ class Mancubus { * Retrieve all the data needed to display the entry for given entryId * * @param string $entryId Number - * @return array|mixed + * @return array */ public function getEntry(string $entryId): array { $ret = array(); @@ -568,10 +568,10 @@ class Mancubus { * lookup function for field type upload_multiple * * @param string $entryId Number - * @param string $fieldData + * @param array $fieldData * @return array */ - private function _loadFieldValue_upload_multiple(string $entryId, string $fieldData): array { + private function _loadFieldValue_upload_multiple(string $entryId, array $fieldData): array { $ret = array(); if(!empty($entryId) && !empty($fieldData) && !empty($this->_collectionId)) { @@ -611,7 +611,7 @@ class Mancubus { * * @return void */ - private function _setDefaults() { + private function _setDefaults(): void { // default query options $options['limit'] = 5; $options['offset'] = false;