Example #1
0
 * Copyright (c) 2012 Aalto University and University of Helsinki
 * MIT License
 * see LICENSE.txt for more information
 */
/**
 * 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') {
Example #2
0
 /**
  * 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;
 }