Exemplo n.º 1
0
 public function onCreateMenu($event)
 {
     $modelUri = (string) $event->resource;
     $baseUrl = OntoWiki::getInstance()->config->urlBase;
     $extensionManager = OntoWiki::getInstance()->extensionManager;
     // do NOT create the menu entry ...
     switch (true) {
         // ... for resources
         case !$event->isModel:
             // ... for localhost models (can't be registered at CKAN)
         // ... for localhost models (can't be registered at CKAN)
         case substr_count($modelUri, 'http://localhost') > 0:
             // ... if the model is not part of the base url (no Linked Data)
         // ... if the model is not part of the base url (no Linked Data)
         case substr_count($modelUri, $baseUrl) !== 1:
             // ... if we do not have a linked data server online
         // ... if we do not have a linked data server online
         case !$extensionManager->isExtensionRegistered('linkeddataserver'):
             return;
     }
     // finally, create the holy menu entry and PREPEND it on top of the menu
     $url = new OntoWiki_Url(array('controller' => 'ckan', 'action' => 'register'), array('m'));
     $url->setParam('m', $modelUri);
     $event->menu->prependEntry('Register Knowledge Base @ CKAN', (string) $url);
 }
Exemplo n.º 2
0
 public function getContents()
 {
     $content = '';
     // comment form part
     if (isset($this->_owApp->selectedModel) && $this->_owApp->erfurt->getAc()->isModelAllowed('edit', $this->_owApp->selectedModel)) {
         $limit = $this->_privateConfig->limit;
         $actionUrl = new OntoWiki_Url(array('controller' => 'community', 'action' => 'comment'), array());
         $listUrl = new OntoWiki_Url(array('controller' => 'community', 'action' => 'list'), array());
         $listUrl->setParam('climit', $limit, true);
         $this->view->actionUrl = (string) $actionUrl;
         $this->view->listUrl = (string) $listUrl;
         $this->view->context = $this->getContext();
         $content = $this->render('templates/comment');
     }
     if ($this->getContext() != 'main.window.community') {
         $helper = $this->_owApp->extensionManager->getComponentHelper('community');
         $comments = $helper->getList($this->view);
         if ($comments === null) {
             $this->view->infomessage = 'There are no discussions yet.';
         } else {
             $this->view->comments = $comments;
         }
         $content .= $this->render('templates/lastcomments');
     }
     return $content;
 }
 public function getContents()
 {
     $this->view->headScript()->appendFile($this->view->moduleUrl . 'showproperties.js');
     $allShownProperties = $this->_instances->getShownPropertiesPlain();
     $shownProperties = array();
     $shownInverseProperties = array();
     foreach ($allShownProperties as $prop) {
         if ($prop['inverse']) {
             $shownInverseProperties[] = $prop['uri'];
         } else {
             $shownProperties[] = $prop['uri'];
         }
     }
     $this->view->headScript()->appendScript('var shownProperties = ' . json_encode($shownProperties) . ';
         var shownInverseProperties = ' . json_encode($shownInverseProperties) . ';');
     $url = new OntoWiki_Url(array('controller' => 'resource', 'action' => 'instances'));
     $url->setParam('instancesconfig', json_encode(array('filter' => array(array('id' => 'propertyUsage', 'action' => 'add', 'mode' => 'query', 'query' => (string) $this->_instances->getAllPropertiesQuery(false))))));
     $url->setParam('init', true);
     $this->view->propertiesListLink = (string) $url;
     $url->setParam('instancesconfig', json_encode(array('filter' => array(array('id' => 'propertyUsage', 'action' => 'add', 'mode' => 'query', 'query' => (string) $this->_instances->getAllPropertiesQuery(true))))));
     $this->view->inversePropertiesListLink = (string) $url;
     if ($this->_privateConfig->filterhidden || $this->_privateConfig->filterlist) {
         $this->view->properties = $this->filterProperties($this->_instances->getAllProperties(false));
         $this->view->reverseProperties = $this->filterProperties($this->_instances->getAllProperties(true));
     } else {
         $this->view->properties = $this->_instances->getAllProperties(false);
         $this->view->reverseProperties = $this->_instances->getAllProperties(true);
     }
     return $this->render('showproperties');
 }
Exemplo n.º 4
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;
 }
 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');
 }
