Esempio n. 1
0
 private function count($pattern = true)
 {
     $pattern = $pattern ? $this->load_pattern() : '';
     $query = "\nSELECT COUNT(?post) as ?count\nWHERE {\n\t?post rdf:type sioct:MicroblogPost .\n\t{$pattern}\n} \n";
     $count = SMOBStore::query($query);
     return $count[0]['count'];
 }
Esempio n. 2
0
 function get_uris()
 {
     $rs = SMOBStore::query("\n\tSELECT DISTINCT ?person ?user WHERE {\n\t  ?post rdf:type sioct:MicroblogPost .\n\t  ?post sioc:has_creator ?user .\n\t  ?post foaf:maker ?person .\n\t  ?person foaf:nick '{$user}' .\n\t}\n\t\t");
     if ($rs) {
         foreach ($rs as $row) {
             $r[$row['person']] = $row['user'];
         }
     }
     return $r;
 }
Esempio n. 3
0
 private function get_location()
 {
     $loc = SMOBTools::location();
     if ($loc) {
         $uri = $loc[0];
         $loc = SMOBStore::query("SELECT ?lat ?long WHERE { <{$uri}> geo:lat ?lat ; geo:long ?long .}");
         return array($loc[0]['lat'], $loc[0]['long']);
     } else {
         return array(0, 0);
     }
 }
Esempio n. 4
0
function existing_uris($term, $type)
{
    $uris = array();
    if ($type == 'user') {
        $query = "\nSELECT DISTINCT ?uri\nWHERE {\n\t[] sioc:addressed_to ?uri .\n\t?uri sioc:name '{$term}' .\n}";
    } elseif (in_array($type, array('tag', 'location'))) {
        $query = "\nSELECT DISTINCT ?uri\nWHERE {\n\t[] tags:associatedTag '{$term}' ;\n\t\tmoat:tagMeaning ?uri .\n}";
    }
    $res = SMOBStore::query($query);
    foreach ($res as $r) {
        $uris[] = $r['uri'];
    }
    return $uris;
}
Esempio n. 5
0
 function get_relationships($user_uri)
 {
     $rel_persons = array();
     //"<" + user_uri + "> <" + rel_types[i] + "> <" + persons[i] + "> . ";
     $query = "SELECT ?person ?rel_type ?rel_label FROM <{$user_uri}> WHERE {\n      <{$user_uri}> ?rel_type ?person . \n      ?person a foaf:person . \n      ?rel_type rdfs:isDefinedBy <http://purl.org/vocab/relationship/> . \n      ?rel_type rdfs:label ?rel_label . }";
     // rdfs:subPropertyOf foaf:knows
     $query = "SELECT ?person ?rel_type ?rel_label FROM <{$user_uri}> WHERE {\n       <{$user_uri}> ?rel_type ?person . \n       FILTER(REGEX(?rel_type, 'http://purl.org/vocab/relationship/', 'i')).\n       OPTIONAL { ?rel_type rdfs:label ?rel_label  } \n       }";
     $data = SMOBStore::query($query);
     error_log("rels", 0);
     error_log(print_r($data, 1), 0);
     if ($data) {
         foreach ($data as $i => $t) {
             $rel_persons[$t['rel_type']] = $t['person'];
             //$persons[$i] = $t['person'];
         }
     }
     return $rel_persons;
 }
