1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link http://www.writesdown.com/ |
4
|
|
|
* @author Agiel K. Saputra <[email protected]> |
5
|
|
|
* @copyright Copyright (c) 2015 WritesDown |
6
|
|
|
* @license http://www.writesdown.com/license/ |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
use common\models\Option; |
10
|
|
|
use frontend\widgets\comment\MediaComment; |
11
|
|
|
use yii\helpers\Html; |
12
|
|
|
|
13
|
|
|
/* @var $comment common\models\MediaComment */ |
14
|
|
|
/* @var $media common\models\Media */ |
15
|
|
|
|
16
|
|
|
?> |
17
|
|
|
<div id="comment-view"> |
18
|
|
View Code Duplication |
<?php if ($media->comment_count): ?> |
|
|
|
|
19
|
|
|
<h2 class="comment-title"> |
20
|
|
|
<?= Yii::t('writesdown', '{comment_count} {comment_word} on {title}', [ |
21
|
|
|
'comment_count' => $media->comment_count, |
22
|
|
|
'comment_word' => $media->comment_count > 1 ? 'Replies' : 'Reply', |
23
|
|
|
'title' => $media->title, |
24
|
|
|
]) ?> |
25
|
|
|
|
26
|
|
|
</h2> |
27
|
|
|
|
28
|
|
|
<?= MediaComment::widget(['model' => $media, 'id' => 'comments']) ?> |
29
|
|
|
|
30
|
|
|
<?php endif ?> |
31
|
|
|
|
32
|
|
View Code Duplication |
<?php if ($media->comment_status == 'open'): ?> |
|
|
|
|
33
|
|
|
<?php $dateInterval = date_diff(new DateTime($media->date), new DateTime('now')) ?> |
34
|
|
|
<?php if (Option::get('comment_registration') && Yii::$app->user->isGuest): ?> |
35
|
|
|
<h3> |
36
|
|
|
<?= Yii::t('writesdown', 'You must login to leave a reply, ') ?> |
37
|
|
|
|
38
|
|
|
<?= Html::a(Yii::t('writesdown', 'Login'), Yii::$app->urlManagerBack->createUrl(['site/login'])); ?> |
39
|
|
|
|
40
|
|
|
</h3> |
41
|
|
|
<?php elseif (Option::get('close_comments_for_old_posts') |
42
|
|
|
&& $dateInterval->d >= Option::get('close_comments_days_old') |
43
|
|
|
): ?> |
44
|
|
|
<h3><?= Yii::t('writesdown', 'Comments are closed') ?></h3>; |
45
|
|
|
<?php else: ?> |
46
|
|
|
<?= $this->render('_form', [ |
47
|
|
|
'model' => $comment, |
48
|
|
|
'media' => $media, |
49
|
|
|
]) ?> |
50
|
|
|
<?php endif ?> |
51
|
|
|
<?php elseif ($media->comment_count && $media->comment_status === 'close'): ?> |
52
|
|
|
<h3><?= Yii::t('writesdown', 'Comments are closed') ?></h3>; |
53
|
|
|
<?php endif ?> |
54
|
|
|
|
55
|
|
|
</div> |
56
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.