From 82f776b035ed002e7069d5571bc1a9b2599e7219 Mon Sep 17 00:00:00 2001 From: Arcturus Date: Thu, 19 Sep 2024 20:46:45 +0900 Subject: [PATCH] update lib/hook --- AvocadoEdition_Light/lib/Hook/hook.class.php | 326 ++ .../lib/Hook/hook.extends.class.php | 167 + AvocadoEdition_Light/lib/common.lib.php | 4143 +++++++++-------- 3 files changed, 2575 insertions(+), 2061 deletions(-) create mode 100644 AvocadoEdition_Light/lib/Hook/hook.class.php create mode 100644 AvocadoEdition_Light/lib/Hook/hook.extends.class.php diff --git a/AvocadoEdition_Light/lib/Hook/hook.class.php b/AvocadoEdition_Light/lib/Hook/hook.class.php new file mode 100644 index 0000000..89746a2 --- /dev/null +++ b/AvocadoEdition_Light/lib/Hook/hook.class.php @@ -0,0 +1,326 @@ + + * @copyright 2017 (c) Josantonius - PHP-Hook + * @license https://opensource.org/licenses/MIT - The MIT License (MIT) + * @link https://github.com/Josantonius/PHP-Hook + * @since 1.0.0 + */ + +/** + * Hook handler. + * + * @since 1.0.0 + */ +class Hook +{ + /** + * Instance id. + * + * @since 1.0.5 + * + * @var int + */ + protected static $id = '0'; + + /** + * Callbacks. + * + * @since 1.0.3 + * + * @var array + */ + protected $callbacks = array(); + + /** + * Number of actions executed. + * + * @since 1.0.3 + * + * @var array + */ + protected $actions = array('count' => 0); + + /** + * Current action hook. + * + * @since 1.0.3 + * + * @var string|false + */ + protected static $current = false; + + /** + * Method to use the singleton pattern and just create an instance. + * + * @since 1.0.0 + * + * @var string + */ + protected $singleton = 'getInstance'; + + /** + * Instances. + * + * @since 1.0.0 + * + * @var array + */ + private static $instances = array(); + + /** + * Get instance. + * + * @since 1.0.0 + * + * @param int $id + * + * @return object → instance + */ + // 이부분 수정 + /* + public static function getInstance($id = '0') + { + self::$id = $id; + if (isset(self::$instances[self::$id])) { + return self::$instances[self::$id]; + } + + return self::$instances[self::$id] = new self; + } + */ + + public static function getInstance($id = '0') + { + self::$id = $id; + if (isset(self::$instances[self::$id])) { + return self::$instances[self::$id]; + } + + $calledClass = get_called_class(); + + return self::$instances[self::$id] = new $calledClass; + } + + /** + * Attach custom function to action hook. + * + * @since 1.0.3 + * + * @param string $tag → action hook name + * @param callable $func → function to attach to action hook + * @param int $priority → order in which the action is executed + * @param int $args → number of arguments accepted + * + * @return bool + */ + public static function addAction($tag, $func, $priority = 8, $args = 0) + { + $that = self::getInstance(self::$id); + + $that->callbacks[$tag][$priority][] = array( + 'function' => $func, + 'arguments' => $args, + ); + + return true; + } + + /** + * Add actions hooks from array. + * + * @since 1.0.3 + * + * @param array $actions + * + * @return bool + */ + public static function addActions($actions) + { + foreach ($actions as $arguments) { + call_user_func_array(array(__CLASS__, 'addAction'), $arguments); + } + + return true; + } + + /** + * Run all hooks attached to the hook. + * + * By default it will look for getInstance method to use singleton + * pattern and create a single instance of the class. If it does not + * exist it will create a new object. + * + * @see setSingletonName() for change the method name. + * + * @since 1.0.3 + * + * @param string $tag → action hook name + * @param mixed $args → optional arguments + * @param bool $remove → delete hook after executing actions + * + * @return returns the output of the last action or false + */ + public static function doAction($tag, $args = array(), $remove = true) + { + $that = self::getInstance(self::$id); + + self::$current = $tag; + + $that->actions['count']++; + + if (!array_key_exists($tag, $that->actions)) { + $that->actions[$tag] = 0; + } + + $that->actions[$tag]++; + $actions = $that->getActions($tag, $remove); + //asort($actions); + // 이 부분 수정 priority 로 정렬 하려면 ksort를 써야함 + ksort($actions); + + foreach ($actions as $priority) { + foreach ($priority as $action) { + $action = $that->runAction($action, $args); + } + } + + self::$current = false; + + return (isset($action)) ? $action : false; + } + + /** + * Set method name for use singleton pattern. + * + * @since 1.0.0 + * + * @param string $method → singleton method name + */ + public static function setSingletonName($method) + { + $that = self::getInstance(self::$id); + + $that->singleton = $method; + } + + /** + * Returns the current action hook. + * + * @since 1.0.3 + * + * @return string|false → current action hook + */ + public static function current() + { + return self::$current; + } + + /** + * Check if there is a certain action hook. + * + * @since 1.0.7 + * + * @param string $tag → action hook name + * + * @return bool + */ + public static function isAction($tag) + { + $that = self::getInstance(self::$id); + + return isset($that->callbacks[$tag]); + } + + /** + * Run action hook. + * + * @since 1.0.3 + * + * @param string $action → action hook + * @param int $args → arguments + * + * @return callable|false → returns the calling function + */ + protected function runAction($action, $args) + { + $function = $action['function']; + $argsNumber = $action['arguments']; + + $class = (isset($function[0])) ? $function[0] : false; + $method = (isset($function[1])) ? $function[1] : false; + + $args = $this->getArguments($argsNumber, $args); + + if (!($class && $method) && function_exists($function)) { + return call_user_func($function, $args); + } elseif ($obj = call_user_func(array($class, $this->singleton))) { + if ($obj !== false) { + return call_user_func_array(array($obj, $method), $args); + } + } elseif (class_exists($class)) { + $instance = new $class; + + return call_user_func_array(array($instance, $method), $args); + } + + return null; + } + + /** + * Get actions for hook + * + * @since 1.0.3 + * + * @param string $tag → action hook name + * @param bool $remove → delete hook after executing actions + * + * @return object|false → returns the calling function + */ + protected function getActions($tag, $remove) + { + if (isset($this->callbacks[$tag])) { + $actions = $this->callbacks[$tag]; + if ($remove) { + unset($this->callbacks[$tag]); + } + } + + return (isset($actions)) ? $actions : array(); + } + + /** + * Get arguments for action. + * + * @since 1.0.3 + * + * @param int $argsNumber → arguments number + * @param mixed $arguments → arguments + * + * @return array → arguments + */ + protected function getArguments($argsNumber, $arguments) + { + if ($argsNumber == 1 && is_string($arguments)) { + return array($arguments); + } elseif ($argsNumber === count($arguments)) { + return $arguments; + } + + for ($i = 0; $i < $argsNumber; $i++) { + if (array_key_exists($i, $arguments)) { + $args[] = $arguments[$i]; + continue; + } + + return $args; + } + + return array(); + } +} diff --git a/AvocadoEdition_Light/lib/Hook/hook.extends.class.php b/AvocadoEdition_Light/lib/Hook/hook.extends.class.php new file mode 100644 index 0000000..95ab392 --- /dev/null +++ b/AvocadoEdition_Light/lib/Hook/hook.extends.class.php @@ -0,0 +1,167 @@ + 0); + + protected $callback_filters = array(); + + protected static $current_filter = false; + + protected function runAction($action, $args) + { + $function = $action['function']; + $argsNumber = $action['arguments']; + + $class = (is_array($function) && isset($function[0])) ? $function[0] : false; + $method = (is_array($function) && isset($function[1])) ? $function[1] : false; + + $args = $this->getArguments($argsNumber, $args); + + if (!($class && $method) && is_callable($function)) { + return call_user_func_array($function, $args); + } elseif ($obj = call_user_func(array($class, $this->singleton))) { + if ($obj !== false) { + return call_user_func_array(array($obj, $method), $args); + } + } elseif (class_exists($class)) { + $instance = new $class; + + return call_user_func_array(array($instance, $method), $args); + } + } + + protected function getFilters($tag, $remove) + { + if (isset($this->callback_filters[$tag])) { + $filters = $this->callback_filters[$tag]; + if ($remove) { + unset($this->callback_filters[$tag]); + } + } + + return (isset($filters)) ? $filters : array(); + } + + public static function get_properties($type, $is_callback = false) + { + + $that = self::getInstance(self::$id); + + if ($type === 'event') { + return $is_callback ? $that->callbacks : $that->actions; + } + + return $is_callback ? $that->callback_filters : $that->filters; + } + + public static function addFilter($tag, $func, $priority = 8, $args = 0) + { + $that = self::getInstance(self::$id); + + $that->callback_filters[$tag][$priority][] = array( + 'function' => $func, + 'arguments' => $args, + ); + + return true; + } + + public static function apply_filters($tag, $args = array(), $remove = true) + { + $that = self::getInstance(self::$id); + + self::$current_filter = $tag; + + $that->filters['count']++; + + if (!array_key_exists($tag, $that->filters)) { + $that->filters[$tag] = 0; + } + + $that->filters[$tag]++; + $filters = $that->getFilters($tag, $remove); + ksort($filters); + + $value = $args[0]; + + foreach ($filters as $priority) { + foreach ($priority as $filter) { + if (isset($args[0])) { + $args[0] = $value; + } + $replace = $that->runAction($filter, $args); + + if (!is_null($replace)) { + $value = $replace; + } + } + } + + self::$current_filter = false; + + return $value; + } + + protected function getArguments($argsNumber, $arguments) + { + if ($argsNumber == 1 && is_string($arguments)) { + return array($arguments); + } elseif ($argsNumber === count($arguments)) { + return $arguments; + } + + $args = array(); + + for ($i = 0; $i < $argsNumber; $i++) { + if (is_array($arguments) && array_key_exists($i, $arguments)) { + $args[] = $arguments[$i]; + } + } + + return $args; + } + + public static function remove_filter($tag, $func, $priority) + { + $that = self::getInstance(self::$id); + + $is_remove = false; + + if (isset($that->callback_filters[$tag]) && isset($that->callback_filters[$tag][$priority])) { + + foreach ((array) $that->callback_filters[$tag][$priority] as $key => $value) { + if (isset($value['function']) && $value['function'] === $func) { + unset($that->callback_filters[$tag][$priority][$key]); + $is_remove = true; + } + } + } + + return $is_remove; + } + + public static function remove_action($tag, $func, $priority) + { + $that = self::getInstance(self::$id); + + $is_remove = false; + + if (isset($that->callbacks[$tag]) && isset($that->callbacks[$tag][$priority])) { + + foreach ((array) $that->callbacks[$tag][$priority] as $key => $value) { + if (isset($value['function']) && $value['function'] === $func) { + unset($that->callbacks[$tag][$priority][$key]); + $is_remove = true; + } + } + } + + return $is_remove; + } +} + +// end Hook Class; diff --git a/AvocadoEdition_Light/lib/common.lib.php b/AvocadoEdition_Light/lib/common.lib.php index 58947e2..19604db 100644 --- a/AvocadoEdition_Light/lib/common.lib.php +++ b/AvocadoEdition_Light/lib/common.lib.php @@ -1,95 +1,100 @@ 1) { - $str .= 'keyboard_double_arrow_left'.PHP_EOL; - } + $str = ''; + if ($cur_page > 1) { + $str .= 'keyboard_double_arrow_left' . PHP_EOL; + } - $start_page = ( ( (int)( ($cur_page - 1 ) / $write_pages ) ) * $write_pages ) + 1; - $end_page = $start_page + $write_pages - 1; + $start_page = (((int) (($cur_page - 1) / $write_pages)) * $write_pages) + 1; + $end_page = $start_page + $write_pages - 1; - if ($end_page >= $total_page) $end_page = $total_page; - if ($start_page > 1) $str .= 'navigate_before'.PHP_EOL; + if ($end_page >= $total_page) + $end_page = $total_page; + if ($start_page > 1) + $str .= 'navigate_before' . PHP_EOL; - if ($total_page > 1) { - $str .= ""; - for ($k=$start_page;$k<=$end_page;$k++) { - if ($cur_page != $k) - $str .= ''.$k.''.PHP_EOL; - else - $str .= ''.$k.''.PHP_EOL; - } - $str .= ""; - } + if ($total_page > 1) { + $str .= ""; + for ($k = $start_page; $k <= $end_page; $k++) { + if ($cur_page != $k) + $str .= '' . $k . '' . PHP_EOL; + else + $str .= '' . $k . '' . PHP_EOL; + } + $str .= ""; + } - if ($total_page > $end_page) $str .= 'navigate_next'.PHP_EOL; - if ($cur_page < $total_page) { - $str .= 'keyboard_double_arrow_right'.PHP_EOL; - } + if ($total_page > $end_page) + $str .= 'navigate_next' . PHP_EOL; + if ($cur_page < $total_page) { + $str .= 'keyboard_double_arrow_right' . PHP_EOL; + } - if ($str) - return ""; - else - return ""; + if ($str) + return ""; + else + return ""; } // 페이징 코드의 태그 이전에 코드를 삽입 function page_insertafter($paging_html, $insert_html) { - if(!$paging_html) - $paging_html = ''; + if (!$paging_html) + $paging_html = ''; - if(preg_match("#".PHP_EOL."#", $paging_html)) - $php_eol = ''; - else - $php_eol = PHP_EOL; + if (preg_match("#" . PHP_EOL . "#", $paging_html)) + $php_eol = ''; + else + $php_eol = PHP_EOL; - return preg_replace("#()$#", $php_eol.$insert_html.'$1', $paging_html); + return preg_replace("#()$#", $php_eol . $insert_html . '$1', $paging_html); } // 변수 또는 배열의 이름과 값을 얻어냄. print_r() 함수의 변형 function print_r2($var) { - ob_start(); - print_r($var); - $str = ob_get_contents(); - ob_end_clean(); - $str = str_replace(" ", " ", $str); - echo nl2br("$str"); + ob_start(); + print_r($var); + $str = ob_get_contents(); + ob_end_clean(); + $str = str_replace(" ", " ", $str); + echo nl2br("$str"); } @@ -97,168 +102,171 @@ function print_r2($var) // header("location:URL") 을 대체 function goto_url($url) { - $url = str_replace("&", "&", $url); - //echo ""; + $url = str_replace("&", "&", $url); + //echo ""; - if (!headers_sent()) - header('Location: '.$url); - else { - echo ''; - echo ''; - } - exit; + if (!headers_sent()) + header('Location: ' . $url); + else { + echo ''; + echo ''; + } + exit; } // 세션변수 생성 function set_session($session_name, $value) { - if (PHP_VERSION < '5.3.0') - session_register($session_name); - // PHP 버전별 차이를 없애기 위한 방법 - $$session_name = $_SESSION[$session_name] = $value; + if (PHP_VERSION < '5.3.0') + session_register($session_name); + // PHP 버전별 차이를 없애기 위한 방법 + $$session_name = $_SESSION[$session_name] = $value; } // 세션변수값 얻음 function get_session($session_name) { - return isset($_SESSION[$session_name]) ? $_SESSION[$session_name] : ''; + return isset($_SESSION[$session_name]) ? $_SESSION[$session_name] : ''; } // 쿠키변수 생성 function set_cookie($cookie_name, $value, $expire) { - global $g5; + global $g5; - setcookie(md5($cookie_name), base64_encode($value), G5_SERVER_TIME + $expire, '/', G5_COOKIE_DOMAIN); + setcookie(md5($cookie_name), base64_encode($value), G5_SERVER_TIME + $expire, '/', G5_COOKIE_DOMAIN); } // 쿠키변수값 얻음 function get_cookie($cookie_name) { - $cookie = md5($cookie_name); - if (array_key_exists($cookie, $_COOKIE)) - return base64_decode($_COOKIE[$cookie]); - else - return ""; + $cookie = md5($cookie_name); + if (array_key_exists($cookie, $_COOKIE)) + return base64_decode($_COOKIE[$cookie]); + else + return ""; } // 경고메세지를 경고창으로 -function alert($msg='', $url='', $error=true, $post=false) +function alert($msg = '', $url = '', $error = true, $post = false) { - global $g5, $config, $member; - global $is_admin; + global $g5, $config, $member; + global $is_admin; - if (!$msg) $msg = '올바른 방법으로 이용해 주십시오.'; + if (!$msg) + $msg = '올바른 방법으로 이용해 주십시오.'; - $header = ''; - if (isset($g5['title'])) { - $header = $g5['title']; - } - include_once(G5_BBS_PATH.'/alert.php'); - exit; + $header = ''; + if (isset($g5['title'])) { + $header = $g5['title']; + } + include_once(G5_BBS_PATH . '/alert.php'); + exit; } // 경고메세지 출력후 창을 닫음 -function alert_close($msg, $error=true) +function alert_close($msg, $error = true) { - global $g5; + global $g5; - $header = ''; - if (isset($g5['title'])) { - $header = $g5['title']; - } - include_once(G5_BBS_PATH.'/alert_close.php'); - exit; + $header = ''; + if (isset($g5['title'])) { + $header = $g5['title']; + } + include_once(G5_BBS_PATH . '/alert_close.php'); + exit; } // confirm 창 -function confirm($msg, $url1='', $url2='', $url3='') +function confirm($msg, $url1 = '', $url2 = '', $url3 = '') { - global $g5; + global $g5; - if (!$msg) { - $msg = '올바른 방법으로 이용해 주십시오.'; - alert($msg); - } + if (!$msg) { + $msg = '올바른 방법으로 이용해 주십시오.'; + alert($msg); + } - if(!trim($url1) || !trim($url2)) { - $msg = '$url1 과 $url2 를 지정해 주세요.'; - alert($msg); - } + if (!trim($url1) || !trim($url2)) { + $msg = '$url1 과 $url2 를 지정해 주세요.'; + alert($msg); + } - if (!$url3) $url3 = clean_xss_tags($_SERVER['HTTP_REFERER']); + if (!$url3) + $url3 = clean_xss_tags($_SERVER['HTTP_REFERER']); - $msg = str_replace("\\n", "
", $msg); + $msg = str_replace("\\n", "
", $msg); - $header = ''; - if (isset($g5['title'])) { - $header = $g5['title']; - } - include_once(G5_BBS_PATH.'/confirm.php'); - exit; + $header = ''; + if (isset($g5['title'])) { + $header = $g5['title']; + } + include_once(G5_BBS_PATH . '/confirm.php'); + exit; } // way.co.kr 의 wayboard 참고 function url_auto_link($str) { - global $g5; - global $config; + global $g5; + global $config; - // 140326 유창화님 제안코드로 수정 - // http://sir.kr/pg_lecture/461 - // http://sir.kr/pg_lecture/463 - $str = str_replace(array("<", ">", "&", """, " ", "'"), array("\t_lt_\t", "\t_gt_\t", "&", "\"", "\t_nbsp_\t", "'"), $str); - //$str = preg_replace("`(?:(?:(?:href|src)\s*=\s*(?:\"|'|)){0})((http|https|ftp|telnet|news|mms)://[^\"'\s()]+)`", "\\1", $str); - $str = preg_replace("/([^(href=\"?'?)|(src=\"?'?)]|\(|^)((http|https|ftp|telnet|news|mms):\/\/[a-zA-Z0-9\.-]+\.[가-힣\xA1-\xFEa-zA-Z0-9\.:&#=_\?\/~\+%@;\-\|\,\(\)]+)/i", "\\1\\2", $str); - $str = preg_replace("/(^|[\"'\s(])(www\.[^\"'\s()]+)/i", "\\1\\2", $str); - $str = preg_replace("/[0-9a-z_-]+@[a-z0-9._-]{4,}/i", "\\0", $str); - $str = str_replace(array("\t_nbsp_\t", "\t_lt_\t", "\t_gt_\t", "'"), array(" ", "<", ">", "'"), $str); + // 140326 유창화님 제안코드로 수정 + // http://sir.kr/pg_lecture/461 + // http://sir.kr/pg_lecture/463 + $str = str_replace(array("<", ">", "&", """, " ", "'"), array("\t_lt_\t", "\t_gt_\t", "&", "\"", "\t_nbsp_\t", "'"), $str); + //$str = preg_replace("`(?:(?:(?:href|src)\s*=\s*(?:\"|'|)){0})((http|https|ftp|telnet|news|mms)://[^\"'\s()]+)`", "\\1", $str); + $str = preg_replace("/([^(href=\"?'?)|(src=\"?'?)]|\(|^)((http|https|ftp|telnet|news|mms):\/\/[a-zA-Z0-9\.-]+\.[가-힣\xA1-\xFEa-zA-Z0-9\.:&#=_\?\/~\+%@;\-\|\,\(\)]+)/i", "\\1\\2", $str); + $str = preg_replace("/(^|[\"'\s(])(www\.[^\"'\s()]+)/i", "\\1\\2", $str); + $str = preg_replace("/[0-9a-z_-]+@[a-z0-9._-]{4,}/i", "\\0", $str); + $str = str_replace(array("\t_nbsp_\t", "\t_lt_\t", "\t_gt_\t", "'"), array(" ", "<", ">", "'"), $str); - /* - // 속도 향상 031011 - $str = preg_replace("/</", "\t_lt_\t", $str); - $str = preg_replace("/>/", "\t_gt_\t", $str); - $str = preg_replace("/&/", "&", $str); - $str = preg_replace("/"/", "\"", $str); - $str = preg_replace("/ /", "\t_nbsp_\t", $str); - $str = preg_replace("/([^(http:\/\/)]|\(|^)(www\.[^[:space:]]+)/i", "\\1\\2", $str); - //$str = preg_replace("/([^(HREF=\"?'?)|(SRC=\"?'?)]|\(|^)((http|https|ftp|telnet|news|mms):\/\/[a-zA-Z0-9\.-]+\.[\xA1-\xFEa-zA-Z0-9\.:&#=_\?\/~\+%@;\-\|\,]+)/i", "\\1\\2", $str); - // 100825 : () 추가 - // 120315 : CHARSET 에 따라 링크시 글자 잘림 현상이 있어 수정 - $str = preg_replace("/([^(HREF=\"?'?)|(SRC=\"?'?)]|\(|^)((http|https|ftp|telnet|news|mms):\/\/[a-zA-Z0-9\.-]+\.[가-힣\xA1-\xFEa-zA-Z0-9\.:&#=_\?\/~\+%@;\-\|\,\(\)]+)/i", "\\1\\2", $str); + /* + // 속도 향상 031011 + $str = preg_replace("/</", "\t_lt_\t", $str); + $str = preg_replace("/>/", "\t_gt_\t", $str); + $str = preg_replace("/&/", "&", $str); + $str = preg_replace("/"/", "\"", $str); + $str = preg_replace("/ /", "\t_nbsp_\t", $str); + $str = preg_replace("/([^(http:\/\/)]|\(|^)(www\.[^[:space:]]+)/i", "\\1\\2", $str); + //$str = preg_replace("/([^(HREF=\"?'?)|(SRC=\"?'?)]|\(|^)((http|https|ftp|telnet|news|mms):\/\/[a-zA-Z0-9\.-]+\.[\xA1-\xFEa-zA-Z0-9\.:&#=_\?\/~\+%@;\-\|\,]+)/i", "\\1\\2", $str); + // 100825 : () 추가 + // 120315 : CHARSET 에 따라 링크시 글자 잘림 현상이 있어 수정 + $str = preg_replace("/([^(HREF=\"?'?)|(SRC=\"?'?)]|\(|^)((http|https|ftp|telnet|news|mms):\/\/[a-zA-Z0-9\.-]+\.[가-힣\xA1-\xFEa-zA-Z0-9\.:&#=_\?\/~\+%@;\-\|\,\(\)]+)/i", "\\1\\2", $str); - // 이메일 정규표현식 수정 061004 - //$str = preg_replace("/(([a-z0-9_]|\-|\.)+@([^[:space:]]*)([[:alnum:]-]))/i", "\\1", $str); - $str = preg_replace("/([0-9a-z]([-_\.]?[0-9a-z])*@[0-9a-z]([-_\.]?[0-9a-z])*\.[a-z]{2,4})/i", "\\1", $str); - $str = preg_replace("/\t_nbsp_\t/", " " , $str); - $str = preg_replace("/\t_lt_\t/", "<", $str); - $str = preg_replace("/\t_gt_\t/", ">", $str); - */ + // 이메일 정규표현식 수정 061004 + //$str = preg_replace("/(([a-z0-9_]|\-|\.)+@([^[:space:]]*)([[:alnum:]-]))/i", "\\1", $str); + $str = preg_replace("/([0-9a-z]([-_\.]?[0-9a-z])*@[0-9a-z]([-_\.]?[0-9a-z])*\.[a-z]{2,4})/i", "\\1", $str); + $str = preg_replace("/\t_nbsp_\t/", " " , $str); + $str = preg_replace("/\t_lt_\t/", "<", $str); + $str = preg_replace("/\t_gt_\t/", ">", $str); + */ - return $str; + return $str; } // url에 http:// 를 붙인다 function set_http($url) { - if (!trim($url)) return; + if (!trim($url)) + return; - if (!preg_match("/^(http|https|ftp|telnet|news|mms)\:\/\//i", $url)) - $url = "http://" . $url; + if (!preg_match("/^(http|https|ftp|telnet|news|mms)\:\/\//i", $url)) + $url = "http://" . $url; - return $url; + return $url; } @@ -266,278 +274,275 @@ function set_http($url) //function get_filesize($file) function get_filesize($size) { - //$size = @filesize(addslashes($file)); - if ($size >= 1048576) { - $size = number_format($size/1048576, 1) . "M"; - } else if ($size >= 1024) { - $size = number_format($size/1024, 1) . "K"; - } else { - $size = number_format($size, 0) . "byte"; - } - return $size; + //$size = @filesize(addslashes($file)); + if ($size >= 1048576) { + $size = number_format($size / 1048576, 1) . "M"; + } else if ($size >= 1024) { + $size = number_format($size / 1024, 1) . "K"; + } else { + $size = number_format($size, 0) . "byte"; + } + return $size; } // 게시글에 첨부된 파일을 얻는다. (배열로 반환) function get_file($bo_table, $wr_id) { - global $g5, $qstr; + global $g5, $qstr; - $file['count'] = 0; - $sql = " select * from {$g5['board_file_table']} where bo_table = '$bo_table' and wr_id = '$wr_id' order by bf_no "; - $result = sql_query($sql); - while ($row = sql_fetch_array($result)) - { - $no = $row['bf_no']; - $file[$no]['href'] = G5_BBS_URL."/download.php?bo_table=$bo_table&wr_id=$wr_id&no=$no" . $qstr; - $file[$no]['download'] = $row['bf_download']; - // 4.00.11 - 파일 path 추가 - $file[$no]['path'] = G5_DATA_URL.'/file/'.$bo_table; - $file[$no]['size'] = get_filesize($row['bf_filesize']); - $file[$no]['datetime'] = $row['bf_datetime']; - $file[$no]['source'] = addslashes($row['bf_source']); - $file[$no]['bf_content'] = $row['bf_content']; - $file[$no]['content'] = get_text($row['bf_content']); - //$file[$no]['view'] = view_file_link($row['bf_file'], $file[$no]['content']); - $file[$no]['view'] = view_file_link($row['bf_file'], $row['bf_width'], $row['bf_height'], $file[$no]['content']); - $file[$no]['file'] = $row['bf_file']; - $file[$no]['image_width'] = $row['bf_width'] ? $row['bf_width'] : 640; - $file[$no]['image_height'] = $row['bf_height'] ? $row['bf_height'] : 480; - $file[$no]['image_type'] = $row['bf_type']; - $file['count']++; - } + $file['count'] = 0; + $sql = " select * from {$g5['board_file_table']} where bo_table = '$bo_table' and wr_id = '$wr_id' order by bf_no "; + $result = sql_query($sql); + while ($row = sql_fetch_array($result)) { + $no = $row['bf_no']; + $file[$no]['href'] = G5_BBS_URL . "/download.php?bo_table=$bo_table&wr_id=$wr_id&no=$no" . $qstr; + $file[$no]['download'] = $row['bf_download']; + // 4.00.11 - 파일 path 추가 + $file[$no]['path'] = G5_DATA_URL . '/file/' . $bo_table; + $file[$no]['size'] = get_filesize($row['bf_filesize']); + $file[$no]['datetime'] = $row['bf_datetime']; + $file[$no]['source'] = addslashes($row['bf_source']); + $file[$no]['bf_content'] = $row['bf_content']; + $file[$no]['content'] = get_text($row['bf_content']); + //$file[$no]['view'] = view_file_link($row['bf_file'], $file[$no]['content']); + $file[$no]['view'] = view_file_link($row['bf_file'], $row['bf_width'], $row['bf_height'], $file[$no]['content']); + $file[$no]['file'] = $row['bf_file']; + $file[$no]['image_width'] = $row['bf_width'] ? $row['bf_width'] : 640; + $file[$no]['image_height'] = $row['bf_height'] ? $row['bf_height'] : 480; + $file[$no]['image_type'] = $row['bf_type']; + $file['count']++; + } - return $file; + return $file; } // 폴더의 용량 ($dir는 / 없이 넘기세요) function get_dirsize($dir) { - $size = 0; - $d = dir($dir); - while ($entry = $d->read()) { - if ($entry != '.' && $entry != '..') { - $size += filesize($dir.'/'.$entry); - } - } - $d->close(); - return $size; + $size = 0; + $d = dir($dir); + while ($entry = $d->read()) { + if ($entry != '.' && $entry != '..') { + $size += filesize($dir . '/' . $entry); + } + } + $d->close(); + return $size; } /************************************************************************* -** -** 그누보드 관련 함수 모음 -** -*************************************************************************/ + ** + ** 그누보드 관련 함수 모음 + ** + *************************************************************************/ // 게시물 정보($write_row)를 출력하기 위하여 $list로 가공된 정보를 복사 및 가공 -function get_list($write_row, $board, $skin_url, $subject_len=40) +function get_list($write_row, $board, $skin_url, $subject_len = 40) { - global $g5, $config; - global $qstr, $page; + global $g5, $config; + global $qstr, $page; - //$t = get_microtime(); + //$t = get_microtime(); - // 배열전체를 복사 - $list = $write_row; - unset($write_row); + // 배열전체를 복사 + $list = $write_row; + unset($write_row); - $board_notice = array_map('trim', explode(',', $board['bo_notice'])); - $list['is_notice'] = in_array($list['wr_id'], $board_notice); + $board_notice = array_map('trim', explode(',', $board['bo_notice'])); + $list['is_notice'] = in_array($list['wr_id'], $board_notice); - if ($subject_len) - $list['subject'] = conv_subject($list['wr_subject'], $subject_len, '…'); - else - $list['subject'] = conv_subject($list['wr_subject'], $board['bo_subject_len'], '…'); + if ($subject_len) + $list['subject'] = conv_subject($list['wr_subject'], $subject_len, '…'); + else + $list['subject'] = conv_subject($list['wr_subject'], $board['bo_subject_len'], '…'); - // 목록에서 내용 미리보기 사용한 게시판만 내용을 변환함 (속도 향상) : kkal3(커피)님께서 알려주셨습니다. - if ($board['bo_use_list_content'] || $board['bo_type'] == 'mmb') - { - $html = 0; - if (strstr($list['wr_option'], 'html1')) - $html = 1; - else if (strstr($list['wr_option'], 'html2')) - $html = 2; + // 목록에서 내용 미리보기 사용한 게시판만 내용을 변환함 (속도 향상) : kkal3(커피)님께서 알려주셨습니다. + if ($board['bo_use_list_content'] || $board['bo_type'] == 'mmb') { + $html = 0; + if (strstr($list['wr_option'], 'html1')) + $html = 1; + else if (strstr($list['wr_option'], 'html2')) + $html = 2; - $list['content'] = conv_content($list['wr_content'], $html); - } + $list['content'] = conv_content($list['wr_content'], $html); + } - $list['comment_cnt'] = ''; - if ($list['wr_comment']) - $list['comment_cnt'] = "".$list['wr_comment'].""; + $list['comment_cnt'] = ''; + if ($list['wr_comment']) + $list['comment_cnt'] = "" . $list['wr_comment'] . ""; - // 당일인 경우 시간으로 표시함 - $list['datetime'] = substr($list['wr_datetime'],0,10); - $list['datetime2'] = $list['wr_datetime']; - if ($list['datetime'] == G5_TIME_YMD) - $list['datetime2'] = substr($list['datetime2'],11,5); - else - $list['datetime2'] = substr($list['datetime2'],5,5); - // 4.1 - $list['last'] = substr($list['wr_last'],0,10); - $list['last2'] = $list['wr_last']; - if ($list['last'] == G5_TIME_YMD) - $list['last2'] = substr($list['last2'],11,5); - else - $list['last2'] = substr($list['last2'],5,5); + // 당일인 경우 시간으로 표시함 + $list['datetime'] = substr($list['wr_datetime'], 0, 10); + $list['datetime2'] = $list['wr_datetime']; + if ($list['datetime'] == G5_TIME_YMD) + $list['datetime2'] = substr($list['datetime2'], 11, 5); + else + $list['datetime2'] = substr($list['datetime2'], 5, 5); + // 4.1 + $list['last'] = substr($list['wr_last'], 0, 10); + $list['last2'] = $list['wr_last']; + if ($list['last'] == G5_TIME_YMD) + $list['last2'] = substr($list['last2'], 11, 5); + else + $list['last2'] = substr($list['last2'], 5, 5); - $list['wr_homepage'] = get_text($list['wr_homepage']); + $list['wr_homepage'] = get_text($list['wr_homepage']); - $tmp_name = get_text(cut_str($list['wr_name'], $config['cf_cut_name'])); // 설정된 자리수 만큼만 이름 출력 - $tmp_name2 = cut_str($list['wr_name'], $config['cf_cut_name']); // 설정된 자리수 만큼만 이름 출력 - if ($board['bo_use_sideview']) - $list['name'] = get_sideview($list['mb_id'], $tmp_name2, $list['wr_email'], $list['wr_homepage']); - else - $list['name'] = ''.$tmp_name.''; + $tmp_name = get_text(cut_str($list['wr_name'], $config['cf_cut_name'])); // 설정된 자리수 만큼만 이름 출력 + $tmp_name2 = cut_str($list['wr_name'], $config['cf_cut_name']); // 설정된 자리수 만큼만 이름 출력 + if ($board['bo_use_sideview']) + $list['name'] = get_sideview($list['mb_id'], $tmp_name2, $list['wr_email'], $list['wr_homepage']); + else + $list['name'] = '' . $tmp_name . ''; - $reply = $list['wr_reply']; + $reply = $list['wr_reply']; - $list['reply'] = strlen($reply)*10; + $list['reply'] = strlen($reply) * 10; - $list['icon_reply'] = ''; - if ($list['reply']) - $list['icon_reply'] = '답변글'; + $list['icon_reply'] = ''; + if ($list['reply']) + $list['icon_reply'] = '답변글'; - $list['icon_link'] = ''; - if ($list['wr_link1'] || $list['wr_link2']) - $list['icon_link'] = '관련링크'; + $list['icon_link'] = ''; + if ($list['wr_link1'] || $list['wr_link2']) + $list['icon_link'] = '관련링크'; - // 분류명 링크 - $list['ca_name_href'] = G5_BBS_URL.'/board.php?bo_table='.$board['bo_table'].'&sca='.urlencode($list['ca_name']); + // 분류명 링크 + $list['ca_name_href'] = G5_BBS_URL . '/board.php?bo_table=' . $board['bo_table'] . '&sca=' . urlencode($list['ca_name']); - $list['href'] = G5_BBS_URL.'/board.php?bo_table='.$board['bo_table'].'&wr_id='.$list['wr_id'].$qstr; - $list['comment_href'] = $list['href']; + $list['href'] = G5_BBS_URL . '/board.php?bo_table=' . $board['bo_table'] . '&wr_id=' . $list['wr_id'] . $qstr; + $list['comment_href'] = $list['href']; - $list['icon_new'] = ''; - if ($board['bo_new'] && $list['wr_datetime'] >= date("Y-m-d H:i:s", G5_SERVER_TIME - ($board['bo_new'] * 3600))) - $list['icon_new'] = '새글'; + $list['icon_new'] = ''; + if ($board['bo_new'] && $list['wr_datetime'] >= date("Y-m-d H:i:s", G5_SERVER_TIME - ($board['bo_new'] * 3600))) + $list['icon_new'] = '새글'; - $list['icon_hot'] = ''; - if ($board['bo_hot'] && $list['wr_hit'] >= $board['bo_hot']) - $list['icon_hot'] = '인기글'; + $list['icon_hot'] = ''; + if ($board['bo_hot'] && $list['wr_hit'] >= $board['bo_hot']) + $list['icon_hot'] = '인기글'; - $list['icon_secret'] = ''; - if (strstr($list['wr_option'], 'secret')) - $list['icon_secret'] = '비밀글'; + $list['icon_secret'] = ''; + if (strstr($list['wr_option'], 'secret')) + $list['icon_secret'] = '비밀글'; - // 링크 - for ($i=1; $i<=G5_LINK_COUNT; $i++) { - $list['link'][$i] = set_http(get_text($list["wr_link{$i}"])); - $list['link_href'][$i] = G5_BBS_URL.'/link.php?bo_table='.$board['bo_table'].'&wr_id='.$list['wr_id'].'&no='.$i.$qstr; - $list['link_hit'][$i] = (int)$list["wr_link{$i}_hit"]; - } + // 링크 + for ($i = 1; $i <= G5_LINK_COUNT; $i++) { + $list['link'][$i] = set_http(get_text($list["wr_link{$i}"])); + $list['link_href'][$i] = G5_BBS_URL . '/link.php?bo_table=' . $board['bo_table'] . '&wr_id=' . $list['wr_id'] . '&no=' . $i . $qstr; + $list['link_hit'][$i] = (int) $list["wr_link{$i}_hit"]; + } - // 가변 파일 - if ($board['bo_use_list_file'] || ($list['wr_file'] && $subject_len == 255) /* view 인 경우 */) { - $list['file'] = get_file($board['bo_table'], $list['wr_id']); - } else { - $list['file']['count'] = $list['wr_file']; - } + // 가변 파일 + if ($board['bo_use_list_file'] || ($list['wr_file'] && $subject_len == 255) /* view 인 경우 */) { + $list['file'] = get_file($board['bo_table'], $list['wr_id']); + } else { + $list['file']['count'] = $list['wr_file']; + } - if ($list['file']['count']) - $list['icon_file'] = '첨부파일'; + if ($list['file']['count']) + $list['icon_file'] = '첨부파일'; - return $list; + return $list; } // get_list 의 alias function get_view($write_row, $board, $skin_url) { - return get_list($write_row, $board, $skin_url, 255); + return get_list($write_row, $board, $skin_url, 255); } // set_search_font(), get_search_font() 함수를 search_font() 함수로 대체 function search_font($stx, $str) { - global $config; + global $config; - // 문자앞에 \ 를 붙입니다. - $src = array('/', '|'); - $dst = array('\/', '\|'); + // 문자앞에 \ 를 붙입니다. + $src = array('/', '|'); + $dst = array('\/', '\|'); - if (!trim($stx)) return $str; + if (!trim($stx)) + return $str; - // 검색어 전체를 공란으로 나눈다 - $s = explode(' ', $stx); + // 검색어 전체를 공란으로 나눈다 + $s = explode(' ', $stx); - // "/(검색1|검색2)/i" 와 같은 패턴을 만듬 - $pattern = ''; - $bar = ''; - for ($m=0; $m)"; - $bar = "|"; - } + // "/(검색1|검색2)/i" 와 같은 패턴을 만듬 + $pattern = ''; + $bar = ''; + for ($m = 0; $m < count($s); $m++) { + if (trim($s[$m]) == '') + continue; + // 태그는 포함하지 않아야 하는데 잘 안되는군. ㅡㅡa + //$pattern .= $bar . '([^<])(' . quotemeta($s[$m]) . ')'; + //$pattern .= $bar . quotemeta($s[$m]); + //$pattern .= $bar . str_replace("/", "\/", quotemeta($s[$m])); + $tmp_str = quotemeta($s[$m]); + $tmp_str = str_replace($src, $dst, $tmp_str); + $pattern .= $bar . $tmp_str . "(?![^<]*>)"; + $bar = "|"; + } - // 지정된 검색 폰트의 색상, 배경색상으로 대체 - $replace = "\\1"; + // 지정된 검색 폰트의 색상, 배경색상으로 대체 + $replace = "\\1"; - return preg_replace("/($pattern)/i", $replace, $str); + return preg_replace("/($pattern)/i", $replace, $str); } // 제목을 변환 -function conv_subject($subject, $len, $suffix='') +function conv_subject($subject, $len, $suffix = '') { - return get_text(cut_str($subject, $len, $suffix)); + return get_text(cut_str($subject, $len, $suffix)); } // 내용을 변환 -function conv_content($content, $html, $filter=true) +function conv_content($content, $html, $filter = true) { - global $config, $board; + global $config, $board; - if ($html) - { - $source = array(); - $target = array(); + if ($html) { + $source = array(); + $target = array(); - $source[] = "//"; - $target[] = ""; + $source[] = "//"; + $target[] = ""; - if ($html == 2) { // 자동 줄바꿈 - $source[] = "/\n/"; - $target[] = "
"; - } + if ($html == 2) { // 자동 줄바꿈 + $source[] = "/\n/"; + $target[] = "
"; + } - // 테이블 태그의 개수를 세어 테이블이 깨지지 않도록 한다. - $table_begin_count = substr_count(strtolower($content), "set('Cache.SerializerPath', G5_DATA_PATH.'/cache'); - $config->set('HTML.SafeEmbed', false); - $config->set('HTML.SafeObject', false); - $config->set('Output.FlashCompat', false); - $config->set('HTML.SafeIframe', true); - $config->set('URI.SafeIframeRegexp','%^(https?:)?//('.$safeiframe.')%'); - $config->set('Attr.AllowedFrameTargets', array('_blank')); - $purifier = new HTMLPurifier($config); - return $purifier->purify($html); + include_once(G5_PLUGIN_PATH . '/htmlpurifier/HTMLPurifier.standalone.php'); + $config = HTMLPurifier_Config::createDefault(); + // data/cache 디렉토리에 CSS, HTML, URI 디렉토리 등을 만든다. + $config->set('Cache.SerializerPath', G5_DATA_PATH . '/cache'); + $config->set('HTML.SafeEmbed', false); + $config->set('HTML.SafeObject', false); + $config->set('Output.FlashCompat', false); + $config->set('HTML.SafeIframe', true); + $config->set('URI.SafeIframeRegexp', '%^(https?:)?//(' . $safeiframe . ')%'); + $config->set('Attr.AllowedFrameTargets', array('_blank')); + $purifier = new HTMLPurifier($config); + return $purifier->purify($html); } // 검색 구문을 얻는다. -function get_sql_search($search_ca_name, $search_field, $search_text, $search_operator='and') +function get_sql_search($search_ca_name, $search_field, $search_text, $search_operator = 'and') { - global $g5; + global $g5; - $str = ""; - if ($search_ca_name) - $str = " ca_name = '$search_ca_name' "; + $str = ""; + if ($search_ca_name) + $str = " ca_name = '$search_ca_name' "; - $search_text = strip_tags(($search_text)); - $search_text = trim(stripslashes($search_text)); + $search_text = strip_tags(($search_text)); + $search_text = trim(stripslashes($search_text)); - if (!$search_text) { - if ($search_ca_name) { - return $str; - } else { - return '0'; - } - } + if (!$search_text) { + if ($search_ca_name) { + return $str; + } else { + return '0'; + } + } - if ($str) - $str .= " and "; + if ($str) + $str .= " and "; - // 쿼리의 속도를 높이기 위하여 ( ) 는 최소화 한다. - $op1 = ""; + // 쿼리의 속도를 높이기 위하여 ( ) 는 최소화 한다. + $op1 = ""; - // 검색어를 구분자로 나눈다. 여기서는 공백 - $s = array(); - $s = explode(" ", $search_text); + // 검색어를 구분자로 나눈다. 여기서는 공백 + $s = array(); + $s = explode(" ", $search_text); - // 검색필드를 구분자로 나눈다. 여기서는 + - $tmp = array(); - $tmp = explode(",", trim($search_field)); - $field = explode("||", $tmp[0]); - $not_comment = ""; - if (!empty($tmp[1])) - $not_comment = $tmp[1]; + // 검색필드를 구분자로 나눈다. 여기서는 + + $tmp = array(); + $tmp = explode(",", trim($search_field)); + $field = explode("||", $tmp[0]); + $not_comment = ""; + if (!empty($tmp[1])) + $not_comment = $tmp[1]; - $str .= "("; - for ($i=0; $i"; + return ""; } // 관리자 정보를 얻음 -function get_admin($admin='super', $fields='*') +function get_admin($admin = 'super', $fields = '*') { - global $config, $group, $board; - global $g5; + global $config, $group, $board; + global $g5; - $is = false; - if ($admin == 'board') { - $mb = sql_fetch("select {$fields} from {$g5['member_table']} where mb_id in ('{$board['bo_admin']}') limit 1 "); - $is = true; - } + $is = false; + if ($admin == 'board') { + $mb = sql_fetch("select {$fields} from {$g5['member_table']} where mb_id in ('{$board['bo_admin']}') limit 1 "); + $is = true; + } - if (($is && !$mb['mb_id']) || $admin == 'group') { - $mb = sql_fetch("select {$fields} from {$g5['member_table']} where mb_id in ('{$group['gr_admin']}') limit 1 "); - $is = true; - } + if (($is && !$mb['mb_id']) || $admin == 'group') { + $mb = sql_fetch("select {$fields} from {$g5['member_table']} where mb_id in ('{$group['gr_admin']}') limit 1 "); + $is = true; + } - if (($is && !$mb['mb_id']) || $admin == 'super') { - $mb = sql_fetch("select {$fields} from {$g5['member_table']} where mb_id in ('{$config['cf_admin']}') limit 1 "); - } + if (($is && !$mb['mb_id']) || $admin == 'super') { + $mb = sql_fetch("select {$fields} from {$g5['member_table']} where mb_id in ('{$config['cf_admin']}') limit 1 "); + } - return $mb; + return $mb; } // 관리자인가? function is_admin($mb_id) { - global $config, $group, $board; + global $config, $group, $board; - if (!$mb_id) return; + if (!$mb_id) + return; - $mb = get_member($mb_id); + $mb = get_member($mb_id); - if ($config['cf_admin'] == $mb_id || $mb['mb_level'] == 10) return 'super'; - if (isset($group['gr_admin']) && ($group['gr_admin'] == $mb_id)) return 'group'; - if (isset($board['bo_admin']) && ($board['bo_admin'] == $mb_id)) return 'board'; - return ''; + if ($config['cf_admin'] == $mb_id || $mb['mb_level'] == 10) + return 'super'; + if (isset($group['gr_admin']) && ($group['gr_admin'] == $mb_id)) + return 'group'; + if (isset($board['bo_admin']) && ($board['bo_admin'] == $mb_id)) + return 'board'; + return ''; } // 분류 옵션을 얻음 // 4.00 에서는 카테고리 테이블을 없애고 보드테이블에 있는 내용으로 대체 -function get_category_option($bo_table='', $ca_name='') +function get_category_option($bo_table = '', $ca_name = '') { - global $g5, $board, $is_admin; + global $g5, $board, $is_admin; - $categories = explode("|", $board['bo_category_list'].($is_admin?"|공지":"")); // 구분자가 | 로 되어 있음 - $str = ""; - for ($i=0; $i\n"; - for ($i=0; $row=sql_fetch_array($result); $i++) { - if ($i == 0) $str .= ""; - $str .= option_selected($row['gr_id'], $selected, $row['gr_subject']); - } - $str .= ""; - return $str; + $result = sql_query($sql); + $str = ""; + return $str; } -function option_selected($value, $selected, $text='') +function option_selected($value, $selected, $text = '') { - if (!$text) $text = $value; - if ($value == $selected) - return "\n"; - else - return "\n"; + if (!$text) + $text = $value; + if ($value == $selected) + return "\n"; + else + return "\n"; } // '예', '아니오'를 SELECT 형식으로 얻음 -function get_yn_select($name, $selected='1', $event='') +function get_yn_select($name, $selected = '1', $event = '') { - $str = ""; - return $str; + $str = ""; + return $str; } // 포인트 부여 -function insert_point($mb_id, $point, $content='', $rel_table='', $rel_id='', $rel_action='', $expire=0) +function insert_point($mb_id, $point, $content = '', $rel_table = '', $rel_id = '', $rel_action = '', $expire = 0) { - global $config; - global $g5; - global $is_admin; + global $config; + global $g5; + global $is_admin; - // 포인트 사용을 하지 않는다면 return - if (!$config['cf_use_point']) { return 0; } + // 포인트 사용을 하지 않는다면 return + if (!$config['cf_use_point']) { + return 0; + } - // 포인트가 없다면 업데이트 할 필요 없음 - if ($point == 0) { return 0; } + // 포인트가 없다면 업데이트 할 필요 없음 + if ($point == 0) { + return 0; + } - // 회원아이디가 없다면 업데이트 할 필요 없음 - if ($mb_id == '') { return 0; } - $mb = sql_fetch(" select mb_id from {$g5['member_table']} where mb_id = '$mb_id' "); - if (!$mb['mb_id']) { return 0; } + // 회원아이디가 없다면 업데이트 할 필요 없음 + if ($mb_id == '') { + return 0; + } + $mb = sql_fetch(" select mb_id from {$g5['member_table']} where mb_id = '$mb_id' "); + if (!$mb['mb_id']) { + return 0; + } - // 회원포인트 - $mb_point = get_point_sum($mb_id); + // 회원포인트 + $mb_point = get_point_sum($mb_id); - // 이미 등록된 내역이라면 건너뜀 - if ($rel_table || $rel_id || $rel_action) - { - $sql = " select count(*) as cnt from {$g5['point_table']} + // 이미 등록된 내역이라면 건너뜀 + if ($rel_table || $rel_id || $rel_action) { + $sql = " select count(*) as cnt from {$g5['point_table']} where mb_id = '$mb_id' and po_rel_table = '$rel_table' and po_rel_id = '$rel_id' and po_rel_action = '$rel_action' "; - $row = sql_fetch($sql); - if ($row['cnt']) - return -1; - } + $row = sql_fetch($sql); + if ($row['cnt']) + return -1; + } - // 포인트 건별 생성 - $po_expire_date = '9999-12-31'; - if($config['cf_point_term'] > 0) { - if($expire > 0) - $po_expire_date = date('Y-m-d', strtotime('+'.($expire - 1).' days', G5_SERVER_TIME)); - else - $po_expire_date = date('Y-m-d', strtotime('+'.($config['cf_point_term'] - 1).' days', G5_SERVER_TIME)); - } + // 포인트 건별 생성 + $po_expire_date = '9999-12-31'; + if ($config['cf_point_term'] > 0) { + if ($expire > 0) + $po_expire_date = date('Y-m-d', strtotime('+' . ($expire - 1) . ' days', G5_SERVER_TIME)); + else + $po_expire_date = date('Y-m-d', strtotime('+' . ($config['cf_point_term'] - 1) . ' days', G5_SERVER_TIME)); + } - $po_expired = 0; - if($point < 0) { - $po_expired = 1; - $po_expire_date = G5_TIME_YMD; - } - $po_mb_point = $mb_point + $point; + $po_expired = 0; + if ($point < 0) { + $po_expired = 1; + $po_expire_date = G5_TIME_YMD; + } + $po_mb_point = $mb_point + $point; - $sql = " insert into {$g5['point_table']} + $sql = " insert into {$g5['point_table']} set mb_id = '$mb_id', - po_datetime = '".G5_TIME_YMDHIS."', - po_content = '".addslashes($content)."', + po_datetime = '" . G5_TIME_YMDHIS . "', + po_content = '" . addslashes($content) . "', po_point = '$point', po_use_point = '0', po_mb_point = '$po_mb_point', @@ -931,170 +944,170 @@ function insert_point($mb_id, $point, $content='', $rel_table='', $rel_id='', $r po_rel_table = '$rel_table', po_rel_id = '$rel_id', po_rel_action = '$rel_action' "; - sql_query($sql); + sql_query($sql); - // 포인트를 사용한 경우 포인트 내역에 사용금액 기록 - if($point < 0) { - insert_use_point($mb_id, $point); - } + // 포인트를 사용한 경우 포인트 내역에 사용금액 기록 + if ($point < 0) { + insert_use_point($mb_id, $point); + } - // 포인트 UPDATE - $sql = " update {$g5['member_table']} set mb_point = '$po_mb_point' where mb_id = '$mb_id' "; - sql_query($sql); + // 포인트 UPDATE + $sql = " update {$g5['member_table']} set mb_point = '$po_mb_point' where mb_id = '$mb_id' "; + sql_query($sql); - return 1; + return 1; } // 사용포인트 입력 -function insert_use_point($mb_id, $point, $po_id='') +function insert_use_point($mb_id, $point, $po_id = '') { - global $g5, $config; + global $g5, $config; - if($config['cf_point_term']) - $sql_order = " order by po_expire_date asc, po_id asc "; - else - $sql_order = " order by po_id asc "; + if ($config['cf_point_term']) + $sql_order = " order by po_expire_date asc, po_id asc "; + else + $sql_order = " order by po_id asc "; - $point1 = abs($point); - $sql = " select po_id, po_point, po_use_point + $point1 = abs($point); + $sql = " select po_id, po_point, po_use_point from {$g5['point_table']} where mb_id = '$mb_id' and po_id <> '$po_id' and po_expired = '0' and po_point > po_use_point $sql_order "; - $result = sql_query($sql); - for($i=0; $row=sql_fetch_array($result); $i++) { - $point2 = $row['po_point']; - $point3 = $row['po_use_point']; + $result = sql_query($sql); + for ($i = 0; $row = sql_fetch_array($result); $i++) { + $point2 = $row['po_point']; + $point3 = $row['po_use_point']; - if(($point2 - $point3) > $point1) { - $sql = " update {$g5['point_table']} + if (($point2 - $point3) > $point1) { + $sql = " update {$g5['point_table']} set po_use_point = po_use_point + '$point1' where po_id = '{$row['po_id']}' "; - sql_query($sql); - break; - } else { - $point4 = $point2 - $point3; - $sql = " update {$g5['point_table']} + sql_query($sql); + break; + } else { + $point4 = $point2 - $point3; + $sql = " update {$g5['point_table']} set po_use_point = po_use_point + '$point4', po_expired = '100' where po_id = '{$row['po_id']}' "; - sql_query($sql); - $point1 -= $point4; - } - } + sql_query($sql); + $point1 -= $point4; + } + } } // 사용포인트 삭제 function delete_use_point($mb_id, $point) { - global $g5, $config; + global $g5, $config; - if($config['cf_point_term']) - $sql_order = " order by po_expire_date desc, po_id desc "; - else - $sql_order = " order by po_id desc "; + if ($config['cf_point_term']) + $sql_order = " order by po_expire_date desc, po_id desc "; + else + $sql_order = " order by po_id desc "; - $point1 = abs($point); - $sql = " select po_id, po_use_point, po_expired, po_expire_date + $point1 = abs($point); + $sql = " select po_id, po_use_point, po_expired, po_expire_date from {$g5['point_table']} where mb_id = '$mb_id' and po_expired <> '1' and po_use_point > 0 $sql_order "; - $result = sql_query($sql); - for($i=0; $row=sql_fetch_array($result); $i++) { - $point2 = $row['po_use_point']; + $result = sql_query($sql); + for ($i = 0; $row = sql_fetch_array($result); $i++) { + $point2 = $row['po_use_point']; - $po_expired = $row['po_expired']; - if($row['po_expired'] == 100 && ($row['po_expire_date'] == '9999-12-31' || $row['po_expire_date'] >= G5_TIME_YMD)) - $po_expired = 0; + $po_expired = $row['po_expired']; + if ($row['po_expired'] == 100 && ($row['po_expire_date'] == '9999-12-31' || $row['po_expire_date'] >= G5_TIME_YMD)) + $po_expired = 0; - if($point2 > $point1) { - $sql = " update {$g5['point_table']} + if ($point2 > $point1) { + $sql = " update {$g5['point_table']} set po_use_point = po_use_point - '$point1', po_expired = '$po_expired' where po_id = '{$row['po_id']}' "; - sql_query($sql); - break; - } else { - $sql = " update {$g5['point_table']} + sql_query($sql); + break; + } else { + $sql = " update {$g5['point_table']} set po_use_point = '0', po_expired = '$po_expired' where po_id = '{$row['po_id']}' "; - sql_query($sql); + sql_query($sql); - $point1 -= $point2; - } - } + $point1 -= $point2; + } + } } // 소멸포인트 삭제 function delete_expire_point($mb_id, $point) { - global $g5, $config; + global $g5, $config; - $point1 = abs($point); - $sql = " select po_id, po_use_point, po_expired, po_expire_date + $point1 = abs($point); + $sql = " select po_id, po_use_point, po_expired, po_expire_date from {$g5['point_table']} where mb_id = '$mb_id' and po_expired = '1' and po_point >= 0 and po_use_point > 0 order by po_expire_date desc, po_id desc "; - $result = sql_query($sql); - for($i=0; $row=sql_fetch_array($result); $i++) { - $point2 = $row['po_use_point']; - $po_expired = '0'; - $po_expire_date = '9999-12-31'; - if($config['cf_point_term'] > 0) - $po_expire_date = date('Y-m-d', strtotime('+'.($config['cf_point_term'] - 1).' days', G5_SERVER_TIME)); + $result = sql_query($sql); + for ($i = 0; $row = sql_fetch_array($result); $i++) { + $point2 = $row['po_use_point']; + $po_expired = '0'; + $po_expire_date = '9999-12-31'; + if ($config['cf_point_term'] > 0) + $po_expire_date = date('Y-m-d', strtotime('+' . ($config['cf_point_term'] - 1) . ' days', G5_SERVER_TIME)); - if($point2 > $point1) { - $sql = " update {$g5['point_table']} + if ($point2 > $point1) { + $sql = " update {$g5['point_table']} set po_use_point = po_use_point - '$point1', po_expired = '$po_expired', po_expire_date = '$po_expire_date' where po_id = '{$row['po_id']}' "; - sql_query($sql); - break; - } else { - $sql = " update {$g5['point_table']} + sql_query($sql); + break; + } else { + $sql = " update {$g5['point_table']} set po_use_point = '0', po_expired = '$po_expired', po_expire_date = '$po_expire_date' where po_id = '{$row['po_id']}' "; - sql_query($sql); + sql_query($sql); - $point1 -= $point2; - } - } + $point1 -= $point2; + } + } } // 포인트 내역 합계 function get_point_sum($mb_id) { - global $g5, $config; + global $g5, $config; - if($config['cf_point_term'] > 0) { - // 소멸포인트가 있으면 내역 추가 - $expire_point = get_expire_point($mb_id); - if($expire_point > 0) { - $mb = get_member($mb_id, 'mb_point'); - $content = '포인트 소멸'; - $rel_table = '@expire'; - $rel_id = $mb_id; - $rel_action = 'expire'.'-'.uniqid(''); - $point = $expire_point * (-1); - $po_mb_point = $mb['mb_point'] + $point; - $po_expire_date = G5_TIME_YMD; - $po_expired = 1; + if ($config['cf_point_term'] > 0) { + // 소멸포인트가 있으면 내역 추가 + $expire_point = get_expire_point($mb_id); + if ($expire_point > 0) { + $mb = get_member($mb_id, 'mb_point'); + $content = '포인트 소멸'; + $rel_table = '@expire'; + $rel_id = $mb_id; + $rel_action = 'expire' . '-' . uniqid(''); + $point = $expire_point * (-1); + $po_mb_point = $mb['mb_point'] + $point; + $po_expire_date = G5_TIME_YMD; + $po_expired = 1; - $sql = " insert into {$g5['point_table']} + $sql = " insert into {$g5['point_table']} set mb_id = '$mb_id', - po_datetime = '".G5_TIME_YMDHIS."', - po_content = '".addslashes($content)."', + po_datetime = '" . G5_TIME_YMDHIS . "', + po_content = '" . addslashes($content) . "', po_point = '$point', po_use_point = '0', po_mb_point = '$po_mb_point', @@ -1103,218 +1116,217 @@ function get_point_sum($mb_id) po_rel_table = '$rel_table', po_rel_id = '$rel_id', po_rel_action = '$rel_action' "; - sql_query($sql); + sql_query($sql); - // 포인트를 사용한 경우 포인트 내역에 사용금액 기록 - if($point < 0) { - insert_use_point($mb_id, $point); - } - } + // 포인트를 사용한 경우 포인트 내역에 사용금액 기록 + if ($point < 0) { + insert_use_point($mb_id, $point); + } + } - // 유효기간이 있을 때 기간이 지난 포인트 expired 체크 - $sql = " update {$g5['point_table']} + // 유효기간이 있을 때 기간이 지난 포인트 expired 체크 + $sql = " update {$g5['point_table']} set po_expired = '1' where mb_id = '$mb_id' and po_expired <> '1' and po_expire_date <> '9999-12-31' - and po_expire_date < '".G5_TIME_YMD."' "; - sql_query($sql); - } + and po_expire_date < '" . G5_TIME_YMD . "' "; + sql_query($sql); + } - // 포인트합 - $sql = " select sum(po_point) as sum_po_point + // 포인트합 + $sql = " select sum(po_point) as sum_po_point from {$g5['point_table']} where mb_id = '$mb_id' "; - $row = sql_fetch($sql); + $row = sql_fetch($sql); - return $row['sum_po_point']; + return $row['sum_po_point']; } // 소멸 포인트 function get_expire_point($mb_id) { - global $g5, $config; + global $g5, $config; - if($config['cf_point_term'] == 0) - return 0; + if ($config['cf_point_term'] == 0) + return 0; - $sql = " select sum(po_point - po_use_point) as sum_point + $sql = " select sum(po_point - po_use_point) as sum_point from {$g5['point_table']} where mb_id = '$mb_id' and po_expired = '0' and po_expire_date <> '9999-12-31' - and po_expire_date < '".G5_TIME_YMD."' "; - $row = sql_fetch($sql); + and po_expire_date < '" . G5_TIME_YMD . "' "; + $row = sql_fetch($sql); - return $row['sum_point']; + return $row['sum_point']; } // 포인트 삭제 function delete_point($mb_id, $rel_table, $rel_id, $rel_action) { - global $g5; + global $g5; - $result = false; - if ($rel_table || $rel_id || $rel_action) - { - // 포인트 내역정보 - $sql = " select * from {$g5['point_table']} + $result = false; + if ($rel_table || $rel_id || $rel_action) { + // 포인트 내역정보 + $sql = " select * from {$g5['point_table']} where mb_id = '$mb_id' and po_rel_table = '$rel_table' and po_rel_id = '$rel_id' and po_rel_action = '$rel_action' "; - $row = sql_fetch($sql); + $row = sql_fetch($sql); - if($row['po_point'] < 0) { - $mb_id = $row['mb_id']; - $po_point = abs($row['po_point']); + if ($row['po_point'] < 0) { + $mb_id = $row['mb_id']; + $po_point = abs($row['po_point']); - delete_use_point($mb_id, $po_point); - } else { - if($row['po_use_point'] > 0) { - insert_use_point($row['mb_id'], $row['po_use_point'], $row['po_id']); - } - } + delete_use_point($mb_id, $po_point); + } else { + if ($row['po_use_point'] > 0) { + insert_use_point($row['mb_id'], $row['po_use_point'], $row['po_id']); + } + } - $result = sql_query(" delete from {$g5['point_table']} + $result = sql_query(" delete from {$g5['point_table']} where mb_id = '$mb_id' and po_rel_table = '$rel_table' and po_rel_id = '$rel_id' and po_rel_action = '$rel_action' ", false); - // po_mb_point에 반영 - $sql = " update {$g5['point_table']} + // po_mb_point에 반영 + $sql = " update {$g5['point_table']} set po_mb_point = po_mb_point - '{$row['po_point']}' where mb_id = '$mb_id' and po_id > '{$row['po_id']}' "; - sql_query($sql); + sql_query($sql); - // 포인트 내역의 합을 구하고 - $sum_point = get_point_sum($mb_id); + // 포인트 내역의 합을 구하고 + $sum_point = get_point_sum($mb_id); - // 포인트 UPDATE - $sql = " update {$g5['member_table']} set mb_point = '$sum_point' where mb_id = '$mb_id' "; - $result = sql_query($sql); - } + // 포인트 UPDATE + $sql = " update {$g5['member_table']} set mb_point = '$sum_point' where mb_id = '$mb_id' "; + $result = sql_query($sql); + } - return $result; + return $result; } // 회원 레이어 -function get_sideview($mb_id, $name='', $email='', $homepage='') +function get_sideview($mb_id, $name = '', $email = '', $homepage = '') { - global $config; - global $g5; - global $bo_table, $sca, $is_admin, $member; + global $config; + global $g5; + global $bo_table, $sca, $is_admin, $member; - $email_enc = new str_encrypt(); - $email = $email_enc->encrypt($email); - $homepage = set_http(clean_xss_tags($homepage)); + $email_enc = new str_encrypt(); + $email = $email_enc->encrypt($email); + $homepage = set_http(clean_xss_tags($homepage)); - $name = get_text($name, 0, true); - $email = get_text($email); - $homepage = get_text($homepage); + $name = get_text($name, 0, true); + $email = get_text($email); + $homepage = get_text($homepage); - $tmp_name = ""; - if ($mb_id) { - //$tmp_name = "$name"; - $tmp_name = ''; + $tmp_name = ""; + if ($mb_id) { + //$tmp_name = "$name"; + $tmp_name = ''; - if ($config['cf_use_member_icon']) { - $mb_dir = substr($mb_id,0,2); - $icon_file = G5_DATA_PATH.'/member/'.$mb_dir.'/'.$mb_id.'.gif'; + if ($config['cf_use_member_icon']) { + $mb_dir = substr($mb_id, 0, 2); + $icon_file = G5_DATA_PATH . '/member/' . $mb_dir . '/' . $mb_id . '.gif'; - if (file_exists($icon_file)) { - $width = $config['cf_member_icon_width']; - $height = $config['cf_member_icon_height']; - $icon_file_url = G5_DATA_URL.'/member/'.$mb_dir.'/'.$mb_id.'.gif'; - $tmp_name .= ''; + if (file_exists($icon_file)) { + $width = $config['cf_member_icon_width']; + $height = $config['cf_member_icon_height']; + $icon_file_url = G5_DATA_URL . '/member/' . $mb_dir . '/' . $mb_id . '.gif'; + $tmp_name .= ''; - if ($config['cf_use_member_icon'] == 2) // 회원아이콘+이름 - $tmp_name = $tmp_name.' '.$name; - } else { - $tmp_name = $tmp_name." ".$name; - } - } else { - $tmp_name = $tmp_name.' '.$name; - } - $tmp_name .= ''; + if ($config['cf_use_member_icon'] == 2) // 회원아이콘+이름 + $tmp_name = $tmp_name . ' ' . $name; + } else { + $tmp_name = $tmp_name . " " . $name; + } + } else { + $tmp_name = $tmp_name . ' ' . $name; + } + $tmp_name .= ''; - $title_mb_id = '['.$mb_id.']'; - } else { - if(!$bo_table) - return $name; + $title_mb_id = '[' . $mb_id . ']'; + } else { + if (!$bo_table) + return $name; - $tmp_name = ''.$name.''; - $title_mb_id = '[비회원]'; - } + $tmp_name = '' . $name . ''; + $title_mb_id = '[비회원]'; + } - $str = "\n"; - $str .= $tmp_name."\n"; + $str = "\n"; + $str .= $tmp_name . "\n"; - $str2 = "\n"; - if($mb_id) - $str2 .= "쪽지보내기\n"; - if($email) - $str2 .= "메일보내기\n"; - if($homepage) - $str2 .= "홈페이지\n"; - if($mb_id) - $str2 .= "자기소개\n"; - if($bo_table) { - if($mb_id) - $str2 .= "아이디로 검색\n"; - else - $str2 .= "이름으로 검색\n"; - } - if($mb_id) - $str2 .= "전체게시물\n"; - if($is_admin == "super" && $mb_id) { - $str2 .= "회원정보변경\n"; - $str2 .= "포인트내역\n"; - } - $str2 .= "\n"; - $str .= $str2; - $str .= "\n"; + $str2 = "\n"; + if ($mb_id) + $str2 .= "쪽지보내기\n"; + if ($email) + $str2 .= "메일보내기\n"; + if ($homepage) + $str2 .= "홈페이지\n"; + if ($mb_id) + $str2 .= "자기소개\n"; + if ($bo_table) { + if ($mb_id) + $str2 .= "아이디로 검색\n"; + else + $str2 .= "이름으로 검색\n"; + } + if ($mb_id) + $str2 .= "전체게시물\n"; + if ($is_admin == "super" && $mb_id) { + $str2 .= "회원정보변경\n"; + $str2 .= "포인트내역\n"; + } + $str2 .= "\n"; + $str .= $str2; + $str .= "\n"; - $str .= ""; + $str .= ""; - return $str; + return $str; } // 파일을 보이게 하는 링크 (이미지, 플래쉬, 동영상) -function view_file_link($file, $width, $height, $content='') +function view_file_link($file, $width, $height, $content = '') { - global $config, $board; - global $g5; - static $ids; + global $config, $board; + global $g5; + static $ids; - if (!$file) return; + if (!$file) + return; - $ids++; + $ids++; - // 파일의 폭이 게시판설정의 이미지폭 보다 크다면 게시판설정 폭으로 맞추고 비율에 따라 높이를 계산 - if ($width > $board['bo_image_width'] && $board['bo_image_width']) - { - $rate = $board['bo_image_width'] / $width; - $width = $board['bo_image_width']; - $height = (int)($height * $rate); - } + // 파일의 폭이 게시판설정의 이미지폭 보다 크다면 게시판설정 폭으로 맞추고 비율에 따라 높이를 계산 + if ($width > $board['bo_image_width'] && $board['bo_image_width']) { + $rate = $board['bo_image_width'] / $width; + $width = $board['bo_image_width']; + $height = (int) ($height * $rate); + } - // 폭이 있는 경우 폭과 높이의 속성을 주고, 없으면 자동 계산되도록 코드를 만들지 않는다. - if ($width) - $attr = ' width="'.$width.'" height="'.$height.'" '; - else - $attr = ''; + // 폭이 있는 경우 폭과 높이의 속성을 주고, 없으면 자동 계산되도록 코드를 만들지 않는다. + if ($width) + $attr = ' width="' . $width . '" height="' . $height . '" '; + else + $attr = ''; - if (preg_match("/\.({$config['cf_image_extension']})$/i", $file)) { - $img = ''; - $img .= ''.$content.''; - $img .= ''; + if (preg_match("/\.({$config['cf_image_extension']})$/i", $file)) { + $img = ''; + $img .= '' . $content . ''; + $img .= ''; - return $img; - } + return $img; + } } @@ -1322,11 +1334,11 @@ function view_file_link($file, $width, $height, $content='') // {img:0} ... {img:n} 과 같은 형식 function view_image($view, $number, $attribute) { - if ($view['file'][$number]['view']) - return preg_replace("/>$/", " $attribute>", $view['file'][$number]['view']); - else - //return "{".$number."번 이미지 없음}"; - return ""; + if ($view['file'][$number]['view']) + return preg_replace("/>$/", " $attribute>", $view['file'][$number]['view']); + else + //return "{".$number."번 이미지 없음}"; + return ""; } @@ -1334,64 +1346,64 @@ function view_image($view, $number, $attribute) // {link:0} ... {link:n} 과 같은 형식 function view_link($view, $number, $attribute) { - global $config; + global $config; - if ($view['link'][$number]['link']) - { - if (!preg_match("/target/i", $attribute)) - $attribute .= " target='$config['cf_link_target']'"; - return "{$view['link'][$number]['link']}"; - } - else - return "{".$number."번 링크 없음}"; + if ($view['link'][$number]['link']) + { + if (!preg_match("/target/i", $attribute)) + $attribute .= " target='$config['cf_link_target']'"; + return "{$view['link'][$number]['link']}"; + } + else + return "{".$number."번 링크 없음}"; } */ -function cut_str($str, $len, $suffix="…") +function cut_str($str, $len, $suffix = "…") { - $arr_str = preg_split("//u", $str, -1, PREG_SPLIT_NO_EMPTY); - $str_len = count($arr_str); + $arr_str = preg_split("//u", $str, -1, PREG_SPLIT_NO_EMPTY); + $str_len = count($arr_str); - if ($str_len >= $len) { - $slice_str = array_slice($arr_str, 0, $len); - $str = join("", $slice_str); + if ($str_len >= $len) { + $slice_str = array_slice($arr_str, 0, $len); + $str = join("", $slice_str); - return $str . ($str_len > $len ? $suffix : ''); - } else { - $str = join("", $arr_str); - return $str; - } + return $str . ($str_len > $len ? $suffix : ''); + } else { + $str = join("", $arr_str); + return $str; + } } // TEXT 형식으로 변환 -function get_text($str, $html=0, $restore=false) +function get_text($str, $html = 0, $restore = false) { - $source[] = "<"; - $target[] = "<"; - $source[] = ">"; - $target[] = ">"; - $source[] = "\""; - $target[] = """; - $source[] = "\'"; - $target[] = "'"; + $source[] = "<"; + $target[] = "<"; + $source[] = ">"; + $target[] = ">"; + $source[] = "\""; + $target[] = """; + $source[] = "\'"; + $target[] = "'"; - if($restore) - $str = str_replace($target, $source, $str); + if ($restore) + $str = str_replace($target, $source, $str); - // 3.31 - // TEXT 출력일 경우 &   등의 코드를 정상으로 출력해 주기 위함 - if ($html == 0) { - $str = html_symbol($str); - } + // 3.31 + // TEXT 출력일 경우 &   등의 코드를 정상으로 출력해 주기 위함 + if ($html == 0) { + $str = html_symbol($str); + } - if ($html) { - $source[] = "\n"; - $target[] = "
"; - } + if ($html) { + $source[] = "\n"; + $target[] = "
"; + } - return str_replace($source, $target, $str); + return str_replace($source, $target, $str); } @@ -1399,9 +1411,9 @@ function get_text($str, $html=0, $restore=false) // HTML 특수문자 변환 htmlspecialchars function hsc($str) { - $trans = array("\"" => """, "'" => "'", "<"=>"<", ">"=>">"); - $str = strtr($str, $trans); - return $str; + $trans = array("\"" => """, "'" => "'", "<"=>"<", ">"=>">"); + $str = strtr($str, $trans); + return $str; } */ @@ -1410,121 +1422,121 @@ function hsc($str) //   & · 등을 정상으로 출력 function html_symbol($str) { - return preg_replace("/\&([a-z0-9]{1,20}|\#[0-9]{0,3});/i", "&\\1;", $str); + return preg_replace("/\&([a-z0-9]{1,20}|\#[0-9]{0,3});/i", "&\\1;", $str); } /************************************************************************* -** -** SQL 관련 함수 모음 -** -*************************************************************************/ + ** + ** SQL 관련 함수 모음 + ** + *************************************************************************/ // DB 연결 -function sql_connect($host, $user, $pass, $db=G5_MYSQL_DB) +function sql_connect($host, $user, $pass, $db = G5_MYSQL_DB) { - global $g5; + global $g5; - if(function_exists('mysqli_connect') && G5_MYSQLI_USE) { - $link = mysqli_connect($host, $user, $pass, $db); + if (function_exists('mysqli_connect') && G5_MYSQLI_USE) { + $link = mysqli_connect($host, $user, $pass, $db); - // 연결 오류 발생 시 스크립트 종료 - if (mysqli_connect_errno()) { - die('Connect Error: '.mysqli_connect_error()); - } - } else { - $link = mysql_connect($host, $user, $pass); - } + // 연결 오류 발생 시 스크립트 종료 + if (mysqli_connect_errno()) { + die('Connect Error: ' . mysqli_connect_error()); + } + } else { + $link = mysql_connect($host, $user, $pass); + } - return $link; + return $link; } // DB 선택 function sql_select_db($db, $connect) { - global $g5; + global $g5; - if(function_exists('mysqli_select_db') && G5_MYSQLI_USE) - return @mysqli_select_db($connect, $db); - else - return @mysql_select_db($db, $connect); + if (function_exists('mysqli_select_db') && G5_MYSQLI_USE) + return @mysqli_select_db($connect, $db); + else + return @mysql_select_db($db, $connect); } -function sql_set_charset($charset, $link=null) +function sql_set_charset($charset, $link = null) { - global $g5; + global $g5; - if(!$link) - $link = $g5['connect_db']; + if (!$link) + $link = $g5['connect_db']; - if(function_exists('mysqli_set_charset') && G5_MYSQLI_USE) - mysqli_set_charset($link, $charset); - else - mysql_query(" set names {$charset} ", $link); + if (function_exists('mysqli_set_charset') && G5_MYSQLI_USE) + mysqli_set_charset($link, $charset); + else + mysql_query(" set names {$charset} ", $link); } // mysqli_query 와 mysqli_error 를 한꺼번에 처리 // mysql connect resource 지정 - 명랑폐인님 제안 -function sql_query($sql, $error=G5_DISPLAY_SQL_ERROR, $link=null) +function sql_query($sql, $error = G5_DISPLAY_SQL_ERROR, $link = null) { - global $g5; + global $g5; - if(!$link) - $link = $g5['connect_db']; + if (!$link) + $link = $g5['connect_db']; - // Blind SQL Injection 취약점 해결 - $sql = trim($sql); - // union의 사용을 허락하지 않습니다. - //$sql = preg_replace("#^select.*from.*union.*#i", "select 1", $sql); - $sql = preg_replace("#^select.*from.*[\s\(]+union[\s\)]+.*#i ", "select 1", $sql); - // `information_schema` DB로의 접근을 허락하지 않습니다. - $sql = preg_replace("#^select.*from.*where.*`?information_schema`?.*#i", "select 1", $sql); + // Blind SQL Injection 취약점 해결 + $sql = trim($sql); + // union의 사용을 허락하지 않습니다. + //$sql = preg_replace("#^select.*from.*union.*#i", "select 1", $sql); + $sql = preg_replace("#^select.*from.*[\s\(]+union[\s\)]+.*#i ", "select 1", $sql); + // `information_schema` DB로의 접근을 허락하지 않습니다. + $sql = preg_replace("#^select.*from.*where.*`?information_schema`?.*#i", "select 1", $sql); - if(function_exists('mysqli_query') && G5_MYSQLI_USE) { - if ($error) { - $result = @mysqli_query($link, $sql) or die("

