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