Mirror of Quill
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
1.9 KiB

  1. <?php
  2. $app->get('/editor', function() use($app) {
  3. if($user=require_login($app)) {
  4. $html = $app->render('editor.php');
  5. $app->response()->body($html);
  6. }
  7. });
  8. $app->post('/editor/publish', function() use($app) {
  9. if($user=require_login($app)) {
  10. $params = $app->request()->params();
  11. $content = $params['body'];
  12. if($user->micropub_optin_html_content) {
  13. $content = ['html' => $params['body']];
  14. }
  15. $micropub_request = array(
  16. 'h' => 'entry',
  17. 'name' => $params['name'],
  18. 'content' => $content
  19. );
  20. $r = micropub_post_for_user($user, $micropub_request);
  21. $app->response()['Content-type'] = 'application/json';
  22. $app->response()->body(json_encode([
  23. 'location' => $r['location'],
  24. 'response' => trim(htmlspecialchars($r['response']))
  25. ]));
  26. }
  27. });
  28. $app->post('/editor/upload', function() use($app) {
  29. // Fake a file uploader by echo'ing back the data URI
  30. $fn = $_FILES['files']['tmp_name'][0];
  31. $imageData = base64_encode(file_get_contents($fn));
  32. $src = 'data:'.mime_content_type($fn).';base64,'.$imageData;
  33. $app->response()['Content-type'] = 'application/json';
  34. $app->response()->body(json_encode([
  35. 'files' => [
  36. [
  37. 'url'=>$src
  38. ]
  39. ]
  40. ]));
  41. });
  42. $app->post('/editor/delete-file', function() use($app) {
  43. $app->response()['Content-type'] = 'application/json';
  44. $app->response()->body(json_encode(['result'=>'deleted']));
  45. });
  46. $app->get('/editor/oembed', function() use($app) {
  47. $url = 'http://medium.iframe.ly/api/oembed?iframe=1&url='.urlencode($app->request()->params()['url']);
  48. $json = file_get_contents($url);
  49. $app->response()['Content-type'] = 'application/json';
  50. $app->response()->body($json);
  51. });
  52. $app->post('/editor/test-login', function() use($app) {
  53. $logged_in = array_key_exists('user_id', $_SESSION);
  54. $app->response()['Content-type'] = 'application/json';
  55. $app->response()->body(json_encode(['logged_in'=>$logged_in]));
  56. });