Comments – wpDiscuz - Version 2.0.4

Version Description

  • Added : Current subscribe status note on comment form (for logged-in users)
  • Added : Unsubscribe link on comment form and in "new comment" notification message.
  • Fixed Bug: Redirection to blank option.php on saving any option page.

IMPORTANT: If you have a Cache Plugin, please reset after wpDiscuz update

Download this release

Release Info

Developer AdvancedCoding
Plugin Icon 128x128 Comments – wpDiscuz
Version 2.0.4
Comparing to
See all releases

Code changes from version 2.0.3 to 2.0.4

comment-form/form.php CHANGED
@@ -29,6 +29,11 @@ $wc_comment_list_update_type = $wc_core->wc_options->wc_options_serialized->wc_c
29
  $('#wpcomm .wc_name').val($.cookie('wc_author_name'));
30
  $('#wpcomm .wc_email').val($.cookie('wc_author_email'));
31
  }
 
 
 
 
 
32
  });
33
  </script>
34
  <?php
@@ -47,6 +52,17 @@ $header_text .= ' "' . get_the_title($post) . '"';
47
  ?>
48
  <div style="clear:both"></div>
49
  <div class="comments-area">
 
 
 
 
 
 
 
 
 
 
 
50
  <h3 id="wc-comment-header"><?php echo $wc_core->wc_options->wc_options_serialized->wc_phrases['wc_leave_a_reply_text']; ?></h3>
51
  <?php do_action('comment_form_before'); ?>
52
  <div id="wpcomm">
@@ -92,13 +108,28 @@ $header_text .= ' "' . get_the_title($post) . '"';
92
  <div style="clear:both"></div>
93
  </div>
94
  <div class="wc_notification_checkboxes">
95
- <?php $wc_notification_state = ($wc_core->wc_options->wc_options_serialized->wc_comment_reply_checkboxes_default_checked == 1) ? 'checked="checked" value="1"' : 'value="0"'; ?>
96
- <?php if ($wc_core->wc_options->wc_options_serialized->wc_show_hide_reply_checkbox) { ?>
97
- <input id="wc_notification_new_reply-<?php echo $unique_id; ?>" class="wc_notification_new_reply" <?php echo $wc_notification_state; ?> type="checkbox" name="wp_comment_reply_notification"/> <label class="wc-label-reply-notify" for="wc_notification_new_reply-<?php echo $unique_id; ?>"><?php echo $wc_core->wc_options->wc_options_serialized->wc_phrases['wc_notify_on_new_reply']; ?></label><br />
98
- <?php } ?>
99
- <?php if ($wc_core->wc_options->wc_options_serialized->wc_show_hide_comment_checkbox) { ?>
100
- <input id="wc_notification_new_comment-<?php echo $unique_id; ?>" class="wc_notification_new_comment" <?php echo $wc_notification_state; ?> type="checkbox" name="wp_post_comment_notification"/> <label class="wc-label-comment-notify" for="wc_notification_new_comment-<?php echo $unique_id; ?>"><?php echo $wc_core->wc_options->wc_options_serialized->wc_phrases['wc_notify_on_new_comment']; ?></label><br />
101
- <?php } ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
  </div>
103
 
104
  </div>
29
  $('#wpcomm .wc_name').val($.cookie('wc_author_name'));
30
  $('#wpcomm .wc_email').val($.cookie('wc_author_email'));
31
  }
32
+
33
+ $('#wc_unsubscribe_message').delay(7000).fadeOut(1500, function () {
34
+ $(this).remove();
35
+ });
36
+
37
  });
38
  </script>
39
  <?php
52
  ?>
53
  <div style="clear:both"></div>
54
  <div class="comments-area">
55
+ <?php
56
+ if (isset($_GET['wpdiscuzSubscribeID']) && isset($_GET['key'])) {
57
+ $wc_core->wc_unsubscribe($_GET['wpdiscuzSubscribeID'], $_GET['key']);
58
+ ?>
59
+ <div id="wc_unsubscribe_message">
60
+ <span class="wc_unsubscribe_message"><?php echo $wc_core->wc_options->wc_options_serialized->wc_phrases['wc_unsubscribe_message']; ?></span>
61
+ </div>
62
+ <?php
63
+ }
64
+ ?>
65
+
66
  <h3 id="wc-comment-header"><?php echo $wc_core->wc_options->wc_options_serialized->wc_phrases['wc_leave_a_reply_text']; ?></h3>
67
  <?php do_action('comment_form_before'); ?>
68
  <div id="wpcomm">
108
  <div style="clear:both"></div>
109
  </div>
110
  <div class="wc_notification_checkboxes">
111
+ <?php
112
+ global $current_user;
113
+ get_currentuserinfo();
114
+ if ($current_user->ID && $wc_core->wc_db_helper->wc_has_post_notification($post->ID, $current_user->user_email)) {
115
+ ?>
116
+ <label class="wc-label-comment-notify" style="cursor: default;"><?php echo $wc_core->wc_options->wc_options_serialized->wc_phrases['wc_subscribed_on_post']; ?> | <a href="<?php echo $wc_core->wc_db_helper->wc_unsubscribe_link($post->ID, $current_user->user_email, 'post'); ?>" rel="nofollow" class="unsubscribe"><?php echo $wc_core->wc_options->wc_options_serialized->wc_phrases['wc_unsubscribe']; ?></a></label>
117
+ <?php
118
+ } else {
119
+ $wc_notification_state = ($wc_core->wc_options->wc_options_serialized->wc_comment_reply_checkboxes_default_checked == 1) ? 'checked="checked" value="1"' : 'value="0"';
120
+ if ($wc_core->wc_options->wc_options_serialized->wc_show_hide_reply_checkbox) {
121
+ ?>
122
+ <input id="wc_notification_new_reply-<?php echo $unique_id; ?>" class="wc_notification_new_reply" <?php echo $wc_notification_state; ?> type="checkbox" name="wp_comment_reply_notification"/> <label class="wc-label-reply-notify" for="wc_notification_new_reply-<?php echo $unique_id; ?>"><?php echo $wc_core->wc_options->wc_options_serialized->wc_phrases['wc_notify_on_new_reply']; ?></label><br />
123
+ <?php
124
+ }
125
+ if ($wc_core->wc_options->wc_options_serialized->wc_show_hide_comment_checkbox) {
126
+ ?>
127
+ <input id="wc_notification_new_comment-<?php echo $unique_id; ?>" class="wc_notification_new_comment" <?php echo $wc_notification_state; ?> type="checkbox" name="wp_post_comment_notification"/> <label class="wc-label-comment-notify" for="wc_notification_new_comment-<?php echo $unique_id; ?>"><?php echo $wc_core->wc_options->wc_options_serialized->wc_phrases['wc_notify_on_new_comment']; ?></label><br />
128
+ <?php
129
+ }
130
+ }
131
+ ?>
132
+
133
  </div>
134
 
135
  </div>
