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
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. 'response' => trim(htmlspecialchars($r['response']))
  20. ]));
  21. }
  22. });
  23. $app->post('/editor/upload', function() use($app) {
  24. // Fake a file uploader by echo'ing back the data URI
  25. $fn = $_FILES['files']['tmp_name'][0];
  26. $imageData = base64_encode(file_get_contents($fn));
  27. $src = 'data:'.mime_content_type($fn).';base64,'.$imageData;
  28. $app->response()['Content-type'] = 'application/json';
  29. $app->response()->body(json_encode([
  30. 'files' => [
  31. [
  32. 'url'=>$src
  33. ]
  34. ]
  35. ]));
  36. });
  37. $app->post('/editor/delete-file', function() use($app) {
  38. $app->response()['Content-type'] = 'application/json';
  39. $app->response()->body(json_encode(['result'=>'deleted']));
  40. });
  41. $app->get('/editor/oembed', function() use($app) {
  42. $url = 'http://medium.iframe.ly/api/oembed?iframe=1&url='.urlencode($app->request()->params()['url']);
  43. $json = file_get_contents($url);
  44. $app->response()['Content-type'] = 'application/json';
  45. $app->response()->body($json);
  46. });
  47. $app->post('/editor/test-login', function() use($app) {
  48. $logged_in = array_key_exists('user_id', $_SESSION);
  49. $app->response()['Content-type'] = 'application/json';
  50. $app->response()->body(json_encode(['logged_in'=>$logged_in]));
  51. });
  52. $app->get('/appcache.manifest', function() use($app) {
  53. $content = partial('partials/appcache');
  54. $app->response()['Content-type'] = 'text/cache-manifest';
  55. $app->response()->body($content);
  56. });