2016-05-19 15:01:28 +01:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
|
|
use App\Services\IndieAuthService;
|
|
|
|
|
use IndieAuth\Client as IndieClient;
|
|
|
|
|
use GuzzleHttp\Client as GuzzleClient;
|
2017-03-18 20:09:11 +00:00
|
|
|
|
use Illuminate\Http\{Request, Response};
|
|
|
|
|
use GuzzleHttp\Exception\{ClientException, ServerException};
|
2016-05-19 15:01:28 +01:00
|
|
|
|
|
|
|
|
|
class MicropubClientController extends Controller
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* The IndieAuth service container.
|
|
|
|
|
*/
|
|
|
|
|
protected $indieAuthService;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Inject the dependencies.
|
|
|
|
|
*/
|
|
|
|
|
public function __construct(
|
|
|
|
|
IndieAuthService $indieAuthService = null,
|
|
|
|
|
IndieClient $indieClient = null,
|
|
|
|
|
GuzzleClient $guzzleClient = null
|
|
|
|
|
) {
|
|
|
|
|
$this->indieAuthService = $indieAuthService ?? new IndieAuthService();
|
|
|
|
|
$this->guzzleClient = $guzzleClient ?? new GuzzleClient();
|
|
|
|
|
$this->indieClient = $indieClient ?? new IndieClient();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Display the new notes form.
|
|
|
|
|
*
|
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
|
* @return \Illuminate\View\Factory view
|
|
|
|
|
*/
|
2017-02-15 20:19:11 +00:00
|
|
|
|
public function create(Request $request)
|
2016-05-19 15:01:28 +01:00
|
|
|
|
{
|
|
|
|
|
$url = $request->session()->get('me');
|
2016-06-29 23:53:48 +01:00
|
|
|
|
$syndication = $request->session()->get('syndication');
|
2017-03-15 12:23:42 +00:00
|
|
|
|
$mediaEndpoint = $request->session()->get('media-endpoint');
|
|
|
|
|
$mediaURLs = $request->session()->get('media-links');
|
2016-05-19 15:01:28 +01:00
|
|
|
|
|
2017-03-15 12:23:42 +00:00
|
|
|
|
return view('micropub.create', compact('url', 'syndication', 'mediaEndpoint', 'mediaURLs'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Process an upload to the media endpoint.
|
|
|
|
|
*
|
|
|
|
|
* @param Illuminate\Http\Request $request
|
|
|
|
|
* @return Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function processMedia(Request $request)
|
|
|
|
|
{
|
|
|
|
|
if ($request->hasFile('file') == false) {
|
|
|
|
|
return back();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$mediaEndpoint = $request->session()->get('media-endpoint');
|
|
|
|
|
if ($mediaEndpoint == null) {
|
|
|
|
|
return back();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$token = $request->session()->get('token');
|
|
|
|
|
|
|
|
|
|
$mediaURLs = [];
|
|
|
|
|
foreach ($request->file('file') as $file) {
|
|
|
|
|
try {
|
|
|
|
|
$response = $this->guzzleClient->request('POST', $mediaEndpoint, [
|
2017-03-18 20:09:11 +00:00
|
|
|
|
'headers' => [
|
|
|
|
|
'Authorization' => 'Bearer ' . $token,
|
|
|
|
|
],
|
|
|
|
|
'multipart' => [
|
2017-03-15 12:23:42 +00:00
|
|
|
|
[
|
2017-03-18 20:09:11 +00:00
|
|
|
|
'name' => 'file',
|
|
|
|
|
'contents' => fopen($file->path(), 'r'),
|
|
|
|
|
'filename' => $file->getClientOriginalName(),
|
2017-03-15 12:23:42 +00:00
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
]);
|
|
|
|
|
} catch (ClientException | ServerException $e) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-18 20:09:11 +00:00
|
|
|
|
$mediaURLs[] = $response->getHeader('Location')[0];
|
2017-03-15 12:23:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-19 15:19:12 +00:00
|
|
|
|
$storedMediaURLs = $request->session()->get('media-links') ?? [];
|
|
|
|
|
$mediaURLsToSave = array_merge($storedMediaURLs, $mediaURLs);
|
|
|
|
|
$request->session()->put('media-links', $mediaURLsToSave);
|
2017-03-15 12:23:42 +00:00
|
|
|
|
|
|
|
|
|
return redirect(route('micropub-client'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function clearLinks(Request $request)
|
|
|
|
|
{
|
|
|
|
|
$request->session()->forget('media-links');
|
|
|
|
|
|
|
|
|
|
return redirect(route('micropub-client'));
|
2016-05-19 15:01:28 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Post the notes content to the relavent micropub API endpoint.
|
|
|
|
|
*
|
|
|
|
|
* @todo make sure this works with multiple syndication targets
|
|
|
|
|
*
|
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
2017-02-15 20:19:11 +00:00
|
|
|
|
public function store(Request $request)
|
2016-05-19 15:01:28 +01:00
|
|
|
|
{
|
|
|
|
|
$domain = $request->session()->get('me');
|
|
|
|
|
$token = $request->session()->get('token');
|
|
|
|
|
|
|
|
|
|
$micropubEndpoint = $this->indieAuthService->discoverMicropubEndpoint(
|
|
|
|
|
$domain,
|
|
|
|
|
$this->indieClient
|
|
|
|
|
);
|
|
|
|
|
if (! $micropubEndpoint) {
|
2017-02-24 15:15:58 +00:00
|
|
|
|
return redirect(route('micropub-client'))->with('error', 'Unable to determine micropub API endpoint');
|
2016-05-19 15:01:28 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$response = $this->postNoteRequest($request, $micropubEndpoint, $token);
|
|
|
|
|
|
|
|
|
|
if ($response->getStatusCode() == 201) {
|
2017-03-18 20:09:11 +00:00
|
|
|
|
$request->session()->forget('media-links');
|
2016-05-19 15:01:28 +01:00
|
|
|
|
$location = $response->getHeader('Location');
|
|
|
|
|
if (is_array($location)) {
|
|
|
|
|
return redirect($location[0]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return redirect($location);
|
|
|
|
|
}
|
2017-02-23 08:59:56 +00:00
|
|
|
|
|
2017-02-24 15:15:58 +00:00
|
|
|
|
return redirect(route('micropub-client'))->with('error', 'Endpoint didn’t create the note.');
|
2016-05-19 15:01:28 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-13 16:18:15 +00:00
|
|
|
|
/**
|
|
|
|
|
* Show currently stored configuration values.
|
|
|
|
|
*
|
|
|
|
|
* @param Illuminate\Http\Request $request
|
|
|
|
|
* @return view
|
|
|
|
|
*/
|
|
|
|
|
public function config(Request $request)
|
|
|
|
|
{
|
|
|
|
|
$data['me'] = $request->session()->get('me');
|
|
|
|
|
$data['token'] = $request->session()->get('token');
|
|
|
|
|
$data['syndication'] = $request->session()->get('syndication') ?? 'none defined';
|
2017-03-15 12:23:42 +00:00
|
|
|
|
$data['media-endpoint'] = $request->session()->get('media-endpoint') ?? 'none defined';
|
|
|
|
|
|
2017-03-13 16:18:15 +00:00
|
|
|
|
return view('micropub.config', compact('data'));
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-15 12:23:42 +00:00
|
|
|
|
/**
|
|
|
|
|
* Query the micropub endpoint and store response in the session.
|
|
|
|
|
*
|
|
|
|
|
* @param Illuminate\Http\Request $request
|
|
|
|
|
* @return redirect
|
|
|
|
|
*/
|
|
|
|
|
public function queryEndpoint(Request $request)
|
|
|
|
|
{
|
|
|
|
|
$domain = $request->session()->get('me');
|
|
|
|
|
$token = $request->session()->get('token');
|
|
|
|
|
$micropubEndpoint = $this->indieAuthService->discoverMicropubEndpoint($domain);
|
|
|
|
|
if ($micropubEndpoint !== null) {
|
|
|
|
|
try {
|
|
|
|
|
$response = $this->guzzleClient->get($micropubEndpoint, [
|
|
|
|
|
'headers' => ['Authorization' => 'Bearer ' . $token],
|
|
|
|
|
'query' => 'q=config',
|
|
|
|
|
]);
|
|
|
|
|
} catch (ClientException | ServerException $e) {
|
|
|
|
|
return back();
|
|
|
|
|
}
|
|
|
|
|
$body = (string) $response->getBody();
|
|
|
|
|
|
|
|
|
|
$syndication = $this->parseSyndicationTargets($body);
|
|
|
|
|
$request->session()->put('syndication', $syndication);
|
|
|
|
|
|
|
|
|
|
$mediaEndpoint = $this->parseMediaEndpoint($body);
|
|
|
|
|
$request->session()->put('media-endpoint', $mediaEndpoint);
|
|
|
|
|
|
|
|
|
|
return back();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-19 15:01:28 +01:00
|
|
|
|
/**
|
|
|
|
|
* This method performs the actual POST request.
|
|
|
|
|
*
|
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
|
* @param string The Micropub endpoint to post to
|
|
|
|
|
* @param string The token to authenticate the request with
|
|
|
|
|
* @return \GuzzleHttp\Response $response | \Illuminate\RedirectFactory redirect
|
|
|
|
|
*/
|
|
|
|
|
private function postNoteRequest(
|
|
|
|
|
Request $request,
|
|
|
|
|
$micropubEndpoint,
|
|
|
|
|
$token
|
|
|
|
|
) {
|
|
|
|
|
$multipart = [
|
|
|
|
|
[
|
|
|
|
|
'name' => 'h',
|
|
|
|
|
'contents' => 'entry',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'name' => 'content',
|
|
|
|
|
'contents' => $request->input('content'),
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
if ($request->hasFile('photo')) {
|
|
|
|
|
$photos = $request->file('photo');
|
|
|
|
|
foreach ($photos as $photo) {
|
|
|
|
|
$multipart[] = [
|
|
|
|
|
'name' => 'photo[]',
|
2016-10-10 16:44:41 +01:00
|
|
|
|
'contents' => fopen($photo->path(), 'r'),
|
|
|
|
|
'filename' => $photo->getClientOriginalName(),
|
2016-05-19 15:01:28 +01:00
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ($request->input('in-reply-to') != '') {
|
|
|
|
|
$multipart[] = [
|
|
|
|
|
'name' => 'in-reply-to',
|
2016-11-07 19:13:22 +00:00
|
|
|
|
'contents' => $request->input('in-reply-to'),
|
2016-05-19 15:01:28 +01:00
|
|
|
|
];
|
|
|
|
|
}
|
2017-01-27 20:41:17 +00:00
|
|
|
|
if ($request->input('mp-syndicate-to')) {
|
|
|
|
|
foreach ($request->input('mp-syndicate-to') as $syn) {
|
2016-05-19 15:01:28 +01:00
|
|
|
|
$multipart[] = [
|
2017-01-27 20:41:17 +00:00
|
|
|
|
'name' => 'mp-syndicate-to[]',
|
2016-05-19 15:01:28 +01:00
|
|
|
|
'contents' => $syn,
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-05 16:10:00 +01:00
|
|
|
|
if ($request->input('location')) {
|
|
|
|
|
if ($request->input('location') !== 'no-location') {
|
2016-05-19 15:01:28 +01:00
|
|
|
|
$multipart[] = [
|
2016-10-05 16:10:00 +01:00
|
|
|
|
'name' => 'location',
|
2016-10-05 16:13:00 +01:00
|
|
|
|
'contents' => $request->input('location'),
|
2016-05-19 15:01:28 +01:00
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-03-18 20:09:11 +00:00
|
|
|
|
if ($request->input('media')) {
|
|
|
|
|
foreach ($request->input('media') as $media) {
|
|
|
|
|
$multipart[] = [
|
|
|
|
|
'name' => 'photo[]',
|
|
|
|
|
'contents' => $media,
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-05-19 15:01:28 +01:00
|
|
|
|
$headers = [
|
|
|
|
|
'Authorization' => 'Bearer ' . $token,
|
|
|
|
|
];
|
|
|
|
|
try {
|
|
|
|
|
$response = $this->guzzleClient->post($micropubEndpoint, [
|
|
|
|
|
'multipart' => $multipart,
|
|
|
|
|
'headers' => $headers,
|
|
|
|
|
]);
|
|
|
|
|
} catch (\GuzzleHttp\Exception\BadResponseException $e) {
|
2017-03-02 16:01:48 +00:00
|
|
|
|
return redirect(route('micropub-client'))->with(
|
|
|
|
|
'error',
|
|
|
|
|
'There was a bad response from the micropub endpoint.'
|
|
|
|
|
);
|
2016-05-19 15:01:28 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a new place.
|
|
|
|
|
*
|
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
2017-02-16 15:35:25 +00:00
|
|
|
|
public function newPlace(Request $request)
|
2016-05-19 15:01:28 +01:00
|
|
|
|
{
|
2016-09-23 12:26:43 +01:00
|
|
|
|
if ($request->session()->has('token') === false) {
|
|
|
|
|
return response()->json([
|
|
|
|
|
'error' => true,
|
|
|
|
|
'error_description' => 'No known token',
|
|
|
|
|
], 400);
|
|
|
|
|
}
|
2016-05-19 15:01:28 +01:00
|
|
|
|
$domain = $request->session()->get('me');
|
|
|
|
|
$token = $request->session()->get('token');
|
|
|
|
|
|
|
|
|
|
$micropubEndpoint = $this->indieAuthService->discoverMicropubEndpoint($domain, $this->indieClient);
|
|
|
|
|
if (! $micropubEndpoint) {
|
2016-09-23 12:26:43 +01:00
|
|
|
|
return response()->json([
|
2016-05-19 15:01:28 +01:00
|
|
|
|
'error' => true,
|
2016-09-23 12:26:43 +01:00
|
|
|
|
'error_description' => 'Could not determine the micropub endpoint.',
|
|
|
|
|
], 400);
|
2016-05-19 15:01:28 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$place = $this->postPlaceRequest($request, $micropubEndpoint, $token);
|
|
|
|
|
if ($place === false) {
|
2016-09-23 12:26:43 +01:00
|
|
|
|
return response()->json([
|
2016-05-19 15:01:28 +01:00
|
|
|
|
'error' => true,
|
2016-09-23 12:26:43 +01:00
|
|
|
|
'error_description' => 'Unable to create the new place',
|
|
|
|
|
], 400);
|
2016-05-19 15:01:28 +01:00
|
|
|
|
}
|
|
|
|
|
|
2016-09-23 12:26:43 +01:00
|
|
|
|
return response()->json([
|
2016-10-07 12:17:12 +01:00
|
|
|
|
'uri' => $place,
|
2016-05-19 15:01:28 +01:00
|
|
|
|
'name' => $request->input('place-name'),
|
|
|
|
|
'latitude' => $request->input('place-latitude'),
|
|
|
|
|
'longitude' => $request->input('place-longitude'),
|
2016-09-23 12:26:43 +01:00
|
|
|
|
]);
|
2016-05-19 15:01:28 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Actually make a micropub request to make a new place.
|
|
|
|
|
*
|
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
|
* @param string The Micropub endpoint to post to
|
|
|
|
|
* @param string The token to authenticate the request with
|
|
|
|
|
* @param \GuzzleHttp\Client $client
|
|
|
|
|
* @return \GuzzleHttp\Response $response | \Illuminate\RedirectFactory redirect
|
|
|
|
|
*/
|
|
|
|
|
private function postPlaceRequest(
|
|
|
|
|
Request $request,
|
|
|
|
|
$micropubEndpoint,
|
|
|
|
|
$token
|
|
|
|
|
) {
|
|
|
|
|
$formParams = [
|
|
|
|
|
'h' => 'card',
|
|
|
|
|
'name' => $request->input('place-name'),
|
|
|
|
|
'description' => $request->input('place-description'),
|
|
|
|
|
'geo' => 'geo:' . $request->input('place-latitude') . ',' . $request->input('place-longitude'),
|
|
|
|
|
];
|
|
|
|
|
$headers = [
|
|
|
|
|
'Authorization' => 'Bearer ' . $token,
|
|
|
|
|
];
|
|
|
|
|
try {
|
|
|
|
|
$response = $this->guzzleClient->request('POST', $micropubEndpoint, [
|
|
|
|
|
'form_params' => $formParams,
|
|
|
|
|
'headers' => $headers,
|
|
|
|
|
]);
|
|
|
|
|
} catch (ClientException $e) {
|
2016-09-22 16:00:04 +01:00
|
|
|
|
return false;
|
2016-05-19 15:01:28 +01:00
|
|
|
|
}
|
|
|
|
|
if ($response->getStatusCode() == 201) {
|
|
|
|
|
return $response->getHeader('Location')[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Make a request to the micropub endpoint requesting any nearby places.
|
|
|
|
|
*
|
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
2017-02-16 15:35:25 +00:00
|
|
|
|
public function nearbyPlaces(Request $request)
|
|
|
|
|
{
|
2016-09-23 12:26:43 +01:00
|
|
|
|
if ($request->session()->has('token') === false) {
|
|
|
|
|
return response()->json([
|
|
|
|
|
'error' => true,
|
|
|
|
|
'error_description' => 'No known token',
|
|
|
|
|
], 400);
|
|
|
|
|
}
|
2016-05-19 15:01:28 +01:00
|
|
|
|
$domain = $request->session()->get('me');
|
|
|
|
|
$token = $request->session()->get('token');
|
2016-09-23 12:26:43 +01:00
|
|
|
|
|
2016-05-19 15:01:28 +01:00
|
|
|
|
$micropubEndpoint = $this->indieAuthService->discoverMicropubEndpoint($domain, $this->indieClient);
|
|
|
|
|
|
|
|
|
|
if (! $micropubEndpoint) {
|
2016-09-23 12:26:43 +01:00
|
|
|
|
return response()->json([
|
|
|
|
|
'error' => true,
|
|
|
|
|
'error_description' => 'No known endpoint',
|
|
|
|
|
], 400);
|
2016-05-19 15:01:28 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
2017-02-16 15:35:25 +00:00
|
|
|
|
$query = 'geo:' . $request->input('latitude') . ',' . $request->input('longitude');
|
2016-10-03 14:46:53 +01:00
|
|
|
|
if ($request->input('u') !== null) {
|
2016-10-03 16:28:09 +01:00
|
|
|
|
$query .= ';u=' . $request->input('u');
|
2016-09-29 11:28:31 +01:00
|
|
|
|
}
|
2016-05-19 15:01:28 +01:00
|
|
|
|
$response = $this->guzzleClient->get($micropubEndpoint, [
|
|
|
|
|
'headers' => ['Authorization' => 'Bearer ' . $token],
|
2016-09-29 11:28:31 +01:00
|
|
|
|
'query' => ['q' => $query],
|
2016-05-19 15:01:28 +01:00
|
|
|
|
]);
|
|
|
|
|
} catch (\GuzzleHttp\Exception\BadResponseException $e) {
|
2016-09-23 12:26:43 +01:00
|
|
|
|
return response()->json([
|
|
|
|
|
'error' => true,
|
2016-11-22 16:08:02 +00:00
|
|
|
|
'error_description' => 'The endpoint ' . $micropubEndpoint . ' returned a non-good response',
|
2016-09-23 12:26:43 +01:00
|
|
|
|
], 400);
|
2016-05-19 15:01:28 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-16 15:35:25 +00:00
|
|
|
|
return response($response->getBody(), 200)
|
2016-05-19 15:01:28 +01:00
|
|
|
|
->header('Content-Type', 'application/json');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Parse the syndication targets retreived from a cookie, to a form that can
|
|
|
|
|
* be used in a view.
|
|
|
|
|
*
|
|
|
|
|
* @param string $syndicationTargets
|
|
|
|
|
* @return array|null
|
|
|
|
|
*/
|
|
|
|
|
private function parseSyndicationTargets($syndicationTargets = null)
|
|
|
|
|
{
|
|
|
|
|
if ($syndicationTargets === null) {
|
2017-02-24 14:38:52 +00:00
|
|
|
|
return;
|
2016-05-19 15:01:28 +01:00
|
|
|
|
}
|
2016-06-23 23:13:38 +01:00
|
|
|
|
$syndicateTo = [];
|
2016-06-29 23:53:48 +01:00
|
|
|
|
$data = json_decode($syndicationTargets, true);
|
2016-07-13 16:39:08 +01:00
|
|
|
|
if (array_key_exists('syndicate-to', $data)) {
|
|
|
|
|
foreach ($data['syndicate-to'] as $syn) {
|
2016-07-13 17:32:10 +01:00
|
|
|
|
$syndicateTo[] = [
|
|
|
|
|
'target' => $syn['uid'],
|
|
|
|
|
'name' => $syn['name'],
|
|
|
|
|
];
|
2016-07-13 16:39:08 +01:00
|
|
|
|
}
|
2016-05-19 15:01:28 +01:00
|
|
|
|
}
|
2016-06-23 23:13:38 +01:00
|
|
|
|
if (count($syndicateTo) > 0) {
|
|
|
|
|
return $syndicateTo;
|
2016-05-19 15:01:28 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-03-15 12:23:42 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Parse the media-endpoint retrieved from querying a micropub endpoint.
|
|
|
|
|
*
|
|
|
|
|
* @param string|null
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
private function parseMediaEndpoint($queryResponse = null)
|
|
|
|
|
{
|
|
|
|
|
if ($queryResponse === null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$data = json_decode($queryResponse, true);
|
|
|
|
|
if (array_key_exists('media-endpoint', $data)) {
|
|
|
|
|
return $data['media-endpoint'];
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-05-19 15:01:28 +01:00
|
|
|
|
}
|