public function actionCreate($id = 0, $callback) { // @todo 暂时无用 if (!request()->getIsAjaxRequest() || !request()->getIsPostRequest()) { throw new CHttpException(500); } $data = array(); $model = new CommentForm(); $model->attributes = $_POST['CommentForm']; if ($model->validate() && ($comment = $model->save())) { $data['errno'] = 0; $data['text'] = t('ajax_comment_done'); $data['html'] = 'x'; // @todo 反回此条评论的html代码 } else { $data['errno'] = 1; $attributes = array_keys($model->getErrors()); foreach ($attributes as $attribute) { $labels[] = $model->getAttributeLabel($attribute); } $errstr = join(' ', $labels); $data['text'] = sprintf(t('ajax_comment_error'), $errstr); } echo json_encode($data); exit(0); }
public function actionComment($callback, $id = 0) { $id = (int) $id; $callback = strip_tags(trim($callback)); if (!request()->getIsAjaxRequest() || !request()->getIsPostRequest() || empty($callback)) { throw new CHttpException(500); } $data = array(); $model = new CommentForm(); $model->attributes = $_POST['CommentForm']; $model->content = h($model->content); if ($id > 0 && ($quote = Comment::model()->findByPk($id))) { $quoteTitle = sprintf(t('comment_quote_title'), $quote->authorName); $html = '<fieldset class="beta-comment-quote"><legend>' . $quoteTitle . '</legend>' . $quote->content . '</fieldset>'; $model->content = $html . $model->content; } if ($model->validate() && ($comment = $model->save())) { $data['errno'] = 0; $data['text'] = t('ajax_comment_done'); $data['html'] = $this->renderPartial('/comment/_one', array('comment' => $comment), true); // @todo 反回此条评论的html代码 } else { $data['errno'] = 1; $attributes = array_keys($model->getErrors()); foreach ($attributes as $attribute) { $labels[] = $model->getAttributeLabel($attribute); } $errstr = join(' ', $labels); $data['text'] = sprintf(t('ajax_comment_error'), $errstr); } echo $callback . '(' . json_encode($data) . ')'; exit(0); }
public function actionWriteComment() { $model = new CommentForm(); if (isset($_POST['CommentForm']) && BlockIp::checkAllowIp(Yii::app()->controller->currentUserIpLong)) { $model->attributes = $_POST['CommentForm']; $model->defineShowRating(); if ($model->validate() && Comment::checkExist(null, $model->modelName, $model->modelId)) { if ($model->modelName == 'News' && !param('enableCommentsForNews', 1) || $model->modelName == 'Apartment' && !param('enableCommentsForApartments', 1) || $model->modelName == 'Menu' && !param('enableCommentsForPages', 0) || $model->modelName == 'Article' && !param('enableCommentsForFaq', 1) || $model->modelName == 'InfoPages' && !param('enableCommentsForPages', 0)) { throw404(); } $comment = new Comment(); $comment->body = $model->body; $comment->parent_id = $model->rel; $comment->user_ip = Yii::app()->controller->currentUserIp; $comment->user_ip_ip2_long = Yii::app()->controller->currentUserIpLong; if ($model->rel == 0) { $comment->rating = $model->rating; } else { $comment->rating = -1; } $comment->model_name = $model->modelName; $comment->model_id = $model->modelId; if (Yii::app()->user->isGuest) { $comment->user_name = $model->user_name; $comment->user_email = $model->user_email; } else { $comment->owner_id = Yii::app()->user->id; } if (param('commentNeedApproval', 1) && !Yii::app()->user->checkAccess('backend_access')) { $comment->status = Comment::STATUS_PENDING; Yii::app()->user->setFlash('success', Yii::t('module_comments', 'Thank you for your comment. Your comment will be posted once it is approved.')); } else { $comment->status = Comment::STATUS_APPROVED; Yii::app()->user->setFlash('success', Yii::t('module_comments', 'Thank you for your comment.')); } $comment->save(false); $this->redirect($model->url); } } $this->render('commentForm', array('model' => $model)); }
/** * Функция добавление комментов */ protected function addComment(&$model) { if (isset($_POST['CommentForm'])) { $commentForm = new CommentForm(); $commentForm->attributes = $_POST['CommentForm']; if ($commentForm->validate()) { Yii::app()->user->setState('CommentForm', null); $comment = new Comment(); $comment->attributes = $_POST['CommentForm']; $comment->object_type = L::r_item('CommentType', get_class($model)); $comment->object_id = $model->id; $comment->created = date('Y-m-d H:i:s'); $comment->rating = 0; $comment->status = L::r_item('commentStatus', 'new'); if ($parent = Comment::model()->findbyPk((int) $commentForm->parent)) { $parent->append($comment); } else { $comment->saveNode(); } Yii::app()->user->setFlash('comment', array('text' => 'Спасибо за Ваш комментарий', 'class' => 'error')); $this->redirect(Yii::app()->request->requestUri . '#comment-' . $comment->id); } else { Yii::app()->user->setState('CommentForm', $commentForm); } } else { Yii::app()->user->setState('CommentForm', null); } }
/** * Add a comment * @param $args array * @param $request Request */ function add($args, $request) { $articleId = isset($args[0]) ? (int) $args[0] : 0; $galleyId = isset($args[1]) ? (int) $args[1] : 0; $parentId = isset($args[2]) ? (int) $args[2] : 0; $journal =& $request->getJournal(); $commentDao =& DAORegistry::getDAO('CommentDAO'); $publishedArticleDao =& DAORegistry::getDAO('PublishedArticleDAO'); $publishedArticle =& $publishedArticleDao->getPublishedArticleByArticleId($articleId); $parent =& $commentDao->getById($parentId, $articleId); if (isset($parent) && $parent->getSubmissionId() != $articleId) { $request->redirect(null, null, 'view', array($articleId, $galleyId)); } $this->validate($request, $articleId); $this->setupTemplate($request, $publishedArticle, $galleyId, $parent); // Bring in comment constants $enableComments = $journal->getSetting('enableComments'); switch ($enableComments) { case COMMENTS_UNAUTHENTICATED: break; case COMMENTS_AUTHENTICATED: case COMMENTS_ANONYMOUS: // The user must be logged in to post comments. if (!$request->getUser()) { Validation::redirectLogin(); } break; default: // Comments are disabled. Validation::redirectLogin(); } import('classes.comment.form.CommentForm'); $commentForm = new CommentForm(null, $articleId, $galleyId, isset($parent) ? $parentId : null); $commentForm->initData(); if (isset($args[3]) && $args[3] == 'save') { $commentForm->readInputData(); if ($commentForm->validate()) { $commentForm->execute(); // Send a notification to associated users import('classes.notification.NotificationManager'); $notificationManager = new NotificationManager(); $articleDao =& DAORegistry::getDAO('ArticleDAO'); $article =& $articleDao->getArticle($articleId); $notificationUsers = $article->getAssociatedUserIds(); foreach ($notificationUsers as $userRole) { $notificationManager->createNotification($request, $userRole['id'], NOTIFICATION_TYPE_USER_COMMENT, $article->getJournalId(), ASSOC_TYPE_ARTICLE, $article->getId()); } $request->redirect(null, null, 'view', array($articleId, $galleyId, $parentId), array('refresh' => 1)); } } $commentForm->display(); }
function add($args) { $paperId = isset($args[0]) ? (int) $args[0] : 0; $galleyId = isset($args[1]) ? (int) $args[1] : 0; $parentId = isset($args[2]) ? (int) $args[2] : 0; $conference =& Request::getConference(); $schedConf =& Request::getSchedConf(); $this->validate($paperId); $paper =& $this->paper; $parent =& $commentDao->getComment($parentId, $paperId); if (isset($parent) && $parent->getPaperId() != $paperId) { Request::redirect(null, null, null, 'view', array($paperId, $galleyId)); } $this->setupTemplate($paper, $galleyId, $parent); // Bring in comment constants $commentDao =& DAORegistry::getDAO('CommentDAO'); $enableComments = $conference->getSetting('enableComments'); $commentsRequireRegistration = $conference->getSetting('commentsRequireRegistration'); $commentsAllowAnonymous = $conference->getSetting('commentsAllowAnonymous'); $closeCommentsDate = $schedConf->getSetting('closeCommentsDate'); $commentsClosed = $schedConf->getSetting('closeComments') ? true : false && strtotime($closeCommentsDate < time()); $enableComments = $enableComments && !$commentsClosed && $paper->getEnableComments(); if (!$enableComments) { Request::redirect(null, null, 'index'); } if ($commentsRequireRegistration && !Request::getUser()) { Validation::redirectLogin(); } import('comment.form.CommentForm'); $commentForm = new CommentForm(null, $paperId, $galleyId, isset($parent) ? $parentId : null); $commentForm->initData(); if (isset($args[3]) && $args[3] == 'save') { $commentForm->readInputData(); if ($commentForm->validate()) { $commentForm->execute(); // Send a notification to associated users import('notification.Notification'); $paperDAO =& DAORegistry::getDAO('PaperDAO'); $paper =& $paperDAO->getPaper($paperId); $notificationUsers = $paper->getAssociatedUserIds(); foreach ($notificationUsers as $userRole) { $url = Request::url(null, null, null, 'view', array($paperId, $galleyId, $parentId)); Notification::createNotification($userRole['id'], "notification.type.userComment", $paper->getLocalizedTitle(), $url, 1, NOTIFICATION_TYPE_USER_COMMENT); } Request::redirect(null, null, null, 'view', array($paperId, $galleyId, $parentId), array('refresh' => 1)); } } $commentForm->display(); }