clean doc and remove magic
This commit is contained in:
parent
247534855e
commit
af5990dccd
@ -14,6 +14,9 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Dotclear\Plugin\cleanURLs;
|
namespace Dotclear\Plugin\cleanURLs;
|
||||||
|
|
||||||
|
use cursor;
|
||||||
|
use dcBlog;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class to remove problematic characters from URLs
|
* Class to remove problematic characters from URLs
|
||||||
*
|
*
|
||||||
@ -30,14 +33,14 @@ class CleanURLs
|
|||||||
/**
|
/**
|
||||||
* Check if a string is UTF-8
|
* Check if a string is UTF-8
|
||||||
*
|
*
|
||||||
* @param string $str String to check
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*
|
|
||||||
* @author WordPress
|
* @author WordPress
|
||||||
* @license https://wordpress.org/about/gpl/ GPLv2
|
* @license https://wordpress.org/about/gpl/ GPLv2
|
||||||
|
*
|
||||||
|
* @param string $str The string to check
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
* */
|
* */
|
||||||
public static function seemsUtf8($str)
|
public static function seemsUtf8(string $str): bool
|
||||||
{
|
{
|
||||||
$length = strlen($str);
|
$length = strlen($str);
|
||||||
for ($i = 0; $i < $length; $i++) {
|
for ($i = 0; $i < $length; $i++) {
|
||||||
@ -72,14 +75,14 @@ class CleanURLs
|
|||||||
*
|
*
|
||||||
* If there are no accent characters, then the string given is just returned.
|
* If there are no accent characters, then the string given is just returned.
|
||||||
*
|
*
|
||||||
|
* @author WordPress
|
||||||
|
* @license https://wordpress.org/about/gpl/ GPLv2
|
||||||
|
*
|
||||||
* @param string $string Text that might have accent characters
|
* @param string $string Text that might have accent characters
|
||||||
*
|
*
|
||||||
* @return string Filtered string with replaced "nice" characters.
|
* @return string Filtered string with replaced "nice" characters.
|
||||||
*
|
|
||||||
* @author WordPress
|
|
||||||
* @license https://wordpress.org/about/gpl/ GPLv2
|
|
||||||
*/
|
*/
|
||||||
public static function removeAccents($string)
|
public static function removeAccents(string $string): string
|
||||||
{
|
{
|
||||||
if (!preg_match('/[\x80-\xff]/', $string)) {
|
if (!preg_match('/[\x80-\xff]/', $string)) {
|
||||||
return $string;
|
return $string;
|
||||||
@ -222,7 +225,7 @@ class CleanURLs
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clean string from diacritics and punctuation
|
* Clean string from diacritics and punctuation.
|
||||||
*
|
*
|
||||||
* @param null|string $str The string
|
* @param null|string $str The string
|
||||||
*
|
*
|
||||||
@ -230,19 +233,17 @@ class CleanURLs
|
|||||||
* */
|
* */
|
||||||
public static function cleanStr(?string $str): ?string
|
public static function cleanStr(?string $str): ?string
|
||||||
{
|
{
|
||||||
return is_string($str) ? strtr(self::removeAccents($str), ',!.?;', '-----') : $str;
|
return is_null($str) ? null : strtr(self::removeAccents($str), ',!.?;', '-----');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clean post URLs from diacritics and punctuation
|
* Clean post URLs from diacritics and punctuation.
|
||||||
*
|
*
|
||||||
* @param object $blog Current blog
|
* @param dcBlog $blog The blog instance
|
||||||
* @param object $cur Cursor
|
* @param cursor $cur The post cursor
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
* */
|
* */
|
||||||
public static function cleanPost($blog, $cur)
|
public static function cleanPost(dcBlog $blog, cursor $cur): void
|
||||||
{
|
{
|
||||||
$cur->post_url = self::cleanStr($cur->post_url);
|
$cur->setField('post_url', self::cleanStr($cur->getField('post_url')));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user