From 100328a0313e11f1e35e5c81ca29f667d996c0f3 Mon Sep 17 00:00:00 2001 From: thisgun Date: Thu, 4 Oct 2018 10:52:24 +0900 Subject: [PATCH] =?UTF-8?q?=EC=9D=BC=EB=B6=80=20=EB=A6=AC=EB=9D=BC?= =?UTF-8?q?=EC=9D=B4=ED=8A=B8=20=EA=B7=9C=EC=B9=99=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bbs/list.php | 2 +- bbs/view.php | 8 ++--- lib/URI/uri.class.php | 51 +++++++++++++++------------- lib/uri.lib.php | 77 ++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 106 insertions(+), 32 deletions(-) diff --git a/bbs/list.php b/bbs/list.php index 9677f3d32..85f179c7c 100644 --- a/bbs/list.php +++ b/bbs/list.php @@ -231,7 +231,7 @@ if ($is_search_bbs) { $write_href = ''; if ($member['mb_level'] >= $board['bo_write_level']) { - $write_href = get_pretty_url($bo_table, '', '', 'write'); + $write_href = short_url_clean(G5_BBS_URL.'/write.php?bo_table='.$bo_table); } $nobr_begin = $nobr_end = ""; diff --git a/bbs/view.php b/bbs/view.php index de5fd5359..bea95be85 100644 --- a/bbs/view.php +++ b/bbs/view.php @@ -62,22 +62,20 @@ if (isset($next['wr_id']) && $next['wr_id']) { // 쓰기 링크 $write_href = ''; if ($member['mb_level'] >= $board['bo_write_level']) { - $write_href = get_pretty_url($bo_table, '', '', 'write'); + $write_href = short_url_clean(G5_BBS_URL.'/write.php?bo_table='.$bo_table); } // 답변 링크 $reply_href = ''; if ($member['mb_level'] >= $board['bo_reply_level']) { - //$reply_href = './write.php?w=r&bo_table='.$bo_table.'&wr_id='.$wr_id.$qstr; - $reply_href = get_pretty_url($bo_table, '', 'w=r&wr_id='.$wr_id.$qstr, 'write'); + $reply_href = short_url_clean(G5_BBS_URL.'/write.php?w=r&bo_table='.$bo_table.'&wr_id='.$wr_id.$qstr); } // 수정, 삭제 링크 $update_href = $delete_href = ''; // 로그인중이고 자신의 글이라면 또는 관리자라면 비밀번호를 묻지 않고 바로 수정, 삭제 가능 if (($member['mb_id'] && ($member['mb_id'] === $write['mb_id'])) || $is_admin) { - //$update_href = G5_BBS_URL.'/write.php?w=u&bo_table='.$bo_table.'&wr_id='.$wr_id.'&page='.$page.$qstr; - $update_href = get_pretty_url($bo_table, '', 'w=u&wr_id='.$wr_id.'&page='.$page.$qstr, 'write'); + $update_href = short_url_clean(G5_BBS_URL.'/write.php?w=u&bo_table='.$bo_table.'&wr_id='.$wr_id.'&page='.$page.$qstr); set_session('ss_delete_token', $token = uniqid(time())); $delete_href = G5_BBS_URL.'/delete.php?bo_table='.$bo_table.'&wr_id='.$wr_id.'&token='.$token.'&page='.$page.urldecode($qstr); } diff --git a/lib/URI/uri.class.php b/lib/URI/uri.class.php index 254c0e6af..0e45ceea8 100644 --- a/lib/URI/uri.class.php +++ b/lib/URI/uri.class.php @@ -84,49 +84,56 @@ class G5_URI { return $links; } - public function makeClean($stringurl) { + public function makeClean($string_url) { /* convert normal URL query string to clean URL */ - $url=parse_url($stringurl); + $url=parse_url($string_url); $strurl = basename($url['path'],".php"); $qstring = parse_str($url['query'],$vars); while(list($k,$v) = each($vars)) $strurl .= "/".$v; return $strurl; } - public function url_clean($stringurl, $add_qry='') { + public function url_clean($string_url, $add_qry='') { global $config, $g5; - $stringurl = str_replace('&', '&', $stringurl); - $url=parse_url($stringurl); - $strurl = basename($url['path'],".php"); + $string_url = str_replace('&', '&', $string_url); + $url=parse_url($string_url); + $page_name = basename($url['path'],".php"); + + $array_page_names = apply_replace('url_clean_page_names', array('board', 'write')); - if( ! in_array($strurl, array('board', 'view_comment.page')) ){ //게시판이 아니면 리턴 - return $stringurl; + if( strpos($string_url, G5_BBS_URL) === false || ! in_array($page_name, $array_page_names) ){ //게시판이 아니면 리턴 + return $string_url; } $return_url = ''; - $qstring = parse_str($url['query'],$vars); + $qstring = parse_str($url['query'], $vars); // 예) Array ( [scheme] => http [host] => sir.kr [path] => /bbs/board.php [query] => wr_id=1110870&bo_table=cm_free&cpage=1 [fragment] => c_1110946 ) - //while(list($k,$v) = each($vars)) $strurl .= "/".$v; + //while(list($k,$v) = each($vars)) $page_name .= "/".$v; + + if( $page_name === 'write' ){ + $vars['action'] = 'write'; + $allow_param_keys = array('bo_table'=>'', 'action'=>''); + } else { + $allow_param_keys = array('bo_table'=>'', 'wr_id'=>''); + } - $tmp = array('bo_table'=>'', 'wr_id'=>''); $s = array(); - foreach( $tmp as $key=>$v ){ + foreach( $allow_param_keys as $key=>$v ){ if( !isset($vars[$key]) || empty($vars[$key]) ) continue; $add = ''; $s[$key] = $vars[$key]; } - if( $config['cf_bbs_rewrite'] > 1 && (isset($s['wr_id']) && $s['wr_id']) && (isset($s['bo_table']) && $s['bo_table']) ){ + if( $config['cf_bbs_rewrite'] > 1 && $page_name === 'board' && (isset($s['wr_id']) && $s['wr_id']) && (isset($s['bo_table']) && $s['bo_table']) ){ $get_write = get_write( get_write_table_name($s['bo_table']), $s['wr_id'], true); if( $get_write['wr_seo_title'] ){ unset($s['wr_id']); $s['wr_seo_title'] = $get_write['wr_seo_title'].'/'; } - } $fragment = isset($url['fragment']) ? '#'.$url['fragment'] : ''; @@ -134,17 +141,17 @@ class G5_URI { $host = G5_URL; if( isset($url['host']) ){ + + $array_file_paths = apply_replace('url_clean_page_paths', array('/'.G5_BBS_DIR.'/board.php', '/'.G5_BBS_DIR.'/write.php')); + $str_path = isset($url['path']) ? $url['path'] : ''; - $http = 'http://'; - if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']=='on') { - $http = 'https://'; - } - $host = $http.$url['host'].str_replace('/'.G5_BBS_DIR.'/board.php', '', $str_path); + $http = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']=='on') ? 'https://' : 'http://'; + $host = $http.$url['host'].str_replace($array_file_paths, '', $str_path); } $add_param = ''; - if( $result = array_diff_key($vars, $tmp ) ){ + if( $result = array_diff_key($vars, $allow_param_keys ) ){ $add_param = '?'.http_build_query($result,'','&'); } @@ -152,8 +159,8 @@ class G5_URI { $add_param .= $add_param ? '&'.$add_qry : '?'.$add_qry; } - while(list($k,$v) = each($s)) $return_url .= "/".$v; - + while(list($k,$v) = each($s)) $return_url .= '/'.$v; + return $host.$return_url.$add_param.$fragment; } } diff --git a/lib/uri.lib.php b/lib/uri.lib.php index 9da9633cb..cb45212d9 100644 --- a/lib/uri.lib.php +++ b/lib/uri.lib.php @@ -94,12 +94,81 @@ function get_pretty_url($folder, $no='', $query_string='', $action='') return implode('/', $segments).$add_query; } -function short_url_clean($url, $add_qry=''){ - if( class_exists('G5_URI') ){ - return G5_URI::getInstance()->url_clean($url, $add_qry); +function short_url_clean($string_url, $add_qry=''){ + + global $config, $g5; + + if( isset($config['cf_bbs_rewrite']) && $config['cf_bbs_rewrite'] ){ + + $string_url = str_replace('&', '&', $string_url); + $url=parse_url($string_url); + $page_name = basename($url['path'],".php"); + + $array_page_names = apply_replace('url_clean_page_names', array('board', 'write')); + + if( strpos($string_url, G5_BBS_URL) === false || ! in_array($page_name, $array_page_names) ){ //게시판이 아니면 리턴 + return $string_url; + } + + $return_url = ''; + $qstring = parse_str($url['query'], $vars); + + // 예) Array ( [scheme] => http [host] => sir.kr [path] => /bbs/board.php [query] => wr_id=1110870&bo_table=cm_free&cpage=1 [fragment] => c_1110946 ) + //while(list($k,$v) = each($vars)) $page_name .= "/".$v; + + if( $page_name === 'write' ){ + $vars['action'] = 'write'; + $allow_param_keys = array('bo_table'=>'', 'action'=>''); + } else { + $allow_param_keys = array('bo_table'=>'', 'wr_id'=>''); + } + + $s = array(); + + foreach( $allow_param_keys as $key=>$v ){ + if( !isset($vars[$key]) || empty($vars[$key]) ) continue; + $add = ''; + $s[$key] = $vars[$key]; + } + + if( $config['cf_bbs_rewrite'] > 1 && $page_name === 'board' && (isset($s['wr_id']) && $s['wr_id']) && (isset($s['bo_table']) && $s['bo_table']) ){ + $get_write = get_write( get_write_table_name($s['bo_table']), $s['wr_id'], true); + + if( $get_write['wr_seo_title'] ){ + unset($s['wr_id']); + $s['wr_seo_title'] = $get_write['wr_seo_title'].'/'; + } + } + + $fragment = isset($url['fragment']) ? '#'.$url['fragment'] : ''; + + $host = G5_URL; + + if( isset($url['host']) ){ + + $array_file_paths = apply_replace('url_clean_page_paths', array('/'.G5_BBS_DIR.'/board.php', '/'.G5_BBS_DIR.'/write.php')); + + $str_path = isset($url['path']) ? $url['path'] : ''; + $http = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']=='on') ? 'https://' : 'http://'; + $host = $http.$url['host'].str_replace($array_file_paths, '', $str_path); + } + + $add_param = ''; + + if( $result = array_diff_key($vars, $allow_param_keys ) ){ + $add_param = '?'.http_build_query($result,'','&'); + } + + if( $add_qry ){ + $add_param .= $add_param ? '&'.$add_qry : '?'.$add_qry; + } + + while(list($k,$v) = each($s)) $return_url .= '/'.$v; + + return $host.$return_url.$add_param.$fragment; } - return $url; + return $string_url; } function correct_goto_url($url){