$sql

" . mysqli_errno($link) . " : " . mysqli_error($link) . "

error file : {$_SERVER['SCRIPT_NAME']}"); - } else { - $result = @mysqli_query($link, $sql); - } - } else { - if ($error) { - $result = @mysql_query($sql, $link) or die("

$sql

" . mysql_errno() . " : " . mysql_error() . "

error file : {$_SERVER['SCRIPT_NAME']}"); - } else { - $result = @mysql_query($sql, $link); - } - } + if (function_exists('mysqli_query') && G5_MYSQLI_USE) { + if ($error) { + $result = @mysqli_query($link, $sql) or die("

$sql

" . mysqli_errno($link) . " : " . mysqli_error($link) . "

error file : {$_SERVER['SCRIPT_NAME']}"); + } else { + $result = @mysqli_query($link, $sql); + } + } else { + if ($error) { + $result = @mysql_query($sql, $link) or die("

$sql

" . mysql_errno() . " : " . mysql_error() . "

error file : {$_SERVER['SCRIPT_NAME']}"); + } else { + $result = @mysql_query($sql, $link); + } + } - return $result; + return $result; } // 쿼리를 실행한 후 결과값에서 한행을 얻는다. -function sql_fetch($sql, $error=G5_DISPLAY_SQL_ERROR, $link=null) +function sql_fetch($sql, $error = G5_DISPLAY_SQL_ERROR, $link = null) { - global $g5; + global $g5; - if(!$link) - $link = $g5['connect_db']; + if (!$link) + $link = $g5['connect_db']; - $result = sql_query($sql, $error, $link); - //$row = @sql_fetch_array($result) or die("

