Ejemplo n.º 1
0
 public function addAction()
 {
     if (user::isGuest() && reg::getKey('/comments/only_reg')) {
         system::stop();
     }
     if (user::isGuest() && !system::validCapcha('random_image')) {
         system::json(array('error' => 1, 'data' => lang::get('FEEDBACK_ERROR1')));
     }
     // Добавляем новый комментарий
     $comment = new comment();
     $comment->setParentId(system::POST('parent_id'));
     $comment->setObjId(system::POST('obj_id'));
     $comment->setUserName(system::POST('username'));
     $comment->setEmail(system::POST('email'));
     $comment->setText(system::POST('text'));
     $comment->setSendEmail(system::POST('send_email'));
     $obj_id = $comment->save();
     if ($obj_id) {
         page::assign('current_url', system::POST('back_url'));
         $html = page::macros('comments')->view($comment->id());
         system::json(array('error' => 0, 'data' => $html));
     } else {
         system::json(array('error' => 2, 'data' => $comment->getErrorListText(' ')));
     }
     if (!empty($_POST['back_url']) && !system::isAjax()) {
         system::redirect($_POST['back_url'] . '#comment' . $obj_id, true);
     } else {
         system::stop();
     }
 }
Ejemplo n.º 2
0
 /**
  * @return comment
  * @param integer $comment_id - ID комментария
  * @desc Вернет указанный комментарий
  */
 public static function get($comment_id)
 {
     $comment = new comment($comment_id);
     if ($comment->id() == $comment_id) {
         return $comment;
     } else {
         return false;
     }
 }