]> git.mjollnir.org Git - s9y.git/commitdiff
Fix decreasing comment count when tracbkack is deleted
authorgarvinhicking <garvinhicking>
Thu, 30 Mar 2006 09:18:03 +0000 (09:18 +0000)
committergarvinhicking <garvinhicking>
Thu, 30 Mar 2006 09:18:03 +0000 (09:18 +0000)
docs/NEWS
include/admin/comments.inc.php
include/functions_comments.inc.php

index 7a131cf50642dab0f5c2239dcc063ac0edc8ee3f..dbb9487552ad3083d2aaa91ee21033a5693d2d78 100644 (file)
--- a/docs/NEWS
+++ b/docs/NEWS
@@ -45,6 +45,9 @@ Version 1.1-alpha1()
 Version 1.0 ()
 ------------------------------------------------------------------------
 
+   * Fix messing up comment count when deleting a trackback from admin
+     panel (garvinhicking)
+
    * Fix missing UTF-8 encoding of date locales on Windows setups
      (garvinhicking)
 
index f46770062185876bae90ba825f4c8bd2959768d4..fd2fca5f7faaffb0ca8eff3514e3b2afa25cabbf 100644 (file)
@@ -171,7 +171,7 @@ function FT_toggle(id) {
     if ( document.getElementById(id + '_full').style.display == '' ) {
         document.getElementById(id + '_full').style.display='none';
         document.getElementById(id + '_summary').style.display='';
-        document.getElementById(id + '_text').innerHTML = '<?php echo VIEW ?>';
+        document.getElementById(id + '_text').innerHTML = '<?php echo TOGGLE_ALL ?>';
     } else {
         document.getElementById(id + '_full').style.display='';
         document.getElementById(id + '_summary').style.display='none';
@@ -387,9 +387,9 @@ foreach ($sql as $rs) {
           <a href="?serendipity[action]=admin&amp;serendipity[adminModule]=comments&amp;serendipity[adminAction]=approve&amp;serendipity[id]=<?php echo $comment['id'] ?>&amp;<?php echo serendipity_setFormToken('url'); ?>" class="serendipityIconLink" title="<?php echo APPROVE; ?>"><img src="<?php echo serendipity_getTemplateFile('admin/img/accept.png'); ?>" alt="<?php echo APPROVE ?>" /><?php echo APPROVE ?></a>
 <?php } ?>
 <?php if ($comment['excerpt']) { ?>
-          <a href="#c<?php echo $comment['id'] ?>" onclick="FT_toggle(<?php echo $comment['id'] ?>); return false;" title="<?php echo VIEW; ?>" class="serendipityIconLink"><img src="<?php echo serendipity_getTemplateFile('admin/img/zoom.png'); ?>" alt="<?php echo VIEW; ?>" /><span id="<?php echo $comment['id'] ?>_text"><?php echo VIEW ?></span></a>
+          <a href="#c<?php echo $comment['id'] ?>" onclick="FT_toggle(<?php echo $comment['id'] ?>); return false;" title="<?php echo VIEW; ?>" class="serendipityIconLink"><img src="<?php echo serendipity_getTemplateFile('admin/img/zoom.png'); ?>" alt="<?php echo TOGGLE_ALL; ?>" /><span id="<?php echo $comment['id'] ?>_text"><?php echo TOGGLE_ALL ?></span></a>
 <?php } ?>
-          <a target="_blank" href="<?php echo $entrylink; ?>" title="<?php echo VIEW; ?>" class="serendipityIconLink"><img src="<?php echo serendipity_getTemplateFile('admin/img/zoom.png'); ?>" alt="<?php echo EDIT; ?>" /><?php echo VIEW ?></a>
+          <a target="_blank" href="<?php echo $entrylink; ?>" title="<?php echo VIEW; ?>" class="serendipityIconLink"><img src="<?php echo serendipity_getTemplateFile('admin/img/zoom.png'); ?>" alt="<?php echo VIEW; ?>" /><?php echo VIEW ?></a>
           <a href="?serendipity[action]=admin&amp;serendipity[adminModule]=comments&amp;serendipity[adminAction]=edit&amp;serendipity[id]=<?php echo $comment['id'] ?>&amp;serendipity[entry_id]=<?php echo $comment['entry_id'] ?>&amp;<?php echo serendipity_setFormToken('url'); ?>" title="<?php echo EDIT; ?>" class="serendipityIconLink"><img src="<?php echo serendipity_getTemplateFile('admin/img/edit.png'); ?>" alt="<?php echo EDIT; ?>" /><?php echo EDIT ?></a>
           <a href="?serendipity[action]=admin&amp;serendipity[adminModule]=comments&amp;serendipity[adminAction]=delete&amp;serendipity[id]=<?php echo $comment['id'] ?>&amp;serendipity[entry_id]=<?php echo $comment['entry_id'] ?>&amp;<?php echo serendipity_setFormToken('url'); ?>" onclick='return confirm("<?php echo sprintf(COMMENT_DELETE_CONFIRM, $comment['id'], htmlspecialchars($comment['author'])) ?>")' title="<?php echo DELETE ?>" class="serendipityIconLink"><img src="<?php echo serendipity_getTemplateFile('admin/img/delete.png'); ?>" alt="<?php echo DELETE; ?>" /><?php echo DELETE ?></a>
           <?php echo $comment['action_more']; ?>
index 11bc34f890e9583736880bace36a1cecab032045..e2929267046f0b6220a2f9a8c92983acbc6801e9 100644 (file)
@@ -297,6 +297,12 @@ function serendipity_printComments($comments, $parentid = 0, $depth = 0, $trace
 function serendipity_deleteComment($id, $entry_id, $type='comments') {
     global $serendipity;
 
+    $id       = (int)$id;
+    $entry_id = (int)$entry_id;
+    if ($id < 1 OR $entry_id < 1) {
+        return false;
+    }
+    
     if ($_SESSION['serendipityAuthedUser'] === true) {
         $admin = '';
         if (!serendipity_checkPermission('adminEntriesMaintainOthers')) {
@@ -305,10 +311,9 @@ function serendipity_deleteComment($id, $entry_id, $type='comments') {
 
         /* We have to figure out if the comment we are about to delete, is awaiting approval,
            if so - we should *not* subtract it from the entries table */
-        $sql = serendipity_db_query("SELECT status, parent_id, body FROM {$serendipity['dbPrefix']}comments
-                                            WHERE entry_id = ". (int)$entry_id ."
-                                                    AND id = ". (int)$id ."
-                                                    $admin", true);
+        $sql = serendipity_db_query("SELECT type, status, parent_id, body FROM {$serendipity['dbPrefix']}comments
+                                            WHERE entry_id = ". $entry_id ."
+                                                    AND id = ". $id, true);
 
 
         /* Check to see if the comment has children
@@ -316,26 +321,30 @@ function serendipity_deleteComment($id, $entry_id, $type='comments') {
             to delete a tree, delete children first */
         $has_parent = serendipity_db_query("SELECT count(id) AS count
                                               FROM {$serendipity['dbPrefix']}comments
-                                             WHERE parent_id = ". (int)$id . "
+                                             WHERE parent_id = ". $id . "
                                              LIMIT 1", true);
 
         if (is_array($has_parent) && isset($has_parent['count']) && $has_parent['count'] > 0 && $sql['body'] != 'COMMENT_DELETED') {
             // Comment has childs, so don't delete it.
             serendipity_db_query("UPDATE {$serendipity['dbPrefix']}comments
                                      SET body = 'COMMENT_DELETED'
-                                   WHERE id = " . (int)$id);
+                                   WHERE id = " . $id);
         } else {
             // Comment has no childs or had already been deleted., it can be safely removed.
             serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}comments
-                                        WHERE entry_id = '". (int)$entry_id ."'
-                                                AND id = '". (int)$id ."'
-                                                $admin");
+                                        WHERE entry_id = ". $entry_id ."
+                                                AND id = ". $id);
 
             if (is_array($sql) && $sql['status'] !== 'pending') {
-                serendipity_db_query("UPDATE {$serendipity['dbPrefix']}entries SET $type = $type-1 WHERE id = '". (int)$entry_id ."' $admin");
+                if (!empty($sql['type']) && $sql['type'] != 'NORMAL') {
+                    $type = 'trackbacks';
+                } else {
+                    $type = 'comments';
+                }
+                serendipity_db_query("UPDATE {$serendipity['dbPrefix']}entries SET $type = $type-1 WHERE id = ". $entry_id ." $admin");
             }
 
-            serendipity_db_query("UPDATE {$serendipity['dbPrefix']}comments SET parent_id = " . (int)$sql['parent_id'] . " WHERE parent_id = '" . (int)$id . "'");
+            serendipity_db_query("UPDATE {$serendipity['dbPrefix']}comments SET parent_id = " . (int)$sql['parent_id'] . " WHERE parent_id = " . $id);
         }
         return true;
     } else {