Browse Source

disable post type buttons if the server doesn't support them

pull/108/head
Aaron Parecki 6 years ago
parent
commit
b749bc6c12
No known key found for this signature in database GPG Key ID: 276C2817346D6056
  1. 3
      controllers/controllers.php
  2. 32
      lib/helpers.php
  3. 2
      schema/migrations/0006.sql
  4. 1
      schema/mysql.sql
  5. 5
      schema/sqlite.sql
  6. 34
      views/dashboard.php
  7. 16
      views/layout.php
  8. 4
      views/new-post.php
  9. 15
      views/settings.php

3
controllers/controllers.php

@ -47,7 +47,8 @@ $app->get('/dashboard', function() use($app) {
if($user=require_login($app)) {
render('dashboard', array(
'title' => 'Dashboard',
'authorizing' => false
'authorizing' => false,
'user' => $user,
));
}
});

32
lib/helpers.php

@ -288,12 +288,19 @@ function get_micropub_config(&$user, $query=[]) {
$user->syndication_targets = json_encode($targets);
$media_endpoint = false;
if($r['data'] && is_array($r['data']) && array_key_exists('media-endpoint', $r['data'])) {
$media_endpoint = $r['data']['media-endpoint'];
$user->micropub_media_endpoint = $media_endpoint;
$supported_post_types = false;
if($r['data'] && is_array($r['data'])) {
if(isset($r['data']['media-endpoint'])) {
$media_endpoint = $r['data']['media-endpoint'];
$user->micropub_media_endpoint = $media_endpoint;
}
if(isset($r['data']['post-types'])) {
$supported_post_types = json_encode($r['data']['post-types']);
$user->supported_post_types = $supported_post_types;
}
}
if(count($targets) || $media_endpoint) {
if(count($targets) || $media_endpoint || $supported_post_types) {
$user->save();
}
@ -303,6 +310,23 @@ function get_micropub_config(&$user, $query=[]) {
];
}
function supports_post_type(&$user, $type) {
if(!$user->supported_post_types)
return true;
$types = json_decode($user->supported_post_types, true);
if(!is_array($types))
return true; // syntax error in response, fail safely
foreach($types as $t) {
if(is_array($t) && isset($t['type']) && $t['type'] == $type) {
return true;
}
}
return false;
}
function get_micropub_source(&$user, $url, $properties) {
$r = micropub_get($user->micropub_endpoint, [
'q' => 'source',

2
schema/migrations/0006.sql

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

1
schema/mysql.sql

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

5
schema/sqlite.sql

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

34
views/dashboard.php

@ -3,14 +3,30 @@
<div style=" margin-top: 4em; margin-bottom: 4em;">
<ul class="post-type-icons">
<li><a href="/editor">📄</a></li>
<li><a href="/new">✏️</a></li>
<li><a href="/event">📅</a></li>
<li><a href="/bookmark">🔖</a></li>
<li><a href="/favorite">👍</a></li>
<li><a href="/repost"></a></li>
<li><a href="/itinerary">✈️</a></li>
<li><a href="/review">⭐️</a></li>
<?php if(supports_post_type($this->user, 'article')): ?>
<li><a href="/editor">📄</a></li>
<?php endif; ?>
<?php if(supports_post_type($this->user, 'note')): ?>
<li><a href="/new">✏️</a></li>
<?php endif; ?>
<?php if(supports_post_type($this->user, 'event')): ?>
<li><a href="/event">📅</a></li>
<?php endif; ?>
<?php if(supports_post_type($this->user, 'bookmark')): ?>
<li><a href="/bookmark">🔖</a></li>
<?php endif; ?>
<?php if(supports_post_type($this->user, 'like')): ?>
<li><a href="/favorite">👍</a></li>
<?php endif; ?>
<?php if(supports_post_type($this->user, 'repost')): ?>
<li><a href="/repost"></a></li>
<?php endif; ?>
<?php if(supports_post_type($this->user, 'itinerary')): ?>
<li><a href="/itinerary">✈️</a></li>
<?php endif; ?>
<?php if(supports_post_type($this->user, 'review')): ?>
<li><a href="/review">⭐️</a></li>
<?php endif; ?>
<li><a href="/email">✉️</a></li>
<li><a href="/settings"></a></li>
</ul>
@ -27,4 +43,4 @@
float: left;
margin-right: 12px;
}
</style>
</style>

16
views/layout.php

@ -77,10 +77,18 @@
<ul class="nav navbar-nav">
<?php if(session('me')) { ?>
<li><a href="/editor">📄 Editor</a></li>
<li><a href="/new">✏️ Note</a></li>
<li><a href="/bookmark">🔖 Bookmark</a></li>
<li><a href="/favorite">👍 Favorite</a></li>
<?php if(supports_post_type($this->user, 'article')): ?>
<li><a href="/editor">📄 Editor</a></li>
<?php endif; ?>
<?php if(supports_post_type($this->user, 'note')): ?>
<li><a href="/new">✏️ Note</a></li>
<?php endif; ?>
<?php if(supports_post_type($this->user, 'bookmark')): ?>
<li><a href="/bookmark">🔖 Bookmark</a></li>
<?php endif; ?>
<?php if(supports_post_type($this->user, 'like')): ?>
<li><a href="/favorite">👍 Favorite</a></li>
<?php endif; ?>
<?php } ?>
<li><a href="/docs">Docs</a></li>

4
views/new-post.php

@ -65,11 +65,15 @@
<input type="text" id="note_slug" value="" class="form-control">
</div>
<?php if(supports_post_type($this->user, 'photo')): ?>
<div class="form-group hidden" id="photo-previews">
</div>
<a href="javascript:addNewPhoto();" id="expand-photo-section"><i class="glyphicon glyphicon-camera" style="color: #aaa; font-size: 36px;"></i></a>
<?php endif ?>
<div 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">

15
views/settings.php

@ -20,6 +20,21 @@
<td>media endpoint</td>
<td><?= $this->user->micropub_media_endpoint ? '<code>'.$this->user->micropub_media_endpoint.'</code>' : '<a href="https://www.w3.org/TR/micropub/#media-endpoint">no media endpoint</a>' ?></td>
</tr>
<?php if($this->user->supported_post_types): ?>
<tr>
<td>supported post types</td>
<td>
<ul>
<?php
$types = json_decode($this->user->supported_post_types, true);
foreach($types as $type) {
echo '<li>'.htmlspecialchars($type['name']).' ('.$type['type'].')</li>';
}
?>
</ul>
</td>
</tr>
<?php endif ?>
<tr>
<td width="140">access token</td>
<td><code style="word-break: break-word; white-space: pre-wrap;"><?= $this->user->micropub_access_token ?></code></td>

Loading…
Cancel
Save