]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Tools/Utils.php
1st draft for Pocket import via API
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Tools / Utils.php
index de97c796bda9f54d2ebc104439465a5864c23f22..b146d98b9c360dfd64a7da1057f9fc3f5d065219 100644 (file)
@@ -5,7 +5,7 @@ namespace Wallabag\CoreBundle\Tools;
 class Utils
 {
     /**
-     * Generate a token used for RSS
+     * Generate a token used for RSS.
      *
      * @return string
      */
@@ -22,6 +22,29 @@ class Utils
             $token = substr(base64_encode(uniqid(mt_rand(), true)), 0, 20);
         }
 
-        return str_replace('+', '', $token);
+        // remove character which can broken the url
+        return str_replace(array('+', '/'), '', $token);
+    }
+
+    /**
+     * @param $words
+     * @return float
+     */
+    public static function convertWordsToMinutes($words)
+    {
+        return floor($words / 200);
+    }
+
+    /**
+     * 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 self::convertWordsToMinutes(str_word_count(strip_tags($text)));
     }
 }