コード例 #1
0
 /**
  * list comments
  */
 public function listAction()
 {
     $translate = $this->_owApp->translate;
     $singleResource = true;
     if ($this->_request->getParam('mode') === 'multi') {
         $windowTitle = $translate->_('Discussion about elements of the list');
         $singleResource = false;
     } else {
         $resource = $this->_owApp->selectedResource;
         if ($resource->getTitle()) {
             $title = $resource->getTitle();
         } else {
             $title = OntoWiki_Utils::contractNamespace($resource->getIri());
         }
         $windowTitle = sprintf($translate->_('Discussion about %1$s'), $title);
     }
     $this->addModuleContext('main.window.community');
     $this->view->placeholder('main.window.title')->set($windowTitle);
     $limit = $this->_request->getParam('climit');
     if ($limit === null) {
         $limit = 10;
     }
     $helper = $this->_owApp->extensionManager->getComponentHelper('community');
     $comments = $helper->getList($this->view, $singleResource, $limit);
     if ($comments === null) {
         $this->view->infomessage = 'There are no discussions yet.';
     } else {
         $this->view->comments = $comments;
     }
 }
コード例 #2
0
 public function lastchange($uri)
 {
     // TODO: fill this value with the erfurt versioning api
     $versioning = Erfurt_App::getInstance()->getVersioning();
     $history = $versioning->getLastModifiedForResource($uri, (string) OntoWiki::getInstance()->selectedModel);
     if (empty($history)) {
         return array('resourceUri' => $uri, 'resourceTitle' => '', 'timeStamp' => '', 'timeIso8601' => '', 'timeDuration' => '', 'userTitle' => '', 'userUri' => '', 'userHref' => '');
     }
     $th = new OntoWiki_Model_TitleHelper(OntoWiki::getInstance()->selectedModel);
     $th->addResource($history['useruri']);
     $th->addResource($uri);
     $return = array();
     $userUrl = new OntoWiki_Url(array('route' => 'properties'));
     $userUrl->setParam('r', $history['useruri']);
     $return['resourceUri'] = $uri;
     $return['resourceTitle'] = $th->getTitle($uri);
     $return['timeStamp'] = $history['tstamp'];
     //unix timestamp
     $return['timeIso8601'] = date('c', $history['tstamp']);
     // ISO 8601 format
     try {
         $return['timeDuration'] = OntoWiki_Utils::dateDifference($history['tstamp'], null, 3);
         // x days ago
     } catch (Exception $e) {
         $return['timeDuration'] = '';
     }
     $return['userTitle'] = $th->getTitle($history['useruri']);
     $return['userUri'] = $history['useruri'];
     $return['userHref'] = $userUrl;
     //use URI helper
     return $return;
 }
コード例 #3
0
 /**
  * Returns the title of the module
  *
  * @return string
  */
 public function getTitle()
 {
     $title = 'OntoWiki';
     if (!$this->_owApp->user instanceof Erfurt_Auth_Identity) {
         return $title;
     }
     if ($this->_owApp->user->isOpenId() || $this->_owApp->user->isWebId()) {
         if ($this->_owApp->user->getLabel() !== '') {
             $userName = $this->_owApp->user->getLabel();
             $userName = OntoWiki_Utils::shorten($userName, 25);
         } else {
             $userName = OntoWiki_Utils::getUriLocalPart($this->_owApp->user->getUri());
             $userName = OntoWiki_Utils::shorten($userName, 25);
         }
     } else {
         if ($this->_owApp->user->getUsername() !== '') {
             $userName = $this->_owApp->user->getUsername();
             $userName = OntoWiki_Utils::shorten($userName, 25);
         } else {
             $userName = OntoWiki_Utils::getUriLocalPart($this->_owApp->user->getUri());
             $userName = OntoWiki_Utils::shorten($userName, 25);
         }
     }
     if (isset($userName) && $userName !== 'Anonymous') {
         $title .= ' (' . $userName . ')';
     }
     return $title;
 }
