Exemplo n.º 1
0
 /**
  * Retieves user credentials from the current request and tries to
  * authenticate the user with Erfurt.
  *
  * @param Zend_Controller_Request_Abstract $request The current request object
  */
 public function routeShutdown(Zend_Controller_Request_Abstract $request)
 {
     if ($credentials = $this->_getAuthHeaderCredentials($request)) {
         switch ($credentials['type']) {
             case 'basic':
                 $erfurt = OntoWiki::getInstance()->erfurt;
                 $logger = OntoWiki::getInstance()->logger;
                 // authenticate
                 $authResult = $erfurt->authenticate($credentials['username'], $credentials['password']);
                 if ($authResult->isValid()) {
                     $logger = OntoWiki::getInstance()->logger;
                     $logger->info("User '{$credentials['username']}' authenticated via HTTP.");
                 } else {
                     // if authentication attempt fails, send appropriate headers
                     $front = Zend_Controller_Front::getInstance();
                     $response = $front->getResponse();
                     $response->setRawHeader('HTTP/1.1 401 Unauthorized');
                     echo 'HTTP/1.1 401 Unauthorized';
                     return;
                 }
                 break;
             case 'foaf+ssl':
                 $adapter = new Erfurt_Auth_Adapter_FoafSsl();
                 $authResult = $adapter->authenticateWithCredentials($credentials['creds']);
                 Erfurt_App::getInstance()->getAuth()->setIdentity($authResult);
                 if ($authResult->isValid()) {
                     $logger = OntoWiki::getInstance()->logger;
                     $logger->info('User authenticated with FOAF+SSL via HTTPS.');
                 }
                 break;
         }
     }
 }
Exemplo n.º 2
0
 public function lastchange($uri)
 {
     // TODO: fill this value with the erfurt versioning api
     $versioning = Erfurt_App::getInstance()->getVersioning();
     $history = $versioning->getLastModifiedForResource($uri, (string) OntoWiki::getInstance()->selectedModel);
     if (empty($history)) {
         return array('resourceUri' => $uri, 'resourceTitle' => '', 'timeStamp' => '', 'timeIso8601' => '', 'timeDuration' => '', 'userTitle' => '', 'userUri' => '', 'userHref' => '');
     }
     $th = new OntoWiki_Model_TitleHelper(OntoWiki::getInstance()->selectedModel);
     $th->addResource($history['useruri']);
     $th->addResource($uri);
     $return = array();
     $userUrl = new OntoWiki_Url(array('route' => 'properties'));
     $userUrl->setParam('r', $history['useruri']);
     $return['resourceUri'] = $uri;
     $return['resourceTitle'] = $th->getTitle($uri);
     $return['timeStamp'] = $history['tstamp'];
     //unix timestamp
     $return['timeIso8601'] = date('c', $history['tstamp']);
     // ISO 8601 format
     try {
         $return['timeDuration'] = OntoWiki_Utils::dateDifference($history['tstamp'], null, 3);
         // x days ago
     } catch (Exception $e) {
         $return['timeDuration'] = '';
     }
     $return['userTitle'] = $th->getTitle($history['useruri']);
     $return['userUri'] = $history['useruri'];
     $return['userHref'] = $userUrl;
     //use URI helper
     return $return;
 }
