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 if ($options[
'dontNeedApprove']) {
90 Yii::app()->user->setFlash(
'commentCreateSuccess' . $options[
'contentId'],
CommentsModule::t(
'Your comment added successfully and will be displayed'));
92 Yii::app()->user->setFlash(
'commentCreateSuccess' . $options[
'contentId'],
CommentsModule::t(
'Your comment added successfully and will be visible after approval of a moderator'));
95 Yii::app()->user->setState(
'Comment' . $options[
'contentId'], null);
98 if ($comment->hasErrors() && !isset($_POST[
'ajax'])) {
99 Yii::app()->user->setState(
'Comment' . $options[
'contentId'], array(
'attributes' => $comment->attributes,
'errors' => $comment->getErrors()));
103 Yii::app()->user->setFlash(
'commentCreateError',
CommentsModule::t(
'Form error'));
105 $this->redirect($_GET[
'return_url']);
121 $options = Yii::app()->cache->get($key);
123 if (!empty($options) && !Yii::app()->user->isGuest) {
126 if ($comment->delete()) {
128 Yii::app()->user->setFlash(
'commentDeleteSuccess' . $options[
'contentId'],
CommentsModule::t(
"Comment deleted successfully"));
131 Yii::app()->user->setFlash(
'commentDeleteError' . $options[
'contentId'],
CommentsModule::t(
"You have no access or comment deleted"));
134 Yii::app()->user->setFlash(
'commentDeleteError' . $options[
'contentId'],
CommentsModule::t(
"You have no access"));
136 $this->redirect($return_url);
151 if ($comment && $comment->hash() == $key) {
152 if ($comment->status == Comment::DELETED) {
153 Yii::app()->user->setFlash(
'remoteActionState',
CommentsModule::t(
'Comment already deleted'));
157 Yii::app()->user->setFlash(
'remoteActionState',
CommentsModule::t(
'Comment deleted'));
160 Yii::app()->user->setFlash(
'remoteActionState',
CommentsModule::t(
'You have no access'));
163 $this->render(
'remoteAction', array(
'comment' => $comment));
179 $options = Yii::app()->cache->get($key);
180 if (!empty($options) && !Yii::app()->user->isGuest && in_array($status, array(Comment::APPROVED,
Comment::NOT_APPROVED))) {
183 $comment->status = $status;
184 $comment->update(
'status');
185 Yii::app()->user->setFlash(
186 'commentApproveSuccess' . $options[
'contentId'],
190 Yii::app()->user->setFlash(
'commentApproveError' . $options[
'contentId'],
CommentsModule::t(
"You have no access"));
193 Yii::app()->user->setFlash(
'commentApproveError' . $options[
'contentId'],
CommentsModule::t(
"You have no access or comment deleted"));
195 $this->redirect($return_url);
211 if ($comment && $comment->hash() == $key) {
212 if ($comment->status == Comment::DELETED) {
213 Yii::app()->user->setFlash(
'remoteActionState',
CommentsModule::t(
'Comment already deleted'));
215 $comment->status = $status;
216 $comment->update(
'status');
221 Yii::app()->user->setFlash(
'remoteActionState',
CommentsModule::t(
'Comment is not available anymore'));
223 $this->render(
'remoteAction', array(
'comment' => $comment));
237 if ($comment->notify_moderator && !empty($comment->moderator_email)) {
238 $subject =
CommentsModule::t(
'Comment created (Moderator) {subject}', array(
'{subject}' => $comment->subject));
241 $this->renderMail(
'/mail_templates/comment_created_admin', $subject, array(
'comment' => $comment,
'pageUrl' => $pageUrl),
true),
242 array(
new EmailRecipient($comment->moderator_email, $this->module->notificationsEmail))
244 Yii::app()->notificationManager->notifyAbout($notification);
247 $subscribers = Yii::app()->db->createCommand()
249 ->from(
'{{comments}}')
250 ->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))
251 ->group(
'email')->queryAll();
252 $recipients = array();
253 $fromEmail = $this->module->notificationsEmail;
254 foreach ($subscribers as $subscriber) {
255 if (trim($subscriber[
"email"]) !=
""){
256 $recipients[] =
new EmailRecipient($subscriber[
'email'], $fromEmail);
259 if (
sizeof($recipients) > 0) {
260 $subject =
CommentsModule::t(
'Comment created: {subject}', array(
'{subject}' => $comment->subject));
263 $this->renderMail(
'/mail_templates/comment_created_user', $subject, array(
'comment' => $comment,
'pageUrl' => $pageUrl),
true),
267 Yii::app()->notificationManager->notifyAbout($notification);
281 if ($comment->notify_user) {
286 $this->renderMail(
'/mail_templates/comment_deleted', $subject, array(
'comment' => $comment,
'pageUrl' => $pageUrl),
true),
289 Yii::app()->notificationManager->notifyAbout($notification);