post.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /*
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. require 'lib/mastodon.php';
  15. require 'lib/ckratelimit.php';
  16. $resp=[
  17. 'ok'=>false,
  18. 'error'=>null,
  19. 'remaining'=>null,
  20. 'secstoreset'=>null,
  21. 'id'=>null
  22. ];
  23. 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'])) {
  24. $timeout=5;
  25. $res=mastpost($_COOKIE['verbose_host'],$_COOKIE['verbose_token'],'/api/v1/statuses',$_POST,$timeout);
  26. //$res=['ok'=>true, 'data'=>['id'=>999], 'error'=>'server exploded'];// test
  27. if ($res['ok']) {
  28. $resp['ok']=true;
  29. $resp['id']=$res['data']['id'];
  30. $rls=ckratelimit($res['headers'],'necho',true,false);
  31. //$rls=['remaining'=>20,'secstoreset'=>5];// test
  32. if (!is_null($rls)) {
  33. $resp['remaining']=$rls['remaining'];
  34. $resp['secstoreset']=$rls['secstoreset'];
  35. }
  36. } else {
  37. $resp['error']=htmlentities($res['error']);
  38. }
  39. } else {
  40. $resp['error']='malformed POST request';
  41. }
  42. header('Content-Type: application/json');
  43. $resp=json_encode($resp);
  44. echo $resp;
  45. //echo '<pre>'.print_r($_POST,true).'</pre>';
  46. function necho($msg) {
  47. // do nothing :-)
  48. }
  49. ?>