22 return (isset($_POST[
'ajax']) && $_POST[
'ajax'] ===
'comment-form') ? array() : array(
24 'class' =>
'CCaptchaAction',
25 'backColor' => 0xFFFFFF,
26 'fixedVerifyCode' => YII_DEBUG ?
'polomo' : null
38 if (isset($_GET[
'return_url'])) {
39 return Yii::app()->createAbsoluteUrl($_GET[
'return_url']);
40 } elseif (isset($_SERVER[
'HTTP_REFERER'])) {
41 return $_SERVER[
'HTTP_REFERER'];
57 Yii::app()->user->setReturnUrl($return_url);
58 $this->redirect($this->module->loginUrl);
69 if (isset($_POST[
'key'])) {
70 $options = Yii::app()->cache->get($_POST[
'key']);
73 if (!empty($options)) {
74 if (!$options[
'allowAnonymous'] && Yii::app()->user->isGuest) {
75 Yii::app()->user->setFlash(
'commentCreateError' . $options[
'contentId'],
CommentsModule::t(
'Anonymous comments not allowed'));
76 } elseif (isset($_POST[
'Comment'])) {
77 $comment =
new Comment(Yii::app()->user->isGuest ?
'createAnonymous' :
'create');
78 $comment->attributes = $_POST[
'Comment'];
79 $comment->content_id = $options[
'contentId'];
80 $comment->notify_moderator = $options[
'notifyModeratorOnNew'];
81 $comment->moderator_email = $options[
'moderatorEmail'];
83 $comment->language = Yii::app()->language;
84 if (!Yii::app()->user->isGuest) {
85 $comment->user_id = Yii::app()->user->id;
86 $comment->email = Yii::app()->user->email;
88 if ($comment->save()) {
89 Yii::app()->user->setFlash(
'commentCreateSuccess' . $options[
'contentId'],
CommentsModule::t(
'Your comment added successfully and will be displayed'));
90 Yii::app()->user->setState(
'Comment' . $options[
'contentId'], null);
93 if ($comment->hasErrors() && !isset($_POST[
'ajax'])) {
94 Yii::app()->user->setState(
'Comment' . $options[
'contentId'], array(
'attributes' => $comment->attributes,
'errors' => $comment->getErrors()));
98 Yii::app()->user->setFlash(
'commentCreateError',
CommentsModule::t(
'Form error'));
100 $this->redirect($_GET[
'return_url']);
116 $options = Yii::app()->cache->get($key);
118 if (!empty($options) && !Yii::app()->user->isGuest) {
121 if ($comment->delete()) {
123 Yii::app()->user->setFlash(
'commentDeleteSuccess' . $options[
'contentId'],
CommentsModule::t(
"Comment deleted successfully"));
126 Yii::app()->user->setFlash(
'commentDeleteError' . $options[
'contentId'],
CommentsModule::t(
"You have no access or comment deleted"));
129 Yii::app()->user->setFlash(
'commentDeleteError' . $options[
'contentId'],
CommentsModule::t(
"You have no access"));
131 $this->redirect($return_url);
146 if ($comment && $comment->hash() == $key) {
147 if ($comment->status == Comment::DELETED) {
148 Yii::app()->user->setFlash(
'remoteActionState',
CommentsModule::t(
'Comment already deleted'));
152 Yii::app()->user->setFlash(
'remoteActionState',
CommentsModule::t(
'Comment deleted'));
155 Yii::app()->user->setFlash(
'remoteActionState',
CommentsModule::t(
'You have no access'));
158 $this->render(
'remoteAction', array(
'comment' => $comment));
174 $options = Yii::app()->cache->get($key);
175 if (!empty($options) && !Yii::app()->user->isGuest && in_array($status, array(Comment::APPROVED,
Comment::NOT_APPROVED))) {
178 $comment->status = $status;
179 $comment->update(
'status');
180 Yii::app()->user->setFlash(
181 'commentApproveSuccess' . $options[
'contentId'],
185 Yii::app()->user->setFlash(
'commentApproveError' . $options[
'contentId'],
CommentsModule::t(
"You have no access"));
188 Yii::app()->user->setFlash(
'commentApproveError' . $options[
'contentId'],
CommentsModule::t(
"You have no access or comment deleted"));
190 $this->redirect($return_url);
206 if ($comment && $comment->hash() == $key) {
207 if ($comment->status == Comment::DELETED) {
208 Yii::app()->user->setFlash(
'remoteActionState',
CommentsModule::t(
'Comment already deleted'));
210 $comment->status = $status;
211 $comment->update(
'status');
216 Yii::app()->user->setFlash(
'remoteActionState',
CommentsModule::t(
'Comment is not available anymore'));
218 $this->render(
'remoteAction', array(
'comment' => $comment));
232 if ($comment->notify_moderator && !empty($comment->moderator_email)) {
233 $subject =
CommentsModule::t(
'Comment created (Moderator) {subject}', array(
'{subject}' => $comment->subject));
236 $this->renderMail(
'/mail_templates/comment_created_admin', $subject, array(
'comment' => $comment,
'pageUrl' => $pageUrl),
true),
237 array(
new EmailRecipient($comment->moderator_email, $this->module->notificationsEmail))
239 Yii::app()->notificationManager->notifyAbout($notification);
242 $subscribers = Yii::app()->db->createCommand()
244 ->from(
'{{comments}}')
245 ->where(
'content_id = :content_id AND notify_user = :notify_user AND status != :status', array(
':content_id' => $comment->content_id,
':notify_user' =>
true,
':status' => Comment::DELETED))
246 ->group(
'email')->queryAll();
247 $recipients = array();
248 $fromEmail = $this->module->notificationsEmail;
249 foreach ($subscribers as $subscriber) {
250 if (trim($subscriber[
"email"]) !=
""){
251 $recipients[] =
new EmailRecipient($subscriber[
'email'], $fromEmail);
254 if (
sizeof($recipients) > 0) {
255 $subject =
CommentsModule::t(
'Comment created: {subject}', array(
'{subject}' => $comment->subject));
258 $this->renderMail(
'/mail_templates/comment_created_user', $subject, array(
'comment' => $comment,
'pageUrl' => $pageUrl),
true),
262 Yii::app()->notificationManager->notifyAbout($notification);
276 if ($comment->notify_user) {
281 $this->renderMail(
'/mail_templates/comment_deleted', $subject, array(
'comment' => $comment,
'pageUrl' => $pageUrl),
true),
284 Yii::app()->notificationManager->notifyAbout($notification);