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("javascript"); // Add js initialization code
41 $this->_addHook("cssfile");
42 $this->_addHook("script_accepted_types");
43 $this->_addHook("content_negociated_user_home");
44 $this->_addHook("content_negociated_project_home");
47 function CallHook ($hookname, &$params) {
48 global $use_oslcplugin,$G_SESSION,$HTML;
49 if ($hookname == "usermenu") {
50 $text = $this->text; // this is what shows in the tab
51 if ($G_SESSION->usesPlugin("oslc")) {
52 $param = '?type=user&id=' . $G_SESSION->getId() . "&pluginname=" . $this->name; // we indicate the part we're calling is the user one
53 echo ' | ' . $HTML->PrintSubMenu (array ($text),
54 array ('/plugins/oslc/index.php' . $param ));
56 } elseif ($hookname == "groupmenu") {
57 $group_id=$params['group'];
58 $project = &group_get_object($group_id);
59 if (!$project || !is_object($project)) {
62 if ($project->isError()) {
65 if (!$project->isProject()) {
68 if ( $project->usesPlugin ( $this->name ) ) {
69 $params['TITLES'][]=$this->text;
70 $params['DIRS'][]=util_make_uri('/plugins/oslc/');
71 $params['ADMIN'][]='';
73 $params['TITLES'][]=$this->text." is [Off]";
75 $params['ADMIN'][]='';
77 (($params['toptab'] == $this->name) ? $params['selected']=(count($params['TITLES'])-1) : '' );
78 } elseif ($hookname == "groupisactivecheckbox") {
79 //Check if the group is active
80 // this code creates the checkbox in the project edit public info page to activate/deactivate the plugin
81 $group_id=$params['group'];
82 $group = &group_get_object($group_id);
85 echo ' <input type="checkbox" name="use_oslcplugin" value="1" ';
86 // checked or unchecked?
87 if ( $group->usesPlugin ( $this->name ) ) {
93 echo "<strong>Use ".$this->text." Plugin</strong>";
96 } elseif ($hookname == "groupisactivecheckboxpost") {
97 // this code actually activates/deactivates the plugin after the form was submitted in the project edit public info page
98 $group_id=$params['group'];
99 $group = &group_get_object($group_id);
100 $use_oslcplugin = getStringFromRequest('use_oslcplugin');
101 if ( $use_oslcplugin == 1 ) {
102 $group->setPluginUse ( $this->name );
104 $group->setPluginUse ( $this->name, false );
106 } elseif ($hookname == "userisactivecheckbox") {
107 //check if user is active
108 // this code creates the checkbox in the user account manteinance page to activate/deactivate the plugin
109 $user = $params['user'];
112 echo ' <input type="checkbox" name="use_oslcplugin" value="1" ';
113 // checked or unchecked?
114 if ( $user->usesPlugin ( $this->name ) ) {
117 echo " /> Use ".$this->text." Plugin";
120 } elseif ($hookname == "userisactivecheckboxpost") {
121 // this code actually activates/deactivates the plugin after the form was submitted in the user account manteinance page
122 $user = $params['user'];
123 $use_oslcplugin = getStringFromRequest('use_oslcplugin');
124 if ( $use_oslcplugin == 1 ) {
125 $user->setPluginUse ( $this->name );
127 $user->setPluginUse ( $this->name, false );
131 echo ' <input type="checkbox" name="use_oslcplugin" value="1" ';
132 // checked or unchecked?
133 if ( $user->usesPlugin ( $this->name ) ) {
136 echo " /> Use ".$this->text." Plugin";
139 } elseif ($hookname == "user_personal_links") {
140 // 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
141 $userid = $params['user_id'];
142 $user = user_get_object($userid);
143 $text = $params['text'];
144 //check if the user has the plugin activated
145 if ($user->usesPlugin($this->name)) {
147 echo util_make_link ("/plugins/oslc/index.php?id=$userid&type=user&pluginname=".$this->name,
148 _('View Personal oslc')
152 } elseif ($hookname == "project_admin_plugins") {
153 // this displays the link in the project admin options page to it's oslc administration
154 $group_id = $params['group_id'];
155 $group = &group_get_object($group_id);
156 if ( $group->usesPlugin ( $this->name ) ) {
157 echo '<p>'.util_make_link ("/plugins/oslc/admin/index.php?id=".$group->getID().'&type=admin&pluginname='.$this->name,
158 _('oslc Admin')).'</p>' ;
161 elseif ($hookname == "user_link_with_tooltip"){
162 require_once dirname( __FILE__ ) . '/compactResource.class.php';
163 $cR = new compactResource($params);
164 $params['user_link'] = $cR->getResourceLink();
166 elseif ($hookname == "project_link_with_tooltip") {
167 require_once dirname( __FILE__ ) . '/compactResource.class.php';
168 $cR = new compactResource($params);
169 $params['group_link'] = $cR->getResourceLink();
171 elseif ($hookname == "javascript_file") {
172 use_javascript('/scripts/jquery/jquery.js');
173 use_javascript('/plugins/oslc/scripts/oslcTooltip.js');
175 elseif ($hookname == "javascript") {
176 // make sure jquery won't conflict with prototype
177 echo 'jQuery.noConflict();';
179 elseif ($hookname == "cssfile") {
180 use_stylesheet('/plugins/oslc/css/oslcTooltipStyle.css');
182 elseif($hookname == "script_accepted_types"){
183 $script = $params['script'];
184 if ($script == 'user_home' || $script == 'project_home') {
185 $params['accepted_types'][] = 'application/x-oslc-compact+xml';
188 elseif($hookname == "content_negociated_user_home") {
189 $username = $params['username'];
190 $accept = $params['accept'];
191 if($accept == 'application/x-oslc-compact+xml') {
192 $params['return'] = '/plugins/oslc/compact/user/'.$username;
195 elseif($hookname == "content_negociated_project_home") {
196 $projectname = $params['groupname'];
197 $accept = $params['accept'];
198 if($accept == 'application/x-oslc-compact+xml') {
199 $params['return'] = '/plugins/oslc/compact/project/'.$projectname;
202 elseif ($hookname == "blahblahblah") {
210 // c-file-style: "bsd"