[XE jQuery] 제목 없음-http://web.geusgod.pe.kr:8081/index.php?mid=xe&document_srl=21290
2017.05.01 18:00
663
0
https://eond.com/380633

$oContext->init();에 대한 분석 다시시작~

function init()
	{
		// set context variables in $GLOBALS (to use in display handler)
		$this->context = &$GLOBALS['__Context__'];
		$this->context->lang = &$GLOBALS['lang'];
		$this->context->_COOKIE = $_COOKIE;

		$this->setRequestMethod('');

		$this->_setXmlRpcArgument();
		$this->_setJSONRequestArgument();
		$this->_setRequestArgument();
		$this->_setUploadedArgument();

		$this->loadDBInfo();

		// If XE is installed, get virtual site information
		if(Context::isInstalled())
		{
			$oModuleModel = getModel('module');
			$site_module_info = $oModuleModel->getDefaultMid();

			if(!isset($site_module_info))
			{
				$site_module_info = new stdClass();
			}

			// if site_srl of site_module_info is 0 (default site), compare the domain to default_url of db_config
			if($site_module_info->site_srl == 0 && $site_module_info->domain != $this->db_info->default_url)
			{
				$site_module_info->domain = $this->db_info->default_url;
			}

			$this->set('site_module_info', $site_module_info);
			if($site_module_info->site_srl && isSiteID($site_module_info->domain))
			{
				$this->set('vid', $site_module_info->domain, true);
			}

			if(!isset($this->db_info))
			{
				$this->db_info = new stdClass();
			}

			$this->db_info->lang_type = $site_module_info->default_language;
			if(!$this->db_info->lang_type)
			{
				$this->db_info->lang_type = 'en';
			}
			if(!$this->db_info->use_db_session)
			{
				$this->db_info->use_db_session = 'N';
			}
		}

		// Load Language File
		$lang_supported = $this->loadLangSelected();

		// Retrieve language type set in user's cookie
		if($this->get('l'))
		{
			$this->lang_type = $this->get('l');
			if($_COOKIE['lang_type'] != $this->lang_type)
			{
				setcookie('lang_type', $this->lang_type, time() + 3600 * 24 * 1000, '/');
			}
		}
		elseif($_COOKIE['lang_type'])
		{
			$this->lang_type = $_COOKIE['lang_type'];
		}

		// If it's not exists, follow default language type set in db_info
		if(!$this->lang_type)
		{
			$this->lang_type = $this->db_info->lang_type;
		}

		// if still lang_type has not been set or has not-supported type , set as English.
		if(!$this->lang_type)
		{
			$this->lang_type = 'en';
		}
		if(is_array($lang_supported) && !isset($lang_supported[$this->lang_type]))
		{
			$this->lang_type = 'en';
		}

		$this->set('lang_supported', $lang_supported);
		$this->setLangType($this->lang_type);

		// load module module's language file according to language setting
		$this->loadLang(_XE_PATH_ . 'modules/module/lang');

		// set session handler
		if(Context::isInstalled() && $this->db_info->use_db_session == 'Y')
		{
			$oSessionModel = getModel('session');
			$oSessionController = getController('session');
			session_set_save_handler(
					array(&$oSessionController, 'open'), array(&$oSessionController, 'close'), array(&$oSessionModel, 'read'), array(&$oSessionController, 'write'), array(&$oSessionController, 'destroy'), array(&$oSessionController, 'gc')
			);
		}
		session_start();
		if(isset($_POST[session_name()]))
		{
			session_id($_POST[session_name()]);
		}

		// set authentication information in Context and session
		if(Context::isInstalled())
		{
			$oModuleModel = getModel('module');
			$oModuleModel->loadModuleExtends();

			$oMemberModel = getModel('member');
			$oMemberController = getController('member');

			if($oMemberController && $oMemberModel)
			{
				// if signed in, validate it.
				if($oMemberModel->isLogged())
				{
					$oMemberController->setSessionInfo();
				}
				// check auto sign-in
				elseif($_COOKIE['xeak'])
				{
					$oMemberController->doAutologin();
				}

				$this->set('is_logged', $oMemberModel->isLogged());
				$this->set('logged_info', $oMemberModel->getLoggedInfo());
			}
		}

		// load common language file
		$this->lang = &$GLOBALS['lang'];
		$this->loadLang(_XE_PATH_ . 'common/lang/');

		// check if using rewrite module
		if(file_exists(_XE_PATH_ . '.htaccess') && $this->db_info->use_rewrite == 'Y')
		{
			$this->allow_rewrite = true;
		}
		else
		{
			$this->allow_rewrite = false;
		}

		// set locations for javascript use
		if($_SERVER['REQUEST_METHOD'] == 'GET')
		{
			if($this->get_vars)
			{
				foreach($this->get_vars as $key => $val)
				{
					if(is_array($val) && count($val))
					{
						foreach($val as $k => $v)
						{
							$url .= ($url ? '&' : '') . $key . '[' . $k . ']=' . urlencode($v);
						}
					}
					elseif($val)
					{
						$url .= ($url ? '&' : '') . $key . '=' . urlencode($val);
					}
				}
				$this->set('current_url', sprintf('%s?%s', Context::getRequestUri(), $url));
			}
			else
			{
				$this->set('current_url', $this->getUrl());
			}
		}
		else
		{
			$this->set('current_url', Context::getRequestUri());
		}
		$this->set('request_uri', Context::getRequestUri());
	}

분석하기에 앞서... 최종 결과에 대한 디버그 값을 찍어보자~




Context 클래스의 init() 실행 전후를 비교하면 아래와 같습니다. (저도 이렇게 보니 한결 보기 편하네요~^^)


한가지 짚고 넘어가자면 lang 변수에 658개의 프로퍼티가 할당되어 있네요... 이러면 정말...
서버에 부하가 심하지 않나요? --; 특히 저사양에서... 아직 잘 모르지만 그렇습니다. 658개나... 필요한지...
다국어라는 특징때문에 한개의 파일에 번역 파일이 있는건 좋지만... 항상 퍼포먼스도 생각해야 하는지라...
아무튼 잘 모르고 하는 소리니... 그러려니 하십시요^^

생각해 보니... 메모리만 많으면... 연산하는것도 아니라서... 부하 문제는 없겠네요~


결국 Context 클래스의 init() 실행하면, 
Context -> context 값
Context -> db_info 값
Context -> lang 값
각종 로그인 정보, 세션정보, site 정보 등을 찾아서 세팅하는 것을 볼 수 있습니다.


자세히 적으려니... 아직 뼈대를 좀 보고 깊이 파는게 좋을 것 같습니다.

우선, 레이아웃과 스킨관련쪽 로드까지 파헤치고 전체적인 출력 관련을 확인하고... 다시 돌아와야지요~

닫기

마이페이지

로그인을 해주세요

네이버로 로그인