일부 코드 수정

This commit is contained in:
thisgun
2018-09-06 17:21:27 +09:00
parent 2b79194f72
commit 25bd7430fc
10 changed files with 703 additions and 8 deletions
+5 -1
View File
@@ -123,6 +123,8 @@ $board = array();
$group = array();
$g5 = array();
include_once(G5_LIB_PATH.'/hook.lib.php'); // hook 함수 파일
include_once(G5_LIB_PATH.'/uri.lib.php'); // URL 함수 파일
//==============================================================================
// 공통
@@ -637,5 +639,7 @@ header('Cache-Control: no-store, no-cache, must-revalidate'); // HTTP/1.1
header('Cache-Control: pre-check=0, post-check=0, max-age=0'); // HTTP/1.1
header('Pragma: no-cache'); // HTTP/1.0
start_event('common_header');
$html_process = new html_process();
?>
?>
+327
View 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
View 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
?>
+7
View File
@@ -0,0 +1,7 @@
<?php
if (!defined('_GNUBOARD_')) exit;
class G5_URI {
}
?>
+2 -2
View File
@@ -405,9 +405,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'].'&amp;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'].'&amp;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'] = '';
+125
View File
@@ -0,0 +1,125 @@
<?php
if (!defined('_GNUBOARD_')) exit;
define('G5_HOOK_DEFAULT_PRIORITY', 8);
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 put_event($tag, $func, $priority=GML_HOOK_DEFAULT_PRIORITY, $args=0){
global $gml;
if( $hook = get_hook_class() ){
$hook::addAction($tag, $func, $priority, $args);
}
}
function start_event($tag, $arg = ''){
global $gml;
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 put_replace($tag, $func, $priority=G5_HOOK_DEFAULT_PRIORITY, $args=0){
global $gml;
if( $hook = get_hook_class() ){
return $hook::addFilter($tag, $func, $priority, $args);
}
return null;
}
function apply_replace($tag, $arg = ''){
global $gml;
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;
}
?>
+71
View File
@@ -0,0 +1,71 @@
<?php
if (!defined('_GNUBOARD_')) exit;
// 짧은 주소 형식으로 만들어서 가져온다.
function get_pretty_url($folder, $no='', $query_string='')
{
global $g5, $config;
$config['cf_bbs_rewrite'] = 1;
/*
static $boards = array();
if( ! $boards ){
$sql = " select bo_table from {$gml['board_table']} ";
$result = sql_query($sql);
while ($row = sql_fetch_array($result)) {
$boards[] = $row['bo_table'];
}
}
*/
// use shortten url
if($config['cf_bbs_rewrite']) {
if(in_array($folder, $boards)) {
$url = G5_URL. '/'. $folder;
if($no) {
$url .= '/'. $no;
}
} else {
$url = G5_URL. '/'.$folder;
if($no) {
$no_array = explode("=", $no);
$no_value = end($no_array);
$url .= '/'. $no_value;
}
}
if($query_string) {
// If the first character of the query string is '&', replace it with '?'.
if(substr($query_string, 0, 1) == '&') {
$url .= preg_replace("/\&amp;/", "?", $query_string, 1);
} else {
$url .= '?'. $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 .= '&amp;wr_id='. $no;
}
if($query_string) {
$url .= '&amp;'. $query_string;
}
} else {
$url = G5_BBS_URL. '/'.$folder.'.php';
if($no) {
$url .= '?'. $no;
}
if($query_string) {
$url .= ($no ? '?' : '&amp;'). $query_string;
}
}
}
return $url;
}
?>
+2 -2
View File
@@ -7,7 +7,7 @@ add_javascript('<script src="'.G5_JS_URL.'/jquery.bxslider.js"></script>', 10);
?>
<div class="lat">
<h2 class="lat_title"><a href="<?php echo G5_BBS_URL ?>/board.php?bo_table=<?php echo $bo_table ?>"><?php echo $bo_subject ?></a></h2>
<h2 class="lat_title"><a href="<?php echo get_pretty_url($bo_table); ?>"><?php echo $bo_subject ?></a></h2>
<ul>
<?php for ($i=0; $i<count($list); $i++) { ?>
<li>
@@ -48,6 +48,6 @@ add_javascript('<script src="'.G5_JS_URL.'/jquery.bxslider.js"></script>', 10);
<li class="empty_li">게시물이 없습니다.</li>
<?php } ?>
</ul>
<a href="<?php echo G5_BBS_URL ?>/board.php?bo_table=<?php echo $bo_table ?>" class="lt_more"><span class="sound_only"><?php echo $bo_subject ?></span><i class="fa fa-plus" aria-hidden="true"></i><span class="sound_only"> 더보기</span></a>
<a href="<?php echo get_pretty_url($bo_table); ?>" class="lt_more"><span class="sound_only"><?php echo $bo_subject ?></span><i class="fa fa-plus" aria-hidden="true"></i><span class="sound_only"> 더보기</span></a>
</div>
+1 -1
View File
@@ -7,7 +7,7 @@ add_javascript('<script src="'.G5_JS_URL.'/jquery.bxslider.js"></script>', 10);
?>
<div class="notice">
<h2><a href="<?php echo G5_BBS_URL ?>/board.php?bo_table=<?php echo $bo_table ?>"><i class="fa fa-bullhorn" aria-hidden="true"></i><span class="sound_only"><?php echo $bo_subject ?></span></a></h2>
<h2><a href="<?php echo get_pretty_url($bo_table); ?>"><i class="fa fa-bullhorn" aria-hidden="true"></i><span class="sound_only"><?php echo $bo_subject ?></span></a></h2>
<ul>
<?php for ($i=0; $i<count($list); $i++) { ?>
<li>
+2 -2
View File
@@ -9,7 +9,7 @@ $thumb_height = 150;
?>
<div class="pic_lt">
<h2 class="lat_title"><a href="<?php echo G5_BBS_URL ?>/board.php?bo_table=<?php echo $bo_table ?>"><?php echo $bo_subject ?></a></h2>
<h2 class="lat_title"><a href="<?php echo get_pretty_url($bo_table); ?>"><?php echo $bo_subject ?></a></h2>
<ul>
<?php
for ($i=0; $i<count($list); $i++) {
@@ -61,6 +61,6 @@ $thumb_height = 150;
<li class="empty_li">게시물이 없습니다.</li>
<?php } ?>
</ul>
<a href="<?php echo G5_BBS_URL ?>/board.php?bo_table=<?php echo $bo_table ?>" class="lt_more"><span class="sound_only"><?php echo $bo_subject ?></span><i class="fa fa-plus" aria-hidden="true"></i><span class="sound_only"> 더보기</span></a>
<a href="<?php echo get_pretty_url($bo_table); ?>" class="lt_more"><span class="sound_only"><?php echo $bo_subject ?></span><i class="fa fa-plus" aria-hidden="true"></i><span class="sound_only"> 더보기</span></a>
</div>