웹마스터 팁
글을 읽을때 마다 조회수 증가시키기 (0.2.9수정#3)
2008.02.20 16:18
0.2.9선행버전에서 0.2.9로 넘어오면서 게시글 조회부분이 바뀌었더군요?
뭐라 했던거 같은데.. 초보라 잘은 모르겠습니다 ㅎㅎ...
이번에 알려드릴 팁은 글을 읽을때마다 조회수가 증가 (자신의 글은 제외) 입니다.
0.2.9 수정 #3에서 잘 작동하구요.
zbxe\modules\document에서 document.controller.php를 수정해주시면 됩니다.
documnet.controller.php에 319번째 라인부터
아래 코드를 복사하셔서 붙여넣으시면 됩니다.
처음 쓰는 팁이라 많이 어색하네요. 제 홈페이지에서는 무리없이 적용되었지만 문제 있으시면 수정해주세요.
/**
* @brief 해당 document의 조회수 증가
**/
function updateReadedCount($oDocument) {
$document_srl = $oDocument->document_srl;
$member_srl = $oDocument->get('member_srl');
$logged_info = Context::get('logged_info');
// 조회수 업데이트가 되면 trigger 호출 (after)
$output = ModuleHandler::triggerCall('document.updateReadedCount', 'after', $oDocument);
if(!$output->toBool()) return $output;
/* session에 정보로 조회수를 증가하였다고 생각하면 패스
if($_SESSION['readed_document'][$document_srl]) return false; */
// 글의 작성 ip와 현재 접속자의 ip가 동일하면 패스
if($document->ipaddress == $_SERVER['REMOTE_ADDR']) {
$_SESSION['readed_document'][$document_srl] = true;
return false;
}
// document의 작성자가 회원일때 글쓴이와 현재 로그인 사용자의 정보가 일치하면 읽었다고 판단후 세션 등록하고 패스
if($member_srl && $logged_info->member_srl == $member_srl) {
$_SESSION['readed_document'][$document_srl] = true;
return false;
}
// 조회수 업데이트
$args->document_srl = $document_srl;
$output = executeQuery('document.updateReadedCount', $args);
// 세션 등록
$_SESSION['readed_document'][$document_srl] = true;
}