init
This commit is contained in:
commit
949352ec2a
3 changed files with 190 additions and 0 deletions
8
.editorconfig
Normal file
8
.editorconfig
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
root = true
|
||||
|
||||
[*]
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
charset = utf-8
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
174
hashtag.addon.php
Normal file
174
hashtag.addon.php
Normal file
|
|
@ -0,0 +1,174 @@
|
|||
<?php
|
||||
class HashtagAddon extends Addon
|
||||
{
|
||||
public $name = "게시글 해시태그 추적 애드온";
|
||||
public $description = "해시태그 추적 애드온";
|
||||
public $author = "Amber";
|
||||
public $link = "https://info.drk.st/about";
|
||||
public $version = "1.0.0";
|
||||
|
||||
public $className;
|
||||
public $addonPath;
|
||||
public $addonFile;
|
||||
|
||||
/**
|
||||
* 애드온 생성자입니다.
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function init($data = [])
|
||||
{
|
||||
$that = $this;
|
||||
|
||||
EventHAndler::addEventHandler(
|
||||
"amber.load_config_after",
|
||||
function ($args = null) {
|
||||
global $g5;
|
||||
|
||||
$g5['hashtags_table'] = G5_TABLE_PREFIX . 'hashtags';
|
||||
$g5['hashtag_posts_table'] = G5_TABLE_PREFIX . 'hashtag_posts';
|
||||
|
||||
if (!sql_fetch_array(sql_query("DESC {$g5['hashtags_table']}"))) {
|
||||
sql_query("CREATE TABLE {$g5['hashtags_table']} (
|
||||
`srl` INT(11) NOT NULL AUTO_INCREMENT,
|
||||
`h_name` VARCHAR(255) NULL DEFAULT '' COLLATE 'utf8mb3_general_ci',
|
||||
`h_hidden` INT(11) NOT NULL DEFAULT '0',
|
||||
`h_created_at` DATETIME NULL DEFAULT current_timestamp(),
|
||||
`h_updated_at` DATETIME NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
|
||||
PRIMARY KEY (`srl`) USING BTREE
|
||||
)
|
||||
COLLATE='utf8mb3_general_ci'
|
||||
ENGINE=MyISAM");
|
||||
}
|
||||
|
||||
if (!sql_fetch_array(sql_query("DESC {$g5['hashtag_posts_table']}"))) {
|
||||
sql_query("CREATE TABLE {$g5['hashtag_posts_table']} (
|
||||
`post_id` INT(11) NOT NULL,
|
||||
`board_id` VARCHAR(255) NOT NULL,
|
||||
`srl` INT NOT NULL,
|
||||
`created_at` DATETIME NULL DEFAULT current_timestamp(),
|
||||
PRIMARY KEY (`post_id`, `board_id`, `srl`),
|
||||
FOREIGN KEY (`srl`) REFERENCES {$g5['hashtags_table']}(`srl`) ON DELETE CASCADE
|
||||
)
|
||||
COLLATE='utf8mb3_general_ci'
|
||||
ENGINE=MyISAM");
|
||||
}
|
||||
},
|
||||
10
|
||||
);
|
||||
|
||||
EventHandler::addEventHandler(
|
||||
"gnuboard.bbs.write_update_document_create",
|
||||
function ($args = null) use ($that) {
|
||||
$that->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 [];
|
||||
}
|
||||
}
|
||||
8
readme.md
Normal file
8
readme.md
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
## 해시태그 애드온
|
||||
|
||||
게시글 작성 시 게시글 내부에 `#` 을 붙여 작성하는 해시태그를 데이터베이스에 등록하고
|
||||
지원하는 스킨에서 사용할 수 있게 해 주는 애드온입니다.
|
||||
|
||||
## 설치방법
|
||||
|
||||
`/addons/hashtag` 폴더를 만들어 저장소의 hashtag.addon.php 를 업로드합니다.
|
||||
Loading…
Reference in a new issue