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("user_personal_links");//to make a link to the user's personal part of the plugin
36 //$this->_addHook("usermenu");
37 //$this->_addHook("groupmenu"); // To put into the project tabs
38 //$this->_addHook("groupisactivecheckbox"); // The "use ..." checkbox in editgroupinfo
39 //$this->_addHook("groupisactivecheckboxpost"); //
40 //$this->_addHook("userisactivecheckbox"); // The "use ..." checkbox in user account
41 //$this->_addHook("userisactivecheckboxpost"); //
42 //$this->_addHook("project_admin_plugins"); // to show up in the admin page fro group
43 $this->_addHook("script_accepted_types");
44 $this->_addHook("content_negociated_project_home");
48 function CallHook ($hookname, &$params) {
49 global $use_doaprdfplugin,$G_SESSION,$HTML;
50 if ($hookname == "usermenu") {
51 $text = $this->text; // this is what shows in the tab
52 if ($G_SESSION->usesPlugin("doaprdf")) {
53 $param = '?type=user&id=' . $G_SESSION->getId() . "&pluginname=" . $this->name; // we indicate the part we're calling is the user one
54 echo ' | ' . $HTML->PrintSubMenu (array ($text),
55 array ('/plugins/doaprdf/index.php' . $param ));
57 } elseif ($hookname == "groupmenu") {
58 $group_id=$params['group'];
59 $project = &group_get_object($group_id);
60 if (!$project || !is_object($project)) {
63 if ($project->isError()) {
66 if (!$project->isProject()) {
69 if ( $project->usesPlugin ( $this->name ) ) {
70 $params['TITLES'][]=$this->text;
71 $params['DIRS'][]=util_make_url ('/plugins/doaprdf/index.php?type=group&id=' . $group_id . "&pluginname=" . $this->name) ; // we indicate the part we're calling is the project one
73 $params['TITLES'][]=$this->text." is [Off]";
76 (($params['toptab'] == $this->name) ? $params['selected']=(count($params['TITLES'])-1) : '' );
77 } elseif ($hookname == "groupisactivecheckbox") {
78 //Check if the group is active
79 // this code creates the checkbox in the project edit public info page to activate/deactivate the plugin
80 $group_id=$params['group'];
81 $group = &group_get_object($group_id);
84 echo ' <input type="checkbox" name="use_doaprdfplugin" value="1" ';
85 // checked or unchecked?
86 if ( $group->usesPlugin ( $this->name ) ) {
92 echo "<strong>Use ".$this->text." Plugin</strong>";
95 } elseif ($hookname == "groupisactivecheckboxpost") {
96 // this code actually activates/deactivates the plugin after the form was submitted in the project edit public info page
97 $group_id=$params['group'];
98 $group = &group_get_object($group_id);
99 $use_doaprdfplugin = getStringFromRequest('use_doaprdfplugin');
100 if ( $use_doaprdfplugin == 1 ) {
101 $group->setPluginUse ( $this->name );
103 $group->setPluginUse ( $this->name, false );
105 } elseif ($hookname == "user_personal_links") {
106 // this displays the link in the user's profile page to it's personal DoaPRDF (if you want other sto access it, youll have to change the permissions in the index.php
107 $userid = $params['user_id'];
108 $user = user_get_object($userid);
109 $text = $params['text'];
110 //check if the user has the plugin activated
111 if ($user->usesPlugin($this->name)) {
113 echo util_make_link ("/plugins/doaprdf/index.php?id=$userid&type=user&pluginname=".$this->name,
114 _('View Personal DoaPRDF')
118 } elseif ($hookname == "project_admin_plugins") {
119 // this displays the link in the project admin options page to it's DoaPRDF administration
120 $group_id = $params['group_id'];
121 $group = &group_get_object($group_id);
122 if ( $group->usesPlugin ( $this->name ) ) {
123 echo '<p>'.util_make_link ("/plugins/doaprdf/admin/index.php?id=".$group->getID().'&type=admin&pluginname='.$this->name,
124 _('DoaPRDF Admin')).'</p>' ;
127 elseif ($hookname == "blahblahblah") {
134 * Declares itself as accepting RDF XML on /users
135 * @param unknown_type $params
137 function script_accepted_types (&$params) {
138 $script = $params['script'];
139 if ($script == 'project_home') {
140 $params['accepted_types'][] = 'application/rdf+xml';
145 * Outputs user's FOAF profile
146 * @param unknown_type $params
148 function content_negociated_project_home (&$params) {
149 $projectname = $params['groupname'];
150 $accept = $params['accept'];
151 $group_id = $params['group_id'];
153 if($accept == 'application/rdf+xml') {
154 $pm = ProjectManager::instance();
155 $project = $pm->getProject($group_id);
156 $project_description = $project->getDescription();
158 if (forge_get_config('use_project_tags')) {
159 $group = group_get_object($group_id);
160 $tags_list = $group->getTags();
163 $params['content_type'] = 'application/rdf+xml';
165 // invoke the 'project_rdf_metadata' hook so as to complement the RDF description
166 // Invoke plugins' hooks 'script_accepted_types' to discover which alternate content types they would accept for /users/...
167 $hook_params = array();
168 $hook_params['prefixes'] = array(
169 'http://www.w3.org/1999/02/22-rdf-syntax-ns#' => 'rdf',
170 'http://www.w3.org/2000/01/rdf-schema#' => 'rdfs',
171 'http://usefulinc.com/ns/doap#' => 'doap',
172 'http://purl.org/dc/terms/' => 'dcterms'
174 $hook_params['xml'] = array();
175 $hook_params['group'] = $group_id;
177 plugin_hook_by_reference('project_rdf_metadata', $hook_params);
179 $xml = '<?xml version="1.0"?>
181 foreach($hook_params['prefixes'] as $url => $prefix) {
182 $xml .= ' xmlns:'. $prefix . '="'. $url .'"';
187 <doap:Project rdf:about="">
188 <doap:name>'. $projectname .'</doap:name>';
189 if($project_description) {
190 $xml .= '<doap:shortdesc>'. $project_description . '</doap:shortdesc>';
193 $tags = split(', ',$tags_list);
194 foreach($tags as $tag) {
195 $xml .= '<dcterms:subject>'.$tag.'</dcterms:subject>';
199 if (count($hook_params['xml'])) {
200 foreach($hook_params['xml'] as $fragment) {
205 $xml .='</doap:Project>
208 $params['content'] = $xml;
215 // c-file-style: "bsd"