Skip to content

Commit

Permalink
Merge branch 'master' into prod
Browse files Browse the repository at this point in the history
  • Loading branch information
shi-yang committed Jul 31, 2015
2 parents 12d8dc4 + d7fd71b commit a44a8fe
Show file tree
Hide file tree
Showing 14 changed files with 249 additions and 59 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -3,6 +3,8 @@ backend/runtime/*
frontend/runtime/*
!frontend/runtime/.gitignore

backend/web/uploads/*

frontend/web/uploads/blog/photo/*
frontend/web/uploads/blog/photo_tmp/*
frontend/web/uploads/forum/icon/*
Expand Down
4 changes: 2 additions & 2 deletions backend/controllers/ExploreController.php
Expand Up @@ -116,7 +116,7 @@ public function actionCreate($category)
case 'post':
$category = 'post';
if (empty($model->summary)) {
$model->summary = mb_substr(strip_tags($model->content), 0, 140, 'utf-8');
$model->summary = mb_substr(strip_tags($model->content), 0, 100, 'utf-8');
}
if (!empty($model->table_id) && !empty($model->table_name)) {
$post = Yii::$app->db->createCommand("SELECT * FROM {{%{$model->table_name}}} WHERE id=:id")->bindValue(':id', $model->table_id)->queryOne();
Expand All @@ -125,7 +125,7 @@ public function actionCreate($category)
return false;
} else {
$model->title = $post['title'];
$model->summary = mb_substr(strip_tags($post['content']), 0, 140, 'utf-8');
$model->summary = mb_substr(strip_tags($post['content']), 0, 100, 'utf-8');
$model->content = $post['content'];
$model->user_id = $post['user_id'];
$table_id = $model->table_id;
Expand Down
20 changes: 9 additions & 11 deletions backend/controllers/PostController.php
Expand Up @@ -4,7 +4,7 @@

use Yii;
use backend\models\Post;
use yii\data\Pagination;
use backend\models\PostSearch;
use common\components\BaseController;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
Expand Down Expand Up @@ -32,16 +32,12 @@ public function behaviors()
*/
public function actionIndex()
{
$query = Post::find();
$countQuery = clone $query;
$pages = new Pagination(['totalCount' => $countQuery->count()]);
$models = $query->offset($pages->offset)
->limit($pages->limit)
->all();
$searchModel = new PostSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);

return $this->render('index', [
'models' => $models,
'pages' => $pages
'dataProvider' => $dataProvider,
'searchModel' => $searchModel,
]);
}

Expand Down Expand Up @@ -102,8 +98,10 @@ public function actionUpdate($id)
*/
public function actionDelete($id)
{
$this->findModel($id)->delete();

$model = $this->findModel($id);
$user_id = $model->user_id;
$model->delete();
Yii::$app->db->createCommand("UPDATE {{%user_data}} SET post_count=post_count-1 WHERE user_id=".$user_id)->execute();
return $this->redirect(['index']);
}

Expand Down
65 changes: 65 additions & 0 deletions backend/models/PostSearch.php
@@ -0,0 +1,65 @@
<?php

namespace backend\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;

/**
* PostSearch represents the model behind the search form about `backend\models\Post`.
*/
class PostSearch extends Post
{
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id', 'created_at', 'user_id'], 'integer'],
[['title', 'content', 'tags'], 'safe'],
];
}

