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 common\models\Taxonomy; |
11
|
|
|
use frontend\assets\CommentAsset; |
12
|
|
|
use yii\helpers\Html; |
13
|
|
|
|
14
|
|
|
/* @var $this yii\web\View */ |
15
|
|
|
/* @var $post common\models\Post */ |
16
|
|
|
/* @var $comment common\models\PostComment */ |
17
|
|
|
/* @var $category common\models\Term */ |
18
|
|
|
/* @var $tags common\models\Term[] */ |
19
|
|
|
|
20
|
|
|
$this->title = Html::encode($post->title . ' - ' . Option::get('sitetitle')); |
21
|
|
|
$this->params['breadcrumbs'][] = [ |
22
|
|
|
'label' => Html::encode($post->postType->singular_name), |
23
|
|
|
'url' => ['/post/index', 'id' => $post->postType->id], |
24
|
|
|
]; |
25
|
|
|
$category = $post->getTerms() |
26
|
|
|
->innerJoinWith([ |
27
|
|
|
'taxonomy' => function ($query) { |
28
|
|
|
/* @var $query \yii\db\ActiveQuery */ |
29
|
|
|
$query->from(['taxonomy' => Taxonomy::tableName()]); |
30
|
|
|
}, |
31
|
|
|
]) |
32
|
|
|
->andWhere(['taxonomy.name' => 'category']) |
33
|
|
|
->one(); |
34
|
|
|
|
35
|
|
View Code Duplication |
if ($category) { |
|
|
|
|
36
|
|
|
$this->params['breadcrumbs'][] = ['label' => Html::encode($category->name), 'url' => $category->url]; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
$this->params['breadcrumbs'][] = Html::encode($post->title); |
40
|
|
|
CommentAsset::register($this); |
41
|
|
|
?> |
42
|
|
|
<div class="single post-view"> |
43
|
|
|
<article class="hentry"> |
44
|
|
|
|
45
|
|
View Code Duplication |
<?php if (Yii::$app->controller->route !== 'site/index'): ?> |
|
|
|
|
46
|
|
|
<header class="entry-header page-header"> |
47
|
|
|
<h1 class="entry-title"><?= Html::encode($post->title) ?></h1> |
48
|
|
|
|
49
|
|
|
<?php $updated = new \DateTime($post->modified, new DateTimeZone(Yii::$app->timeZone)) ?> |
50
|
|
|
<div class="entry-meta"> |
51
|
|
|
<span class="entry-date"> |
52
|
|
|
<span aria-hidden="true" class="glyphicon glyphicon-time"></span> |
53
|
|
|
<a rel="bookmark" href="<?= $post->url ?>"> |
54
|
|
|
<time datetime="<?= $updated->format('c') ?>" class="entry-date"> |
55
|
|
|
<?= Yii::$app->formatter->asDate($post->date) ?> |
56
|
|
|
</time> |
57
|
|
|
</a> |
58
|
|
|
</span> |
59
|
|
|
<span class="byline"> |
60
|
|
|
<span class="author vcard"> |
61
|
|
|
<span aria-hidden="true" class="glyphicon glyphicon-user"></span> |
62
|
|
|
<a rel="author" href="<?= $post->postAuthor->url ?>" class="url fn"> |
63
|
|
|
<?= $post->postAuthor->display_name ?> |
64
|
|
|
</a> |
65
|
|
|
</span> |
66
|
|
|
</span> |
67
|
|
|
<span class="comments-link"> |
68
|
|
|
<span aria-hidden="true" class="glyphicon glyphicon-comment"></span> |
69
|
|
|
<a title="<?= Yii::t( |
70
|
|
|
'writesdown', 'Comment on {postTitle}', |
71
|
|
|
['postTitle' => $post->title] |
72
|
|
|
) ?>" href="<?= $post->url ?>#respond"><?= Yii::t('writesdown', 'Leave a comment') ?></a> |
73
|
|
|
</span> |
74
|
|
|
</div> |
75
|
|
|
</header> |
76
|
|
|
<?php endif ?> |
77
|
|
|
|
78
|
|
|
<div class="entry-content clearfix"> |
79
|
|
|
<?= $post->content ?> |
80
|
|
|
</div> |
81
|
|
|
<footer class="footer-meta"> |
82
|
|
|
<?php $tags = $post->getTerms() |
83
|
|
|
->innerJoinWith([ |
84
|
|
|
'taxonomy' => function ($query) { |
85
|
|
|
/** @var $query \yii\db\ActiveQuery */ |
86
|
|
|
return $query->from(['taxonomy' => Taxonomy::tableName()]); |
87
|
|
|
}, |
88
|
|
|
]) |
89
|
|
|
->where(['taxonomy.name' => 'tag']) |
90
|
|
|
->all() ?> |
91
|
|
|
|
92
|
|
|
<?php if ($tags): ?> |
93
|
|
|
<h3> |
94
|
|
|
<?php foreach ($tags as $tag): ?> |
95
|
|
|
<?= Html::a($tag->name, $tag->url, ['class' => 'btn btn-xs btn-success']) . "\n" ?> |
96
|
|
|
<?php endforeach ?> |
97
|
|
|
</h3> |
98
|
|
|
<?php endif ?> |
99
|
|
|
|
100
|
|
|
</footer> |
101
|
|
|
</article> |
102
|
|
|
<nav id="single-pagination"> |
103
|
|
|
<ul class="pager"> |
104
|
|
|
<li class="previous"> |
105
|
|
|
<?= $post->getPrevPostLink( |
106
|
|
|
true, |
107
|
|
|
false, |
108
|
|
|
'<span aria-hidden="true" class="glyphicon glyphicon-menu-left"></span> PREV' |
109
|
|
|
) ?> |
110
|
|
|
|
111
|
|
|
</li> |
112
|
|
|
<li class="next"> |
113
|
|
|
<?= $post->getNextPostLink( |
114
|
|
|
true, |
115
|
|
|
false, |
116
|
|
|
'NEXT <span aria-hidden="true" class="glyphicon glyphicon-menu-right"></span>' |
117
|
|
|
) ?> |
118
|
|
|
|
119
|
|
|
</li> |
120
|
|
|
</ul> |
121
|
|
|
</nav> |
122
|
|
|
<?= $this->render('/post-comment/comments', ['post' => $post, 'comment' => $comment]) ?> |
123
|
|
|
</div> |
124
|
|
|
|
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.