From 027ac4ed77957b17b397dbaecd14d90db8804adb Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 3 Apr 2022 22:31:05 +0200 Subject: [PATCH 1/8] try report function --- post.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/post.php b/post.php index 599e9353..e035143e 100644 --- a/post.php +++ b/post.php @@ -357,6 +357,9 @@ function handle_report(){ $query->bindValue(':reason', $reason, PDO::PARAM_STR); $query->execute() or error(db_error($query)); + $postcontent = mb_substr($thread['body_nomarkup'], 0, 120) . '... _*(POST TRIMMED)*_'; + $slackmessage = '<' .$config['domain'] . "/mod.php?/" . $board['dir'] . $config['dir']['res'] . ( $thread['thread'] ? $thread['thread'] : $id ) . ".html" . ($thread['thread'] ? '#' . $id : '') . '> \n ' . $reason . '\n ' . $postcontent . '\n'; + if ($config['slack']) { @@ -382,14 +385,17 @@ function handle_report(){ return $result; } - $postcontent = mb_substr($thread['body_nomarkup'], 0, 120) . '... _*(POST TRIMMED)*_'; - $slackmessage = '<' .$config['domain'] . "/mod.php?/" . $board['dir'] . $config['dir']['res'] . ( $thread['thread'] ? $thread['thread'] : $id ) . ".html" . ($thread['thread'] ? '#' . $id : '') . '> \n ' . $reason . '\n ' . $postcontent . '\n'; - $slackresult = slack($slackmessage, $config['slack_channel']); } + if(isset($config['matrix'])){ + $ch = curl_init("$config['matrix']['host']/_matrix/client/r0/rooms/$config['matrix']['room_id']/send/m.room.message?access_token=$config['matrix']['access_token']"); + curl_setopt($ch, CURLOPT_POSTFIELDS, $slackmessage); + $result = curl_exec($ch); + curl_close($ch); + } } $is_mod = isset($_POST['mod']) && $_POST['mod']; -- 2.25.1 From 57ec54c3a7d077fa8436245321da8af3b6052af9 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 3 Apr 2022 23:37:00 +0200 Subject: [PATCH 2/8] report function fix --- inc/config.php | 7 +++++++ post.php | 13 ++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/inc/config.php b/inc/config.php index c5fa69d9..0b38662b 100644 --- a/inc/config.php +++ b/inc/config.php @@ -1824,6 +1824,13 @@ * ==================== */ + // Matrix integration for reports + // $config['matrix'] = array( + // 'access_token' => 'ACCESS_TOKEN', + // 'room_id' => '%21askjdlkajsdlka:matrix.org', + // 'host' => 'https://matrix.org' + // ); + //Securimage captcha //Note from lainchan PR: "TODO move a bunch of things here" diff --git a/post.php b/post.php index e035143e..a1d50a55 100644 --- a/post.php +++ b/post.php @@ -391,9 +391,16 @@ function handle_report(){ if(isset($config['matrix'])){ - $ch = curl_init("$config['matrix']['host']/_matrix/client/r0/rooms/$config['matrix']['room_id']/send/m.room.message?access_token=$config['matrix']['access_token']"); - curl_setopt($ch, CURLOPT_POSTFIELDS, $slackmessage); - $result = curl_exec($ch); + $slackmessage = $config['domain'] . "/mod.php?/" . $board['dir'] . $config['dir']['res'] . ( $thread['thread'] ? $thread['thread'] : $id ) . ".html" . ($thread['thread'] ? '#' . $id : '') . ' \\n ' . $reason . '\\n ' . $postcontent . ' \\n '; + $url = $config['matrix']['host'] . "/_matrix/client/r0/rooms/" . $config['matrix']['room_id'] . "/send/m.room.message?access_token=" . $config['matrix']['access_token']; + $ch = curl_init($url); + $post_data = json_encode(array( + "msgtype" => "m.text", + "body" => $slackmessage + )); + curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + $postResult = curl_exec($ch); curl_close($ch); } } -- 2.25.1 From a9ce704576abfc1458b44bdbbe03981b67694750 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 3 Apr 2022 23:43:55 +0200 Subject: [PATCH 3/8] report --- post.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/post.php b/post.php index a1d50a55..437f45f0 100644 --- a/post.php +++ b/post.php @@ -391,12 +391,15 @@ function handle_report(){ if(isset($config['matrix'])){ - $slackmessage = $config['domain'] . "/mod.php?/" . $board['dir'] . $config['dir']['res'] . ( $thread['thread'] ? $thread['thread'] : $id ) . ".html" . ($thread['thread'] ? '#' . $id : '') . ' \\n ' . $reason . '\\n ' . $postcontent . ' \\n '; - $url = $config['matrix']['host'] . "/_matrix/client/r0/rooms/" . $config['matrix']['room_id'] . "/send/m.room.message?access_token=" . $config['matrix']['access_token']; - $ch = curl_init($url); + $trimmed_post = strlen($thread['body_nomarkup']) > 280 ? '[...]' : ''; + $postcontent = mb_substr($thread['body_nomarkup'], 0, 280) . $trimmed_post; + $reported_post_url = $config['domain'] . "/mod.php?/" . $board['dir'] . $config['dir']['res'] . ( $thread['thread'] ? $thread['thread'] : $id ) . ".html"; + $matrix_message = $reported_post_url . ($thread['thread'] ? '#' . $id : '') . ' \\n ' . $reason . '\\n ' . $postcontent . ' \\n '; + $post_url = $config['matrix']['host'] . "/_matrix/client/r0/rooms/" . $config['matrix']['room_id'] . "/send/m.room.message?access_token=" . $config['matrix']['access_token']; + $ch = curl_init($post_url); $post_data = json_encode(array( "msgtype" => "m.text", - "body" => $slackmessage + "body" => $matrix_message )); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); -- 2.25.1 From 42d1e42c50a3e38311f705753509682da0611a3c Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 3 Apr 2022 23:48:17 +0200 Subject: [PATCH 4/8] newline --- post.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/post.php b/post.php index 437f45f0..5221128f 100644 --- a/post.php +++ b/post.php @@ -394,7 +394,7 @@ function handle_report(){ $trimmed_post = strlen($thread['body_nomarkup']) > 280 ? '[...]' : ''; $postcontent = mb_substr($thread['body_nomarkup'], 0, 280) . $trimmed_post; $reported_post_url = $config['domain'] . "/mod.php?/" . $board['dir'] . $config['dir']['res'] . ( $thread['thread'] ? $thread['thread'] : $id ) . ".html"; - $matrix_message = $reported_post_url . ($thread['thread'] ? '#' . $id : '') . ' \\n ' . $reason . '\\n ' . $postcontent . ' \\n '; + $matrix_message = $reported_post_url . ($thread['thread'] ? '#' . $id : '') . " \n" . $reason . " \n" . $postcontent . " \n"; $post_url = $config['matrix']['host'] . "/_matrix/client/r0/rooms/" . $config['matrix']['room_id'] . "/send/m.room.message?access_token=" . $config['matrix']['access_token']; $ch = curl_init($post_url); $post_data = json_encode(array( -- 2.25.1 From 78adc6fee6b3c0d822dd2d4a6b217c2ca4553036 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 3 Apr 2022 23:52:37 +0200 Subject: [PATCH 5/8] improve --- post.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/post.php b/post.php index 5221128f..c17e6188 100644 --- a/post.php +++ b/post.php @@ -394,7 +394,7 @@ function handle_report(){ $trimmed_post = strlen($thread['body_nomarkup']) > 280 ? '[...]' : ''; $postcontent = mb_substr($thread['body_nomarkup'], 0, 280) . $trimmed_post; $reported_post_url = $config['domain'] . "/mod.php?/" . $board['dir'] . $config['dir']['res'] . ( $thread['thread'] ? $thread['thread'] : $id ) . ".html"; - $matrix_message = $reported_post_url . ($thread['thread'] ? '#' . $id : '') . " \n" . $reason . " \n" . $postcontent . " \n"; + $matrix_message = $reported_post_url . ($thread['thread'] ? '#' . $id : '') . " \nReason:\n" . $reason . " \nPost:\n" . $postcontent . " \n"; $post_url = $config['matrix']['host'] . "/_matrix/client/r0/rooms/" . $config['matrix']['room_id'] . "/send/m.room.message?access_token=" . $config['matrix']['access_token']; $ch = curl_init($post_url); $post_data = json_encode(array( -- 2.25.1 From 850d75dabb6101f79b474fda9cb762c2d16b97a8 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 3 Apr 2022 23:55:10 +0200 Subject: [PATCH 6/8] undo change --- post.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/post.php b/post.php index c17e6188..f326141e 100644 --- a/post.php +++ b/post.php @@ -357,9 +357,6 @@ function handle_report(){ $query->bindValue(':reason', $reason, PDO::PARAM_STR); $query->execute() or error(db_error($query)); - $postcontent = mb_substr($thread['body_nomarkup'], 0, 120) . '... _*(POST TRIMMED)*_'; - $slackmessage = '<' .$config['domain'] . "/mod.php?/" . $board['dir'] . $config['dir']['res'] . ( $thread['thread'] ? $thread['thread'] : $id ) . ".html" . ($thread['thread'] ? '#' . $id : '') . '> \n ' . $reason . '\n ' . $postcontent . '\n'; - if ($config['slack']) { @@ -385,6 +382,9 @@ function handle_report(){ return $result; } + $postcontent = mb_substr($thread['body_nomarkup'], 0, 120) . '... _*(POST TRIMMED)*_'; + $slackmessage = '<' .$config['domain'] . "/mod.php?/" . $board['dir'] . $config['dir']['res'] . ( $thread['thread'] ? $thread['thread'] : $id ) . ".html" . ($thread['thread'] ? '#' . $id : '') . '> \n ' . $reason . '\n ' . $postcontent . '\n'; + $slackresult = slack($slackmessage, $config['slack_channel']); } -- 2.25.1 From b0fee21b01708880373556f805a7c5910646761a Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 3 Apr 2022 23:59:21 +0200 Subject: [PATCH 7/8] cleaned up --- inc/config.php | 3 ++- post.php | 10 ++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/inc/config.php b/inc/config.php index 0b38662b..1b80cd22 100644 --- a/inc/config.php +++ b/inc/config.php @@ -1828,7 +1828,8 @@ // $config['matrix'] = array( // 'access_token' => 'ACCESS_TOKEN', // 'room_id' => '%21askjdlkajsdlka:matrix.org', - // 'host' => 'https://matrix.org' + // 'host' => 'https://matrix.org', + // 'max_message_length' => 240 // ); //Securimage captcha diff --git a/post.php b/post.php index f326141e..c9631d5f 100644 --- a/post.php +++ b/post.php @@ -391,16 +391,18 @@ function handle_report(){ if(isset($config['matrix'])){ - $trimmed_post = strlen($thread['body_nomarkup']) > 280 ? '[...]' : ''; - $postcontent = mb_substr($thread['body_nomarkup'], 0, 280) . $trimmed_post; $reported_post_url = $config['domain'] . "/mod.php?/" . $board['dir'] . $config['dir']['res'] . ( $thread['thread'] ? $thread['thread'] : $id ) . ".html"; - $matrix_message = $reported_post_url . ($thread['thread'] ? '#' . $id : '') . " \nReason:\n" . $reason . " \nPost:\n" . $postcontent . " \n"; $post_url = $config['matrix']['host'] . "/_matrix/client/r0/rooms/" . $config['matrix']['room_id'] . "/send/m.room.message?access_token=" . $config['matrix']['access_token']; - $ch = curl_init($post_url); + + $trimmed_post = strlen($thread['body_nomarkup']) > 480 ? ' [...]' : ''; + $postcontent = mb_substr($thread['body_nomarkup'], 0, 480) . $trimmed_post; + $matrix_message = $reported_post_url . ($thread['thread'] ? '#' . $id : '') . " \nReason:\n" . $reason . " \nPost:\n" . $postcontent . " \n"; $post_data = json_encode(array( "msgtype" => "m.text", "body" => $matrix_message )); + + $ch = curl_init($post_url); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $postResult = curl_exec($ch); -- 2.25.1 From aba5199f65ea5493d5efd28357b08cdc05304fcf Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 4 Apr 2022 00:05:48 +0200 Subject: [PATCH 8/8] cleaned up --- post.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/post.php b/post.php index c9631d5f..7996cedb 100644 --- a/post.php +++ b/post.php @@ -394,8 +394,8 @@ function handle_report(){ $reported_post_url = $config['domain'] . "/mod.php?/" . $board['dir'] . $config['dir']['res'] . ( $thread['thread'] ? $thread['thread'] : $id ) . ".html"; $post_url = $config['matrix']['host'] . "/_matrix/client/r0/rooms/" . $config['matrix']['room_id'] . "/send/m.room.message?access_token=" . $config['matrix']['access_token']; - $trimmed_post = strlen($thread['body_nomarkup']) > 480 ? ' [...]' : ''; - $postcontent = mb_substr($thread['body_nomarkup'], 0, 480) . $trimmed_post; + $trimmed_post = strlen($thread['body_nomarkup']) > $config['matrix']['max_message_length'] ? ' [...]' : ''; + $postcontent = mb_substr($thread['body_nomarkup'], 0, $config['matrix']['max_message_length']) . $trimmed_post; $matrix_message = $reported_post_url . ($thread['thread'] ? '#' . $id : '') . " \nReason:\n" . $reason . " \nPost:\n" . $postcontent . " \n"; $post_data = json_encode(array( "msgtype" => "m.text", -- 2.25.1