From 25bd7430fc3b30b3a0a8e80d6ef5e24223eb0e5b Mon Sep 17 00:00:00 2001 From: thisgun Date: Thu, 6 Sep 2018 17:18:45 +0900 Subject: [PATCH 01/13] =?UTF-8?q?=EC=9D=BC=EB=B6=80=20=EC=BD=94=EB=93=9C?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common.php | 6 +- lib/Hook/hook.class.php | 327 ++++++++++++++++++++++++++ lib/Hook/hook.extends.class.php | 161 +++++++++++++ lib/URI/uri.class.php | 7 + lib/common.lib.php | 4 +- lib/hook.lib.php | 125 ++++++++++ lib/uri.lib.php | 71 ++++++ skin/latest/basic/latest.skin.php | 4 +- skin/latest/notice/latest.skin.php | 2 +- skin/latest/pic_basic/latest.skin.php | 4 +- 10 files changed, 703 insertions(+), 8 deletions(-) create mode 100644 lib/Hook/hook.class.php create mode 100644 lib/Hook/hook.extends.class.php create mode 100644 lib/URI/uri.class.php create mode 100644 lib/hook.lib.php create mode 100644 lib/uri.lib.php 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); ?>
-

+

@@ -70,12 +74,12 @@ RewriteRule ^([0-9a-zA-Z_]+)/([0-9]+)$ bbs/board.php?bo_table=$1&wr_id=$2&rewri
 
 if (!-e $request_filename){
-    rewrite ^/g54/rss/([0-9a-zA-Z_]+)$ /g54/bbs/rss.php?bo_table=$1 break;
-    rewrite ^/g54/([0-9a-zA-Z_]+)$ /g54/bbs/board.php?bo_table=$1&rewrite=1 break;
-    rewrite ^/g54/([0-9a-zA-Z_]+)/([^/]+)/$ /g54/bbs/board.php?bo_table=$1&wr_seo_title=$2&rewrite=1 break;
-    rewrite ^/g54/([0-9a-zA-Z_]+)/write$ /g54/bbs/write.php?bo_table=$1&rewrite=1 break;
-    rewrite ^/g54/([0-9a-zA-Z_]+)/p([0-9]+)$ /g54/bbs/board.php?bo_table=$1&page=$2 break;
-    rewrite ^/g54/([0-9a-zA-Z_]+)/([0-9]+)$ /g54/bbs/board.php?bo_table=$1&wr_id=$2&rewrite=1 break;
+    rewrite ^rss/([0-9a-zA-Z_]+)$ /g54/bbs/rss.php?bo_table=$1 break;
+    rewrite ^([0-9a-zA-Z_]+)$ /g54/bbs/board.php?bo_table=$1&rewrite=1 break;
+    rewrite ^([0-9a-zA-Z_]+)/([^/]+)/$ /g54/bbs/board.php?bo_table=$1&wr_seo_title=$2&rewrite=1 break;
+    rewrite ^([0-9a-zA-Z_]+)/write$ /g54/bbs/write.php?bo_table=$1&rewrite=1 break;
+    rewrite ^([0-9a-zA-Z_]+)/p([0-9]+)$ /g54/bbs/board.php?bo_table=$1&page=$2 break;
+    rewrite ^([0-9a-zA-Z_]+)/([0-9]+)$ /g54/bbs/board.php?bo_table=$1&wr_id=$2&rewrite=1 break;
 }
 
