From d98c5cf3d5d8f7d763de5e5798429aedf646f586 Mon Sep 17 00:00:00 2001 From: Markus Ackermann Date: Mon, 30 Mar 2015 13:17:34 +0200 Subject: [PATCH 1/9] Modified initialisation process in index.php so that the application gets better awareness of it's location (the app base). Now Xodx will will also realize if it it's not directly located at the root of a (virtual) server. Administrators are also able to set the app base directly using a HTTP-Header 'APP_BASE'. --- .gitignore | 3 +++ index.php | 37 ++++++++++++++++++++++++++++++------- 2 files changed, 33 insertions(+), 7 deletions(-) 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/index.php b/index.php index ef90e46..650ae91 100644 --- a/index.php +++ b/index.php @@ -40,17 +40,40 @@ $app->setAppNamespace('Xodx_'); $app->setBaseDir($main_dir); -// Check if Application should be started normaly or to run the Worker +// Check if Application should be started normally or to run the Worker $options = getopt('j'); if (!isset($options['j'])) { - // if the Application is started normaly we assume to be in a server environment - if (isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') { - $protocol = 'https'; + // if the Application is started normally we assume to be in a server environment + + + if (!empty($_SERVER['APP_BASE'])) { + //is we receive an explicit setup for the app base, we use it + $base_uri = $_SERVER['APP_BASE']; } else { - $protocol = 'http'; - } + //otherwise attempt to construct it from default headers + if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') { + $protocol = 'https'; + } else { + $protocol = 'http'; + } + + //use the whole request URI to obtain the app base path, since that seems the only reliable method + $app_path = $_SERVER['REQUEST_URI']; - $base_uri = $protocol . "://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['SCRIPT_NAME']); + //trim trailing query string if present + if(!empty($_SERVER['QUERY_STRING'])) { + $app_path = preg_replace('/'. preg_quote('?' . $_SERVER['QUERY_STRING'], '/') . '$/', '', $app_path); + } + + //remove PHP script name and remaining suffix after it, if it occured explicitly in the requers URI + if(preg_match('/^.*?(\w+\.php.*)$/', $app_path, $script_match) === 1) { + $app_path = str_replace($script_match[1], '', $app_path); + } + + //original hostname of the client query must be handed to the CGI call unmodified for this to work properly + //HTTPD rewrite and proxy usage must be configured accordingly + $base_uri = $protocol . "://" . $_SERVER['HTTP_HOST'] . $app_path; + } // append trailing slash if not present if ($base_uri[strlen($base_uri) - 1] != '/') { From f3135969e9f443491855508a14064728d800e329 Mon Sep 17 00:00:00 2001 From: Franz Teichmann Date: Sat, 2 Jan 2016 14:49:36 +0100 Subject: [PATCH 2/9] initiated statcontroller with triples, followers and a lot to do --- classes/Xodx/StatController.php | 135 ++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 classes/Xodx/StatController.php diff --git a/classes/Xodx/StatController.php b/classes/Xodx/StatController.php new file mode 100644 index 0000000..3d13cb3 --- /dev/null +++ b/classes/Xodx/StatController.php @@ -0,0 +1,135 @@ +_app->getController('Xodx_ApplicationController'); +// $userId = $applicationController->getUser(); +// $userUri = $this->_app->getBaseUri() . '?c=user&id=' . $userId; +// echo $userId; + + echo "Observation : ".$this->getObsId($user); + // - followers + $dataset = "xo:dataset-xoFollower"; + $followers = $this->getFollowers($user); + echo "Followers = ".$followers."\n"; + +//TODO + // get messages sent + + $dataset = "xo:dataset-xoOUT"; + + // get messages received + $dataset = "xo:dataset-xoIN"; + + // get stored triples + $dataset = "xo:dataset-xoTriples"; + $triples = $this->getTriples(); + echo "Triples = ".$triples."\n"; + // - size in kb? - no + // - Access Time in microseconds? +//TODO END + +// $template->disableLayout(); +// $template->setRawContent($output); + +// return $template; + } + + private function getFollowers($user){ + $bootstrap = $this->_app->getBootstrap(); + $model = $bootstrap->getResource('model'); + // SPARQL-Query + $query = 'SELECT COUNT(*) WHERE {'.$user.' ?feed}'; + + $resultset = $model->sparqlQuery($query); + $countResult = $resultset[0]['callret-0']; + + return $countResult; + + } + + private function getSentMessages($user){ + $bootstrap = $this->_app->getBootstrap(); + $model = $bootstrap->getResource('model'); + // SPARQL-Query + //http://xmlns.notu.be/aair#activityVerb http://xmlns.notu.be/aair#Post + //http://xmlns.notu.be/aair#activityVerb http://xmlns.notu.be/aair#Share + // http://xmlns.notu.be/aair#activityActor ?user + $query = 'SELECT COUNT(*) WHERE {'.$user.' ?feed}'; + $countResult = $resultset[0]['callret-0']; + + return $countResult; + + } + private function getReceivedMessages(){ + + return 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}
"; + + + + } + +} From 43eba9868cd01d30b08b27da2f6fd116dc2b5d34 Mon Sep 17 00:00:00 2001 From: Franz Teichmann Date: Mon, 4 Jan 2016 11:20:26 +0100 Subject: [PATCH 3/9] partly finished observation generation --- classes/Xodx/StatController.php | 126 ++++++++++++++++++++++---------- 1 file changed, 86 insertions(+), 40 deletions(-) diff --git a/classes/Xodx/StatController.php b/classes/Xodx/StatController.php index 3d13cb3..393d495 100644 --- a/classes/Xodx/StatController.php +++ b/classes/Xodx/StatController.php @@ -12,74 +12,90 @@ */ class Xodx_StatController extends Saft_Controller { - /** - * This is the username of the currently logedin user - */ - private $_user; - - private function getObsId($user){ - return $user.'observation-'.md5(rand()); - } - /* - * function to generate turtle code for the observation part of the datacube - * TODO finish - */ - private function buildObservationTTL($id,$dataset,$value){ - return ""; - } /** * Function to request a turtle representation of all currently available Observations * @return string */ public function getStatsAction ($template){ //TODO nach User fragen. - $user = "?user"; - //setting up user and userUri // $applicationController = $this->_app->getController('Xodx_ApplicationController'); // $userId = $applicationController->getUser(); // $userUri = $this->_app->getBaseUri() . '?c=user&id=' . $userId; // echo $userId; + $user = "http://localhost/workspace/dssn/xodx/?c=person&id=Franz"; + $time = "1"; + + //initiate observationString + $observationString = ""; - echo "Observation : ".$this->getObsId($user); // - followers $dataset = "xo:dataset-xoFollower"; - $followers = $this->getFollowers($user); - echo "Followers = ".$followers."\n"; - -//TODO + $measureProperty = "xo:follower"; + $value = $this->getFollowers($user); + $observationString .= $this->buildObservation( + $this->getObsId($time), + $dataset, + $user, + $measureProperty, + $time, + $value); // get messages sent - $dataset = "xo:dataset-xoOUT"; - + $measureProperty = "xo:outgoingMessages"; + $value = $this->getSentMessages($user); + $observationString .= $this->buildObservation( + $this->getObsId($time), + $dataset, + $user, + $measureProperty, + $time, + $value); // get messages received $dataset = "xo:dataset-xoIN"; + $measureProperty = "xo:receivedMessages"; + $value = $this->getReceivedMessages($user); + $observationString .= $this->buildObservation( + $this->getObsId($time), + $dataset, + $user, + $measureProperty, + $time, + $value); // get stored triples $dataset = "xo:dataset-xoTriples"; - $triples = $this->getTriples(); - echo "Triples = ".$triples."\n"; + $measureProperty = "xo:triples"; + $value = $this->getTriples(); + $observationString .= $this->buildObservation( + $this->getObsId($time), + $dataset, + $user, + $measureProperty, + $time, + $value); // - size in kb? - no // - Access Time in microseconds? //TODO END -// $template->disableLayout(); -// $template->setRawContent($output); + $template->disableLayout(); + $template->setRawContent($observationString); -// return $template; + return $template; } private function getFollowers($user){ $bootstrap = $this->_app->getBootstrap(); $model = $bootstrap->getResource('model'); // SPARQL-Query - $query = 'SELECT COUNT(*) WHERE {'.$user.' ?feed}'; + // maybe use ? + $query = 'SELECT COUNT(*) WHERE {<'.$user.'> ?x}'; $resultset = $model->sparqlQuery($query); $countResult = $resultset[0]['callret-0']; - return $countResult; + return ($countResult?$countResult:0); } @@ -87,18 +103,34 @@ private function getSentMessages($user){ $bootstrap = $this->_app->getBootstrap(); $model = $bootstrap->getResource('model'); // SPARQL-Query - //http://xmlns.notu.be/aair#activityVerb http://xmlns.notu.be/aair#Post - //http://xmlns.notu.be/aair#activityVerb http://xmlns.notu.be/aair#Share - // http://xmlns.notu.be/aair#activityActor ?user - $query = 'SELECT COUNT(*) WHERE {'.$user.' ?feed}'; + $query = 'SELECT COUNT(*) WHERE {'; + $query .= ' ?x a .'; + $query .= ' ?x .'; + $query .= ' ?x <'.$user.'>'; + $query .= '}'; + + $resultset = $model->sparqlQuery($query); $countResult = $resultset[0]['callret-0']; - return $countResult; + return ($countResult?$countResult:0); } - private function getReceivedMessages(){ + private function getReceivedMessages($user){ - return 0; + $bootstrap = $this->_app->getBootstrap(); + $model = $bootstrap->getResource('model'); + // SPARQL-Query + $query = 'SELECT COUNT(*) WHERE {'; + $query .= ' ?x a .'; + $query .= ' ?x .'; + $query .= ' ?x ?u.'; + $query .= ' <'.$user.'> ?u'; + $query .= '}'; + + $resultset = $model->sparqlQuery($query); + $countResult = $resultset[0]['callret-0']; + + return ($countResult?$countResult:0); } private function getTriples(){ $bootstrap = $this->_app->getBootstrap(); @@ -116,7 +148,6 @@ public function readStoreAction($template){ $model = $bootstrap->getResource('model'); $query = 'SELECT * WHERE {?s ?p ?o}'; $resultset = $model->sparqlQuery($query); - echo ""; foreach($resultset as $line){ @@ -127,9 +158,24 @@ public function readStoreAction($template){ echo ""; } echo "
SubjectPredicateObject
"; + } + private function getObsId($x){ + return 'xo:observation-'.$x.'-'.md5(rand()); + } - + /** + * 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; } } From 025348ef0ebb5ff6e70f9ae1335b0ff90a069a9f Mon Sep 17 00:00:00 2001 From: Franz Teichmann Date: Mon, 4 Jan 2016 16:42:07 +0100 Subject: [PATCH 4/9] todo: access function --- classes/Xodx/StatController.php | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/classes/Xodx/StatController.php b/classes/Xodx/StatController.php index 393d495..79b9447 100644 --- a/classes/Xodx/StatController.php +++ b/classes/Xodx/StatController.php @@ -18,7 +18,6 @@ class Xodx_StatController extends Saft_Controller * @return string */ public function getStatsAction ($template){ -//TODO nach User fragen. //setting up user and userUri // $applicationController = $this->_app->getController('Xodx_ApplicationController'); // $userId = $applicationController->getUser(); @@ -75,10 +74,21 @@ public function getStatsAction ($template){ $measureProperty, $time, $value); - // - size in kb? - no - // - Access Time in microseconds? -//TODO END - + // - Access Time in microseconds + $starttime = microtime(true); + //TODO + usleep(100); + $endtime = microtime(true); + $dataset = "xo:dataset-xoAccess"; + $measureProperty = "xo:Access"; + $value = $endtime - $starttime; + $observationString .= $this->buildObservation( + $this->getObsId($time), + $dataset, + $user, + $measureProperty, + $time, + $value); $template->disableLayout(); $template->setRawContent($observationString); @@ -177,5 +187,4 @@ private function buildObservation($id,$dataset,$user,$measureProperty,$time,$val $observationString .= ".".PHP_EOL; return $observationString; } - } From 76bd183d4477a64b6eb5d17c096fcd61d241e60b Mon Sep 17 00:00:00 2001 From: Franz Teichmann Date: Tue, 5 Jan 2016 17:28:31 +0100 Subject: [PATCH 5/9] finished StatController with Access time measure --- classes/Xodx/StatController.php | 49 +++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/classes/Xodx/StatController.php b/classes/Xodx/StatController.php index 79b9447..4dfb9e0 100644 --- a/classes/Xodx/StatController.php +++ b/classes/Xodx/StatController.php @@ -17,15 +17,14 @@ class Xodx_StatController extends Saft_Controller * Function to request a turtle representation of all currently available Observations * @return string */ - public function getStatsAction ($template){ - //setting up user and userUri -// $applicationController = $this->_app->getController('Xodx_ApplicationController'); -// $userId = $applicationController->getUser(); -// $userUri = $this->_app->getBaseUri() . '?c=user&id=' . $userId; -// echo $userId; - $user = "http://localhost/workspace/dssn/xodx/?c=person&id=Franz"; - $time = "1"; + public function getStatsAction ($template, $user = null, $time = null){ + //setting up time and user + $bootstrap = $this->_app->getBootstrap(); + $request = $bootstrap->getResource('request'); + $time = $request->getValue('time'); + $user = urldecode($request->getValue('user')); + //initiate observationString $observationString = ""; @@ -40,7 +39,7 @@ public function getStatsAction ($template){ $measureProperty, $time, $value); - // get messages sent + // get messages sent $dataset = "xo:dataset-xoOUT"; $measureProperty = "xo:outgoingMessages"; $value = $this->getSentMessages($user); @@ -51,7 +50,7 @@ public function getStatsAction ($template){ $measureProperty, $time, $value); - // get messages received + // get messages received $dataset = "xo:dataset-xoIN"; $measureProperty = "xo:receivedMessages"; $value = $this->getReceivedMessages($user); @@ -62,8 +61,7 @@ public function getStatsAction ($template){ $measureProperty, $time, $value); - - // get stored triples + // get stored triples $dataset = "xo:dataset-xoTriples"; $measureProperty = "xo:triples"; $value = $this->getTriples(); @@ -74,14 +72,10 @@ public function getStatsAction ($template){ $measureProperty, $time, $value); - // - Access Time in microseconds - $starttime = microtime(true); - //TODO - usleep(100); - $endtime = microtime(true); + // get Access Time in microseconds $dataset = "xo:dataset-xoAccess"; $measureProperty = "xo:Access"; - $value = $endtime - $starttime; + $value = $this->getAccessTime($user); $observationString .= $this->buildObservation( $this->getObsId($time), $dataset, @@ -89,6 +83,7 @@ public function getStatsAction ($template){ $measureProperty, $time, $value); + $template->disableLayout(); $template->setRawContent($observationString); @@ -174,6 +169,23 @@ 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 */ @@ -187,4 +199,5 @@ private function buildObservation($id,$dataset,$user,$measureProperty,$time,$val $observationString .= ".".PHP_EOL; return $observationString; } + } From 7abd8eb25fbe007709fd285608cd1db6fc7e93a8 Mon Sep 17 00:00:00 2001 From: Franz Teichmann Date: Fri, 8 Jan 2016 09:33:10 +0100 Subject: [PATCH 6/9] merging with https://github.com/AKSW/xodx/commit/b7de98e3666e686780cb62f25843c37e2a0fc4f3 but correcting spelling mistakes ressource -> resource everywhere --- Makefile | 2 +- README.md | 2 +- classes/Xodx/ActivityController.php | 8 +++---- classes/Xodx/PersonController.php | 11 +++++++-- classes/Xodx/ResourceController.php | 8 +++---- classes/Xodx/StatController.php | 14 +++++++---- classes/Xodx/UserController.php | 2 +- index.php | 37 ++++++----------------------- 8 files changed, 36 insertions(+), 48 deletions(-) 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 index 4dfb9e0..95a0687 100644 --- a/classes/Xodx/StatController.php +++ b/classes/Xodx/StatController.php @@ -17,13 +17,16 @@ class Xodx_StatController extends Saft_Controller * Function to request a turtle representation of all currently available Observations * @return string */ - public function getStatsAction ($template, $user = null, $time = null){ - + public function getStatsAction ($template, $id = null, $time = null){ + //TODO: Where to use Person, where to use user + //- delete model + //re-download xodx, add statcontroller //setting up time and user $bootstrap = $this->_app->getBootstrap(); $request = $bootstrap->getResource('request'); $time = $request->getValue('time'); - $user = urldecode($request->getValue('user')); + $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 = ""; @@ -42,7 +45,7 @@ public function getStatsAction ($template, $user = null, $time = null){ // get messages sent $dataset = "xo:dataset-xoOUT"; $measureProperty = "xo:outgoingMessages"; - $value = $this->getSentMessages($user); + $value = $this->getSentMessages($person); $observationString .= $this->buildObservation( $this->getObsId($time), $dataset, @@ -94,7 +97,7 @@ private function getFollowers($user){ $bootstrap = $this->_app->getBootstrap(); $model = $bootstrap->getResource('model'); // SPARQL-Query - // maybe use ? + // maybe use ?c=user&uri= ? $query = 'SELECT COUNT(*) WHERE {<'.$user.'> ?x}'; $resultset = $model->sparqlQuery($query); @@ -125,6 +128,7 @@ private function getReceivedMessages($user){ $bootstrap = $this->_app->getBootstrap(); $model = $bootstrap->getResource('model'); // SPARQL-Query + //subscribed to $query = 'SELECT COUNT(*) WHERE {'; $query .= ' ?x a .'; $query .= ' ?x .'; 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( diff --git a/index.php b/index.php index 650ae91..ef90e46 100644 --- a/index.php +++ b/index.php @@ -40,41 +40,18 @@ $app->setAppNamespace('Xodx_'); $app->setBaseDir($main_dir); -// Check if Application should be started normally or to run the Worker +// Check if Application should be started normaly or to run the Worker $options = getopt('j'); if (!isset($options['j'])) { - // if the Application is started normally we assume to be in a server environment - - - if (!empty($_SERVER['APP_BASE'])) { - //is we receive an explicit setup for the app base, we use it - $base_uri = $_SERVER['APP_BASE']; + // if the Application is started normaly we assume to be in a server environment + if (isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') { + $protocol = 'https'; } else { - //otherwise attempt to construct it from default headers - if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') { - $protocol = 'https'; - } else { - $protocol = 'http'; - } - - //use the whole request URI to obtain the app base path, since that seems the only reliable method - $app_path = $_SERVER['REQUEST_URI']; - - //trim trailing query string if present - if(!empty($_SERVER['QUERY_STRING'])) { - $app_path = preg_replace('/'. preg_quote('?' . $_SERVER['QUERY_STRING'], '/') . '$/', '', $app_path); - } - - //remove PHP script name and remaining suffix after it, if it occured explicitly in the requers URI - if(preg_match('/^.*?(\w+\.php.*)$/', $app_path, $script_match) === 1) { - $app_path = str_replace($script_match[1], '', $app_path); - } - - //original hostname of the client query must be handed to the CGI call unmodified for this to work properly - //HTTPD rewrite and proxy usage must be configured accordingly - $base_uri = $protocol . "://" . $_SERVER['HTTP_HOST'] . $app_path; + $protocol = 'http'; } + $base_uri = $protocol . "://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['SCRIPT_NAME']); + // append trailing slash if not present if ($base_uri[strlen($base_uri) - 1] != '/') { $base_uri .= '/'; From 985ff709bc627d97a9bf5a60008f92a8488645ac Mon Sep 17 00:00:00 2001 From: Franz Teichmann Date: Fri, 8 Jan 2016 11:05:20 +0100 Subject: [PATCH 7/9] finished StatController, improved message-measure functions --- classes/Xodx/StatController.php | 39 +++++++++++++++++---------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/classes/Xodx/StatController.php b/classes/Xodx/StatController.php index 95a0687..32ef2f7 100644 --- a/classes/Xodx/StatController.php +++ b/classes/Xodx/StatController.php @@ -32,9 +32,10 @@ public function getStatsAction ($template, $id = null, $time = null){ $observationString = ""; // - followers - $dataset = "xo:dataset-xoFollower"; - $measureProperty = "xo:follower"; - $value = $this->getFollowers($user); + $dataset = "xo:dataset-xofollowedFeeds"; + $measureProperty = "xo:followedFeeds"; + $value = $this->getFollowedfeeds($user,$person); + $observationString = $value; $observationString .= $this->buildObservation( $this->getObsId($time), $dataset, @@ -56,7 +57,7 @@ public function getStatsAction ($template, $id = null, $time = null){ // get messages received $dataset = "xo:dataset-xoIN"; $measureProperty = "xo:receivedMessages"; - $value = $this->getReceivedMessages($user); + $value = $this->getReceivedMessages($person); $observationString .= $this->buildObservation( $this->getObsId($time), $dataset, @@ -86,35 +87,37 @@ public function getStatsAction ($template, $id = null, $time = null){ $measureProperty, $time, $value); - $template->disableLayout(); $template->setRawContent($observationString); return $template; } - private function getFollowers($user){ + private function getFollowedfeeds($user,$person){ $bootstrap = $this->_app->getBootstrap(); $model = $bootstrap->getResource('model'); // SPARQL-Query - // maybe use ?c=user&uri= ? - $query = 'SELECT COUNT(*) WHERE {<'.$user.'> ?x}'; + $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']; - + var_dump ($resultset); return ($countResult?$countResult:0); } - private function getSentMessages($user){ + private function getSentMessages($person){ $bootstrap = $this->_app->getBootstrap(); $model = $bootstrap->getResource('model'); // SPARQL-Query $query = 'SELECT COUNT(*) WHERE {'; - $query .= ' ?x a .'; - $query .= ' ?x .'; - $query .= ' ?x <'.$user.'>'; + $query .= ' ?x a .'; + $query .= ' ?x <'.$person.'>'; $query .= '}'; $resultset = $model->sparqlQuery($query); @@ -123,17 +126,15 @@ private function getSentMessages($user){ return ($countResult?$countResult:0); } - private function getReceivedMessages($user){ + private function getReceivedMessages($person){ $bootstrap = $this->_app->getBootstrap(); $model = $bootstrap->getResource('model'); // SPARQL-Query - //subscribed to $query = 'SELECT COUNT(*) WHERE {'; - $query .= ' ?x a .'; - $query .= ' ?x .'; - $query .= ' ?x ?u.'; - $query .= ' <'.$user.'> ?u'; + $query .= ' ?x a .'; + $query .= ' ?x ?maker.'; + $query .= ' <'.$person.'> ?maker'; $query .= '}'; $resultset = $model->sparqlQuery($query); From f8c46d47c55c28a8df87c2646ee5a1c9916b8e88 Mon Sep 17 00:00:00 2001 From: Franz Teichmann Date: Fri, 8 Jan 2016 11:18:29 +0100 Subject: [PATCH 8/9] removed var_dump --- classes/Xodx/StatController.php | 1 - 1 file changed, 1 deletion(-) diff --git a/classes/Xodx/StatController.php b/classes/Xodx/StatController.php index 32ef2f7..65884d0 100644 --- a/classes/Xodx/StatController.php +++ b/classes/Xodx/StatController.php @@ -106,7 +106,6 @@ private function getFollowedfeeds($user,$person){ $resultset = $model->sparqlQuery($query); $countResult = $resultset[0]['callret-0']; - var_dump ($resultset); return ($countResult?$countResult:0); } From bc70252cf2277039a674dfd86186be45d7ee6449 Mon Sep 17 00:00:00 2001 From: Franz Teichmann Date: Fri, 8 Jan 2016 12:57:51 +0100 Subject: [PATCH 9/9] fixed output error --- classes/Xodx/StatController.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/classes/Xodx/StatController.php b/classes/Xodx/StatController.php index 65884d0..e1bc58a 100644 --- a/classes/Xodx/StatController.php +++ b/classes/Xodx/StatController.php @@ -18,8 +18,6 @@ class Xodx_StatController extends Saft_Controller * @return string */ public function getStatsAction ($template, $id = null, $time = null){ - //TODO: Where to use Person, where to use user - //- delete model //re-download xodx, add statcontroller //setting up time and user $bootstrap = $this->_app->getBootstrap(); @@ -32,10 +30,13 @@ public function getStatsAction ($template, $id = null, $time = null){ $observationString = ""; // - followers - $dataset = "xo:dataset-xofollowedFeeds"; - $measureProperty = "xo:followedFeeds"; + $dataset = "xo:dataset-xofollowers"; + $measureProperty = "xo:followers"; + + //!!!!! + //IMPORTANT! Assuming: FOLLOWED FEEDS OF PERSONS = PERSONS THAT FOLLOW THE USER! + //!!!!! $value = $this->getFollowedfeeds($user,$person); - $observationString = $value; $observationString .= $this->buildObservation( $this->getObsId($time), $dataset,