@@ -198,7 +198,7 @@ include_once(G5_LIB_PATH.'/popular.lib.php');
} //end foreach $row
if ($i == 0) { ?>
-
메뉴 준비 중입니다. 관리자모드 > 환경설정 > 메뉴설정 에서 설정하실 수 있습니다.
+
메뉴 준비 중입니다. 관리자모드 > 환경설정 > 메뉴설정 에서 설정하실 수 있습니다.
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/install/install_db.php b/install/install_db.php
index 431ff1740..4f359bd12 100644
--- a/install/install_db.php
+++ b/install/install_db.php
@@ -13,6 +13,11 @@ include_once ('../config.php');
include_once ('../lib/common.lib.php');
include_once('./install.function.php'); // 인스톨 과정 함수 모음
+include_once('../lib/hook.lib.php'); // hook 함수 파일
+include_once('../lib/get_data.lib.php');
+include_once('../lib/uri.lib.php'); // URL 함수 파일
+include_once('../lib/cache.lib.php');
+
$title = G5_VERSION." 설치 완료 3/3";
include_once ('./install.inc.php');
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/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/obj.class.php b/lib/URI/obj.class.php
new file mode 100644
index 000000000..194f4f923
--- /dev/null
+++ b/lib/URI/obj.class.php
@@ -0,0 +1,79 @@
+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' ) {
+
+ $return_data = '';
+
+ switch ($type) {
+ 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]) );
+ }
+
+ function set($type, $key, $data=array(), $group='default') {
+ if ( is_object( $data ) )
+ $data = clone $data;
+
+ switch ($type) {
+ case 'bbs':
+ $this->writes[$group][$key] = $data;
+ break;
+ case 'content':
+ $this->contents[$group][$key] = $data;
+ break;
+ }
+
+ }
+
+ function delete($key, $group='default') {
+ switch ($type) {
+ case 'bbs':
+ $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
+
+?>
\ 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..254c0e6af
--- /dev/null
+++ b/lib/URI/uri.class.php
@@ -0,0 +1,160 @@
+basename = $basename;
+ $this->parts = $parts;
+
+ }
+
+ public function setRelative($relativevar) {
+ /* count the number of slash
+ to define relative path */
+ $numslash = count($this->parts);
+ $slashes="";
+ for($i=0;$i<$numslash;$i++){
+ $slashes .= "../";
+ }
+ $this->slashes = $slashes;
+ /* make relative path variable available for webpage */
+ //eval("\$GLOBALS['$relativevar'] = '$slashes';");
+
+ $links = array();
+ $links[$relativevar] = $slashes;
+
+ return $links;
+ }
+
+ public function getParts() {
+ /* return array of sliced query string */
+ return $this->parts;
+ }
+
+ public function setParts() {
+ /* pair off query string variable and query string value */
+ $numargs = func_num_args();
+ $arg_list = func_get_args();
+ $urlparts = $this->getParts();
+ $links = array();
+ for ($i = 0; $i < $numargs; $i++) {
+ /* make them available for webpage */
+ //eval ("\$GLOBALS['".$arg_list[$i] ."']= '$urlparts[$i]';");
+ $links[$arg_list[$i]] = $urlparts[$i];
+ }
+
+ return $links;
+ }
+
+ public function makeClean($stringurl) {
+ /* convert normal URL query string to clean URL */
+ $url=parse_url($stringurl);
+ $strurl = basename($url['path'],".php");
+ $qstring = parse_str($url['query'],$vars);
+ while(list($k,$v) = each($vars)) $strurl .= "/".$v;
+ return $strurl;
+ }
+
+ public function url_clean($stringurl, $add_qry='') {
+ global $config, $g5;
+
+ $stringurl = str_replace('&', '&', $stringurl);
+ $url=parse_url($stringurl);
+ $strurl = basename($url['path'],".php");
+
+ if( ! in_array($strurl, array('board', 'view_comment.page')) ){ //게시판이 아니면 리턴
+ return $stringurl;
+ }
+
+ $return_url = '';
+ $qstring = parse_str($url['query'],$vars);
+
+ // 예) Array ( [scheme] => http [host] => sir.kr [path] => /bbs/board.php [query] => wr_id=1110870&bo_table=cm_free&cpage=1 [fragment] => c_1110946 )
+ //while(list($k,$v) = each($vars)) $strurl .= "/".$v;
+
+ $tmp = array('bo_table'=>'', 'wr_id'=>'');
+ $s = array();
+
+ foreach( $tmp as $key=>$v ){
+ if( !isset($vars[$key]) || empty($vars[$key]) ) continue;
+ $add = '';
+ $s[$key] = $vars[$key];
+ }
+
+ if( $config['cf_bbs_rewrite'] > 1 && (isset($s['wr_id']) && $s['wr_id']) && (isset($s['bo_table']) && $s['bo_table']) ){
+ $get_write = get_write( get_write_table_name($s['bo_table']), $s['wr_id'], true);
+
+ if( $get_write['wr_seo_title'] ){
+ unset($s['wr_id']);
+ $s['wr_seo_title'] = $get_write['wr_seo_title'].'/';
+ }
+
+ }
+
+ $fragment = isset($url['fragment']) ? '#'.$url['fragment'] : '';
+
+ $host = G5_URL;
+
+ if( isset($url['host']) ){
+ $str_path = isset($url['path']) ? $url['path'] : '';
+ $http = 'http://';
+ if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']=='on') {
+ $http = 'https://';
+ }
+ $host = $http.$url['host'].str_replace('/'.G5_BBS_DIR.'/board.php', '', $str_path);
+ }
+
+ $add_param = '';
+
+ if( $result = array_diff_key($vars, $tmp ) ){
+ $add_param = '?'.http_build_query($result,'','&');
+ }
+
+ if( $add_qry ){
+ $add_param .= $add_param ? '&'.$add_qry : '?'.$add_qry;
+ }
+
+ while(list($k,$v) = each($s)) $return_url .= "/".$v;
+
+ return $host.$return_url.$add_param.$fragment;
+ }
+}
+?>
\ No newline at end of file
diff --git a/lib/cache.lib.php b/lib/cache.lib.php
new file mode 100644
index 000000000..2cad87d3e
--- /dev/null
+++ b/lib/cache.lib.php
@@ -0,0 +1,94 @@
+ 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();
+
+ foreach( $board_tables as $board_table ){
+ delete_cache_latest($board_table);
+ }
+
+ start_event('adm_cache_delete', $board_tables);
+
+}
+
+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 8685f4e52..ba8fc8a0d 100644
--- a/lib/common.lib.php
+++ b/lib/common.lib.php
@@ -335,11 +335,13 @@ function get_dirsize($dir)
// 게시물 정보($write_row)를 출력하기 위하여 $list로 가공된 정보를 복사 및 가공
function get_list($write_row, $board, $skin_url, $subject_len=40)
{
- global $g5, $config;
+ global $g5, $config, $g5_object;
global $qstr, $page;
//$t = get_microtime();
+ $g5_object->set('bbs', $write_row['wr_id'], $write_row, $board['bo_table']);
+
// 배열전체를 복사
$list = $write_row;
unset($write_row);
@@ -405,9 +407,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'] = '';
@@ -682,13 +684,24 @@ function get_sql_search($search_ca_name, $search_field, $search_text, $search_op
return $str;
}
-
// 게시판 테이블에서 하나의 행을 읽음
-function get_write($write_table, $wr_id)
+function get_write($write_table, $wr_id, $is_cache=false)
{
- return sql_fetch(" select * from $write_table where wr_id = '$wr_id' ");
-}
+ global $g5, $g5_object;
+ $wr_bo_table = preg_replace('/^'.preg_quote($g5['write_prefix']).'/i', '', $write_table);
+
+ $write = $g5_object->get('bbs', $wr_id, $wr_bo_table);
+
+ if( !$write ){
+ $sql = " select * from {$write_table} where wr_id = '{$wr_id}' ";
+ $write = sql_fetch($sql);
+
+ $g5_object->set('bbs', $wr_id, $write, $wr_bo_table);
+ }
+
+ return $write;
+}
// 게시판의 다음글 번호를 얻는다.
function get_next_num($table)
@@ -702,22 +715,47 @@ function get_next_num($table)
// 그룹 설정 테이블에서 하나의 행을 읽음
-function get_group($gr_id)
+function get_group($gr_id, $is_cache=false)
{
global $g5;
- return sql_fetch(" select * from {$g5['group_table']} where gr_id = '$gr_id' ");
+ static $cache = array();
+
+ $gr_id = preg_replace('/[^a-z0-9_]/i', '', $gr_id);
+ $key = md5($gr_id);
+
+ if( $is_cache && isset($cache[$key]) ){
+ return $cache[$key];
+ }
+
+ $sql = " select * from {$g5['group_table']} where gr_id = '$gr_id' ";
+
+ $cache[$key] = apply_replace('get_group', sql_fetch($sql), $gr_id, $is_cache);
+
+ return $cache[$key];
}
// 회원 정보를 얻는다.
-function get_member($mb_id, $fields='*')
+function get_member($mb_id, $fields='*', $is_cache=false)
{
global $g5;
$mb_id = preg_replace("/[^0-9a-z_]+/i", "", $mb_id);
- return sql_fetch(" select $fields from {$g5['member_table']} where mb_id = TRIM('$mb_id') ");
+ static $cache = array();
+
+ $key = md5($fields);
+
+ if( $is_cache && isset($cache[$mb_id]) && isset($cache[$mb_id][$key]) ){
+ return $cache[$mb_id][$key];
+ }
+
+ $sql = " select $fields from {$g5['member_table']} where mb_id = TRIM('$mb_id') ";
+
+ $cache[$mb_id][$key] = apply_replace('get_member', sql_fetch($sql), $mb_id, $fields, $is_cache);
+
+ return $cache[$mb_id][$key];
}
@@ -1259,7 +1297,7 @@ function get_sideview($mb_id, $name='', $email='', $homepage='')
if(!$bo_table)
return $name;
- $tmp_name = '
'.$name.' ';
+ $tmp_name = '
'.$name.' ';
$title_mb_id = '[비회원]';
}
@@ -1277,9 +1315,9 @@ function get_sideview($mb_id, $name='', $email='', $homepage='')
$str2 .= "
자기소개 \n";
if($bo_table) {
if($mb_id)
- $str2 .= "
아이디로 검색 \n";
+ $str2 .= "
아이디로 검색 \n";
else
- $str2 .= "
이름으로 검색 \n";
+ $str2 .= "
이름으로 검색 \n";
}
if($mb_id)
$str2 .= "
전체게시물 \n";
@@ -1484,7 +1522,7 @@ function sql_set_charset($charset, $link=null)
// mysql connect resource 지정 - 명랑폐인님 제안
function sql_query($sql, $error=G5_DISPLAY_SQL_ERROR, $link=null)
{
- global $g5;
+ global $g5, $g5_debug;
if(!$link)
$link = $g5['connect_db'];
@@ -1497,6 +1535,10 @@ function sql_query($sql, $error=G5_DISPLAY_SQL_ERROR, $link=null)
// `information_schema` DB로의 접근을 허락하지 않습니다.
$sql = preg_replace("#^select.*from.*where.*`?information_schema`?.*#i", "select 1", $sql);
+ $is_debug = get_permission_debug_show();
+
+ $start_time = $is_debug ? get_microtime() : 0;
+
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']}");
@@ -1511,6 +1553,15 @@ function sql_query($sql, $error=G5_DISPLAY_SQL_ERROR, $link=null)
}
}
+ if($result && $is_debug) {
+ // 여기에 실행한 sql문을 화면에 표시하는 로직 넣기
+ $g5_debug['sql'][] = array(
+ 'sql' => $sql,
+ 'start_time' => $start_time,
+ 'end_time' => get_microtime(),
+ );
+ }
+
return $result;
}
@@ -1996,6 +2047,16 @@ function is_utf8($str)
// 출처 : https://www.google.co.kr/search?q=utf8_strcut&aq=f&oq=utf8_strcut&aqs=chrome.0.57j0l3.826j0&sourceid=chrome&ie=UTF-8
function utf8_strcut( $str, $size, $suffix='...' )
{
+ if( function_exists('mb_strlen') && function_exists('mb_substr') ){
+
+ if(mb_strlen($str)<=$size) {
+ return $str;
+ } else {
+ $str = mb_substr($str, 0, $size, 'utf-8');
+ $str .= $suffix;
+ }
+
+ } else {
$substr = substr( $str, 0, $size * 2 );
$multi_size = preg_match_all( '/[\x80-\xff]/', $substr, $multi_chars );
@@ -2007,8 +2068,9 @@ function utf8_strcut( $str, $size, $suffix='...' )
$str = preg_replace( '/(([\x80-\xff]{3})*?)([\x80-\xff]{0,2})$/', '$1', $str );
$str .= $suffix;
}
+ }
- return $str;
+ return $str;
}
@@ -2159,11 +2221,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.'-');
}
// 게시판 첨부파일 썸네일 삭제
@@ -2447,6 +2505,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]))
@@ -2473,6 +2533,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]))
@@ -2501,6 +2563,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;
}
@@ -2672,10 +2745,16 @@ function get_qa_config($fld='*')
{
global $g5;
- $sql = " select $fld from {$g5['qa_config_table']} ";
- $row = sql_fetch($sql);
+ static $cache = array();
- return $row;
+ if( $is_cache && !empty($cache) ){
+ return $cache;
+ }
+
+ $sql = " select * from {$g5['qa_config_table']} ";
+ $cache = apply_replace('get_qa_config', sql_fetch($sql));
+
+ return $cache;
}
// get_sock 함수 대체
@@ -3176,22 +3255,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);
@@ -3200,16 +3276,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
new file mode 100644
index 000000000..b7f65ad99
--- /dev/null
+++ b/lib/get_data.lib.php
@@ -0,0 +1,336 @@
+get($type, $co_id, $type);
+
+ 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);
+ }
+
+ return $co;
+}
+
+function get_board_names(){
+ global $g5;
+
+ static $boards = array();
+
+ if( ! $boards ){
+ $sql = " select bo_table from {$g5['board_table']} ";
+ $result = sql_query($sql);
+
+ while ($row = sql_fetch_array($result)) {
+ $boards[] = $row['bo_table'];
+ }
+ }
+
+ return $boards;
+}
+
+function get_board_db($bo_table, $is_cache=false){
+ global $g5;
+
+ static $cache = array();
+
+ $cache = apply_replace('get_board_db_cache', $cache, $bo_table, $is_cache);
+
+ $key = md5($bo_table);
+
+ $bo_table = preg_replace('/[^a-z0-9_]/i', '', $bo_table);
+ if( $is_cache && isset($cache[$key]) ){
+ return $cache[$key];
+ }
+
+ if( !($cache[$key] = apply_replace('get_board_db', array(), $bo_table)) ){
+
+ $sql = " select * from {$g5['board_table']} where bo_table = '$bo_table' ";
+
+ $cache[$key] = sql_fetch($sql);
+
+ }
+
+ 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)
+{
+ global $g5;
+
+ static $cache = array();
+
+ $wr_id = (int) $wr_id;
+ $key = md5($bo_table.'|'.$wr_id.$fields.$add_where);
+
+ if( $is_cache && isset($cache[$key]) ){
+ return $cache[$key];
+ }
+
+ $sql = " select $fields from {$g5['board_file_table']}
+ where bo_table = '$bo_table' and wr_id = '$wr_id' $add_where order by bf_no limit 0, 1 ";
+
+ $cache[$key] = sql_fetch($sql);
+
+ return $cache[$key];
+}
+
+function get_poll_db($po_id, $is_cache=false){
+ global $g5;
+
+ static $cache = array();
+
+ $po_id = (int) $po_id;
+ $key = md5($po_id);
+
+ if( $is_cache && isset($cache[$key]) ){
+ return $cache[$key];
+ }
+
+ $sql = " select * from {$g5['poll_table']} where po_id = '{$po_id}' ";
+
+ $cache[$key] = sql_fetch($sql);
+
+ return $cache[$key];
+}
+
+function get_point_db($po_id, $is_cache=false){
+ global $g5;
+
+ static $cache = array();
+
+ $po_id = (int) $po_id;
+ $key = md5($po_id);
+
+ if( $is_cache && isset($cache[$key]) ){
+ return $cache[$key];
+ }
+
+ $sql = " select * from {$g5['point_table']} where po_id = '{$po_id}' ";
+
+ $cache[$key] = sql_fetch($sql);
+
+ return $cache[$key];
+}
+
+function get_mail_content_db($ma_id, $is_cache=false){
+ global $g5;
+
+ static $cache = array();
+
+ $ma_id = (int) $ma_id;
+ $key = md5($ma_id);
+
+ if( $is_cache && isset($cache[$key]) ){
+ return $cache[$key];
+ }
+
+ $sql = " select * from {$g5['mail_table']} where ma_id = '{$ma_id}' ";
+
+ $cache[$key] = sql_fetch($sql);
+
+ return $cache[$key];
+}
+
+function get_qacontent_db($qa_id, $is_cache=false){
+ global $g5;
+
+ static $cache = array();
+
+ $qa_id = (int) $qa_id;
+ $key = md5($qa_id);
+
+ if( $is_cache && isset($cache[$key]) ){
+ return $cache[$key];
+ }
+
+ $sql = " select * from {$g5['qa_content_table']} where qa_id = '{$qa_id}' ";
+
+ $cache[$key] = sql_fetch($sql);
+
+ return $cache[$key];
+}
+
+function get_thumbnail_find_cache($bo_table, $wr_id, $wr_key){
+ global $g5;
+
+ if( $cache_content = g5_latest_cache_data($bo_table, array(), $wr_id) ){
+ if( $wr_key === 'content' ){
+ return $cache_content;
+ } else if ( $wr_key === 'file' && isset($cache_content['first_file_thumb']) ){
+ return $cache_content['first_file_thumb'];
+ }
+ }
+
+ if( $wr_key === 'content' ){
+ $write_table = $g5['write_prefix'].$bo_table;
+ 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);
+}
+
+function get_write_table_name($bo_table){
+ global $g5;
+
+ return $g5['write_prefix'].preg_replace('/[^a-z0-9_]/i', '', $bo_table);
+}
+
+function get_db_charset($charset){
+
+ $add_charset = $charset;
+
+ if ( 'utf8mb4' === $charset ) {
+ $add_charset .= ' COLLATE utf8mb4_unicode_ci';
+ }
+
+ return apply_replace('get_db_charset', $add_charset, $charset);
+}
+
+function get_db_create_replace($sql_str){
+
+ if( in_array(strtolower(G5_DB_ENGINE), array('innodb', 'myisam')) ){
+ $sql_str = preg_replace('/ENGINE=MyISAM/', 'ENGINE='.G5_DB_ENGINE, $sql_str);
+ } else {
+ $sql_str = preg_replace('/ENGINE=MyISAM/', '', $sql_str);
+ }
+
+ if( G5_DB_CHARSET !== 'utf8' ){
+ $sql_str = preg_replace('/CHARSET=utf8/', 'CHARACTER SET '.get_db_charset(G5_DB_CHARSET), $sql_str);
+ }
+
+ return $sql_str;
+}
+
+function get_permission_debug_show(){
+ global $member;
+
+ $bool = false;
+ if ( defined('G5_DEBUG') && G5_DEBUG ){
+ $bool = true;
+ }
+
+ return apply_replace('get_permission_debug_show', $bool, $member);
+}
+
+function get_check_mod_rewrite(){
+
+ if( function_exists('apache_get_modules') && in_array('mod_rewrite', apache_get_modules()) )
+ $mod_rewrite = 1;
+ elseif( isset($_SERVER['IIS_UrlRewriteModule']) )
+ $mod_rewrite = 1;
+ else
+ $mod_rewrite = 0;
+
+ return $mod_rewrite;
+}
+
+// 생성되면 안되는 게시판명
+function get_bo_table_banned_word(){
+
+ $folders = array();
+
+ foreach(glob(G5_PATH.'/*', GLOB_ONLYDIR) as $dir) {
+ $folders[] = basename($dir);
+ }
+
+ return apply_replace('get_bo_table_banned_word', $folders);
+}
+
+// 읽지 않은 메모 갯수 반환
+function get_memo_not_read($mb_id, $add_where='')
+{
+ global $g5;
+
+ $sql = " SELECT count(*) as cnt FROM {$g5['memo_table']} WHERE me_recv_mb_id = '$mb_id' and me_type= 'recv' and me_read_datetime like '0%' $add_where ";
+ $row = sql_fetch($sql, false);
+
+ return $row['cnt'];
+}
+
+function get_scrap_totals($mb_id=''){
+ global $g5;
+
+ $add_where = $mb_id ? " and mb_id = '$mb_id' " : '';
+
+ $sql = " select count(*) as cnt from {$g5['scrap_table']} where 1=1 $add_where";
+ $row = sql_fetch($sql, false);
+
+ return $row['cnt'];
+}
+?>
\ No newline at end of file
diff --git a/lib/hook.lib.php b/lib/hook.lib.php
new file mode 100644
index 000000000..77ca17253
--- /dev/null
+++ b/lib/hook.lib.php
@@ -0,0 +1,125 @@
+
\ No newline at end of file
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 = '
';
+ $list[$i]['img_thumbnail'] = '
'.$img_content.' ';
+ // } else {
+ // $img_content = '
';
+ }
+ }
+ }
+ 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
new file mode 100644
index 000000000..00c620a04
--- /dev/null
+++ b/lib/uri.lib.php
@@ -0,0 +1,259 @@
+ 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;
+
+ if($no) {
+
+ if( $config['cf_bbs_rewrite'] > 1 ){
+
+ $get_write = get_write( $g5['write_prefix'].$folder, $no , true);
+
+ $segments[2] = $get_write['wr_seo_title'] ? urlencode($get_write['wr_seo_title']).'/' : urlencode($no);
+
+ } else {
+ $segments[2] = urlencode($no);
+ }
+
+ } else if($action) {
+ $segments[2] = urlencode($action);
+ }
+
+ } else {
+ $segments[1] = $folder;
+ if($no) {
+ $no_array = explode("=", $no);
+ $no_value = end($no_array);
+ $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) == '&') {
+ $add_query = preg_replace("/\&/", "?", $query_string, 1);
+ } else {
+ $add_query = '?'. $query_string;
+ }
+ }
+
+ } else { // don't use shortten url
+ if(in_array($folder, $boards)) {
+ $url = G5_BBS_URL. '/board.php?bo_table='. $folder;
+ if($no) {
+ $url .= '&wr_id='. $no;
+ }
+ if($query_string) {
+ $url .= '&'. $query_string;
+ }
+ } else {
+ $url = G5_BBS_URL. '/'.$folder.'.php';
+ if($no) {
+ $url .= '?'. $no;
+ }
+ if($query_string) {
+ $url .= ($no ? '?' : '&'). $query_string;
+ }
+ }
+
+ $segments[0] = $url;
+ }
+
+ return implode('/', $segments).$add_query;
+}
+
+function short_url_clean($url, $add_qry=''){
+ if( class_exists('G5_URI') ){
+ return G5_URI::getInstance()->url_clean($url, $add_qry);
+ }
+
+ return $url;
+}
+
+function correct_goto_url($url){
+ return $url.'/';
+}
+
+function generate_seo_title($string, $wordLimit=G5_SEO_TITEL_WORD_CUT){
+ $separator = '-';
+
+ if($wordLimit != 0){
+ $wordArr = explode(' ', $string);
+ $string = implode(' ', array_slice($wordArr, 0, $wordLimit));
+ }
+
+ $quoteSeparator = preg_quote($separator, '#');
+
+ $trans = array(
+ '&.+?;' => '',
+ '[^\w\d _-]' => '',
+ '\s+' => $separator,
+ '('.$quoteSeparator.')+'=> $separator
+ );
+
+ $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);
+ }
+
+ $string = strtolower($string);
+
+ return trim(trim($string, $separator));
+}
+
+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;
+ }
+
+ if ($exists_title)
+ return 'is_exists';
+ else
+ return '';
+}
+
+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;
+
+ if( ! exist_seo_url($type, $seo_title_add, $write_table, $sql_id) ){
+ return $seo_title_add;
+ }
+
+ $count++;
+
+ if( $count > 253 ){
+ return $seo_title_add;
+ }
+
+ 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_]+)/([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
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 @@
'