コード例 #4
0
 public function getContents()
 {
     $url = new OntoWiki_Url(array('route' => 'properties'), array('r'));
     $changes = array();
     if ($this->results) {
         foreach ($this->results as $change) {
             if ($this->getContext() == "main.window.dashmodelinfo") {
                 //id, resource, tstamp, action_type
                 $change['useruri'] = $this->user;
                 $this->model = null;
             }
             if (Erfurt_Uri::check($change['resource'])) {
                 $change['aresource'] = new OntoWiki_Resource((string) $change['useruri'], $this->systemModel);
                 $change['author'] = $change['aresource']->getTitle() ? $change['aresource']->getTitle() : OntoWiki_Utils::getUriLocalPart($change['aresource']);
                 $url->setParam('r', (string) $change['aresource'], true);
                 $change['ahref'] = (string) $url;
                 //$change['date'] = OntoWiki_Utils::dateDifference($change['tstamp'], null, 3);
                 $url->setParam('r', (string) $change['resource'], true);
                 $change['rhref'] = (string) $url;
                 $change['resource'] = new OntoWiki_Resource((string) $change['resource'], $this->model);
                 $change['rname'] = $change['resource']->getTitle() ? $change['resource']->getTitle() : OntoWiki_Utils::contractNamespace($change['resource']->getIri());
                 $changes[] = $change;
             }
         }
     }
     if (empty($changes)) {
         $this->view->infomessage = 'There are no changes yet.';
     } else {
         $this->view->changes = $changes;
     }
     return $this->render('templates/lastchanges');
 }
コード例 #5
0
 public function onDisplayLiteralPropertyValue($event)
 {
     $parameter = $event->getParams();
     if (!empty($parameter['datatype'])) {
         $url = new OntoWiki_Url(array('route' => 'properties'), array('r'));
         $url->setParam('r', $parameter['datatype'], true);
         $datatypeLink = "<a class=\"hasMenu\" about=\"" . $parameter['datatype'] . "\" href=\"" . (string) $url . "\">" . OntoWiki_Utils::getUriLocalPart($parameter['datatype']) . "</a>";
         $ret = "<span>" . $parameter['value'] . "</span>";
         $ret .= "<span style = 'float:right;margin-left:2em'>[" . $datatypeLink . "]</span>";
         return $ret;
     }
     if (!empty($parameter['language'])) {
         $ret = "<span>" . $parameter['value'] . "</span>";
         $ret .= "<span style = 'float:right;margin-left:2em'>[" . $parameter['language'] . "]</span>";
         return $ret;
     }
 }
コード例 #6
0
ファイル: Request.php プロジェクト: dmj/uni-helmstedt.hab.de
 /**
  * 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;
 }
コード例 #7
0
 /**
  * Matches the request's accept header againest supported mime types
  * and returns the supported type with highest priority found.
  *
  * @param Zend_Request_Abstract the request object
  *
  * @return string
  */
 private function _matchDocumentTypeRequest($request, array $supportedTypes = array())
 {
     return OntoWiki_Utils::matchMimetypeFromRequest($request, $supportedTypes);
 }
コード例 #8
0
 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;
         }
     }
 }
コード例 #9
0
 /**
  * Returns the title property for the resource URI in the requested language.
  * If no title property is found for that language a list of fallback languages
  * is used. If no title property is found for any language, the local part
  * of the resource URI is returned.
  *
  * @param string $resourceUri
  * @param string $language The preferred language for the title
  *
  * @return string
  */
 public function getTitle($resourceUri, $language = null)
 {
     if (!Erfurt_Uri::check($resourceUri)) {
         return $resourceUri;
     }
     $cacheValue = $this->_cache($resourceUri, (string) $this->_model);
     if ($cacheValue === false) {
         // * means any language
         if (trim($language) == '*') {
             $language = null;
         }
         // add if we don't have this URI (but logg)
         if (!array_key_exists($resourceUri, (array) $this->_resources)) {
             if (defined('_OWDEBUG')) {
                 $logger = OntoWiki::getInstance()->logger;
                 $logger->info('TitleHelper: getTitle called for unknown resource. Adding resource before fetch.');
             }
             $this->addResource($resourceUri);
         }
         // if this is the first getTitle request, fetch titles
         if (!array_key_exists($resourceUri, $this->_resourceTitles)) {
             $this->_fetchResourceTitlesFromQueryResult();
         }
         // prepend the language that is asked for to the array
         // of languages we will look for
         $languages = $this->_languages;
         if (null !== $language) {
             array_unshift($languages, (string) $language);
         }
         $languages = array_values(array_unique($languages));
         $title = null;
         // has anything been found for the resource?
         if (array_key_exists($resourceUri, $this->_resourceTitles)) {
             $titleProperties = (array) $this->_resourceTitles[$resourceUri];
             $currentBestLanguage = PHP_INT_MAX;
             foreach ($this->_titleProperties as $currentTitleProperty) {
                 // has the property been found for the resource?
                 if (array_key_exists($currentTitleProperty, $titleProperties)) {
                     for ($i = 0, $max = count($languages); $i < $max; ++$i) {
                         $currentLanguage = $languages[$i];
                         if ($i < $currentBestLanguage && isset($titleProperties[$currentTitleProperty][$currentLanguage])) {
                             $title = $titleProperties[$currentTitleProperty][$currentLanguage];
                             $currentBestLanguage = $i;
                             if (!$this->_alwaysSearchAllProperties || $currentBestLanguage === 0) {
                                 // it won't get better :)
                                 break 2;
                             }
                         }
                     }
                 }
             }
         }
         // still not found?
         if (null === $title) {
             $title = OntoWiki_Utils::contractNamespace($resourceUri);
             // not even namespace found?
             if ($title == $resourceUri && $this->_alwaysUseLocalNames) {
                 $title = OntoWiki_Utils::getUriLocalPart($resourceUri);
                 // now we have to add this localName to the ResourceTitles array to prevent
                 // querying of resources without titles all the time
                 $this->_resourceTitles[$resourceUri]["localname"]["localname"] = $title;
             }
         }
         $this->_cache($resourceUri, (string) $this->_model, $title);
     } else {
         // cached title
         $title = $cacheValue;
     }
     return $title;
 }
