<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
$allowedTargets = array('', 'parent.', 'top.', 'top.opener.');
$target = in_array($target, $allowedTargets, true) ? $target : '';
$url = str_replace('&amp;','&',(string)$url);
if (preg_match('/^\s*(?:javascript|data):/i', $url)) $url = '';
$historyNumber = is_numeric($history) ? (int)$history : 0;
?>
<html lang="ko" xml:lang="ko" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>안내메세지</title>
<meta name="robots" content="noindex,nofollow" />
<script type="text/javascript">
//<![CDATA[
var targetWindow = window;
<?php if ($target === 'parent.'):?>targetWindow = window.parent;<?php endif?>
<?php if ($target === 'top.'):?>targetWindow = window.top;<?php endif?>
<?php if ($target === 'top.opener.'):?>targetWindow = window.top.opener || window.top;<?php endif?>
var cHref = targetWindow.location.href.split('#');
<?php if($alert):?>alert(<?php echo json_encode($alert, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT)?>);<?php endif?>
<?php if(!strpos($url,'__target')):?>
	<?php if($url === 'reload'):?>
		<?php if($_POST):?>targetWindow.location.replace(cHref[0]);<?php else:?>targetWindow.location.reload();<?php endif?>
	<?php endif?>
	<?php if($url && $url !== 'reload'):?>targetWindow.location.href=<?php echo json_encode($url, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT)?>;<?php endif?>
<?php endif?>
<?php if($history === 'close'):?>window.top.close();<?php endif?>
<?php if($historyNumber < 0):?>history.go(<?php echo $historyNumber?>);<?php endif?>
//]]>
</script>
</head>
<body>

<?php
if (strpos($url,'__target') !== false) :
	$urlParts = parse_url($url);
	$params = array();
	parse_str($urlParts['query'] ?? '', $params);
	$formTarget = (string)($params['__target'] ?? '');
	if (!preg_match('/^[A-Za-z0-9_.-]{1,64}$/', $formTarget)) $formTarget = '';
	unset($params['__target']);
?>
	<form name="backForm" action="<?php echo htmlspecialchars($g['s'], ENT_QUOTES, 'UTF-8')?>" method="get" target="">
	<?php foreach($params as $_key => $_value): if (!is_scalar($_value) || !preg_match('/^[A-Za-z][A-Za-z0-9_]*$/', $_key)) continue?>
	<input type="hidden" name="<?php echo htmlspecialchars($_key, ENT_QUOTES, 'UTF-8')?>" value="<?php echo htmlspecialchars((string)$_value, ENT_QUOTES, 'UTF-8')?>" />
	<?php endforeach?>
	<?php if (!empty($params['a'])):?><input type="hidden" name="_csrf" value="<?php echo kimsq_csrf_token()?>" /><?php endif?>
	</form>
	<script type="text/javascript">
	//<![CDATA[
	document.backForm.target = <?php echo json_encode($formTarget, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT)?>;
	document.backForm.submit();
	//]]>
	</script>
<?php endif?>

<h1><a href="<?php echo htmlspecialchars(kimsq_site_origin(), ENT_QUOTES, 'UTF-8')?>/"><?php echo htmlspecialchars((string)$_HS['title'], ENT_QUOTES, 'UTF-8') ?></a></h1>
</body>
</html>
<?php exit?>