Exemplo n.º 3
0
 /**
  * Constructor
  */
 public function __construct($name, $context, $config)
 {
     // init view
     if (null === $this->view) {
         $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
         if (null === $viewRenderer->view) {
             $viewRenderer->initView();
         }
         $this->view = clone $viewRenderer->view;
         $this->view->clearVars();
     }
     $this->_templateSuffix = '.' . ltrim($this->_templateSuffix, '.');
     $this->_owApp = OntoWiki::getInstance();
     $this->_erfurt = $this->_owApp->erfurt;
     $this->_store = $this->_erfurt->getStore();
     $this->_config = $this->_owApp->config;
     $this->_lang = $this->_config->languages->locale;
     $this->_request = Zend_Controller_Front::getInstance()->getRequest();
     $this->_name = $name;
     // set important script variables
     $this->view->themeUrlBase = $this->_config->themeUrlBase;
     $this->view->urlBase = $this->_config->urlBase;
     $this->view->moduleUrl = $this->_config->staticUrlBase . $this->_config->extensions->base . $config->extensionName . '/';
     // set the config
     $this->_privateConfig = $config->private;
     // set the context
     $this->setContext($context);
     // allow custom module initialization
     $this->init();
 }
 public function onPropertiesActionData($event)
 {
     if ($this->_privateConfig->sort->property) {
         $store = Erfurt_App::getInstance()->getStore();
         $config = Erfurt_App::getInstance()->getConfig();
         $data = $event->predicates;
         foreach ($data as $graphUri => $predicates) {
             $query = new Erfurt_Sparql_SimpleQuery();
             $query->setProloguePart('SELECT DISTINCT *')->addFrom((string) $graphUri)->setWherePart('WHERE { ?p <' . $this->_privateConfig->sort->property . '> ?o . }');
             $result = $store->sparqlQuery($query);
             if (!empty($result)) {
                 $order = array();
                 foreach ($result as $v) {
                     $order[$v['p']] = $v['o'];
                 }
                 $predicateOrder = array();
                 foreach (array_keys($predicates) as $predicate) {
                     if (array_key_exists($predicate, $order)) {
                         $predicateOrder[] = (int) $order[$predicate];
                     } else {
                         $predicateOrder[] = 0;
                     }
                 }
                 array_multisort($predicateOrder, SORT_DESC, SORT_STRING, $predicates);
                 $data[$graphUri] = $predicates;
             }
         }
         $event->predicates = $data;
         return true;
     }
 }
 public function _initErfurt()
 {
     $erfurt = null;
     // require Config
     $this->bootstrap('Config');
     $config = $this->getResource('Config');
     // require OntoWiki
     $this->bootstrap('OntoWiki');
     $ontoWiki = $this->getResource('OntoWiki');
     // require Logger, since Erfurt logger should write into OW logs dir
     $this->bootstrap('Logger');
     // Reset the Erfurt app for testability... needs to be refactored.
     Erfurt_App::reset();
     try {
         $erfurt = Erfurt_App::getInstance(false)->start($config);
     } catch (Erfurt_Exception $ee) {
         throw new OntoWiki_Exception('Error loading Erfurt framework: ' . $ee->getMessage());
     } catch (Exception $e) {
         throw new OntoWiki_Exception('Unexpected error: ' . $e->getMessage());
     }
     $store = new Erfurt_Store(array('adapterInstance' => new Erfurt_Store_Adapter_Test()), 'Test');
     $erfurt->setStore($store);
     // make available
     $ontoWiki->erfurt = $erfurt;
     return $erfurt;
 }
 /**
  * Displays OntoWiki's about page
  */
 public function aboutAction()
 {
     OntoWiki::getInstance()->getNavigation()->disableNavigation();
     $this->view->placeholder('main.window.title')->set('About ' . $this->_config->version->label);
     $version = $this->_config->version->number;
     if (isset($this->_config->version->suffix)) {
         $version .= ' ' . $this->_config->version->suffix;
     }
     $cacheWritable = is_writable($this->_config->cache->path) ? ' <span style="color:#aea">(writable)</span>' : ' <span style="color:#eaa">(not writable!)</span>';
     $logWritable = is_writable($this->_config->log->path) ? ' <span style="color:#aea">(writable)</span>' : ' <span style="color:#eaa">(not writable!)</span>';
     $cacheBackend = $this->_config->cache->backend->type;
     $cacheBackendOptions = array();
     $cacheFrontendOptions = array();
     foreach ($this->_config->cache->frontend->toArray() as $key => $value) {
         $cacheFrontendOptions[] = $key . ": " . (string) $value;
     }
     if (isset($this->_config->cache->backend->{$cacheBackend})) {
         foreach ($this->_config->cache->backend->{$cacheBackend}->toArray() as $key => $value) {
             $cacheBackendOptions[] = $key . ": " . (string) $value;
         }
     }
     $cacheFrontendOptions = join(", ", $cacheFrontendOptions);
     $cacheBackendOptions = join(", ", $cacheBackendOptions);
     $data = array('System' => array('Release' => $version, 'PHP Version' => phpversion(), 'Backend' => $this->_owApp->erfurt->getStore()->getBackendName(), 'Debug Mode' => defined('_OWDEBUG') ? 'enabled' : 'disabled'), 'User Interface' => array('Theme' => rtrim($this->_config->themes->default, '/'), 'Language' => $this->_config->languages->locale), 'Paths' => array('Extensions Path' => _OWROOT . rtrim($this->_config->extensions->base, '/'), 'Translations Path' => _OWROOT . rtrim($this->_config->languages->path, '/'), 'Themes Path' => _OWROOT . rtrim($this->_config->themes->path, '/'), 'Temporary Directory' => Erfurt_App::getInstance()->getTmpDir()), 'Cache' => array('State' => $this->_config->cache->frontend->enable ? 'enabled' : 'disabled', 'Frontend Options' => $cacheFrontendOptions, 'Backend' => $cacheBackend, 'Backend Options' => $cacheBackendOptions, 'Module Caching' => (bool) $this->_config->cache->modules == true ? 'enabled' : 'disabled', 'Translation Caching' => (bool) $this->_config->cache->translation == true ? 'enabled' : 'disabled'), 'Logging' => array('Path' => rtrim($this->_config->log->path, '/') . $logWritable, 'Level' => (bool) $this->_config->loglevel ? $this->_config->loglevel : 'disabled'));
     // check if the git comand exists and ontowiki is a working directory
     if (file_exists(".git") && substr(@exec("git --version"), 0, 11) == "git version") {
         @exec('git status', $arr);
         $data['Git Versioning'] = array('Version' => @exec("git describe"), 'Branch' => substr($arr[0], 12), 'last commit' => @exec("git log --pretty=format:'%ar' -n 1"));
     }
     $this->view->data = $data;
 }
