Changeset 122

Show
Ignore:
Timestamp:
15/06/05 23:28:17 (4 years ago)
Author:
davea
Message:

Comments can be deleted from individual entries now, if the blog owner is logged in.

Files:

Legend:

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

    r121 r122  
    557557                $this->printComments(); 
    558558                $this->printAuthorisedUsers(); 
     559        } 
     560 
     561        function deleteComments($entry) { 
     562                if(isset($_POST['submit'])) { 
     563                        if(count($_POST['comment'])==0){ 
     564                                error(5, _("No comments selected for deletion.")); 
     565                                echo "<a href=\"{$this->blog->blogPath}entry/$entry\">"._("Return to blog entry")."</a>\n"; 
     566                        } else { 
     567                                $del = "("; 
     568                                foreach($_POST['comment'] as $c) { 
     569                                        $del .= "id = $c OR "; 
     570                                } 
     571                                $del = substr($del, 0, -4).")"; 
     572                                $sql = "DELETE FROM comments WHERE $del"; 
     573                                if(!db_query($sql)) { 
     574                                        error(2, _("Database commit error.")); 
     575                                } else { 
     576                                        echo "<div class=\"updateinfo\">".count($_POST['comment'])._(" comment(s) deleted.")."</div>\n"; 
     577                                        echo "<a href=\"{$this->blog->blogPath}entry/$entry\">"._("Return to blog entry")."</a>\n"; 
     578                                } 
     579                        } 
     580                } 
    559581        } 
    560582 
  • admin.php

    r121 r122  
    7373                                                $admin->updateComments(); 
    7474                                                break; 
     75                                        case "deletecomments": 
     76                                                $admin->deleteComments(array_shift($request)); 
     77                                                break; 
    7578                                        case "updateauthusers": 
    7679                                                $admin->updateAuthorisedUsers(); 
  • blog.css

    r121 r122  
    279279        font-size: 12px; 
    280280} 
     281.errorinfo { 
     282        border: solid 1px red; 
     283        background-color: #FF8074; 
     284        padding: 3px; 
     285        font-size: 12px; 
     286} 
     287 
     288input.smallcheckbox { 
     289        padding: 0; 
     290        margin: 0; 
     291} 
  • blog.lib.php

    r121 r122  
    2222*/ 
    2323function error($level, $error) { 
    24         echo("Level ".$level." error - ".$error); 
     24        echo("<p class=\"errorinfo\">"._("Level ").$level._(" error - ").$error."</p>"); 
    2525} 
    2626 
     
    4040        var $entryError;        //new entry errors 
    4141        var $entryTags;         //what we allow in the entry 
    42                          
     42        var $currentEntry;      // the shortsubject of the current entry (where applicable) 
     43                 
    4344        //Constructor - checks we've been given a valid username, and pulls in generic blog info 
    4445        function blogs($user)  
     
    6970                        $this->comment_moderation = ($sqlRow['moderate']=='t') ? TRUE : FALSE; 
    7071                        $this->entryTags = array('<b>','<i>','<strong>','<em>','<p>','<a>','<img>','<hr>','<br>'); 
     72                        $this->currentEntry = ""; 
    7173 
    7274                        // setup the session 
     
    179181                else    { 
    180182                        $sqlRow = db_getrow($sql); 
     183                        $this->currentEntry = $sqlRow['shortsubject']; 
    181184                        $this->printEntry($sqlRow, false, false); 
    182185                        $this->printComments($sqlRow['id']); 
     
    188191        function printComments($postid, $offset=0, $limit=15)  
    189192        { 
    190                 $sql = db_query("SELECT timestamp, name, email, body, host FROM comments WHERE post = ".$postid." and moderated = true ORDER BY timestamp ASC limit ".$limit." OFFSET ".$offset.";"); 
    191                 $sqlNum = db_num_rows($sql); 
     193                $sql = db_query("SELECT timestamp, name, email, body, host, id FROM comments WHERE post = ".$postid." and moderated = true ORDER BY timestamp ASC limit ".$limit." OFFSET ".$offset.";"); 
     194                $sqlNum = db_num_rows($sql); 
     195                $blogOwner = $this->checkSessionOwner(); 
     196                $count=0; 
     197                if($blogOwner) { 
     198                        echo "<form name=\"deletecomments\" id=\"deletecomments\" method=\"post\" action=\"{$this->httpPath}admin.php/deletecomments/{$this->currentEntry}\">\n"; 
     199                } 
    192200                echo "<div id=\"comments\">\n"; 
    193201                if ($sqlNum > 0) { 
    194202                        while ($sqlRow = db_getrow($sql)) { 
    195                                 $this->printComment($sqlRow); 
     203                                $this->printComment($sqlRow, $blogOwner, $count++); 
    196204                        } 
    197205                } 
    198206                echo "</div>\n"; 
     207                if($blogOwner) { 
     208                        echo "<div style=\"width: 100%; text-align: right\">\n"; 
     209                        echo "<input type=\"submit\" name=\"submit\" value=\"Delete Comments\" />\n"; 
     210                        echo "</div>\n"; 
     211                        echo "</form>\n"; 
     212                } 
    199213        } 
    200214 
    201215        //print a comment 
    202         function printComment($row)  
     216        function printComment($row, $printCheckBox=FALSE, $checkBoxNum=0)  
    203217        { 
    204218                echo "<div class=\"blogcomment\">\n"; 
    205219                echo "<h3>" . $row['name'] . " writes:</h3>"; 
    206220                echo "<p>" . $row['body'] . "</p>\n"; 
    207                 echo "<p class=\"entryfoot\">[ " .strftime($this->longDateFormat,strtotime($row['timestamp'])). " ]</p>\n"; 
     221                echo "<p class=\"entryfoot\">[ " .strftime($this->longDateFormat,strtotime($row['timestamp'])); 
     222                if($printCheckBox){ 
     223                        echo " | <input class=\"smallcheckbox\" type=\"checkbox\" id=\"comment{$checkBoxNum}\" name=\"comment[{$checkBoxNum}]\" value=\"{$row['id']}\" />\n"; 
     224                        echo "<label for=\"comment{$checkBoxNum}\">Delete</label>\n"; 
     225                } 
     226                echo " ]</p>\n"; 
    208227                echo "</div>\n"; 
    209228        } 
     
    348367                        else { 
    349368                                if(!$moderated) { 
    350                                         echo "<p class=\"updateinfo\">*** "._("Your comment has been added, but before it appears here it must be accepted by the blog owner.")." ***</p>"; 
     369                                        echo "<p class=\"updateinfo\">"._("Your comment has been added, but before it appears here it must be accepted by the blog owner.")."</p>"; 
    351370                                } elseif(!$printentry) { 
    352371                                        echo "<div class=\"blogcomment\">\n";