Exemplo n.º 1
0
 public function execute($pair)
 {
     global $conf;
     global $localUri;
     global $uri;
     global $acceptContentType;
     global $endpoints;
     global $lodspk;
     global $results;
     global $firstResults;
     list($res, $page, $format) = $pair;
     //If resource is not the page, send a 303 to the document
     if ($res == $localUri) {
         HTTPStatus::send303($page, $acceptContentType);
     }
     $uri = $res;
     if ($conf['mirror_external_uris'] != false) {
         $localUri = preg_replace("|^" . $conf['ns']['local'] . "|", $conf['basedir'], $res);
     }
     $extension = Utils::getExtension($format);
     /*Redefine Content type based on the
      * dcterms:format for this page
      */
     $acceptContentType = $format;
     //Check if files for model and view exist
     $t = Queries::getClass($uri, $endpoints['local']);
     $obj = $this->getModelandView($t, $extension);
     $modelFile = $obj['modelFile'];
     $lodspk['model'] = $conf['model']['directory'];
     $viewFile = $obj['viewFile'];
     $lodspk['view'] = $obj['view']['directory'];
     if ($viewFile == null) {
         $lodspk['transform_select_query'] = true;
     }
     $lodspk['type'] = $modelFile;
     $lodspk['home'] = $conf['basedir'];
     $lodspk['baseUrl'] = $conf['basedir'];
     $lodspk['module'] = 'type';
     $lodspk['root'] = $conf['root'];
     $lodspk['contentType'] = $acceptContentType;
     $lodspk['ns'] = $conf['ns'];
     $lodspk['endpoint'] = $conf['endpoint'];
     $lodspk['view'] = $conf['view']['directory'];
     $lodspk['add_mirrored_uris'] = true;
     $lodspk['this']['value'] = $uri;
     $lodspk['this']['curie'] = Utils::uri2curie($uri);
     $lodspk['local']['value'] = $localUri;
     $lodspk['local']['curie'] = Utils::uri2curie($localUri);
     $lodspk['this']['extension'] = $extension;
     //chdir($conf['home'].$conf['model']['directory']);
     Utils::queryFile($modelFile, $endpoints['local'], $results, $firstResults);
     if (!$lodspk['resultRdf']) {
         $results = Utils::internalize($results);
         $firstAux = Utils::getfirstResults($results);
         //chdir($conf['home']);
         if (is_array($results)) {
             $resultsObj = Convert::array_to_object($results);
             $results = $resultsObj;
         } else {
             $resultsObj = $results;
         }
         $lodspk['firstResults'] = Convert::array_to_object($firstAux);
     } else {
         $resultsObj = $results;
     }
     //chdir($conf['home'].$conf['model']['directory']);
     Utils::processDocument($viewFile, $lodspk, $resultsObj);
 }
Exemplo n.º 2
0
 public static function showView($lodspkData, $data, $view)
 {
     global $conf;
     global $uri;
     global $lodspk;
     global $extension;
     //$lodspk = $conf['view']['standard'];
     $lodspk = $lodspkData;
     if (isset($lodspkData['params'])) {
         $lodspk['this']['params'] = $lodspkData['params'];
     }
     if (isset($lodspk['queryTimes'])) {
         $lodspk['queryTimes'] = Convert::array_to_object($lodspk['queryTimes']);
     }
     require_once $conf['home'] . 'lib/Haanga/lib/Haanga.php';
     $viewAux = explode("/", $view);
     $viewFile = array_pop($viewAux);
     //$viewFile = $view;
     $viewPath = join("/", $viewAux);
     Haanga::configure(array('template_dir' => $viewPath, 'cache_dir' => $conf['home'] . 'cache/'));
     $rdf = null;
     if (array_key_exists('rdf', $data)) {
         $rdf = $data['rdf'];
         unset($data['rdf']);
     } else {
     }
     $models = $data;
     Convert::getPaths($models, "");
     $first = $lodspk['firstResults'];
     unset($lodspk['firstResults']);
     //unset($lodspk);
     $vars = compact('uri', 'lodspk', 'conf', 'models', 'rdf', 'first');
     if ($conf['debug']) {
         //Logging::log(var_export($vars, true));
     }
     if (is_string($data)) {
         echo $data;
     } elseif (is_file($view)) {
         try {
             Haanga::Load($viewFile, $vars);
         } catch (Exception $e) {
             echo '<pre>';
             echo $e->getMessage() . "' in " . $e->getFile() . ":" . $e->getLine() . "\nStack trace:\n" . $e->getTraceAsString();
             echo '</pre>';
         }
     } elseif ($view == null) {
         $fnc = Haanga::compile('{{models|safe}}');
         $fnc($vars, TRUE);
     } else {
         echo $conf['home'] . $viewPath . " " . $viewFile;
         $fnc = Haanga::compile($view);
         $fnc($vars, TRUE);
     }
 }