コード例 #10
0
 /**
  * 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));
 }
コード例 #11
0
 public function onDisplayLiteralPropertyValue($event)
 {
     if (array_key_exists($event->property, $this->_properties) && Erfurt_Uri::check($event->value)) {
         return '<a href="' . $event->value . '">' . OntoWiki_Utils::shorten($event->value, 60) . '</a>';
     }
 }
コード例 #12
0
ファイル: Url.php プロジェクト: dmj/uni-helmstedt.hab.de
 /**
  * Sets a URL parameter. Paramters with the same name already
  * set will be overwritten.
  *
  * @param string  $name              parameter name
  * @param string  $value             parameter value
  * @param boolean $contractNamespace denotes whether to contract namespaces in URIs
  *
  * @return OntoWiki_Url
  */
 public function setParam($name, $value, $contractNamespace = false)
 {
     switch ($name) {
         case 'controller':
         case 'action':
             $this->{'_' . $name} = $value;
             break;
         default:
             if (null !== $value) {
                 if ($contractNamespace) {
                     $value = OntoWiki_Utils::contractNamespace($value);
                 }
                 // if (preg_match('/\//', $value)) {
                 //     $this->_useSefUrls = false;
                 // }
                 $this->_params[$name] = $value;
             } else {
                 unset($this->_params[$name]);
             }
     }
     // allow chaining
     return $this;
 }
コード例 #13
0
ファイル: Instances.php プロジェクト: cfrancois7/aksw.org
 /**
  * get link-url, curi, title for an array of properties
  *
  * @param array $properties
  *
  * @return array
  */
 protected function convertProperties($properties)
 {
     $uris = array();
     foreach ($properties as $property) {
         $uris[] = $property['uri'];
     }
     if (!empty($properties)) {
         $this->_titleHelper->addResources($uris);
         $url = new OntoWiki_Url(array('route' => 'properties'), array('r'));
     }
     $propertyResults = array();
     foreach ($properties as $key => $property) {
         if (in_array($property['uri'], $this->_ignoredShownProperties)) {
             continue;
         }
         // set URL
         $url->setParam('r', $property['uri'], true);
         $property['url'] = (string) $url;
         $property['curi'] = OntoWiki_Utils::contractNamespace($property['uri']);
         $property['title'] = $this->_titleHelper->getTitle($property['uri']);
         $propertyResults[$key] = $property;
     }
     return $propertyResults;
 }
コード例 #14
0
 /**
  * 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);
 }
コード例 #15
0
ファイル: TitleHelper.php プロジェクト: cfrancois7/aksw.org
 /**
  * extract the localname from given resourceUri
  *
  * @param string resourceUri
  * @return string title
  */
 private function _extractTitleFromLocalName($resourceUri)
 {
     $title = OntoWiki_Utils::contractNamespace($resourceUri);
     // not even namespace found?
     if ($title == $resourceUri && $this->_alwaysUseLocalNames) {
         $title = OntoWiki_Utils::getUriLocalPart($resourceUri);
     }
     return $title;
 }