Exemplo n.º 6
0
 public function url($uri, $additionalParams = array())
 {
     $url = new OntoWiki_Url(array('route' => 'properties'), array('r'));
     $url->setParam('r', $uri, true);
     foreach ($additionalParams as $name => $value) {
         $url->setParam($name, $value, true);
     }
     return (string) $url;
 }
 public function getContents()
 {
     $titleHelper = new OntoWiki_Model_TitleHelper($this->_owApp->selectedModel);
     $query = new Erfurt_Sparql_SimpleQuery();
     $results = false;
     $_predicates = $this->_predicates;
     $properties = array();
     $instances = array();
     $url = new OntoWiki_Url(array('route' => 'properties'), array('r'));
     $titleHelper->addResources($_predicates, 'uri');
     foreach ($_predicates as $predicate) {
         $predicateUri = $predicate['uri'];
         $url->setParam('r', $predicateUri, true);
         // create properties url for the relation
         $properties[$predicateUri]['uri'] = $predicateUri;
         $properties[$predicateUri]['url'] = (string) $url;
         $properties[$predicateUri]['title'] = $titleHelper->getTitle($predicateUri, $this->_lang);
         $query->resetInstance()->setProloguePart('SELECT DISTINCT ?uri')->setWherePart('WHERE {
                     ?uri <' . $predicateUri . '> <' . (string) $this->_owApp->selectedResource . '> .
                     FILTER (isURI(?uri))
                 }')->setLimit(OW_SHOW_MAX + 1);
         if ($subjects = $this->_owApp->selectedModel->sparqlQuery($query)) {
             $results = true;
             // has_more is used for the dots
             if (count($subjects) > OW_SHOW_MAX) {
                 $properties[$predicateUri]['has_more'] = true;
                 $subjects = array_splice($subjects, 0, OW_SHOW_MAX);
             } else {
                 $properties[$predicateUri]['has_more'] = false;
             }
             $subjectTitleHelper = new OntoWiki_Model_TitleHelper($this->_owApp->selectedModel);
             $subjectTitleHelper->addResources($subjects, 'uri');
             foreach ($subjects as $subject) {
                 $subjectUri = $subject['uri'];
                 $subject['title'] = $subjectTitleHelper->getTitle($subjectUri, $this->_lang);
                 // set URL
                 $url->setParam('r', $subjectUri, true);
                 $subject['url'] = (string) $url;
                 if (array_key_exists($predicateUri, $instances)) {
                     if (!array_key_exists($subjectUri, $instances[$predicateUri])) {
                         $instances[$predicateUri][$subjectUri] = $subject;
                     }
                 } else {
                     $instances[$predicateUri] = array($subjectUri => $subject);
                 }
             }
         }
     }
     $this->view->resource = $this->_owApp->selectedResource;
     $this->view->properties = $properties;
     $this->view->instances = $instances;
     if (!$results) {
         $this->view->message = 'No matches.';
     }
     return $this->render('linkinghere');
 }
 public function getContents()
 {
     $query = new Erfurt_Sparql_SimpleQuery();
     $results = false;
     $similars = array();
     $typesArr = array();
     $types = $this->_getTypes();
     $url = new OntoWiki_Url(array('route' => 'properties'), array('r'));
     $listUrl = new OntoWiki_Url(array('route' => 'instances'), array());
     $titleHelper = new OntoWiki_Model_TitleHelper($this->_owApp->selectedModel);
     $titleHelper->addResources($types);
     foreach ($types as $typeUri) {
         if (!array_key_exists($typeUri, $typesArr)) {
             $typesArr[$typeUri] = $typeUri;
         }
         $query->resetInstance()->setProloguePart('SELECT DISTINCT ?uri')->setWherePart('WHERE {
                     ?uri a <' . $typeUri . '> .
                     FILTER (!sameTerm(?uri, <' . (string) $this->_owApp->selectedResource . '>))
                     FILTER (isURI(?uri))
                 }')->setLimit(OW_SHOW_MAX + 1);
         if ($instances = $this->_owApp->selectedModel->sparqlQuery($query)) {
             $results = true;
             $url->setParam('r', $typeUri, true);
             // create properties url for the class
             $typesArr[$typeUri] = array('uri' => $typeUri, 'url' => (string) $url, 'title' => $titleHelper->getTitle($typeUri, $this->_lang), 'has_more' => false);
             // has_more is used for the dots
             if (count($instances) > OW_SHOW_MAX) {
                 $typesArr[$typeUri]['has_more'] = true;
                 $instances = array_splice($instances, 0, OW_SHOW_MAX);
             }
             $instTitleHelper = new OntoWiki_Model_TitleHelper($this->_owApp->selectedModel);
             $instTitleHelper->addResources($instances, 'uri');
             $conf['filter'][0] = array('mode' => 'rdfsclass', 'rdfsclass' => $typeUri, 'action' => 'add');
             // the list url is used for the context menu link
             $listUrl->setParam('instancesconfig', json_encode($conf), true);
             $listUrl->setParam('init', true, true);
             $typesArr[$typeUri]['listUrl'] = (string) $listUrl;
             foreach ($instances as $row) {
                 $instanceUri = $row['uri'];
                 // set URL
                 $url->setParam('r', $instanceUri, true);
                 if (!array_key_exists($typeUri, $similars)) {
                     $similars[$typeUri] = array();
                 }
                 // add instance
                 $similars[$typeUri][$instanceUri] = array('uri' => $instanceUri, 'title' => $instTitleHelper->getTitle($instanceUri, $this->_lang), 'url' => (string) $url);
             }
         }
     }
     $this->view->types = $typesArr;
     $this->view->similars = $similars;
     if (!$results) {
         $this->view->message = 'No matches.';
     }
     return $this->render('similarinstances');
 }
 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;
     }
 }
Exemplo n.º 10
0
 public function objectlist($objectArray, $titleHelper, $separator = ', ')
 {
     $list = array();
     foreach ((array) $objectArray as $object) {
         if (isset($object['type'])) {
             if ($object['type'] == 'uri') {
                 $url = new OntoWiki_Url(array('route' => 'properties'), array('r'));
                 $url->setParam('r', $object['value'], true);
                 $link = sprintf('<a href="%s">%s</a>', (string) $url, $titleHelper->getTitle($object['value']));
                 array_push($list, $link);
             } else {
                 array_push($list, $object['value']);
             }
         }
     }
     return implode($separator, $list);
 }
