public
Description: The ultra-lightweight ultra-flexible blogging engine with a fetish for birds and misspellings.
Homepage: http://chyrp.net/
Clone URL: git://github.com/vito/chyrp.git
Click here to lend your support to: chyrp and make a donation at www.pledgie.com !
Refactored and fixed AJAX comment autoreloading.
vito (author)
Thu Sep 04 14:10:04 -0700 2008
commit  351a1a8fd43618ddcf5b8227c64a1217df797efd
tree    61525ac31f7fb4af888fab1c305df7d06f283db2
parent  3adf78dfab6e39235682694388d7913361a3a7a4
...
98
99
100
101
 
102
103
104
...
425
426
427
428
 
429
430
 
431
432
433
...
440
441
442
443
444
445
 
 
446
 
 
 
 
447
448
 
449
450
451
...
98
99
100
 
101
102
103
104
...
425
426
427
 
428
429
 
430
431
432
433
...
440
441
442
 
443
 
444
445
446
447
448
449
450
451
 
452
453
454
455
0
@@ -98,7 +98,7 @@
0
                        $created_at);
0
 
0
       if (isset($_POST['ajax']))
0
-        exit("{ comment_id: ".$_POST['id']." }");
0
+        exit("{ comment_id: ".$_POST['id'].", comment_timestamp: \"".$created_at."\" }");
0
 
0
       if ($_POST['status'] == "spam")
0
         Flash::notice(__("Comment updated."), "/admin/?action=manage_spam");
0
@@ -425,9 +425,9 @@
0
           $post = new Post($_POST['post_id']);
0
           if ($post->latest_comment > $_POST['last_comment']) {
0
             $new_comments = $sql->select("comments",
0
-                                         "id",
0
+                                         "id, created_at",
0
                                          array("post_id" => $_POST['post_id'],
0
-                                               "id >" => $_POST['last_comment'],
0
+                                               "created_at >" => $_POST['last_comment'],
0
                                                "status not" => "spam",
0
                                                "status != 'denied' OR (
0
                                                     (
0
@@ -440,12 +440,16 @@
0
                                          "created_at ASC",
0
                                          array(":visitor_id" => $visitor->id));
0
 
0
-            error_log(print_r($new_comments, true));
0
             $ids = array();
0
-            while ($the_comment = $new_comments->fetchObject())
0
+            $last_comment = "";
0
+            while ($the_comment = $new_comments->fetchObject()) {
0
               $ids[] = $the_comment->id;
0
+
0
+              if (strtotime($last_comment) < strtotime($the_comment->created_at))
0
+                $last_comment = $the_comment->created_at;
0
+            }
0
 ?>
0
-{ "comment_ids": [ <?php echo implode(", ", $ids); ?> ] }
0
+{ comment_ids: [ <?php echo implode(", ", $ids); ?> ], last_comment: "<?php echo $last_comment; ?>" }
0
 <?php
0
           }
0
           break;
...
10
11
12
13
 
14
15
16
...
22
23
24
25
 
26
27
28
...
64
65
66
 
67
68
69
70
71
...
10
11
12
 
13
14
15
16
...
22
23
24
 
25
26
27
28
...
64
65
66
67
68
 
69
70
71
0
@@ -10,7 +10,7 @@ $(function(){
0
 <?php if ($config->auto_reload_comments and $config->enable_reload_comments): ?>
0
     var updater = setInterval("Comment.reload()", <?php echo $config->auto_reload_comments * 1000; ?>);
0
 <?php endif; ?>
0
-    $("#add_comment").append($(document.createElement("input")).attr({ type: "hidden", name: "ajax", value: "true", id: "ajax" }));
0
+    $("#add_comment").append($(document.createElement("input")).attr({ type: "hidden", name: "ajax", value: "true", id: "ajax" }))
0
     $("#add_comment").ajaxForm({ dataType: "json", resetForm: true, beforeSubmit: function(){
0
       $("#add_comment").loader();
0
     }, success: function(json){
0
@@ -22,7 +22,7 @@ $(function(){
0
           var plural = (count == 1) ? "" : "s"
0
           $(".comment_plural").text(plural)
0
         }
0
-        $("#last_comment").val(json.comment_id)
0
+        $("#last_comment").val(json.comment_timestamp)
0
         $(data).appendTo(".comments:not(:header)").hide().fadeIn("slow")
0
       })
0
     }, complete: function(){
0
@@ -64,8 +64,8 @@ var Comment = {
0
     var id = $(".comments:not(:header)").attr("id").replace(/comments_/, "")
0
     if (editing == 0 && notice == 0 && $(".comments:not(:header)").children().size() < <?php echo $config->comments_per_page; ?>) {
0
       $.ajax({ type: "post", dataType: "json", url: "<?php echo $config->chyrp_url; ?>/includes/ajax.php", data: "action=reload_comments&post_id="+id+"&last_comment="+$("#last_comment").val(), success: function(json) {
0
+        $("#last_comment").val(json.last_comment)
0
         $.each(json.comment_ids, function(i, id) {
0
-          $("#last_comment").val(id)
0
           $.post("<?php echo $config->chyrp_url; ?>/includes/ajax.php", { action: "show_comment", comment_id: id }, function(data){
0
             $(data).appendTo(".comments:not(:header)").hide().fadeIn("slow")
0
           })
...
14
15
16
 
 
 
17
18
19
...
110
111
112
113
 
114
115
116
...
132
133
134
135
 
136
137
138
...
14
15
16
17
18
19
20
21
22
...
113
114
115
 
116
117
118
119
...
135
136
137
 
138
139
140
141
0
@@ -14,6 +14,9 @@
0
     public function __construct($comment_id, $options = array()) {
0
       parent::grab($this, $comment_id, $options);
0
 
0
+      if ($this->no_results)
0
+        return false;
0
+
0
       $this->body_unfiltered = $this->body;
0
       $group = ($this->user_id and !$this->user()->no_results) ? $this->user()->group() : new Group(Config::current()->guest_group) ;
0
 
0
@@ -110,7 +113,7 @@
0
           $_SESSION['comments'][] = $comment->id;
0
 
0
           if (isset($_POST['ajax']))
0
-            exit("{ comment_id: ".$comment->id." }");
0
+            exit("{ comment_id: ".$comment->id.", comment_timestamp: \"".$comment->created_at."\" }");
0
 
0
           Flash::notice(__("Comment added."), $post->url()."#comment_".$comment->id);
0
         }
0
@@ -132,7 +135,7 @@
0
         $_SESSION['comments'][] = $comment->id;
0
 
0
         if (isset($_POST['ajax']))
0
-          exit("{ comment_id: ".$comment->id." }");
0
+          exit("{ comment_id: ".$comment->id.", comment_timestamp: \"".$comment->created_at."\" }");
0
 
0
         Flash::notice(__("Comment added."), $post->url()."#comment_".$comment->id);
0
       }

Comments