コード例 #16
0
 /**
  * OntoWiki Sparql Endpoint
  *
  * Implements the SPARQL protocol according to {@link http://www.w3.org/TR/rdf-sparql-protocol/}.
  */
 public function sparqlAction()
 {
     // service controller needs no view renderer
     $this->_helper->viewRenderer->setNoRender();
     // disable layout for Ajax requests
     $this->_helper->layout()->disableLayout();
     $store = OntoWiki::getInstance()->erfurt->getStore();
     $response = $this->getResponse();
     // fetch params
     // TODO: support maxOccurs:unbound
     $queryString = $this->_request->getParam('query', '');
     if (get_magic_quotes_gpc()) {
         $queryString = stripslashes($queryString);
     }
     $defaultGraph = $this->_request->getParam('default-graph-uri', null);
     $namedGraph = $this->_request->getParam('named-graph-uri', null);
     if (!empty($queryString)) {
         $query = Erfurt_Sparql_SimpleQuery::initWithString($queryString);
         // overwrite query-specidfied dataset with protocoll-specified dataset
         if (null !== $defaultGraph) {
             $query->setFrom((array) $defaultGraph);
         }
         if (null !== $namedGraph) {
             $query->setFromNamed((array) $namedGraph);
         }
         // check graph availability
         $ac = Erfurt_App::getInstance()->getAc();
         foreach (array_merge($query->getFrom(), $query->getFromNamed()) as $graphUri) {
             if (!$ac->isModelAllowed('view', $graphUri)) {
                 if (Erfurt_App::getInstance()->getAuth()->getIdentity()->isAnonymousUser()) {
                     // In this case we allow the requesting party to authorize...
                     $response->setRawHeader('HTTP/1.1 401 Unauthorized')->setHeader('WWW-Authenticate', 'Basic realm="OntoWiki"')->setHttpResponseCode(401);
                     return;
                 } else {
                     $response->setRawHeader('HTTP/1.1 500 Internal Server Error')->setBody('QueryRequestRefused')->setHttpResponseCode(500);
                     return;
                 }
             }
         }
         $typeMapping = array('application/sparql-results+xml' => 'xml', 'application/json' => 'json', 'application/sparql-results+json' => 'json');
         try {
             $type = OntoWiki_Utils::matchMimetypeFromRequest($this->_request, array_keys($typeMapping));
         } catch (Exeption $e) {
             //
         }
         if (empty($type) && isset($this->_request->callback)) {
             // JSONp
             $type = 'application/sparql-results+json';
         } else {
             if (empty($type)) {
                 // default: XML
                 $type = 'application/sparql-results+xml';
             }
         }
         try {
             // get result for mimetype
             $result = $store->sparqlQuery($query, array('result_format' => $typeMapping[$type]));
         } catch (Exception $e) {
             $response->setRawHeader('HTTP/1.1 400 Bad Request')->setBody('MalformedQuery: ' . $e->getMessage())->setHttpResponseCode(400);
             return;
         }
         if (isset($this->_request->callback)) {
             // return jsonp
             $response->setHeader('Content-Type', 'application/javascript');
             $padding = $this->_request->getParam('callback', '');
             $response->setBody($padding . '(' . $result . ')');
         } else {
             // set header
             $response->setHeader('Content-Type', $type);
             // return normally
             $response->setBody($result);
         }
         $response->setHttpResponseCode(200);
         return;
     }
 }
コード例 #17
0
 public function editAction()
 {
     $store = $this->_owApp->erfurt->getStore();
     $resource = $this->_owApp->selectedResource;
     $translate = $this->_owApp->translate;
     $allowSaving = false;
     $showList = false;
     // window title
     if (!$resource) {
         $this->_owApp->appendMessage(new OntoWiki_Message("No resource selected", OntoWiki_Message::WARNING));
         $title = 'RDF Source';
     } else {
         $title = $resource->getTitle() ? $resource->getTitle() : OntoWiki_Utils::contractNamespace($resource->getIri());
     }
     $windowTitle = sprintf($translate->_('Source of Statements about %1$s') . ' (' . $translate->_('without imported statements') . ')', $title);
     $this->view->placeholder('main.window.title')->set($windowTitle);
     // check for N3 capability
     if (array_key_exists('ttl', $store->getSupportedImportFormats())) {
         $allowSaving = true;
     } else {
         $this->_owApp->appendMessage(new OntoWiki_Message("Store adapter cannot handle TTL.", OntoWiki_Message::WARNING));
     }
     if (!$this->_owApp->selectedModel || !$this->_owApp->selectedModel->isEditable()) {
         $allowSaving = false;
         $this->_owApp->appendMessage(new OntoWiki_Message('No model selected or no permissions to edit this model.', OntoWiki_Message::WARNING));
     }
     if ($this->_owApp->lastRoute === 'instances') {
         $allowSaving = false;
         $this->_owApp->appendMessage(new OntoWiki_Message("Modifications of a list currently not supported.", OntoWiki_Message::WARNING));
         $showList = true;
     }
     // do not show edit stuff if model is not writeable
     if ($this->_owApp->erfurt->getAc()->isModelAllowed('edit', $this->_owApp->selectedModel)) {
         $allowSaving = true;
     } else {
         $allowSaving = false;
     }
     if ($allowSaving) {
         // toolbar
         $toolbar = $this->_owApp->toolbar;
         $toolbar->appendButton(OntoWiki_Toolbar::SUBMIT, array('name' => 'Save Source', 'id' => 'savesource'));
         $this->view->placeholder('main.window.toolbar')->set($toolbar);
     } else {
         $this->_owApp->appendMessage(new OntoWiki_Message("Saving has been disabled.", OntoWiki_Message::WARNING));
     }
     // form
     $this->view->formActionUrl = $this->_config->urlBase . 'model/update';
     $this->view->formEncoding = 'multipart/form-data';
     $this->view->formClass = 'simple-input input-justify-left';
     $this->view->formMethod = 'post';
     $this->view->formName = 'savesource';
     $this->view->readonly = $allowSaving ? '' : 'readonly="readonly"';
     $this->view->graphUri = (string) $this->_owApp->selectedModel;
     // construct N3
     $exporter = Erfurt_Syntax_RdfSerializer::rdfSerializerWithFormat('ttl');
     if (!$showList) {
         $source = $exporter->serializeResourceToString((string) $this->_owApp->selectedResource, (string) $this->_owApp->selectedModel);
     } else {
         $listHelper = Zend_Controller_Action_HelperBroker::getStaticHelper('List');
         $listName = "instances";
         if ($listHelper->listExists($listName)) {
             $list = $listHelper->getList($listName);
         } else {
             $this->_owApp->appendMessage(new OntoWiki_Message('something went wrong with the list of instances you want to rdf-view', OntoWiki_Message::ERROR));
         }
         $source = $exporter->serializeQueryResultToString(clone $list->getResourceQuery(), (string) $this->_owApp->selectedModel);
     }
     $this->view->source = $source;
     $url = new OntoWiki_Url(array('route' => 'properties'), array());
     $url->setParam('r', (string) $resource, true);
     $this->view->redirectUri = urlencode((string) $url);
 }
