소셜로그인 중단 안내

계정으로 로그인 기능이 2023년 11월 16일 중단되었습니다.

아이보스 계정이 사라지는 것은 절대 아니며, 계정의 이메일 주소를 이용해 로그인 하실 수 있습니다.

▶️ 자세한 공지사항 확인

인기도 점수 뽑아오는 클래스(추천 비추천 코멘트 히트수)

2007.02.07 15:44

유창화

조회수 3,553

댓글 6



아래 올린 팁의 개선형태입니다.

php사이트를 운영하시는 분들은 쉽게 활용할수 있도록 클래스로 만들었습니다.

아래 설명을 잘보시고 그대로 하시면 됩니다.

물론 변수나 이런것은 자신의 사이트에 맞게 고치셔야 합니다.
(클래스 자체는 수정하실 필요없습니다.)




해당 게시물의 인기도를 뽑아오는 클래스 입니다.

클래스 부분은 그냥 복사해서 적당한 파일로 만들어서 서버에 올리고

해당 페이지에선 인클루드 하여 사용합니다.

이하 클래스
______________________________________________________________________


//게시물의 인기도를 측정하는 클래스
class favor_point {

var $point_good;
var $point_nogood;
var $point_comment;
var $point_defalut_full;

var $set_default;
var $set_good;
var $set_comment;

function favor_point($point_good=100, $point_comment=30, $point_defalut_full=5000, $set_default=70, $set_good=15, $set_comment=15){

$this->set_point($point_good, $point_comment, $point_defalut_full);
$this->set_setting($set_default, $set_good, $set_comment);

if (empty($this->point_good) || empty($this->point_nogood) || empty($this->point_comment) || empty($this->point_defalut_full) || empty($this->set_default) || empty($this->set_good) || empty($this->set_comment)) {

die('favor_point : 제대로 된 변수값이 설정되지 않았습니다.');
}
}

function set_point($point_good, $point_comment, $point_defalut_full){

if ($point_good < 1 || $point_comment < 1 || $point_defalut_full < 1 || !is_numeric($point_good) || !is_numeric($point_comment) || !is_numeric($point_defalut_full)) return;
$this->point_good = $point_good;
$this->point_nogood = ceil($point_good * (-1.1));
$this->point_comment = $point_comment;
$this->point_defalut_full = $point_defalut_full;
}

function set_setting($set_default, $set_good, $set_comment){

if ($set_default < 1 || $set_good < 1 || $set_comment < 1 || !is_numeric($set_default) || !is_numeric($set_good) || !is_numeric($set_comment)) return;

if ($set_default + $set_good + $set_comment != 100) return;

$this->set_default = $set_default;
$this->set_good = $set_good;
$this->set_comment = $set_comment;
}

function get_favor_point($good, $nogood, $comment, $hit, $date=''){

$return = Array();

if (empty($date)) $date = date("Y-m-d");
$day = ceil((time() - strtotime($date)) / 86400);
$rule = $this->autochange_rule($day);

$return['default'] = ceil((($good * $rule['point_good']) + ($nogood * $rule['point_nogood']) + ($comment * $rule['point_comment']) + $hit) / $rule['point_defalut_full'] * $rule['set_default']);

if ($return['default'] > $rule['set_default']) $return['default'] = $rule['set_default'];
else if ($return['default'] < 0) $return['default'] = 0;

if ($good > 0 && $good > $nogood) {

$return['good'] = ceil((1 - ($hit / (($good * $rule['point_good']) + ($nogood * $rule['point_nogood'])))) * $rule['set_good']);

if ($return['good'] > $rule['set_good']) $return['good'] = $rule['set_good'];
else if ($return['good'] < 0) $return['good'] = 0;
}
else {

$return['good'] = 0;
}

if ($comment > 0) {

$return['comment'] = ceil((1 - ($hit / ($comment * $rule['point_comment']))) * $rule['set_comment']);

if ($return['comment'] > $rule['set_comment']) $return['comment'] = $rule['set_comment'];
else if ($return['comment'] < 0) $return['comment'] = 0;
}
else {

$return['comment'] = 0;
}

$return['total'] = $return['default'] + $return['good'] + $return['comment'];
return $return;
}

//글작성일에 따른 포인트 자동 변환
function autochange_rule($day){

$return = Array();
$return['point_good'] = $this->point_good;
$return['point_nogood'] = $this->point_nogood;
$return['point_comment'] = $this->point_comment;
$return['point_defalut_full'] = $this->point_defalut_full;

$return['set_default'] = $this->set_default;
$return['set_good'] = $this->set_good;
$return['set_comment'] = $this->set_comment;

if ($day >=31 && $day < 91) {//31일에서 90일 사이 5프로 적용

$return = $this->calculation(5);
}
else if ($day >=91 && $day < 181) {//91일에서 180일 사이 10프로 적용

$return = $this->calculation(10);
}
else if ($day >=181) {//181일 이상 15프로 적용

$return = $this->calculation(15);
}

return $return;
}

function calculation($per){

$return = Array();
$per1 = (float)(1.00 + ($per * 0.01));
$per2 = (float)(1.00 - ($per * 0.01));

$return['point_good'] = ceil($this->point_good * ($per1));
$return['point_nogood'] = ceil($return['point_good'] * (-1.1));
$return['point_comment'] = ceil($this->point_comment * ($per1));
$return['point_defalut_full'] = ceil($this->point_defalut_full * ($per1));

$return['set_default'] = ceil($this->set_default * ($per2));//기본 점수 분포를 지정된 퍼센트로 낮춤

$temp = (100 - $return['set_default'] - $this->set_good - $this->set_comment);
$temp2 = ceil($temp / 2);
$temp3 = (2 * $temp2) - $temp;
$add_set_good = $temp2;
$add_set_comment = $temp2 - $temp3;

$return['set_good'] = $this->set_good + $add_set_good;
$return['set_comment'] = $this->set_comment + $add_set_comment;

return $return;
}
}

