From 354bf541f2b6adc7343b82f42ab33d7371ef72e2 Mon Sep 17 00:00:00 2001 From: zero Date: Wed, 3 Jun 2009 04:52:29 +0000 Subject: [PATCH] =?UTF-8?q?1.=20Context::getUrl()=20=ED=95=A8=EC=88=98=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=EC=8B=9C=20=ED=8A=B9=EB=B3=84=ED=95=9C=20?= =?UTF-8?q?=EA=B2=BD=EC=9A=B0(SSL=20=EC=A0=84=ED=99=98)=EC=9D=84=20?= =?UTF-8?q?=EC=A0=9C=EC=99=B8=ED=95=98=EA=B3=A0=EB=8A=94=20http://...=20?= =?UTF-8?q?=EA=B2=BD=EB=A1=9C=EA=B0=80=20=EC=95=84=EB=8B=8C=20/=20?= =?UTF-8?q?=EB=A1=9C=20=EC=8B=9C=EC=9E=91=ED=95=98=EB=8A=94=20=EA=B2=BD?= =?UTF-8?q?=EB=A1=9C=EB=A1=9C=20url=EC=9D=84=20=EC=83=9D=EC=84=B1=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD=202.=2080=EB=B2=88=20?= =?UTF-8?q?=ED=8F=AC=ED=8A=B8=EA=B0=80=20=EC=95=84=EB=8B=8C=20=EA=B2=BD?= =?UTF-8?q?=EC=9A=B0=20Context::getRequestUri()=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=ED=8F=AC=ED=8A=B8=EB=B2=88=ED=98=B8=EB=A5=BC=20=EC=A0=9C?= =?UTF-8?q?=EB=8C=80=EB=A1=9C=20=EC=9D=B8=EC=8B=9D=ED=95=98=EC=A7=80=20?= =?UTF-8?q?=EB=AA=BB=ED=95=98=EB=8A=94=20=EB=AC=B8=EC=A0=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=203.=20=EC=B2=98=EC=9D=8C=20=EC=84=A4=EC=B9=98?= =?UTF-8?q?=EC=8B=9C=EC=97=90=20default=20site=20info=EB=A5=BC=20=EB=93=B1?= =?UTF-8?q?=EB=A1=9D=ED=95=98=EA=B3=A0=20=EA=B8=B0=EB=B3=B8=20=EA=B2=8C?= =?UTF-8?q?=EC=8B=9C=ED=8C=90=EC=9D=84=20=EC=A0=95=EC=83=81=EC=A0=81?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EB=A7=8C=EB=93=A4=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://xe-core.googlecode.com/svn/sandbox@6464 201d5d3c-b55e-5fd7-737f-ddc643e51545 --- classes/context/Context.class.php | 170 ++++++++++++++++-------------- modules/board/board.class.php | 15 +-- modules/module/module.class.php | 18 +++- 3 files changed, 112 insertions(+), 91 deletions(-) diff --git a/classes/context/Context.class.php b/classes/context/Context.class.php index c8e2cf223..e6dbdd286 100644 --- a/classes/context/Context.class.php +++ b/classes/context/Context.class.php @@ -771,128 +771,138 @@ **/ function _getUrl($num_args=0, $args_list=array(), $domain = null) { static $site_module_info = null; - if($domain) $is_site = true; - else $is_site = false; - if(is_null($site_module_info)) { - $site_module_info = Context::get('site_module_info'); - } + // 가상 사이트 정보를 구함 + if(is_null($site_module_info)) $site_module_info = Context::get('site_module_info'); - // SiteID 요청시 전처리 + // SiteID 요청시 전처리 ($domain이 vid 형식일 경우 $domain값을 없애고 vid로 처리하도록 함) if($domain && isSiteID($domain)) { $vid = $domain; $domain = ''; } - // SiteID가 요청되지 않았다면 현재 site_module_info에서 SiteID 판별 - if(!$vid && $site_module_info->domain && isSiteID($site_module_info->domain)) { - $vid = $site_module_info->domain; + // $domain, $vid값이 없을 경우(= 현재 사이트 정보를 이용함) + if(!$domain && !$vid) { + if($site_module_info->domain && isSiteID($site_module_info->domain)) $vid = $site_module_info->domain; + else $domain = $site_module_info->domain; } - if(!$domain) { - if($site_module_info->domain && !isSiteID($site_module_info->domain)) $domain = $site_module_info->domain; + // $domain값이 있을 경우 현재 요청된 도메인과 비교해서 동일할 경우 제거 그렇지 않으면 http 프로토콜을 제거하고 제일 뒤에 / 를 붙임 + if($domain) { + $domain_info = parse_url($domain); + $current_info = parse_url($_SERVER['HTTP_HOST'].getScriptPath()); + if($domain_info['host'].$domain_info['path']==$current_info['host'].$current_info['path']) unset($domain); else { - if($this->db_info->default_url) $domain = $this->db_info->default_url; - else if(!$domain) $domain = Context::getRequestUri(); + $domain = preg_replace('/^(http|https):\/\//i','', trim($domain)); + if(substr($domain,-1) != '/') $domain .= '/'; } } - $domain = preg_replace('/^(http|https):\/\//i','', trim($domain)); - if(substr($domain,-1) != '/') $domain .= '/'; + // 변수 정리 + $get_vars = null; + + // GET 변수가 없거나 변수 초기화 지정이 되었을 경우 if(!$this->get_vars || $args_list[0]=='') { - $get_vars = null; - if(is_array($args_list) && $args_list[0]=='') { - array_shift($args_list); - $num_args = count($args_list); - } + // 요청받은 변수가 있고 첫번째 인자가 '' 라서 초기화를 해야 할 경우 요청받은 변수를 정리 + if(is_array($args_list) && $args_list[0]=='') array_shift($args_list); + // 초기화를 원하지 않을 경우 GET 변수를 배열로 처리 } else { $get_vars = get_object_vars($this->get_vars); } - for($i=0;$i<$num_args;$i=$i+2) { + // 새로 꾸미기를 원하는 변수를 정리 + for($i=0,$c=count($args_list);$i<$c;$i=$i+2) { $key = $args_list[$i]; $val = trim($args_list[$i+1]); + + // 값이 없으면 GET변수에서 해당 키를 제거 if(!isset($val)) { unset($get_vars[$key]); continue; } + // 새로운 변수를 정리 $get_vars[$key] = $val; } - unset($get_vars['vid']); + + // 변수중 vid, rnd값 제거 unset($get_vars['rnd']); - if(isset($get_vars['page'])&&$get_vars['page']<2) unset($get_vars['page']); + if($vid) $get_vars['vid'] = $vid; + else unset($get_vars['vid']); - /* member module중의 쪽지함/친구 관리 기능이 communication 모듈로 이전하여 하위 호환성을 위한 act값 변경 */ - if($get_vars['act'] == 'dispMemberFriend') $get_vars['act'] = 'dispCommunicationFriend'; - elseif($get_vars['act'] == 'dispMemberMessages') $get_vars['act'] = 'dispCommunicationMessages'; - /* 기존의 action의 값이 바뀌어서 이를 강제 변경 */ - elseif($get_vars['act'] == 'dispDocumentAdminManageDocument') $get_vars['act'] = 'dispDocumentManageDocument'; - elseif($get_vars['act'] == 'dispModuleAdminSelectList') $get_vars['act'] = 'dispModuleSelectList'; - - if($get_vars['act'] && $this->isExistsSSLAction($get_vars['act'])) $path = $this->getRequestUri(ENFORCE_SSL, $domain); - else $path = $this->getRequestUri(RELEASE_SSL, $domain); - - $var_count = count($get_vars); - if(!$var_count) { - if(!$is_site) return $path; - if($vid) { - if($this->allow_rewrite) $path .= $vid; - else $path .= '?vid='.$vid; - } - return $path; - } - - // rewrite모듈을 사용할때 getUrl()을 이용한 url 생성 - // 2009. 4. 8 mid, document_srl, site id, entry 를 제외하고는 rewrite rule 사용하지 않도록 변경 - if($this->allow_rewrite) { - if(count($get_vars)) foreach($get_vars as $key => $value) if(!isset($value) || $value === '') unset($get_vars[$key]); - - $var_keys = array_keys($get_vars); - asort($var_keys); - $target = implode('.',$var_keys); - - if($vid) $rpath = $path.$vid .'/'; - else $rpath = $path; - - switch($target) { - case 'mid' : - return $rpath.$get_vars['mid']; - case 'document_srl' : - return $rpath.$get_vars['document_srl']; - case 'document_srl.mid' : - return sprintf('%s%s/%s',$rpath,$get_vars['mid'],$get_vars['document_srl']); - case 'entry.mid' : - return sprintf('%s%s/entry/%s',$rpath,$get_vars['mid'],$get_vars['entry']); - case 'act.document_srl.key' : - if($get_vars['act']=='trackback') return sprintf('%s%s/%s/%s', $rpath,$get_vars['document_srl'],$get_vars['key'],$get_vars['act']); - break; - + if(count($get_vars)) { + foreach($get_vars as $key => $val) { + if(!trim($val)) unset($get_vars[$key]); } } - // rewrite 모듈을 사용하지 않고 인자의 값이 2개 이상이거나 rewrite모듈을 위한 인자로 적당하지 않을 경우 - if($vid) $url = 'vid='.$vid; - foreach($get_vars as $key => $val) { - if(!isset($val)) continue; - if(is_array($val) && count($val)) { - foreach($val as $k => $v) { - $url .= ($url?'&':'').$key.'['.$k.']='.urlencode($v); + // action명이 변경되었던 것에 대해 호환성을 유지하기 위한 강제 값 변경 + switch($get_vars['act']) { + case 'dispMemberFriend' : $get_vars['act'] = 'dispCommunicationFriend'; break; + case 'dispMemberMessages' : $get_vars['act'] = 'dispCommunicationMessages'; break; + case 'dispDocumentAdminManageDocument' : $get_vars['act'] = 'dispDocumentManageDocument'; break; + case 'dispModuleAdminSelectList' : $get_vars['act'] = 'dispModuleSelectList'; break; + } + + // URL 구성 + $query = null; + if($var_count = count($get_vars)) { + // rewrite mod 사용시 + if($this->allow_rewrite) { + $var_keys = array_keys($get_vars); + asort($var_keys); + $target = implode('.',$var_keys); + switch($target) { + case 'mid' : $query = $get_vars['mid']; break; + case 'document_srl' : $query = $get_vars['document_srl']; break; + case 'document_srl.mid' : $query = $get_vars['mid'].'/'.$get_vars['document_srl']; break; + case 'entry.mid' : $query = $get_vars['mid'].'/'.$get_vars['entry']; break; + case 'act.document_srl.key' : $query = $get_vars['act']=='trackback'?$get_vars['document_srl'].'/'.$get_vars['key'].'/'.$get_vars['act']:''; break; + case 'mid.vid' : $query = $get_vars['vid'].'/'.$get_vars['mid']; break; + case 'document_srl.vid' : $query = $get_vars['vid'].'/'.$get_vars['document_srl']; break; + case 'document_srl.mid.vid' : $query = $get_vars['vid'].'/'.$get_vars['mid'].'/'.$get_vars['document_srl']; break; + case 'entry.mid.vid' : $query = $get_vars['vid'].'/'.$get_vars['mid'].'/'.$get_vars['entry']; break; + case 'act.document_srl.key.vid' : $query = $get_vars['vid'].'/'.$get_vars['act']=='trackback'?$get_vars['document_srl'].'/'.$get_vars['key'].'/'.$get_vars['act']:''; break; } - } else { - $url .= ($url?'&':'').$key.'='.urlencode($val); + } + + // rewrite mod 미사용 또는 query값이 생성되지 않았을 경우 get argument로 생성 + if(!$query) { + foreach($get_vars as $key => $val) { + if(is_array($val) && count($val)) { + foreach($val as $k => $v) $query .= ($query?'&':'').$key.'['.$k.']='.urlencode($v); + } else { + $query .= ($query?'&':'').$key.'='.urlencode($val); + } + } + if($query) $query = '?'.$query; } } - return $path.'?'.htmlspecialchars($url); + + // XE가 설치된 절대 경로를 구해서 query를 완성 + $query = getScriptPath().$query; + + // 항상 SSL을 이용하고 현재 SSL이 아닌 경우 https에 대한 prefix를 붙임 + if(Context::get('_use_ssl')=='always') { + if($_SERVER['HTTPS']!='on') $query = substr($this->getRequestUri(ENFORCE_SSL, $domain),0,-1).$query; + // 상황에 따라 혹은 지정된 대상만 SSL 취급될 경우 + } else { + // SSL상태인데 대상이 SSL이 아닌 경우 + if($_SERVER['HTTPS']=='on') $query = substr($this->getRequestUri(ENFORCE_SSL, $domain),0,-1).$query; + // SSL 상태가 아니면 domain값에 따라 query 완성 + else if($domain) $query = substr($this->getRequestUri(FOLLOW_REQUEST_SSL, $domain),0,-1).$query; + } + return htmlspecialchars($query); } /** * @brief 요청이 들어온 URL에서 argument를 제거하여 return **/ function getRequestUri($ssl_mode = FOLLOW_REQUEST_SSL, $domain = null) { + static $url = array(); + // HTTP Request가 아니면 패스 if(!isset($_SERVER['SERVER_PROTOCOL'])) return ; - static $url = array(); if(Context::get('_use_ssl') == "always") $ssl_mode = ENFORCE_SSL; if($domain) $domain_key = md5($domain); @@ -933,7 +943,7 @@ if(Context::get("_http_port") && Context::get("_http_port") != 80) { $url_info['port'] = Context::get("_http_port"); } - else + elseif($url_info['port']==80) { unset($url_info['port']); } diff --git a/modules/board/board.class.php b/modules/board/board.class.php index d58d83cb1..b6d953350 100644 --- a/modules/board/board.class.php +++ b/modules/board/board.class.php @@ -23,27 +23,22 @@ function moduleInstall() { // action forward에 등록 (관리자 모드에서 사용하기 위함) $oModuleController = &getController('module'); + $oModuleModel = &getModel('module'); // 2007. 10. 17 아이디 클릭시 나타나는 팝업메뉴에 작성글 보기 기능 추가 $oModuleController->insertTrigger('member.getMemberMenu', 'board', 'controller', 'triggerMemberMenu', 'after'); // 기본 게시판 생성 - $output = executeQuery('module.getDefaultMidInfo'); - if($output->data) return new Object(); - - // 기본 모듈을 찾음 - $oModuleModel = &getModel('module'); - $site_args->site_srl = 0; - $mid_list = $oModuleModel->getMidList($site_args); - if(!count($mid_list)) { + $args->site_srl = 0; + $output = executeQuery('module.getSite', $args); + if(!$output->data->index_module_srl) { $args->mid = 'board'; $args->module = 'board'; - $args->browser_title = 'test module'; + $args->browser_title = 'XpressEngine'; $args->skin = 'xe_default'; $args->site_srl = 0; $output = $oModuleController->insertModule($args); $module_srl = $output->get('module_srl'); - $site_args->site_srl = 0; $site_args->index_module_srl = $module_srl; $oModuleController = &getController('module'); diff --git a/modules/module/module.class.php b/modules/module/module.class.php index 7a4353f21..430ce1e56 100644 --- a/modules/module/module.class.php +++ b/modules/module/module.class.php @@ -15,13 +15,29 @@ $oModuleController = &getController('module'); $oDB = &DB::getInstance(); - $oDB->addIndex("modules","idx_site_mid", array("site_srl","mid"), true); // module 모듈에서 사용할 디렉토리 생성 FileHandler::makeDir('./files/cache/module_info'); FileHandler::makeDir('./files/cache/triggers'); + // sites 테이블에 기본 사이트 정보 입력 + $args->site_srl = 0; + $output = $oDB->executeQuery('module.getSite', $args); + if(!$output->data || !$output->data->index_module_srl) { + $db_info = Context::getDBInfo(); + $domain = Context::getDefaultUrl(); + $url_info = parse_url($domain); + $domain = $url_info['host'].( (!empty($url_info['port'])&&$url_info['port']!=80)?':'.$url_info['port']:'').$url_info['path']; + $site_args->site_srl = 0; + $site_args->index_module_srl = 0; + $site_args->domain = $domain; + $site_args->default_language = $db_info->lang_type; + + $output = executeQuery('module.insertSite', $site_args); + if(!$output->toBool()) return $output; + } + return new Object(); }