aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/WallabagBundle/Twig
diff options
context:
space:
mode:
Diffstat (limited to 'src/WallabagBundle/Twig')
-rw-r--r--src/WallabagBundle/Twig/Extension/WallabagExtension.php41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/WallabagBundle/Twig/Extension/WallabagExtension.php b/src/WallabagBundle/Twig/Extension/WallabagExtension.php
new file mode 100644
index 00000000..741fb191
--- /dev/null
+++ b/src/WallabagBundle/Twig/Extension/WallabagExtension.php
@@ -0,0 +1,41 @@
1<?php
2
3namespace WallabagBundle\Twig\Extension;
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 }
41} \ No newline at end of file