/**
  * Returns the menu of the module
  *
  * @return string
  */
 public function getMenu()
 {
     // check if menu must be shown
     if (!$this->_privateConfig->defaults->showMenu) {
         return new OntoWiki_Menu();
     }
     // build main menu (out of sub menus below)
     $mainMenu = new OntoWiki_Menu();
     // edit sub menu
     if ($this->_owApp->erfurt->getAc()->isModelAllowed('edit', $this->_owApp->selectedModel)) {
         $editMenu = new OntoWiki_Menu();
         $editMenu->setEntry('Add Resource here', "javascript:navigationAddElement()");
         $mainMenu->setEntry('Edit', $editMenu);
     }
     // count sub menu
     $countMenu = new OntoWiki_Menu();
     $countMenu->setEntry('10', "javascript:navigationEvent('setLimit', 10)")->setEntry('20', "javascript:navigationEvent('setLimit', 20)")->setEntry('30', "javascript:navigationEvent('setLimit', 30)");
     // toggle sub menu
     $toggleMenu = new OntoWiki_Menu();
     // hidden elements
     $toggleMenu->setEntry('Hidden Elements', "javascript:navigationEvent('toggleHidden')");
     // empty elements
     $toggleMenu->setEntry('Empty Elements', "javascript:navigationEvent('toggleEmpty')");
     // implicit
     $toggleMenu->setEntry('Implicit Elements', "javascript:navigationEvent('toggleImplicit')");
     // view sub menu
     $viewMenu = new OntoWiki_Menu();
     $viewMenu->setEntry('Number of Elements', $countMenu);
     $viewMenu->setEntry('Toggle Elements', $toggleMenu);
     $viewMenu->setEntry('Reset Navigation', "javascript:navigationEvent('reset')");
     $mainMenu->setEntry('View', $viewMenu);
     // navigation type submenu
     $sortMenu = new OntoWiki_Menu();
     foreach ($this->_privateConfig->sorting->toArray() as $sortKey => $sortItem) {
         $sortMenu->setEntry($sortItem['title'], "javascript:navigationEvent('setSort', '" . $sortItem['type'] . "')");
     }
     $mainMenu->setEntry('Sort', $sortMenu);
     // navigation type submenu
     $typeMenu = new OntoWiki_Menu();
     foreach ($this->_privateConfig->config as $key => $config) {
         if ($this->_privateConfig->defaults->checkTypes) {
             if (isset($config->checkVisibility) && $config->checkVisibility == false) {
                 $typeMenu->setEntry($config->title, "javascript:navigationEvent('setType', '{$key}')");
             } else {
                 if ($this->checkConfig($config) > 0) {
                     $typeMenu->setEntry($config->title, "javascript:navigationEvent('setType', '{$key}')");
                 }
             }
         } else {
             $typeMenu->setEntry($config->title, "javascript:navigationEvent('setType', '{$key}')");
         }
     }
     $mainMenu->setEntry('Type', $typeMenu);
     return $mainMenu;
 }
Esempio n. 2
0
 public function getMenu()
 {
     $edit = new OntoWiki_Menu();
     $edit->setEntry('Add', 'javascript:showAddFilterBox()')->setEntry('Remove all', 'javascript:removeAllFilters()');
     $help = new OntoWiki_Menu();
     $help->setEntry('Toggle help', 'javascript:toggleHelp()');
     $main = new OntoWiki_Menu();
     $main->setEntry('Edit', $edit);
     $main->setEntry('Help', $help);
     return $main;
 }
 /**
  * Returns the menu of the module
  *
  * @return string
  */
 public function getMenu()
 {
     if ($this->_erfurt->getAc()->isActionAllowed('ModelManagement')) {
         $editMenu = new OntoWiki_Menu();
         $editMenu->setEntry('Create Knowledge Base', $this->_config->urlBase . 'model/create');
     }
     $viewMenu = new OntoWiki_Menu();
     $session = new Zend_Session_Namespace(_OWSESSION);
     if (!isset($session->showHiddenGraphs) || $session->showHiddenGraphs == false) {
         $viewMenu->setEntry('Show Hidden Knowledge Bases', array('class' => 'modellist_hidden_button show'));
     } else {
         $viewMenu->setEntry('Hide Hidden Knowledge Bases', array('class' => 'modellist_hidden_button'));
     }
     // build menu out of sub menus
     $mainMenu = new OntoWiki_Menu();
     if (isset($editMenu)) {
         $mainMenu->setEntry('Edit', $editMenu);
     }
     $mainMenu->setEntry('View', $viewMenu);
     return $mainMenu;
 }