Exemplo n.º 11
0
 protected function _getEntry($resultUri, $hasChildren = false)
 {
     $classes = '';
     if ($resultUri == $this->_current) {
         $classes .= ' selected';
     }
     if ($hasChildren) {
         $classes .= ' has-children';
     }
     $this->_url->setParam('r', $resultUri, true);
     $entry = array('uri' => $resultUri, 'url' => (string) $this->_url, 'classes' => trim($classes), 'title' => $this->_titleHelper->getTitle($resultUri, $this->_config->languages->locale), 'children' => array(), 'has_children' => $hasChildren, 'open' => is_array($this->_session->hierarchyOpen) && in_array($resultUri, $this->_session->hierarchyOpen));
     return $entry;
 }
Exemplo n.º 12
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);
 }
Exemplo n.º 13
0
 /**
  * Returns pagination links for the current URL with $count and $limit items.
  *
  * @param $count the total number of items
  * @param $limit the number of items per page
  */
 public static function get($count, $limit = null, $itemsOnPage = null, $page = null, $listName = null, $otherParams = array())
 {
     if (null != $limit) {
         self::$_options['default_limit'] = $limit;
     }
     if (Erfurt_Store::COUNT_NOT_SUPPORTED == $count) {
         self::$_options['show_first_last'] = false;
         //self::$_options['max_page_links']  = 0;
     }
     // get URL with params p (page number) and limit (not used atm)
     $paramsToKeep = array_merge($otherParams, array('p', 'limit', 'r', 'm'));
     self::$_url = new OntoWiki_Url(array(), $paramsToKeep);
     self::$_url->setParam("list", $listName);
     $limit = isset(self::$_url->limit) ? self::$_url->limit : self::$_options['default_limit'];
     if ($limit == 0) {
         // means no limit
         // no pager needed
         return "";
     }
     $page = isset(self::$_url->{self::$_options['page_param']}) ? self::$_url->{self::$_options['page_param']} : ($page != null ? $page : 1);
     // self::$_url->limit = $limit;
     $pagerLinks = array();
     // translation helper
     $translate = OntoWiki::getInstance()->translate;
     // pagination necessary
     if ($count > $limit || $count == Erfurt_Store::COUNT_NOT_SUPPORTED) {
         // previous page exists
         if ($page > 1) {
             if (self::$_options['show_first_last']) {
                 self::$_url->{self::$_options['page_param']} = 1;
                 self::$_url->limit = $limit;
                 $pagerLinks[] = sprintf('<a class="minibutton" href="%s">%s</a>', self::$_url, self::$firstHtml . $translate->_('First'));
             }
             self::$_url->{self::$_options['page_param']} = $page - 1;
             self::$_url->limit = $limit;
             $pagerLinks[] = sprintf('<a class="minibutton" href="%s">%s</a>', self::$_url, self::$prevHtml . $translate->_('Previous'));
         } else {
             if (self::$_options['show_first_last']) {
                 $pagerLinks[] = sprintf('<a class="disabled minibutton">%s</a>', self::$firstHtml . $translate->_('First'));
             }
             $pagerLinks[] = sprintf('<a class="disabled minibutton">%s</a>', self::$prevHtml . $translate->_('Previous'));
         }
         // individual page links
         if ($count != null) {
             if (self::$_options['show_first_last']) {
                 $maxLinksAsym = floor(self::$_options['max_page_links'] / 2);
                 $offset = 0;
             } else {
                 // first and last links are disabled, so always show first and last individual page
                 $maxLinksAsym = floor((self::$_options['max_page_links'] - 2) / 2);
                 self::$_url->{self::$_options['page_param']} = 1;
                 self::$_url->limit = $limit;
                 if ($page == 1) {
                     $pagerLinks[] = '<a class="selected minibutton">1</a>';
                 } else {
                     $pagerLinks[] = '<a class="minibutton" href="' . self::$_url . '">1</a>';
                 }
                 $offset = 1;
                 // if there is a gap, show dots
                 if ($page - $maxLinksAsym > 2) {
                     $pagerLinks[] = '&hellip;';
                 }
             }
             if ($count === Erfurt_Store::COUNT_NOT_SUPPORTED) {
                 for ($i = max(1 + $offset, $page - $maxLinksAsym); $i <= $page; ++$i) {
                     self::$_url->{self::$_options['page_param']} = $i;
                     self::$_url->limit = $limit;
                     if ($page == $i) {
                         $pagerLinks[] = '<a class="selected minibutton">' . $i . '</a>';
                     } else {
                         $pagerLinks[] = '<a class="minibutton" href="' . self::$_url . '">' . $i . '</a>';
                     }
                 }
             } else {
                 $forLoopTest = min(ceil($count / $limit) - $offset, $page + $maxLinksAsym);
                 for ($i = max(1 + $offset, $page - $maxLinksAsym); $i <= $forLoopTest; ++$i) {
                     self::$_url->{self::$_options['page_param']} = $i;
                     self::$_url->limit = $limit;
                     if ($page == $i) {
                         $pagerLinks[] = '<a class="selected minibutton">' . $i . '</a>';
                     } else {
                         $pagerLinks[] = '<a class="minibutton" href="' . self::$_url . '">' . $i . '</a>';
                     }
                 }
             }
             if (!self::$_options['show_first_last'] && $count !== Erfurt_Store::COUNT_NOT_SUPPORTED) {
                 self::$_url->{self::$_options['page_param']} = (int) ceil($count / $limit);
                 self::$_url->limit = $limit;
                 if (self::$_url->{self::$_options['page_param']} - $page > 2) {
                     $pagerLinks[] = '&hellip;';
                 }
                 if ($page == self::$_url->{self::$_options['page_param']}) {
                     $pagerLinks[] = '<a class="selected minibutton">' . self::$_url->{self::$_options['page_param']} . '</a>';
                 } else {
                     $pagerLinks[] = '<a class="minibutton" href="' . self::$_url . '">' . self::$_url->{self::$_options['page_param']} . '</a>';
                 }
             }
         }
         // next page exists
         if ($count > $page * $limit || $count == Erfurt_Store::COUNT_NOT_SUPPORTED && $itemsOnPage === $limit) {
             self::$_url->{self::$_options['page_param']} = $page + 1;
             self::$_url->limit = $limit;
             $pagerLinks[] = sprintf('<a class="minibutton" href="%s">%s</a>', self::$_url, $translate->_('Next') . self::$nextHtml);
             if (self::$_options['show_first_last']) {
                 self::$_url->{self::$_options['page_param']} = (int) ceil($count / $limit);
                 self::$_url->limit = $limit;
                 $pagerLinks[] = sprintf('<a class="minibutton" href="%s">%s</a>', self::$_url, $translate->_('Last') . self::$lastHtml);
             }
         } else {
             $pagerLinks[] = sprintf('<a class="disabled minibutton">%s</a>', $translate->_('Next') . self::$nextHtml);
             if (self::$_options['show_first_last']) {
                 $pagerLinks[] = sprintf('<a class="disabled minibutton">%s</a>', $translate->_('Last') . self::$lastHtml);
             }
         }
         $ret = '<ul>';
         foreach ($pagerLinks as $link) {
             $ret .= '<li>' . $link . '</li>';
         }
         $ret .= '</ul>';
         return $ret;
     }
 }
