Matrix report integration (#74)

Enables posting reports to a matrix room.
Co-authored-by: nonmakina <nonmakina@leftypol.org>
Co-committed-by: nonmakina <nonmakina@leftypol.org>
This commit is contained in:
nonmakina 2022-04-03 22:06:42 +00:00
parent 2b5365b572
commit 3725d27e72
2 changed files with 26 additions and 0 deletions

View File

@ -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"

View File

@ -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'];