loggedInUserId = $UserId; $this->serverContainer = $serverContainer; } /** * @NoAdminRequired * @NoCSRFRequired * @PublicPage */ public function singleUserTimeMap($userId, $url) { // XXX workaround, as nextcloud corrupts the $url parameter. $routePrefix = "u/$userId/"; $url = getUrlParameter("{$routePrefix}timemap"); $matchingMementos = $this->findSingleUserMementosForUrl($userId, $url); return $this->makeResponse($url, $matchingMementos, $routePrefix); } /** * @NoAdminRequired * @NoCSRFRequired * @PublicPage */ public function allUsersTimeMap($url) { $routePrefix = ""; $url = getUrlParameter("{$routePrefix}timemap"); $matchingMementos = $this->findAllUsersMementosForUrl($url); return $this->makeResponse($url, $matchingMementos, $routePrefix); } private function makeResponse($url, $matchingMementos, $routePrefix) { // Build the list of links. // $timeMapUrl = $this->URLGenerator->linkToRouteAbsolute('timeMap#timeMap', [ 'url' => $url ]); // $timeGateUrl = $this->URLGenerator->linkToRouteAbsolute('timeGate#timeGate', [ 'url' => $url ]); // FIXME ...is linkToRouteAbsolute broken? Hardcoding the path then.. $URLGenerator = $this->serverContainer->getURLGenerator(); $timeMapUrl = $URLGenerator->getAbsoluteUrl("/apps/memento/{$routePrefix}timemap/$url"); $timeGateUrl = $URLGenerator->getAbsoluteUrl("/apps/memento/{$routePrefix}timegate/$url"); if (count($matchingMementos) > 0) { $firstDatetime = datetimeTimestampToString($matchingMementos[0]['datetime']); $lastMemento = $matchingMementos[count($matchingMementos)-1]; $lastDatetime = datetimeTimestampToString($lastMemento['datetime']); } $links = [ "<$url>;rel=\"original\"", "<$timeGateUrl>;rel=\"timegate\"", "<$timeMapUrl>;rel=\"self\";type=\"application/link-format\"" . ($firstDatetime && $lastDatetime ? ";from=\"$firstDatetime\";until=\"$lastDatetime\"" : "") ]; foreach ($matchingMementos as $index => $memento) { $datetime = datetimeTimestampToString($memento['datetime']); $maybeFirst = $index === 0 ? 'first ' : ''; $maybeLast = $index === count($matchingMementos)-1 ? 'last ' : ''; // Make absolute, as the spec says URLs are to be interpreted relative to the *original* url! $absoluteMementoUrl = $URLGenerator->getAbsoluteURL($memento['mementoUrl']); $links[] = "<$absoluteMementoUrl>" . ";rel=\"{$maybeFirst}{$maybeLast}memento\"" . ";datetime=\"$datetime\""; } $linksString = implode(",\n", $links); $headers = [ "Content-Type" => "application/link-format" ]; $response = new DataDisplayResponse($linksString, 200, $headers); return $response; } }