From 3232f3a2909ffdf024285ceeec84df60d0717997 Mon Sep 17 00:00:00 2001 From: Banana Date: Sat, 9 Oct 2021 10:23:03 +0200 Subject: [PATCH] php 7 syntax --- CHANGELOG | 1 + TODO | 1 - webclient/lib/doomguy.class.php | 30 +-- webclient/lib/gorenest.class.php | 8 +- .../lib/managecollectionfields.class.php | 15 +- webclient/lib/managecollections.class.php | 20 +- webclient/lib/manageentry.class.php | 48 ++--- webclient/lib/managetags.class.php | 10 +- webclient/lib/mancubus.class.php | 24 +-- webclient/lib/possessed.class.php | 32 +-- webclient/lib/spectre.class.php | 10 +- webclient/lib/summoner.class.php | 182 +++--------------- 12 files changed, 123 insertions(+), 258 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 41abb56..00db1ea 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,6 +3,7 @@ * New field: artists - lookupmultiple field * Added setup process. See setup/install.txt for more details * Stats info page + * Some more PHP 7 syntax 1.2 - NyLeve's Falls 20210717 * Updated requirements information diff --git a/TODO b/TODO index fc3c759..d379cae 100644 --- a/TODO +++ b/TODO @@ -10,4 +10,3 @@ * Field management: Web interface * minimal theme * Automatic upgrade from DB changes -* PHP 7 syntax and specifications diff --git a/webclient/lib/doomguy.class.php b/webclient/lib/doomguy.class.php index 3943281..dd6bf4b 100644 --- a/webclient/lib/doomguy.class.php +++ b/webclient/lib/doomguy.class.php @@ -2,7 +2,7 @@ /** * Bibliotheca * - * Copyright 2018-2020 Johannes Keßler + * Copyright 2018-2021 Johannes Keßler * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -78,8 +78,9 @@ class Doomguy { * Doomguy constructor. * * @param mysqli $db The database object + * @return void */ - public function __construct($db) { + public function __construct(mysqli $db) { $this->_DB = $db; if($this->_checkSession() === true) { @@ -99,7 +100,7 @@ class Doomguy { * @param string $param * @return bool|mixed */ - public function param($param) { + public function param(string $param) { $ret = false; $param = trim($param); @@ -114,9 +115,9 @@ class Doomguy { /** * Get the currently loaded user data info from $this->userData * - * @return array|bool + * @return array */ - public function getAllUserData() { + public function getAllUserData(): array { return $this->userData; } @@ -125,7 +126,7 @@ class Doomguy { * * @return bool */ - public function isSignedIn() { + public function isSignedIn(): bool { return $this->isSignedIn; } @@ -134,7 +135,7 @@ class Doomguy { * * @return boolean */ - public function logOut () { + public function logOut (): bool { $ret = false; if($this->_checkAgainstSessionTable() === true) { @@ -152,7 +153,7 @@ class Doomguy { * @param integer $groupID * @return bool */ - public function isInGroup($groupID) { + public function isInGroup(int $groupID): bool { $ret = false; if($this->userData['isRoot'] === true) { @@ -172,7 +173,7 @@ class Doomguy { * @param string $password * @return boolean */ - public function authenticate($username,$password) { + public function authenticate(string $username, string $password): bool { $ret = false; if(!empty($username) && !empty($password)) { @@ -220,8 +221,9 @@ class Doomguy { * Use the user identified by apitoken * * @param string $token + * @return void */ - public function authByApiToken($token) { + public function authByApiToken(string $token) { if(!empty($token)) { $queryStr = "SELECT `id` FROM `".DB_PREFIX."_user` @@ -287,7 +289,7 @@ class Doomguy { * * @return bool */ - protected function _checkSession() { + protected function _checkSession(): bool { if(ini_set('session.use_only_cookies',true) === false || ini_set('session.cookie_httponly',true) === false || @@ -323,7 +325,7 @@ class Doomguy { * * @return bool */ - protected function _checkAgainstSessionTable() { + protected function _checkAgainstSessionTable(): bool { $ret = false; $timeframe = date("Y-m-d H:i:s",time()-SESSION_LIFETIME); @@ -364,7 +366,7 @@ class Doomguy { * @param string $u * @return bool */ - protected function _checkAgainstUserTable($u) { + protected function _checkAgainstUserTable(string $u): bool { $ret = false; if(!empty($u)) { @@ -463,7 +465,7 @@ class Doomguy { * * @return bool */ - protected function _destroySession() { + protected function _destroySession(): bool { $timeframe = date("Y-m-d H:i:s",time()-SESSION_LIFETIME); $queryStr = "DELETE FROM `".DB_PREFIX."_userSession` WHERE `fk_user_id` = '".$this->_DB->real_escape_string($this->userID)."' diff --git a/webclient/lib/gorenest.class.php b/webclient/lib/gorenest.class.php index 5c14f6c..1f34147 100644 --- a/webclient/lib/gorenest.class.php +++ b/webclient/lib/gorenest.class.php @@ -2,7 +2,7 @@ /** * Bibliotheca * - * Copyright 2018-2020 Johannes Keßler + * Copyright 2018-2021 Johannes Keßler * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -98,16 +98,16 @@ class GoreNest { * @param bool $reload * @return array */ - public function get(string $category, $reload=false) { + public function get(string $category, $reload=false): array { $ret = array(); - if(empty($category)) return false; + if(empty($category)) return array(); if(empty($reload) && isset($this->_menuData[$category])) { return $this->_menuData[$category]; } - $this->loadMenu($reload); + $this->loadMenu(); if(isset($this->_menuData[$category])) { $ret = $this->_menuData[$category]; } diff --git a/webclient/lib/managecollectionfields.class.php b/webclient/lib/managecollectionfields.class.php index 6136778..7110e11 100644 --- a/webclient/lib/managecollectionfields.class.php +++ b/webclient/lib/managecollectionfields.class.php @@ -71,7 +71,7 @@ class ManageCollectionFields { * @param mysqli $databaseConnectionObject * @param Doomguy $userObj */ - public function __construct($databaseConnectionObject, $userObj) { + public function __construct(mysqli $databaseConnectionObject, Doomguy $userObj) { $this->_DB = $databaseConnectionObject; $this->_User = $userObj; } @@ -90,10 +90,11 @@ class ManageCollectionFields { /** * Get available fields based on user * + * @param bool $refresh * @return array * @todo No rights implemented yet. Maybe not needed. Management done by hand directly on DB */ - public function getAvailableFields($refresh=false) { + public function getAvailableFields($refresh=false): array { if($refresh === false && !empty($this->_cacheAvailableFields)) { return $this->_cacheAvailableFields; @@ -125,7 +126,7 @@ class ManageCollectionFields { * @param string $string * @return bool */ - public function validateFieldSortString($string) { + public function validateFieldSortString(string $string): bool { $ret = false; $_t = str_replace(",","",$string); @@ -144,7 +145,7 @@ class ManageCollectionFields { * @param string $fieldsSortString * @return bool */ - public function updateFields($fieldsSortString) { + public function updateFields(string $fieldsSortString): bool { $ret = false; $ids = array(); @@ -250,7 +251,7 @@ class ManageCollectionFields { * @param bool $sortAZ * @return array */ - public function getExistingFields($refresh=false, $sortAZ=false) { + public function getExistingFields($refresh=false, $sortAZ=false): array { if($refresh === false && !empty($this->_cacheExistingSysFields)) { return $this->_cacheExistingSysFields; } @@ -316,7 +317,7 @@ class ManageCollectionFields { * * @return array */ - private function _getExistingCollectionColumns() { + private function _getExistingCollectionColumns(): array { $ret = array(); $queryStr = "SHOW COLUMNS FROM `".DB_PREFIX."_collection_entry_".$this->_collectionId."`"; @@ -345,7 +346,7 @@ class ManageCollectionFields { * @param array $columnIds sort=>fk_field_id * @return array */ - private function _getSQLForCollectionColumns($columnIds) { + private function _getSQLForCollectionColumns(array $columnIds): array { $_fields = array(); // enrich with information $_sysFields = $this->getAvailableFields(); diff --git a/webclient/lib/managecollections.class.php b/webclient/lib/managecollections.class.php index 023c238..05b2055 100644 --- a/webclient/lib/managecollections.class.php +++ b/webclient/lib/managecollections.class.php @@ -82,7 +82,7 @@ class ManageCollections { * * @return array */ - public function getGroupsForSelection() { + public function getGroupsForSelection(): array { $ret = array(); $queryStr = "SELECT `id`, `name`, `description` @@ -110,7 +110,7 @@ class ManageCollections { * * @return array */ - public function getUsersForSelection() { + public function getUsersForSelection(): array { $ret = array(); $queryStr = "SELECT `id`, `name`, `login` @@ -137,7 +137,7 @@ class ManageCollections { * * @return array */ - public function getToolsForSelection() { + public function getToolsForSelection(): array { $ret = array(); $queryStr = "SELECT `id`, `name`, `description` @@ -355,7 +355,7 @@ class ManageCollections { * @param string $id Number * @return bool */ - public function deleteCollection($id) { + public function deleteCollection(string $id): bool { $ret = false; if(!empty($id) && Summoner::validate($id, 'digit')) { @@ -409,7 +409,7 @@ class ManageCollections { * @param string $id Number * @return array */ - public function getAvailableTools($id) { + public function getAvailableTools(string $id): array { $ret = array(); $queryStr = "SELECT `t`.`id`, `t`.`name`, `t`.`description`, `t`.`action`, `t`.`target` @@ -438,7 +438,7 @@ class ManageCollections { * @param string $name * @return bool */ - private function _validNewCollectionName($name) { + private function _validNewCollectionName(string $name): bool { $ret = false; if (Summoner::validate($name, 'nospace')) { $queryStr = "SELECT `id` FROM `".DB_PREFIX."_collection` @@ -465,7 +465,7 @@ class ManageCollections { * @param string $id Number * @return bool */ - private function _validUpdateCollectionName($name, $id) { + private function _validUpdateCollectionName(string $name, string $id): bool { $ret = false; if (Summoner::validate($name, 'nospace') @@ -496,7 +496,7 @@ class ManageCollections { * @param array $tool * @return bool */ - private function _updateToolRelation($id,$tool) { + private function _updateToolRelation(string $id, array $tool): bool { $ret = false; @@ -538,7 +538,7 @@ class ManageCollections { * @param string|bool $group * @param string|bool $rights */ - private function _updateEntryRights($collectionId, $owner=false, $group=false, $rights=false) { + private function _updateEntryRights(string $collectionId, $owner=false, $group=false, $rights=false) { if(!empty($collectionId)) { $queryStr = "UPDATE `".DB_PREFIX."_collection_entry_".$collectionId."` SET"; @@ -569,7 +569,7 @@ class ManageCollections { * @param array $data * @return array */ - private function _loadAdvancedSearchTableFields($data) { + private function _loadAdvancedSearchTableFields(array $data): array { $ret = array(); $_t = explode(',',$data); diff --git a/webclient/lib/manageentry.class.php b/webclient/lib/manageentry.class.php index c49426a..a3e8aed 100644 --- a/webclient/lib/manageentry.class.php +++ b/webclient/lib/manageentry.class.php @@ -58,7 +58,7 @@ class Manageentry { * @param mysqli $databaseConnectionObject * @param Doomguy $userObj */ - public function __construct($databaseConnectionObject, $userObj) { + public function __construct(mysqli $databaseConnectionObject, Doomguy $userObj) { $this->_DB = $databaseConnectionObject; $this->_User = $userObj; } @@ -68,7 +68,7 @@ class Manageentry { * * @param string $collectionId Number */ - public function setCollection($collectionId) { + public function setCollection(string $collectionId) { if(!empty($collectionId)) { $this->_collectionId = $collectionId; } @@ -81,7 +81,7 @@ class Manageentry { * @param bool $refresh * @return array */ - public function getEditFields($refresh=false) { + public function getEditFields($refresh=false): array { if($refresh === false && !empty($this->_cacheEditFields)) { return $this->_cacheEditFields; @@ -260,7 +260,7 @@ class Manageentry { * @param string $entryId Number * @return bool */ - public function delete($entryId) { + public function delete(string $entryId): bool { $ret = false; if(!empty($entryId) && !empty($this->_collectionId)) { @@ -347,7 +347,7 @@ class Manageentry { * @param string $entryId Number * @return bool */ - private function _canDelete($entryId) { + private function _canDelete(string $entryId): bool { $ret = false; if(!empty($entryId) && !empty($this->_collectionId)) { @@ -382,7 +382,7 @@ class Manageentry { * @param array $entryFields * @return array */ - private function _mergeEntryWithFields($entryData, $entryFields) { + private function _mergeEntryWithFields(array $entryData, array $entryFields): array { if(!empty($entryFields)) { foreach($entryFields as $f) { $_mnValue = '_loadFieldValue_'.$f['type']; @@ -399,12 +399,12 @@ class Manageentry { * Load the values for given $entryId for $fieldData * lookup function for field type lookupmultiple * - * @see Mancubus * @param string $entryId Number * @param array $fieldData * @return array + * @see Mancubus */ - private function _loadFieldValue_lookupmultiple($entryId, $fieldData) { + private function _loadFieldValue_lookupmultiple(string $entryId, array $fieldData): array { $ret = array(); if(!empty($entryId) && !empty($fieldData) && !empty($this->_collectionId)) { @@ -433,12 +433,12 @@ class Manageentry { * Get the single upload file from storage location * lookup function for field type upload * - * @see Mancubus * @param string $entryId Number * @param array $fieldData * @return string + * @see Mancubus */ - private function _loadFieldValue_upload($entryId, $fieldData) { + private function _loadFieldValue_upload(string $entryId, array $fieldData): string { $ret = ""; if(!empty($entryId) && !empty($fieldData) && !empty($this->_collectionId)) { @@ -457,12 +457,12 @@ class Manageentry { * Get the multiple upload files from storage location * lookup function for field type upload_multiple * - * @see Mancubus * @param string $entryId Number * @param array $fieldData * @return array + * @see Mancubus */ - private function _loadFieldValue_upload_multiple($entryId, $fieldData) { + private function _loadFieldValue_upload_multiple(string $entryId, array $fieldData): array { $ret = array(); if(!empty($entryId) && !empty($fieldData) && !empty($this->_collectionId)) { @@ -483,7 +483,7 @@ class Manageentry { * @param array $data * @return array */ - private function _loadField_selection($data) { + private function _loadField_selection(array $data): array { if(!empty($data) && isset($data['value']) && !empty($data['value'])) { if(strstr($data['value'], ",")) { $data['options'] = explode(",", $data['value']); @@ -495,10 +495,10 @@ class Manageentry { /** * Load suggestions based on the existing data for this field * - * @param array $data Field data + * @param array $data Field data * @return array */ - private function _loadField_lookupmultiple($data) { + private function _loadField_lookupmultiple(array $data): array { if(!empty($data) && isset($data['id']) && !empty($data['id'])) { $queryStr = "SELECT DISTINCT(`value`) FROM `".DB_PREFIX."_collection_entry2lookup_".$this->_DB->real_escape_string($this->_collectionId)."` @@ -522,11 +522,11 @@ class Manageentry { /** * Create part of the insert statement for field type text * - * @param array $data Field data - * @param array $queryData Query data array + * @param array $data Field data + * @param array $queryData Query data array * @return array */ - private function _saveField_text($data, $queryData) { + private function _saveField_text(array $data, array $queryData): array { $queryData['init'][] = "`".$data['identifier']."` = '".$this->_DB->real_escape_string($data['valueToSave'])."'"; return $queryData; } @@ -538,7 +538,7 @@ class Manageentry { * @param array $queryData Query data array * @return array */ - private function _saveField_text3($data, $queryData) { + private function _saveField_text3(array $data, array $queryData): array { return $this->_saveField_text($data, $queryData); } @@ -549,7 +549,7 @@ class Manageentry { * @param array $queryData Query data array * @return array */ - private function _saveField_textarea($data, $queryData) { + private function _saveField_textarea(array $data, array $queryData): array { return $this->_saveField_text($data, $queryData); } @@ -560,7 +560,7 @@ class Manageentry { * @param array $queryData Query data array * @return array */ - private function _saveField_selection($data, $queryData) { + private function _saveField_selection(array $data, array $queryData): array { return $this->_saveField_text($data, $queryData); } @@ -573,7 +573,7 @@ class Manageentry { * @param array $queryData Query data array * @return array */ - private function _saveField_year($data, $queryData) { + private function _saveField_year(array $data, array $queryData): array { preg_match('/[0-9]{4}/', $data['valueToSave'], $matches); if(isset($matches[0]) && !empty($matches[0])) { $data['valueToSave'] = $matches[0]; @@ -589,7 +589,7 @@ class Manageentry { * @param array $queryData * @return mixed */ - private function _saveField_number($data, $queryData) { + private function _saveField_number(array $data, array $queryData): array { // make sure there is something (int) to save if(empty($data['valueToSave'])) { $data['valueToSave'] = 0; @@ -606,7 +606,7 @@ class Manageentry { * @param array $queryData Query data array * @return array */ - private function _saveField_lookupmultiple($data, $queryData) { + private function _saveField_lookupmultiple(array $data, array $queryData): array { $_d = trim($data['valueToSave']); $_d = trim($_d, ","); diff --git a/webclient/lib/managetags.class.php b/webclient/lib/managetags.class.php index 7aeb07b..3d88d88 100644 --- a/webclient/lib/managetags.class.php +++ b/webclient/lib/managetags.class.php @@ -47,7 +47,7 @@ class ManageTags { * @param mysqli $databaseConnectionObject * @param Doomguy $userObj */ - public function __construct($databaseConnectionObject, $userObj) { + public function __construct(mysqli $databaseConnectionObject, Doomguy $userObj) { $this->_DB = $databaseConnectionObject; $this->_User = $userObj; } @@ -57,7 +57,7 @@ class ManageTags { * * @param string $collectionId Number */ - public function setCollection($collectionId) { + public function setCollection(string $collectionId) { if(!empty($collectionId)) { $this->_collectionId = $collectionId; } @@ -73,7 +73,7 @@ class ManageTags { * @param array $data Needs use=fromString, move=toString, doDelete=true * @return string */ - public function doWithTag($ident, $data) { + public function doWithTag(string $ident, array $data): string { $ret = ''; if(!empty($this->_collectionId) && !empty($ident) && !empty($data) && isset($data['use']) && !empty($data['use'])) { @@ -100,7 +100,7 @@ class ManageTags { * @param string $to Value string to set to in lookup table * @return string */ - private function _move($field, $from, $to) { + private function _move(string $field, string $from, string $to): string { $ret = ''; if(!Summoner::validate($field,'digit')) return 'Invalid field id for move/rename'; @@ -131,7 +131,7 @@ class ManageTags { * @param string $what Value to search for and delete from lookup table * @return string */ - private function _delete($field, $what) { + private function _delete(string $field, string $what): string { $ret = ''; if(!Summoner::validate($field,'digit')) return 'Invalid field id for delete'; diff --git a/webclient/lib/mancubus.class.php b/webclient/lib/mancubus.class.php index 676ec4e..1fe1d00 100644 --- a/webclient/lib/mancubus.class.php +++ b/webclient/lib/mancubus.class.php @@ -72,7 +72,7 @@ class Mancubus { * @param mysqli $databaseConnectionObject * @param Doomguy $userObj */ - public function __construct($databaseConnectionObject, $userObj) { + public function __construct(mysqli $databaseConnectionObject, Doomguy $userObj) { $this->_DB = $databaseConnectionObject; $this->_User = $userObj; @@ -84,7 +84,7 @@ class Mancubus { * * @param string $collectionId Number */ - public function setCollection($collectionId) { + public function setCollection(string $collectionId) { if(!empty($collectionId)) { $this->_collectionId = $collectionId; } @@ -101,7 +101,7 @@ class Mancubus { * * @param array $options */ - public function setQueryOptions($options) { + public function setQueryOptions(array $options) { if(!isset($options['limit'])) $options['limit'] = 5; if(!isset($options['offset'])) $options['offset'] = false; @@ -341,7 +341,7 @@ class Mancubus { * @param string $fieldValue Value of the field * @return array */ - public function getEntriesByFieldValue($fieldId, $fieldValue) { + public function getEntriesByFieldValue(string $fieldId, string $fieldValue): array { $ret = array(); $_entryFields = $this->_getEntryFields(); @@ -421,9 +421,9 @@ class Mancubus { * Return the storage info for loaded collection * Used by API * - * @return array|mixed + * @return array */ - public function getEntryStructure() { + public function getEntryStructure(): array { $ret = array(); $_entryFields = $this->_getEntryFields(); @@ -437,7 +437,7 @@ class Mancubus { * * @return array */ - private function _getEntryFields() { + private function _getEntryFields(): array { if(!empty($this->_cacheEntryFields)) { return $this->_cacheEntryFields; @@ -474,7 +474,7 @@ class Mancubus { * @param array $entryFields Loaded fields * @return mixed */ - private function _mergeEntryWithFields($entryData, $entryFields) { + private function _mergeEntryWithFields(array $entryData, array $entryFields): array { if(!empty($entryFields)) { foreach($entryFields as $f) { $_mnValue = '_loadFieldValue_'.$f['type']; @@ -505,7 +505,7 @@ class Mancubus { * @param array $fieldData * @return array */ - private function _loadFieldValue_lookupmultiple($entryId, $fieldData) { + private function _loadFieldValue_lookupmultiple(string $entryId, array $fieldData): array { $ret = array(); if(!empty($entryId) && !empty($fieldData) && !empty($this->_collectionId)) { @@ -548,7 +548,7 @@ class Mancubus { * @param array $fieldData * @return string */ - private function _loadFieldValue_upload($entryId, $fieldData) { + private function _loadFieldValue_upload(string $entryId, array $fieldData): string { $ret = ""; if(!empty($entryId) && !empty($fieldData) && !empty($this->_collectionId)) { @@ -571,7 +571,7 @@ class Mancubus { * @param string $fieldData * @return array */ - private function _loadFieldValue_upload_multiple($entryId, $fieldData) { + private function _loadFieldValue_upload_multiple(string $entryId, string $fieldData): array { $ret = array(); if(!empty($entryId) && !empty($fieldData) && !empty($this->_collectionId)) { @@ -591,7 +591,7 @@ class Mancubus { * @param string $data * @return array */ - private function _loadFieldSelection_selection($data) { + private function _loadFieldSelection_selection(string $data): array { $ret = array(); if(is_string($data)) { diff --git a/webclient/lib/possessed.class.php b/webclient/lib/possessed.class.php index f185654..6e0c4eb 100644 --- a/webclient/lib/possessed.class.php +++ b/webclient/lib/possessed.class.php @@ -55,7 +55,7 @@ class Possessed { * * @return array */ - public function getGroups() { + public function getGroups(): array { $ret = array(); $queryStr = "SELECT `id`, `name`, `description`, `created`, `protected` @@ -253,7 +253,7 @@ class Possessed { * @param string $userId Number * @return array */ - public function getEditData($userId) { + public function getEditData(string $userId): array { $ret = array(); if(Summoner::validate($userId,'digit')) { @@ -284,7 +284,7 @@ class Possessed { * @param string $id Number * @return bool */ - public function deleteUser($id) { + public function deleteUser(string $id): bool { $ret = false; if(Summoner::validate($id,'digit')) { @@ -319,7 +319,7 @@ class Possessed { * @param string $description * @return bool */ - public function createGroup($name, $description) { + public function createGroup(string $name, string $description): bool { $ret = false; if($this->_validNewGroup($name)) { @@ -352,7 +352,7 @@ class Possessed { * @param string $description * @return bool */ - public function updateGroup($id, $name, $description) { + public function updateGroup(string $id, string $name, string $description): bool { $ret = false; if($this->_validUpdateGroup($name, $id)) { @@ -381,7 +381,7 @@ class Possessed { * @param string $id Number * @return bool */ - public function deleteGroup($id) { + public function deleteGroup(string $id): bool { $ret = false; if(Summoner::validate($id,'digit')) { @@ -408,7 +408,7 @@ class Possessed { * @param string $id Number * @return array */ - public function getEditGroupData($id) { + public function getEditGroupData(string $id): array { $ret = array(); if(Summoner::validate($id,'digit')) { @@ -437,7 +437,7 @@ class Possessed { * @param string $name * @return bool */ - private function _validNewGroup($name) { + private function _validNewGroup(string $name): bool { $ret = false; if (Summoner::validate($name, 'nospace')) { @@ -465,7 +465,7 @@ class Possessed { * @param string $id Number * @return bool */ - private function _validUpdateGroup($name,$id) { + private function _validUpdateGroup(string $name, string $id): bool { $ret = false; if (Summoner::validate($name, 'nospace') && Summoner::validate($id,"digit")) { @@ -493,7 +493,7 @@ class Possessed { * @param string $login * @return bool */ - private function _validNewLogin($login) { + private function _validNewLogin(string $login): bool { $ret = false; if (Summoner::validate($login, 'nospace')) { @@ -521,7 +521,7 @@ class Possessed { * @param string $id Number * @return bool */ - private function _validUpdateLogin($login,$id) { + private function _validUpdateLogin(string $login, string $id): bool { $ret = false; if (Summoner::validate($login, 'nospace') && Summoner::validate($id,"digit")) { @@ -549,7 +549,7 @@ class Possessed { * @param string $groupId Number * @return bool */ - private function _validUsergroup($groupId) { + private function _validUsergroup(string $groupId): bool { $ret = false; if(Summoner::validate($groupId,'digit')) { @@ -579,7 +579,7 @@ class Possessed { * @param bool $clean * @return bool */ - private function _setGroupReleation($userid, $group, $clean=false) { + private function _setGroupReleation(string $userid, array $group, $clean=false): bool { $ret = false; if(Summoner::validate($userid,'digit') @@ -612,12 +612,12 @@ class Possessed { /** * Load all the groups the user is in and the information of them * - * @todo Not really needed. Can be done in one query. See Doomguy class - * * @param string $userId Number * @return array + * @todo Not really needed. Can be done in one query. See Doomguy class + * */ - private function _loadUserGroupInfo($userId) { + private function _loadUserGroupInfo(string $userId): array{ $ret = array(); $queryStr = "SELECT g.name AS groupName, diff --git a/webclient/lib/spectre.class.php b/webclient/lib/spectre.class.php index 0f6e9ac..f92aa54 100644 --- a/webclient/lib/spectre.class.php +++ b/webclient/lib/spectre.class.php @@ -2,7 +2,7 @@ /** * Bibliotheca * - * Copyright 2018-2020 Johannes Keßler + * Copyright 2018-2021 Johannes Keßler * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -48,7 +48,7 @@ class Spectre { * @param mysqli $databaseConnectionObject * @param Doomguy $userObj */ - public function __construct($databaseConnectionObject, $userObj) { + public function __construct(mysqli $databaseConnectionObject, Doomguy $userObj) { $this->_DB = $databaseConnectionObject; $this->_User = $userObj; } @@ -59,7 +59,7 @@ class Spectre { * @param string $request * @return bool */ - public function allowedRequests($request) { + public function allowedRequests(string $request): bool { $ret = false; if(in_array($request, $this->_allowedRequests)) { @@ -76,7 +76,7 @@ class Spectre { * @param array $data * @return array */ - public function buildAddStructure($data) { + public function buildAddStructure(array $data): array { $ret = array(); if(!empty($data) && is_array($data)) { @@ -96,7 +96,7 @@ class Spectre { * @param array $data * @return array */ - public function prepareFilesArray($data) { + public function prepareFilesArray(array $data): array { $ret = array(); if(!empty($data)) { diff --git a/webclient/lib/summoner.class.php b/webclient/lib/summoner.class.php index b3aed8c..5ca5521 100644 --- a/webclient/lib/summoner.class.php +++ b/webclient/lib/summoner.class.php @@ -29,7 +29,7 @@ class Summoner { * @param string $defaultTheme Default theme name can be overwritten * @return bool|string False of nothing is found */ - static function themefile($file, $theme, $defaultTheme='default') { + static function themefile(string $file, string $theme, $defaultTheme='default') { $ret = false; if(file_exists('view/'.$theme.'/'.$file)) { @@ -50,6 +50,7 @@ class Summoner { * @param string $mode How the string should be checked * @param mixed $limit If int given the string is checked for length * + * @return bool * @see http://de.php.net/manual/en/regexp.reference.unicode.php * http://www.sql-und-xml.de/unicode-database/#pc * @@ -57,9 +58,8 @@ class Summoner { * the replace should be empty, otherwise are there chars which are not * allowed * - * @return bool */ - static function validate($input,$mode='text',$limit=false) { + static function validate(string $input, $mode='text', $limit=false): bool { // check if we have input $input = trim($input); @@ -142,33 +142,13 @@ class Summoner { return $ret; } - /** - * return if the given string is utf8 - * http://php.net/manual/en/function.mb-detect-encoding.php - * - * @param string $string - * @return number - */ - static function is_utf8 ( $string ) { - // From http://w3.org/International/questions/qa-forms-utf-8.html - return preg_match('%^(?: - [\x09\x0A\x0D\x20-\x7E] # ASCII - | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte - | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs - | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte - | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates - | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3 - | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15 - | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16 - )*$%xs', $string); - } - /** * check if the given string is a rights string. + * * @param string $string * @return boolean */ - static function isRightsString($string) { + static function isRightsString(string $string): bool { $ret = false; $string = trim($string); @@ -195,11 +175,11 @@ class Summoner { * IMPORTANT: keep the order otherwise the rights will be messed up * * @param array $rightsArr - * @return mixed + * @return array */ - static function prepareRightsString($rightsArr) { + static function prepareRightsString(array $rightsArr): array { $rsArr = array(); - $ret = false; + $ret = array(); if(!empty($rightsArr)) { // we need a complete type list @@ -244,7 +224,7 @@ class Summoner { $rString .= $rsArr['other']['read'].$rsArr['other']['write'].$rsArr['other']['delete']; if(strlen($rString) != 9) { - $ret = false; + $ret = array(); // invalid rights string !! } else { @@ -257,10 +237,11 @@ class Summoner { /** * Creates from given rights string the rights array + * * @param string $rightsString * @return array */ - static function prepareRightsArray($rightsString) { + static function prepareRightsArray(string $rightsString): array { $ret = array(); if(self::isRightsString($rightsString) === true) { @@ -289,66 +270,16 @@ class Summoner { return $ret; } - /** - * get the mime type for given file - * uses either mime_content_type or finfo - * @param string $file The absolute path to the file - * @return mixed|string - */ - static function getMimeType($file) { - $mime = 'application/octet-stream'; # default - - if(function_exists('mime_content_type') !== true) { - $mime = mime_content_type($file); - } - elseif(function_exists('finfo_open') === true) { - # provide empty magic file, system default file will be used - $finfo = finfo_open(FILEINFO_MIME_TYPE,null); - if($finfo) { - $mime = finfo_file($finfo, $file); - finfo_close($finfo); - } - - # the mime info returns sometimes "application/x-gzip; charset=binary" - # but wee need the part before the ; - if(strstr($mime,';')) { - $tmp = explode(";",$mime); - $mime = $tmp[0]; - } - } - - return $mime; - } - - /** - * use the mimeType string to return the string to be used as an icon identifier - * eg. application/pdf => pdf - * @param string $mime - * @return string $ret - */ - static function mimeToIcon($mime) { - $ret = 'unknown'; - - if(!empty($mime) && strstr($mime,'/') !== false) { - $tmp = explode('/', $mime); - $ret = $tmp[1]; - } - elseif($mime === "directory") { - $ret = "dir"; - } - - return $ret; - } - /** * read a dir and return the entries as an array * with full path to the files + * * @param string $directory The absolute path to the directory * @param array $ignore An Array with strings to ignored * @param bool $recursive If we run a recursive scan or not * @return array */ - static function readDir($directory,$ignore=array(),$recursive=false) { + static function readDir(string $directory, $ignore=array(), $recursive=false): array { $files = array(); $dh = opendir($directory); @@ -386,7 +317,7 @@ class Summoner { * @param mixed $fTime If not false remove files older then this value in sec. * @return bool */ - static function recursive_remove_directory($directory, $empty=false,$fTime=false) { + static function recursive_remove_directory(string $directory, $empty=false, $fTime=false): bool { // if the path has a slash at the end we remove it here if(substr($directory,-1) == '/') { $directory = substr($directory,0,-1); @@ -463,7 +394,7 @@ class Summoner { * @param string $needle * @return bool */ - static function startsWith($haystack, $needle) { + static function startsWith(string $haystack, string $needle): bool { $length = strlen($needle); return (substr($haystack, 0, $length) === $needle); } @@ -475,7 +406,7 @@ class Summoner { * @param string $needle * @return bool */ - static function endsWith($haystack, $needle) { + static function endsWith(string $haystack, string $needle): bool { $length = strlen($needle); if ($length == 0) { return true; @@ -484,82 +415,13 @@ class Summoner { return (substr($haystack, -$length) === $needle); } - /** - * http://de1.php.net/manual/en/function.getimagesize.php - * http://php.net/manual/en/function.imagecreatefromjpeg.php - * - * @param string $file The absolute path to the image file - * @param number $width - * @param number $height - * @return bool - */ - static function createThumbnail($file,$width=ADMIN_THUMBNAIL_DEFAULT_WIDTH,$height=ADMIN_THUMBNAIL_DEFAULT_HEIGHT) { - $ret = false; - - if(!is_file($file)) return false; - # check if this is a support file type to create a thumbnail - $mimeType = self::getMimeType($file); - if(!strstr(ADMIN_THUMBNAIL_SUPPORTED_FILE_TYPES, $mimeType)) return false; - - // Get new dimensions - $imageinfo = getimagesize($file); - - if(empty($imageinfo)) return false; - - $thumbnailName = $file.ADMIN_THUMBNAIL_IDENTIFIER.".".$height."x".$width; - - $width_orig = $imageinfo[0]; - $height_orig = $imageinfo[1]; - $ratio_orig = $width_orig/$height_orig; - - if ($width/$height > $ratio_orig) { - $width = $height*$ratio_orig; - } else { - $height = $width/$ratio_orig; - } - - $im = false; - - // Resample - $image_p = imagecreatetruecolor($width, $height); - - switch ($imageinfo[2]) { - case IMAGETYPE_GIF: - $im = imageCreateFromGif($file); - imagecopyresampled($image_p, $im, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); - imagegif($image_p, $thumbnailName); - break; - - case IMAGETYPE_JPEG: - $im = imageCreateFromJpeg($file); - imagecopyresampled($image_p, $im, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); - // save - $do = imagejpeg($image_p, $thumbnailName, 70); - break; - - case IMAGETYPE_PNG: - $im = imageCreateFromPng($file); - imagecopyresampled($image_p, $im, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); - imagepng($image_p, $thumbnailName, 5); - break; - } - - imagedestroy($im); - imagedestroy($image_p); - - if(file_exists($thumbnailName)) { - $ret = true; - } - - return $ret; - } - /** * fix the filesystem filenames. Remove whitespace and ... + * * @param array $filenames File or folder list * @return array */ - static function fixAssetFilenames($filenames) { + static function fixAssetFilenames(array $filenames): array { $ret = $filenames; foreach($filenames as $k=>$file) { @@ -587,7 +449,7 @@ class Summoner { * @param array|string $key * @return bool|mixed */ - static function ifset($array,$key) { + static function ifset(array $array, $key) { if(is_array($key)) { $_t = $array; $_c = 0; @@ -613,7 +475,7 @@ class Summoner { * @param string $value The value to compare * @return bool */ - static function ifsetValue($array,$key,$value) { + static function ifsetValue(array $array, string $key, string $value): bool { if(self::ifset($array,$key) !== false) { return $array[$key] == $value; } @@ -628,7 +490,7 @@ class Summoner { * @param string $replace * @return string */ - static function replaceOnce($haystack, $needle, $replace) { + static function replaceOnce(string $haystack, string $needle, string $replace): string { $newstring = $haystack; $pos = strpos($haystack, $needle); if ($pos !== false) { @@ -675,7 +537,7 @@ class Summoner { * @param string $endChar * @return string */ - static function limitWithDots($string, $length, $endChar) { + static function limitWithDots(string $string, int $length, string $endChar): string { $ret = $string; if(strlen($string.$endChar) > $length) { -- 2.39.5