cmt.JPG

아래 내용은 전에 있던 소스를 다시수정 하여 최근덧글을 출력하고 마우스가 올려지면 색상이 반전되게 하였습니다.

php를 거의 모르는 상태에서 수정한거라 더 깔끔한 방법이 있을 수도 있습니다.

현제 제 홈페이지 첫화면에 적용되어있는 만큼 출력은 정상적으로 됩니다.

색상은 본인의 게시판에 맞게 수정해도 됩니다. 아래의 소스를 php로 저장한뒤 원하는 부분에서 include 시키면됩니다.

최초 소스의 작성자는 배상봉님의 것임을 밝힘니다.

최근덧글 뉴스티커처럼 흐르게 하기 : http://www.zeroboard.com/?mid=zb4_tip&search_target=user_id&search_keyword=gegoori&document_srl=854038

==============================================================================================================================================

<?
   $_zb_url = "http://계정/bbs/";
   $_zb_path = "/home/계정/bbs/";  // 계정에 따라 조금씩 다름.
   include $_zb_path."outlogin.php";// 여기까지 본인에 맞는것으로 수정

//////////////////////////////////////////////////
// Program Start
///////////////////////////////////////////////////

// Function Recent Comment        Y년m월d일 h시i분am(orpm) 형식을 '/'로 바꿈
function recent_cmt($num=10, $textlen=20, $datetype="Y/m/d h:ia") {
// 위의 시간 끝부분 'a'를 뺴면 12시간 단위가 됨
global $_zb_url, $connect, $t_board, $t_comment, $mb_id, $mb_conf;

// get and set variable
$id = $mb_id; // get IDs
$cutTimeMode = $mb_conf[timemode]; // get time mode
$tc = 0; //Total Counts

// timeMode (1: in 24 hours; 2: today;)
if($cutTimeMode == 1){
  $cut_time = time() - 3600 * 24;   // 24hours
}else if($cutTimeMode == 2){
  $cut_time = mktime(0,0,0,date("m"),date("d"),date("Y")); // today
}else{  $cut_time = 0; // normal
}  

// get values from database
for( $i = 0; $i < sizeof($id); $i++){

// get memo data
    $query = "select * from ".$t_comment."_".$id[$i]." where reg_date >
$cut_time order by no desc limit $num";
    $result = mysql_query($query, $connect) or die(mysql_error());

    while($data=mysql_fetch_array($result)){
      // memo data
      $cmt[$tc][no]      = $data[no];
      $cmt[$tc][name]    = stripslashes($data[name]);
      $cmt[$tc][parent]  = $data[parent];
      $cmt[$tc][date]    = date($datetype, $data[reg_date]);
      $cmt[$tc][reg_date] = $data[reg_date];
      $cmt[$tc][memo]    = cut_str(stripslashes($data[memo]), $textlen);

      // get parent data
      $p_data = mysql_fetch_array(mysql_query("select * from $t_board"."_$id[$i]
where no='$data[parent]'"));
      $cmt[$tc][p_subject] = stripslashes($p_data[subject]);
      $cmt[$tc][p_name]    = stripslashes($p_data[name]);
      $cmt[$tc][p_date]    = date($datetype, $p_data[reg_date]);
      $cmt[$tc][p_target]  = $_zb_url."view.php?id=".$id[$i]."&no=".$p_data[no];

      // ready for sorting
      $tm[$tc] = $data[reg_date]."_$tc";
      $map[$data[reg_date]."_$tc"] = $tc;

      $tc++;
    }
}
// sort by time
if($tc)    
  sort($tm);

// output
$tmp1 = time() - 3600 * 12;
$tmp2 = time() - 3600 * 24;

for($i = sizeof($tm)-1; $i >= sizeof($tm)-$num && $i >= 0; $i--){
$n = $map[$tm[$i]];

?>
<table border="0" width="100%" cellspacing="0" cellpadding="0"><tr><td bgcolor="#666666" onmouseout="this.style.backgroundColor=''" onmouseover="this.style.backgroundColor='#555555'">
<?
if($cmt[$n][reg_date] > $tmp1){
$tmpcolor = "white";
}else if($cmt[$n][reg_date] > $tmp2){
$tmpcolor = "black";
}else{
$tmpcolor = "#999999";
}

//아래의 body문에 있는 table다음에 보여질 최근 코멘트 내용 불러오는 부분=================
print "<font title="".$cmt[$n][memo]."" color=$tmpcolor>  ▶</font>";
print "<font size=2><a href=".$cmt[$n][p_target]." title='글쓴이: ".$cmt[$n][p_name].
"  글쓴날: ".$cmt[$n][p_date]."'>";
print $cmt[$n][memo]."</a>   ";   // [p_subject]를 [memo]로 수정함
print $cmt[$n][name]."  ".$cmt[$n][date]."  ";
print "</font><br>";
//여기까지 (수정 가능함)==================================================================

?>
</td></tr></table>
<?
}

}
?>

<html>
<head><title>Recent Comments</title></head>    
<body leftmargin="0" marginwidth="0" topmargin="0" marginheight="0">
<font size="2">
<?
    $mb_id = array("게시판1", "게시판2", ~~~~~);//본인의 게시판이름 나열
    recent_cmt(10,30);// 앞의 10은 덧글 개수 뒤의 30는 덧글의 길이지정
?>
</font>
</body>
</html>