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 require_once 'common/include/rdfutils.php';
30 class foafprofilesPlugin extends Plugin {
31 public function __construct($id=0) {
33 $this->name = "foafprofiles";
34 $this->text = "User FOAF Profiles"; // To show in the tabs, use...
35 $this->_addHook("script_accepted_types");
36 $this->_addHook("content_negociated_user_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 == 'user_home') {
47 $params['accepted_types'][] = 'application/rdf+xml';
52 * Outputs user's FOAF profile
53 * @param unknown_type $params
55 function content_negociated_user_home (&$params) {
56 $username = $params['username'];
57 $accept = $params['accept'];
59 if($accept == 'application/rdf+xml') {
60 $params['content_type'] = 'application/rdf+xml';
62 $user_obj = user_get_object_by_name($username);
64 $user_real_name = $user_obj->getRealName();
65 $user_email = $user_obj->getEmail();
66 $mbox = 'mailto:'.$user_email;
67 $mbox_sha1sum = sha1($mbox);
69 $projects = $user_obj->getGroups() ;
70 sortProjectList($projects) ;
71 $roles = RBACEngine::getInstance()->getAvailableRolesForUser($user_obj) ;
72 sortRoleList($roles) ;
74 // Construct an ARC2_Resource containing the project's RDF (DOAP) description
76 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
77 'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#',
78 'foaf' => 'http://xmlns.com/foaf/0.1/',
79 'sioc' => 'http://rdfs.org/sioc/ns#',
80 'doap' => 'http://usefulinc.com/ns/doap#',
81 'dcterms' => 'http://purl.org/dc/terms/',
82 'planetforge' => 'http://coclico-project.org/ontology/planetforge#'
89 // First, let's deal with the account
90 $account_res = ARC2::getResource($conf);
91 $account_uri = util_make_url_u($username, $user_obj->getID());
92 $account_uri = rtrim($account_uri,'/');
93 $person_uri = $account_uri . '#person';
95 $account_res->setURI( $account_uri );
96 // $account_res->setRel('rdf:type', 'foaf:OnlineAccount');
97 rdfutils_setPropToUri($account_res, 'rdf:type', 'foaf:OnlineAccount');
98 rdfutils_setPropToUri($account_res, 'foaf:accountServiceHomepage', $account_uri . '/');
99 $account_res->setProp('foaf:accountName', $username);
100 rdfutils_setPropToUri($account_res, 'sioc:account_of', $person_uri);
101 rdfutils_setPropToUri($account_res, 'foaf:accountProfilePage', $account_uri);
103 $groups_index = array();
104 $projects_index = array();
105 $roles_index = array();
107 $usergroups_uris = array();
108 // see if there were any groups
109 if (count($projects) >= 1) {
110 foreach ($projects as $p) {
111 // TODO : report also private projects if authenticated, for instance through OAuth
113 $project_link = util_make_link_g ($p->getUnixName(),$p->getID(),$p->getPublicName());
114 $project_uri = util_make_url_g ($p->getUnixName(),$p->getID());
115 // sioc:UserGroups for all members of a project are named after /projects/A_PROJECT/members/
116 $usergroup_uri = $project_uri .'members/';
118 $role_names = array();
120 $usergroups_uris[] = $usergroup_uri;
122 $usergroup_res = ARC2::getResource($conf);
123 $usergroup_res->setURI( $usergroup_uri );
124 rdfutils_setPropToUri($usergroup_res, 'rdf:type', 'sioc:UserGroup');
125 rdfutils_setPropToUri($usergroup_res, 'sioc:usergroup_of', $project_uri);
127 $roles_uris = array();
128 foreach ($roles as $r) {
129 if ($r instanceof RoleExplicit
130 && $r->getHomeProject() != NULL
131 && $r->getHomeProject()->getID() == $p->getID()) {
132 $role_names[$r->getID()] = $r->getName() ;
133 $role_uri = $project_uri .'roles/'.$r->getID();
135 $roles_uris[] = $role_uri;
138 rdfutils_setPropToUri($usergroup_res, 'planetforge:group_has_function', $roles_uris);
140 $project_res = ARC2::getResource($conf);
141 $project_res->setURI( $project_uri );
142 rdfutils_setPropToUri($project_res, 'rdf:type', 'planetforge:ForgeProject');
143 $project_res->setProp('doap:name', $p->getUnixName());
145 $projects_index = ARC2::getMergedIndex($projects_index, $project_res->index);
148 foreach ($role_names as $id => $name) {
149 $role_res = ARC2::getResource($conf);
150 $role_res->setURI( $project_uri .'roles/'.$id );
151 rdfutils_setPropToUri($role_res, 'rdf:type', 'sioc:Role');
152 $role_res->setProp('sioc:name', $name);
154 $roles_index = ARC2::getMergedIndex($roles_index, $role_res->index);
157 $groups_index = ARC2::getMergedIndex($groups_index, $usergroup_res->index);
162 rdfutils_setPropToUri($account_res, 'sioc:member_of', $usergroups_uris);
164 // next, deal with the person
165 $person_res = ARC2::getResource($conf);
167 $person_res->setURI( $person_uri );
168 rdfutils_setPropToUri($person_res, 'rdf:type', 'foaf:Person');
169 $person_res->setProp('foaf:name', $user_real_name);
170 rdfutils_setPropToUri($person_res, 'foaf:holdsAccount', $account_uri);
171 $person_res->setProp('foaf:mbox_sha1sum', $mbox_sha1sum);
173 // merge the two sets of triples
174 $merged_index = ARC2::getMergedIndex($account_res->index, $person_res->index);
175 $merged_index = ARC2::getMergedIndex($merged_index, $groups_index);
176 $merged_index = ARC2::getMergedIndex($merged_index, $projects_index);
177 $merged_index = ARC2::getMergedIndex($merged_index, $roles_index);
181 'serializer_type_nodes' => true
184 $ser = ARC2::getRDFXMLSerializer($conf);
186 /* Serialize a resource index */
187 $doc = $ser->getSerializedIndex($merged_index);
189 $params['content'] = $doc . "\n";
196 // c-file-style: "bsd"