From f38a36c025174dc5402776e5766803dfbc7a7a8a Mon Sep 17 00:00:00 2001 From: Arcturus Date: Fri, 4 Oct 2024 11:52:42 +0900 Subject: [PATCH] update character.lib.php --- AvocadoEdition_Light/bbs/index.php | 12 +- .../classes/character/character.class.php | 309 ++++++++++++++++++ AvocadoEdition_Light/classes/module.class.php | 112 +++++++ AvocadoEdition_Light/common.php | 4 +- AvocadoEdition_Light/extend/character.lib.php | 69 +--- AvocadoEdition_Light/extraconfig.php | 11 + AvocadoEdition_Light/install/gnuboard5.sql | 81 +++++ AvocadoEdition_Light/install/install_db.php | 3 + AvocadoEdition_Light/lib/common.lib.php | 9 + 9 files changed, 543 insertions(+), 67 deletions(-) create mode 100644 AvocadoEdition_Light/classes/character/character.class.php create mode 100644 AvocadoEdition_Light/classes/module.class.php create mode 100644 AvocadoEdition_Light/extraconfig.php diff --git a/AvocadoEdition_Light/bbs/index.php b/AvocadoEdition_Light/bbs/index.php index a056b70..17580ad 100644 --- a/AvocadoEdition_Light/bbs/index.php +++ b/AvocadoEdition_Light/bbs/index.php @@ -9,7 +9,7 @@ $ch_list = []; if ($config['cf_side_title']) { $side_result = sql_query("SELECT * FROM {$g5['side_table']}"); for ($i = 0; $si = sql_fetch_array($side_result); $i++) { - $list[] = get_character_list($si['si_id']); + $list[] = Character::getList($si['si_id']); $side[] = $si; } } @@ -18,21 +18,21 @@ if (!$config['cf_side_title'] || count($side) < 2) { $list = []; $side = []; - $list[] = get_character_list(); + $list[] = Character::getList(); $side[] = ''; } $g5['title'] = "멤버란"; -include_once(G5_PATH . '/head.php'); +include_once G5_PATH . '/head.php'; if (defined('G5_THEME_PATH') && is_file(G5_THEME_PATH . "/member/list.skin.php")) { - include(G5_THEME_PATH . "/member/list.skin.php"); + include G5_THEME_PATH . "/member/list.skin.php"; } else { - include(G5_PATH . "/member/skin/list.skin.php"); + include G5_PATH . "/member/skin/list.skin.php"; } unset($ch); unset($list); -include_once(G5_PATH . '/tail.php'); +include_once G5_PATH . '/tail.php'; diff --git a/AvocadoEdition_Light/classes/character/character.class.php b/AvocadoEdition_Light/classes/character/character.class.php new file mode 100644 index 0000000..94cd3d3 --- /dev/null +++ b/AvocadoEdition_Light/classes/character/character.class.php @@ -0,0 +1,309 @@ +getError() === 0) { + return $character; + } + } + + return ["error" => "DB에 연결하지 못했습니다."]; + } + + /** + * get character by character_id (compatilbe name for avocado) + * @param mixed $character_id + * @return Character|array|object|null + */ + public static function get_character($character_id) + { + return self::getCharacter($character_id); + } + + /** + * get character by name + * @param mixed $character_name + * @return Character|null + */ + public static function getCharacterByName($character_name) + { + global $g5; + + $character_name = addslashes($character_name); + $character = sql_fetch("SELECT ch_id FROM {$g5["character_table"]} WHERE ch_name = '{$character_name}'"); + + if ($character) { + return new Character(intval($character["ch_id"])); + } + + return null; + } + + public static function get_character_by_name($character_name) + { + return self::getCharacterByName($character_name); + } + + /** + * get character name by character_id + * @param mixed $character_id + * @return string + */ + public static function getName($character_id) + { + global $g5; + if (isset($g5["connect_db"]) && isset($g5["character_table"])) { + $data = sql_fetch("SELECT ch.ch_name FROM {$g5['character_table']} ch WHERE ch.ch_id = '{$character_id}'"); + if (!empty($data)) { + return $data["ch_name"]; + } else { + return "캐릭터를 찾을 수 없습니다."; + } + } + + return "DB에 연결하지 못했습니다."; + } + + /** + * get character name by character_id (compatilbe name for avocado) + * @param mixed $character_id + * @return string + */ + public static function get_character_name($character_id) + { + return self::getName($character_id); + } + + /** + * get character name by member_id + * @param mixed $member_id + * @return string + */ + public static function getNameByMemberID($member_id) + { + global $g5; + if (isset($g5["connect_db"]) && isset($g5["character_table"]) && isset($g5["member_table"])) { + $data = sql_fetch("SELECT ch.ch_name FROM {$g5["character_table"]} ch, {$g5["member_table"]} mb WHERE mb.mb_id = '{$member_id}' AND ch.mb_id = mb.mb_id"); + if (!empty($data)) { + return $data["ch_name"]; + } else { + return "캐릭터를 찾을 수 없습니다."; + } + } + + return "DB에 연결하지 못했습니다."; + } + + /** + * get character name by member_id (compatible name for avocadoedition) + * @param mixed $member_id + * @return string + */ + public static function get_member_character_name($member_id) + { + return self::getNameByMemberID($member_id); + } + + public static function getInfoList($character_id) + { + global $g5; + if (isset($g5["connect_db"]) && isset($g5["character_table"]) && isset($g5["value_table"])) { + $info_list = []; + $rawdata = sql_query("SELECT ar_code, av_value FROM {$g5["value_table"]} WHERE ch_id = '{$character_id}'"); + while($r = sql_fetch_array($rawdata)) { + $info_list[$r["ar_code"]] = $r["av_value"]; + } + } + + return $info_list; + } + + /** + * get character info (compatible name for avocadoedition) + * @param int|string $character_id + * @param string $extra_code + * @return string + */ + public static function getInfo($character_id, $extra_code) + { + global $g5; + if (isset($g5["connect_db"]) && isset($g5["character_table"]) && isset($g5["value_table"])) { + $data = sql_fetch("SELECT av_value FROM {$g5["value_table"]} WHERE ch_id = '{$character_id}' AND ar_code = '{$extra_code}'"); + if (!empty($data)) { + + } else { + return ""; + } + } + + return "DB에 연결하지 못했습니다."; + } + + /** + * get character info (compatible name for avocadoedition) + * @param int|string $character_id + * @param string $extra_code + * @return string + */ + public static function get_character_info($character_id, $extra_code) + { + return self::getInfo($character_id, $extra_code); + } + + /** + * get character list + * @param string $side + * @param string $class + * @param string $state + * @return array + */ + public static function getList($side = "", $class = "", $state = "승인") + { + global $g5; + + $character = []; + $s = ''; + $s .= $side ? " and ch_side = '{$side}' " : ""; + $s .= $class ? " and ch_class = '{$class}' " : ""; + + $sql = "SELECT * FROM {$g5["character_table"]} WHERE ch_state = '{$state}' {$s} ORDER BY ch_id ASC"; + + $res = sql_query($sql); + while($r = sql_fetch_array($res)) { + $character[] = $r; + } + + return $character; + } + + /** + * get character list (compatible name for avocadoedition) + * @param string $side + * @param string $class + * @param string $state + * @return array + */ + public static function get_character_list($side = "", $class = "", $state = "승인") + { + return self::getList($side, $class, $state); + } + + /** + * get character thumb + * @param mixed $character_id + * @return string + */ + public static function getHead($character_id) + { + global $g5; + if (isset($g5["connect_db"]) && isset($g5["character_table"])) { + $data = sql_fetch("SELECT ch.ch_thumb FROM {$g5['character_table']} ch WHERE ch.ch_id = '{$character_id}'"); + if (!empty($data)) { + return $data["ch_thumb"]; + } else { + return ""; + } + } + + return ""; + } + + /** + * get character thumb (compatible name for avocadoedition) + * @param mixed $character_id + * @return string + */ + public static function get_character_head($character_id) + { + return self::getHead($character_id); + } + + /** + * get member name + * @param mixed $member_id + * @return mixed + */ + public static function getMemberName($member_id) + { + global $g5; + if (isset($g5["connect_db"]) && isset($g5["member_table"])) { + $data = sql_fetch("SELECT mb.mb_nick FROM {$g5['member_table']} mb WHERE mb.mb_nick = '{$member_id}'"); + if (!empty($data)) { + return $data["mb_nick"]; + } else { + return ""; + } + } + + return ""; + } + + /** + * get member name (compatible name for avocadoedition) + * @param mixed $member_id + * @return mixed + */ + public static function get_member_name($member_id) + { + return self::getMemberName($member_id); + } + + public static function fixMemberCharacter() + { + global $g5, $is_member, $member, $character; + + if (isset($g5["connect_db"]) && isset($g5["member_table"]) && isset($g5["character_table"]) && $is_member && ( + $member["mb_id"] != $character["mb_id"] || $member["ch_id"] == "" || !$character["ch_id"] + )) { + $character_sql = "SELECT * FROM {$g5["character_table"]} where mb_id = '{$member['mb_id']}' limit 0, 1"; + $character = sql_fetch($character_sql); + + if ($character['ch_id']) { + sql_query("UPDATE {$g5["member_table"]} SET ch_id = '{$character['ch_id']}' WHERE mb_id = '{$member['mb_id']}'"); + } + } + } + + public static function resetSearchCount() + { + global $g5, $character; + + if ($character["ch_id"]) { + if ($character["ch_search_date"] != G5_TIME_YMD) { + $time = G5_TIME_YMD; + sql_query("UPDATE {$g5["character_table"]} SET ch_search = 0, ch_search_date = '{$time}' WHERE ch_id = '{$character['ch_id']}'"); + $character["ch_search"] = 0; + $character["ch_search_date"] = G5_TIME_YMD; + } + } + } + + public function __construct($character_id) + { + global $g5; + parent::__construct(); + + if (isset($g5["connect_db"]) && isset($g5["character_table"])) { + $this->_rawdata = sql_fetch("SELECT ch.ch_name FROM {$g5['character_table']} ch WHERE ch.ch_id = '{$character_id}'"); + if (!empty($this->rawdata)) { + parent::init($this->_rawdata); + } else { + $this->setError(2); + } + } else { + $this->setError(1); + } + } +} diff --git a/AvocadoEdition_Light/classes/module.class.php b/AvocadoEdition_Light/classes/module.class.php new file mode 100644 index 0000000..8d51694 --- /dev/null +++ b/AvocadoEdition_Light/classes/module.class.php @@ -0,0 +1,112 @@ +createdAt = microtime(true); + $this->setError($err); + } + + public function init($data = []) + { + $this->triggerEvent('beforeInit'); + if (!empty($data)) { + $this->adds($data); + } + $this->triggerEvent('afterInit'); + } + + public function setResult($msg = "") + { + $this->result = $msg; + } + + public function getResult() + { + return $this->result; + } + + public function setError($err = 0) + { + $this->error = $err; + } + + public function getError() + { + return $this->error; + } + + public function get($key) + { + return array_key_exists($key, $this->variables) ? $this->variables[$key] : null; + } + + public function gets() + { + $args = func_get_args(); + $ret = new stdClass(); + foreach ($args as $arg) { + $ret->$arg = $this->get($arg); + } + return $ret; + } + + public function add($key, $val) + { + $this->variables[$key] = $val; + } + + public function adds($obj) + { + if (is_object($obj)) { + $obj = get_object_vars($obj); + } + + if (is_array($obj)) { + foreach ($obj as $k => $v) { + $this->variables[$k] = $v; + } + } + } + + protected function addStopwatch($key) + { + if (defined("__IS_DEBUG__")) { + if (count($this->performanceStopwatch) > 0) { + $prev = end($this->performanceStopwatch); + $this->performanceStopwatch[$key] = microtime(true) - $this->createdAt - $prev; + } else { + $this->performanceStopwatch[$key] = microtime(true) - $this->createdAt; + } + } + } + + public function addStopwatchWithCallStack($key) + { + if (defined("__IS_DEBUG__")) { + if ($key === 0) + $key = "start"; + else if ($key === 1) + $key = "end"; + $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); + $cf = $backtrace[1]['function'] ? $backtrace[1]['function'] : 'global scope'; + $this->addStopwatch("{$cf} {$key}"); + } + } + + public function addEventHandler($event, $callback) + { + EventHandler::addEventHandler($event, $callback); + } + + protected static function triggerEvent($event, $data = []) + { + EventHandler::triggerEvent($event, $data); + } +} diff --git a/AvocadoEdition_Light/common.php b/AvocadoEdition_Light/common.php index 69737c4..0f630e1 100644 --- a/AvocadoEdition_Light/common.php +++ b/AvocadoEdition_Light/common.php @@ -223,6 +223,7 @@ function chrome_domain_session_name() } include_once __DIR__ . "/classes/event_handler.php"; +include_once __DIR__ . "/classes/module.class.php"; $extra_headers = [ 'HTTP_X_REAL_IP', @@ -379,8 +380,7 @@ if (file_exists($dbconfig_file)) { include_once $dbconfig_file; include_once G5_LIB_PATH . '/common.lib.php'; // 공통 라이브러리 - $g5["font_table"] = G5_TABLE_PREFIX . "editor_fonts"; - $g5["addons_config_table"] = G5_TABLE_PREFIX . "addons_config"; + include_once G5_PATH . "/extraconfig.php"; $connect_db = sql_connect(G5_MYSQL_HOST, G5_MYSQL_USER, G5_MYSQL_PASSWORD) or die('MySQL Connect Error!!!'); $select_db = sql_select_db(G5_MYSQL_DB, $connect_db) or die('MySQL DB Error!!!'); diff --git a/AvocadoEdition_Light/extend/character.lib.php b/AvocadoEdition_Light/extend/character.lib.php index 26017fe..8250925 100644 --- a/AvocadoEdition_Light/extend/character.lib.php +++ b/AvocadoEdition_Light/extend/character.lib.php @@ -2,93 +2,44 @@ if (!defined('_GNUBOARD_')) exit; -$character = get_character($member['ch_id']); -if ($is_member && ($member['mb_id'] != $character['mb_id'] || $member['ch_id'] == '' || !$character['ch_id'])) { - $character_sql = "SELECT * FROM {$g5['character_table']} where mb_id = '{$member['mb_id']}' limit 0, 1"; - $character = sql_fetch($character_sql); - if ($character['ch_id']) { - sql_query("UPDATE {$g5['member_table']} SET ch_id = '{$character['ch_id']}' where mb_id = '{$member['mb_id']}'"); - } -} +$character = Character::getCharacter($member['ch_id']); -if ($character['ch_id']) { - if ($character['ch_search_date'] != G5_TIME_YMD) { - $time = G5_TIME_YMD; - sql_query("UPDATE {$g5['character_table']} - SET ch_search = 0, - ch_search_date = '{$time}' - WHERE ch_id = '{$character['ch_id']}' - "); - $character['ch_search'] = 0; - $character['ch_search_date'] = G5_TIME_YMD; - } -} +Character::fixMemberCharacter(); +Character::resetSearchCount(); function get_character_name($ch_id) { - global $g5; - $character = sql_fetch("SELECT ch_name FROM {$g5['character_table']} where ch_id = '{$ch_id}'"); - return $character['ch_name']; + return Character::getName($ch_id); } function get_member_character_name($mb_id) { - global $g5; - $character = sql_fetch("SELECT ch.ch_name FROM {$g5['character_table']} ch, {$g5['member_table']} mb where mb.mb_id= '{$mb_id}' and ch.mb_id = mb.mb_id"); - return $character['ch_name']; + return Character::getNameByMemberID($mb_id); } function get_character_head($ch_id) { - global $g5; - $ch = sql_fetch("SELECT ch_thumb FROM {$g5['character_table']} where ch_id = '{$ch_id}'"); - return $ch['ch_thumb']; + return Character::getHead($ch_id); } function get_member_name($mb_id) { - global $g5; - $member = sql_fetch("SELECT mb_nick FROM {$g5['member_table']} where mb_id = '{$mb_id}'"); - return $member['mb_nick']; + return Character::getMemberName($mb_id); } function get_character($ch_id) { - global $g5; - $character = sql_fetch("SELECT * FROM {$g5['character_table']} where ch_id = '{$ch_id}'"); - return $character; + return Character::getCharacter($ch_id); } function get_character_info($ch_id, $ar_code) { - global $g5; - $ch = sql_fetch("SELECT av_value FROM {$g5['value_table']} where ch_id = '{$ch_id}' and ar_code = '{$ar_code}'"); - return $ch['av_value']; + return Character::getInfo($ch_id, $ar_code); } function get_character_list($side = '', $class = '', $state = '승인') { - global $g5; - $character = []; - $sql_search = ''; - - if ($side) { - $sql_search .= " and ch_side = '{$side}' "; - } - - if ($class) { - $sql_search .= " and ch_class = '{$class}' "; - } - - $sql_common = "SELECT * FROM {$g5['character_table']} - WHERE ch_state = '{$state}' - {$sql_search} - ORDER BY ch_id ASC"; - $result = sql_query($sql_common); - for ($i = 0; $row = sql_fetch_array($result); $i++) { - $character[] = $row; - } - return $character; + return Character::getList($side, $class, $state); } function add_profile_article($theme, $code, $name, $type = 'text', $pice = '', $help = '', $order = '') diff --git a/AvocadoEdition_Light/extraconfig.php b/AvocadoEdition_Light/extraconfig.php new file mode 100644 index 0000000..e2451ca --- /dev/null +++ b/AvocadoEdition_Light/extraconfig.php @@ -0,0 +1,11 @@ +