mirror of
https://github.com/wallabag/wallabag.git
synced 2025-10-15 19:42:08 +00:00
Move source files directly under src/ directory
This commit is contained in:
parent
804261bc26
commit
a37b385c23
190 changed files with 19 additions and 21 deletions
33
src/Tools/Utils.php
Normal file
33
src/Tools/Utils.php
Normal file
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
namespace Wallabag\CoreBundle\Tools;
|
||||
|
||||
class Utils
|
||||
{
|
||||
/**
|
||||
* Generate a token used for Feeds.
|
||||
*
|
||||
* @param int $length Length of the token
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function generateToken($length = 15)
|
||||
{
|
||||
$token = substr(base64_encode(random_bytes($length)), 0, $length);
|
||||
|
||||
// remove character which can broken the url
|
||||
return str_replace(['+', '/'], '', $token);
|
||||
}
|
||||
|
||||
/**
|
||||
* For a given text, we calculate reading time for an article based on 200 words per minute.
|
||||
*
|
||||
* @param string $text
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public static function getReadingTime($text)
|
||||
{
|
||||
return floor(\count(preg_split('~([^\p{L}\p{N}\']+|(\p{Han}|\p{Hiragana}|\p{Katakana}|\p{Hangul}){1,2})~u', strip_tags($text))) / 200);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue