From 949352ec2a1c00f8415a18372c8d7cf344d61054 Mon Sep 17 00:00:00 2001 From: Arcturus Date: Sat, 5 Oct 2024 12:03:13 +0900 Subject: [PATCH] init --- .editorconfig | 8 +++ hashtag.addon.php | 174 ++++++++++++++++++++++++++++++++++++++++++++++ readme.md | 8 +++ 3 files changed, 190 insertions(+) create mode 100644 .editorconfig create mode 100644 hashtag.addon.php create mode 100644 readme.md diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..78c6dde --- /dev/null +++ b/.editorconfig @@ -0,0 +1,8 @@ +root = true + +[*] +end_of_line = lf +insert_final_newline = true +charset = utf-8 +indent_style = space +indent_size = 2 diff --git a/hashtag.addon.php b/hashtag.addon.php new file mode 100644 index 0000000..61a87d7 --- /dev/null +++ b/hashtag.addon.php @@ -0,0 +1,174 @@ +writeUpdateDocumentUpdate($args); + } + , + 10 + ); + + EventHandler::addEventHandler( + "gnuboard.bbs.write_update_document_update", + function ($args = null) use ($that) { + $that->writeUpdateDocumentUpdate($args); + } + , + 10 + ); + + EventHandler::addEventHandler( + "gnuboard.bbs.delete", + function ($args = null) use ($that) { + $bo_table = $_POST["bo_table"]; + $write = $args[0]; + + $that->delete_hashtags($bo_table, $write['wr_id']); + } + , + 10 + ); + } + + public function extract_hashtags($content) + { + preg_match_all('/#([A-Za-z0-9가-힣ㄱ-ㅎㅏ-ㅣ_]+)/', $content, $matches); + return $matches[1]; + } + + public function delete_hashtags($bo_table, $wr_id) + { + global $g5; + sql_query("DELETE FROM {$g5['hashtag_posts_table']} WHERE `board_id` = '{$bo_table}' AND `post_id` = '{$wr_id}'"); + $sql = "SELECT h.srl, COUNT(hp.srl) AS count + FROM {$g5['hashtags_table']} h + LEFT JOIN {$g5['hashtag_posts_table']} hp + ON h.srl = hp.srl + GROUP BY h.srl + HAVING count = 0"; + + $result = sql_query($sql); + + while ($row = sql_fetch_array($result)) { + $delete_srl = $row['srl']; + $delete_sql = "DELETE FROM {$g5['hashtags_table']} WHERE srl = '$delete_srl'"; + sql_query($delete_sql); + } + } + + public function proc_hashtags($bo_table, $wr_id, $content) + { + global $g5; + // if post update, reset hashtag data - arcturus + $this->delete_hashtags($bo_table, $wr_id); + + $hashtags = $this->extract_hashtags($content); + foreach ($hashtags as $hashtag) { + $q = sql_fetch("SELECT `srl` FROM `{$g5['hashtags_table']}` WHERE `h_name` = '{$hashtag}'"); + if (!$q) { + sql_query("INSERT INTO {$g5['hashtags_table']} SET `h_name` = '{$hashtag}', `h_hidden` = 0"); + $q = sql_fetch("SELECT `srl` FROM `{$g5['hashtags_table']}` WHERE `h_name` = '{$hashtag}'"); + } + sql_query("INSERT INTO {$g5['hashtag_posts_table']} SET `board_id` = '{$bo_table}', `post_id` = '{$wr_id}', `srl` = '{$q['srl']}'"); + } + } + + public function writeUpdateDocumentUpdate($data) + { + global $is_admin; + + if ($is_admin) { + $wr_content = ''; + if (isset($_POST['wr_content'])) { + $wr_content = substr(trim($_POST['wr_content']), 0, 65536); + $wr_content = preg_replace("#[\\\]+$#", "", $wr_content); + } + + $bo_table = isset($data[0]) ? $data[0] : ''; + $wr_id = isset($data[2]) ? $data[2] : ''; + + $this->proc_hashtags($bo_table, $wr_id, $wr_content); + } + } + + public function printConfigForm() + { + // $config = $this->getConfig(); + echo '현재 애드온에 별도의 설정이 없습니다.'; + } + + public function getConfig() + { + global $g5; + + $sql = "SELECT addon_config FROM {$g5['addons_config_table']} WHERE addon_name = '{$this->className}'"; + $result = sql_fetch($sql); + + if ($result && isset($result['addon_config'])) { + return json_decode($result['addon_config'], true) ?: []; + } + + return []; + } +} diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..231d17c --- /dev/null +++ b/readme.md @@ -0,0 +1,8 @@ +## 해시태그 애드온 + +게시글 작성 시 게시글 내부에 `#` 을 붙여 작성하는 해시태그를 데이터베이스에 등록하고 +지원하는 스킨에서 사용할 수 있게 해 주는 애드온입니다. + +## 설치방법 + +`/addons/hashtag` 폴더를 만들어 저장소의 hashtag.addon.php 를 업로드합니다.