Exemplo n.º 14
0
 /**
  * Handles identity recovery operations
  */
 public function recoverAction()
 {
     OntoWiki::getInstance()->getNavigation()->disableNavigation();
     $config = Erfurt_App::getInstance()->getConfig();
     $translate = $this->_owApp->translate;
     // start in phase 0
     $phase = 0;
     $success = true;
     $translate = $this->_owApp->translate;
     // check available params
     // phase 1 is generation of hash taking recovery measures (mailing etc...)
     $params['for'] = $this->getParam('for');
     if (empty($params['for'])) {
         unset($params['for']);
     } else {
         $this->view->identity = $params['for'];
         $phase = 1;
     }
     // phase 2 for entering new password
     $params['hash'] = $this->getParam('hash');
     if (empty($params['hash'])) {
         unset($params['hash']);
     } else {
         $this->view->hash = $params['hash'];
         $phase = 2;
     }
     // phase 3 for cleanup and password change in ow system
     $params['password_o'] = $this->getParam('password_o');
     $params['password_r'] = $this->getParam('password_r');
     if (empty($params['hash']) || empty($params['password_o']) || empty($params['password_r'])) {
         unset($params['password_o']);
         unset($params['password_r']);
     } else {
         $phase = 3;
     }
     $title = sprintf($translate->_('Account Recovery Stage %s'), $phase + 1 . ' / 4');
     $this->view->placeholder('main.window.title')->set($title);
     $this->view->phase = $phase;
     require_once 'Erfurt/Auth/Identity/Recovery.php';
     $recoveryObject = new Erfurt_Auth_Identity_Recovery();
     try {
         switch ($phase) {
             case 0:
                 break;
             case 1:
                 $userInfo = $recoveryObject->validateUser($params['for']);
                 $tplDir = $this->_componentRoot . 'templates/';
                 $userUri = $userInfo['userUri'];
                 $template = array();
                 $template['mailSubject'] = $translate->_('OntoWiki Account Recovery');
                 $template['mailTo'] = $userInfo[$config->ac->user->mail];
                 $template['mailUser'] = $userInfo[$config->ac->user->name];
                 $url = new OntoWiki_Url();
                 $url->setParam('controller', 'account');
                 $url->setParam('action', 'recover');
                 $url->setParam('hash', $userInfo['hash']);
                 $url->setParam('for', null);
                 $this->view->recoveryUrl = (string) $url;
                 $this->view->username = $userInfo[$config->ac->user->name];
                 $txtFile = 'mail/text/' . $this->_owApp->translate->getLocale() . '.txt';
                 if (file_exists($tplDir . $txtFile)) {
                     $template['contentText'] = $this->view->render($txtFile);
                 } else {
                     $template['contentText'] = $this->view->render('mail/text/default.txt');
                 }
                 $htmlFile = 'mail/html/' . $this->_owApp->translate->getLocale() . '.phtml';
                 if (file_exists($tplDir . $htmlFile)) {
                     $template['contentHtml'] = $this->view->render($htmlFile);
                 } else {
                     $template['contentHtml'] = $this->view->render('mail/html/default.phtml');
                 }
                 $recoveryObject->setTemplate($template);
                 $success = $recoveryObject->recoverWithIdentity($userUri);
                 break;
             case 2:
                 $success = $recoveryObject->validateHash($params['hash']);
                 break;
             case 3:
                 $success = $recoveryObject->resetPassword($params['hash'], $params['password_o'], $params['password_r']);
                 break;
             default:
                 break;
         }
     } catch (Erfurt_Exception $e) {
         $success = false;
         $message = $translate->_($e->getMessage());
         $this->_owApp->appendMessage(new OntoWiki_Message($message, OntoWiki_Message::ERROR));
     }
     // show toolbar if not in last phase and no errors occured
     if ($success && $phase < 3) {
         $toolbar = $this->_owApp->toolbar;
         $toolbar->appendButton(OntoWiki_Toolbar::SUBMIT, array('name' => 'Submit'));
         $this->view->placeholder('main.window.toolbar')->set($toolbar);
     }
     if (!$success) {
         $title = $translate->_('Account Recovery Error');
         $this->view->placeholder('main.window.title')->set($title);
     }
     $this->view->success = $success;
     $this->view->formActionUrl = $this->_config->urlBase . 'account/recover';
     $this->view->formEncoding = 'multipart/form-data';
     $this->view->formClass = 'simple-input input-justify-left';
     $this->view->formMethod = 'post';
     $this->view->formName = 'accountrecovery';
 }
 /**
  * Handles search requests
  */
 public function searchAction()
 {
     $title = $this->_owApp->translate->_('Resource Search');
     $this->view->placeholder('main.window.title')->set($title);
     OntoWiki::getInstance()->getNavigation()->disableNavigation();
     $store = $this->_erfurt->getStore();
     if (isset($this->_owApp->selectedModel) && null !== $this->_owApp->selectedModel) {
         $modelUri = $this->_owApp->selectedModel->getModelIri();
     } else {
         $modelUri = null;
     }
     if ($this->_request->getParam('searchtext-input') !== null) {
         $searchText = trim($this->getParam('searchtext-input'));
     }
     $error = false;
     $errorMsg = '';
     // check if search is already errorenous
     if (!$error) {
         // try sparql query pre search check (with limit to 1)
         $elements = $store->getSearchPattern($searchText, $modelUri);
         $query = new Erfurt_Sparql_Query2();
         $query->addElements($elements);
         $query->setLimit(1);
         $query->addFrom($modelUri);
         try {
             $store->sparqlQuery($query);
         } catch (Exception $e) {
             // build error message
             $this->_owApp->appendMessage(new OntoWiki_Message($this->_owApp->translate->_('search failed'), OntoWiki_Message::ERROR));
             $error = true;
             $errorMsg .= 'Message details: ';
             $errorMsg .= str_replace('LIMIT 1', '', $e->getMessage());
         }
     }
     // if error occured set output for error page
     if ($error) {
         $this->view->errorMsg = $errorMsg;
     } else {
         // set redirect to effective search controller
         $url = new OntoWiki_Url(array('controller' => 'list'), array());
         $url->setParam('s', $searchText);
         $url->setParam('init', '1');
         $this->_redirect($url);
     }
 }
