soselo/api/v1/http/mastodon/accounts/suspend/mod.php

40 lines
1.1 KiB
PHP

<?php
$_ = function() {
$id = trim($_GET['id']);
if (!valid_mastodon_account_id($id))
return apiresult(['error' => 'id parameter has incorrect format'], 400);
instance_config();
$explain = 'Your account has been suspended';
if (isset($_POST['explain']))
$explain = trim($_POST['explain']);
$is_remote_account = false;
$pg = new PgDatabase();
if ($pg->is_ok()) {
$result = $pg->fetch('SELECT domain FROM accounts WHERE id = '.$id);
$is_remote_account = isset($result['domain']) && $result['domain'] !== null;
}
$output = instance_http_post('/api/v1/admin/accounts/'.$id.'/action',
['type' => 'suspend', 'text' => $explain ]);
if ($is_remote_account)
instance_http_delete('/api/v1/admin/accounts/'.$id);
$suspended = [];
$susp_file = 'suspended_accounts,'.$GLOBALS['ap_software'].','.$GLOBALS['ap_instance'];
if (filedb_exists('cache', $susp_file))
$suspended = unserialize(filedb_get('cache', $susp_file));
$suspended []= $id;
$suspended = array_unique($suspended);
filedb_put('cache', $susp_file, serialize($suspended));
if (!isset($_SERVER['REQUEST_URI']))
sleep(3);
return apiresult($output);
};
$_();