짧은 주소 url 수정
This commit is contained in:
1 parent
7547b6e0ab
commit
cbeef0e453
22 files changed
+542
-144
No files matched your search
@@ -0,0 +1,187 @@
|
||||
<?php
|
||||
if (!defined('_GNUBOARD_')) exit;
|
||||
|
||||
class FileCache
|
||||
{
|
||||
|
||||
/**
|
||||
* The root cache directory.
|
||||
* @var string
|
||||
*/
|
||||
protected $_cache_path = '/tmp/cache';
|
||||
|
||||
/** @var string */
|
||||
protected $file_extension = '';
|
||||
|
||||
/**
|
||||
* Creates a FileCache object
|
||||
*
|
||||
* @param array $options
|
||||
*/
|
||||
public function __construct($options = array())
|
||||
{
|
||||
$available_options = array('_cache_path', 'file_extension');
|
||||
foreach ($available_options as $name) {
|
||||
if (isset($options[$name])) {
|
||||
$this->$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);
|
||||
}
|
||||
}
|
||||
?>
|
||||
+30
-13
@@ -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
|
||||
|
||||
@@ -1,6 +1,73 @@
|
||||
<?php
|
||||
if (!defined('_GNUBOARD_')) exit;
|
||||
|
||||
include_once(dirname(__FILE__) .'/Cache/FileCache.class.php');
|
||||
|
||||
function get_cachemanage_instance(){
|
||||
static $instance = null;
|
||||
|
||||
if( ! (defined('G5_USE_CACHE') && G5_USE_CACHE) ) return $instance;
|
||||
|
||||
if( $instance === null ){
|
||||
$options = array(
|
||||
'_cache_path'=> 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;
|
||||
}
|
||||
?>
|
||||
+35
-45
@@ -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('#(</head>[^<]*<body[^>]*>)#', "$javascript{$nl}$1", $buffer);
|
||||
|
||||
$meta_tag = apply_replace('html_process_add_meta', '');
|
||||
|
||||
if( $meta_tag ){
|
||||
/*
|
||||
</title>content<body>
|
||||
전에 메타태그가 위치 하도록 하게 한다.
|
||||
*/
|
||||
$nl = "\n";
|
||||
$buffer = preg_replace('#(<title[^>]*>.*?</title>)#', "$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)
|
||||
{
|
||||
|
||||
+59
-10
@@ -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);
|
||||
|
||||
+38
-41
@@ -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 = '<img src="'.$thumb['src'].'" alt="'.$thumb['alt'].'" width="'.$thumb_width.'" height="'.$thumb_height.'">';
|
||||
$list[$i]['img_thumbnail'] = '<a href="'.$list[$i]['href'].'" class="lt_img">'.$img_content.'</a>';
|
||||
// } else {
|
||||
// $img_content = '<img src="'. G5_IMG_URL.'/no_img.png'.'" alt="'.$thumb['alt'].'" width="'.$thumb_width.'" height="'.$thumb_height.'" class="no_img">';
|
||||
}
|
||||
}
|
||||
}
|
||||
g5_latest_cache_data($bo_table, $list);
|
||||
|
||||
if(G5_USE_CACHE) {
|
||||
|
||||
$caches = array(
|
||||
'list' => $list,
|
||||
'bo_subject' => sql_escape_string($bo_subject),
|
||||
);
|
||||
$cache_content = "<?php if (!defined('_GNUBOARD_')) exit; ?>\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();
|
||||
|
||||
@@ -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'];
|
||||
|
||||
+54
-18
@@ -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);
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in new issue
Block a user