mirror of
https://code.castopod.org/adaures/castopod
synced 2025-06-06 18:31:05 +00:00
fix(import): use cocur/slugify library to handle non latin text
This commit is contained in:
parent
04b2d8bafa
commit
4ca7f9ccae
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
use App\Entities\Person;
|
use App\Entities\Person;
|
||||||
use App\Entities\Podcast;
|
use App\Entities\Podcast;
|
||||||
|
use Cocur\Slugify\Slugify;
|
||||||
use Config\App;
|
use Config\App;
|
||||||
use Config\Images;
|
use Config\Images;
|
||||||
use Modules\Media\Entities\Image;
|
use Modules\Media\Entities\Image;
|
||||||
@ -42,105 +43,8 @@ if (! function_exists('slugify')) {
|
|||||||
$text = substr($text, 0, strrpos(substr($text, 0, $maxLength), ' '));
|
$text = substr($text, 0, strrpos(substr($text, 0, $maxLength), ' '));
|
||||||
}
|
}
|
||||||
|
|
||||||
// replace non letter or digits by -
|
$slugify = new Slugify();
|
||||||
$text = preg_replace('~[^\pL\d]+~u', '-', $text);
|
return $slugify->slugify($text);
|
||||||
|
|
||||||
$unwanted = [
|
|
||||||
'Š' => 'S',
|
|
||||||
'š' => 's',
|
|
||||||
'Đ' => 'Dj',
|
|
||||||
'đ' => 'dj',
|
|
||||||
'Ž' => 'Z',
|
|
||||||
'ž' => 'z',
|
|
||||||
'Č' => 'C',
|
|
||||||
'č' => 'c',
|
|
||||||
'Ć' => 'C',
|
|
||||||
'ć' => 'c',
|
|
||||||
'À' => 'A',
|
|
||||||
'Á' => 'A',
|
|
||||||
'Â' => 'A',
|
|
||||||
'Ã' => 'A',
|
|
||||||
'Ä' => 'A',
|
|
||||||
'Å' => 'A',
|
|
||||||
'Æ' => 'AE',
|
|
||||||
'Ç' => 'C',
|
|
||||||
'È' => 'E',
|
|
||||||
'É' => 'E',
|
|
||||||
'Ê' => 'E',
|
|
||||||
'Ë' => 'E',
|
|
||||||
'Ì' => 'I',
|
|
||||||
'Í' => 'I',
|
|
||||||
'Î' => 'I',
|
|
||||||
'Ï' => 'I',
|
|
||||||
'Ñ' => 'N',
|
|
||||||
'Ò' => 'O',
|
|
||||||
'Ó' => 'O',
|
|
||||||
'Ô' => 'O',
|
|
||||||
'Õ' => 'O',
|
|
||||||
'Ö' => 'O',
|
|
||||||
'Ø' => 'O',
|
|
||||||
'Œ' => 'OE',
|
|
||||||
'Ù' => 'U',
|
|
||||||
'Ú' => 'U',
|
|
||||||
'Û' => 'U',
|
|
||||||
'Ü' => 'U',
|
|
||||||
'Ý' => 'Y',
|
|
||||||
'Þ' => 'B',
|
|
||||||
'ß' => 'Ss',
|
|
||||||
'à' => 'a',
|
|
||||||
'á' => 'a',
|
|
||||||
'â' => 'a',
|
|
||||||
'ã' => 'a',
|
|
||||||
'ä' => 'a',
|
|
||||||
'å' => 'a',
|
|
||||||
'æ' => 'ae',
|
|
||||||
'ç' => 'c',
|
|
||||||
'è' => 'e',
|
|
||||||
'é' => 'e',
|
|
||||||
'ê' => 'e',
|
|
||||||
'ë' => 'e',
|
|
||||||
'ì' => 'i',
|
|
||||||
'í' => 'i',
|
|
||||||
'î' => 'i',
|
|
||||||
'ï' => 'i',
|
|
||||||
'ð' => 'o',
|
|
||||||
'ñ' => 'n',
|
|
||||||
'ò' => 'o',
|
|
||||||
'ó' => 'o',
|
|
||||||
'ô' => 'o',
|
|
||||||
'õ' => 'o',
|
|
||||||
'ö' => 'o',
|
|
||||||
'ø' => 'o',
|
|
||||||
'œ' => 'OE',
|
|
||||||
'ù' => 'u',
|
|
||||||
'ú' => 'u',
|
|
||||||
'û' => 'u',
|
|
||||||
'ý' => 'y',
|
|
||||||
'þ' => 'b',
|
|
||||||
'ÿ' => 'y',
|
|
||||||
'Ŕ' => 'R',
|
|
||||||
'ŕ' => 'r',
|
|
||||||
'/' => '-',
|
|
||||||
' ' => '-',
|
|
||||||
];
|
|
||||||
$text = strtr($text, $unwanted);
|
|
||||||
|
|
||||||
// transliterate
|
|
||||||
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
|
|
||||||
|
|
||||||
// remove unwanted characters
|
|
||||||
$text = preg_replace('~[^\-\w]+~', '', $text);
|
|
||||||
|
|
||||||
// trim
|
|
||||||
$text = trim($text, '-');
|
|
||||||
|
|
||||||
// remove duplicate -
|
|
||||||
$text = preg_replace('~-+~', '-', $text);
|
|
||||||
|
|
||||||
// lowercase
|
|
||||||
$text = strtolower($text);
|
|
||||||
|
|
||||||
return $text;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,25 +7,26 @@
|
|||||||
"license": "AGPL-3.0-or-later",
|
"license": "AGPL-3.0-or-later",
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^8.1",
|
"php": "^8.1",
|
||||||
"codeigniter4/framework": "v4.4.1",
|
|
||||||
"james-heinrich/getid3": "^2.0.0-beta5",
|
|
||||||
"whichbrowser/parser": "^v2.1.7",
|
|
||||||
"geoip2/geoip2": "v2.13.0",
|
|
||||||
"league/commonmark": "^2.4.1",
|
|
||||||
"vlucas/phpdotenv": "v5.5.0",
|
|
||||||
"league/html-to-markdown": "5.1.1",
|
|
||||||
"opawg/user-agents-php": "^v1.0",
|
|
||||||
"adaures/ipcat-php": "^v1.0.0",
|
"adaures/ipcat-php": "^v1.0.0",
|
||||||
"adaures/podcast-persons-taxonomy": "^v1.0.1",
|
"adaures/podcast-persons-taxonomy": "^v1.0.1",
|
||||||
"phpseclib/phpseclib": "~2.0.45",
|
|
||||||
"michalsn/codeigniter4-uuid": "v1.0.2",
|
|
||||||
"codeigniter4/settings": "v2.1.2",
|
|
||||||
"chrisjean/php-ico": "^1.0.4",
|
|
||||||
"melbahja/seo": "^v2.1.1",
|
|
||||||
"codeigniter4/shield": "v1.0.0-beta.6",
|
|
||||||
"aws/aws-sdk-php": "^3.281.12",
|
"aws/aws-sdk-php": "^3.281.12",
|
||||||
"mpratt/embera": "^2.0.34",
|
"chrisjean/php-ico": "^1.0.4",
|
||||||
|
"cocur/slugify": "^4.5",
|
||||||
|
"codeigniter4/framework": "v4.4.1",
|
||||||
|
"codeigniter4/settings": "v2.1.2",
|
||||||
|
"codeigniter4/shield": "v1.0.0-beta.6",
|
||||||
"codeigniter4/tasks": "dev-develop",
|
"codeigniter4/tasks": "dev-develop",
|
||||||
|
"geoip2/geoip2": "v2.13.0",
|
||||||
|
"james-heinrich/getid3": "^2.0.0-beta5",
|
||||||
|
"league/commonmark": "^2.4.1",
|
||||||
|
"league/html-to-markdown": "5.1.1",
|
||||||
|
"melbahja/seo": "^v2.1.1",
|
||||||
|
"michalsn/codeigniter4-uuid": "v1.0.2",
|
||||||
|
"mpratt/embera": "^2.0.34",
|
||||||
|
"opawg/user-agents-php": "^v1.0",
|
||||||
|
"phpseclib/phpseclib": "~2.0.45",
|
||||||
|
"vlucas/phpdotenv": "v5.5.0",
|
||||||
|
"whichbrowser/parser": "^v2.1.7",
|
||||||
"yassinedoghri/podcast-feed": "dev-main"
|
"yassinedoghri/podcast-feed": "dev-main"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
|
73
composer.lock
generated
73
composer.lock
generated
@ -4,7 +4,7 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "2f7475f224d54face5bb527c0edc893a",
|
"content-hash": "b7d9181ef215329ee3c3d2c52e23b2d1",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "adaures/ipcat-php",
|
"name": "adaures/ipcat-php",
|
||||||
@ -302,6 +302,75 @@
|
|||||||
},
|
},
|
||||||
"time": "2016-09-27T22:00:56+00:00"
|
"time": "2016-09-27T22:00:56+00:00"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "cocur/slugify",
|
||||||
|
"version": "v4.5.1",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/cocur/slugify.git",
|
||||||
|
"reference": "7c6e088228b9f082050876ae8b0cd287b117b840"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/cocur/slugify/zipball/7c6e088228b9f082050876ae8b0cd287b117b840",
|
||||||
|
"reference": "7c6e088228b9f082050876ae8b0cd287b117b840",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"ext-mbstring": "*",
|
||||||
|
"php": "~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0"
|
||||||
|
},
|
||||||
|
"conflict": {
|
||||||
|
"symfony/config": "<3.4 || >=4,<4.3",
|
||||||
|
"symfony/dependency-injection": "<3.4 || >=4,<4.3",
|
||||||
|
"symfony/http-kernel": "<3.4 || >=4,<4.3",
|
||||||
|
"twig/twig": "<2.12.1"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"laravel/framework": "^5.0|^6.0|^7.0|^8.0",
|
||||||
|
"latte/latte": "~2.2",
|
||||||
|
"league/container": "^2.2.0",
|
||||||
|
"mikey179/vfsstream": "~1.6.8",
|
||||||
|
"mockery/mockery": "^1.3",
|
||||||
|
"nette/di": "~2.4",
|
||||||
|
"pimple/pimple": "~1.1",
|
||||||
|
"plumphp/plum": "~0.1",
|
||||||
|
"symfony/config": "^3.4 || ^4.3 || ^5.0 || ^6.0",
|
||||||
|
"symfony/dependency-injection": "^3.4 || ^4.3 || ^5.0 || ^6.0",
|
||||||
|
"symfony/http-kernel": "^3.4 || ^4.3 || ^5.0 || ^6.0",
|
||||||
|
"symfony/phpunit-bridge": "^5.4 || ^6.0",
|
||||||
|
"twig/twig": "^2.12.1 || ~3.0",
|
||||||
|
"zendframework/zend-modulemanager": "~2.2",
|
||||||
|
"zendframework/zend-servicemanager": "~2.2",
|
||||||
|
"zendframework/zend-view": "~2.2"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Cocur\\Slugify\\": "src"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": ["MIT"],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Florian Eckerstorfer",
|
||||||
|
"email": "florian@eckerstorfer.co",
|
||||||
|
"homepage": "https://florian.ec"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Ivo Bathke",
|
||||||
|
"email": "ivo.bathke@gmail.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Converts a string into a slug.",
|
||||||
|
"keywords": ["slug", "slugify"],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/cocur/slugify/issues",
|
||||||
|
"source": "https://github.com/cocur/slugify/tree/v4.5.1"
|
||||||
|
},
|
||||||
|
"time": "2023-09-17T07:26:20+00:00"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "codeigniter4/framework",
|
"name": "codeigniter4/framework",
|
||||||
"version": "v4.4.1",
|
"version": "v4.4.1",
|
||||||
@ -6517,9 +6586,9 @@
|
|||||||
"aliases": [],
|
"aliases": [],
|
||||||
"minimum-stability": "stable",
|
"minimum-stability": "stable",
|
||||||
"stability-flags": {
|
"stability-flags": {
|
||||||
"james-heinrich/getid3": 10,
|
|
||||||
"codeigniter4/shield": 10,
|
"codeigniter4/shield": 10,
|
||||||
"codeigniter4/tasks": 20,
|
"codeigniter4/tasks": 20,
|
||||||
|
"james-heinrich/getid3": 10,
|
||||||
"yassinedoghri/podcast-feed": 20
|
"yassinedoghri/podcast-feed": 20
|
||||||
},
|
},
|
||||||
"prefer-stable": true,
|
"prefer-stable": true,
|
||||||
|
@ -162,7 +162,7 @@ class PodcastImport extends BaseCommand
|
|||||||
|
|
||||||
$podcastModel = new PodcastModel();
|
$podcastModel = new PodcastModel();
|
||||||
if (! $podcastModel->update($this->podcast->id, $this->podcast)) {
|
if (! $podcastModel->update($this->podcast->id, $this->podcast)) {
|
||||||
throw new Exception(print_r($podcastModel->errors()));
|
throw new Exception((string) print_r($podcastModel->errors()));
|
||||||
}
|
}
|
||||||
|
|
||||||
CLI::showProgress(false);
|
CLI::showProgress(false);
|
||||||
@ -250,7 +250,7 @@ class PodcastImport extends BaseCommand
|
|||||||
$podcastModel = new PodcastModel();
|
$podcastModel = new PodcastModel();
|
||||||
if (! ($podcastId = $podcastModel->insert($podcast, true))) {
|
if (! ($podcastId = $podcastModel->insert($podcast, true))) {
|
||||||
$db->transRollback();
|
$db->transRollback();
|
||||||
throw new Exception(print_r($podcastModel->errors()));
|
throw new Exception((string) print_r($podcastModel->errors()));
|
||||||
}
|
}
|
||||||
|
|
||||||
$podcast->id = $podcastId;
|
$podcast->id = $podcastId;
|
||||||
@ -347,7 +347,7 @@ class PodcastImport extends BaseCommand
|
|||||||
$personGroupSlug,
|
$personGroupSlug,
|
||||||
$personRoleSlug
|
$personRoleSlug
|
||||||
)) {
|
)) {
|
||||||
throw new Exception(print_r($podcastPersonModel->errors()));
|
throw new Exception((string) print_r($podcastPersonModel->errors()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -485,7 +485,7 @@ class PodcastImport extends BaseCommand
|
|||||||
|
|
||||||
if (! ($episodeId = $episodeModel->insert($episode, true))) {
|
if (! ($episodeId = $episodeModel->insert($episode, true))) {
|
||||||
$db->transRollback();
|
$db->transRollback();
|
||||||
throw new Exception(print_r($episodeModel->errors()));
|
throw new Exception((string) print_r($episodeModel->errors()));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->importEpisodePersons($episodeId, $item->podcast_persons);
|
$this->importEpisodePersons($episodeId, $item->podcast_persons);
|
||||||
@ -535,7 +535,7 @@ class PodcastImport extends BaseCommand
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
if (! ($newPersonId = $personModel->insert($newPerson))) {
|
if (! ($newPersonId = $personModel->insert($newPerson))) {
|
||||||
throw new Exception(print_r($personModel->errors()));
|
throw new Exception((string) print_r($personModel->errors()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -567,7 +567,7 @@ class PodcastImport extends BaseCommand
|
|||||||
$personGroupSlug,
|
$personGroupSlug,
|
||||||
$personRoleSlug
|
$personRoleSlug
|
||||||
)) {
|
)) {
|
||||||
throw new Exception(print_r($episodePersonModel->errors()));
|
throw new Exception((string) print_r($episodePersonModel->errors()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user