6 * Copyright 2012, Olivier Berger & Institut Mines-Telecom
8 * This file is part of FusionForge. FusionForge is free software;
9 * you can redistribute it and/or modify it under the terms of the
10 * GNU General Public License as published by the Free Software
11 * Foundation; either version 2 of the Licence, or (at your option)
14 * FusionForge is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 //require_once('common/include/ProjectManager.class.php');
26 //require_once('common/include/rdfutils.php');
28 class admsswPlugin extends Plugin {
29 public function __construct($id=0) {
31 $this->name = "admssw";
32 $this->text = "ADMS.SW"; // To show in the tabs, use...
34 $this->_addHook("project_rdf_metadata"); // will provide some RDF metadata for the project's DOAP profile to 'doaprdf' plugin
35 $this->_addHook("alt_representations");
36 $this->_addHook("script_accepted_types");
37 $this->_addHook("content_negociated_projects_list");
42 * Declares itself as accepting RDF XML on /projects/...
43 * @param unknown_type $params
45 function project_rdf_metadata (&$params) {
47 # TODO : create another resource
48 $group_id=$params['group'];
50 $new_prefixes = array('admssw' => 'http://purl.org/adms/sw/',
51 'rad' => 'http://www.w3.org/ns/radion#',
52 'schema' => 'http://schema.org/');
53 foreach($new_prefixes as $s => $u)
55 if (! isset($params['prefixes'][$u])) {
56 $params['prefixes'][$u] = $s;
60 $res = $params['in_Resource'];
62 // we could save the type doap:Project in such case, as there's an equivalence, but not sure all consumers do reasoning
63 $types = array('doap:Project', 'admssw:SoftwareProject');
64 rdfutils_setPropToUri($res, 'rdf:type', $types);
67 if (forge_get_config('use_project_tags')) {
68 $group = group_get_object($group_id);
69 $tags_list = $group->getTags();
71 // connect to FusionForge internals
72 $pm = ProjectManager::instance();
73 $project = $pm->getProject($group_id);
77 $tags = split(', ',$tags_list);
79 // reuse the same as dcterms:subject until further specialization of adms.sw keywords
80 $res->setProp('rad:keyword', $tags);
83 $project_description = $project->getDescription();
84 if($project_description) {
85 // it seems that doap:description is not equivalent to dcterms:description, so repeat
86 $res->setProp('dcterms:description', $project_description);
89 $res->setProp('rdfs:comment', "Generated with the doaprdf and admssw plugins of fusionforge");
91 rdfutils_setPropToUri($res, 'dcterms:isPartOf', util_make_url ("/projects"));
93 $admins = $project->getAdmins() ;
94 $members = $project->getUsers() ;
95 $contributors_uris = array();
97 foreach ($admins as $u) {
98 $contributor_uri = util_make_url_u ($u->getUnixName(),$u->getID());
99 $contributor_uri = rtrim($contributor_uri, '/');
100 $contributor_uri = $contributor_uri . '#person';
101 if (! in_array($contributor_uri, $contributors_uris) ) {
102 $contributors_uris[] = $contributor_uri;
105 foreach ($members as $u) {
106 $contributor_uri = util_make_url_u ($u->getUnixName(),$u->getID());
107 $contributor_uri = rtrim($contributor_uri, '/');
108 $contributor_uri = $contributor_uri . '#person';
109 if (! in_array($contributor_uri, $contributors_uris) ) {
110 $contributors_uris[] = $contributor_uri;
113 rdfutils_setPropToUri($res, 'schema:contributor', $contributors_uris);
115 $params['out_Resources'][] = $res;
121 * Declares a link to itself in the link+meta HTML headers
122 * @param unknown_type $params
124 function alt_representations (&$params) {
125 $script_name = $params['script_name'];
126 $php_self = $params['php_self'];
127 $php_self = rtrim($php_self, '/');
128 if ($php_self == '/projects') {
129 $params['return'][] = '<link rel="meta" type="application/rdf+xml" title="ADMS.SW RDF Data" href=""/>';
135 * Declares itself as accepting RDF XML on /projects ...
136 * @param unknown_type $params
138 function script_accepted_types (&$params) {
139 $script = $params['script'];
140 if ($script == 'projects_list') {
141 $params['accepted_types'][] = 'application/rdf+xml';
146 * Outputs the public projects list as ADMS.SW for /projects
147 * @param unknown_type $params
149 function content_negociated_projects_list (&$params) {
151 $accept = $params['accept'];
153 if($accept == 'application/rdf+xml') {
156 // We will return RDF+XML
157 $params['content_type'] = 'application/rdf+xml';
159 // Construct an ARC2_Resource containing the project's RDF (DOAP) description
161 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
162 'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#',
163 'doap' => 'http://usefulinc.com/ns/doap#',
164 'dcterms' => 'http://purl.org/dc/terms/',
165 'admssw' => 'http://purl.org/adms/sw/',
166 'adms' => 'http://www.w3.org/ns/adms#'
173 $res = ARC2::getResource($conf);
174 $res->setURI( util_make_url ("/projects") );
176 // $res->setRel('rdf:type', 'doap:Project');
177 rdfutils_setPropToUri($res, 'rdf:type', 'admssw:SoftwareRepository');
179 //$res->setProp('doap:name', $projectname);
180 $res->setProp('adms:accessURL', util_make_url ("/softwaremap/") );
181 $forge_name = forge_get_config ('forge_name');
182 $ff = new FusionForge();
183 $res->setProp('dcterms:description', 'Public projects in the '. $ff->software_name .' Software Map on '. $forge_name );
184 $res->setProp('rdfs:label', $forge_name .' public projects');
185 $res->setProp('adms:supportedSchema', 'ADMS.SW v1.0');
187 // same as for trove's full list
188 $projects = get_public_active_projects_asc();
189 $proj_uris = array();
190 foreach ($projects as $row_grp) {
191 $proj_uri = util_make_url_g(strtolower($row_grp['unix_group_name']),$row_grp['group_id']);
192 $proj_uris[] = $proj_uri;
194 if(count($proj_uris)) {
195 rdfutils_setPropToUri($res, 'dcterms:hasPart', $proj_uris);
200 'serializer_type_nodes' => true
203 $ser = ARC2::getRDFXMLSerializer($conf);
205 /* Serialize a resource index */
206 $doc = $ser->getSerializedIndex($res->index);
208 $params['content'] = $doc . "\n";
217 // c-file-style: "bsd"