$sql

" . mysqli_errno() . " : " . mysqli_error() . "

error file : $_SERVER['SCRIPT_NAME']"); - $row = sql_fetch_array($result); - return $row; + $result = sql_query($sql, $error, $link); + //$row = @sql_fetch_array($result) or die("

$sql

" . mysqli_errno() . " : " . mysqli_error() . "

error file : $_SERVER['SCRIPT_NAME']"); + $row = sql_fetch_array($result); + return $row; } // 결과값에서 한행 연관배열(이름으로)로 얻는다. function sql_fetch_array($result) { - if(function_exists('mysqli_fetch_assoc') && G5_MYSQLI_USE) - $row = @mysqli_fetch_assoc($result); - else - $row = @mysql_fetch_assoc($result); + if (function_exists('mysqli_fetch_assoc') && G5_MYSQLI_USE) + $row = @mysqli_fetch_assoc($result); + else + $row = @mysql_fetch_assoc($result); - return $row; + return $row; } @@ -1533,348 +1545,342 @@ function sql_fetch_array($result) // 단, 결과 값은 스크립트(script) 실행부가 종료되면서 메모리에서 자동적으로 지워진다. function sql_free_result($result) { - if(function_exists('mysqli_free_result') && G5_MYSQLI_USE) - return mysqli_free_result($result); - else - return mysql_free_result($result); + if (function_exists('mysqli_free_result') && G5_MYSQLI_USE) + return mysqli_free_result($result); + else + return mysql_free_result($result); } function sql_password($value) { - // mysql 4.0x 이하 버전에서는 password() 함수의 결과가 16bytes - // mysql 4.1x 이상 버전에서는 password() 함수의 결과가 41bytes - $row = sql_fetch(" select password('$value') as pass "); + // mysql 4.0x 이하 버전에서는 password() 함수의 결과가 16bytes + // mysql 4.1x 이상 버전에서는 password() 함수의 결과가 41bytes + $row = sql_fetch(" select password('$value') as pass "); - return $row['pass']; + return $row['pass']; } -function sql_insert_id($link=null) +function sql_insert_id($link = null) { - global $g5; + global $g5; - if(!$link) - $link = $g5['connect_db']; + if (!$link) + $link = $g5['connect_db']; - if(function_exists('mysqli_insert_id') && G5_MYSQLI_USE) - return mysqli_insert_id($link); - else - return mysql_insert_id($link); + if (function_exists('mysqli_insert_id') && G5_MYSQLI_USE) + return mysqli_insert_id($link); + else + return mysql_insert_id($link); } function sql_num_rows($result) { - if(function_exists('mysqli_num_rows') && G5_MYSQLI_USE) - return mysqli_num_rows($result); - else - return mysql_num_rows($result); + if (function_exists('mysqli_num_rows') && G5_MYSQLI_USE) + return mysqli_num_rows($result); + else + return mysql_num_rows($result); } -function sql_field_names($table, $link=null) +function sql_field_names($table, $link = null) { - global $g5; + global $g5; - if(!$link) - $link = $g5['connect_db']; + if (!$link) + $link = $g5['connect_db']; - $columns = array(); + $columns = array(); - $sql = " select * from `$table` limit 1 "; - $result = sql_query($sql, $link); + $sql = " select * from `$table` limit 1 "; + $result = sql_query($sql, $link); - if(function_exists('mysqli_fetch_field') && G5_MYSQLI_USE) { - while($field = mysqli_fetch_field($result)) { - $columns[] = $field->name; - } - } else { - $i = 0; - $cnt = mysql_num_fields($result); - while($i < $cnt) { - $field = mysql_fetch_field($result, $i); - $columns[] = $field->name; - $i++; - } - } + if (function_exists('mysqli_fetch_field') && G5_MYSQLI_USE) { + while ($field = mysqli_fetch_field($result)) { + $columns[] = $field->name; + } + } else { + $i = 0; + $cnt = mysql_num_fields($result); + while ($i < $cnt) { + $field = mysql_fetch_field($result, $i); + $columns[] = $field->name; + $i++; + } + } - return $columns; + return $columns; } -function sql_error_info($link=null) +function sql_error_info($link = null) { - global $g5; + global $g5; - if(!$link) - $link = $g5['connect_db']; + if (!$link) + $link = $g5['connect_db']; - if(function_exists('mysqli_error') && G5_MYSQLI_USE) { - return mysqli_errno($link) . ' : ' . mysqli_error($link); - } else { - return mysql_errno($link) . ' : ' . mysql_error($link); - } + if (function_exists('mysqli_error') && G5_MYSQLI_USE) { + return mysqli_errno($link) . ' : ' . mysqli_error($link); + } else { + return mysql_errno($link) . ' : ' . mysql_error($link); + } } // PHPMyAdmin 참고 -function get_table_define($table, $crlf="\n") +function get_table_define($table, $crlf = "\n") { - global $g5; + global $g5; - // For MySQL < 3.23.20 - $schema_create .= 'CREATE TABLE ' . $table . ' (' . $crlf; + // For MySQL < 3.23.20 + $schema_create .= 'CREATE TABLE ' . $table . ' (' . $crlf; - $sql = 'SHOW FIELDS FROM ' . $table; - $result = sql_query($sql); - while ($row = sql_fetch_array($result)) - { - $schema_create .= ' ' . $row['Field'] . ' ' . $row['Type']; - if (isset($row['Default']) && $row['Default'] != '') - { - $schema_create .= ' DEFAULT \'' . $row['Default'] . '\''; - } - if ($row['Null'] != 'YES') - { - $schema_create .= ' NOT NULL'; - } - if ($row['Extra'] != '') - { - $schema_create .= ' ' . $row['Extra']; - } - $schema_create .= ',' . $crlf; - } // end while - sql_free_result($result); + $sql = 'SHOW FIELDS FROM ' . $table; + $result = sql_query($sql); + while ($row = sql_fetch_array($result)) { + $schema_create .= ' ' . $row['Field'] . ' ' . $row['Type']; + if (isset($row['Default']) && $row['Default'] != '') { + $schema_create .= ' DEFAULT \'' . $row['Default'] . '\''; + } + if ($row['Null'] != 'YES') { + $schema_create .= ' NOT NULL'; + } + if ($row['Extra'] != '') { + $schema_create .= ' ' . $row['Extra']; + } + $schema_create .= ',' . $crlf; + } // end while + sql_free_result($result); - $schema_create = preg_replace('/,' . $crlf . '$/', '', $schema_create); + $schema_create = preg_replace('/,' . $crlf . '$/', '', $schema_create); - $sql = 'SHOW KEYS FROM ' . $table; - $result = sql_query($sql); - while ($row = sql_fetch_array($result)) - { - $kname = $row['Key_name']; - $comment = (isset($row['Comment'])) ? $row['Comment'] : ''; - $sub_part = (isset($row['Sub_part'])) ? $row['Sub_part'] : ''; + $sql = 'SHOW KEYS FROM ' . $table; + $result = sql_query($sql); + while ($row = sql_fetch_array($result)) { + $kname = $row['Key_name']; + $comment = (isset($row['Comment'])) ? $row['Comment'] : ''; + $sub_part = (isset($row['Sub_part'])) ? $row['Sub_part'] : ''; - if ($kname != 'PRIMARY' && $row['Non_unique'] == 0) { - $kname = "UNIQUE|$kname"; - } - if ($comment == 'FULLTEXT') { - $kname = 'FULLTEXT|$kname'; - } - if (!isset($index[$kname])) { - $index[$kname] = array(); - } - if ($sub_part > 1) { - $index[$kname][] = $row['Column_name'] . '(' . $sub_part . ')'; - } else { - $index[$kname][] = $row['Column_name']; - } - } // end while - sql_free_result($result); + if ($kname != 'PRIMARY' && $row['Non_unique'] == 0) { + $kname = "UNIQUE|$kname"; + } + if ($comment == 'FULLTEXT') { + $kname = 'FULLTEXT|$kname'; + } + if (!isset($index[$kname])) { + $index[$kname] = array(); + } + if ($sub_part > 1) { + $index[$kname][] = $row['Column_name'] . '(' . $sub_part . ')'; + } else { + $index[$kname][] = $row['Column_name']; + } + } // end while + sql_free_result($result); - while (list($x, $columns) = @each($index)) { - $schema_create .= ',' . $crlf; - if ($x == 'PRIMARY') { - $schema_create .= ' PRIMARY KEY ('; - } else if (substr($x, 0, 6) == 'UNIQUE') { - $schema_create .= ' UNIQUE ' . substr($x, 7) . ' ('; - } else if (substr($x, 0, 8) == 'FULLTEXT') { - $schema_create .= ' FULLTEXT ' . substr($x, 9) . ' ('; - } else { - $schema_create .= ' KEY ' . $x . ' ('; - } - $schema_create .= implode($columns, ', ') . ')'; - } // end while + while (list($x, $columns) = @each($index)) { + $schema_create .= ',' . $crlf; + if ($x == 'PRIMARY') { + $schema_create .= ' PRIMARY KEY ('; + } else if (substr($x, 0, 6) == 'UNIQUE') { + $schema_create .= ' UNIQUE ' . substr($x, 7) . ' ('; + } else if (substr($x, 0, 8) == 'FULLTEXT') { + $schema_create .= ' FULLTEXT ' . substr($x, 9) . ' ('; + } else { + $schema_create .= ' KEY ' . $x . ' ('; + } + $schema_create .= implode($columns, ', ') . ')'; + } // end while - $schema_create .= $crlf . ') ENGINE=MyISAM DEFAULT CHARSET=utf8'; + $schema_create .= $crlf . ') ENGINE=MyISAM DEFAULT CHARSET=utf8'; - return $schema_create; + return $schema_create; } // end of the 'PMA_getTableDef()' function // 리퍼러 체크 -function referer_check($url='') +function referer_check($url = '') { - /* - // 제대로 체크를 하지 못하여 주석 처리함 - global $g5; + /* + // 제대로 체크를 하지 못하여 주석 처리함 + global $g5; - if (!$url) - $url = G5_URL; + if (!$url) + $url = G5_URL; - if (!preg_match("/^http['s']?:\/\/".$_SERVER['HTTP_HOST']."/", $_SERVER['HTTP_REFERER'])) - alert("제대로 된 접근이 아닌것 같습니다.", $url); - */ + if (!preg_match("/^http['s']?:\/\/".$_SERVER['HTTP_HOST']."/", $_SERVER['HTTP_REFERER'])) + alert("제대로 된 접근이 아닌것 같습니다.", $url); + */ } // 한글 요일 -function get_yoil($date, $full=0) +function get_yoil($date, $full = 0) { - $arr_yoil = array ('일', '월', '화', '수', '목', '금', '토'); + $arr_yoil = array('일', '월', '화', '수', '목', '금', '토'); - $yoil = date("w", strtotime($date)); - $str = $arr_yoil[$yoil]; - if ($full) { - $str .= '요일'; - } - return $str; + $yoil = date("w", strtotime($date)); + $str = $arr_yoil[$yoil]; + if ($full) { + $str .= '요일'; + } + return $str; } // 날짜를 select 박스 형식으로 얻는다 -function date_select($date, $name='') +function date_select($date, $name = '') { - global $g5; + global $g5; - $s = ''; - if (substr($date, 0, 4) == "0000") { - $date = G5_TIME_YMDHIS; - } - preg_match("/([0-9]{4})-([0-9]{2})-([0-9]{2})/", $date, $m); + $s = ''; + if (substr($date, 0, 4) == "0000") { + $date = G5_TIME_YMDHIS; + } + preg_match("/([0-9]{4})-([0-9]{2})-([0-9]{2})/", $date, $m); - // 년 - $s .= "