Esempio n. 4
0
 public function testToJson()
 {
     $subMenuA = new OntoWiki_Menu();
     $subMenuA->setEntry('Sub Entry 1', 'Sub Value 1');
     $subMenuB = new OntoWiki_Menu();
     $subMenuB->setEntry('Sub Entry 2', 'Old Sub Value 2')->setEntry('Sub Entry 2', 'New Sub Value 2');
     $this->_menu->setEntry('Entry 1', 'Value 1')->setEntry('Sub Menu 1', $subMenuA)->setEntry('Sub Menu 2', $subMenuB);
     $expected = '{"Entry 1":"Value 1","Sub Menu 1":{"Sub Entry 1":"Sub Value 1"},' . '"Sub Menu 2":{"Sub Entry 2":"New Sub Value 2"}}';
     $this->assertEquals($expected, $this->_menu->toJson(false));
     $this->_menu->setEntry('Sub Menu 1', 'Replaced Sub Menu Entry');
     $expected = '{"Entry 1":"Value 1","Sub Menu 1":"Replaced Sub Menu Entry","Sub Menu 2":' . '{"Sub Entry 2":"New Sub Value 2"}}';
     $this->assertEquals($expected, $this->_menu->toJson(false));
 }
 public function createConfigurationView($urlBase)
 {
     $ontowiki = OntoWiki::getInstance();
     $model = $ontowiki->selectedModel;
     $this->view->scovo = true;
     $this->view->placeholder('main.window.title')->append('Import CSV Data');
     $this->view->actionUrl = $urlBase . 'csvimport/mapping';
     $this->view->salt = hash("md5", serialize($this->parsedFile));
     OntoWiki_Navigation::disableNavigation();
     if ($model->isEditable()) {
         $toolbar = $ontowiki->toolbar;
         $toolbar->appendButton(OntoWiki_Toolbar::ADD, array('name' => 'Add Dimension', 'id' => 'btn-add-dimension'))->appendButton(OntoWiki_Toolbar::ADD, array('name' => 'Add Attribute', 'id' => 'btn-attribute', 'class' => ''))->appendButton(OntoWiki_Toolbar::EDIT, array('name' => 'Select Data Range', 'id' => 'btn-datarange', 'class' => ''))->appendButton(OntoWiki_Toolbar::SEPARATOR)->appendButton(OntoWiki_Toolbar::SUBMIT, array('name' => 'Extract Triples', 'id' => 'extract'))->appendButton(OntoWiki_Toolbar::RESET, array('name' => 'Cancel'));
         $this->view->placeholder('main.window.toolbar')->set($toolbar);
         $configurationMenu = OntoWiki_Menu_Registry::getInstance()->getMenu('Configurations');
         $i = 0;
         $pattern = '/\'/i';
         $replacement = "\\'";
         $this->view->configs = array();
         if (isset($this->storedConfigurations)) {
             foreach ($this->storedConfigurations as $configNum => $config) {
                 $this->view->configs[$i] = preg_replace($pattern, $replacement, $config['config']);
                 $configurationMenu->prependEntry('Select ' . $config['label'], 'javascript:useCSVConfiguration(csvConfigs[' . $i . '])');
                 $i++;
             }
         }
         $menu = new OntoWiki_Menu();
         $menu->setEntry('Configurations', $configurationMenu);
         $event = new Erfurt_Event('onCreateMenu');
         $event->menu = $configurationMenu;
         $this->view->placeholder('main.window.menu')->set($menu->toArray(false, true));
     } else {
         $ontowiki->appendMessage();
     }
     $this->view->table = $this->view->partial('partials/table.phtml', array('data' => $this->parsedFile, 'tableClass' => 'csvimport'));
     #        $this->viewElements = array(
     #            'table' => array(
     #                'template' => 'partials/table.phtml',
     #                'data' => array(
     #                    'data' => $this->parsedFile,
     #                    'tableClass' => 'csvimport'
     #                )
     #            )
     #        );
 }
 /**
  * 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');
 }
Esempio n. 7
0
 /**
  * Create the application menu and fill it with its default entries
  */
 private function _getApplicationMenu($context = null)
 {
     $owApp = OntoWiki::getInstance();
     // user sub menu
     if ($owApp->erfurt->isActionAllowed('RegisterNewUser') && !(isset($owApp->config->ac) && (bool) $owApp->config->ac->deactivateRegistration === true)) {
         if (!$owApp->erfurt->getAc() instanceof Erfurt_Ac_None) {
             $userMenu = new OntoWiki_Menu();
             $userMenu->setEntry('Register New User', $owApp->config->urlBase . 'application/register');
         }
     }
     if ($owApp->user && !$owApp->user->isAnonymousUser()) {
         if (!isset($userMenu)) {
             $userMenu = new OntoWiki_Menu();
         }
         if (!$owApp->user->isDbUser()) {
             $userMenu->setEntry('Preferences', $owApp->config->urlBase . 'application/preferences');
         }
         $userMenu->setEntry('Logout', $owApp->config->urlBase . 'application/logout');
     }
     // view sub menu
     $viewMenu = new OntoWiki_Menu();
     // extras sub menu
     $extrasMenu = new OntoWiki_Menu();
     $extrasMenu->setEntry('News', $owApp->config->urlBase . 'index/news');
     // help sub menue
     $helpMenu = new OntoWiki_Menu();
     $helpMenu->setEntry('Documentation', $owApp->config->help->documentation)->setEntry('Bug Report', $owApp->config->help->issues)->setEntry('Version Info', $owApp->config->help->versioninfo . '#' . $owApp->config->version->number)->setEntry('About', $owApp->config->urlBase . 'application/about');
     // build menu out of sub menus
     $applicationMenu = new OntoWiki_Menu();
     if (isset($userMenu)) {
         $applicationMenu->setEntry('User', $userMenu);
     }
     $applicationMenu->setEntry('Extras', $extrasMenu)->setEntry('Help', $helpMenu);
     // add cache entry only if use is allowed to use debug action
     if ($owApp->erfurt->isActionAllowed('Debug')) {
         $debugMenu = new OntoWiki_Menu();
         $debugMenu->setEntry('Clear Module Cache', $owApp->config->urlBase . 'debug/clearmodulecache')->setEntry('Clear Translation Cache', $owApp->config->urlBase . 'debug/cleartranslationcache')->setEntry('Clear Object & Query Cache', $owApp->config->urlBase . 'debug/clearquerycache')->setEntry('Start xdebug Session', $owApp->config->urlBase . '?XDEBUG_SESSION_START=xdebug')->setEntry('Reset Session', $owApp->config->urlBase . 'debug/destroysession');
         // for testing sub menus
         // $test1 = new OntoWiki_Menu();
         // $test1->appendEntry('Test 1', '#');
         // $test2 = new OntoWiki_Menu();
         // $test2->appendEntry('Test 2', $test1);
         // $debugMenu->setEntry('Test', $test2);
         $applicationMenu->setEntry('Debug', $debugMenu);
     }
     return $applicationMenu;
 }
 public function editorAction()
 {
     if ($this->_owApp->selectedModel === null) {
         $this->_owApp->appendMessage(new OntoWiki_Message($this->view->_('No model selected.'), OntoWiki_Message::ERROR));
         $this->view->errorFlag = true;
         return;
     }
     $this->view->headLink()->appendStylesheet($this->_owApp->extensionManager->getComponentUrl('queries') . 'resources/querieseditor.css');
     $this->view->placeholder('main.window.title')->set('SPARQL Query Editor');
     $this->view->formActionUrl = $this->_config->urlBase . 'queries/editor';
     $this->view->formMethod = 'post';
     $this->view->formName = 'sparqlquery';
     $this->view->query = $this->_request->getParam('query', '');
     $this->view->urlBase = $this->_config->urlBase;
     $this->view->writeable = $this->_owApp->selectedModel->isEditable();
     // set URIs
     if ($this->_owApp->selectedModel) {
         $this->view->modelUri = $this->_owApp->selectedModel->getModelIri();
     }
     if ($this->_owApp->selectedResource) {
         $this->view->resourceUri = $this->_owApp->selectedResource;
     }
     // build toolbar
     $toolbar = $this->_owApp->toolbar;
     $toolbar->appendButton(OntoWiki_Toolbar::SUBMIT, array('name' => 'Submit Query'))->appendButton(OntoWiki_Toolbar::RESET, array('name' => 'Reset Form'));
     $this->view->placeholder('main.window.toolbar')->set($toolbar);
     // build menu
     if ($this->_owApp->selectedModel) {
         $insertMenu = new OntoWiki_Menu();
         $insertMenu->setEntry('Current Model URI', 'javascript:insertModelUri()');
         if ($this->_owApp->selectedResource) {
             $insertMenu->setEntry('Current Resource URI', 'javascript:insertResourceUri()');
         }
     }
     $helpMenu = new OntoWiki_Menu();
     $helpMenu->setEntry('Specification', 'http://www.w3.org/TR/rdf-sparql-query/')->setEntry('Reference Card', 'http://www.dajobe.org/2005/04-sparql/')->setEntry('Tutorial', 'http://platon.escet.urjc.es/%7Eaxel/sparqltutorial/');
     $menu = new OntoWiki_Menu();
     if (isset($insertMenu)) {
         $menu->setEntry('Insert', $insertMenu);
     }
     $menu->setEntry('Help', $helpMenu);
     $this->view->placeholder('main.window.menu')->set($menu->toArray());
     $prefixes = $this->_owApp->selectedModel->getNamespacePrefixes();
     if (isset($this->_request->queryUri)) {
         $query = $this->getQuery($this->_request->queryUri);
     }
     if (empty($query)) {
         $query = $this->getParam('query');
     }
     $format = $this->_request->getParam('result_format', 'plain');
     if (!empty($query)) {
         //handle a posted query
         $store = $this->_erfurt->getStore();
         foreach ($prefixes as $prefix => $namespace) {
             $prefixString = 'PREFIX ' . $prefix . ': <' . $namespace . '>';
             // only add prefix if it's not there yet
             if (strpos($query, $prefixString) === false) {
                 $query = $prefixString . PHP_EOL . $query;
             }
         }
         if ($format == 'list') {
             $url = new OntoWiki_Url(array('controller' => 'list'), array());
             $query = str_replace("\r\n", ' ', $query);
             $url .= '?init=1&instancesconfig=' . urlencode(json_encode(array('filter' => array(array('mode' => 'query', 'action' => 'add', 'query' => $query)))));
             //redirect
             $this->_redirect($url);
             return;
         }
         if (stristr($query, 'select') && !stristr($query, 'limit')) {
             $query .= PHP_EOL . 'LIMIT 20';
         }
         $this->view->query = $query;
         $result = null;
         try {
             $start = microtime(true);
             //this switch is for the target selection module
             if ($this->_request->getParam('target') == 'all') {
                 //query all models
                 $result = $store->sparqlQuery($query, array('result_format' => $format));
             } else {
                 //query selected model
                 $result = $this->_owApp->selectedModel->sparqlQuery($query, array('result_format' => $format));
             }
             //this is for the "output to file option
             if (($format == 'json' || $format == 'xml') && $this->_request->getParam('result_outputfile') == 'true') {
                 $this->_helper->viewRenderer->setNoRender();
                 $this->_helper->layout()->disableLayout();
                 $response = $this->getResponse();
                 switch ($format) {
                     case 'xml':
                         $contentType = 'application/rdf+xml';
                         $filename = 'query-result.xml';
                         break;
                     case 'json':
                         $contentType = 'application/json';
                         $filename = 'query-result.json';
                         break;
                 }
                 $response->setHeader('Content-Type', $contentType, true);
                 $response->setHeader('Content-Disposition', 'filename="' . $filename . '"');
                 $response->setBody($result);
                 return;
             }
             $this->view->time = (microtime(true) - $start) * 1000;
             $header = array();
             if (is_array($result) && isset($result[0]) && is_array($result[0])) {
                 $header = array_keys($result[0]);
             } else {
                 if (is_bool($result)) {
                     $result = $result ? 'yes' : 'no';
                 } else {
                     if (is_int($result)) {
                         $result = (string) $result;
                     } else {
                         if (is_string($result)) {
                             // json
                             $result = $result;
                         } else {
                             $result = 'no result';
                         }
                     }
                 }
             }
         } catch (Exception $e) {
             $this->view->error = $e->getMessage();
             $header = '';
             $result = '';
             $this->view->time = 0;
         }
         $this->view->data = $result;
         $this->view->header = $header;
     }
     //load js for sparql syntax highlighting
     $this->view->headLink()->appendStylesheet($this->_componentUrlBase . 'resources/codemirror/lib/codemirror.css');
     $this->view->headScript()->appendFile($this->_componentUrlBase . 'resources/codemirror/lib/codemirror.js');
     $this->view->headScript()->appendFile($this->_componentUrlBase . 'resources/codemirror/addon/edit/matchbrackets.js');
     $this->view->headScript()->appendFile($this->_componentUrlBase . 'resources/codemirror/mode/sparql/sparql.js');
     $this->view->headStyle()->appendStyle('.CodeMirror { border: 1px solid black; }');
     $this->view->headScript()->appendScript('var editor;
         $(document).ready(
             function(){
                 editor = CodeMirror.fromTextArea(
                     document.getElementById("inputfield"),
                     {
                         mode: "application/x-sparql-query",
                         tabMode: "indent",
                         matchBrackets: true,
                     }
                 );
                 $(".CodeMirror").resizable({
                     resize: function() {
                         editor.setSize($(this).width(), $(this).height());
                     }
                 });
             }
         );');
     //fill in some placeholders
     $this->view->prefixes = $prefixes;
     $this->view->placeholder('sparql.result.format')->set($format);
     $this->view->placeholder('sparql.query.target')->set($this->_request->getParam('target', 'this'));
     //load modules
     $this->addModuleContext('main.window.queryeditor');
     if ($this->_privateConfig->general->enabled->saving) {
         $this->addModuleContext('main.window.savequery');
     }
 }