diff --git a/common.php b/common.php index 5ba0419cc..f8ddc31c1 100644 --- a/common.php +++ b/common.php @@ -123,6 +123,8 @@ $board = array(); $group = array(); $g5 = array(); +include_once(G5_LIB_PATH.'/hook.lib.php'); // hook 함수 파일 +include_once(G5_LIB_PATH.'/uri.lib.php'); // URL 함수 파일 //============================================================================== // 공통 @@ -637,5 +639,7 @@ header('Cache-Control: no-store, no-cache, must-revalidate'); // HTTP/1.1 header('Cache-Control: pre-check=0, post-check=0, max-age=0'); // HTTP/1.1 header('Pragma: no-cache'); // HTTP/1.0 +start_event('common_header'); + $html_process = new html_process(); -?> \ No newline at end of file +?> diff --git a/lib/Hook/hook.class.php b/lib/Hook/hook.class.php new file mode 100644 index 000000000..70452b041 --- /dev/null +++ b/lib/Hook/hook.class.php @@ -0,0 +1,327 @@ + + * @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(); + } +} + +?> \ No newline at end of file diff --git a/lib/Hook/hook.extends.class.php b/lib/Hook/hook.extends.class.php new file mode 100644 index 000000000..fd8b7cb82 --- /dev/null +++ b/lib/Hook/hook.extends.class.php @@ -0,0 +1,161 @@ + 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) && function_exists($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) { + $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]) ) { + + $found_key = array_search($func, array_column($that->callback_filters[$tag][$priority], 'function')); + + if( $found_key !== false ){ + unset($that->callback_filters[$tag][$priority][$found_key]); + } + } + + 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]) ) { + + $found_key = array_search($func, array_column($that->callbacks[$tag][$priority], 'function')); + + if( $found_key !== false ){ + unset($that->callbacks[$tag][$priority][$found_key]); + } + } + + return $is_remove; + } +} + +// end Hook Class + +?> \ No newline at end of file diff --git a/lib/URI/uri.class.php b/lib/URI/uri.class.php new file mode 100644 index 000000000..2f650e45b --- /dev/null +++ b/lib/URI/uri.class.php @@ -0,0 +1,7 @@ + \ No newline at end of file diff --git a/lib/common.lib.php b/lib/common.lib.php index 963701e47..ba5fd126e 100644 --- a/lib/common.lib.php +++ b/lib/common.lib.php @@ -405,9 +405,9 @@ function get_list($write_row, $board, $skin_url, $subject_len=40) $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'] = get_pretty_url($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['href'] = get_pretty_url($board['bo_table'], $list['wr_id'], $qstr); $list['comment_href'] = $list['href']; $list['icon_new'] = ''; diff --git a/lib/hook.lib.php b/lib/hook.lib.php new file mode 100644 index 000000000..3739fbcc3 --- /dev/null +++ b/lib/hook.lib.php @@ -0,0 +1,125 @@ + \ No newline at end of file diff --git a/lib/uri.lib.php b/lib/uri.lib.php new file mode 100644 index 000000000..ec02dad09 --- /dev/null +++ b/lib/uri.lib.php @@ -0,0 +1,71 @@ + \ No newline at end of file diff --git a/skin/latest/basic/latest.skin.php b/skin/latest/basic/latest.skin.php index 1c1a60698..2671779af 100644 --- a/skin/latest/basic/latest.skin.php +++ b/skin/latest/basic/latest.skin.php @@ -7,7 +7,7 @@ add_javascript('', 10); ?>
-

+

- 더보기 + 더보기
diff --git a/skin/latest/notice/latest.skin.php b/skin/latest/notice/latest.skin.php index 5091d3178..d994b10f3 100644 --- a/skin/latest/notice/latest.skin.php +++ b/skin/latest/notice/latest.skin.php @@ -7,7 +7,7 @@ add_javascript('', 10); ?>
-

+