Exemplo n.º 7
0
 public function parseFromFilenameToStore($filename, $graphUri, $useAc = true)
 {
     $triples = $this->parseFromFilename($filename);
     $store = Erfurt_App::getInstance()->getStore();
     $store->addMultipleStatements($graphUri, $triples, $useAc);
     return true;
 }
Exemplo n.º 8
0
 /**
  * fetches all titles according the given array if Uris
  *
  * @param array resourceUris
  */
 private function _fetchTitlesFromResourcePool($resourceUris)
 {
     $resourcePool = $this->_erfurtApp->getResourcePool();
     $resources = array();
     if (!empty($this->_model)) {
         $modelUri = $this->_model->getModelIri();
         $resources = $resourcePool->getResources($resourceUris, $modelUri);
     } else {
         $resources = $resourcePool->getResources($resourceUris);
     }
     $memoryModel = new Erfurt_Rdf_MemoryModel();
     foreach ($resources as $resourceUri => $resource) {
         $resourceDescription = $resource->getDescription();
         $memoryModel->addStatements($resourceDescription);
         $found = false;
         foreach ($this->_titleProperties as $titleProperty) {
             $values = $memoryModel->getValues($resourceUri, $titleProperty);
             foreach ($values as $value) {
                 if (!empty($value['lang'])) {
                     $language = $value['lang'];
                 } else {
                     $language = '';
                 }
                 $this->_resources[$resourceUri][$titleProperty][$language] = $value['value'];
             }
         }
     }
 }
 public function onPropertiesActionData($event)
 {
     if ($this->_privateConfig->hide->property) {
         $store = Erfurt_App::getInstance()->getStore();
         $config = Erfurt_App::getInstance()->getConfig();
         $data = $event->predicates;
         foreach ($data as $graphUri => $predicates) {
             $query = new Erfurt_Sparql_SimpleQuery();
             $query->setProloguePart('SELECT DISTINCT *')->addFrom((string) $graphUri)->setWherePart('WHERE { ?p <' . $this->_privateConfig->hide->property . '> ?o . }');
             $results = $store->sparqlQuery($query);
             if (!empty($results)) {
                 $publicPredicates = array();
                 foreach ($data as $element) {
                     foreach ($element as $propertykey => $property) {
                         $hide = false;
                         foreach ($results as $result) {
                             if ($result['p'] == $property['uri']) {
                                 $hide = true;
                                 break;
                             }
                         }
                         if (!$hide) {
                             $publicPredicates[$propertykey] = $property;
                         }
                     }
                 }
                 $data[$graphUri] = $publicPredicates;
             }
         }
     }
     $event->predicates = $data;
     return true;
 }
Exemplo n.º 10
0
 public function setUp()
 {
     $this->markTestNeedsZendDb();
     $config = Erfurt_App::getInstance()->getConfig();
     $adapterOptions = $config->store->zenddb->toArray();
     $this->fixture = new Erfurt_Store_Adapter_EfZendDb($adapterOptions);
 }
Exemplo n.º 11
0
 /**
  * @param Erfurt_Syntax_StringWriterInterface $stringWriter
  * @param MemModel $model
  */
 public function __construct($stringWriter, $useAc = true)
 {
     $this->resetState();
     $this->_useAc = $useAc;
     $this->_stringWriter = $stringWriter;
     $this->_stringWriter->setDoctype(EF_RDF_NS, 'RDF');
     $this->_store = Erfurt_App::getInstance()->getStore();
 }
