protected function addFile($params) { $path = "components/" . implode("/", array_slice($params, 1)); $basicContent = "SELECT * WHERE{\n ?s ?p ?o\n }LIMIT 10"; if (strpos($path, ".template") !== FALSE) { //It is not a query, but a template $basicContent = "<!DOCTYPE html>\n<html>\n <head>\n <meta http-equiv='Content-type' content='text/html; charset=utf-8'>\n </head>\n <body>\n </body>\n</html>"; } if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (sizeof($params) < 3) { HTTPStatus::send404(); exit(0); } $return_var = 0; if (file_exists($path)) { echo json_encode(array('success' => false)); return; } $dirpath = $path; $dirArray = explode("/", $path); array_pop($dirArray); $dirpath = implode("/", $dirArray); if (!is_dir($dirpath)) { $oldumask = umask(0); $return_var = mkdir($dirpath, 0755, true); umask($oldumask); if ($return_var === FALSE) { HTTPStatus::send500("mkdir " . var_export($return_var, true) . " " . $dirpath); } } $return_var = file_put_contents($path, $basicContent); //echo $return_var;exit(0); if ($return_var === FALSE) { HTTPStatus::send500("file_puts_content " . var_export($return_var, true) . " " . $path); } else { echo json_encode(array('success' => true, 'return' => $return_var)); } } else { HTTPStatus::send406(); exit(0); } }
public function match($uri) { global $conf; global $acceptContentType; global $localUri; global $lodspk; $lodspk['model'] = null; $lodspk['view'] = null; $q = preg_replace('|^' . $conf['basedir'] . '|', '', $localUri); $qArr = explode('/', $q); if (sizeof($qArr) == 0) { return FALSE; } $extension = Utils::getExtension($acceptContentType); $viewFile = null; $tokens = $qArr; $arguments = array(); while (sizeof($tokens) > 0) { $serviceName = join("%2F", $tokens); //Use .extension at the end of the service to force a particular content type $lastSegment = end($tokens); if (strpos($lastSegment, '.') > 0) { $aux = explode(".", $lastSegment); if (sizeof($aux) > 1) { $requestExtension = array_pop($aux); $contentTypes = $conf['http_accept'][$requestExtension]; if ($contentTypes != null) { $acceptContentType = $contentTypes[0]; $extension = $requestExtension; } } $serviceName = join(".", $aux); } //checking default components if (file_exists($conf['model']['directory'] . '/' . $conf['service']['prefix'] . '/' . $serviceName . '/scaffold.ttl')) { $subDir = $this->readScaffold($conf['model']['directory'] . '/' . $conf['service']['prefix'] . '/' . $serviceName . '/scaffold.ttl', join("/", $arguments)); $subDir .= '/'; $lodspk['model'] = $conf['home'] . $conf['model']['directory'] . '/' . $conf['service']['prefix'] . '/' . $serviceName . '/' . $subDir; $lodspk['view'] = $conf['view']['directory'] . '/' . $conf['service']['prefix'] . '/' . $serviceName . '/' . $subDir . $extension . '.template'; } elseif (file_exists($conf['home'] . $conf['model']['directory'] . '/' . $conf['service']['prefix'] . '/' . $serviceName)) { $lodspk['model'] = $conf['home'] . $conf['model']['directory'] . '/' . $conf['service']['prefix'] . '/' . $serviceName . '/'; $lodspk['view'] = $conf['home'] . $conf['view']['directory'] . '/' . $conf['service']['prefix'] . '/' . $serviceName . '/' . $extension . '.template'; } else { if ($lodspk['model'] == null && $lodspk['view'] == null) { //checking other components if (sizeof($conf['components']['services']) > 0) { foreach ($conf['components']['services'] as $service) { $serviceArray = explode("/", $service); if ($serviceName == end($serviceArray)) { array_pop($serviceArray); $conf['service']['prefix'] = array_pop($serviceArray); $conf['model']['directory'] = join("/", $serviceArray); $conf['view']['directory'] = $conf['model']['directory']; if (file_exists($conf['model']['directory'] . '/' . $conf['service']['prefix'] . '/' . $serviceName . '/scaffold.ttl')) { $subDir = $this->readScaffold($conf['model']['directory'] . '/' . $conf['service']['prefix'] . '/' . $serviceName . '/scaffold.ttl', join("/", $arguments)); $subDir .= '/'; $lodspk['model'] = $conf['model']['directory'] . '/' . $conf['service']['prefix'] . '/' . $serviceName . '/' . $subDir; $lodspk['view'] = $conf['view']['directory'] . '/' . $conf['service']['prefix'] . '/' . $serviceName . '/' . $subDir . $extension . '.template'; } elseif (file_exists($conf['model']['directory'] . '/' . $conf['service']['prefix'] . '/' . $serviceName)) { $lodspk['model'] = $conf['model']['directory'] . '/' . $conf['service']['prefix'] . '/' . $serviceName . '/'; $lodspk['view'] = $conf['view']['directory'] . '/' . $conf['service']['prefix'] . '/' . $serviceName . '/' . $extension . '.template'; } } } } } } $lodspk['serviceName'] = join("/", $tokens); $lodspk['componentName'] = $lodspk['serviceName']; $modelFile = $lodspk['model'] . $extension . '.queries'; if (file_exists($lodspk['model'] . $extension . '.queries')) { if (!file_exists($lodspk['view'])) { $viewFile = null; } else { $viewFile = $lodspk['view']; } return array($modelFile, $viewFile); } elseif (file_exists($lodspk['model'] . 'queries')) { $modelFile = $lodspk['model'] . 'queries'; if (!file_exists($lodspk['view'])) { $lodspk['resultRdf'] = true; $viewFile = null; } else { $viewFile = $lodspk['view']; } return array($modelFile, $viewFile); } elseif (file_exists($lodspk['model'])) { HTTPStatus::send406($uri); return null; } array_unshift($arguments, array_pop($tokens)); } return FALSE; }
error_reporting(E_ERROR); } include_once 'classes/HTTPStatus.php'; include_once 'classes/Utils.php'; include_once 'classes/Queries.php'; include_once 'classes/Endpoint.php'; include_once 'classes/Convert.php'; $results = array(); $firstResults = array(); $endpoints = array(); $endpoints['local'] = new Endpoint($conf['endpoint']['local'], $conf['endpointParams']['config']); $acceptContentType = Utils::getBestContentType($_SERVER['HTTP_ACCEPT']); $extension = Utils::getExtension($acceptContentType); //Check content type is supported by LODSPeaKr if ($acceptContentType == NULL) { HTTPStatus::send406($uri); } //Export if ($conf['export'] && $_GET['q'] == 'export') { include_once 'settings.inc.php'; include_once 'classes/Exporter.php'; $exp = new Exporter(); header('Content-Type: text/plain'); $exp->run(); exit(0); } //Redirect to root URL if necessary $uri = $conf['basedir'] . $_GET['q']; $localUri = $uri; if ($uri == $conf['basedir']) { header('Location: ' . $conf['root']);