Added check for IntlChar module

This commit is contained in:
Michael 2023-10-11 19:20:51 +00:00
parent f4591b2cc7
commit a6bbbd738f
3 changed files with 32 additions and 24 deletions

View file

@ -28,9 +28,9 @@ Due to the large variety of operating systems and PHP platforms in existence we
### Requirements ### Requirements
* Apache with mod-rewrite enabled and "Options All" so you can use a local `.htaccess` file * 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 * 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) * 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. * 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. 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.

View file

@ -384,13 +384,11 @@ class Installer
$help = ''; $help = '';
$status = true; $status = true;
if (function_exists('apache_get_modules')) { if (function_exists('apache_get_modules') && !in_array('mod_rewrite', 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.'); $help = DI::l10n()->t('Error: Apache webserver mod-rewrite module is required but not installed.');
$status = false; $status = false;
$returnVal = false; $returnVal = false;
} }
}
$this->addCheck(DI::l10n()->t('Apache mod_rewrite module'), $status, true, $help); $this->addCheck(DI::l10n()->t('Apache mod_rewrite module'), $status, true, $help);
$help = ''; $help = '';
@ -399,15 +397,22 @@ class Installer
$status = false; $status = false;
$help = DI::l10n()->t('Error: PDO or MySQLi PHP module required but not installed.'); $help = DI::l10n()->t('Error: PDO or MySQLi PHP module required but not installed.');
$returnVal = false; $returnVal = false;
} else { } elseif (!function_exists('mysqli_connect') && class_exists('pdo') && !in_array('mysql', \PDO::getAvailableDrivers())) {
if (!function_exists('mysqli_connect') && class_exists('pdo') && !in_array('mysql', \PDO::getAvailableDrivers())) {
$status = false; $status = false;
$help = DI::l10n()->t('Error: The MySQL driver for PDO is not installed.'); $help = DI::l10n()->t('Error: The MySQL driver for PDO is not installed.');
$returnVal = false; $returnVal = false;
} }
}
$this->addCheck(DI::l10n()->t('PDO or MySQLi PHP module'), $status, true, $help); $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 // check for XML DOM Documents being able to be generated
$help = ''; $help = '';
$status = true; $status = true;

View file

@ -49,7 +49,6 @@ use Friendica\Util\Proxy;
use Friendica\Util\Strings; use Friendica\Util\Strings;
use Friendica\Util\Temporal; use Friendica\Util\Temporal;
use GuzzleHttp\Psr7\Uri; use GuzzleHttp\Psr7\Uri;
use IntlChar;
use LanguageDetection\Language; use LanguageDetection\Language;
class Item class Item
@ -2064,6 +2063,10 @@ class Item
*/ */
private static function splitByBlocks(string $body): array private static function splitByBlocks(string $body): array
{ {
if (class_exists('IntlChar')) {
return [$body];
}
$blocks = []; $blocks = [];
$previous_block = 0; $previous_block = 0;
@ -2072,12 +2075,12 @@ class Item
$previous = ($i > 0) ? mb_substr($body, $i - 1, 1) : ''; $previous = ($i > 0) ? mb_substr($body, $i - 1, 1) : '';
$next = ($i < mb_strlen($body)) ? mb_substr($body, $i + 1, 1) : ''; $next = ($i < mb_strlen($body)) ? mb_substr($body, $i + 1, 1) : '';
if (!IntlChar::isalpha($character)) { if (!\IntlChar::isalpha($character)) {
if (($previous != '') && (IntlChar::isalpha($previous))) { if (($previous != '') && (\IntlChar::isalpha($previous))) {
$previous_block = self::getBlockCode($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; $blocks[$block] = ($blocks[$block] ?? '') . $character;
} else { } else {
$block = self::getBlockCode($character); $block = self::getBlockCode($character);
@ -2103,7 +2106,7 @@ class Item
*/ */
private static function getBlockCode(string $character): int private static function getBlockCode(string $character): int
{ {
if (!IntlChar::isalpha($character)) { if (!\IntlChar::isalpha($character)) {
return 0; return 0;
} }
return self::isLatin($character) ? 1 : 2; return self::isLatin($character) ? 1 : 2;
@ -2117,11 +2120,11 @@ class Item
*/ */
private static function isLatin(string $character): bool private static function isLatin(string $character): bool
{ {
return in_array(IntlChar::getBlockCode($character), [ return in_array(\IntlChar::getBlockCode($character), [
IntlChar::BLOCK_CODE_BASIC_LATIN, IntlChar::BLOCK_CODE_LATIN_1_SUPPLEMENT, \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_A, \IntlChar::BLOCK_CODE_LATIN_EXTENDED_B,
IntlChar::BLOCK_CODE_LATIN_EXTENDED_C, IntlChar::BLOCK_CODE_LATIN_EXTENDED_D, \IntlChar::BLOCK_CODE_LATIN_EXTENDED_C, \IntlChar::BLOCK_CODE_LATIN_EXTENDED_D,
IntlChar::BLOCK_CODE_LATIN_EXTENDED_E, IntlChar::BLOCK_CODE_LATIN_EXTENDED_ADDITIONAL \IntlChar::BLOCK_CODE_LATIN_EXTENDED_E, \IntlChar::BLOCK_CODE_LATIN_EXTENDED_ADDITIONAL
]); ]);
} }