コード例 #18
0
 public function infoAction()
 {
     OntoWiki::getInstance()->getNavigation()->disableNavigation();
     $this->_owApp->selectedResource = new OntoWiki_Resource($this->_request->getParam('m'), $this->_owApp->selectedModel);
     $store = $this->_owApp->erfurt->getStore();
     $graph = $this->_owApp->selectedModel;
     $resource = $this->_owApp->selectedResource;
     //$navigation = $this->_owApp->navigation;
     $translate = $this->_owApp->translate;
     $event = new Erfurt_Event('onPropertiesAction');
     $event->uri = (string) $resource;
     $event->graph = (string) $resource;
     $event->trigger();
     $windowTitle = $translate->_('Model info');
     $this->view->placeholder('main.window.title')->set($windowTitle);
     $title = $resource->getTitle($this->_owApp->getConfig()->languages->locale);
     $this->view->modelTitle = $title ? $title : OntoWiki_Utils::contractNamespace((string) $resource);
     $resourcesUrl = new OntoWiki_Url(array('route' => 'instances'), array());
     $resourcesUrl->init = true;
     $this->view->resourcesUrl = (string) $resourcesUrl;
     if (!empty($resource)) {
         $model = new OntoWiki_Model_Resource($store, $graph, (string) $resource);
         $values = $model->getValues();
         $predicates = $model->getPredicates();
         $titleHelper = new OntoWiki_Model_TitleHelper($graph);
         $graphs = array_keys($predicates);
         $titleHelper->addResources($graphs);
         $graphInfo = array();
         $editableFlags = array();
         foreach ($graphs as $g) {
             $graphInfo[$g] = $titleHelper->getTitle($g, $this->_config->languages->locale);
             $editableFlags[$g] = false;
         }
         $this->view->graphs = $graphInfo;
         $this->view->resourceIri = (string) $resource;
         $this->view->graphIri = $graph->getModelIri();
         $this->view->values = $values;
         $this->view->predicates = $predicates;
         $this->view->graphBaseIri = $graph->getBaseIri();
         $this->view->namespacePrefixes = $graph->getNamespacePrefixes();
         $this->view->editableFlags = $editableFlags;
         if (!is_array($this->view->namespacePrefixes)) {
             $this->view->namespacePrefixes = array();
         }
         if (!array_key_exists(OntoWiki_Utils::DEFAULT_BASE, $this->view->namespacePrefixes)) {
             $this->view->namespacePrefixes[OntoWiki_Utils::DEFAULT_BASE] = $graph->getBaseIri();
         }
         $infoUris = $this->_config->descriptionHelper->properties;
         //echo (string)$resource;
         if (count($values) > 0) {
             $query = 'ASK FROM <' . (string) $resource . '>' . ' WHERE {' . '     <' . (string) $resource . '> a <http://xmlns.com/foaf/0.1/PersonalProfileDocument>' . ' }';
             $q = Erfurt_Sparql_SimpleQuery::initWithString($query);
             if ($this->_owApp->extensionManager->isExtensionActive('foafprofileviewer') && $store->sparqlAsk($q) === true) {
                 $this->view->showFoafLink = true;
                 $this->view->foafLink = $this->_config->urlBase . 'foafprofileviewer/display';
             }
         }
         $this->view->infoPredicates = array();
         foreach ($infoUris as $infoUri) {
             if (isset($predicates[(string) $graph]) && array_key_exists($infoUri, $predicates[(string) $graph])) {
                 $this->view->infoPredicates[$infoUri] = $predicates[(string) $graph][$infoUri];
             }
         }
     }
     $this->addModuleContext('main.window.modelinfo');
 }
