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 yii\helpers\Html; |
12
|
|
|
use yii\widgets\LinkPager; |
13
|
|
|
|
14
|
|
|
/* @var $this yii\web\View */ |
15
|
|
|
/* @var $s string */ |
16
|
|
|
/* @var $posts common\models\Post[] */ |
17
|
|
|
/* @var $tags common\models\Term[] */ |
18
|
|
|
/* @var $pages yii\data\Pagination */ |
19
|
|
|
|
20
|
|
|
$this->title = Html::encode(Yii::t('writesdown', 'Search Result: {s}', ['s' => $s]) . ' - ' . Option::get('sitetitle')); |
21
|
|
|
$this->params['breadcrumbs'][] = Html::encode(Yii::t('writesdown', 'Search Result: {s}', ['s' => $s])); |
22
|
|
|
$this->registerMetaTag([ |
23
|
|
|
'name' => 'robots', |
24
|
|
|
'content' => 'noindex, nofollow', |
25
|
|
|
]); |
26
|
|
|
?> |
27
|
|
|
|
28
|
|
|
<div class="archive post-index"> |
29
|
|
|
<header id="archive-header" class="archive-header page-header"> |
30
|
|
|
<h1><?= Html::encode(Yii::t('writesdown', 'Search Result: {s}', ['s' => $s])) ?></h1> |
31
|
|
|
|
32
|
|
|
</header> |
33
|
|
|
|
34
|
|
View Code Duplication |
<?php if ($posts): ?> |
|
|
|
|
35
|
|
|
<?php foreach ($posts as $post): ?> |
36
|
|
|
<article class="hentry"> |
37
|
|
|
<header class="entry-header page-header"> |
38
|
|
|
<h2 class="entry-title"><?= Html::a(Html::encode($post->title), $post->url) ?></h2> |
39
|
|
|
|
40
|
|
|
<?php $updated = new \DateTime($post->modified, new DateTimeZone(Yii::$app->timeZone)) ?> |
41
|
|
|
<div class="entry-meta"> |
42
|
|
|
<span class="entry-date"> |
43
|
|
|
<span aria-hidden="true" class="glyphicon glyphicon-time"></span> |
44
|
|
|
<a rel="bookmark" href="<?= $post->url ?>"> |
45
|
|
|
<time datetime="<?= $updated->format('c') ?>" class="entry-date"> |
46
|
|
|
<?= Yii::$app->formatter->asDate($post->date) ?> |
47
|
|
|
</time> |
48
|
|
|
</a> |
49
|
|
|
</span> |
50
|
|
|
<span class="byline"> |
51
|
|
|
<span class="author vcard"> |
52
|
|
|
<span aria-hidden="true" class="glyphicon glyphicon-user"></span> |
53
|
|
|
<a rel="author" href="<?= $post->postAuthor->url ?>" class="url fn"> |
54
|
|
|
<?= $post->postAuthor->display_name ?> |
55
|
|
|
</a> |
56
|
|
|
</span> |
57
|
|
|
</span> |
58
|
|
|
<span class="comments-link"> |
59
|
|
|
<span aria-hidden="true" class="glyphicon glyphicon-comment"></span> |
60
|
|
|
<a title="<?= Yii::t( |
61
|
|
|
'writesdown', |
62
|
|
|
'Comment on {postTitle}', |
63
|
|
|
['postTitle' => $post->title] |
64
|
|
|
) ?>" href="<?= $post->url ?>#respond"><?= Yii::t('writesdown', 'Leave a comment') ?></a> |
65
|
|
|
</span> |
66
|
|
|
</div> |
67
|
|
|
</header> |
68
|
|
|
<div class="entry-summary"> |
69
|
|
|
<?= $post->excerpt ?>... |
70
|
|
|
</div> |
71
|
|
|
<footer class="footer-meta"> |
72
|
|
|
<?php $tags = $post->getTerms() |
73
|
|
|
->innerJoinWith([ |
74
|
|
|
'taxonomy' => function ($query) { |
75
|
|
|
/** @var $query \yii\db\ActiveQuery */ |
76
|
|
|
return $query->from(['taxonomy' => Taxonomy::tableName()]); |
77
|
|
|
}, |
78
|
|
|
]) |
79
|
|
|
->where(['taxonomy.name' => 'tag']) |
80
|
|
|
->all() ?> |
81
|
|
|
|
82
|
|
|
<?php if ($tags): ?> |
83
|
|
|
<h3> |
84
|
|
|
<?php foreach ($tags as $tag): ?> |
85
|
|
|
<?= Html::a($tag->name, $tag->url, [ |
86
|
|
|
'class' => 'btn btn-xs btn-success', |
87
|
|
|
]) . "\n" ?> |
88
|
|
|
<?php endforeach ?> |
89
|
|
|
</h3> |
90
|
|
|
<?php endif; ?> |
91
|
|
|
|
92
|
|
|
</footer> |
93
|
|
|
</article> |
94
|
|
|
<?php endforeach ?> |
95
|
|
|
<nav id="archive-pagination"> |
96
|
|
|
<?= LinkPager::widget([ |
97
|
|
|
'pagination' => $pages, |
98
|
|
|
'activePageCssClass' => 'active', |
99
|
|
|
'disabledPageCssClass' => 'disabled', |
100
|
|
|
'options' => ['class' => 'pagination'], |
101
|
|
|
]) ?> |
102
|
|
|
</nav> |
103
|
|
|
<?php endif ?> |
104
|
|
|
|
105
|
|
|
</div> |
106
|
|
|
|
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.