aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/WallabagBundle/Twig/Extension/WallabagExtension.php
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas@loeuillet.org>2015-01-22 17:18:56 +0100
committerNicolas LÅ“uillet <nicolas@loeuillet.org>2015-01-22 17:18:56 +0100
commit9d50517ceaeadaba227ccdbaa43a5918abd16728 (patch)
tree5aa92beb3250895079690d7ecb8b3ddde28cda15 /src/WallabagBundle/Twig/Extension/WallabagExtension.php
parent2b9fe72b397a239c40f8c66d83506e0e2e8d5854 (diff)
downloadwallabag-9d50517ceaeadaba227ccdbaa43a5918abd16728.tar.gz
wallabag-9d50517ceaeadaba227ccdbaa43a5918abd16728.tar.zst
wallabag-9d50517ceaeadaba227ccdbaa43a5918abd16728.zip
migrating legacy to symfony
Diffstat (limited to 'src/WallabagBundle/Twig/Extension/WallabagExtension.php')
-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