From a6bbbd738fe662a66e9c5105bd04331f5c24ecdc Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 11 Oct 2023 19:20:51 +0000 Subject: [PATCH] Added check for IntlChar module --- doc/Install.md | 4 ++-- src/Core/Installer.php | 29 +++++++++++++++++------------ src/Model/Item.php | 23 +++++++++++++---------- 3 files changed, 32 insertions(+), 24 deletions(-) diff --git a/doc/Install.md b/doc/Install.md index bf9dffb357..dc390fbc8a 100644 --- a/doc/Install.md +++ b/doc/Install.md @@ -28,9 +28,9 @@ Due to the large variety of operating systems and PHP platforms in existence we ### Requirements * Apache with mod-rewrite enabled and "Options All" so you can use a local `.htaccess` file -* PHP 7.3+ (PHP8 is not fully supported yet) +* PHP 7.3+ * PHP *command line* access with register_argc_argv set to true in the php.ini file - * Curl, GD, GMP, PDO, mbstrings, MySQLi, hash, xml, zip and OpenSSL extensions + * Curl, GD, GMP, PDO, mbstrings, MySQLi, hash, xml, zip, IntlChar and OpenSSL extensions * The POSIX module of PHP needs to be activated (e.g. [RHEL, CentOS](http://www.bigsoft.co.uk/blog/index.php/2014/12/08/posix-php-commands-not-working-under-centos-7) have disabled it) * Some form of email server or email gateway such that PHP mail() works. If you cannot set up your own email server, you can use the [phpmailer](https://github.com/friendica/friendica-addons/tree/develop/phpmailer) addon and use a remote SMTP server. diff --git a/src/Core/Installer.php b/src/Core/Installer.php index 583ad5fe28..68f40c01a1 100644 --- a/src/Core/Installer.php +++ b/src/Core/Installer.php @@ -384,12 +384,10 @@ class Installer $help = ''; $status = true; - if (function_exists('apache_get_modules')) { - if (!in_array('mod_rewrite', apache_get_modules())) { - $help = DI::l10n()->t('Error: Apache webserver mod-rewrite module is required but not installed.'); - $status = false; - $returnVal = false; - } + if (function_exists('apache_get_modules') && !in_array('mod_rewrite', apache_get_modules())) { + $help = DI::l10n()->t('Error: Apache webserver mod-rewrite module is required but not installed.'); + $status = false; + $returnVal = false; } $this->addCheck(DI::l10n()->t('Apache mod_rewrite module'), $status, true, $help); @@ -399,15 +397,22 @@ class Installer $status = false; $help = DI::l10n()->t('Error: PDO or MySQLi PHP module required but not installed.'); $returnVal = false; - } else { - if (!function_exists('mysqli_connect') && class_exists('pdo') && !in_array('mysql', \PDO::getAvailableDrivers())) { - $status = false; - $help = DI::l10n()->t('Error: The MySQL driver for PDO is not installed.'); - $returnVal = false; - } + } elseif (!function_exists('mysqli_connect') && class_exists('pdo') && !in_array('mysql', \PDO::getAvailableDrivers())) { + $status = false; + $help = DI::l10n()->t('Error: The MySQL driver for PDO is not installed.'); + $returnVal = false; } $this->addCheck(DI::l10n()->t('PDO or MySQLi PHP module'), $status, true, $help); + $help = ''; + $status = true; + if (!class_exists('IntlChar')) { + $status = false; + $help = DI::l10n()->t('Error: The IntlChar module is not installed.'); + $returnVal = false; + } + $this->addCheck(DI::l10n()->t('IntlChar PHP module'), $status, true, $help); + // check for XML DOM Documents being able to be generated $help = ''; $status = true; diff --git a/src/Model/Item.php b/src/Model/Item.php index 55884a802e..ad93b949d9 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -49,7 +49,6 @@ use Friendica\Util\Proxy; use Friendica\Util\Strings; use Friendica\Util\Temporal; use GuzzleHttp\Psr7\Uri; -use IntlChar; use LanguageDetection\Language; class Item @@ -2064,6 +2063,10 @@ class Item */ private static function splitByBlocks(string $body): array { + if (class_exists('IntlChar')) { + return [$body]; + } + $blocks = []; $previous_block = 0; @@ -2072,12 +2075,12 @@ class Item $previous = ($i > 0) ? mb_substr($body, $i - 1, 1) : ''; $next = ($i < mb_strlen($body)) ? mb_substr($body, $i + 1, 1) : ''; - if (!IntlChar::isalpha($character)) { - if (($previous != '') && (IntlChar::isalpha($previous))) { + if (!\IntlChar::isalpha($character)) { + if (($previous != '') && (\IntlChar::isalpha($previous))) { $previous_block = self::getBlockCode($previous); } - $block = (($next != '') && IntlChar::isalpha($next)) ? self::getBlockCode($next) : $previous_block; + $block = (($next != '') && \IntlChar::isalpha($next)) ? self::getBlockCode($next) : $previous_block; $blocks[$block] = ($blocks[$block] ?? '') . $character; } else { $block = self::getBlockCode($character); @@ -2103,7 +2106,7 @@ class Item */ private static function getBlockCode(string $character): int { - if (!IntlChar::isalpha($character)) { + if (!\IntlChar::isalpha($character)) { return 0; } return self::isLatin($character) ? 1 : 2; @@ -2117,11 +2120,11 @@ class Item */ private static function isLatin(string $character): bool { - return in_array(IntlChar::getBlockCode($character), [ - IntlChar::BLOCK_CODE_BASIC_LATIN, IntlChar::BLOCK_CODE_LATIN_1_SUPPLEMENT, - IntlChar::BLOCK_CODE_LATIN_EXTENDED_A, IntlChar::BLOCK_CODE_LATIN_EXTENDED_B, - IntlChar::BLOCK_CODE_LATIN_EXTENDED_C, IntlChar::BLOCK_CODE_LATIN_EXTENDED_D, - IntlChar::BLOCK_CODE_LATIN_EXTENDED_E, IntlChar::BLOCK_CODE_LATIN_EXTENDED_ADDITIONAL + return in_array(\IntlChar::getBlockCode($character), [ + \IntlChar::BLOCK_CODE_BASIC_LATIN, \IntlChar::BLOCK_CODE_LATIN_1_SUPPLEMENT, + \IntlChar::BLOCK_CODE_LATIN_EXTENDED_A, \IntlChar::BLOCK_CODE_LATIN_EXTENDED_B, + \IntlChar::BLOCK_CODE_LATIN_EXTENDED_C, \IntlChar::BLOCK_CODE_LATIN_EXTENDED_D, + \IntlChar::BLOCK_CODE_LATIN_EXTENDED_E, \IntlChar::BLOCK_CODE_LATIN_EXTENDED_ADDITIONAL ]); }