From d91787589bfd7541a99032cc23243165dc1572c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 9 Aug 2013 08:25:16 +0200 Subject: fix #113 - reading time --- inc/poche/Poche.class.php | 4 ++++ inc/poche/Tools.class.php | 9 +++++++++ 2 files changed, 13 insertions(+) (limited to 'inc') diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 56910bc0..78747e32 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -69,6 +69,10 @@ class Poche $filter = new Twig_SimpleFilter('getDomain', 'Tools::getDomain'); $this->tpl->addFilter($filter); + # filter for reading time + $filter = new Twig_SimpleFilter('getReadingTime', 'Tools::getReadingTime'); + $this->tpl->addFilter($filter); + # Pagination $this->pagination = new Paginator($this->user->getConfigValue('pager'), 'p'); } diff --git a/inc/poche/Tools.class.php b/inc/poche/Tools.class.php index 4a72bae3..0eb0d9ea 100644 --- a/inc/poche/Tools.class.php +++ b/inc/poche/Tools.class.php @@ -224,4 +224,13 @@ class Tools return FALSE; } + + public static function getReadingTime($text) { + $word = str_word_count(strip_tags($text)); + $minutes = floor($word / 200); + $seconds = floor($word % 200 / (200 / 60)); + $time = array('minutes' => $minutes, 'seconds' => $seconds); + + return $minutes; + } } \ No newline at end of file -- cgit v1.2.3