1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
|
<?php
/**
* extsubprojPlugin Class
*
*
* This file is part of FusionForge.
*
* FusionForge is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* FusionForge is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
class extsubprojPlugin extends Plugin {
public function __construct($id=0) {
$this->Plugin($id) ;
$this->name = "extsubproj";
$this->text = "External SubProjects"; // To show in the tabs, use...
/*
$this->_addHook("user_personal_links");//to make a link to the user's personal part of the plugin
$this->_addHook("usermenu");
$this->_addHook("groupmenu"); // To put into the project tabs
$this->_addHook("userisactivecheckbox"); // The "use ..." checkbox in user account
$this->_addHook("userisactivecheckboxpost"); //
*/
$this->_addHook("groupisactivecheckbox"); // The "use ..." checkbox in editgroupinfo
$this->_addHook("groupisactivecheckboxpost"); //
$this->_addHook("project_admin_plugins"); // to show up in the admin page fro group
$this->_addHook('site_admin_option_hook'); // to provide a link to the site wide administrative pages of plugin
$this->_addHook('widget_instance'); // creates widgets when requested
$this->_addHook('widgets'); // declares which widgets are provided by the plugin
}
function site_admin_option_hook(&$params) {
// Use this to provide a link to the site wide administrative pages for your plugin
echo '<li>'.$this->getAdminOptionLink().'</li>';
}
function project_admin_plugins(&$params) {
$group_id = $params['group_id'];
$group = group_get_object($group_id);
if ($group->usesPlugin($this->name)) {
echo '<p>';
echo $this->getProjectAdminLink($group_id);
echo '</p>';
}
}
/**
* getAdminOptionLink - return the admin link url
*
* @return string html url
* @access public
*/
function getAdminOptionLink() {
return util_make_link('/plugins/'.$this->name.'/?type=globaladmin&pluginname='.$this->name,_('External subprojects admin'), array('class'=>'tabtitle', 'title'=>_('Configure the External subprojects plugin')));
}
/**
* getProjectAdminLink - return the project admin link url
*
* @return string html url
* @access public
*/
function getProjectAdminLink($group_id) {
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')));
}
function getProjectAdminAddExtSubProjAction($group_id) {
return '/plugins/'.$this->name.'/?group_id='.$group_id.'&type=admin&pluginname='.$this->name.'&action=addExtSubProj';
}
function getProjectAdminDelExtSubProjAction($group_id, $url) {
return '/plugins/'.$this->name.'/?group_id='.$group_id.'&type=admin&pluginname='.$this->name.'&action=delExtSubProj&url='.urlencode($url);
}
/**
* getHeader - initialize header and js
* @param string type : user, project (aka group)
* @param array params
* @return bool success or not
*/
function getHeader($type, $params=NULL) {
global $gfplugins;
$returned = false;
switch ($type) {
case 'globaladmin': {
session_require_global_perm('forge_admin');
global $gfwww;
require_once($gfwww.'admin/admin_utils.php');
site_admin_header(array('title'=>_('Site Global External subprojects Admin'), 'toptab'=>''));
$returned = true;
break;
}
case 'admin':
default: {
site_project_header($params);
$returned = true;
break;
}
}
return $returned;
}
/**
* getFooter - display footer
*/
function getFooter($type) {
global $gfplugins;
$returned = false;
switch ($type) {
case 'globaladmin': {
session_require_global_perm('forge_admin');
site_admin_footer(array());
break;
}
case 'admin':
default: {
site_project_footer(array());
break;
}
}
return $returned;
}
/**
* redirect - encapsulate session_redirect to handle correctly the redirection URL
*
* @param string usually http_referer from $_SERVER
* @param string type of feedback : error, warning, feedback
* @param string the message of feedback
* @access public
*/
function redirect($http_referer, $type, $message) {
switch ($type) {
case 'warning_msg':
case 'error_msg':
case 'feedback': {
break;
}
default: {
$type = 'error_msg';
}
}
$url = util_find_relative_referer($http_referer);
if (strpos($url,'?')) {
session_redirect($url.'&'.$type.'='.urlencode($message));
}
session_redirect($url.'?'.$type.'='.urlencode($message));
}
/**
* getGlobalAdminView - display the global configuration view
*
* @return boolean True
* @access public
*/
function getGlobalAdminView() {
global $gfplugins, $use_tooltips;
include $gfplugins.$this->name.'/view/admin/viewGlobalConfiguration.php';
return true;
}
/**
* getProjectAdminView - display the project admin view
* @return boolean
*/
function getProjectAdminView() {
global $gfplugins, $use_tooltips;
include $gfplugins.$this->name.'/view/admin/viewProjectConfiguration.php';
return true;
}
function getSubProjects($project_id) {
$res = db_query_params('SELECT sub_project_url from plugin_extsubproj_subprojects where project_id=$1', array($project_id));
if (!$res) {
return false;
}
$returnArr = array();
while ($row = db_fetch_array($res)) {
$returnArr[] = $row['sub_project_url'];
}
return $returnArr;
}
function addExtSubProj($project_id, $url) {
// verify URL
if(!util_check_url($url)) {
return false;
}
// check if not already in the existing subprojects (even for another project)
// TODO first check with HTTP then check with HTTPS
$res = db_query_params('SELECT count(*) from plugin_extsubproj_subprojects where sub_project_url=$1', array($url));
if ($res && db_result($res, 0, 'count') == '0') {
$res = db_query_params('INSERT INTO plugin_extsubproj_subprojects (project_id, sub_project_url) VALUES ($1, $2)',
array($project_id, $url));
if (!$res) {
return false;
}
return true;
}
}
function delExtSubProj($project_id, $url) {
// TODO verify URL
// check if not already in the existing subprojects (even for another project)
// TODO first check with HTTP then check with HTTPS
$res = db_query_params('SELECT count(*) from plugin_extsubproj_subprojects where sub_project_url=$1', array($url));
if ($res && db_result($res, 0, 'count') > '0') {
$res = db_query_params('DELETE FROM plugin_extsubproj_subprojects WHERE project_id=$1 AND sub_project_url=$2',
array($project_id, $url));
if (!$res) {
return false;
}
return true;
}
}
/**
* widgets - 'widgets' hook handler
* @param array $params
* @return boolean
*/
function widgets($params) {
global $gfcommon;
require_once $gfcommon.'/widget/WidgetLayoutManager.class.php';
if ($params['owner_type'] == WidgetLayoutManager::OWNER_TYPE_GROUP) {
$group = group_get_object($GLOBALS['group_id']);
if ($group->usesPlugin($this->name)) {
$params['fusionforge_widgets'][] = 'plugin_extsubproj_project_subprojects';
}
}
return true;
}
/**
* Process the 'widget_instance' hook to create instances of the widgets
* @param array $params
*/
function widget_instance($params) {
global $gfplugins, $gfcommon;
//$user = UserManager::instance()->getCurrentUser();
require_once $gfcommon.'/widget/WidgetLayoutManager.class.php';
if ($params['widget'] == 'plugin_extsubproj_project_subprojects') {
require_once $gfplugins.$this->name.'/include/extsubproj_Widget_SubProjects.class.php';
$params['instance'] = new extsubproj_Widget_SubProjects(WidgetLayoutManager::OWNER_TYPE_GROUP, $this);
}
}
}
// Local Variables:
// mode: php
// c-file-style: "bsd"
// End:
|