コード例 #19
0
ファイル: Base.php プロジェクト: dmj/uni-helmstedt.hab.de
 /**
  * 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;
 }
コード例 #20
0
ファイル: Utils.php プロジェクト: dmj/uni-helmstedt.hab.de
 /**
  * Loads the namespaces from the currently selected model
  */
 private static function _reloadNamespaces()
 {
     $model = OntoWiki::getInstance()->selectedModel;
     if ($model instanceof Erfurt_Rdfs_Model) {
         self::$_namespaces = $model->getNamespaces();
     } else {
         self::$_namespaces = array();
     }
 }
コード例 #21
0
ファイル: Curie.php プロジェクト: dmj/uni-helmstedt.hab.de
 public function curie($uri)
 {
     $curi = OntoWiki_Utils::compactUri($uri);
     return $curi;
 }
コード例 #22
0
 /**
  *  Restoring actions that are specified within the POST parameter
  */
 public function rollbackAction()
 {
     $resource = $this->_owApp->selectedResource;
     $graphuri = (string) $this->_owApp->selectedModel;
     $translate = $this->_owApp->translate;
     $params = $this->_request->getParams();
     // abort on missing parameters
     if (!array_key_exists('actionid', $params) || empty($resource) || empty($graphuri)) {
         $this->_abort('missing parameters.', OntoWiki_Message::ERROR);
     }
     // set active tab to history
     OntoWiki::getInstance()->getNavigation()->setActive('history');
     // setting default title
     $title = $resource->getTitle() ? $resource->getTitle() : OntoWiki_Utils::contractNamespace($resource->getIri());
     $windowTitle = sprintf($translate->_('Versions for %1$s'), $title);
     $this->view->placeholder('main.window.title')->set($windowTitle);
     // setting more view variables
     $url = new OntoWiki_Url(array('controller' => 'view', 'action' => 'index'), null);
     $this->view->backUrl = (string) $url;
     // set translate on view
     $this->view->translate = $this->_owApp->translate;
     // abort on insufficient rights
     if (!$this->_erfurt->getAc()->isActionAllowed('Rollback')) {
         $this->_abort('not allowed.', OntoWiki_Message::ERROR);
     }
     // enabling versioning
     $versioning = $this->_erfurt->getVersioning();
     if (!$versioning->isVersioningEnabled()) {
         $this->_abort('versioning / history is currently disabled.', null, false);
     }
     $successIDs = array();
     $errorIDs = array();
     $actionids = array();
     // starting rollback action
     $actionSpec = array('modeluri' => $graphuri, 'type' => Erfurt_Versioning::STATEMENTS_ROLLBACK, 'resourceuri' => (string) $resource);
     $versioning->startAction($actionSpec);
     // Trying to rollback actions from POST parameters (style: serialized in actionid)
     foreach (unserialize($params['actionid']) as $id) {
         if ($versioning->rollbackAction($id)) {
             $successIDs[] = $id;
         } else {
             $errorIDs[] = $id;
         }
     }
     // ending rollback action
     $versioning->endAction();
     // adding messages for errors and success
     if (!empty($successIDs)) {
         $this->_owApp->appendMessage(new OntoWiki_Message('Rolled back action(s): ' . implode(', ', $successIDs), OntoWiki_Message::SUCCESS));
     }
     if (!empty($errorIDs)) {
         $this->_owApp->appendMessage(new OntoWiki_Message('Error on rollback of action(s): ' . implode(', ', $errorIDs), OntoWiki_Message::ERROR));
     }
 }
