From 0e8ee9973a550a3ab0a2069d9a12b683651b7d9b Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Tue, 17 Jan 2017 09:24:41 -0800 Subject: use `mp-syndicate-to` by default, add setting * adds setting to choose the property to use for the syndication targets * all existing users default to the old value `syndicate-to` * new users default to `mp-syndicate-to` closes #66 --- controllers/controllers.php | 4 ++++ schema/migrations/0004.sql | 5 +++++ schema/mysql.sql | 1 + schema/sqlite.sql | 1 + views/docs/note.php | 2 +- views/new-bookmark.php | 12 ++++++------ views/new-post.php | 4 ++-- views/settings.php | 18 ++++++++++++++++-- 8 files changed, 36 insertions(+), 11 deletions(-) create mode 100644 schema/migrations/0004.sql diff --git a/controllers/controllers.php b/controllers/controllers.php index 505589f..3f95147 100644 --- a/controllers/controllers.php +++ b/controllers/controllers.php @@ -115,6 +115,7 @@ $app->get('/bookmark', function() use($app) { 'bookmark_tags' => $tags, 'token' => generate_login_token(), 'syndication_targets' => json_decode($user->syndication_targets, true), + 'user' => $user, 'authorizing' => false )); } @@ -323,6 +324,9 @@ $app->post('/settings/save', function() use($app) { if(array_key_exists('slug_field', $params) && $params['slug_field']) $user->micropub_slug_field = $params['slug_field']; + if(array_key_exists('syndicate_field', $params) && $params['syndicate_field']) + $user->micropub_syndicate_field = $params['syndicate_field']; + $user->save(); $app->response()['Content-type'] = 'application/json'; $app->response()->body(json_encode(array( diff --git a/schema/migrations/0004.sql b/schema/migrations/0004.sql new file mode 100644 index 0000000..8b74018 --- /dev/null +++ b/schema/migrations/0004.sql @@ -0,0 +1,5 @@ +ALTER TABLE users +ADD COLUMN `micropub_syndicate_field` VARCHAR(255) NOT NULL DEFAULT 'mp-syndicate-to' AFTER `micropub_slug_field`; + +UPDATE users +SET micropub_syndicate_field = 'syndicate-to'; diff --git a/schema/mysql.sql b/schema/mysql.sql index 31f10fd..9796b5d 100644 --- a/schema/mysql.sql +++ b/schema/mysql.sql @@ -9,6 +9,7 @@ CREATE TABLE `users` ( `micropub_scope` varchar(255) DEFAULT NULL, `micropub_response` text, `micropub_slug_field` varchar(255) NOT NULL DEFAULT 'mp-slug', + `micropub_syndicate_field` varchar(255) NOT NULL DEFAULT 'mp-syndicate-to', `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 1dced77..00e5f1c 100644 --- a/schema/sqlite.sql +++ b/schema/sqlite.sql @@ -9,6 +9,7 @@ CREATE TABLE users ( micropub_scope TEXT, micropub_response TEXT, micropub_slug_field TEXT default 'mp-slug', + micropub_syndicate_field TEXT default 'mp-syndicate-to', micropub_success INTEGER default 0, date_created datetime, last_login datetime, diff --git a/views/docs/note.php b/views/docs/note.php index 654c478..737e811 100644 --- a/views/docs/note.php +++ b/views/docs/note.php @@ -30,7 +30,7 @@
  • location - If you check the "location" box, then this property will be a Geo URI with the location the browser detected. You will see a preview of the value in the note interface along with a map.
  • photo or photo[] - If your server supports a Media Endpoint, this will be set to the URL that your endpoint returned when it uploaded the photo. Otherwise, this will be one of the parts in the multipart request with the image file itself.
  • mp-slug - If you enter a slug, this will be sent in the request. You can customize the name of this property in settings.
  • -
  • syndicate-to[] - (Note: this is deprecated and will be replaced with "mp-syndicate-to[]" soon) Each syndication destination selected will be sent in this property. The values will be the uid that your endpoint returns. See Syndication for more details.
  • +
  • mp-syndicate-to[] - Each syndication destination selected will be sent in this property. The values will be the uid that your endpoint returns. See Syndication for more details. (If you are using an older Micropub endpoint that expects syndicate-to, you can customize this property in the settings.)

  • diff --git a/views/new-bookmark.php b/views/new-bookmark.php index 32e9043..068422f 100644 --- a/views/new-bookmark.php +++ b/views/new-bookmark.php @@ -13,27 +13,27 @@
    - +
    - +
    - +
    - +
    - +
    syndication_targets) { @@ -90,7 +90,7 @@ $(function(){ name: $("#note_name").val(), content: $("#note_content").val(), category: csv_to_array($("#note_category").val()), - 'syndicate-to': syndications + 'user->micropub_syndicate_field ?>': syndications }, function(response){ if(response.location != false) { diff --git a/views/new-post.php b/views/new-post.php index 7059c5e..57a2ffa 100644 --- a/views/new-post.php +++ b/views/new-post.php @@ -429,7 +429,7 @@ $(function(){ } if(syndications.length > 0) { for(var i in syndications) { - formData.append("syndicate-to[]", syndications[i]); + formData.append("user->micropub_syndicate_field ?>[]", syndications[i]); } } if(v=$("#note_slug").val()) { @@ -485,7 +485,7 @@ $(function(){ location: $("#note_location").val(), category: category, slug: $("#note_slug").val(), - 'syndicate-to': syndications + 'user->micropub_syndicate_field ?>': syndications }, function(data){ var response = JSON.parse(data); diff --git a/views/settings.php b/views/settings.php index 2662eb0..5895718 100644 --- a/views/settings.php +++ b/views/settings.php @@ -36,15 +36,23 @@

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

    - +
    - + + + + + @@ -91,5 +99,11 @@ $(function(){ }); }); + $("#save-syndicate-to-field").click(function(){ + $.post("/settings/save", { + syndicate_field: $("#syndicate-to-field-name").val() + }); + }); + }); -- cgit v1.2.3
    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.
    Syndication +
    +
    +
    Choose the name of the field that the syndication values will be sent in. This should be set to mp-syndicate-to unless your endpoint is using the deprecated syndicate-to property.
    Send HTML Content user->micropub_optin_html_content ? 'checked="checked"' : '' ?>>