From 4527df602fcc7efdf400ab1fecbcad78fa54a870 Mon Sep 17 00:00:00 2001 From: Art4 Date: Tue, 26 Nov 2024 07:55:01 +0000 Subject: [PATCH 01/10] Add checks for CLD2Detector ans CLD2Encoding classes --- cld/cld.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cld/cld.php b/cld/cld.php index 5ca4c932..83361e2b 100644 --- a/cld/cld.php +++ b/cld/cld.php @@ -22,6 +22,16 @@ function cld_detect_languages(array &$data) return; } + if (!class_exists('CLD2Detector')) { + Logger::warning('CLD2Detector class does not exist.'); + return; + } + + if (!class_exists('CLD2Encoding')) { + Logger::warning('CLD2Encoding class does not exist.'); + return; + } + $cld2 = new \CLD2Detector(); $cld2->setEncodingHint(CLD2Encoding::UTF8); // optional, hints about text encoding From 9d172b70822ef58fcea267b05691c4a2afbad143 Mon Sep 17 00:00:00 2001 From: Art4 Date: Tue, 26 Nov 2024 08:23:27 +0000 Subject: [PATCH 02/10] refactor convert addon, replace each() calls with foreach loop --- convert/convert.php | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/convert/convert.php b/convert/convert.php index 57ce6ea8..2c97e2aa 100644 --- a/convert/convert.php +++ b/convert/convert.php @@ -6,7 +6,6 @@ * Author: Mike Macgirvin */ -use Friendica\App; use Friendica\Core\Hook; function convert_install() { @@ -26,7 +25,7 @@ function convert_content() { // @TODO Let's one day rewrite this to a modern composer package include 'UnitConvertor.php'; - class TP_Converter extends UnitConvertor + $conv = new class('en') extends UnitConvertor { public function __construct(string $lang = 'en') { @@ -43,7 +42,7 @@ function convert_content() { private function findBaseUnit($from, $to) { - while (list($skey, $sval) = each($this->bases)) { + foreach ($this->bases as $skey => $sval) { if ($skey == $from || $to == $skey || in_array($to, $sval) || in_array($from, $sval)) { return $skey; } @@ -63,7 +62,7 @@ function convert_content() { $cells[] = $cell; // We now have the base unit and value now lets produce the table; - while (list($key, $val) = each($this->bases[$base_unit])) { + foreach ($this->bases[$base_unit] as $val) { $cell ['value'] = $this->convert($value, $from_unit, $val, $precision) . ' ' . $val; $cell ['class'] = ($val == $from_unit || $val == $to_unit) ? 'framedred' : ''; $cells[] = $cell; @@ -86,9 +85,7 @@ function convert_content() { return $string; } - } - - $conv = new TP_Converter('en'); + }; $conversions = [ 'Temperature' => ['base' => 'Celsius', @@ -176,10 +173,10 @@ function convert_content() { ] ]; - while (list($key, $val) = each($conversions)) { + foreach ($conversions as $key => $val) { $conv->addConversion($val['base'], $val['conv']); $list[$key][] = $val['base']; - while (list($ukey, $uval) = each($val['conv'])) { + foreach ($val['conv'] as $ukey => $uval) { $list[$key][] = $ukey; } } @@ -202,10 +199,9 @@ function convert_content() { $o .= ''; $o .= '