PageRenderTime 59ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

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