Exemplo n.º 12
0
 private function _import($modelIri, $fileOrUrl)
 {
     try {
         Erfurt_App::getInstance()->getStore()->importRdf($modelIri, $fileOrUrl);
     } catch (Erfurt_Exception $e) {
         // re-throw
         throw new OntoWiki_Controller_Exception('Could not import given model: ' . $e->getMessage(), 0, $e);
     }
 }
Exemplo n.º 13
0
 public function __construct()
 {
     if (Erfurt_App::getInstance()->getAc()->isActionAllowed('ExtensionConfiguration')) {
         $owApp = OntoWiki::getInstance();
         $translate = $owApp->translate;
         $url = new OntoWiki_Url(array('controller' => 'exconf', 'action' => 'list'), array());
         $extrasMenu = OntoWiki_Menu_Registry::getInstance()->getMenu('application')->getSubMenu('Extras');
         $extrasMenu->setEntry($translate->_('Configure Extensions'), (string) $url);
     }
 }
Exemplo n.º 14
0
 public function setUp()
 {
     $this->markTestNeedsTestConfig();
     $this->markTestNeedsDatabase();
     $config = $this->getTestConfig();
     $config->cache->frontend->enable = TRUE;
     $config->cache->query->enable = TRUE;
     $this->_cacheBackend = Erfurt_App::getInstance(false)->getQueryCache()->getBackend();
     parent::setUp();
 }
 public function setUp()
 {
     $this->markTestNeedsTestConfig();
     $this->markTestNeedsDatabase();
     $this->_erfurtApp = Erfurt_App::getInstance();
     $this->_store = $this->_erfurtApp->getStore();
     $this->authenticateDbUser();
     $this->_modelUri = 'http://example.org/graph123/';
     $this->_addTestData();
     parent::setUp();
 }
Exemplo n.º 16
0
 public function testResultHeadVarsHaveCorrectName()
 {
     $this->markTestNeedsDatabase();
     $this->authenticateDbUser();
     $store = Erfurt_App::getInstance()->getStore();
     $sparql = Erfurt_Sparql_SimpleQuery::initWithString('SELECT ?s ?p ?o WHERE { ?s ?p ?o } LIMIT 10');
     $result = $store->sparqlQuery($sparql, array('result_format' => 'extended'));
     $head = $result['head'];
     $this->assertEquals('s', $head['vars'][0]);
     $this->assertEquals('p', $head['vars'][1]);
     $this->assertEquals('o', $head['vars'][2]);
 }
Exemplo n.º 17
0
 public function testGetDescription()
 {
     $this->markTestNeedsDatabase();
     $this->authenticateDbUser();
     $model = Erfurt_App::getInstance()->getSysOntModel();
     $resource = new Erfurt_Rdf_Resource('http://ns.ontowiki.net/SysOnt/Anonymous', $model);
     $description = $resource->getDescription();
     $this->assertTrue(isset($description['http://ns.ontowiki.net/SysOnt/Anonymous']));
     $anonymousDesc = $description['http://ns.ontowiki.net/SysOnt/Anonymous'];
     $this->assertTrue(isset($anonymousDesc['http://www.w3.org/1999/02/22-rdf-syntax-ns#type']));
     $this->assertTrue(isset($anonymousDesc['http://www.w3.org/2000/01/rdf-schema#label']));
     $this->assertTrue(isset($anonymousDesc['http://www.w3.org/2000/01/rdf-schema#comment']));
 }
Exemplo n.º 18
0
 public function onRouteShutdown($event)
 {
     if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) === 'on' && extension_loaded('openssl')) {
         $app = Erfurt_App::getInstance();
         if ($app->getAuth()->getIdentity()->isAnonymousUser()) {
             $result = $app->authenticateWithFoafSsl();
             if ($result->isValid()) {
                 // Redirect to referer page...
                 require_once 'Zend/Controller/Front.php';
                 $front = Zend_Controller_Front::getInstance()->getResponse()->setRedirect($_SERVER['HTTP_REFERER']);
             }
         }
     }
 }
