コード例 #1
0
 public function actionReply($id)
 {
     $request = Yii::$app->getRequest();
     $me = Yii::$app->getUser()->getIdentity();
     $topic = $this->findTopicModel($id, ['node', 'author']);
     if (!$me->canReply($topic)) {
         throw new ForbiddenHttpException('您没有权限回复或此主题已关闭回复。');
     }
     $model = new Comment();
     if ($model->load($request->post()) && $model->validate()) {
         $model->user_id = $me->id;
         $cid = new \app\models\Commentid(['id' => null]);
         $cid->save(false);
         $model->id = $cid->id;
         $model->link('topic', $topic);
         $this->redirect(Topic::getRedirectUrl($id, $model->position));
     }
     return $this->render('add', ['comment' => $model, 'topic' => Util::convertModelToArray($topic)]);
 }
コード例 #2
0
<ul class="list-group sf-box">
	<li class="list-group-item">
	<?php 
echo Html::a('首页', ['topic/index']), '&nbsp;/&nbsp;', $this->title;
?>
	</li>
<?php 
foreach ($notices as $notice) {
    echo '<li class="list-group-item media">', Html::a(Html::img('@web/' . str_replace('{size}', 'small', $notice['source']['avatar']), ['class' => 'media-object', 'alt' => Html::encode($notice['source']['username'])]), ['user/view', 'username' => Html::encode($notice['source']['username'])], ['class' => 'media-left']), '<div class="media-body">
				<span class="fr gray small">', Yii::$app->formatter->asRelativeTime($notice['created_at']), '</span>', Html::a(Html::encode($notice['source']['username']), ['user/view', 'username' => Html::encode($notice['source']['username'])]), ' ';
    if ($notice['type'] == Notice::TYPE_COMMENT) {
        echo '回复了您的帖子【' . Html::a(Html::encode($notice['topic']['title']), Topic::getRedirectUrl($notice['topic_id'], $notice['position'])) . '】', $notice['notice_count'] > 0 ? '<span class="small gray">(省略类似通知' . $notice['notice_count'] . '次)</span>' : '';
    } else {
        if ($notice['type'] == Notice::TYPE_MENTION) {
            if ($notice['position'] > 0) {
                echo '在主题【' . Html::a(Html::encode($notice['topic']['title']), Topic::getRedirectUrl($notice['topic_id'], $notice['position'])) . '】的回帖中提到了您';
            } else {
                echo '在主题【' . Html::a(Html::encode($notice['topic']['title']), ['topic/view', 'id' => $notice['topic_id']]) . '】中提到了您';
            }
        } else {
            if ($notice['type'] == Notice::TYPE_FOLLOW_TOPIC) {
                echo '收藏了您发布的主题【', Html::a(Html::encode($notice['topic']['title']), ['topic/view', 'id' => $notice['topic_id']]), '】';
            } else {
                if ($notice['type'] == Notice::TYPE_FOLLOW_USER) {
                    echo '关注了您';
                }
            }
        }
    }
    echo '</div>';
    echo '</li>';
コード例 #3
0
 public function actionEdit($id)
 {
     $request = Yii::$app->getRequest();
     $me = Yii::$app->getUser()->getIdentity();
     $model = $this->findTopicModel($id, ['content', 'node']);
     if (!$me->canEdit($model)) {
         throw new ForbiddenHttpException('您没有权限修改或已超过可修改时间。');
     }
     if ($me->isAdmin()) {
         $model->scenario = Topic::SCENARIO_ADMIN_EDIT;
     } else {
         $model->scenario = Topic::SCENARIO_AUTHOR_EDIT;
     }
     if (!($content = $model->content)) {
         $content = new TopicContent(['topic_id' => $model->id]);
     }
     $oldTags = $model->tags;
     if ($model->load($request->post()) && $model->validate() && $content->load($request->post()) && $content->validate()) {
         //			$model->tags = Tag::editTags($model->tags, $oldTags);
         $model->tags = Tag::getTags($model->tags);
         $model->save(false) && $content->save(false);
         Tag::afterTopicEdit($model->id, $model->tags, $oldTags);
         (new History(['user_id' => $me->id, 'action' => History::ACTION_EDIT_TOPIC, 'action_time' => $model->updated_at, 'target' => $model->id]))->save(false);
         return $this->redirect(Topic::getRedirectUrl($id, 0, $request->get('ip', 1), $request->get('np', 1)));
     }
     return $this->render('edit', ['model' => $model, 'content' => $content]);
 }