7 * This file is part of FusionForge.
9 * FusionForge is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * FusionForge is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 require_once 'common/include/rdfutils.php';
26 class oslcPlugin extends Plugin {
27 public function __construct($id=0) {
30 $this->text = "oslc"; // To show in the tabs, use...
31 $this->_addHook("user_personal_links");//to make a link to the user's personal part of the plugin
32 $this->_addHook("usermenu");
33 $this->_addHook("groupmenu"); // To put into the project tabs
34 $this->_addHook("groupisactivecheckbox"); // The "use ..." checkbox in editgroupinfo
35 $this->_addHook("groupisactivecheckboxpost"); //
36 $this->_addHook("userisactivecheckbox"); // The "use ..." checkbox in user account
37 $this->_addHook("userisactivecheckboxpost"); //
38 $this->_addHook("project_admin_plugins"); // to show up in the admin page fro group
39 $this->_addHook("project_rdf_metadata"); // will provide some RDF metadata for the project's DOAP profile to 'doaprdf' plugin
42 function CallHook ($hookname, &$params) {
43 global $use_oslcplugin,$G_SESSION,$HTML;
44 if ($hookname == "usermenu") {
45 $text = $this->text; // this is what shows in the tab
46 if ($G_SESSION->usesPlugin("oslc")) {
47 $param = '?type=user&id=' . $G_SESSION->getId() . "&pluginname=" . $this->name; // we indicate the part we're calling is the user one
48 echo $HTML->PrintSubMenu (array ($text),
49 array ('/plugins/oslc/index.php' . $param ));
51 } elseif ($hookname == "groupmenu") {
52 $group_id=$params['group'];
53 $project = &group_get_object($group_id);
54 if (!$project || !is_object($project)) {
57 if ($project->isError()) {
60 if (!$project->isProject()) {
63 if ( $project->usesPlugin ( $this->name ) ) {
64 $params['TITLES'][]=$this->text;
65 $params['DIRS'][]=util_make_uri('/plugins/oslc/');
66 $params['ADMIN'][]='';
68 $params['TITLES'][]=$this->text." is [Off]";
70 $params['ADMIN'][]='';
72 (($params['toptab'] == $this->name) ? $params['selected']=(count($params['TITLES'])-1) : '' );
73 } elseif ($hookname == "groupisactivecheckbox") {
74 //Check if the group is active
75 // this code creates the checkbox in the project edit public info page to activate/deactivate the plugin
76 $group_id=$params['group'];
77 $group = &group_get_object($group_id);
80 echo ' <input type="checkbox" name="use_oslcplugin" value="1" ';
81 // checked or unchecked?
82 if ( $group->usesPlugin ( $this->name ) ) {
88 echo "<strong>Use ".$this->text." Plugin</strong>";
91 } elseif ($hookname == "groupisactivecheckboxpost") {
92 // this code actually activates/deactivates the plugin after the form was submitted in the project edit public info page
93 $group_id=$params['group'];
94 $group = &group_get_object($group_id);
95 $use_oslcplugin = getStringFromRequest('use_oslcplugin');
96 if ( $use_oslcplugin == 1 ) {
97 $group->setPluginUse ( $this->name );
99 $group->setPluginUse ( $this->name, false );
101 } elseif ($hookname == "userisactivecheckbox") {
102 //check if user is active
103 // this code creates the checkbox in the user account manteinance page to activate/deactivate the plugin
104 $user = $params['user'];
107 echo ' <input type="checkbox" name="use_oslcplugin" value="1" ';
108 // checked or unchecked?
109 if ( $user->usesPlugin ( $this->name ) ) {
112 echo " /> Use ".$this->text." Plugin";
115 } elseif ($hookname == "userisactivecheckboxpost") {
116 // this code actually activates/deactivates the plugin after the form was submitted in the user account manteinance page
117 $user = $params['user'];
118 $use_oslcplugin = getStringFromRequest('use_oslcplugin');
119 if ( $use_oslcplugin == 1 ) {
120 $user->setPluginUse ( $this->name );
122 $user->setPluginUse ( $this->name, false );
126 echo ' <input type="checkbox" name="use_oslcplugin" value="1" ';
127 // checked or unchecked?
128 if ( $user->usesPlugin ( $this->name ) ) {
131 echo " /> Use ".$this->text." Plugin";
134 } elseif ($hookname == "user_personal_links") {
135 // this displays the link in the user's profile page to it's personal oslc (if you want other sto access it, youll have to change the permissions in the index.php
136 $userid = $params['user_id'];
137 $user = user_get_object($userid);
138 $text = $params['text'];
139 //check if the user has the plugin activated
140 if ($user->usesPlugin($this->name)) {
142 echo util_make_link ("/plugins/oslc/index.php?id=$userid&type=user&pluginname=".$this->name,
143 _('View Personal oslc')
147 } elseif ($hookname == "project_admin_plugins") {
148 // this displays the link in the project admin options page to it's oslc administration
149 $group_id = $params['group_id'];
150 $group = &group_get_object($group_id);
151 if ( $group->usesPlugin ( $this->name ) ) {
152 echo '<p>'.util_make_link ("/plugins/oslc/admin/index.php?id=".$group->getID().'&type=admin&pluginname='.$this->name,
153 _('oslc Admin')).'</p>' ;
156 elseif($hookname == "project_rdf_metadata") {
158 # TODO : create another resource
159 $group_id=$params['group'];
161 if (! isset($params['prefixes']['http://open-services.net/ns/core#'])) {
162 $params['prefixes']['http://open-services.net/ns/core#'] = 'oslc';
165 $serviceprovider = util_make_url ("/plugins/oslc/cm/oslc-cm-services/".$group_id);
167 $res = $params['in_Resource'];
169 rdfutils_setPropToUri($res, 'oslc:serviceProvider', $serviceprovider);
171 $params['out_Resources'][] = $res;
174 elseif ($hookname == "blahblahblah") {
182 // c-file-style: "bsd"