/** * Parses the user request. * @param Request $request the request component * @return array|boolean the route and the associated parameters. * False is returned if the current request cannot be successfully parsed. */ public function parseRequest($request) { $route = $request->getQueryParam('r', ''); if (is_array($route)) { $route = ''; } return [(string) $route, []]; }
public static function query($key, $default = null, $sanitize = true) { $result = Request::getQueryParam($key, $default); if ($sanitize) { $result = htmlspecialchars($result); $result = trim($result); } return $result; }
*/ /** * Includes the side wide settings. */ require_once 'vendor/autoload.php'; header("Access-Control-Allow-Origin: *"); // enable CORS for the whole REST API try { $config = new GlobalConfig(); $model = new Model($config); $controller = new RestController($model); $request = new Request($model); $path = $request->getServerConstant('PATH_INFO') ? $request->getServerConstant('PATH_INFO') : ''; // eg. "/search" $parts = explode('/', $path); $request->setUri($request->getQueryParam('uri')); $request->setLang($request->getQueryParam('lang')); if ($request->getQueryParam('vocab')) { $request->setVocab($request->getQueryParam('vocab')); } if (sizeof($parts) < 2 || $parts[1] == "") { header("HTTP/1.0 404 Not Found"); echo "404 Not Found"; } elseif ($parts[1] == 'vocabularies') { $controller->vocabularies($request); } elseif ($parts[1] == 'search') { $controller->search($request); } elseif ($parts[1] == 'types') { $controller->types($request); } elseif ($parts[1] == 'data') { $controller->data($request);
$model = new Model($config); $controller = new WebController($model); $request = new Request($model); // PATH_INFO, for example "/ysa/fi" $path = $request->getServerConstant('PATH_INFO') ? $request->getServerConstant('PATH_INFO') : ''; $parts = explode('/', $path); if (sizeof($parts) <= 2) { // if language code missing, redirect to guessed language // in any case, redirect to <lang>/ $lang = sizeof($parts) == 2 && $parts[1] !== '' ? $parts[1] : $controller->guessLanguage(); header("Location: " . $lang . "/"); } else { if (array_key_exists($parts[1], $config->getLanguages())) { // global pages $request->setLang($parts[1]); $content_lang = $request->getQueryParam('clang'); $request->setContentLang($content_lang); $parts[2] == 'about' || $parts[2] == 'feedback' || $parts[2] == 'search' ? $request->setPage($parts[2]) : $request->setPage(''); if ($request->getPage() == '') { $controller->invokeVocabularies($request); } elseif ($request->getPage() == 'about') { $controller->invokeAboutPage($request); } elseif ($request->getPage() == 'feedback') { $controller->invokeFeedbackForm($request); } elseif ($request->getPage() == 'search') { $controller->invokeGlobalSearch($request); } else { $controller->invokeGenericErrorPage($request); } } else { // vocabulary-specific pages
/** * Loads and renders the view containing a list of recent changes in the vocabulary. * @param Request $request */ public function invokeChangeList($request, $prop = 'dc:created') { // set language parameters for gettext $this->setLanguageProperties($request->getLang()); $vocab = $request->getVocab(); $offset = $request->getQueryParam('offset') && is_numeric($request->getQueryParam('offset')) && $request->getQueryParam('offset') >= 0 ? $request->getQueryParam('offset') : 0; $changeList = $vocab->getChangeList($prop, $request->getContentLang(), $request->getLang(), $offset); // load template $template = $this->twig->loadTemplate('changes.twig'); // render template echo $template->render(array('vocab' => $vocab, 'languages' => $this->languages, 'request' => $request, 'changeList' => $changeList)); }
/** * Download a concept as json-ld or redirect to download the whole vocabulary. * @param Request $request * @return object json-ld formatted concept. */ public function data($request) { $vocab = $request->getVocab(); $format = $request->getQueryParam('format'); if ($request->getUri()) { $uri = $request->getUri(); } else { if ($vocab !== null) { // whole vocabulary - redirect to download URL $urls = $vocab->getDataURLs(); if (sizeof($urls) == 0) { return $this->returnError('404', 'Not Found', "No download source URL known for vocabulary {$vocab}"); } $format = $this->negotiateFormat(array_keys($urls), $request->getServerConstant('HTTP_ACCEPT'), $format); if (!$format) { return $this->returnError(406, 'Not Acceptable', "Unsupported format. Supported MIME types are: " . implode(' ', array_keys($urls))); } header("Location: " . $urls[$format]); return; } else { return $this->returnError(400, 'Bad Request', "uri parameter missing"); } } $format = $this->negotiateFormat(explode(' ', self::$SUPPORTED_MIME_TYPES), $request->getServerConstant('HTTP_ACCEPT'), $format); if (!$format) { return $this->returnError(406, 'Not Acceptable', "Unsupported format. Supported MIME types are: " . self::$SUPPORTED_MIME_TYPES); } $vocid = $vocab ? $vocab->getId() : null; $results = $this->model->getRDF($vocid, $uri, $format); if ($format == 'application/ld+json' || $format == 'application/json') { // further compact JSON-LD document using a context $context = array('skos' => 'http://www.w3.org/2004/02/skos/core#', 'isothes' => 'http://purl.org/iso25964/skos-thes#', 'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#', 'owl' => 'http://www.w3.org/2002/07/owl#', 'dct' => 'http://purl.org/dc/terms/', 'dc11' => 'http://purl.org/dc/elements/1.1/', 'uri' => '@id', 'type' => '@type', 'lang' => '@language', 'value' => '@value', 'graph' => '@graph', 'label' => 'rdfs:label', 'prefLabel' => 'skos:prefLabel', 'altLabel' => 'skos:altLabel', 'hiddenLabel' => 'skos:hiddenLabel', 'broader' => 'skos:broader', 'narrower' => 'skos:narrower', 'related' => 'skos:related', 'inScheme' => 'skos:inScheme'); $compact_jsonld = \ML\JsonLD\JsonLD::compact($results, json_encode($context)); $results = \ML\JsonLD\JsonLD::toString($compact_jsonld); } header("Content-type: {$format}; charset=utf-8"); echo $results; }