Exemplo n.º 3
0
 public function execute($service)
 {
     global $conf;
     global $localUri;
     global $uri;
     global $acceptContentType;
     global $endpoints;
     global $lodspk;
     global $firstResults;
     global $results;
     $context = array();
     $context['contentType'] = $acceptContentType;
     $context['endpoints'] = $endpoints;
     //$f = $this->getFunction($localUri);
     $params = array();
     $params = $this->getParams($localUri);
     //$params[] = $context;
     //$acceptContentType = Utils::getBestContentType($_SERVER['HTTP_ACCEPT']);
     $extension = Utils::getExtension($acceptContentType);
     $args = array();
     list($modelFile, $viewFile) = $service;
     try {
         $prefixHeader = array();
         for ($i = 0; $i < sizeof($params); $i++) {
             if ($conf['mirror_external_uris'] != false) {
                 $altUri = Utils::curie2uri($params[$i]);
                 $altUri = preg_replace("|^" . $conf['basedir'] . "|", $conf['ns']['local'], $altUri);
                 $params[$i] = Utils::uri2curie($altUri);
             }
         }
         $segmentConnector = "";
         for ($i = 0; $i < sizeof($params); $i++) {
             Utils::curie2uri($params[$i]);
             //echo $params[$i]." ".Utils::curie2uri($params[$i]);exit(0);
             $auxPrefix = Utils::getPrefix($params[$i]);
             if ($auxPrefix['ns'] != NULL) {
                 $prefixHeader[] = $auxPrefix;
             }
             $args["arg" . $i] = $params[$i];
             $args["all"] .= $segmentConnector . $params[$i];
             if ($segmentConnector == "") {
                 $segmentConnector = "/";
             }
         }
         $results['params'] = $params;
         $lodspk['home'] = $conf['basedir'];
         $lodspk['baseUrl'] = $conf['basedir'];
         $lodspk['module'] = 'service';
         $lodspk['root'] = $conf['root'];
         $lodspk['contentType'] = $acceptContentType;
         $lodspk['ns'] = $conf['ns'];
         $lodspk['this']['value'] = $uri;
         $lodspk['this']['curie'] = Utils::uri2curie($uri);
         $lodspk['local']['value'] = $localUri;
         $lodspk['local']['curie'] = Utils::uri2curie($localUri);
         $lodspk['contentType'] = $acceptContentType;
         $lodspk['endpoint'] = $conf['endpoint'];
         $lodspk['type'] = $modelFile;
         $lodspk['header'] = $prefixHeader;
         $lodspk['args'] = $args;
         $lodspk['add_mirrored_uris'] = false;
         $lodspk['baseUrl'] = $conf['basedir'];
         $lodspk['this']['value'] = $uri;
         if ($viewFile == null) {
             $lodspk['transform_select_query'] = true;
         }
         //  chdir($lodspk['model']);
         Utils::queryFile($modelFile, $endpoints['local'], $results, $firstResults);
         if (!$lodspk['resultRdf']) {
             $results = Utils::internalize($results);
             $firstAux = Utils::getfirstResults($results);
             //  	chdir($conf['home']);
             if (is_array($results)) {
                 $resultsObj = Convert::array_to_object($results);
                 $results = $resultsObj;
             } else {
                 $resultsObj = $results;
             }
             $lodspk['firstResults'] = Convert::array_to_object($firstAux);
         } else {
             $resultsObj = $results;
         }
         //Need to redefine viewFile as 'local' i.e., inside service.foo/ so I can load files with the relative path correctly
         //$viewFile = $extension.".template";
         //chdir($conf['home']);
         Utils::processDocument($viewFile, $lodspk, $results);
     } catch (Exception $ex) {
         echo $ex->getMessage();
         if ($conf['debug']) {
             Logging::log($ex->getMessage(), E_ERROR);
         }
         HTTPStatus::send500($uri);
     }
 }
Exemplo n.º 4
0
 public function execute($p)
 {
     global $conf;
     global $localUri;
     global $uri;
     global $acceptContentType;
     global $endpoints;
     global $lodspk;
     global $results;
     global $firstResults;
     $res = $p['res'];
     $page = $p['page'];
     $format = $p['format'];
     $modelFile = $p['modelFile'];
     $viewFile = $p['viewFile'];
     $uri = $res;
     $curie = Utils::uri2curie($res);
     //If resource is not the page, send a 303 to the document
     if ($res == $localUri) {
         HTTPStatus::send303($page, $acceptContentType);
     }
     $uri = $res;
     if ($conf['mirror_external_uris'] != false) {
         $localUri = preg_replace("|^" . $conf['ns']['local'] . "|", $conf['basedir'], $res);
     }
     $extension = Utils::getExtension($format);
     /*Redefine Content type based on the
      * dcterms:format for this page
      */
     $acceptContentType = $format;
     $curie = Utils::uri2curie($uri);
     if ($modelFile == NULL) {
         return;
     }
     //$lodspk = $conf['view']['standard'];
     $lodspk['type'] = $modelFile;
     $lodspk['home'] = $conf['basedir'];
     $lodspk['module'] = 'uri';
     $lodspk['add_mirrored_uris'] = true;
     $lodspk['this']['value'] = $uri;
     $lodspk['this']['curie'] = Utils::uri2curie($uri);
     $lodspk['local']['value'] = $localUri;
     $lodspk['local']['curie'] = Utils::uri2curie($localUri);
     $lodspk['contentType'] = $acceptContentType;
     $lodspk['model'] = $conf['model']['directory'];
     $lodspk['view'] = $conf['view']['directory'];
     $lodspk['ns'] = $conf['ns'];
     //chdir($conf['home'].$conf['model']['directory']);
     Utils::queryFile($modelFile, $endpoints['local'], $results, $firstResults);
     if (!$lodspk['resultRdf']) {
         $results = Utils::internalize($results);
         $firstAux = Utils::getfirstResults($results);
         chdir($conf['home']);
         if (is_array($results)) {
             $resultsObj = Convert::array_to_object($results);
             $results = $resultsObj;
         } else {
             $resultsObj = $results;
         }
         $lodspk['firstResults'] = Convert::array_to_object($firstAux);
     } else {
         $resultsObj = $results;
     }
     //chdir($conf['home']);
     if ($conf['debug']) {
         Logging::log("Using template " . $viewFile);
     }
     Utils::processDocument($viewFile, $lodspk, $resultsObj);
 }