PageRenderTime 278ms CodeModel.GetById 202ms app.highlight 66ms RepoModel.GetById 1ms app.codeStats 1ms

/config/func.inc.php

https://github.com/prologos/xe-core
PHP | 1620 lines | 1058 code | 164 blank | 398 comment | 167 complexity | 018b226361eabe4b97ce1eca8b6c508c MD5 | raw file
   1<?php
   2/* Copyright (C) NAVER <http://www.navercorp.com> */
   3
   4/**
   5 * function library files for convenience
   6 *
   7 * @author NAVER (developers@xpressengine.com)
   8 */
   9if(!defined('__XE__'))
  10{
  11	exit();
  12}
  13
  14// define an empty function to avoid errors when iconv function doesn't exist
  15if(!function_exists('iconv'))
  16{
  17	eval('
  18		function iconv($in_charset, $out_charset, $str)
  19		{
  20			return $str;
  21		}
  22	');
  23}
  24
  25/**
  26 * Time zone
  27 * @var array
  28 */
  29$time_zone = array(
  30	'-1200' => '[GMT -12:00] Baker Island Time',
  31	'-1100' => '[GMT -11:00] Niue Time, Samoa Standard Time',
  32	'-1000' => '[GMT -10:00] Hawaii-Aleutian Standard Time, Cook Island Time',
  33	'-0930' => '[GMT -09:30] Marquesas Islands Time',
  34	'-0900' => '[GMT -09:00] Alaska Standard Time, Gambier Island Time',
  35	'-0800' => '[GMT -08:00] Pacific Standard Time',
  36	'-0700' => '[GMT -07:00] Mountain Standard Time',
  37	'-0600' => '[GMT -06:00] Central Standard Time',
  38	'-0500' => '[GMT -05:00] Eastern Standard Time',
  39	'-0400' => '[GMT -04:00] Atlantic Standard Time',
  40	'-0330' => '[GMT -03:30] Newfoundland Standard Time',
  41	'-0300' => '[GMT -03:00] Amazon Standard Time, Central Greenland Time',
  42	'-0200' => '[GMT -02:00] Fernando de Noronha Time, South Georgia &amp; the South Sandwich Islands Time',
  43	'-0100' => '[GMT -01:00] Azores Standard Time, Cape Verde Time, Eastern Greenland Time',
  44	'0000' => '[GMT  00:00] Western European Time, Greenwich Mean Time',
  45	'+0100' => '[GMT +01:00] Central European Time, West African Time',
  46	'+0200' => '[GMT +02:00] Eastern European Time, Central African Time',
  47	'+0300' => '[GMT +03:00] Moscow Standard Time, Eastern African Time',
  48	'+0330' => '[GMT +03:30] Iran Standard Time',
  49	'+0400' => '[GMT +04:00] Gulf Standard Time, Samara Standard Time',
  50	'+0430' => '[GMT +04:30] Afghanistan Time',
  51	'+0500' => '[GMT +05:00] Pakistan Standard Time, Yekaterinburg Standard Time',
  52	'+0530' => '[GMT +05:30] Indian Standard Time, Sri Lanka Time',
  53	'+0545' => '[GMT +05:45] Nepal Time',
  54	'+0600' => '[GMT +06:00] Bangladesh Time, Bhutan Time, Novosibirsk Standard Time',
  55	'+0630' => '[GMT +06:30] Cocos Islands Time, Myanmar Time',
  56	'+0700' => '[GMT +07:00] Indochina Time, Krasnoyarsk Standard Time',
  57	'+0800' => '[GMT +08:00] China Standard Time, Australian Western Standard Time, Irkutsk Standard Time',
  58	'+0845' => '[GMT +08:45] Southeastern Western Australia Standard Time',
  59	'+0900' => '[GMT +09:00] Korea Standard Time, Japan Standard Time',
  60	'+0930' => '[GMT +09:30] Australian Central Standard Time',
  61	'+1000' => '[GMT +10:00] Australian Eastern Standard Time, Vladivostok Standard Time',
  62	'+1030' => '[GMT +10:30] Lord Howe Standard Time',
  63	'+1100' => '[GMT +11:00] Solomon Island Time, Magadan Standard Time',
  64	'+1130' => '[GMT +11:30] Norfolk Island Time',
  65	'+1200' => '[GMT +12:00] New Zealand Time, Fiji Time, Kamchatka Standard Time',
  66	'+1245' => '[GMT +12:45] Chatham Islands Time',
  67	'+1300' => '[GMT +13:00] Tonga Time, Phoenix Islands Time',
  68	'+1400' => '[GMT +14:00] Line Island Time'
  69);
  70
  71/**
  72 * Define a function to use {@see ModuleHandler::getModuleObject()} ($module_name, $type)
  73 *
  74 * @param string $module_name The module name to get a instance
  75 * @param string $type disp, proc, controller, class
  76 * @param string $kind admin, null
  77 * @return mixed Module instance
  78 */
  79function getModule($module_name, $type = 'view', $kind = '')
  80{
  81	return ModuleHandler::getModuleInstance($module_name, $type, $kind);
  82}
  83
  84/**
  85 * Create a controller instance of the module
  86 *
  87 * @param string $module_name The module name to get a controller instance
  88 * @return mixed Module controller instance
  89 */
  90function getController($module_name)
  91{
  92	return getModule($module_name, 'controller');
  93}
  94
  95/**
  96 * Create a admin controller instance of the module
  97 *
  98 * @param string $module_name The module name to get a admin controller instance
  99 * @return mixed Module admin controller instance
 100 */
 101function getAdminController($module_name)
 102{
 103	return getModule($module_name, 'controller', 'admin');
 104}
 105
 106/**
 107 * Create a view instance of the module
 108 *
 109 * @param string $module_name The module name to get a view instance
 110 * @return mixed Module view instance
 111 */
 112function getView($module_name)
 113{
 114	return getModule($module_name, 'view');
 115}
 116
 117/**
 118 * Create a mobile instance of the module
 119 *
 120 * @param string $module_name The module name to get a mobile instance
 121 * @return mixed Module mobile instance
 122 */
 123function &getMobile($module_name)
 124{
 125	return getModule($module_name, 'mobile');
 126}
 127
 128/**
 129 * Create a admin view instance of the module
 130 *
 131 * @param string $module_name The module name to get a admin view instance
 132 * @return mixed Module admin view instance
 133 */
 134function getAdminView($module_name)
 135{
 136	return getModule($module_name, 'view', 'admin');
 137}
 138
 139/**
 140 * Create a model instance of the module
 141 *
 142 * @param string $module_name The module name to get a model instance
 143 * @return mixed Module model instance
 144 */
 145function getModel($module_name)
 146{
 147	return getModule($module_name, 'model');
 148}
 149
 150/**
 151 * Create an admin model instance of the module
 152 *
 153 * @param string $module_name The module name to get a admin model instance
 154 * @return mixed Module admin model instance
 155 */
 156function getAdminModel($module_name)
 157{
 158	return getModule($module_name, 'model', 'admin');
 159}
 160
 161/**
 162 * Create an api instance of the module
 163 *
 164 * @param string $module_name The module name to get a api instance
 165 * @return mixed Module api class instance
 166 */
 167function getAPI($module_name)
 168{
 169	return getModule($module_name, 'api');
 170}
 171
 172/**
 173 * Create a wap instance of the module
 174 *
 175 * @param string $module_name The module name to get a wap instance
 176 * @return mixed Module wap class instance
 177 */
 178function getWAP($module_name)
 179{
 180	return getModule($module_name, 'wap');
 181}
 182
 183/**
 184 * Create a class instance of the module
 185 *
 186 * @param string $module_name The module name to get a class instance
 187 * @return mixed Module class instance
 188 */
 189function getClass($module_name)
 190{
 191	return getModule($module_name, 'class');
 192}
 193
 194/**
 195 * The alias of DB::executeQuery()
 196 *
 197 * @see DB::executeQuery()
 198 * @param string $query_id (module name.query XML file)
 199 * @param object $args values of args object
 200 * @param string[] $arg_columns Column list
 201 * @return object Query result data
 202 */
 203function executeQuery($query_id, $args = NULL, $arg_columns = NULL)
 204{
 205	$oDB = DB::getInstance();
 206	return $oDB->executeQuery($query_id, $args, $arg_columns);
 207}
 208
 209/**
 210 * Function to handle the result of DB::executeQuery() as an array
 211 *
 212 * @see DB::executeQuery()
 213 * @see executeQuery()
 214 * @param string $query_id (module name.query XML file)
 215 * @param object $args values of args object
 216 * @param string[] $arg_columns Column list
 217 * @return object Query result data
 218 */
 219function executeQueryArray($query_id, $args = NULL, $arg_columns = NULL)
 220{
 221	$oDB = DB::getInstance();
 222	$output = $oDB->executeQuery($query_id, $args, $arg_columns);
 223	if(!is_array($output->data) && count($output->data) > 0)
 224	{
 225		$output->data = array($output->data);
 226	}
 227	return $output;
 228}
 229
 230/**
 231 * Alias of DB::getNextSequence()
 232 *
 233 * @see DB::getNextSequence()
 234 * @return int
 235 */
 236function getNextSequence()
 237{
 238	$oDB = DB::getInstance();
 239	$seq = $oDB->getNextSequence();
 240	setUserSequence($seq);
 241	return $seq;
 242}
 243
 244/**
 245 * Set Sequence number to session
 246 *
 247 * @param int $seq sequence number
 248 * @return void
 249 */
 250function setUserSequence($seq)
 251{
 252	$arr_seq = array();
 253	if(isset($_SESSION['seq']))
 254	{
 255		$arr_seq = $_SESSION['seq'];
 256	}
 257	$arr_seq[] = $seq;
 258	$_SESSION['seq'] = $arr_seq;
 259}
 260
 261/**
 262 * Check Sequence number grant
 263 *
 264 * @param int $seq sequence number
 265 * @return boolean
 266 */
 267function checkUserSequence($seq)
 268{
 269	if(!isset($_SESSION['seq']))
 270	{
 271		return false;
 272	}
 273	if(!in_array($seq, $_SESSION['seq']))
 274	{
 275		return false;
 276	}
 277
 278	return true;
 279}
 280
 281/**
 282 * Get a encoded url. Define a function to use Context::getUrl()
 283 *
 284 * getUrl() returns the URL transformed from given arguments of RequestURI
 285 * <ol>
 286 *  <li>argument format follows as (key, value).
 287 * ex) getUrl('key1', 'val1', 'key2',''): transform key1 and key2 to val1 and '' respectively</li>
 288 * <li>returns URL without the argument if no argument is given.</li>
 289 * <li>URL made of args_list added to RequestUri if the first argument value is ''.</li>
 290 * </ol>
 291 *
 292 * @return string
 293 */
 294function getUrl()
 295{
 296	$num_args = func_num_args();
 297	$args_list = func_get_args();
 298
 299	if($num_args)
 300		$url = Context::getUrl($num_args, $args_list);
 301	else
 302		$url = Context::getRequestUri();
 303
 304	return preg_replace('@\berror_return_url=[^&]*|\w+=(?:&|$)@', '', $url);
 305}
 306
 307/**
 308 * Get a not encoded(html entity) url
 309 *
 310 * @see getUrl()
 311 * @return string
 312 */
 313function getNotEncodedUrl()
 314{
 315	$num_args = func_num_args();
 316	$args_list = func_get_args();
 317
 318	if($num_args)
 319	{
 320		$url = Context::getUrl($num_args, $args_list, NULL, FALSE);
 321	}
 322	else
 323	{
 324		$url = Context::getRequestUri();
 325	}
 326
 327	return preg_replace('@\berror_return_url=[^&]*|\w+=(?:&|$)@', '', $url);
 328}
 329
 330/**
 331 * Get a encoded url. If url is encoded, not encode. Otherwise html encode the url.
 332 *
 333 * @see getUrl()
 334 * @return string
 335 */
 336function getAutoEncodedUrl()
 337{
 338	$num_args = func_num_args();
 339	$args_list = func_get_args();
 340
 341	if($num_args)
 342	{
 343		$url = Context::getUrl($num_args, $args_list, NULL, TRUE, TRUE);
 344	}
 345	else
 346	{
 347		$url = Context::getRequestUri();
 348	}
 349
 350	return preg_replace('@\berror_return_url=[^&]*|\w+=(?:&|$)@', '', $url);
 351}
 352
 353/**
 354 * Return the value adding request uri to getUrl() to get the full url
 355 *
 356 * @return string
 357 */
 358function getFullUrl()
 359{
 360	$num_args = func_num_args();
 361	$args_list = func_get_args();
 362	$request_uri = Context::getRequestUri();
 363	if(!$num_args)
 364	{
 365		return $request_uri;
 366	}
 367
 368	$url = Context::getUrl($num_args, $args_list);
 369	if(strncasecmp('http', $url, 4) !== 0)
 370	{
 371		preg_match('/^(http|https):\/\/([^\/]+)\//', $request_uri, $match);
 372		return substr($match[0], 0, -1) . $url;
 373	}
 374	return $url;
 375}
 376
 377/**
 378 * Return the value adding request uri to getUrl() to get the not encoded full url
 379 *
 380 * @return string
 381 */
 382function getNotEncodedFullUrl()
 383{
 384	$num_args = func_num_args();
 385	$args_list = func_get_args();
 386	$request_uri = Context::getRequestUri();
 387	if(!$num_args)
 388	{
 389		return $request_uri;
 390	}
 391
 392	$url = Context::getUrl($num_args, $args_list, NULL, FALSE);
 393	if(strncasecmp('http', $url, 4) !== 0)
 394	{
 395		preg_match('/^(http|https):\/\/([^\/]+)\//', $request_uri, $match);
 396		$url = Context::getUrl($num_args, $args_list, NULL, FALSE);
 397		return substr($match[0], 0, -1) . $url;
 398	}
 399	return $url;
 400}
 401
 402/**
 403 * getSiteUrl() returns the URL by transforming the given argument value of domain
 404 * The first argument should consist of domain("http://" not included) and path
 405 * 
 406 * @return string
 407 */
 408function getSiteUrl()
 409{
 410	$num_args = func_num_args();
 411	$args_list = func_get_args();
 412
 413	if(!$num_args)
 414	{
 415		return Context::getRequestUri();
 416	}
 417
 418	$domain = array_shift($args_list);
 419	$num_args = count($args_list);
 420
 421	return Context::getUrl($num_args, $args_list, $domain);
 422}
 423
 424/**
 425 * getSiteUrl() returns the not encoded URL by transforming the given argument value of domain
 426 * The first argument should consist of domain("http://" not included) and path
 427 * 
 428 * @return string
 429 */
 430function getNotEncodedSiteUrl()
 431{
 432	$num_args = func_num_args();
 433	$args_list = func_get_args();
 434
 435	if(!$num_args)
 436	{
 437		return Context::getRequestUri();
 438	}
 439
 440	$domain = array_shift($args_list);
 441	$num_args = count($args_list);
 442
 443	return Context::getUrl($num_args, $args_list, $domain, FALSE);
 444}
 445
 446/**
 447 * Return the value adding request uri to the getSiteUrl() To get the full url
 448 *
 449 * @return string
 450 */
 451function getFullSiteUrl()
 452{
 453	$num_args = func_num_args();
 454	$args_list = func_get_args();
 455
 456	$request_uri = Context::getRequestUri();
 457	if(!$num_args)
 458	{
 459		return $request_uri;
 460	}
 461
 462	$domain = array_shift($args_list);
 463	$num_args = count($args_list);
 464
 465	$url = Context::getUrl($num_args, $args_list, $domain);
 466	if(strncasecmp('http', $url, 4) !== 0)
 467	{
 468		preg_match('/^(http|https):\/\/([^\/]+)\//', $request_uri, $match);
 469		return substr($match[0], 0, -1) . $url;
 470	}
 471	return $url;
 472}
 473
 474/**
 475 * Return if domain of the virtual site is url type or id type
 476 *
 477 * @param string $domain
 478 * @return bool
 479 */
 480function isSiteID($domain)
 481{
 482	return preg_match('/^([a-zA-Z0-9\_]+)$/', $domain);
 483}
 484
 485/**
 486 * Put a given tail after trimming string to the specified size
 487 *
 488 * @param string $string The original string to trim
 489 * @param int $cut_size The size to be
 490 * @param string $tail Tail to put in the end of the string after trimming
 491 * @return string
 492 */
 493function cut_str($string, $cut_size = 0, $tail = '...')
 494{
 495	if($cut_size < 1 || !$string)
 496	{
 497		return $string;
 498	}
 499
 500	if($GLOBALS['use_mb_strimwidth'] || function_exists('mb_strimwidth'))
 501	{
 502		$GLOBALS['use_mb_strimwidth'] = TRUE;
 503		return mb_strimwidth($string, 0, $cut_size + 4, $tail, 'utf-8');
 504	}
 505
 506	$chars = array(12, 4, 3, 5, 7, 7, 11, 8, 4, 5, 5, 6, 6, 4, 6, 4, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 4, 4, 8, 6, 8, 6, 10, 8, 8, 9, 8, 8, 7, 9, 8, 3, 6, 7, 7, 11, 8, 9, 8, 9, 8, 8, 7, 8, 8, 10, 8, 8, 8, 6, 11, 6, 6, 6, 4, 7, 7, 7, 7, 7, 3, 7, 7, 3, 3, 6, 3, 9, 7, 7, 7, 7, 4, 7, 3, 7, 6, 10, 6, 6, 7, 6, 6, 6, 9);
 507	$max_width = $cut_size * $chars[0] / 2;
 508	$char_width = 0;
 509
 510	$string_length = strlen($string);
 511	$char_count = 0;
 512
 513	$idx = 0;
 514	while($idx < $string_length && $char_count < $cut_size && $char_width <= $max_width)
 515	{
 516		$c = ord(substr($string, $idx, 1));
 517		$char_count++;
 518		if($c < 128)
 519		{
 520			$char_width += (int) $chars[$c - 32];
 521			$idx++;
 522		}
 523		else if(191 < $c && $c < 224)
 524		{
 525			$char_width += $chars[4];
 526			$idx += 2;
 527		}
 528		else
 529		{
 530			$char_width += $chars[0];
 531			$idx += 3;
 532		}
 533	}
 534
 535	$output = substr($string, 0, $idx);
 536	if(strlen($output) < $string_length)
 537	{
 538		$output .= $tail;
 539	}
 540
 541	return $output;
 542}
 543
 544/**
 545 * Get a time gap between server's timezone and XE's timezone
 546 *
 547 * @return int
 548 */
 549function zgap()
 550{
 551	$time_zone = $GLOBALS['_time_zone'];
 552	if($time_zone < 0)
 553	{
 554		$to = -1;
 555	}
 556	else
 557	{
 558		$to = 1;
 559	}
 560
 561	$t_hour = substr($time_zone, 1, 2) * $to;
 562	$t_min = substr($time_zone, 3, 2) * $to;
 563
 564	$server_time_zone = date("O");
 565	if($server_time_zone < 0)
 566	{
 567		$so = -1;
 568	}
 569	else
 570	{
 571		$so = 1;
 572	}
 573
 574	$c_hour = substr($server_time_zone, 1, 2) * $so;
 575	$c_min = substr($server_time_zone, 3, 2) * $so;
 576
 577	$g_min = $t_min - $c_min;
 578	$g_hour = $t_hour - $c_hour;
 579
 580	$gap = $g_min * 60 + $g_hour * 60 * 60;
 581	return $gap;
 582}
 583
 584/**
 585 * YYYYMMDDHHIISS format changed to unix time value
 586 *
 587 * @param string $str Time value in format of YYYYMMDDHHIISS
 588 * @return int
 589 */
 590function ztime($str)
 591{
 592	if(!$str)
 593	{
 594		return;
 595	}
 596
 597	$hour = (int) substr($str, 8, 2);
 598	$min = (int) substr($str, 10, 2);
 599	$sec = (int) substr($str, 12, 2);
 600	$year = (int) substr($str, 0, 4);
 601	$month = (int) substr($str, 4, 2);
 602	$day = (int) substr($str, 6, 2);
 603	if(strlen($str) <= 8)
 604	{
 605		$gap = 0;
 606	}
 607	else
 608	{
 609		$gap = zgap();
 610	}
 611
 612	return mktime($hour, $min, $sec, $month ? $month : 1, $day ? $day : 1, $year) + $gap;
 613}
 614
 615/**
 616 * If the recent post within a day, output format of YmdHis is "min/hours ago from now". If not within a day, it return format string.
 617 *
 618 * @param string $date Time value in format of YYYYMMDDHHIISS
 619 * @param string $format If gap is within a day, returns this format.
 620 * @return string
 621 */
 622function getTimeGap($date, $format = 'Y.m.d')
 623{
 624	$gap = $_SERVER['REQUEST_TIME'] + zgap() - ztime($date);
 625
 626	$lang_time_gap = Context::getLang('time_gap');
 627	if($gap < 60)
 628	{
 629		$buff = sprintf($lang_time_gap['min'], (int) ($gap / 60) + 1);
 630	}
 631	elseif($gap < 60 * 60)
 632	{
 633		$buff = sprintf($lang_time_gap['mins'], (int) ($gap / 60) + 1);
 634	}
 635	elseif($gap < 60 * 60 * 2)
 636	{
 637		$buff = sprintf($lang_time_gap['hour'], (int) ($gap / 60 / 60) + 1);
 638	}
 639	elseif($gap < 60 * 60 * 24)
 640	{
 641		$buff = sprintf($lang_time_gap['hours'], (int) ($gap / 60 / 60) + 1);
 642	}
 643	else
 644	{
 645		$buff = zdate($date, $format);
 646	}
 647
 648	return $buff;
 649}
 650
 651/**
 652 * Name of the month return
 653 *
 654 * @param int $month Month
 655 * @param boot $short If set, returns short string
 656 * @return string
 657 */
 658function getMonthName($month, $short = TRUE)
 659{
 660	$short_month = array('', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
 661	$long_month = array('', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
 662	return !$short ? $long_month[$month] : $short_month[$month];
 663}
 664
 665/**
 666 * Change the time format YYYYMMDDHHIISS to the user defined format
 667 *
 668 * @param string|int $str YYYYMMDDHHIISS format time values
 669 * @param string $format Time format of php date() function
 670 * @param bool $conversion Means whether to convert automatically according to the language
 671 * @return string
 672 */
 673function zdate($str, $format = 'Y-m-d H:i:s', $conversion = TRUE)
 674{
 675	// return null if no target time is specified
 676	if(!$str)
 677	{
 678		return;
 679	}
 680	// convert the date format according to the language
 681	if($conversion == TRUE)
 682	{
 683		switch(Context::getLangType())
 684		{
 685			case 'en' :
 686			case 'es' :
 687				if($format == 'Y-m-d')
 688				{
 689					$format = 'M d, Y';
 690				}
 691				elseif($format == 'Y-m-d H:i:s')
 692				{
 693					$format = 'M d, Y H:i:s';
 694				}
 695				elseif($format == 'Y-m-d H:i')
 696				{
 697					$format = 'M d, Y H:i';
 698				}
 699				break;
 700			case 'vi' :
 701				if($format == 'Y-m-d')
 702				{
 703					$format = 'd-m-Y';
 704				}
 705				elseif($format == 'Y-m-d H:i:s')
 706				{
 707					$format = 'H:i:s d-m-Y';
 708				}
 709				elseif($format == 'Y-m-d H:i')
 710				{
 711					$format = 'H:i d-m-Y';
 712				}
 713				break;
 714		}
 715	}
 716
 717	// If year value is less than 1970, handle it separately.
 718	if((int) substr($str, 0, 4) < 1970)
 719	{
 720		$hour = (int) substr($str, 8, 2);
 721		$min = (int) substr($str, 10, 2);
 722		$sec = (int) substr($str, 12, 2);
 723		$year = (int) substr($str, 0, 4);
 724		$month = (int) substr($str, 4, 2);
 725		$day = (int) substr($str, 6, 2);
 726
 727		// leading zero?
 728		$lz = create_function('$n', 'return ($n>9?"":"0").$n;');
 729
 730		$trans = array(
 731			'Y' => $year,
 732			'y' => $lz($year % 100),
 733			'm' => $lz($month),
 734			'n' => $month,
 735			'd' => $lz($day),
 736			'j' => $day,
 737			'G' => $hour,
 738			'H' => $lz($hour),
 739			'g' => $hour % 12,
 740			'h' => $lz($hour % 12),
 741			'i' => $lz($min),
 742			's' => $lz($sec),
 743			'M' => getMonthName($month),
 744			'F' => getMonthName($month, FALSE)
 745		);
 746
 747		$string = strtr($format, $trans);
 748	}
 749	else
 750	{
 751		// if year value is greater than 1970, get unixtime by using ztime() for date() function's argument. 
 752		$string = date($format, ztime($str));
 753	}
 754	// change day and am/pm for each language
 755	$unit_week = Context::getLang('unit_week');
 756	$unit_meridiem = Context::getLang('unit_meridiem');
 757	$string = str_replace(array('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'), $unit_week, $string);
 758	$string = str_replace(array('am', 'pm', 'AM', 'PM'), $unit_meridiem, $string);
 759	return $string;
 760}
 761
 762/**
 763 * Returns encoded value of given email address for email scraping
 764 *
 765 * @param string $email The email
 766 * @return string
 767 */
 768function getEncodeEmailAddress($email)
 769{
 770	$return = '';
 771	for($i = 0, $c = strlen($email); $i < $c; $i++)
 772	{
 773		$return .= '&#' . (rand(0, 1) == 0 ? ord($email[$i]) : 'X' . dechex(ord($email[$i]))) . ';';
 774	}
 775	return $return;
 776}
 777
 778/**
 779 * Prints debug messages 
 780 *
 781 * Display $buff contents into the file ./files/_debug_message.php.
 782 * You can see the file on your prompt by command: tail-f./files/_debug_message.php
 783 *
 784 * @param mixed $debug_output Target object to be printed
 785 * @param bool $display_option boolean Flag whether to print seperator (default:true)
 786 * @param string $file Target file name
 787 * @return void
 788 */
 789function debugPrint($debug_output = NULL, $display_option = TRUE, $file = '_debug_message.php')
 790{
 791	static $debug_file;
 792	static $debug_file_exist;
 793
 794	if(!(__DEBUG__ & 1))
 795	{
 796		return;
 797	}
 798
 799	static $firephp;
 800	$bt = debug_backtrace();
 801	if(is_array($bt))
 802	{
 803		$bt_debug_print = array_shift($bt);
 804		$bt_called_function = array_shift($bt);
 805	}
 806	$file_name = str_replace(_XE_PATH_, '', $bt_debug_print['file']);
 807	$line_num = $bt_debug_print['line'];
 808	$function = $bt_called_function['class'] . $bt_called_function['type'] . $bt_called_function['function'];
 809
 810	if(__DEBUG_OUTPUT__ == 2 && version_compare(PHP_VERSION, '6.0.0') === -1)
 811	{
 812		if(!isset($firephp))
 813		{
 814			$firephp = FirePHP::getInstance(TRUE);
 815		}
 816		$type = FirePHP::INFO;
 817
 818		$label = sprintf('[%s:%d] %s() (Memory usage: current=%s, peak=%s)', $file_name, $line_num, $function, FileHandler::filesize(memory_get_usage()), FileHandler::filesize(memory_get_peak_usage()));
 819
 820		// Check a FirePHP option
 821		if($display_option === 'TABLE')
 822		{
 823			$label = $display_option;
 824		}
 825		if($display_option === 'ERROR')
 826		{
 827			$type = $display_option;
 828		}
 829		// Check if the IP specified by __DEBUG_PROTECT__ option is same as the access IP.
 830		if(__DEBUG_PROTECT__ === 1 && __DEBUG_PROTECT_IP__ != $_SERVER['REMOTE_ADDR'])
 831		{
 832			$debug_output = 'The IP address is not allowed. Change the value of __DEBUG_PROTECT_IP__ into your IP address in config/config.user.inc.php or config/config.inc.php';
 833			$label = NULL;
 834		}
 835
 836		$firephp->fb($debug_output, $label, $type);
 837	}
 838	else
 839	{
 840		if(__DEBUG_PROTECT__ === 1 && __DEBUG_PROTECT_IP__ != $_SERVER['REMOTE_ADDR'])
 841		{
 842			return;
 843		}
 844
 845		$print = array();
 846		if($debug_file_exist === NULL) $print[] = '<?php exit() ?>';
 847
 848		if(!$debug_file) $debug_file =  _XE_PATH_ . 'files/' . $file;
 849		if(!$debug_file_exist) $debug_file_exist = file_exists($debug_file);
 850
 851		if($display_option === TRUE || $display_option === 'ERROR')
 852		{
 853			$print[] = str_repeat('=', 80);
 854		}
 855
 856		$print[] = sprintf("[%s %s:%d] %s() - mem(%s)", date('Y-m-d H:i:s'), $file_name, $line_num, $function, FileHandler::filesize(memory_get_usage()));
 857
 858		$type = gettype($debug_output);
 859		if(!in_array($type, array('array', 'object', 'resource')))
 860		{
 861			if($display_option === 'ERROR') $print[] = 'ERROR : ' . var_export($debug_output, TRUE);
 862			else $print[] = $type . '(' . var_export($debug_output, TRUE) . ')';
 863			$print[] = PHP_EOL.PHP_EOL;
 864		}
 865		else
 866		{
 867			$print[] = print_r($debug_output, TRUE);
 868			$print[] = PHP_EOL;
 869		}
 870
 871		@file_put_contents($debug_file, implode(PHP_EOL, $print), FILE_APPEND|LOCK_EX);
 872	}
 873}
 874
 875/**
 876 * microtime() return
 877 *
 878 * @return float
 879 */
 880function getMicroTime()
 881{
 882	list($time1, $time2) = explode(' ', microtime());
 883	return (float) $time1 + (float) $time2;
 884}
 885
 886/**
 887 * Delete the second object vars from the first argument
 888 *
 889 * @param object $target_obj An original object
 890 * @param object $del_obj Object vars to delete from the original object
 891 * @return object
 892 */
 893function delObjectVars($target_obj, $del_obj)
 894{
 895	if(!is_object($target_obj))
 896	{
 897		return;
 898	}
 899	if(!is_object($del_obj))
 900	{
 901		return;
 902	}
 903
 904	$target_vars = get_object_vars($target_obj);
 905	$del_vars = get_object_vars($del_obj);
 906
 907	$target = array_keys($target_vars);
 908	$del = array_keys($del_vars);
 909	if(!count($target) || !count($del))
 910	{
 911		return $target_obj;
 912	}
 913
 914	$return_obj = new stdClass();
 915
 916	$target_count = count($target);
 917	for($i = 0; $i < $target_count; $i++)
 918	{
 919		$target_key = $target[$i];
 920		if(!in_array($target_key, $del))
 921		{
 922			$return_obj->{$target_key} = $target_obj->{$target_key};
 923		}
 924	}
 925
 926	return $return_obj;
 927}
 928
 929function getDestroyXeVars(&$vars)
 930{
 931	$del_vars = array('error_return_url', 'success_return_url', 'ruleset', 'xe_validator_id');
 932
 933	foreach($del_vars as $var)
 934	{
 935		if(is_array($vars)) unset($vars[$var]);
 936		else if(is_object($vars)) unset($vars->$var);
 937	}
 938
 939	return $vars;
 940}
 941
 942/**
 943 * Change error_handing to debugPrint on php5 higher 
 944 *
 945 * @param int $errno
 946 * @param string $errstr
 947 * @param string $file
 948 * @param int $line
 949 * @return void
 950 */
 951function handleError($errno, $errstr, $file, $line)
 952{
 953	if(!__DEBUG__)
 954	{
 955		return;
 956	}
 957	$errors = array(E_USER_ERROR, E_ERROR, E_PARSE);
 958	if(!in_array($errno, $errors))
 959	{
 960		return;
 961	}
 962
 963	$output = sprintf("Fatal error : %s - %d", $file, $line);
 964	$output .= sprintf("%d - %s", $errno, $errstr);
 965
 966	debugPrint($output);
 967}
 968
 969/**
 970 * Trim a given number to a fiven size recursively
 971 *
 972 * @param int $no A given number
 973 * @param int $size A given digits
 974 */
 975function getNumberingPath($no, $size = 3)
 976{
 977	$mod = pow(10, $size);
 978	$output = sprintf('%0' . $size . 'd/', $no % $mod);
 979	if($no >= $mod)
 980	{
 981		$output .= getNumberingPath((int) $no / $mod, $size);
 982	}
 983	return $output;
 984}
 985
 986/**
 987 * Decode the URL in Korean
 988 *
 989 * @param string $str The url
 990 * @return string
 991 */
 992function url_decode($str)
 993{
 994	return preg_replace('/%u([[:alnum:]]{4})/', '&#x\\1;', $str);
 995}
 996
 997function purifierHtml(&$content)
 998{
 999	require_once(_XE_PATH_ . 'classes/security/Purifier.class.php');
1000	$oPurifier = Purifier::getInstance();
1001	$oPurifier->purify($content);
1002}
1003
1004/**
1005 * Pre-block the codes which may be hacking attempts
1006 *
1007 * @param string $content Taget content
1008 * @return string
1009 */
1010function removeHackTag($content)
1011{
1012	require_once(_XE_PATH_ . 'classes/security/EmbedFilter.class.php');
1013	$oEmbedFilter = EmbedFilter::getInstance();
1014	$oEmbedFilter->check($content);
1015
1016	purifierHtml($content);
1017
1018	// change the specific tags to the common texts
1019	$content = preg_replace('@<(\/?(?:html|body|head|title|meta|base|link|script|style|applet)(/*).*?>)@i', '&lt;$1', $content);
1020
1021	/**
1022	 * Remove codes to abuse the admin session in src by tags of imaages and video postings
1023	 * - Issue reported by Sangwon Kim
1024	 */
1025	$content = preg_replace_callback('@<(/?)([a-z]+[0-9]?)((?>"[^"]*"|\'[^\']*\'|[^>])*?\b(?:on[a-z]+|data|style|background|href|(?:dyn|low)?src)\s*=[\s\S]*?)(/?)($|>|<)@i', 'removeSrcHack', $content);
1026
1027	// xmp tag ?뺤씤 �??�붽?
1028	$content = checkXmpTag($content);
1029	return $content;
1030}
1031
1032/**
1033 * check uploaded file which may be hacking attempts
1034 *
1035 * @param string $file Taget file path
1036 * @return bool
1037 */
1038function checkUploadedFile($file)
1039{
1040	require_once(_XE_PATH_ . 'classes/security/UploadFileFilter.class.php');
1041	return UploadFileFilter::check($file);
1042}
1043
1044/**
1045 * Check xmp tag, close it.
1046 *
1047 * @param string $content Target content
1048 * @return string
1049 */
1050function checkXmpTag($content)
1051{
1052	$content = preg_replace('@<(/?)xmp.*?>@i', '<\1xmp>', $content);
1053
1054	if(($start_xmp = strrpos($content, '<xmp>')) !== FALSE)
1055	{
1056		if(($close_xmp = strrpos($content, '</xmp>')) === FALSE)
1057		{
1058			$content .= '</xmp>';
1059		}
1060		else if($close_xmp < $start_xmp)
1061		{
1062			$content .= '</xmp>';
1063		}
1064	}
1065
1066	return $content;
1067}
1068
1069/**
1070 * Remove src hack(preg_replace_callback)
1071 *
1072 * @param array $match
1073 * @return string
1074 */
1075function removeSrcHack($match)
1076{
1077	$tag = strtolower($match[2]);
1078
1079	// xmp tag ?뺣━
1080	if($tag == 'xmp')
1081	{
1082		return "<{$match[1]}xmp>";
1083	}
1084	if($match[1])
1085	{
1086		return $match[0];
1087	}
1088	if($match[4])
1089	{
1090		$match[4] = ' ' . $match[4];
1091	}
1092
1093	$attrs = array();
1094	if(preg_match_all('/([\w:-]+)\s*=(?:\s*(["\']))?(?(2)(.*?)\2|([^ ]+))/s', $match[3], $m))
1095	{
1096		foreach($m[1] as $idx => $name)
1097		{
1098			if(strlen($name) >= 2 && substr_compare($name, 'on', 0, 2) === 0)
1099			{
1100				continue;
1101			}
1102
1103			$val = preg_replace('/&#(?:x([a-fA-F0-9]+)|0*(\d+));/e', 'chr("\\1"?0x00\\1:\\2+0)', $m[3][$idx] . $m[4][$idx]);
1104			$val = preg_replace('/^\s+|[\t\n\r]+/', '', $val);
1105
1106			if(preg_match('/^[a-z]+script:/i', $val))
1107			{
1108				continue;
1109			}
1110
1111			$attrs[$name] = $val;
1112		}
1113	}
1114
1115	if(isset($attrs['style']) && preg_match('@(?:/\*|\*/|\n|:\s*expression\s*\()@i', $attrs['style']))
1116	{
1117		unset($attrs['style']);
1118	}
1119
1120	$attr = array();
1121	foreach($attrs as $name => $val)
1122	{
1123		if($tag == 'object' || $tag == 'embed' || $tag == 'a')
1124		{
1125			$attribute = strtolower(trim($name));
1126			if($attribute == 'data' || $attribute == 'src' || $attribute == 'href')
1127			{
1128				if(stripos($val, 'data:') === 0)
1129				{
1130					continue;
1131				}
1132			}
1133		}
1134
1135		if($tag == 'img')
1136		{
1137			$attribute = strtolower(trim($name));
1138			if(stripos($val, 'data:') === 0)
1139			{
1140				continue;
1141			}
1142		}
1143		$val = str_replace('"', '&quot;', $val);
1144		$attr[] = $name . "=\"{$val}\"";
1145	}
1146	$attr = count($attr) ? ' ' . implode(' ', $attr) : '';
1147
1148	return "<{$match[1]}{$tag}{$attr}{$match[4]}>";
1149}
1150
1151// convert hexa value to RGB
1152if(!function_exists('hexrgb'))
1153{
1154
1155	/**
1156	 * Convert hexa value to RGB
1157	 *
1158	 * @param string $hexstr
1159	 * @return array
1160	 */
1161	function hexrgb($hexstr)
1162	{
1163		$int = hexdec($hexstr);
1164
1165		return array('red' => 0xFF & ($int >> 0x10),
1166			'green' => 0xFF & ($int >> 0x8),
1167			'blue' => 0xFF & $int);
1168	}
1169
1170}
1171
1172/**
1173 * Php function for mysql old_password()
1174 * provides backward compatibility for zero board4 which uses old_password() of mysql 4.1 earlier versions. 
1175 * the function implemented by referring to the source codes of password.c file in mysql
1176 *
1177 * @param string $password
1178 * @return string
1179 */
1180function mysql_pre4_hash_password($password)
1181{
1182	$nr = 1345345333;
1183	$add = 7;
1184	$nr2 = 0x12345671;
1185
1186	settype($password, "string");
1187
1188	for($i = 0; $i < strlen($password); $i++)
1189	{
1190		if($password[$i] == ' ' || $password[$i] == '\t')
1191		{
1192			continue;
1193		}
1194		$tmp = ord($password[$i]);
1195		$nr ^= ((($nr & 63) + $add) * $tmp) + ($nr << 8);
1196		$nr2 += ($nr2 << 8) ^ $nr;
1197		$add += $tmp;
1198	}
1199	$result1 = sprintf("%08lx", $nr & ((1 << 31) - 1));
1200	$result2 = sprintf("%08lx", $nr2 & ((1 << 31) - 1));
1201
1202	if($result1 == '80000000')
1203	{
1204		$nr += 0x80000000;
1205	}
1206	if($result2 == '80000000')
1207	{
1208		$nr2 += 0x80000000;
1209	}
1210
1211	return sprintf("%08lx%08lx", $nr, $nr2);
1212}
1213
1214/**
1215 * Return the requested script path
1216 *
1217 * @return string
1218 */
1219function getScriptPath()
1220{
1221	static $url = NULL;
1222	if($url == NULL)
1223	{
1224		$url = str_ireplace('/tools/', '/', preg_replace('/index.php$/i', '', str_replace('\\', '/', $_SERVER['SCRIPT_NAME'])));
1225	}
1226	return $url;
1227}
1228
1229/**
1230 * Return the requested script path
1231 *
1232 * @return string
1233 */
1234function getRequestUriByServerEnviroment()
1235{
1236	return str_replace('<', '&lt;', $_SERVER['REQUEST_URI']);
1237}
1238
1239/**
1240 * PHP unescape function of javascript's escape
1241 * Function converts an Javascript escaped string back into a string with specified charset (default is UTF-8).
1242 * Modified function from http://pure-essence.net/stuff/code/utf8RawUrlDecode.phps
1243 *
1244 * @param string $source
1245 * @return string
1246 */
1247function utf8RawUrlDecode($source)
1248{
1249	$decodedStr = '';
1250	$pos = 0;
1251	$len = strlen($source);
1252	while($pos < $len)
1253	{
1254		$charAt = substr($source, $pos, 1);
1255		if($charAt == '%')
1256		{
1257			$pos++;
1258			$charAt = substr($source, $pos, 1);
1259			if($charAt == 'u')
1260			{
1261				// we got a unicode character
1262				$pos++;
1263				$unicodeHexVal = substr($source, $pos, 4);
1264				$unicode = hexdec($unicodeHexVal);
1265				$decodedStr .= _code2utf($unicode);
1266				$pos += 4;
1267			}
1268			else
1269			{
1270				// we have an escaped ascii character
1271				$hexVal = substr($source, $pos, 2);
1272				$decodedStr .= chr(hexdec($hexVal));
1273				$pos += 2;
1274			}
1275		}
1276		else
1277		{
1278			$decodedStr .= $charAt;
1279			$pos++;
1280		}
1281	}
1282	return $decodedStr;
1283}
1284
1285/**
1286 * Returns utf-8 string of given code
1287 *
1288 * @param int $num
1289 * @return string
1290 */
1291function _code2utf($num)
1292{
1293	if($num < 128)
1294	{
1295		return chr($num);
1296	}
1297	if($num < 2048)
1298	{
1299		return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
1300	}
1301	if($num < 65536)
1302	{
1303		return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
1304	}
1305	if($num < 2097152)
1306	{
1307		return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
1308	}
1309	return '';
1310}
1311
1312/**
1313 * Get whether utf8 or not given string
1314 *
1315 * @param string $string
1316 * @param bool $return_convert If set, returns converted string
1317 * @param bool $urldecode
1318 * @return bool|string
1319 */
1320function detectUTF8($string, $return_convert = FALSE, $urldecode = TRUE)
1321{
1322	if($urldecode)
1323	{
1324		$string = urldecode($string);
1325	}
1326
1327	$sample = iconv('utf-8', 'utf-8', $string);
1328	$is_utf8 = (md5($sample) == md5($string));
1329
1330	if(!$urldecode)
1331	{
1332		$string = urldecode($string);
1333	}
1334
1335	if($return_convert)
1336	{
1337		return ($is_utf8) ? $string : iconv('euc-kr', 'utf-8', $string);
1338	}
1339
1340	return $is_utf8;
1341}
1342
1343/**
1344 * get json encoded string of data
1345 *
1346 * @param mixed $data
1347 * @return string
1348 */
1349function json_encode2($data)
1350{
1351	switch(gettype($data))
1352	{
1353		case 'boolean':
1354			return $data ? 'true' : 'false';
1355		case 'integer':
1356		case 'double':
1357			return $data;
1358		case 'string':
1359			return '"' . strtr($data, array('\\' => '\\\\', '"' => '\\"')) . '"';
1360		case 'object':
1361			$data = get_object_vars($data);
1362		case 'array':
1363			$rel = FALSE; // relative array?
1364			$key = array_keys($data);
1365			foreach($key as $v)
1366			{
1367				if(!is_int($v))
1368				{
1369					$rel = TRUE;
1370					break;
1371				}
1372			}
1373
1374			$arr = array();
1375			foreach($data as $k => $v)
1376			{
1377				$arr[] = ($rel ? '"' . strtr($k, array('\\' => '\\\\', '"' => '\\"')) . '":' : '') . json_encode2($v);
1378			}
1379
1380			return $rel ? '{' . join(',', $arr) . '}' : '[' . join(',', $arr) . ']';
1381		default:
1382			return '""';
1383	}
1384}
1385
1386/**
1387 * Get is current user crawler
1388 *
1389 * @param string $agent if set, use this value instead HTTP_USER_AGENT
1390 * @return bool
1391 */
1392function isCrawler($agent = NULL)
1393{
1394	if(!$agent)
1395	{
1396		$agent = $_SERVER['HTTP_USER_AGENT'];
1397	}
1398
1399	$check_agent = array('bot', 'spider', 'google', 'yahoo', 'daum', 'teoma', 'fish', 'hanrss', 'facebook');
1400	$check_ip = array(
1401		'211.245.21.110-211.245.21.119' /* mixsh */
1402	);
1403
1404	foreach($check_agent as $str)
1405	{
1406		if(stristr($agent, $str) != FALSE)
1407		{
1408			return TRUE;
1409		}
1410	}
1411
1412	return IpFilter::filter($check_ip);
1413}
1414
1415/**
1416 * Remove embed media for admin
1417 *
1418 * @param string $content
1419 * @param int $writer_member_srl
1420 * @return void
1421 */
1422function stripEmbedTagForAdmin(&$content, $writer_member_srl)
1423{
1424	if(!Context::get('is_logged'))
1425	{
1426		return;
1427	}
1428
1429	$oModuleModel = getModel('module');
1430	$logged_info = Context::get('logged_info');
1431
1432	if($writer_member_srl != $logged_info->member_srl && ($logged_info->is_admin == "Y" || $oModuleModel->isSiteAdmin($logged_info)))
1433	{
1434		if($writer_member_srl)
1435		{
1436			$oMemberModel = getModel('member');
1437			$member_info = $oMemberModel->getMemberInfoByMemberSrl($writer_member_srl);
1438			if($member_info->is_admin == "Y")
1439			{
1440				return;
1441			}
1442		}
1443		$security_msg = "<div style='border: 1px solid #DDD; background: #FAFAFA; text-align:center; margin: 1em 0;'><p style='margin: 1em;'>" . Context::getLang('security_warning_embed') . "</p></div>";
1444		$content = preg_replace('/<object[^>]+>(.*?<\/object>)?/is', $security_msg, $content);
1445		$content = preg_replace('/<embed[^>]+>(\s*<\/embed>)?/is', $security_msg, $content);
1446		$content = preg_replace('/<img[^>]+editor_component="multimedia_link"[^>]*>(\s*<\/img>)?/is', $security_msg, $content);
1447	}
1448
1449	return;
1450}
1451
1452/**
1453 * Require pear
1454 *
1455 * @return void
1456 */
1457function requirePear()
1458{
1459	if(version_compare(PHP_VERSION, "5.3.0") < 0)
1460	{
1461		set_include_path(_XE_PATH_ . "libs/PEAR");
1462	}
1463	else
1464	{
1465		set_include_path(_XE_PATH_ . "libs/PEAR.1.9");
1466	}
1467}
1468
1469function checkCSRF()
1470{
1471	if($_SERVER['REQUEST_METHOD'] != 'POST')
1472	{
1473		return FALSE;
1474	}
1475
1476	$defaultUrl = Context::getDefaultUrl();
1477	$referer = parse_url($_SERVER["HTTP_REFERER"]);
1478
1479	$oModuleModel = getModel('module');
1480	$siteModuleInfo = $oModuleModel->getDefaultMid();
1481
1482	if($siteModuleInfo->site_srl == 0)
1483	{
1484		if(!strstr(strtolower($defaultUrl), strtolower($referer['host'])))
1485		{
1486			return FALSE;
1487		}
1488	}
1489	else
1490	{
1491		$virtualSiteInfo = $oModuleModel->getSiteInfo($siteModuleInfo->site_srl);
1492		if(strtolower($virtualSiteInfo->domain) != strtolower(Context::get('vid')) && !strstr(strtolower($virtualSiteInfo->domain), strtolower($referer['host'])))
1493		{
1494			return FALSE;
1495		}
1496	}
1497
1498	return TRUE;
1499}
1500
1501/**
1502 * menu exposure check by isShow column
1503 * @param array $menu
1504 * @return void
1505 */
1506function recurciveExposureCheck(&$menu)
1507{
1508	if(is_array($menu))
1509	{
1510		foreach($menu AS $key=>$value)
1511		{
1512			if(!$value['isShow'])
1513			{
1514				unset($menu[$key]);
1515			}
1516			if(is_array($value['list']) && count($value['list']) > 0)
1517			{
1518				recurciveExposureCheck($menu[$key]['list']);
1519			}
1520		}
1521	}
1522}
1523
1524function changeValueInUrl($key, $requestKey, $dbKey, $urlName = 'success_return_url')
1525{
1526	if($requestKey != $dbKey)
1527	{
1528		$arrayUrl = parse_url(Context::get('success_return_url'));
1529		if($arrayUrl['query'])
1530		{
1531			parse_str($arrayUrl['query'], $parsedStr);
1532
1533			if(isset($parsedStr[$key]))
1534			{
1535				$parsedStr[$key] = $requestKey;
1536				$successReturnUrl .= $arrayUrl['path'].'?'.http_build_query($parsedStr);
1537				Context::set($urlName, $successReturnUrl);
1538			}
1539		}
1540	}
1541}
1542
1543/**
1544 * Print raw html header
1545 *
1546 * @return void
1547 */
1548function htmlHeader()
1549{
1550	echo '<!DOCTYPE html>
1551<html lang="ko">
1552<head>
1553<meta charset="utf-8" />
1554</head>
1555<body>';
1556}
1557
1558/**
1559 * Print raw html footer
1560 *
1561 * @return void
1562 */
1563function htmlFooter()
1564{
1565	echo '</body></html>';
1566}
1567
1568/**
1569 * Print raw alert message script
1570 *
1571 * @param string $msg
1572 * @return void
1573 */
1574function alertScript($msg)
1575{
1576	if(!$msg)
1577	{
1578		return;
1579	}
1580
1581	echo '<script type="text/javascript">
1582//<![CDATA[
1583alert("' . $msg . '");
1584//]]>
1585</script>';
1586}
1587
1588/**
1589 * Print raw close window script
1590 *
1591 * @return void
1592 */
1593function closePopupScript()
1594{
1595	echo '<script type="text/javascript">
1596//<![CDATA[
1597window.close();
1598//]]>
1599</script>';
1600}
1601
1602/**
1603 * Print raw reload script
1604 *
1605 * @param bool $isOpener
1606 * @return void
1607 */
1608function reload($isOpener = FALSE)
1609{
1610	$reloadScript = $isOpener ? 'window.opener.location.reload()' : 'document.location.reload()';
1611
1612	echo '<script type="text/javascript">
1613//<![CDATA[
1614' . $reloadScript . '
1615//]]>
1616</script>';
1617}
1618
1619/* End of file func.inc.php */
1620/* Location: ./config/func.inc.php */