/**
  * This add a new reply to an existing thread
  */
 public function actionNewReply($id)
 {
     $thread = Thread::model()->findByPk($id);
     if (null == $thread) {
         throw new CHttpException(404, 'Thread not found.');
     }
     if (!Yii::app()->user->isForumAdmin() && $thread->is_locked) {
         throw new CHttpException(403, 'Thread is locked.');
     }
     $model = new PostForm();
     if (isset($_POST['PostForm'])) {
         if (!isset($_POST['YII_CSRF_TOKEN']) || $_POST['YII_CSRF_TOKEN'] != Yii::app()->getRequest()->getCsrfToken()) {
             throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.');
         }
         $model->attributes = $_POST['PostForm'];
         if ($model->validate()) {
             $post = new Post();
             $post->author_id = Yii::app()->user->id;
             $post->thread_id = $thread->id;
             $post->content = $model->content;
             $post->save(false);
             $thread->lastPost_user_id = Yii::app()->user->id;
             $thread->lastPost_time = time();
             if (Yii::app()->user->isForumAdmin() && $thread->is_locked != $model->lockthread) {
                 $thread->is_locked = $model->lockthread;
             }
             $thread->save(false);
             $this->redirect($thread->url);
         }
     }
     $this->render('postform', array('thread' => $thread, 'model' => $model));
 }
Esempio n. 2
0
 public function actionCreate()
 {
     $this->channel = 'contribute';
     $form = new PostForm();
     if (request()->getIsPostRequest() && isset($_POST['PostForm'])) {
         $form->attributes = $_POST['PostForm'];
         if ($form->validate()) {
             $post = $form->save();
             if (!$post->hasErrors()) {
                 user()->setFlash('success_post_id', $post->id);
                 $this->redirect(url('post/success'));
                 exit(0);
             }
         }
     } else {
         $key = param('sess_post_create_token');
         if (!app()->session->contains($key) || empty(app()->session[$key])) {
             app()->session->add($key, uniqid('beta', true));
         } else {
             $token = app()->session[$key];
             $tempPictures = Upload::model()->findAllByAttributes(array('token' => $token));
         }
     }
     $captchaWidget = $form->hasErrors('captcha') ? $this->widget('BetaCaptcha', array(), true) : $this->widget('BetaCaptcha', array('skin' => 'defaultLazy'), true);
     $captchaClass = $form->hasErrors('captcha') ? 'error' : 'hide';
     $this->setSiteTitle(t('contribute_post'));
     cs()->registerMetaTag('noindex, follow', 'robots');
     $this->render('create', array('form' => $form, 'captchaClass' => $captchaClass, 'captchaWidget' => $captchaWidget, 'tempPictures' => $tempPictures));
 }