Disqus Comment System - Version 2.45

Version Description

Download this release

Release Info

Developer Disqus
Plugin Icon Disqus Comment System
Version 2.45
Comparing to
See all releases

Code changes from version 2.43 to 2.45

Files changed (5) hide show
  1. comments.php +6 -6
  2. disqus.php +46 -11
  3. lib/wpapi.php +2 -1
  4. manage.php +1 -1
  5. readme.txt +11 -1
comments.php CHANGED
@@ -81,11 +81,11 @@
81
  if( $count ) { echo ','; }
82
  ?>
83
  {
84
- 'author_name': '<?php echo htmlspecialchars(get_comment_author(), ENT_QUOTES); ?>',
85
- 'author_url': '<?php echo htmlspecialchars(get_comment_author_url(), ENT_QUOTES); ?>',
86
- 'date': '<?php comment_date('m/d/Y h:i A'); ?>',
87
- 'excerpt': '<?php echo str_replace(array("\r\n", "\n", "\r"), '<br />', htmlspecialchars(get_comment_excerpt(), ENT_QUOTES)); ?>',
88
- 'type': '<?php echo $comment_type; ?>'
89
  }
90
  <?php
91
  $count++;
@@ -93,7 +93,7 @@
93
  }
94
  ?>
95
  ],
96
- 'trackback_url': '<?php trackback_url(); ?>'
97
  };
98
  </script>
99
 
81
  if( $count ) { echo ','; }
82
  ?>
83
  {
84
+ 'author_name': <?php echo cf_json_encode(get_comment_author()); ?>,
85
+ 'author_url': <?php echo cf_json_encode(get_comment_author_url()); ?>,
86
+ 'date': <?php echo cf_json_encode(get_comment_date('m/d/Y h:i A')); ?>,
87
+ 'excerpt': <?php echo cf_json_encode(str_replace(array("\r\n", "\n", "\r"), '<br />', get_comment_excerpt())); ?>,
88
+ 'type': <?php echo cf_json_encode($comment_type); ?>
89
  }
90
  <?php
91
  $count++;
93
  }
94
  ?>
95
  ],
96
+ 'trackback_url': <?php echo cf_json_encode(get_trackback_url()); ?>
97
  };
98
  </script>
99
 
disqus.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: Disqus Comment System
4
  Plugin URI: http://disqus.com/
5
  Description: The Disqus comment system replaces your WordPress comment system with your comments hosted and powered by Disqus. Head over to the Comments admin page to set up your DISQUS Comment System.
6
  Author: Disqus <team@disqus.com>
7
- Version: 2.43
8
  Author URI: http://disqus.com/
9
  */
10
 