Esempio n. 6
0
 private function load_tweet($tweet)
 {
     $id = $tweet->id;
     $username = $tweet->user->screen_name;
     $local = $this->user;
     $uri = "http://twitter.com/{$username}/status/{$id}";
     $content = $tweet->text;
     $userid = $tweet->user->id;
     $name = $tweet->user->name;
     $ts = date('c', time($tweet->created_at));
     $user_uri = "http://twitter.com/{$username}";
     $user_foaf_uri = "http://twitter.com/{$username}#me";
     $depiction = $tweet->user->profile_image_url;
     $triples = array();
     $triples[] = array(SMOBTools::uri($uri), "a", "sioct:MicroblogPost");
     $triples[] = array("sioc:has_container", SMOBTools::uri('http://twitter.com/'));
     $triples[] = array("sioc:has_creator", SMOBTools::uri($user_uri));
     $triples[] = array("foaf:maker", SMOBTools::uri($user_foaf_uri));
     $triples[] = array("dct:created", SMOBTools::date($ts));
     $triples[] = array("dct:title", SMOBTools::literal("Update - " . $ts));
     $triples[] = array("sioc:content", SMOBTools::literal($content));
     if (strpos($content, '@' . $this->user) !== false) {
         $triples[] = array("sioc:addressed_to", SMOBTools::uri(FOAF_URI));
         $triples[] = array("sioc:addressed_to", SMOBTools::uri('http://twitter.com/' . $this->user . '#me'));
         $triples[] = array(SMOBTools::uri(FOAF_URI), 'sioc:name', SMOBTools::literal($this->user));
         $triples[] = array(SMOBTools::uri('http://twitter.com/' . $this->user . '#me'), 'sioc:name', SMOBTools::literal($this->user));
     }
     $triples[] = array(SMOBTools::uri($user_foaf_uri), "foaf:name", SMOBTools::literal($name));
     $triples[] = array("foaf:depiction", SMOBTools::uri($depiction));
     $opo_uri = $uri . '#presence';
     $triples[] = array(SMOBTools::uri($opo_uri), "a", "opo:OnlinePresence");
     $triples[] = array("opo:declaredOn", SMOBTools::uri($user_uri));
     $triples[] = array("opo:declaredBy", SMOBTools::uri($user_foaf_uri));
     $triples[] = array("opo:StartTime", SMOBTools::date($ts));
     $triples[] = array("opo:customMessage", SMOBTools::uri($uri));
     $graph = SMOB_ROOT . "data/twitter/{$id}";
     $rdf = SMOBTools::render_sparql_triples($triples);
     $query = "INSERT INTO <{$graph}> { {$rdf} }";
     $res = SMOBStore::query($query);
 }
Esempio n. 7
0
 public function triples_from_graph($graph)
 {
     $turtle = "";
     $query = "\nSELECT *\nWHERE { \n  GRAPH <{$graph}> {\n    ?s ?p ?o\n  }\n}";
     $data = SMOBStore::query($query);
     foreach ($data as $triple) {
         $s = $triple['s'];
         $p = $triple['p'];
         $o = $triple['o'];
         $ot = $triple['o type'];
         $odt = in_array('o datatype', array_keys($triple)) ? '^^<' . $triple['o datatype'] . '>' : '';
         $turtle .= "<{$s}> <{$p}> ";
         $turtle .= $ot == 'uri' ? "<{$o}> " : "\"{$o}\"{$odt} ";
         $turtle .= ". ";
     }
     return $turtle;
 }
