git subtree merge를 위한 g4s_branch 및 서브트리 생성

This commit is contained in:
chicpro
2013-04-26 15:21:39 +09:00
parent f7247c0050
commit da91511e5f
711 changed files with 94885 additions and 0 deletions

1980
g4s/lib/common.lib.php Normal file

File diff suppressed because it is too large Load Diff

30
g4s/lib/connect.lib.php Normal file
View File

@ -0,0 +1,30 @@
<?php
if (!defined('_GNUBOARD_')) exit;
// 현재 접속자수 출력
function connect($skin_dir='')
{
global $config, $g4;
// 회원, 방문객 카운트
$sql = " select sum(IF(mb_id<>'',1,0)) as mb_cnt, count(*) as total_cnt from {$g4['login_table']} where mb_id <> '{$config['cf_admin']}' ";
$row = sql_fetch($sql);
if (!$skin_dir)
$skin_dir = $config['cf_connect_skin'];
if(G4_IS_MOBILE) {
$connect_skin_path = G4_MOBILE_PATH.'/'.G4_SKIN_DIR.'/connect/'.$skin_dir;
$connect_skin_url = G4_MOBILE_URL.'/'.G4_SKIN_DIR.'/connect/'.$skin_dir;
} else {
$connect_skin_path = G4_SKIN_PATH.'/connect/'.$skin_dir;
$connect_skin_url = G4_SKIN_URL.'/connect/'.$skin_dir;
}
ob_start();
include_once ($connect_skin_path.'/connect.skin.php');
$content = ob_get_contents();
ob_end_clean();
return $content;
}
?>

57
g4s/lib/latest.lib.php Normal file
View File

@ -0,0 +1,57 @@
<?php
if (!defined('_GNUBOARD_')) exit;
// 최신글 추출
function latest($skin_dir='', $bo_table, $rows=10, $subject_len=40)
{
global $g4;
static $css = array();
if (!$skin_dir) $skin_dir = 'basic';
if(G4_IS_MOBILE) {
$latest_skin_path = G4_MOBILE_PATH.'/'.G4_SKIN_DIR.'/latest/'.$skin_dir;
$latest_skin_url = G4_MOBILE_URL.'/'.G4_SKIN_DIR.'/latest/'.$skin_dir;
} else {
$latest_skin_path = G4_SKIN_PATH.'/latest/'.$skin_dir;
$latest_skin_url = G4_SKIN_URL.'/latest/'.$skin_dir;
}
$cache_file = G4_DATA_PATH."/cache/latest-{$bo_table}-{$skin_dir}-{$rows}-{$subject_len}.php";
if (!G4_USE_CACHE || !file_exists($cache_file)) {
$list = array();
$sql = " select * from {$g4['board_table']} where bo_table = '{$bo_table}' ";
$board = sql_fetch($sql);
$tmp_write_table = $g4['write_prefix'] . $bo_table; // 게시판 테이블 전체이름
$sql = " select * from {$tmp_write_table} where wr_is_comment = 0 order by wr_num limit 0, {$rows} ";
$result = sql_query($sql);
for ($i=0; $row = sql_fetch_array($result); $i++) {
$list[$i] = get_list($row, $board, $latest_skin_url, $subject_len);
}
$handle = fopen($cache_file, 'w');
$cache_content = "<?php\nif (!defined('_GNUBOARD_')) exit;\n\$bo_subject=\"".get_text($board['bo_subject'])."\";\n\$list=".var_export($list, true)."?>";
fwrite($handle, $cache_content);
fclose($handle);
}
include_once($cache_file);
/*
// 같은 스킨은 .css 를 한번만 호출한다.
if (!in_array($skin_dir, $css) && is_file($latest_skin_path.'/style.css')) {
echo '<link rel="stylesheet" href="'.$latest_skin_url.'/style.css">';
$css[] = $skin_dir;
}
*/
ob_start();
include $latest_skin_path.'/latest.skin.php';
$content = ob_get_contents();
ob_end_clean();
return $content;
}
?>

170
g4s/lib/mailer.lib.php Normal file
View File

