Browse Source

add channel selection to event interface

pull/125/head
Aaron Parecki 5 years ago
parent
commit
8dec126e7d
No known key found for this signature in database GPG Key ID: 276C2817346D6056
  1. 4
      controllers/controllers.php
  2. 11
      controllers/micropub.php
  3. 10
      lib/helpers.php
  4. 6
      schema/migrations/0011.sql
  5. 1
      schema/mysql.sql
  6. 1
      schema/sqlite.sql
  7. 21
      views/event.php
  8. 18
      views/partials/syndication-js.php
  9. 43
      views/settings.php

4
controllers/controllers.php

@ -182,8 +182,11 @@ $app->get('/event', function() use($app) {
if($user=require_login($app)) { if($user=require_login($app)) {
$params = $app->request()->params(); $params = $app->request()->params();
$channels = $user->channels ? json_decode($user->channels, true) : [];
render('event', array( render('event', array(
'title' => 'Event', 'title' => 'Event',
'channels' => $channels,
'authorizing' => false 'authorizing' => false
)); ));
} }
@ -362,6 +365,7 @@ $app->get('/settings', function() use($app) {
'title' => 'Settings', 'title' => 'Settings',
'user' => $user, 'user' => $user,
'syndication_targets' => json_decode($user->syndication_targets, true), 'syndication_targets' => json_decode($user->syndication_targets, true),
'channels' => json_decode($user->channels, true),
'authorizing' => false 'authorizing' => false
]); ]);
} }

11
controllers/micropub.php