?>

_______________________________________________________________________

이전에 제가 올린 팁과 다른점은
클래스로 만들어 사용하기 쉽다는 점과
기간이 오래된 게시물일 경우
히트수 비율이나 추천 비율이 떨어질걸 감안하여
기간에 따라 다른 점수분포를 가지도록 하였습니다.

사용법은 해당 클래스를 해당 페이지에서 인클루드 한다음
객체를 생성합니다.

//인기도 관련 클래스 인클루드
include_once("$g4[path]/lib/favor_point.lib.php");
$favor_point = new favor_point(200, 100, 2000, 70, 15, 15);

이런식으로........
이것은 페이지에서 딱 한번 실행하면 됩니다.
$favor_point = new favor_point(200, 100, 2000, 70, 15, 15);
여기의 수치에 대한 것은
200 은 추천 하나에 대한 점수입니다.
100 은 코멘트 하나에 대한 점수입니다.
2000 은 기본 점수 만점입니다.
70은 점수 분포중 기본점수 입니다.
15는 점수 분포중 추천점수 입니다.
15는 점수 분포중 코멘트점수 입니다.
마지막 세개의 인자는 합이 100 이어야 하고 모두 양의 정수만 사용해야 합니다.

글작성일에 따라
30일 이하는 그대로
90일 이하는 5프로 변동
180일 이하는 10프로 변동
그이상은 15프로 변동


출력해줄 곳에서는

get_favor_point($list[$i]['wr_good'], $list[$i]['wr_nogood'], $list[$i]['wr_comment'], $list[$i]['wr_hit'], $list[$i]['wr_datetime']); ?>

%' style='margin: 2 0 2 0;'>




% height=13 background='/img/star_s.gif'>




이런식으로 사용하면 됩니다.


get_favor_point($list[$i]['wr_good'], $list[$i]['wr_nogood'], $list[$i]['wr_comment'], $list[$i]['wr_hit'], $list[$i]['wr_datetime']); ?>
이것에 대한 설명은
인자가 순서대로 추천수, 비추천수, 코멘트수, 히트수, 작성일 입니다.
작성일은 date 형식이나 datetime형식이나 관계없습니다.
목록
댓글 6
댓글 새로고침
목록
로그인 후 더욱 많은 기능을 이용하세요!아이보스 로그인