/** * Returns a parameter from the current request and expands its URI * using the local namespace table. It also strips slashes if * magic_quotes_gpc is turned on in PHP. * * @param string $name the name of the parameter * @param boolean $expandNamespace Whether to expand the namespace or not * * @return mixed the parameter or null if not found */ public function getParam($key, $default = null, $expandNamespace = false) { // get parameter value from Zend_Request $value = parent::getParam($key, $default); if ($expandNamespace) { // expandable parameters cannot be arrays if (is_array($value)) { $value = current($value); } // expand namespace $value = OntoWiki_Utils::expandNamespace($value); } // strip slash quotes if necessary if (get_magic_quotes_gpc() && is_string($value)) { $value = stripslashes($value); } return $value; }
public function onBuildUrl($event) { $site = $this->getSiteConfig(); $graph = isset($site['model']) ? $site['model'] : null; $resource = isset($event->params['r']) ? OntoWiki_Utils::expandNamespace($event->params['r']) : null; // URL for this site? if ($graph === (string) OntoWiki::getInstance()->selectedModel && !empty($this->_site)) { if (false !== strpos($resource, $graph)) { // LD-capable if ((string) $resource[strlen($resource) - 1] == '/') { // Slash should not get a suffix $event->url = (string) $resource; // URL created return true; } else { $event->url = $resource . $this->getCurrentSuffix(); // URL created return true; } } else { // classic $event->route = null; $event->controller = 'site'; $event->action = $site['id']; // URL not created, but params changed return false; } } }
/** * Returns a parameter from the current request and expands its URI * using the local namespace table. It also strips slashes if * magic_quotes_gpc is turned on in PHP. * * @param string $name the name of the parameter * @param boolean $expandNamespace Whether to expand the namespace or not * * @deprecated 0.9.5, use OntoWiki_Request::getParam() instead * * @return mixed the parameter or null if not found */ public function getParam($name, $expandNamespace = false) { $value = $this->_request->getParam($name); if ($expandNamespace) { $value = OntoWiki_Utils::expandNamespace($value); } if (get_magic_quotes_gpc()) { $value = stripslashes($value); } return $value; }
/** * Deletes one or more resources denoted by param 'r' * TODO: This should be done by a evolution pattern in the future */ public function deleteAction() { $this->view->clearModuleCache(); $this->_helper->viewRenderer->setNoRender(); $this->_helper->layout->disableLayout(); $store = $this->_erfurt->getStore(); $model = $this->_owApp->selectedModel; $modelIri = (string) $model; $redirect = $this->_request->getParam('redirect', $this->_config->urlBase); if (isset($this->_request->r)) { $resources = $this->_request->getParam('r', array()); } else { throw new OntoWiki_Exception('Missing parameter r!'); } if (!is_array($resources)) { $resources = array($resources); } // get versioning $versioning = $this->_erfurt->getVersioning(); $count = 0; if ($this->_erfurt->getAc()->isModelAllowed('edit', $modelIri)) { foreach ($resources as $resource) { // if we have only a nice uri, fill to full uri if (Zend_Uri::check($resource) == false) { // check for namespace if (strstr($resource, ':')) { $resource = OntoWiki_Utils::expandNamespace($resource); } else { $resource = $model->getBaseIri() . $resource; } } // action spec for versioning $actionSpec = array(); $actionSpec['type'] = 130; $actionSpec['modeluri'] = $modelIri; $actionSpec['resourceuri'] = $resource; // starting action $versioning->startAction($actionSpec); $stmtArray = array(); // query for all triples to delete them $sparqlQuery = new Erfurt_Sparql_SimpleQuery(); $sparqlQuery->setProloguePart('SELECT ?p, ?o'); $sparqlQuery->addFrom($modelIri); $sparqlQuery->setWherePart('{ <' . $resource . '> ?p ?o . }'); $result = $store->sparqlQuery($sparqlQuery, array('result_format' => 'extended')); // transform them to statement array to be compatible with store methods foreach ($result['results']['bindings'] as $stmt) { $stmtArray[$resource][$stmt['p']['value']][] = $stmt['o']; } $store->deleteMultipleStatements($modelIri, $stmtArray); // stopping action $versioning->endAction(); $count++; } $message = $count . ' resource' . ($count != 1 ? 's' : '') . ($count ? ' successfully' : '') . ' deleted.'; $this->_owApp->appendMessage(new OntoWiki_Message($message, OntoWiki_Message::SUCCESS)); } else { $message = 'not allowed.'; $this->_owApp->appendMessage(new OntoWiki_Message($message, OntoWiki_Message::WARNING)); } $event = new Erfurt_Event('onDeleteResources'); $event->resourceArray = $resources; $event->modelUri = $modelIri; $event->trigger(); $this->_redirect($redirect, array('code' => 302)); }
/** * webservice to save a query */ public function savequeryAction() { $this->_helper->layout()->disableLayout(); $response = $this->getResponse(); $response->setHeader('Content-Type', 'text/plain'); $store = $this->_erfurt->getStore(); $storeGraph = $this->_owApp->selectedModel; $graphUri = (string) $this->_owApp->selectedModel; $res = "json or desc missing"; // checking for post data to save queries $params = $this->_request->getParams(); if (isset($params['json']) && isset($params['json'])) { if ($this->_request->getParam('share') == "true") { // store in the model itself - everybody can see it $storeGraph = $this->_owApp->selectedModel; } else { //private db - should be configured so only the user can see it $storeGraph = $this->getUserQueryDB(); } // checking whether any queries exist yet in this store $existingQueriesQuery = Erfurt_Sparql_SimpleQuery::initWithString('SELECT * WHERE { ?query <' . EF_RDF_TYPE . '> <' . OntoWiki_Utils::expandNamespace($this->_privateConfig->saving->ClassUri) . '> . }'); $existingQueries = $storeGraph->sparqlQuery($existingQueriesQuery); if (empty($existingQueries)) { //this is the first query $this->insertInitials($storeGraph); } $hash = md5($this->_request->getParam('json') . $this->_request->getParam('query')); $name = (string) $storeGraph . '#Query-' . $hash; // checking whether a query with same content (Where-Part) already exists (check by md5 sum) $existingDataQuery = Erfurt_Sparql_SimpleQuery::initWithString('SELECT * WHERE { <' . $name . '> a <' . OntoWiki_Utils::expandNamespace($this->_privateConfig->saving->ClassUri) . '> }'); $existingData = $storeGraph->sparqlQuery($existingDataQuery); if (empty($existingData)) { //such a query is not saved yet - lets save it $storeGraph->addStatement($name, EF_RDF_TYPE, array('value' => $this->_privateConfig->saving->ClassUri, 'type' => 'uri'), false); $storeGraph->addStatement($name, $this->_privateConfig->saving->ModelUri, array('value' => (string) $this->_owApp->selectedModel, 'type' => 'uri'), false); $storeGraph->addStatement($name, $this->_privateConfig->saving->NameUri, array('value' => $this->_request->getParam('name'), 'type' => 'literal'), false); $storeGraph->addStatement($name, $this->_privateConfig->saving->DateUri, array('value' => (string) date('c'), 'type' => 'literal', 'datatype' => OntoWiki_Utils::expandNamespace('xsd:dateTime')), false); $storeGraph->addStatement($name, OntoWiki_Utils::expandNamespace($this->_privateConfig->saving->NumViewsUri), array('value' => '1', 'type' => 'literal', 'datatype' => OntoWiki_Utils::expandNamespace('xsd:integer')), false); if ($this->_request->getParam('generator') == "gqb" || $this->_request->getParam('generator') == "qb") { $storeGraph->addStatement($name, $this->_privateConfig->saving->JsonUri, array('value' => $this->_request->getParam('json'), 'type' => 'literal'), false); } $storeGraph->addStatement($name, $this->_privateConfig->saving->QueryUri, array('value' => $this->_request->getParam('query'), 'type' => 'literal'), false); $storeGraph->addStatement($name, $this->_privateConfig->saving->GeneratorUri, array('value' => $this->_request->getParam('generator'), 'type' => 'literal'), false); if ($this->_request->getParam('generator') == "gqb") { $storeGraph->addStatement($name, $this->_privateConfig->saving->IdUri, array('value' => $this->_request->getParam('id'), 'type' => 'literal'), false); $storeGraph->addStatement($name, $this->_privateConfig->saving->SelClassUri, array('value' => $this->_request->getParam('type'), 'type' => 'uri'), false); $storeGraph->addStatement($name, $this->_privateConfig->saving->SelClassLabelUri, array('value' => $this->_request->getParam('typelabel'), 'type' => 'literal'), false); } else { //TODO gqb uses id - qb not... needed? $storeGraph->addStatement($name, $this->_privateConfig->saving->IdUri, array('value' => $hash, 'type' => 'literal'), false); } $user = $this->_erfurt->getAuth()->getIdentity(); $userUri = $user->getUri(); $storeGraph->addStatement($name, $this->_privateConfig->saving->CreatorUri, array('value' => $userUri, 'type' => 'uri'), false); $res = 'All OK'; } else { $res = 'Save failed. (Query with same pattern exists)'; } } $response->setBody($res); }