From b7963f719b26e8d86b421dcefb5778527b8b86f8 Mon Sep 17 00:00:00 2001 From: Banana Date: Thu, 1 Apr 2021 23:17:49 +0200 Subject: [PATCH] adapt some php 7 code styles --- ChangeLog | 1 + README | 1 + TODO | 4 +- webroot/lib/category.class.php | 42 +++--- webroot/lib/email-import-helper.class.php | 15 ++- webroot/lib/import-export.class.php | 26 ++-- webroot/lib/link.class.php | 91 +++++++++---- webroot/lib/management.class.php | 156 +++++++++++++--------- webroot/lib/simple-imap.class.php | 44 +++--- webroot/lib/snapshot.class.php | 28 ++-- webroot/lib/summoner.class.php | 114 ++++++++-------- webroot/lib/tag.class.php | 69 ++++++---- webroot/lib/translation.class.php | 7 +- webroot/view/editcategories.inc.php | 6 +- 14 files changed, 377 insertions(+), 227 deletions(-) diff --git a/ChangeLog b/ChangeLog index a1ae9fe..c35ee14 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ version 2.7 - Sacred Grove + Fixed bug #12. Missing translation key + + Adapted some new PHP code formatting version 2.6 - Hypostyle diff --git a/README b/README index 5ab96b2..c01abe6 100644 --- a/README +++ b/README @@ -9,3 +9,4 @@ https://bulma.io/ https://github.com/PHPMailer/PHPMailer https://ionicons.com/ https://github.com/ifsnop/mysqldump-php +shellcommand by Michael Härtl diff --git a/TODO b/TODO index 6f07b65..e242914 100644 --- a/TODO +++ b/TODO @@ -1,9 +1,7 @@ TODO / Feature list -+ adapt new php 7 -++ http://php.net/manual/en/migration70.new-features.php#migration70.new-features.null-coalesce-op + view table really still needed? + stats cleanup. Management functions should be standalone + theme support + more "secure" user authentication ++ multiple user accounts and stuff -+ combine cat and tag class into one. ++ combine category and tag class into one. diff --git a/webroot/lib/category.class.php b/webroot/lib/category.class.php index 12c75de..4f6ace1 100644 --- a/webroot/lib/category.class.php +++ b/webroot/lib/category.class.php @@ -53,10 +53,10 @@ class Category { * by given string load the info from the DB and even create if not existing * * @param string $string - * @return int 0=fail, 1=existing, 2=new, 3=newNotCreated - * @return bool|int + * @param bool $doNotCreate + * @return int 0=fail, 1=existing, 2=new, 3=newNotCreated */ - public function initbystring($string, $doNotCreate=false) { + public function initbystring(string $string, $doNotCreate=false): int { $ret = 0; $this->_id = false; if(!empty($string)) { @@ -91,11 +91,12 @@ class Category { /** * by given DB table id load all the info we need + * * @param int $id - * @return mixed + * @return integer */ - public function initbyid($id) { - $this->_id = false; + public function initbyid(int $id): int { + $this->_id = 0; if(!empty($id)) { $queryStr = "SELECT id,name @@ -114,10 +115,11 @@ class Category { /** * return all or data fpr given key on the current loaded tag + * * @param bool $key - * @return array|mixed + * @return array */ - public function getData($key=false) { + public function getData($key=false): array { $ret = $this->_data; if(!empty($key) && isset($this->_data[$key])) { @@ -129,10 +131,11 @@ class Category { /** * set the relation to the given link to the loaded category - * @param int $linkid + * + * @param integer $linkid * @return void */ - public function setRelation($linkid) { + public function setRelation(int $linkid) { if(!empty($linkid) && !empty($this->_id)) { $queryStr = "INSERT IGNORE INTO `".DB_PREFIX."_categoryrelation` SET `linkid` = '".$this->DB->real_escape_string($linkid)."', @@ -143,9 +146,10 @@ class Category { /** * Return an array of any linkid related to the current loaded category + * * @return array */ - public function getReleations() { + public function getRelations(): array { $ret = array(); $queryStr = "SELECT linkid @@ -163,9 +167,10 @@ class Category { /** * deletes the current loaded category from db + * * @return boolean */ - public function delete() { + public function delete(): bool { $ret = false; if(!empty($this->_id)) { @@ -196,12 +201,13 @@ class Category { return $ret; } - /** - * Rename current loaded cat name - * @param $newValue - * @return void - */ - public function rename($newValue) { + /** + * Rename current loaded cat name + * + * @param string $newValue + * @return void + */ + public function rename(string $newValue) { if(!empty($newValue)) { $queryStr = "UPDATE `".DB_PREFIX."_category` SET `name` = '".$this->DB->real_escape_string($newValue)."' diff --git a/webroot/lib/email-import-helper.class.php b/webroot/lib/email-import-helper.class.php index 42db67c..97d80ab 100644 --- a/webroot/lib/email-import-helper.class.php +++ b/webroot/lib/email-import-helper.class.php @@ -3,7 +3,7 @@ * Insipid * Personal web-bookmark-system * - * Copyright 2016-2020 Johannes Keßler + * Copyright 2016-2021 Johannes Keßler * * Development starting from 2011: Johannes Keßler * https://www.bananas-playground.net/projekt/insipid/ @@ -38,7 +38,7 @@ class EmailImportHelper { * @param string $string * @return array $ret */ - static function extractEmailLinks($string) { + static function extractEmailLinks(string $string): array { $ret = array(); #this matches a valid URL. An URL with | is still valid... @@ -56,13 +56,14 @@ class EmailImportHelper { /** * Check if given from is in the valid EMAIL_REPLY_BACK_VALID - * @param $replyto + * + * @param string $replyTo * @return bool */ - static function canSendReplyTo($replyto) { + static function canSendReplyTo(string $replyTo): bool { if(defined("EMAIL_REPORT_BACK") && EMAIL_REPORT_BACK === true && defined("EMAIL_REPLY_BACK_VALID") && !empty(EMAIL_REPLY_BACK_VALID)) { - if(strstr($replyto,EMAIL_REPLY_BACK_VALID)) { + if(strstr($replyTo,EMAIL_REPLY_BACK_VALID)) { return true; } } @@ -82,10 +83,10 @@ class EmailImportHelper { * * this does not really quality check the values. It just checks if some headers are set * - * @param $headers complete email headers as an array + * @param array $headers complete email headers as an array * @return bool */ - static function isAutoReplyMessage($headers) { + static function isAutoReplyMessage(array $headers): bool { if(empty($headers)) { return true; } diff --git a/webroot/lib/import-export.class.php b/webroot/lib/import-export.class.php index 99bf51b..819771f 100644 --- a/webroot/lib/import-export.class.php +++ b/webroot/lib/import-export.class.php @@ -3,7 +3,7 @@ * Insipid * Personal web-bookmark-system * - * Copyright 2016-2020 Johannes Keßler + * Copyright 2016-2021 Johannes Keßler * * Development starting from 2011: Johannes Keßler * https://www.bananas-playground.net/projekt/insipid/ @@ -33,7 +33,7 @@ class ImportExport { /** - * @var String The current memory xmlwriter + * @var XMLWriter The current memory xmlwriter */ private $_currentXW; @@ -51,10 +51,11 @@ class ImportExport { /** * create a xml file for a given single link * expects the array from Link->load + * * @param array $data * @return string XML string from xmlwriter */ - public function createSingleLinkExportXML($data) { + public function createSingleLinkExportXML(array $data): string { $this->_currentXW = xmlwriter_open_memory(); xmlwriter_set_indent($this->_currentXW, 1); @@ -148,11 +149,13 @@ class ImportExport { } /** - * @param $file array $_FILES array. Just check if everything is there - * and put it into _uploadedData + * Just check if everything is there and put it into _uploadedData + * + * @param array $file $_FILES array. * @throws Exception + * @return void */ - public function loadImportFile($file) { + public function loadImportFile(array $file) { if(!isset($file['name']) || !isset($file['type']) @@ -193,10 +196,11 @@ class ImportExport { /** * parse the data from _uploadedData and create an array we can use + * * @return array * @throws Exception */ - public function parseImportFile() { + public function parseImportFile(): array { $ret = array(); if(!empty($this->_uploadedData)) { @@ -241,11 +245,13 @@ class ImportExport { /** * Create a single xml element for the current loaded xmlwriter + * * @param String $name * @param String $key * @param String $value + * @return void */ - private function _elementFromKeyValue($name, $key, $value) { + private function _elementFromKeyValue(string $name, string $key, string $value) { if(!empty($key) && !empty($value) && !empty($name)) { xmlwriter_start_element($this->_currentXW, $name); @@ -265,6 +271,7 @@ class ImportExport { /** * validate an import of a export xml with the * saved xsd file _xmlImportXSD + * * @return bool|string */ private function _validateXMLImport() { @@ -291,9 +298,10 @@ class ImportExport { /** * Reads libxml_get_errors and creates a simple string with all * the info we need. + * * @return string */ - private function _xmlErrors() { + private function _xmlErrors(): string { $errors = libxml_get_errors(); $result = array(); foreach ($errors as $error) { diff --git a/webroot/lib/link.class.php b/webroot/lib/link.class.php index 5c99e50..13fee3d 100644 --- a/webroot/lib/link.class.php +++ b/webroot/lib/link.class.php @@ -26,30 +26,42 @@ * */ +/** + * Class Link + */ class Link { /** * the database object - * @var object + * + * @var Object */ private $DB; /** * the current loaded link data + * * @var array */ private $_data; + /** + * Link constructor. + * + * @param Object $databaseConnectionObject + * @return void + */ public function __construct($databaseConnectionObject) { $this->DB = $databaseConnectionObject; } /** * load all the info we have about a link by given hash + * * @param string $hash - * @return mixed + * @return array */ - public function load($hash) { + public function load(string $hash): array { $this->_data = array(); @@ -87,10 +99,10 @@ class Link { * loads only the info needed to display the link * for edit use $this->load * - * @param $hash + * @param string $hash * @return array */ - public function loadShortInfo($hash) { + public function loadShortInfo(string $hash): array { $this->_data = array(); if (!empty($hash)) { @@ -110,7 +122,13 @@ class Link { return $this->_data; } - public function loadFromDataShortInfo($data) { + /** + * Get shortinfo from given data array + * + * @param array $data + * @return array + */ + public function loadFromDataShortInfo(array $data): array { $this->_data = array(); if(isset($data['id']) && isset($data['link']) && isset($data['created']) && isset($data['status']) @@ -128,7 +146,7 @@ class Link { * @param bool $key * @return array|mixed */ - public function getData($key = false) { + public function getData($key = false): array { $ret = $this->_data; if (!empty($key) && isset($this->_data[$key])) { @@ -140,23 +158,26 @@ class Link { /** * reload the current id from DB + * + * @return void */ public function reload() { $this->load($this->_data['hash']); } - /** - * create a new link with the given data - * @param array $data - * @param bool $returnId - * @return boolean|int - */ - public function create($data, $returnId = false) { - $ret = false; + /** + * create a new link with the given data + * + * @param array $data + * @param bool $returnId + * @return int + */ + public function create(array $data, $returnId = false): int { + $ret = 0; - if (!isset($data['link']) || empty($data['link'])) return false; - if (!isset($data['hash']) || empty($data['hash'])) return false; - if (!isset($data['title']) || empty($data['title'])) return false; + if (!isset($data['link']) || empty($data['link'])) return $ret; + if (!isset($data['hash']) || empty($data['hash'])) return $ret; + if (!isset($data['title']) || empty($data['title'])) return $ret; $_t = parse_url($data['link']); $data['search'] = $data['title']; @@ -183,7 +204,7 @@ class Link { $ret = $this->DB->insert_id; } else { - error_log('ERROR Failed to rcreate link: '.var_export($data,true)); + error_log('ERROR Failed to create link: '.var_export($data,true)); } return $ret; @@ -193,9 +214,9 @@ class Link { * update the current loaded link with the given data * * @param array $data - * @return boolean|int + * @return boolean */ - public function update($data) { + public function update(array $data): bool { $ret = false; @@ -321,6 +342,8 @@ class Link { /** * call this to delete all the relations to this link. * To completely remove the link use Management->deleteLink() + * + * @return void */ public function deleteRelations() { $this->_removeTagRelation(false); @@ -333,6 +356,8 @@ class Link { /** * load all the tags we have to the already loaded link * needs $this->load called first + * + * @return void */ private function _tags() { $ret = array(); @@ -359,6 +384,8 @@ class Link { /** * load all the categories we have to the already loaded link * needs $this->load called first + * + * @return void */ private function _categories() { $ret = array(); @@ -383,7 +410,9 @@ class Link { /** * remove all or given tag relation to the current loaded link - * @param mixed $tagid + * + * @param boolean|integer $tagid + * @return void */ private function _removeTagRelation($tagid) { if (!empty($this->_data['id'])) { @@ -406,7 +435,9 @@ class Link { /** * remove all or given category relation to the current loaded link - * @param mixed $categoryid + * + * @param boolean|integer $categoryid + * @return void */ private function _removeCategoryRelation($categoryid) { if (!empty($this->_data['id'])) { @@ -430,6 +461,8 @@ class Link { /** * determine of we have a local stored image * if so populate the localImage attribute + * + * @return void */ private function _image() { if (!empty($this->_data['hash'])) { @@ -445,6 +478,8 @@ class Link { /** * determine if we have a local stored snapshot * if so populate the snapshotLink attribute + * + * @return void */ private function _snapshot() { if (!empty($this->_data['hash'])) { @@ -459,6 +494,8 @@ class Link { /** * determine if we have a local full page screenshot * if so populate the pagescreenshotLink attribute + * + * @return void */ private function _pageScreenshot() { if (!empty($this->_data['hash'])) { @@ -472,6 +509,8 @@ class Link { /** * remove the local stored image + * + * @return void */ private function _deleteImage() { if (!empty($this->_data['hash']) && !empty($this->_data['imageToShow'])) { @@ -484,6 +523,8 @@ class Link { /** * remove the local stored snapshot + * + * @return void */ private function _deleteSnapshot() { if (!empty($this->_data['hash']) && !empty($this->_data['snapshotLink'])) { @@ -496,6 +537,8 @@ class Link { /** * remove the local stored pagescreenshot + * + * @return void */ private function _deletePageScreenshot() { if (!empty($this->_data['hash']) && !empty($this->_data['pagescreenshotLink'])) { @@ -508,6 +551,8 @@ class Link { /** * check if the status is private and set the info + * + * @return void */ private function _private() { if (!empty($this->_data['status']) && $this->_data['status'] == "1") { diff --git a/webroot/lib/management.class.php b/webroot/lib/management.class.php index a609fff..d6189bb 100644 --- a/webroot/lib/management.class.php +++ b/webroot/lib/management.class.php @@ -26,6 +26,9 @@ * */ +/** + * Class Management + */ class Management { const LINK_QUERY_STATUS = 2; @@ -45,27 +48,36 @@ class Management { /** * the database object + * * @var object */ private $DB; /** * Type of links based on status to show + * * @var bool */ private $_queryStatus = self::LINK_QUERY_STATUS; - + /** + * Management constructor. + * + * @param Object $databaseConnectionObject + * @return void + */ public function __construct($databaseConnectionObject) { $this->DB = $databaseConnectionObject; } /** * Show private links or not - * @param $bool + * + * @param boolean $bool + * @return void */ - public function setShowPrivate($bool) { + public function setShowPrivate(bool $bool) { $this->_queryStatus = self::LINK_QUERY_STATUS; if($bool === true) { $this->_queryStatus = 1; @@ -74,9 +86,11 @@ class Management { /** * Show awaiting moderation links or not - * @param $bool + * + * @param boolean $bool + * @return void */ - public function setShowAwm($bool) { + public function setShowAwm(bool $bool) { $this->_queryStatus = self::LINK_QUERY_STATUS; if($bool === true) { $this->_queryStatus = 3; @@ -87,11 +101,12 @@ class Management { * get all the available categories from the DB. * optional limit * optional stats - * @param bool | int $limit + * + * @param bool|int $limit * @param bool $stats * @return array */ - public function categories($limit=false, $stats=false) { + public function categories($limit=false, $stats=false): array { $ret = array(); $statsInfo = array(); @@ -137,11 +152,12 @@ class Management { * get all the available tags from the DB. * optional limit * optional stats - * @param bool | int $limit + * + * @param bool|int $limit * @param bool $stats * @return array */ - public function tags($limit=false, $stats=false) { + public function tags($limit=false, $stats=false): array { $ret = array(); $statsInfo = array(); @@ -184,10 +200,11 @@ class Management { /** * return the latest added links + * * @param int $limit * @return array */ - public function latestLinks($limit=5) { + public function latestLinks($limit=5): array { $ret = array(); $queryStr = "SELECT `title`, `link` FROM `".DB_PREFIX."_link` AS t"; @@ -206,8 +223,10 @@ class Management { /** * get all the categories ordered by link added date + * + * @return array */ - public function categoriesByDateAdded() { + public function categoriesByDateAdded(): array { $ret = array(); $categories = $this->categories(); @@ -224,15 +243,15 @@ class Management { return $ret; } - /** - * find all links by given category string or id. - * Return array sorted by creation date DESC + /** + * find all links by given category string or id. + * Return array sorted by creation date DESC * - * @param int $id Category ID - * @param array $options Array with limit|offset|sort|sortDirection - * @return array - */ - public function linksByCategory($id, $options=array()) { + * @param int $id Category ID + * @param array $options Array with limit|offset|sort|sortDirection + * @return array + */ + public function linksByCategory(int $id, $options=array()): array { $ret = array(); if(!isset($options['limit'])) $options['limit'] = 5; @@ -291,15 +310,15 @@ class Management { return $ret; } - /** - * find all links by given tag string or id. - * Return array sorted by creation date DESC + /** + * find all links by given tag string or id. + * Return array sorted by creation date DESC * - * @param int $id Tag id - * @param array $options Array with limit|offset|sort|sortDirection - * @return array - */ - public function linksByTag($id, $options=array()) { + * @param int $id Tag id + * @param array $options Array with limit|offset|sort|sortDirection + * @return array + */ + public function linksByTag(int $id, $options=array()): array { $ret = array(); if(!isset($options['limit'])) $options['limit'] = 5; @@ -360,11 +379,12 @@ class Management { /** * return all links and Info we have from the combined view - * @param bool | int $limit + * + * @param bool|int $limit * @param bool $offset * @return array */ - public function links($limit=10,$offset=false) { + public function links($limit=10,$offset=false): array { $ret = array(); $querySelect = "SELECT `hash`"; @@ -400,7 +420,7 @@ class Management { * @param int $categoryid * @return array */ - public function latestLinkForCategory($categoryid) { + public function latestLinkForCategory(int $categoryid): array { $ret = array(); if(!empty($categoryid) && is_numeric($categoryid)) { @@ -421,11 +441,12 @@ class Management { /** * Search for the given url in the links table - * @param $url - * @return mixed + * + * @param string $url + * @return array */ - public function searchForLinkByURL($url) { - $ret = false; + public function searchForLinkByURL(string $url): array { + $ret = array(); if(!empty($url)) { $queryStr = "SELECT * FROM `".DB_PREFIX."_link` AS t"; @@ -443,11 +464,12 @@ class Management { /** * search for given searchstring in the search data of the links - * @param $searchStr - * @return mixed + * + * @param string $searchStr + * @return array */ - public function searchForLinkBySearchData($searchStr) { - $ret = false; + public function searchForLinkBySearchData(string $searchStr): array { + $ret = array(); if(!empty($searchStr)) { $queryStr = "SELECT *, @@ -468,9 +490,10 @@ class Management { /** * amount of links in the DB. Status 1 and 2 only + * * @return int */ - public function linkAmount() { + public function linkAmount(): int { $ret = 0; $queryStr = "SELECT COUNT(*) AS amount @@ -489,9 +512,10 @@ class Management { /** * amount of tags + * * @return int */ - public function tagAmount() { + public function tagAmount(): int { $ret = 0; $queryStr = "SELECT COUNT(*) AS amount FROM `".DB_PREFIX."_tag`"; @@ -507,9 +531,10 @@ class Management { /** * amount of categories + * * @return int */ - public function categoryAmount() { + public function categoryAmount(): int { $ret = 0; $queryStr = "SELECT COUNT(*) AS amount FROM `".DB_PREFIX."_category`"; @@ -525,9 +550,10 @@ class Management { /** * Amount of links need moderation + * * @return int */ - public function moderationAmount() { + public function moderationAmount(): int { $ret = 0; $queryStr = "SELECT COUNT(*) AS amount FROM `".DB_PREFIX."_link`"; @@ -544,9 +570,10 @@ class Management { /** * get the used disk space for local image storage - * @return false|int + * + * @return int */ - public function storageAmount() { + public function storageAmount(): int { $ret = 0; $_storageFolder = ABSOLUTE_PATH.'/'.LOCAL_STORAGE; @@ -560,9 +587,10 @@ class Management { /** * empties the local storage directory + * * @return bool */ - public function clearLocalStorage() { + public function clearLocalStorage(): bool { $ret = false; $_storageFolder = ABSOLUTE_PATH.'/'.LOCAL_STORAGE; @@ -577,12 +605,13 @@ class Management { /** * Load link by given hash. Do not use Link class directly. * Otherwise the authentication will be ignored. - * @param String $hash Link hash + * + * @param String $hash Link hash * @param bool $fullInfo Load all the info we have * @param bool $withObject An array with data and the link obj itself - * @return array|mixed + * @return array */ - public function loadLink($hash,$fullInfo=true,$withObject=false) { + public function loadLink(string $hash, $fullInfo=true, $withObject=false): array { $ret = array(); if (!empty($hash)) { @@ -616,10 +645,11 @@ class Management { /** * Delete link by given hash - * @param $hash + * + * @param string $hash * @return bool */ - public function deleteLink($hash) { + public function deleteLink(string $hash): bool { $ret = false; if (!empty($hash)) { @@ -641,11 +671,12 @@ class Management { /** * Export given link for download as a xml file - * @param $hash - * @param bool $linkObj Use already existing link obj + * + * @param string $hash + * @param bool|Link $linkObj Use already existing link obj * @return bool */ - public function exportLinkData($hash,$linkObj=false) { + public function exportLinkData(string $hash, $linkObj=false): bool { $ret = false; if (!empty($hash)) { @@ -670,8 +701,10 @@ class Management { /** * for simpler management we have the search data in a separate column * it is not fancy or even technical nice but it damn works + * + * @return boolean */ - public function updateSearchIndex() { + public function updateSearchIndex(): bool { $ret = false; $allLinks = array(); @@ -715,11 +748,12 @@ class Management { /** * process the given xml file. Based on the export file * options are overwrite => true|false - * @param $file - * @param $options + * + * @param string $file + * @param array $options * @return array */ - public function processImportFile($file, $options) { + public function processImportFile(string $file, array $options): array { $ret = array( 'status' => 'error', 'message' => 'Processing error' @@ -819,9 +853,10 @@ class Management { /** * Return the query string for the correct status type + * * @return string */ - private function _decideLinkTypeForQuery() { + private function _decideLinkTypeForQuery(): string { switch ($this->_queryStatus) { case 1: $ret = "t.status IN (2,1)"; @@ -838,10 +873,11 @@ class Management { /** * Check if given id (not hash) exists in link database - * @param $id + * + * @param integer $id * @return bool */ - private function _linkExistsById($id) { + private function _linkExistsById($id): bool { $ret = false; if(!empty($id)) { diff --git a/webroot/lib/simple-imap.class.php b/webroot/lib/simple-imap.class.php index 4eef04a..8b09bc1 100644 --- a/webroot/lib/simple-imap.class.php +++ b/webroot/lib/simple-imap.class.php @@ -3,7 +3,7 @@ * Insipid * Personal web-bookmark-system * - * Copyright 2016-2020 Johannes Keßler + * Copyright 2016-2021 Johannes Keßler * * Development starting from 2011: Johannes Keßler * https://www.bananas-playground.net/projekt/insipid/ @@ -45,11 +45,17 @@ class SimpleImap { private $_connectionstring = ''; + /** + * SimpleImap constructor. + */ function __construct() { # create the mailboxstring $this->_connectionstring = '{'.$this->_server.':'.$this->_port.'/imap/ssl}'; } + /** + * + */ function __destruct() { imap_close($this->_connection); } @@ -84,11 +90,12 @@ class SimpleImap { /** * process the given mailbox and check for the special messages * return the body and headers from the found message + * * @param string $subjectmarker * @return array emailId => array(body, header); * @throws Exception */ - function messageWithValidSubject($subjectmarker) { + function messageWithValidSubject(string $subjectmarker): array { $ret = array(); $messagecount = imap_num_msg($this->_connection); @@ -160,38 +167,42 @@ class SimpleImap { /** * This function causes a fetch of the complete, unfiltered RFC2822 format header of the specified message. - * @param $messagenum Int + * + * @param integer $messagenum * @return string */ - public function emailHeaders($messagenum) { + public function emailHeaders(int $messagenum): string { return imap_fetchheader($this->_connection, $messagenum); } /** * return the email headers by given emailid - * @param $messagenum + * + * @param integer $messagenum * @return object */ - public function emailHeaders_rfc822($messagenum) { + public function emailHeaders_rfc822(int $messagenum) { return imap_rfc822_parse_headers($this->emailHeaders($messagenum)); } /** * Email headers parsed as an array - * @param $messagenum + * + * @param integer $messagenum * @return array */ - public function emailHeadersAsArray($messagenum) { + public function emailHeadersAsArray(int $messagenum): array { preg_match_all('/([^: ]+): (.+?(?:\r\n\s(?:.+?))*)\r\n/m', $this->emailHeaders($messagenum), $matches ); return array_combine( $matches[1], $matches[2]); } - /** - * Move given message to given folder - * @param $messageUid This is the message Uid as an int - * @param string $folder This is the target folder. Default is EMAIL_ARCHIVE_FOLDER - */ - public function moveMessage($messageUid,$folder=EMAIL_ARCHIVE_FOLDER) { + /** + * Move given message to given folder + * + * @param integer $messageUid This is the message Uid as an int + * @param string $folder This is the target folder. Default is EMAIL_ARCHIVE_FOLDER + */ + public function moveMessage(int $messageUid, $folder=EMAIL_ARCHIVE_FOLDER) { if(!empty($messageUid) && !empty($folder)) { $messageUid = (string)$messageUid; imap_setflag_full($this->_connection,$messageUid,"\SEEN", ST_UID); @@ -207,7 +218,7 @@ class SimpleImap { * @param int $messagenum * @return string */ - private function _extractSubject($messagenum) { + private function _extractSubject(int $messagenum): string { $ret = ''; $headerinfo = $this->emailHeaders_rfc822($messagenum); @@ -221,12 +232,13 @@ class SimpleImap { /** * extract the body of the given message + * * @see http://php.net/manual/en/function.imap-fetchstructure.php * * @param int $messagenum * @return string */ - private function _extractBody($messagenum) { + private function _extractBody(int $messagenum): string { $ret = ''; $emailstructure = imap_fetchstructure($this->_connection, $messagenum); diff --git a/webroot/lib/snapshot.class.php b/webroot/lib/snapshot.class.php index aa341af..895c0c1 100644 --- a/webroot/lib/snapshot.class.php +++ b/webroot/lib/snapshot.class.php @@ -3,7 +3,7 @@ * Insipid * Personal web-bookmark-system * - * Copyright 2016-2020 Johannes Keßler + * Copyright 2016-2021 Johannes Keßler * * Development starting from 2011: Johannes Keßler * https://www.bananas-playground.net/projekt/insipid/ @@ -32,19 +32,30 @@ * right now it uses google pagespeedonline. */ class Snapshot { + /** + * @var string + */ private $_googlePageSpeed = 'https://www.googleapis.com/pagespeedonline/v2/runPagespeed?url='; + + /** + * @var string + */ private $_wkhtmltoimageOptions = '--load-error-handling ignore --quality 80 --quiet --width 1900'; + /** + * Snapshot constructor + */ public function __constructor() {} /** * call given url with google PageSpeed API - * to recieve image data + * to receive image data * * @param String $url URL to take a thumbnail from - * @return + * @param string $filename + * @return boolean */ - public function doSnapshot($url,$filename) { + public function doSnapshot(string $url, string $filename): bool { $ret = false; if(!empty($url) && is_writable(dirname($filename))) { @@ -64,13 +75,14 @@ class Snapshot { } /** - * use configired WKHTMLTOPDF_COMMAND to create a whole page screenshot + * use configured WKHTMLTOPDF_COMMAND to create a whole page screenshot * of the given link and store it locally * * @param String $url URL to take the screenshot from - * @return + * @param string $filename + * @return boolean */ - public function wholePageSnpashot($url,$filename) { + public function wholePageSnpashot(string $url, string $filename): bool { $ret = false; require_once 'lib/shellcommand.class.php'; @@ -89,4 +101,4 @@ class Snapshot { return $ret; } -} \ No newline at end of file +} diff --git a/webroot/lib/summoner.class.php b/webroot/lib/summoner.class.php index 1406722..15d4d45 100644 --- a/webroot/lib/summoner.class.php +++ b/webroot/lib/summoner.class.php @@ -3,7 +3,7 @@ * Insipid * Personal web-bookmark-system * - * Copyright 2016-2020 Johannes Keßler + * Copyright 2016-2021 Johannes Keßler * * Development starting from 2011: Johannes Keßler * https://www.bananas-playground.net/projekt/insipid/ @@ -50,7 +50,7 @@ class Summoner { * * @return bool */ - static function validate($input,$mode='text',$limit=false) { + static function validate($input,$mode='text',$limit=false): bool { // check if we have input $input = trim($input); @@ -131,12 +131,13 @@ class Summoner { /** * execute a curl call to the given $url + * * @param string $url The request url * @param bool $port - * @return bool|mixed + * @return string */ - static function curlCall($url,$port=false) { - $ret = false; + static function curlCall(string $url, $port=false): string { + $ret = ''; $ch = curl_init(); @@ -171,12 +172,13 @@ class Summoner { /** * Download given url to given file - * @param $url - * @param $whereToStore + * + * @param string $url + * @param string $whereToStore * @param bool $port * @return bool */ - static function downloadFile($url, $whereToStore, $port=false) { + static function downloadFile(string $url, string $whereToStore, $port=false): bool { $fh = fopen($whereToStore, 'w+'); $ret = false; @@ -210,21 +212,22 @@ class Summoner { * this only works with arrays and checking if the key is there and echo/return it. * http://php.net/manual/en/migration70.new-features.php#migration70.new-features.null-coalesce-op * - * @param $array - * @param $key + * @param array $array + * @param string $key * @return bool */ - static function ifset($array,$key) { + static function ifset(array $array, string $key): bool { return isset($array[$key]) ? $array[$key] : false; } /** * try to gather meta information from given URL + * * @param string $url - * @return array|bool + * @return array */ - static function gatherInfoFromURL($url) { - $ret = false; + static function gatherInfoFromURL(string $url): array { + $ret = array(); if(self::validate($url,'url')) { $data = self::curlCall($url); @@ -239,10 +242,11 @@ class Summoner { /** * get as much as possible social meta infos from given string * the string is usually a HTML source + * * @param string $string * @return array */ - static function socialMetaInfos($string) { + static function socialMetaInfos(string $string): array { #http://www.w3bees.com/2013/11/fetch-facebook-og-meta-tags-with-php.html #http://www.9lessons.info/2014/01/social-meta-tags-for-google-twitter-and.html #http://ogp.me/ @@ -335,7 +339,7 @@ class Summoner { * @param string $string * @return array */ - static function prepareTagOrCategoryStr($string) { + static function prepareTagOrCategoryStr(string $string): array { $ret = array(); $_ret = array(); @@ -400,10 +404,11 @@ class Summoner { /** * check if we have a valid auth. Nothing more. + * * @see Summoner::simpleAuth to trigger the auth * @return bool */ - static function simpleAuthCheck() { + static function simpleAuthCheck(): bool { if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW']) && $_SERVER['PHP_AUTH_USER'] === FRONTEND_USERNAME && $_SERVER['PHP_AUTH_PW'] === FRONTEND_PASSWORD ) { @@ -415,10 +420,11 @@ class Summoner { /** * Checks if in the given urlstring a scheme is existent. If not add http:// to it - * @param $urlString + * + * @param string $urlString * @return string */ - static function addSchemeToURL($urlString) { + static function addSchemeToURL($urlString): string { $ret = $urlString; if(empty(parse_url($ret, PHP_URL_SCHEME))) { @@ -428,12 +434,13 @@ class Summoner { return $ret; } - /** - * retrieve the folder size with its children of given folder path - * @param $folder - * @return false|int - */ - static function folderSize($folder) { + /** + * retrieve the folder size with its children of given folder path + * + * @param string $folder + * @return int + */ + static function folderSize(string $folder): int { $ret = 0; if(file_exists($folder) && is_readable($folder)) { @@ -445,13 +452,14 @@ class Summoner { return $ret; } - /** - * Calculate the given byte size in more human readable format. - * @param $size - * @param string $unit - * @return string - */ - static function humanFileSize($size,$unit="") { + /** + * Calculate the given byte size in more human readable format. + * + * @param integer $size + * @param string $unit + * @return string + */ + static function humanFileSize(int $size, $unit=""): string { $ret = number_format($size)." bytes"; if((!$unit && $size >= 1<<30) || $unit == "GB") { @@ -467,17 +475,17 @@ class Summoner { return $ret; } - /** - * delete and/or empty a directory - * - * $empty = true => empty the directory but do not delete it - * - * @param string $directory - * @param boolean $empty - * @param int $fTime If not false remove files older then this value in sec. - * @return boolean - */ - static function recursive_remove_directory($directory,$empty=false,$fTime=0) { + /** + * delete and/or empty a directory + * + * $empty = true => empty the directory but do not delete it + * + * @param string $directory + * @param boolean $empty + * @param int $fTime If not false remove files older then this value in sec. + * @return boolean + */ + static function recursive_remove_directory(string $directory, $empty=false, $fTime=0): bool { if(substr($directory,-1) == '/') { $directory = substr($directory,0,-1); } @@ -524,16 +532,16 @@ class Summoner { } } - /** - * http_build_query with modify array - * modify will add: key AND value not empty - * modify will remove: only key with no value - * - * @param $array - * @param bool $modify - * @return string - */ - static function createFromParameterLinkQuery($array,$modify=false) { + /** + * http_build_query with modify array + * modify will add: key AND value not empty + * modify will remove: only key with no value + * + * @param array $array + * @param bool $modify + * @return string + */ + static function createFromParameterLinkQuery(array $array, $modify=false): string { $ret = ''; if(!empty($modify)) { diff --git a/webroot/lib/tag.class.php b/webroot/lib/tag.class.php index 0207e8c..d89c375 100644 --- a/webroot/lib/tag.class.php +++ b/webroot/lib/tag.class.php @@ -3,7 +3,7 @@ * Insipid * Personal web-bookmark-system * - * Copyright 2016-2020 Johannes Keßler + * Copyright 2016-2021 Johannes Keßler * * Development starting from 2011: Johannes Keßler * https://www.bananas-playground.net/projekt/insipid/ @@ -26,35 +26,48 @@ * */ +/** + * Class Tag + */ class Tag { /** * the database object + * * @var object */ private $DB; /** * the current loaded tag by DB id + * * @var int */ private $_id; /** * current loaded tag data + * * @var array */ private $_data; + /** + * Tag constructor. + * + * @param Obnject $databaseConnectionObject + */ public function __construct($databaseConnectionObject) { $this->DB = $databaseConnectionObject; } - /** - * by given string load the info from the DB and even create if not existing - * @param string $string - * @return int 0=fail, 1=existing, 2=new, 3=newNotCreated - */ - public function initbystring($string, $doNotCreate=false) { + /** + * by given string load the info from the DB and even create if not existing + * + * @param string $string + * @param bool $doNotCreate + * @return int 0=fail, 1=existing, 2=new, 3=newNotCreated + */ + public function initbystring(string $string, $doNotCreate=false): int { $ret = 0; $this->_id = false; if(!empty($string)) { @@ -89,11 +102,12 @@ class Tag { /** * by given DB table id load all the info we need + * * @param int $id - * @return bool|int + * @return int */ - public function initbyid($id) { - $this->_id = false; + public function initbyid(int $id): int { + $this->_id = 0; if(!empty($id)) { $queryStr = "SELECT `id`,`name` FROM `".DB_PREFIX."_tag` @@ -111,8 +125,9 @@ class Tag { /** * return all or data fpr given key on the current loaded tag + * * @param bool $key - * @return array|mixed + * @return array|string */ public function getData($key=false) { $ret = $this->_data; @@ -124,12 +139,13 @@ class Tag { return $ret; } - /** - * set the relation to the given link to the loaded tag - * @param int $linkid - * @return void - */ - public function setRelation($linkid) { + /** + * set the relation to the given link to the loaded tag + * + * @param int $linkid + * @return void + */ + public function setRelation(int $linkid) { if(!empty($linkid) && !empty($this->_id)) { $queryStr = "INSERT IGNORE INTO `".DB_PREFIX."_tagrelation` SET `linkid` = '".$this->DB->real_escape_string($linkid)."', @@ -140,9 +156,10 @@ class Tag { /** * Return an array of any linkid related to the current loaded tag + * * @return array */ - public function getReleations() { + public function getReleations(): array { $ret = array(); $queryStr = "SELECT linkid @@ -160,9 +177,10 @@ class Tag { /** * deletes the current loaded tag from db + * * @return boolean */ - public function delete() { + public function delete(): bool { $ret = false; if(!empty($this->_id)) { @@ -193,12 +211,13 @@ class Tag { return $ret; } - /** - * Rename current loaded tag name - * @param $newValue - * @return void - */ - public function rename($newValue) { + /** + * Rename current loaded tag name + * + * @param string $newValue + * @return void + */ + public function rename(string $newValue) { if(!empty($newValue)) { $queryStr = "UPDATE `".DB_PREFIX."_tag` SET `name` = '".$this->DB->real_escape_string($newValue)."' diff --git a/webroot/lib/translation.class.php b/webroot/lib/translation.class.php index 7eec61d..a3f5493 100644 --- a/webroot/lib/translation.class.php +++ b/webroot/lib/translation.class.php @@ -43,6 +43,9 @@ class Translation { */ private $_langData = array(); + /** + * Translation constructor. + */ public function __construct() { $_langFile = ABSOLUTE_PATH.'/lib/lang/'.$this->_defaultLangToUse.'.lang.ini'; if(defined('FRONTEND_LANGUAGE')) { @@ -65,10 +68,10 @@ class Translation { /** * Return text for given key for currently loaded lang * - * @param $key + * @param string $key * @return string */ - public function t($key) { + public function t(string $key): string { $ret = $key; if(isset($this->_langData[$key])) { $ret = $this->_langData[$key]; diff --git a/webroot/view/editcategories.inc.php b/webroot/view/editcategories.inc.php index d9e943d..dbeeef8 100644 --- a/webroot/view/editcategories.inc.php +++ b/webroot/view/editcategories.inc.php @@ -3,7 +3,7 @@ * Insipid * Personal web-bookmark-system * - * Copyright 2016-2020 Johannes Keßler + * Copyright 2016-2021 Johannes Keßler * * Development starting from 2011: Johannes Keßler * https://www.bananas-playground.net/projekt/insipid/ @@ -67,7 +67,7 @@ if(isset($_POST['category']) && !empty($_POST['category']) && isset($_POST['upda $catDoNotDeleteFromUpdate[$catObjAlternative->getData('id')] = $catObjAlternative->getData('id'); $catObjOld = new Category($DB); if(!empty($catObjOld->initbyid($k))) { - $linksToUpdate = $catObjOld->getReleations(); + $linksToUpdate = $catObjOld->getRelations(); if(!empty($linksToUpdate)) { foreach($linksToUpdate as $linkId) { $catObjAlternative->setRelation($linkId); @@ -100,7 +100,7 @@ if(isset($_POST['category']) && !empty($_POST['category']) && isset($_POST['upda if($v == "delete" && !isset($catDoNotDeleteFromUpdate[$k])) { $catObj = new Category($DB); $load = $catObj->initbyid($k); - if($load !== false) { + if(!empty($load)) { $catObj->delete(); } else { -- 2.39.5