Browse Source

Add link from timegate to timemap

tags/v0.1.0
Gerben 6 years ago
parent
commit
3505635ece
1 changed files with 19 additions and 2 deletions
  1. +19
    -2
      lib/Controller/TimeGateController.php

+ 19
- 2
lib/Controller/TimeGateController.php View File

@@ -5,6 +5,7 @@ require_once __DIR__ . '/findMementos.php';
require_once __DIR__ . '/datetimeConversion.php'; require_once __DIR__ . '/datetimeConversion.php';


use OCP\IRequest; use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\IServerContainer; use OCP\IServerContainer;
use OCP\AppFramework\Controller; use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\RedirectResponse; use OCP\AppFramework\Http\RedirectResponse;
@@ -14,15 +15,18 @@ use findMementos;


class TimeGateController extends Controller { class TimeGateController extends Controller {
private $userFolder; private $userFolder;
private $URLGenerator;


public function __construct( public function __construct(
$AppName, $AppName,
IRequest $request, IRequest $request,
$UserId, $UserId,
IServerContainer $serverContainer
IServerContainer $serverContainer,
IURLGenerator $URLGenerator
) { ) {
parent::__construct($AppName, $request); parent::__construct($AppName, $request);
$this->userFolder = $serverContainer->getUserFolder($UserId); $this->userFolder = $serverContainer->getUserFolder($UserId);
$this->URLGenerator = $URLGenerator;
} }


/** /**
@@ -65,7 +69,20 @@ class TimeGateController extends Controller {
$response = new RedirectResponse($chosenMemento['mementoUrl']); $response = new RedirectResponse($chosenMemento['mementoUrl']);
$response->setStatus(302); $response->setStatus(302);
$response->addHeader('Vary', 'accept-datetime'); $response->addHeader('Vary', 'accept-datetime');
$response->addHeader('Link', "<{$chosenMemento['originalUrl']}>; rel=\"original\"");

// Add a link to the original and to the timemap.
$originalLink = "<{$chosenMemento['originalUrl']}>;rel=\"original\"";
// XXX hardcoding the route URL.
$timeMapUrl = $this->URLGenerator->getAbsoluteUrl("/apps/memento/timemap/$url");
$firstDatetime = datetimeTimestampToString($matchingMementos[0]['datetime']);
$lastMemento = $matchingMementos[count($matchingMementos)-1];
$lastDatetime = datetimeTimestampToString($lastMemento['datetime']);
$timeMapLink = "<$timeMapUrl>"
. ";rel=\"timemap\""
. ";type=\"application/link-format\""
. ";from=\"$firstDatetime\";until=\"$lastDatetime\"";
$response->addHeader('Link', "$originalLink, $timeMapLink");

return $response; return $response;
} }
} }


Loading…
Cancel
Save