コード例 #23
0
ファイル: Resource.php プロジェクト: dmj/uni-helmstedt.hab.de
 /**
  * Returns an array of predicate values for the current resource.
  * The array is indexed with the predicate's URIs.
  *
  * @return array
  */
 public function getValues()
 {
     if (null === $this->_valueResults) {
         $this->_valueResults = array();
         // get results
         $results = $this->getQueryResults();
         // load predicates first
         $this->getPredicates();
         // URL object to build URLs
         $url = new OntoWiki_Url(array('route' => 'properties'), array('r'));
         // keep track of URI objects already used
         $objects = array();
         foreach ($results as $graph => $resultsForGraph) {
             $this->_valueResults[$graph] = array();
             foreach ($resultsForGraph as $row) {
                 $predicateUri = $row['predicate']['value'];
                 if (!array_key_exists($predicateUri, $objects)) {
                     $objects[$predicateUri] = array();
                 }
                 // create space for value information if not exists
                 if (!array_key_exists($predicateUri, $this->_valueResults[$graph])) {
                     $this->_valueResults[$graph][$predicateUri] = array();
                 }
                 // default values
                 $value = array('content' => null, 'object' => null, 'object_hash' => null, 'datatype' => null, 'lang' => null, 'url' => null, 'uri' => null, 'curi' => null);
                 switch ($row['object']['type']) {
                     case 'uri':
                         // every URI objects is only used once for each statement
                         if (in_array($row['object']['value'], $objects[$predicateUri])) {
                             continue;
                         }
                         // URL
                         $url->setParam('r', $row['object']['value'], true);
                         $value['url'] = (string) $url;
                         // URI
                         $value['uri'] = $row['object']['value'];
                         // title
                         $title = $this->_titleHelper->getTitle($row['object']['value']);
                         /**
                          * @trigger onDisplayObjectPropertyValue Triggered if an object value of some
                          * property is returned. Plugins can attach to this trigger in order to modify
                          * the value that gets displayed.
                          * Event payload: value, property, title and link
                          */
                         // set up event
                         $event = new Erfurt_Event('onDisplayObjectPropertyValue');
                         $event->value = $row['object']['value'];
                         $event->property = $predicateUri;
                         $event->title = $title;
                         $event->link = (string) $url;
                         // trigger
                         $value['object'] = $event->trigger();
                         if (!$event->handled()) {
                             // object (modified by plug-ins)
                             $value['object'] = $title;
                         }
                         array_push($objects[$predicateUri], $row['object']['value']);
                         break;
                     case 'typed-literal':
                         $event = new Erfurt_Event('onDisplayLiteralPropertyValue');
                         $value['datatype'] = OntoWiki_Utils::compactUri($row['object']['datatype']);
                         $literalString = Erfurt_Utils::buildLiteralString($row['object']['value'], $row['object']['datatype']);
                         $value['object_hash'] = md5($literalString);
                         $event->value = $row['object']['value'];
                         $event->datatype = $row['object']['datatype'];
                         $event->property = $predicateUri;
                         $value['object'] = $event->trigger();
                         // keep unmodified value in content
                         $value['content'] = $row['object']['value'];
                         if (!$event->handled()) {
                             // object (modified by plug-ins)
                             $value['object'] = $row['object']['value'];
                         }
                         break;
                     case 'literal':
                         // original (unmodified) for RDFa
                         $value['content'] = $row['object']['value'];
                         $literalString = Erfurt_Utils::buildLiteralString($row['object']['value'], null, isset($row['object']['xml:lang']) ? $row['object']['xml:lang'] : null);
                         $value['object_hash'] = md5($literalString);
                         /**
                          * @trigger onDisplayLiteralPropertyValue Triggered if a literal value of some
                          * property is returned. Plugins can attach to this trigger in order to modify
                          * the value that gets displayed.
                          */
                         $event = new Erfurt_Event('onDisplayLiteralPropertyValue');
                         $event->value = $row['object']['value'];
                         $event->property = $predicateUri;
                         // set literal language
                         if (isset($row['object']['xml:lang'])) {
                             $value['lang'] = $row['object']['xml:lang'];
                             $event->language = $row['object']['xml:lang'];
                         }
                         // trigger
                         $value['object'] = $event->trigger();
                         // keep unmodified value in content
                         $value['content'] = $row['object']['value'];
                         // set default if event has not been handled
                         if (!$event->handled()) {
                             $value['object'] = $row['object']['value'];
                         }
                         break;
                 }
                 // push it only if it doesn't exceed number of items to display
                 if (count($this->_valueResults[$graph][$predicateUri]) < $this->_limit) {
                     array_push($this->_valueResults[$graph][$predicateUri], $value);
                 } else {
                     $this->_predicateResults[$graph][$predicateUri]['has_more'] = true;
                 }
                 if (count($this->_valueResults[$graph][$predicateUri]) > 1) {
                     // create the "has more link" (used for area context menu as well)
                     // do it only once per predicate
                     if (!isset($this->_predicateResults[$graph][$predicateUri]['has_more_link'])) {
                         //when all values are literal, we dont use a link to the list,but to the query editor
                         $allValuesAreLiterals = true;
                         foreach ($this->_valueResults[$graph][$predicateUri] as $value) {
                             if (isset($value['uri'])) {
                                 $allValuesAreLiterals = false;
                             }
                         }
                         if (!$allValuesAreLiterals) {
                             $hasMoreUrl = new OntoWiki_Url(array('route' => 'instances', 'action' => 'list'), array());
                             $filterExp = json_encode(array('filter' => array(array('action' => 'add', 'mode' => 'box', 'id' => 'allvalues', 'property' => $predicateUri, 'isInverse' => true, 'propertyLabel' => "value", 'filter' => 'equals', 'value1' => $this->_uri, 'value2' => null, 'valuetype' => 'uri', 'literaltype' => null, 'hidden' => false))));
                             $hasMoreUrl->setParam('instancesconfig', $filterExp)->setParam('init', true);
                         } else {
                             $hasMoreUrl = new OntoWiki_Url(array('controller' => 'queries', 'action' => 'editor'), array());
                             $hasMoreUrl->setParam('query', 'SELECT ?value WHERE {<' . $this->_uri . '> <' . $predicateUri . '> ?value}')->setParam('immediate', true);
                         }
                         $this->_predicateResults[$graph][$predicateUri]['has_more_link'] = (string) $hasMoreUrl;
                     }
                 }
             }
         }
         return $this->_valueResults;
     }
 }
