store = $store; $this->graph = $graph; $this->url = $url; } public function set_url($url) { $this->url = $url; } public function set_graph($graph) { $this->graph = $graph; } public function set_details($title, $user, $content, $source, $created, $taggings) { $this->title = $title; $this->user = $user; $this->content = $content; $this->source = $source; $this->created = $created; $this->taggings = $taggings; } function set_edit($edit) { $this->edit = $edit; } function set_geo($lat = null, $long = null) { $this->lat = $lat; $this->long = $long; } // RDF (Turtle) description of the item function __toString() { return $this->to_rdf(); } function to_rdf() { $url = $this->url; $source = $this->source; $created = $this->created; $content = $this->content; $title = $this->title; $user = $this->user; $rdf = " <$url> a sioc:Item ; dc:title '$title' ; dct:created '$created' ; sioc:has_space <$source> ; foaf:maker <$user> ; content:encoded '$content' . "; if($this->taggings) { foreach($this->taggings as $tagging => $tag) { $taguri = $tag['taguri']; $tagname = $tag['tagname']; $rdf .= " <$tagging> a tags:RestrictedTagging ; tags:taggedContent <$url> ; tags:taggedBy <$user> ; tags:taggedWithTag <$taguri> . <$taguri> a moat:Tag ; tags:name \"$tagname\" . "; } } return $rdf; } // Load the item from the triplestore public function load() { $graphuri = $this->graph; $query = " SELECT DISTINCT ?url ?title ?user ?created ?content ?source WHERE { GRAPH <$graphuri> { ?url a sioc:Item ; dc:title ?title ; dct:created ?created ; foaf:maker ?user ; content:encoded ?content ; sioc:has_space ?source . } } LIMIT 1"; $res = $this->store->do_query($query); $url = $res['result']['rows'][0]['url']; $title = $res['result']['rows'][0]['title']; $content = $res['result']['rows'][0]['content']; $source = $res['result']['rows'][0]['source']; $created = $res['result']['rows'][0]['created']; $user = $res['result']['rows'][0]['user']; // Tags / MOAT links $query = " SELECT DISTINCT ?tagging ?tag ?meaning WHERE { GRAPH <$graphuri> { ?tagging a tags:RestrictedTagging ; tags:taggedContent <$url> ; tags:taggedBy <$user> ; tags:taggedWithTag ?tag . OPTIONAL { ?tagging moat:tagMeaning ?meaning } } } "; $res = $this->store->do_query($query); foreach($res['result']['rows'] as $tags) { $tagging = $tags['tagging']; $tag = $tags['tag']; $meaning = @$tags['meaning']; $taggings[$tagging][$tag] = $meaning; } $this->set_url($url); $this->set_details($title, $user, $content, $source, $created, $taggings); } // Check if the item already exists in the store public function exists() { $url = $this->url; $res = $this->store->do_query("ASK WHERE { <$url> rdf:type sioc:Item }"); return $res['result']; } // Save the item in triplestore, using the graph id public function save() { $graph = $this->graph; $this->store->do_query("INSERT INTO <$graph> { $this } "); } // TODO - Fix (or deprecate) /* public function exhibit() { $title = $this->title; $source = $this->source; $url = $this->url; $graph = $this->graph; $content = $this->content; $created = $this->created; $day = strftime('%Y-%m-%d', strtotime($created)); if($this->lat && $this->long) { $geo = $this->lat . ',' . $this->long; $latlng = "latlng : \"$geo\","; } $icon = LODrTools::get_icon($source); $out = <<<_END_ { type : "item", url: "$url", label : "$title", graph : "$graph", source: "$source", icon : "$icon", $latlng created : "$created", day : "$day", }, _END_; return $out; }*/ // HTML rendering of the item function html_output() { $url = $this->url; $title = $this->title; $content = $this->content; $created = $this->created; $source = $this->source; $user = $this->user; $icon = LODrTools::get_icon($this->source); $out = <<<_END_

service logo $title

$content
_END_; if(!$this->edit) { $out .= $this->html_view(); } else { $out .= $this->html_edit(); } $out .= "\n\n\t
\n\t"; return $out; } function html_view() { $id = $this->graph; $url = $this->url; $user = $this->user; $out .= "\n\n\t

Edit

"; return $out; } function html_edit() { $id = $this->graph; global $base, $tagserv, $endpoints; $out .= "
"; foreach($this->taggings as $taggings => $tag) { $tagging = $taggings; foreach($tag as $tag => $meaning) { $tagname = LODrTools::tagname($tag); $out .= "

$tagname

"; // MOAT server suggesting foreach($tagserv as $serv) { $out .= $this->moat_uris($serv, $id, $tagging, $tag, $meaning); } // SPARQL Endpoints suggesting // - TODO foreach($endpoints as $endpoint) { $out .= $this->endpoint_uris($endpoint, $id, $tagging, $tag, $meaning); } // New URI w/ Sindice $out .= "New URI: "; $out .= ""; $out .= '
'; } } $out .= "Secret key: "; $out .= "
"; return $out; } function moat_uris($serv, $id, $tagging, $tag, $meaning) { list($servname, $servuri, $servkey) = $serv; $tagname = LODrTools::tagname($tag); $uris = LODrTools::moat_get($servuri, $tagname); $out .= "
Suggestion(s) from the $servname community"; if($uris) { foreach($uris as $uri) { $uri = $uri->uri->value; $checked = ($uri == $meaning) ? 'checked="on"' : ''; $label = LODrTools::get_label($this->store, $uri); //. " ($uri)"; $out .= " $label
"; } } else { $out .= "Nothing yet, add one using the field below !"; } $out .= "
"; return $out; } function endpoint_uris($endpoint, $id, $tagging, $tag, $meaning) { list($name, $sparql) = $endpoint; $tagname = LODrTools::tagname($tag); $uris = LODrTools::sparql_get($sparql, $tagname); $out .= "
Suggestion(s) from the $name endpoint"; if($uris) { foreach($uris as $uri) { $label = $uri->label->value; $uri = $uri->uri->value; $checked = ($uri == $meaning) ? 'checked="on"' : ''; $out .= " $label
"; } } else { $out .= "Nothing yet"; } $out .= "
"; return $out; } public function go($format) { $this->load(); return $this->html_output(); } } ?>