4 * oauthproviderPlugin Class
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 // TODO : fix missing copyright
26 class oauthproviderPlugin extends Plugin {
27 public function __construct($id=0) {
29 $this->name = 'oauthprovider';
30 $this->text = 'OAuthProvider'; // 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("site_admin_option_hook");
40 $this->_addHook("account_menu");
43 function CallHook ($hookname, $params) {
44 global $use_oauthproviderplugin,$G_SESSION,$HTML;
45 if ($hookname == "usermenu") {
46 $text = $this->text; // this is what shows in the tab
47 if ($G_SESSION->usesPlugin("oauthprovider")) {
48 echo $HTML->PrintSubMenu (array ($text),
49 array ('/plugins/oauthprovider/index.php'), array(''));
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_url ('/plugins/oauthprovider/index.php?type=group&id=' . $group_id) ; // we indicate the part we're calling is the project one
67 $params['TITLES'][]=$this->text." is [Off]";
70 (($params['toptab'] == $this->name) ? $params['selected']=(count($params['TITLES'])-1) : '' );
71 } elseif ($hookname == "groupisactivecheckbox") {
72 //Check if the group is active
73 // this code creates the checkbox in the project edit public info page to activate/deactivate the plugin
74 $group_id=$params['group'];
75 $group = &group_get_object($group_id);
78 echo ' <input type="checkbox" name="use_oauthproviderplugin" value="1" ';
79 // checked or unchecked?
80 if ( $group->usesPlugin ( $this->name ) ) {
86 echo "<strong>Use ".$this->text." Plugin</strong>";
89 } elseif ($hookname == "groupisactivecheckboxpost") {
90 // this code actually activates/deactivates the plugin after the form was submitted in the project edit public info page
91 $group_id=$params['group'];
92 $group = &group_get_object($group_id);
93 $use_oauthproviderplugin = getStringFromRequest('use_oauthproviderplugin');
94 if ( $use_oauthproviderplugin == 1 ) {
95 $group->setPluginUse ( $this->name );
97 $group->setPluginUse ( $this->name, false );
99 }elseif ($hookname == "userisactivecheckbox") {
100 //Check if the group is active
101 // this code creates the checkbox in the project edit public info page to activate/deactivate the plugin
102 $userid = $params['user_id'];
103 $user = user_get_object($userid);
106 echo ' <input type="checkbox" name="use_oauthproviderplugin" value="1" ';
107 // checked or unchecked?
108 if ( $user->usesPlugin ( $this->name ) ) {
114 echo "<strong>Use ".$this->text." Plugin</strong>";
117 } elseif ($hookname == "userisactivecheckboxpost") {
118 // this code actually activates/deactivates the plugin after the form was submitted in the project edit public info page
119 $userid = $params['user_id'];
120 $user = user_get_object($userid);
121 $use_oauthproviderplugin = getStringFromPost('use_oauthproviderplugin');
122 if ( $use_oauthproviderplugin == 1 ) {
123 $user->setPluginUse ( $this->name );
125 $user->setPluginUse ( $this->name, false );
127 } elseif ($hookname == "user_personal_links") {
128 // this displays the link in the user's profile page to it's personal oauthprovider (if you want other sto access it, youll have to change the permissions in the index.php
129 $userid = $params['user_id'];
130 $user = user_get_object($userid);
131 $text = $params['text'];
132 //check if the user has the plugin activated
133 if ($user->usesPlugin($this->name)) {
135 echo util_make_link ("/plugins/oauthprovider/index.php?type=user",
136 _('View Personal oauthprovider')
140 } elseif ($hookname == "project_admin_plugins") {
141 // this displays the link in the project admin options page to it's oauthprovider administration
142 $group_id = $params['group_id'];
143 $group = &group_get_object($group_id);
144 if ( $group->usesPlugin ( $this->name ) ) {
145 echo '<p>'.util_make_link ("/plugins/oauthprovider/admin/index.php?id=".$group->getID().'&type=admin&pluginname='.$this->name,
146 _('oauthprovider Admin')).'</p>' ;
149 elseif ($hookname == "site_admin_option_hook") {
150 $this->site_admin_option_hook();
152 elseif ($hookname == "account_menu") {
153 $this->account_menu();
155 elseif ($hookname == "blahblahblah") {
160 function site_admin_option_hook( ) {
161 echo '<li>'. util_make_link ('/plugins/oauthprovider/consumer.php', _('Manage OAuth consumers'). ' [' . _('OAuth provider plugin') . ']'). '</li>';
164 function account_menu( ) {
165 return array( '<a href="' . $gfplugins.'oauthprovider/www/access_tokens.php' . '">' . $plugin_oauthprovider_menu_account_summary. '</a>', );