* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+\r
require_once('common/include/ProjectManager.class.php');
+require_once('common/include/rdfutils.php');\r
class doaprdfPlugin extends Plugin {
public function __construct($id=0) {
$group_id = $params['group_id'];
if($accept == 'application/rdf+xml') {
+
+ // connect to FusionForge internals
$pm = ProjectManager::instance();
$project = $pm->getProject($group_id);
$project_shortdesc = $project->getPublicName();
$tags_list = $group->getTags();
}
+ // We will return RDF+XML
$params['content_type'] = 'application/rdf+xml';
- // invoke the 'project_rdf_metadata' hook so as to complement the RDF description
- // Invoke plugins' hooks 'script_accepted_types' to discover which alternate content types they would accept for /users/...
+ // Construct an ARC2_Resource containing the project's RDF (DOAP) description
+ $ns = array(\r
+ 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',\r
+ 'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#',\r
+ 'doap' => 'http://usefulinc.com/ns/doap#',\r
+ 'dcterms' => 'http://purl.org/dc/terms/' /*,\r
+ 'oslc' => 'http://open-services.net/ns/core#' */\r
+ );\r
+ \r
+ $conf = array(\r
+ 'ns' => $ns\r
+ /*,
+ 'serializer_type_nodes' => true*/\r
+ );\r
+ \r
+ $res = ARC2::getResource($conf);\r
+ $res->setURI('');\r
+ \r
+ //$res->setRel('rdf:type', 'doap:Project');\r
+ rdfutils_setPropToUri($res, 'rdf:type', 'doap:Project');\r
+ \r
+ $res->setProp('doap:name', $projectname);\r
+ $res->setProp('doap:shortdesc', $project_shortdesc);\r
+ if($project_description) {\r
+ $res->setProp('doap:description', $project_description);\r
+ }\r
+ if($tags_list) {\r
+ $tags = split(', ',$tags_list);\r
+ $res->setProp('dcterms:subject', $tags);\r
+ }\r
+
+ // Now, we need to collect complementary RDF descriptiosn of the project via other plugins \r
+ // invoke the 'project_rdf_metadata' hook so as to complement the RDF description\r
$hook_params = array();
- $hook_params['prefixes'] = array(
- 'http://www.w3.org/1999/02/22-rdf-syntax-ns#' => 'rdf',
- 'http://www.w3.org/2000/01/rdf-schema#' => 'rdfs',
- 'http://usefulinc.com/ns/doap#' => 'doap',
- 'http://purl.org/dc/terms/' => 'dcterms'
- );
- $hook_params['xml'] = array();
- $hook_params['group'] = $group_id;
-
- plugin_hook_by_reference('project_rdf_metadata', $hook_params);
-
- $xml = '<?xml version="1.0"?>
- <rdf:RDF';
- foreach($hook_params['prefixes'] as $url => $prefix) {
- $xml .= ' xmlns:'. $prefix . '="'. $url .'"';
- }
-
- $xml .='>
-
- <doap:Project rdf:about="">
- <doap:name>'. $projectname .'</doap:name>';
- $xml .= '<doap:shortdesc>'. $project_shortdesc . '</doap:shortdesc>';
- if($project_description) {
- $xml .= '<doap:description>'. $project_description . '</doap:description>';
- }
- if($tags_list) {
- $tags = split(', ',$tags_list);
- foreach($tags as $tag) {
- $xml .= '<dcterms:subject>'.$tag.'</dcterms:subject>';
- }
- }
- if (count($hook_params['xml'])) {
- foreach($hook_params['xml'] as $fragment) {
- $xml .= $fragment;
- }
+ $hook_params['prefixes'] = array();
+ foreach($ns as $prefix => $url) {
+ $hook_params['prefixes'][$url] = $prefix;
}
+ /*\r
+ $hook_params['prefixes'] = array(\r
+ 'http://www.w3.org/1999/02/22-rdf-syntax-ns#' => 'rdf',\r
+ 'http://www.w3.org/2000/01/rdf-schema#' => 'rdfs',\r
+ 'http://usefulinc.com/ns/doap#' => 'doap',\r
+ 'http://purl.org/dc/terms/' => 'dcterms'\r
+ );
+ */\r
+ $hook_params['group'] = $group_id;\r
- $xml .='</doap:Project>
- </rdf:RDF>';
+ // pass the resource in case it could be useful (read-only in principle)\r
+ $hook_params['in_Resource'] = $res;\r
+
+ $hook_params['out_Resources'] = array();\r
+ \r
+ plugin_hook_by_reference('project_rdf_metadata', $hook_params);\r
+
+ // add new prefixes to the list
+ foreach($hook_params['prefixes'] as $url => $prefix) {
+ if (!isset($ns[$prefix])) {\r
+ $ns[$prefix] = $url;
+ }\r
+ }\r
+
+ $merged_index = $res->index;\r
+ foreach($hook_params['out_Resources'] as $out_res) {
+ $merged_index = ARC2::getMergedIndex($merged_index, $out_res->index);
+ }\r
+
+ $conf = array(\r
+ 'ns' => $ns,\r
+ 'serializer_type_nodes' => true\r
+ );\r
- $doc = new DOMDocument();
- $doc->preserveWhiteSpace = false;
- $doc->formatOutput = true;
- $doc->loadXML($xml);
-
- $params['content'] = $doc->saveXML();
+ $ser = ARC2::getRDFXMLSerializer($conf);\r
+ \r
+ /* Serialize a resource index */\r
+ $doc = $ser->getSerializedIndex($merged_index);\r
+
+ $params['content'] = $doc;
}
}
}