mirror of
https://github.com/standardebooks/web.git
synced 2025-07-15 02:46:46 -04:00
Remove flaky iconv and replace with PHP-intl
This commit is contained in:
parent
ba53958596
commit
b812485d8a
3 changed files with 15 additions and 9 deletions
|
@ -12,7 +12,7 @@ You’ll also need to ensure the following:
|
||||||
|
|
||||||
- Your PHP installation must be configured to have `/standardebooks.org/lib/` in its include path.
|
- Your PHP installation must be configured to have `/standardebooks.org/lib/` in its include path.
|
||||||
|
|
||||||
- PHP-APCu must be installed. On Ubuntu this can be done with `sudo apt install php-apcu`.
|
- [PHP-APCu](http://php.net/manual/en/book.apcu.php) and [PHP-intl](http://php.net/manual/en/book.intl.php) must be installed. On Ubuntu this can be done with `sudo apt install php-apcu php-intl`.
|
||||||
|
|
||||||
- The URL `^/ebooks/([^\.]+?)/?$` must redirect to `/standardebooks.org/ebooks/ebook.php?url-path=$1`
|
- The URL `^/ebooks/([^\.]+?)/?$` must redirect to `/standardebooks.org/ebooks/ebook.php?url-path=$1`
|
||||||
|
|
||||||
|
|
|
@ -342,9 +342,8 @@ class Ebook{
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove diacritics and non-alphanumeric characters
|
// Remove diacritics and non-alphanumeric characters
|
||||||
$searchString = str_replace(['‘,', '’'], '', $searchString);
|
$searchString = trim(preg_replace('|[^a-zA-Z0-9 ]|ius', ' ', Formatter::RemoveDiacritics($searchString)) ?? '');
|
||||||
$searchString = trim(preg_replace('|[^a-zA-Z0-9 ]|ius', ' ', iconv('UTF-8', 'ASCII//TRANSLIT', $searchString) ?: '') ?? '');
|
$query = trim(preg_replace('|[^a-zA-Z0-9 ]|ius', ' ', Formatter::RemoveDiacritics($query)) ?? '');
|
||||||
$query = trim(preg_replace('|[^a-zA-Z0-9 ]|ius', ' ', iconv('UTF-8', 'ASCII//TRANSLIT', $query) ?: '') ?? '');
|
|
||||||
|
|
||||||
if($query == ''){
|
if($query == ''){
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -1,12 +1,19 @@
|
||||||
<?
|
<?
|
||||||
class Formatter{
|
class Formatter{
|
||||||
public static function MakeUrlSafe(string $text): string{
|
public static function RemoveDiacritics(string $text): string{
|
||||||
// Remove apostrophes
|
if(!isset($GLOBALS['transliterator'])){
|
||||||
// We have to do this first so iconv doesn't choke
|
$GLOBALS['transliterator'] = Transliterator::createFromRules(':: Any-Latin; :: Latin-ASCII; :: NFD; :: [:Nonspacing Mark:] Remove; :: Lower(); :: NFC;', Transliterator::FORWARD);
|
||||||
$text = str_replace(['\'', '‘,', '’'], '', $text);
|
}
|
||||||
|
|
||||||
|
return $GLOBALS['transliterator']->transliterate($text);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function MakeUrlSafe(string $text): string{
|
||||||
// Remove accent characters
|
// Remove accent characters
|
||||||
$text = iconv('UTF-8', 'ASCII//TRANSLIT', $text) ?: '';
|
$text = self::RemoveDiacritics($text);
|
||||||
|
|
||||||
|
// Remove apostrophes
|
||||||
|
$text = str_replace('\'', '', $text);
|
||||||
|
|
||||||
// Trim and convert to lowercase
|
// Trim and convert to lowercase
|
||||||
$text = mb_strtolower(trim($text));
|
$text = mb_strtolower(trim($text));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue