Exemplo n.º 1
0
 private function AddComment(sfWebRequest $request)
 {
     $text = $request->getParameter('comment_text');
     if ($request->isMethod("GET")) {
         $text = urldecode($text);
     }
     if ($this->getRequestParameter('comment_picture_url')) {
         $filename = jrFileUploader::UploadRemote($request->getParameter('comment_picture_url'));
         if ($text) {
             $text .= "<br/>";
         }
         $text .= "<img src='http://" . $request->getHost() . "/uploads/" . $filename . "' />";
     }
     if (!trim($text)) {
         return;
     }
     sfApplicationConfiguration::getActive()->loadHelpers(array('Parse', 'Text', 'Tag', 'I18N', 'Url'));
     $user = $this->getUser()->getGuardUser();
     $comment = new PostComment();
     $comment->setUser($user);
     $comment->setPost($this->post);
     if ($this->parent) {
         $comment->setParent($this->parent);
     }
     $comment->setComment(parsetext($text));
     $comment->setCommentOriginal($text);
     $comment->save();
     $this->curUser = $this->getUser()->getGuardUser();
     if ($this->curUser) {
         Cookie::setCookie($this->curUser, "comments" . $this->post->getId(), $this->post->getAllComments('count'), time() + 24 * 60 * 60);
         Cookie::setCookie($this->curUser, "comments" . $this->post->getId() . "Time", date("Y-m-d H:i:s"), time() + 24 * 60 * 60);
     }
 }
Exemplo n.º 2
0
 /**
  * 提交评论
  *
  * @return [type] [description]
  */
 public function actionPostComment()
 {
     $nickname = trim($this->_gets->getParam('nickname'));
     $email = trim($this->_gets->getParam('email'));
     $postId = trim($this->_gets->getParam('postId'));
     $comment = trim($this->_gets->getParam('comment'));
     try {
         if (empty($postId)) {
             throw new Exception('编号丢失');
         } elseif (empty($nickname) || empty($email) || empty($comment)) {
             throw new Exception('昵称、邮箱、内容必须填写');
         }
         $bagecmsPostCommentModel = new PostComment();
         $bagecmsPostCommentModel->attributes = array('post_id' => $postId, 'nickname' => $nickname, 'email' => $email, 'content' => $comment);
         if ($bagecmsPostCommentModel->save()) {
             $var['state'] = 'success';
             $var['message'] = '提交成功';
         } else {
             throw new Exception(CHtml::errorSummary($bagecmsPostCommentModel, null, null, array('firstError' => '')));
         }
     } catch (Exception $e) {
         $var['state'] = 'error';
         $var['message'] = '出现错误:' . $e->getMessage();
     }
     exit(CJSON::encode($var));
 }