@ -0,0 +1,170 @@
<?php
if (!defined('_GNUBOARD_')) exit;
// 메일 보내기 (파일 여러개 첨부 가능)
// type : text=0, html=1, text+html=2
function mailer($fname, $fmail, $to, $subject, $content, $type=0, $file='', $cc='', $bcc='')
{
global $config;
global $g4;
// 메일발송 사용을 하지 않는다면
if (!$config['cf_email_use']) return;
$fname = "=?utf-8?B?" . base64_encode($fname) . "?=";
$subject = "=?utf-8?B?" . base64_encode($subject) . "?=";
$header = "Return-Path: <$fmail>\n";
$header .= "From: $fname <$fmail>\n";
$header .= "Reply-To: <$fmail>\n";
if ($cc) $header .= "Cc: $cc\n";
if ($bcc) $header .= "Bcc: $bcc\n";
$header .= "MIME-Version: 1.0\n";
$header .= "X-Mailer: {$_SERVER['SERVER_ADDR']} : {$_SERVER['REMOTE_ADDR']} : ".G4_URL." : {$_SERVER['PHP_SELF']} : {$_SERVER['HTTP_REFERER']} \n";
if ($file != '') {
$boundary = uniqid('http://sir.co.kr/');
$header .= "Content-type: MULTIPART/MIXED; BOUNDARY=\"$boundary\"\n\n";
$header .= "--$boundary\n";
}
if ($type) {
$header .= "Content-Type: TEXT/HTML; charset=utf-8\n";
if ($type == 2)
$content = nl2br($content);
} else {
$header .= "Content-Type: TEXT/PLAIN; charset=utf-8\n";
$content = stripslashes($content);
}
$header .= "Content-Transfer-Encoding: BASE64\n\n";
$header .= chunk_split(base64_encode($content)) . "\n";
if ($file != '') {
foreach ($file as $f) {
$header .= "\n--$boundary\n";
$header .= "Content-Type: APPLICATION/OCTET-STREAM; name=\"{$f['name']}\"\n";
$header .= "Content-Transfer-Encoding: BASE64\n";
$header .= "Content-Disposition: inline; filename=\"{$f['name']}\"\n";
$header .= "\n";
$header .= chunk_split(base64_encode($f['data']));
$header .= "\n";
}
$header .= "--$boundary--\n";
}
@mail($to, $subject, "", $header);
}
// 파일 첨부시
/*
$fp = fopen(__FILE__, "r");
$file[] = array(
"name"=>basename(__FILE__),
"data"=>fread($fp, filesize(__FILE__)));
fclose($fp);
*/
// 파일을 첨부함
function attach_file($filename, $file)
{
$fp = fopen($file, "r");
$tmpfile = array(
"name" => $filename,
"data" => fread($fp, filesize($file)));
fclose($fp);
return $tmpfile;
}
// 메일 유효성 검사
// core PHP Programming 책 참고
// hanmail.net , hotmail.com , kebi.com 등이 정상적이지 않음으로 사용 불가
function verify_email($address, &$error)
{
global $g4;
$WAIT_SECOND = 3; // ?초 기다림
list($user, $domain) = explode("@", $address);
// 도메인에 메일 교환기가 존재하는지 검사
if (checkdnsrr($domain, "MX")) {
// 메일 교환기 레코드들을 얻는다
if (!getmxrr($domain, $mxhost, $mxweight)) {
$error = '메일 교환기를 회수할 수 없음';
return false;
}
} else {
// 메일 교환기가 없으면, 도메인 자체가 편지를 받는 것으로 간주
$mxhost[] = $domain;
$mxweight[] = 1;
}
// 메일 교환기 호스트의 배열을 만든다.
for ($i=0; $i<count($mxhost); $i++)
$weighted_host[($mxweight[$i])] = $mxhost[$i];
ksort($weighted_host);
// 각 호스트를 검사
foreach($weighted_host as $host) {
// 호스트의 SMTP 포트에 연결
if (!($fp = @fsockopen($host, 25))) continue;
// 220 메세지들은 건너뜀
// 3초가 지나도 응답이 없으면 포기
socket_set_blocking($fp, false);
$stoptime = G4_SERVER_TIME + $WAIT_SECOND;
$gotresponse = false;
while (true) {
// 메일서버로부터 한줄 얻음
$line = fgets($fp, 1024);
if (substr($line, 0, 3) == '220') {
// 타이머를 초기화
$stoptime = G4_SERVER_TIME + $WAIT_SECOND;
$gotresponse = true;
} else if ($line == '' && $gotresponse)
break;
else if (G4_SERVER_TIME > $stoptime)
break;
}
// 이 호스트는 응답이 없음. 다음 호스트로 넘어간다
if (!$gotresponse) continue;
socket_set_blocking($fp, true);
// SMTP 서버와의 대화를 시작
fputs($fp, "HELO {$_SERVER['SERVER_NAME']}\r\n");
echo "HELO {$_SERVER['SERVER_NAME']}\r\n";
fgets($fp, 1024);
// From을 설정
fputs($fp, "MAIL FROM: <info@$domain>\r\n");
echo "MAIL FROM: <info@$domain>\r\n";
fgets($fp, 1024);
// 주소를 시도
fputs($fp, "RCPT TO: <$address>\r\n");
echo "RCPT TO: <$address>\r\n";
$line = fgets($fp, 1024);
// 연결을 닫음
fputs($fp, "QUIT\r\n");
fclose($fp);
if (substr($line, 0, 3) != '250') {
// SMTP 서버가 이 주소를 인식하지 못하므로 잘못된 주소임
$error = $line;
return false;
} else
// 주소를 인식했음
return true;
}
$error = '메일 교환기에 도달하지 못하였습니다.';
return false;
}
?>

145
g4s/lib/mobile.lib.php Normal file
View File