Exemplo n.º 16
0
 /**
  * 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;
     }
 }
Exemplo n.º 17
0
 /**
  * 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;
 }
Exemplo n.º 18
0
 /**
  * prepare and do the redirect
  */
 private function _doImportActionRedirect($modelUri)
 {
     $post = $this->_request->getPost();
     $id = $post['importAction'];
     $importOptions = $post['importOptions'];
     $actions = $this->_getImportActions();
     if (isset($actions[$id])) {
         $controller = $actions[$id]['controller'];
         $action = $actions[$id]['action'];
     } else {
         $controller = 'model';
         $action = 'info';
     }
     $url = new OntoWiki_Url(array('controller' => $controller, 'action' => $action), array('m', 'importOptions'));
     $url->setParam('m', $modelUri);
     $url->setParam('importOptions', $importOptions);
     $this->_redirect($url, array('code' => 302));
 }
Exemplo n.º 19
0
 public function getContents()
 {
     $url = new OntoWiki_Url(array('route' => 'properties'));
     if (!empty($this->_subjects)) {
         $instances = array();
         $instancesTitleHelper = new OntoWiki_Model_TitleHelper($this->_owApp->selectedModel);
         $instancesTitleHelper->addResources($this->_subjects, 'resourceUri');
         foreach ($this->_subjects as $instance) {
             $instanceUri = $instance['resourceUri'];
             if (!array_key_exists($instanceUri, $instances)) {
                 // URL
                 $url->setParam('r', $instanceUri, true);
                 $instances[$instanceUri] = array('uri' => $instanceUri, 'title' => $instancesTitleHelper->getTitle($instanceUri, $this->_lang), 'url' => (string) $url);
             }
         }
         $this->view->instances = $instances;
     }
     if (!empty($this->_objects)) {
         $objects = array();
         $objectTitleHelper = new OntoWiki_Model_TitleHelper($this->_owApp->selectedModel);
         $objectTitleHelper->addResources($this->_objects, 'resourceUri');
         foreach ($this->_objects as $object) {
             $objectUri = $object['resourceUri'];
             if (!array_key_exists($objectUri, $objects)) {
                 // URL
                 $url->setParam('r', $objectUri, true);
                 $objects[$objectUri] = array('uri' => $objectUri, 'title' => $objectTitleHelper->getTitle($objectUri, $this->_lang), 'url' => (string) $url);
             }
         }
         $this->view->objects = $objects;
     }
     $url = new OntoWiki_Url(array('controller' => 'resource', 'action' => 'instances'));
     $url->setParam('instancesconfig', json_encode(array('filter' => array(array('id' => 'propertyUsage', 'action' => 'add', 'mode' => 'query', 'query' => (string) $this->_subjectQuery)))));
     $url->setParam('init', true);
     $this->view->subjectListLink = (string) $url;
     $url->setParam('instancesconfig', json_encode(array('filter' => array(array('id' => 'propertyUsage', 'action' => 'add', 'mode' => 'query', 'query' => (string) $this->_objectQuery)))));
     $this->view->objectListLink = (string) $url;
     if (empty($this->_subjects) && empty($this->_objects)) {
         $this->view->message = 'No matches.';
     }
     // render data into template
     return $this->render('usage');
 }
