1 | <?php |
---|
2 | |
---|
3 | class Comments |
---|
4 | { |
---|
5 | |
---|
6 | function Comments($kll_id) |
---|
7 | { |
---|
8 | $this->id_ = $kll_id; |
---|
9 | $this->raw_ = false; |
---|
10 | |
---|
11 | $this->comments_ = array(); |
---|
12 | $qry = new DBQuery(true); |
---|
13 | $qry->execute("SELECT *,id FROM kb3_comments WHERE `kll_id` = '".$kll_id."' order by posttime asc"); |
---|
14 | while ($row = $qry->getRow()) |
---|
15 | { |
---|
16 | $this->comments_[] = array('time' => $row['posttime'], 'name' => $row['name'], 'comment' => stripslashes($row['comment']), 'id' => $row['id']); |
---|
17 | } |
---|
18 | } |
---|
19 | |
---|
20 | function getComments() |
---|
21 | { |
---|
22 | global $smarty; |
---|
23 | |
---|
24 | $smarty->assign_by_ref('comments', $this->comments_); |
---|
25 | return $smarty->fetch(get_tpl('block_comments')); |
---|
26 | } |
---|
27 | |
---|
28 | function addComment($name, $text) |
---|
29 | { |
---|
30 | $comment = $this->bbencode($text); |
---|
31 | |
---|
32 | $name = slashfix(strip_tags($name)); |
---|
33 | $qry = new DBQuery(true); |
---|
34 | $qry->execute("INSERT INTO kb3_comments (`kll_id`,`comment`,`name`,`posttime`) |
---|
35 | VALUES ('".$this->id_."','".$comment."','".$name."','".kbdate('Y-m-d H:i:s')."')"); |
---|
36 | $id = $qry->getInsertID(); |
---|
37 | $this->comments_[] = array('time' => kbdate('Y-m-d H:i:s'), 'name' => $name, 'comment' => stripslashes($comment), 'id' => $id); |
---|
38 | |
---|
39 | // create comment_added event |
---|
40 | event::call('comment_added', $this); |
---|
41 | } |
---|
42 | |
---|
43 | function delComment($c_id) |
---|
44 | { |
---|
45 | $qry = new DBQuery(true); |
---|
46 | $qry->execute("DELETE FROM kb3_comments WHERE id='".$c_id."' LIMIT 1"); |
---|
47 | } |
---|
48 | |
---|
49 | function postRaw($bool) |
---|
50 | { |
---|
51 | $this->raw_ = $bool; |
---|
52 | } |
---|
53 | |
---|
54 | function bbencode($string) |
---|
55 | { |
---|
56 | if (!$this->raw_) |
---|
57 | { |
---|
58 | $string = strip_tags(stripslashes($string)); |
---|
59 | } |
---|
60 | $string = str_replace(array('[b]','[/b]','[i]','[/i]','[u]','[/u]'), |
---|
61 | array('<b>','</b>','<i>','</i>','<u>','</u>'), $string); |
---|
62 | $string = preg_replace('^\[color=(.*?)](.*?)\[/color]^', '<font color="\1">\2</font>', $string); |
---|
63 | $string = preg_replace('^\[kill=(.*?)](.*?)\[/kill]^', '<a href="\?a=kill_detail&kll_id=\1">\2</a>', $string); |
---|
64 | $string = preg_replace('^\[pilot=(.*?)](.*?)\[/pilot]^', '<a href="\?a=pilot_detail&plt_id=\1">\2</a>', $string); |
---|
65 | return nl2br(addslashes($string)); |
---|
66 | } |
---|
67 | } |
---|
68 | ?> |
---|