4 * extsubprojPlugin 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 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 class extsubprojPlugin extends Plugin {
25 public function __construct($id=0) {
27 $this->name = "extsubproj";
28 $this->text = "External SubProjects"; // To show in the tabs, use...
30 $this->_addHook("user_personal_links");//to make a link to the user's personal part of the plugin
31 $this->_addHook("usermenu");
32 $this->_addHook("groupmenu"); // To put into the project tabs
34 $this->_addHook("userisactivecheckbox"); // The "use ..." checkbox in user account
35 $this->_addHook("userisactivecheckboxpost"); //
37 $this->_addHook("groupisactivecheckbox"); // The "use ..." checkbox in editgroupinfo
38 $this->_addHook("groupisactivecheckboxpost"); //
39 $this->_addHook("project_admin_plugins"); // to show up in the admin page fro group
40 $this->_addHook('site_admin_option_hook'); // to provide a link to the site wide administrative pages of plugin
41 $this->_addHook('widget_instance'); // creates widgets when requested
42 $this->_addHook('widgets'); // declares which widgets are provided by the plugin
45 function site_admin_option_hook(&$params) {
46 // Use this to provide a link to the site wide administrative pages for your plugin
47 echo '<li>'.$this->getAdminOptionLink().'</li>';
50 function project_admin_plugins(&$params) {
51 $group_id = $params['group_id'];
52 $group = group_get_object($group_id);
53 if ($group->usesPlugin($this->name)) {
55 echo $this->getProjectAdminLink($group_id);
61 * getAdminOptionLink - return the admin link url
63 * @return string html url
66 function getAdminOptionLink() {
67 return util_make_link('/plugins/'.$this->name.'/?type=globaladmin&pluginname='.$this->name,_('External subprojects admin'), array('class'=>'tabtitle', 'title'=>_('Configure the External subprojects plugin')));
70 * getProjectAdminLink - return the project admin link url
72 * @return string html url
75 function getProjectAdminLink($group_id) {
76 return util_make_link('/plugins/'.$this->name.'/?group_id='.$group_id.'&type=admin&pluginname='.$this->name, _('External subprojects Admin'), array('class'=>'tabtitle', 'title'=>_('Configure the External subprojects plugin')));
78 function getProjectAdminAddExtSubProjAction($group_id) {
79 return '?group_id='.$group_id.'&type=admin&pluginname='.$this->name.'&action=addExtSubProj';
81 function getProjectAdminDelExtSubProjAction($group_id, $url) {
82 return '?group_id='.$group_id.'&type=admin&pluginname='.$this->name.'&action=delExtSubProj&url='.urlencode($url);
85 * getHeader - initialize header and js
86 * @param string type : user, project (aka group)
88 * @return bool success or not
90 function getHeader($type, $params=NULL) {
95 session_require_global_perm('forge_admin');
97 require_once($gfwww.'admin/admin_utils.php');
98 site_admin_header(array('title'=>_('Site Global External subprojects Admin'), 'toptab'=>''));
104 site_project_header($params);
113 * getFooter - display footer
115 function getFooter($type) {
119 case 'globaladmin': {
120 session_require_global_perm('forge_admin');
121 site_admin_footer(array());
126 site_project_footer(array());
133 * redirect - encapsulate session_redirect to handle correctly the redirection URL
135 * @param string usually http_referer from $_SERVER
136 * @param string type of feedback : error, warning, feedback
137 * @param string the message of feedback
140 function redirect($http_referer, $type, $message) {
151 $url = util_find_relative_referer($http_referer);
152 if (strpos($url,'?')) {
153 session_redirect($url.'&'.$type.'='.urlencode($message));
155 session_redirect($url.'?'.$type.'='.urlencode($message));
159 * getGlobalAdminView - display the global configuration view
161 * @return boolean True
164 function getGlobalAdminView() {
165 global $gfplugins, $use_tooltips;
166 include $gfplugins.$this->name.'/view/admin/viewGlobalConfiguration.php';
171 * getProjectAdminView - display the project admin view
174 function getProjectAdminView() {
175 global $gfplugins, $use_tooltips;
176 include $gfplugins.$this->name.'/view/admin/viewProjectConfiguration.php';
180 function getSubProjects($project_id) {
181 $res = db_query_params('SELECT sub_project_url from plugin_extsubproj_subprojects where project_id=$1', array($project_id));
185 $returnArr = array();
186 while ($row = db_fetch_array($res)) {
187 $returnArr[] = $row['sub_project_url'];
192 function addExtSubProj($project_id, $url) {
194 if(!util_check_url($url)) {
197 // check if not already in the existing subprojects (even for another project)
198 // TODO first check with HTTP then check with HTTPS
199 $res = db_query_params('SELECT count(*) from plugin_extsubproj_subprojects where sub_project_url=$1', array($url));
200 if ($res && db_result($res, 0, 'count') == '0') {
201 $res = db_query_params('INSERT INTO plugin_extsubproj_subprojects (project_id, sub_project_url) VALUES ($1, $2)',
202 array($project_id, $url));
210 function delExtSubProj($project_id, $url) {
212 // check if not already in the existing subprojects (even for another project)
213 // TODO first check with HTTP then check with HTTPS
214 $res = db_query_params('SELECT count(*) from plugin_extsubproj_subprojects where sub_project_url=$1', array($url));
215 if ($res && db_result($res, 0, 'count') > '0') {
216 $res = db_query_params('DELETE FROM plugin_extsubproj_subprojects WHERE project_id=$1 AND sub_project_url=$2',
217 array($project_id, $url));
226 * widgets - 'widgets' hook handler
227 * @param array $params
230 function widgets($params) {
231 require_once 'common/widget/WidgetLayoutManager.class.php';
232 if ($params['owner_type'] == WidgetLayoutManager::OWNER_TYPE_GROUP) {
233 $params['fusionforge_widgets'][] = 'plugin_extsubproj_project_subprojects';
235 if ($params['owner_type'] == WidgetLayoutManager::OWNER_TYPE_USER) {
236 $params['fusionforge_widgets'][] = 'plugin_scmgit_user_myrepositories';
242 * Process the 'widget_instance' hook to create instances of the widgets
243 * @param array $params
245 function widget_instance($params) {
247 //$user = UserManager::instance()->getCurrentUser();
248 require_once 'common/widget/WidgetLayoutManager.class.php';
249 if ($params['widget'] == 'plugin_extsubproj_project_subprojects') {
250 require_once $gfplugins.$this->name.'/include/extsubproj_Widget_SubProjects.class.php';
251 $params['instance'] = new extsubproj_Widget_SubProjects(WidgetLayoutManager::OWNER_TYPE_GROUP, $this);
255 * getConf - return the configuration defined at project level
257 * @param integer the group id
258 * @return array the configuration array
260 /*function getConf($project_id) {
261 $resConf = db_query_params('SELECT * from plugin_extsubproj_subprojects where project_id=$1',array($project_id));
266 $row = db_numrows($resConf);
268 if ($row == null || count($row) > 2) {
272 $resArr = db_fetch_array($resConf);
273 $returnArr = array();
275 foreach($resArr as $column => $value) {
277 $returnArr[$column] = true;
279 $returnArr[$column] = false;
287 // function CallHook ($hookname, &$params) {
288 // global $use_extsubprojplugin,$G_SESSION,$HTML;
290 if ($hookname == "usermenu") {
291 $text = $this->text; // this is what shows in the tab
292 if ($G_SESSION->usesPlugin("extsubproj")) {
293 $param = '?type=user&id=' . $G_SESSION->getId() . "&pluginname=" . $this->name; // we indicate the part we're calling is the user one
294 echo $HTML->PrintSubMenu (array ($text),
295 array ('/plugins/extsubproj/index.php' . $param ));
298 } elseif ($hookname == "groupmenu") {
299 $group_id=$params['group'];
300 $project = &group_get_object($group_id);
301 if (!$project || !is_object($project)) {
304 if ($project->isError()) {
307 if (!$project->isProject()) {
310 if ( $project->usesPlugin ( $this->name ) ) {
311 $params['TITLES'][]=$this->text;
312 $params['DIRS'][]=util_make_url ('/plugins/extsubproj/index.php?type=group&id=' . $group_id . "&pluginname=" . $this->name) ; // we indicate the part we're calling is the project one
314 $params['TITLES'][]=$this->text." is [Off]";
315 $params['DIRS'][]='';
317 (($params['toptab'] == $this->name) ? $params['selected']=(count($params['TITLES'])-1) : '' );
318 } elseif ($hookname == "groupisactivecheckbox") {
319 //Check if the group is active
320 // this code creates the checkbox in the project edit public info page to activate/deactivate the plugin
321 $group_id=$params['group'];
322 $group = &group_get_object($group_id);
325 echo ' <input type="checkbox" name="use_extsubprojplugin" value="1" ';
326 // checked or unchecked?
327 if ( $group->usesPlugin ( $this->name ) ) {
333 echo "<strong>Use ".$this->text." Plugin</strong>";
336 } elseif ($hookname == "groupisactivecheckboxpost") {
337 // this code actually activates/deactivates the plugin after the form was submitted in the project edit public info page
338 $group_id=$params['group'];
339 $group = &group_get_object($group_id);
340 $use_extsubprojplugin = getStringFromRequest('use_extsubprojplugin');
341 if ( $use_extsubprojplugin == 1 ) {
342 $group->setPluginUse ( $this->name );
344 $group->setPluginUse ( $this->name, false );
346 } elseif ($hookname == "user_personal_links") {
347 // this displays the link in the user's profile page to it's personal extsubproj (if you want other sto access it, youll have to change the permissions in the index.php
348 $userid = $params['user_id'];
349 $user = user_get_object($userid);
350 $text = $params['text'];
351 //check if the user has the plugin activated
352 if ($user->usesPlugin($this->name)) {
354 echo util_make_link ("/plugins/extsubproj/index.php?id=$userid&type=user&pluginname=".$this->name,
355 _('View Personal extsubproj')
359 } elseif ($hookname == "project_admin_plugins") {
360 // this displays the link in the project admin options page to it's extsubproj administration
361 $group_id = $params['group_id'];
362 $group = &group_get_object($group_id);
363 if ( $group->usesPlugin ( $this->name ) ) {
364 echo '<p>'.util_make_link ("/plugins/extsubproj/admin/index.php?id=".$group->getID().'&type=admin&pluginname='.$this->name,
365 _('extsubproj Admin')).'</p>' ;
368 elseif ($hookname == "blahblahblah") {
378 // c-file-style: "bsd"