3 * FusionForge plugin system
5 * Copyright 2002, Roland Mas
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
11 * by the Free Software Foundation; either version 2 of the License,
12 * or (at your option) any later version.
14 * FusionForge is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * 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
24 * Portions Copyright (c) Xerox Corporation, Codendi Team, 2001-2009. All rights reserved
25 * Portions Copyright 2010 (c) Mélanie Le Bail
28 class Plugin extends Error {
33 * Plugin() - constructor
36 function Plugin ($id=0) {
39 $this->hooks = array () ;
43 * GetHooks() - get list of hooks to subscribe to
45 * @return List of strings
47 function GetHooks () {
51 * _addHooks() - add a hook to the list of hooks
53 function _addHook ($name) {
54 return $this->hooks[]=$name ;
58 * GetName() - get plugin name
60 * @return the plugin name
67 * GetInstallDir() - get installation dir for the plugin
69 * @return the directory where the plugin should be linked.
71 function GetInstallDir () {
72 if (isset($this->installdir) && $this->installdir)
73 return $this->installdir;
75 return 'plugins/'.$this->name ;
79 * provide() - return true if plugin provides the feature.
81 * @return bool if feature is provided or not.
83 function provide($feature) {
84 return (isset($this->provides[$feature]) && $this->provides[$feature]);
88 * Added for Codendi compatibility
89 * getPluginPath() - get installation dir for the plugin
91 * @return the directory where the plugin should be linked.
93 function getPluginPath () {
94 if (isset($this->installdir) && $this->installdir)
95 return $this->installdir;
97 return 'plugins/'.$this->name ;
101 * CallHook() - call a particular hook
103 * @param hookname - the "handle" of the hook
104 * @param params - array of parameters to pass the hook
106 function CallHook ($hookname, $params) {
111 * getGroups - get a list of all groups using a plugin
113 * @return array array containing group ids
115 function getGroups() {
117 $res = db_query_params ('SELECT group_plugin.group_id
118 FROM group_plugin, plugins
119 WHERE group_plugin.plugin_id=plugins.plugin_id
120 AND plugins.plugin_name=$1
121 ORDER BY group_plugin.group_id ASC',
122 array ($this->name));
123 $rows = db_numrows($res);
125 for ($i=0; $i<$rows; $i++) {
126 $group_id = db_result($res,$i,'group_id');
127 $result[] = group_get_object ($group_id) ;
133 function getThemePath(){
134 return util_make_url('plugins/'.$this->name.'/themes/default');
137 function registerRoleValues(&$params, $values) {
138 $role =& $params['role'] ;
141 function groupisactivecheckbox (&$params) {
142 //Check if the group is active
143 // this code creates the checkbox in the project edit public info page to activate/deactivate the plugin
144 $group = group_get_object($params['group']);
145 $flag = strtolower('use_'.$this->name);
148 echo ' <input type="checkbox" name="'.$flag.'" value="1" ';
149 // checked or unchecked?
150 if ( $group->usesPlugin ( $this->name ) ) {
151 echo "checked=\"checked\"";
156 echo "<strong>Use ".$this->text." Plugin</strong>";
161 function groupisactivecheckboxpost (&$params) {
162 // this code actually activates/deactivates the plugin after the form was submitted in the project edit public info page
163 $group = group_get_object($params['group']);
164 $flag = strtolower('use_'.$this->name);
165 if ( getStringFromRequest($flag) == 1 ) {
166 $group->setPluginUse ( $this->name );
168 $group->setPluginUse ( $this->name, false );
172 function userisactivecheckbox (&$params) {
173 //check if user is active
174 // this code creates the checkbox in the user account manteinance page to activate/deactivate the plugin
175 $user = $params['user'];
176 $flag = strtolower('use_'.$this->name);
179 echo ' <input type="checkbox" name="'.$flag.'" value="1" ';
180 // checked or unchecked?
181 if ( $user->usesPlugin ( $this->name ) ) {
182 echo 'checked="checked"';
184 echo " /> Use ".$this->text." Plugin";
189 function userisactivecheckboxpost (&$params) {
190 // this code actually activates/deactivates the plugin after the form was submitted in the user account manteinance page
191 $user = $params['user'];
192 $flag = strtolower('use_'.$this->name);
193 if ( getStringFromRequest($flag) == 1 ) {
194 $user->setPluginUse ( $this->name );
196 $user->setPluginUse ( $this->name, false );
200 echo ' <input type="checkbox" name="'.$flag.'" value="1" ';
201 // checked or unchecked?
202 if ( $user->usesPlugin ( $this->name ) ) {
203 echo 'checked="checked"';
205 echo " /> Use ".$this->text." Plugin";
211 class PluginSpecificRoleSetting {
215 var $values = array () ;
216 var $default_values = array () ;
217 var $global = false ;
219 function PluginSpecificRoleSetting (&$role, $name, $global = false) {
220 $this->global = $global ;
221 $this->role =& $role ;
222 $this->name = $name ;
225 function SetAllowedValues ($values) {
226 $this->role->role_values = array_replace_recursive ($this->role->role_values,
227 array ($this->name => $values)) ;
229 $this->role->global_settings[] = $this->name ;
233 function SetDefaultValues ($defaults) {
234 foreach ($defaults as $rname => $v) {
235 $this->role->defaults[$rname][$this->name] = $v ;
239 function setValueDescriptions ($descs) {
240 global $rbac_permission_names ;
241 foreach ($descs as $k => $v) {
242 $rbac_permission_names[$this->name.$k] = $v ;
246 function setDescription ($desc) {
247 global $rbac_edit_section_names ;
248 $rbac_edit_section_names[$this->name] = $desc ;
254 // c-file-style: "bsd"