Esempio n. 8
0
 // Remove a follower
 if ($t == 'follower') {
     // @TODO: has it sense that the user remove a follower?. Then the follower should also be notified to remove the current user as following
     // Instead, when the request comes from another user removing a following, the action will not be run as there is not authentication
     $remote_user = $u;
     $local_user = SMOBTools::user_uri();
     $follow = "<{$remote_user}> sioc:follows <{$local_user}> . ";
     $local = "DELETE FROM <" . SMOB_ROOT . "data/followers> { {$follow} }";
     SMOBStore::query($local);
     error_log("DEBUG: Removed follower {$remote_user} with the query: {$local}", 0);
 } elseif ($t == 'following') {
     $remote_user = $u;
     $local_user = SMOBTools::user_uri();
     $follow = "<{$local_user}> sioc:follows <{$remote_user}> . ";
     $local = "DELETE FROM <" . SMOB_ROOT . "data/followings> { {$follow} }";
     SMOBStore::query($local);
     error_log("DEBUG: Removed following {$remote_user} with the query: {$local}", 0);
     // And ping to update the followers list remotely
     //$ping = str_replace("me","remove", $u)."/follower/$local_user";
     $ping = SMOBTools::host($u) . "/remove/follower/{$local_user}";
     error_log("DEBUG: Sent {$ping}", 0);
     $result = SMOBTools::do_curl($ping);
     error_log("DEBUG: Server answer: " . join(' ', $result), 0);
     // Unsubscribe to the Hub
     //@TODO: following Hub should be stored?,
     $remote_user_feed = $remote_user . FEED_URL_PATH;
     $xml = simplexml_load_file($remote_user_feed);
     if (count($xml) == 0) {
         return;
     }
     $link_attributes = $xml->channel->link->attributes();
Esempio n. 9
0
 public function turtle()
 {
     // Function similar to raw, but it returns the turtle triples as text instead of a new page
     $turtle = "";
     $uri = $this->graph();
     $query = "\nSELECT *\nWHERE { \n\tGRAPH <{$uri}> {\n\t\t?s ?p ?o\n\t}\n}";
     $data = SMOBStore::query($query);
     foreach ($data as $triple) {
         $s = $triple['s'];
         $p = $triple['p'];
         $o = $triple['o'];
         $ot = $triple['o type'];
         $odt = in_array('o datatype', array_keys($triple)) ? '^^<' . $triple['o datatype'] . '>' : '';
         $turtle .= "<{$s}> <{$p}> ";
         $turtle .= $ot == 'uri' ? "<{$o}> " : "\"{$o}\"{$odt} ";
         $turtle .= ". ";
     }
     return $turtle;
 }
Esempio n. 10
0
<?php

require_once dirname(__FILE__) . "/../lib/smob/SMOBTools.php";
require_once dirname(__FILE__) . "/../lib/smob/SMOBStore.php";
require_once dirname(__FILE__) . "/../config/config.php";
$triples = $_POST['triples'];
error_log($triples, 0);
error_log(SMOB_ROOT, 0);
$query = "DELETE FROM <" . SMOB_ROOT . "me> ";
$res = SMOBStore::query($query);
#error_log(var_dump($res, 1), 0);
$query = "INSERT INTO <" . SMOB_ROOT . "me> { {$triples} }";
$res = SMOBStore::query($query);
#error_log(var_dump($res, 1), 0);
print "Your private profile has been stored...\n";
error_log("private profile stored");
Esempio n. 11
0
function setupUser()
{
    include_once dirname(__FILE__) . '/../config/config.php';
    $foaf_uri = $_GET['foaf_uri'];
    $twitter_read = $_GET['twitter_read'] == 'on' ? 1 : 0;
    $twitter_post = $_GET['twitter_post'] == 'on' ? 1 : 0;
    $twitter_login = $_GET['twitter_login'];
    $twitter_pass = $_GET['twitter_pass'];
    $auth = $_GET['auth'];
    if ($foaf_uri) {
        if (!SMOBTools::checkFoaf($foaf_uri)) {
            print "<p>An error occurred with your FOAF URI. <b>Please ensure that it dereferences to an RDF file and that this file contains information about your URI.<b><br/>You will have to <a href='{$smob_root}'>restart the install process<a/></p>";
            unlink(dirname(__FILE__) . '/../config/config.php');
            die;
        }
    } else {
        if (!$foaf_uri) {
            $foaf_uri = SMOB_ROOT . 'me#id';
            $username = $_GET['username'];
            $depiction = $_GET['depiction'];
            $profile = "\nINSERT INTO <" . SMOB_ROOT . "/profile> {\t\t\t\n<{$foaf_uri}> a foaf:Person ; \n\tfoaf:name \"{$username}\" ;\n\tfoaf:depiction <{$depiction}> .\n}";
            SMOBStore::query($profile);
        }
    }
    $config = "\ndefine('FOAF_URI', '{$foaf_uri}');\n\ndefine('TWITTER_READ', '{$twitter_read}');\ndefine('TWITTER_POST', '{$twitter_post}');\n\ndefine('TWITTER_USER', '{$twitter_login}');\ndefine('TWITTER_PASS', '{$twitter_pass}');\n\ndefine('AUTH', '{$auth}');\n\t\t\n?>";
    $f = fopen(dirname(__FILE__) . '/../config/config.php', 'a');
    fwrite($f, $config);
    fclose($f);
    print "<p>Enjoy, you can now access your <a href='.'>SMOB Hub</a> !<br/>\n\tLog-in using the 'Authenticate' link and start writing microblog po.<br/>\n\tAlso, be sure to restrict access to the <code>config/</code> directory.</p>";
}
Esempio n. 12
0
 function ask($query)
 {
     return SMOBStore::query("ASK { {$query} }", true);
 }
Esempio n. 13
0
    function get_foaf_rsakey($uri)
    {
        if ($uri) {
            // while not support for several certificates/keys, delete the existing
            // ones before insert another to ensure there's only one
            $query = '
        PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
        PREFIX rsa: <http://www.w3.org/ns/auth/rsa#> 
        PREFIX cert: <http://www.w3.org/ns/auth/cert#>
        PREFIX foaf: <http://xmlns.com/foaf/0.1/> .
        DELETE {
          ?sig a rsa:RSAPublicKey .
          ?sig cert:identity <' . $uri . '> .
					?sig rsa:modulus ?mod .
					?sig rsa:public_exponent ?exp .
        }
        WHERE {
          ?sig a rsa:RSAPublicKey;
              cert:identity <' . $uri . '> ;
					    rsa:modulus ?mod ;
					    rsa:public_exponent ?exp .
        }';
            $res = SMOBStore::query($query);
            error_log('result deleting:', 0);
            error_log(print_r($res, 1), 0);
            SMOBStore::query('LOAD <' . $uri . '>');
            // should it be stored in a named graph?
            SMOBStore::query('LOAD <' . $uri . '> INTO <' . $uri . '>');
            // then the delete would be just
            // 'DELETE FROM <'.$uri.'>'
            /* list names */
            $q = '
			  PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
			  PREFIX rsa: <http://www.w3.org/ns/auth/rsa#> 
			  PREFIX cert: <http://www.w3.org/ns/auth/cert#>
			  PREFIX foaf: <http://xmlns.com/foaf/0.1/> .
			  SELECT ?mod ?exp  WHERE {
				?sig cert:identity ?person .
				?sig a rsa:RSAPublicKey;
					rsa:modulus [ cert:hex ?mod ] ;
					rsa:public_exponent [ cert:decimal ?exp ] .
			  }';
            // for some reason the previous query doesn't work in ARC
            // sig is not needed, replaced by bnode
            $q = '
			  PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
			  PREFIX rsa: <http://www.w3.org/ns/auth/rsa#> 
			  PREFIX cert: <http://www.w3.org/ns/auth/cert#>
			  PREFIX foaf: <http://xmlns.com/foaf/0.1/> .
			  SELECT ?mod ?exp  WHERE {
				[] a rsa:RSAPublicKey;
          cert:identity <' . $uri . '>;
					rsa:modulus ?mod ;
					rsa:public_exponent ?exp .
			  }';
            $res = SMOBStore::query($q);
            if ($res) {
                // TODO: support several keys for webid uri?
                $modulus = SMOBAuth::cleanhex($res[0]['mod']);
                $exponent = SMOBAuth::cleanhex($res[0]['exp']);
                error_log('modulus: ', 0);
                error_log($modulus, 0);
                error_log('exponent: ', 0);
                error_log($exponent, 0);
            }
            if ($modulus && $exponent) {
                return array('modulus' => $modulus, 'exponent' => dechex($exponent));
            }
        }
    }