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.

75 lines
2.1 KiB

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