/**
* @inheritdoc
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}

/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Post::find();

$dataProvider = new ActiveDataProvider([
'query' => $query,
]);

if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}

$query->andFilterWhere([
'id' => $this->id,
'created_at' => $this->created_at,
'user_id' => $this->user_id,
]);

$query->andFilterWhere(['like', 'title', $this->title])
->andFilterWhere(['like', 'content', $this->content])
->andFilterWhere(['like', 'tags', $this->tags]);

return $dataProvider;
}
}
20 changes: 17 additions & 3 deletions backend/modules/forum/controllers/BoardController.php
Expand Up @@ -4,10 +4,9 @@

use Yii;
use backend\modules\forum\models\Board;
use yii\data\ActiveDataProvider;
use backend\modules\forum\models\BoardSearch;
use common\components\BaseController;
use yii\web\NotFoundHttpException;
use yii\web\ForbiddenHttpException;
use yii\filters\VerbFilter;
use backend\modules\forum\models\Thread;

Expand Down Expand Up @@ -38,7 +37,22 @@ public function actions()
]
];
}


/**
* Lists all Board models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new BoardSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);

return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}

/**
* Displays a single Board model.
* @param integer $id
Expand Down
17 changes: 17 additions & 0 deletions backend/modules/forum/controllers/ForumController.php
Expand Up @@ -156,6 +156,23 @@ public function actionUpdate($id, $action='dashboard')
]);
}

/**
* Deletes an existing Forum model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
*/
public function actionDelete($id)
{
$model = $this->findModel($id);
if ($model->delete()) {
Yii::$app->getSession()->setFlash('success', Yii::t('app', 'Deleted successfully.'));
} else {
Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Error.'));
}
return $this->redirect(['/forum/forum/index']);
}

/**
* Finds the Forum model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
Expand Down
1 change: 1 addition & 0 deletions backend/modules/forum/messages/zh-CN/forum.php
@@ -1,6 +1,7 @@
<?php
return [
'Forum' => '论坛',
'Board' => '版块',
'Thread' => '帖子',
'Post' => '评论',
];
66 changes: 66 additions & 0 deletions backend/modules/forum/models/BoardSearch.php
@@ -0,0 +1,66 @@
<?php

namespace backend\modules\forum\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;

/**
* BoardSearch represents the model behind the search form about `backend\modules\forum\models\Board`.
*/
class BoardSearch extends Board
{
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id', 'forum_id', 'parent_id', 'columns', 'user_id'], 'integer'],
[['name', 'description'], 'safe'],
];
}

/**
* @inheritdoc
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}

/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Board::find();

$dataProvider = new ActiveDataProvider([
'query' => $query,
]);

if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}

$query->andFilterWhere([
'id' => $this->id,
'user_id' => $this->user_id,
'forum_id' => $this->forum_id,
'columns' => $this->columns,
'parent_id' => $this->parent_id
]);

$query->andFilterWhere(['like', 'name', $this->name])
->andFilterWhere(['like', 'description', $this->description]);

return $dataProvider;
}
}
30 changes: 30 additions & 0 deletions backend/modules/forum/views/board/index.php
@@ -0,0 +1,30 @@
<?php

use yii\helpers\Html;
use yii\grid\GridView;

/* @var $this yii\web\View */

$this->title = Yii::t('forum', 'Board');
?>
<div class="board-index">
<h1><?= Html::encode($this->title) ?></h1>
<div class="board-all">
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],

'id',
'name',
'parent_id',
'forum_id',
'description:ntext',
'user_id',

['class' => 'yii\grid\ActionColumn'],
],
]); ?>
</div>
</div>
1 change: 1 addition & 0 deletions backend/modules/forum/views/layouts/forum.php
Expand Up @@ -17,6 +17,7 @@
<div class="col-md-3">
<div class="list-group">
<a class="list-group-item" href="<?= Url::toRoute(['/forum/forum/index']) ?>"><i class="glyphicon glyphicon-chevron-right pull-right"></i><span><?= Yii::t('forum', 'Forum') ?></span></a>
<a class="list-group-item" href="<?= Url::toRoute(['/forum/board/index']) ?>"><i class="glyphicon glyphicon-chevron-right pull-right"></i><span><?= Yii::t('forum', 'Board') ?></span></a>
<a class="list-group-item" href="<?= Url::toRoute(['/forum/thread/index']) ?>"><i class="glyphicon glyphicon-chevron-right pull-right"></i><span><?= Yii::t('forum', 'Thread') ?></span></a>
<a class="list-group-item" href="<?= Url::toRoute(['/forum/post/index']) ?>"><i class="glyphicon glyphicon-chevron-right pull-right"></i><span><?= Yii::t('forum', 'Post') ?></span></a>
</div>
Expand Down
60 changes: 25 additions & 35 deletions backend/views/post/index.php
@@ -1,46 +1,36 @@
<?php

