Skip to content

NOW MANAGED ON CODEBERG

Updated string functions to use mulitbyte versions where needed

Dan Brown13c0386e84ac
diff --git a/app/Auth/User.php b/app/Auth/User.php
index 12f022b06..259b8eec0 100644
--- a/app/Auth/User.php
+++ b/app/Auth/User.php
@@ -216,12 +216,12 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
*/
public function getShortName($chars = 8)
{
- if (strlen($this->name) <= $chars) {
+ if (mb_strlen($this->name) <= $chars) {
return $this->name;
}
$splitName = explode(' ', $this->name);
- if (strlen($splitName[0]) <= $chars) {
+ if (mb_strlen($splitName[0]) <= $chars) {
return $splitName[0];
}
diff --git a/app/Console/Commands/CreateAdmin.php b/app/Console/Commands/CreateAdmin.php
index 90c1ddb1c..e67da8717 100644
--- a/app/Console/Commands/CreateAdmin.php
+++ b/app/Console/Commands/CreateAdmin.php
@@ -49,7 +49,7 @@ class CreateAdmin extends Command
if (empty($email)) {
$email = $this->ask('Please specify an email address for the new admin user');
}
- if (strlen($email) < 5 || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
+ if (mb_strlen($email) < 5 || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
return $this->error('Invalid email address provided');
}
@@ -61,7 +61,7 @@ class CreateAdmin extends Command
if (empty($name)) {
$name = $this->ask('Please specify an name for the new admin user');
}
- if (strlen($name) < 2) {
+ if (mb_strlen($name) < 2) {
return $this->error('Invalid name provided');
}
@@ -69,7 +69,7 @@ class CreateAdmin extends Command
if (empty($password)) {
$password = $this->secret('Please specify a password for the new admin user');
}
- if (strlen($password) < 5) {
+ if (mb_strlen($password) < 5) {
return $this->error('Invalid password provided, Must be at least 5 characters');
}
diff --git a/app/Entities/Book.php b/app/Entities/Book.php
index 77cacf632..decdde9dc 100644
--- a/app/Entities/Book.php
+++ b/app/Entities/Book.php
@@ -104,7 +104,7 @@ class Book extends Entity
public function getExcerpt(int $length = 100)
{
$description = $this->description;
- return strlen($description) > $length ? substr($description, 0, $length-3) . '...' : $description;
+ return mb_strlen($description) > $length ? mb_substr($description, 0, $length-3) . '...' : $description;
}
/**
diff --git a/app/Entities/Bookshelf.php b/app/Entities/Bookshelf.php
index 1de767fec..c8f8b990c 100644
--- a/app/Entities/Bookshelf.php
+++ b/app/Entities/Bookshelf.php
@@ -83,7 +83,7 @@ class Bookshelf extends Entity
public function getExcerpt(int $length = 100)
{
$description = $this->description;
- return strlen($description) > $length ? substr($description, 0, $length-3) . '...' : $description;
+ return mb_strlen($description) > $length ? mb_substr($description, 0, $length-3) . '...' : $description;
}
/**
diff --git a/app/Entities/Chapter.php b/app/Entities/Chapter.php
index bdacb7c9d..936404758 100644
--- a/app/Entities/Chapter.php
+++ b/app/Entities/Chapter.php
@@ -56,7 +56,7 @@ class Chapter extends Entity
public function getExcerpt(int $length = 100)
{
$description = $this->text ?? $this->description;
- return strlen($description) > $length ? substr($description, 0, $length-3) . '...' : $description;
+ return mb_strlen($description) > $length ? mb_substr($description, 0, $length-3) . '...' : $description;
}
/**
diff --git a/app/Entities/Repos/PageRepo.php b/app/Entities/Repos/PageRepo.php
index 208aa5fa3..e6cb309e7 100644
--- a/app/Entities/Repos/PageRepo.php
+++ b/app/Entities/Repos/PageRepo.php
@@ -192,7 +192,7 @@ class PageRepo extends EntityRepo
// Create an unique id for the element
// Uses the content as a basis to ensure output is the same every time
// the same content is passed through.
- $contentId = 'bkmrk-' . substr(strtolower(preg_replace('/\s+/', '-', trim($element->nodeValue))), 0, 20);
+ $contentId = 'bkmrk-' . mb_substr(strtolower(preg_replace('/\s+/', '-', trim($element->nodeValue))), 0, 20);
$newId = urlencode($contentId);
$loopIndex = 0;
@@ -424,8 +424,8 @@ class PageRepo extends EntityRepo
$tree = collect($headers)->map(function($header) {
$text = trim(str_replace("\xc2\xa0", '', $header->nodeValue));
- if (strlen($text) > 30) {
- $text = substr($text, 0, 27) . '...';
+ if (mb_strlen($text) > 30) {
+ $text = mb_substr($text, 0, 27) . '...';
}
return [
@@ -435,7 +435,7 @@ class PageRepo extends EntityRepo
'text' => $text,
];
})->filter(function($header) {
- return strlen($header['text']) > 0;
+ return mb_strlen($header['text']) > 0;
});
// Normalise headers if only smaller headers have been used
diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php
index 79d696652..d57105b62 100644
--- a/app/Http/Controllers/Auth/RegisterController.php
+++ b/app/Http/Controllers/Auth/RegisterController.php
@@ -142,7 +142,7 @@ class RegisterController extends Controller
if ($registrationRestrict) {
$restrictedEmailDomains = explode(',', str_replace(' ', '', $registrationRestrict));
- $userEmailDomain = $domain = substr(strrchr($userData['email'], "@"), 1);
+ $userEmailDomain = $domain = mb_substr(mb_strrchr($userData['email'], "@"), 1);
if (!in_array($userEmailDomain, $restrictedEmailDomains)) {
throw new UserRegistrationException(trans('auth.registration_email_domain_invalid'), '/register');
}
diff --git a/app/helpers.php b/app/helpers.php
index 0fedf2e8d..8cb3fa3f4 100644
--- a/app/helpers.php
+++ b/app/helpers.php
@@ -123,7 +123,7 @@ function baseUrl($path, $forceAppDomain = false)
// Remove non-specified domain if forced and we have a domain
if ($isFullUrl && $forceAppDomain) {
if (!empty($base) && strpos($path, $base) === 0) {
- $path = substr($path, strlen($base));
+ $path = mb_substr($path, mb_strlen($base));
} else {
$explodedPath = explode('/', $path);
$path = implode('/', array_splice($explodedPath, 3));