Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndi_G <andigros72@googlemail.com>2011-01-17 22:37:54 (GMT)
committer Andi_G <andigros72@googlemail.com>2011-01-17 22:37:54 (GMT)
commit143aae08714810892c81349fd03a8b23dabc0531 (patch)
tree5ff949cc17834003bfbc2ea1de662d4e4e8a9cf4
parent7aab67189856a1c34835b819c42a8093a602a00e (diff)
added the annotation wordpress plugin that acts as the counterpart for the anno activity
-rwxr-xr-xannotation/annotation.php821
-rwxr-xr-xannotation/annotation_plugin.php136
-rwxr-xr-xannotation/readme.txt19
3 files changed, 976 insertions, 0 deletions
diff --git a/annotation/annotation.php b/annotation/annotation.php
new file mode 100755
index 0000000..e0bda4a
--- /dev/null
+++ b/annotation/annotation.php
@@ -0,0 +1,821 @@
+<?php
+/*
+
+Copyright 2010 Andreas Gros (email : info@andreasgros.net)
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3 of the License.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+$error = '';
+if (!defined('ABSPATH'))
+ {
+ if(file_exists('./../../../wp-blog-header.php'))
+ require('./../../../wp-blog-header.php');
+ else if(file_exists('./../../../../wpmu/wp-blog-header.php'))
+ require('./../../../../wpmu/wp-blog-header.php');
+ else if(file_exists('/var/wpmu/wp-blog-header.php'))
+ require('/var/wpmu/wp-blog-header.php');
+ else $error = 'The file "wp-blog-header.php" does not seem to be at the place configured in this file.';
+ }
+
+
+function strToHex($string)
+{
+ $hex='';
+ for ($i=0; $i < strlen($string); $i++)
+ {
+ $hex .= dechex(ord($string[$i]));
+ }
+ return $hex;
+}
+
+function hexToStr($hex)
+{
+ $string='';
+ for ($i=0; $i < strlen($hex)-1; $i+=2)
+ {
+ $string .= chr(hexdec($hex[$i].$hex[$i+1]));
+ }
+ return $string;
+}
+
+header('Content-Type: application/rdf+xml');
+
+if(empty($error))
+ {
+ global $xmlres;
+ global $wpdb;
+ $wpdb->show_errors();
+ /*
+ str = "<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" "
+ str += "xmlns:rdfs=\"http://www.w3.org/2001/01/rdf-schema#\" "
+ str += "xmlns:cnt=\"http://www.w3.org/2008/content\" "
+ str += "xmlns:dc=\"http://purl.org/dc/elements/1.1/\" "
+ str += "xmlns:dcterms=\"http://purl.org/dc/terms/\" "
+ str += "xmlns:foaf=\"http://xmlns.com/foaf/0.1/\" "
+ str += "xmlns:oac=\"http://www.openannotation.org/ns/\" "
+ str += "xmlns:ore=\"http://www.openarchives.org/ore/terms/\">"
+
+ str += "<oac:Annotation rdf:about=\"urn:uuid:" + self._uuid + "#AnnotationContent\">"
+ str += "<dc:title>" + self._annotitle + "</dc:title>"
+ str += "<oac:hasTarget rdf:resource=\"" + self._hasTarget + "\" dcterms:isPartOf=\"" + self._hasTarget + "\"/>"
+ str += "<oac:hasTargetContext>"
+ str += "<oac:TargetContext>"
+ str += "<oac:contextAbout rdf:resource=\"" + self._hasTarget + "\"/>"
+ str += "<dc:type>" + self._mimetype + "</dc:type>"
+ str += "</oac:TargetContext>"
+ str += "</oac:hasTargetContext>"
+
+ str += "<oac:hasContentContext>"
+ str += "<oac:Context rdf:resource=\"" + self._context + "\">"
+ str += "<oac:contextAbout>"
+ str += self._hasTarget
+ str += "</oac:contextAbout>"
+ str += '<oac:when> %f </oac:when>' % self._created
+ str += "</oac:Context>"
+ str += "</oac:hasContentContext>"
+
+ str += "<rdf:type rdf:resource=\"http://www.w3.org/2000/10/annotation-ns#Annotation\"/>"
+ str += "<oac:predicate rdf:resource=\"http://www.openannotation.org/ns/hasTarget\"/>"
+ str += "<dcterms:creator>" + self._creator + "</dcterms:creator>"
+
+ str += "<oac:hasContent rdf:about=\"urn:uuid:" + self._uuid + "#AnnotationContent\">"
+ str += "<rdf:type rdf:resource=\"" + self._annotationurl + "\"/>"
+ str += "<dc:title>" + self._annotitle + "</dc:title>"
+ str += "<oac:hasBody>"
+ str += "<rdf:type rdf:resource=\"http://www.openannotation.org/ns/Note\"/>"
+ str += "<oac:body>"
+ str += self._bodyurl
+ str += "</oac:body>"
+ str += "</oac:hasBody>"
+ str += '<dcterms:modified> %f </dcterms:modified>' % self._modified
+ str += "</oac:hasContent>"
+ str += "</oac:Annotation>"
+
+
+ str += "<rdf:Description rdf:about=\"" + self._hasTarget + "\">"
+ str += "<ore:Proxy>"
+ str += "<ore:proxyIn rdf:nodeID=\"anno\" />"
+ str += "<ore:proxyFor rdf:resource=\"" + self._hasTarget + "\">"
+ str += "<oac:hasSegmentDescription>"
+ str += "<oac:SegmentDescription dc:format=\"image/svg+xml\">"
+ str += "<cnt:ContentAsText>"
+ str += "<cnt:chars>"
+ str += self._bodysvg
+ str += "</cnt:chars>"
+ str += "<cnt:characterEncoding>utf-8</cnt:characterEncoding>"
+ str += "</cnt:ContentAsText>"
+ str += "</oac:SegmentDescription>"
+ str += "</oac:hasSegmentDescription>"
+ str += "</ore:proxyFor>"
+ str += "</ore:Proxy>"
+ str += "</rdf:Description>"
+ str += "</rdf:RDF>"
+ */
+
+
+ if(isset($_POST["getidforuser"]) && (!empty($_POST["getidforuser"])))
+ {
+ $userid = $_POST["getidforuser"];
+ $res = '';
+ $toadd = '';
+ do
+ {
+ $userid = $userid . $toadd;
+ $shamid = sha1($userid, FALSE);
+
+ $sql = "SELECT userid FROM " . $wpdb->prefix . "annotation_userid WHERE userid=\"" . $shamid . "\"";
+ $res = $wpdb->get_var($sql);
+ $rval = sprintf("%d", rand());
+ $toadd = $toadd . $rval;
+ }
+ while(!empty($res));
+
+ $sql = $wpdb->prepare("INSERT INTO " . $wpdb->prefix . "annotation_userid ( userid ) VALUES ( %s )", $shamid);
+ $wpdb->query($sql);
+
+ $rdf = getRDFHeader();
+ $rdf .= '<rdf:Description>' . $nl;
+ $rdf .= '<dcterms:identifier>' . $shamid . '</dcterms:identifier>'. $nl;
+ $rdf .= '</rdf:Description>' . $nl;
+ $rdf .= "</rdf:RDF>";
+ $res = $rdf;
+ }
+ else
+ {
+ if(isset($_GET["anid"]) && (!empty($_GET["anid"])) && (is_numeric($_GET["anid"])) && (intval($_GET["anid"])>0))
+ {
+ $sql = $wpdb->prepare("SELECT body FROM " . $wpdb->prefix . "annotation WHERE id=%d", intval($_GET["anid"]));
+ $res = $wpdb->get_var($sql);
+ }
+ if(isset($_GET["boid"]) && (!empty($_GET["boid"])) && (is_numeric($_GET["boid"])) && (intval($_GET["boid"])>0))
+ {
+ $sql = $wpdb->prepare("SELECT body FROM " . $wpdb->prefix . "annotation WHERE id=%d", intval($_GET["boid"]));
+ $res = $wpdb->get_var($sql);
+ }
+ else if(isset($_POST["w3c_hasTarget"]) && (!empty($_POST["w3c_hasTarget"])))
+ {
+ $url = $_POST["w3c_hasTarget"];
+ $delete_anid = '';
+ if (isset($_POST["delete_anid"]) && (!empty($_POST["delete_anid"])))
+ {
+ $delete_anid = $_POST["delete_anid"];
+ }
+ if (!empty($delete_anid))
+ {
+ $sql = "SELECT clientuuid FROM " . $wpdb->prefix . "annotation WHERE annotates=\"" . $url . "\" and clientuuid=\"" . $delete_anid . "\"";
+ $res_arr = $wpdb->get_results($sql, ARRAY_A);
+ if (!empty($res_arr))
+ {
+ $sql = "DELETE FROM " . $wpdb->prefix . "annotation WHERE annotates=\"" . $url . "\" and clientuuid=\"" . $delete_anid . "\"";
+ $wpdb->query($sql);
+ }
+ }
+ $wherestr = '';
+ if (isset($_POST["creator"]) and (!empty($_POST["creator"])))
+ {
+ $wherestr = " and creator=\"" . $_POST["creator"] . "\"";
+ }
+
+ $sql = "SELECT * FROM " . $wpdb->prefix . "annotation WHERE annotates=\"" . $url . "\"" . $wherestr;
+ $res_arr = $wpdb->get_results($sql, ARRAY_A);
+
+ $res = getRDFHeader();
+
+ if(!empty($res_arr))
+ {
+ foreach($res_arr as $ann_arr)
+ {
+ $res .= assembleAnnotation($ann_arr);
+ }
+ }
+ $res .= "</rdf:RDF>";
+ }
+ else
+ {
+ $replace_anid = null;
+ if(strpos($_SERVER["REQUEST_URI"], "replace_source" )>0)
+ {
+ if (preg_match('/anid=(\d+)/', $_SERVER["REQUEST_URI"], $result))
+ {
+ $replace_anid = intval($result[1]);
+ }
+ else if (preg_match('/boid=(\d+)/', $_SERVER["REQUEST_URI"], $result))
+ {
+ $replace_anid = intval($result[1]);
+ }
+ else { $replace_anid = null; }
+ }
+
+ $data = $HTTP_RAW_POST_DATA;
+ $res = parseannotationXML($data);
+
+ $created_time = assembleDBDate($xmlres["contextwhen"]);
+
+ if ( ( isset( $xmlres['clientuuid'] ) ) and
+ ( strlen($xmlres['clientuuid']) > 0 ) and
+ ( isset( $xmlres['target'] ) ) and
+ ( strlen($xmlres['target']) > 0 ) )
+ {
+ #check if the clientuuid is already in the database
+ $sql = $wpdb->prepare("SELECT id FROM " . $wpdb->prefix .
+ "annotation WHERE clientuuid='%s' AND target='%s'" ,
+ $xmlres["clientuuid"],
+ $xmlres["target"]);
+ $aid = $wpdb->get_var($sql);
+ if( ( $aid != null ) and !empty($aid) and is_numeric($aid) )
+ {
+ $replace_anid = intval($aid);
+ }
+ }
+
+
+ /*
+ database fields:
+ id mediumint(9) NOT NULL AUTO_INCREMENT,
+ clientuuid VARCHAR(100) NULL,
+ annotationurl VARCHAR(100) NULL,
+ page VARCHAR(10) NULL,
+ creator VARCHAR(100) NOT NULL,
+ created datetime DEFAULT 0,
+ modified timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+ body text NOT NULL,
+ bodyurl VARCHAR(255) NOT NULL,
+ bodysvg text NULL,
+ contentcontext text NOT NULL,
+ contextwhen datetime DEFAULT 0,
+ targetcontext text NOT NULL,
+ title VARCHAR(255) NOT NULL,
+ annotates VARCHAR(255) NOT NULL,
+ target VARCHAR(255) NULL,
+ mimetype VARCHAR(100) NULL,
+ rdf text NOT NULL,
+ UNIQUE KEY id (id)
+ */
+
+
+ if(empty($replace_anid))
+ {
+ $sql = $wpdb->prepare("INSERT INTO " . $wpdb->prefix .
+ "annotation ( clientuuid, annotationurl, page, creator, created, " .
+ "body, bodyurl, bodysvg, contentcontext, " .
+ "contextwhen, targetcontext, title, annotates, " .
+ "target, mimetype, rdf ) " .
+ "VALUES ( %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, " .
+ "%s, %s, %s, %s, %s, %s )",
+ $xmlres["clientuuid"],
+ $xmlres["annotationurl"],
+ $xmlres["page"],
+ $xmlres["creator"],
+ $xmlres["contextwhen"],
+ $xmlres["bodysvg"], #FIXME
+ $xmlres["bodyurl"],
+ $xmlres["bodysvg"],
+ $xmlres["contentcontext"],
+ $xmlres["contextwhen"],
+ $xmlres["targetcontext"],
+ $xmlres["title"],
+ $xmlres["target"],
+ $xmlres["target"],
+ $xmlres["mimetype"],
+ $data);
+ $wpdb->query($sql);
+ }
+ else
+ {
+ $wpdb->update($wpdb->prefix . "annotation", array('clientuuid' => $xmlres["clientuuid"],
+ 'annotationurl' => $xmlres["annotationurl"], 'page' => $xmlres["page"],
+ 'creator' => $xmlres["creator"], 'created' => $xmlres["created"],
+ 'body' => $xmlres["bodysvg"], 'bodysvg' => $xmlres["bodysvg"],
+ 'bodyurl' => $xmlres['bodyurl'], 'contentcontext' => $xmlres["contentcontext"],
+ 'contextwhen' => $xmlres["contextwhen"], 'targetcontext' => $xmlres["targetcontext"],
+ 'title' => $xmlres['title'], 'annotates' => $xmlres['target'],
+ 'target' => $xmlres['target'], 'mimetype' => $xmlres['mimetype'],
+ 'rdf' => $data), array('id' => $replace_anid), null, array('%d')
+ );
+
+ }
+ $errstr = mysql_error($wpdb->dbh);
+ if (empty($errstr))
+ {
+ //get the annotation id of the most recent entry of the database
+ $sql = $wpdb->prepare("SELECT id FROM " . $wpdb->prefix . "annotation WHERE annotates='%s' AND clientuuid='%s' ORDER BY modified", $xmlres["target"], $xmlres['clientuuid']);
+
+ $anid = $wpdb->get_var($sql);
+ $annotationresurl = 'http://' . $_SERVER["HTTP_HOST"] .'/' . PLUGINDIR . '/annotation/annotation.php?anid=' . $anid;
+ $bodyresurl = 'http://' . $_SERVER["HTTP_HOST"] .'/' . PLUGINDIR . '/annotation/annotation.php?boid=' . $anid;
+
+ $nl = "\n";
+ $res = getRDFHeader();
+ $res .= '<rdf:Description rdf:about="' . $annotationresurl . '">' . $nl;
+ $res .= '<oac:hasTarget>' . $xmlres["target"] . '</oac:hasTarget>' . $nl;
+
+ if(!empty($xmlres["bodyurl"]))
+ {
+ $res .= '<oac:body rdf:resource="' . $xmlres["bodyurl"] . '"/>' . $nl;
+ }
+ else
+ {
+ $res .= '<oac:body rdf:resource="' . $bodyresurl . '"/>' . $nl;
+ }
+ $res .= '</rdf:Description>' . $nl;
+ $res .= '</rdf:RDF>';
+ }
+ else
+ {
+ $res = assembleErrorMsg($errstr);
+ }
+ }
+ }
+ }
+else
+ {
+ $res = assembleErrorMsg($error);
+ }
+print $res;
+if (isset($xmlres))
+ {
+ unset($xmlres);
+ }
+
+
+
+
+function getRDFHeader()
+ {
+ $str = "<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" ";
+ $str .= "xmlns:rdfs=\"http://www.w3.org/2001/01/rdf-schema#\" ";
+ $str .= "xmlns:cnt=\"http://www.w3.org/2008/content\" ";
+ $str .= "xmlns:dc=\"http://purl.org/dc/elements/1.1/\" ";
+ $str .= "xmlns:dcterms=\"http://purl.org/dc/terms/\" ";
+ $str .= "xmlns:foaf=\"http://xmlns.com/foaf/0.1/\" ";
+ $str .= "xmlns:oac=\"http://www.openannotation.org/ns/\" ";
+ $str .= "xmlns:ore=\"http://www.openarchives.org/ore/terms/\" ";
+ $str .= "xmlns:bibo=\"http://purl.org/ontology/bibo/\">";
+ return $str;
+ }
+
+
+
+
+
+
+
+
+function assembleAnnotation($db_arr)
+ {
+ $res = "";
+ if(!empty($db_arr) && is_array($db_arr))
+ {
+ $annotationresurl = 'http://' . $_SERVER["HTTP_HOST"] .'/' . PLUGINDIR . '/annotation/annotation.php?anid=' . $db_arr["id"];
+ $bodyresurl = 'http://' . $_SERVER["HTTP_HOST"] .'/' . PLUGINDIR . '/annotation/annotation.php?boid=' . $db_arr["id"];
+
+ $res .= "<oac:Annotation rdf:about=\"" . $db_arr["clientuuid"] . "\">";
+ $res .= "<bibo:pageStart>" . $db_arr["page"] . "</bibo:pageStart>";
+ $res .= "<dc:title>" . $db_arr["title"] . "</dc:title>";
+ $res .= "<oac:hasTarget rdf:resource=\"" . $db_arr["annotates"] . "\" dcterms:isPartOf=\"" . $db_arr["annotates"] . "\"/>";
+ $res .= "<oac:hasTargetContext>";
+ $res .= "<oac:TargetContext>";
+ $res .= "<oac:contextAbout rdf:resource=\"" . $db_arr["annotates"] . "\"/>";
+ $res .= "<dc:type>" . $db_arr["mimetype"] . "</dc:type>";
+ $res .= "</oac:TargetContext>";
+ $res .= "</oac:hasTargetContext>";
+
+ $res .= "<oac:hasContentContext>";
+ $res .= "<oac:Context rdf:resource=\"" . $db_arr["contentcontext"] . "\">";
+ $res .= "<oac:contextAbout>";
+ $res .= $db_arr["annotates"];
+ $res .= "</oac:contextAbout>";
+ $res .= "<oac:when>" . $db_arr["contextwhen"] . "</oac:when>";
+ $res .= "</oac:Context>";
+ $res .= "</oac:hasContentContext>";
+
+ $res .= "<rdf:type rdf:resource=\"http://www.w3.org/2000/10/annotation-ns#Annotation\"/>";
+ $res .= "<oac:predicate rdf:resource=\"http://www.openannotation.org/ns/annotates\"/>";
+ $res .= "<dcterms:creator>" . $db_arr["creator"] . "</dcterms:creator>";
+
+ $res .= "<oac:hasContent rdf:about=\"" . $db_arr["clientuuid"] . "\">";
+ $res .= "<rdf:type rdf:resource=\"" . $annotationresurl . "\"/>";
+ $res .= "<dc:title>" . $db_arr["title"] . "</dc:title>";
+ $res .= "<oac:hasBody>";
+ $res .= "<rdf:type rdf:resource=\"http://www.openannotation.org/ns/Note\"/>";
+ $res .= "<oac:body>";
+ $res .= $bodyresurl;
+ $res .= "</oac:body>";
+ $res .= "</oac:hasBody>";
+ $res .= "<dcterms:modified>" . $db_arr["modified"] . "</dcterms:modified>";
+ $res .= "</oac:hasContent>";
+ $res .= "</oac:Annotation>";
+
+
+ $res .= "<rdf:Description rdf:about=\"" . $db_arr["annotates"] . "\">";
+ $res .= "<ore:Proxy>";
+ $res .= "<ore:proxyIn rdf:nodeID=\"anno\" />";
+ $res .= "<ore:proxyFor rdf:resource=\"" . $db_arr["annotates"] . "\">";
+ $res .= "<oac:hasSegmentDescription>";
+ $res .= "<oac:SegmentDescription dc:format=\"image/svg.xml\">";
+ $res .= "<cnt:ContentAsText>";
+ $res .= "<cnt:chars>";
+ $res .= $db_arr["body"];
+ $res .= "</cnt:chars>";
+ $res .= "<cnt:characterEncoding>utf-8</cnt:characterEncoding>";
+ $res .= "</cnt:ContentAsText>";
+ $res .= "</oac:SegmentDescription>";
+ $res .= "</oac:hasSegmentDescription>";
+ $res .= "</ore:proxyFor>";
+ $res .= "</ore:Proxy>";
+ $res .= "</rdf:Description>";
+
+
+
+
+ //
+ //check out if the comment was a reference to an existing website with
+ //the actual comment text or if the actual textual comment was sent
+ /*
+ if(!empty($db_arr["bodyurl"]))
+ {
+ $res .= '<a:body rdf:resource="' . $db_arr["bodyurl"] . '"/>' . $nl;
+ }
+ else
+ {
+ $res .= '<a:body rdf:resource="' . $bodyresurl;
+ if(empty($db_arr["body"]))
+ {
+ $res .= '"/>' . $nl;
+ }
+ else
+ {
+ $res .= '">' . $nl . $db_arr["body"] . $nl;
+ $res .= '</a:body>' . $nl;
+ }
+ }
+ $res .= '</rdf:Description>' . $nl; */
+ }
+ return $res;
+ }
+
+
+
+
+
+
+
+function assembleErrorMsg($error = "")
+ {
+ $nl = "\n";
+ $res = '<rdf:RDF '.
+ 'xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" '. $nl .
+ 'xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">'. $nl .
+ $res .= '<error>' . $error . '</error>' . $nl;
+ $res .= '</rdf:RDF>';
+ return $res;
+ }
+
+
+
+
+
+
+
+
+ //
+ //get a datetime for WP DB
+ //@param: $thedate = a timestamp format or year or year-month
+ //
+ function assembleDBDate($thedate)
+ {
+ $len = strlen($thedate);
+ if($len < 10)
+ {
+ if($len == 7)
+ { //it's possibly yyyy-mm
+ $thedate = $thedate . "-01 00:00:00";
+ }
+ else if($len == 4)
+ { //it's just a yeardf: yyyy
+ $thedate = $thedate . "-01-01 00:00:00";
+ }
+ else if(empty($thedate))
+ {
+ $thedate = "0000-00-00 00:00:00";
+ }
+ }
+ else if(stripos($thedate, "T") !== false)
+ { //it's an ISO date from PubMan
+ $thedate = str_ireplace("T", " ", $thedate);
+ if(stripos($thedate, ".") !== false)
+ {
+ $thedate = substr($thedate, 0, strrpos($thedate, "."));
+ }
+ if(strpos($thedate, "Z") !== false)
+ {
+ $thedate = substr($thedate, 0, strrpos($thedate, "Z"));
+ }
+ }
+ return $thedate;
+ }
+
+
+
+
+/*
+ *
+ Parse annotation RDF XML like
+
+str = "<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" "
+ str += "xmlns:rdfs=\"http://www.w3.org/2001/01/rdf-schema#\" "
+ str += "xmlns:cnt=\"http://www.w3.org/2008/content\" "
+ str += "xmlns:dc=\"http://purl.org/dc/elements/1.1/\" "
+ str += "xmlns:dcterms=\"http://purl.org/dc/terms/\" "
+ str += "xmlns:foaf=\"http://xmlns.com/foaf/0.1/\" "
+ str += "xmlns:oac=\"http://www.openannotation.org/ns/\" "
+ str += "xmlns:ore=\"http://www.openarchives.org/ore/terms/\">"
+
+ str += "<oac:Annotation rdf:about=\"urn:uuid:" + self._uuid + "#AnnotationContent\">"
+ str += "<dc:title>" + self._annotitle + "</dc:title>"
+ str += "<oac:hasTarget rdf:resource=\"" + self._hasTarget + "\" dcterms:isPartOf=\"" + self._hasTarget + "\"/>"
+ str += "<oac:hasTargetContext>"
+ str += "<oac:TargetContext>"
+ str += "<oac:contextAbout rdf:resource=\"" + self._hasTarget + "\"/>"
+ str += "<dc:type>" + self._mimetype + "</dc:type>"
+ str += "</oac:TargetContext>"
+ str += "</oac:hasTargetContext>"
+
+ str += "<oac:hasContentContext>"
+ str += "<oac:Context rdf:resource=\"" + self._context + "\">"
+ str += "<oac:contextAbout>"
+ str += self._hasTarget
+ str += "</oac:contextAbout>"
+ str += '<oac:when> %f </oac:when>' % self._created
+ str += "</oac:Context>"
+ str += "</oac:hasContentContext>"
+
+ str += "<rdf:type rdf:resource=\"http://www.w3.org/2000/10/annotation-ns#Annotation\"/>"
+ str += "<oac:predicate rdf:resource=\"http://www.openannotation.org/ns/hasTarget\"/>"
+ str += "<dcterms:creator>" + self._creator + "</dcterms:creator>"
+
+ str += "<oac:hasContent rdf:about=\"urn:uuid:" + self._uuid + "#AnnotationContent\">"
+ str += "<rdf:type rdf:resource=\"" + self._annotationurl + "\"/>"
+ str += "<dc:title>" + self._annotitle + "</dc:title>"
+ str += "<oac:hasBody>"
+ str += "<rdf:type rdf:resource=\"http://www.openannotation.org/ns/Note\"/>"
+ str += "<oac:body>"
+ str += self._bodyurl
+ str += "</oac:body>"
+ str += "</oac:hasBody>"
+ str += '<dcterms:modified> %f </dcterms:modified>' % self._modified
+ str += "</oac:hasContent>"
+ str += "</oac:Annotation>"
+
+
+ str += "<rdf:Description rdf:about=\"" + self._hasTarget + "\">"
+ str += "<ore:Proxy>"
+ str += "<ore:proxyIn rdf:nodeID=\"anno\" />"
+ str += "<ore:proxyFor rdf:resource=\"" + self._hasTarget + "\">"
+ str += "<oac:hasSegmentDescription>"
+ str += "<oac:SegmentDescription dc:format=\"image/svg+xml\">"
+ str += "<cnt:ContentAsText>"
+ str += "<cnt:chars>"
+ str += self._bodysvg
+ str += "</cnt:chars>"
+ str += "<cnt:characterEncoding>utf-8</cnt:characterEncoding>"
+ str += "</cnt:ContentAsText>"
+ str += "</oac:SegmentDescription>"
+ str += "</oac:hasSegmentDescription>"
+ str += "</ore:proxyFor>"
+ str += "</ore:Proxy>"
+ str += "</rdf:Description>"
+ str += "</rdf:RDF>"
+ */
+function parseannotationXML($rdf)
+ {
+ global $annotationdata;
+ global $annotationcount;
+ global $xmlres;
+
+ $retstr = "";
+
+ $dom = new DOMDocument('1.0', 'UTF-8');
+ if ($dom->loadXML($rdf) === false)
+ {
+ die('Parsing failed');
+ }
+ $xmlres = array();
+ $root = $dom->firstChild;
+ $node = $root->firstChild;
+
+
+ //get namespace prefixes
+
+ /*<rdf:rdf xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" "
+ str += "xmlns:rdfs=\"http://www.w3.org/2001/01/rdf-schema#\" "
+ str += "xmlns:cnt=\"http://www.w3.org/2008/content\" "
+ str += "xmlns:dc=\"http://purl.org/dc/elements/1.1/\" "
+ str += "xmlns:dcterms=\"http://purl.org/dc/terms/\" "
+ str += "xmlns:foaf=\"http://xmlns.com/foaf/0.1/\" "
+ str += "xmlns:oac=\"http://www.openannotation.org/ns/\" "
+ str += "xmlns:ore=\"http://www.openarchives.org/ore/terms/\">"
+
+ */
+
+
+ global $rdfprefix;
+ global $annotationprefix;
+ global $dcprefix;
+ global $rdfsprefix;
+ global $contentprefix;
+ global $annotationprefix;
+ global $dctermsprefix;
+ global $foafprefix;
+ global $oacprefix;
+ global $oreprefix;
+ global $biboprefix;
+
+ $rdfprefix = $node->lookupPrefix("http://www.w3.org/1999/02/22-rdf-syntax-ns#");
+ $rdfsprefix = $node->lookupPrefix("http://www.w3.org/2001/01/rdf-schema#");
+ $contentprefix = $node->lookupPrefix("http://www.w3.org/2008/content");
+ $annotationprefix = $node->lookupPrefix("http://www.w3.org/2000/10/annotation-ns#");
+ $dcprefix = $node->lookupPrefix("http://purl.org/dc/elements/1.1/");
+ $dctermsprefix = $node->lookupPrefix("http://purl.org/dc/terms/");
+ $foafprefix = $node->lookupPrefix("http://xmlns.com/foaf/0.1/");
+ $oacprefix = $node->lookupPrefix("http://www.openannotation.org/ns/");
+ $oreprefix = $node->lookupPrefix("http://www.openarchives.org/ore/terms/");
+ $biboprefix = $node->lookupPrefix("http://purl.org/ontology/bibo/");
+
+
+ if(isset($xmlres)) { unset($xmlres); }
+ $xmlres = array();
+ parseannotationXMLObject($node); //here all the stuff gets stuffed into $xmlres
+ }
+
+
+
+
+
+function parseannotationXMLObject($node)
+ {
+ global $xmlres;
+ global $rdfprefix;
+ global $annotationprefix;
+ global $dcprefix;
+ global $rdfsprefix;
+ global $contentprefix;
+ global $annotationprefix;
+ global $dctermsprefix;
+ global $foafprefix;
+ global $oacprefix;
+ global $oreprefix;
+ global $biboprefix;
+
+ $hitTargetContext = false;
+ $hitContentContext = false;
+ $hasHitContent = false;
+ $hasHitContentAsText = false;
+
+
+ while($node)
+ {
+ if($node->nodeName != "#text")
+ {
+ if($node->hasChildNodes())
+ {
+ parseannotationXMLObject($node->firstChild);
+ }
+ if ( ($node->nodeName == "$oacprefix:hasTarget") )
+ {
+ if(empty($node->nodeValue))
+ {
+ $hasTarget = getNodeAttribute('resource', $node->attributes);
+ $xmlres["target"] = trim($hasTarget);
+ }
+ else
+ {
+ $xmlres["target"] = trim($node->nodeValue);
+ }
+ }
+
+ if ( ($node->nodeName == "$oacprefix:hasContentContext") )
+ {
+ $hitContentContext = true;
+ }
+
+ if ( ($node->nodeName == "$biboprefix:pageStart" ) )
+ {
+ $xmlres["page"] = trim($node->nodeValue);
+ }
+
+ if ( ($node->nodeName == "$oacprefix:hasTargetContext") )
+ {
+ $hitTargetContext = true;
+ }
+
+ if ( ($node->nodeName == "$oacprefix:contextAbout") )
+ {
+ if($hitTargetContext)
+ {
+ $targetContext = getNodeAttribute('resource', $node->attributes);
+ $xmlres["targetcontext"] = trim($targetContext);
+ }
+ else
+ {
+ $contentContext = getNodeAttribute('resource', $node->attributes);
+ $xmlres["contentcontext"] = trim($contentContext);
+ }
+ }
+
+ if ( ($node->nodeName == "$dcprefix:type") )
+ {
+ $xmlres["mimetype"] = trim($node->nodeValue);
+ }
+
+ if ( ($node->nodeName == "$dcprefix:title") )
+ {
+ $xmlres["title"] = trim($node->nodeValue);
+ }
+ if ( ($node->nodeName == "$dctermsprefix:creator") )
+ {
+ $xmlres["creator"] = trim($node->nodeValue);
+ }
+ if ( ($node->nodeName == "$oacprefix:when") )
+ {
+ $xmlres["contextwhen"] = trim($node->nodeValue);
+ $xmlres["created"] = trim($node->nodeValue);
+ }
+
+ if ( ($node->nodeName == "$oacprefix:Annotation") )
+ {
+ $uuid = getNodeAttribute('about', $node->attributes);
+ $xmlres["clientuuid"] = trim($uuid);
+ }
+
+ if ( ($node->nodeName == "$oacprefix:hasContent") )
+ {
+ $hasHitContent = true;
+ }
+
+ if ( ($node->nodeName == "$rdfprefix:type") && $hasHitContent )
+ {
+ $annotationurl = getNodeAttribute('resource', $node->attributes);
+ $xmlres["annotationurl"] = trim($annotationurl);
+ }
+ if ( ($node->nodeName == "$oacprefix:body") && $hasHitContent )
+ {
+ $xmlres["bodyurl"] = trim($node->nodeValue);
+ }
+ if ( ($node->nodeName == "$dctermsprefix:modified") && $hasHitContent )
+ {
+ $xmlres["modified"] = trim($node->nodeValue);
+ }
+
+ if ( ($node->nodeName == "$contentprefix:ContentAsText"))
+ {
+ $hasHitContentAsText = true;
+ }
+
+ if ( ($node->nodeName == "$contentprefix:chars"))
+ {
+ $xmlres["bodysvg"] = DOMinnerHTML($node);
+ }
+ }
+ $node = $node->nextSibling;
+ }
+ }
+
+
+
+function getNodeAttribute($name, $attr)
+ {
+ foreach($attr as $i)
+ {
+ if($i->name == $name)
+ return $i->value;
+ }
+ return "";
+ }
+
+function DOMinnerHTML($element)
+ {
+ $innerHTML = "";
+ $children = $element->childNodes;
+ foreach ($children as $child)
+ {
+ $tmp_dom = new DOMDocument();
+ $tmp_dom->appendChild($tmp_dom->importNode($child->cloneNode(true), true));
+ $innerHTML.=trim($tmp_dom->saveHTML());
+ }
+ return $innerHTML;
+ }
+
+?>
diff --git a/annotation/annotation_plugin.php b/annotation/annotation_plugin.php
new file mode 100755
index 0000000..c2e23bc
--- /dev/null
+++ b/annotation/annotation_plugin.php
@@ -0,0 +1,136 @@
+<?php
+/*
+Plugin Name: Annotation plugin
+Plugin URI: http://www.andreasgros.net
+Description: This plugin turns your wordpress blog into an annotation server
+Author: Andreas Gros
+Author URI: http://www.andreasgros.net/author/andi
+
+*/
+
+if(!class_exists("AnnotationPlugin"))
+ {
+
+ class AnnotationPlugin
+ {
+
+ function AnnotationPlugin()
+ {
+ global $wpdb;
+
+ $table_name = $wpdb->prefix . "annotation";
+
+ $sql = "CREATE TABLE " . $table_name . " (
+ id mediumint(9) NOT NULL AUTO_INCREMENT,
+ clientuuid VARCHAR(100) NULL,
+ annotationurl VARCHAR(100) NULL,
+ page VARCHAR(10) NULL,
+ creator VARCHAR(100) NOT NULL,
+ created datetime DEFAULT 0,
+ modified timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+ body text NOT NULL,
+ bodyurl VARCHAR(255) NOT NULL,
+ bodysvg text NULL,
+ contentcontext text NOT NULL,
+ contextwhen datetime DEFAULT 0,
+ targetcontext text NOT NULL,
+ title VARCHAR(255) NOT NULL,
+ annotates VARCHAR(255) NOT NULL,
+ target VARCHAR(255) NULL,
+ mimetype VARCHAR(100) NULL,
+ rdf text NOT NULL,
+ UNIQUE KEY id (id)
+ );";
+
+
+ if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name)
+ {
+ require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
+ dbDelta($sql);
+ }
+ else //TO DELETE: just for testing purposes
+ {
+ //$tsql = "DROP TABLE " . $table_name;
+ //dbDelta($tsql);
+ //dbDelta($sql);
+ }
+
+ $table_name = $wpdb->prefix . "annotation_userid";
+ $sql = "CREATE TABLE " . $table_name . " ( userid VARCHAR(64) );";
+ if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name)
+ {
+ require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
+ dbDelta($sql);
+ }
+ }
+
+ /**
+ * Get a specific annotation record
+ *
+ * @param string $record URL of the annotated resource
+ */
+ function annotation_record($record=null)
+ {
+ //return $this->get_annotation_record($record);
+ }
+
+ function get_author_info_from_request_uri()
+ {
+ if (preg_match('/author\/(.+)\/$/', $_SERVER["REQUEST_URI"], $result))
+ {
+ $_GET['author_name'] = $result[1];
+ return $result[1];
+ }
+ return false;
+ }
+
+ }//class AnnotationPlugin
+
+ }//if(!class_exists("AnnotationPlugin"))
+
+
+ //
+ // crate the pubman plugin
+ //
+ if(class_exists("AnnotationPlugin") && !isset($annotationPlugin))
+ {
+ $annotationPlugin = new AnnotationPlugin();
+ register_activation_hook('annotation/annotation_plugin.php', 'annotation_activate');
+ if ( function_exists('register_uninstall_hook') ) {
+ register_uninstall_hook('annotation/annotation_plugin.php', 'annotation_uninstall');
+ }
+
+
+ /**
+ * Activate plugin.
+ */
+
+ if(!function_exists('annotation_activate'))
+ {
+ function annotation_activate()
+ {
+ global $annotationPlugin;
+ if(!$annotationPlugin)
+ {
+ $annotationPlugin = new AnnotationPlugin();
+ }
+ }
+ }
+
+ /**
+ * Uninstall plugin.
+ */
+ if(!function_exists('annotation_uninstall'))
+ {
+ function annotation_uninstall()
+ {
+ //delete_option('annotation_option');
+ }
+ }
+
+
+
+ }
+
+
+?>
diff --git a/annotation/readme.txt b/annotation/readme.txt
new file mode 100755
index 0000000..67c6da0
--- /dev/null
+++ b/annotation/readme.txt
@@ -0,0 +1,19 @@
+=== FOAF Profile ===
+Contributors: Andreas Gros
+Tags: Annotation sharing plugin for wordpress that's the counterpart for the anno activity
+equires at least: 2.6
+Tested up to: 3.0.4
+Stable tag: trunk
+
+
+This wordpress plugin serves as an annotation server
+
+
+== Description ==
+This wordpress plugin serves as an annotation server. The anno activity syncs its annotations with this plugin.
+
+== Installation ==
+
+Copy the 'annotation' directory into your wordpress/wp-content/plugins/ directory and activate the plugin in the admin section of your wordpress blog
+
+