Browse Source

add a dropdown to choose post visibility

pull/111/head
Aaron Parecki 5 years ago
parent
commit
f0c5635c2f
No known key found for this signature in database GPG Key ID: 276C2817346D6056
  1. 1
      controllers/controllers.php
  2. 2
      controllers/micropub.php
  3. 5
      lib/helpers.php
  4. 2
      schema/migrations/0007.sql
  5. 1
      schema/mysql.sql
  6. 3
      schema/sqlite.sql
  7. 30
      views/new-post.php

1
controllers/controllers.php

@ -72,6 +72,7 @@ $app->get('/new', function() use($app) {
'micropub_access_token' => $user->micropub_access_token,
'response_date' => $user->last_micropub_response_date,
'syndication_targets' => json_decode($user->syndication_targets, true),
'supported_visibility' => json_decode($user->supported_visibility, true),
'location_enabled' => $user->location_enabled,
'user' => $user,
'authorizing' => false

2
controllers/micropub.php

@ -2,7 +2,7 @@
$app->get('/micropub/syndications', function() use($app) {
if($user=require_login($app)) {
$data = get_micropub_config($user, ['q'=>'syndicate-to']);
$data = get_micropub_config($user);
$app->response()['Content-type'] = 'application/json';
$app->response()->body(json_encode(array(
'targets' => $data['targets'],

5
lib/helpers.php

@ -298,6 +298,7 @@ function get_micropub_config(&$user, $query=[]) {
// Reset the values so they can be overwritten
$user->syndication_targets = '';
$user->supported_post_types = '';
$user->supported_visibility = '';
$user->micropub_media_endpoint = '';
if(count($targets))
@ -316,6 +317,10 @@ function get_micropub_config(&$user, $query=[]) {
}
}
if(isset($r['data']['visibility']) && is_array($r['data']['visibility'])) {
$user->supported_visibility = json_encode($r['data']['visibility']);
}
$user->save();
return [

2
schema/migrations/0007.sql

@ -0,0 +1,2 @@
ALTER TABLE users
ADD COLUMN `supported_visibility` LONGTEXT;

1
schema/mysql.sql

@ -25,5 +25,6 @@ CREATE TABLE `users` (
`email_username` varchar(255) DEFAULT NULL,
`default_timezone` varchar(255) DEFAULT NULL,
`supported_post_types` longtext,
`supported_visibility` longtext,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

3
schema/sqlite.sql

@ -24,5 +24,6 @@ CREATE TABLE users (
instagram_access_token TEXT,
email_username TEXT,
default_timezone TEXT,
supported_post_types TEXT
supported_post_types TEXT,
supported_visibility TEXT
);

30
views/new-post.php

@ -79,8 +79,23 @@
<?php endif ?>
<?php if($this->syndication_targets): ?>
<?php if($this->supported_visibility): ?>
<div class="form-group" style="margin-top: 1em;">
<label for="visibility">Visibility</label>
<select class="form-control" id="visibility">
<?php
foreach(['Public','Unlisted','Private'] as $v):
if(in_array(strtolower($v), $this->supported_visibility)):
echo '<option value="'.strtolower($v).'">'.$v.'</option>';
endif;
endforeach;
?>
</select>
</div>
<?php endif ?>
<?php if($this->syndication_targets): ?>
<div id="syndication-targets" class="form-group" style="margin-top: 1em;">
<label for="note_syndicate-to">Syndicate <a href="javascript:reload_syndications()">(refresh list)</a></label>
<div id="syndication-container">
<?php
@ -562,6 +577,14 @@ $(function(){
}
});
$("#visibility").on('change', function(e){
if($(this).val() == 'private') {
$("#syndication-targets").addClass('hidden');
} else {
$("#syndication-targets").removeClass('hidden');
}
});
$("#expand-reply").click(function(){
$('.reply-section').removeClass('hidden');
$(this).addClass('hidden');
@ -740,6 +763,11 @@ $(function(){
entry["rsvp"] = $("#note_rsvp").val();
}
if($("#visibility").val()) {
formData.append("visibility", $("#visibility").val());
entry["visibility"] = $("#visibility").val();
}
function appendPhotoToFormData(photo, prop) {
if(photo.external) {
if(photo.alt) {

Loading…
Cancel
Save