Changeset 189

Show
Ignore:
Timestamp:
06/09/06 11:13:19 (2 years ago)
Author:
rollercow
Message:

Users should no longer be able to delete comments that don't belong to them.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • admin.lib.php

    r166 r189  
    438438                } 
    439439                // checkbox for comment moderation, either is or isnt 
    440                 if ($_POST['moderate'] != "") { 
     440                if ($_POST['moderate'] != "") { 
    441441                        $moderate = "true"; 
    442442                } 
     
    445445                }        
    446446                // checkbox for editor, either is or isnt 
    447                 if ($_POST['editor'] != "") { 
     447                if ($_POST['editor'] != "") { 
    448448                        $editor = "true"; 
    449449                }  
     
    603603                        } 
    604604                        //how display each of the comments 
    605                         if ($r['spam'] == 't')  
     605                        if ($r['spam'] == 't') {  
    606606                                echo "\t<tr class=\"errorinfo\">\n"; 
    607                         else 
     607                        } else { 
    608608                                echo "\t<tr>\n"; 
     609                        } 
    609610                        echo "\t\t<td><a href=\"mailto:{$r['email']}\" title=\"IP: {$r['host']}\">{$r['name']}</a></td>\n"; 
    610611                        echo "\t\t<td>{$r['body']}</td>\n"; 
    611612                        echo "\t\t<td><input type=\"radio\" name=\"group[$count]\" value=\"a:{$r['id']}\" /></td>\n"; 
    612                         if ($r['spam'] == 't')  
     613                        if ($r['spam'] == 't') {  
    613614                                echo "\t\t<td><input type=\"radio\" name=\"group[".$count++."]\" value=\"d:{$r['id']}\" checked=\"checked\"/></td>\n"; 
    614                         else 
     615                        } else { 
    615616                                echo "\t\t<td><input type=\"radio\" name=\"group[".$count++."]\" value=\"d:{$r['id']}\" /></td>\n"; 
     617                        } 
    616618                        echo "\t</tr>\n"; 
    617619                } 
     
    621623                echo "</div>\n"; 
    622624        } 
    623 //got here 
    624625        // approve or delete comments 
    625626        function updateComments() { 
     
    628629                        return; 
    629630                } 
     631                $check = ""; 
    630632                $approved = ""; 
    631633                $acount = 0; 
    632634                $deleted = ""; 
    633635                $dcount = 0; 
     636                //get the comment numbers and requested actions. 
    634637                foreach($_POST['group'] as $comment) { 
    635638                        $c = explode(":", $comment); 
    636639                        if ($c[0] == "a") { 
    637                                 $approved .= $c[1].", "; 
     640                                $approved .= (int)$c[1].", "; 
    638641                                $acount++; 
    639642                        } elseif ($c[0] == "d") { 
    640                                 $deleted .= $c[1].", "; 
     643                                $deleted .= (int)$c[1].", "; 
    641644                                $dcount++; 
    642645                        } else { 
     
    647650                $approved = substr($approved, 0, -2); 
    648651                $deleted = substr($deleted, 0, -2); 
    649 /* 
    650  * Both these querys need a user id check.. even if that means lots of nasty joins 
    651  */ 
     652                //construct a list of comments to check 
     653                if ($approved and $deleted) { 
     654                        $check = $deleted.", ".$approved; 
     655                } else { 
     656                        $check = $deleted.$approved; 
     657                } 
     658                //check the comments exist and blong to the user 
     659                $result = db_getrow(db_query("SELECT count(comments.id) from comments join entries on comments.post = entries.id where entries.user_id = ".$this->id." and comments.id IN($check);")); 
     660                if($result[count] != ($acount + $dcount)) { 
     661                        error(1,_("Cant find the requested comments, maybe they have already been deleted.")); 
     662                        return; 
     663                } 
     664                //delete comments 
    652665                if($deleted!="") { 
    653666                        db_query("DELETE FROM comments WHERE id IN ($deleted);"); 
    654667                } 
     668                //set moderated flag on comments 
    655669                if($approved!="") { 
    656670                        db_query("UPDATE comments SET moderated=true WHERE id IN ($approved);"); 
    657671                } 
     672                //reprint the form 
    658673                echo "<div class=\"updateinfo\">$acount "._("comments approved").", $dcount "._("comments deleted").".</div>\n"; 
    659674                $this->printComments(); 
    660675                $this->printAuthorisedUsers(); 
    661676        } 
    662  
     677        //Delete moderated comments from (a single post) 
    663678        function deleteComments($entry) { 
    664679                if(isset($_POST['submit'])) { 
     
    669684                                $del = "("; 
    670685                                foreach($_POST['comment'] as $c) { 
    671                                         $del .= "id = $c OR "; 
     686                                        $del .= "comments.id = ".(int)$c." OR "; 
    672687                                } 
    673688                                $del = substr($del, 0, -4).")"; 
     689                                //check the comments exist and blong to the user 
     690                                $result = db_getrow(db_query("SELECT count(comments.id) from comments join entries on comments.post = entries.id where entries.user_id = ".$this->id." and $del;")); 
     691                                if($result[count] != count($_POST['comment'])) { 
     692                                        error(1,_("Cant find the requested comments, maybe they have already been deleted.")); 
     693                                        return; 
     694                                } 
     695                                //delete the comments 
    674696                                $sql = "DELETE FROM comments WHERE $del"; 
    675697                                if(!db_query($sql)) { 
     
    701723                $result = db_query("SELECT name,email FROM authorised_emails WHERE user_id=".$this->id." ORDER BY email ASC"); 
    702724                while($r = db_getrow($result)) { 
    703                         echo "\t<option value=\"{$r['email']}\">{$r['email']} ({$r['name']})</option>\n"; 
     725                        echo "\t<option value=\"{$r['email']}\">{$r['email']} ({$r['name']})</option>\n"; 
    704726                } 
    705727                echo "</select><br />\n"; 
     
    844866                if (isset($_POST['username']) && trim($_POST['username']) != "" && (int)$_POST['username'] == 0) { 
    845867                        if (safeuname($_POST['username'])) { 
    846                                       $username = addslashes(trim(strip_tags($_POST['username']))); 
    847                               } 
    848                               else { 
    849                                       $this->inputError = _("Invalid Username Provided"); 
    850                               } 
     868                              $username = addslashes(trim(strip_tags($_POST['username']))); 
     869                      } 
     870                      else { 
     871                              $this->inputError = _("Invalid Username Provided"); 
     872                      } 
    851873                } else { 
    852874                        $this->inputError = _("No Username Provided");