|
14 | 14 | use Symfony\Component\Translation\TranslatorInterface; |
15 | 15 | use Twig\Extension\AbstractExtension; |
16 | 16 | use Yeskn\MainBundle\Entity\User; |
| 17 | +use Twig; |
17 | 18 |
|
18 | 19 | class GlobalValue extends AbstractExtension |
19 | 20 | { |
@@ -87,6 +88,15 @@ public function signed(User $user) |
87 | 88 | } |
88 | 89 | } |
89 | 90 |
|
| 91 | + public function ellipsis($string, $length) |
| 92 | + { |
| 93 | + if (mb_strlen($string) > $length) { |
| 94 | + return mb_substr($string, 0, $length) . '...'; |
| 95 | + } |
| 96 | + |
| 97 | + return $string; |
| 98 | + } |
| 99 | + |
90 | 100 | public function ago(\DateTime $dateTime) |
91 | 101 | { |
92 | 102 | $current = time(); |
@@ -286,23 +296,24 @@ public function javascriptPlugins() |
286 | 296 | public function getFilters() |
287 | 297 | { |
288 | 298 | return array( |
289 | | - new \Twig_SimpleFilter('signed', array($this,'signed')), |
290 | | - new \Twig_SimpleFilter('ago', array($this,'ago')), |
| 299 | + new Twig\TwigFilter('signed', array($this,'signed')), |
| 300 | + new Twig\TwigFilter('ago', array($this,'ago')), |
| 301 | + new Twig\TwigFilter('ellipsis', array($this,'ellipsis')), |
291 | 302 | ); |
292 | 303 | } |
293 | 304 |
|
294 | 305 | public function getFunctions() |
295 | 306 | { |
296 | 307 | return array( |
297 | | - new \Twig_SimpleFunction('hotPosts',array($this,'hotPosts'),array('needs_environment' => true, 'is_safe' => 'html')), |
298 | | - new \Twig_SimpleFunction('hotTags',array($this,'hotTags'),array('needs_environment' => true, 'is_safe' => 'html')), |
299 | | - new \Twig_SimpleFunction('hotComments',array($this,'hotComments'),array('needs_environment' => true, 'is_safe' => 'html')), |
300 | | - new \Twig_SimpleFunction('unReadMessages',array($this,'unReadMessages'),array('needs_environment' => true, 'is_safe' => 'html')), |
301 | | - new \Twig_SimpleFunction('hotUsers',array($this,'hotUsers'),array('needs_environment' => true, 'is_safe' => 'html')), |
302 | | - new \Twig_SimpleFunction('onlineUserCount',array($this,'onlineUserCount'),array('needs_environment' => true, 'is_safe' => 'html')), |
303 | | - new \Twig_SimpleFunction('siteState',array($this,'siteState'),array('needs_environment' => true, 'is_safe' => 'html')), |
304 | | - new \Twig_SimpleFunction('javascriptVariables',array($this,'javascriptVariables')), |
305 | | - new \Twig_SimpleFunction('javascriptPlugins',array($this,'javascriptPlugins')), |
| 308 | + new Twig\TwigFunction('hotPosts',array($this,'hotPosts'),array('needs_environment' => true, 'is_safe' => 'html')), |
| 309 | + new Twig\TwigFunction('hotTags',array($this,'hotTags'),array('needs_environment' => true, 'is_safe' => 'html')), |
| 310 | + new Twig\TwigFunction('hotComments',array($this,'hotComments'),array('needs_environment' => true, 'is_safe' => 'html')), |
| 311 | + new Twig\TwigFunction('unReadMessages',array($this,'unReadMessages'),array('needs_environment' => true, 'is_safe' => 'html')), |
| 312 | + new Twig\TwigFunction('hotUsers',array($this,'hotUsers'),array('needs_environment' => true, 'is_safe' => 'html')), |
| 313 | + new Twig\TwigFunction('onlineUserCount',array($this,'onlineUserCount'),array('needs_environment' => true, 'is_safe' => 'html')), |
| 314 | + new Twig\TwigFunction('siteState',array($this,'siteState'),array('needs_environment' => true, 'is_safe' => 'html')), |
| 315 | + new Twig\TwigFunction('javascriptVariables',array($this,'javascriptVariables')), |
| 316 | + new Twig\TwigFunction('javascriptPlugins',array($this,'javascriptPlugins')), |
306 | 317 | ); |
307 | 318 | } |
308 | 319 | } |
0 commit comments