mirror of
https://github.com/wallabag/wallabag.git
synced 2024-09-26 13:30:08 +00:00
7a0e6970b4
random_bytes is a PHP 7 function wich has been ported to PHP 5 using paragonie/random_compat
34 lines
754 B
PHP
34 lines
754 B
PHP
<?php
|
|
|
|
namespace Wallabag\CoreBundle\Tools;
|
|
|
|
class Utils
|
|
{
|
|
/**
|
|
* Generate a token used for RSS.
|
|
*
|
|
* @param integer $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(array('+', '/'), '', $token);
|
|
}
|
|
|
|
/**
|
|
* For a given text, we calculate reading time for an article
|
|
* based on 200 words per minute.
|
|
*
|
|
* @param $text
|
|
*
|
|
* @return float
|
|
*/
|
|
public static function getReadingTime($text)
|
|
{
|
|
return floor(str_word_count(strip_tags($text)) / 200);
|
|
}
|
|
}
|