function LDP_get_prefix($path, $uri, $type = 'http://ns.rww.io/ldpx#ldprPrefix') { if ($path && $uri) { $g = new Graph('', $path, '', $uri); if ($g->size() > 0) { // specific authorization $q = 'SELECT ?s, ?prefix WHERE { ?s <' . $type . '> ?prefix }'; $s = $g->SELECT($q); $res = $s['results']['bindings']; if (isset($res) && count($res) > 0) { return $res[0]['prefix']['value']; } } } return null; }
function webid_getinfo($uri) { $g = new Graph('uri', $uri, '', $uri); $q = $g->SELECT(sprintf("PREFIX : <http://xmlns.com/foaf/0.1/>\n SELECT ?name ?pic ?depic FROM <%s> WHERE { \n ?s a :Person .\n FILTER (?s = <%s>) .\n OPTIONAL { ?s :name ?name } . \n OPTIONAL { ?s :img ?pic } .\n OPTIONAL { ?s :depiction ?depic } .\n }", $uri, $uri)); if (isset($q['results']) && isset($q['results']['bindings'])) { $r = $q['results']['bindings']; } if (isset($r) && is_array($r) && sizeof($r) > 0) { $name = $r[0]['name']['value']; $pic = $r[0]['pic']['value']; $depic = $r[0]['depic']['value']; if (strlen($name) == 0) { $name = 'No name'; } if (strlen($pic) == 0) { $pic = strlen($depic) > 0 ? $depic : '/common/images/nouser.png'; } } else { $name = ''; $pic = '/common/images/nouser.png'; } return array('name' => $name, 'pic' => $pic); }
$g->append('turtle', "@prefix p: <http://www.w3.org/ns/posix/stat#> . <" . $properties['resource'] . "> a " . $properties['type'] . " ; p:mtime " . $properties['mtime'] . " ; p:size " . $properties['size'] . " ."); } // add ldp:contains triple to the LDPC if ($show_containment) { $g->append('turtle', "<" . $_base . "> <http://www.w3.org/ns/ldp#contains> <" . $properties['resource'] . "> . "); } // add resource type from resources containing metadata if ($properties['type'] != 'p:File') { if ($properties['type'] == 'p:Directory') { $meta_uri = dirname($properties['uri']) . '/.meta.' . basename($properties['uri']); $meta_file = $_filename . '.meta.' . basename($properties['resource']); } else { $meta_uri = $properties['uri']; $meta_file = $_filename . basename($properties['resource']); } $dg = new Graph('', $meta_file, '', $meta_uri); if ($dg->size() > 0) { $q = 'SELECT * WHERE { <' . $properties['resource'] . '> ?p ?o }'; $s = $dg->SELECT($q); $res = $s['results']['bindings']; // add the resource type if (isset($res) && count($res) > 0) { foreach ($res as $t) { if ($t['p']['value'] == 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type') { $g->append_objects($properties['uri'], $t['p']['value'], array($t['o'])); } } } } } }
/** * Check if the user has access to a specific URI * @param string $method Read/Write/Append/Control * @param array $options local configuration options * @param string $uri the URI of the resource * * @return boolean (true if user has access) */ function can($method) { $this->_debug[] = "Method=" . $method; // check if we are the domain owner if (is_file($this->_root_path . '.acl')) { $g = new Graph('', $this->_root_path . '.acl', '', $this->_root_uri . '.acl'); if ($g->size() > 0) { // for the domain owner $this->_debug[] = "Graph size=" . $g->size(); $q = "PREFIX acl: <http://www.w3.org/ns/auth/acl#>\n SELECT ?z WHERE { \n ?z acl:agent <" . $this->_user . "> .\n }"; $r = $g->SELECT($q); if (isset($r['results']['bindings']) && count($r['results']['bindings']) > 0) { $this->_reason .= "User " . $this->_user . " was authenticated as owner!"; return true; } } } // Recursively find a .acl $path = $this->_path; $uri = $this->_uri; $parent_path = dirname($path) == $this->_root_path ? $path : dirname($path); $parent_uri = dirname($uri) == $this->_root_uri ? $uri : dirname($uri); $break = false; // debug $this->_debug[] = " "; $this->_debug[] = "------------"; $this->_debug[] = "Not the owner, going recursively! BASE=" . $this->_path; $this->_debug[] = "User is: " . $this->_user; // walk path (force stop if we hit root level) while ($path != dirname($this->_root_path)) { if ($break == true) { return true; } $r = $path; $this->_debug[] = "------------"; $this->_debug[] = "Current level: " . $r; $resource = $uri; if ($r != $this->_root_path) { $path = dirname($path) == $this->_root_path ? $path : dirname($path) . '/'; $this->_debug[] = "PATH=" . $path . " / ROOT_PATH=" . $this->_root_path; $acl_file = substr(basename($r), 0, 4) != '.acl' ? '.acl.' . basename($r) : basename($r); $acl_path = $path . $acl_file; $acl_uri = dirname($uri) == $this->_root_uri ? $acl_file : dirname($uri) . '/' . $acl_file; $this->_debug[] = "Dir=" . $r . " | acl_path=" . $acl_path . " | acl_uri=" . $acl_uri; $uri = dirname($uri) == $this->_root_uri ? $uri : dirname($uri) . '/'; $this->_debug[] = 'Parent_path=' . $path . ' | parent_uri=' . $uri; /* $acl_file = (substr(basename($r), 0, 4) != '.acl')?'/.acl.'.basename($r):'/'.basename($r); $acl_path = $parent_path.$acl_file; $acl_uri = (dirname($uri) == $this->_root_uri)?$acl_file:dirname($uri).$acl_file; $this->_debug[] = "Dir=".$r." | acl_path=".$acl_path." | acl_uri=".$acl_uri; $path = (dirname($path) == $this->_root_path)?$path:dirname($path).'/'; $uri = (dirname($uri) == $this->_root_uri)?$uri:dirname($uri).'/'; $this->_debug[] = 'Parent_path='.$path.' | parent_uri='.$uri; */ } else { $acl_path = $r . '.acl'; $acl_uri = $uri . '.acl'; $this->_debug[] = "ROOT Dir=" . $r . " | acl_path=" . $acl_path . " | acl_uri=" . $acl_uri; if ($path == $this->_root_path) { $break = true; } } if ($r == $this->_path) { $verb = 'accessTo'; } else { $verb = 'defaultForNew'; if (substr($resource, -1) != '/') { $resource = $resource . '/'; } } $this->_debug[] = "Verb=" . $verb . " | Resource=" . $resource; if (is_file($acl_path)) { $g = new Graph('', $acl_path, '', $acl_uri); if ($g->size() > 0) { // specific authorization $q = "PREFIX acl: <http://www.w3.org/ns/auth/acl#>" . "SELECT * WHERE { " . "?z acl:agent <" . $this->_user . "> ; " . "acl:mode acl:" . $method . " ; " . "acl:" . $verb . " <" . $resource . "> . " . "}"; $this->_debug[] = $q; $res = $g->SELECT($q); if (isset($res['results']['bindings']) && count($res['results']['bindings']) > 0) { $this->_reason .= 'User ' . $this->_user . ' is allowed (' . $method . ') access to ' . $r . "\n"; return true; } // public authorization $q = "PREFIX acl: <http://www.w3.org/ns/auth/acl#>" . "SELECT * WHERE { " . "?z acl:agentClass <http://xmlns.com/foaf/0.1/Agent>; " . "acl:mode acl:" . $method . "; " . "acl:" . $verb . " <" . $resource . "> . " . "}"; $this->_debug[] = $q; $res = $g->SELECT($q); if (isset($res['results']['bindings']) && count($res['results']['bindings']) > 0) { $this->_reason .= 'Everyone is allowed (' . $method . ') ' . $verb . ' to ' . $r . "\n"; return true; } $this->_reason = 'No one is allowed (' . $verb . ') ' . $method . ' for resource ' . $this->_uri . "\n"; return false; } } } }