* 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
* Field management: Web interface
* minimal theme
* Automatic upgrade from DB changes
-* PHP 7 syntax and specifications
/**
* 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.
* 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) {
* @param string $param
* @return bool|mixed
*/
- public function param($param) {
+ public function param(string $param) {
$ret = false;
$param = trim($param);
/**
* 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;
}
*
* @return bool
*/
- public function isSignedIn() {
+ public function isSignedIn(): bool {
return $this->isSignedIn;
}
*
* @return boolean
*/
- public function logOut () {
+ public function logOut (): bool {
$ret = false;
if($this->_checkAgainstSessionTable() === true) {
* @param integer $groupID
* @return bool
*/
- public function isInGroup($groupID) {
+ public function isInGroup(int $groupID): bool {
$ret = false;
if($this->userData['isRoot'] === true) {
* @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)) {
* 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`
*
* @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 ||
*
* @return bool
*/
- protected function _checkAgainstSessionTable() {
+ protected function _checkAgainstSessionTable(): bool {
$ret = false;
$timeframe = date("Y-m-d H:i:s",time()-SESSION_LIFETIME);
* @param string $u
* @return bool
*/
- protected function _checkAgainstUserTable($u) {
+ protected function _checkAgainstUserTable(string $u): bool {
$ret = false;
if(!empty($u)) {
*
* @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)."'
/**
* 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.
* @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];
}
* @param mysqli $databaseConnectionObject
* @param Doomguy $userObj
*/
- public function __construct($databaseConnectionObject, $userObj) {
+ public function __construct(mysqli $databaseConnectionObject, Doomguy $userObj) {
$this->_DB = $databaseConnectionObject;
$this->_User = $userObj;
}
/**
* 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;
* @param string $string
* @return bool
*/
- public function validateFieldSortString($string) {
+ public function validateFieldSortString(string $string): bool {
$ret = false;
$_t = str_replace(",","",$string);
* @param string $fieldsSortString
* @return bool
*/
- public function updateFields($fieldsSortString) {
+ public function updateFields(string $fieldsSortString): bool {
$ret = false;
$ids = array();
* @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;
}
*
* @return array
*/
- private function _getExistingCollectionColumns() {
+ private function _getExistingCollectionColumns(): array {
$ret = array();
$queryStr = "SHOW COLUMNS FROM `".DB_PREFIX."_collection_entry_".$this->_collectionId."`";
* @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();
*
* @return array
*/
- public function getGroupsForSelection() {
+ public function getGroupsForSelection(): array {
$ret = array();
$queryStr = "SELECT `id`, `name`, `description`
*
* @return array
*/
- public function getUsersForSelection() {
+ public function getUsersForSelection(): array {
$ret = array();
$queryStr = "SELECT `id`, `name`, `login`
*
* @return array
*/
- public function getToolsForSelection() {
+ public function getToolsForSelection(): array {
$ret = array();
$queryStr = "SELECT `id`, `name`, `description`
* @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')) {
* @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`
* @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`
* @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')
* @param array $tool
* @return bool
*/
- private function _updateToolRelation($id,$tool) {
+ private function _updateToolRelation(string $id, array $tool): bool {
$ret = false;
* @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";
* @param array $data
* @return array
*/
- private function _loadAdvancedSearchTableFields($data) {
+ private function _loadAdvancedSearchTableFields(array $data): array {
$ret = array();
$_t = explode(',',$data);
* @param mysqli $databaseConnectionObject
* @param Doomguy $userObj
*/
- public function __construct($databaseConnectionObject, $userObj) {
+ public function __construct(mysqli $databaseConnectionObject, Doomguy $userObj) {
$this->_DB = $databaseConnectionObject;
$this->_User = $userObj;
}
*
* @param string $collectionId Number
*/
- public function setCollection($collectionId) {
+ public function setCollection(string $collectionId) {
if(!empty($collectionId)) {
$this->_collectionId = $collectionId;
}
* @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;
* @param string $entryId Number
* @return bool
*/
- public function delete($entryId) {
+ public function delete(string $entryId): bool {
$ret = false;
if(!empty($entryId) && !empty($this->_collectionId)) {
* @param string $entryId Number
* @return bool
*/
- private function _canDelete($entryId) {
+ private function _canDelete(string $entryId): bool {
$ret = false;
if(!empty($entryId) && !empty($this->_collectionId)) {
* @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'];
* 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)) {
* 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)) {
* 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)) {
* @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']);
/**
* 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)."`
/**
* 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;
}
* @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);
}
* @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);
}
* @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);
}
* @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];
* @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;
* @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, ",");
* @param mysqli $databaseConnectionObject
* @param Doomguy $userObj
*/
- public function __construct($databaseConnectionObject, $userObj) {
+ public function __construct(mysqli $databaseConnectionObject, Doomguy $userObj) {
$this->_DB = $databaseConnectionObject;
$this->_User = $userObj;
}
*
* @param string $collectionId Number
*/
- public function setCollection($collectionId) {
+ public function setCollection(string $collectionId) {
if(!empty($collectionId)) {
$this->_collectionId = $collectionId;
}
* @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'])) {
* @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';
* @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';
* @param mysqli $databaseConnectionObject
* @param Doomguy $userObj
*/
- public function __construct($databaseConnectionObject, $userObj) {
+ public function __construct(mysqli $databaseConnectionObject, Doomguy $userObj) {
$this->_DB = $databaseConnectionObject;
$this->_User = $userObj;
*
* @param string $collectionId Number
*/
- public function setCollection($collectionId) {
+ public function setCollection(string $collectionId) {
if(!empty($collectionId)) {
$this->_collectionId = $collectionId;
}
*
* @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;
* @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();
* 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();
*
* @return array
*/
- private function _getEntryFields() {
+ private function _getEntryFields(): array {
if(!empty($this->_cacheEntryFields)) {
return $this->_cacheEntryFields;
* @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'];
* @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)) {
* @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)) {
* @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)) {
* @param string $data
* @return array
*/
- private function _loadFieldSelection_selection($data) {
+ private function _loadFieldSelection_selection(string $data): array {
$ret = array();
if(is_string($data)) {
*
* @return array
*/
- public function getGroups() {
+ public function getGroups(): array {
$ret = array();
$queryStr = "SELECT `id`, `name`, `description`, `created`, `protected`
* @param string $userId Number
* @return array
*/
- public function getEditData($userId) {
+ public function getEditData(string $userId): array {
$ret = array();
if(Summoner::validate($userId,'digit')) {
* @param string $id Number
* @return bool
*/
- public function deleteUser($id) {
+ public function deleteUser(string $id): bool {
$ret = false;
if(Summoner::validate($id,'digit')) {
* @param string $description
* @return bool
*/
- public function createGroup($name, $description) {
+ public function createGroup(string $name, string $description): bool {
$ret = false;
if($this->_validNewGroup($name)) {
* @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)) {
* @param string $id Number
* @return bool
*/
- public function deleteGroup($id) {
+ public function deleteGroup(string $id): bool {
$ret = false;
if(Summoner::validate($id,'digit')) {
* @param string $id Number
* @return array
*/
- public function getEditGroupData($id) {
+ public function getEditGroupData(string $id): array {
$ret = array();
if(Summoner::validate($id,'digit')) {
* @param string $name
* @return bool
*/
- private function _validNewGroup($name) {
+ private function _validNewGroup(string $name): bool {
$ret = false;
if (Summoner::validate($name, 'nospace')) {
* @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")) {
* @param string $login
* @return bool
*/
- private function _validNewLogin($login) {
+ private function _validNewLogin(string $login): bool {
$ret = false;
if (Summoner::validate($login, 'nospace')) {
* @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")) {
* @param string $groupId Number
* @return bool
*/
- private function _validUsergroup($groupId) {
+ private function _validUsergroup(string $groupId): bool {
$ret = false;
if(Summoner::validate($groupId,'digit')) {
* @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')
/**
* 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,
/**
* 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.
* @param mysqli $databaseConnectionObject
* @param Doomguy $userObj
*/
- public function __construct($databaseConnectionObject, $userObj) {
+ public function __construct(mysqli $databaseConnectionObject, Doomguy $userObj) {
$this->_DB = $databaseConnectionObject;
$this->_User = $userObj;
}
* @param string $request
* @return bool
*/
- public function allowedRequests($request) {
+ public function allowedRequests(string $request): bool {
$ret = false;
if(in_array($request, $this->_allowedRequests)) {
* @param array $data
* @return array
*/
- public function buildAddStructure($data) {
+ public function buildAddStructure(array $data): array {
$ret = array();
if(!empty($data) && is_array($data)) {
* @param array $data
* @return array
*/
- public function prepareFilesArray($data) {
+ public function prepareFilesArray(array $data): array {
$ret = array();
if(!empty($data)) {
* @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)) {
* @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
*
* 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);
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);
* 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
$rString .= $rsArr['other']['read'].$rsArr['other']['write'].$rsArr['other']['delete'];
if(strlen($rString) != 9) {
- $ret = false;
+ $ret = array();
// invalid rights string !!
}
else {
/**
* 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) {
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);
* @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);
* @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);
}
* @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;
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) {
* @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;
* @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;
}
* @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) {
* @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) {