Exemplo n.º 19
0
 /**
  * @medium
  */
 public function testScan()
 {
     Erfurt_App::getInstance(false)->getCache()->clean();
     // clear cache, since otherwise the extension manager may have the real extensions loaded
     if (function_exists('apc_clear_cache')) {
         apc_clear_cache('user');
     }
     $em = new OntoWiki_Extension_Manager($this->_resourcesDirectory, CACHE_PATH . 'extensions_test.json');
     $ex = $em->getExtensions();
     $this->assertCount(2, $ex);
     $this->assertArrayHasKey('test1', $ex);
     $this->assertArrayHasKey('test2', $ex);
     //test local ini
     $this->assertFalse((bool) $ex['test2']->private->sub->b);
 }
 /**
  * Returns the imports associated with a given model and/or useruri.
  * @param  [type]  $model (optional)
  * @param  [type]  $useruri (optional)
  * @param  integer $page (optional)
  * @return [type]
  */
 public function getImports($model = null, $useruri = null, $page = 1)
 {
     $sql = 'SELECT id, model, useruri, resource, tstamp FROM ef_versioning_actions
     WHERE action_type = ' . self::import_action_type . ' ';
     if ($model != null) {
         $sql .= 'AND model = \'' . $model . '\' ';
     }
     if ($useruri != null) {
         $sql .= 'AND useruri = \'' . $useruri . '\' ';
     }
     $sql .= 'ORDER BY id DESC';
     $logger = Erfurt_App::getInstance()->getLog();
     $result = $this->_sqlQuery($sql, $this->getLimit() + 1, $page * $this->getLimit() - $this->getLimit());
     return $result;
 }
 public function onPropertiesActionTemplate($event)
 {
     $store = Erfurt_App::getInstance()->getStore();
     $config = Erfurt_App::getInstance()->getConfig();
     $model = $event->model;
     $graph = $event->graph;
     $resource = $event->resource;
     $predicates = $model->getPredicates();
     $description = $resource->getDescription();
     if ($this->_privateConfig->template->restrictive) {
         foreach ($description as $resource) {
             if (isset($resource[EF_RDF_TYPE])) {
                 $type = $resource[EF_RDF_TYPE][0]['value'];
             } else {
                 return false;
             }
         }
         $query = new Erfurt_Sparql_SimpleQuery();
         $query->setProloguePart('PREFIX erm: <http://vocab.ub.uni-leipzig.de/bibrm/> SELECT DISTINCT ?uri');
         $query->addFrom((string) $event->graph);
         $query->setWherePart('{?template a <' . $this->_template . '> .
                                 ?template erm:providesProperty ?uri .
                                 ?template erm:bindsClass <' . $type . '> .
                             } ');
         $query->setLimit('20');
         $result = $store->sparqlQuery($query);
     }
     if (!empty($result)) {
         // flatten Array and flip keys with values to use array_intersect_key
         $result = array_map(function ($x) {
             return array_flip($x);
         }, $result);
         // FIXME Find a method to add standard properties which will be
         // displayed by default
         $result[] = array(EF_RDF_TYPE => "bla");
         $result[] = array(EF_RDFS_LABEL => "bla");
         $newResult = array();
         foreach ($result as $newKey => $newValue) {
             $newResult = array_merge($newResult, $newValue);
         }
         $matched = array_intersect_key($predicates[(string) $graph], $newResult);
         $matched = array((string) $graph => $matched);
         $event->predicates = $matched;
     } else {
         return false;
     }
     return true;
 }
Exemplo n.º 22
0
 public function serializeGraphToString($graphUri, $pretty = false, $useAc = true)
 {
     $triples = array();
     $store = Erfurt_App::getInstance()->getStore();
     require_once 'Erfurt/Sparql/SimpleQuery.php';
     $sparql = new Erfurt_Sparql_SimpleQuery();
     $sparql->setProloguePart('SELECT ?s ?p ?o');
     $sparql->addFrom($graphUri);
     $sparql->setWherePart('WHERE { ?s ?p ?o }');
     $sparql->setOrderClause('?s ?p ?o');
     $sparql->setLimit(1000);
     $offset = 0;
     while (true) {
         $sparql->setOffset($offset);
         $result = $store->sparqlQuery($sparql, array('result_format' => 'extended', 'use_owl_imports' => false, 'use_additional_imports' => false, 'use_ac' => $useAc));
         $counter = 0;
         foreach ($result['results']['bindings'] as $stm) {
             $s = $stm['s']['value'];
             $p = $stm['p']['value'];
             $o = $stm['o'];
             if (!isset($triples["{$s}"])) {
                 $triples["{$s}"] = array();
             }
             if (!isset($triples["{$s}"]["{$p}"])) {
                 $triples["{$s}"]["{$p}"] = array();
             }
             if ($o['type'] === 'typed-literal') {
                 $triples["{$s}"]["{$p}"][] = array('type' => 'literal', 'value' => $o['value'], 'datatype' => $o['datatype']);
             } else {
                 if ($o['type'] === 'typed-literal') {
                     $oArray = array('type' => 'literal', 'value' => $o['value']);
                     if (isset($o['xml:lang'])) {
                         $oArray['lang'] = $o['xml:lang'];
                     }
                     $triples["{$s}"]["{$p}"][] = $oArray;
                 } else {
                     $triples["{$s}"]["{$p}"][] = array('type' => $o['type'], 'value' => $o['value']);
                 }
             }
             $counter++;
         }
         if ($counter < 1000) {
             break;
         }
         $offset += 1000;
     }
     return json_encode($triples);
 }
 /**
  * inits the controller (e.g. for getting the config)
  *
  * @return void
  */
 public function init()
 {
     parent::init();
     // Disable layout (we want only output xml)
     $this->_helper->layout->disableLayout();
     // Needed here because of the automatic rendering should be deactivated
     //$this->_helper->viewRenderer->setNoRender(true);
     // Add the path of templates needed by this plugin
     //$this->view->addScriptPath(REAL_BASE.'plugins/SemanticSitemap/templates/');
     // get the default store from the registry
     $this->_store = Erfurt_App::getInstance()->getStore();
     // fetch the modellist from the store
     $this->_models = $this->_store->getAvailableModels();
     // todo: where to set the content type? currently we get a Quirks mode :-(
     $this->_response->setRawHeader('Content-Type: application/xml');
 }
