Skip to content

Commit 5abc0e4

Browse files
author
Chepurnoy
committed
init
1 parent cccf2f5 commit 5abc0e4

20 files changed

+1495
-0
lines changed

CommentAsset.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace yii2mod\comments;
4+
5+
use yii\web\AssetBundle;
6+
7+
/**
8+
* Class CommentAsset
9+
* @package yii2mod\comments
10+
*/
11+
class CommentAsset extends AssetBundle
12+
{
13+
/**
14+
* @inheritdoc
15+
*/
16+
public $sourcePath = '@vendor/yii2mod/yii2-comments/assets';
17+
18+
/**
19+
* @inheritdoc
20+
*/
21+
public $js = [
22+
'js/comment.js'
23+
];
24+
25+
/**
26+
* @inheritdoc
27+
*/
28+
public $css = [
29+
'css/comment.css'
30+
];
31+
32+
/**
33+
* @inheritdoc
34+
*/
35+
public $depends = [
36+
'yii\web\JqueryAsset',
37+
'yii\web\YiiAsset'
38+
];
39+
}

Module.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
namespace yii2mod\comments;
4+
5+
use yii2mod\comments\models\CommentModel;
6+
7+
/**
8+
* Class Module
9+
* @package yii2mod\comments
10+
*/
11+
class Module extends \yii\base\Module
12+
{
13+
/**
14+
* @var string module name
15+
*/
16+
public static $name = 'comment';
17+
18+
/**
19+
* @var string|null
20+
*/
21+
public $userIdentityClass = null;
22+
23+
/**
24+
* @var string comment model class, by default its yii2mod\comments\models\CommentModel::className();
25+
* You can override functions (getAuthor, getAvatar, ect) in your own comment model class
26+
*/
27+
public $commentModelClass = null;
28+
29+
/**
30+
* @var string the namespace that controller classes are in.
31+
* This namespace will be used to load controller classes by prepending it to the controller
32+
* class name.
33+
*/
34+
public $controllerNamespace = 'yii2mod\comments\controllers';
35+
36+
/**
37+
* Initializes the module.
38+
*
39+
* This method is called after the module is created and initialized with property values
40+
* given in configuration. The default implementation will initialize [[controllerNamespace]]
41+
* if it is not set.
42+
*
43+
* If you override this method, please make sure you call the parent implementation.
44+
*/
45+
public function init()
46+
{
47+
if ($this->userIdentityClass === null) {
48+
$this->userIdentityClass = \Yii::$app->getUser()->identityClass;
49+
}
50+
if ($this->commentModelClass === null) {
51+
$this->commentModelClass = CommentModel::className();
52+
}
53+
parent::init();
54+
}
55+
56+
}

README.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
Comments module for Yii2
2+
========================
3+
4+
This module provide a comments managing system for Yii2 application.
5+
6+
Installation
7+
------------
8+
9+
The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
10+
11+
Either run
12+
13+
```
14+
php composer.phar require --prefer-dist yii2mod/yii2-comments "*"
15+
```
16+
17+
or add
18+
19+
```json
20+
"yii2mod/yii2-comments": "*"
21+
```
22+
23+
to the require section of your composer.json.
24+
25+
26+
Usage
27+
======================================
28+
29+
1. Manage comments in admin panel:
30+
31+
- Add following code to admin module section in main config
32+
33+
```php
34+
'controllerMap' => [
35+
'comments' => 'yii2mod\comments\controllers\ManageController'
36+
]
37+
```
38+
- Run migrations:
39+
40+
```php
41+
php yii migrate --migrationPath=@vendor/yii2mod/yii2-comments/migrations
42+
```
43+
44+
- You can then access to management section through the following URL:
45+
```
46+
http://localhost/path/to/index.php?r=admin/comments/index
47+
```
48+
49+
50+
2. Add widget to view
51+
52+
- Add module to config section:
53+
```php
54+
'modules' => [
55+
'comment' => [
56+
'class' => 'yii2mod\comments\Module'
57+
]
58+
]
59+
```
60+
61+
- Use in view:
62+
63+
```php
64+
<?php echo \yii2mod\comments\widgets\Comment::widget(['model' => $model]); ?>
65+
```

