4 * foafprofilesPlugin Class
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 class foafprofilesPlugin extends Plugin {
29 public function __construct($id=0) {
31 $this->name = "foafprofiles";
32 $this->text = "User FOAF Profiles"; // To show in the tabs, use...
33 $this->_addHook("script_accepted_types");
34 $this->_addHook("content_negociated_user_home");
39 * Declares itself as accepting RDF XML on /users
40 * @param unknown_type $params
42 function script_accepted_types (&$params) {
43 $script = $params['script'];
44 if ($script == 'user_home') {
45 $params['accepted_types'][] = 'application/rdf+xml';
50 * Outputs user's FOAF profile
51 * @param unknown_type $params
53 function content_negociated_user_home (&$params) {
54 $username = $params['username'];
55 $accept = $params['accept'];
57 if($accept == 'application/rdf+xml') {
58 $params['content_type'] = 'application/rdf+xml';
60 $user_obj = user_get_object_by_name($username);
62 $user_real_name = $user_obj->getRealName();
63 $user_email = $user_obj->getEmail();
64 $mbox = 'mailto:'.$user_email;
65 $mbox_sha1sum = sha1($mbox);
67 $projects = $user_obj->getGroups() ;
68 sortProjectList($projects) ;
69 $roles = RBACEngine::getInstance()->getAvailableRolesForUser($user_obj) ;
70 sortRoleList($roles) ;
78 // see if there were any groups
79 if (count($projects) >= 1) {
80 foreach ($projects as $p) {
81 // TODO : report also private projects if authenticated, for instance through OAuth
83 $project_link = util_make_link_g ($p->getUnixName(),$p->getID(),$p->getPublicName());
84 $project_uri = util_make_url_g ($p->getUnixName(),$p->getID());
85 // sioc:UserGroups for all members of a project are named after /projects/A_PROJECT/members/
86 $usergroup_uri = $project_uri .'members/';
88 $group_roles_xml = '';
90 $role_names = array () ;
91 foreach ($roles as $r) {
92 if ($r instanceof RoleExplicit
93 && $r->getHomeProject() != NULL
94 && $r->getHomeProject()->getID() == $p->getID()) {
95 $role_names[$r->getID()] = $r->getName() ;
96 $role_uri = $project_uri .'roles/'.$r->getID();
97 $group_roles_xml .= '<planetforge:group_has_function rdf:resource="'. $role_uri .'" />';
101 $member_of_xml .= '<sioc:member_of rdf:resource="'. $usergroup_uri .'" />';
102 $groups_xml .= '<sioc:UserGroup rdf:about="'. $usergroup_uri .'">
103 <sioc:usergroup_of rdf:resource="'. $project_uri .'"/>';
105 $groups_xml .= $group_roles_xml;
107 $groups_xml .= '</sioc:UserGroup>';
108 $projects_xml .= '<planetforge:ForgeProject rdf:about="'. $project_uri .'">
109 <doap:name>'. $p->getUnixName() .'</doap:name>
110 </planetforge:ForgeProject>';
112 foreach ($role_names as $id => $name) {
113 $projects_xml .= '<sioc:Role rdf:about="'. $project_uri .'roles/'.$id .'">
114 <sioc:name>'. $name .'</sioc:name>
121 $xml_content = '<?xml version="1.0"?>
123 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
124 xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
125 xmlns:foaf="http://xmlns.com/foaf/0.1/"
126 xmlns:sioc="http://rdfs.org/sioc/ns#"
127 xmlns:doap="http://usefulinc.com/ns/doap#"
128 xmlns:planetforge="http://coclico-project.org/ontology/planetforge#">
130 <foaf:OnlineAccount rdf:about="">
131 <foaf:accountServiceHomepage rdf:resource="/"/>
132 <foaf:accountName>'. $username .'</foaf:accountName>
133 <sioc:account_of rdf:resource="#person" />
134 <foaf:accountProfilePage rdf:resource="" />';
136 $xml_content .= $member_of_xml;
138 $xml_content .= '</foaf:OnlineAccount>
140 <foaf:Person rdf:ID="person">
141 <foaf:name>'. $user_real_name .'</foaf:name>
142 <foaf:holdsAccount rdf:resource="" />
143 <foaf:mbox_sha1sum>'. $mbox_sha1sum .'</foaf:mbox_sha1sum>
146 $xml_content .= $groups_xml;
148 $xml_content .= $projects_xml;
150 $xml_content .= '</rdf:RDF>';
152 $doc = new DOMDocument();
153 $doc->preserveWhiteSpace = false;
154 $doc->formatOutput = true;
155 $doc->loadXML($xml_content);
157 $params['content'] = $doc->saveXML();
164 // c-file-style: "bsd"