コード例 #24
0
 /**
  * Searches for properties in the local database.
  *
  * @param array  $termsArray
  * @param string $modelUri
  * @param int    $limit
  *
  * @return array
  */
 private function _searchLocalPropertiesOnly(array $termsArray, $modelUri, $limit)
 {
     require_once 'Erfurt/Sparql/SimpleQuery.php';
     $query = new Erfurt_Sparql_SimpleQuery();
     $query->setProloguePart('SELECT DISTINCT ?uri ?o');
     if (null !== $modelUri) {
         $query->addFrom($modelUri);
     }
     $where = '{ { ?uri ?p ?o . ?uri <' . EF_RDF_TYPE . '> ?o2 .
         FILTER (
             sameTerm(?o2, <http://www.w3.org/1999/02/22-rdf-syntax-ns#Property>) ||
             sameTerm(?o2, <http://www.w3.org/2002/07/owl#DatatypeProperty>) ||
             sameTerm(?o2, <http://www.w3.org/2002/07/owl#ObjectProperty>)
         )
         FILTER ((';
     $uriRegexFilter = array();
     foreach ($termsArray as $t) {
         $uriRegexFilter[] = 'regex(str(?uri), "' . $t . '", "i")';
     }
     $where .= implode(' && ', $uriRegexFilter) . ') || (isLiteral(?o) && ';
     $oRegexFilter = array();
     foreach ($termsArray as $t) {
         $oRegexFilter[] = 'regex(?o, "' . $t . '", "i")';
     }
     $where .= implode(' && ', $oRegexFilter) . ')) } UNION {';
     $where .= '?s ?uri ?o .
               FILTER (';
     $where .= implode(' && ', $uriRegexFilter) . ') } }';
     $query->setWherePart($where);
     $query->setOrderClause('?uri');
     $query->setLimit($limit);
     $store = Erfurt_App::getInstance()->getStore();
     $queryResult = $store->sparqlQuery($query, array('result_format' => 'extended'));
     $tempResult = array();
     foreach ($queryResult['results']['bindings'] as $row) {
         if ($row['o']['type'] === 'literal') {
             $weight = $this->_getWeight($termsArray, $row['uri']['value'], $row['o']['value']);
         } else {
             $weight = $this->_getWeight($termsArray, $row['uri']['value']);
         }
         if (isset($tempResult[$row['uri']['value']])) {
             if ($weight > $tempResult[$row['uri']['value']]) {
                 $tempResult[$row['uri']['value']] = $weight;
             }
         } else {
             $tempResult[$row['uri']['value']] = $weight;
         }
     }
     arsort($tempResult);
     require_once 'OntoWiki/Model/TitleHelper.php';
     require_once 'OntoWiki/Utils.php';
     if (null !== $modelUri) {
         $model = $store->getModel($modelUri, false);
         $titleHelper = new OntoWiki_Model_TitleHelper($model);
     } else {
         $titleHelper = new OntoWiki_Model_TitleHelper();
     }
     $titleHelper->addResources(array_keys($tempResult));
     $translate = $this->_owApp->translate;
     $result = array();
     foreach ($tempResult as $uri => $w) {
         $title = $titleHelper->getTitle($uri);
         if (null !== $title) {
             $result[$uri] = str_replace('|', '&Iota;', $title) . '|' . $uri . '|' . $translate->_('Local Search');
         } else {
             $result[$uri] = OntoWiki_Utils::compactUri($uri) . $uri . '|' . $translate->_('Local Search');
         }
     }
     return $result;
 }