root/dev/common/includes/class.comments.php @ 406

Revision 406, 3.1 KB (checked in by kovell, 13 years ago)

Fixes: Feed version correctly shown. Extra white space in class.comments removed.

Line 
1<?php 
2//! Store and retrieve comments for each killmail.
3
4//! This class is used when the details of a kill are viewed.
5class Comments 
6{ 
7    //! Create a Comments object for a particular kill.
8   
9    /*
10     * \param $kll_id The kill id to attach comments to or retrieve for.
11     */
12    function Comments($kll_id) 
13    {
14        $this->id_ = $kll_id; 
15        $this->raw_ = false; 
16
17        $this->comments_ = array(); 
18    } 
19    //! Retrieve comments for a kill.
20   
21    //! The kill id is set when the Comments object is constructed.
22    function getComments() 
23    { 
24        global $smarty;
25       
26        $qry = new DBQuery(true); 
27        $qry->execute("SELECT *,id FROM kb3_comments WHERE `kll_id` = '".
28            $this->id_."' order by posttime asc");
29        while ($row = $qry->getRow()) 
30        { 
31            $this->comments_[] = array('time' => $row['posttime'], 'name' => $row['name'],
32              'comment' => stripslashes($row['comment']), 'id' => $row['id']); 
33        } 
34        $smarty->assign_by_ref('comments', $this->comments_);
35                $smarty->assign('norep', time()%3700);
36        return $smarty->fetch(get_tpl('block_comments')); 
37    } 
38    //! Add a comment to a kill.
39   
40    /*!
41     * The kill id is set when the Comments object is constructed.
42     * \param $name The name of the comment poster.
43     * \param $text The text of the comment to post.
44     */
45    function addComment($name, $text) 
46    { 
47        $comment = $this->bbencode($text); 
48
49        $name = slashfix(strip_tags($name)); 
50        $qry = new DBQuery(true); 
51        $qry->execute("INSERT INTO kb3_comments (`kll_id`,`comment`,`name`,`posttime`)
52                       VALUES ('".$this->id_."','".$comment."','".$name."','".kbdate('Y-m-d H:i:s')."')"); 
53        $id = $qry->getInsertID(); 
54        $this->comments_[] = array('time' => kbdate('Y-m-d H:i:s'), 
55            'name' => $name, 'comment' => stripslashes($comment), 'id' => $id); 
56
57        // create comment_added event
58        event::call('comment_added', $this); 
59    } 
60    //! Delete a comment.
61   
62    /*
63     * \param $c_id The id of the comment to delete.
64     */
65    function delComment($c_id) 
66    { 
67        $qry = new DBQuery(true); 
68        $qry->execute("DELETE FROM kb3_comments WHERE id='".$c_id); 
69    } 
70    //! Set whether to post the raw comment text or bbencode it.
71    function postRaw($bool) 
72    { 
73        $this->raw_ = $bool; 
74    } 
75    //! bbencode a string.
76   
77    //! Used before posting a comment.
78    function bbencode($string) 
79    { 
80        if (!$this->raw_) 
81        { 
82            $string = strip_tags(stripslashes($string)); 
83        } 
84        $string = str_replace(array('[b]','[/b]','[i]','[/i]','[u]','[/u]'), 
85                              array('<b>','</b>','<i>','</i>','<u>','</u>'), $string); 
86        $string = preg_replace('^\[color=(.*?)](.*?)\[/color]^', '<font color="\1">\2</font>', $string); 
87        $string = preg_replace('^\[kill=(.*?)](.*?)\[/kill]^', '<a href="\?a=kill_detail&kll_id=\1">\2</a>', $string); 
88        $string = preg_replace('^\[pilot=(.*?)](.*?)\[/pilot]^', '<a href="\?a=pilot_detail&plt_id=\1">\2</a>', $string); 
89        return nl2br(addslashes($string)); 
90    } 
91} 
92?>
Note: See TracBrowser for help on using the browser.