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.

68 lines
2.0 KiB

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