diff options
author | Aaron Parecki <aaron@parecki.com> | 2015-05-10 14:05:06 +0200 |
---|---|---|
committer | Aaron Parecki <aaron@parecki.com> | 2015-05-10 14:05:06 +0200 |
commit | 4898ed74a57b6d14cbcd962e967111adffd4595d (patch) | |
tree | 5eec23250a6eff45d6b694b880120f84a3ebb073 /controllers/editor.php | |
parent | fb6d4181e429833f083ddd7e1770ed99a70949db (diff) |
set up medium-style editor with image embedding and appcache
Diffstat (limited to 'controllers/editor.php')
-rw-r--r-- | controllers/editor.php | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/controllers/editor.php b/controllers/editor.php new file mode 100644 index 0000000..995438b --- /dev/null +++ b/controllers/editor.php @@ -0,0 +1,41 @@ +<?php + +$app->get('/editor', function() use($app) { + // Don't require login because appcache caches the whole page + $html = $app->render('editor.php'); + $app->response()->body($html); +}); + +$app->post('/editor/upload', function() use($app) { + // Fake a file uploader by echo'ing back the data URI + $fn = $_FILES['files']['tmp_name'][0]; + $imageData = base64_encode(file_get_contents($fn)); + $src = 'data: '.mime_content_type($fn).';base64,'.$imageData; + + $app->response()['Content-type'] = 'application/json'; + $app->response()->body(json_encode([ + 'files' => [ + [ + 'url'=>$src + ] + ] + ])); +}); +$app->post('/editor/delete-file', function() use($app) { + $app->response()['Content-type'] = 'application/json'; + $app->response()->body(json_encode(['result'=>'deleted'])); +}); + +$app->get('/editor/oembed', function() use($app) { + $url = 'http://medium.iframe.ly/api/oembed?iframe=1&url='.urlencode($app->request()->params()['url']); + $json = file_get_contents($url); + $app->response()['Content-type'] = 'application/json'; + $app->response()->body($json); +}); + +$app->get('/appcache.manifest', function() use($app) { + $content = partial('partials/appcache'); + + $app->response()['Content-type'] = 'text/cache-manifest'; + $app->response()->body($content); +}); |