From 5456eb6530e4ebab76bcedc01a66636951791c02 Mon Sep 17 00:00:00 2001 From: Banana Date: Tue, 27 Dec 2022 12:48:18 +0100 Subject: [PATCH] more php8.1 syntax --- webroot/index.php | 2 -- webroot/lib/link.class.php | 4 ++-- webroot/lib/snapshot.class.php | 11 +++++++---- webroot/lib/summoner.class.php | 22 +++++++++++----------- webroot/lib/tag.class.php | 2 +- webroot/lib/translation.class.php | 6 +++--- webroot/view/editlink.inc.php | 8 ++++---- webroot/view/home.inc.php | 2 +- webroot/view/linkinfo.inc.php | 4 ++-- webroot/view/overview.inc.php | 16 ++++++++-------- webroot/view/stats.inc.php | 1 - 11 files changed, 39 insertions(+), 39 deletions(-) diff --git a/webroot/index.php b/webroot/index.php index 40ead7c..40c815c 100644 --- a/webroot/index.php +++ b/webroot/index.php @@ -62,8 +62,6 @@ require('lib/translation.class.php'); ## main vars $Summoner = new Summoner(); -# database object -$DB = false; # the template data as an array $TemplateData = array(); # translation diff --git a/webroot/lib/link.class.php b/webroot/lib/link.class.php index 0354bd6..46da7f0 100644 --- a/webroot/lib/link.class.php +++ b/webroot/lib/link.class.php @@ -308,14 +308,14 @@ class Link { } } - # decide if we want to make a local full page scrrenshot + # decide if we want to make a local full page screenshot if(isset($data['pagescreenshot'])) { $pagescreenshot = ABSOLUTE_PATH . '/' . LOCAL_STORAGE . '/pagescreenshot-' . $this->_data['hash'].'.jpg'; if ($data['pagescreenshot'] === true) { if (!file_exists($pagescreenshot) || $_imageUrlChanged === true) { require_once 'lib/snapshot.class.php'; $snap = new Snapshot(); - $do = $snap->wholePageSnpashot($this->_data['link'], $pagescreenshot); + $do = $snap->wholePageSnapshot($this->_data['link'], $pagescreenshot); if(!empty($do)) { error_log('ERROR Failed to create snapshot: '.var_export($data,true)); } diff --git a/webroot/lib/snapshot.class.php b/webroot/lib/snapshot.class.php index 1e0f4c9..d7fdb40 100644 --- a/webroot/lib/snapshot.class.php +++ b/webroot/lib/snapshot.class.php @@ -35,17 +35,17 @@ class Snapshot { /** * @var string */ - private $_googlePageSpeed = 'https://www.googleapis.com/pagespeedonline/v2/runPagespeed?url='; + private string $_googlePageSpeed = 'https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url='; /** * @var string */ - private $_wkhtmltoimageOptions = '--load-error-handling ignore --quality 80 --quiet --width 1900'; + private string $_wkhtmltoimageOptions = '--load-error-handling ignore --quality 80 --quiet --width 1900'; /** * Snapshot constructor */ - public function __constructor() {} + public function __constructor(): void {} /** * call given url with google PageSpeed API @@ -58,6 +58,9 @@ class Snapshot { public function doSnapshot(string $url, string $filename): bool { $ret = false; + // new path in jason + // lighthouseResult audits full-page-screenshot details screenshot data (base64 encoded) + if(!empty($url) && is_writable(dirname($filename))) { $theCall = Summoner::curlCall($this->_googlePageSpeed.urlencode($url).'&screenshot=true'); if(!empty($theCall)) { @@ -82,7 +85,7 @@ class Snapshot { * @param string $filename * @return boolean */ - public function wholePageSnpashot(string $url, string $filename): bool { + public function wholePageSnapshot(string $url, string $filename): bool { $ret = false; require_once 'lib/shellcommand.class.php'; diff --git a/webroot/lib/summoner.class.php b/webroot/lib/summoner.class.php index 3d036be..4efd73c 100644 --- a/webroot/lib/summoner.class.php +++ b/webroot/lib/summoner.class.php @@ -133,10 +133,10 @@ class Summoner { * execute a curl call to the given $url * * @param string $url The request url - * @param bool $port + * @param int $port * @return string */ - static function curlCall(string $url, $port=false): string { + static function curlCall(string $url, int $port=0): string { $ret = ''; $ch = curl_init(); @@ -175,10 +175,10 @@ class Summoner { * * @param string $url * @param string $whereToStore - * @param bool $port + * @param int $port * @return bool */ - static function downloadFile(string $url, string $whereToStore, $port=false): bool { + static function downloadFile(string $url, string $whereToStore, int $port=0): bool { $fh = fopen($whereToStore, 'w+'); $ret = false; @@ -216,7 +216,7 @@ class Summoner { * @param string $key * @return mixed */ - static function ifset(array $array, string $key) { + static function ifset(array $array, string $key): mixed { return $array[$key] ?? false; } @@ -424,7 +424,7 @@ class Summoner { * @param string $urlString * @return string */ - static function addSchemeToURL($urlString): string { + static function addSchemeToURL(string $urlString): string { $ret = $urlString; if(empty(parse_url($ret, PHP_URL_SCHEME))) { @@ -459,7 +459,7 @@ class Summoner { * @param string $unit * @return string */ - static function humanFileSize(int $size, $unit=""): string { + static function humanFileSize(int $size, string $unit=""): string { $ret = number_format($size)." bytes"; if((!$unit && $size >= 1<<30) || $unit == "GB") { @@ -485,7 +485,7 @@ class Summoner { * @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 { + static function recursive_remove_directory(string $directory, bool $empty=false, int $fTime=0): bool { if(substr($directory,-1) == '/') { $directory = substr($directory,0,-1); } @@ -508,7 +508,7 @@ class Summoner { recursive_remove_directory($path); } else { - if($fTime !== false && is_int($fTime)) { + if(!empty($fTime) && is_int($fTime)) { $ft = filemtime($path); $offset = time()-$fTime; if($ft <= $offset) { @@ -538,10 +538,10 @@ class Summoner { * modify will remove: only key with no value * * @param array $array - * @param bool $modify + * @param array $modify * @return string */ - static function createFromParameterLinkQuery(array $array, $modify=false): string { + static function createFromParameterLinkQuery(array $array, array $modify=array()): string { $ret = ''; if(!empty($modify)) { diff --git a/webroot/lib/tag.class.php b/webroot/lib/tag.class.php index 239ce02..2fd46ce 100644 --- a/webroot/lib/tag.class.php +++ b/webroot/lib/tag.class.php @@ -3,7 +3,7 @@ * Insipid * Personal web-bookmark-system * - * Copyright 2016-2021 Johannes Keßler + * Copyright 2016-2022 Johannes Keßler * * Development starting from 2011: Johannes Keßler * https://www.bananas-playground.net/projekt/insipid/ diff --git a/webroot/lib/translation.class.php b/webroot/lib/translation.class.php index a3f5493..7cdd678 100644 --- a/webroot/lib/translation.class.php +++ b/webroot/lib/translation.class.php @@ -3,7 +3,7 @@ * Insipid * Personal web-bookmark-system * - * Copyright 2016-2021 Johannes Keßler + * Copyright 2016-2022 Johannes Keßler * * Development starting from 2011: Johannes Keßler * https://www.bananas-playground.net/projekt/insipid/ @@ -36,12 +36,12 @@ class Translation { /** * @var string The lang code */ - private $_defaultLangToUse = 'eng'; + private string $_defaultLangToUse = 'eng'; /** * @var array The loaded lang information from the file */ - private $_langData = array(); + private array $_langData = array(); /** * Translation constructor. diff --git a/webroot/view/editlink.inc.php b/webroot/view/editlink.inc.php index a84fa0e..75cc19e 100644 --- a/webroot/view/editlink.inc.php +++ b/webroot/view/editlink.inc.php @@ -33,10 +33,10 @@ $formData = array(); # can/should be extended in the future. Summoner::simpleAuth(); -$_id = false; +$_id = ''; if(isset($_GET['id']) && !empty($_GET['id'])) { $_id = trim($_GET['id']); - $_id = Summoner::validate($_id,'nospace') ? $_id : false; + $_id = Summoner::validate($_id,'nospace') ? $_id : ''; } $_isAwm = false; @@ -46,10 +46,10 @@ if(isset($_GET['awm']) && !empty($_GET['awm'])) { $Management->setShowAwm($_isAwm); } -$_requestMode = false; +$_requestMode = ''; if(isset($_GET['m']) && !empty($_GET['m'])) { $_requestMode = trim($_GET['m']); - $_requestMode = Summoner::validate($_requestMode,'nospace') ? $_requestMode : false; + $_requestMode = Summoner::validate($_requestMode,'nospace') ? $_requestMode : ''; } $linkData = $Management->loadLink($_id); diff --git a/webroot/view/home.inc.php b/webroot/view/home.inc.php index a858581..6b4bded 100644 --- a/webroot/view/home.inc.php +++ b/webroot/view/home.inc.php @@ -35,7 +35,7 @@ $showAddForm = false; $honeypotCheck = false; $formData = array(); -$_requestMode = false; +$_requestMode = ''; if(isset($_GET['m']) && !empty($_GET['m'])) { $_requestMode = trim($_GET['m']); $_requestMode = Summoner::validate($_requestMode,'nospace') ? $_requestMode : "all"; diff --git a/webroot/view/linkinfo.inc.php b/webroot/view/linkinfo.inc.php index a64a3d3..36f95b7 100644 --- a/webroot/view/linkinfo.inc.php +++ b/webroot/view/linkinfo.inc.php @@ -26,10 +26,10 @@ * */ -$_id = false; +$_id = ''; if(isset($_GET['id']) && !empty($_GET['id'])) { $_id = trim($_GET['id']); - $_id = Summoner::validate($_id,'nospace') ? $_id : false; + $_id = Summoner::validate($_id,'nospace') ? $_id : ''; } $linkData = $Management->loadLink($_id); diff --git a/webroot/view/overview.inc.php b/webroot/view/overview.inc.php index 4adedf0..146a5bd 100644 --- a/webroot/view/overview.inc.php +++ b/webroot/view/overview.inc.php @@ -27,16 +27,16 @@ */ $currentGetParameters['p'] = 'overview'; -$_requestMode = false; +$_requestMode = ''; if(isset($_GET['m']) && !empty($_GET['m'])) { $_requestMode = trim($_GET['m']); - $_requestMode = Summoner::validate($_requestMode,'nospace') ? $_requestMode : false; + $_requestMode = Summoner::validate($_requestMode,'nospace') ? $_requestMode : ''; } -$_id = false; +$_id = ''; if(isset($_GET['id']) && !empty($_GET['id'])) { $_id = trim($_GET['id']); - $_id = Summoner::validate($_id,'digit') ? $_id : false; + $_id = Summoner::validate($_id,'digit') ? $_id : ''; } $_curPage = 1; @@ -45,16 +45,16 @@ if(isset($_GET['page']) && !empty($_GET['page'])) { $_curPage = Summoner::validate($_curPage,'digit') ? $_curPage : 1; } -$_sort = false; +$_sort = ''; if(isset($_GET['s']) && !empty($_GET['s'])) { $_sort = trim($_GET['s']); - $_sort = Summoner::validate($_sort,'nospace') ? $_sort : false; + $_sort = Summoner::validate($_sort,'nospace') ? $_sort : ''; } -$_sortDirection = false; +$_sortDirection = ''; if(isset($_GET['sd']) && !empty($_GET['sd'])) { $_sortDirection = trim($_GET['sd']); - $_sortDirection = Summoner::validate($_sortDirection,'nospace') ? $_sortDirection : false; + $_sortDirection = Summoner::validate($_sortDirection,'nospace') ? $_sortDirection : ''; } $linkCollection = array(); diff --git a/webroot/view/stats.inc.php b/webroot/view/stats.inc.php index 27dbc48..9ba2f3f 100644 --- a/webroot/view/stats.inc.php +++ b/webroot/view/stats.inc.php @@ -32,7 +32,6 @@ if(Summoner::simpleAuthCheck() === true) { } if(isset($_POST['statsDeleteLocalStorage'])) { - if($Management->clearLocalStorage() === true) { $TemplateData['refresh'] = 'index.php?p=stats'; } -- 2.39.5