assets/css/comment.css

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
/* Comments */
2+
.comments {
3+
margin: 40px 0 40px 0;
4+
}
5+
6+
.comments .comments-list {
7+
list-style: none;
8+
padding: 0;
9+
}
10+
11+
.comments .comment-author-avatar {
12+
float: left;
13+
width: 60px;
14+
}
15+
16+
.comments .comment-details {
17+
padding-left: 90px;
18+
}
19+
20+
.comments .comment-content {
21+
background: -webkit-linear-gradient(right left, #f8f8f8, #f3f3f3);
22+
background: -moz-linear-gradient(right left, #f8f8f8, #f3f3f3);
23+
background: -o-linear-gradient(right left, #f8f8f8, #f3f3f3);
24+
background: linear-gradient(to left right, #f8f8f8, #f3f3f3);
25+
-webkit-box-shadow: 0 0 3px #cccccc, inset 0 -1px 1px #e9e9e9, 0 1px 1px rgba(0, 0, 0, 0.12), inset 0 1px 1px white;
26+
-moz-box-shadow: 0 0 3px #cccccc, inset 0 -1px 1px #e9e9e9, 0 1px 1px rgba(0, 0, 0, 0.12), inset 0 1px 1px white;
27+
box-shadow: 0 0 3px #cccccc, inset 0 -1px 1px #e9e9e9, 0 1px 1px rgba(0, 0, 0, 0.12), inset 0 1px 1px white;
28+
padding: 20px;
29+
border-radius: 5px;
30+
border-top: 1px solid #e7e7e7;
31+
overflow: hidden;
32+
}
33+
34+
.comments .comment-date {
35+
font-size: 14px;
36+
color: #979797;
37+
font-style: italic;
38+
font-weight: normal;
39+
}
40+
41+
.comments .comment-author-name {
42+
font-weight: bold;
43+
font-size: 14px;
44+
margin: 0 0 5px 0;
45+
}
46+
47+
/* Apply on 2nd level comments list */
48+
.comments-list .children {
49+
padding-left: 45px;
50+
border-left: 2px solid #dfdfdf;
51+
margin: 20px 0 0 0;
52+
}
53+
54+
.comments-list .comment {
55+
position: relative;
56+
margin: 0 0 20px 0;
57+
}
58+
59+
.comments-list .children .comment:after {
60+
content: "";
61+
position: absolute;
62+
left: -46px;
63+
top: 48px;
64+
width: 0;
65+
height: 0;
66+
border-style: solid;
67+
border-width: 3px 0 3px 6px;
68+
border-color: transparent transparent transparent #184780;
69+
}
70+
71+
.comments-list .children .comment:before {
72+
content: "";
73+
position: absolute;
74+
left: -47px;
75+
top: 25px;
76+
width: 2px;
77+
height: 40px;
78+
background-color: #184780;
79+
border-bottom: 6px solid #f9f9f9;
80+
border-top: 6px solid #f9f9f9;
81+
}
82+
83+
.comments .comment-author-avatar img {
84+
border: 1px solid #e2e2e2;
85+
}
86+
87+
.comments ul,
88+
.comments ol {
89+
list-style-type: none;
90+
}
91+
92+
.title-block .title-seperator {
93+
background: url("../images/title-pattern.png");
94+
height: 5px;
95+
overflow: hidden;
96+
margin-top: 8px;
97+
}
98+
99+
.title-block .h3-body-title {
100+
float: left;
101+
margin: 0 20px 20px 0;
102+
}
103+
104+
.comment-action-buttons {
105+
float: right;
106+
}
107+
108+
.comment-action-buttons a {
109+
font-weight: normal;
110+
font-size: 14px;
111+
color: rgba(0, 0, 0, 0.63);
112+
padding: 5px;
113+
}
114+
115+
.comment-action-buttons a:hover {
116+
text-decoration: none;
117+
color: rgba(0, 0, 0, 0.63);
118+
}
119+
120+
.comment-action-buttons a:focus {
121+
outline: none;
122+
text-decoration: none;
123+
color: rgba(0, 0, 0, 0.63);
124+
}
125+
126+
.comment-box {
127+
margin-top: 15px;
128+
}
129+
130+
.comment-box textarea {
131+
background: #fdfdfd;
132+
vertical-align: middle;
133+
-webkit-border-radius: 2px;
134+
-moz-border-radius: 2px;
135+
-ms-border-radius: 2px;
136+
-o-border-radius: 2px;
137+
padding: 5px 6px 4px;
138+
-webkit-box-shadow: 0 0 3px rgba(0, 0, 0, 0.1) inset;
139+
-moz-box-shadow: 0 0 3px rgba(0, 0, 0, 0.1) inset;
140+
box-shadow: 0 0 3px rgba(0, 0, 0, 0.1) inset;
141+
border: 1px solid #c1c1c1;
142+
font-size: 13px;
143+
color: #333;
144+
line-height: 17px;
145+
-webkit-box-sizing: border-box;
146+
-moz-box-sizing: border-box;
147+
box-sizing: border-box;
148+
width: 100%;
149+
max-width: 100%;
150+
position: relative;
151+
overflow: auto;
152+
border-radius: 0;
153+
}
154+
155+
.comment-box .comment-box-partial .comment-submit {
156+
-webkit-appearance: none;
157+
-moz-appearance: none;
158+
appearance: none;
159+
font-size: 12px;
160+
font-weight: normal;
161+
-webkit-box-sizing: border-box;
162+
-moz-box-sizing: border-box;
163+
box-sizing: border-box;
164+
padding: 0 15px;
165+
border: 1px solid #008cc9;
166+
border-radius: 3px;
167+
height: 26px;
168+
line-height: 26px;
169+
cursor: pointer;
170+
white-space: nowrap;
171+
display: block;
172+
color: #fff !important;
173+
background: #008cc9 0 0;
174+
-webkit-transition: all .2s ease-in-out;
175+
-moz-transition: all .2s ease-in-out;
176+
-o-transition: all .2s ease-in-out;
177+
transition: all .2s ease-in-out;
178+
margin: 10px 0 0;
179+
}
180+
181+
.comment-submit:focus {
182+
outline: none !important;
183+
}
184+
185+
.comment-box .comment-box-partial .comment-submit:hover {
186+
background: #187BA7;
187+
}
188+
189+
#cancel-reply {
190+
display: none;
191+
color: #008cc9;
192+
}
193+
194+
#cancel-reply:hover {
195+
text-decoration: none;
196+
color: #187BA7;
197+
}

assets/images/title-pattern.png

1016 Bytes
Loading

0 commit comments

Comments
 (0)