2015-03-28 13:27:45 +00:00
|
|
|
<?php
|
|
|
|
|
2024-02-19 00:30:12 +00:00
|
|
|
namespace Wallabag\Tools;
|
2015-03-28 13:27:45 +00:00
|
|
|
|
|
|
|
class Utils
|
|
|
|
{
|
|
|
|
/**
|
2017-06-13 16:48:10 +00:00
|
|
|
* Generate a token used for Feeds.
|
2015-03-28 13:27:45 +00:00
|
|
|
*
|
2016-01-22 07:01:32 +00:00
|
|
|
* @param int $length Length of the token
|
2016-01-21 15:35:41 +00:00
|
|
|
*
|
2015-03-28 13:27:45 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
2016-01-21 15:35:41 +00:00
|
|
|
public static function generateToken($length = 15)
|
2015-03-28 13:27:45 +00:00
|
|
|
{
|
2016-01-21 15:35:41 +00:00
|
|
|
$token = substr(base64_encode(random_bytes($length)), 0, $length);
|
2015-03-28 13:27:45 +00:00
|
|
|
|
2015-04-01 19:54:22 +00:00
|
|
|
// remove character which can broken the url
|
2016-04-12 09:36:01 +00:00
|
|
|
return str_replace(['+', '/'], '', $token);
|
2015-03-28 13:27:45 +00:00
|
|
|
}
|
2015-08-20 18:10:32 +00:00
|
|
|
|
|
|
|
/**
|
2019-01-04 10:22:43 +00:00
|
|
|
* For a given text, we calculate reading time for an article based on 200 words per minute.
|
2015-08-20 18:10:32 +00:00
|
|
|
*
|
2019-01-04 10:22:43 +00:00
|
|
|
* @param string $text
|
2015-08-20 18:10:32 +00:00
|
|
|
*
|
|
|
|
* @return float
|
|
|
|
*/
|
|
|
|
public static function getReadingTime($text)
|
|
|
|
{
|
2019-01-05 04:30:15 +00:00
|
|
|
return floor(\count(preg_split('~([^\p{L}\p{N}\']+|(\p{Han}|\p{Hiragana}|\p{Katakana}|\p{Hangul}){1,2})~u', strip_tags($text))) / 200);
|
2015-08-20 18:10:32 +00:00
|
|
|
}
|
2015-03-28 13:27:45 +00:00
|
|
|
}
|