diff --git a/mobile/tail.php b/mobile/tail.php index 74335a2af..e3c984bde 100644 --- a/mobile/tail.php +++ b/mobile/tail.php @@ -18,9 +18,9 @@ if(defined('G5_THEME_PATH')) {
Copyright © 소유하신 도메인. All rights reserved.
diff --git a/tail.php b/tail.php index 9a83862d4..427dc513e 100644 --- a/tail.php +++ b/tail.php @@ -37,9 +37,9 @@ if (G5_IS_MOBILE) {
<?php echo G5_VERSION ?>
diff --git a/theme/basic/tail.php b/theme/basic/tail.php index 33d3dcb76..23b828ecf 100644 --- a/theme/basic/tail.php +++ b/theme/basic/tail.php @@ -32,9 +32,9 @@ if (G5_IS_MOBILE) {
<?php echo G5_VERSION ?>
From cbeef0e4537bfd0b89a66febcccfb2339f6d09f5 Mon Sep 17 00:00:00 2001 From: thisgun Date: Thu, 20 Sep 2018 09:29:08 +0900 Subject: [PATCH 10/13] =?UTF-8?q?=EC=A7=A7=EC=9D=80=20=EC=A3=BC=EC=86=8C?= =?UTF-8?q?=20url=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- adm/admin.head.php | 2 +- adm/contentformupdate.php | 5 + adm/dbupgrade.php | 32 ++++++ adm/sql_write.sql | 2 + bbs/content.php | 10 +- bbs/list.php | 2 + bbs/view.php | 5 +- bbs/write_update.php | 2 +- common.php | 2 +- config.php | 3 + extend/debugbar.extend.php | 2 +- head.sub.php | 2 +- lib/Cache/FileCache.class.php | 187 ++++++++++++++++++++++++++++++++++ lib/URI/obj.class.php | 43 +++++--- lib/cache.lib.php | 78 ++++++++++++++ lib/common.lib.php | 80 +++++++-------- lib/get_data.lib.php | 69 +++++++++++-- lib/latest.lib.php | 79 +++++++------- lib/thumbnail.lib.php | 4 +- lib/uri.lib.php | 72 +++++++++---- mobile/content.php | 3 - theme/basic/head.sub.php | 2 +- 22 files changed, 542 insertions(+), 144 deletions(-) create mode 100644 lib/Cache/FileCache.class.php diff --git a/adm/admin.head.php b/adm/admin.head.php index 12934fc14..1ed34b228 100644 --- a/adm/admin.head.php +++ b/adm/admin.head.php @@ -1,7 +1,7 @@ 현재 DB 업그레이드가 완료된 상태입니다.'; ?> diff --git a/adm/sql_write.sql b/adm/sql_write.sql index 21cad8d7f..e4394f34a 100644 --- a/adm/sql_write.sql +++ b/adm/sql_write.sql @@ -10,6 +10,7 @@ CREATE TABLE `__TABLE_NAME__` ( `wr_option` set('html1','html2','secret','mail') NOT NULL, `wr_subject` varchar(255) NOT NULL, `wr_content` text NOT NULL, + `wr_seo_title` varchar(255) NOT NULL DEFAULT '' `wr_link1` text NOT NULL, `wr_link2` text NOT NULL, `wr_link1_hit` int(11) NOT NULL DEFAULT '0', @@ -39,6 +40,7 @@ CREATE TABLE `__TABLE_NAME__` ( `wr_9` varchar(255) NOT NULL, `wr_10` varchar(255) NOT NULL, PRIMARY KEY (`wr_id`), + KEY `wr_seo_title` (`wr_seo_title`), KEY `wr_num_reply_parent` (`wr_num`,`wr_reply`,`wr_parent`), KEY `wr_is_comment` (`wr_is_comment`,`wr_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; \ No newline at end of file diff --git a/bbs/content.php b/bbs/content.php index f9551ed80..818d52799 100644 --- a/bbs/content.php +++ b/bbs/content.php @@ -6,14 +6,18 @@ if( !isset($g5['content_table']) ){ die('관리자 모드에서 게시판관리->내용 관리를 먼저 확인해 주세요.'); } +// 내용 +if($co_seo_title){ + $co = get_content_by_field($g5['content_table'], 'content', 'co_seo_title', $co_seo_title); +} else { + $co = get_content_db($co_id); +} + if (G5_IS_MOBILE) { include_once(G5_MOBILE_PATH.'/content.php'); return; } -// 내용 -$sql = " select * from {$g5['content_table']} where co_id = '$co_id' "; -$co = sql_fetch($sql); if (!$co['co_id']) alert('등록된 내용이 없습니다.'); diff --git a/bbs/list.php b/bbs/list.php index 3ccc05a42..9677f3d32 100644 --- a/bbs/list.php +++ b/bbs/list.php @@ -200,6 +200,8 @@ if($page_rows > 0) { } } +g5_latest_cache_data($board['bo_table'], $list); + $write_pages = get_paging(G5_IS_MOBILE ? $config['cf_mobile_pages'] : $config['cf_write_pages'], $page, $total_page, get_pretty_url($bo_table, '', $qstr.'&page=')); $list_href = ''; diff --git a/bbs/view.php b/bbs/view.php index 68bfb864f..de5fd5359 100644 --- a/bbs/view.php +++ b/bbs/view.php @@ -69,14 +69,15 @@ if ($member['mb_level'] >= $board['bo_write_level']) { $reply_href = ''; if ($member['mb_level'] >= $board['bo_reply_level']) { //$reply_href = './write.php?w=r&bo_table='.$bo_table.'&wr_id='.$wr_id.$qstr; - $reply_href = get_pretty_url($bo_table, '', 'wr_id='.$wr_id.$qstr, 'write'); + $reply_href = get_pretty_url($bo_table, '', 'w=r&wr_id='.$wr_id.$qstr, 'write'); } // 수정, 삭제 링크 $update_href = $delete_href = ''; // 로그인중이고 자신의 글이라면 또는 관리자라면 비밀번호를 묻지 않고 바로 수정, 삭제 가능 if (($member['mb_id'] && ($member['mb_id'] === $write['mb_id'])) || $is_admin) { - $update_href = G5_BBS_URL.'/write.php?w=u&bo_table='.$bo_table.'&wr_id='.$wr_id.'&page='.$page.$qstr; + //$update_href = G5_BBS_URL.'/write.php?w=u&bo_table='.$bo_table.'&wr_id='.$wr_id.'&page='.$page.$qstr; + $update_href = get_pretty_url($bo_table, '', 'w=u&wr_id='.$wr_id.'&page='.$page.$qstr, 'write'); set_session('ss_delete_token', $token = uniqid(time())); $delete_href = G5_BBS_URL.'/delete.php?bo_table='.$bo_table.'&wr_id='.$wr_id.'&token='.$token.'&page='.$page.urldecode($qstr); } diff --git a/bbs/write_update.php b/bbs/write_update.php index e0d1d8ec8..b5719fd5b 100644 --- a/bbs/write_update.php +++ b/bbs/write_update.php @@ -211,7 +211,7 @@ if ($w == '' || $w == 'r') { if (!isset($_POST['wr_subject']) || !trim($_POST['wr_subject'])) alert('제목을 입력하여 주십시오.'); -$wr_seo_title = exist_seo_url_recursive('bbs', generate_seo_url($wr_subject), $write_table, $wr_id); +$wr_seo_title = exist_seo_title_recursive('bbs', generate_seo_title($wr_subject), $write_table, $wr_id); if ($w == '' || $w == 'r') { diff --git a/common.php b/common.php index b63190a25..52fbb1e9e 100644 --- a/common.php +++ b/common.php @@ -418,7 +418,7 @@ if ($bo_table) { if (isset($wr_id) && $wr_id) { $write = get_write($write_table, $wr_id); } else if (isset($wr_seo_title) && $wr_seo_title) { - $write = get_write_by_field($write_table, 'wr_seo_title', $wr_seo_title); + $write = get_content_by_field($write_table, 'bbs', 'wr_seo_title', $wr_seo_title); if( isset($write['wr_id']) ){ $wr_id = $write['wr_id']; } diff --git a/config.php b/config.php index 0079b0884..c5d57d715 100644 --- a/config.php +++ b/config.php @@ -153,6 +153,9 @@ define('G5_HANGUL', 16); // 한글 define('G5_SPACE', 32); // 공백 define('G5_SPECIAL', 64); // 특수문자 +// SEO TITLE 문단 길이 +define('G5_SEO_TITEL_WORD_CUT', 8); // SEO TITLE 문단 길이 + // 퍼미션 define('G5_DIR_PERMISSION', 0755); // 디렉토리 생성시 퍼미션 define('G5_FILE_PERMISSION', 0644); // 파일 생성시 퍼미션 diff --git a/extend/debugbar.extend.php b/extend/debugbar.extend.php index d01d8051e..a3f935665 100644 --- a/extend/debugbar.extend.php +++ b/extend/debugbar.extend.php @@ -14,7 +14,7 @@ function show_debug_bar() { } $memory_usage = function_exists( 'memory_get_peak_usage' ) ? memory_get_peak_usage() : memory_get_usage(); - $php_run_time = get_microtime()-$gml_debug['begin_time']; + $php_run_time = get_microtime()-$g5_debug['php']['begin_time']; include_once( G5_PLUGIN_PATH.'/debugbar/debugbar.php' ); } diff --git a/head.sub.php b/head.sub.php index 020900ea2..ae69e3664 100644 --- a/head.sub.php +++ b/head.sub.php @@ -8,7 +8,7 @@ if(!defined('G5_IS_ADMIN') && defined('G5_THEME_PATH') && is_file(G5_THEME_PATH. return; } -$begin_time = get_microtime(); +$g5_debug['php']['begin_time'] = $begin_time = get_microtime(); if (!isset($g5['title'])) { $g5['title'] = $config['cf_title']; diff --git a/lib/Cache/FileCache.class.php b/lib/Cache/FileCache.class.php new file mode 100644 index 000000000..f65948947 --- /dev/null +++ b/lib/Cache/FileCache.class.php @@ -0,0 +1,187 @@ +$name = $options[$name]; + } + } + } + + /** + * Fetches an entry from the cache. + * + * @param string $id + */ + public function get($id) + { + $data = $this->_get($id); + return is_array($data) ? $data['data'] : FALSE; + } + + protected function get_cache_file_path($id){ + + $id = str_replace(DIRECTORY_SEPARATOR, '/', $id); + $add_separator = ''; + $add_file_extension = ''; + + if( strpos('/', $id) !== 0 ){ + $add_separator = '/'; + } + + $ext = pathinfo($id, PATHINFO_EXTENSION); + + if( !(isset($ext['extension']) && $ext['extension']) ){ + $add_file_extension = $this->file_extension; + } + + return $this->_cache_path.$add_separator.$id.$add_file_extension; + + } + + protected function _get($id) + { + $cache_file_path = $this->get_cache_file_path($id); + + if ( ! is_file($cache_file_path) ) + { + return FALSE; + } + + $data = unserialize(file_get_contents( $cache_file_path )); + + if ($data['ttl'] > 0 && time() > $data['time'] + $data['ttl']) + { + unlink( $cache_file_path ); + return FALSE; + } + + return $data; + } + + public function write_file($path, $data, $mode = 'wb') + { + if ( ! $fp = @fopen($path, $mode)) + { + return FALSE; + } + + flock($fp, LOCK_EX); + + for ($result = $written = 0, $length = strlen($data); $written < $length; $written += $result) + { + if (($result = fwrite($fp, substr($data, $written))) === FALSE) + { + break; + } + } + + flock($fp, LOCK_UN); + fclose($fp); + + return is_int($result); + } + + /** + * Deletes a cache entry. + * + * @param string $id + * + * @return bool + */ + public function delete($id) + { + $cache_file_path = $this->get_cache_file_path($id); + + return file_exists($cache_file_path) ? unlink($cache_file_path) : FALSE; + } + + /** + * Puts data into the cache. + * + * @param string $id + * @param mixed $data + * @param int $lifetime + * + * @return bool + */ + public function save($id, $data, $ttl = 60, $raw = FALSE) + { + $cache_file_path = $this->get_cache_file_path($id); + + $contents = array( + 'time' => time(), + 'ttl' => $ttl, + 'data' => $data + ); + + if ($this->write_file($cache_file_path, serialize($contents))) + { + chmod($cache_file_path, G5_FILE_PERMISSION); + return TRUE; + } + + return FALSE; + } + + /** + * Fetches a base directory to store the cache data + * + * @return string + */ + protected function getCacheDirectory() + { + return $this->_cache_path; + } + + /** + * Encodes some data to a string so it can be written to disk + * + * @param mixed $data + * @param int $ttl + * @return string + */ + public function encode($data, $ttl) + { + $expire = null; + if ($ttl !== null) { + $expire = time() + $ttl; + } + return serialize(array($data, $expire)); + } + + /** + * Decodes a string encoded by {@see encode()} + * + * Must returns a tuple (data, expire). Expire + * can be null to signal no expiration. + * + * @param string $data + * @return array (data, expire) + */ + public function decode($data) + { + return unserialize($data); + } +} +?> \ No newline at end of file diff --git a/lib/URI/obj.class.php b/lib/URI/obj.class.php index d77c9ebb0..194f4f923 100644 --- a/lib/URI/obj.class.php +++ b/lib/URI/obj.class.php @@ -3,21 +3,27 @@ if (!defined('_GNUBOARD_')) exit; Class G5_object_store { public $writes = array(); - + public $contents = array(); + function get($type, $key, $group ='default') { switch ($type) { case 'bbs': - if( $this->exists('bbs', $key, $group) ){ - if ( is_object($this->writes[$group][$key]) ) - return clone $this->writes[$group][$key]; - else - return $this->writes[$group][$key]; - } - return false; + $datas = $this->writes; + break; + case 'content' : + $datas = $this->contents; break; } + if( $this->exists($type, $key, $group) ){ + if ( is_object($datas[$group][$key]) ) + return clone $datas[$group][$key]; + else + return $datas[$group][$key]; + } + + return false; } function exists($type, $key, $group = 'default' ) { @@ -28,6 +34,9 @@ Class G5_object_store { case 'bbs': $datas = $this->writes; break; + case 'content': + $datas = $this->contents; + break; } return isset($datas[$group]) && ( isset($datas[$group][$key]) || array_key_exists($key, $datas[$group]) ); @@ -41,6 +50,9 @@ Class G5_object_store { case 'bbs': $this->writes[$group][$key] = $data; break; + case 'content': + $this->contents[$group][$key] = $data; + break; } } @@ -48,13 +60,18 @@ Class G5_object_store { function delete($key, $group='default') { switch ($type) { case 'bbs': - if ( ! $this->exists('bbs', $key, $group) ) - return false; - - unset( $this->writes[$group][$key] ); - return true; + $datas = $this->writes; + break; + case 'content': + $datas = $this->contents; break; } + + if ( ! $this->exists('bbs', $key, $group) ) + return false; + + unset( $datas[$group][$key] ); + return true; } } //end Class diff --git a/lib/cache.lib.php b/lib/cache.lib.php index ba0b43379..2cad87d3e 100644 --- a/lib/cache.lib.php +++ b/lib/cache.lib.php @@ -1,6 +1,73 @@ G5_DATA_PATH.'/cache', + 'file_extension'=>'.php', + ); + $instance = new FileCache($options); + } + + return $instance; +} + +function g5_cache_secret_key(){ + static $str = ''; + + if( $str ) return $str; + + $str = substr(md5($_SERVER['SERVER_SOFTWARE'].$_SERVER['DOCUMENT_ROOT']), 0, 6); + + return $str; +} + +function g5_latest_cache_data($bo_table, $cache_list=array(), $find_wr_id=0){ + static $cache = array(); + + if( $bo_table && $cache_list && ! isset($cache[$bo_table]) ){ + foreach( (array) $cache_list as $wr ){ + if( empty($wr) || ! isset($wr['wr_id']) ) continue; + $cache[$bo_table][$wr['wr_id']] = $wr; + } + } + + if( $find_wr_id && isset($cache[$bo_table][$find_wr_id]) ){ + return $cache[$bo_table][$find_wr_id]; + } +} + +function g5_set_cache($key, $save_data, $ttl = null){ + + if( $cache = get_cachemanage_instance() ){ + $cache->save($key, $save_data, $ttl); + } +} + +function g5_get_cache($key){ + + if( $cache = get_cachemanage_instance() ){ + return $cache->get($key); + } + + return false; +} + +function g5_delete_cache($key){ + if( $cache = get_cachemanage_instance() ){ + return $cache->delete($key); + } + + return false; +} + function g5_delete_all_cache(){ $board_tables = get_board_names(); @@ -13,4 +80,15 @@ function g5_delete_all_cache(){ } +function g5_delete_cache_by_prefix($key){ + $files = glob(G5_DATA_PATH.'/cache/'.$key.'*'); + + foreach( (array) $files as $filename){ + if(empty($filename)) continue; + + unlink($filename); + } + + return ($files) ? true : false; +} ?> \ No newline at end of file diff --git a/lib/common.lib.php b/lib/common.lib.php index c9fa12b3d..9e9c53816 100644 --- a/lib/common.lib.php +++ b/lib/common.lib.php @@ -703,33 +703,6 @@ function get_write($write_table, $wr_id, $is_cache=false) return $write; } -// 게시판 테이블에서 하나의 행을 읽음 -function get_write_by_field($write_table, $where_field='', $where_value='', $is_cache=false) -{ - global $g5, $g5_object; - - if( ! in_array($where_field, array('wr_id', 'wr_num', 'wr_reply', 'wr_parent', 'wr_is_comment', 'ca_name', 'wr_option', 'wr_subject', 'wr_content', 'wr_seo_title', 'wr_link1', 'wr_link2', 'wr_hit', 'wr_good', 'wr_nogood', 'mb_id', 'wr_name', 'wr_email', 'wr_homepage', 'wr_datetime', 'wr_ip', 'wr_1', 'wr_2', 'wr_3', 'wr_4', 'wr_5', 'wr_6', 'wr_7', 'wr_8', 'wr_9', 'wr_10')) ){ - return ''; - } - - $where_value = strip_tags($where_value); - $key = md5($write_table.'|'.$where_field.'|'.$where_value); - - if( $is_cache && isset($cache[$key]) ){ - return $cache[$key]; - } - - $sql = " select * from {$write_table} where $where_field = '".sql_real_escape_string($where_value)."' "; - - $cache[$key] = sql_fetch($sql); - - $wr_bo_table = preg_replace('/^'.preg_quote($g5['write_prefix']).'/i', '', $write_table); - - $g5_object->set('bbs', $cache[$key]['wr_id'], $cache[$key], $wr_bo_table); - - return $cache[$key]; -} - // 게시판의 다음글 번호를 얻는다. function get_next_num($table) { @@ -2246,11 +2219,7 @@ function delete_cache_latest($bo_table) return; } - $files = glob(G5_DATA_PATH.'/cache/latest-'.$bo_table.'-*'); - if (is_array($files)) { - foreach ($files as $filename) - unlink($filename); - } + g5_delete_cache_by_prefix('latest-'.$bo_table.'-'); } // 게시판 첨부파일 썸네일 삭제 @@ -2534,6 +2503,8 @@ class html_process { } array_multisort($order, SORT_ASC, $index, SORT_ASC, $links); + + $links = apply_replace('html_process_css_files', $links); foreach($links as $link) { if(!trim($link[1])) @@ -2560,6 +2531,8 @@ class html_process { } array_multisort($order, SORT_ASC, $index, SORT_ASC, $scripts); + + $scripts = apply_replace('html_process_script_files', $scripts); foreach($scripts as $js) { if(!trim($js[1])) @@ -2588,6 +2561,17 @@ class html_process { if($javascript) $nl = "\n"; $buffer = preg_replace('#([^<]*]*>)#', "$javascript{$nl}$1", $buffer); + + $meta_tag = apply_replace('html_process_add_meta', ''); + + if( $meta_tag ){ + /* + content + 전에 메타태그가 위치 하도록 하게 한다. + */ + $nl = "\n"; + $buffer = preg_replace('#(]*>.*?)#', "$meta_tag{$nl}$1", $buffer); + } return $buffer; } @@ -3269,22 +3253,19 @@ function clean_query_string($query, $amp=true) return $str; } -function get_device_change_url() -{ +function get_params_merge_url($params){ $p = @parse_url(G5_URL); $href = $p['scheme'].'://'.$p['host']; if(isset($p['port']) && $p['port']) $href .= ':'.$p['port']; - $href .= $_SERVER['SCRIPT_NAME']; + if( $tmp = explode('?', $_SERVER['REQUEST_URI']) ){ + if( isset($tmp[0]) && $tmp[0] ) + $href .= $tmp[0]; + } $q = array(); - $device = 'device='.(G5_IS_MOBILE ? 'pc' : 'mobile'); - if($_SERVER['QUERY_STRING']) { foreach($_GET as $key=>$val) { - if($key == 'device') - continue; - $key = strip_tags($key); $val = strip_tags($val); @@ -3293,16 +3274,25 @@ function get_device_change_url() } } - if(!empty($q)) { - $query = http_build_query($q, '', '&'); - $href .= '?'.$query.'&'.$device; - } else { - $href .= '?'.$device; + if( is_array($params) ){ + $q = array_merge($q, $params); } + $query = http_build_query($q, '', '&'); + $href .= '?'.$query; + return $href; } +function get_device_change_url() +{ + $q = array(); + $device = (G5_IS_MOBILE ? 'pc' : 'mobile'); + $q['device'] = $device; + + return get_params_merge_url($q); +} + // 스킨 path function get_skin_path($dir, $skin) { diff --git a/lib/get_data.lib.php b/lib/get_data.lib.php index 51f7f30e0..b7f65ad99 100644 --- a/lib/get_data.lib.php +++ b/lib/get_data.lib.php @@ -19,22 +19,31 @@ function get_config($is_cache=false){ } function get_content_db($co_id, $is_cache=false){ - global $g5; + global $g5, $g5_object; static $cache = array(); + + $type = 'content'; $co_id = preg_replace('/[^a-z0-9_]/i', '', $co_id); - $key = md5($co_id); + $co = $g5_object->get($type, $co_id, $type); - if( $is_cache && isset($cache[$key]) ){ - return $cache[$key]; + if( !$co ){ + + $cache_file_name = "{$type}-{$co_id}-".g5_cache_secret_key(); + $co = g5_get_cache($cache_file_name, 10800); + + if( $co === false ){ + $sql = " select * from {$g5['content_table']} where co_id = '$co_id' "; + $co = sql_fetch($sql); + + g5_set_cache($cache_file_name, $co, 10800); + } + + $g5_object->set($type, $co_id, $co, $type); } - $sql = " select * from {$g5['content_table']} where co_id = '$co_id' "; - - $cache[$key] = sql_fetch($sql); - - return $cache[$key]; + return $co; } function get_board_names(){ @@ -79,6 +88,46 @@ function get_board_db($bo_table, $is_cache=false){ return $cache[$key]; } +// 게시판 테이블에서 하나의 행을 읽음 +function get_content_by_field($write_table, $type='bbs', $where_field='', $where_value='', $is_cache=false) +{ + global $g5, $g5_object; + + if( $type === 'content' ){ + $check_array = array('co_id', 'co_html', 'co_subject', 'co_content', 'co_seo_title', 'co_mobile_content', 'co_skin', 'co_mobile_skin', 'co_tag_filter_use', 'co_hit', 'co_include_head', 'co_include_tail'); + } else { + $check_array = array('wr_id', 'wr_num', 'wr_reply', 'wr_parent', 'wr_is_comment', 'ca_name', 'wr_option', 'wr_subject', 'wr_content', 'wr_seo_title', 'wr_link1', 'wr_link2', 'wr_hit', 'wr_good', 'wr_nogood', 'mb_id', 'wr_name', 'wr_email', 'wr_homepage', 'wr_datetime', 'wr_ip', 'wr_1', 'wr_2', 'wr_3', 'wr_4', 'wr_5', 'wr_6', 'wr_7', 'wr_8', 'wr_9', 'wr_10'); + } + + if( ! in_array($where_field, $check_array) ){ + return ''; + } + + $where_value = strip_tags($where_value); + $key = md5($write_table.'|'.$where_field.'|'.$where_value); + + if( $is_cache && isset($cache[$key]) ){ + return $cache[$key]; + } + + $sql = " select * from {$write_table} where $where_field = '".sql_real_escape_string($where_value)."' "; + + $cache[$key] = sql_fetch($sql); + + if( $type === 'content' ){ + + $g5_object->set($type, $cache[$key]['co_id'], $cache[$key], 'content'); + + } else { + + $wr_bo_table = preg_replace('/^'.preg_quote($g5['write_prefix']).'/i', '', $write_table); + $g5_object->set($type, $cache[$key]['wr_id'], $cache[$key], $wr_bo_table); + + } + + return $cache[$key]; +} + // 게시판 첨부파일 테이블에서 하나의 행을 읽음 function get_board_file_db($bo_table, $wr_id, $fields='*', $add_where='', $is_cache=false) { @@ -190,7 +239,7 @@ function get_thumbnail_find_cache($bo_table, $wr_id, $wr_key){ if( $wr_key === 'content' ){ $write_table = $g5['write_prefix'].$bo_table; - return get_write_db($write_table, $wr_id, 'wr_content', true); + return get_write($write_table, $wr_id, true); } return get_board_file_db($bo_table, $wr_id, 'bf_file, bf_content', "and bf_type between '1' and '3'", true); diff --git a/lib/latest.lib.php b/lib/latest.lib.php index 63fe44f47..eb9d1c05f 100644 --- a/lib/latest.lib.php +++ b/lib/latest.lib.php @@ -30,46 +30,27 @@ function latest($skin_dir='', $bo_table, $rows=10, $subject_len=40, $cache_time= } } - $cache_fwrite = false; + $caches = null; + if(G5_USE_CACHE) { - $cache_file = G5_DATA_PATH."/cache/latest-{$bo_table}-{$skin_dir}-{$rows}-{$subject_len}-serial.php"; - - if(!file_exists($cache_file)) { - $cache_fwrite = true; - } else { - if($cache_time > 0) { - $filetime = filemtime($cache_file); - if($filetime && $filetime < (G5_SERVER_TIME - 3600 * $cache_time)) { - @unlink($cache_file); - $cache_fwrite = true; - } - } - - if(!$cache_fwrite) { - try{ - $file_contents = file_get_contents($cache_file); - $file_ex = explode("\n\n", $file_contents); - $caches = unserialize(base64_decode($file_ex[1])); - - $list = (is_array($caches) && isset($caches['list'])) ? $caches['list'] : array(); - $bo_subject = (is_array($caches) && isset($caches['bo_subject'])) ? $caches['bo_subject'] : ''; - } catch(Exception $e){ - $cache_fwrite = true; - $list = array(); - } - } - } + $cache_file_name = "latest-{$bo_table}-{$skin_dir}-{$rows}-{$subject_len}-".g5_cache_secret_key(); + $caches = g5_get_cache($cache_file_name); + $cache_list = isset($caches['list']) ? $caches['list'] : array(); + g5_latest_cache_data($bo_table, $cache_list); } - if(!G5_USE_CACHE || $cache_fwrite) { + if( $caches === false ){ + $list = array(); - $sql = " select * from {$g5['board_table']} where bo_table = '{$bo_table}' "; - $board = sql_fetch($sql); + $board = get_board_db($bo_table, true); + $bo_subject = get_text($board['bo_subject']); + $board['bo_use_sideview'] = 0; // not use sideview $tmp_write_table = $g5['write_prefix'] . $bo_table; // 게시판 테이블 전체이름 $sql = " select * from {$tmp_write_table} where wr_is_comment = 0 order by wr_num limit 0, {$rows} "; + $result = sql_query($sql); for ($i=0; $row = sql_fetch_array($result); $i++) { try { @@ -82,22 +63,38 @@ function latest($skin_dir='', $bo_table, $rows=10, $subject_len=40, $cache_time= $row['file'] = array('count'=>0); } $list[$i] = get_list($row, $board, $latest_skin_url, $subject_len); - } - if($cache_fwrite) { - $handle = fopen($cache_file, 'w'); + $list[$i]['first_file_thumb'] = (isset($row['wr_file']) && $row['wr_file']) ? get_board_file_db($bo_table, $row['wr_id'], 'bf_file, bf_content', "and bf_type between '1' and '3'", true) : array('bf_file'=>'', 'bf_content'=>''); + $list[$i]['bo_table'] = $bo_table; + // 썸네일 추가 + if($options) { + $options_arr = explode(',', $options); + $thumb_width = $options_arr[0]; + $thumb_height = $options_arr[1]; + $thumb = get_list_thumbnail($bo_table, $row['wr_id'], $thumb_width, $thumb_height, false, true); + // 이미지 썸네일 + if($thumb['src']) { + $img_content = ''.$thumb['alt'].''; + $list[$i]['img_thumbnail'] = ''.$img_content.''; + // } else { + // $img_content = ''.$thumb['alt'].''; + } + } + } + g5_latest_cache_data($bo_table, $list); + + if(G5_USE_CACHE) { + $caches = array( 'list' => $list, 'bo_subject' => sql_escape_string($bo_subject), - ); - $cache_content = "\n\n"; - $cache_content .= base64_encode(serialize($caches)); //serialize + ); - fwrite($handle, $cache_content); - fclose($handle); - - @chmod($cache_file, 0640); + g5_set_cache($cache_file_name, $caches, 3600 * $cache_time); } + } else { + $list = $cache_list; + $bo_subject = (is_array($caches) && isset($caches['bo_subject'])) ? $caches['bo_subject'] : ''; } ob_start(); diff --git a/lib/thumbnail.lib.php b/lib/thumbnail.lib.php index 1665d207a..81f1da0fe 100644 --- a/lib/thumbnail.lib.php +++ b/lib/thumbnail.lib.php @@ -10,9 +10,7 @@ function get_list_thumbnail($bo_table, $wr_id, $thumb_width, $thumb_height, $is_ $filename = $alt = ""; $edt = false; - $sql = " select bf_file, bf_content from {$g5['board_file_table']} - where bo_table = '$bo_table' and wr_id = '$wr_id' and bf_type between '1' and '3' order by bf_no limit 0, 1 "; - $row = sql_fetch($sql); + $row = get_thumbnail_find_cache($bo_table, $wr_id, 'file'); if($row['bf_file']) { $filename = $row['bf_file']; diff --git a/lib/uri.lib.php b/lib/uri.lib.php index 7da5ce1be..f926705fa 100644 --- a/lib/uri.lib.php +++ b/lib/uri.lib.php @@ -10,48 +10,65 @@ function get_pretty_url($folder, $no='', $query_string='', $action='') global $g5, $config; $boards = get_board_names(); + $segments = array(); + $url = $add_query = ''; // use shortten url if($config['cf_bbs_rewrite']) { - if(in_array($folder, $boards)) { + + $segments[0] = G5_URL; + + if( $folder === 'content' && $no ){ // 내용관리 + + $segments[1] = $folder; + + if( $config['cf_bbs_rewrite'] > 1 ){ + + $get_content = get_content_db( $no , true); + $segments[2] = $get_content['co_seo_title'] ? urlencode($get_content['co_seo_title']).'/' : urlencode($no); + + } else { + $segments[2] = urlencode($no); + } + + } else if(in_array($folder, $boards)) { // 게시판 + + $segments[1] = $folder; - $url = G5_URL. '/'. $folder; if($no) { if( $config['cf_bbs_rewrite'] > 1 ){ $get_write = get_write( $g5['write_prefix'].$folder, $no , true); - - if( $get_write['wr_seo_title'] ){ - $url .= '/'. urlencode($get_write['wr_seo_title']).'/'; - } else { - $url .= '/'. $no; - } + + $segments[2] = $get_write['wr_seo_title'] ? urlencode($get_write['wr_seo_title']).'/' : urlencode($no); } else { - $url .= '/'. $no; + $segments[2] = urlencode($no); } } else if($action) { - $url .= '/'. $action; + $segments[2] = urlencode($action); } } else { - $url = G5_URL. '/'.$folder; + $segments[1] = $folder; if($no) { $no_array = explode("=", $no); $no_value = end($no_array); - $url .= '/'. $no_value; + $segments[2] = urlencode($no_value); } } + if($query_string) { // If the first character of the query string is '&', replace it with '?'. if(substr($query_string, 0, 1) == '&') { - $url .= preg_replace("/\&/", "?", $query_string, 1); + $add_query = preg_replace("/\&/", "?", $query_string, 1); } else { - $url .= '?'. $query_string; + $add_query = '?'. $query_string; } } + } else { // don't use shortten url if(in_array($folder, $boards)) { $url = G5_BBS_URL. '/board.php?bo_table='. $folder; @@ -70,9 +87,11 @@ function get_pretty_url($folder, $no='', $query_string='', $action='') $url .= ($no ? '?' : '&'). $query_string; } } + + $segments[0] = $url; } - return $url; + return implode('/', $segments).$add_query; } function short_url_clean($url, $add_qry=''){ @@ -87,7 +106,7 @@ function correct_goto_url($url){ return $url.'/'; } -function generate_seo_url($string, $wordLimit = 0){ +function generate_seo_title($string, $wordLimit=G5_SEO_TITEL_WORD_CUT){ $separator = '-'; if($wordLimit != 0){ @@ -105,6 +124,11 @@ function generate_seo_url($string, $wordLimit = 0){ ); $string = strip_tags($string); + + if( function_exists('mb_convert_encoding') ){ + $string = mb_convert_encoding($string, 'UTF-8', 'UTF-8'); + } + foreach ($trans as $key => $val){ $string = preg_replace('#'.$key.'#iu', $val, $string); } @@ -118,12 +142,24 @@ function exist_seo_url($type, $seo_title, $write_table, $sql_id=0){ global $g5; $exists_title = ''; + $sql_id = preg_replace('/[^a-z0-9_]/i', '', $sql_id); + if( $type === 'bbs' ){ $sql = "select wr_seo_title FROM {$write_table} WHERE wr_seo_title = '".sql_real_escape_string($seo_title)."' AND wr_id <> '$sql_id' limit 1"; + $row = sql_fetch($sql); + + echo $sql; $exists_title = $row['wr_seo_title']; + } else if ( $type === 'content' ){ + + $sql = "select co_seo_title FROM {$write_table} WHERE co_seo_title = '".sql_real_escape_string($seo_title)."' AND co_id <> '$sql_id' limit 1"; + $row = sql_fetch($sql); + + $exists_title = $row['co_seo_title']; + } else { return $seo_title; } @@ -134,7 +170,7 @@ function exist_seo_url($type, $seo_title, $write_table, $sql_id=0){ return ''; } -function exist_seo_url_recursive($type, $seo_title, $write_table, $sql_id=0){ +function exist_seo_title_recursive($type, $seo_title, $write_table, $sql_id=0){ static $count = 0; $seo_title_add = ($count > 0) ? utf8_strcut($seo_title, 255 - ($count+1), '')."-$count" : $seo_title; @@ -149,7 +185,7 @@ function exist_seo_url_recursive($type, $seo_title, $write_table, $sql_id=0){ return $seo_title_add; } - return exist_seo_url_recursive($type, $seo_title, $write_table, $sql_id); + return exist_seo_title_recursive($type, $seo_title, $write_table, $sql_id); } ?> \ No newline at end of file diff --git a/mobile/content.php b/mobile/content.php index cb683b2e1..08387f012 100644 --- a/mobile/content.php +++ b/mobile/content.php @@ -1,9 +1,6 @@ Date: Fri, 21 Sep 2018 18:16:54 +0900 Subject: [PATCH 11/13] =?UTF-8?q?=EC=A7=A7=EC=9D=80=20=EC=A3=BC=EC=86=8C?= =?UTF-8?q?=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- adm/_rewrite_config_form.php | 70 +++++++++++++++++++++--------------- adm/config_form_update.php | 2 ++ adm/css/admin.css | 9 ++++- lib/uri.lib.php | 69 +++++++++++++++++++++++++++++++++++ 4 files changed, 121 insertions(+), 29 deletions(-) diff --git a/adm/_rewrite_config_form.php b/adm/_rewrite_config_form.php index e5986ad4c..e40c7db44 100644 --- a/adm/_rewrite_config_form.php +++ b/adm/_rewrite_config_form.php @@ -7,9 +7,22 @@ $is_nginx = (stripos($_SERVER['SERVER_SOFTWARE'], 'nginx') !== false); $is_iis = !$is_apache && (stripos($_SERVER['SERVER_SOFTWARE'], 'microsoft-iis') !== false); +$is_write_file = false; + +if ( $is_nginx ){ + $is_write_file = false; +} else if ( $is_apache && ((!file_exists(G5_PATH.'/.htaccess') && is_writable($home_path)) || is_writable(G5_PATH.'/.htaccess')) ){ + $is_write_file = true; +} + $get_path_url = parse_url( G5_URL ); $base_path = isset($get_path_url['path']) ? $get_path_url['path'].'/' : '/'; + +// add_stylesheet('css 구문', 출력순서); 숫자가 작을 수록 먼저 출력됨 +add_stylesheet('', 11); +add_stylesheet('', 12); +add_javascript('', 10); ?>

짧은 주소 설정

@@ -20,6 +33,14 @@ $base_path = isset($get_path_url['path']) ? $get_path_url['path'].'/' : '/';

+
+ + + + + +
+
@@ -47,41 +68,34 @@ $base_path = isset($get_path_url['path']) ? $get_path_url['path'].'/' : '/';
-
+ -
- -# nginx configuration -
+        
 
     
diff --git a/adm/config_form_update.php b/adm/config_form_update.php index e10a4647d..86227e727 100644 --- a/adm/config_form_update.php +++ b/adm/config_form_update.php @@ -184,5 +184,7 @@ if( isset($_POST['cf_bbs_rewrite']) ){ start_event('admin_config_form_update'); +update_rewrite_rules(); + goto_url('./config_form.php', false); ?> \ No newline at end of file diff --git a/adm/css/admin.css b/adm/css/admin.css index 5b31afdc1..33d6d69d2 100644 --- a/adm/css/admin.css +++ b/adm/css/admin.css @@ -512,8 +512,15 @@ td.td_grpset {width:160px;border-left:1px solid #e9ecee;text-align:center} /* 환경설정 */ .cf_cert_hide {display:none} +.is_rewrite .connect-close {position:absolute;top:10px;right:10px;margin:0;padding:0;width:30px;height:30px;border:0;background:transparent;color:#383838;cursor:pointer;font-size:15px} +.is_rewrite .connect-close:hover {color:#ff5191} +.is_rewrite .connect-close .fa {margin:0 0 0 1px} +.is_rewrite .connect-close .txt {position:absolute;line-height:0;font-size:0;overflow:hidden} +.is_rewrite textarea{width:99%} +.is_rewrite .copy_title{margin-top:25px;margin-bottom:10px;font-weight:bold;text-align:left} + /* 관리권한설정 */ -#add_admin fieldset {margin-top:20px} +#add_admin fieldset {margin-top:20px;overflow:auto;padding:2px 6px;line-height:1.4;resize:vertical} /* 메일 테스트 */ diff --git a/lib/uri.lib.php b/lib/uri.lib.php index f926705fa..a1c56fb57 100644 --- a/lib/uri.lib.php +++ b/lib/uri.lib.php @@ -188,4 +188,73 @@ function exist_seo_title_recursive($type, $seo_title, $write_table, $sql_id=0){ return exist_seo_title_recursive($type, $seo_title, $write_table, $sql_id); } +function get_mod_rewrite_rules($return_string=false){ + + $get_path_url = parse_url( G5_URL ); + + $base_path = isset($get_path_url['path']) ? $get_path_url['path'].'/' : '/'; + + $rules = array(); + + $rules[] = '#### '.G5_VERSION.' rewrite BOF #####'; + $rules[] = ''; + $rules[] = 'RewriteEngine On'; + $rules[] = 'RewriteBase '.$base_path; + $rules[] = 'RewriteCond %{REQUEST_FILENAME} !-f'; + $rules[] = 'RewriteCond %{REQUEST_FILENAME} !-d'; + $rules[] = 'RewriteRule ^content/([0-9a-zA-Z_]+)$ '.G5_BBS_DIR.'/content.php?co_id=$1&rewrite=1 [L]'; + $rules[] = 'RewriteRule ^content/([^/]+)/$ '.G5_BBS_DIR.'/content.php?co_seo_title=$1&rewrite=1 [QSA,L]'; + $rules[] = 'RewriteRule ^rss/([0-9a-zA-Z_]+)$ '.G5_BBS_DIR.'/rss.php?bo_table=$1 [L]'; + $rules[] = 'RewriteRule ^([0-9a-zA-Z_]+)$ '.G5_BBS_DIR.'/board.php?bo_table=$1&rewrite=1 [QSA,L]'; + $rules[] = 'RewriteRule ^([0-9a-zA-Z_]+)/([^/]+)/$ '.G5_BBS_DIR.'/board.php?bo_table=$1&wr_seo_title=$2&rewrite=1 [QSA,L]'; + $rules[] = 'RewriteRule ^([0-9a-zA-Z_]+)/write$ '.G5_BBS_DIR.'/write.php?bo_table=$1&rewrite=1 [QSA,L]'; + $rules[] = 'RewriteRule ^([0-9a-zA-Z_]+)/p([0-9]+)$ '.G5_BBS_DIR.'/board.php?bo_table=$1&page=$2 [QSA,L]'; + $rules[] = 'RewriteRule ^([0-9a-zA-Z_]+)/([0-9]+)$ '.G5_BBS_DIR.'/board.php?bo_table=$1&wr_id=$2&rewrite=1 [QSA,L]'; + $rules[] = ''; + $rules[] = '#### '.G5_VERSION.' rewrite EOF #####'; + + return $return_string ? implode('\n', $rules) : $rules; +} + +function update_rewrite_rules(){ + + $is_apache = (stripos($_SERVER['SERVER_SOFTWARE'], 'apache') !== false); + + if($is_apache){ + $save_path = G5_PATH.'/.htaccess'; + + if( (!file_exists($save_path) && is_writable(G5_PATH)) || is_writable($save_path) ){ + + $rules = get_mod_rewrite_rules(); + + $bof_str = $rules[0]; + $eof_str = end($rules); + + if( file_exists($save_path) ){ + $code = file_get_contents($save_path); + + if( $code && strpos($code, $bof_str) !== false && strpos($code, $eof_str) !== false ){ + return true; + } + } + + $fp = fopen($save_path, "ab"); + flock( $fp, LOCK_EX ); + + $rewrite_str = implode("\n", $rules); + + fwrite( $fp, "\n" ); + fwrite( $fp, $rewrite_str ); + fwrite( $fp, "\n" ); + + flock( $fp, LOCK_UN ); + fclose($fp); + + return true; + } + } + + return false; + +} ?> \ No newline at end of file From e17e4dc869afbbe683fb2ce3d0e27d9591748367 Mon Sep 17 00:00:00 2001 From: thisgun Date: Mon, 1 Oct 2018 10:48:59 +0900 Subject: [PATCH 12/13] =?UTF-8?q?KVE-2018-0732=20=EC=B7=A8=EC=95=BD?= =?UTF-8?q?=EC=A0=90=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- adm/admin.lib.php | 13 +++++++++++++ adm/member_list_update.php | 16 ++++++++-------- lib/common.lib.php | 2 ++ 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/adm/admin.lib.php b/adm/admin.lib.php index 9509f3a8d..04919ebc4 100644 --- a/adm/admin.lib.php +++ b/adm/admin.lib.php @@ -489,6 +489,19 @@ if (isset($stx)) $arr_query[] = 'stx='.$stx; if (isset($page)) $arr_query[] = 'page='.$page; $qstr = implode("&", $arr_query); +if ( isset($_REQUEST) && $_REQUEST ){ + if( admin_referer_check(true) ){ + + foreach( $_REQUEST as $key=>$value ){ + if( $value && preg_match('/<\s?[^\>]*\/?\s?>/i', $value) && preg_match('/script.*?\/script/ius', $value) ){ + alert('요청 쿼리에 잘못된 스크립트문장이 있습니다.\\nXSS 공격일수도 있습니다.'); + die(); + } + } + + } +} + // 관리자에서는 추가 스크립트는 사용하지 않는다. //$config['cf_add_script'] = ''; ?> \ No newline at end of file diff --git a/adm/member_list_update.php b/adm/member_list_update.php index eb6d8f791..915fdb880 100644 --- a/adm/member_list_update.php +++ b/adm/member_list_update.php @@ -29,19 +29,19 @@ if ($_POST['act_button'] == "선택수정") { $msg .= $mb['mb_id'].' : 로그인 중인 관리자는 수정 할 수 없습니다.\\n'; } else { if($_POST['mb_certify'][$k]) - $mb_adult = $_POST['mb_adult'][$k]; + $mb_adult = (int) $_POST['mb_adult'][$k]; else $mb_adult = 0; $sql = " update {$g5['member_table']} - set mb_level = '{$_POST['mb_level'][$k]}', - mb_intercept_date = '{$_POST['mb_intercept_date'][$k]}', - mb_mailling = '{$_POST['mb_mailling'][$k]}', - mb_sms = '{$_POST['mb_sms'][$k]}', - mb_open = '{$_POST['mb_open'][$k]}', - mb_certify = '{$_POST['mb_certify'][$k]}', + set mb_level = '".sql_real_escape_string($_POST['mb_level'][$k])."', + mb_intercept_date = '".sql_real_escape_string($_POST['mb_intercept_date'][$k])."', + mb_mailling = '".sql_real_escape_string($_POST['mb_mailling'][$k])."', + mb_sms = '".sql_real_escape_string($_POST['mb_sms'][$k])."', + mb_open = '".sql_real_escape_string($_POST['mb_open'][$k])."', + mb_certify = '".sql_real_escape_string($_POST['mb_certify'][$k])."', mb_adult = '{$mb_adult}' - where mb_id = '{$_POST['mb_id'][$k]}' "; + where mb_id = '".sql_real_escape_string($_POST['mb_id'][$k])."' "; sql_query($sql); } } diff --git a/lib/common.lib.php b/lib/common.lib.php index 9e9c53816..ba8fc8a0d 100644 --- a/lib/common.lib.php +++ b/lib/common.lib.php @@ -740,6 +740,8 @@ function get_group($gr_id, $is_cache=false) function get_member($mb_id, $fields='*', $is_cache=false) { global $g5; + + $mb_id = preg_replace("/[^0-9a-z_]+/i", "", $mb_id); static $cache = array(); From f6d994d810f04f0a77b2e68108674a233b273f7e Mon Sep 17 00:00:00 2001 From: thisgun Date: Mon, 1 Oct 2018 18:35:08 +0900 Subject: [PATCH 13/13] =?UTF-8?q?=EB=A6=AC=EB=9D=BC=EC=9D=B4=ED=8A=B8=20?= =?UTF-8?q?=EA=B7=9C=EC=B9=99=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- adm/_rewrite_config_form.php | 16 +++++++++------- lib/uri.lib.php | 3 +-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/adm/_rewrite_config_form.php b/adm/_rewrite_config_form.php index e40c7db44..4c2b79dca 100644 --- a/adm/_rewrite_config_form.php +++ b/adm/_rewrite_config_form.php @@ -34,10 +34,10 @@ add_javascript('', 10);
- - + + - +
@@ -75,10 +75,12 @@ add_javascript('', 10); 닫기 -

아래 코드를 복사하여 .htaccess 파일에 붙여넣기 하여 주세요.

- +

.htaccess 파일에 적용할 코드입니다. + +
아래 코드를 복사하여 .htaccess 파일에 붙여넣기 하여 주세요. + +

+
짧은주소 설정