Skip to content

Commit 570a7e0

Browse files
committed
update sidebar comment list
1 parent 29ce58f commit 570a7e0

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

src/Yeskn/MainBundle/Resources/views/sidebar/latest-comments.html.twig

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,20 @@
1212
</span>
1313
<div class="chat-body clearfix">
1414
<div class="header">
15-
<strong class="primary-font"><a href="{{ path('member_home', {username: comment.user.username}) }}" data-pjax>{{ comment.user.nickname }}</a></strong>
15+
<strong class="primary-font">
16+
<a href="{{ path('member_home', {username: comment.user.username}) }}" data-pjax>
17+
{{ comment.user.nickname }}
18+
</a>
19+
</strong>
20+
&raquo; <a data-pjax href="{{ path('post_show', {id:comment.post.id}) }}#comments">
21+
{{ comment.post.title|ellipsis(6) }}
22+
</a>
1623
<small class="pull-right text-muted" data-toggle="tooltip" title="{{ comment.createdAt|date }}">
1724
<i class="fa fa-clock-o fa-fw"></i> {{ comment.createdAt|ago }}
1825
</small>
1926
</div>
2027
<div style="margin-top: 5px">
21-
<a data-pjax href="{{ path('post_show', {id:comment.post.id}) }}#comments">{{ comment.content|raw }}</a>
28+
{{ comment.content|raw }}
2229
</div>
2330
</div>
2431
</li>

src/Yeskn/MainBundle/Twig/GlobalValue.php

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\Translation\TranslatorInterface;
1515
use Twig\Extension\AbstractExtension;
1616
use Yeskn\MainBundle\Entity\User;
17+
use Twig;
1718

1819
class GlobalValue extends AbstractExtension
1920
{
@@ -87,6 +88,15 @@ public function signed(User $user)
8788
}
8889
}
8990

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+
90100
public function ago(\DateTime $dateTime)
91101
{
92102
$current = time();
@@ -286,23 +296,24 @@ public function javascriptPlugins()
286296
public function getFilters()
287297
{
288298
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')),
291302
);
292303
}
293304

294305
public function getFunctions()
295306
{
296307
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')),
306317
);
307318
}
308319
}

0 commit comments

Comments
 (0)