@ -11,6 +11,17 @@ $app->get('/micropub/syndications', function() use($app) {
} }
}); });
$app->get('/micropub/channels', function() use($app) {
if($user=require_login($app)) {
$data = get_micropub_config($user, ['q'=>'config']);
$app->response()['Content-type'] = 'application/json';
$app->response()->body(json_encode(array(
'channels' => $data['channels'],
'response' => $data['response']
)));
}
});
$app->post('/micropub/post', function() use($app) { $app->post('/micropub/post', function() use($app) {
if($user=require_login($app)) { if($user=require_login($app)) {
$params = $app->request()->params(); $params = $app->request()->params();

10
lib/helpers.php

@ -269,6 +269,7 @@ function parse_headers($headers) {
function get_micropub_config(&$user, $query=[]) { function get_micropub_config(&$user, $query=[]) {
$targets = []; $targets = [];
$channels = [];
$r = micropub_get($user->micropub_endpoint, $query, $user->micropub_access_token); $r = micropub_get($user->micropub_endpoint, $query, $user->micropub_access_token);
if($r['data'] && is_array($r['data']) && array_key_exists('syndicate-to', $r['data'])) { if($r['data'] && is_array($r['data']) && array_key_exists('syndicate-to', $r['data'])) {
@ -295,8 +296,13 @@ function get_micropub_config(&$user, $query=[]) {
} }
} }
if($r['data'] && is_array($r['data']) && array_key_exists('channels', $r['data']) && is_array($r['data']['channels'])) {
$channels = $r['data']['channels'];
}
// Reset the values so they can be overwritten // Reset the values so they can be overwritten
$user->syndication_targets = ''; $user->syndication_targets = '';
$user->channels = '';
$user->supported_post_types = ''; $user->supported_post_types = '';
$user->supported_visibility = ''; $user->supported_visibility = '';
$user->micropub_media_endpoint = ''; $user->micropub_media_endpoint = '';
@ -304,6 +310,9 @@ function get_micropub_config(&$user, $query=[]) {
if(count($targets)) if(count($targets))
$user->syndication_targets = json_encode($targets); $user->syndication_targets = json_encode($targets);
if(count($channels))
$user->channels = json_encode($channels);
$media_endpoint = false; $media_endpoint = false;
$supported_post_types = false; $supported_post_types = false;
if($r['data'] && is_array($r['data'])) { if($r['data'] && is_array($r['data'])) {
@ -325,6 +334,7 @@ function get_micropub_config(&$user, $query=[]) {
return [ return [
'targets' => $targets, 'targets' => $targets,
'channels' => $channels,
'response' => $r 'response' => $r
]; ];
} }

6
schema/migrations/0011.sql

@ -0,0 +1,6 @@
ALTER TABLE users
DROP COLUMN flightaware_username,
DROP COLUMN flightaware_apikey;
ALTER TABLE users
ADD COLUMN `channels` TEXT AFTER syndication_targets;

1
schema/mysql.sql

@ -17,6 +17,7 @@ CREATE TABLE `users` (
`last_micropub_response_date` datetime DEFAULT NULL, `last_micropub_response_date` datetime DEFAULT NULL,
`location_enabled` tinyint(4) NOT NULL DEFAULT '0', `location_enabled` tinyint(4) NOT NULL DEFAULT '0',
`syndication_targets` text, `syndication_targets` text,
`channels` text,
`twitter_access_token` text, `twitter_access_token` text,
`twitter_token_secret` text, `twitter_token_secret` text,
`twitter_username` varchar(255) DEFAULT NULL, `twitter_username` varchar(255) DEFAULT NULL,

1
schema/sqlite.sql

@ -17,6 +17,7 @@ CREATE TABLE users (
last_micropub_response_date datetime, last_micropub_response_date datetime,
location_enabled INTEGER NOT NULL default 0, location_enabled INTEGER NOT NULL default 0,
syndication_targets TEXT, syndication_targets TEXT,
channels TEXT,
twitter_access_token TEXT, twitter_access_token TEXT,
twitter_token_secret TEXT, twitter_token_secret TEXT,
twitter_username TEXT, twitter_username TEXT,

21
views/event.php

@ -44,6 +44,24 @@
<input type="text" id="note_category" value="" class="form-control"> <input type="text" id="note_category" value="" class="form-control">
</div> </div>
<?php if($this->channels): ?>
<div class="form-group">
<label for="note_channel">Channel</label>
<div id="channel-container">
<?php
echo '<select class="form-control" id="note_channel">';
echo '<option value="none"></option>';
foreach($this->channels as $ch) {
echo '<option value="'.htmlspecialchars($ch).'" '.($ch == 'events' ? 'selected' : '').'>'
. htmlspecialchars($ch)
. '</option>';
}
echo '</select>';
?>
</div>
</div>
<?php endif; ?>
<div style="float: right; margin-top: 6px;"> <div style="float: right; margin-top: 6px;">
<button class="btn btn-success" id="btn_post">Post</button> <button class="btn btn-success" id="btn_post">Post</button>
</div> </div>
@ -229,6 +247,9 @@
properties.end = event_end; properties.end = event_end;
} }
if($("#note_channel").val()) {
properties['p3k-channel'] = $("#note_channel").val();
}
$.post("/micropub/postjson", { $.post("/micropub/postjson", {
data: JSON.stringify({ data: JSON.stringify({

18
views/partials/syndication-js.php

@ -26,3 +26,21 @@ function bind_syndication_buttons() {
return false; return false;
}); });
} }
function reload_channels() {
$.getJSON("/micropub/channels", function(data){
console.log(data);
if(data.channels) {
$("#channel-container").html('<select class="form-control" name="channel"></select>');
for(var i in data.channels) {
var channel = data.channels[i];
$("#channel-container select").append('<option value="'+htmlspecialchars(channel)+'">'+htmlspecialchars(channel)+'</option>');
}
} else {
}
console.log(data);
});
}

43
views/settings.php

@ -81,13 +81,37 @@
echo '</ul>'; echo '</ul>';
} else { } else {
?><div class="bs-callout bs-callout-warning">No syndication targets were found on your site. ?><div class="bs-callout bs-callout-warning">No syndication targets were found on your site.
Your server can provide a <a href="/docs#syndication">list of supported syndication targets</a> that will appear as checkboxes here.</div><?php
Your server can provide a <a href="/docs/syndication">list of supported syndication targets</a> that will appear as buttons here.</div><?php
} }
?> ?>
</div> </div>
</div> </div>
<h3>Channels</h3>
<div class="form-group">
<label for="note_channels"><a href="javascript:reload_channels()">Reload</a></label>
<div id="channel-container">
<?php
if($this->channels) {
echo '<select class="form-control" name="channel">';
foreach($this->channels as $ch) {
echo '<option value="'.htmlspecialchars($ch).'">'
. htmlspecialchars($ch)
. '</option>';
}
echo '</select>';
} else {
?><div class="bs-callout bs-callout-warning">No channels were found on your site.
Your server can provide a <a href="/docs/channels">list of channels</a> that will appear as buttons here.</div><?php
}
?>
</div>
</div>
<?php if(!Config::$twitterClientID): ?> <?php if(!Config::$twitterClientID): ?>
<h3>Twitter</h3> <h3>Twitter</h3>
<p>Connecting a Twitter account will automatically "favorite" and "retweet" tweets on Twitter when you favorite and retweet a Twitter URL in Quill.</p> <p>Connecting a Twitter account will automatically "favorite" and "retweet" tweets on Twitter when you favorite and retweet a Twitter URL in Quill.</p>
@ -185,21 +209,6 @@ $(function(){
}); });
function reload_syndications() {
$.getJSON("/micropub/syndications", function(data){
if(data.targets) {
$("#syndication-container").html('<ul></ul>');
for(var i in data.targets) {
var target = data.targets[i].target;
var uid = data.targets[i].uid;
var favicon = data.targets[i].favicon;
$("#syndication-container ul").append('<li><button data-syndicate-to="'+htmlspecialchars(uid ? uid : target)+'" class="btn btn-default btn-block">'+(favicon ? '<img src="'+htmlspecialchars(favicon)+'" width="16" height="16"> ':'')+htmlspecialchars(target)+'</button></li>');
}
bind_syndication_buttons();
} else {
<?= partial('partials/syndication-js') ?>
}
console.log(data);
});
}
</script> </script>
Loading…
Cancel
Save