* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+require_once('common/include/rdfutils.php');
+
class foafprofilesPlugin extends Plugin {
public function __construct($id=0) {
$this->Plugin($id) ;
$this->name = "foafprofiles";
- $this->text = "FOAFProfiles!"; // To show in the tabs, use...
- //$this->_addHook("user_personal_links");//to make a link to the user's personal part of the plugin
- //$this->_addHook("usermenu");
- //$this->_addHook("groupmenu"); // To put into the project tabs
- //$this->_addHook("groupisactivecheckbox"); // The "use ..." checkbox in editgroupinfo
- //$this->_addHook("groupisactivecheckboxpost"); //
- //$this->_addHook("userisactivecheckbox"); // The "use ..." checkbox in user account
- //$this->_addHook("userisactivecheckboxpost"); //
- //$this->_addHook("project_admin_plugins"); // to show up in the admin page fro group
+ $this->text = "User FOAF Profiles"; // To show in the tabs, use...
$this->_addHook("script_accepted_types");
$this->_addHook("content_negociated_user_home");
}
-/*
- function CallHook ($hookname, &$params) {
- global $use_foafprofilesplugin,$G_SESSION,$HTML;
- if ($hookname == "usermenu") {
- $text = $this->text; // this is what shows in the tab
- if ($G_SESSION->usesPlugin("foafprofiles")) {
- $param = '?type=user&id=' . $G_SESSION->getId() . "&pluginname=" . $this->name; // we indicate the part we're calling is the user one
- echo ' | ' . $HTML->PrintSubMenu (array ($text),
- array ('/plugins/foafprofiles/index.php' . $param ));
- }
- } elseif ($hookname == "groupmenu") {
- $group_id=$params['group'];
- $project = &group_get_object($group_id);
- if (!$project || !is_object($project)) {
- return;
- }
- if ($project->isError()) {
- return;
- }
- if (!$project->isProject()) {
- return;
- }
- if ( $project->usesPlugin ( $this->name ) ) {
- $params['TITLES'][]=$this->text;
- $params['DIRS'][]=util_make_url ('/plugins/foafprofiles/index.php?type=group&id=' . $group_id . "&pluginname=" . $this->name) ; // we indicate the part we're calling is the project one
- } else {
- $params['TITLES'][]=$this->text." is [Off]";
- $params['DIRS'][]='';
- }
- (($params['toptab'] == $this->name) ? $params['selected']=(count($params['TITLES'])-1) : '' );
- } elseif ($hookname == "groupisactivecheckbox") {
- //Check if the group is active
- // this code creates the checkbox in the project edit public info page to activate/deactivate the plugin
- $group_id=$params['group'];
- $group = &group_get_object($group_id);
- echo "<tr>";
- echo "<td>";
- echo ' <input type="checkbox" name="use_foafprofilesplugin" value="1" ';
- // checked or unchecked?
- if ( $group->usesPlugin ( $this->name ) ) {
- echo "checked";
- }
- echo " /><br/>";
- echo "</td>";
- echo "<td>";
- echo "<strong>Use ".$this->text." Plugin</strong>";
- echo "</td>";
- echo "</tr>";
- } elseif ($hookname == "groupisactivecheckboxpost") {
- // this code actually activates/deactivates the plugin after the form was submitted in the project edit public info page
- $group_id=$params['group'];
- $group = &group_get_object($group_id);
- $use_foafprofilesplugin = getStringFromRequest('use_foafprofilesplugin');
- if ( $use_foafprofilesplugin == 1 ) {
- $group->setPluginUse ( $this->name );
- } else {
- $group->setPluginUse ( $this->name, false );
- }
- } elseif ($hookname == "user_personal_links") {
- // this displays the link in the user's profile page to it's personal FOAFProfiles (if you want other sto access it, youll have to change the permissions in the index.php
- $userid = $params['user_id'];
- $user = user_get_object($userid);
- $text = $params['text'];
- //check if the user has the plugin activated
- if ($user->usesPlugin($this->name)) {
- echo ' <p>' ;
- echo util_make_link ("/plugins/foafprofiles/index.php?id=$userid&type=user&pluginname=".$this->name,
- _('View Personal FOAFProfiles')
- );
- echo '</p>';
- }
- } elseif ($hookname == "project_admin_plugins") {
- // this displays the link in the project admin options page to it's FOAFProfiles administration
- $group_id = $params['group_id'];
- $group = &group_get_object($group_id);
- if ( $group->usesPlugin ( $this->name ) ) {
- echo '<p>'.util_make_link ("/plugins/foafprofiles/admin/index.php?id=".$group->getID().'&type=admin&pluginname='.$this->name,
- _('FOAFProfiles Admin')).'</p>' ;
- }
- }
- elseif ($hookname == "blahblahblah") {
- // ...
- }
- }
- */
/**
* Declares itself as accepting RDF XML on /users
$mbox = 'mailto:'.$user_email;
$mbox_sha1sum = sha1($mbox);
- $params['content'] = '<?xml version="1.0"?>
- <rdf:RDF
- xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
- xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
- xmlns:foaf="http://xmlns.com/foaf/0.1/"
- xmlns:sioc="http://rdfs.org/sioc/ns#">
+ $projects = $user_obj->getGroups() ;
+ sortProjectList($projects) ;
+ $roles = RBACEngine::getInstance()->getAvailableRolesForUser($user_obj) ;
+ sortRoleList($roles) ;
+
+ // Construct an ARC2_Resource containing the project's RDF (DOAP) description
+ $ns = array(
+ 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
+ 'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#',
+ 'foaf' => 'http://xmlns.com/foaf/0.1/',
+ 'sioc' => 'http://rdfs.org/sioc/ns#',
+ 'doap' => 'http://usefulinc.com/ns/doap#',
+ 'dcterms' => 'http://purl.org/dc/terms/',
+ 'planetforge' => 'http://coclico-project.org/ontology/planetforge#'
+ );
+
+ $conf = array(
+ 'ns' => $ns
+ );
+
+ // First, let's deal with the account
+ $account_res = ARC2::getResource($conf);
+ $account_uri = util_make_url_u($username, $user_obj->getID());
+ $account_uri = rtrim($account_uri,'/');
+ $person_uri = $account_uri . '#person';
+
+ $account_res->setURI( $account_uri );
+ // $account_res->setRel('rdf:type', 'foaf:OnlineAccount');
+ rdfutils_setPropToUri($account_res, 'rdf:type', 'foaf:OnlineAccount');
+ rdfutils_setPropToUri($account_res, 'foaf:accountServiceHomepage', $account_uri . '/');
+ $account_res->setProp('foaf:accountName', $username);
+ rdfutils_setPropToUri($account_res, 'sioc:account_of', $person_uri);
+ rdfutils_setPropToUri($account_res, 'foaf:accountProfilePage', $account_uri);
- <foaf:OnlineAccount rdf:about="">
- <foaf:accountServiceHomepage rdf:resource="/"/>
- <foaf:accountName>'. $username .'</foaf:accountName>
- <sioc:account_of rdf:resource="#person" />
- <foaf:accountProfilePage rdf:resource="" />
- </foaf:OnlineAccount>
+ $groups_index = array();
+ $projects_index = array();
+ $roles_index = array();
+
+ $usergroups_uris = array();
+ // see if there were any groups
+ if (count($projects) >= 1) {
+ foreach ($projects as $p) {
+ // TODO : report also private projects if authenticated, for instance through OAuth
+ if($p->isPublic()) {
+ $project_link = util_make_link_g ($p->getUnixName(),$p->getID(),$p->getPublicName());
+ $project_uri = util_make_url_g ($p->getUnixName(),$p->getID());
+ // sioc:UserGroups for all members of a project are named after /projects/A_PROJECT/members/
+ $usergroup_uri = $project_uri .'members/';
- <foaf:Person rdf:ID="person">
- <foaf:name>'. $username .'</foaf:name>
- <foaf:holdsAccount rdf:resource="" />
- <foaf:mbox_sha1sum>'. $mbox_sha1sum .'</foaf:mbox_sha1sum>
- </foaf:Person>
+ $role_names = array();
+
+ $usergroups_uris[] = $usergroup_uri;
+
+ $usergroup_res = ARC2::getResource($conf);
+ $usergroup_res->setURI( $usergroup_uri );
+ rdfutils_setPropToUri($usergroup_res, 'rdf:type', 'sioc:UserGroup');
+ rdfutils_setPropToUri($usergroup_res, 'sioc:usergroup_of', $project_uri);
- </rdf:RDF>';
+ $roles_uris = array();
+ foreach ($roles as $r) {
+ if ($r instanceof RoleExplicit
+ && $r->getHomeProject() != NULL
+ && $r->getHomeProject()->getID() == $p->getID()) {
+ $role_names[$r->getID()] = $r->getName() ;
+ $role_uri = $project_uri .'roles/'.$r->getID();
+
+ $roles_uris[] = $role_uri;
+ }
+ }
+ rdfutils_setPropToUri($usergroup_res, 'planetforge:group_has_function', $roles_uris);
+ $project_res = ARC2::getResource($conf);
+ $project_res->setURI( $project_uri );
+ rdfutils_setPropToUri($project_res, 'rdf:type', 'planetforge:ForgeProject');
+ $project_res->setProp('doap:name', $p->getUnixName());
+
+ $projects_index = ARC2::getMergedIndex($projects_index, $project_res->index);
+
+
+ foreach ($role_names as $id => $name) {
+ $role_res = ARC2::getResource($conf);
+ $role_res->setURI( $project_uri .'roles/'.$id );
+ rdfutils_setPropToUri($role_res, 'rdf:type', 'sioc:Role');
+ $role_res->setProp('sioc:name', $name);
+
+ $roles_index = ARC2::getMergedIndex($roles_index, $role_res->index);
+ }
+
+ $groups_index = ARC2::getMergedIndex($groups_index, $usergroup_res->index);
+
+ }
+ }
+ } // end if groups
+ rdfutils_setPropToUri($account_res, 'sioc:member_of', $usergroups_uris);
+
+ // next, deal with the person
+ $person_res = ARC2::getResource($conf);
+
+ $person_res->setURI( $person_uri );
+ rdfutils_setPropToUri($person_res, 'rdf:type', 'foaf:Person');
+ $person_res->setProp('foaf:name', $user_real_name);
+ rdfutils_setPropToUri($person_res, 'foaf:holdsAccount', $account_uri);
+ $person_res->setProp('foaf:mbox_sha1sum', $mbox_sha1sum);
+
+ // merge the two sets of triples
+ $merged_index = ARC2::getMergedIndex($account_res->index, $person_res->index);
+ $merged_index = ARC2::getMergedIndex($merged_index, $groups_index);
+ $merged_index = ARC2::getMergedIndex($merged_index, $projects_index);
+ $merged_index = ARC2::getMergedIndex($merged_index, $roles_index);
+
+ $conf = array(
+ 'ns' => $ns,
+ 'serializer_type_nodes' => true
+ );
+
+ $ser = ARC2::getRDFXMLSerializer($conf);
+
+ /* Serialize a resource index */
+ $doc = $ser->getSerializedIndex($merged_index);
+
+ $params['content'] = $doc . "\n";
}
}
}