@ -0,0 +1,145 @@
<?php
if (!defined('_GNUBOARD_')) exit;
// 원본 이미지를 넘기면 비율에 따라 썸네일 이미지를 생성함
function mobile_create_thumb($srcImg, $width, $thumb)
{
$size = @getimagesize($srcImg);
if ($size[2] == 1)
$source = @imagecreatefromgif($srcImg);
else if ($size[2] == 2)
$source = @imagecreatefromjpeg($srcImg);
else if ($size[2] == 3)
$source = @imagecreatefrompng($srcImg);
else
return "";
if (!$source)
return "";
if ($size[0] < $width) {
$width = $size[0];
$height = $size[1];
}
else {
$rate = $width / $size[0];
$height = (int)($size[1] * $rate);
}
$target = @imagecreatetruecolor($width, $height);
$bgcolor = @imagecolorallocate($target, 255, 255, 255); // 썸네일 배경
imagefilledrectangle($target, 0, 0, $width, $height, $bgcolor);
imagecopyresampled($source, $source, 0, 0, 0, 0, $width, $height, $size[0], $size[1]);
imagecopy($target, $source, 0, 0, 0, 0, $size[0], $size[1]);
imagejpeg($target, $thumb, 100);
chmod($thumb, 0606); // 추후 삭제를 위하여 파일모드 변경
return $thumb;
}
function mobile_thumb($matches)
{
global $is_admin;
global $g4, $bo_table, $wr_id;
$width = 300; // (소스이미지 width pixel)
//if ($is_admin) print_r2($matches);
if ($is_admin) {
foreach ($matches as $img) {
echo "<p>";
preg_match("/src=[\"\']?([^\"\'\s>]+)/i", $img, $m);
$src = trim($m[1]);
//echo $src;
// 상대경로(..)로 시작되면 sir.co.kr 도메인으로 여긴다.
$src = preg_replace("/^\.\.\//", "http://m.sir.co.kr/", $src);
$absolute = preg_replace("/^http\:\/\/(www\.)?sir\.co\.kr\/(.*)$/", "/home/sir/$2", $src);
$thumb_dir = G4_DATA_PATH.'/thumb/'.$bo_table;
if (!is_dir($thumb_dir)) {
@mkdir($thumb_dir, 0707);
@chmod($thumb_dir, 0707);
}
$result = true;
if (preg_match("/\.(jpe?g|png)$/i", $src)) {
// 유일한 파일명을 만든다.
$src_md5 = md5($src.$width);
$thumb = "$thumb_dir/{$wr_id}-{$src_md5}";
if (!file_exists($thumb)) {
$result = mobile_create_thumb($src, $width, $thumb);
}
}
else {
$thumb = $src;
}
if ($result) {
$size = @getimagesize($absolute);
if ($size[2] == IMAGETYPE_GIF)
$w = ($size[0] < $width) ? $size[0] : $width;
else
$w = ($size[0] < $width) ? $size[0] : "100%";
return "<img src='$thumb' width='$w' />";
}
}
} else {
foreach ($matches as $img) {
preg_match("/src=[\"\']?([^\"\'\s>]+)/i", $img, $m);
$result = true;
$src = trim($m[1]);
//if ($is_admin) echo $src."<br>";
if (preg_match("/\.(jpe?g|png)$/i", $src)) {
// 상대경로(..)로 시작되면 도메인으로 여긴다.
$src = preg_replace("/^\.\.\//", 'http://'.$_SERVER['SERVER_NAME'].'/', $src);
// 유일한 파일명을 만든다.
$src_md5 = md5($src.$width);
$thumb = G4_DATA_PATH.'/thumb/'.$bo_table.'-'.$wr_id.'-'.$src_md5;
if (!file_exists($thumb)) {
$result = mobile_create_thumb($src, $width, $thumb);
}
}
else {
$thumb = $src;
}
if ($result) {
//if ($is_admin) { $begin_time = get_microtime(); }
//echo $thumb;
$size = @getimagesize($thumb);
//if ($is_admin) print_r2($size);
if ($size[2] == IMAGETYPE_GIF)
$w = ($size[0] < $width) ? $size[0] : $width;
else
$w = ($size[0] < $width) ? $size[0] : "100%";
//if ($is_admin) { echo "<p>time : "; echo get_microtime() - $begin_time; }
return "<img src='$thumb' width='$w' />";
}
}
}
}
function mobile_embed($matches)
{
foreach ($matches as $embed) {
//$embed = preg_replace("#height\=\d+#i", "", $embed);
//$embed = preg_replace("#width\=\d+#i", "", $embed);
return $embed;
}
}
?>

72
g4s/lib/outlogin.lib.php Normal file
View File

@ -0,0 +1,72 @@
<?php
if (!defined('_GNUBOARD_')) exit;
// 외부로그인
function outlogin($skin_dir='basic')
{
global $config, $member, $g4, $urlencode, $is_admin, $is_member;
if (array_key_exists('mb_nick', $member)) {
$nick = cut_str($member['mb_nick'], $config['cf_cut_name']);
}
if (array_key_exists('mb_point', $member)) {
$point = number_format($member['mb_point']);
}
if (G4_IS_MOBILE) {
$outlogin_skin_path = G4_MOBILE_PATH.'/'.G4_SKIN_DIR.'/outlogin/'.$skin_dir;
$outlogin_skin_url = G4_MOBILE_URL.'/'.G4_SKIN_DIR.'/outlogin/'.$skin_dir;
} else {
$outlogin_skin_path = G4_SKIN_PATH.'/outlogin/'.$skin_dir;
$outlogin_skin_url = G4_SKIN_URL.'/outlogin/'.$skin_dir;
}
// 읽지 않은 쪽지가 있다면
if ($is_member) {
$sql = " select count(*) as cnt from {$g4['memo_table']} where me_recv_mb_id = '{$member['mb_id']}' and me_read_datetime = '0000-00-00 00:00:00' ";
$row = sql_fetch($sql);
$memo_not_read = $row['cnt'];
$is_auth = false;
$sql = " select count(*) as cnt from {$g4['auth_table']} where mb_id = '{$member['mb_id']}' ";
$row = sql_fetch($sql);
if ($row['cnt'])
$is_auth = true;
}
if (G4_HTTPS_DOMAIN) {
$outlogin_url = $_GET['url'];
if ($outlogin_url) {
if (preg_match("/^\.\.\//", $outlogin_url)) {
$outlogin_url = urlencode(G4_URL."/".preg_replace("/^\.\.\//", "", $outlogin_url));
}
else {
$purl = parse_url(G4_URL);
if ($purl['path']) {
$path = urlencode($purl['path']);
$urlencode = preg_replace("/".$path."/", "", $urlencode);
}
$outlogin_url = $urlencode;
}
}
else {
$outlogin_url = G4_URL;
}
}
else {
$outlogin_url = $urlencode;
}
$outlogin_action_url = G4_HTTPS_BBS_URL.'/login_check.php';
ob_start();
if ($is_member)
include_once ($outlogin_skin_path.'/outlogin.skin.2.php');
else // 로그인 전이라면
include_once ($outlogin_skin_path.'/outlogin.skin.1.php');
$content = ob_get_contents();
ob_end_clean();
return $content;
}
?>

34
g4s/lib/poll.lib.php Normal file
View File

