Skip to content

Commit

Permalink
✨ alert post in selected forums and show cateory
Browse files Browse the repository at this point in the history
  • Loading branch information
popiazaza committed Mar 12, 2023
1 parent 60ea8ce commit 9bd002f
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 14 deletions.
20 changes: 19 additions & 1 deletion th_chat/discuz_plugin_th_chat.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<item id="datatables"><![CDATA[]]></item>
<item id="directory"><![CDATA[th_chat/]]></item>
<item id="copyright"><![CDATA[newz & popiazaza]]></item>
<item id="version"><![CDATA[3.3.7]]></item>
<item id="version"><![CDATA[3.3.8]]></item>
<item id="__modules">
<item id="0">
<item id="name"><![CDATA[hook]]></item>
Expand Down Expand Up @@ -320,6 +320,24 @@ dark = มืด]]></item>
2 = ให้เลือกส่งได้โดยมีค่าเริ่มต้นเป็น ส่ง
3 = ให้เลือกส่งได้โดยมีค่าเริ่มต้นเป็น ไมส่ง]]></item>
</item>
<item id="39">
<item id="displayorder"><![CDATA[39]]></item>
<item id="title"><![CDATA[หมวดหมู่เว็บบอร์ดที่ให้มีการแจ้งเตือนได้]]></item>
<item id="description"><![CDATA[]]></item>
<item id="variable"><![CDATA[category_post]]></item>
<item id="type"><![CDATA[forums]]></item>
<item id="value"><![CDATA[]]></item>
<item id="extra"><![CDATA[]]></item>
</item>
<item id="40">
<item id="displayorder"><![CDATA[40]]></item>
<item id="title"><![CDATA[แสดงหมวดหมู่เว็บบอร์ดในข้อความแจ้งเตือน]]></item>
<item id="description"><![CDATA[]]></item>
<item id="variable"><![CDATA[show_category]]></item>
<item id="type"><![CDATA[radio]]></item>
<item id="value"><![CDATA[]]></item>
<item id="extra"><![CDATA[]]></item>
</item>
</item>
</item>
</root>
45 changes: 32 additions & 13 deletions th_chat/hook.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ function post_middle()
if ($_G['uid']) {
loadcache('plugin');
$config = $_G['cache']['plugin']['th_chat'];
if ($config['new_post'] > 0 && $_GET['action'] == 'newthread') {
if ($config['new_post'] > 1) {
return '<input type="checkbox" id="th_chat_notify" name="th_chat_notify" value="1"' . ($config['new_post'] == 2 ? ' checked' : '') . '><label for="th_chat_notify"> โพสต์กระทู้นี้ไปยังห้องแชท</label><br>';
}
} elseif ($config['edit_post'] > 0 && $_GET['action'] == 'edit') {
if ($config['edit_post'] > 1 && $post = DB::fetch_first("SELECT * FROM " . DB::table('forum_post') . " WHERE tid=" . intval($_GET['tid']) . " AND pid=" . intval($_GET['pid']) . " AND position=1")) {
return '<input type="checkbox" id="th_chat_notify" name="th_chat_notify" value="1"' . ($config['edit_post'] == 2 ? ' checked' : '') . '><label for="th_chat_notify"> โพสต์การแก้ไขกระทู้นี้ไปยังห้องแชท</label><br>';
$forums = unserialize($config['category_post']);
if (in_array($_GET['fid'], $forums)) {
if ($config['new_post'] > 0 && $_GET['action'] == 'newthread') {
if ($config['new_post'] > 1) {
return '<input type="checkbox" id="th_chat_notify" name="th_chat_notify" value="1"' . ($config['new_post'] == 2 ? ' checked' : '') . '><label for="th_chat_notify"> โพสต์กระทู้นี้ไปยังห้องแชท</label><br>';
}
} elseif ($config['edit_post'] > 0 && $_GET['action'] == 'edit') {
if ($config['edit_post'] > 1 && DB::fetch_first("SELECT * FROM " . DB::table('forum_post') . " WHERE tid=" . intval($_GET['tid']) . " AND pid=" . intval($_GET['pid']) . " AND position=1")) {
return '<input type="checkbox" id="th_chat_notify" name="th_chat_notify" value="1"' . ($config['edit_post'] == 2 ? ' checked' : '') . '><label for="th_chat_notify"> โพสต์การแก้ไขกระทู้นี้ไปยังห้องแชท</label><br>';
}
}
}
}
Expand All @@ -37,15 +40,31 @@ function post_middle_message($args)
loadcache('plugin');
$config = $_G['cache']['plugin']['th_chat'];
if ($config['new_post'] > 0 && $args['param'][0] == 'post_newthread_succeed') {
if ($config['new_post'] == 2 || $_POST['th_chat_notify']) {
if ($post = DB::fetch_first("SELECT * FROM " . DB::table('forum_post') . " WHERE `fid` = " . $args['param'][2]['fid'] . " AND `tid` = " . $args['param'][2]['tid'] . " AND `pid` = " . $args['param'][2]['pid'])) {
DB::query("INSERT INTO " . DB::table('newz_data') . " (uid,touid,icon,text,time,ip) VALUES (" . $_G['uid'] . ",0,'bot','โพสต์ <a target=\"_blank\" href=\"forum.php?mod=viewthread&tid=" . $post['tid'] . "\">" . addslashes($post['subject']) . "</a>'," . time() . ",'" . $_G['clientip'] . "')");
$forums = unserialize($config['category_post']);
if (in_array($args['param'][2]['fid'], $forums)) {
if ($config['new_post'] == 2 || $_POST['th_chat_notify']) {
if ($post = DB::fetch_first("SELECT * FROM " . DB::table('forum_post') . " WHERE `fid` = " . $args['param'][2]['fid'] . " AND `tid` = " . $args['param'][2]['tid'] . " AND `pid` = " . $args['param'][2]['pid'])) {
$msg = "โพสต์ <a target=\"_blank\" href=\"forum.php?mod=viewthread&tid=" . $post['tid'] . "\">" . addslashes($post['subject']) . "</a>";
if ($config['show_category']) {
$cat = DB::fetch_first("SELECT * FROM " . DB::table('forum_forum') . " WHERE `fid` = " . $post['fid']);
$msg .= " ใน <a target=\"_blank\" href=\"forum.php?mod=forumdisplay&fid=" . $post['fid'] . "\">" . addslashes($cat['name']) . "</a>";
}
DB::query("INSERT INTO " . DB::table('newz_data') . " (uid,touid,icon,text,time,ip) VALUES (" . $_G['uid'] . ",0,'bot','" . $msg . "'," . time() . ",'" . $_G['clientip'] . "')");
}
}
}
} else if ($config['edit_post'] > 0 && $args['param'][0] == 'post_edit_succeed') {
if ($config['edit_post'] == 2 || $_POST['th_chat_notify']) {
if ($post = DB::fetch_first("SELECT * FROM " . DB::table('forum_post') . " WHERE `fid` = " . $args['param'][2]['fid'] . " AND `tid` = " . $args['param'][2]['tid'] . " AND `pid` = " . $args['param'][2]['pid'])) {
DB::query("INSERT INTO " . DB::table('newz_data') . " (uid,touid,icon,text,time,ip) VALUES (" . $_G['uid'] . ",0,'bot','อัปเดตโพสต์ <a target=\"_blank\" href=\"forum.php?mod=viewthread&tid=" . $post['tid'] . "\">" . addslashes($post['subject']) . "</a>'," . time() . ",'" . $_G['clientip'] . "')");
$forums = unserialize($config['category_post']);
if (in_array($args['param'][2]['fid'], $forums)) {
if ($config['edit_post'] == 2 || $_POST['th_chat_notify']) {
if ($post = DB::fetch_first("SELECT * FROM " . DB::table('forum_post') . " WHERE `fid` = " . $args['param'][2]['fid'] . " AND `tid` = " . $args['param'][2]['tid'] . " AND `pid` = " . $args['param'][2]['pid'])) {
$msg = "อัปเดตโพสต์ <a target=\"_blank\" href=\"forum.php?mod=viewthread&tid=" . $post['tid'] . "\">" . addslashes($post['subject']) . "</a>";
if ($config['show_category']) {
$cat = DB::fetch_first("SELECT * FROM " . DB::table('forum_forum') . " WHERE `fid` = " . $post['fid']);
$msg .= " ใน <a target=\"_blank\" href=\"forum.php?mod=forumdisplay&fid=" . $post['fid'] . "\">" . addslashes($cat['name']) . "</a>";
}
DB::query("INSERT INTO " . DB::table('newz_data') . " (uid,touid,icon,text,time,ip) VALUES (" . $_G['uid'] . ",0,'bot','" . $msg . "'," . time() . ",'" . $_G['clientip'] . "')");
}
}
}
}
Expand Down

0 comments on commit 9bd002f

Please sign in to comment.