Exemplo n.º 20
0
 /**
  * Create the (context) menu for classes and fill it with its default entries
  */
 private function _getClassMenu($resource = null)
 {
     $owApp = OntoWiki::getInstance();
     $classMenu = new OntoWiki_Menu();
     $query = Erfurt_Sparql_SimpleQuery::initWithString('SELECT *
          FROM <' . (string) $owApp->selectedModel . '>
          WHERE {
             <' . $resource . '> a ?type  .
          }');
     $results[] = $owApp->erfurt->getStore()->sparqlQuery($query);
     $query = Erfurt_Sparql_SimpleQuery::initWithString('SELECT *
          FROM <' . (string) $owApp->selectedModel . '>
          WHERE {
             ?inst a <' . $resource . '> .
          } LIMIT 2');
     if (count($owApp->erfurt->getStore()->sparqlQuery($query)) > 0) {
         $hasInstances = true;
     } else {
         $hasInstances = false;
     }
     $typeArray = array();
     foreach ($results[0] as $row) {
         $typeArray[] = $row['type'];
     }
     if (in_array(EF_RDFS_CLASS, $typeArray) || in_array(EF_OWL_CLASS, $typeArray) || $hasInstances) {
         $url = new OntoWiki_Url(array('action' => 'list'), array());
         $url->setParam('class', $resource, false);
         $url->setParam('init', "true", true);
         $classMenu->appendEntry('List Instances', (string) $url);
         // add class menu entries
         if ($owApp->erfurt->getAc()->isModelAllowed('edit', $owApp->selectedModel)) {
             $classMenu->appendEntry('Create Instance', "javascript:createInstanceFromClassURI('{$resource}');");
         }
     }
     return $classMenu;
 }
 protected function _getListLink($uri, $setup)
 {
     if (isset($setup->config->directLink) && $setup->config->directLink) {
         $return = new OntoWiki_Url(array('route' => 'properties'), array('r'));
         // set URL
         $return->setParam('r', $uri, true);
         return $return;
     }
     $owUrl = new OntoWiki_Url(array('route' => 'instances'), array());
     $return = (string) $owUrl;
     // at the moment, we use r= here, not class=
     $return .= "?init";
     $conf = array();
     // there is a shortcut for rdfs classes
     if (isset($setup->config->list->config)) {
         $configString = str_replace("|", '"', $setup->config->list->config);
         $configString = str_replace("%resource%", $uri, $configString);
         $conf = json_decode($configString);
     } else {
         if (isset($setup->config->list->query)) {
             // show properties
             if (isset($setup->config->list->shownProperties)) {
                 $configString = str_replace("|", '"', $setup->config->list->shownProperties);
                 $configString = str_replace("%resource%", $uri, $configString);
                 $conf['shownProperties'][] = json_decode($configString);
             }
             // query
             $configQuery = str_replace("%resource%", $uri, $setup->config->list->query);
             $configQuery = str_replace("\n", " ", $configQuery);
             $conf['filter'][] = array('mode' => 'query', 'query' => $configQuery);
         } else {
             if (isset($setup->config->instanceRelation->out) && isset($setup->config->instanceRelation->in) && $setup->config->instanceRelation->out[0] == EF_RDF_TYPE && $setup->config->hierarchyRelations->in[0] == EF_RDFS_SUBCLASSOF) {
                 $conf['filter'][] = array('mode' => 'rdfsclass', 'rdfsclass' => $uri, 'action' => 'add');
             } else {
                 $conf['filter'][] = array('mode' => 'cnav', 'cnav' => $setup, 'uri' => $uri, 'action' => 'add');
             }
         }
     }
     //$this->_owApp->logger->info("conf: ".print_r($conf,true));
     return $return . "&instancesconfig=" . urlencode(json_encode($conf));
 }
Exemplo n.º 22
0
 /**
  * This method is called, when the onIsDispatchable event was triggered.
  *
  * The onIsDispatchable event is fired in an early stage of the OntoWiki
  * request lifecycle. Hence it is not decided in that moment, which controller
  * an action will be used.
  *
  * The given Erfurt_Event object has an uri property, which contains the
  * requested URI. The method then checks if a resource identified by that
  * URI exists in the local store. Iff this is the case it sends a redirect
  * to another URL depending on the requested MIME type.
  *
  * $event->uri contains the request URI.
  *
  * @param Erfurt_Event $event The event containing the required parameters.
  *
  * @return boolean false if the request was not handled, i.e. no resource was found.
  */
 public function onIsDispatchable($event)
 {
     $store = null;
     try {
         $store = OntoWiki::getInstance()->erfurt->getStore();
     } catch (Exception $e) {
         // if we can't get the store, we do nothing
         return;
     }
     $request = Zend_Controller_Front::getInstance()->getRequest();
     $response = Zend_Controller_Front::getInstance()->getResponse();
     $aliascheck = new Erfurt_Event('onResolveDomainAliasInput');
     $aliascheck->uri = $event->uri;
     $aliascheck->trigger();
     $uri = $aliascheck->uri;
     try {
         // Check for a supported type by investigating the suffix of the URI or by
         // checking the Accept header (content negotiation). The $matchingSuffixFlag
         // parameter contains true if the suffix was used instead of the Accept header.
         $matchingSuffixFlag = false;
         $type = $this->_getTypeForRequest($request, $uri, $matchingSuffixFlag);
         // We need a readable graph to query. We use the first graph that was found.
         // If no readable graph is available for the current user, we cancel here.
         list($graph, $matchedUri) = $this->_matchGraphAndUri($uri);
         if (!$graph || !$matchedUri) {
             // URI not found
             return false;
         }
         if ($uri !== $matchedUri) {
             // Re-append faux file extension
             if ($matchingSuffixFlag) {
                 $matchedUri .= '.' . $type;
             }
             // Redirect to new (correct URI)
             $response->setRedirect((string) $matchedUri, 301);
             return;
         }
         // Prepare for redirect according to the given type.
         $url = null;
         // This will contain the URL to redirect to.
         switch ($type) {
             case 'rdf':
             case 'n3':
             case 'ttl':
                 // Check the config, whether provenance information should be included.
                 $prov = false;
                 if (isset($this->_privateConfig->provenance) && isset($this->_privateConfig->provenance->enabled)) {
                     $prov = (bool) $this->_privateConfig->provenance->enabled;
                 }
                 // Special case: If the graph URI is identical to the requested URI, we export
                 // the whole graph instead of only data regarding the resource.
                 if ($graph === $uri) {
                     $controllerName = 'model';
                     $actionName = 'export';
                 } else {
                     $controllerName = 'resource';
                     $actionName = 'export';
                 }
                 // Create a URL with the export action on the resource or model controller.
                 // Set the required parameters for this action.
                 $url = new OntoWiki_Url(array('controller' => $controllerName, 'action' => $actionName), array());
                 $url->setParam('r', $uri, true)->setParam('f', $type)->setParam('m', $graph)->setParam('provenance', $prov);
                 break;
             case 'html':
             default:
                 // Defaults to the standard property view.
                 // Set the required parameters for this action.
                 $url = new OntoWiki_Url(array('route' => 'properties'), array());
                 $url->setParam('r', $uri, true)->setParam('m', $graph);
                 break;
         }
         // Make $graph the active graph (session required) and make the resource
         // in $uri the active resource.
         $activeModel = $store->getModel($graph);
         OntoWiki::getInstance()->selectedModel = $activeModel;
         OntoWiki::getInstance()->selectedResource = new OntoWiki_Resource($uri, $activeModel);
         // Mark the request as dispatched, since we have all required information now.
         $request->setDispatched(true);
         // Give plugins a chance to do something before redirecting.
         $event = new Erfurt_Event('onBeforeLinkedDataRedirect');
         $event->response = $response;
         $event->trigger();
         // Give plugins a chance to handle the redirection instead of doing it here.
         $event = new Erfurt_Event('onShouldLinkedDataRedirect');
         $event->request = $request;
         $event->response = $response;
         $event->type = $type;
         $event->uri = $uri;
         $event->flag = $matchingSuffixFlag;
         $event->setDefault(true);
         $shouldRedirect = $event->trigger();
         if ($shouldRedirect) {
             // set redirect and send immediately
             $response->setRedirect((string) $url, 303);
             return;
         }
         return !$shouldRedirect;
         // will default to false
     } catch (Erfurt_Exception $e) {
         // don't handle errors since other plug-ins
         // could chain this event
         return false;
     }
 }
Exemplo n.º 23
0
 /**
  * Returns the URL of the given navigation element
  *
  * @return OntoWiki_Url
  */
 protected function _getUrl($elementKey, $currentController, $currentAction)
 {
     $request = Zend_Controller_Front::getInstance()->getRequest();
     $router = Zend_Controller_Front::getInstance()->getRouter();
     $current = $this->_navigation[$elementKey];
     $hasRoute = false;
     if (isset($current['route'])) {
         if ($router->hasRoute($current['route'])) {
             $route = $router->getRoute($current['route']);
             $defaults = $route->getDefaults();
             if ($defaults['controller'] == $current['controller'] && $defaults['action'] == $current['action']) {
                 $hasRoute = true;
             }
         }
     }
     if ($hasRoute) {
         $url = new OntoWiki_Url(array('route' => $current['route']), $this->_keepParams);
     } else {
         $controller = $current['controller'];
         $action = $current['action'] ? $current['action'] : null;
         $url = new OntoWiki_Url(array('controller' => $controller, 'action' => $action), $this->_keepParams);
     }
     $keyBlacklist = array('route', 'controller', 'action', 'priority', 'name', 'active');
     foreach ($current as $key => $value) {
         if (!in_array($key, $keyBlacklist)) {
             $url->setParam($key, $value);
         }
     }
     return $url;
 }
Exemplo n.º 24
0
 public function link($options = array())
 {
     $model = OntoWiki::getInstance()->selectedModel;
     $titleHelper = new OntoWiki_Model_TitleHelper($model);
     // check for options and assign local vars or null
     $uri = isset($options['uri']) ? (string) $options['uri'] : null;
     $literal = isset($options['literal']) ? $options['literal'] : null;
     $text = isset($options['text']) ? $options['text'] : null;
     $property = isset($options['property']) ? $options['property'] : null;
     $class = isset($options['class']) ? ' class="' . $options['class'] . '"' : '';
     $prefix = isset($options['prefix']) ? $options['prefix'] : '';
     $suffix = isset($options['suffix']) ? $options['suffix'] : '';
     $iprefix = isset($options['iprefix']) ? $options['iprefix'] : '';
     $isuffix = isset($options['isuffix']) ? $options['isuffix'] : '';
     $direct = isset($options['direct']) ? true : false;
     // resolve short forms (overwrite full name values with short forms values)
     $uri = isset($options['r']) ? (string) $options['r'] : $uri;
     $literal = isset($options['l']) ? $options['l'] : $literal;
     $text = isset($options['t']) ? $options['t'] : $text;
     $property = isset($options['p']) ? $options['p'] : $property;
     // if an uri is given, we do not need to search for
     if (isset($uri)) {
         // resolve qnames and check uri input
         $uri = Erfurt_Uri::getFromQnameOrUri((string) $uri, $model);
     } else {
         // if no uri is given, we need to search by using the literal
         if (!isset($literal)) {
             throw new Exception('The link helper needs at least one parameter literal or uri');
         }
         // if a property is given, use <properyuri> instead of a variable part in the query
         $property = $property ? '<' . Erfurt_Uri::getFromQnameOrUri($property, $model) . '>' : '?property';
         // build the query including PREFIX declarations
         $query = '';
         foreach ($model->getNamespaces() as $ns => $nsprefix) {
             $query .= 'PREFIX ' . $nsprefix . ': <' . $ns . '>' . PHP_EOL;
         }
         $query .= 'SELECT DISTINCT ?resourceUri WHERE {?resourceUri ' . $property . ' ?literal
             FILTER (!isBLANK(?resourceUri))
             FILTER (REGEX(?literal, "^' . $literal . '$", "i"))
             }  LIMIT 1';
         $result = $model->sparqlQuery($query);
         if (!$result) {
             // resource not found, so return plain literal or given text
             return isset($text) ? $text : $literal;
         } else {
             $uri = $result[0]['resourceUri'];
         }
     }
     // generate the link URL from the resource URI
     if ($direct == true) {
         $url = $uri;
     } else {
         $url = new OntoWiki_Url(array('route' => 'properties'), array('r'));
         $url->setParam('r', $uri, true);
         $url = (string) $url;
     }
     // link text comes from title helper or option
     $text = isset($text) ? $text : $titleHelper->getTitle($uri);
     return "{$prefix}<a{$class} href='{$url}'>{$iprefix}{$text}{$isuffix}</a>{$suffix}";
 }
Exemplo n.º 25
0
 protected function _gracefulError()
 {
     $requestExtra = str_replace($this->getRequest()->getBaseUrl(), '', $this->getRequest()->getRequestUri());
     $requestedUri = OntoWiki::getInstance()->config->urlBase . ltrim($requestExtra, '/');
     $createUrl = new OntoWiki_Url(array(), array());
     $createUrl->controller = 'resource';
     $createUrl->action = 'new';
     $createUrl->setParam('r', $requestedUri);
     $this->view->requestedUrl = (string) $requestedUri;
     $this->view->createUrl = (string) $createUrl;
     $this->view->urlBase = OntoWiki::getInstance()->config->urlBase;
     $exception = null;
     $exceptionType = null;
     if ($this->_request->has('error_handler')) {
         // get errors passed by error handler plug-in
         $errors = $this->_getParam('error_handler');
         $exception = $errors->exception;
         $exceptionType = get_class($exception);
         $errorString = $exception->getMessage();
         OntoWiki::getInstance()->logger->emerg($exceptionType . ': ' . $errorString . ' -> ' . $exception->getFile() . '@' . $exception->getLine());
     }
     // Zend_Controller_Dispatcher_Exception means invalid controller
     // -> resource not found
     if ($this->_request->has('error_handler') && $exceptionType != 'Zend_Controller_Dispatcher_Exception') {
         if (null !== $exception && method_exists($exception, 'getResponseCode') && null !== $exception->getResponseCode()) {
             $this->getResponse()->setHttpResponseCode($exception->getResponseCode());
             $this->_helper->viewRenderer->setScriptAction('error');
         } else {
             $this->getResponse()->setHttpResponseCode(500);
             $this->_helper->viewRenderer->setScriptAction('500');
         }
     } else {
         $this->getResponse()->setHttpResponseCode(404);
         $this->_helper->viewRenderer->setScriptAction('404');
     }
 }