@ -0,0 +1,34 @@
<?php
if (!defined('_GNUBOARD_')) exit;
// 설문조사
function poll($skin_dir='basic', $po_id=false)
{
global $config, $member, $g4, $is_admin;
// 투표번호가 넘어오지 않았다면 가장 큰(최근에 등록한) 투표번호를 얻는다
if (!$po_id) {
$row = sql_fetch(" select MAX(po_id) as max_po_id from {$g4['poll_table']} ");
$po_id = $row['max_po_id'];
}
if(!$po_id)
return;
$po = sql_fetch(" select * from {$g4['poll_table']} where po_id = '$po_id' ");
ob_start();
if (G4_IS_MOBILE) {
$poll_skin_path = G4_MOBILE_PATH.'/'.G4_SKIN_DIR.'/poll/'.$skin_dir;
$poll_skin_url = G4_MOBILE_URL.'/'.G4_SKIN_DIR.'/poll/'.$skin_dir;
} else {
$poll_skin_path = G4_SKIN_PATH.'/poll/'.$skin_dir;
$poll_skin_url = G4_SKIN_URL.'/poll/'.$skin_dir;
}
include_once ($poll_skin_path.'/poll.skin.php');
$content = ob_get_contents();
ob_end_clean();
return $content;
}
?>

37
g4s/lib/popular.lib.php Normal file
View File

@ -0,0 +1,37 @@
<?php
if (!defined('_GNUBOARD_')) exit;
// 인기검색어 출력
// $skin_dir : 스킨 디렉토리
// $pop_cnt : 검색어 몇개
// $date_cnt : 몇일 동안
function popular($skin_dir='basic', $pop_cnt=7, $date_cnt=3)
{
global $config, $g4;
if (!$skin_dir) $skin_dir = 'basic';
$date_gap = date("Y-m-d", G4_SERVER_TIME - ($date_cnt * 86400));
$sql = " select pp_word, count(*) as cnt from {$g4['popular_table']} where pp_date between '$date_gap' and '".G4_TIME_YMD."' group by pp_word order by cnt desc, pp_word limit 0, $pop_cnt ";
$result = sql_query($sql);
for ($i=0; $row=sql_fetch_array($result); $i++) {
$list[$i] = $row;
// 스크립트등의 실행금지
$list[$i]['pp_word'] = get_text($list[$i]['pp_word']);
}
ob_start();
if(G4_IS_MOBILE) {
$popular_skin_path = G4_MOBILE_PATH.'/'.G4_SKIN_DIR.'/popular/'.$skin_dir;
$popular_skin_url = G4_MOBILE_URL.'/'.G4_SKIN_DIR.'/popular/'.$skin_dir;
} else {
$popular_skin_path = G4_SKIN_PATH.'/popular/'.$skin_dir;
$popular_skin_url = G4_SKIN_URL.'/popular/'.$skin_dir;
}
include_once ($popular_skin_path.'/popular.skin.php');
$content = ob_get_contents();
ob_end_clean();
return $content;
}
?>

175
g4s/lib/register.lib.php Normal file
View File

@ -0,0 +1,175 @@
<?php
if (!defined('_GNUBOARD_')) exit;
function empty_mb_id($reg_mb_id)
{
if (trim($reg_mb_id)=='')
return "회원아이디를 입력해 주십시오.";
else
return "";
}
function valid_mb_id($reg_mb_id)
{
if (preg_match("/[^0-9a-z_]+/i", $reg_mb_id))
return "회원아이디는 영문자, 숫자, _ 만 입력하세요.";
else
return "";
}
function count_mb_id($reg_mb_id)
{
if (strlen($reg_mb_id) < 3)
return "회원아이디는 최소 3글자 이상 입력하세요.";
else
return "";
}
function exist_mb_id($reg_mb_id)
{
global $g4;
$sql = " select count(*) as cnt from `{$g4['member_table']}` where mb_id = '$reg_mb_id' ";
$row = sql_fetch($sql);
if ($row['cnt'])
return "이미 사용중인 회원아이디 입니다.";
else
return "";
}
function reserve_mb_id($reg_mb_id)
{
global $config;
if (preg_match("/[\,]?{$reg_mb_id}/i", $config['cf_prohibit_id']))
return "이미 예약된 단어로 사용할 수 없는 회원아이디 입니다.";
else
return "";
}
function empty_mb_nick($reg_mb_nick)
{
if (!trim($reg_mb_nick))
return "별명을 입력해 주십시오.";
else
return "";
}
function valid_mb_nick($reg_mb_nick)
{
if (!check_string($reg_mb_nick, G4_HANGUL + G4_ALPHABETIC + G4_NUMERIC))
return "별명은 공백없이 한글, 영문, 숫자만 입력 가능합니다.";
else
return "";
}
function count_mb_nick($reg_mb_nick)
{
if (strlen($reg_mb_nick) < 4)
return "별명은 한글 2글자, 영문 4글자 이상 입력 가능합니다.";
else
return "";
}
function exist_mb_nick($reg_mb_nick, $reg_mb_id)
{
global $g4;
$row = sql_fetch(" select count(*) as cnt from {$g4['member_table']} where mb_nick = '$reg_mb_nick' and mb_id <> '$reg_mb_id' ");
if ($row['cnt'])
return "이미 존재하는 별명입니다.";
else
return "";
}
function reserve_mb_nick($reg_mb_nick)
{
global $config;
if (preg_match("/[\,]?{$reg_mb_nick}/i", $config['cf_prohibit_id']))
return "이미 예약된 단어로 사용할 수 없는 별명 입니다.";
else
return "";
}
function empty_mb_email($reg_mb_email)
{
if (!trim($reg_mb_email))
return "E-mail 주소를 입력해 주십시오.";
else
return "";
}
function valid_mb_email($reg_mb_email)
{
if (!preg_match("/([0-9a-zA-Z_-]+)@([0-9a-zA-Z_-]+)\.([0-9a-zA-Z_-]+)/", $reg_mb_email))
return "E-mail 주소가 형식에 맞지 않습니다.";
else
return "";
}
// 금지 메일 도메인 검사
function prohibit_mb_email($reg_mb_email)
{
global $config;
list($id, $domain) = explode("@", $reg_mb_email);
$email_domains = explode("\n", trim($config['cf_prohibit_email']));
for ($i=0; $i<count($email_domains); $i++) {
if (strtolower($domain) == strtolower($email_domains[$i]))
return "$domain 메일은 사용할 수 없습니다.";
}
return "";
}
function exist_mb_email($reg_mb_email, $reg_mb_id)
{
global $g4;
$row = sql_fetch(" select count(*) as cnt from `{$g4['member_table']}` where mb_email = '$reg_mb_email' and mb_id <> '$reg_mb_id' ");
if ($row['cnt'])
return "이미 사용중인 E-mail 주소입니다.";
else
return "";
}
function empty_mb_name($reg_mb_name)
{
if (!trim($reg_mb_name))
return "이름을 입력해 주십시오.";
else
return "";
}
function valid_mb_name($mb_name)
{
if (!check_string($mb_name, G4_HANGUL))
return "이름은 공백없이 한글만 입력 가능합니다.";
else
return "";
}
function valid_mb_hp($reg_mb_hp)
{
$reg_mb_hp = preg_replace("/[^0-9]/", "", $reg_mb_hp);
if(!$reg_mb_hp)
return "핸드폰번호를 입력해 주십시오.";
else {
if(preg_match("/^01[0-9]{8,9}$/", $reg_mb_hp))
return "";
else
return "휴대폰번호를 올바르게 입력해 주십시오.";
}
}
function exist_mb_hp($reg_mb_hp, $reg_mb_id)
{
global $g4;
$reg_mb_hp = hyphen_hp_number($reg_mb_hp);
$sql = "select count(*) as cnt from {$g4['member_table']} where mb_hp = '$reg_mb_hp' and mb_id <> '$reg_mb_id' ";
$row = sql_fetch($sql);
if($row['cnt'])
return "이미 사용 중인 핸드폰번호입니다.";
else
return "";
}
return;
?>

