]> git.immae.eu Git - github/wallabag/wallabag.git/blob - src/Wallabag/CoreBundle/Tools/Utils.php
Merge pull request #2418 from wallabag/add-twitter-cards
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Tools / Utils.php
1 <?php
2
3 namespace Wallabag\CoreBundle\Tools;
4
5 class Utils
6 {
7 /**
8 * Generate a token used for RSS.
9 *
10 * @param int $length Length of the token
11 *
12 * @return string
13 */
14 public static function generateToken($length = 15)
15 {
16 $token = substr(base64_encode(random_bytes($length)), 0, $length);
17
18 // remove character which can broken the url
19 return str_replace(['+', '/'], '', $token);
20 }
21
22 /**
23 * For a given text, we calculate reading time for an article
24 * based on 200 words per minute.
25 *
26 * @param $text
27 *
28 * @return float
29 */
30 public static function getReadingTime($text)
31 {
32 return floor(str_word_count(strip_tags($text)) / 200);
33 }
34 }