use yii\helpers\Html;
use yii\helpers\Url;
use yii\helpers\HtmlPurifier;
use shiyang\infinitescroll\InfiniteScrollPager;
use yii\grid\GridView;

/* @var $this yii\web\View */
/* @var $model backend\models\Post */

$this->title = Yii::t('app', 'Posts');
$this->params['breadcrumbs'][] = $this->title;
$this->title = Yii::$app->setting->get('siteTitle');
?>
<div class="post-index">

<h1><?= Html::encode($this->title) ?></h1>
<ul class="timeline">
<li class="time-label">
<?= Html::a(Yii::t('app', 'Create a post'), ['/post/create', 'category' => 'post'], ['class' => 'btn btn-success']) ?>
</li>
<?php foreach($models as $post): ?>
<li>
<i class="glyphicon glyphicon-list-alt bg-blue"></i>
<div class="timeline-item">
<span class="time"><?= Yii::$app->formatter->asRelativeTime($post['created_at']) ?></span>
<h3 class="timeline-header"><span class="new-icon"></span>
<a href="<?= Url::toRoute(['/post/view', 'id' => $post['id']]) ?>" title="?" target="_blank"><?= Html::encode($post['title']) ?></a>
</h3>
<div class="timeline-body">
<p><?= HtmlPurifier::process(mb_substr(strip_tags($post['content']), 0, 140, 'utf-8')) ?></p>
</div>
<div class="timeline-footer">
<a class="btn btn-primary btn-xs" href="<?= Url::toRoute(['/post/view', 'id' => $post['id']]) ?>" target="_blank"><?= Yii::t('app', 'Read more') ?></a>
<a class="btn btn-danger btn-xs" href="<?= Url::toRoute(['/post/delete', 'id' => $post['id']]) ?>" data-confirm="<?= Yii::t('app', 'Are you sure to delete it?') ?>" data-method="post">
<span class="glyphicon glyphicon-trash"></span> <?= Yii::t('app', 'Delete') ?>
</a>
</div>
</div>
</li>
<?php endforeach ?>
<?= InfiniteScrollPager::widget([
'pagination' => $pages,
'widgetId' => '.timeline',
]);?>
</ul>
<p>
<?= Html::a(Yii::t('app', 'Create Post'), ['create'], ['class' => 'btn btn-success']) ?>
</p>
<div class="post-all">
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
'id',
'title:ntext',
[
'attribute' => 'content',
'value' => function ($model) {
return mb_substr($model->content, 0, 200, 'utf-8');
}
],
'tags:ntext',
'user_id',
'created_at:time',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
</div>
</div>
2 changes: 1 addition & 1 deletion frontend/modules/user/controllers/MessageController.php
Expand Up @@ -112,7 +112,7 @@ public function actionOutbox()
public function actionView($id)
{
$model = $this->findModel($id);
if (!$model->read_indicator) {
if (!$model->read_indicator && $model->sendto == Yii::$app->user->id) {
$model->read_indicator = 1;
$model->update();
Yii::$app->userData->updateKey('unread_message_count', Yii::$app->user->id, -1);
Expand Down
2 changes: 1 addition & 1 deletion frontend/themes/basic/explore/_post.php
Expand Up @@ -13,7 +13,7 @@
$pattern = "/<[img|IMG].*?src=\"([^^]*?)\".*?>/";
preg_match_all($pattern, $post['content'], $match);
if (!empty($match[1][0])) {
$img = Html::img($match[1][0], ['style' => 'max-width:100%;max-height:100%;']);
$img = Html::img($match[1][0]);
echo Html::a($img, ['/explore/view-post', 'id' => $post['id']], ['target' => '_blank']);
}
?>
Expand Down

0 comments on commit a44a8fe

Please sign in to comment.