Exemplo n.º 24
0
 public function getContents()
 {
     $url = new OntoWiki_Url(array('controller' => 'community', 'action' => 'rate'), array());
     $this->view->actionUrl = (string) $url;
     $query = new Erfurt_Sparql_SimpleQuery();
     $model = new OntoWiki_Model(Erfurt_App::getInstance()->getStore(), $this->_owApp->selectedModel);
     //query ratings for the current resource
     $query->setProloguePart('prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
          prefix ns0: <http://rdfs.org/sioc/ns#>
          prefix ns1: <http://rdfs.org/sioc/types#>
          prefix terms: <http://purl.org/dc/terms/>
          SELECT *')->setWherePart('where {
             ?rating rdf:type ns1:Poll.
             ?rating ns0:about <' . $this->_owApp->selectedResource . '>.
             ?rating ns0:note ?note.
             ?rating ns0:has_creator ?creator}');
     $results = $this->_store->sparqlQuery($query);
     $ratingArray = array();
     $user = (string) $this->_owApp->getUser()->getUri();
     $creator = '0';
     $creatorNote = '0';
     foreach ($results as $result) {
         $ratingArray[] = (double) $result['note'];
         if ($user == $result['creator']) {
             $creator = '1';
             $creatorNote = (double) $result['note'];
         }
     }
     $rating = '0';
     $ratingvalue = '0';
     if (count($ratingArray) != 0) {
         $ratingvalue = round(array_sum($ratingArray) / count($ratingArray), 2);
         $rating = round(array_sum($ratingArray) / count($ratingArray) * 2 - 1, 0);
     }
     $ratingJs = 'var rating = ' . $rating . '; var count =' . count($ratingArray) . '; var creator =' . $creator . '; var creatorNote =' . ($creatorNote - 1) . '; var ratingValue =' . $ratingvalue . ';';
     // append Java Scripts and Style Sheets
     $this->view->headScript()->appendScript($ratingJs);
     $this->view->headScript()->appendFile($this->_config->urlBase . 'extensions/modules/rating/jquery.MetaData.js');
     $this->view->headScript()->appendFile($this->_config->urlBase . 'extensions/modules/rating/jquery.rating.js');
     $this->view->headScript()->appendFile($this->_config->urlBase . 'extensions/modules/rating/jquery.rating.pack.js');
     $this->view->headScript()->appendFile($this->_config->urlBase . 'extensions/modules/rating/rating.js');
     $this->view->headLink()->appendStylesheet($this->_config->urlBase . 'extensions/modules/rating/jquery.rating.css');
     $this->view->count = count($ratingArray);
     $this->view->rating = $ratingvalue;
     $content = $this->render('templates/rating');
     return $content;
 }
Exemplo n.º 25
0
 private function _setupStore()
 {
     //$this->markTestNeedsDatabase();
     $this->markTestNeedsTestConfig();
     // prepare Erfurt_App
     $testConfig = $this->getTestConfig();
     $testConfig->debug = true;
     $testConfig->store->backend = 'memory';
     Erfurt_App::reset();
     Erfurt_App::getInstance(false)->start($testConfig);
     $app = Erfurt_App::getInstance();
     $this->markTestIncomplete('This test doesn\'t work because of an authentication problem in _setupStore');
     // PHP Fatal error:  Call to a member function getUri() on a non-object in Erfurt/library/Erfurt/Versioning.php on line 606
     $this->authenticateDbUser();
     // prepare Model
     $this->_store = $app->getStore();
 }
Exemplo n.º 26
0
 public function onAfterInitController($event)
 {
     //this extension should only run if no explicit model is given via request parameter "m"
     $request = new Zend_Controller_Request_Http();
     if ($request->get("m")) {
         return;
     }
     $config = $this->_privateConfig->toArray();
     $efApp = Erfurt_App::getInstance();
     // disable model box if config value is true and modelmanangement isn't allowed
     if ($config['modelsHide'] && !$efApp->getAc()->isActionAllowed($config['modelsExclusiveRight'])) {
         $registry = OntoWiki_Module_Registry::getInstance();
         $registry->disableModule('modellist', 'main.sidewindow');
     }
     //only do this once (so if the model is changed later, this plugin will not prevent it)
     if ($config['setOnce'] && isset($_SESSION['defaultModelHasBeenSet']) && $_SESSION['defaultModelHasBeenSet']) {
         return;
     }
     $_SESSION['defaultModelHasBeenSet'] = true;
     require_once 'OntoWiki/Module/Registry.php';
     $owApp = OntoWiki::getInstance();
     $efStore = $efApp->getStore();
     $availableModels = $efStore->getAvailableModels();
     if (array_key_exists('modelUri', $config) && array_key_exists($config['modelUri'], $availableModels)) {
         $modelUri = $config['modelUri'];
     } elseif (count($availableModels) === 1) {
         $modelUri = current(array_keys($availableModels));
     } else {
         $modelUri = false;
     }
     // set default model if it could be determined
     if ($modelUri && !$efApp->getAc()->isActionAllowed($config['modelsExclusiveRight'])) {
         if (!($owApp->selectedModel && $modelUri == $owApp->selectedModel->getModelUri())) {
             $owApp->selectedModel = $efStore->getModel($modelUri);
             return;
         }
         if ($config['setSelectedResource']) {
             $owApp->selectedResource = $modelUri;
         }
     }
 }
Exemplo n.º 27
0
 public function onDatagatheringComponentSearch($event)
 {
     $baseUri = 'http://api.sindice.com/v2/search?qt=term&page=1&q=';
     $searchUri = $baseUri . implode('+', $event->termsArray);
     $client = Erfurt_App::getInstance()->getHttpClient($searchUri, array('maxredirects' => 2, 'timeout' => 10));
     $client->setHeaders('Accept', 'application/json');
     $response = $client->request();
     $sindiceResult = json_decode($response->getBody(), true);
     $result = array();
     // unfortunatly json_last_error is PHP >= 5.3.0, so this is not perfect
     // and someday we should us ---> if (json_last_error() == JSON_ERROR_NONE) {
     if ($sindiceResult != null) {
         // TODO Keep order of original sindice result!!!
         foreach ($sindiceResult['entries'] as $row) {
             $title = implode(' - ', $row['title']);
             $uri = $row['link'];
             $result[$uri] = str_replace('|', '&Iota;', $title) . '|' . $uri . '|' . $event->translate->_('Sindice Search');
         }
     }
     return $result;
 }
Exemplo n.º 28
0
 public function testOdFmiLimitQueryWithZendDbIssue782WithoutLimit()
 {
     $this->markTestNeedsZendDb();
     $this->authenticateDbUser();
     $store = Erfurt_App::getInstance()->getStore();
     $store->getNewModel('http://od.fmi.uni-leipzig.de/model/');
     $store->importRdf('http://od.fmi.uni-leipzig.de/model/', $this->_resourceDir . 'fmi.rdf', 'rdf');
     $store->getNewModel('http://od.fmi.uni-leipzig.de/s10/');
     $store->importRdf('http://od.fmi.uni-leipzig.de/s10/', $this->_resourceDir . 'fmi-s10.rdf', 'rdf');
     $sparql = 'PREFIX od: <http://od.fmi.uni-leipzig.de/model/>
     PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
     PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
     SELECT DISTINCT ?lv ?titel ?typ ?wtyp ?von ?bis ?tag ?raum
     FROM <http://od.fmi.uni-leipzig.de/s10/>
     WHERE {{
      ?lv a od:LV . ?lv rdf:type ?typ .
      ?lv rdfs:label ?titel .
      ?lv od:dayOfWeek ?tag .} OPTIONAL {
      ?lv od:locatedAt ?raum .
      ?lv od:startTime ?von .
      ?lv od:endTime ?bis .
      ?lv od:typeOfWeek ?wtyp .
     }}';
     $result = $store->sparqlQuery($sparql, array(Erfurt_Store::RESULTFORMAT => 'extended'));
     $this->assertEquals(680, count($result['bindings']));
     foreach ($result['bindings'] as $row) {
         $this->assertTrue(array_key_exists('lv', $row));
         $this->assertTrue(array_key_exists('titel', $row));
         $this->assertTrue(array_key_exists('typ', $row));
         $this->assertTrue(array_key_exists('tag', $row));
         $this->assertTrue(array_key_exists('wtyp', $row));
         $this->assertTrue(array_key_exists('von', $row));
         $this->assertTrue(array_key_exists('bis', $row));
         $this->assertTrue(array_key_exists('raum', $row));
         if ($row['raum']['type'] !== null) {
             $this->assertEquals('uri', $row['raum']['type']);
             // raum binding is optional
         }
     }
 }
Exemplo n.º 29
0
 public function serializeResourceToString($resource, $graphUri, $pretty = false, $useAc = true, array $additional = array())
 {
     require_once 'Erfurt/Syntax/RdfSerializer/Adapter/RdfXml/StringWriterXml.php';
     require_once 'Erfurt/Syntax/RdfSerializer/Adapter/RdfXml/RdfWriter.php';
     $xmlStringWriter = new Erfurt_Syntax_RdfSerializer_Adapter_RdfXml_StringWriterXml();
     $this->_rdfWriter = new Erfurt_Syntax_RdfSerializer_Adapter_RdfXml_RdfWriter($xmlStringWriter, $useAc);
     $this->_store = Erfurt_App::getInstance()->getStore();
     $this->_graphUri = $graphUri;
     $graph = $this->_store->getModel($graphUri, $useAc);
     $this->_rdfWriter->setGraphUri($graphUri);
     $base = $graph->getBaseUri();
     $this->_rdfWriter->setBase($base);
     $namespaces = Erfurt_App::getInstance()->getNamespaces();
     foreach ($namespaces->getNamespacePrefixes($graphUri) as $prefix => $ns) {
         $this->_rdfWriter->addNamespacePrefix($prefix, $ns);
     }
     $config = Erfurt_App::getInstance()->getConfig();
     if (isset($config->serializer->ad)) {
         $this->_rdfWriter->startDocument($config->serializer->ad);
     } else {
         $this->_rdfWriter->startDocument();
     }
     $this->_rdfWriter->setMaxLevel(1);
     foreach ($additional as $s => $pArray) {
         foreach ($pArray as $p => $oArray) {
             foreach ($oArray as $o) {
                 $sType = substr($s, 0, 2) === '_:' ? 'bnode' : 'uri';
                 $lang = isset($o['lang']) ? $o['lang'] : null;
                 $dType = isset($o['datatype']) ? $o['datatype'] : null;
                 $this->_handleStatement($s, $p, $o['value'], $sType, $o['type'], $lang, $dType);
             }
         }
     }
     $this->_rdfWriter->resetState();
     $this->_serializeResource($resource, $useAc);
     $this->_rdfWriter->endDocument();
     return $this->_rdfWriter->getContentString();
 }
Exemplo n.º 30
0
 /**
  * Builds the SPARQL query
  */
 private function _buildQueries()
 {
     $query = new Erfurt_Sparql_Query2();
     $uri = new Erfurt_Sparql_Query2_IriRef($this->_uri);
     $predVar = new Erfurt_Sparql_Query2_Var('predicate');
     $objVar = new Erfurt_Sparql_Query2_Var('object');
     $query->addTriple($uri, $predVar, $objVar);
     $query->addFilter(new Erfurt_Sparql_Query2_UnaryExpressionNot(new Erfurt_Sparql_Query2_isBlank($objVar)));
     if (!empty($this->_ignoredPredicates)) {
         $or = new Erfurt_Sparql_Query2_ConditionalAndExpression();
         $filter = new Erfurt_Sparql_Query2_Filter($or);
         foreach ($this->_ignoredPredicates as $ignored) {
             $or->addElement(new Erfurt_Sparql_Query2_UnaryExpressionNot(new Erfurt_Sparql_Query2_sameTerm($predVar, new Erfurt_Sparql_Query2_IriRef($ignored))));
         }
         $query->getWhere()->addElement($filter);
     }
     $query->setDistinct(true)->addProjectionVar($predVar)->addProjectionVar($objVar)->getOrder()->add($predVar);
     $queries = array();
     $closure = Erfurt_App::getInstance()->getStore()->getImportsClosure($this->_model->getModelUri(), true);
     $queryGraphs = array_merge(array($this->_graph), $closure);
     foreach ($queryGraphs as $currentGraph) {
         $query->setFroms(array($currentGraph));
         $queries[$currentGraph] = clone $query;
     }
     return $queries;
 }