comment-form/tpl-comment.php CHANGED
@@ -188,14 +188,27 @@ class WC_Comment_Template_Builder {
188
  $output_form .= '<div class="wc-field-submit"><input type="button" name="submit" value="' . $this->wc_options->wc_options_serialized->wc_phrases['wc_submit_text'] . '" id="wc_comm-' . $unique_id . '" class="wc_comm_submit button alt"/></div>';
189
  $output_form .= '<div style="clear:both"></div>';
190
  $output_form .= '<div class="wc_notification_checkboxes">';
191
-
192
- $wc_notification_state = ($this->wc_options->wc_options_serialized->wc_comment_reply_checkboxes_default_checked == 1) ? 'checked="checked" value="1"' : 'value="0"';
193
- if ($this->wc_options->wc_options_serialized->wc_show_hide_reply_checkbox) {
194
- $output_form .= '<input class="wc-label-reply-notify wc_notification_new_reply" id="wc_notification_new_reply-' . $unique_id . '" ' . $wc_notification_state . ' type="checkbox" name="wc_notification_new_reply"/> <label class="wc-label-comment-notify" for="wc_notification_new_reply-' . $unique_id . '">' . $this->wc_options->wc_options_serialized->wc_phrases['wc_notify_on_new_reply'] . '</label><br />';
195
- }
196
- if ($this->wc_options->wc_options_serialized->wc_show_hide_comment_checkbox) {
197
- $output_form .= '<input class="wc-label-comment-notify wc_notification_new_comment" id="wc_notification_new_comment-' . $unique_id . '" ' . $wc_notification_state . ' type="checkbox" name="wc_notification_new_comment"/> <label class="wc-label-comment-notify" for="wc_notification_new_comment-' . $unique_id . '">' . $this->wc_options->wc_options_serialized->wc_phrases['wc_notify_on_new_comment'] . '</label><br />';
 
 
 
 
 
 
 
 
 
 
 
 
198
  }
 
199
  $output_form .= '</div>';
200
  $output_form .= '</div>';
201
  $output_form .= '</div>';
188
  $output_form .= '<div class="wc-field-submit"><input type="button" name="submit" value="' . $this->wc_options->wc_options_serialized->wc_phrases['wc_submit_text'] . '" id="wc_comm-' . $unique_id . '" class="wc_comm_submit button alt"/></div>';
189
  $output_form .= '<div style="clear:both"></div>';
190
  $output_form .= '<div class="wc_notification_checkboxes">';
191
+
192
+ global $current_user;
193
+ get_currentuserinfo();
194
+ // $output_form .= $current_user->ID . ' - ' . $current_user->user_email . ' stugum : ' . $current_user->ID && $this->wc_db_helper->wc_has_post_notification($comment->comment_post_ID, $current_user->user_email);
195
+
196
+ if ($current_user->ID && $this->wc_db_helper->wc_has_post_notification($comment->comment_post_ID, $current_user->user_email)) {
197
+ $output_form .= '<label class="wc-label-comment-notify" style="cursor: default;">' . $this->wc_options->wc_options_serialized->wc_phrases['wc_subscribed_on_post'] . ' | <a href="' . $this->wc_db_helper->wc_unsubscribe_link($comment->comment_post_ID, $current_user->user_email, 'post') . '" rel="nofollow" class="unsubscribe">' . $this->wc_options->wc_options_serialized->wc_phrases['wc_unsubscribe'] . '</a></label>';
198
+ } else {
199
+ $wc_notification_state = ($this->wc_options->wc_options_serialized->wc_comment_reply_checkboxes_default_checked == 1) ? 'checked="checked" value="1"' : 'value="0"';
200
+ if ($current_user->ID && $this->wc_db_helper->wc_has_comment_notification($comment->comment_post_ID, $comment->comment_ID, $current_user->user_email)) {
201
+ $output_form .= '<label class="wc-label-reply-notify" style="cursor: default;">' . $this->wc_options->wc_options_serialized->wc_phrases['wc_subscribed_on_comment'] . ' | <a href="' . $this->wc_db_helper->wc_unsubscribe_link($comment->comment_ID, $current_user->user_email, 'comment') . '" rel="nofollow" class="unsubscribe">' . $this->wc_options->wc_options_serialized->wc_phrases['wc_unsubscribe'] . '</a></label><br/>';
202
+ // echo 'subscribed reply';
203
+ } else if ($this->wc_options->wc_options_serialized->wc_show_hide_reply_checkbox) {
204
+ $output_form .= '<input class="wc-label-reply-notify wc_notification_new_reply" id="wc_notification_new_reply-' . $unique_id . '" ' . $wc_notification_state . ' type="checkbox" name="wc_notification_new_reply"/> <label class="wc-label-comment-notify" for="wc_notification_new_reply-' . $unique_id . '">' . $this->wc_options->wc_options_serialized->wc_phrases['wc_notify_on_new_reply'] . '</label><br />';
205
+ // echo 'not subscribed reply';
206
+ }
207
+ if ($this->wc_options->wc_options_serialized->wc_show_hide_comment_checkbox) {
208
+ $output_form .= '<input class="wc-label-comment-notify wc_notification_new_comment" id="wc_notification_new_comment-' . $unique_id . '" ' . $wc_notification_state . ' type="checkbox" name="wc_notification_new_comment"/> <label class="wc-label-comment-notify" for="wc_notification_new_comment-' . $unique_id . '">' . $this->wc_options->wc_options_serialized->wc_phrases['wc_notify_on_new_comment'] . '</label>';
209
+ }
210
  }
211
+
212
  $output_form .= '</div>';
213
  $output_form .= '</div>';
214
  $output_form .= '</div>';
files/js/wc-ajax.js CHANGED
@@ -72,6 +72,25 @@ jQuery(document).ready(function ($) {
72
  depth = getCommentDepth($(this).parents('.wc-comment'));
73
  }
74
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  var submit = true;
76
  // evaluate the form using generic validaing
77
  if (!validator.checkAll(wc_form)) {
@@ -95,6 +114,7 @@ jQuery(document).ready(function ($) {
95
  comment_post_ID: wc_comment_post_ID,
96
  comment_parent: wc_comment_parent,
97
  comment_depth: depth,
 
98
  action: 'wc_comms_via_ajax'
99
  }
100
  }).done(function (response) {
@@ -164,26 +184,7 @@ jQuery(document).ready(function ($) {
164
  $('.wc_comm_form input').css('box-shadow', '0 0 4px -2px #d4d0ba');
165
  $('.wc_comm_form textarea').css('box-shadow', '0 0 4px -2px #d4d0ba');
166
 
167
- if ($('.wc_notification_new_comment').length || $('.wc_notification_new_reply').length) {
168
- if (obj.code !== -1) {
169
- var notification_type = '';
170
- var wc_comment_reply_checkboxes_default_checked = $('#wc_comment_reply_checkboxes_default_checked').val();
171
- if (wc_notification_new_reply !== 0) {
172
- notification_type = 'reply';
173
- if (wc_comment_reply_checkboxes_default_checked == 0) {
174
- $('#wc_notification_new_reply-' + uniqueID).val('0').prop("checked", false);
175
- }
176
- }
177
- if (wc_notification_new_comment !== 0) {
178
- notification_type = 'post';
179
- if (wc_comment_reply_checkboxes_default_checked == 0) {
180
- $('#wc_notification_new_comment-' + uniqueID).val('0').prop("checked", false);
181
- }
182
- }
183
-
184
- notify_on_new_comment(wc_comment_post_ID, wc_new_comment_id, wc_email, notification_type);
185
- }
186
- }
187
  } catch (e) {
188
  $('#wc_captcha-' + uniqueID).val('');
189
  $('.wc_tooltipster').tooltipster({offsetY: 2});
@@ -337,13 +338,6 @@ jQuery(document).ready(function ($) {
337
  });
338
  });
339
 
340
-
341
- // $(document).delegate('.wc-comment', 'mouseenter', function () {
342
- // $('.wc-comment').animate({
343
- // backgroundColor: "rgb( 20, 20, 20 )"
344
- // }, 1500);
345
- // });
346
-
347
  // MUST BE CHANGED IN NEXT VERSION OF PLUGIN
348
  $(document).delegate('.wc_new_reply', 'click', function () {
349
  wc_submitID = $('.wc_main_comm_form input.wc_comm_submit').attr('id');
72
  depth = getCommentDepth($(this).parents('.wc-comment'));
73
  }
74
 
75
+
76
+ var notification_type = '';
77
+ if ($('.wc_notification_new_comment').length || $('.wc_notification_new_reply').length) {
78
+ //var wc_comment_reply_checkboxes_default_checked = $('#wc_comment_reply_checkboxes_default_checked').val();
79
+ if (wc_notification_new_reply !== 0) {
80
+ notification_type = 'reply';
81
+ //if (wc_comment_reply_checkboxes_default_checked == 0) {
82
+ $('#wc_notification_new_reply-' + uniqueID).val('0').prop("checked", false);
83
+ // }
84
+ }
85
+ if (wc_notification_new_comment !== 0) {
86
+ notification_type = 'post';
87
+ //if (wc_comment_reply_checkboxes_default_checked == 0) {
88
+ $('#wc_notification_new_comment-' + uniqueID).val('0').prop("checked", false);
89
+ // }
90
+ }
91
+
92
+ }
93
+
94
  var submit = true;
95
  // evaluate the form using generic validaing
96
  if (!validator.checkAll(wc_form)) {
114
  comment_post_ID: wc_comment_post_ID,
115
  comment_parent: wc_comment_parent,
116
  comment_depth: depth,
117
+ notification_type: notification_type,
118
  action: 'wc_comms_via_ajax'
119
  }
120
  }).done(function (response) {
184
  $('.wc_comm_form input').css('box-shadow', '0 0 4px -2px #d4d0ba');
185
  $('.wc_comm_form textarea').css('box-shadow', '0 0 4px -2px #d4d0ba');
186
 
187
+ notify_on_new_comment(wc_comment_post_ID, wc_new_comment_id, wc_email, notification_type);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
188
  } catch (e) {
189
  $('#wc_captcha-' + uniqueID).val('');
190
  $('.wc_tooltipster').tooltipster({offsetY: 2});
338
  });
339
  });
340
 
 
 
 
 
 
 
 
341
  // MUST BE CHANGED IN NEXT VERSION OF PLUGIN
342
  $(document).delegate('.wc_new_reply', 'click', function () {
343
  wc_submitID = $('.wc_main_comm_form input.wc_comm_submit').attr('id');
files/js/wc-frontend.js CHANGED
@@ -1,13 +1,13 @@
1
- jQuery(document).ready(function($){
2
- $('.wc_notification_new_comment').change(function () {
3
  if ($(this).is(':checked')) {
4
  $(this).val('1');
5
  } else {
6
  $(this).val('0');
7
  }
8
  });
9
-
10
- $('.wc_notification_new_reply').change(function () {
11
  if ($(this).is(':checked')) {
12
  $(this).val('1');
13
  } else {
1
+ jQuery(document).ready(function ($) {
2
+ $(document).delegate('.wc_notification_new_comment', 'change', function () {
3
  if ($(this).is(':checked')) {
4
  $(this).val('1');
5
  } else {
6
  $(this).val('0');
7
  }
8
  });
9
+
10
+ $(document).delegate('.wc_notification_new_reply', 'change', function () {
11
  if ($(this).is(':checked')) {
12
  $(this).val('1');
13
  } else {
helper/wc-helper.php CHANGED
@@ -260,6 +260,6 @@ class WC_Helper {
260
  $wc_parent_comments[$i] = $wc_parent_comments[$j];
261
  $wc_parent_comments[$j] = $tmp;
262
  return $wc_parent_comments;
263
- }
264
 
265
  }
260
  $wc_parent_comments[$i] = $wc_parent_comments[$j];
261
  $wc_parent_comments[$j] = $tmp;
262
  return $wc_parent_comments;
263
+ }
264
 
265
  }
includes/wc-db-helper.php CHANGED
@@ -16,25 +16,77 @@ class WC_DB_Helper {
16
  $this->dbprefix = $wpdb->prefix;
17
  $this->users_voted = $this->dbprefix . 'wc_users_voted';
18
  $this->phrases = $this->dbprefix . 'wc_phrases';
19
- $this->email_notification = $this->dbprefix . 'wc_email_notfication';
20
  }
21
 
22
  /**
23
  * create table in db on activation if not exists
24
  */
25
  public function create_tables() {
26
- if ($this->db->get_var("SHOW TABLES LIKE '$this->users_voted'") != $this->users_voted) {
27
  $sql = "CREATE TABLE `" . $this->users_voted . "`(`id` INT(11) NOT NULL AUTO_INCREMENT,`user_id` INT(11) NOT NULL, `comment_id` INT(11) NOT NULL, `vote_type` INT(11) DEFAULT NULL, PRIMARY KEY (`id`), KEY `user_id` (`user_id`), KEY `comment_id` (`comment_id`), KEY `vote_type` (`vote_type`)) ENGINE=MyISAM DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci AUTO_INCREMENT=1;";
28
  dbDelta($sql);
29
  }
30
- if ($this->db->get_var("SHOW TABLES LIKE '$this->phrases'") != $this->phrases) {
31
  $sql = "CREATE TABLE `" . $this->phrases . "`(`id` INT(11) NOT NULL AUTO_INCREMENT, `phrase_key` VARCHAR(255) NOT NULL, `phrase_value` VARCHAR(255) NOT NULL, PRIMARY KEY (`id`), KEY `phrase_key` (`phrase_key`)) ENGINE=MyISAM DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci AUTO_INCREMENT=1;";
32
  dbDelta($sql);
33
  }
34
- if ($this->db->get_var("SHOW TABLES LIKE '$this->email_notification'") != $this->email_notification) {
35
- $sql = "CREATE TABLE `" . $this->email_notification . "`(`id` INT(11) NOT NULL AUTO_INCREMENT,`email` VARCHAR(255) NOT NULL,`post_id` INT(11) DEFAULT 0,`comment_id` INT(11) DEFAULT 0, PRIMARY KEY (`id`), KEY `post_id` (`post_id`), KEY `comment_id` (`comment_id`))ENGINE=MYISAM DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci AUTO_INCREMENT=1;";
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  dbDelta($sql);
37
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  }
39
 
40
  /**
@@ -165,44 +217,73 @@ class WC_DB_Helper {
165
  return $this->db->get_results($sql_get_visible_ids, ARRAY_N);
166
  }
167
 
168
- public function wc_create_email_notification_tabel() {
169
- if ($this->db->get_var("SHOW TABLES LIKE '$this->email_notification'") != $this->email_notification) {
170
- $sql = "CREATE TABLE `" . $this->email_notification . "`(`id` INT(11) NOT NULL AUTO_INCREMENT,`email` VARCHAR(255) NOT NULL,`post_id` INT(11) DEFAULT 0,`comment_id` INT(11) DEFAULT 0, PRIMARY KEY (`id`), KEY `post_id` (`post_id`), KEY `comment_id` (`comment_id`))ENGINE=MYISAM DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci AUTO_INCREMENT=1;";
171
- dbDelta($sql);
172
- }
173
- }
174
-
175
- public function wc_add_email_notification($id, $email, $is_comment) {
176
- if ($is_comment) {
177
- $sql = $this->db->prepare("INSERT INTO `" . $this->email_notification . "`(`post_id`,`email`)VALUES(%d,%s);", $id, $email);
178
  } else {
179
- $sql = $this->db->prepare("INSERT INTO `" . $this->email_notification . "`(`comment_id`,`email`)VALUES(%d,%s);", $id, $email);
180
  }
 
 
181
  $this->db->query($sql);
182
  }
183
 
184
  public function wc_get_post_new_comment_notification($post_id, $email) {
185
- $sql = $this->db->prepare("SELECT `email` FROM `" . $this->email_notification . "` WHERE `post_id` = %d AND `email` != %s GROUP BY `email`", $post_id, $email);
186
- return $this->db->get_results($sql, ARRAY_N);
187
  }
188
 
189
  public function wc_get_post_new_reply_notification($comment_id, $email) {
190
- $sql = $this->db->prepare("SELECT `email` FROM `" . $this->email_notification . "` WHERE `comment_id` = %d AND `email` != %s GROUP BY `email`", $comment_id, $email);
191
- return $this->db->get_results($sql, ARRAY_N);
192
  }
193
 
194
- public function wc_has_notification_in_comment($post_id, $email) {
195
- $sql = $this->db->prepare("SELECT `id` FROM `" . $this->email_notification . "` WHERE `post_id` = %d AND `email` = %s", $post_id, $email);
196
  $result = $this->db->get_results($sql, ARRAY_N);
197
  return count($result);
198
  }
199
 
200
- public function wc_has_notification_in_reply($comment_id, $email) {
201
- $sql = $this->db->prepare("SELECT `id` FROM `" . $this->email_notification . "` WHERE `comment_id` = %d AND `email` = %s", $comment_id, $email);
 
 
 
 
 
202
  $result = $this->db->get_results($sql, ARRAY_N);
203
  return count($result);
204
  }
205
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
206
  }
207
 
208
  ?>
16
  $this->dbprefix = $wpdb->prefix;
17
  $this->users_voted = $this->dbprefix . 'wc_users_voted';
18
  $this->phrases = $this->dbprefix . 'wc_phrases';
19
+ $this->email_notification = $this->dbprefix . 'wc_email_notify';
20
  }
21
 
22
  /**
23
  * create table in db on activation if not exists
24
  */
25
  public function create_tables() {
26
+ if (!$this->wc_is_table_exists($this->users_voted)) {
27
  $sql = "CREATE TABLE `" . $this->users_voted . "`(`id` INT(11) NOT NULL AUTO_INCREMENT,`user_id` INT(11) NOT NULL, `comment_id` INT(11) NOT NULL, `vote_type` INT(11) DEFAULT NULL, PRIMARY KEY (`id`), KEY `user_id` (`user_id`), KEY `comment_id` (`comment_id`), KEY `vote_type` (`vote_type`)) ENGINE=MyISAM DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci AUTO_INCREMENT=1;";
28
  dbDelta($sql);
29
  }
30
+ if (!$this->wc_is_table_exists($this->phrases)) {
31
  $sql = "CREATE TABLE `" . $this->phrases . "`(`id` INT(11) NOT NULL AUTO_INCREMENT, `phrase_key` VARCHAR(255) NOT NULL, `phrase_value` VARCHAR(255) NOT NULL, PRIMARY KEY (`id`), KEY `phrase_key` (`phrase_key`)) ENGINE=MyISAM DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci AUTO_INCREMENT=1;";
32
  dbDelta($sql);
33
  }
34
+ $this->wc_create_email_notification_table();
35
+ }
36
+
37
+ /**
38
+ * check if table exists in database
39
+ * return true if exists false otherwise
40
+ */
41
+ public function wc_is_table_exists($wc_table_name) {
42
+ return $this->db->get_var("SHOW TABLES LIKE '$wc_table_name'") == $wc_table_name;
43
+ }
44
+
45
+ public function wc_create_email_notification_table() {
46
+ $wc_old_notification_table_name = $this->dbprefix . 'wc_email_notfication';
47
+ if (!$this->wc_is_table_exists($this->email_notification)) {
48
+ $sql = "CREATE TABLE `" . $this->email_notification . "`(`id` INT(11) NOT NULL AUTO_INCREMENT, `email` VARCHAR(255) NOT NULL, `subscribtion_id` INT(11) NOT NULL, `post_id` INT(11) NOT NULL, `subscribtion_type` VARCHAR(255) NOT NULL, `activation_key` VARCHAR(255) NOT NULL, PRIMARY KEY (`id`), KEY `subscribtion_id` (`subscribtion_id`), KEY `post_id` (`post_id`)) ENGINE=MYISAM DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci AUTO_INCREMENT=1;";
49
  dbDelta($sql);
50
  }
51
+
52
+ if ($this->wc_is_table_exists($wc_old_notification_table_name)) {
53
+ $this->wc_save_notification_data($wc_old_notification_table_name);
54
+ }
55
+ }
56
+
57
+ /**
58
+ * save old notification data into new created table and drop old table
59
+ */
60
+ public function wc_save_notification_data($wc_old_notification_table_name) {
61
+ $sql_post_notification_data = "SELECT * FROM `" . $wc_old_notification_table_name . "` WHERE `post_id` > 0;";
62
+ $sql_comment_notification_data = "SELECT * FROM `" . $wc_old_notification_table_name . "` WHERE `comment_id` > 0;";
63
+ $post_notifications_data = $this->db->get_results($sql_post_notification_data, ARRAY_A);
64
+ $comment_notifications_data = $this->db->get_results($sql_comment_notification_data, ARRAY_A);
65
+ $inserted_post_ids = array();
66
+ foreach ($post_notifications_data as $p_notification_data) {
67
+ $email = $p_notification_data['email'];
68
+ $post_id = $p_notification_data['post_id'];
69
+ $inserted_post_ids[] = $post_id;
70
+ $subscribtion_type = "post";
71
+ $activation_key = md5($email . uniqid() . time());
72
+ $sql_add_old_post_notification = "INSERT INTO `" . $this->email_notification . "` (`email`, `subscribtion_id`, `post_id`, `subscribtion_type`, `activation_key`) VALUES('$email', $post_id, $post_id, '$subscribtion_type', '$activation_key');";
73
+ $this->db->query($sql_add_old_post_notification);
74
+ }
75
+
76
+ foreach ($comment_notifications_data as $c_notification_data) {
77
+ $email = $c_notification_data['email'];
78
+ $comment_id = $c_notification_data['comment_id'];
79
+ $comment = get_comment($comment_id);
80
+ if (!$this->wc_has_comment_notification($comment->comment_post_ID, $comment_id, $email)) {
81
+ $subscribtion_type = "comment";
82
+ $activation_key = md5($email . uniqid() . time());
83
+ $sql_add_old_post_notification = "INSERT INTO `" . $this->email_notification . "` (`email`, `subscribtion_id`, `post_id`, `subscribtion_type`, `activation_key`) VALUES('$email', $comment_id, $comment->comment_post_ID, '$subscribtion_type', '$activation_key');";
84
+ $this->db->query($sql_add_old_post_notification);
85
+ }
86
+ }
87
+
88
+ $sql_drop_old_notification_table = "DROP TABLE `" . $wc_old_notification_table_name . "`;";
89
+ $this->db->query($sql_drop_old_notification_table);
90
  }
91
 
92
  /**
217
  return $this->db->get_results($sql_get_visible_ids, ARRAY_N);
218
  }
219
 
220
+ public function wc_add_email_notification($id, $post_id, $email, $is_all) {
221
+ if ($is_all) {
222
+ $subscribtion_type = 'post';
223
+ $this->wc_delete_comment_notifications($id, $email);
 
 
 
 
 
 
224
  } else {
225
+ $subscribtion_type = 'comment';
226
  }
227
+ $activation_key = md5($email . uniqid() . time());
228
+ $sql = $this->db->prepare("INSERT INTO `" . $this->email_notification . "` (`email`, `subscribtion_id`, `post_id`, `subscribtion_type`, `activation_key`) VALUES(%s, %d, %d, %s, %s);", $email, $id, $post_id, $subscribtion_type, $activation_key);
229
  $this->db->query($sql);
230
  }
231
 
232
  public function wc_get_post_new_comment_notification($post_id, $email) {
233
+ $sql = $this->db->prepare("SELECT `id`,`email`,`activation_key` FROM `" . $this->email_notification . "` WHERE `subscribtion_type` = 'post' AND `subscribtion_id` = %d AND `email` != %s;", $post_id, $email);
234
+ return $this->db->get_results($sql, ARRAY_A);
235
  }
236
 
237
  public function wc_get_post_new_reply_notification($comment_id, $email) {
238
+ $sql = $this->db->prepare("SELECT `id`,`email`,`activation_key` FROM `" . $this->email_notification . "` WHERE `subscribtion_type` = 'comment' AND `subscribtion_id` = %d AND `email` != %s;", $comment_id, $email);
239
+ return $this->db->get_results($sql, ARRAY_A);
240
  }
241
 
242
+ public function wc_has_post_notification($post_id, $email) {
243
+ $sql = $this->db->prepare("SELECT `id` FROM `" . $this->email_notification . "` WHERE `subscribtion_type` = 'post' AND `subscribtion_id` = %d AND `email` = %s", $post_id, $email);
244
  $result = $this->db->get_results($sql, ARRAY_N);
245
  return count($result);
246
  }
247
 
248
+ public function wc_has_comment_notification($post_id, $comment_id, $email) {
249
+ $sql_comments_notifications = $this->db->prepare("SELECT count(*) FROM `" . $this->email_notification . "` WHERE `email` LIKE %s AND `subscribtion_type` LIKE 'post' AND `subscribtion_id` = %d", $email, $post_id);
250
+ if ($this->db->get_var($sql_comments_notifications)) {
251
+ return 1;
252
+ }
253
+
254
+ $sql = $this->db->prepare("SELECT `id` FROM `" . $this->email_notification . "` WHERE `subscribtion_type` = 'comment' AND `subscribtion_id` = %d AND `email` = %s", $comment_id, $email);
255
  $result = $this->db->get_results($sql, ARRAY_N);
256
  return count($result);
257
  }
258
 
259
+ /**
260
+ * delete comment thread subscribtions if new subscribtion type is post
261
+ */
262
+ public function wc_delete_comment_notifications($post_id, $email) {
263
+ $sql_delete_comment_notifications = $this->db->prepare("DELETE FROM `" . $this->email_notification . "` WHERE `subscribtion_type` = 'comment' AND `post_id` = %d AND `email` LIKE %s;", $post_id, $email);
264
+ $this->db->query($sql_delete_comment_notifications);
265
+ }
266
+
267
+ /**
268
+ * create unsubscribe link
269
+ */
270
+ public function wc_unsubscribe_link($id, $email, $subscribtion_type) {
271
+ $sql_subscriber_data = $this->db->prepare("SELECT `id`, `post_id`, `activation_key` FROM `" . $this->email_notification . "` WHERE `subscribtion_type` = %s AND `subscribtion_id` = %d AND `email` LIKE %s", $subscribtion_type, $id, $email);
272
+ $wc_unsubscribe = $this->db->get_row($sql_subscriber_data, ARRAY_A);
273
+ $post_id = $wc_unsubscribe['post_id'];
274
+
275
+ $wc_unsubscribe_link = get_permalink($post_id) . "?wpdiscuzSubscribeID=" . $wc_unsubscribe['id'] . "&key=" . $wc_unsubscribe['activation_key'] . '&#wc_unsubscribe_message';
276
+ return $wc_unsubscribe_link;
277
+ }
278
+
279
+ /**
280
+ * delete subscribtion
281
+ */
282
+ public function wc_unsubscribe($id, $activation_key) {
283
+ $sql_unsubscribe = $this->db->prepare("DELETE FROM `" . $this->email_notification . "` WHERE `id` = %d AND `activation_key` LIKE %s", $id, $activation_key);
284
+ return $this->db->query($sql_unsubscribe);
285
+ }
286
+
287
  }
288
 
289
  ?>
options-templates/options-template-main.php CHANGED
@@ -229,7 +229,7 @@
229
  <tr valign="top">
230
  <th scope="row">
231
  <span><?php _e('Show "Notify of all new follow-up comments"', 'wpdiscuz'); ?></span><br />
232
- <span style="line-height:22px;"><?php _e('Show "Notify of new replies to my comments"', 'wpdiscuz'); ?></span><br />
233
  <p style="font-size:13px; color:#999999; width:80%; padding-left:0px; margin-left:0px;">
234
  <?php _e('Please keep the both or at least one of those options ON, otherwise users will not have any option for email notifications and they\'ll not get any messages.', 'wpdiscuz') ?></p>
235
  </th>
229
  <tr valign="top">
230
  <th scope="row">
231
  <span><?php _e('Show "Notify of all new follow-up comments"', 'wpdiscuz'); ?></span><br />
232
+ <span style="line-height:22px;"><?php _e('Show "Notify of new replies to this comment"', 'wpdiscuz'); ?></span><br />
233
  <p style="font-size:13px; color:#999999; width:80%; padding-left:0px; margin-left:0px;">
234
  <?php _e('Please keep the both or at least one of those options ON, otherwise users will not have any option for email notifications and they\'ll not get any messages.', 'wpdiscuz') ?></p>
235
  </th>
options-templates/options-template-phrases.php CHANGED
@@ -127,7 +127,7 @@
127
  </th>
128
  <td colspan="3">
129
  <label for="wc_notify_on_new_reply">
130
- <input type="text" value="<?php echo isset($this->wc_options_serialized->wc_phrases['wc_notify_on_new_reply']) ? $this->wc_options_serialized->wc_phrases['wc_notify_on_new_reply'] : _e('Notify of new replies to my comments', 'wpdiscuz'); ?>" name="wc_notify_on_new_reply" id="wc_notify_on_new_reply" />
131
  </label>
132
  </td>
133
  </tr>
@@ -311,6 +311,50 @@
311
  </td>
312
  </tr>
313
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
314
  <tr valign="top">
315
  <th scope="row">
316
  <?php _e('Error message for empty field', 'wpdiscuz'); ?>
127
  </th>
128
  <td colspan="3">
129
  <label for="wc_notify_on_new_reply">
130
+ <input type="text" value="<?php echo isset($this->wc_options_serialized->wc_phrases['wc_notify_on_new_reply']) ? $this->wc_options_serialized->wc_phrases['wc_notify_on_new_reply'] : _e('Notify of new replies to this comment', 'wpdiscuz'); ?>" name="wc_notify_on_new_reply" id="wc_notify_on_new_reply" />
131
  </label>
132
  </td>
133
  </tr>
311
  </td>
312
  </tr>
313
 
314
+ <tr valign="top">
315
+ <th scope="row">
316
+ <?php _e('Subscribed on this comment replies', 'wpdiscuz'); ?>
317
+ </th>
318
+ <td colspan="3">
319
+ <label for="wc_subscribed_on_comment">
320
+ <textarea name="wc_subscribed_on_comment" id="wc_subscribed_on_comment"><?php echo $this->wc_options_serialized->wc_phrases['wc_subscribed_on_comment']; ?></textarea>
321
+ </label>
322
+ </td>
323
+ </tr>
324
+
325
+ <tr valign="top">
326
+ <th scope="row">
327
+ <?php _e('Subscribed on this post', 'wpdiscuz'); ?>
328
+ </th>
329
+ <td colspan="3">
330
+ <label for="wc_subscribed_on_post">
331
+ <textarea name="wc_subscribed_on_post" id="wc_subscribed_on_post"><?php echo $this->wc_options_serialized->wc_phrases['wc_subscribed_on_post']; ?></textarea>
332
+ </label>
333
+ </td>
334
+ </tr>
335
+
336
+ <tr valign="top">
337
+ <th scope="row">
338
+ <?php _e('New Reply Message', 'wpdiscuz'); ?>
339
+ </th>
340
+ <td colspan="3">
341
+ <label for="wc_unsubscribe">
342
+ <input type="text" name="wc_unsubscribe" id="wc_unsubscribe" class="wc_unsubscribe" value="<?php echo $this->wc_options_serialized->wc_phrases['wc_unsubscribe']; ?>" placeholder="<?php echo _e('Unsubscribe', 'wpdiscuz'); ?>"/>
343
+ </label>
344
+ </td>
345
+ </tr>
346
+
347
+ <tr valign="top">
348
+ <th scope="row">
349
+ <?php _e('You\'ve successfully unsubscribed.', 'wpdiscuz'); ?>
350
+ </th>
351
+ <td colspan="3">
352
+ <label for="wc_unsubscribe_message">
353
+ <textarea name="wc_unsubscribe_message" id="wc_unsubscribe_message"><?php echo $this->wc_options_serialized->wc_phrases['wc_unsubscribe_message']; ?></textarea>
354
+ </label>
355
+ </td>
356
+ </tr>
357
+
358
  <tr valign="top">
359
  <th scope="row">
360
  <?php _e('Error message for empty field', 'wpdiscuz'); ?>
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
4
  Tags: wordpress comments, ajax comments, ajax, live update, theme, post comments, comments box, community, discussion, discuss, comment form, reply, comments, discussions, comment template, activity, comment author, comment system
5
  Requires at least: 2.7
6
  Tested up to: 4.1
7
- Stable tag: 2.0.3
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -108,12 +108,18 @@ IMPORTANT: If you have a Cache Plugin, please delete all caches after wpDiscuz u
108
 
109
  == Changelog ==
110
 
 
 
 
 
 
 
 
 
111
  = 2.0.3 =
112
  * Fixed Bug: Problem with email notification options on comment form
113
  * Added : Option to keep checked-on the email notification checkboxes on comment form by default
114
 
115
- IMPORTANT: If you have a Cache Plugin, please reset after wpDiscuz update
116
-
117
 
118
  = 2.0.2 =
119
  * Fixed Bug: Problem with saving checkbox options (incorrect logic of values)
4
  Tags: wordpress comments, ajax comments, ajax, live update, theme, post comments, comments box, community, discussion, discuss, comment form, reply, comments, discussions, comment template, activity, comment author, comment system
5
  Requires at least: 2.7
6
  Tested up to: 4.1
7
+ Stable tag: 2.0.4
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
108
 
109
  == Changelog ==
110
 
111
+ = 2.0.4 =
112
+ * Added : Current subscribe status note on comment form (for logged-in users)
113
+ * Added : Unsubscribe link on comment form and in "new comment" notification message.
114
+ * Fixed Bug: Redirection to blank option.php on saving any option page.
115
+
116
+ IMPORTANT: If you have a Cache Plugin, please reset after wpDiscuz update
117
+
118
+
119
  = 2.0.3 =
120
  * Fixed Bug: Problem with email notification options on comment form
121
  * Added : Option to keep checked-on the email notification checkboxes on comment form by default
122
 
 
 
123
 
124
  = 2.0.2 =
125
  * Fixed Bug: Problem with saving checkbox options (incorrect logic of values)
wc-css.php CHANGED
@@ -13,7 +13,7 @@ class WC_CSS {
13
  */
14
  public function init_styles() {
15
  ?>
16
- <style type="text/css"> #wc-comment-header{ padding:20px 5px 1px 5px; display:block; float:none; clear:both; font-size:18px;} #wpcomm form div{ box-sizing: inherit; } #wpcomm form .item {display: block;} .item input { border-radius:0px; } #wpcomm { margin:15px 5px; padding:1px 0px 10px 0px; border-top:#DDDDDD solid 1px; } #wpcomm form { margin:0px; padding:0px; background:none; border:none; } #wpcomm form div{ margin:0px; } #wpcomm .wc_new_comment_and_replies { margin:0px; padding:0px; width:100%; height:auto; background:transparent;} #wpcomm .wc_new_comment_and_replies .wc_new_comment{ float:right; display:none; background:<?php echo $this->wc_options->wc_options_serialized->wc_author_title_color; ?>; padding:3px 10px; font-size:12px; margin:1px 0px 1px 3px; cursor:pointer; color:#fff; line-height: 15px;} #wpcomm .wc_new_comment_and_replies .wc_new_reply{ float:right; display:none; background:<?php echo $this->wc_options->wc_options_serialized->wc_author_title_color; ?>; padding:3px 10px; font-size:12px; margin:1px 0px 1px 1px; cursor:pointer; color:#fff; line-height: 15px;} #wpcomm .wc-comment-title{ margin:0px; line-height:18px; font-weight:bold; padding:10px; margin-bottom:10px; font-size:13px; text-align:right; border-bottom:#CCCCCC dotted 1px; padding-bottom:10px; } #wpcomm .wc-form-wrapper{ padding:10px; background:<?php echo isset($this->wc_options->wc_options_serialized->wc_form_bg_color) ? $this->wc_options->wc_options_serialized->wc_form_bg_color : '#f9f9f9'; ?>; margin-top:20px; border:1px solid #F1F1F1; } #wpcomm .wc-author-data{ margin-bottom:6px; } #wpcomm .wc-field-submit{ padding:5px 0px 13px 0px; } #wpcomm .wc-field-name{ width:49%; float:left; } #wpcomm .wc-field-email{ width:49%; float:right; text-align:right; } #wpcomm .wc-field-comment{ margin:5px auto 10px auto; } #wpcomm .wc-field-captcha{ width:55%; float:left; margin:0px; height:auto!important; } #wpcomm .wc-field-submit{ width:45%; float:right; text-align:right; margin:0px; } #wpcomm .wc-field-name input[type="text"]{ width:99%; max-width:100%; padding:5px; font-size:14px; margin:0px; height:29px; } #wpcomm .wc-field-email input[type="email"]{ width:100%; max-width:100%; padding:5px; font-size:14px; margin:0px; height:29px; } #wpcomm .wc-field-captcha input[type="text"]{ width:40%; padding:5px; font-size:14px; margin:0px 5px 0px 0px; height:27px; } #wpcomm .wc-field-submit input[type="submit"]{ margin:1px; } #wpcomm .wc-field-submit input[type="button"]{ margin:1px; border:#DDDDDD 1px solid; font-size: 13px; line-height: 16px; padding: 6px 15px; } #wpcomm .captcha_msg{ color: #999999; font-family: Lato,sans-serif; font-size: 13px; line-height: 18px; display:block; clear:both; padding:5px 0px 0px 0px; } #wpcomm .wc-field-comment textarea{ width:100%; max-width:100%; height:46px; min-height: 46px !important; padding:5px; box-sizing: border-box; border-radius:0px; } #wpcomm .wc-label{ display:block; font-size:14px; padding:5px; } #wpcomm .wc_notification_checkboxes{ padding:1px 0px 7px 0px; text-align:left;} #wpcomm .wc_notification_checkboxes input[type="checkbox"]{ overflow:none; width:inherit; font-size:13px; margin:0px; padding:0px; display:inline; } #wpcomm .wc-label-comment-notify{ display:inline; font-size:13px; padding:0px; margin:0px; border:none; line-height:15px; text-decoration:none; color:#999999; font-family:Lato,sans-serif; cursor:pointer; } #wpcomm .wc-label-reply-notify{ display:inline; font-size:13px; padding:0px; margin:0px; border:none; line-height:15px; text-decoration:none; color:#999999; font-family:Lato,sans-serif; cursor:pointer; } #wpcomm .wc-field-captcha .wc-label{ font-size:14px; padding:5px; text-align:center; display:inline; } #wpcomm input[type="text"], #wpcomm input[type="email"], #wpcomm textarea{ font-size:14px; color:#666666; font-family:Lato,sans-serif; box-sizing: border-box; margin:0px; } #wpcomm .wc-copyright{ margin: 0px 0px 0px auto; text-align:right; display: block; padding-top: 2px; } #wpcomm .wc-copyright a{ font-size: 9px; color: #AAAAAA; cursor:help; text-decoration:none; margin:0px; padding:0px; border:none;} #wpcomm .wc-thread-wrapper{ padding:10px 0px; margin-bottom:10px;} #wpcomm .wc-comment { margin-bottom:13px; } #wpcomm .wc-comment .wc-field-submit{ padding:5px 0px 5px 0px; } #wpcomm .wc-comment .wc-form-wrapper{ padding:10px 10px 2px 10px; } #wpcomm .wc-comment .wc-comment-left{ width:62px; float:left; position:absolute; text-align:center; font-family:Lato,sans-serif; line-height:16px; } #wpcomm .wc-comment .wc-comment-right{ margin-left:70px; border:#F5F5F5 1px solid; padding:10px 10px 3px 10px; background:<?php echo $this->wc_options->wc_options_serialized->wc_comment_bg_color; ?>} #wpcomm .wc-reply .wc-comment-right{ margin-left:70px; border:#F5F5F5 1px solid; padding:10px 10px 3px 10px; } #wpcomm .wc-reply { margin-top: 10px; margin-bottom:0px; margin-left:40px; } #wpcomm .wc-reply .wc-comment-right{ background:<?php echo $this->wc_options->wc_options_serialized->wc_reply_bg_color; ?>; } #wpcomm .wc-must-login{ margin:0px; font-size:14px; line-height:16px; padding:10px; text-align:center; } #wpcomm hr{ background-color: rgba(0, 0, 0, 0.1); border: 0 none; height: 1px; margin:10px 0px; } #wpcomm .avatar{ border: 1px solid rgba(0, 0, 0, 0.1); padding: 2px; margin:0px auto; float:none; display:inline; width:48px; height:auto; } #wpcomm .wc-comment-text{ font-size:<?php echo isset($this->wc_options->wc_options_serialized->wc_comment_text_size) ? $this->wc_options->wc_options_serialized->wc_comment_text_size : '14px'; ?>; text-align:left; color:<?php echo $this->wc_options->wc_options_serialized->wc_comment_text_color; ?>; padding-bottom:5px; line-height: 20px; } #wpcomm .wc-comment-header{ margin-bottom:7px; font-family:Lato,sans-serif; } #wpcomm .wc-comment-author{ color:<?php echo $this->wc_options->wc_options_serialized->wc_author_title_color; ?>; font-size:16px; width:40%; float:left; white-space:nowrap; } #wpcomm .wc-comment-author a{ color:<?php echo $this->wc_options->wc_options_serialized->wc_author_title_color; ?>; font-size:16px; white-space:nowrap; text-decoration:none; } #wpcomm .wc-comment-label{ background:<?php echo $this->wc_options->wc_options_serialized->wc_author_title_color; ?>; color:#FFFFFF; padding:2px 5px; font-size:12px; margin:4px auto; text-align:center; display:table; line-height:16px; } #wpcomm .wc-comment-date{ font-size:12px; color:#999999; float:right; text-align:right; white-space:nowrap; line-height:27px; } #wpcomm .wc-comment-footer { font-size:12px; font-weight:normal; color:#999999; margin-top:12px; min-height: 28px; font-family:Lato,sans-serif; } #wpcomm .wc-comment-footer a{ text-decoration:none; font-size:13px; font-weight:bold; color:<?php echo $this->wc_options->wc_options_serialized->wc_vote_reply_color; ?>; } #wpcomm .wc-comment-footer .share_buttons_box img{ vertical-align:middle; } #wpcomm .wc-comment-footer .wc-voted{ color:#666666; cursor:default; } #wpcomm .wc-comment-footer .wc-vote-result{ padding:2px 6px 2px 5px; background:<?php echo $this->wc_options->wc_options_serialized->wc_vote_reply_color; ?>; color:#FFFFFF; font-size:12px; font-weight:bold; display:inline; margin-right:5px;} #wpcomm .wc-toggle{ float:right; text-align:right; padding-right:0px; margin-right:0px; color:#999999; cursor:pointer; font-size:12px; white-space:nowrap; } #wpcomm .item { background: none; border-radius: 0px; box-shadow: none; } #wc_response_info img{ margin: 0px auto 0px auto; } #wpcomm .share_buttons_box img { display:inline!important; width:16px; height:16px; } #wpcomm .wc-captcha-label img{ display: inline!important; border:none; padding:0px 0px 0px 2px; margin:0px; vertical-align:middle; } #wpcomm .wc-reply-link, #wpcomm .wc-vote-link, #wpcomm .wc-share-link { cursor: pointer; font-size:13px; font-weight:bold; color: <?php echo $this->wc_options->wc_options_serialized->wc_vote_reply_color; ?>; } #wpcomm .wc-form-footer, #wpcomm .wc-secondary-forms-wrapper {display: none;} #wpcomm .wc-field-captcha .wc-captcha-label { padding: 0; display: inline-block; } #wpcomm .wc_captcha_refresh_img {cursor: pointer; margin-left: 3px;} #wpcomm .share_buttons_box {display: none;} #wpcomm .wc-no-left-margin {margin-left: 0 !important;} div.wc_modal { background: none repeat scroll 0 0 #EDEDED; color:#444444; font-size: 18px; font-weight: normal; padding: 45px 10px 50px 10px!important; text-align: center; line-height:25px;} .wc-load-more-submit-wrap { width: 100%; text-align: center; margin-bottom:20px; } .wc-load-more-submit { width: 100%; text-align: center; } #wc_openModalFormAction > div#wc_response_info { width: 200px; background: none repeat scroll 0 0 #EDEDED; color:#444444; font-size: 18px; font-weight: normal; padding: 45px 10px 50px 10px!important; text-align: center; line-height:25px;} #wc_openModalFormAction > div#wc_response_info { } #wc_openModalFormAction > div#wc_response_info a.close { background: url("<?php echo plugins_url(WC_Core::$PLUGIN_DIRECTORY . '/files/img/x.png'); ?>") no-repeat; background-position-x: right; background-position-y: top; } #wpcomm #bywpdiscuz{ display:none; } #wpcomm .by-wpdiscuz{ text-align:right; border-top:#DDDDDD solid 1px; padding:1px 1px 1px 1px; } #wpcomm .by-wpdiscuz a{ font-size:11px; font-weight:bold; text-align:right; color:#CCCCCC; padding:1px; margin:0px; line-height:12px; border:none; text-decoration:none; } #wpcomm .wpdimg{ border:none; padding:0px; margin:0px; height:12px; cursor:pointer; display:inline; clear:both; } #wpcomm .wc-comment .wc-comment-right.wc_new_loaded_comment {background: <?php echo $this->wc_options->wc_options_serialized->wc_new_loaded_comment_bg_color; ?>;} <?php echo stripslashes($this->wc_options->wc_options_serialized->wc_custom_css); ?></style>
17
  <?php
18
  }
19
 
13
  */
14
  public function init_styles() {
15
  ?>
16
+ <style type="text/css"> #wc-comment-header{ padding:20px 5px 1px 5px; display:block; float:none; clear:both; font-size:18px;} #wpcomm form div{ box-sizing: inherit; } #wpcomm form .item {display: block;} .item input { border-radius:0px; } #wpcomm { margin:15px 5px; padding:1px 0px 10px 0px; border-top:#DDDDDD solid 1px; } #wpcomm form { margin:0px; padding:0px; background:none; border:none; } #wpcomm form div{ margin:0px; } #wpcomm .wc_new_comment_and_replies { margin:0px; padding:0px; width:100%; height:auto; background:transparent;} #wpcomm .wc_new_comment_and_replies .wc_new_comment{ float:right; display:none; background:<?php echo $this->wc_options->wc_options_serialized->wc_author_title_color; ?>; padding:3px 10px; font-size:12px; margin:1px 0px 1px 3px; cursor:pointer; color:#fff; line-height: 15px;} #wpcomm .wc_new_comment_and_replies .wc_new_reply{ float:right; display:none; background:<?php echo $this->wc_options->wc_options_serialized->wc_author_title_color; ?>; padding:3px 10px; font-size:12px; margin:1px 0px 1px 1px; cursor:pointer; color:#fff; line-height: 15px;} #wpcomm .wc-comment-title{ margin:0px; line-height:18px; font-weight:bold; padding:10px; margin-bottom:10px; font-size:13px; text-align:right; border-bottom:#CCCCCC dotted 1px; padding-bottom:10px; } #wpcomm .wc-form-wrapper{ padding:10px; background:<?php echo isset($this->wc_options->wc_options_serialized->wc_form_bg_color) ? $this->wc_options->wc_options_serialized->wc_form_bg_color : '#f9f9f9'; ?>; margin-top:20px; border:1px solid #F1F1F1; } #wpcomm .wc-author-data{ margin-bottom:6px; } #wpcomm .wc-field-submit{ padding:5px 0px 13px 0px; } #wpcomm .wc-field-name{ width:49%; float:left; } #wpcomm .wc-field-email{ width:49%; float:right; text-align:right; } #wpcomm .wc-field-comment{ margin:5px auto 10px auto; } #wpcomm .wc-field-captcha{ width:55%; float:left; margin:0px; height:auto!important; } #wpcomm .wc-field-submit{ width:45%; float:right; text-align:right; margin:0px; } #wpcomm .wc-field-name input[type="text"]{ width:99%; max-width:100%; padding:5px; font-size:14px; margin:0px; height:29px; } #wpcomm .wc-field-email input[type="email"]{ width:100%; max-width:100%; padding:5px; font-size:14px; margin:0px; height:29px; } #wpcomm .wc-field-captcha input[type="text"]{ width:40%; padding:5px; font-size:14px; margin:0px 5px 0px 0px; height:27px; } #wpcomm .wc-field-submit input[type="submit"]{ margin:1px; } #wpcomm .wc-field-submit input[type="button"]{ margin:1px; border:#DDDDDD 1px solid; font-size: 13px; line-height: 16px; padding: 6px 15px; } #wpcomm .captcha_msg{ color: #999999; font-family: Lato,sans-serif; font-size: 13px; line-height: 18px; display:block; clear:both; padding:5px 0px 0px 0px; } #wpcomm .wc-field-comment textarea{ width:100%; max-width:100%; height:46px; min-height: 46px !important; padding:5px; box-sizing: border-box; border-radius:0px; } #wpcomm .wc-label{ display:block; font-size:14px; padding:5px; } #wpcomm .wc_notification_checkboxes{ padding:1px 0px 7px 0px; text-align:left;} #wpcomm .wc_notification_checkboxes input[type="checkbox"]{ overflow:none; width:inherit; font-size:13px; margin:0px; padding:0px; display:inline; } #wpcomm .wc-label-comment-notify{ display:inline; font-size:13px; padding:0px; margin:0px; border:none; line-height:15px; text-decoration:none; color:#999999; font-family:Lato,sans-serif; cursor:pointer; } #wpcomm .wc-label-reply-notify{ display:inline; font-size:13px; padding:0px; margin:0px; border:none; line-height:15px; text-decoration:none; color:#999999; font-family:Lato,sans-serif; cursor:pointer; } #wpcomm .wc-field-captcha .wc-label{ font-size:14px; padding:5px; text-align:center; display:inline; } #wpcomm input[type="text"], #wpcomm input[type="email"], #wpcomm textarea{ font-size:14px; color:#666666; font-family:Lato,sans-serif; box-sizing: border-box; margin:0px; } #wpcomm .wc-copyright{ margin: 0px 0px 0px auto; text-align:right; display: block; padding-top: 2px; } #wpcomm .wc-copyright a{ font-size: 9px; color: #AAAAAA; cursor:help; text-decoration:none; margin:0px; padding:0px; border:none;} #wpcomm .wc-thread-wrapper{ padding:10px 0px; margin-bottom:10px;} #wpcomm .wc-comment { margin-bottom:13px; } #wpcomm .wc-comment .wc-field-submit{ padding:5px 0px 5px 0px; } #wpcomm .wc-comment .wc-form-wrapper{ padding:10px 10px 2px 10px; } #wpcomm .wc-comment .wc-comment-left{ width:62px; float:left; position:absolute; text-align:center; font-family:Lato,sans-serif; line-height:16px; } #wpcomm .wc-comment .wc-comment-right{ margin-left:70px; border:#F5F5F5 1px solid; padding:10px 10px 3px 10px; background:<?php echo $this->wc_options->wc_options_serialized->wc_comment_bg_color; ?>} #wpcomm .wc-reply .wc-comment-right{ margin-left:70px; border:#F5F5F5 1px solid; padding:10px 10px 3px 10px; } #wpcomm .wc-reply { margin-top: 10px; margin-bottom:0px; margin-left:40px; } #wpcomm .wc-reply .wc-comment-right{ background:<?php echo $this->wc_options->wc_options_serialized->wc_reply_bg_color; ?>; } #wpcomm .wc-must-login{ margin:0px; font-size:14px; line-height:16px; padding:10px; text-align:center; } #wpcomm hr{ background-color: rgba(0, 0, 0, 0.1); border: 0 none; height: 1px; margin:10px 0px; } #wpcomm .avatar{ border: 1px solid rgba(0, 0, 0, 0.1); padding: 2px; margin:0px auto; float:none; display:inline; width:48px; height:auto; } #wpcomm .wc-comment-text{ font-size:<?php echo isset($this->wc_options->wc_options_serialized->wc_comment_text_size) ? $this->wc_options->wc_options_serialized->wc_comment_text_size : '14px'; ?>; text-align:left; color:<?php echo $this->wc_options->wc_options_serialized->wc_comment_text_color; ?>; padding-bottom:5px; line-height: 20px; } #wpcomm .wc-comment-header{ margin-bottom:7px; font-family:Lato,sans-serif; } #wpcomm .wc-comment-author{ color:<?php echo $this->wc_options->wc_options_serialized->wc_author_title_color; ?>; font-size:16px; width:40%; float:left; white-space:nowrap; } #wpcomm .wc-comment-author a{ color:<?php echo $this->wc_options->wc_options_serialized->wc_author_title_color; ?>; font-size:16px; white-space:nowrap; text-decoration:none; } #wpcomm .wc-comment-label{ background:<?php echo $this->wc_options->wc_options_serialized->wc_author_title_color; ?>; color:#FFFFFF; padding:2px 5px; font-size:12px; margin:4px auto; text-align:center; display:table; line-height:16px; } #wpcomm .wc-comment-date{ font-size:12px; color:#999999; float:right; text-align:right; white-space:nowrap; line-height:27px; } #wpcomm .wc-comment-footer { font-size:12px; font-weight:normal; color:#999999; margin-top:12px; min-height: 28px; font-family:Lato,sans-serif; } #wpcomm .wc-comment-footer a{ text-decoration:none; font-size:13px; font-weight:bold; color:<?php echo $this->wc_options->wc_options_serialized->wc_vote_reply_color; ?>; } #wpcomm .wc-comment-footer .share_buttons_box img{ vertical-align:middle; } #wpcomm .wc-comment-footer .wc-voted{ color:#666666; cursor:default; } #wpcomm .wc-comment-footer .wc-vote-result{ padding:2px 6px 2px 5px; background:<?php echo $this->wc_options->wc_options_serialized->wc_vote_reply_color; ?>; color:#FFFFFF; font-size:12px; font-weight:bold; display:inline; margin-right:5px;} #wpcomm .wc-toggle{ float:right; text-align:right; padding-right:0px; margin-right:0px; color:#999999; cursor:pointer; font-size:12px; white-space:nowrap; } #wpcomm .item { background: none; border-radius: 0px; box-shadow: none; } #wc_response_info img{ margin: 0px auto 0px auto; } #wpcomm .share_buttons_box img { display:inline!important; width:16px; height:16px; } #wpcomm .wc-captcha-label img{ display: inline!important; border:none; padding:0px 0px 0px 2px; margin:0px; vertical-align:middle; } #wpcomm .wc-reply-link, #wpcomm .wc-vote-link, #wpcomm .wc-share-link { cursor: pointer; font-size:13px; font-weight:bold; color: <?php echo $this->wc_options->wc_options_serialized->wc_vote_reply_color; ?>; } #wpcomm .wc-form-footer, #wpcomm .wc-secondary-forms-wrapper {display: none;} #wpcomm .wc-field-captcha .wc-captcha-label { padding: 0; display: inline-block; } #wpcomm .wc_captcha_refresh_img {cursor: pointer; margin-left: 3px;} #wpcomm .share_buttons_box {display: none;} #wpcomm .wc-no-left-margin {margin-left: 0 !important;} div.wc_modal { background: none repeat scroll 0 0 #EDEDED; color:#444444; font-size: 18px; font-weight: normal; padding: 45px 10px 50px 10px!important; text-align: center; line-height:25px;} .wc-load-more-submit-wrap { width: 100%; text-align: center; margin-bottom:20px; } .wc-load-more-submit { width: 100%; text-align: center; } #wc_openModalFormAction > div#wc_response_info { width: 200px; background: none repeat scroll 0 0 #EDEDED; color:#444444; font-size: 18px; font-weight: normal; padding: 45px 10px 50px 10px!important; text-align: center; line-height:25px;} #wc_openModalFormAction > div#wc_response_info { } #wc_openModalFormAction > div#wc_response_info a.close { background: url("<?php echo plugins_url(WC_Core::$PLUGIN_DIRECTORY . '/files/img/x.png'); ?>") no-repeat; background-position-x: right; background-position-y: top; } #wpcomm #bywpdiscuz{ display:none; } #wpcomm .by-wpdiscuz{ text-align:right; border-top:#DDDDDD solid 1px; padding:1px 1px 1px 1px; } #wpcomm .by-wpdiscuz a{ font-size:11px; font-weight:bold; text-align:right; color:#CCCCCC; padding:1px; margin:0px; line-height:12px; border:none; text-decoration:none; } #wpcomm .wpdimg{ border:none; padding:0px; margin:0px; height:12px; cursor:pointer; display:inline; clear:both; } #wpcomm .wc-comment .wc-comment-right.wc_new_loaded_comment {background: <?php echo $this->wc_options->wc_options_serialized->wc_new_loaded_comment_bg_color; ?>;} #wc_unsubscribe_message { margin:10px auto 1px auto; padding:10px; text-align:center; border:#00DD00 1px dotted; background:#CCFFCC; } .wc_unsubscribe_message { font-size:14px; color:#444; } #wpcomm .wc_comment_level-3 { margin-left: 40px!important; } #wpcomm .wc_comment_level-4 { margin-left: 40px!important; } #wpcomm .wc_comment_level-5 { margin-left: 40px!important; } <?php echo stripslashes($this->wc_options->wc_options_serialized->wc_custom_css); ?> </style>
17
  <?php
18
  }
19
 
wc-options-serialize.php CHANGED
@@ -292,7 +292,7 @@ class WC_Options_Serialize {
292
  'wc_captcha_text' => 'Please insert the code above to comment',
293
  'wc_submit_text' => 'Post Comment',
294
  'wc_notify_on_new_comment' => 'Notify of all new follow-up comments',
295
- 'wc_notify_on_new_reply' => 'Notify of new replies to my comments',
296
  'wc_load_more_submit_text' => 'Load More Comments',
297
  'wc_reply_text' => 'Reply',
298
  'wc_share_text' => 'Share',
@@ -309,6 +309,10 @@ class WC_Options_Serialize {
309
  'wc_email_message' => 'New comment on the discussion section you\'ve been interested in',
310
  'wc_new_reply_email_subject' => 'New Reply',
311
  'wc_new_reply_email_message' => 'New reply on the discussion section you\'ve been interested in',
 
 
 
 
312
  'wc_error_empty_text' => 'please fill out this field to comment',
313
  'wc_error_email_text' => 'email address is invalid',
314
  'wc_year_text' => array('datetime' => array('year', 1)),
292
  'wc_captcha_text' => 'Please insert the code above to comment',
293
  'wc_submit_text' => 'Post Comment',
294
  'wc_notify_on_new_comment' => 'Notify of all new follow-up comments',
295
+ 'wc_notify_on_new_reply' => 'Notify of new replies to this comment',
296
  'wc_load_more_submit_text' => 'Load More Comments',
297
  'wc_reply_text' => 'Reply',
298
  'wc_share_text' => 'Share',
309
  'wc_email_message' => 'New comment on the discussion section you\'ve been interested in',
310
  'wc_new_reply_email_subject' => 'New Reply',
311
  'wc_new_reply_email_message' => 'New reply on the discussion section you\'ve been interested in',
312
+ 'wc_subscribed_on_comment' => 'You\'re subscribed for new replies on this comment',
313
+ 'wc_subscribed_on_post' => 'You\'re subscribed for new follow-up comments on this post',
314
+ 'wc_unsubscribe' => 'Unsubscribe',
315
+ 'wc_unsubscribe_message' => 'You\'ve successfully unsubscribed.',
316
  'wc_error_empty_text' => 'please fill out this field to comment',
317
  'wc_error_email_text' => 'email address is invalid',
318
  'wc_year_text' => array('datetime' => array('year', 1)),
wc-options.php CHANGED
@@ -213,7 +213,11 @@ class WC_Options {
213
  $this->wc_options_serialized->wc_phrases['wc_email_subject'] = $_POST['wc_email_subject'];
214
  $this->wc_options_serialized->wc_phrases['wc_email_message'] = $_POST['wc_email_message'];
215
  $this->wc_options_serialized->wc_phrases['wc_new_reply_email_subject'] = $_POST['wc_new_reply_email_subject'];
216
- $this->wc_options_serialized->wc_phrases['wc_new_reply_email_message'] = $_POST['wc_new_reply_email_message'];
 
 
 
 
217
  $this->wc_options_serialized->wc_phrases['wc_error_empty_text'] = $_POST['wc_error_empty_text'];
218
  $this->wc_options_serialized->wc_phrases['wc_error_email_text'] = $_POST['wc_error_email_text'];
219
  $this->wc_options_serialized->wc_phrases['wc_year_text']['datetime'][0] = $_POST['wc_year_text'];
213
  $this->wc_options_serialized->wc_phrases['wc_email_subject'] = $_POST['wc_email_subject'];
214
  $this->wc_options_serialized->wc_phrases['wc_email_message'] = $_POST['wc_email_message'];
215
  $this->wc_options_serialized->wc_phrases['wc_new_reply_email_subject'] = $_POST['wc_new_reply_email_subject'];
216
+ $this->wc_options_serialized->wc_phrases['wc_new_reply_email_message'] = $_POST['wc_new_reply_email_message'];
217
+ $this->wc_options_serialized->wc_phrases['wc_subscribed_on_comment'] = $_POST['wc_subscribed_on_comment'];
218
+ $this->wc_options_serialized->wc_phrases['wc_subscribed_on_post'] = $_POST['wc_subscribed_on_post'];
219
+ $this->wc_options_serialized->wc_phrases['wc_unsubscribe'] = $_POST['wc_unsubscribe'];
220
+ $this->wc_options_serialized->wc_phrases['wc_unsubscribe_message'] = $_POST['wc_unsubscribe_message'];
221
  $this->wc_options_serialized->wc_phrases['wc_error_empty_text'] = $_POST['wc_error_empty_text'];
222
  $this->wc_options_serialized->wc_phrases['wc_error_email_text'] = $_POST['wc_error_email_text'];
223
  $this->wc_options_serialized->wc_phrases['wc_year_text']['datetime'][0] = $_POST['wc_year_text'];
wc.php CHANGED
@@ -1,835 +1,845 @@
1
- <?php
2
-
3
- /*
4
- Plugin Name: wpDiscuz - Wordpress Comments
5
- Description: Better comment system. Wordpress post comments and discussion plugin. Allows your visitors discuss, vote for comments and share.
6
- Version: 2.0.3
7
- Author: gVectors Team (A. Chakhoyan, G. Zakaryan, H. Martirosyan)
8
- Author URI: http://www.gvectors.com/
9
- Plugin URI: http://www.gvectors.com/wpdiscuz/
10
- */
11
-
12
- include_once 'wc-options.php';
13
- include_once 'helper/wc-helper.php';
14
- include_once 'includes/wc-db-helper.php';
15
- include_once 'comment-form/tpl-comment.php';
16
- include_once 'dto/wc-comment.php';
17
- include_once 'wc-css.php';
18
-
19
- class WC_Core {
20
-
21
- public $wc_options;
22
- public $comment_types;
23
- public $reviews_count;
24
- public $wc_db_helper;
25
- public $wc_helper;
26
- public $comment_tpl_builder;
27
- public $wc_css;
28
- public $wc_parent_comments_count;
29
- public $commetns_count = 0;
30
- public $comment_count_text;
31
- public static $PLUGIN_DIRECTORY;
32
- public $post_type;
33
- private $wc_version_slug = 'wc_plugin_version';
34
-
35
- function __construct() {
36
- add_action('init', array(&$this, 'init_plugin_dir_name'), 1);
37
-
38
- $this->wc_options = new WC_Options();
39
- $this->wc_db_helper = $this->wc_options->wc_db_helper;
40
-
41
- register_activation_hook(__FILE__, array($this, 'db_operations'));
42
-
43
-
44
- $this->wc_helper = new WC_Helper($this->wc_options->wc_options_serialized);
45
- $this->wc_css = new WC_CSS($this->wc_options);
46
- $this->comment_tpl_builder = new WC_Comment_Template_Builder($this->wc_helper, $this->wc_db_helper, $this->wc_options);
47
-
48
- add_action('init', array(&$this, 'register_session'), 2);
49
- add_action('admin_init', array(&$this, 'wc_plugin_new_version'), 2);
50
-
51
- add_action('admin_enqueue_scripts', array(&$this, 'admin_page_styles_scripts'), 2315);
52
- add_action('wp_enqueue_scripts', array(&$this, 'front_end_styles_scripts'));
53
- add_action('wp_enqueue_scripts', array(&$this->wc_css, 'init_styles'));
54
-
55
- add_action('admin_menu', array(&$this, 'add_plugin_options_page'), -191);
56
-
57
- add_action('wp_ajax_wc_comms_via_ajax', array(&$this, 'comment_submit_via_ajax'));
58
- add_action('wp_ajax_nopriv_wc_comms_via_ajax', array(&$this, 'comment_submit_via_ajax'));
59
-
60
- add_action('wp_ajax_wc_load_more_comments', array(&$this, 'load_more_comments'));
61
- add_action('wp_ajax_nopriv_wc_load_more_comments', array(&$this, 'load_more_comments'));
62
-
63
- add_action('wp_ajax_wc_vote_via_ajax', array(&$this, 'vote_on_comment'));
64
- add_action('wp_ajax_nopriv_wc_vote_via_ajax', array(&$this, 'vote_on_comment'));
65
-
66
- add_action('wp_ajax_wc_check_notification_type', array(&$this, 'wc_check_notification_type'));
67
- add_action('wp_ajax_nopriv_wc_check_notification_type', array(&$this, 'wc_check_notification_type'));
68
-
69
- add_action('wp_ajax_wc_live_update', array(&$this, 'live_update'));
70
- add_action('wp_ajax_nopriv_wc_live_update', array(&$this, 'live_update'));
71
-
72
- add_action('wp_ajax_wc_list_new_comments', array(&$this, 'wc_list_new_comments'));
73
- add_action('wp_ajax_nopriv_wc_list_new_comments', array(&$this, 'wc_list_new_comments'));
74
-
75
- add_filter('preprocess_comment', array(&$this, 'wc_new_comment'));
76
-
77
- add_action('wp_head', array(&$this, 'init_current_post_type'));
78
- }
79
-
80
- /**
81
- * create table
82
- * updates the comments to set comment type review if comment id is exists in comment meta table
83
- */
84
- public function db_operations() {
85
- $this->wc_db_helper->create_tables();
86
- }
87
-
88
- public function wc_plugin_new_version() {
89
- $this->wc_db_helper->wc_create_email_notification_tabel();
90
- $wc_version = (!get_option($this->wc_version_slug) ) ? '1.0.0' : get_option($this->wc_version_slug);
91
- $wc_plugin_data = get_plugin_data(__FILE__);
92
- if (version_compare($wc_plugin_data['Version'], $wc_version)) {
93
- $this->wc_add_new_options();
94
- $this->wc_add_new_phrases();
95
- if ($wc_version === '1.0.0') {
96
- add_option($this->wc_version_slug, $wc_plugin_data['Version']);
97
- } else {
98
- update_option($this->wc_version_slug, $wc_plugin_data['Version']);
99
- }
100
- }
101
- }
102
-
103
- private function wc_add_new_options() {
104
- $this->wc_options->wc_options_serialized->init_options(get_option($this->wc_options->wc_options_serialized->wc_options_slug));
105
- $wc_new_options = $this->wc_options->wc_options_serialized->to_array();
106
- $wc_new_options['wc_show_hide_comment_checkbox'] = '1';
107
- $wc_new_options['wc_show_hide_reply_checkbox'] = '1';
108
- update_option($this->wc_options->wc_options_serialized->wc_options_slug, serialize($wc_new_options));
109
- }
110
-
111
- private function wc_add_new_phrases() {
112
- if ($this->wc_db_helper->is_phrase_exists('wc_leave_a_reply_text')) {
113
- $wc_saved_phrases = $this->wc_db_helper->get_phrases();
114
- $this->wc_options->wc_options_serialized->init_phrases();
115
- $wc_phrases = $this->wc_options->wc_options_serialized->wc_phrases;
116
- $wc_new_phrases = array_merge($wc_phrases, $wc_saved_phrases);
117
- $this->wc_db_helper->update_phrases($wc_new_phrases);
118
- }
119
- }
120
-
121
- /*
122
- * register new session
123
- */
124
-
125
- public function register_session() {
126
- if (!session_id()) {
127
- @session_start();
128
- }
129
- }
130
-
131
- /**
132
- * change comment type
133
- */
134
- // MUST BE CHANGED IN NEXT VERSION OF PLUGIN
135
- public function wc_new_comment($commentdata) {
136
-
137
- $commentdata['comment_type'] = isset($commentdata['comment_type']) ? $commentdata['comment_type'] : '';
138
- $comment_post = get_post($commentdata['comment_post_ID']);
139
- if ($comment_post->post_type === 'product' && $commentdata['comment_type'] != 'wpdiscuz') {
140
- $com_parent = $commentdata['comment_parent'];
141
- if ($com_parent != 0) {
142
- $parent_comment = get_comment($com_parent);
143
- if ($parent_comment->comment_type == 'wpdiscuz') {
144
- $commentdata['comment_type'] = 'wpdiscuz';
145
- } else {
146
- $commentdata['comment_type'] = 'wpdiscuz_review';
147
- }
148
- } else {
149
- $commentdata['comment_type'] = 'wpdiscuz_review';
150
- }
151
- }
152
-
153
- return $commentdata;
154
- }
155
-
156
- /**
157
- * register options page for plugin
158
- */
159
- public function add_plugin_options_page() {
160
- if (function_exists('add_options_page')) {
161
- add_menu_page('WpDiscuz', 'WpDiscuz', 'manage_options', 'wpdiscuz_options_page', array(&$this->wc_options, 'main_options_form'), plugins_url(WC_Core::$PLUGIN_DIRECTORY . '/files/img/plugin-icon/plugin-icon-20.png'), 1246);
162
- add_submenu_page('wpdiscuz_options_page', 'Phrases', 'Phrases', 'manage_options', 'wpdiscuz_phrases_page', array(&$this->wc_options, 'phrases_options_form'));
163
- }
164
- }
165
-
166
- /**
167
- * Styles and scripts registration to use on front page
168
- */
169
- public function front_end_styles_scripts() {
170
- $u_agent = $_SERVER['HTTP_USER_AGENT'];
171
-
172
- if ($this->wc_options->wc_options_serialized->wc_comment_list_update_type != 0) {
173
- wp_enqueue_script('wc-jquery-ui', plugins_url(WC_Core::$PLUGIN_DIRECTORY . '/files/third-party/jquery-ui/jquery-ui.js'), array('jquery'), '1.11.2', false);
174
- }
175
-
176
- if (preg_match('/MSIE/i', $u_agent)) {
177
- wp_enqueue_script('wc-html5-js', plugins_url(WC_Core::$PLUGIN_DIRECTORY . '/files/third-party/tooltipster/js/html5.js'), array('jquery'), '1.2', false);
178
-
179
- wp_register_style('modal-css-ie', plugins_url(WC_Core::$PLUGIN_DIRECTORY . '/files/third-party/modal-box/modal-box-ie.css'));
180
- wp_enqueue_style('modal-css-ie');
181
- }
182
-
183
- wp_register_style('modal-box-css', plugins_url(WC_Core::$PLUGIN_DIRECTORY . '/files/third-party/modal-box/modal-box.css'));
184
- wp_enqueue_style('modal-box-css');
185
-
186
- wp_enqueue_script('form-validator-js', plugins_url(WC_Core::$PLUGIN_DIRECTORY . '/files/js/validator.js'), array('jquery'), '1.0.0', false);
187
-
188
- wp_register_style('validator-style', plugins_url(WC_Core::$PLUGIN_DIRECTORY . '/files/css/fv.css'));
189
- wp_enqueue_style('validator-style');
190
-
191
- wp_enqueue_script('wc-ajax-js', plugins_url(WC_Core::$PLUGIN_DIRECTORY . '/files/js/wc-ajax.js'), array('jquery'), '2.0.1', false);
192
- wp_localize_script('wc-ajax-js', 'wc_ajax_obj', array('url' => admin_url('admin-ajax.php')));
193
-
194
- wp_enqueue_script('wc-cookie-js', plugins_url(WC_Core::$PLUGIN_DIRECTORY . '/files/js/jquery.cookie.js'), array('jquery'), '1.4.1', false);
195
-
196
- wp_register_style('wc-tooltipster-style', plugins_url(WC_Core::$PLUGIN_DIRECTORY . '/files/third-party/tooltipster/css/tooltipster.css'));
197
- wp_enqueue_style('wc-tooltipster-style');
198
-
199
- wp_enqueue_script('wc-tooltipster-js', plugins_url(WC_Core::$PLUGIN_DIRECTORY . '/files/third-party/tooltipster/js/jquery.tooltipster.min.js'), array('jquery'), '1.2', false);
200
-
201
- wp_enqueue_script('autogrowtextarea-js', plugins_url(WC_Core::$PLUGIN_DIRECTORY . '/files/js/jquery.autogrowtextarea.min.js'), array('jquery'), '3.0', false);
202
- wp_enqueue_script('wc-frontend-js', plugins_url(WC_Core::$PLUGIN_DIRECTORY . '/files/js/wc-frontend.js'), array('jquery'));
203
- }
204
-
205
- /**
206
- * Scripts and styles registration on administration pages
207
- */
208
- public function admin_page_styles_scripts() {
209
-
210
- $u_agent = $_SERVER['HTTP_USER_AGENT'];
211
- if (preg_match('/MSIE/i', $u_agent)) {
212
- wp_register_style('modal-css-ie', plugins_url(WC_Core::$PLUGIN_DIRECTORY . '/files/third-party/modal-box/modal-box-ie.css'));
213
- wp_enqueue_style('modal-css-ie');
214
- }
215
-
216
- wp_register_style('modal-box-css', plugins_url(WC_Core::$PLUGIN_DIRECTORY . '/files/third-party/modal-box/modal-box.css'));
217
- wp_enqueue_style('modal-box-css');
218
-
219
- wp_register_style('colorpicker-css', plugins_url(WC_Core::$PLUGIN_DIRECTORY . '/files/third-party/colorpicker/css/colorpicker.css'));
220
- wp_enqueue_style('colorpicker-css');
221
-
222
- wp_register_script('wc-colorpicker-js', plugins_url(WC_Core::$PLUGIN_DIRECTORY . '/files/third-party/colorpicker/js/colorpicker.js'), array('jquery'), '2.0.0.9', false);
223
- wp_enqueue_script('wc-colorpicker-js');
224
-
225
- wp_register_style('wc-options-css', plugins_url(WC_Core::$PLUGIN_DIRECTORY . '/files/css/options-css.css'));
226
- wp_enqueue_style('wc-options-css');
227
-
228
- wp_register_script('wc-option-js', plugins_url(WC_Core::$PLUGIN_DIRECTORY . '/files/js/options-js.js'), array('jquery'));
229
- wp_enqueue_script('wc-option-js');
230
-
231
- wp_register_script('wc-scripts-js', plugins_url(WC_Core::$PLUGIN_DIRECTORY . '/files/js/wc-scripts.js'), array('jquery'));
232
- wp_enqueue_script('wc-scripts-js');
233
- }
234
-
235
- /*
236
- * post comment via ajax
237
- */
238
-
239
- public function comment_submit_via_ajax() {
240
- $message_array = array();
241
- $comment_post_ID = intval(filter_input(INPUT_POST, 'comment_post_ID'));
242
- $comment_parent = intval(filter_input(INPUT_POST, 'comment_parent'));
243
- $comment_depth = intval(filter_input(INPUT_POST, 'comment_depth'));
244
-
245
- if (!$this->wc_options->wc_options_serialized->wc_captcha_show_hide) {
246
- if (!is_user_logged_in()) {
247
- $sess_captcha = $_SESSION['wc_captcha'][$comment_post_ID . '-' . $comment_parent];
248
- $captcha = filter_input(INPUT_POST, 'captcha');
249
- if (md5(strtolower($captcha)) !== $sess_captcha) {
250
- $message_array['code'] = -1;
251
- $message_array['message'] = $this->wc_options->wc_options_serialized->wc_phrases['wc_invalid_captcha'];
252
- echo json_encode($message_array);
253
- exit;
254
- }
255
- }
256
- }
257
- $comment = filter_input(INPUT_POST, 'comment');
258
-
259
- if (is_user_logged_in()) {
260
- $user_id = get_current_user_id();
261
- $user = get_userdata($user_id);
262
- $name = $user->display_name;
263
- $email = $user->user_email;
264
- $user_url = $user->user_url;
265
- } else {
266
- $name = filter_input(INPUT_POST, 'name');
267
- $email = filter_input(INPUT_POST, 'email');
268
- $user_id = 0;
269
- $user_url = '';
270
- }
271
-
272
- $comment = wp_kses($comment, array(
273
- 'br' => array(),
274
- 'a' => array('href' => array(), 'title' => array()),
275
- 'i' => array(),
276
- 'b' => array(),
277
- 'u' => array(),
278
- 'strong' => array(),
279
- 'p' => array()
280
- ));
281
-
282
- $comment = $this->wc_helper->make_clickable($comment);
283
- $comment = nl2br($comment);
284
-
285
- if ($name && filter_var($email, FILTER_VALIDATE_EMAIL) && $comment && filter_var($comment_post_ID)) {
286
-
287
- $held_moderate = 1;
288
- if ($this->wc_options->wc_options_serialized->wc_held_comment_to_moderate) {
289
- $held_moderate = 0;
290
- }
291
-
292
- $new_commentdata = array(
293
- 'user_id' => $user_id,
294
- 'comment_post_ID' => $comment_post_ID,
295
- 'comment_parent' => $comment_parent,
296
- 'comment_author' => $name,
297
- 'comment_author_email' => $email,
298
- 'comment_content' => $comment,
299
- 'comment_author_url' => $user_url,
300
- 'comment_approved' => $held_moderate
301
- );
302
- if (!$held_moderate) {
303
- $new_comment_id = wp_new_comment($new_commentdata);
304
- $new_inserted_comment = get_comment($new_comment_id);
305
- if ($new_inserted_comment->comment_approved) {
306
- $held_moderate = 1;
307
- }
308
- } else {
309
- $new_comment_id = wp_insert_comment($new_commentdata);
310
- }
311
- $new_comment = new WC_Comment(get_comment($new_comment_id, OBJECT));
312
-
313
- if (!$held_moderate) {
314
- $message_array['code'] = -2;
315
- $message_array['message'] = $this->wc_options->wc_options_serialized->wc_phrases['wc_held_for_moderate'];
316
- } else {
317
- $message_array['code'] = 1;
318
- $message_array['message'] = $this->comment_tpl_builder->get_comment_template($new_comment, null, $comment_depth);
319
- $message_array['wc_all_comments_count_new'] = $this->wc_db_helper->get_comments_count($comment_post_ID, null, null);
320
- }
321
- $message_array['wc_new_comment_id'] = $new_comment_id;
322
- } else {
323
- $message_array['code'] = -1;
324
- $message_array['wc_new_comment_id'] = -1;
325
- $message_array['message'] = $this->wc_options->wc_options_serialized->wc_phrases['wc_invalid_field'];
326
- }
327
-
328
- echo json_encode($message_array);
329
- exit;
330
- }
331
-
332
- /**
333
- * vote on comment via ajax
334
- */
335
- // MUST BE CHANGED IN NEXT VERSION OF PLUGIN
336
- public function vote_on_comment() {
337
- if ($this->wc_db_helper->is_phrase_exists('wc_leave_a_reply_text')) {
338
- $this->wc_options->wc_options_serialized->wc_phrases = $this->wc_db_helper->get_phrases();
339
- }
340
- $messageArray = array();
341
- $messageArray['code'] = -1;
342
- $comment_id = '';
343
- if (!is_user_logged_in()) {
344
- $messageArray['message'] = $this->wc_options->wc_options_serialized->wc_phrases['wc_login_to_vote'];
345
- echo json_encode($messageArray);
346
- exit();
347
- }
348
- if (isset($_POST['comment_ID']) && isset($_POST['vote_type']) && intval($_POST['comment_ID']) && intval($_POST['vote_type'])) {
349
- $comment_id = $_POST['comment_ID'];
350
- $user_id = get_current_user_id();
351
- $vote_type = $_POST['vote_type'];
352
-
353
- $is_user_voted = $this->wc_db_helper->is_user_voted($user_id, $comment_id);
354
- $comment = get_comment($comment_id);
355
- if ($comment->user_id == $user_id) {
356
- $messageArray['message'] = $this->wc_options->wc_options_serialized->wc_phrases['wc_self_vote'];
357
- echo json_encode($messageArray);
358
- exit();
359
- }
360
-
361
- if ($is_user_voted != '') {
362
- $vote = intval($is_user_voted) + intval($vote_type);
363
- if ($vote >= -1 && $vote <= 1) {
364
- $this->wc_db_helper->update_vote_type($user_id, $comment_id, $vote);
365
- $vote_count = intval(get_comment_meta($comment_id, 'wpdiscuz_votes', true)) + intval($vote_type);
366
- update_comment_meta($comment_id, 'wpdiscuz_votes', '' . $vote_count);
367
- $messageArray['code'] = 1;
368
- $messageArray['message'] = $this->wc_options->wc_options_serialized->wc_phrases['wc_vote_counted'];
369
- } else {
370
- $messageArray['message'] = $this->wc_options->wc_options_serialized->wc_phrases['wc_vote_only_one_time'];
371
- }
372
- } else {
373
- $this->wc_db_helper->add_vote_type($user_id, $comment_id, $vote_type);
374
- $vote_count = get_comment_meta($comment_id, 'wpdiscuz_votes', true);
375
- if ($vote_count == '') {
376
- add_comment_meta($comment_id, 'wpdiscuz_votes', '' . $vote_type);
377
- } else {
378
- $vote_count = intval($vote_count) + intval($vote_type);
379
- update_comment_meta($comment_id, 'wpdiscuz_votes', '' . $vote_count);
380
- }
381
- $messageArray['code'] = 1;
382
- $messageArray['message'] = $this->wc_options->wc_options_serialized->wc_phrases['wc_vote_counted'];
383
- }
384
- } else {
385
- $messageArray['message'] = $this->wc_options->wc_options_serialized->wc_phrases['wc_voting_error'];
386
- }
387
-
388
- echo json_encode($messageArray);
389
- exit();
390
- }
391
-
392
- // MUST BE CHANGED IN NEXT VERSION OF PLUGIN
393
- public function live_update() {
394
- global $current_user;
395
- get_currentuserinfo();
396
- $message_array = array();
397
- $wc_post_id = isset($_POST['wc_post_id']) ? intval($_POST['wc_post_id']) : 0;
398
- $wc_comment_list_update_type = $this->wc_options->wc_options_serialized->wc_comment_list_update_type;
399
-
400
- $wc_all_new_comments_count = $this->wc_db_helper->get_comments_count($wc_post_id, null, null);
401
- $wc_last_comment_id = isset($_POST['wc_last_comment_id']) ? intval($_POST['wc_last_comment_id']) : 0;
402
- $wc_last_new_comment_id = isset($_POST['wc_last_new_comment_id']) ? intval($_POST['wc_last_new_comment_id']) : 0;
403
- $wc_last_new_reply_id = isset($_POST['wc_last_new_reply_id']) ? intval($_POST['wc_last_new_reply_id']) : 0;
404
-
405
- if (is_user_logged_in()) {
406
- $wc_author_email = $current_user->user_email;
407
- } else {
408
- $wc_author_email = isset($_POST['wc_author_email']) ? $_POST['wc_author_email'] : '';
409
- }
410
-
411
- $c_offset = intval($_POST['wc_comments_offset']);
412
- $c_offset = ($c_offset) ? $c_offset : 1;
413
- $wc_curr_user_comment_count = isset($_POST['wc_curr_user_comment_count']) ? $_POST['wc_curr_user_comment_count'] : 0;
414
- $wc_limit = $c_offset * $this->wc_options->wc_options_serialized->wc_comment_count + $wc_curr_user_comment_count;
415
- $wc_new_comments = $this->wc_db_helper->wc_get_new_comments($wc_post_id, $wc_last_comment_id, $wc_author_email);
416
-
417
- $wc_visible_parent_comment_ids = $this->wc_db_helper->wc_get_visible_parent_comment_ids($wc_post_id, $wc_limit);
418
- $wc_hidden_new_comment_data = $this->get_invisible_comment_count($wc_new_comments, $wc_author_email, $wc_visible_parent_comment_ids, $wc_last_new_comment_id, $wc_last_new_reply_id);
419
- $wc_hidden_new_comment_count = $wc_hidden_new_comment_data['new_comments_count'];
420
-
421
- if ($wc_new_comments) {
422
- if ($wc_comment_list_update_type == 1) {
423
-
424
- $wc_wp_comments = $this->get_wp_comments($c_offset, $wc_post_id, $wc_curr_user_comment_count, $wc_hidden_new_comment_count);
425
- $message_array['code'] = 1;
426
- $message_array['wc_last_comment_id'] = $this->wc_db_helper->get_last_comment_id_by_post_id($wc_post_id);
427
- $message_array['message'] = $wc_wp_comments['wc_list'];
428
- $message_array['wc_all_comments_count_new'] = $wc_all_new_comments_count;
429
- } else if ($wc_comment_list_update_type == 2) {
430
-
431
- $wc_user_comments_replies_count = count($wc_hidden_new_comment_data['wc_new_replies_ids']);
432
- $wc_all_new_comments_count = count($wc_hidden_new_comment_data['wc_new_comments_ids']);
433
- $wc_all_new_comments_count_text = ($wc_all_new_comments_count > 1) ? $this->wc_options->wc_options_serialized->wc_phrases['wc_new_comments_button_text'] : $this->wc_options->wc_options_serialized->wc_phrases['wc_new_comment_button_text'];
434
- $wc_user_comments_replies_count_text = ($wc_user_comments_replies_count > 1) ? $this->wc_options->wc_options_serialized->wc_phrases['wc_new_replies_button_text'] : $this->wc_options->wc_options_serialized->wc_phrases['wc_new_reply_button_text'];
435
-
436
- $message_array['code'] = 2;
437
- $message_array['wc_new_comment_button_text'] = $wc_all_new_comments_count_text;
438
- $message_array['wc_new_comment_count'] = $wc_all_new_comments_count;
439
- $message_array['wc_new_reply_button_text'] = $wc_user_comments_replies_count_text;
440
- $message_array['wc_new_reply_count'] = $wc_user_comments_replies_count;
441
- }
442
- } else {
443
- $message_array['code'] = 2;
444
- $message_array['wc_new_comment_count'] = 0;
445
- $message_array['wc_new_reply_count'] = 0;
446
- }
447
- echo json_encode($message_array);
448
- exit();
449
- }
450
-
451
- /**
452
- * list new comments
453
- */
454
- // MUST BE CHANGED IN NEXT VERSION OF PLUGIN
455
- public function wc_list_new_comments() {
456
- global $current_user;
457
- get_currentuserinfo();
458
- $message_array = array();
459
- $wc_post_id = isset($_POST['wc_post_id']) ? intval($_POST['wc_post_id']) : 0;
460
- $wc_last_comment_id = isset($_POST['wc_last_comment_id']) ? intval($_POST['wc_last_comment_id']) : 0;
461
- $wc_requested_comments_type = isset($_POST['wc_requested_comments_type']) ? intval($_POST['wc_requested_comments_type']) : 0;
462
- $wc_curr_user_comment_count = isset($_POST['wc_curr_user_comment_count']) ? intval($_POST['wc_curr_user_comment_count']) : 0;
463
- $wc_comments_offset = isset($_POST['wc_comments_offset']) ? $_POST['wc_comments_offset'] : 1;
464
- $wc_limit = $wc_comments_offset * $this->wc_options->wc_options_serialized->wc_comment_count + $wc_curr_user_comment_count;
465
- $wc_comments_max_depth = $this->wc_options->wc_options_serialized->wc_comments_max_depth ? $this->wc_options->wc_options_serialized->wc_comments_max_depth : 2;
466
-
467
- $wc_new_comments_ids = array();
468
- if (is_user_logged_in()) {
469
- $wc_author_email = $current_user->user_email;
470
- } else {
471
- $wc_author_email = isset($_POST['wc_author_email']) ? $_POST['wc_author_email'] : '';
472
- }
473
-
474
- $wc_visible_comment_ids = isset($_POST['wc_visible_comments_ids']) ? $_POST['wc_visible_comments_ids'] : '';
475
- $wc_visible_parent_comment_ids = array_filter(explode(',', $wc_visible_comment_ids));
476
-
477
- $wc_new_comments = $this->wc_db_helper->wc_get_new_comments($wc_post_id, $wc_last_comment_id, $wc_author_email);
478
-
479
- $wc_new_comments = $this->get_invisible_comment_count($wc_new_comments, $wc_author_email, $wc_visible_parent_comment_ids, $wc_last_comment_id, $wc_last_comment_id);
480
- if ($wc_requested_comments_type == 1) {
481
- $message_array['code'] = 1;
482
- $wc_new_comments_ids = $wc_new_comments['wc_new_comments_ids'];
483
- } elseif ($wc_requested_comments_type == 2) {
484
- $message_array['code'] = 2;
485
- $wc_new_comments_ids = $wc_new_comments['wc_new_replies_ids'];
486
- } else {
487
- $message_array['code'] = 0;
488
- }
489
-
490
- if ($message_array['code'] != 0) {
491
- $wc_parent_comments = array();
492
-
493
- if (count($wc_visible_parent_comment_ids)) {
494
- foreach ($wc_visible_parent_comment_ids as $wc_visible_parent_comment_id) {
495
- $wc_vpcommid = $wc_visible_parent_comment_id;
496
- $parent_comment = get_comment($wc_vpcommid);
497
- if (!$parent_comment->comment_parent) {
498
- $wc_parent_comments[] = $parent_comment;
499
- }
500
- }
501
- }
502
-
503
- foreach ($wc_new_comments_ids as $wc_new_comment_id) {
504
- $parent_comment = WC_Helper::get_comment_root_id($wc_new_comment_id);
505
- if (!in_array($parent_comment, $wc_parent_comments)) {
506
- $wc_parent_comments[] = $parent_comment;
507
- }
508
- }
509
-
510
- $comm_list_args = array(
511
- 'callback' => array(&$this, 'wc_comment_callback'),
512
- 'style' => 'div',
513
- 'per_page' => -1,
514
- 'max_depth' => $wc_comments_max_depth,
515
- 'reverse_top_level' => false,
516
- 'echo' => false,
517
- 'wc_visible_parent_comment_ids' => $wc_visible_parent_comment_ids
518
- );
519
-
520
- $wc_child_comments = array();
521
- $wc_parent_comments = $this->wc_helper->wc_sort_parent_comments($wc_parent_comments);
522
-
523
- if ($this->wc_options->wc_options_serialized->wc_comment_list_order === 'desc') {
524
- $wc_parent_comments = array_reverse($wc_parent_comments);
525
- }
526
-
527
- $wc_parent_comments = $this->get_comments_tree($wc_parent_comments, $wc_child_comments);
528
- $wc_parent_comments = $this->init_wc_comments($wc_parent_comments);
529
- $message_array['wc_last_comment_id'] = max($wc_new_comments_ids);
530
- $message_array['message'] = wp_list_comments($comm_list_args, $wc_parent_comments);
531
- $wc_post_parent_comments_count = $this->wc_db_helper->get_post_parent_comments_count($wc_post_id);
532
-
533
- if ($wc_post_parent_comments_count > $this->wc_options->wc_options_serialized->wc_comment_count * $wc_comments_offset + $wc_curr_user_comment_count) {
534
-
535
- $unique_id = $wc_post_id . '_' . 0;
536
- $load_more = '<div class="wc-load-more-submit-wrap">';
537
- $load_more .= '<button name="submit" id="wc-load-more-submit-' . $unique_id . '" class="wc-load-more-submit button">' . $this->wc_options->wc_options_serialized->wc_phrases['wc_load_more_submit_text'];
538
-
539
- $load_more .= '</button>';
540
- $load_more .= '</div>';
541
- $message_array['message'] .= $load_more;
542
- }
543
- }
544
- echo json_encode($message_array);
545
- exit();
546
- }
547
-
548
- /**
549
- * recursively get new comments tree
550
- */
551
- public function get_comments_tree($wc_parent_comments, &$wc_child_comments) {
552
- if (!$wc_parent_comments) {
553
- return $wc_child_comments;
554
- }
555
- $child_comments = array();
556
- foreach ($wc_parent_comments as $parent_comment) {
557
- $child_comments = get_comments(array('parent' => $parent_comment->comment_ID, 'order' => $wc_comment_list_order = $this->wc_options->wc_options_serialized->wc_comment_list_order));
558
- if (!$this->has_comment($wc_child_comments, $parent_comment)) {
559
- $wc_child_comments[] = $parent_comment;
560
- }
561
- foreach ($child_comments as $child_comment) {
562
- if (!$this->has_comment($wc_child_comments, $child_comment)) {
563
- $wc_child_comments[] = $child_comment;
564
- }
565
- }
566
- if ($child_comments) {
567
- $this->get_comments_tree($child_comments, $wc_child_comments);
568
- }
569
- }
570
- return $this->get_comments_tree($child_comments, $wc_child_comments);
571
- }
572
-
573
- public function has_comment($comments, $comment) {
574
- foreach ($comments as $c) {
575
- if ($c->comment_ID == $comment->comment_ID)
576
- return true;
577
- }
578
- return false;
579
- }
580
-
581
- // MUST BE CHANGED IN NEXT VERSION OF PLUGIN
582
- public function get_invisible_comment_count($wc_new_comments, $wc_author_email = null, $visible_parent_comment_ids = array(), $wc_last_new_comment_id = 0, $wc_last_new_reply_id = 0) {
583
- $wc_new_comments_data = array();
584
- $wc_new_comments_count = 0;
585
- $wc_visible_parent_comment_ids = $visible_parent_comment_ids;
586
- $wc_visible_pcomment_ids = WC_Helper::wc_get_array($wc_visible_parent_comment_ids);
587
-
588
- $wc_new_comments_data['wc_new_comments_ids'] = array();
589
- $wc_new_comments_data['wc_new_replies_ids'] = array();
590
- $wc_new_comments_data['last_comment_id'] = 0;
591
-
592
- foreach ($wc_new_comments as $wc_new_comment) {
593
- $cid = $wc_new_comment['comment_id']; // new comment id
594
- $cpid = $wc_new_comment['comment_parent']; // new comment parent id
595
- $parent_comment = WC_Helper::get_comment_root_id($cid);
596
- $pid = $parent_comment->comment_ID;
597
- if (!(in_array($pid, $wc_visible_pcomment_ids))) {
598
- $wc_new_comments_count++;
599
- } else {
600
- if ($wc_new_comments_data['last_comment_id'] < $cid && $cid != 0) {
601
- $wc_new_comments_data['last_comment_id'] = $cid;
602
- }
603
- }
604
-
605
- if ($cpid) {
606
- $current_new_comment_parent = get_comment($cpid);
607
- $current_new_comment_author_email = $current_new_comment_parent->comment_author_email;
608
- } else {
609
- $current_new_comment_author_email = '';
610
- }
611
-
612
- if ($cid > $wc_last_new_comment_id && $wc_author_email != $current_new_comment_author_email || !$wc_author_email) {
613
- $wc_new_comments_data['wc_new_comments_ids'][] = $cid;
614
- }
615
-
616
- if ($cid > $wc_last_new_reply_id && $wc_author_email == $current_new_comment_author_email) {
617
- $wc_new_comments_data['wc_new_replies_ids'][] = $cid;
618
- }
619
- }
620
- $wc_new_comments_data['new_comments_count'] = $wc_new_comments_count;
621
- return $wc_new_comments_data;
622
- }
623
-
624
- /**
625
- * get comments by comment type
626
- */
627
- // MUST BE CHANGED IN NEXT VERSION OF PLUGIN
628
- public function get_wp_comments($comments_offset, $post_id = null, $wc_curr_user_comment_count = 0, $wc_hidden_new_comment_count = 0) {
629
- global $post;
630
- if ($this->wc_db_helper->is_phrase_exists('wc_leave_a_reply_text')) {
631
- $this->wc_options->wc_options_serialized->wc_phrases = $this->wc_db_helper->get_phrases();
632
- }
633
-
634
- if (!$post_id) {
635
- $post_id = $post->ID;
636
- }
637
- $wc_comment_count = $this->wc_options->wc_options_serialized->wc_comment_count;
638
- $wc_comment_list_order = $this->wc_options->wc_options_serialized->wc_comment_list_order;
639
- $wc_comments_max_depth = $this->wc_options->wc_options_serialized->wc_comments_max_depth ? $this->wc_options->wc_options_serialized->wc_comments_max_depth : 2;
640
-
641
- $comm_list_args = array(
642
- 'callback' => array(&$this, 'wc_comment_callback'),
643
- 'style' => 'div',
644
- 'per_page' => $comments_offset * $wc_comment_count + $wc_curr_user_comment_count,
645
- 'max_depth' => $wc_comments_max_depth,
646
- 'reverse_top_level' => false,
647
- 'echo' => false
648
- );
649
-
650
- $wc_wp_comments = array();
651
- $comments = get_comments(array('post_id' => $post_id, 'status' => 'approve', 'order' => $wc_comment_list_order));
652
- $wc_comments = $this->init_wc_comments($comments);
653
- $wc_wp_comments['wc_list'] = wp_list_comments($comm_list_args, $wc_comments);
654
- $wc_button_comments_count_style = $wc_hidden_new_comment_count > 0 ? "inline-block" : "none";
655
-
656
- if ($this->wc_parent_comments_count > $this->wc_options->wc_options_serialized->wc_comment_count * $comments_offset + $wc_curr_user_comment_count) {
657
-
658
- $unique_id = $post_id . '_' . 0;
659
- $load_more = '<div class="wc-load-more-submit-wrap">';
660
- $load_more .= '<button name="submit" id="wc-load-more-submit-' . $unique_id . '" class="wc-load-more-submit button">' . $this->wc_options->wc_options_serialized->wc_phrases['wc_load_more_submit_text'];
661
-
662
- if ($this->wc_options->wc_options_serialized->wc_comment_list_update_type == 1) {
663
- $load_more .= '<span style="display:' . $wc_button_comments_count_style . ';" id="wc_button_new_comments_text" class="wc_button_new_comments_text">&nbsp;&nbsp;-&nbsp;&nbsp;' . $this->wc_options->wc_options_serialized->wc_phrases['wc_new_comments_text'] . ' : ';
664
- $load_more .= '<span id="wc_button_new_comments_count" class="wc_button_new_comments_count">' . $wc_hidden_new_comment_count . '</span></span>';
665
- }
666
-
667
- $load_more .= '</button>';
668
- $load_more .= '</div>';
669
- $wc_wp_comments['wc_list'] .= $load_more;
670
- }
671
-
672
- $wc_wp_comments['wc_parent_comments_count'] = $this->wc_parent_comments_count + $wc_curr_user_comment_count;
673
- return $wc_wp_comments;
674
- }
675
-
676
- /**
677
- * load more comments by offset
678
- */
679
- // MUST BE CHANGED IN NEXT VERSION OF PLUGIN
680
- public function load_more_comments() {
681
- $c_offset = intval($_POST['comments_offset']);
682
- $c_offset = ($c_offset) ? $c_offset : 1;
683
- $post_id = intval($_POST['wc_post_id']);
684
- $message_array = array();
685
- if ($c_offset && $post_id) {
686
- $wc_limit = $c_offset * $this->wc_options->wc_options_serialized->wc_comment_count;
687
- $wc_last_comment_id = isset($_POST['wc_last_comment_id']) ? $_POST['wc_last_comment_id'] : 0;
688
- $wc_curr_user_comment_count = isset($_POST['wc_curr_user_comment_count']) ? $_POST['wc_curr_user_comment_count'] : 0;
689
- $wc_new_comments = $this->wc_db_helper->wc_get_new_comments($post_id, $wc_last_comment_id);
690
- $wc_visible_parent_comment_ids = $this->wc_db_helper->wc_get_visible_parent_comment_ids($post_id, $wc_limit);
691
- $wc_hidden_new_comment_data = $this->get_invisible_comment_count($wc_new_comments, null, $wc_visible_parent_comment_ids);
692
-
693
- $message_array['code'] = 1;
694
- if ($this->wc_options->wc_options_serialized->wc_comment_list_update_type == 2) {
695
- $message_array['wc_last_comment_id'] = ($wc_hidden_new_comment_data['last_comment_id']) ? $wc_hidden_new_comment_data['last_comment_id'] : $wc_last_comment_id;
696
- } else {
697
- $message_array['wc_last_comment_id'] = $this->wc_db_helper->get_last_comment_id_by_post_id($post_id);
698
- }
699
-
700
- $wc_hidden_new_comment_count = $wc_hidden_new_comment_data['new_comments_count'];
701
- $wc_wp_comments = $this->get_wp_comments($c_offset, $post_id, $wc_curr_user_comment_count, $wc_hidden_new_comment_count);
702
- $message_array['message'] = $wc_wp_comments['wc_list'];
703
- }
704
- echo json_encode($message_array);
705
- exit();
706
- }
707
-
708
- /**
709
- * initialize WPC comments
710
- */
711
- public function init_wc_comments($comments) {
712
- $wc_comments = array();
713
- if ($comments) {
714
- foreach ($comments as $comment) {
715
- if (!$comment->comment_parent) {
716
- $this->wc_parent_comments_count++;
717
- }
718
- $wc_comments[] = new WC_Comment($comment);
719
- }
720
- }
721
- return $wc_comments;
722
- }
723
-
724
- public function wc_comment_callback($comment, $args, $depth) {
725
- $GLOBALS['comment'] = $comment;
726
- echo $this->comment_tpl_builder->get_comment_template($comment, $args, $depth);
727
- }
728
-
729
- public function is_guest_can_comment() {
730
- $user_can_comment = TRUE;
731
- if ($this->wc_options->wc_options_serialized->wc_user_must_be_registered) {
732
- if (!is_user_logged_in()) {
733
- $user_can_comment = FALSE;
734
- }
735
- }
736
- return $user_can_comment;
737
- }
738
-
739
- public function init_plugin_dir_name() {
740
- $plugin_dir_path = plugin_dir_path(__FILE__);
741
- $path_array = array_values(array_filter(explode(DIRECTORY_SEPARATOR, $plugin_dir_path)));
742
- $path_last_part = $path_array[count($path_array) - 1];
743
- WC_Core::$PLUGIN_DIRECTORY = untrailingslashit($path_last_part);
744
- }
745
-
746
- public function init_current_post_type() {
747
- global $post;
748
- if (in_array($post->post_type, $this->wc_options->wc_options_serialized->wc_post_types) && comments_open($post->ID)) {
749
- add_filter('comments_template', array(&$this, 'remove_comments_template_on_pages'), 1);
750
- }
751
- }
752
-
753
- public function remove_comments_template_on_pages($file) {
754
- $file = dirname(__FILE__) . '/comment-form/form.php';
755
- return $file;
756
- }
757
-
758
- /**
759
- * Check notification type and send email to post new comments subscribers
760
- */
761
- public function wc_check_notification_type() {
762
- $comment_id = intval($_POST['wc_comment_id']);
763
- $post_id = intval($_POST['wc_post_id']);
764
- $notification_type = $_POST['wc_notifcattion_type'];
765
- $current_user = wp_get_current_user();
766
-
767
-
768
- if ($current_user->user_email) {
769
- $email = $current_user->user_email;
770
- } else {
771
- $email = isset($_POST['wc_email']) ? $_POST['wc_email'] : '';
772
- }
773
-
774
-
775
- if ($comment_id && $email && $post_id) {
776
- $comment = get_comment($comment_id);
777
- $parrent_comment_id = $comment->comment_parent;
778
- if ($notification_type == 'post' && !$this->wc_db_helper->wc_has_notification_in_comment($post_id, $email)) {
779
- $this->wc_db_helper->wc_add_email_notification($post_id, $email, 1);
780
- } else if ($notification_type == 'reply' && !$this->wc_db_helper->wc_has_notification_in_reply($comment_id, $email)) {
781
- $this->wc_db_helper->wc_add_email_notification($comment_id, $email, 0);
782
- }
783
- if ($comment->comment_approved) {
784
- $this->wc_notify_on_new_comments($post_id, $comment_id, $email);
785
- }
786
- if ($comment->comment_approved && $parrent_comment_id) {
787
- $this->wc_notify_on_new_reply($parrent_comment_id, $comment->comment_ID, $email);
788
- }
789
- }
790
- exit();
791
- }
792
-
793
- /**
794
- * notify on new comments
795
- */
796
- public function wc_notify_on_new_comments($post_id, $comment_id, $email) {
797
- $emails_array = $this->wc_db_helper->wc_get_post_new_comment_notification($post_id, $email);
798
- $subject = ($this->wc_options->wc_options_serialized->wc_phrases['wc_email_subject']) ? $this->wc_options->wc_options_serialized->wc_phrases['wc_email_subject'] : 'New Comment';
799
- $message = ($this->wc_options->wc_options_serialized->wc_phrases['wc_email_message']) ? $this->wc_options->wc_options_serialized->wc_phrases['wc_email_message'] : 'New comment on the discussion section you\'ve been interested in';
800
- foreach ($emails_array as $e_row) {
801
- $this->wc_email_sender($e_row[0], $comment_id, $subject, $message);
802
- }
803
- }
804
-
805
- /**
806
- * notify on comment new replies
807
- */
808
- public function wc_notify_on_new_reply($parent_comment_id, $new_comment_id, $email) {
809
- $emails_array = $this->wc_db_helper->wc_get_post_new_reply_notification($parent_comment_id, $email);
810
- $subject = ($this->wc_options->wc_options_serialized->wc_phrases['wc_new_reply_email_subject']) ? $this->wc_options->wc_options_serialized->wc_phrases['wc_new_reply_email_subject'] : 'New Reply';
811
- $message = ($this->wc_options->wc_options_serialized->wc_phrases['wc_new_reply_email_message']) ? $this->wc_options->wc_options_serialized->wc_phrases['wc_new_reply_email_message'] : 'New reply on the discussion section you\'ve been interested in';
812
- foreach ($emails_array as $e_row) {
813
- $this->wc_email_sender($e_row[0], $new_comment_id, $subject, $message);
814
- }
815
- }
816
-
817
- /**
818
- * send email
819
- */
820
- public function wc_email_sender($email, $wc_new_comment_id, $subject, $message) {
821
- $comment = get_comment($wc_new_comment_id);
822
- $wc_new_comment_content = $comment->comment_content;
823
- $permalink = get_comment_link($wc_new_comment_id);
824
- $message .= "<br/><br/><a href='$permalink'>$permalink</a>";
825
- $message .= "<br/><br/>$wc_new_comment_content";
826
- $headers = array();
827
- $headers[] = "Content-Type: text/html; charset=UTF-8";
828
- $headers[] = "From: " . get_bloginfo('name') . "\r\n";
829
- wp_mail($email, $subject, $message, $headers);
830
- }
831
-
832
- }
833
-
834
- $wc_core = new WC_Core();
 
 
 
 
 
 
 
 
 
 
835
  ?>
1
+ <?php
2
+
3
+ /*
4
+ Plugin Name: wpDiscuz - Wordpress Comments
5
+ Description: Better comment system. Wordpress post comments and discussion plugin. Allows your visitors discuss, vote for comments and share.
6
+ Version: 2.0.4
7
+ Author: gVectors Team (A. Chakhoyan, G. Zakaryan, H. Martirosyan)
8
+ Author URI: http://www.gvectors.com/
9
+ Plugin URI: http://www.gvectors.com/wpdiscuz/
10
+ */
11
+
12
+ include_once 'wc-options.php';
13
+ include_once 'helper/wc-helper.php';
14
+ include_once 'includes/wc-db-helper.php';
15
+ include_once 'comment-form/tpl-comment.php';
16
+ include_once 'dto/wc-comment.php';
17
+ include_once 'wc-css.php';
18
+
19
+ class WC_Core {
20
+
21
+ public $wc_options;
22
+ public $comment_types;
23
+ public $reviews_count;
24
+ public $wc_db_helper;
25
+ public $wc_helper;
26
+ public $comment_tpl_builder;
27
+ public $wc_css;
28
+ public $wc_parent_comments_count;
29
+ public $commetns_count = 0;
30
+ public $comment_count_text;
31
+ public static $PLUGIN_DIRECTORY;
32
+ public $post_type;
33
+ private $wc_version_slug = 'wc_plugin_version';
34
+
35
+ function __construct() {
36
+ add_action('init', array(&$this, 'init_plugin_dir_name'), 1);
37
+
38
+ $this->wc_options = new WC_Options();
39
+ $this->wc_db_helper = $this->wc_options->wc_db_helper;
40
+
41
+ register_activation_hook(__FILE__, array($this, 'db_operations'));
42
+
43
+ $this->wc_helper = new WC_Helper($this->wc_options->wc_options_serialized);
44
+ $this->wc_css = new WC_CSS($this->wc_options);
45
+ $this->comment_tpl_builder = new WC_Comment_Template_Builder($this->wc_helper, $this->wc_db_helper, $this->wc_options);
46
+
47
+ add_action('init', array(&$this, 'register_session'), 2);
48
+ add_action('admin_init', array(&$this, 'wc_plugin_new_version'), 2);
49
+
50
+ add_action('admin_enqueue_scripts', array(&$this, 'admin_page_styles_scripts'), 2315);
51
+ add_action('wp_enqueue_scripts', array(&$this, 'front_end_styles_scripts'));
52
+ add_action('wp_enqueue_scripts', array(&$this->wc_css, 'init_styles'));
53
+
54
+ add_action('admin_menu', array(&$this, 'add_plugin_options_page'), -191);
55
+
56
+ add_action('wp_ajax_wc_comms_via_ajax', array(&$this, 'comment_submit_via_ajax'));
57
+ add_action('wp_ajax_nopriv_wc_comms_via_ajax', array(&$this, 'comment_submit_via_ajax'));
58
+
59
+ add_action('wp_ajax_wc_load_more_comments', array(&$this, 'load_more_comments'));
60
+ add_action('wp_ajax_nopriv_wc_load_more_comments', array(&$this, 'load_more_comments'));
61
+
62
+ add_action('wp_ajax_wc_vote_via_ajax', array(&$this, 'vote_on_comment'));
63
+ add_action('wp_ajax_nopriv_wc_vote_via_ajax', array(&$this, 'vote_on_comment'));
64
+
65
+ add_action('wp_ajax_wc_check_notification_type', array(&$this, 'wc_check_notification_type'));
66
+ add_action('wp_ajax_nopriv_wc_check_notification_type', array(&$this, 'wc_check_notification_type'));
67
+
68
+ add_action('wp_ajax_wc_live_update', array(&$this, 'live_update'));
69
+ add_action('wp_ajax_nopriv_wc_live_update', array(&$this, 'live_update'));
70
+
71
+ add_action('wp_ajax_wc_list_new_comments', array(&$this, 'wc_list_new_comments'));
72
+ add_action('wp_ajax_nopriv_wc_list_new_comments', array(&$this, 'wc_list_new_comments'));
73
+
74
+ add_filter('preprocess_comment', array(&$this, 'wc_new_comment'));
75
+
76
+ add_action('wp_head', array(&$this, 'init_current_post_type'));
77
+ }
78
+
79
+ /**
80
+ * create table
81
+ * updates the comments to set comment type review if comment id is exists in comment meta table
82
+ */
83
+ public function db_operations() {
84
+ $this->wc_db_helper->create_tables();
85
+ }
86
+
87
+ public function wc_plugin_new_version() {
88
+ $this->wc_db_helper->wc_create_email_notification_table();
89
+ $wc_version = (!get_option($this->wc_version_slug) ) ? '1.0.0' : get_option($this->wc_version_slug);
90
+ $wc_plugin_data = get_plugin_data(__FILE__);
91
+ if (version_compare($wc_plugin_data['Version'], $wc_version, '>')) {
92
+ $this->wc_add_new_options();
93
+ $this->wc_add_new_phrases();
94
+ if ($wc_version === '1.0.0') {
95
+ add_option($this->wc_version_slug, $wc_plugin_data['Version']);
96
+ } else {
97
+ update_option($this->wc_version_slug, $wc_plugin_data['Version']);
98
+ }
99
+ }
100
+ }
101
+
102
+ private function wc_add_new_options() {
103
+ $this->wc_options->wc_options_serialized->init_options(get_option($this->wc_options->wc_options_serialized->wc_options_slug));
104
+ $wc_new_options = $this->wc_options->wc_options_serialized->to_array();
105
+ $wc_new_options['wc_show_hide_comment_checkbox'] = '1';
106
+ $wc_new_options['wc_show_hide_reply_checkbox'] = '1';
107
+ update_option($this->wc_options->wc_options_serialized->wc_options_slug, serialize($wc_new_options));
108
+ }
109
+
110
+ private function wc_add_new_phrases() {
111
+ if ($this->wc_db_helper->is_phrase_exists('wc_leave_a_reply_text')) {
112
+ $wc_saved_phrases = $this->wc_db_helper->get_phrases();
113
+ $this->wc_options->wc_options_serialized->init_phrases();
114
+ $wc_phrases = $this->wc_options->wc_options_serialized->wc_phrases;
115
+ $wc_new_phrases = array_merge($wc_phrases, $wc_saved_phrases);
116
+ $this->wc_db_helper->update_phrases($wc_new_phrases);
117
+ }
118
+ }
119
+
120
+ /*
121
+ * register new session
122
+ */
123
+
124
+ public function register_session() {
125
+ if (!session_id()) {
126
+ @session_start();
127
+ }
128
+ }
129
+
130
+ /**
131
+ * change comment type
132
+ */
133
+ // MUST BE CHANGED IN NEXT VERSION OF PLUGIN
134
+ public function wc_new_comment($commentdata) {
135
+
136
+ $commentdata['comment_type'] = isset($commentdata['comment_type']) ? $commentdata['comment_type'] : '';
137
+ $comment_post = get_post($commentdata['comment_post_ID']);
138
+ if ($comment_post->post_type === 'product' && $commentdata['comment_type'] != 'wpdiscuz') {
139
+ $com_parent = $commentdata['comment_parent'];
140
+ if ($com_parent != 0) {
141
+ $parent_comment = get_comment($com_parent);
142
+ if ($parent_comment->comment_type == 'wpdiscuz') {
143
+ $commentdata['comment_type'] = 'wpdiscuz';
144
+ } else {
145
+ $commentdata['comment_type'] = 'wpdiscuz_review';
146
+ }
147
+ } else {
148
+ $commentdata['comment_type'] = 'wpdiscuz_review';
149
+ }
150
+ }
151
+
152
+ return $commentdata;
153
+ }
154
+
155
+ /**
156
+ * register options page for plugin
157
+ */
158
+ public function add_plugin_options_page() {
159
+ if (function_exists('add_options_page')) {
160
+ add_menu_page('WpDiscuz', 'WpDiscuz', 'manage_options', 'wpdiscuz_options_page', array(&$this->wc_options, 'main_options_form'), plugins_url(WC_Core::$PLUGIN_DIRECTORY . '/files/img/plugin-icon/plugin-icon-20.png'), 1246);
161
+ add_submenu_page('wpdiscuz_options_page', 'Phrases', 'Phrases', 'manage_options', 'wpdiscuz_phrases_page', array(&$this->wc_options, 'phrases_options_form'));
162
+ }
163
+ }
164
+
165
+ /**
166
+ * Styles and scripts registration to use on front page
167
+ */
168
+ public function front_end_styles_scripts() {
169
+ $u_agent = $_SERVER['HTTP_USER_AGENT'];
170
+
171
+ if ($this->wc_options->wc_options_serialized->wc_comment_list_update_type != 0) {
172
+ wp_enqueue_script('wc-jquery-ui', plugins_url(WC_Core::$PLUGIN_DIRECTORY . '/files/third-party/jquery-ui/jquery-ui.js'), array('jquery'), '1.11.2', false);
173
+ }
174
+
175
+ if (preg_match('/MSIE/i', $u_agent)) {
176
+ wp_enqueue_script('wc-html5-js', plugins_url(WC_Core::$PLUGIN_DIRECTORY . '/files/third-party/tooltipster/js/html5.js'), array('jquery'), '1.2', false);
177
+
178
+ wp_register_style('modal-css-ie', plugins_url(WC_Core::$PLUGIN_DIRECTORY . '/files/third-party/modal-box/modal-box-ie.css'));
179
+ wp_enqueue_style('modal-css-ie');
180
+ }
181
+
182
+ wp_register_style('modal-box-css', plugins_url(WC_Core::$PLUGIN_DIRECTORY . '/files/third-party/modal-box/modal-box.css'));
183
+ wp_enqueue_style('modal-box-css');
184
+
185
+ wp_enqueue_script('form-validator-js', plugins_url(WC_Core::$PLUGIN_DIRECTORY . '/files/js/validator.js'), array('jquery'), '1.0.0', false);
186
+
187
+ wp_register_style('validator-style', plugins_url(WC_Core::$PLUGIN_DIRECTORY . '/files/css/fv.css'));
188
+ wp_enqueue_style('validator-style');
189
+
190
+ wp_enqueue_script('wc-ajax-js', plugins_url(WC_Core::$PLUGIN_DIRECTORY . '/files/js/wc-ajax.js'), array('jquery'), '2.0.1', false);
191
+ wp_localize_script('wc-ajax-js', 'wc_ajax_obj', array('url' => admin_url('admin-ajax.php')));
192
+
193
+ wp_enqueue_script('wc-cookie-js', plugins_url(WC_Core::$PLUGIN_DIRECTORY . '/files/js/jquery.cookie.js'), array('jquery'), '1.4.1', false);
194
+
195
+ wp_register_style('wc-tooltipster-style', plugins_url(WC_Core::$PLUGIN_DIRECTORY . '/files/third-party/tooltipster/css/tooltipster.css'));
196
+ wp_enqueue_style('wc-tooltipster-style');
197
+
198
+ wp_enqueue_script('wc-tooltipster-js', plugins_url(WC_Core::$PLUGIN_DIRECTORY . '/files/third-party/tooltipster/js/jquery.tooltipster.min.js'), array('jquery'), '1.2', false);
199
+
200
+ wp_enqueue_script('autogrowtextarea-js', plugins_url(WC_Core::$PLUGIN_DIRECTORY . '/files/js/jquery.autogrowtextarea.min.js'), array('jquery'), '3.0', false);
201
+ wp_enqueue_script('wc-frontend-js', plugins_url(WC_Core::$PLUGIN_DIRECTORY . '/files/js/wc-frontend.js'), array('jquery'));
202
+ }
203
+
204
+ /**
205
+ * Scripts and styles registration on administration pages
206
+ */
207
+ public function admin_page_styles_scripts() {
208
+
209
+ $u_agent = $_SERVER['HTTP_USER_AGENT'];
210
+ if (preg_match('/MSIE/i', $u_agent)) {
211
+ wp_register_style('modal-css-ie', plugins_url(WC_Core::$PLUGIN_DIRECTORY . '/files/third-party/modal-box/modal-box-ie.css'));
212
+ wp_enqueue_style('modal-css-ie');
213
+ }
214
+
215
+ wp_register_style('modal-box-css', plugins_url(WC_Core::$PLUGIN_DIRECTORY . '/files/third-party/modal-box/modal-box.css'));
216
+ wp_enqueue_style('modal-box-css');
217
+
218
+ wp_register_style('colorpicker-css', plugins_url(WC_Core::$PLUGIN_DIRECTORY . '/files/third-party/colorpicker/css/colorpicker.css'));
219
+ wp_enqueue_style('colorpicker-css');
220
+
221
+ wp_register_script('wc-colorpicker-js', plugins_url(WC_Core::$PLUGIN_DIRECTORY . '/files/third-party/colorpicker/js/colorpicker.js'), array('jquery'), '2.0.0.9', false);
222
+ wp_enqueue_script('wc-colorpicker-js');
223
+
224
+ wp_register_style('wc-options-css', plugins_url(WC_Core::$PLUGIN_DIRECTORY . '/files/css/options-css.css'));
225
+ wp_enqueue_style('wc-options-css');
226
+
227
+ wp_register_script('wc-option-js', plugins_url(WC_Core::$PLUGIN_DIRECTORY . '/files/js/options-js.js'), array('jquery'));
228
+ wp_enqueue_script('wc-option-js');
229
+
230
+ wp_register_script('wc-scripts-js', plugins_url(WC_Core::$PLUGIN_DIRECTORY . '/files/js/wc-scripts.js'), array('jquery'));
231
+ wp_enqueue_script('wc-scripts-js');
232
+ }
233
+
234
+ /*
235
+ * post comment via ajax
236
+ */
237
+
238
+ public function comment_submit_via_ajax() {
239
+ $message_array = array();
240
+ $comment_post_ID = intval(filter_input(INPUT_POST, 'comment_post_ID'));
241
+ $comment_parent = intval(filter_input(INPUT_POST, 'comment_parent'));
242
+ $comment_depth = intval(filter_input(INPUT_POST, 'comment_depth'));
243
+
244
+ $notification_type = isset($_POST['notification_type']) ? $_POST['notification_type'] : '';
245
+
246
+
247
+ if (!$this->wc_options->wc_options_serialized->wc_captcha_show_hide) {
248
+ if (!is_user_logged_in()) {
249
+ $sess_captcha = $_SESSION['wc_captcha'][$comment_post_ID . '-' . $comment_parent];
250
+ $captcha = filter_input(INPUT_POST, 'captcha');
251
+ if (md5(strtolower($captcha)) !== $sess_captcha) {
252
+ $message_array['code'] = -1;
253
+ $message_array['message'] = $this->wc_options->wc_options_serialized->wc_phrases['wc_invalid_captcha'];
254
+ echo json_encode($message_array);
255
+ exit;
256
+ }
257
+ }
258
+ }
259
+ $comment = filter_input(INPUT_POST, 'comment');
260
+
261
+ if (is_user_logged_in()) {
262
+ $user_id = get_current_user_id();
263
+ $user = get_userdata($user_id);
264
+ $name = $user->display_name;
265
+ $email = $user->user_email;
266
+ $user_url = $user->user_url;
267
+ } else {
268
+ $name = filter_input(INPUT_POST, 'name');
269
+ $email = filter_input(INPUT_POST, 'email');
270
+ $user_id = 0;
271
+ $user_url = '';
272
+ }
273
+
274
+ $comment = wp_kses($comment, array(
275
+ 'br' => array(),
276
+ 'a' => array('href' => array(), 'title' => array()),
277
+ 'i' => array(),
278
+ 'b' => array(),
279
+ 'u' => array(),
280
+ 'strong' => array(),
281
+ 'p' => array()
282
+ ));
283
+
284
+ $comment = $this->wc_helper->make_clickable($comment);
285
+ $comment = nl2br($comment);
286
+
287
+ if ($name && filter_var($email, FILTER_VALIDATE_EMAIL) && $comment && filter_var($comment_post_ID)) {
288
+
289
+ $held_moderate = 1;
290
+ if ($this->wc_options->wc_options_serialized->wc_held_comment_to_moderate) {
291
+ $held_moderate = 0;
292
+ }
293
+
294
+ $new_commentdata = array(
295
+ 'user_id' => $user_id,
296
+ 'comment_post_ID' => $comment_post_ID,
297
+ 'comment_parent' => $comment_parent,
298
+ 'comment_author' => $name,
299
+ 'comment_author_email' => $email,
300
+ 'comment_content' => $comment,
301
+ 'comment_author_url' => $user_url,
302
+ 'comment_approved' => $held_moderate
303
+ );
304
+ if (!$held_moderate) {
305
+ $new_comment_id = wp_new_comment($new_commentdata);
306
+ $new_inserted_comment = get_comment($new_comment_id);
307
+ if ($new_inserted_comment->comment_approved) {
308
+ $held_moderate = 1;
309
+ }
310
+ } else {
311
+ $new_comment_id = wp_insert_comment($new_commentdata);
312
+ }
313
+
314
+ if ($notification_type == 'post' && !$this->wc_db_helper->wc_has_post_notification($comment_post_ID, $email)) {
315
+ $this->wc_db_helper->wc_add_email_notification($comment_post_ID, $comment_post_ID, $email, 1);
316
+ } else if ($notification_type == 'reply' && !$this->wc_db_helper->wc_has_comment_notification($comment_post_ID, $new_comment_id, $email)) {
317
+ $this->wc_db_helper->wc_add_email_notification($new_comment_id, $comment_post_ID, $email, 0);
318
+ }
319
+
320
+ $new_comment = new WC_Comment(get_comment($new_comment_id, OBJECT));
321
+
322
+ if (!$held_moderate) {
323
+ $message_array['code'] = -2;
324
+ $message_array['message'] = $this->wc_options->wc_options_serialized->wc_phrases['wc_held_for_moderate'];
325
+ } else {
326
+ $message_array['code'] = 1;
327
+ $message_array['message'] = $this->comment_tpl_builder->get_comment_template($new_comment, null, $comment_depth);
328
+ $message_array['wc_all_comments_count_new'] = $this->wc_db_helper->get_comments_count($comment_post_ID, null, null);
329
+ }
330
+ $message_array['wc_new_comment_id'] = $new_comment_id;
331
+ } else {
332
+ $message_array['code'] = -1;
333
+ $message_array['wc_new_comment_id'] = -1;
334
+ $message_array['message'] = $this->wc_options->wc_options_serialized->wc_phrases['wc_invalid_field'];
335
+ }
336
+
337
+ echo json_encode($message_array);
338
+ exit;
339
+ }
340
+
341
+ /**
342
+ * vote on comment via ajax
343
+ */
344
+ // MUST BE CHANGED IN NEXT VERSION OF PLUGIN
345
+ public function vote_on_comment() {
346
+ if ($this->wc_db_helper->is_phrase_exists('wc_leave_a_reply_text')) {
347
+ $this->wc_options->wc_options_serialized->wc_phrases = $this->wc_db_helper->get_phrases();
348
+ }
349
+ $messageArray = array();
350
+ $messageArray['code'] = -1;
351
+ $comment_id = '';
352
+ if (!is_user_logged_in()) {
353
+ $messageArray['message'] = $this->wc_options->wc_options_serialized->wc_phrases['wc_login_to_vote'];
354
+ echo json_encode($messageArray);
355
+ exit();
356
+ }
357
+ if (isset($_POST['comment_ID']) && isset($_POST['vote_type']) && intval($_POST['comment_ID']) && intval($_POST['vote_type'])) {
358
+ $comment_id = $_POST['comment_ID'];
359
+ $user_id = get_current_user_id();
360
+ $vote_type = $_POST['vote_type'];
361
+
362
+ $is_user_voted = $this->wc_db_helper->is_user_voted($user_id, $comment_id);
363
+ $comment = get_comment($comment_id);
364
+ if ($comment->user_id == $user_id) {
365
+ $messageArray['message'] = $this->wc_options->wc_options_serialized->wc_phrases['wc_self_vote'];
366
+ echo json_encode($messageArray);
367
+ exit();
368
+ }
369
+
370
+ if ($is_user_voted != '') {
371
+ $vote = intval($is_user_voted) + intval($vote_type);
372
+ if ($vote >= -1 && $vote <= 1) {
373
+ $this->wc_db_helper->update_vote_type($user_id, $comment_id, $vote);
374
+ $vote_count = intval(get_comment_meta($comment_id, 'wpdiscuz_votes', true)) + intval($vote_type);
375
+ update_comment_meta($comment_id, 'wpdiscuz_votes', '' . $vote_count);
376
+ $messageArray['code'] = 1;
377
+ $messageArray['message'] = $this->wc_options->wc_options_serialized->wc_phrases['wc_vote_counted'];
378
+ } else {
379
+ $messageArray['message'] = $this->wc_options->wc_options_serialized->wc_phrases['wc_vote_only_one_time'];
380
+ }
381
+ } else {
382
+ $this->wc_db_helper->add_vote_type($user_id, $comment_id, $vote_type);
383
+ $vote_count = get_comment_meta($comment_id, 'wpdiscuz_votes', true);
384
+ if ($vote_count == '') {
385
+ add_comment_meta($comment_id, 'wpdiscuz_votes', '' . $vote_type);
386
+ } else {
387
+ $vote_count = intval($vote_count) + intval($vote_type);
388
+ update_comment_meta($comment_id, 'wpdiscuz_votes', '' . $vote_count);
389
+ }
390
+ $messageArray['code'] = 1;
391
+ $messageArray['message'] = $this->wc_options->wc_options_serialized->wc_phrases['wc_vote_counted'];
392
+ }
393
+ } else {
394
+ $messageArray['message'] = $this->wc_options->wc_options_serialized->wc_phrases['wc_voting_error'];
395
+ }
396
+
397
+ echo json_encode($messageArray);
398
+ exit();
399
+ }
400
+
401
+ // MUST BE CHANGED IN NEXT VERSION OF PLUGIN
402
+ public function live_update() {
403
+ global $current_user;
404
+ get_currentuserinfo();
405
+ $message_array = array();
406
+ $wc_post_id = isset($_POST['wc_post_id']) ? intval($_POST['wc_post_id']) : 0;
407
+ $wc_comment_list_update_type = $this->wc_options->wc_options_serialized->wc_comment_list_update_type;
408
+
409
+ $wc_all_new_comments_count = $this->wc_db_helper->get_comments_count($wc_post_id, null, null);
410
+ $wc_last_comment_id = isset($_POST['wc_last_comment_id']) ? intval($_POST['wc_last_comment_id']) : 0;
411
+ $wc_last_new_comment_id = isset($_POST['wc_last_new_comment_id']) ? intval($_POST['wc_last_new_comment_id']) : 0;
412
+ $wc_last_new_reply_id = isset($_POST['wc_last_new_reply_id']) ? intval($_POST['wc_last_new_reply_id']) : 0;
413
+
414
+ if (is_user_logged_in()) {
415
+ $wc_author_email = $current_user->user_email;
416
+ } else {
417
+ $wc_author_email = isset($_POST['wc_author_email']) ? $_POST['wc_author_email'] : '';
418
+ }
419
+
420
+ $c_offset = intval($_POST['wc_comments_offset']);
421
+ $c_offset = ($c_offset) ? $c_offset : 1;
422
+ $wc_curr_user_comment_count = isset($_POST['wc_curr_user_comment_count']) ? $_POST['wc_curr_user_comment_count'] : 0;
423
+ $wc_limit = $c_offset * $this->wc_options->wc_options_serialized->wc_comment_count + $wc_curr_user_comment_count;
424
+ $wc_new_comments = $this->wc_db_helper->wc_get_new_comments($wc_post_id, $wc_last_comment_id, $wc_author_email);
425
+
426
+ $wc_visible_parent_comment_ids = $this->wc_db_helper->wc_get_visible_parent_comment_ids($wc_post_id, $wc_limit);
427
+ $wc_hidden_new_comment_data = $this->get_invisible_comment_count($wc_new_comments, $wc_author_email, $wc_visible_parent_comment_ids, $wc_last_new_comment_id, $wc_last_new_reply_id);
428
+ $wc_hidden_new_comment_count = $wc_hidden_new_comment_data['new_comments_count'];
429
+
430
+ if ($wc_new_comments) {
431
+ if ($wc_comment_list_update_type == 1) {
432
+
433
+ $wc_wp_comments = $this->get_wp_comments($c_offset, $wc_post_id, $wc_curr_user_comment_count, $wc_hidden_new_comment_count);
434
+ $message_array['code'] = 1;
435
+ $message_array['wc_last_comment_id'] = $this->wc_db_helper->get_last_comment_id_by_post_id($wc_post_id);
436
+ $message_array['message'] = $wc_wp_comments['wc_list'];
437
+ $message_array['wc_all_comments_count_new'] = $wc_all_new_comments_count;
438
+ } else if ($wc_comment_list_update_type == 2) {
439
+
440
+ $wc_user_comments_replies_count = count($wc_hidden_new_comment_data['wc_new_replies_ids']);
441
+ $wc_all_new_comments_count = count($wc_hidden_new_comment_data['wc_new_comments_ids']);
442
+ $wc_all_new_comments_count_text = ($wc_all_new_comments_count > 1) ? $this->wc_options->wc_options_serialized->wc_phrases['wc_new_comments_button_text'] : $this->wc_options->wc_options_serialized->wc_phrases['wc_new_comment_button_text'];
443
+ $wc_user_comments_replies_count_text = ($wc_user_comments_replies_count > 1) ? $this->wc_options->wc_options_serialized->wc_phrases['wc_new_replies_button_text'] : $this->wc_options->wc_options_serialized->wc_phrases['wc_new_reply_button_text'];
444
+
445
+ $message_array['code'] = 2;
446
+ $message_array['wc_new_comment_button_text'] = $wc_all_new_comments_count_text;
447
+ $message_array['wc_new_comment_count'] = $wc_all_new_comments_count;
448
+ $message_array['wc_new_reply_button_text'] = $wc_user_comments_replies_count_text;
449
+ $message_array['wc_new_reply_count'] = $wc_user_comments_replies_count;
450
+ }
451
+ } else {
452
+ $message_array['code'] = 2;
453
+ $message_array['wc_new_comment_count'] = 0;
454
+ $message_array['wc_new_reply_count'] = 0;
455
+ }
456
+ echo json_encode($message_array);
457
+ exit();
458
+ }
459
+
460
+ /**
461
+ * list new comments
462
+ */
463
+ // MUST BE CHANGED IN NEXT VERSION OF PLUGIN
464
+ public function wc_list_new_comments() {
465
+ global $current_user;
466
+ get_currentuserinfo();
467
+ $message_array = array();
468
+ $wc_post_id = isset($_POST['wc_post_id']) ? intval($_POST['wc_post_id']) : 0;
469
+ $wc_last_comment_id = isset($_POST['wc_last_comment_id']) ? intval($_POST['wc_last_comment_id']) : 0;
470
+ $wc_requested_comments_type = isset($_POST['wc_requested_comments_type']) ? intval($_POST['wc_requested_comments_type']) : 0;
471
+ $wc_curr_user_comment_count = isset($_POST['wc_curr_user_comment_count']) ? intval($_POST['wc_curr_user_comment_count']) : 0;
472
+ $wc_comments_offset = isset($_POST['wc_comments_offset']) ? $_POST['wc_comments_offset'] : 1;
473
+ $wc_limit = $wc_comments_offset * $this->wc_options->wc_options_serialized->wc_comment_count + $wc_curr_user_comment_count;
474
+ $wc_comments_max_depth = $this->wc_options->wc_options_serialized->wc_comments_max_depth ? $this->wc_options->wc_options_serialized->wc_comments_max_depth : 2;
475
+
476
+ $wc_new_comments_ids = array();
477
+ if (is_user_logged_in()) {
478
+ $wc_author_email = $current_user->user_email;
479
+ } else {
480
+ $wc_author_email = isset($_POST['wc_author_email']) ? $_POST['wc_author_email'] : '';
481
+ }
482
+
483
+ $wc_visible_comment_ids = isset($_POST['wc_visible_comments_ids']) ? $_POST['wc_visible_comments_ids'] : '';
484
+ $wc_visible_parent_comment_ids = array_filter(explode(',', $wc_visible_comment_ids));
485
+
486
+ $wc_new_comments = $this->wc_db_helper->wc_get_new_comments($wc_post_id, $wc_last_comment_id, $wc_author_email);
487
+
488
+ $wc_new_comments = $this->get_invisible_comment_count($wc_new_comments, $wc_author_email, $wc_visible_parent_comment_ids, $wc_last_comment_id, $wc_last_comment_id);
489
+ if ($wc_requested_comments_type == 1) {
490
+ $message_array['code'] = 1;
491
+ $wc_new_comments_ids = $wc_new_comments['wc_new_comments_ids'];
492
+ } elseif ($wc_requested_comments_type == 2) {
493
+ $message_array['code'] = 2;
494
+ $wc_new_comments_ids = $wc_new_comments['wc_new_replies_ids'];
495
+ } else {
496
+ $message_array['code'] = 0;
497
+ }
498
+
499
+ if ($message_array['code'] != 0) {
500
+ $wc_parent_comments = array();
501
+
502
+ if (count($wc_visible_parent_comment_ids)) {
503
+ foreach ($wc_visible_parent_comment_ids as $wc_visible_parent_comment_id) {
504
+ $wc_vpcommid = $wc_visible_parent_comment_id;
505
+ $parent_comment = get_comment($wc_vpcommid);
506
+ if (!$parent_comment->comment_parent) {
507
+ $wc_parent_comments[] = $parent_comment;
508
+ }
509
+ }
510
+ }
511
+
512
+ foreach ($wc_new_comments_ids as $wc_new_comment_id) {
513
+ $parent_comment = WC_Helper::get_comment_root_id($wc_new_comment_id);
514
+ if (!in_array($parent_comment, $wc_parent_comments)) {
515
+ $wc_parent_comments[] = $parent_comment;
516
+ }
517
+ }
518
+
519
+ $comm_list_args = array(
520
+ 'callback' => array(&$this, 'wc_comment_callback'),
521
+ 'style' => 'div',
522
+ 'per_page' => -1,
523
+ 'max_depth' => $wc_comments_max_depth,
524
+ 'reverse_top_level' => false,
525
+ 'echo' => false,
526
+ 'wc_visible_parent_comment_ids' => $wc_visible_parent_comment_ids
527
+ );
528
+
529
+ $wc_child_comments = array();
530
+ $wc_parent_comments = $this->wc_helper->wc_sort_parent_comments($wc_parent_comments);
531
+
532
+ if ($this->wc_options->wc_options_serialized->wc_comment_list_order === 'desc') {
533
+ $wc_parent_comments = array_reverse($wc_parent_comments);
534
+ }
535
+
536
+ $wc_parent_comments = $this->get_comments_tree($wc_parent_comments, $wc_child_comments);
537
+ $wc_parent_comments = $this->init_wc_comments($wc_parent_comments);
538
+ $message_array['wc_last_comment_id'] = max($wc_new_comments_ids);
539
+ $message_array['message'] = wp_list_comments($comm_list_args, $wc_parent_comments);
540
+ $wc_post_parent_comments_count = $this->wc_db_helper->get_post_parent_comments_count($wc_post_id);
541
+
542
+ if ($wc_post_parent_comments_count > $this->wc_options->wc_options_serialized->wc_comment_count * $wc_comments_offset + $wc_curr_user_comment_count) {
543
+
544
+ $unique_id = $wc_post_id . '_' . 0;
545
+ $load_more = '<div class="wc-load-more-submit-wrap">';
546
+ $load_more .= '<button name="submit" id="wc-load-more-submit-' . $unique_id . '" class="wc-load-more-submit button">' . $this->wc_options->wc_options_serialized->wc_phrases['wc_load_more_submit_text'];
547
+
548
+ $load_more .= '</button>';
549
+ $load_more .= '</div>';
550
+ $message_array['message'] .= $load_more;
551
+ }
552
+ }
553
+ echo json_encode($message_array);
554
+ exit();
555
+ }
556
+
557
+ /**
558
+ * recursively get new comments tree
559
+ */
560
+ public function get_comments_tree($wc_parent_comments, &$wc_child_comments) {
561
+ if (!$wc_parent_comments) {
562
+ return $wc_child_comments;
563
+ }
564
+ $child_comments = array();
565
+ foreach ($wc_parent_comments as $parent_comment) {
566
+ $child_comments = get_comments(array('parent' => $parent_comment->comment_ID, 'order' => $wc_comment_list_order = $this->wc_options->wc_options_serialized->wc_comment_list_order));
567
+ if (!$this->has_comment($wc_child_comments, $parent_comment)) {
568
+ $wc_child_comments[] = $parent_comment;
569
+ }
570
+ foreach ($child_comments as $child_comment) {
571
+ if (!$this->has_comment($wc_child_comments, $child_comment)) {
572
+ $wc_child_comments[] = $child_comment;
573
+ }
574
+ }
575
+ if ($child_comments) {
576
+ $this->get_comments_tree($child_comments, $wc_child_comments);
577
+ }
578
+ }
579
+ return $this->get_comments_tree($child_comments, $wc_child_comments);
580
+ }
581
+
582
+ public function has_comment($comments, $comment) {
583
+ foreach ($comments as $c) {
584
+ if ($c->comment_ID == $comment->comment_ID)
585
+ return true;
586
+ }
587
+ return false;
588
+ }
589
+
590
+ // MUST BE CHANGED IN NEXT VERSION OF PLUGIN
591
+ public function get_invisible_comment_count($wc_new_comments, $wc_author_email = null, $visible_parent_comment_ids = array(), $wc_last_new_comment_id = 0, $wc_last_new_reply_id = 0) {
592
+ $wc_new_comments_data = array();
593
+ $wc_new_comments_count = 0;
594
+ $wc_visible_parent_comment_ids = $visible_parent_comment_ids;
595
+ $wc_visible_pcomment_ids = WC_Helper::wc_get_array($wc_visible_parent_comment_ids);
596
+
597
+ $wc_new_comments_data['wc_new_comments_ids'] = array();
598
+ $wc_new_comments_data['wc_new_replies_ids'] = array();
599
+ $wc_new_comments_data['last_comment_id'] = 0;
600
+
601
+ foreach ($wc_new_comments as $wc_new_comment) {
602
+ $cid = $wc_new_comment['comment_id']; // new comment id
603
+ $cpid = $wc_new_comment['comment_parent']; // new comment parent id
604
+ $parent_comment = WC_Helper::get_comment_root_id($cid);
605
+ $pid = $parent_comment->comment_ID;
606
+ if (!(in_array($pid, $wc_visible_pcomment_ids))) {
607
+ $wc_new_comments_count++;
608
+ } else {
609
+ if ($wc_new_comments_data['last_comment_id'] < $cid && $cid != 0) {
610
+ $wc_new_comments_data['last_comment_id'] = $cid;
611
+ }
612
+ }
613
+
614
+ if ($cpid) {
615
+ $current_new_comment_parent = get_comment($cpid);
616
+ $current_new_comment_author_email = $current_new_comment_parent->comment_author_email;
617
+ } else {
618
+ $current_new_comment_author_email = '';
619
+ }
620
+
621
+ if ($cid > $wc_last_new_comment_id && $wc_author_email != $current_new_comment_author_email || !$wc_author_email) {
622
+ $wc_new_comments_data['wc_new_comments_ids'][] = $cid;
623
+ }
624
+
625
+ if ($cid > $wc_last_new_reply_id && $wc_author_email == $current_new_comment_author_email) {
626
+ $wc_new_comments_data['wc_new_replies_ids'][] = $cid;
627
+ }
628
+ }
629
+ $wc_new_comments_data['new_comments_count'] = $wc_new_comments_count;
630
+ return $wc_new_comments_data;
631
+ }
632
+
633
+ /**
634
+ * get comments by comment type
635
+ */
636
+ // MUST BE CHANGED IN NEXT VERSION OF PLUGIN
637
+ public function get_wp_comments($comments_offset, $post_id = null, $wc_curr_user_comment_count = 0, $wc_hidden_new_comment_count = 0) {
638
+ global $post;
639
+ if ($this->wc_db_helper->is_phrase_exists('wc_leave_a_reply_text')) {
640
+ $this->wc_options->wc_options_serialized->wc_phrases = $this->wc_db_helper->get_phrases();
641
+ }
642
+
643
+ if (!$post_id) {
644
+ $post_id = $post->ID;
645
+ }
646
+ $wc_comment_count = $this->wc_options->wc_options_serialized->wc_comment_count;
647
+ $wc_comment_list_order = $this->wc_options->wc_options_serialized->wc_comment_list_order;
648
+ $wc_comments_max_depth = $this->wc_options->wc_options_serialized->wc_comments_max_depth ? $this->wc_options->wc_options_serialized->wc_comments_max_depth : 2;
649
+
650
+ $comm_list_args = array(
651
+ 'callback' => array(&$this, 'wc_comment_callback'),
652
+ 'style' => 'div',
653
+ 'per_page' => $comments_offset * $wc_comment_count + $wc_curr_user_comment_count,
654
+ 'max_depth' => $wc_comments_max_depth,
655
+ 'reverse_top_level' => false,
656
+ 'echo' => false
657
+ );
658
+
659
+ $wc_wp_comments = array();
660
+ $comments = get_comments(array('post_id' => $post_id, 'status' => 'approve', 'order' => $wc_comment_list_order));
661
+ $wc_comments = $this->init_wc_comments($comments);
662
+ $wc_wp_comments['wc_list'] = wp_list_comments($comm_list_args, $wc_comments);
663
+ $wc_button_comments_count_style = $wc_hidden_new_comment_count > 0 ? "inline-block" : "none";
664
+
665
+ if ($this->wc_parent_comments_count > $this->wc_options->wc_options_serialized->wc_comment_count * $comments_offset + $wc_curr_user_comment_count) {
666
+
667
+ $unique_id = $post_id . '_' . 0;
668
+ $load_more = '<div class="wc-load-more-submit-wrap">';
669
+ $load_more .= '<button name="submit" id="wc-load-more-submit-' . $unique_id . '" class="wc-load-more-submit button">' . $this->wc_options->wc_options_serialized->wc_phrases['wc_load_more_submit_text'];
670
+
671
+ if ($this->wc_options->wc_options_serialized->wc_comment_list_update_type == 1) {
672
+ $load_more .= '<span style="display:' . $wc_button_comments_count_style . ';" id="wc_button_new_comments_text" class="wc_button_new_comments_text">&nbsp;&nbsp;-&nbsp;&nbsp;' . $this->wc_options->wc_options_serialized->wc_phrases['wc_new_comments_text'] . ' : ';
673
+ $load_more .= '<span id="wc_button_new_comments_count" class="wc_button_new_comments_count">' . $wc_hidden_new_comment_count . '</span></span>';
674
+ }
675
+
676
+ $load_more .= '</button>';
677
+ $load_more .= '</div>';
678
+ $wc_wp_comments['wc_list'] .= $load_more;
679
+ }
680
+
681
+ $wc_wp_comments['wc_parent_comments_count'] = $this->wc_parent_comments_count + $wc_curr_user_comment_count;
682
+ return $wc_wp_comments;
683
+ }
684
+
685
+ /**
686
+ * load more comments by offset
687
+ */
688
+ // MUST BE CHANGED IN NEXT VERSION OF PLUGIN
689
+ public function load_more_comments() {
690
+ $c_offset = intval($_POST['comments_offset']);
691
+ $c_offset = ($c_offset) ? $c_offset : 1;
692
+ $post_id = intval($_POST['wc_post_id']);
693
+ $message_array = array();
694
+ if ($c_offset && $post_id) {
695
+ $wc_limit = $c_offset * $this->wc_options->wc_options_serialized->wc_comment_count;
696
+ $wc_last_comment_id = isset($_POST['wc_last_comment_id']) ? $_POST['wc_last_comment_id'] : 0;
697
+ $wc_curr_user_comment_count = isset($_POST['wc_curr_user_comment_count']) ? $_POST['wc_curr_user_comment_count'] : 0;
698
+ $wc_new_comments = $this->wc_db_helper->wc_get_new_comments($post_id, $wc_last_comment_id);
699
+ $wc_visible_parent_comment_ids = $this->wc_db_helper->wc_get_visible_parent_comment_ids($post_id, $wc_limit);
700
+ $wc_hidden_new_comment_data = $this->get_invisible_comment_count($wc_new_comments, null, $wc_visible_parent_comment_ids);
701
+
702
+ $message_array['code'] = 1;
703
+ if ($this->wc_options->wc_options_serialized->wc_comment_list_update_type == 2) {
704
+ $message_array['wc_last_comment_id'] = ($wc_hidden_new_comment_data['last_comment_id']) ? $wc_hidden_new_comment_data['last_comment_id'] : $wc_last_comment_id;
705
+ } else {
706
+ $message_array['wc_last_comment_id'] = $this->wc_db_helper->get_last_comment_id_by_post_id($post_id);
707
+ }
708
+
709
+ $wc_hidden_new_comment_count = $wc_hidden_new_comment_data['new_comments_count'];
710
+ $wc_wp_comments = $this->get_wp_comments($c_offset, $post_id, $wc_curr_user_comment_count, $wc_hidden_new_comment_count);
711
+ $message_array['message'] = $wc_wp_comments['wc_list'];
712
+ }
713
+ echo json_encode($message_array);
714
+ exit();
715
+ }
716
+
717
+ /**
718
+ * initialize WPC comments
719
+ */
720
+ public function init_wc_comments($comments) {
721
+ $wc_comments = array();
722
+ if ($comments) {
723
+ foreach ($comments as $comment) {
724
+ if (!$comment->comment_parent) {
725
+ $this->wc_parent_comments_count++;
726
+ }
727
+ $wc_comments[] = new WC_Comment($comment);
728
+ }
729
+ }
730
+ return $wc_comments;
731
+ }
732
+
733
+ public function wc_comment_callback($comment, $args, $depth) {
734
+ $GLOBALS['comment'] = $comment;
735
+ echo $this->comment_tpl_builder->get_comment_template($comment, $args, $depth);
736
+ }
737
+
738
+ public function is_guest_can_comment() {
739
+ $user_can_comment = TRUE;
740
+ if ($this->wc_options->wc_options_serialized->wc_user_must_be_registered) {
741
+ if (!is_user_logged_in()) {
742
+ $user_can_comment = FALSE;
743
+ }
744
+ }
745
+ return $user_can_comment;
746
+ }
747
+
748
+ public function init_plugin_dir_name() {
749
+ $plugin_dir_path = plugin_dir_path(__FILE__);
750
+ $path_array = array_values(array_filter(explode(DIRECTORY_SEPARATOR, $plugin_dir_path)));
751
+ $path_last_part = $path_array[count($path_array) - 1];
752
+ WC_Core::$PLUGIN_DIRECTORY = untrailingslashit($path_last_part);
753
+ }
754
+
755
+ public function init_current_post_type() {
756
+ global $post;
757
+ if (in_array($post->post_type, $this->wc_options->wc_options_serialized->wc_post_types) && comments_open($post->ID)) {
758
+ add_filter('comments_template', array(&$this, 'remove_comments_template_on_pages'), 1);
759
+ }
760
+ }
761
+
762
+ public function remove_comments_template_on_pages($file) {
763
+ $file = dirname(__FILE__) . '/comment-form/form.php';
764
+ return $file;
765
+ }
766
+
767
+ /**
768
+ * Check notification type and send email to post new comments subscribers
769
+ */
770
+ public function wc_check_notification_type() {
771
+ $comment_id = intval($_POST['wc_comment_id']);
772
+ $post_id = intval($_POST['wc_post_id']);
773
+ $notification_type = isset($_POST['wc_notifcattion_type']) ? $_POST['wc_notifcattion_type'] : '';
774
+ $current_user = wp_get_current_user();
775
+
776
+
777
+ if ($current_user->user_email) {
778
+ $email = $current_user->user_email;
779
+ } else {
780
+ $email = isset($_POST['wc_email']) ? $_POST['wc_email'] : '';
781
+ }
782
+
783
+
784
+ if ($comment_id && $email && $post_id) {
785
+ $comment = get_comment($comment_id);
786
+ $parrent_comment_id = $comment->comment_parent;
787
+ if ($comment->comment_approved) {
788
+ $this->wc_notify_on_new_comments($post_id, $comment_id, $email);
789
+ }
790
+ if ($comment->comment_approved && $parrent_comment_id) {
791
+ $this->wc_notify_on_new_reply($parrent_comment_id, $comment->comment_ID, $email);
792
+ }
793
+ }
794
+ exit();
795
+ }
796
+
797
+ /**
798
+ * notify on new comments
799
+ */
800
+ public function wc_notify_on_new_comments($post_id, $comment_id, $email) {
801
+ $emails_array = $this->wc_db_helper->wc_get_post_new_comment_notification($post_id, $email);
802
+ $subject = ($this->wc_options->wc_options_serialized->wc_phrases['wc_email_subject']) ? $this->wc_options->wc_options_serialized->wc_phrases['wc_email_subject'] : 'New Comment';
803
+ $message = ($this->wc_options->wc_options_serialized->wc_phrases['wc_email_message']) ? $this->wc_options->wc_options_serialized->wc_phrases['wc_email_message'] : 'New comment on the discussion section you\'ve been interested in';
804
+ foreach ($emails_array as $e_row) {
805
+ $this->wc_email_sender($e_row, $comment_id, $subject, $message);
806
+ }
807
+ }
808
+
809
+ /**
810
+ * notify on comment new replies
811
+ */
812
+ public function wc_notify_on_new_reply($parent_comment_id, $new_comment_id, $email) {
813
+ $emails_array = $this->wc_db_helper->wc_get_post_new_reply_notification($parent_comment_id, $email);
814
+ $subject = ($this->wc_options->wc_options_serialized->wc_phrases['wc_new_reply_email_subject']) ? $this->wc_options->wc_options_serialized->wc_phrases['wc_new_reply_email_subject'] : 'New Reply';
815
+ $message = ($this->wc_options->wc_options_serialized->wc_phrases['wc_new_reply_email_message']) ? $this->wc_options->wc_options_serialized->wc_phrases['wc_new_reply_email_message'] : 'New reply on the discussion section you\'ve been interested in';
816
+ foreach ($emails_array as $e_row) {
817
+ $this->wc_email_sender($e_row, $new_comment_id, $subject, $message);
818
+ }
819
+ }
820
+
821
+ /**
822
+ * send email
823
+ */
824
+ public function wc_email_sender($email_data, $wc_new_comment_id, $subject, $message) {
825
+ $comment = get_comment($wc_new_comment_id);
826
+ $wc_new_comment_content = $comment->comment_content;
827
+ $permalink = get_comment_link($wc_new_comment_id);
828
+ $unsubscribe_url = get_permalink($comment->comment_post_ID) . "?wpdiscuzSubscribeID=" . $email_data['id'] . "&key=" . $email_data['activation_key'] . '&#wc_unsubscribe_message';
829
+ $message .= "<br/><br/><a href='$permalink'>$permalink</a>";
830
+ $message .= "<br/><br/>$wc_new_comment_content";
831
+ $message .= "<br/><br/><a href='$unsubscribe_url'>" . $this->wc_options->wc_options_serialized->wc_phrases['wc_unsubscribe'] . "</a>";
832
+ $headers = array();
833
+ $headers[] = "Content-Type: text/html; charset=UTF-8";
834
+ $headers[] = "From: " . get_bloginfo('name') . "\r\n";
835
+ wp_mail($email_data['email'], $subject, $message, $headers);
836
+ }
837
+
838
+ public function wc_unsubscribe($id, $activation_key) {
839
+ $this->wc_db_helper->wc_unsubscribe($id, $activation_key);
840
+ }
841
+
842
+ }
843
+
844
+ $wc_core = new WC_Core();
845
  ?>