501
g4s/lib/thumbnail.lib.php Normal file
View File

@ -0,0 +1,501 @@
<?php
if (!defined('_GNUBOARD_')) exit;
@ini_set('memory_limit', '512M');
function it_img_thumb($filename, $filepath, $thumb_width, $thumb_height, $is_create=false)
{
return thumbnail($filename, $filepath, $filepath, $thumb_width, $thumb_height, $is_create);
}
// 게시글리스트 썸네일 생성
function get_list_thumbnail($bo_table, $wr_id, $thumb_width, $thumb_height, $is_create=false, $is_crop=true, $crop_mode='center', $is_sharpen=true, $um_value='80/0.5/3')
{
global $g4, $config;
$filename = $alt = "";
$edt = false;
$sql = " select bf_file, bf_content from {$g4['board_file_table']}
where bo_table = '$bo_table' and wr_id = '$wr_id' and bf_type between '1' and '3' order by bf_no limit 0, 1 ";
$row = sql_fetch($sql);
if($row['bf_file']) {
$filename = $row['bf_file'];
$filepath = G4_DATA_PATH.'/file/'.$bo_table;
$alt = get_text($row['bf_content']);
} else {
$write_table = $g4['write_prefix'].$bo_table;
$sql = " select wr_content from $write_table where wr_id = '$wr_id' ";
$write = sql_fetch($sql);
$matchs = get_editor_image($write['wr_content']);
$edt = true;
for($i=0; $i<count($matchs[1]); $i++)
{
// 이미지 path 구함
$p = parse_url($matchs[1][$i]);
if(strpos($p['path'], "/data/") != 0)
$data_path = preg_replace("/^\/.*\/data/", "/data", $p['path']);
else
$data_path = $p['path'];
$srcfile = G4_PATH.$data_path;
if(preg_match("/\.({$config['cf_image_extension']})$/i", $srcfile) && is_file($srcfile)) {
$size = @getimagesize($srcfile);
if(empty($size))
continue;
$filename = basename($srcfile);
$filepath = dirname($srcfile);
preg_match("/alt=[\"\']?([^\"\']*)[\"\']?/", $matchs[0][$i], $malt);
$alt = get_text($malt[1]);
break;
}
}
}
if(!$filename)
return false;
$tname = thumbnail($filename, $filepath, $filepath, $thumb_width, $thumb_height, $is_create, $is_crop);
if($tname) {
if($edt) {
$src = G4_URL.str_replace($filename, $tname, $data_path);
} else {
$src = G4_DATA_URL.'/file/'.$bo_table.'/'.$tname;
}
} else {
return false;
}
$thumb = array("src"=>$src, "alt"=>$alt);
return $thumb;
}
// 게시글보기 썸네일 생성
function get_view_thumbnail($contents)
{
global $board, $config;
$dvc_width = intval($_COOKIE['device_width']);
if(G4_IS_MOBILE && $dvc_width) {
// 썸네일 width 설정
$thumb_width = 320;
if($dvc_width >= 1000) {
return $contents;
} else if($dvc_width >= 760 && $dvc_width < 1000) {
$thumb_width = 760;
} else if($dvc_width >= 480 && $dvc_width < 760) {
$thumb_width = 480;
}
} else {
$thumb_width = $board['bo_image_width'];
}
// $contents 중 img 태그 추출
$matchs = get_editor_image($contents);
if(empty($matchs))
return $contents;
for($i=0; $i<count($matchs[1]); $i++) {
// 이미지 path 구함
$p = parse_url($matchs[1][$i]);
if(strpos($p['path'], "/data/") != 0)
$data_path = preg_replace("/^\/.*\/data/", "/data", $p['path']);
else
$data_path = $p['path'];
$srcfile = G4_PATH.$data_path;
if(is_file($srcfile)) {
// 썸네일 높이
$size = @getimagesize($srcfile);
if(empty($size))
continue;
// 원본 width가 thumb_width보다 작다면
if($size[0] <= $thumb_width)
continue;
// Animated GIF 체크
$is_animated = false;
if($size[2] == 1) {
$is_animated = is_animated_gif($srcfile);
}
$thumb_height = round(($thumb_width * $size[1]) / $size[0]);
$filename = basename($srcfile);
$filepath = dirname($srcfile);
// 썸네일 생성
if(!$is_animated)
$thumb_file = thumbnail($filename, $filepath, $filepath, $thumb_width, $thumb_height, false);
else
$thumb_file = $filename;
$img_tag = $matchs[0][$i];
preg_match("/alt=[\"\']?([^\"\']*)[\"\']?/", $img_tag, $malt);
$alt = get_text($malt[1]);
$thumb_tag = '<img src="'.G4_URL.str_replace($filename, $thumb_file, $data_path).'" alt="'.$alt.'"/>';
// $img_tag에 editor 경로가 있으면 원본보기 링크 추가
if(strpos($matchs[1][$i], 'data/editor') && preg_match("/\.({$config['cf_image_extension']})$/i", $filename)) {
$imgurl = str_replace(G4_URL, "", $matchs[1][$i]);
$thumb_tag = '<a href="'.G4_BBS_URL.'/view_image.php?fn='.urlencode($imgurl).'" target="_blank" class="view_image">'.$thumb_tag.'</a>';
}
$contents = str_replace($img_tag, $thumb_tag, $contents);
}
}
return $contents;
}
function thumbnail($filename, $source_path, $target_path, $thumb_width, $thumb_height, $is_create, $is_crop=false, $crop_mode='center', $is_sharpen=true, $um_value='80/0.5/3')
{
global $g4;
if(!$thumb_width && !$thumb_height)
return;
$thumb_filename = preg_replace("/\.[^\.]+$/i", "", $filename); // 확장자제거
$thumb_file = "$target_path/thumb-{$thumb_filename}_{$thumb_width}x{$thumb_height}.jpg";
$source_file = "$source_path/$filename";
if(!is_file($source_file)) // 원본 파일이 없다면
return;
$size = @getimagesize($source_file);
if($size[2] < 1 || $size[2] > 3) // gif, jpg, png 에 대해서만 적용
return;
if (!is_dir($target_path)) {
@mkdir($target_path, 0707);
@chmod($target_path, 0707);
}
// Animated GIF는 썸네일 생성하지 않음
if($size[2] == 1) {
if(is_animated_gif($source_file))
return;
}
$thumb_time = @filemtime($thumb_file);
$source_time = @filemtime($source_file);
if (file_exists($thumb_file)) {
if ($is_create == false && $source_time < $thumb_time) {
return basename($thumb_file);
}
}
// 원본파일의 GD 이미지 생성
$src = null;
if ($size[2] == 1) {
$src = imagecreatefromgif($source_file);
} else if ($size[2] == 2) {
$src = imagecreatefromjpeg($source_file);
} else if ($size[2] == 3) {
$src = imagecreatefrompng($source_file);
} else {
return;
}
if(!$src)
return;
$is_large = true;
// width, height 설정
if($thumb_width) {
if(!$thumb_height) {
$thumb_height = round(($thumb_width * $size[1]) / $size[0]);
} else {
if($size[0] < $thumb_width || $size[1] < $thumb_height)
$is_large = false;
}
} else {
if($thumb_height) {
$thumb_width = round(($thumb_height * $size[0]) / $size[1]);
}
}
$dst_x = 0;
$dst_y = 0;
$src_x = 0;
$src_y = 0;
$dst_w = $thumb_width;
$dst_h = $thumb_height;
$src_w = $size[0];
$src_h = $size[1];
$ratio = $dst_h / $dst_w;
if($is_large) {
// 크롭처리
if($is_crop) {
switch($crop_mode)
{
case 'center':
if($size[1] / $size[0] >= $ratio) {
$src_h = round($src_w * $ratio);
$src_y = round(($size[1] - $src_h) / 2);
} else {
$src_w = round($size[1] / $ratio);
$src_x = round(($size[0] - $src_w) / 2);
}
break;
default:
if($size[1] / $size[0] >= $ratio) {
$src_h = round($src_w * $ratio);
} else {
$src_w = round($size[1] / $ratio);
}
break;
}
} else {
if($size[1] / $size[0] >= $ratio) {
$src_h = round($src_w * $ratio);
} else {
$src_w = round($size[1] / $ratio);
}
}
$dst = imagecreatetruecolor($dst_w, $dst_h);
} else {
$dst = imagecreatetruecolor($dst_w, $dst_h);
if($src_w < $dst_w) {
if($src_h >= $dst_h) {
$dst_x = round(($dst_w - $src_w) / 2);
$src_h = $dst_h;
} else {
$dst_x = round(($dst_w - $src_w) / 2);
$dst_y = round(($dst_h - $src_h) / 2);
$dst_w = $src_w;
$dst_h = $src_h;
}
} else {
if($src_h < $dst_h) {
$dst_y = round(($dst_h - $src_h) / 2);
$dst_h = $src_h;
$src_w = $dst_w;
}
}
$bgcolor = imagecolorallocate($dst, 255, 255, 255); // 배경색
imagefill($dst, 0, 0, $bgcolor);
}
imagecopyresampled($dst, $src, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
// sharpen 적용
if($is_sharpen && $is_large) {
$val = explode('/', $um_value);
UnsharpMask($dst, $val[0], $val[1], $val[2]);
}
imagejpeg($dst, $thumb_file, 90);
chmod($thumb_file, 0606); // 추후 삭제를 위하여 파일모드 변경
imagedestroy($src);
imagedestroy($dst);
return basename($thumb_file);
}
function UnsharpMask($img, $amount, $radius, $threshold) {
/*
출처 : http://vikjavev.no/computing/ump.php
New:
- In version 2.1 (February 26 2007) Tom Bishop has done some important speed enhancements.
- From version 2 (July 17 2006) the script uses the imageconvolution function in PHP
version >= 5.1, which improves the performance considerably.
Unsharp masking is a traditional darkroom technique that has proven very suitable for
digital imaging. The principle of unsharp masking is to create a blurred copy of the image
and compare it to the underlying original. The difference in colour values
between the two images is greatest for the pixels near sharp edges. When this
difference is subtracted from the original image, the edges will be
accentuated.
The Amount parameter simply says how much of the effect you want. 100 is 'normal'.
Radius is the radius of the blurring circle of the mask. 'Threshold' is the least
difference in colour values that is allowed between the original and the mask. In practice
this means that low-contrast areas of the picture are left unrendered whereas edges
are treated normally. This is good for pictures of e.g. skin or blue skies.
Any suggenstions for improvement of the algorithm, expecially regarding the speed
and the roundoff errors in the Gaussian blur process, are welcome.
*/
////////////////////////////////////////////////////////////////////////////////////////////////
////
//// Unsharp Mask for PHP - version 2.1.1
////
//// Unsharp mask algorithm by Torstein Hønsi 2003-07.
//// thoensi_at_netcom_dot_no.
//// Please leave this notice.
////
///////////////////////////////////////////////////////////////////////////////////////////////
// $img is an image that is already created within php using
// imgcreatetruecolor. No url! $img must be a truecolor image.
// Attempt to calibrate the parameters to Photoshop:
if ($amount > 500) $amount = 500;
$amount = $amount * 0.016;
if ($radius > 50) $radius = 50;
$radius = $radius * 2;
if ($threshold > 255) $threshold = 255;
$radius = abs(round($radius)); // Only integers make sense.
if ($radius == 0) {
return $img; imagedestroy($img); break; }
$w = imagesx($img); $h = imagesy($img);
$imgCanvas = imagecreatetruecolor($w, $h);
$imgBlur = imagecreatetruecolor($w, $h);
// Gaussian blur matrix:
//
// 1 2 1
// 2 4 2
// 1 2 1
//
//////////////////////////////////////////////////
if (function_exists('imageconvolution')) { // PHP >= 5.1
$matrix = array(
array( 1, 2, 1 ),
array( 2, 4, 2 ),
array( 1, 2, 1 )
);
$divisor = array_sum(array_map('array_sum', $matrix));
$offset = 0;
imagecopy ($imgBlur, $img, 0, 0, 0, 0, $w, $h);
imageconvolution($imgBlur, $matrix, $divisor, $offset);
}
else {
// Move copies of the image around one pixel at the time and merge them with weight
// according to the matrix. The same matrix is simply repeated for higher radii.
for ($i = 0; $i < $radius; $i++) {
imagecopy ($imgBlur, $img, 0, 0, 1, 0, $w - 1, $h); // left
imagecopymerge ($imgBlur, $img, 1, 0, 0, 0, $w, $h, 50); // right
imagecopymerge ($imgBlur, $img, 0, 0, 0, 0, $w, $h, 50); // center
imagecopy ($imgCanvas, $imgBlur, 0, 0, 0, 0, $w, $h);
imagecopymerge ($imgBlur, $imgCanvas, 0, 0, 0, 1, $w, $h - 1, 33.33333 ); // up
imagecopymerge ($imgBlur, $imgCanvas, 0, 1, 0, 0, $w, $h, 25); // down
}
}
if($threshold>0){
// Calculate the difference between the blurred pixels and the original
// and set the pixels
for ($x = 0; $x < $w-1; $x++) { // each row
for ($y = 0; $y < $h; $y++) { // each pixel
$rgbOrig = ImageColorAt($img, $x, $y);
$rOrig = (($rgbOrig >> 16) & 0xFF);
$gOrig = (($rgbOrig >> 8) & 0xFF);
$bOrig = ($rgbOrig & 0xFF);
$rgbBlur = ImageColorAt($imgBlur, $x, $y);
$rBlur = (($rgbBlur >> 16) & 0xFF);
$gBlur = (($rgbBlur >> 8) & 0xFF);
$bBlur = ($rgbBlur & 0xFF);
// When the masked pixels differ less from the original
// than the threshold specifies, they are set to their original value.
$rNew = (abs($rOrig - $rBlur) >= $threshold)
? max(0, min(255, ($amount * ($rOrig - $rBlur)) + $rOrig))
: $rOrig;
$gNew = (abs($gOrig - $gBlur) >= $threshold)
? max(0, min(255, ($amount * ($gOrig - $gBlur)) + $gOrig))
: $gOrig;
$bNew = (abs($bOrig - $bBlur) >= $threshold)
? max(0, min(255, ($amount * ($bOrig - $bBlur)) + $bOrig))
: $bOrig;
if (($rOrig != $rNew) || ($gOrig != $gNew) || ($bOrig != $bNew)) {
$pixCol = ImageColorAllocate($img, $rNew, $gNew, $bNew);
ImageSetPixel($img, $x, $y, $pixCol);
}
}
}
}
else{
for ($x = 0; $x < $w; $x++) { // each row
for ($y = 0; $y < $h; $y++) { // each pixel
$rgbOrig = ImageColorAt($img, $x, $y);
$rOrig = (($rgbOrig >> 16) & 0xFF);
$gOrig = (($rgbOrig >> 8) & 0xFF);
$bOrig = ($rgbOrig & 0xFF);
$rgbBlur = ImageColorAt($imgBlur, $x, $y);
$rBlur = (($rgbBlur >> 16) & 0xFF);
$gBlur = (($rgbBlur >> 8) & 0xFF);
$bBlur = ($rgbBlur & 0xFF);
$rNew = ($amount * ($rOrig - $rBlur)) + $rOrig;
if($rNew>255){$rNew=255;}
elseif($rNew<0){$rNew=0;}
$gNew = ($amount * ($gOrig - $gBlur)) + $gOrig;
if($gNew>255){$gNew=255;}
elseif($gNew<0){$gNew=0;}
$bNew = ($amount * ($bOrig - $bBlur)) + $bOrig;
if($bNew>255){$bNew=255;}
elseif($bNew<0){$bNew=0;}
$rgbNew = ($rNew << 16) + ($gNew <<8) + $bNew;
ImageSetPixel($img, $x, $y, $rgbNew);
}
}
}
imagedestroy($imgCanvas);
imagedestroy($imgBlur);
return true;
}
function is_animated_gif($filename) {
if(!($fh = @fopen($filename, 'rb')))
return false;
$count = 0;
// 출처 : http://www.php.net/manual/en/function.imagecreatefromgif.php#104473
// an animated gif contains multiple "frames", with each frame having a
// header made up of:
// * a static 4-byte sequence (\x00\x21\xF9\x04)
// * 4 variable bytes
// * a static 2-byte sequence (\x00\x2C) (some variants may use \x00\x21 ?)
// We read through the file til we reach the end of the file, or we've found
// at least 2 frame headers
while(!feof($fh) && $count < 2) {
$chunk = fread($fh, 1024 * 100); //read 100kb at a time
$count += preg_match_all('#\x00\x21\xF9\x04.{4}\x00(\x2C|\x21)#s', $chunk, $matches);
}
fclose($fh);
return $count > 1;
}
?>

86
g4s/lib/visit.lib.php Normal file
View File

@ -0,0 +1,86 @@
<?php
if (!defined('_GNUBOARD_')) exit;
// 방문자수 출력
function visit($skin_dir='basic')
{
global $config, $g4;
// visit 배열변수에
// $visit[1] = 오늘
// $visit[2] = 어제
// $visit[3] = 최대
// $visit[4] = 전체
// 숫자가 들어감
preg_match("/오늘:(.*),어제:(.*),최대:(.*),전체:(.*)/", $config['cf_visit'], $visit);
settype($visit[0], "integer");
settype($visit[1], "integer");
settype($visit[2], "integer");
settype($visit[3], "integer");
ob_start();
if(G4_IS_MOBILE) {
$visit_skin_path = G4_MOBILE_PATH.'/'.G4_SKIN_DIR.'/visit/'.$skin_dir;
$visit_skin_url = G4_MOBILE_URL.'/'.G4_SKIN_DIR.'/visit/'.$skin_dir;
} else {
$visit_skin_path = G4_SKIN_PATH.'/visit/'.$skin_dir;
$visit_skin_url = G4_SKIN_URL.'/visit/'.$skin_dir;
}
include_once ($visit_skin_path.'/visit.skin.php');
$content = ob_get_contents();
ob_end_clean();
return $content;
}
// get_browser() 함수는 이미 있음
function get_brow($agent)
{
$agent = strtolower($agent);
//echo $agent; echo "<br/>";
if (preg_match("/msie ([1-9][0-9]\.[0-9]+)/", $agent, $m)) { $s = 'MSIE '.$m[1]; }
else if(preg_match("/firefox/", $agent)) { $s = "FireFox"; }
else if(preg_match("/chrome/", $agent)) { $s = "Chrome"; }
else if(preg_match("/x11/", $agent)) { $s = "Netscape"; }
else if(preg_match("/opera/", $agent)) { $s = "Opera"; }
else if(preg_match("/gec/", $agent)) { $s = "Gecko"; }
else if(preg_match("/bot|slurp/", $agent)) { $s = "Robot"; }
else if(preg_match("/internet explorer/", $agent)) { $s = "IE"; }
else if(preg_match("/mozilla/", $agent)) { $s = "Mozilla"; }
else { $s = "기타"; }
return $s;
}
function get_os($agent)
{
$agent = strtolower($agent);
//echo $agent; echo "<br/>";
if (preg_match("/windows 98/", $agent)) { $s = "98"; }
else if(preg_match("/windows 95/", $agent)) { $s = "95"; }
else if(preg_match("/windows nt 4\.[0-9]*/", $agent)) { $s = "NT"; }
else if(preg_match("/windows nt 5\.0/", $agent)) { $s = "2000"; }
else if(preg_match("/windows nt 5\.1/", $agent)) { $s = "XP"; }
else if(preg_match("/windows nt 5\.2/", $agent)) { $s = "2003"; }
else if(preg_match("/windows nt 6\.0/", $agent)) { $s = "Vista"; }
else if(preg_match("/windows nt 6\.1/", $agent)) { $s = "Windows7"; }
else if(preg_match("/windows nt 6\.2/", $agent)) { $s = "Windows8"; }
else if(preg_match("/windows 9x/", $agent)) { $s = "ME"; }
else if(preg_match("/windows ce/", $agent)) { $s = "CE"; }
else if(preg_match("/mac/", $agent)) { $s = "MAC"; }
else if(preg_match("/linux/", $agent)) { $s = "Linux"; }
else if(preg_match("/sunos/", $agent)) { $s = "sunOS"; }
else if(preg_match("/irix/", $agent)) { $s = "IRIX"; }
else if(preg_match("/phone/", $agent)) { $s = "Phone"; }
else if(preg_match("/bot|slurp/", $agent)) { $s = "Robot"; }
else if(preg_match("/internet explorer/", $agent)) { $s = "IE"; }
else if(preg_match("/mozilla/", $agent)) { $s = "Mozilla"; }
else { $s = "기타"; }
return $s;
}
?>