From acafb9192a6402a3f3d60d5e6af11cb4576fc96c Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Wed, 4 Jan 2017 15:26:51 -0800 Subject: [PATCH] add tags, slug and status field to quill editor --- controllers/controllers.php | 54 +++++++++++++++++++---------------- controllers/editor.php | 11 +++++++ controllers/static.php | 19 ++++++------ public/editor-files/editor.js | 29 +++++++++++++------ public/editor-files/style.css | 50 ++++++++++++++++---------------- schema/migrations/0002.sql | 5 ++++ schema/mysql.sql | 1 + schema/sqlite.sql | 2 ++ views/editor.php | 29 ++++++++++++++----- views/layout.php | 2 +- views/new-post.php | 2 +- views/settings.php | 37 +++++++++++++++++++++++- 12 files changed, 162 insertions(+), 79 deletions(-) create mode 100644 schema/migrations/0002.sql diff --git a/controllers/controllers.php b/controllers/controllers.php index 8ffaedb..1c3db83 100644 --- a/controllers/controllers.php +++ b/controllers/controllers.php @@ -44,11 +44,10 @@ function generate_login_token() { $app->get('/dashboard', function() use($app) { if($user=require_login($app)) { - $html = render('dashboard', array( + render('dashboard', array( 'title' => 'Dashboard', 'authorizing' => false )); - $app->response()->body($html); } }); @@ -73,7 +72,7 @@ $app->get('/new', function() use($app) { } } - $html = render('new-post', array( + render('new-post', array( 'title' => 'New Post', 'in_reply_to' => $in_reply_to, 'micropub_endpoint' => $user->micropub_endpoint, @@ -87,7 +86,6 @@ $app->get('/new', function() use($app) { 'user' => $user, 'authorizing' => false )); - $app->response()->body($html); } }); @@ -109,7 +107,7 @@ $app->get('/bookmark', function() use($app) { if(array_key_exists('content', $params)) $content = $params['content']; - $html = render('new-bookmark', array( + render('new-bookmark', array( 'title' => 'New Bookmark', 'bookmark_url' => $url, 'bookmark_name' => $name, @@ -119,7 +117,6 @@ $app->get('/bookmark', function() use($app) { 'syndication_targets' => json_decode($user->syndication_targets, true), 'authorizing' => false )); - $app->response()->body($html); } }); @@ -132,13 +129,12 @@ $app->get('/favorite', function() use($app) { if(array_key_exists('url', $params)) $url = $params['url']; - $html = render('new-favorite', array( + render('new-favorite', array( 'title' => 'New Favorite', 'url' => $url, 'token' => generate_login_token(), 'authorizing' => false )); - $app->response()->body($html); } }); @@ -146,11 +142,10 @@ $app->get('/event', function() use($app) { if($user=require_login($app)) { $params = $app->request()->params(); - $html = render('event', array( + render('event', array( 'title' => 'Event', 'authorizing' => false )); - $app->response()->body($html); } }); @@ -158,11 +153,10 @@ $app->get('/itinerary', function() use($app) { if($user=require_login($app)) { $params = $app->request()->params(); - $html = render('new-itinerary', array( + render('new-itinerary', array( 'title' => 'Itinerary', 'authorizing' => false )); - $app->response()->body($html); } }); @@ -170,12 +164,11 @@ $app->get('/photo', function() use($app) { if($user=require_login($app)) { $params = $app->request()->params(); - $html = render('photo', array( + render('photo', array( 'title' => 'New Photo', 'note_content' => '', 'authorizing' => false )); - $app->response()->body($html); } }); @@ -183,11 +176,10 @@ $app->get('/review', function() use($app) { if($user=require_login($app)) { $params = $app->request()->params(); - $html = render('review', array( + render('review', array( 'title' => 'Review', 'authorizing' => false )); - $app->response()->body($html); } }); @@ -200,13 +192,12 @@ $app->get('/repost', function() use($app) { if(array_key_exists('url', $params)) $url = $params['url']; - $html = render('new-repost', array( + render('new-repost', array( 'title' => 'New Repost', 'url' => $url, 'token' => generate_login_token(), 'authorizing' => false )); - $app->response()->body($html); } }); @@ -258,8 +249,7 @@ $app->get('/add-to-home', function() use($app) { $app->redirect('/add-to-home?token='.$token, 301); } else { unset($_SESSION['add-to-home-started']); - $html = render('add-to-home', array('title' => 'Quill')); - $app->response()->body($html); + render('add-to-home', array('title' => 'Quill')); } } } @@ -285,24 +275,40 @@ $app->get('/email', function() use($app) { $user->save(); } - $html = render('email', array( + render('email', array( 'title' => 'Post-by-Email', 'micropub_endpoint' => $user->micropub_endpoint, 'test_response' => $test_response, 'user' => $user )); - $app->response()->body($html); } }); $app->get('/settings', function() use($app) { if($user=require_login($app)) { - $html = render('settings', [ + render('settings', [ 'title' => 'Settings', 'user' => $user, 'authorizing' => false ]); - $app->response()->body($html); + } +}); + +$app->post('/settings/save', function() use($app) { + if($user=require_login($app)) { + $params = $app->request()->params(); + + if(array_key_exists('html_content', $params)) + $user->micropub_optin_html_content = $params['html_content'] ? 1 : 0; + + if(array_key_exists('slug_field', $params) && $params['slug_field']) + $user->micropub_slug_field = $params['slug_field']; + + $user->save(); + $app->response()['Content-type'] = 'application/json'; + $app->response()->body(json_encode(array( + 'result' => 'ok' + ))); } }); diff --git a/controllers/editor.php b/controllers/editor.php index 3818328..0f4380b 100644 --- a/controllers/editor.php +++ b/controllers/editor.php @@ -25,6 +25,17 @@ $app->post('/editor/publish', function() use($app) { 'content' => $content ); + if(array_key_exists('category', $params) && $params['category']) + $micropub_request['category'] = $params['category']; + + if(array_key_exists('slug', $params) && $params['slug']) + $micropub_request[$user->micropub_slug_field] = $params['slug']; + + if(array_key_exists('status', $params) && $params['status']) { + if($params['status'] == 'draft') + $micropub_request['post-status'] = $params['status']; + } + $r = micropub_post_for_user($user, $micropub_request); $app->response()['Content-type'] = 'application/json'; diff --git a/controllers/static.php b/controllers/static.php index bf9740d..c53fa14 100644 --- a/controllers/static.php +++ b/controllers/static.php @@ -7,14 +7,11 @@ $app->get('/', function($format='html') use($app) { $app->redirect('/auth/start?'.http_build_query($params), 302); } - ob_start(); render('index', array( 'title' => 'Quill', 'meta' => '', 'authorizing' => false )); - $html = ob_get_clean(); - $res->body($html); }); $app->get('/creating-a-token-endpoint', function() use($app) { @@ -22,16 +19,18 @@ $app->get('/creating-a-token-endpoint', function() use($app) { }); $app->get('/creating-a-micropub-endpoint', function() use($app) { - $html = render('creating-a-micropub-endpoint', array('title' => 'Creating a Micropub Endpoint', 'authorizing' => false)); - $app->response()->body($html); + render('creating-a-micropub-endpoint', array('title' => 'Creating a Micropub Endpoint', 'authorizing' => false)); }); $app->get('/docs', function() use($app) { - $html = render('docs', array('title' => 'Documentation', 'authorizing' => false)); - $app->response()->body($html); + render('docs', array('title' => 'Documentation', 'authorizing' => false)); +}); + +$app->get('/docs/post-status', function() use($app) { + render('docs/post-status', array('title' => 'Post Status Documentation', 'authorizing' => false)); }); $app->get('/privacy', function() use($app) { - $html = render('privacy', array('title' => 'Quill Privacy Policy', 'authorizing' => false)); - $app->response()->body($html); -}); \ No newline at end of file + render('privacy', array('title' => 'Quill Privacy Policy', 'authorizing' => false)); +}); + diff --git a/public/editor-files/editor.js b/public/editor-files/editor.js index 46b838d..63bb911 100644 --- a/public/editor-files/editor.js +++ b/public/editor-files/editor.js @@ -47,6 +47,7 @@ $(function() { $('#publish-success').addClass('hidden'); $('#publish-error').addClass('hidden'); $('#publish-help').removeClass('hidden'); + $('#publish-fields').removeClass('hidden'); } else { $('.publish-dropdown').addClass('hidden'); } @@ -69,10 +70,14 @@ $(function() { $('#publish-confirm').click(function(){ $('#publish-help').addClass('hidden'); $('#publish-in-progress').removeClass('hidden'); + $('#publish-fields').addClass('hidden'); $.post('/editor/publish', { name: $("#post-name").val(), - body: editor.serialize().content.value + body: editor.serialize().content.value, + category: csv_to_array($("#post-tags").val()), + slug: $("#post-slug").val(), + status: $("#post-status").val() }, function(response) { if(response.location) { reset_page().then(function(){ @@ -87,6 +92,7 @@ $(function() { $('#publish-error-debug').html(response.response).removeClass('hidden'); $('#publish-error').removeClass('hidden'); $('#publish-success').addClass('hidden'); + $('#publish-fields').removeClass('hidden'); } }); }); @@ -99,6 +105,10 @@ $(function() { }); }); + $("#post-status").change(function(){ + $("#published-status-warning").removeClass("hidden"); + }); + $.getJSON('/settings/html-content', function(data){ if(data.html == '0') { $('.micropub-html-warning').show(); @@ -108,22 +118,23 @@ $(function() { function reset_page() { $("#post-name").val(''); + $("#post-slug").val(''); + $("#post-tags").val(''); + $("#post-status").val('published'); $("#content").html(''); $("#draft-status").text("New"); $("#publish-confirm").hide(); return localforage.setItem('currentdraft', {}); } -function onUpdateReady() { - // Show the notice that says there is a new version of the app - $("#new_version_available").show(); +function csv_to_array(val) { + if(val.length > 0) { + return val.split(/[, ]+/); + } else { + return []; + } } -window.applicationCache.addEventListener('updateready', onUpdateReady); -if(window.applicationCache.status === window.applicationCache.UPDATEREADY) { - onUpdateReady(); -} - /* ************************************************ */ /* autosave loop */ var autosaveTimeout = false; diff --git a/public/editor-files/style.css b/public/editor-files/style.css index 9bb8042..e4099ee 100644 --- a/public/editor-files/style.css +++ b/public/editor-files/style.css @@ -22,6 +22,10 @@ h1, h2, h3, h4, h5, h6, th, td, caption { font-weight:normal; } img { border: 0; } + +/* ************************************** */ + + .micropub-html-warning { max-width: 600px; margin-left: auto; @@ -49,6 +53,8 @@ img { border: 0; } float: right; } + + /* ************************************** */ /* Toolbar */ @@ -120,15 +126,23 @@ img { border: 0; } input.form-field-small { height: 24px; - margin-top: 1px; + margin-top: 2px; font-size: 13px; color: #51a1a8; padding: 0 10px; - -webkit-border-radius: 10px; - -moz-border-radius: 10px; - border-radius: 10px; + -webkit-border-radius: 6px; + -moz-border-radius: 6px; + border-radius: 6px; border: 1px #93dee5 solid; } +select.form-select-small { + border-radius: 6px; + border: 1px #93dee5 solid; + height: 24px; + margin-top: 2px; + font-size: 13px; + color: #51a1a8; +} .publish-dropdown { position: fixed; @@ -165,6 +179,10 @@ input.form-field-small { .publish-dropdown .dropdown-content { padding: 9px; } +.publish-dropdown .dropdown-content, +.publish-dropdown .dropdown-content a { + color: #51a1a8; +} .publish-dropdown input { font-family: sans-serif; } @@ -182,30 +200,10 @@ pre#publish-error-debug { display: none; } -/* ************************************** */ -/* App Cache */ - -#new_version_available { - display: none; - position: fixed; - z-index: 1000; - bottom: 0; - left: 0; - right: 0; - background: rgba(246,206,217,0.3); -} -#new_version_available .inner { - padding: 10px; - width: 600px; - margin: 0 auto; - text-align: center; - font-weight: bold; - color: #cf224f; - font-size: 14px; - font-family: sans-serif; +.small { + font-size: 0.8em; } - /* ************************************** */ /* Editor CSS */ diff --git a/schema/migrations/0002.sql b/schema/migrations/0002.sql new file mode 100644 index 0000000..60d591a --- /dev/null +++ b/schema/migrations/0002.sql @@ -0,0 +1,5 @@ +ALTER TABLE users +ADD COLUMN `micropub_slug_field` VARCHAR(255) NOT NULL DEFAULT 'mp-slug' AFTER `micropub_response`; + +UPDATE users +SET micropub_slug_field = 'slug'; diff --git a/schema/mysql.sql b/schema/mysql.sql index 8eccb3a..610b01b 100644 --- a/schema/mysql.sql +++ b/schema/mysql.sql @@ -8,6 +8,7 @@ CREATE TABLE `users` ( `micropub_access_token` text, `micropub_scope` varchar(255) DEFAULT NULL, `micropub_response` text, + `micropub_slug_field` varchar(255) NOT NULL DEFAULT 'mp-slug', `micropub_success` tinyint(4) DEFAULT '0', `date_created` datetime DEFAULT NULL, `last_login` datetime DEFAULT NULL, diff --git a/schema/sqlite.sql b/schema/sqlite.sql index 9f05c1e..3dc6e91 100644 --- a/schema/sqlite.sql +++ b/schema/sqlite.sql @@ -4,9 +4,11 @@ CREATE TABLE users ( authorization_endpoint TEXT, token_endpoint TEXT, micropub_endpoint TEXT, + micropub_media_endpoint TEXT, micropub_access_token TEXT, micropub_scope TEXT, micropub_response TEXT, + micropub_slug_field TEXT default 'mp-slug', micropub_success INTEGER default 0, date_created datetime, last_login datetime, diff --git a/views/editor.php b/views/editor.php index 78b1858..f1d2250 100644 --- a/views/editor.php +++ b/views/editor.php @@ -67,14 +67,29 @@ diff --git a/views/new-post.php b/views/new-post.php index 3418272..6ce8095 100644 --- a/views/new-post.php +++ b/views/new-post.php @@ -419,7 +419,7 @@ $(function(){ } } if(v=$("#note_slug").val()) { - formData.append("slug", v); + formData.append("user->micropub_slug_field ?>", v); } // Add either the photo as a file, or the photo URL depending on whether the user has a media endpoint diff --git a/views/settings.php b/views/settings.php index 5acc7dd..2662eb0 100644 --- a/views/settings.php +++ b/views/settings.php @@ -18,7 +18,7 @@ media endpoint - user->media_endpoint ? ''.$this->user->media_endpoint.'' : 'no media endpoint' ?> + user->micropub_media_endpoint ? ''.$this->user->micropub_media_endpoint.'' : 'no media endpoint' ?> access token @@ -31,6 +31,28 @@

Connecting a Twitter account will automatically "favorite" and "retweet" tweets on Twitter when you favorite and retweet a Twitter URL in Quill.

+ +

Backwards Compatibility

+ +

You can customize some of the properties that are sent in the Micropub request to work with your specific endpoint.

+ + + + + + + + + + + + +
Slug +
+
+
Choose the name of the field that the slug will be sent in. This should be set to mp-slug unless your endpoint is using a custom property or the deprecated slug property.
Send HTML Contentuser->micropub_optin_html_content ? 'checked="checked"' : '' ?>>When checked, content from Quill's HTML editor will be sent in a property called content[html] rather than just content. See the Micropub specification for more details.
+ +