/** * 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; } }
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'); }
/** * 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; }
/** * 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; }
/** * Displays all preoperties and values for a resource, denoted by parameter */ public function propertiesAction() { $this->_addLastModifiedHeader(); $store = $this->_owApp->erfurt->getStore(); $graph = $this->_owApp->selectedModel; $resource = $this->_owApp->selectedResource; $navigation = $this->_owApp->navigation; $translate = $this->_owApp->translate; // add export formats to resource menu $resourceMenu = OntoWiki_Menu_Registry::getInstance()->getMenu('resource'); $menu = new OntoWiki_Menu(); $menu->setEntry('Resource', $resourceMenu); $event = new Erfurt_Event('onCreateMenu'); $event->menu = $resourceMenu; $event->resource = $this->_owApp->selectedResource; $event->model = $this->_owApp->selectedModel; $event->trigger(); $event = new Erfurt_Event('onPropertiesAction'); $event->uri = (string) $resource; $event->graph = $this->_owApp->selectedModel->getModelUri(); $event->trigger(); // Give plugins a chance to add entries to the menu $this->view->placeholder('main.window.menu')->set($menu->toArray(false, true)); $title = $resource->getTitle($this->_config->languages->locale) ? $resource->getTitle($this->_config->languages->locale) : OntoWiki_Utils::contractNamespace((string) $resource); $windowTitle = sprintf($translate->_('Properties of %1$s'), $title); $this->view->placeholder('main.window.title')->set($windowTitle); if (!empty($resource)) { $event = new Erfurt_Event('onPreTabsContentAction'); $event->uri = (string) $resource; $result = $event->trigger(); if ($result) { $this->view->preTabsContent = $result; } $event = new Erfurt_Event('onPrePropertiesContentAction'); $event->uri = (string) $resource; $result = $event->trigger(); if ($result) { $this->view->prePropertiesContent = $result; } $model = new OntoWiki_Model_Resource($store, $graph, (string) $resource); $values = $model->getValues(); $predicates = $model->getPredicates(); // new trigger onPropertiesActionData to work with data (reorder with plugin) $event = new Erfurt_Event('onPropertiesActionData'); $event->uri = (string) $resource; $event->predicates = $predicates; $event->values = $values; $result = $event->trigger(); if ($result) { $predicates = $event->predicates; $values = $event->values; } $titleHelper = new OntoWiki_Model_TitleHelper($graph); // add graphs $graphs = array_keys($predicates); $titleHelper->addResources($graphs); // set RDFa widgets update info for editable graphs and other graph info $graphInfo = array(); $editableFlags = array(); foreach ($graphs as $g) { $graphInfo[$g] = $titleHelper->getTitle($g, $this->_config->languages->locale); if ($this->_erfurt->getAc()->isModelAllowed('edit', $g)) { $editableFlags[$g] = true; $this->view->placeholder('update')->append(array('sourceGraph' => $g, 'queryEndpoint' => $this->_config->urlBase . 'sparql/', 'updateEndpoint' => $this->_config->urlBase . 'update/')); } else { $editableFlags[$g] = false; } } $this->view->graphs = $graphInfo; $this->view->editableFlags = $editableFlags; $this->view->values = $values; $this->view->predicates = $predicates; $this->view->resourceUri = (string) $resource; $this->view->graphUri = $graph->getModelIri(); $this->view->graphBaseUri = $graph->getBaseIri(); $this->view->editable = false; // use $this->editableFlags[$graph] now // prepare namespaces $namespacePrefixes = $graph->getNamespacePrefixes(); $graphBase = $graph->getBaseUri(); if (!array_key_exists(OntoWiki_Utils::DEFAULT_BASE, $namespacePrefixes)) { $namespacePrefixes[OntoWiki_Utils::DEFAULT_BASE] = $graphBase; } $this->view->namespacePrefixes = $namespacePrefixes; } $toolbar = $this->_owApp->toolbar; // show only if not forwarded and if model is writeable // TODO: why is isEditable not false here? if ($this->_request->getParam('action') == 'properties' && $graph->isEditable() && $this->_owApp->erfurt->getAc()->isModelAllowed('edit', $this->_owApp->selectedModel)) { // TODO: check acl $toolbar->appendButton(OntoWiki_Toolbar::EDIT, array('name' => 'Edit Properties', 'title' => 'SHIFT + ALT + e')); $toolbar->appendButton(OntoWiki_Toolbar::EDITADD, array('name' => 'Clone', 'class' => 'clone-resource', 'title' => 'SHIFT + ALT + l')); // ->appendButton(OntoWiki_Toolbar::EDITADD, array('name' => 'Add Property', 'class' => 'property-add')); $params = array('name' => 'Delete', 'url' => $this->_config->urlBase . 'resource/delete/?r=' . urlencode((string) $resource)); $toolbar->appendButton(OntoWiki_Toolbar::SEPARATOR); $toolbar->appendButton(OntoWiki_Toolbar::DELETE, $params); $toolbar->prependButton(OntoWiki_Toolbar::SEPARATOR); $toolbar->prependButton(OntoWiki_Toolbar::ADD, array('name' => 'Add Property', '+class' => 'property-add', 'title' => 'SHIFT + ALT + a')); $toolbar->prependButton(OntoWiki_Toolbar::SEPARATOR); $toolbar->prependButton(OntoWiki_Toolbar::CANCEL, array('+class' => 'hidden', 'title' => 'SHIFT + ALT + c')); $toolbar->prependButton(OntoWiki_Toolbar::SAVE, array('+class' => 'hidden', 'title' => 'SHIFT + ALT + s')); } // let plug-ins add buttons $toolbarEvent = new Erfurt_Event('onCreateToolbar'); $toolbarEvent->resource = (string) $resource; $toolbarEvent->graph = (string) $graph; $toolbarEvent->toolbar = $toolbar; $eventResult = $toolbarEvent->trigger(); if ($eventResult instanceof OntoWiki_Toolbar) { $toolbar = $eventResult; } // add toolbar $this->view->placeholder('main.window.toolbar')->set($toolbar); //show modules $this->addModuleContext('main.window.properties'); }
/** * 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; }
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); }
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'); }
/** * 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; }
/** * 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)); } }