Browse Source

Matrix report integration (#74)

Enables posting reports to a matrix room.
Co-authored-by: nonmakina <[email protected]>
Co-committed-by: nonmakina <[email protected]>
lazyLoading
nonmakina 6 months ago
parent
commit
6f2e953bd5
  1. 8
      inc/config.php
  2. 18
      post.php

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

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

Loading…
Cancel
Save