]> git.immae.eu Git - github/wallabag/wallabag.git/blob - src/Wallabag/CoreBundle/Tools/Utils.php
1st draft for Pocket import via API
[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 * @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
25 // remove character which can broken the url
26 return str_replace(array('+', '/'), '', $token);
27 }
28
29 /**
30 * @param $words
31 * @return float
32 */
33 public static function convertWordsToMinutes($words)
34 {
35 return floor($words / 200);
36 }
37
38 /**
39 * For a given text, we calculate reading time for an article
40 * based on 200 words per minute.
41 *
42 * @param $text
43 *
44 * @return float
45 */
46 public static function getReadingTime($text)
47 {
48 return self::convertWordsToMinutes(str_word_count(strip_tags($text)));
49 }
50 }