영카트 5.4 버전 내용 적용
This commit is contained in:
187
lib/Cache/FileCache.class.php
Normal file
187
lib/Cache/FileCache.class.php
Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
?>
|
||||
92
lib/Cache/obj.class.php
Normal file
92
lib/Cache/obj.class.php
Normal file
@ -0,0 +1,92 @@
|
||||
<?php
|
||||
if (!defined('_GNUBOARD_')) exit;
|
||||
|
||||
Class G5_object_cache {
|
||||
public $writes = array();
|
||||
public $contents = array();
|
||||
public $etcs = array();
|
||||
|
||||
function get($type, $key, $group ='default') {
|
||||
|
||||
switch ($type) {
|
||||
case 'bbs':
|
||||
$datas = $this->writes;
|
||||
break;
|
||||
case 'content' :
|
||||
$datas = $this->contents;
|
||||
break;
|
||||
default :
|
||||
$datas = $this->etcs;
|
||||
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;
|
||||
default :
|
||||
$datas = $this->etcs;
|
||||
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;
|
||||
default :
|
||||
$datas = $this->etcs[$group][$key] = $data;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function delete($key, $group='default') {
|
||||
switch ($type) {
|
||||
case 'bbs':
|
||||
$datas = $this->writes;
|
||||
break;
|
||||
case 'content':
|
||||
$datas = $this->contents;
|
||||
break;
|
||||
default :
|
||||
$datas = $this->etcs;
|
||||
break;
|
||||
}
|
||||
|
||||
if ( ! $this->exists('bbs', $key, $group) )
|
||||
return false;
|
||||
|
||||
unset( $datas[$group][$key] );
|
||||
return true;
|
||||
}
|
||||
|
||||
} //end Class
|
||||
|
||||
?>
|
||||
327
lib/Hook/hook.class.php
Normal file
327
lib/Hook/hook.class.php
Normal file
@ -0,0 +1,327 @@
|
||||
<?php
|
||||
if (!defined('_GNUBOARD_')) exit;
|
||||
|
||||
/**
|
||||
* Library for handling hooks.
|
||||
*
|
||||
* @author Josantonius <hello@josantonius.com>
|
||||
* @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();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
161
lib/Hook/hook.extends.class.php
Normal file
161
lib/Hook/hook.extends.class.php
Normal file
@ -0,0 +1,161 @@
|
||||
<?php
|
||||
if (!defined('_GNUBOARD_')) exit;
|
||||
|
||||
Class GML_Hook extends Hook {
|
||||
|
||||
protected $filters = array('count' => 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
|
||||
|
||||
?>
|
||||
167
lib/URI/uri.class.php
Normal file
167
lib/URI/uri.class.php
Normal file
@ -0,0 +1,167 @@
|
||||
<?php
|
||||
if (!defined('_GNUBOARD_')) exit;
|
||||
|
||||
class G5_URI {
|
||||
public $basename;
|
||||
public $parts;
|
||||
public $slashes;
|
||||
|
||||
public static function getInstance()
|
||||
{ //싱글톤
|
||||
static $instance = null;
|
||||
if (null === $instance) {
|
||||
$instance = new self();
|
||||
}
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
public function parseURL() {
|
||||
/* grab URL query string and script name */
|
||||
$uri = $_SERVER['REQUEST_URI'];
|
||||
$script = $_SERVER['SCRIPT_NAME'];
|
||||
/* get extension */
|
||||
$ext = end( explode(".",$script) );
|
||||
|
||||
/* if extension is found in URL, eliminate it */
|
||||
if(strstr($uri,".")) {
|
||||
$arr_uri = explode('.', $uri);
|
||||
/* get last part */
|
||||
$last = end($arr_uri);
|
||||
|
||||
if($last == $ext){
|
||||
array_pop($arr_uri);
|
||||
$uri = implode('.', $arr_uri);
|
||||
}
|
||||
}
|
||||
|
||||
/* pick the name without extension */
|
||||
$basename = basename ($script, '.'.$ext);
|
||||
/* slicing query string */
|
||||
$temp = explode('/',$uri);
|
||||
$key = array_search($basename,$temp);
|
||||
$parts = array_slice ($temp, $key+1);
|
||||
$this->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($string_url) {
|
||||
/* convert normal URL query string to clean URL */
|
||||
$url=parse_url($string_url);
|
||||
$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($string_url, $add_qry='') {
|
||||
global $config, $g5;
|
||||
|
||||
$string_url = str_replace('&', '&', $string_url);
|
||||
$url=parse_url($string_url);
|
||||
$page_name = basename($url['path'],".php");
|
||||
|
||||
$array_page_names = run_replace('url_clean_page_names', array('board', 'write'));
|
||||
|
||||
if( strpos($string_url, G5_BBS_URL) === false || ! in_array($page_name, $array_page_names) ){ //게시판이 아니면 리턴
|
||||
return $string_url;
|
||||
}
|
||||
|
||||
$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)) $page_name .= "/".$v;
|
||||
|
||||
if( $page_name === 'write' ){
|
||||
$vars['action'] = 'write';
|
||||
$allow_param_keys = array('bo_table'=>'', 'action'=>'');
|
||||
} else {
|
||||
$allow_param_keys = array('bo_table'=>'', 'wr_id'=>'');
|
||||
}
|
||||
|
||||
$s = array();
|
||||
|
||||
foreach( $allow_param_keys as $key=>$v ){
|
||||
if( !isset($vars[$key]) || empty($vars[$key]) ) continue;
|
||||
$add = '';
|
||||
$s[$key] = $vars[$key];
|
||||
}
|
||||
|
||||
if( $config['cf_bbs_rewrite'] > 1 && $page_name === 'board' && (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']) ){
|
||||
|
||||
$array_file_paths = run_replace('url_clean_page_paths', array('/'.G5_BBS_DIR.'/board.php', '/'.G5_BBS_DIR.'/write.php'));
|
||||
|
||||
$str_path = isset($url['path']) ? $url['path'] : '';
|
||||
$http = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']=='on') ? 'https://' : 'http://';
|
||||
$host = $http.$url['host'].str_replace($array_file_paths, '', $str_path);
|
||||
}
|
||||
|
||||
$add_param = '';
|
||||
|
||||
if( $result = array_diff_key($vars, $allow_param_keys ) ){
|
||||
$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;
|
||||
}
|
||||
}
|
||||
?>
|
||||
95
lib/cache.lib.php
Normal file
95
lib/cache.lib.php
Normal file
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
if (!defined('_GNUBOARD_')) exit;
|
||||
|
||||
include_once(dirname(__FILE__) .'/Cache/obj.class.php');
|
||||
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();
|
||||
|
||||
foreach( $board_tables as $board_table ){
|
||||
delete_cache_latest($board_table);
|
||||
}
|
||||
|
||||
run_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;
|
||||
}
|
||||
?>
|
||||
@ -1,6 +1,8 @@
|
||||
<?php
|
||||
if (!defined('_GNUBOARD_')) exit;
|
||||
|
||||
include_once(dirname(__FILE__) .'/pbkdf2.compat.php');
|
||||
|
||||
/*************************************************************************
|
||||
**
|
||||
** 일반 함수 모음
|
||||
@ -19,7 +21,8 @@ function get_microtime()
|
||||
function get_paging($write_pages, $cur_page, $total_page, $url, $add="")
|
||||
{
|
||||
//$url = preg_replace('#&page=[0-9]*(&page=)$#', '$1', $url);
|
||||
$url = preg_replace('#&page=[0-9]*#', '', $url) . '&page=';
|
||||
$url = preg_replace('#(&)?page=[0-9]*#', '', $url);
|
||||
$url .= substr($url, -1) === '?' ? 'page=' : '&page=';
|
||||
|
||||
$str = '';
|
||||
if ($cur_page > 1) {
|
||||
@ -152,6 +155,8 @@ function alert($msg='', $url='', $error=true, $post=false)
|
||||
{
|
||||
global $g5, $config, $member;
|
||||
global $is_admin;
|
||||
|
||||
run_event('alert', $msg, $url, $error, $post);
|
||||
|
||||
$msg = $msg ? strip_tags($msg, '<br>') : '올바른 방법으로 이용해 주십시오.';
|
||||
|
||||
@ -169,6 +174,8 @@ function alert_close($msg, $error=true)
|
||||
{
|
||||
global $g5;
|
||||
|
||||
run_event('alert_close', $msg, $error);
|
||||
|
||||
$msg = strip_tags($msg, '<br>');
|
||||
|
||||
$header = '';
|
||||
@ -245,7 +252,7 @@ function url_auto_link($str)
|
||||
$str = preg_replace("/\t_gt_\t/", ">", $str);
|
||||
*/
|
||||
|
||||
return $str;
|
||||
return run_replace('url_auto_link', $str);
|
||||
}
|
||||
|
||||
|
||||
@ -304,6 +311,9 @@ function get_file($bo_table, $wr_id)
|
||||
$file[$no]['image_width'] = $row['bf_width'] ? $row['bf_width'] : 640;
|
||||
$file[$no]['image_height'] = $row['bf_height'] ? $row['bf_height'] : 480;
|
||||
$file[$no]['image_type'] = $row['bf_type'];
|
||||
$file[$no]['bf_fileurl'] = $row['bf_fileurl'];
|
||||
$file[$no]['bf_thumburl'] = $row['bf_thumburl'];
|
||||
$file[$no]['bf_storage'] = $row['bf_storage'];
|
||||
$file['count']++;
|
||||
}
|
||||
|
||||
@ -336,11 +346,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);
|
||||
@ -353,6 +365,10 @@ function get_list($write_row, $board, $skin_url, $subject_len=40)
|
||||
else
|
||||
$list['subject'] = conv_subject($list['wr_subject'], $board['bo_subject_len'], '…');
|
||||
|
||||
if( ! (isset($list['wr_seo_title']) && $list['wr_seo_title']) && $list['wr_id'] ){
|
||||
seo_title_update(get_write_table_name($board['bo_table']), $list['wr_id'], 'bbs');
|
||||
}
|
||||
|
||||
// 목록에서 내용 미리보기 사용한 게시판만 내용을 변환함 (속도 향상) : kkal3(커피)님께서 알려주셨습니다.
|
||||
if ($board['bo_use_list_content'])
|
||||
{
|
||||
@ -406,9 +422,9 @@ function get_list($write_row, $board, $skin_url, $subject_len=40)
|
||||
$list['icon_link'] = '<i class="fa fa-link" aria-hidden="true"></i> ';
|
||||
|
||||
// 분류명 링크
|
||||
$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'] = '';
|
||||
@ -683,13 +699,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 || $is_cache == false ){
|
||||
$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)
|
||||
@ -703,22 +730,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] = run_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] = run_replace('get_member', sql_fetch($sql), $mb_id, $fields, $is_cache);
|
||||
|
||||
return $cache[$mb_id][$key];
|
||||
}
|
||||
|
||||
|
||||
@ -797,12 +849,19 @@ function is_admin($mb_id)
|
||||
{
|
||||
global $config, $group, $board;
|
||||
|
||||
if (!$mb_id) return;
|
||||
if (!$mb_id) return '';
|
||||
|
||||
if ($config['cf_admin'] == $mb_id) return 'super';
|
||||
if (isset($group['gr_admin']) && ($group['gr_admin'] == $mb_id)) return 'group';
|
||||
if (isset($board['bo_admin']) && ($board['bo_admin'] == $mb_id)) return 'board';
|
||||
return '';
|
||||
$is_authority = '';
|
||||
|
||||
if ($config['cf_admin'] == $mb_id){
|
||||
$is_authority = 'super';
|
||||
} else if (isset($group['gr_admin']) && ($group['gr_admin'] == $mb_id)){
|
||||
$is_authority = 'group';
|
||||
} else if (isset($board['bo_admin']) && ($board['bo_admin'] == $mb_id)){
|
||||
$is_authority = 'board';
|
||||
}
|
||||
|
||||
return run_replace('is_admin', $is_authority, $mb_id);
|
||||
}
|
||||
|
||||
|
||||
@ -1216,8 +1275,7 @@ function get_sideview($mb_id, $name='', $email='', $homepage='')
|
||||
global $g5;
|
||||
global $bo_table, $sca, $is_admin, $member;
|
||||
|
||||
$email_enc = new str_encrypt();
|
||||
$email = $email_enc->encrypt($email);
|
||||
$email = get_string_encrypt($email);
|
||||
$homepage = set_http(clean_xss_tags($homepage));
|
||||
|
||||
$name = get_text($name, 0, true);
|
||||
@ -1225,18 +1283,20 @@ function get_sideview($mb_id, $name='', $email='', $homepage='')
|
||||
$homepage = get_text($homepage);
|
||||
|
||||
$tmp_name = "";
|
||||
$en_mb_id = $mb_id;
|
||||
|
||||
if ($mb_id) {
|
||||
//$tmp_name = "<a href=\"".G5_BBS_URL."/profile.php?mb_id=".$mb_id."\" class=\"sv_member\" title=\"$name 자기소개\" rel="nofollow" target=\"_blank\" onclick=\"return false;\">$name</a>";
|
||||
$tmp_name = '<a href="'.G5_BBS_URL.'/profile.php?mb_id='.$mb_id.'" class="sv_member" title="'.$name.' 자기소개" target="_blank" rel="nofollow" onclick="return false;">';
|
||||
|
||||
if ($config['cf_use_member_icon']) {
|
||||
$mb_dir = substr($mb_id,0,2);
|
||||
$icon_file = G5_DATA_PATH.'/member/'.$mb_dir.'/'.$mb_id.'.gif';
|
||||
$icon_file = G5_DATA_PATH.'/member/'.$mb_dir.'/'.get_mb_icon_name($mb_id).'.gif';
|
||||
|
||||
if (file_exists($icon_file)) {
|
||||
$width = $config['cf_member_icon_width'];
|
||||
$height = $config['cf_member_icon_height'];
|
||||
$icon_file_url = G5_DATA_URL.'/member/'.$mb_dir.'/'.$mb_id.'.gif';
|
||||
$icon_file_url = G5_DATA_URL.'/member/'.$mb_dir.'/'.get_mb_icon_name($mb_id).'.gif';
|
||||
$tmp_name .= '<span class="profile_img"><img src="'.$icon_file_url.'" width="'.$width.'" height="'.$height.'" alt=""></span>';
|
||||
|
||||
if ($config['cf_use_member_icon'] == 2) // 회원아이콘+이름
|
||||
@ -1260,7 +1320,7 @@ function get_sideview($mb_id, $name='', $email='', $homepage='')
|
||||
if(!$bo_table)
|
||||
return $name;
|
||||
|
||||
$tmp_name = '<a href="'.G5_BBS_URL.'/board.php?bo_table='.$bo_table.'&sca='.$sca.'&sfl=wr_name,1&stx='.$name.'" title="'.$name.' 이름으로 검색" class="sv_guest" rel="nofollow" onclick="return false;">'.$name.'</a>';
|
||||
$tmp_name = '<a href="'.get_pretty_url($bo_table, '', 'sca='.$sca.'&sfl=wr_name,1&stx='.$name).'" title="'.$name.' 이름으로 검색" class="sv_guest" rel="nofollow" onclick="return false;">'.$name.'</a>';
|
||||
$title_mb_id = '[비회원]';
|
||||
}
|
||||
|
||||
@ -1277,10 +1337,11 @@ function get_sideview($mb_id, $name='', $email='', $homepage='')
|
||||
if($mb_id)
|
||||
$str2 .= "<a href=\"".G5_BBS_URL."/profile.php?mb_id=".$mb_id."\" onclick=\"win_profile(this.href); return false;\">자기소개</a>\n";
|
||||
if($bo_table) {
|
||||
if($mb_id)
|
||||
$str2 .= "<a href=\"".G5_BBS_URL."/board.php?bo_table=".$bo_table."&sca=".$sca."&sfl=mb_id,1&stx=".$mb_id."\">아이디로 검색</a>\n";
|
||||
else
|
||||
$str2 .= "<a href=\"".G5_BBS_URL."/board.php?bo_table=".$bo_table."&sca=".$sca."&sfl=wr_name,1&stx=".$name."\">이름으로 검색</a>\n";
|
||||
if($mb_id) {
|
||||
$str2 .= "<a href=\"".get_pretty_url($bo_table, '', "sca=".$sca."&sfl=mb_id,1&stx=".$en_mb_id)."\">아이디로 검색</a>\n";
|
||||
} else {
|
||||
$str2 .= "<a href=\"".get_pretty_url($bo_table, '', "sca=".$sca."&sfl=wr_name,1&stx=".$name)."\">이름으로 검색</a>\n";
|
||||
}
|
||||
}
|
||||
if($mb_id)
|
||||
$str2 .= "<a href=\"".G5_BBS_URL."/new.php?mb_id=".$mb_id."\" class=\"link_new_page\" onclick=\"check_goto_new(this.href, event);\">전체게시물</a>\n";
|
||||
@ -1480,12 +1541,21 @@ function sql_set_charset($charset, $link=null)
|
||||
mysql_query(" set names {$charset} ", $link);
|
||||
}
|
||||
|
||||
function sql_data_seek($result, $offset=0)
|
||||
{
|
||||
if ( ! $result ) return;
|
||||
|
||||
if(function_exists('mysqli_set_charset') && G5_MYSQLI_USE)
|
||||
mysqli_data_seek($result, $offset);
|
||||
else
|
||||
mysql_data_seek($result, $offset);
|
||||
}
|
||||
|
||||
// mysqli_query 와 mysqli_error 를 한꺼번에 처리
|
||||
// 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'];
|
||||
@ -1498,6 +1568,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("<p>$sql<p>" . mysqli_errno($link) . " : " . mysqli_error($link) . "<p>error file : {$_SERVER['SCRIPT_NAME']}");
|
||||
@ -1512,6 +1586,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;
|
||||
}
|
||||
|
||||
@ -1997,6 +2080,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 );
|
||||
|
||||
@ -2008,8 +2101,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;
|
||||
}
|
||||
|
||||
|
||||
@ -2168,11 +2262,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.'-');
|
||||
}
|
||||
|
||||
// 게시판 첨부파일 썸네일 삭제
|
||||
@ -2456,6 +2546,8 @@ class html_process {
|
||||
}
|
||||
|
||||
array_multisort($order, SORT_ASC, $index, SORT_ASC, $links);
|
||||
|
||||
$links = run_replace('html_process_css_files', $links);
|
||||
|
||||
foreach($links as $link) {
|
||||
if(!trim($link[1]))
|
||||
@ -2482,6 +2574,8 @@ class html_process {
|
||||
}
|
||||
|
||||
array_multisort($order, SORT_ASC, $index, SORT_ASC, $scripts);
|
||||
|
||||
$scripts = run_replace('html_process_script_files', $scripts);
|
||||
|
||||
foreach($scripts as $js) {
|
||||
if(!trim($js[1]))
|
||||
@ -2510,6 +2604,17 @@ class html_process {
|
||||
if($javascript)
|
||||
$nl = "\n";
|
||||
$buffer = preg_replace('#(</head>[^<]*<body[^>]*>)#', "$javascript{$nl}$1", $buffer);
|
||||
|
||||
$meta_tag = run_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;
|
||||
}
|
||||
@ -2681,10 +2786,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 = run_replace('get_qa_config', sql_fetch($sql));
|
||||
|
||||
return $cache;
|
||||
}
|
||||
|
||||
// get_sock 함수 대체
|
||||
@ -3069,11 +3180,43 @@ function get_encrypt_string($str)
|
||||
// 비밀번호 비교
|
||||
function check_password($pass, $hash)
|
||||
{
|
||||
if(defined('G5_STRING_ENCRYPT_FUNCTION') && G5_STRING_ENCRYPT_FUNCTION === 'create_hash') {
|
||||
return validate_password($pass, $hash);
|
||||
}
|
||||
|
||||
$password = get_encrypt_string($pass);
|
||||
|
||||
return ($password === $hash);
|
||||
}
|
||||
|
||||
// 로그인 패스워드 체크
|
||||
function login_password_check($mb, $pass, $hash)
|
||||
{
|
||||
global $g5;
|
||||
|
||||
$mb_id = isset($mb['mb_id']) ? $mb['mb_id'] : '';
|
||||
|
||||
if(!$mb_id)
|
||||
return false;
|
||||
|
||||
if(G5_STRING_ENCRYPT_FUNCTION === 'create_hash' && (strlen($hash) === G5_MYSQL_PASSWORD_LENGTH || strlen($hash) === 16)) {
|
||||
if( sql_password($pass) === $hash ){
|
||||
|
||||
if( ! isset($mb['mb_password2']) ){
|
||||
$sql = "ALTER TABLE `{$g5['member_table']}` ADD `mb_password2` varchar(255) NOT NULL default '' AFTER `mb_password`";
|
||||
sql_query($sql);
|
||||
}
|
||||
|
||||
$new_password = create_hash($pass);
|
||||
$sql = " update {$g5['member_table']} set mb_password = '$new_password', mb_password2 = '$hash' where mb_id = '$mb_id' ";
|
||||
sql_query($sql);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return check_password($pass, $hash);
|
||||
}
|
||||
|
||||
// 동일한 host url 인지
|
||||
function check_url_host($url, $msg='', $return_url=G5_URL, $is_redirect=false)
|
||||
{
|
||||
@ -3222,22 +3365,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);
|
||||
|
||||
@ -3246,16 +3386,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)
|
||||
{
|
||||
@ -3400,7 +3549,7 @@ function get_member_profile_img($mb_id='', $width='', $height='', $alt='profile_
|
||||
if( isset($member_cache[$mb_id]) ){
|
||||
$src = $member_cache[$mb_id];
|
||||
} else {
|
||||
$member_img = G5_DATA_PATH.'/member_image/'.substr($mb_id,0,2).'/'.$mb_id.'.gif';
|
||||
$member_img = G5_DATA_PATH.'/member_image/'.substr($mb_id,0,2).'/'.get_mb_icon_name($mb_id).'.gif';
|
||||
if (is_file($member_img)) {
|
||||
$member_cache[$mb_id] = $src = str_replace(G5_DATA_PATH, G5_DATA_URL, $member_img);
|
||||
}
|
||||
|
||||
478
lib/get_data.lib.php
Normal file
478
lib/get_data.lib.php
Normal file
@ -0,0 +1,478 @@
|
||||
<?php
|
||||
if (!defined('_GNUBOARD_')) exit;
|
||||
|
||||
function get_config($is_cache=false){
|
||||
global $g5;
|
||||
|
||||
static $cache = array();
|
||||
|
||||
$cache = run_replace('get_config_cache', $cache, $is_cache);
|
||||
|
||||
if( $is_cache && !empty($cache) ){
|
||||
return $cache;
|
||||
}
|
||||
|
||||
$sql = " select * from {$g5['config_table']} ";
|
||||
$cache = run_replace('get_config', sql_fetch($sql));
|
||||
|
||||
return $cache;
|
||||
}
|
||||
|
||||
function get_content_db($co_id, $is_cache=false){
|
||||
global $g5, $g5_object;
|
||||
|
||||
static $cache = array();
|
||||
|
||||
$type = 'content';
|
||||
|
||||
$co_id = preg_replace('/[^a-z0-9_]/i', '', $co_id);
|
||||
$co = $g5_object->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();
|
||||
|
||||
$boards = run_replace('get_board_names_cache', $boards);
|
||||
|
||||
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 = run_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] = run_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_menu_db($use_mobile=0, $is_cache=false){
|
||||
global $g5;
|
||||
|
||||
static $cache = array();
|
||||
|
||||
$cache = run_replace('get_menu_db_cache', $cache, $use_mobile, $is_cache);
|
||||
|
||||
$key = md5($use_mobile);
|
||||
|
||||
if( $is_cache && isset($cache[$key]) ){
|
||||
return $cache[$key];
|
||||
}
|
||||
|
||||
$where = $use_mobile ? "me_mobile_use = '1'" : "me_use = '1'";
|
||||
|
||||
if( !($cache[$key] = run_replace('get_menu_db', array(), $use_mobile)) ){
|
||||
$sql = " select *
|
||||
from {$g5['menu_table']}
|
||||
where $where
|
||||
and length(me_code) = '2'
|
||||
order by me_order, me_id ";
|
||||
$result = sql_query($sql, false);
|
||||
|
||||
for ($i=0; $row=sql_fetch_array($result); $i++) {
|
||||
|
||||
$row['ori_me_link'] = $row['me_link'];
|
||||
$row['me_link'] = short_url_clean($row['me_link']);
|
||||
$cache[$key][$i] = $row;
|
||||
|
||||
$sql2 = " select *
|
||||
from {$g5['menu_table']}
|
||||
where $where
|
||||
and length(me_code) = '4'
|
||||
and substring(me_code, 1, 2) = '{$row['me_code']}'
|
||||
order by me_order, me_id ";
|
||||
$result2 = sql_query($sql2);
|
||||
for ($k=0; $row2=sql_fetch_array($result2); $k++) {
|
||||
$row2['ori_me_link'] = $row2['me_link'];
|
||||
$row2['me_link'] = short_url_clean($row2['me_link']);
|
||||
$cache[$key][$i]['sub'][$k] = $row2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 run_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_class_encrypt(){
|
||||
static $cache;
|
||||
|
||||
if( $cache && is_object($obj) ){
|
||||
return $cache;
|
||||
}
|
||||
|
||||
$cache = run_replace('get_class_encrypt', new str_encrypt());
|
||||
|
||||
return $cache;
|
||||
}
|
||||
|
||||
function get_string_encrypt($str){
|
||||
|
||||
$new = get_class_encrypt();
|
||||
|
||||
$encrypt_str = $new->encrypt($str);
|
||||
|
||||
return $encrypt_str;
|
||||
}
|
||||
|
||||
function get_string_decrypt($str){
|
||||
|
||||
$new = get_class_encrypt();
|
||||
|
||||
$decrypt_str = $new->decrypt($str);
|
||||
|
||||
return $decrypt_str;
|
||||
}
|
||||
|
||||
function get_permission_debug_show(){
|
||||
global $member;
|
||||
|
||||
$bool = false;
|
||||
if ( defined('G5_DEBUG') && G5_DEBUG ){
|
||||
$bool = true;
|
||||
}
|
||||
|
||||
return run_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_mb_icon_name($mb_id){
|
||||
|
||||
if( $icon_name = run_replace('get_mb_icon_name', '', $mb_id) ){
|
||||
return $icon_name;
|
||||
}
|
||||
|
||||
return $mb_id;
|
||||
}
|
||||
|
||||
// 생성되면 안되는 게시판명
|
||||
function get_bo_table_banned_word(){
|
||||
|
||||
$folders = array();
|
||||
|
||||
foreach(glob(G5_PATH.'/*', GLOB_ONLYDIR) as $dir) {
|
||||
$folders[] = basename($dir);
|
||||
}
|
||||
|
||||
return run_replace('get_bo_table_banned_word', $folders);
|
||||
}
|
||||
|
||||
function get_board_sort_fields($board=array(), $make_key_return=''){
|
||||
$bo_sort_fields = run_replace('get_board_sort_fields', array(
|
||||
array('wr_num, wr_reply', '기본'),
|
||||
array('wr_datetime asc', '날짜 이전것 부터'),
|
||||
array('wr_datetime desc', '날짜 최근것 부터'),
|
||||
array('wr_hit asc, wr_num, wr_reply', '조회수 낮은것 부터'),
|
||||
array('wr_hit desc, wr_num, wr_reply', '조회수 높은것 부터'),
|
||||
array('wr_last asc', '최근글 이전것 부터'),
|
||||
array('wr_last desc', '최근글 최근것 부터'),
|
||||
array('wr_comment asc, wr_num, wr_reply', '댓글수 낮은것 부터'),
|
||||
array('wr_comment desc, wr_num, wr_reply', '댓글수 높은것 부터'),
|
||||
array('wr_good asc, wr_num, wr_reply', '추천수 낮은것 부터'),
|
||||
array('wr_good desc, wr_num, wr_reply', '추천수 높은것 부터'),
|
||||
array('wr_nogood asc, wr_num, wr_reply', '비추천수 낮은것 부터'),
|
||||
array('wr_nogood desc, wr_num, wr_reply', '비추천수 높은것 부터'),
|
||||
array('wr_subject asc, wr_num, wr_reply', '제목 오름차순'),
|
||||
array('wr_subject desc, wr_num, wr_reply', '제목 내림차순'),
|
||||
array('wr_name asc, wr_num, wr_reply', '글쓴이 오름차순'),
|
||||
array('wr_name desc, wr_num, wr_reply', '글쓴이 내림차순'),
|
||||
array('ca_name asc, wr_num, wr_reply', '분류명 오름차순'),
|
||||
array('ca_name desc, wr_num, wr_reply', '분류명 내림차순'),
|
||||
), $board, $make_key_return);
|
||||
|
||||
if( $make_key_return ){
|
||||
|
||||
$returns = array();
|
||||
foreach( $bo_sort_fields as $v ){
|
||||
$key = preg_replace("/[\<\>\'\"\\\'\\\"\%\=\(\)\/\^\*\s]/", "", $v[0]);
|
||||
$returns[$key] = $v[0];
|
||||
}
|
||||
|
||||
return $returns;
|
||||
}
|
||||
return $bo_sort_fields;
|
||||
}
|
||||
|
||||
function get_board_sfl_select_options($sfl){
|
||||
|
||||
global $is_admin;
|
||||
|
||||
$str = '';
|
||||
$str .= '<option value="wr_subject" '.get_selected($sfl, 'wr_subject', true).'>제목</option>';
|
||||
$str .= '<option value="wr_content" '.get_selected($sfl, 'wr_content').'>내용</option>';
|
||||
$str .= '<option value="wr_subject||wr_content" '.get_selected($sfl, 'wr_subject||wr_content').'>제목+내용</option>';
|
||||
if ( $is_admin ){
|
||||
$str .= '<option value="mb_id,1" '.get_selected($sfl, 'mb_id,1').'>회원아이디</option>';
|
||||
$str .= '<option value="mb_id,0" '.get_selected($sfl, 'mb_id,0').'>회원아이디(코)</option>';
|
||||
}
|
||||
$str .= '<option value="wr_name,1" '.get_selected($sfl, 'wr_name,1').'>글쓴이</option>';
|
||||
$str .= '<option value="wr_name,0" '.get_selected($sfl, 'wr_name,0').'>글쓴이(코)</option>';
|
||||
|
||||
return run_replace('get_board_sfl_select_options', $str, $sfl);
|
||||
}
|
||||
|
||||
// 읽지 않은 메모 갯수 반환
|
||||
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'];
|
||||
}
|
||||
?>
|
||||
134
lib/hook.lib.php
Normal file
134
lib/hook.lib.php
Normal file
@ -0,0 +1,134 @@
|
||||
<?php
|
||||
if (!defined('_GNUBOARD_')) exit;
|
||||
|
||||
define('G5_HOOK_DEFAULT_PRIORITY', 8);
|
||||
|
||||
if (!function_exists('get_called_class')) {
|
||||
function get_called_class() {
|
||||
$bt = debug_backtrace();
|
||||
$lines = file($bt[1]['file']);
|
||||
preg_match(
|
||||
'/([a-zA-Z0-9\_]+)::'.$bt[1]['function'].'/',
|
||||
$lines[$bt[1]['line']-1],
|
||||
$matches
|
||||
);
|
||||
return $matches[1];
|
||||
}
|
||||
}
|
||||
|
||||
include_once(dirname(__FILE__) .'/Hook/hook.class.php');
|
||||
include_once(dirname(__FILE__) .'/Hook/hook.extends.class.php');
|
||||
|
||||
function get_hook_class(){
|
||||
|
||||
if( class_exists('GML_Hook') ){
|
||||
return GML_Hook::getInstance();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function add_event($tag, $func, $priority=G5_HOOK_DEFAULT_PRIORITY, $args=0){
|
||||
|
||||
if( $hook = get_hook_class() ){
|
||||
$hook->addAction($tag, $func, $priority, $args);
|
||||
}
|
||||
}
|
||||
|
||||
function run_event($tag, $arg = ''){
|
||||
|
||||
if( $hook = get_hook_class() ){
|
||||
|
||||
$args = array();
|
||||
|
||||
if (
|
||||
is_array($arg)
|
||||
&&
|
||||
isset($arg[0])
|
||||
&&
|
||||
is_object($arg[0])
|
||||
&&
|
||||
1 == count($arg)
|
||||
) {
|
||||
$args[] =& $arg[0];
|
||||
} else {
|
||||
$args[] = $arg;
|
||||
}
|
||||
|
||||
$numArgs = func_num_args();
|
||||
|
||||
for ($a = 2; $a < $numArgs; $a++) {
|
||||
$args[] = func_get_arg($a);
|
||||
}
|
||||
|
||||
$hook->doAction($tag, $args, false);
|
||||
}
|
||||
}
|
||||
|
||||
function add_replace($tag, $func, $priority=G5_HOOK_DEFAULT_PRIORITY, $args=0){
|
||||
|
||||
if( $hook = get_hook_class() ){
|
||||
return $hook->addFilter($tag, $func, $priority, $args);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function run_replace($tag, $arg = ''){
|
||||
|
||||
if( $hook = get_hook_class() ){
|
||||
|
||||
$args = array();
|
||||
|
||||
if (
|
||||
is_array($arg)
|
||||
&&
|
||||
isset($arg[0])
|
||||
&&
|
||||
is_object($arg[0])
|
||||
&&
|
||||
1 == count($arg)
|
||||
) {
|
||||
$args[] =& $arg[0];
|
||||
} else {
|
||||
$args[] = $arg;
|
||||
}
|
||||
|
||||
$numArgs = func_num_args();
|
||||
|
||||
for ($a = 2; $a < $numArgs; $a++) {
|
||||
$args[] = func_get_arg($a);
|
||||
}
|
||||
|
||||
return $hook->apply_filters($tag, $args, false);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function delete_event($tag, $func, $priority=G5_HOOK_DEFAULT_PRIORITY){
|
||||
|
||||
if( $hook = get_hook_class() ){
|
||||
return $hook->remove_action($tag, $func, $priority);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function delete_replace($tag, $func, $priority=G5_HOOK_DEFAULT_PRIORITY){
|
||||
|
||||
if( $hook = get_hook_class() ){
|
||||
return $hook->remove_filter($tag, $func, $priority);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function get_hook_datas($type='', $is_callback=''){
|
||||
if( $hook = get_hook_class() ){
|
||||
return $hook->get_properties($type, $is_callback);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
?>
|
||||
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
if (!defined('_GNUBOARD_')) exit;
|
||||
@include_once(G5_LIB_PATH.'/thumbnail.lib.php');
|
||||
|
||||
// 최신글 추출
|
||||
// $cache_time 캐시 갱신시간
|
||||
@ -30,46 +31,26 @@ 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']);
|
||||
|
||||
$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 && is_string($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();
|
||||
|
||||
@ -34,7 +34,7 @@ class naverpay_register
|
||||
$diff_cost = 0;
|
||||
|
||||
foreach($keys as $it_id) {
|
||||
$it = sql_fetch(" select * from {$g5['g5_shop_item_table']} where it_id = '$it_id' ");
|
||||
$it = get_shop_item($it_id, true);
|
||||
if(!$it['it_id'])
|
||||
continue;
|
||||
|
||||
@ -192,8 +192,7 @@ function get_naverpay_item_image_url($it_id)
|
||||
{
|
||||
global $g5;
|
||||
|
||||
$sql = " select it_id, it_img1, it_img2, it_img3, it_img4, it_img5, it_img6, it_img7, it_img8, it_img9, it_img10 from {$g5['g5_shop_item_table']} where it_id = '$it_id' ";
|
||||
$row = sql_fetch($sql);
|
||||
$row = get_shop_item($it_id, true);
|
||||
|
||||
if(!$row['it_id'])
|
||||
return '';
|
||||
@ -233,8 +232,7 @@ function get_naverpay_item_stock($it_id)
|
||||
{
|
||||
global $g5;
|
||||
|
||||
$sql = " select it_id, it_stock_qty, it_use, it_soldout from {$g5['g5_shop_item_table']} where it_id = '$it_id' ";
|
||||
$it = sql_fetch($sql);
|
||||
$it = get_shop_item($it_id, true);
|
||||
if(!$it['it_id'] || !$it['it_use'] || $it['it_soldout'])
|
||||
return 0;
|
||||
|
||||
|
||||
@ -5,6 +5,8 @@ if (!defined('_GNUBOARD_')) exit;
|
||||
function outlogin($skin_dir='basic')
|
||||
{
|
||||
global $config, $member, $g5, $urlencode, $is_admin, $is_member;
|
||||
|
||||
$is_auth = false;
|
||||
|
||||
if (array_key_exists('mb_nick', $member)) {
|
||||
$nick = get_text(cut_str($member['mb_nick'], $config['cf_cut_name']));
|
||||
@ -36,11 +38,13 @@ function outlogin($skin_dir='basic')
|
||||
|
||||
// 읽지 않은 쪽지가 있다면
|
||||
if ($is_member) {
|
||||
$sql = " select count(*) as cnt from {$g5['memo_table']} where me_recv_mb_id = '{$member['mb_id']}' and me_read_datetime = '0000-00-00 00:00:00' ";
|
||||
$row = sql_fetch($sql);
|
||||
$memo_not_read = $row['cnt'];
|
||||
|
||||
$is_auth = false;
|
||||
if( isset($member['mb_memo_cnt']) ){
|
||||
$memo_not_read = $member['mb_memo_cnt'];
|
||||
} else {
|
||||
$memo_not_read = get_memo_not_read($member['mb_id']);
|
||||
}
|
||||
|
||||
$mb_scrap_cnt = isset($member['mb_scrap_cnt']) ? (int) $member['mb_scrap_cnt'] : '';
|
||||
$sql = " select count(*) as cnt from {$g5['auth_table']} where mb_id = '{$member['mb_id']}' ";
|
||||
$row = sql_fetch($sql);
|
||||
if ($row['cnt'])
|
||||
@ -49,7 +53,7 @@ function outlogin($skin_dir='basic')
|
||||
|
||||
$outlogin_url = login_url($urlencode);
|
||||
$outlogin_action_url = G5_HTTPS_BBS_URL.'/login_check.php';
|
||||
|
||||
|
||||
ob_start();
|
||||
if ($is_member)
|
||||
include_once ($outlogin_skin_path.'/outlogin.skin.2.php');
|
||||
@ -58,6 +62,6 @@ function outlogin($skin_dir='basic')
|
||||
$content = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
return $content;
|
||||
return run_replace('outlogin_content', $content, $is_auth, $outlogin_url, $outlogin_action_url);
|
||||
}
|
||||
?>
|
||||
221
lib/pbkdf2.compat.php
Normal file
221
lib/pbkdf2.compat.php
Normal file
@ -0,0 +1,221 @@
|
||||
<?php
|
||||
if (!defined('_GNUBOARD_')) exit;
|
||||
|
||||
/*
|
||||
* Password Hashing with PBKDF2 (http://crackstation.net/hashing-security.htm).
|
||||
* Copyright (c) 2013, Taylor Hornby
|
||||
* All rights reserved.
|
||||
*
|
||||
* Modified to Work with Older Versions of PHP
|
||||
* Copyright (c) 2014, Kijin Sung
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
// These constants may be changed without breaking existing hashes.
|
||||
|
||||
define('PBKDF2_COMPAT_HASH_ALGORITHM', 'SHA256');
|
||||
define('PBKDF2_COMPAT_ITERATIONS', 12000);
|
||||
define('PBKDF2_COMPAT_SALT_BYTES', 24);
|
||||
define('PBKDF2_COMPAT_HASH_BYTES', 24);
|
||||
|
||||
// Calculates a hash from the given password.
|
||||
|
||||
function create_hash($password, $force_compat = false)
|
||||
{
|
||||
// Generate the salt.
|
||||
|
||||
if (function_exists('mcrypt_create_iv')) {
|
||||
$salt = base64_encode(mcrypt_create_iv(PBKDF2_COMPAT_SALT_BYTES, MCRYPT_DEV_URANDOM));
|
||||
} elseif (@file_exists('/dev/urandom') && $fp = @fopen('/dev/urandom', 'r')) {
|
||||
$salt = base64_encode(fread($fp, PBKDF2_COMPAT_SALT_BYTES));
|
||||
} else {
|
||||
$salt = '';
|
||||
for ($i = 0; $i < PBKDF2_COMPAT_SALT_BYTES; $i += 2) {
|
||||
$salt .= pack('S', mt_rand(0, 65535));
|
||||
}
|
||||
$salt = base64_encode(substr($salt, 0, PBKDF2_COMPAT_SALT_BYTES));
|
||||
}
|
||||
|
||||
// Determine the best supported algorithm and iteration count.
|
||||
|
||||
$algo = strtolower(PBKDF2_COMPAT_HASH_ALGORITHM);
|
||||
$iterations = PBKDF2_COMPAT_ITERATIONS;
|
||||
if ($force_compat || !function_exists('hash_algos') || !in_array($algo, hash_algos())) {
|
||||
$algo = false; // This flag will be detected by pbkdf2_default()
|
||||
$iterations = round($iterations / 5); // PHP 4 is very slow. Don't cause too much server load.
|
||||
}
|
||||
|
||||
// Return format: algorithm:iterations:salt:hash
|
||||
|
||||
$pbkdf2 = pbkdf2_default($algo, $password, $salt, $iterations, PBKDF2_COMPAT_HASH_BYTES);
|
||||
$prefix = $algo ? $algo : 'sha1';
|
||||
return $prefix . ':' . $iterations . ':' . $salt . ':' . base64_encode($pbkdf2);
|
||||
}
|
||||
|
||||
// Checks whether a password matches a previously calculated hash
|
||||
|
||||
function validate_password($password, $hash)
|
||||
{
|
||||
// Split the hash into 4 parts.
|
||||
|
||||
$params = explode(':', $hash);
|
||||
if (count($params) < 4) return false;
|
||||
|
||||
// Recalculate the hash and compare it with the original.
|
||||
|
||||
$pbkdf2 = base64_decode($params[3]);
|
||||
$pbkdf2_check = pbkdf2_default($params[0], $password, $params[2], (int)$params[1], strlen($pbkdf2));
|
||||
return slow_equals($pbkdf2, $pbkdf2_check);
|
||||
}
|
||||
|
||||
// Checks whether a hash needs upgrading.
|
||||
|
||||
function needs_upgrade($hash)
|
||||
{
|
||||
// Get the current algorithm and iteration count.
|
||||
|
||||
$params = explode(':', $hash);
|
||||
if (count($params) < 4) return true;
|
||||
$algo = $params[0];
|
||||
$iterations = (int)$params[1];
|
||||
|
||||
// Compare the current hash with the best supported options.
|
||||
|
||||
if (!function_exists('hash_algos') || !in_array($algo, hash_algos())) {
|
||||
return false;
|
||||
} elseif ($algo === strtolower(PBKDF2_COMPAT_HASH_ALGORITHM) && $iterations >= PBKDF2_COMPAT_ITERATIONS) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Compares two strings $a and $b in length-constant time.
|
||||
|
||||
function slow_equals($a, $b)
|
||||
{
|
||||
$diff = strlen($a) ^ strlen($b);
|
||||
for($i = 0; $i < strlen($a) && $i < strlen($b); $i++) {
|
||||
$diff |= ord($a[$i]) ^ ord($b[$i]);
|
||||
}
|
||||
return $diff === 0;
|
||||
}
|
||||
|
||||
// PBKDF2 key derivation function as defined by RSA's PKCS #5: https://www.ietf.org/rfc/rfc2898.txt
|
||||
// Test vectors can be found here: https://www.ietf.org/rfc/rfc6070.txt
|
||||
// This implementation of PBKDF2 was originally created by https://defuse.ca
|
||||
// With improvements by http://www.variations-of-shadow.com
|
||||
|
||||
function pbkdf2_default($algo, $password, $salt, $count, $key_length)
|
||||
{
|
||||
// Sanity check.
|
||||
|
||||
if ($count <= 0 || $key_length <= 0) {
|
||||
trigger_error('PBKDF2 ERROR: Invalid parameters.', E_USER_ERROR);
|
||||
}
|
||||
|
||||
// Check if we should use the fallback function.
|
||||
|
||||
if (!$algo) return pbkdf2_fallback($password, $salt, $count, $key_length);
|
||||
|
||||
// Check if the selected algorithm is available.
|
||||
|
||||
$algo = strtolower($algo);
|
||||
if (!function_exists('hash_algos') || !in_array($algo, hash_algos())) {
|
||||
if ($algo === 'sha1') {
|
||||
return pbkdf2_fallback($password, $salt, $count, $key_length);
|
||||
} else {
|
||||
trigger_error('PBKDF2 ERROR: Hash algorithm not supported.', E_USER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
// Use built-in function if available.
|
||||
|
||||
if (function_exists('hash_pbkdf2')) {
|
||||
return hash_pbkdf2($algo, $password, $salt, $count, $key_length, true);
|
||||
}
|
||||
|
||||
// Count the blocks.
|
||||
|
||||
$hash_length = strlen(hash($algo, '', true));
|
||||
$block_count = ceil($key_length / $hash_length);
|
||||
|
||||
// Hash it!
|
||||
|
||||
$output = '';
|
||||
for ($i = 1; $i <= $block_count; $i++) {
|
||||
$last = $salt . pack('N', $i); // $i encoded as 4 bytes, big endian.
|
||||
$last = $xorsum = hash_hmac($algo, $last, $password, true); // first iteration.
|
||||
for ($j = 1; $j < $count; $j++) { // The other $count - 1 iterations.
|
||||
$xorsum ^= ($last = hash_hmac($algo, $last, $password, true));
|
||||
}
|
||||
$output .= $xorsum;
|
||||
}
|
||||
|
||||
// Truncate and return.
|
||||
|
||||
return substr($output, 0, $key_length);
|
||||
}
|
||||
|
||||
// Fallback function using sha1() and a pure-PHP implementation of HMAC.
|
||||
// The result is identical to the default function when used with SHA-1.
|
||||
// But it is approximately 1.6x slower than the hash_hmac() function of PHP 5.1.2+,
|
||||
// And approximately 2.3x slower than the hash_pbkdf2() function of PHP 5.5+.
|
||||
|
||||
function pbkdf2_fallback($password, $salt, $count, $key_length)
|
||||
{
|
||||
// Count the blocks.
|
||||
|
||||
$hash_length = 20;
|
||||
$block_count = ceil($key_length / $hash_length);
|
||||
|
||||
// Prepare the HMAC key and padding.
|
||||
|
||||
if (strlen($password) > 64) {
|
||||
$password = str_pad(sha1($password, true), 64, chr(0));
|
||||
} else {
|
||||
$password = str_pad($password, 64, chr(0));
|
||||
}
|
||||
|
||||
$opad = str_repeat(chr(0x5C), 64) ^ $password;
|
||||
$ipad = str_repeat(chr(0x36), 64) ^ $password;
|
||||
|
||||
// Hash it!
|
||||
|
||||
$output = '';
|
||||
for ($i = 1; $i <= $block_count; $i++) {
|
||||
$last = $salt . pack('N', $i);
|
||||
$xorsum = $last = pack('H*', sha1($opad . pack('H*', sha1($ipad . $last))));
|
||||
for ($j = 1; $j < $count; $j++) {
|
||||
$last = pack('H*', sha1($opad . pack('H*', sha1($ipad . $last))));
|
||||
$xorsum ^= $last;
|
||||
}
|
||||
$output .= $xorsum;
|
||||
}
|
||||
|
||||
// Truncate and return.
|
||||
|
||||
return substr($output, 0, $key_length);
|
||||
}
|
||||
258
lib/shop.data.lib.php
Normal file
258
lib/shop.data.lib.php
Normal file
@ -0,0 +1,258 @@
|
||||
<?php
|
||||
if (!defined('_GNUBOARD_')) exit;
|
||||
|
||||
function get_shop_item($it_id, $is_cache=false, $add_query=''){
|
||||
|
||||
global $g5, $g5_object;
|
||||
|
||||
$add_query_key = $add_query ? 'shop_'.md5($add_query) : '';
|
||||
|
||||
$item = $is_cache ? $g5_object->get('shop', $it_id, $add_query_key) : null;
|
||||
|
||||
if( !$item ){
|
||||
$sql = " select * from {$g5['g5_shop_item_table']} where it_id = '{$it_id}' $add_query ";
|
||||
$item = sql_fetch($sql);
|
||||
|
||||
$g5_object->set('shop', $it_id, $item, $add_query_key);
|
||||
}
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
function get_shop_item_with_category($it_id, $seo_title='', $add_query=''){
|
||||
|
||||
global $g5, $default;
|
||||
|
||||
if( $seo_title ){
|
||||
$sql = " select a.*, b.ca_name, b.ca_use from {$g5['g5_shop_item_table']} a, {$g5['g5_shop_category_table']} b where a.it_seo_title = '".sql_real_escape_string(generate_seo_title($seo_title))."' and a.ca_id = b.ca_id $add_query";
|
||||
} else {
|
||||
$sql = " select a.*, b.ca_name, b.ca_use from {$g5['g5_shop_item_table']} a, {$g5['g5_shop_category_table']} b where a.it_id = '$it_id' and a.ca_id = b.ca_id $add_query";
|
||||
}
|
||||
|
||||
return sql_fetch($sql);
|
||||
}
|
||||
|
||||
function get_shop_navigation_data($is_cache, $ca_id, $ca_id2='', $ca_id3=''){
|
||||
|
||||
$all_categories = get_shop_category_array($is_cache);
|
||||
|
||||
$datas = array();
|
||||
|
||||
if( strlen($ca_id) >= 2 && $all_categories ){
|
||||
foreach((array) $all_categories as $category1 ){
|
||||
$datas[0][] = $category1['text'];
|
||||
}
|
||||
}
|
||||
|
||||
$select_ca_id = $ca_id2 ? $ca_id2 : $ca_id;
|
||||
$item_categories2 = $select_ca_id ? get_shop_category_by($is_cache, 'ca_id', $select_ca_id) : array();
|
||||
|
||||
if( strlen($select_ca_id) >= 4 && $item_categories2 ){
|
||||
foreach((array) $item_categories2 as $key=>$category2 ){
|
||||
if( $key === 'text' ) continue;
|
||||
|
||||
$datas[1][] = $category2['text'];
|
||||
}
|
||||
}
|
||||
|
||||
$select_ca_id = $ca_id3 ? $ca_id3 : $ca_id;
|
||||
$item_categories3 = $select_ca_id ? get_shop_category_by($is_cache, 'ca_id', $select_ca_id) : array();
|
||||
|
||||
if( strlen($select_ca_id) >= 6 && $item_categories3 && isset($item_categories3[substr($select_ca_id,0,4)]) ){
|
||||
$sub_categories = $item_categories3[substr($select_ca_id,0,4)];
|
||||
|
||||
foreach((array) $sub_categories as $key=>$category3 ){
|
||||
if( $key === 'text' ) continue;
|
||||
|
||||
$datas[2][] = $category3['text'];
|
||||
}
|
||||
}
|
||||
|
||||
return $datas;
|
||||
}
|
||||
|
||||
function get_shop_category_by($is_cache, $case, $value){
|
||||
|
||||
if( $case === 'ca_id' ){
|
||||
$categories = get_shop_category_array($is_cache);
|
||||
|
||||
$key = substr(preg_replace('/[^0-9a-z]/i', '', $value), 0, 2);
|
||||
|
||||
if( isset($categories[$key]) ){
|
||||
return $categories[$key];
|
||||
}
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
function get_shop_category_array($is_cache=false){
|
||||
|
||||
static $categories = array();
|
||||
|
||||
$categories = run_replace('get_shop_category_array', $categories, $is_cache);
|
||||
|
||||
if( $is_cache && !empty($categories) ){
|
||||
return $categories;
|
||||
}
|
||||
|
||||
$result = sql_query(get_shop_category_sql('', 2));
|
||||
|
||||
for($i=0; $row=sql_fetch_array($result); $i++) {
|
||||
|
||||
$row['url'] = shop_category_url($row['ca_id']);
|
||||
$categories[$row['ca_id']]['text'] = $row;
|
||||
|
||||
if( $row['ca_id'] ){
|
||||
$result2 = sql_query(get_shop_category_sql($row['ca_id'], 4));
|
||||
|
||||
for($j=0; $row2=sql_fetch_array($result2); $j++) {
|
||||
|
||||
$row2['url'] = shop_category_url($row2['ca_id']);
|
||||
$categories[$row['ca_id']][$row2['ca_id']]['text'] = $row2;
|
||||
|
||||
if( $row2['ca_id'] ){
|
||||
$result3 = sql_query(get_shop_category_sql($row2['ca_id'], 6));
|
||||
for($k=0; $row3=sql_fetch_array($result3); $k++) {
|
||||
|
||||
$row3['url'] = shop_category_url($row3['ca_id']);
|
||||
$categories[$row['ca_id']][$row2['ca_id']][$row3['ca_id']]['text'] = $row3;
|
||||
}
|
||||
} //end if
|
||||
} //end for
|
||||
} //end if
|
||||
} //end for
|
||||
|
||||
return $categories;
|
||||
}
|
||||
|
||||
function get_shop_category_sql($ca_id, $len){
|
||||
global $g5;
|
||||
|
||||
$sql = " select * from {$g5['g5_shop_category_table']}
|
||||
where ca_use = '1' ";
|
||||
if($ca_id)
|
||||
$sql .= " and ca_id like '$ca_id%' ";
|
||||
$sql .= " and length(ca_id) = '$len' order by ca_order, ca_id ";
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
function get_shop_member_coupon_count($mb_id='', $is_cache=false){
|
||||
global $g5, $member;
|
||||
|
||||
static $cache = array();
|
||||
|
||||
$key = md5($mb_id);
|
||||
|
||||
if( $is_cache && isset($cache[$key]) ){
|
||||
return $cache[$key];
|
||||
}
|
||||
|
||||
if( !$mb_id ){
|
||||
$mb_id = $member['mb_id'];
|
||||
}
|
||||
|
||||
// 쿠폰
|
||||
$cp_count = 0;
|
||||
$sql = " select cp_id
|
||||
from {$g5['g5_shop_coupon_table']}
|
||||
where mb_id IN ( '{$mb_id}', '전체회원' )
|
||||
and cp_start <= '".G5_TIME_YMD."'
|
||||
and cp_end >= '".G5_TIME_YMD."' ";
|
||||
$res = sql_query($sql);
|
||||
|
||||
for($k=0; $cp=sql_fetch_array($res); $k++) {
|
||||
if(!is_used_coupon($mb_id, $cp['cp_id']))
|
||||
$cp_count++;
|
||||
}
|
||||
|
||||
$cache[$key] = $cp_count;
|
||||
|
||||
return $cp_count;
|
||||
}
|
||||
|
||||
// 상품리스트에서 옵션항목
|
||||
function get_shop_item_options($it_id, $subject, $no)
|
||||
{
|
||||
global $g5;
|
||||
|
||||
if(!$it_id || !$subject)
|
||||
return '';
|
||||
|
||||
$sql = " select * from {$g5['g5_shop_item_option_table']} where io_type = '0' and it_id = '$it_id' and io_use = '1' order by io_no asc ";
|
||||
$result = sql_query($sql);
|
||||
if(!sql_num_rows($result))
|
||||
return '';
|
||||
|
||||
$str = '';
|
||||
$subj = explode(',', $subject);
|
||||
$subj_count = count($subj);
|
||||
|
||||
if($subj_count > 1) {
|
||||
$options = array();
|
||||
|
||||
// 옵션항목 배열에 저장
|
||||
for($i=0; $row=sql_fetch_array($result); $i++) {
|
||||
$opt_id = explode(chr(30), $row['io_id']);
|
||||
|
||||
for($k=0; $k<$subj_count; $k++) {
|
||||
if(!is_array($options[$k]))
|
||||
$options[$k] = array();
|
||||
|
||||
if($opt_id[$k] && !in_array($opt_id[$k], $options[$k]))
|
||||
$options[$k][] = $opt_id[$k];
|
||||
}
|
||||
}
|
||||
|
||||
// 옵션선택목록 만들기
|
||||
for($i=0; $i<$subj_count; $i++) {
|
||||
$opt = $options[$i];
|
||||
$opt_count = count($opt);
|
||||
$disabled = '';
|
||||
if($opt_count) {
|
||||
$seq = $no.'_'.($i + 1);
|
||||
if($i > 0)
|
||||
$disabled = ' disabled="disabled"';
|
||||
|
||||
$str .= '<label for="it_option_'.$seq.'" class="sound_only">'.$subj[$i].'</label>'.PHP_EOL;
|
||||
|
||||
$select = '<select id="it_option_'.$seq.'" class="it_option"'.$disabled.'>'.PHP_EOL;
|
||||
$select .= '<option value="">'.$subj[$i].'</option>'.PHP_EOL;
|
||||
for($k=0; $k<$opt_count; $k++) {
|
||||
$opt_val = $opt[$k];
|
||||
if(strlen($opt_val)) {
|
||||
$select .= '<option value="'.$opt_val.'">'.$opt_val.'</option>'.PHP_EOL;
|
||||
}
|
||||
}
|
||||
$select .= '</select>'.PHP_EOL;
|
||||
|
||||
$str .= $select.PHP_EOL;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$str .= '<label for="it_option_1">'.$subj[0].'</label>'.PHP_EOL;
|
||||
|
||||
$select = '<select id="it_option_1" class="it_option">'.PHP_EOL;
|
||||
$select .= '<option value="">선택</option>'.PHP_EOL;
|
||||
for($i=0; $row=sql_fetch_array($result); $i++) {
|
||||
if($row['io_price'] >= 0)
|
||||
$price = ' + '.number_format($row['io_price']).'원';
|
||||
else
|
||||
$price = ' '.number_format($row['io_price']).'원';
|
||||
|
||||
if(!$row['io_stock_qty'])
|
||||
$soldout = ' [품절]';
|
||||
else
|
||||
$soldout = '';
|
||||
|
||||
$select .= '<option value="'.$row['io_id'].','.$row['io_price'].','.$row['io_stock_qty'].'">'.$row['io_id'].$price.$soldout.'</option>'.PHP_EOL;
|
||||
}
|
||||
$select .= '</select>'.PHP_EOL;
|
||||
|
||||
$str .= $select.PHP_EOL;
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
?>
|
||||
240
lib/shop.lib.php
240
lib/shop.lib.php
@ -83,6 +83,7 @@ class item_list
|
||||
protected $view_it_cust_price = false; // 소비자가
|
||||
protected $view_it_icon = false; // 아이콘
|
||||
protected $view_sns = false; // SNS
|
||||
protected $view_star = false; // 별점
|
||||
|
||||
// 몇번째 class 호출인지를 저장합니다.
|
||||
protected $count = 0;
|
||||
@ -99,7 +100,6 @@ class item_list
|
||||
// 외부에서 쿼리문을 넘겨줄 경우에 담아두는 변수
|
||||
protected $query = "";
|
||||
|
||||
|
||||
// $type : 상품유형 (기본으로 1~5까지 사용)
|
||||
// $list_skin : 상품리스트를 노출할 스킨을 설정합니다. 스킨위치는 skin/shop/쇼핑몰설정스킨/type??.skin.php
|
||||
// $list_mod : 1줄에 몇개의 상품을 노출할지를 설정합니다.
|
||||
@ -254,6 +254,8 @@ class item_list
|
||||
function run() {
|
||||
|
||||
global $g5, $config, $member, $default;
|
||||
|
||||
$list = array();
|
||||
|
||||
if ($this->query) {
|
||||
|
||||
@ -309,7 +311,21 @@ class item_list
|
||||
$row2 = sql_fetch($sql2);
|
||||
$this->total_count = $row2['cnt'];
|
||||
}
|
||||
}
|
||||
|
||||
if( isset($result) && $result ){
|
||||
while ($row=sql_fetch_array($result)) {
|
||||
|
||||
if( isset($row['it_seo_title']) && ! $row['it_seo_title'] ){
|
||||
shop_seo_title_update($row['it_id']);
|
||||
}
|
||||
|
||||
$list[] = $row;
|
||||
}
|
||||
|
||||
if(function_exists('sql_data_seek')){
|
||||
sql_data_seek($result, 0);
|
||||
}
|
||||
}
|
||||
|
||||
$file = $this->list_skin;
|
||||
@ -329,7 +345,6 @@ class item_list
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 장바구니 건수 검사
|
||||
function get_cart_count($cart_id)
|
||||
{
|
||||
@ -389,12 +404,13 @@ function get_it_image($it_id, $width, $height=0, $anchor=false, $img_id='', $img
|
||||
if(!$it_id || !$width)
|
||||
return '';
|
||||
|
||||
$sql = " select it_id, it_img1, it_img2, it_img3, it_img4, it_img5, it_img6, it_img7, it_img8, it_img9, it_img10 from {$g5['g5_shop_item_table']} where it_id = '$it_id' ";
|
||||
$row = sql_fetch($sql);
|
||||
$row = get_shop_item($it_id, true);
|
||||
|
||||
if(!$row['it_id'])
|
||||
return '';
|
||||
|
||||
$filename = $thumb = $img = '';
|
||||
|
||||
for($i=1;$i<=10; $i++) {
|
||||
$file = G5_DATA_PATH.'/item/'.$row['it_img'.$i];
|
||||
if(is_file($file) && $row['it_img'.$i]) {
|
||||
@ -435,17 +451,20 @@ function get_it_image($it_id, $width, $height=0, $anchor=false, $img_id='', $img
|
||||
$img .= '>';
|
||||
|
||||
if($anchor)
|
||||
$img = '<a href="'.G5_SHOP_URL.'/item.php?it_id='.$it_id.'">'.$img.'</a>';
|
||||
$img = $img = '<a href="'.shop_item_url($it_id).'">'.$img.'</a>';
|
||||
|
||||
return $img;
|
||||
return run_replace('get_it_image_tag', $img, $thumb, $it_id, $width, $height, $anchor, $img_id, $img_alt, $is_crop);
|
||||
}
|
||||
|
||||
|
||||
// 상품이미지 썸네일 생성
|
||||
function get_it_thumbnail($img, $width, $height=0, $id='', $is_crop=false)
|
||||
{
|
||||
$str = '';
|
||||
|
||||
if ( $replace_tag = run_replace('get_it_thumbnail_tag', $str, $img, $width, $height, $id, $is_crop) ){
|
||||
return $replace_tag;
|
||||
}
|
||||
|
||||
$file = G5_DATA_PATH.'/item/'.$img;
|
||||
if(is_file($file))
|
||||
$size = @getimagesize($file);
|
||||
@ -481,10 +500,7 @@ function get_it_imageurl($it_id)
|
||||
{
|
||||
global $g5;
|
||||
|
||||
$sql = " select it_img1, it_img2, it_img3, it_img4, it_img5, it_img6, it_img7, it_img8, it_img9, it_img10
|
||||
from {$g5['g5_shop_item_table']}
|
||||
where it_id = '$it_id' ";
|
||||
$row = sql_fetch($sql);
|
||||
$row = get_shop_item($it_id, true);
|
||||
$filepath = '';
|
||||
|
||||
for($i=1; $i<=10; $i++) {
|
||||
@ -921,7 +937,6 @@ function title_sort($col, $type=0)
|
||||
return "{$_SERVER['SCRIPT_NAME']}?$q1&$q2&page=$page";
|
||||
}
|
||||
|
||||
|
||||
// 세션값을 체크하여 이쪽에서 온것이 아니면 메인으로
|
||||
function session_check()
|
||||
{
|
||||
@ -931,9 +946,8 @@ function session_check()
|
||||
gotourl(G5_SHOP_URL);
|
||||
}
|
||||
|
||||
|
||||
// 상품 선택옵션
|
||||
function get_item_options($it_id, $subject, $is_div='')
|
||||
function get_item_options($it_id, $subject, $is_div='', $is_first_option_title='')
|
||||
{
|
||||
global $g5;
|
||||
|
||||
@ -977,14 +991,17 @@ function get_item_options($it_id, $subject, $is_div='')
|
||||
|
||||
if($is_div === 'div') {
|
||||
$str .= '<div class="get_item_options">'.PHP_EOL;
|
||||
$str .= '<label for="it_option_'.$seq.'">'.$subj[$i].'</label>'.PHP_EOL;
|
||||
$str .= '<label for="it_option_'.$seq.'" class="label-title">'.$subj[$i].'</label>'.PHP_EOL;
|
||||
} else {
|
||||
$str .= '<tr>'.PHP_EOL;
|
||||
$str .= '<th><label for="it_option_'.$seq.'">'.$subj[$i].'</label></th>'.PHP_EOL;
|
||||
$str .= '<th><label for="it_option_'.$seq.'" class="label-title">'.$subj[$i].'</label></th>'.PHP_EOL;
|
||||
}
|
||||
|
||||
$select = '<select id="it_option_'.$seq.'" class="it_option"'.$disabled.'>'.PHP_EOL;
|
||||
$select .= '<option value="">선택</option>'.PHP_EOL;
|
||||
|
||||
$first_option_title = $is_first_option_title ? $subj[$i] : '선택';
|
||||
|
||||
$select .= '<option value="">'.$first_option_title.'</option>'.PHP_EOL;
|
||||
for($k=0; $k<$opt_count; $k++) {
|
||||
$opt_val = $opt[$k];
|
||||
if(strlen($opt_val)) {
|
||||
@ -1041,9 +1058,8 @@ function get_item_options($it_id, $subject, $is_div='')
|
||||
return $str;
|
||||
}
|
||||
|
||||
|
||||
// 상품 추가옵션
|
||||
function get_item_supply($it_id, $subject, $is_div='')
|
||||
function get_item_supply($it_id, $subject, $is_div='', $is_first_option_title='')
|
||||
{
|
||||
global $g5;
|
||||
|
||||
@ -1092,14 +1108,16 @@ function get_item_supply($it_id, $subject, $is_div='')
|
||||
$seq = $i + 1;
|
||||
if($is_div === 'div') {
|
||||
$str .= '<div class="get_item_supply">'.PHP_EOL;
|
||||
$str .= '<label for="it_supply_'.$seq.'">'.$subj[$i].'</label>'.PHP_EOL;
|
||||
$str .= '<label for="it_supply_'.$seq.'" class="label-title">'.$subj[$i].'</label>'.PHP_EOL;
|
||||
} else {
|
||||
$str .= '<tr>'.PHP_EOL;
|
||||
$str .= '<th><label for="it_supply_'.$seq.'">'.$subj[$i].'</label></th>'.PHP_EOL;
|
||||
}
|
||||
|
||||
$first_option_title = $is_first_option_title ? $subj[$i] : '선택';
|
||||
|
||||
$select = '<select id="it_supply_'.$seq.'" class="it_supply">'.PHP_EOL;
|
||||
$select .= '<option value="">선택</option>'.PHP_EOL;
|
||||
$select .= '<option value="">'.$first_option_title.'</option>'.PHP_EOL;
|
||||
for($k=0; $k<$opt_count; $k++) {
|
||||
$opt_val = $opt[$k];
|
||||
if($opt_val) {
|
||||
@ -1121,7 +1139,6 @@ function get_item_supply($it_id, $subject, $is_div='')
|
||||
return $str;
|
||||
}
|
||||
|
||||
|
||||
function print_item_options($it_id, $cart_id)
|
||||
{
|
||||
global $g5;
|
||||
@ -1430,7 +1447,7 @@ function relation_item($it_id, $width, $height, $rows=3)
|
||||
|
||||
$img = get_it_image($row['it_id'], $width, $height);
|
||||
|
||||
$str .= '<li class="sct_rel_li"><a href="'.G5_SHOP_URL.'/item.php?it_id='.$row['it_id'].'" class="sct_rel_a">'.$img.'</a></li>';
|
||||
$str .= '<li class="sct_rel_li"><a href="'.get_pretty_url('shop', $row['it_id']).'" class="sct_rel_a">'.$img.'</a></li>';
|
||||
}
|
||||
|
||||
if($i > 0)
|
||||
@ -1457,7 +1474,7 @@ function item_icon($it)
|
||||
$icon .= '<span class="shop_icon shop_icon_3">최신</span>';
|
||||
|
||||
if ($it['it_type4'])
|
||||
$icon .= '<span class="shop_icon shop_icon_4">BEST</span>';
|
||||
$icon .= '<span class="shop_icon shop_icon_4">인기</span>';
|
||||
|
||||
if ($it['it_type5'])
|
||||
$icon .= '<span class="shop_icon shop_icon_5">할인</span>';
|
||||
@ -1477,10 +1494,6 @@ function item_icon($it)
|
||||
if($row['cnt'])
|
||||
$icon .= '<span class="shop_icon shop_icon_coupon">쿠폰</span>';
|
||||
|
||||
// 품절
|
||||
if (is_soldout($it['it_id']))
|
||||
$icon .= '<br><span class="shop_icon_soldout">Sold Out</span>';
|
||||
|
||||
$icon .= '</span>';
|
||||
|
||||
return $icon;
|
||||
@ -1911,13 +1924,21 @@ function is_used_coupon($mb_id, $cp_id)
|
||||
}
|
||||
|
||||
// 품절상품인지 체크
|
||||
function is_soldout($it_id)
|
||||
function is_soldout($it_id, $is_cache=false)
|
||||
{
|
||||
global $g5;
|
||||
|
||||
static $cache = array();
|
||||
|
||||
$it_id = preg_replace('/[^a-z0-9_]/i', '', $it_id);
|
||||
$key = md5($it_id);
|
||||
|
||||
if( $is_cache && isset($cache[$key]) ){
|
||||
return $cache[$key];
|
||||
}
|
||||
|
||||
// 상품정보
|
||||
$sql = " select it_soldout, it_stock_qty from {$g5['g5_shop_item_table']} where it_id = '$it_id' ";
|
||||
$it = sql_fetch($sql);
|
||||
$it = get_shop_item($it_id, $is_cache);
|
||||
|
||||
if($it['it_soldout'] || $it['it_stock_qty'] <= 0)
|
||||
return true;
|
||||
@ -1955,6 +1976,8 @@ function is_soldout($it_id)
|
||||
if($stock_qty <= 0)
|
||||
$soldout = true;
|
||||
}
|
||||
|
||||
$cache[$key] = $soldout;
|
||||
|
||||
return $soldout;
|
||||
}
|
||||
@ -1994,8 +2017,7 @@ function shop_member_cert_check($id, $type)
|
||||
switch($type)
|
||||
{
|
||||
case 'item':
|
||||
$sql = " select ca_id, ca_id2, ca_id3 from {$g5['g5_shop_item_table']} where it_id = '$id' ";
|
||||
$it = sql_fetch($sql);
|
||||
$it = get_shop_item($id, true);
|
||||
|
||||
$seq = '';
|
||||
for($i=0; $i<3; $i++) {
|
||||
@ -2131,7 +2153,7 @@ function get_view_today_items($is_cache=false)
|
||||
$tv_it_idx = $tv_idx - ($i - 1);
|
||||
$tv_it_id = get_session("ss_tv[$tv_it_idx]");
|
||||
|
||||
$rowx = sql_fetch(" select * from {$g5['g5_shop_item_table']} where it_id = '$tv_it_id' ");
|
||||
$rowx = get_shop_item($tv_it_id, true);
|
||||
if(!$rowx['it_id'])
|
||||
continue;
|
||||
|
||||
@ -2205,6 +2227,7 @@ function get_wishlist_datas($mb_id, $is_cache=false)
|
||||
return $cache[$mb_id];
|
||||
}
|
||||
|
||||
$cache[$mb_id] = array();
|
||||
$sql = " select a.it_id, b.it_name from {$g5['g5_shop_wish_table']} a, {$g5['g5_shop_item_table']} b ";
|
||||
$sql .= " where a.mb_id = '".$mb_id."' and a.it_id = b.it_id order by a.wi_id desc ";
|
||||
$result = sql_query($sql);
|
||||
@ -2342,48 +2365,60 @@ function get_delivery_company($company)
|
||||
}
|
||||
|
||||
// 사용후기 썸네일 생성
|
||||
function get_itemuse_thumb($contents, $thumb_width, $thumb_height, $is_create=false, $is_crop=true, $crop_mode='center', $is_sharpen=true, $um_value='80/0.5/3'){
|
||||
|
||||
global $config;
|
||||
|
||||
$img = $filename = $alt = "";
|
||||
|
||||
$matches = get_editor_image($contents, false);
|
||||
|
||||
for($i=0; $i<count($matches[1]); $i++)
|
||||
{
|
||||
// 이미지 path 구함
|
||||
$p = parse_url($matches[1][$i]);
|
||||
if(strpos($p['path'], '/'.G5_DATA_DIR.'/') != 0)
|
||||
$data_path = preg_replace('/^\/.*\/'.G5_DATA_DIR.'/', '/'.G5_DATA_DIR, $p['path']);
|
||||
else
|
||||
$data_path = $p['path'];
|
||||
|
||||
$srcfile = G5_PATH.$data_path;
|
||||
|
||||
if(preg_match("/\.({$config['cf_image_extension']})$/i", $srcfile) && is_file($srcfile)) {
|
||||
$size = @getimagesize($srcfile);
|
||||
if(empty($size))
|
||||
continue;
|
||||
|
||||
$filename = basename($srcfile);
|
||||
$filepath = dirname($srcfile);
|
||||
|
||||
preg_match("/alt=[\"\']?([^\"\']*)[\"\']?/", $matches[0][$i], $malt);
|
||||
$alt = get_text($malt[1]);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if($filename) {
|
||||
$thumb = thumbnail($filename, $filepath, $filepath, $thumb_width, $thumb_height, $is_create, $is_crop, $crop_mode, $is_sharpen, $um_value);
|
||||
|
||||
if($thumb) {
|
||||
$src = G5_URL.str_replace($filename, $thumb, $data_path);
|
||||
$img = '<img src="'.$src.'" width="'.$thumb_width.'" height="'.$thumb_height.'" alt="'.$alt.'">';
|
||||
}
|
||||
}
|
||||
|
||||
return $img;
|
||||
}
|
||||
|
||||
// 사용후기에서 후기에 이미지가 있으면 썸네일을 리턴하며 후기에 이미지가 없으면 상품이미지를 리턴합니다.
|
||||
function get_itemuselist_thumbnail($it_id, $contents, $thumb_width, $thumb_height, $is_create=false, $is_crop=true, $crop_mode='center', $is_sharpen=true, $um_value='80/0.5/3')
|
||||
{
|
||||
global $g5, $config;
|
||||
$img = $filename = $alt = "";
|
||||
|
||||
if($contents) {
|
||||
$matches = get_editor_image($contents, false);
|
||||
|
||||
for($i=0; $i<count($matches[1]); $i++)
|
||||
{
|
||||
// 이미지 path 구함
|
||||
$p = parse_url($matches[1][$i]);
|
||||
if(strpos($p['path'], '/'.G5_DATA_DIR.'/') != 0)
|
||||
$data_path = preg_replace('/^\/.*\/'.G5_DATA_DIR.'/', '/'.G5_DATA_DIR, $p['path']);
|
||||
else
|
||||
$data_path = $p['path'];
|
||||
|
||||
$srcfile = G5_PATH.$data_path;
|
||||
|
||||
if(preg_match("/\.({$config['cf_image_extension']})$/i", $srcfile) && is_file($srcfile)) {
|
||||
$size = @getimagesize($srcfile);
|
||||
if(empty($size))
|
||||
continue;
|
||||
|
||||
$filename = basename($srcfile);
|
||||
$filepath = dirname($srcfile);
|
||||
|
||||
preg_match("/alt=[\"\']?([^\"\']*)[\"\']?/", $matches[0][$i], $malt);
|
||||
$alt = get_text($malt[1]);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if($filename) {
|
||||
$thumb = thumbnail($filename, $filepath, $filepath, $thumb_width, $thumb_height, $is_create, $is_crop, $crop_mode, $is_sharpen, $um_value);
|
||||
|
||||
if($thumb) {
|
||||
$src = G5_URL.str_replace($filename, $thumb, $data_path);
|
||||
$img = '<img src="'.$src.'" width="'.$thumb_width.'" height="'.$thumb_height.'" alt="'.$alt.'">';
|
||||
}
|
||||
}
|
||||
$img = get_itemuse_thumb($contents, $thumb_width, $thumb_height);
|
||||
}
|
||||
|
||||
if(!$img)
|
||||
@ -2458,7 +2493,6 @@ function cart_item_clean()
|
||||
sql_query($sql);
|
||||
}
|
||||
|
||||
|
||||
// 임시주문 데이터로 주문 필드 생성
|
||||
function make_order_field($data, $exclude)
|
||||
{
|
||||
@ -2480,6 +2514,47 @@ function make_order_field($data, $exclude)
|
||||
return $field;
|
||||
}
|
||||
|
||||
// 주문요청기록 로그를 남깁니다.
|
||||
function add_order_post_log($msg='', $code='error'){
|
||||
global $g5, $member;
|
||||
|
||||
if( empty($_POST) ) return;
|
||||
|
||||
$post_data = base64_encode(serialize($_POST));
|
||||
$od_id = get_session('ss_order_id');
|
||||
|
||||
if( $code === 'delete' ){
|
||||
sql_query(" delete from {$g5['g5_shop_post_log_table']} where (oid = '$od_id' and mb_id = '{$member['mb_id']}') OR ol_datetime < '".date('Y-m-d H:i:s', strtotime('-15 day', G5_SERVER_TIME))."' ", false);
|
||||
return;
|
||||
}
|
||||
|
||||
$sql = "insert into `{$g5['g5_shop_post_log_table']}`
|
||||
set oid = '$od_id',
|
||||
mb_id = '{$member['mb_id']}',
|
||||
post_data = '$post_data',
|
||||
ol_code = '$code',
|
||||
ol_msg = '$msg',
|
||||
ol_datetime = '".G5_TIME_YMDHIS."',
|
||||
ol_ip = '{$_SERVER['REMOTE_ADDR']}'";
|
||||
|
||||
if( $result = sql_query($sql, false) ){
|
||||
sql_query(" delete from {$g5['g5_shop_post_log_table']} where ol_datetime < '".date('Y-m-d H:i:s', strtotime('-15 day', G5_SERVER_TIME))."' ", false);
|
||||
} else {
|
||||
if(!sql_query(" DESC {$g5['g5_shop_post_log_table']} ", false)) {
|
||||
sql_query(" CREATE TABLE IF NOT EXISTS `{$g5['g5_shop_post_log_table']}` (
|
||||
`oid` bigint(20) unsigned NOT NULL,
|
||||
`mb_id` varchar(255) NOT NULL DEFAULT '',
|
||||
`post_data` text NOT NULL,
|
||||
`ol_code` varchar(255) NOT NULL DEFAULT '',
|
||||
`ol_msg` varchar(255) NOT NULL DEFAULT '',
|
||||
`ol_datetime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
||||
`ol_ip` varchar(25) NOT NULL DEFAULT '',
|
||||
PRIMARY KEY (`oid`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8; ", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//이니시스의 삼성페이 또는 L.pay 결제가 활성화 되어 있는지 체크합니다.
|
||||
function is_inicis_simple_pay(){
|
||||
global $default;
|
||||
@ -2513,6 +2588,29 @@ function is_inicis_order_pay($type){
|
||||
return false;
|
||||
}
|
||||
|
||||
function get_item_images_info($it, $size=array(), $image_width, $image_height){
|
||||
|
||||
if( !(is_array($it) && $it) ) return array();
|
||||
$images = array();
|
||||
|
||||
for($i=1; $i<=10; $i++) {
|
||||
if(!$it['it_img'.$i]) continue;
|
||||
$file = G5_DATA_PATH.'/item/'.$it['it_img'.$i];
|
||||
if( $is_exists = run_replace('is_exists_item_file', is_file($file), $it, $i) ){
|
||||
$thumb = get_it_thumbnail($it['it_img'.$i], $image_width, $image_height);
|
||||
$attr = (isset($size[0]) && isset($size[1]) && $size[0] && $size[1]) ? 'width="'.$size[0].'" height="'.$size[1].'" ' : '';
|
||||
$imageurl = G5_DATA_URL.'/item/'.$it['it_img'.$i];
|
||||
$infos = array(
|
||||
'thumb'=>$thumb,
|
||||
'imageurl'=>$imageurl,
|
||||
'imagehtml'=>'<img src="'.$imageurl.'" '.$attr.' alt="'.get_text($it['it_name']).'" id="largeimage_'.$i.'">',
|
||||
);
|
||||
$images[$i] = run_replace('get_image_by_item', $infos, $it, $i, $size);
|
||||
}
|
||||
}
|
||||
return $images;
|
||||
}
|
||||
|
||||
//결제방식 이름을 체크하여 치환 대상인 문자열은 따로 리턴합니다.
|
||||
function check_pay_name_replace($payname){
|
||||
|
||||
|
||||
222
lib/shop.uri.lib.php
Normal file
222
lib/shop.uri.lib.php
Normal file
@ -0,0 +1,222 @@
|
||||
<?php
|
||||
if (!defined('_GNUBOARD_')) exit;
|
||||
|
||||
function shop_type_url($type){
|
||||
global $config;
|
||||
|
||||
if( $config['cf_bbs_rewrite'] ){
|
||||
return get_pretty_url('shop', 'type-'.$type);
|
||||
}
|
||||
|
||||
return G5_SHOP_URL.'/listtype.php?type='.urlencode($type);
|
||||
}
|
||||
|
||||
function shop_item_url($it_id){
|
||||
global $config;
|
||||
|
||||
if( $config['cf_bbs_rewrite'] ){
|
||||
return get_pretty_url('shop', $it_id);
|
||||
}
|
||||
|
||||
return G5_SHOP_URL.'/item.php?it_id='.urlencode($it_id);
|
||||
}
|
||||
|
||||
function shop_category_url($ca_id){
|
||||
global $config;
|
||||
|
||||
if( $config['cf_bbs_rewrite'] ){
|
||||
return get_pretty_url('shop', 'list-'.$ca_id);
|
||||
}
|
||||
|
||||
return G5_SHOP_URL.'/list.php?ca_id='.urlencode($ca_id);
|
||||
}
|
||||
|
||||
function add_pretty_shop_url($url, $folder, $no='', $query_string='', $action=''){
|
||||
global $g5, $config;
|
||||
|
||||
if( $folder !== 'shop' ){
|
||||
return $url;
|
||||
}
|
||||
|
||||
$segments = array();
|
||||
$url = $add_query = '';
|
||||
|
||||
if( $config['cf_bbs_rewrite'] ){
|
||||
$segments[0] = G5_URL;
|
||||
$segments[1] = urlencode($folder);
|
||||
|
||||
if( $config['cf_bbs_rewrite'] > 1 && ! preg_match('/^(list|type)\-([^\/]+)/i', $no) ){
|
||||
$item = get_shop_item($no, true);
|
||||
$segments[2] = $item['it_seo_title'] ? urlencode($item['it_seo_title']).'/' : urlencode($no);
|
||||
} else {
|
||||
$segments[2] = urlencode($no);
|
||||
}
|
||||
|
||||
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 {
|
||||
|
||||
if( preg_match('/^list\-([^\/]+)/i', $no) ){
|
||||
$url = G5_SHOP_URL. '/list.php?ca_id='.urlencode($no);
|
||||
} else if( preg_match('/^type\-([^\/]+)/i', $no) ){
|
||||
$url = G5_SHOP_URL. '/listtype.php?type='.urlencode($no);
|
||||
} else {
|
||||
$url = G5_SHOP_URL. '/item.php?it_id='.urlencode($no);
|
||||
}
|
||||
|
||||
if($query_string) {
|
||||
$url .= ($no ? '?' : '&'). $query_string;
|
||||
}
|
||||
|
||||
$segments[0] = $url;
|
||||
}
|
||||
|
||||
return implode('/', $segments).$add_query;
|
||||
}
|
||||
|
||||
function shop_short_url_clean($string_url, $url, $page_name, $array_page_names){
|
||||
|
||||
global $config, $g5;
|
||||
|
||||
if( $config['cf_bbs_rewrite'] && stripos($string_url, G5_SHOP_URL) !== false && in_array($page_name, array('item', 'list', 'listtype')) ){
|
||||
|
||||
parse_str($url['query'], $vars);
|
||||
|
||||
$allow_param_keys = array('it_id'=>'', 'ca_id'=>'', 'type'=>'');
|
||||
|
||||
$s = array('shop_dir'=>G5_SHOP_DIR);
|
||||
|
||||
foreach( $allow_param_keys as $key=>$v ){
|
||||
if( !isset($vars[$key]) || empty($vars[$key]) ) continue;
|
||||
|
||||
$key_value = $vars[$key];
|
||||
|
||||
if( $key === 'ca_id' ){
|
||||
$key_value = 'list-'.$vars[$key];
|
||||
} else if ( $key === 'type' ){
|
||||
$key_value = 'type-'.$vars[$key];
|
||||
}
|
||||
|
||||
$s[$key] = $key_value;
|
||||
}
|
||||
|
||||
if( $config['cf_bbs_rewrite'] > 1 && $page_name === 'item' && (isset($s['it_id']) && $s['it_id']) ){
|
||||
$get_item = get_shop_item($s['it_id'], true);
|
||||
|
||||
if( $get_item['it_seo_title'] ){
|
||||
unset($s['it_id']);
|
||||
$s['it_seo_title'] = urlencode($get_item['it_seo_title']).'/';
|
||||
}
|
||||
}
|
||||
|
||||
$fragment = isset($url['fragment']) ? '#'.$url['fragment'] : '';
|
||||
|
||||
$host = G5_URL;
|
||||
|
||||
if( isset($url['host']) ){
|
||||
|
||||
$array_file_paths = run_replace('url_clean_page_paths', array('/'.G5_SHOP_DIR.'/item.php', '/'.G5_SHOP_DIR.'/list.php', '/'.G5_SHOP_DIR.'/listtype.php'));
|
||||
|
||||
$str_path = isset($url['path']) ? $url['path'] : '';
|
||||
$http = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']=='on') ? 'https://' : 'http://';
|
||||
$port = (isset($url['port']) && ($url['port']!==80 || $url['port']!==443)) ? ':'.$url['port'] : '';
|
||||
$host = $http.$url['host'].$port.str_replace($array_file_paths, '', $str_path);
|
||||
}
|
||||
|
||||
$add_param = '';
|
||||
|
||||
if( $result = array_diff_key($vars, $allow_param_keys ) ){
|
||||
$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;
|
||||
}
|
||||
|
||||
return $string_url;
|
||||
}
|
||||
|
||||
function add_shop_nginx_conf_rules($rules, $get_path_url, $base_path, $return_string=false){
|
||||
|
||||
$add_rules = array();
|
||||
|
||||
$add_rules[] = "rewrite ^{$base_path}shop/list-([0-9a-z]+)$ {$base_path}".G5_SHOP_DIR."/list.php?ca_id=$1&rewrite=1 break;";
|
||||
$add_rules[] = "rewrite ^{$base_path}shop/type-([0-9a-z]+)$ {$base_path}".G5_SHOP_DIR."/listtype.php?type=$1&rewrite=1 break;";
|
||||
$add_rules[] = "rewrite ^{$base_path}shop/([0-9a-zA-Z_]+)$ {$base_path}".G5_SHOP_DIR."/item.php?it_id=$1&rewrite=1 break;";
|
||||
$add_rules[] = "rewrite ^{$base_path}shop/([^/]+)/$ {$base_path}".G5_SHOP_DIR."/item.php?it_seo_title=$1&rewrite=1 break;";
|
||||
|
||||
return implode("\n", $add_rules).$rules;
|
||||
|
||||
}
|
||||
|
||||
function add_shop_mod_rewrite_rules($rules, $get_path_url, $base_path, $return_string=false){
|
||||
|
||||
$add_rules = array();
|
||||
|
||||
$add_rules[] = 'RewriteRule ^shop/list-([0-9a-z]+)$ '.G5_SHOP_DIR.'/list.php?ca_id=$1&rewrite=1 [QSA,L]';
|
||||
$add_rules[] = 'RewriteRule ^shop/type-([0-9a-z]+)$ '.G5_SHOP_DIR.'/listtype.php?type=$1&rewrite=1 [QSA,L]';
|
||||
$add_rules[] = 'RewriteRule ^shop/([0-9a-zA-Z_]+)$ '.G5_SHOP_DIR.'/item.php?it_id=$1&rewrite=1 [QSA,L]';
|
||||
$add_rules[] = 'RewriteRule ^shop/([^/]+)/$ '.G5_SHOP_DIR.'/item.php?it_seo_title=$1&rewrite=1 [QSA,L]';
|
||||
|
||||
return implode("\n", $add_rules).$rules;
|
||||
|
||||
}
|
||||
|
||||
function add_shop_admin_dbupgrade($is_check){
|
||||
global $g5;
|
||||
|
||||
// 내용 관리 짧은 주소
|
||||
$sql = " SHOW COLUMNS FROM `{$g5['g5_shop_item_table']}` LIKE 'it_seo_title' ";
|
||||
$row = sql_fetch($sql);
|
||||
|
||||
if( !$row ){
|
||||
sql_query("ALTER TABLE `{$g5['g5_shop_item_table']}`
|
||||
ADD `it_seo_title` varchar(200) NOT NULL DEFAULT '' AFTER `it_name`,
|
||||
ADD INDEX `it_seo_title` (`it_seo_title`);
|
||||
", false);
|
||||
|
||||
$is_check = true;
|
||||
}
|
||||
|
||||
return $is_check;
|
||||
|
||||
}
|
||||
|
||||
function shop_exist_check_seo_title($seo_title, $type, $shop_item_table, $it_id){
|
||||
|
||||
$sql = "select it_seo_title FROM {$shop_item_table} WHERE it_seo_title = '".sql_real_escape_string($seo_title)."' AND it_id <> '$it_id' limit 1";
|
||||
$row = sql_fetch($sql, false);
|
||||
|
||||
if( $row['it_seo_title'] ){
|
||||
return 'is_exists';
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
function shop_seo_title_update($it_id){
|
||||
global $g5;
|
||||
|
||||
$item = get_shop_item($it_id, true);
|
||||
|
||||
if( ! $item['it_seo_title'] && $item['it_name'] ){
|
||||
$it_seo_title = exist_seo_title_recursive('shop', generate_seo_title($item['it_name']), $g5['g5_shop_item_table'], $item['it_id']);
|
||||
|
||||
if( $it_seo_title ){
|
||||
$sql = " update `{$g5['g5_shop_item_table']}` set it_seo_title = '{$it_seo_title}' where it_id = '{$item['it_id']}' ";
|
||||
sql_query($sql);
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -7,25 +7,20 @@ if (!defined('_GNUBOARD_')) exit;
|
||||
function get_list_thumbnail($bo_table, $wr_id, $thumb_width, $thumb_height, $is_create=false, $is_crop=false, $crop_mode='center', $is_sharpen=false, $um_value='80/0.5/3')
|
||||
{
|
||||
global $g5, $config;
|
||||
$filename = $alt = "";
|
||||
$filename = $alt = $data_path = '';
|
||||
$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'];
|
||||
$filepath = G5_DATA_PATH.'/file/'.$bo_table;
|
||||
$alt = get_text($row['bf_content']);
|
||||
} else {
|
||||
$write_table = $g5['write_prefix'].$bo_table;
|
||||
$sql = " select wr_content from $write_table where wr_id = '$wr_id' ";
|
||||
$write = sql_fetch($sql);
|
||||
$matches = get_editor_image($write['wr_content'], false);
|
||||
$write = get_thumbnail_find_cache($bo_table, $wr_id, 'content');
|
||||
$edt = true;
|
||||
|
||||
if(isset($matches[1]) && is_array($matches[1])){
|
||||
|
||||
if( $matches = get_editor_image($write['wr_content'], false) ){
|
||||
for($i=0; $i<count($matches[1]); $i++)
|
||||
{
|
||||
// 이미지 path 구함
|
||||
@ -50,12 +45,18 @@ function get_list_thumbnail($bo_table, $wr_id, $thumb_width, $thumb_height, $is_
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$filename = run_replace('get_editor_filename', $filename, $p);
|
||||
} //end for
|
||||
} //end if
|
||||
}
|
||||
|
||||
if(!$filename)
|
||||
return false;
|
||||
|
||||
if( $thumbnail_info = run_replace('get_list_thumbnail_info', array(), array('bo_table'=>$bo_table, 'wr_id'=>$wr_id, 'data_path'=>$data_path, 'edt'=>$edt, 'filename'=>$filename, 'filepath'=>$filepath, 'thumb_width'=>$thumb_width, 'thumb_height'=>$thumb_height, 'is_create'=>$is_create, 'is_crop'=>$is_crop, 'crop_mode'=>$crop_mode, 'is_sharpen'=>$is_sharpen, 'um_value'=>$um_value)) ){
|
||||
return $thumbnail_info;
|
||||
}
|
||||
|
||||
$tname = thumbnail($filename, $filepath, $filepath, $thumb_width, $thumb_height, $is_create, $is_crop, $crop_mode, $is_sharpen, $um_value);
|
||||
|
||||
@ -78,6 +79,20 @@ function get_list_thumbnail($bo_table, $wr_id, $thumb_width, $thumb_height, $is_
|
||||
return $thumb;
|
||||
}
|
||||
|
||||
// 게시글보기 파일 썸네일 리턴
|
||||
function get_file_thumbnail($file){
|
||||
|
||||
if( ! is_array($file) ) return '';
|
||||
|
||||
if( preg_match('/(\.jpg|\.jpeg|\.gif|\.png|\.bmp)$/i', $file['file']) && $contents = run_replace('get_file_thumbnail_tags', '', $file) ){
|
||||
return $contents;
|
||||
} else if ($file['view']) {
|
||||
return get_view_thumbnail($file['view']);
|
||||
}
|
||||
|
||||
return $file['view'];
|
||||
}
|
||||
|
||||
// 게시글보기 썸네일 생성
|
||||
function get_view_thumbnail($contents, $thumb_width=0)
|
||||
{
|
||||
@ -187,7 +202,7 @@ function get_view_thumbnail($contents, $thumb_width=0)
|
||||
}
|
||||
}
|
||||
|
||||
return $contents;
|
||||
return run_replace('get_view_thumbnail', $contents);
|
||||
}
|
||||
|
||||
function thumbnail($filename, $source_path, $target_path, $thumb_width, $thumb_height, $is_create, $is_crop=false, $crop_mode='center', $is_sharpen=false, $um_value='80/0.5/3')
|
||||
|
||||
427
lib/uri.lib.php
Normal file
427
lib/uri.lib.php
Normal file
@ -0,0 +1,427 @@
|
||||
<?php
|
||||
if (!defined('_GNUBOARD_')) exit;
|
||||
|
||||
include_once(dirname(__FILE__) .'/URI/uri.class.php');
|
||||
|
||||
// 짧은 주소 형식으로 만들어서 가져온다.
|
||||
function get_pretty_url($folder, $no='', $query_string='', $action='')
|
||||
{
|
||||
global $g5, $config;
|
||||
|
||||
$boards = get_board_names();
|
||||
$segments = array();
|
||||
$url = $add_query = '';
|
||||
|
||||
if( $url = run_replace('get_pretty_url', $url, $folder, $no, $query_string, $action) ){
|
||||
return $url;
|
||||
}
|
||||
|
||||
// use shortten url
|
||||
if($config['cf_bbs_rewrite']) {
|
||||
|
||||
$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;
|
||||
|
||||
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) {
|
||||
if(substr($query_string, 0, 1) !== '&') {
|
||||
$url .= '&';
|
||||
}
|
||||
|
||||
$url .= $query_string;
|
||||
}
|
||||
} else {
|
||||
$url = G5_BBS_URL. '/'.$folder.'.php';
|
||||
if($no) {
|
||||
$url .= ($folder === 'content') ? '?co_id='. $no : '?'. $no;
|
||||
}
|
||||
if($query_string) {
|
||||
$url .= ($no ? '?' : '&'). $query_string;
|
||||
}
|
||||
}
|
||||
|
||||
$segments[0] = $url;
|
||||
}
|
||||
|
||||
return implode('/', $segments).$add_query;
|
||||
}
|
||||
|
||||
function short_url_clean($string_url, $add_qry=''){
|
||||
|
||||
global $config, $g5;
|
||||
|
||||
if( isset($config['cf_bbs_rewrite']) && $config['cf_bbs_rewrite'] ){
|
||||
|
||||
$string_url = str_replace('&', '&', $string_url);
|
||||
$url=parse_url($string_url);
|
||||
$page_name = basename($url['path'],".php");
|
||||
|
||||
$array_page_names = run_replace('url_clean_page_names', array('board', 'write', 'content'));
|
||||
|
||||
if( strpos($string_url, G5_BBS_URL) === false || ! in_array($page_name, $array_page_names) ){ //게시판이 아니면 리턴
|
||||
return $string_url;
|
||||
}
|
||||
|
||||
$return_url = '';
|
||||
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)) $page_name .= "/".$v;
|
||||
|
||||
if( $page_name === 'write' ){
|
||||
$vars['action'] = 'write';
|
||||
$allow_param_keys = array('bo_table'=>'', 'action'=>'');
|
||||
} else if( $page_name === 'content' ){
|
||||
$vars['action'] = 'content';
|
||||
$allow_param_keys = array('action'=>'', 'co_id'=>'');
|
||||
} else {
|
||||
$allow_param_keys = array('bo_table'=>'', 'wr_id'=>'');
|
||||
}
|
||||
|
||||
$s = array();
|
||||
|
||||
foreach( $allow_param_keys as $key=>$v ){
|
||||
if( !isset($vars[$key]) || empty($vars[$key]) ) continue;
|
||||
|
||||
$s[$key] = $vars[$key];
|
||||
}
|
||||
|
||||
if( $config['cf_bbs_rewrite'] > 1 && $page_name === 'board' && (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'] = urlencode($get_write['wr_seo_title']).'/';
|
||||
}
|
||||
}
|
||||
|
||||
$fragment = isset($url['fragment']) ? '#'.$url['fragment'] : '';
|
||||
|
||||
$host = G5_URL;
|
||||
|
||||
if( isset($url['host']) ){
|
||||
|
||||
$array_file_paths = run_replace('url_clean_page_paths', array('/'.G5_BBS_DIR.'/board.php', '/'.G5_BBS_DIR.'/write.php', '/'.G5_BBS_DIR.'/content.php'));
|
||||
|
||||
$str_path = isset($url['path']) ? $url['path'] : '';
|
||||
$http = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']=='on') ? 'https://' : 'http://';
|
||||
$port = (isset($url['port']) && ($url['port']!==80 || $url['port']!==443)) ? ':'.$url['port'] : '';
|
||||
$host = $http.$url['host'].$port.str_replace($array_file_paths, '', $str_path);
|
||||
}
|
||||
|
||||
$add_param = '';
|
||||
|
||||
if( $result = array_diff_key($vars, $allow_param_keys ) ){
|
||||
$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;
|
||||
}
|
||||
|
||||
return $string_url;
|
||||
}
|
||||
|
||||
function correct_goto_url($url){
|
||||
|
||||
if( substr($url, -1) !== '/' ){
|
||||
return $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);
|
||||
|
||||
$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 run_replace('exist_check_seo_title', $seo_title, $type, $write_table, $sql_id);
|
||||
}
|
||||
|
||||
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, 200 - ($count+1), '')."-$count" : $seo_title;
|
||||
|
||||
if( ! exist_seo_url($type, $seo_title_add, $write_table, $sql_id) ){
|
||||
return $seo_title_add;
|
||||
}
|
||||
|
||||
$count++;
|
||||
|
||||
if( $count > 198 ){
|
||||
return $seo_title_add;
|
||||
}
|
||||
|
||||
return exist_seo_title_recursive($type, $seo_title, $write_table, $sql_id);
|
||||
}
|
||||
|
||||
function seo_title_update($db_table, $pk_id, $type='bbs'){
|
||||
|
||||
global $g5;
|
||||
|
||||
$pk_id = (int) $pk_id;
|
||||
|
||||
if( $type === 'bbs' ){
|
||||
|
||||
$write = get_write($db_table, $pk_id, true);
|
||||
if( ! $write['wr_seo_title'] && $write['wr_subject'] ){
|
||||
$wr_seo_title = exist_seo_title_recursive('bbs', generate_seo_title($write['wr_subject']), $db_table, $pk_id);
|
||||
|
||||
$sql = " update `{$db_table}` set wr_seo_title = '{$wr_seo_title}' where wr_id = '{$pk_id}' ";
|
||||
sql_query($sql);
|
||||
}
|
||||
} else if ( $type === 'content' ){
|
||||
|
||||
$co = get_content_db($pk_id, true);
|
||||
if( ! $co['co_seo_title'] && $co['co_subject'] ){
|
||||
$co_seo_title = exist_seo_title_recursive('content', generate_seo_title($co['co_subject']), $db_table, $pk_id);
|
||||
|
||||
$sql = " update `{$db_table}` set co_seo_title = '{$co_seo_title}' where co_id = '{$pk_id}' ";
|
||||
sql_query($sql);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function get_nginx_conf_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.' nginx rules BEGIN #####';
|
||||
$rules[] = 'if (!-e $request_filename){';
|
||||
|
||||
if( $add_rules = run_replace('add_nginx_conf_rules', '', $get_path_url, $base_path, $return_string) ){
|
||||
$rules[] = $add_rules;
|
||||
}
|
||||
|
||||
$rules[] = "rewrite ^{$base_path}content/([0-9a-zA-Z_]+)$ {$base_path}".G5_BBS_DIR."/content.php?co_id=$1&rewrite=1 break;";
|
||||
$rules[] = "rewrite ^{$base_path}content/([^/]+)/$ {$base_path}".G5_BBS_DIR."/content.php?co_seo_title=$1&rewrite=1 break;";
|
||||
$rules[] = "rewrite ^{$base_path}rss/([0-9a-zA-Z_]+)$ {$base_path}".G5_BBS_DIR."/rss.php?bo_table=$1 break;";
|
||||
$rules[] = "rewrite ^{$base_path}([0-9a-zA-Z_]+)$ {$base_path}".G5_BBS_DIR."/board.php?bo_table=$1&rewrite=1 break;";
|
||||
$rules[] = "rewrite ^{$base_path}([0-9a-zA-Z_]+)/write$ {$base_path}".G5_BBS_DIR."/write.php?bo_table=$1&rewrite=1 break;";
|
||||
$rules[] = "rewrite ^{$base_path}([0-9a-zA-Z_]+)/([^/]+)/$ {$base_path}".G5_BBS_DIR."/board.php?bo_table=$1&wr_seo_title=$2&rewrite=1 break;";
|
||||
$rules[] = "rewrite ^{$base_path}([0-9a-zA-Z_]+)/([0-9]+)$ {$base_path}".G5_BBS_DIR."/board.php?bo_table=$1&wr_id=$2&rewrite=1 break;";
|
||||
$rules[] = '}';
|
||||
$rules[] = '#### '.G5_VERSION.' nginx rules END #####';
|
||||
|
||||
return $return_string ? implode("\n", $rules) : $rules;
|
||||
}
|
||||
|
||||
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 BEGIN #####';
|
||||
$rules[] = '<IfModule mod_rewrite.c>';
|
||||
$rules[] = 'RewriteEngine On';
|
||||
$rules[] = 'RewriteBase '.$base_path;
|
||||
$rules[] = 'RewriteCond %{REQUEST_FILENAME} -f [OR]';
|
||||
$rules[] = 'RewriteCond %{REQUEST_FILENAME} -d';
|
||||
$rules[] = 'RewriteRule ^ - [L]';
|
||||
|
||||
if( $add_rules = run_replace('add_mod_rewrite_rules', '', $get_path_url, $base_path, $return_string) ){
|
||||
$rules[] = $add_rules;
|
||||
}
|
||||
|
||||
$rules[] = 'RewriteRule ^content/([0-9a-zA-Z_]+)$ '.G5_BBS_DIR.'/content.php?co_id=$1&rewrite=1 [QSA,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 [QSA,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[] = '</IfModule>';
|
||||
$rules[] = '#### '.G5_VERSION.' rewrite END #####';
|
||||
|
||||
return $return_string ? implode("\n", $rules) : $rules;
|
||||
}
|
||||
|
||||
function check_need_rewrite_rules(){
|
||||
$is_apache = (stripos($_SERVER['SERVER_SOFTWARE'], 'apache') !== false);
|
||||
|
||||
if($is_apache){
|
||||
$save_path = G5_PATH.'/.htaccess';
|
||||
|
||||
if( !file_exists($save_path) ){
|
||||
return true;
|
||||
}
|
||||
|
||||
$rules = get_mod_rewrite_rules();
|
||||
|
||||
$bof_str = $rules[0];
|
||||
$eof_str = end($rules);
|
||||
|
||||
$code = file_get_contents($save_path);
|
||||
|
||||
if( strpos($code, $bof_str) === false || strpos($code, $eof_str) === false ){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user