6 * Copyright 2011, Olivier Berger & Institut Telecom
8 * This program was developped in the frame of the COCLICO project
9 * (http://www.coclico-project.org/) with financial support of the Paris
12 * This file is part of FusionForge. FusionForge is free software;
13 * you can redistribute it and/or modify it under the terms of the
14 * GNU General Public License as published by the Free Software
15 * Foundation; either version 2 of the Licence, or (at your option)
18 * FusionForge is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License along
24 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 require_once('common/include/ProjectManager.class.php');
30 require_once('common/include/rdfutils.php');
32 class doaprdfPlugin extends Plugin {
33 public function __construct($id=0) {
35 $this->name = "doaprdf";
36 $this->text = "DoaPRDF!"; // To show in the tabs, use...
37 $this->_addHook("script_accepted_types");
38 $this->_addHook("content_negociated_project_home");
39 $this->_addHook("alt_representations");
44 * Declares itself as accepting RDF XML on /users
45 * @param unknown_type $params
47 function script_accepted_types (&$params) {
48 $script = $params['script'];
49 if ($script == 'project_home') {
50 $params['accepted_types'][] = 'application/rdf+xml';
55 * Outputs user's FOAF profile
56 * @param unknown_type $params
58 function content_negociated_project_home (&$params) {
59 $projectname = $params['groupname'];
60 $accept = $params['accept'];
61 $group_id = $params['group_id'];
63 if($accept == 'application/rdf+xml') {
65 // connect to FusionForge internals
66 $pm = ProjectManager::instance();
67 $project = $pm->getProject($group_id);
68 $project_shortdesc = $project->getPublicName();
69 $project_description = $project->getDescription();
71 if (forge_get_config('use_project_tags')) {
72 $group = group_get_object($group_id);
73 $tags_list = $group->getTags();
76 // We will return RDF+XML
77 $params['content_type'] = 'application/rdf+xml';
79 // Construct an ARC2_Resource containing the project's RDF (DOAP) description
81 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
82 'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#',
83 'doap' => 'http://usefulinc.com/ns/doap#',
84 'dcterms' => 'http://purl.org/dc/terms/' /*,
85 'oslc' => 'http://open-services.net/ns/core#' */
91 'serializer_type_nodes' => true*/
94 $res = ARC2::getResource($conf);
97 //$res->setRel('rdf:type', 'doap:Project');
98 rdfutils_setPropToUri($res, 'rdf:type', 'doap:Project');
100 $res->setProp('doap:name', $projectname);
101 $res->setProp('doap:shortdesc', $project_shortdesc);
102 if($project_description) {
103 $res->setProp('doap:description', $project_description);
106 $tags = split(', ',$tags_list);
107 $res->setProp('dcterms:subject', $tags);
110 // Now, we need to collect complementary RDF descriptiosn of the project via other plugins
111 // invoke the 'project_rdf_metadata' hook so as to complement the RDF description
112 $hook_params = array();
114 $hook_params['prefixes'] = array();
115 foreach($ns as $prefix => $url) {
116 $hook_params['prefixes'][$url] = $prefix;
119 $hook_params['prefixes'] = array(
120 'http://www.w3.org/1999/02/22-rdf-syntax-ns#' => 'rdf',
121 'http://www.w3.org/2000/01/rdf-schema#' => 'rdfs',
122 'http://usefulinc.com/ns/doap#' => 'doap',
123 'http://purl.org/dc/terms/' => 'dcterms'
126 $hook_params['group'] = $group_id;
128 // pass the resource in case it could be useful (read-only in principle)
129 $hook_params['in_Resource'] = $res;
131 $hook_params['out_Resources'] = array();
133 plugin_hook_by_reference('project_rdf_metadata', $hook_params);
135 // add new prefixes to the list
136 foreach($hook_params['prefixes'] as $url => $prefix) {
137 if (!isset($ns[$prefix])) {
142 $merged_index = $res->index;
143 foreach($hook_params['out_Resources'] as $out_res) {
144 $merged_index = ARC2::getMergedIndex($merged_index, $out_res->index);
149 'serializer_type_nodes' => true
152 $ser = ARC2::getRDFXMLSerializer($conf);
154 /* Serialize a resource index */
155 $doc = $ser->getSerializedIndex($merged_index);
157 $params['content'] = $doc;
162 * Declares a link to itself in the link+meta HTML headers
163 * @param unknown_type $params
165 function alt_representations (&$params) {
166 $script_name = $params['script_name'];
167 if ($script_name == '/projects') {
168 $params['return'][] = '<link rel="meta" type="application/rdf+xml" title="DOAP RDF Data" href=""/>';
176 // c-file-style: "bsd"