diff --git a/.gitignore b/.gitignore index 94a9fe1..405c800 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,6 @@ resources/bootstrap/ resources/jquery/ xodx.log config.ini + +.idea/ +*.iml diff --git a/Makefile b/Makefile index 1a1d682..ed5f8fa 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ # vim: set ai ts=4 sw=4 et!: # Set Zend and bootstrap version -ZENDVERSION=1.12.0 +ZENDVERSION=1.12.17 TWBSVERSION=2.3.2 TW_BOOTSTRAP_SRC='http://getbootstrap.com/${TWBSVERSION}/assets/bootstrap.zip' diff --git a/README.md b/README.md index 73c65dc..12dcf31 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Because this software is written in PHP you'll need php (>= 5.3.7) with the bind Take the prepared `config.ini-dist` file, copy it to `config.ini` and configure it according to your system setup. If you have an OntoWiki runnnig you can copy the database connection section (`store.*`) into the `config.ini` of xodx. To import the initial base ontology for Erfurt you have to allow virtuoso to read the xodx directory. -You can configure this by adding the directory to `DirsAllowed` in your `virtuoso.ini` (on debian systems you can find it at `/etc/virtuoso-opensource-6.1/virtuoso.ini`). +You can configure this by adding the directory to `DirsAllowed` in your `virtuoso.ini` (on debian systems you can find it at `/etc/virtuoso-opensource-6.1/virtuoso.ini`, if you are using the debian packages; or `/var/lib/virtuoso/db/virtuoso.ini`, if you are using the lod2 package or if you have build virtuoso from the source). ### Erfurt, lib-dssn and Saft Run `make submodules` to clone Erfurt, lib-dssn-php and Saft. diff --git a/classes/Xodx/ActivityController.php b/classes/Xodx/ActivityController.php index 99d2832..81ba1d9 100644 --- a/classes/Xodx/ActivityController.php +++ b/classes/Xodx/ActivityController.php @@ -247,7 +247,7 @@ public function addActivity ($actorUri, $verbUri, $object) $subscribeFeeds[$activityUri] = $activityFeedUri; // II. general statements of object resource - // if $type == 'Uri' the ressource of aair:activityObject statement allready exists + // if $type == 'Uri' the resource of aair:activityObject statement allready exists // e.g. 'Sharing a Bookmark (URI)' and 'Friending' if ($type != 'Uri') { $objectFeedUri = $baseUri . '?c=feed&a=getFeed&uri=' . urlencode($objectUri); @@ -458,7 +458,7 @@ public function getActivities ($resourceUri) return null; } - // get Type of Ressource and go on + // get Type of resource and go on $resourceController = $this->_app->getController('Xodx_ResourceController'); $type = $resourceController->getType($resourceUri); @@ -548,8 +548,8 @@ public function getActivities ($resourceUri) if (!empty($objectResult[0]['content'])) { $activity['objectContent'] = $objectResult[0]['content']; } - if (!empty($objectResult[0]['image'])) { - $activity['objectImage'] = $objectResult[0]['image']; + if (!empty($objectResult[0]['image'])) { + $activity['objectImage'] = $objectResult[0]['image']; } // set data from activity to get valid feed } else { diff --git a/classes/Xodx/PersonController.php b/classes/Xodx/PersonController.php index 0f53c13..a4907c6 100644 --- a/classes/Xodx/PersonController.php +++ b/classes/Xodx/PersonController.php @@ -131,9 +131,16 @@ public function rdfAction ($template) $model = $bootstrap->getResource('model'); $request = $bootstrap->getResource('request'); - $objectId = $request->getValue('id', 'get'); + + $personUri = $request->getValue('uri', 'get'); + $id = $request->getValue('id', 'get'); $controller = $request->getValue('c', 'get'); - $personUri = $this->_app->getBaseUri() . '?c=' . $controller . '&id=' . $objectId; + + // get URI + if ($id !== null) { + $personUri = $this->_app->getBaseUri() . '?c=' . $controller . '&id=' . $id; + } + $documentUri = new Saft_Url($request); $mimetypeHelper = $this->_app->getHelper('Saft_Helper_MimetypeHelper'); diff --git a/classes/Xodx/ResourceController.php b/classes/Xodx/ResourceController.php index 31427ce..7dabcb4 100644 --- a/classes/Xodx/ResourceController.php +++ b/classes/Xodx/ResourceController.php @@ -164,8 +164,8 @@ public function imgAction ($template) /** * - * get the type of a ressource - * @param $resourceUri a URI of a ressource + * get the type of a resource + * @param $resourceUri a URI of a resource */ public function getType ($resourceUri) { @@ -191,9 +191,9 @@ public function getType ($resourceUri) /** * - * methods looks up a ressource to get the Uri of the activity feed + * methods looks up a resource to get the Uri of the activity feed * and returns it if succesfull - * @param $resourceUri - the URI of the ressource to be looked up + * @param $resourceUri - the URI of the resource to be looked up */ public function getActivityFeedUri($resourceUri) { diff --git a/classes/Xodx/StatController.php b/classes/Xodx/StatController.php new file mode 100644 index 0000000..e1bc58a --- /dev/null +++ b/classes/Xodx/StatController.php @@ -0,0 +1,208 @@ +_app->getBootstrap(); + $request = $bootstrap->getResource('request'); + $time = $request->getValue('time'); + $user = $this->_app->getBaseUri().'?c=user&id='.urldecode($request->getValue('id')); + $person = $this->_app->getBaseUri().'?c=person&id='.urldecode($request->getValue('id')); + + //initiate observationString + $observationString = ""; + + // - followers + $dataset = "xo:dataset-xofollowers"; + $measureProperty = "xo:followers"; + + //!!!!! + //IMPORTANT! Assuming: FOLLOWED FEEDS OF PERSONS = PERSONS THAT FOLLOW THE USER! + //!!!!! + $value = $this->getFollowedfeeds($user,$person); + $observationString .= $this->buildObservation( + $this->getObsId($time), + $dataset, + $user, + $measureProperty, + $time, + $value); + // get messages sent + $dataset = "xo:dataset-xoOUT"; + $measureProperty = "xo:outgoingMessages"; + $value = $this->getSentMessages($person); + $observationString .= $this->buildObservation( + $this->getObsId($time), + $dataset, + $user, + $measureProperty, + $time, + $value); + // get messages received + $dataset = "xo:dataset-xoIN"; + $measureProperty = "xo:receivedMessages"; + $value = $this->getReceivedMessages($person); + $observationString .= $this->buildObservation( + $this->getObsId($time), + $dataset, + $user, + $measureProperty, + $time, + $value); + // get stored triples + $dataset = "xo:dataset-xoTriples"; + $measureProperty = "xo:triples"; + $value = $this->getTriples(); + $observationString .= $this->buildObservation( + $this->getObsId($time), + $dataset, + $user, + $measureProperty, + $time, + $value); + // get Access Time in microseconds + $dataset = "xo:dataset-xoAccess"; + $measureProperty = "xo:Access"; + $value = $this->getAccessTime($user); + $observationString .= $this->buildObservation( + $this->getObsId($time), + $dataset, + $user, + $measureProperty, + $time, + $value); + $template->disableLayout(); + $template->setRawContent($observationString); + + return $template; + } + + private function getFollowedfeeds($user,$person){ + $bootstrap = $this->_app->getBootstrap(); + $model = $bootstrap->getResource('model'); + // SPARQL-Query + $query = 'SELECT COUNT(?friendperson) WHERE {'; + $query .= ' <'.$user.'> ?resource.'; + $query .= ' ?resource ?feed.'; + $query .= ' ?friendperson ?feed.'; + $query .= ' <'.$person.'> ?friendperson'; + $query .= '} GROUP BY ?friendperson'; + + $resultset = $model->sparqlQuery($query); + $countResult = $resultset[0]['callret-0']; + return ($countResult?$countResult:0); + + } + + private function getSentMessages($person){ + $bootstrap = $this->_app->getBootstrap(); + $model = $bootstrap->getResource('model'); + // SPARQL-Query + $query = 'SELECT COUNT(*) WHERE {'; + $query .= ' ?x a .'; + $query .= ' ?x <'.$person.'>'; + $query .= '}'; + + $resultset = $model->sparqlQuery($query); + $countResult = $resultset[0]['callret-0']; + + return ($countResult?$countResult:0); + + } + private function getReceivedMessages($person){ + + $bootstrap = $this->_app->getBootstrap(); + $model = $bootstrap->getResource('model'); + // SPARQL-Query + $query = 'SELECT COUNT(*) WHERE {'; + $query .= ' ?x a .'; + $query .= ' ?x ?maker.'; + $query .= ' <'.$person.'> ?maker'; + $query .= '}'; + + $resultset = $model->sparqlQuery($query); + $countResult = $resultset[0]['callret-0']; + + return ($countResult?$countResult:0); + } + private function getTriples(){ + $bootstrap = $this->_app->getBootstrap(); + $model = $bootstrap->getResource('model'); + $query = 'SELECT COUNT(*) WHERE {?s ?p ?o}'; + + $resultset = $model->sparqlQuery($query); + $triples = $resultset[0]['callret-0']; + return $triples; + } + + + public function readStoreAction($template){ + $bootstrap = $this->_app->getBootstrap(); + $model = $bootstrap->getResource('model'); + $query = 'SELECT * WHERE {?s ?p ?o}'; + $resultset = $model->sparqlQuery($query); + + echo ""; + foreach($resultset as $line){ + echo ""; + foreach($line as $value){ + echo ""; + } + echo ""; + } + echo "
SubjectPredicateObject
{$value}
"; + } + + private function getObsId($x){ + return 'xo:observation-'.$x.'-'.md5(rand()); + } + + private function getAccessTime($user){ + $starttime = microtime(true); + + $client = new Zend_Http_Client(); + $client->setUri($this->_app->getBaseUri()); + $client->setParameterGet(array( + 'c' => 'feed', + 'a' => 'getFeed', + 'uri' => $user, + )); + $response = $client->request(); + $feed = $response->getBody(); + + $endtime = microtime(true); + return $endtime - $starttime; + } + + /** + * function to generate turtle code for the observation part of the datacube + */ + private function buildObservation($id,$dataset,$user,$measureProperty,$time,$value){ + $observationString = ""; + $observationString .= $id." a qb:Observation;".PHP_EOL; + $observationString .= "qb:dataSet ".$dataset.";".PHP_EOL; + $observationString .= "xo:refAgent <".$user.">;".PHP_EOL; + $observationString .= "xo:refTime ".$time.";".PHP_EOL; + $observationString .= $measureProperty." ".$value.";".PHP_EOL; + $observationString .= ".".PHP_EOL; + return $observationString; + } + +} diff --git a/classes/Xodx/UserController.php b/classes/Xodx/UserController.php index eff85fb..e9436f1 100644 --- a/classes/Xodx/UserController.php +++ b/classes/Xodx/UserController.php @@ -179,7 +179,7 @@ private function _subscribeToFeed ($subscriberUri, $feedUri, $local = false) $nsDssn = 'http://purl.org/net/dssn/'; $nsRdf = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'; - $subUri = $this->_app->getBaseUri() . '&c=ressource&id=' . md5(rand()); + $subUri = $this->_app->getBaseUri() . '&c=resource&id=' . md5(rand()); $cbUri = $this->_app->getBaseUri() . '?c=push&a=callback'; $subscription = array(