]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
fix #113 - reading time
authorNicolas Lœuillet <nicolas.loeuillet@gmail.com>
Fri, 9 Aug 2013 06:25:16 +0000 (08:25 +0200)
committerNicolas Lœuillet <nicolas.loeuillet@gmail.com>
Fri, 9 Aug 2013 06:25:16 +0000 (08:25 +0200)
inc/poche/Poche.class.php
inc/poche/Tools.class.php
tpl/css/style.css
tpl/home.twig

index 56910bc03deb94f238a2f8f2a3fb3dfeb861dc97..78747e32192515701817203663a826844ef02f12 100644 (file)
@@ -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');
     }
index 4a72bae3defb9b252da525ab675b6abdd8b0c282..0eb0d9ea26e3807c1e6a9ec2d40a8cc5cb0ea4bf 100644 (file)
@@ -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
index d23c18964c89332a770fe59a9a3a043c94c80d8e..de82a82226d6fc9249e1cea54e3f0937b559072c 100644 (file)
@@ -241,4 +241,8 @@ a, a:hover, a:visited {
 
 footer {
     clear: both;
+}
+
+.reading-time {
+    font-size: 13px;
 }
\ No newline at end of file
index a6da641f6a4d95bcc266032d3e305ea6cccb4a5e..03f9f70da513d1be93380220788423c8e329a75d 100644 (file)
@@ -19,6 +19,7 @@
                         <a title="{% trans "toggle mark as read" %}" class="tool archive {% if entry.is_read == 0 %}archive-off{% endif %}" href="./?action=toggle_archive&id={{ entry.id|e }}"><span></span></a></li>
                         <li><a title="{% trans "toggle favorite" %}" class="tool fav {% if entry.is_fav == 0 %}fav-off{% endif %}" href="./?action=toggle_fav&id={{ entry.id|e }}"><span></span></a></li>
                         <li><a title="{% trans "delete" %}" class="tool delete" href="./?action=delete&id={{ entry.id|e }}"><span></span></a></li>
+                        <li class="reading-time">{{ entry.content| getReadingTime }} min</li>
                     </li>
                 </ul>
                 <p>{{ entry.content|striptags|slice(0, 300) }}...</p>