@@ -63,7 +63,7 @@ define('DSQ_PLUGIN_URL', WP_CONTENT_URL . '/plugins/' . dsq_plugin_basename(__FI
63
  * @global string $dsq_version
64
  * @since 1.0
65
  */
66
- $dsq_version = '2.41';
67
  $mt_dsq_version = '2.01';
68
  /**
69
  * Response from Disqus get_thread API call for comments template.
@@ -179,9 +179,11 @@ function dsq_manage_dialog($message, $error = false) {
179
 
180
  function dsq_sync_comments($post, $comments) {
181
  global $wpdb;
 
 
182
 
183
  // Get last_comment_date id for $post with Disqus metadata
184
- // (This is the date that is stored in the Disqus DB.)
185
  $last_comment_date = $wpdb->get_var($wpdb->prepare('SELECT max(comment_date) FROM ' . $wpdb->comments . ' WHERE comment_post_ID = %d AND comment_agent LIKE \'Disqus/%%\'', $post->ID));
186
 
187
  if ( $last_comment_date ) {
@@ -222,8 +224,19 @@ function dsq_sync_comments($post, $comments) {
222
  $commentdata['comment_author_url'] = $comment->author->url;
223
  $commentdata['comment_author_IP'] = $comment->author->ip_address;
224
  }
225
-
226
- wp_insert_comment($commentdata);
 
 
 
 
 
 
 
 
 
 
 
227
  }
228
  }
229
 
@@ -272,7 +285,8 @@ function dsq_request_handler() {
272
  // schedule the event for 30 seconds from now in case they
273
  // happen to make a quick post
274
  wp_schedule_single_event(time(), 'dsq_sync_post', array($post_id));
275
- die('OK');
 
276
  break;
277
  case 'export_comments':
278
  if (current_user_can('manage_options') && DISQUS_CAN_EXPORT) {
@@ -345,18 +359,25 @@ function dsq_request_handler() {
345
  add_action('init', 'dsq_request_handler');
346
 
347
  function dsq_sync_post($post_id) {
348
- global $dsq_api;
349
 
350
  $post = get_post($post_id);
351
 
352
  // Call update_thread to ensure our permalink is up to date
353
  dsq_update_permalink($post);
354
 
 
 
 
 
 
 
 
 
355
  // Pull comments from API
356
- $dsq_response = $dsq_api->get_thread($post);
357
  if( $dsq_response < 0 ) {
358
- // header("HTTP/1.0 500 Internal Server Error");
359
- echo 'There was an error when attempting to sync comments';
360
  return;
361
  }
362
  // Sync comments with database.
@@ -512,7 +533,10 @@ function dsq_get_style() {
512
 
513
  add_action('wp_head','dsq_get_style');
514
 
 
 
515
  function dsq_comments_template($value) {
 
516
  global $post;
517
  global $comments;
518
 
@@ -531,7 +555,7 @@ function dsq_comments_template($value) {
531
  // TODO: If a disqus-comments.php is found in the current template's
532
  // path, use that instead of the default bundled comments.php
533
  //return TEMPLATEPATH . '/disqus-comments.php';
534
-
535
  return dirname(__FILE__) . '/comments.php';
536
  }
537
 
@@ -564,6 +588,17 @@ function dsq_plugin_action_links($links, $file) {
564
  }
565
  add_filter('plugin_action_links', 'dsq_plugin_action_links', 10, 2);
566
 
 
 
 
 
 
 
 
 
 
 
 
567
  // Always add Disqus management page to the admin menu
568
  function dsq_add_pages() {
569
  add_submenu_page(
4
  Plugin URI: http://disqus.com/
5
  Description: The Disqus comment system replaces your WordPress comment system with your comments hosted and powered by Disqus. Head over to the Comments admin page to set up your DISQUS Comment System.
6
  Author: Disqus <team@disqus.com>
7
+ Version: 2.45
8
  Author URI: http://disqus.com/
9
  */
10
 
63
  * @global string $dsq_version
64
  * @since 1.0
65
  */
66
+ $dsq_version = '2.45';
67
  $mt_dsq_version = '2.01';
68
  /**
69
  * Response from Disqus get_thread API call for comments template.
179
 
180
  function dsq_sync_comments($post, $comments) {
181
  global $wpdb;
182
+
183
+ $_has_updated_thread = false;
184
 
185
  // Get last_comment_date id for $post with Disqus metadata
186
+ // (This is the date that is stored in the Disqus DB.)
187
  $last_comment_date = $wpdb->get_var($wpdb->prepare('SELECT max(comment_date) FROM ' . $wpdb->comments . ' WHERE comment_post_ID = %d AND comment_agent LIKE \'Disqus/%%\'', $post->ID));
188
 
189
  if ( $last_comment_date ) {
224
  $commentdata['comment_author_url'] = $comment->author->url;
225
  $commentdata['comment_author_IP'] = $comment->author->ip_address;
226
  }
227
+ if (!$_has_updated_thread) {
228
+ update_post_meta($post->ID, 'dsq_thread_id', $comment->thread->id);
229
+ $_has_updated_thread = true;
230
+ }
231
+ $comment_id = wp_insert_comment($commentdata);
232
+ if ($comment->parent_post) {
233
+ $parent_id = $wpdb->get_var($wpdb->prepare( "SELECT comment_id FROM $wpdb->commentmeta WHERE meta_key = 'dsq_post_id' AND meta_value = '%s' LIMIT 1", $comment->parent_post));
234
+ if ($parent_id) {
235
+ $commentdata['comment_parent'] = $parent_id;
236
+ }
237
+ }
238
+ update_comment_meta($comment_id, 'dsq_parent_post_id', $comment->parent_post);
239
+ update_comment_meta($comment_id, 'dsq_post_id', $comment->id);
240
  }
241
  }
242
 
285
  // schedule the event for 30 seconds from now in case they
286
  // happen to make a quick post
287
  wp_schedule_single_event(time(), 'dsq_sync_post', array($post_id));
288
+ //dsq_sync_post($post_id);
289
+ die('');
290
  break;
291
  case 'export_comments':
292
  if (current_user_can('manage_options') && DISQUS_CAN_EXPORT) {
359
  add_action('init', 'dsq_request_handler');
360
 
361
  function dsq_sync_post($post_id) {
362
+ global $dsq_api, $wpdb;
363
 
364
  $post = get_post($post_id);
365
 
366
  // Call update_thread to ensure our permalink is up to date
367
  dsq_update_permalink($post);
368
 
369
+ // get_thread should limit based on last comment date
370
+ $last_comment_id = $wpdb->get_var($wpdb->prepare( "SELECT cm.comment_id FROM $wpdb->commentmeta as cm INNER JOIN $wpdb->comments as c ON c.comment_ID = cm.comment_id WHERE cm.meta_key = 'dsq_post_id' ORDER BY cm.meta_value LIMIT 1"));
371
+ if (!$last_comment_id) {
372
+ $last_comment_id = 0;
373
+ } else {
374
+ $last_comment_id++;
375
+ }
376
+
377
  // Pull comments from API
378
+ $dsq_response = $dsq_api->get_thread($post, $last_comment_id);
379
  if( $dsq_response < 0 ) {
380
+ header("HTTP/1.0 500 Internal Server Error");
 
381
  return;
382
  }
383
  // Sync comments with database.
533
 
534
  add_action('wp_head','dsq_get_style');
535
 
536
+ // ugly global hack for comments closing
537
+ $EMBED = false;
538
  function dsq_comments_template($value) {
539
+ global $EMBED;
540
  global $post;
541
  global $comments;
542
 
555
  // TODO: If a disqus-comments.php is found in the current template's
556
  // path, use that instead of the default bundled comments.php
557
  //return TEMPLATEPATH . '/disqus-comments.php';
558
+ $EMBED = true;
559
  return dirname(__FILE__) . '/comments.php';
560
  }
561
 
588
  }
589
  add_filter('plugin_action_links', 'dsq_plugin_action_links', 10, 2);
590
 
591
+ /**
592
+ * Hide the default comment form to stop spammers by marking all comments
593
+ * as closed.
594
+ */
595
+ function dsq_comments_open($open, $post_id=null) {
596
+ global $EMBED;
597
+ if ($EMBED) return false;
598
+ return $open;
599
+ }
600
+ add_filter('comments_open', 'dsq_comments_open');
601
+
602
  // Always add Disqus management page to the admin menu
603
  function dsq_add_pages() {
604
  add_submenu_page(
lib/wpapi.php CHANGED
@@ -74,12 +74,13 @@ class DisqusWordPressAPI {
74
  return $response->thread;
75
  }
76
 
77
- function get_thread($post) {
78
  $identifier = dsq_identifier_for_post($post);
79
 
80
  $response = $this->api->get_thread_posts(null, array(
81
  'thread_identifier' => $identifier,
82
  'filter' => 'approved',
 
83
  ));
84
  return $response;
85
  }
74
  return $response->thread;
75
  }
76
 
77
+ function get_thread($post, $start_id=0) {
78
  $identifier = dsq_identifier_for_post($post);
79
 
80
  $response = $this->api->get_thread_posts(null, array(
81
  'thread_identifier' => $identifier,
82
  'filter' => 'approved',
83
+ 'start_id' => $start_id,
84
  ));
85
  return $response;
86
  }
manage.php CHANGED
@@ -128,7 +128,7 @@ foreach ( $dsq_sites as $counter => $dsq_site ):
128
  endforeach;
129
  ?>
130
  <hr />
131
- <a href="http://disqus.com/comments/register/"><?php echo dsq_i('Or register a new one on the Disqus website.'); ?></a>
132
  </td>
133
  </tr>
134
  </table>
128
  endforeach;
129
  ?>
130
  <hr />
131
+ <a href="<?php echo DISQUS_URL; ?>comments/register/"><?php echo dsq_i('Or register a new one on the Disqus website.'); ?></a>
132
  </td>
133
  </tr>
134
  </table>
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: disqus, alexkingorg, crowdfavorite
3
  Tags: comments, threaded, email, notification, spam, avatars, community, profile, widget
4
  Requires at least: 2.8
5
  Tested up to: 3.0
6
- Stable tag: 2.43
7
 
8
  The Disqus comment system replaces your WordPress comment system with your comments hosted and powered by Disqus.
9
 
@@ -62,6 +62,16 @@ you should remove it, and the new plugin should be stored in 'disqus'.
62
 
63
  == Changes ==
64
 
 
 
 
 
 
 
 
 
 
 
65
  2.43
66
 
67
  * Fixed a JavaScript syntax error which would cause linting to fail.
3
  Tags: comments, threaded, email, notification, spam, avatars, community, profile, widget
4
  Requires at least: 2.8
5
  Tested up to: 3.0
6
+ Stable tag: 2.45
7
 
8
  The Disqus comment system replaces your WordPress comment system with your comments hosted and powered by Disqus.
9
 
62
 
63
  == Changes ==
64
 
65
+ 2.45
66
+
67
+ * Comments should now store thread information as well as certain other meta data.
68
+ * Optimize get_thread polling to only pull comments which aren't stored properly.
69
+
70
+ 2.44
71
+
72
+ * Fixed JavaScript response for comments sync call.
73
+ * Comments are now marked as closed while showing the embed (fixes showing default respond form).
74
+
75
  2.43
76
 
77
  * Fixed a JavaScript syntax error which would cause linting to fail.