wallabag/src/Wallabag/CoreBundle/Tools/Utils.php

35 lines
819 B
PHP
Raw Normal View History

2015-03-28 13:27:45 +00:00
<?php
namespace Wallabag\CoreBundle\Tools;
class Utils
{
/**
2015-05-30 11:52:26 +00:00
* Generate a token used for RSS.
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
/**
* For a given text, we calculate reading time for an article
2015-08-20 18:39:52 +00:00
* based on 200 words per minute.
2015-08-20 18:10:32 +00:00
*
* @param $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})~u', strip_tags($text))) / 200);
2015-08-20 18:10:32 +00:00
}
2015-03-28 13:27:45 +00:00
}