비회원 또는 신고 댓글 블라인드 애드온을 만들고 있는데요
다음과 같이 코드를 구현했습니다
$oDocumentModel = getModel('document');
$document_srl = Context::get('document_srl');
$oDocument = $oDocumentModel->getDocument($document_srl);
$comment_list = $oDocument->getComments();
if($comment_list)
{
foreach($comment_list as $key => $comment)
{
$comment->add('content', '블라인드된 댓글입니다');
}
}
$document_srl = Context::get('document_srl');
$oDocument = $oDocumentModel->getDocument($document_srl);
$comment_list = $oDocument->getComments();
if($comment_list)
{
foreach($comment_list as $key => $comment)
{
$comment->add('content', '블라인드된 댓글입니다');
}
}
그런데 아무리 해도 댓글 내용이 안바뀌길래 알아보니
$oDocument->getComments() 로 $comment_list 를 받아올 경우
내용이 바뀌지 않는다고 하는데 댓글 내용을 바꿀 방법이 없을까요?
어렵네요...
댓글 6
foreach에 '회원인 경우'와 '해당 댓글이 신고 받지 않은 경우'로 조건 걸어서 댓글을 뿌려주면 되지 않을까요?
'비회원인 경우' 또는 '신고된 댓글인 경우'는 출력하시려는 메시지를 내보내시면 될 거구요.
해당 if 제어는 구현 해놨는데
$comment->add('content', '블라인드된 댓글입니다'); 이 부분이 동작하질 않네요
답변 감사합니다
호출 시점을 어떻게 하셨는지, 등등을 알 수 있게 소스를 좀 더 공개해주시면 더 많은 조언을 얻으실 수 있을 거 같은데요.
if(!defined("__XE__")) exit();
if($called_position == 'after_module_proc') {
if($this->act != "dispBoardContent" && $this->act != "procBoardInsertDocument" && $this->act != "dispBoardDelete") return;
$oModuleModel = &getModel('module');
$logged_info = Context::get('logged_info');
$declared_max = (int)$addon_info->declared_max;
$blamed_max = (int)$addon_info->blamed_max;
if($blamed_max == 0 && $declared_max == 0) return;
$useDeclared = $declared_max > 0;
$useBlamed = $blamed_max > 0;
$limited_title = $addon_info->limited_title;
$limited_message = $addon_info->limited_message;
$document_srl = Context::get('document_srl');
$document_list = Context::get('document_list');
// 본문 블라인드
if($document_list) {
foreach($document_list as $key=>$document){
if ( $useBlamed ) {
$result = executeQuery('document.getDeclaredDocument', $document);
}
if($result->data->declared_count >= $blamed_max){
$grant = $oModuleModel->getGrant($oModuleModel->getModuleInfoByModuleSrl($document->get('module_srl')), $logged_info);
$document->add('title', $limited_title.' - '.$document->get('title'));
$document->add('nick_name', "익명");
$document->add('content', $limited_message);
}
}
}
$oDocumentModel = getModel('document');
$document_srl = Context::get('document_srl');
$oDocument = $oDocumentModel->getDocument($document_srl);
$comment_list = $oDocument->getComments();
// 댓글 블라인드
if($comment_list)
{
foreach($comment_list as $key => $comment)
{
// 댓글 정보를 구해옴
if ( $useDeclared ) {
$result = executeQuery('comment.getDeclaredcomment', $comment);
}
// 댓글 블라인드 내용 부분
if($result->data->declared_count >= $declared_max) {
$comment->add('content', '블라인드된 댓글입니다');
}
}
}
}
?>
현재 작성 코드는 이렇습니다
대부분의 게시판 스킨이 getComments()를 직접 호출하여 DB에서 새 데이터를 불러오기 때문에, 예전에 조작해 놓은 내용은 무시됩니다. 애드온에서 댓글을 조작하려면 before_display_output 시점에 HTML 콘텐츠를 직접 뜯어고치는 방법밖에 없어요.
순정 XE가 아닌 라이믹스라면 document.getComments (after) 또는 comment.getCommentList (after) 트리거를 통해 댓글을 DB에서 불러오는 시점에 끼어들어 조작할 수 있고, 애드온에서도 트리거를 쓸 수 있습니다.
어쩐지 아무리 해도 조작이 안되더라니... 참고해서 다듬어보겠습니다 ㅠㅠ