]> git.immae.eu Git - github/wallabag/wallabag.git/blame - src/Wallabag/CoreBundle/Twig/Extension/WallabagExtension.php
CS
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Twig / Extension / WallabagExtension.php
CommitLineData
9d50517c
NL
1<?php
2
ad4d1caa 3namespace Wallabag\CoreBundle\Twig\Extension;
9d50517c
NL
4
5class WallabagExtension extends \Twig_Extension
6{
7 public function getFilters()
8 {
9 return array(
10 new \Twig_SimpleFilter('readingTime', array($this, 'getReadingTime')),
11 new \Twig_SimpleFilter('domainName', array($this, 'getDomainName')),
12 );
13 }
14
15 /**
16 * Returns the domain name for a URL
17 *
18 * @param $url
19 * @return string
20 */
21 public static function getDomainName($url)
22 {
23 return parse_url($url, PHP_URL_HOST);
24 }
25
26 /**
27 * For a given text, we calculate reading time for an article
28 *
29 * @param $text
30 * @return float
31 */
32 public static function getReadingTime($text)
33 {
34 return floor(str_word_count(strip_tags($text)) / 200);
35 }
36
37 public function getName()
38 {
39 return 'wallabag_extension';
40 }
7df80cb3 41}