diff --git a/inc/config.php b/inc/config.php index c5fa69d9..1b80cd22 100644 --- a/inc/config.php +++ b/inc/config.php @@ -1824,6 +1824,14 @@ * ==================== */ + // Matrix integration for reports + // $config['matrix'] = array( + // 'access_token' => 'ACCESS_TOKEN', + // 'room_id' => '%21askjdlkajsdlka:matrix.org', + // 'host' => 'https://matrix.org', + // 'max_message_length' => 240 + // ); + //Securimage captcha //Note from lainchan PR: "TODO move a bunch of things here" diff --git a/post.php b/post.php index 599e9353..7996cedb 100644 --- a/post.php +++ b/post.php @@ -390,6 +390,24 @@ function handle_report(){ } + if(isset($config['matrix'])){ + $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']) > $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", + "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); + curl_close($ch); + } } $is_mod = isset($_POST['mod']) && $_POST['mod'];