]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | ||
3 | namespace Wallabag\CoreBundle\Twig\Extension; | |
4 | ||
5 | class 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 | * | |
20 | * @return string | |
21 | */ | |
22 | public static function getDomainName($url) | |
23 | { | |
24 | return parse_url($url, PHP_URL_HOST); | |
25 | } | |
26 | ||
27 | /** | |
28 | * For a given text, we calculate reading time for an article. | |
29 | * | |
30 | * @param $text | |
31 | * | |
32 | * @return float | |
33 | */ | |
34 | public static function getReadingTime($text) | |
35 | { | |
36 | return floor(str_word_count(strip_tags($text)) / 200); | |
37 | } | |
38 | ||
39 | public function getName() | |
40 | { | |
41 | return 'wallabag_extension'; | |
42 | } | |
43 | } |