코드 수정좀~
본문
원래코드는 if ($list[$i][wo_status])
echo "<a href='" . $list[$i][url] . "' $target_link >"; 입니다
그리고
write_reply : 답글
write_comment : 코멘트
인데요
이걸 답글일 경우 링크될 주소끝에 #board를 붙이려고 합니다, 코멘트일 경우 #board를 안붙이고 원래 주소로 가주고요
if ($list[$i][wo_status])
echo "<a href='" . $list[$i][url] . "(if 'write_reply' #board else none)' $target_link >";
이런식으로 코드안에 답글일 경우 #board를 붙여주고 답글이 아닐경우(코멘트) 안붙여주게 조건문을 넣으려면 어떻게 해야하나요?
*밑의 내용을 참조해 주세요~
----------------------------------------------------------------------------------------------------------------------------------------------------------
내글에 답글 등이 달린 것을 g4_board_new 테이블을 이용해서 얻다가 보니
생각보다 시스템에 부하가 많이 걸리는 편 입니다.
facebook이나 네이버 캐스트를 보면,
내글에 답글/코멘트가 달리면 alert를 주고 있는데
그 기능을 그누보드용으로 작성하였습니다.
이름은 TopSchool님의 제안처럼, 왔숑~(g4 what's on)으로 하기로 했습니다.
왔쑝~!!!
저작권은 없습니다.
수정하든 말든 맘대로 하시되 왔숑~! 을 돈 받구 팔지만 말아주세요.
===
왔숑~의 알람 type
write_reply : 답글
write_comment : 코멘트
===
ajax_whatson.php, whatson.php는 bbs/에
whatson.lib.php 파일은 lib/에
스킨은 skin/에 넣구요.
===
내가 코멘트, 답글 등을 달면, 왔숑~은 오지 않습니다. 당연한거죠?
글쓴이가 제목을 변경하는 경우, 왔숑에는 제목을 변경하지 않습니다.
내가 쓸 때의 제목을 기억하는게 맞는거 같아서요.
누가 그랬는지는 알려주지 않게 했습니다.
왜?
그냥 클릭해보면 알게 되는데, 굳이 공간 낭비할 필요가 없을거 같아서요.
몇시간 전인지? 그거는 안알려줍니다.
시간으로 보세요. ㅎㅎ
내글의 반응과 비슷하지만, 기능이 다르고 이게 더 본질적으로 유용할 것 같아요.
===
사용법은 적당한 위치에서
include_once("$g4[path]/lib/whatson.lib.php");
echo whatson("basic");
===
CREATE TABLE IF NOT EXISTS `g4_whatson` (
`wo_id` int(11) NOT NULL auto_increment,
`mb_id` varchar(255) NOT NULL,
`wo_id` int(11) NOT NULL auto_increment,
`mb_id` varchar(255) NOT NULL,
`wo_type` varchar(20) NOT NULL,
`bo_table` varchar(20) NOT NULL,
`wr_subject` varchar(255) NOT NULL,
`wr_id` int(11) NOT NULL,
`bo_table` varchar(20) NOT NULL,
`wr_subject` varchar(255) NOT NULL,
`wr_id` int(11) NOT NULL,
`comment_id` int(11) NOT NULL,
`wo_count` tinyint(4) NOT NULL,
`wo_datetime` datetime NOT NULL,
`wo_status` tinyint(4) NOT NULL,
PRIMARY KEY (`wo_id`),
KEY `mb_id` (`mb_id`)
)
`wo_count` tinyint(4) NOT NULL,
`wo_datetime` datetime NOT NULL,
`wo_status` tinyint(4) NOT NULL,
PRIMARY KEY (`wo_id`),
KEY `mb_id` (`mb_id`)
)
===
수정사항 (스킨에 따라 영향을 받지 않게 그누 원본을 수정 합니다)
config.php에서 테이블을 정의 합니다.
$g4['whatson_table'] = $g4['table_prefix'] . "whatson"; // 왔~쑝~ 테이블
업데이트는 왔숑~을 할 필요가 없는 것이고,
새글도 왔숑~을 할 필요 없는 것이고,
답글에 대해서 ($w=="r") 왔숑을 보내줘야 하겠죠?
bbs/write_update.php에서 아래 코드를 추가 합니다.
// 불당팩 - 왔~숑~ : 답글의 왔숑 통보, 원글이 회원의 글이고, 원글의 회원아이디와 지금 글쓰는 아이디가 다를 경우에만
if ($w == 'r' && $wr[mb_id] && $wr[mb_id] !== $member[mb_id])
{
$tsql = " UPDATE $g4[whatson_table]
SET wr_subject = '" . get_text(stripslashes($wr[wr_subject])) . "',
wo_count = wo_count+1,
wo_datetime = '$g4[time_ymdhis]'
where bo_table = '$bo_table' and wr_id='$wr[wr_id]' and wo_type='write_reply' ";
sql_query($tsql);
if ($w == 'r' && $wr[mb_id] && $wr[mb_id] !== $member[mb_id])
{
$tsql = " UPDATE $g4[whatson_table]
SET wr_subject = '" . get_text(stripslashes($wr[wr_subject])) . "',
wo_count = wo_count+1,
wo_datetime = '$g4[time_ymdhis]'
where bo_table = '$bo_table' and wr_id='$wr[wr_id]' and wo_type='write_reply' ";
sql_query($tsql);
// update가 안되는 경우에는 insert를 합니다.
if (!mysql_affected_rows()) {
$tsql = " insert into $g4[whatson_table] ( mb_id, wr_subject, wo_type, wo_count, wo_datetime, bo_table, wr_id )
values ('$wr[mb_id]', '" . get_text(stripslashes($wr[wr_subject])) . "','write_reply','1','$g4[time_ymdhis]','$bo_table','$wr[wr_id]') ";
sql_query($tsql);
}
}
if (!mysql_affected_rows()) {
$tsql = " insert into $g4[whatson_table] ( mb_id, wr_subject, wo_type, wo_count, wo_datetime, bo_table, wr_id )
values ('$wr[mb_id]', '" . get_text(stripslashes($wr[wr_subject])) . "','write_reply','1','$g4[time_ymdhis]','$bo_table','$wr[wr_id]') ";
sql_query($tsql);
}
}
게시글을 삭제하는 경우, 해당 게시글에 대한 모든 왔숑~을 삭제 합니다.
그런데, 여기에는 좀 미묘한 문제들이 있습니다.
삭제에 대한 왔숑을 줄것인가 하는 것인데, 이경우는 link가 없기 때문에 주지 않습니다.
bbs/delete.php에서, 답글/코멘트/원글의 왔숑~을 모두 삭제해야 합니다.
// 불당팩 - whaton 삭제 (답글)
$sql = " delete from $g4[whatson_table] where bo_table ='$bo_table' and wr_id = '$row[wr_id]' ";
sql_query($sql);
$sql = " delete from $g4[whatson_table] where bo_table ='$bo_table' and wr_id = '$row[wr_id]' ";
sql_query($sql);
// 불당팩 - whaton 삭제 (코멘트)
$sql = " delete from $g4[whatson_table] where bo_table ='$bo_table' and wr_id = '$row[wr_id]' ";
sql_query($sql);
// 불당팩 - whaton 삭제
$sql = " delete from $g4[whatson_table] where bo_table ='$bo_table' and wr_id = '$write[wr_id]' ";
sql_query($sql);
$sql = " delete from $g4[whatson_table] where bo_table ='$bo_table' and wr_id = '$write[wr_id]' ";
sql_query($sql);
bbs/write_comment_update.php는 코멘트 답변 앞부분의 SQL을 수정하고,
$sql = " select wr_id, wr_comment, wr_comment_reply, mb_id from $write_table
where wr_id = '$comment_id' ";
where wr_id = '$comment_id' ";
아래와 같이 코드를 추가 합니다.
// 불당팩 - 왔~숑~ : 코멘트의 왔숑 통보 (원글에, mb_id가 있고, 현재 글쓴이와 다를 경우에만.)
if ($wr[mb_id] && $wr[mb_id] !== $member[mb_id])
{
$tsql = " UPDATE $g4[whatson_table]
SET wr_subject = '" . get_text(stripslashes($wr[wr_subject])) . "',
wo_count = wo_count+1,
wo_datetime = '$g4[time_ymdhis]'
where bo_table = '$bo_table' and wr_id='$wr[wr_id]' and wo_type='write_comment' ";
sql_query($tsql);
if ($wr[mb_id] && $wr[mb_id] !== $member[mb_id])
{
$tsql = " UPDATE $g4[whatson_table]
SET wr_subject = '" . get_text(stripslashes($wr[wr_subject])) . "',
wo_count = wo_count+1,
wo_datetime = '$g4[time_ymdhis]'
where bo_table = '$bo_table' and wr_id='$wr[wr_id]' and wo_type='write_comment' ";
sql_query($tsql);
// update가 안되는 경우에는 insert를 합니다.
if (!mysql_affected_rows()) {
$tsql = " insert into $g4[whatson_table] ( mb_id, wr_subject, wo_type, wo_count, wo_datetime, bo_table, wr_id, comment_id )
values ('$wr[mb_id]', '" . get_text(stripslashes($wr[wr_subject])) . "','write_comment','1','$g4[time_ymdhis]','$bo_table','$wr_id', '$comment_id') ";
sql_query($tsql);
}
}
// 불당팩 - 왔~숑~ : 코멘트의 왔숑 통보 (원래 코멘트에, mb_id가 있을 때만)
if ($comment_id && $reply_array[mb_id] && $reply_array[mb_id] !== $member[mb_id]) {
$tsql = " UPDATE $g4[whatson_table]
SET wr_subject = '" . get_text(stripslashes($wr[wr_subject])) . "',
wo_count = wo_count+1,
wo_datetime = '$g4[time_ymdhis]'
where bo_table = '$bo_table' and wr_id='$wr_id' and comment_id='$comment_id' and wo_type='write_comment' ";
sql_query($tsql);
if (!mysql_affected_rows()) {
$tsql = " insert into $g4[whatson_table] ( mb_id, wr_subject, wo_type, wo_count, wo_datetime, bo_table, wr_id, comment_id )
values ('$wr[mb_id]', '" . get_text(stripslashes($wr[wr_subject])) . "','write_comment','1','$g4[time_ymdhis]','$bo_table','$wr_id', '$comment_id') ";
sql_query($tsql);
}
}
// 불당팩 - 왔~숑~ : 코멘트의 왔숑 통보 (원래 코멘트에, mb_id가 있을 때만)
if ($comment_id && $reply_array[mb_id] && $reply_array[mb_id] !== $member[mb_id]) {
$tsql = " UPDATE $g4[whatson_table]
SET wr_subject = '" . get_text(stripslashes($wr[wr_subject])) . "',
wo_count = wo_count+1,
wo_datetime = '$g4[time_ymdhis]'
where bo_table = '$bo_table' and wr_id='$wr_id' and comment_id='$comment_id' and wo_type='write_comment' ";
sql_query($tsql);
// update가 안되는 경우에는 insert를 합니다.
if (!mysql_affected_rows()) {
$tsql = " insert into $g4[whatson_table] ( mb_id, wr_subject, wo_type, wo_count, wo_datetime, bo_table, wr_id, comment_id )
values ('$reply_array[mb_id]', '" . get_text(stripslashes($wr[wr_subject])) . "','write_comment','1','$g4[time_ymdhis]','$bo_table', '$wr_id', '$comment_id') ";
sql_query($tsql);
}
}
if (!mysql_affected_rows()) {
$tsql = " insert into $g4[whatson_table] ( mb_id, wr_subject, wo_type, wo_count, wo_datetime, bo_table, wr_id, comment_id )
values ('$reply_array[mb_id]', '" . get_text(stripslashes($wr[wr_subject])) . "','write_comment','1','$g4[time_ymdhis]','$bo_table', '$wr_id', '$comment_id') ";
sql_query($tsql);
}
}
답변 1
if ($list[$i]['wo_status'])
echo "<a href='" . $list[$i]['url'] . ($list[$i]['wo_type']=='write_reply'?'#board':''). $target_link .">";
답변을 작성하시기 전에 로그인 해주세요.