wallabag/src/Tools/Utils.php

34 lines
817 B
PHP
Raw Normal View History

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
{
/**
* 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
*
2015-03-28 13:27:45 +00:00
* @return string
*/
public static function generateToken($length = 15)
2015-03-28 13:27:45 +00:00
{
$token = substr(base64_encode(random_bytes($length)), 0, $length);
2015-03-28 13:27:45 +00:00
// remove character which can broken the url
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)
{
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
}