Show
Ignore:
Timestamp:
11/30/06 22:07:03 (14 years ago)
Author:
exi
Message:

Moved comments to a small class and made it use smarty.
Fixed an error message output of the parser.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • dev/common/comments.php

    r92 r130  
    11<?php 
    2 $html .= "<div id=comments-wrap>"; 
     2require_once('class.comments.php'); 
    33 
    4 function bbencode($string) 
    5 { 
    6     $string = strip_tags(stripslashes($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(addslashes($string)); 
    13 } 
    14  
    15 //$kll_id defined now in kill_detail 
    16 //$kll_id = intval($_GET['kll_id']); 
    17 $qry = new DBQuery(); 
     4$comments = new Comments($kll_id); 
    185if (isset($_POST['comment'])) 
    196{ 
    20     $kb = new Killboard(KB_SITE); 
    21     $config = $kb->getConfig(); 
    22  
    237    $pw = false; 
    248    if (!$config->getConfig('comments_pw') || $page->isAdmin()) 
     
    3519        { 
    3620            $comment = $_POST['comment']; 
    37             $comment = bbencode($comment); 
    38  
    3921            $name = $_POST['name']; 
    4022            if ($name == null) 
     
    4224                $name = "Anonymous"; 
    4325            } 
    44             $name = slashfix(strip_tags($name)); 
    45             // Password if right so insert the comment. 
    46             $qry->execute("INSERT INTO kb3_comments (`kll_id`,`comment`,`name`,`posttime`) 
    47                            VALUES ('$kll_id','$comment','$name','".date('Y-m-d H:i:s')."')"); 
     26            $comments->addComment($name, $comment); 
    4827        } 
    4928    } 
     
    5534} 
    5635 
    57 $qry = new DBQuery(); 
    58 $qry->execute("SELECT *,id FROM kb3_comments WHERE `kll_id` = '".$kll_id."' order by posttime asc"); 
    59 if ($qry->recordCount() == 0) 
    60 { 
    61     // no commments 
    62     // $html .= "No Comments yet."; 
    63 } 
    64 else 
    65 { 
    66     while ($data = $qry->getRow()) 
    67     { 
    68         $name = $data['name']; 
    69         $comment = stripslashes($data['comment']); 
    70         $html .= "\n<div class=\"comment-text\" style=\"position: relative;\"><a href=\"?a=search&searchtype=pilot&searchphrase=".$name."\">".$name."</a>:"; 
    71         if ($data['posttime'] && $data['posttime'] != '0000-00-00 00:00:00') 
    72         { 
    73             $html .= '<span style="position:absolute; right: 0px;">'.$data['posttime'].'</span>'; 
    74         } 
    75         $html .= "<p>".$comment."</p>"; 
    76         if ($page->isAdmin()) 
    77         { 
    78             $html .= "<a href=\"javascript:openWindow('?a=comments_delete&c_id=".$data['id']."', null, 480, 350, '' );\">Delete Comment</a>"; 
    79         } 
    80         $html .= "</div>"; 
    81     } 
    82 } 
     36$smarty->assign_by_ref('page', $page); 
    8337 
    84 $html .= "<div><form id=\"postform\" name=\"postform\" method=\"post\" action=\"?a=kill_detail&kll_id=".$kill->getID()."\">"; 
    85 $html .= "<br><b>Add Comment:</b><br><textarea class=\"comment\" name=\"comment\" cols=\"55\" rows=\"5\" wrap=\"PHYSICAL\" onkeyup=\"limitText(this.form.comment,document.getElementById('countdown'),200);\" onkeypress=\"limitText(this.form.comment,document.getElementById('countdown'),200);\"></textarea><br>"; 
    86 $html .= "<span name=\"countdown\" id=\"countdown\">200</span> Letters left<br/>"; 
    87 $html .= "<b>Name:</b>"; 
    88 $html .= "<input style=\"position:relative; right:-3px;\" class=\"comment-button\" name=\"name\" type=\"text\" size=\"24\" maxlength=\"24\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"; 
    89 if ($config->getConfig('comments_pw') && !$page->isAdmin()) 
    90 { 
    91     $html .= "<br><b>Password:</b>"; 
    92     $html .= "<input type=\"password\" name=\"password\" size=\"19\" class=comment-button>&nbsp;&nbsp;&nbsp;&nbsp;"; 
    93 } 
    94 $html .= "<input class=\"comment-button\" name=\"submit\" type=\"submit\" value=\"Add Comment\">"; 
    95 $html .= "</form></div></div>"; 
     38$comment = $comments->getComments(); 
    9639?>