summaryrefslogtreecommitdiff
path: root/controllers
diff options
context:
space:
mode:
authorAaron Parecki <aaron@parecki.com>2014-07-06 18:28:18 -0700
committerAaron Parecki <aaron@parecki.com>2014-07-06 18:28:18 -0700
commit592eac5d8dc4c704bfb34915c0703fc2aecc6d46 (patch)
treea9875ed88b33674da0571c0ad8007c01eda07f23 /controllers
parentb2337158a38b7dfda6d5c4e3c5f0dd4ae9f4845d (diff)
Adds support for querying your micropub endpoint to check for syndication targets.
This changes the value of "in-reply-to" to use hyphens instead of underscore separators!! Also shows you the full request made to your micropub endpoint.
Diffstat (limited to 'controllers')
-rw-r--r--controllers/auth.php4
-rw-r--r--controllers/controllers.php18
2 files changed, 22 insertions, 0 deletions
diff --git a/controllers/auth.php b/controllers/auth.php
index abbe3b9..13081c4 100644
--- a/controllers/auth.php
+++ b/controllers/auth.php
@@ -235,6 +235,10 @@ $app->get('/auth/callback', function() use($app) {
$user->micropub_response = $token['response'];
$user->save();
$_SESSION['user_id'] = $user->id();
+
+ // Make a request to the micropub endpoint to discover the syndication targets if any.
+ // Errors are silently ignored here. The user will be able to retry from the new post interface and get feedback.
+ get_syndication_targets($user);
}
unset($_SESSION['auth_state']);
diff --git a/controllers/controllers.php b/controllers/controllers.php
index 5b28bb8..dc18584 100644
--- a/controllers/controllers.php
+++ b/controllers/controllers.php
@@ -32,6 +32,7 @@ $app->get('/new', function() use($app) {
'micropub_scope' => $user->micropub_scope,
'micropub_access_token' => $user->micropub_access_token,
'response_date' => $user->last_micropub_response_date,
+ 'syndication_targets' => json_decode($user->syndication_targets, true),
'test_response' => $test_response,
'location_enabled' => $user->location_enabled
));
@@ -104,12 +105,28 @@ $app->get('/add-to-home', function() use($app) {
}
});
+$app->get('/micropub/syndications', function() use($app) {
+ if($user=require_login($app)) {
+ $data = get_syndication_targets($user);
+ $app->response()->body(json_encode(array(
+ 'targets' => $data['targets'],
+ 'response' => $data['response']
+ )));
+ }
+});
+
$app->post('/micropub/post', function() use($app) {
if($user=require_login($app)) {
$params = $app->request()->params();
+ // Remove any blank params
+ $params = array_filter($params, function($v){
+ return $v !== '';
+ });
+
// Now send to the micropub endpoint
$r = micropub_post($user->micropub_endpoint, $params, $user->micropub_access_token);
+ $request = $r['request'];
$response = $r['response'];
$user->last_micropub_response = json_encode($r);
@@ -126,6 +143,7 @@ $app->post('/micropub/post', function() use($app) {
$user->save();
$app->response()->body(json_encode(array(
+ 'request' => htmlspecialchars($request),
'response' => htmlspecialchars($response),
'location' => $location,
'error' => $r['error'],