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
20 * along with FusionForge; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 class oslcPlugin extends Plugin {
25 public function __construct($id=0) {
28 $this->text = "oslc"; // To show in the tabs, use...
29 $this->_addHook("user_personal_links");//to make a link to the user's personal part of the plugin
30 $this->_addHook("usermenu");
31 $this->_addHook("groupmenu"); // To put into the project tabs
32 $this->_addHook("groupisactivecheckbox"); // The "use ..." checkbox in editgroupinfo
33 $this->_addHook("groupisactivecheckboxpost"); //
34 $this->_addHook("userisactivecheckbox"); // The "use ..." checkbox in user account
35 $this->_addHook("userisactivecheckboxpost"); //
36 $this->_addHook("project_admin_plugins"); // to show up in the admin page fro group
37 $this->_addHook("user_link_with_tooltip");
38 $this->_addHook("project_link_with_tooltip");
39 $this->_addHook("javascript_file"); // Add js files for oslc plugin
40 $this->_addHook("cssfile");
41 $this->_addHook("script_accepted_types");
42 $this->_addHook("content_negociated_user_home");
43 $this->_addHook("content_negociated_project_home");
46 function CallHook ($hookname, &$params) {
47 global $use_oslcplugin,$G_SESSION,$HTML;
48 if ($hookname == "usermenu") {
49 $text = $this->text; // this is what shows in the tab
50 if ($G_SESSION->usesPlugin("oslc")) {
51 $param = '?type=user&id=' . $G_SESSION->getId() . "&pluginname=" . $this->name; // we indicate the part we're calling is the user one
52 echo ' | ' . $HTML->PrintSubMenu (array ($text),
53 array ('/plugins/oslc/index.php' . $param ));
55 } elseif ($hookname == "groupmenu") {
56 $group_id=$params['group'];
57 $project = &group_get_object($group_id);
58 if (!$project || !is_object($project)) {
61 if ($project->isError()) {
64 if (!$project->isProject()) {
67 if ( $project->usesPlugin ( $this->name ) ) {
68 $params['TITLES'][]=$this->text;
69 $params['DIRS'][]=util_make_uri('/plugins/oslc/');
70 $params['ADMIN'][]='';
72 $params['TITLES'][]=$this->text." is [Off]";
74 $params['ADMIN'][]='';
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_oslcplugin" 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_oslcplugin = getStringFromRequest('use_oslcplugin');
100 if ( $use_oslcplugin == 1 ) {
101 $group->setPluginUse ( $this->name );
103 $group->setPluginUse ( $this->name, false );
105 } elseif ($hookname == "userisactivecheckbox") {
106 //check if user is active
107 // this code creates the checkbox in the user account manteinance page to activate/deactivate the plugin
108 $user = $params['user'];
111 echo ' <input type="checkbox" name="use_oslcplugin" value="1" ';
112 // checked or unchecked?
113 if ( $user->usesPlugin ( $this->name ) ) {
116 echo " /> Use ".$this->text." Plugin";
119 } elseif ($hookname == "userisactivecheckboxpost") {
120 // this code actually activates/deactivates the plugin after the form was submitted in the user account manteinance page
121 $user = $params['user'];
122 $use_oslcplugin = getStringFromRequest('use_oslcplugin');
123 if ( $use_oslcplugin == 1 ) {
124 $user->setPluginUse ( $this->name );
126 $user->setPluginUse ( $this->name, false );
130 echo ' <input type="checkbox" name="use_oslcplugin" value="1" ';
131 // checked or unchecked?
132 if ( $user->usesPlugin ( $this->name ) ) {
135 echo " /> Use ".$this->text." Plugin";
138 } elseif ($hookname == "user_personal_links") {
139 // 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
140 $userid = $params['user_id'];
141 $user = user_get_object($userid);
142 $text = $params['text'];
143 //check if the user has the plugin activated
144 if ($user->usesPlugin($this->name)) {
146 echo util_make_link ("/plugins/oslc/index.php?id=$userid&type=user&pluginname=".$this->name,
147 _('View Personal oslc')
151 } elseif ($hookname == "project_admin_plugins") {
152 // this displays the link in the project admin options page to it's oslc administration
153 $group_id = $params['group_id'];
154 $group = &group_get_object($group_id);
155 if ( $group->usesPlugin ( $this->name ) ) {
156 echo '<p>'.util_make_link ("/plugins/oslc/admin/index.php?id=".$group->getID().'&type=admin&pluginname='.$this->name,
157 _('oslc Admin')).'</p>' ;
160 elseif ($hookname == "user_link_with_tooltip"){
161 require_once dirname( __FILE__ ) . '/compactResource.class.php';
162 $cR = new compactResource($params);
163 $params['user_link'] = $cR->getResourceLink();
165 elseif ($hookname == "project_link_with_tooltip") {
166 require_once dirname( __FILE__ ) . '/compactResource.class.php';
167 $cR = new compactResource($params);
168 $params['group_link'] = $cR->getResourceLink();
170 elseif ($hookname == "javascript_file") {
171 use_javascript('/scripts/jquery/jquery.js');
172 use_javascript('/plugins/oslc/scripts/oslcTooltip.js');
174 elseif ($hookname == "cssfile") {
175 use_stylesheet('/plugins/oslc/css/oslcTooltipStyle.css');
177 elseif($hookname == "script_accepted_types"){
178 $script = $params['script'];
179 if ($script == 'user_home' || $script == 'project_home') {
180 $params['accepted_types'][] = 'application/x-oslc-compact+xml';
183 elseif($hookname == "content_negociated_user_home") {
184 $username = $params['username'];
185 $accept = $params['accept'];
186 if($accept == 'application/x-oslc-compact+xml') {
187 $params['return'] = '/plugins/oslc/compact/user/'.$username;
190 elseif($hookname == "content_negociated_project_home") {
191 $projectname = $params['groupname'];
192 $accept = $params['accept'];
193 if($accept == 'application/x-oslc-compact+xml') {
194 $params['return'] = '/plugins/oslc/compact/project/'.$projectname;
197 elseif ($hookname == "blahblahblah") {
205 // c-file-style: "bsd"