root/dev/common/comments.php @ 39

Revision 39, 3.4 KB (checked in by exi, 16 years ago)

created cache/data for several purposes
small changes to comments and kill details to filter for valid killids
added signature generator alpha-version

Line 
1<?php
2$html .= "<div id=comments-wrap>";
3
4function bbencode($string)
5{
6    $string = strip_tags(&$string);
7    $string = str_replace(array('[b]','[/b]','[i]','[/i]','[u]','[/u]'),
8                          array('<b>','</b>','<i>','</i>','<u>','</u>'), $string);
9    $string = preg_replace('^\[color=(.*?)](.*?)\[/color]^', '<font color="\1">\2</font>', $string);
10    $string = preg_replace('^\[kill=(.*?)](.*?)\[/kill]^', '<a href="\?a=kill_detail&kll_id=\1">\2</a>', $string);
11    $string = preg_replace('^\[pilot=(.*?)](.*?)\[/pilot]^', '<a href="\?a=pilot_detail&plt_id=\1">\2</a>', $string);
12        return nl2br($string);
13}
14
15//$kll_id defined now in kill_detail
16//$kll_id = intval($_GET['kll_id']);
17$qry = new DBQuery();
18if (isset($_POST['comment']))
19{
20    $kb = new Killboard(KB_SITE);
21    $config = $kb->getConfig();
22
23    $pw = false;
24    if (!$config->getConfig('comments_pw') || $page->isAdmin())
25    {
26        $pw = true;
27    }
28    if ($_POST['password'] == $config->getPostPassword() || $pw)
29    {
30        if ($_POST['comment'] == '')
31        {
32            $html .= "Error: Sillent type hey? good for you, bad for a comment.";
33        }
34        else
35        {
36            $comment = $_POST['comment'];
37            $comment = bbencode($comment);
38
39            $name = $_POST['name'];
40            if ($name == null)
41            {
42                $name = "Anonymous";
43            }
44            $name = strip_tags($name);
45            // Password if right so insert the comment.
46            $qry->execute("INSERT INTO kb3_comments (`kll_id`,`comment`,`name`)
47                           VALUES ('$kll_id','$comment','$name')");
48        }
49    }
50    else
51    {
52        // Password is wrong
53        $html .= "Error: Wrong Password";
54    }
55}
56
57$qry = new DBQuery();
58$qry->execute("SELECT id, name, comment FROM kb3_comments WHERE `kll_id` = $kll_id");
59if ($qry->recordCount() == 0)
60{
61    // no commments
62    // $html .= "No Comments yet.";
63}
64else
65{
66    while ($data = $qry->getRow())
67    {
68        $name = $data['name'];
69        $comment = $data['comment'];
70        $html .= "<div class=\"comment-text\"><a href=\"?a=search&searchtype=pilot&searchphrase=".$name."\">".$name."</a>:<p>".$comment."</p>";
71        if ($page->isAdmin())
72        {
73            $html .= "<a href=\"javascript:openWindow('?a=comments_delete&c_id=".$data['id']."', null, 480, 350, '' );\">Delete Comment</a>";
74        }
75        $html .= "</div><br/>";
76    }
77}
78
79$html .= "<div><form id=\"postform\" name=\"postform\" method=\"post\" action=\"?a=kill_detail&kll_id=".$kill->getID()."\">";
80$html .= "<br><b>Add Comment:</b><br><textarea class=\"comment\" name=\"comment\" cols=\"55\" rows=\"5\" wrap=\"PHYSICAL\" onKeypress=\"limitText(this.form.comment,this.form.countdown,200);\"></textarea><br>";
81$html .= "<input readonly type=\"text\" name=\"countdown\" id=\"countdown\" size=\"1\" value=\"200\">Letters left<br/>";
82$html .= "<b>Name:</b>";
83$html .= "<input style=\"position:relative; right:-3px;\" class=\"comment-button\" name=\"name\" type=\"text\" size=\"24\" maxlength=\"24\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
84if ($config->getConfig('comments_pw') && !$page->isAdmin())
85{
86    $html .= "<br><b>Password:</b>";
87    $html .= "<input type=\"password\" name=\"password\" size=\"19\" class=comment-button>&nbsp;&nbsp;&nbsp;&nbsp;";
88}
89$html .= "<input class=\"comment-button\" name=\"submit\" type=\"submit\" value=\"Add Comment\">";
90$html .= "</form></div></div>";
91?>
Note: See TracBrowser for help on using the browser.