verbose/post.php
2023-11-20 12:42:57 +01:00

60 righe
1,8 KiB
PHP

<?php
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
require 'lib/mastodon.php';
require 'lib/ckratelimit.php';
$resp=[
'ok'=>false,
'error'=>null,
'remaining'=>null,
'secstoreset'=>null,
'id'=>null
];
if (isset($_COOKIE['verbose_host']) && isset($_COOKIE['verbose_token']) && isset($_POST['visibility']) && in_array($_POST['visibility'],['public','unlisted','private','direct']) && isset($_POST['language']) && isset($_POST['status'])) {
$timeout=5;
$res=mastpost($_COOKIE['verbose_host'],$_COOKIE['verbose_token'],'/api/v1/statuses',$_POST,$timeout);
//$res=['ok'=>true, 'data'=>['id'=>999], 'error'=>'server exploded'];// test
if ($res['ok']) {
$resp['ok']=true;
$resp['id']=$res['data']['id'];
$rls=ckratelimit($res['headers'],'necho',true,false);
//$rls=['remaining'=>20,'secstoreset'=>5];// test
if (!is_null($rls)) {
$resp['remaining']=$rls['remaining'];
$resp['secstoreset']=$rls['secstoreset'];
}
} else {
$resp['error']=htmlentities($res['error']);
}
} else {
$resp['error']='malformed POST request';
}
header('Content-Type: application/json');
$resp=json_encode($resp);
echo $resp;
//echo '<pre>'.print_r($_POST,true).'</pre>';
function necho($msg) {
// do nothing :-)
}
?>