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.
28 require_once('common/include/ProjectManager.class.php');
30 class doaprdfPlugin extends Plugin {
31 public function __construct($id=0) {
33 $this->name = "doaprdf";
34 $this->text = "DoaPRDF!"; // To show in the tabs, use...
35 $this->_addHook("script_accepted_types");
36 $this->_addHook("content_negociated_project_home");
41 * Declares itself as accepting RDF XML on /users
42 * @param unknown_type $params
44 function script_accepted_types (&$params) {
45 $script = $params['script'];
46 if ($script == 'project_home') {
47 $params['accepted_types'][] = 'application/rdf+xml';
52 * Outputs user's FOAF profile
53 * @param unknown_type $params
55 function content_negociated_project_home (&$params) {
56 $projectname = $params['groupname'];
57 $accept = $params['accept'];
58 $group_id = $params['group_id'];
60 if($accept == 'application/rdf+xml') {
61 $pm = ProjectManager::instance();
62 $project = $pm->getProject($group_id);
63 $project_shortdesc = $project->getPublicName();
64 $project_description = $project->getDescription();
66 if (forge_get_config('use_project_tags')) {
67 $group = group_get_object($group_id);
68 $tags_list = $group->getTags();
71 $params['content_type'] = 'application/rdf+xml';
73 // invoke the 'project_rdf_metadata' hook so as to complement the RDF description
74 // Invoke plugins' hooks 'script_accepted_types' to discover which alternate content types they would accept for /users/...
75 $hook_params = array();
76 $hook_params['prefixes'] = array(
77 'http://www.w3.org/1999/02/22-rdf-syntax-ns#' => 'rdf',
78 'http://www.w3.org/2000/01/rdf-schema#' => 'rdfs',
79 'http://usefulinc.com/ns/doap#' => 'doap',
80 'http://purl.org/dc/terms/' => 'dcterms'
82 $hook_params['xml'] = array();
83 $hook_params['group'] = $group_id;
85 plugin_hook_by_reference('project_rdf_metadata', $hook_params);
87 $xml = '<?xml version="1.0"?>
89 foreach($hook_params['prefixes'] as $url => $prefix) {
90 $xml .= ' xmlns:'. $prefix . '="'. $url .'"';
95 <doap:Project rdf:about="">
96 <doap:name>'. $projectname .'</doap:name>';
97 $xml .= '<doap:shortdesc>'. $project_shortdesc . '</doap:shortdesc>';
98 if($project_description) {
99 $xml .= '<doap:description>'. $project_description . '</doap:description>';
102 $tags = split(', ',$tags_list);
103 foreach($tags as $tag) {
104 $xml .= '<dcterms:subject>'.$tag.'</dcterms:subject>';
108 if (count($hook_params['xml'])) {
109 foreach($hook_params['xml'] as $fragment) {
114 $xml .='</doap:Project>
117 $doc = new DOMDocument();
118 $doc->preserveWhiteSpace = false;
119 $doc->formatOutput = true;
122 $params['content'] = $doc->saveXML();
129 // c-file-style: "bsd"