]> git.immae.eu Git - github/wallabag/wallabag.git/blame - src/Wallabag/CoreBundle/Tools/Utils.php
refactor pocket import
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Tools / Utils.php
CommitLineData
0c83fd59
J
1<?php
2
3namespace Wallabag\CoreBundle\Tools;
4
5class Utils
6{
7 /**
4346a860 8 * Generate a token used for RSS.
0c83fd59
J
9 *
10 * @return string
11 */
12 public static function generateToken()
13 {
14 if (ini_get('open_basedir') === '') {
15 if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
16 // alternative to /dev/urandom for Windows
17 $token = substr(base64_encode(uniqid(mt_rand(), true)), 0, 20);
18 } else {
19 $token = substr(base64_encode(file_get_contents('/dev/urandom', false, null, 0, 20)), 0, 15);
20 }
21 } else {
22 $token = substr(base64_encode(uniqid(mt_rand(), true)), 0, 20);
23 }
24
132f614d
J
25 // remove character which can broken the url
26 return str_replace(array('+', '/'), '', $token);
0c83fd59 27 }
6eebd8c9 28
1f4408de
NL
29 /**
30 * @param $words
ff7b031d 31 *
1f4408de
NL
32 * @return float
33 */
34 public static function convertWordsToMinutes($words)
35 {
36 return floor($words / 200);
37 }
38
6eebd8c9
JB
39 /**
40 * For a given text, we calculate reading time for an article
6682139e 41 * based on 200 words per minute.
6eebd8c9
JB
42 *
43 * @param $text
44 *
45 * @return float
46 */
47 public static function getReadingTime($text)
48 {
1f4408de 49 return self::convertWordsToMinutes(str_word_count(strip_tags($text)));
6eebd8c9 50 }
0c83fd59 51}