mirror of
https://github.com/moparisthebest/wallabag
synced 2025-01-06 19:28:00 -05:00
[change] twig extensions moved in src
This commit is contained in:
parent
6a26814da8
commit
4a857c4afb
17
app/app.php
17
app/app.php
@ -3,6 +3,7 @@ use Knp\Provider\ConsoleServiceProvider;
|
||||
use Poche\Api\EntryApi;
|
||||
use Poche\Api\ContentFullTextRssApi;
|
||||
use Poche\Repository\EntryRepository;
|
||||
use Poche\Twig;
|
||||
|
||||
use Symfony\Component\Translation\Loader\PoFileLoader;
|
||||
use Silex\Provider\SessionServiceProvider;
|
||||
@ -21,21 +22,17 @@ $app->before(function () use ($app) {
|
||||
});
|
||||
|
||||
$app['twig'] = $app->share($app->extend('twig', function($twig) {
|
||||
$twig->addFilter(new Twig_SimpleFilter('getDomain', function ($url) {
|
||||
return parse_url($url, PHP_URL_HOST);
|
||||
}));
|
||||
$twig->addFilter(new Twig_SimpleFilter('getDomain', 'Poche\Twig\Filter::getDomain'));
|
||||
return $twig;
|
||||
}));
|
||||
|
||||
$app['twig'] = $app->share($app->extend('twig', function($twig) {
|
||||
$twig->addFilter(new Twig_SimpleFilter('getReadingTime', function ($text) {
|
||||
$word = str_word_count(strip_tags($text));
|
||||
$minutes = floor($word / 200);
|
||||
$seconds = floor($word % 200 / (200 / 60));
|
||||
$time = array('minutes' => $minutes, 'seconds' => $seconds);
|
||||
$twig->addFilter(new Twig_SimpleFilter('getReadingTime', 'Poche\Twig\Filter::getReadingTime'));
|
||||
return $twig;
|
||||
}));
|
||||
|
||||
return $minutes;
|
||||
}));
|
||||
$app['twig'] = $app->share($app->extend('twig', function($twig) {
|
||||
$twig->addFilter(new Twig_SimpleFilter('getPicture', 'Poche\Twig\Filter::getPicture'));
|
||||
return $twig;
|
||||
}));
|
||||
|
||||
|
36
src/Poche/Twig/Filter.php
Normal file
36
src/Poche/Twig/Filter.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
* poche, a read it later open source system
|
||||
*
|
||||
* @category poche
|
||||
* @author Nicolas Lœuillet <support@inthepoche.com>
|
||||
* @copyright 2013
|
||||
* @license http://www.wtfpl.net/ see COPYING file
|
||||
*/
|
||||
|
||||
namespace Poche\Twig;
|
||||
|
||||
class Filter
|
||||
{
|
||||
public function getDomain($url)
|
||||
{
|
||||
return parse_url($url, PHP_URL_HOST);
|
||||
}
|
||||
|
||||
public 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;
|
||||
}
|
||||
|
||||
public function getPicture($text)
|
||||
{
|
||||
$output = preg_match('/<img.+src=[\'"]([^\'"]+)[\'"].*>/Ui', $text, $result);
|
||||
|
||||
return $output ? $result[1] : '';
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user